@escapeaihq/client-core 0.4.2 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -3
- package/dist/api.d.ts +95 -1
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +127 -2
- package/dist/api.js.map +1 -1
- package/dist/websocket.d.ts +105 -1
- package/dist/websocket.d.ts.map +1 -1
- package/dist/websocket.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/chat-auth.test.ts +261 -0
- package/src/__tests__/loadBundleManifest.test.ts +331 -0
- package/src/api.ts +204 -2
- package/src/websocket.ts +107 -1
package/src/websocket.ts
CHANGED
|
@@ -9,7 +9,11 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import type { HelloPayload } from './audio';
|
|
12
|
-
import type {
|
|
12
|
+
import type {
|
|
13
|
+
AudioMetadataMessage,
|
|
14
|
+
BargeInAckMessage,
|
|
15
|
+
WordPhonemeInfo,
|
|
16
|
+
} from './audioProtocol';
|
|
13
17
|
|
|
14
18
|
export interface Citation {
|
|
15
19
|
videoId: string;
|
|
@@ -38,6 +42,104 @@ export interface ToolResult {
|
|
|
38
42
|
*/
|
|
39
43
|
export type DoneReason = 'complete' | 'timeout' | (string & {});
|
|
40
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Discriminated union of every event the chat WebSocket can emit.
|
|
47
|
+
*
|
|
48
|
+
* Prefer this over the legacy {@link WebSocketMessage} flat interface
|
|
49
|
+
* when writing new code — TypeScript narrows each `case` in a switch
|
|
50
|
+
* to exactly the fields that case carries, so missing cases surface
|
|
51
|
+
* as compile errors rather than silent undefineds. The legacy shape
|
|
52
|
+
* is retained for back-compat with existing consumers but is being
|
|
53
|
+
* phased out — both seer-agent's React `chat-ws/page.tsx` and the
|
|
54
|
+
* Vue `seer-ai-chat.vue` hand-rolled their own copies of this union
|
|
55
|
+
* before it lived here.
|
|
56
|
+
*
|
|
57
|
+
* **Timestamp asymmetry.** Most cases carry `timestamp?: number`
|
|
58
|
+
* because `api/chat/ws.py` injects one into the dict literal before
|
|
59
|
+
* sending. The two pydantic-modelled cases (`AudioMetadataMessage`,
|
|
60
|
+
* `BargeInAckMessage` from `audioProtocol.ts`) intentionally omit it
|
|
61
|
+
* — their pydantic models use `extra="forbid"` and don't declare a
|
|
62
|
+
* timestamp field, so the server cannot send one. Don't add
|
|
63
|
+
* `timestamp?` to those interfaces unless you also relax the pydantic
|
|
64
|
+
* schemas.
|
|
65
|
+
*
|
|
66
|
+
* Source of truth for field semantics: `api/chat/app.py:websocket_endpoint`
|
|
67
|
+
* docstring + `api/chat/ws.py`.
|
|
68
|
+
*/
|
|
69
|
+
export type ChatWsEvent =
|
|
70
|
+
| { type: 'token'; timestamp?: number; content: string }
|
|
71
|
+
| {
|
|
72
|
+
type: 'citation';
|
|
73
|
+
timestamp?: number;
|
|
74
|
+
citation: Citation;
|
|
75
|
+
span?: string;
|
|
76
|
+
}
|
|
77
|
+
| { type: 'done'; timestamp?: number; reason?: DoneReason }
|
|
78
|
+
| { type: 'error'; timestamp?: number; message: string }
|
|
79
|
+
| {
|
|
80
|
+
type: 'image';
|
|
81
|
+
timestamp?: number;
|
|
82
|
+
imageUrl: string;
|
|
83
|
+
entity?: string;
|
|
84
|
+
prompt?: string;
|
|
85
|
+
sourceTimestamp?: number;
|
|
86
|
+
}
|
|
87
|
+
| {
|
|
88
|
+
type: 'tool_use';
|
|
89
|
+
timestamp?: number;
|
|
90
|
+
tool: string;
|
|
91
|
+
toolUseId: string;
|
|
92
|
+
}
|
|
93
|
+
| {
|
|
94
|
+
type: 'tool_result';
|
|
95
|
+
timestamp?: number;
|
|
96
|
+
tool?: string;
|
|
97
|
+
toolUseId?: string;
|
|
98
|
+
result?: ToolResult;
|
|
99
|
+
}
|
|
100
|
+
| {
|
|
101
|
+
type: 'hello_ack';
|
|
102
|
+
timestamp?: number;
|
|
103
|
+
sessionId: string;
|
|
104
|
+
mode: 'hybrid' | 'sonic';
|
|
105
|
+
/** Negotiated audio format ('pcm16' or 'mp3'). Optional on the
|
|
106
|
+
* wire — the server only populates it when the negotiation
|
|
107
|
+
* actually picked a value. See `HelloAckMessage` in
|
|
108
|
+
* `shared/audio_protocol.py`. */
|
|
109
|
+
audioFormat?: string;
|
|
110
|
+
}
|
|
111
|
+
| {
|
|
112
|
+
type: 'transcript';
|
|
113
|
+
timestamp?: number;
|
|
114
|
+
text: string;
|
|
115
|
+
final: boolean;
|
|
116
|
+
resultId?: string;
|
|
117
|
+
}
|
|
118
|
+
| AudioMetadataMessage
|
|
119
|
+
| BargeInAckMessage
|
|
120
|
+
| {
|
|
121
|
+
type: 'audio_chunk';
|
|
122
|
+
timestamp?: number;
|
|
123
|
+
chunkId?: string;
|
|
124
|
+
audio: string;
|
|
125
|
+
format: 'mp3' | 'pcm16' | 'ogg_opus';
|
|
126
|
+
}
|
|
127
|
+
| {
|
|
128
|
+
type: 'metrics';
|
|
129
|
+
timestamp?: number;
|
|
130
|
+
llm_first_token_ms?: number;
|
|
131
|
+
tts_first_chunk_ms?: number;
|
|
132
|
+
transcript_to_first_audio_ms?: number;
|
|
133
|
+
}
|
|
134
|
+
| { type: 'heartbeat'; timestamp?: number }
|
|
135
|
+
| { type: 'pong'; timestamp?: number };
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* @deprecated Prefer {@link ChatWsEvent} — the flat-shape interface
|
|
139
|
+
* here defeats exhaustiveness checking in switch statements. Kept for
|
|
140
|
+
* back-compat with existing handler signatures; new code should consume
|
|
141
|
+
* `ChatWsEvent` instead.
|
|
142
|
+
*/
|
|
41
143
|
export interface WebSocketMessage {
|
|
42
144
|
type:
|
|
43
145
|
| 'token'
|
|
@@ -70,6 +172,10 @@ export interface WebSocketMessage {
|
|
|
70
172
|
reason?: DoneReason;
|
|
71
173
|
mode?: 'hybrid' | 'sonic';
|
|
72
174
|
sessionId?: string;
|
|
175
|
+
/** Negotiated audio format on `{type: 'hello_ack'}` — 'pcm16' or
|
|
176
|
+
* 'mp3'. See `HelloAckMessage.audioFormat` in
|
|
177
|
+
* `shared/audio_protocol.py`. */
|
|
178
|
+
audioFormat?: string;
|
|
73
179
|
// Image regeneration fields
|
|
74
180
|
imageUrl?: string;
|
|
75
181
|
entity?: string;
|