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.

WASM computes versioned fingerprint digest ↓ POST /api/v1/device/init ↓ server HMAC → stable fingerprint key → device_id + device_token ↓ POST /api/v1/auth/init ↓ server verifies device_token → session_key + JWT ↓ WASM signs chat request with session_key
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.