PYPYLAB
LIVE DEMO

P03 · AI Application Infrastructure

AI Web Chat SDK

A secure embedded AI conversation layer: browser runtime, Web Component, device identity, request signing, anti-replay, short-lived sessions, quotas and service-side controls.

Rust/WASMTypeScriptFastAPIRedisWeb ComponentsHMACAnti-ReplayTDD
ARCHITECTURE

Security-sensitive work stays behind explicit boundaries.

Web pageHost application embeds the SDK
Web ComponentUI + conversation continuity
Rust / WASMFingerprint digest, signing, anti-replay data
FastAPIDevice, auth, session and chat endpoints
RedisStable mapping, quota, session and rate-limit state
AUTH FLOW

Server-issued identity, then short-lived session authority.

  1. CLIENT · WASMBrowser

    Build a versioned fingerprint digest

    WASM calculates a versioned device fingerprint digest. The browser supplies identity input; it does not mint the server-owned device_id.

  2. SERVER · DEVICEPOST /api/v1/device/init

    Resolve a stable device identity

    The server applies HMAC to derive a stable fingerprint key, resolves device_id and returns device_token alongside that identity.

    Response: device_id + device_token
  3. SERVER · AUTHPOST /api/v1/auth/init

    Verify identity and issue a session

    The service validates device_token and grants short-lived session authority.

    Response: session_key + JWT
  4. CLIENT → SERVERSigned chat request

    Sign, verify, then account for usage

    WASM signs chat requests with session_key. The server checks request integrity and replay protections before counting accepted usage; quota and rate limits remain separate controls.

Identity

Server-issued device_id

The browser does not mint its own device identity. The mapping is derived and owned by the service boundary.

Integrity

Signed + replay-aware requests

Request signatures are validated before accepted usage is counted, preventing duplicate signatures from consuming quota twice.

Abuse control

Quota and rate layers

Daily device quota, short-lived sessions and IP minute-level limits represent distinct operational concerns.

20accepted user requests per device per Asia/Shanghai day
40recent user/assistant messages retained as conversation context
5mshort-lived session lifetime in the current implementation

Implementation snapshot.

The same SDK powers Ask Portfolio AI.

Browser-side SDK, service security controls and MCP-backed portfolio knowledge form one end-to-end AI interaction path.