@letta-ai/letta-code 0.29.5 → 0.29.7
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/dist/app-server-client.cjs +16 -20
- package/dist/app-server-client.cjs.map +3 -3
- package/dist/app-server-client.js +16 -20
- package/dist/app-server-client.js.map +3 -3
- package/dist/memory-confinement.js +363 -0
- package/dist/memory-confinement.js.map +18 -0
- package/dist/types/app-server-client.d.ts +12 -9
- package/dist/types/app-server-client.d.ts.map +1 -1
- package/dist/types/channels/plugin-types.d.ts +2 -2
- package/dist/types/channels/plugin-types.d.ts.map +1 -1
- package/dist/types/channels/types.d.ts +15 -1
- package/dist/types/channels/types.d.ts.map +1 -1
- package/dist/types/memory-confinement.d.ts +13 -0
- package/dist/types/memory-confinement.d.ts.map +1 -0
- package/dist/types/permissions/memory-confinement-launcher.d.ts +20 -0
- package/dist/types/permissions/memory-confinement-launcher.d.ts.map +1 -0
- package/dist/types/permissions/sandbox-policy.d.ts +138 -0
- package/dist/types/permissions/sandbox-policy.d.ts.map +1 -0
- package/dist/types/sandbox/availability.d.ts +60 -0
- package/dist/types/sandbox/availability.d.ts.map +1 -0
- package/dist/types/sandbox/bwrap.d.ts +36 -0
- package/dist/types/sandbox/bwrap.d.ts.map +1 -0
- package/dist/types/sandbox/policy.d.ts +79 -0
- package/dist/types/sandbox/policy.d.ts.map +1 -0
- package/dist/types/sandbox/seatbelt.d.ts +39 -0
- package/dist/types/sandbox/seatbelt.d.ts.map +1 -0
- package/dist/types/sandbox/wrap.d.ts +18 -0
- package/dist/types/sandbox/wrap.d.ts.map +1 -0
- package/dist/types/types/protocol_v2.d.ts +2 -0
- package/dist/types/types/protocol_v2.d.ts.map +1 -1
- package/dist/types/utils/local-backend-paths.d.ts +23 -0
- package/dist/types/utils/local-backend-paths.d.ts.map +1 -0
- package/letta.js +1868 -1076
- package/package.json +11 -1
- package/scripts/source-file-size-baseline.json +5 -5
|
@@ -29,6 +29,7 @@ var __export = (target, all) => {
|
|
|
29
29
|
// src/app-server-client.ts
|
|
30
30
|
var exports_app_server_client = {};
|
|
31
31
|
__export(exports_app_server_client, {
|
|
32
|
+
resolveAppServerUrl: () => resolveAppServerUrl,
|
|
32
33
|
resolveAppServerChannelUrl: () => resolveAppServerChannelUrl,
|
|
33
34
|
isAppServerInfoResponseMessage: () => isAppServerInfoResponseMessage,
|
|
34
35
|
createAppServerClient: () => createAppServerClient,
|
|
@@ -70,11 +71,14 @@ function normalizeBaseUrl(url) {
|
|
|
70
71
|
}
|
|
71
72
|
return parsed;
|
|
72
73
|
}
|
|
73
|
-
function
|
|
74
|
+
function resolveAppServerUrl(url) {
|
|
74
75
|
const parsed = normalizeBaseUrl(url);
|
|
75
|
-
parsed.searchParams.
|
|
76
|
+
parsed.searchParams.delete("channel");
|
|
76
77
|
return parsed.toString();
|
|
77
78
|
}
|
|
79
|
+
function resolveAppServerChannelUrl(url, _channel) {
|
|
80
|
+
return resolveAppServerUrl(url);
|
|
81
|
+
}
|
|
78
82
|
function attachSocketListener(socket, type, listener) {
|
|
79
83
|
if (socket.addEventListener && socket.removeEventListener) {
|
|
80
84
|
socket.addEventListener(type, listener);
|
|
@@ -185,6 +189,7 @@ function streamDeltaErrorMessage(message) {
|
|
|
185
189
|
}
|
|
186
190
|
|
|
187
191
|
class AppServerClient {
|
|
192
|
+
socket;
|
|
188
193
|
control;
|
|
189
194
|
stream;
|
|
190
195
|
requestTimeoutMs;
|
|
@@ -203,26 +208,18 @@ class AppServerClient {
|
|
|
203
208
|
}
|
|
204
209
|
this.requestTimeoutMs = options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
|
|
205
210
|
const socketOptions = appServerSocketOptions(options.authToken);
|
|
206
|
-
this.
|
|
207
|
-
this.
|
|
208
|
-
|
|
211
|
+
this.socket = new WebSocket(resolveAppServerUrl(options.url), socketOptions);
|
|
212
|
+
this.control = this.socket;
|
|
213
|
+
this.stream = this.socket;
|
|
214
|
+
attachSocketListener(this.socket, "message", (event) => {
|
|
209
215
|
this.handleMessage(event, "control");
|
|
210
216
|
});
|
|
211
|
-
attachSocketListener(this.
|
|
212
|
-
this.handleMessage(event, "stream");
|
|
213
|
-
});
|
|
214
|
-
attachSocketListener(this.control, "close", (event) => {
|
|
217
|
+
attachSocketListener(this.socket, "close", (event) => {
|
|
215
218
|
this.handleDisconnect("control", event);
|
|
216
219
|
});
|
|
217
|
-
attachSocketListener(this.stream, "close", (event) => {
|
|
218
|
-
this.handleDisconnect("stream", event);
|
|
219
|
-
});
|
|
220
220
|
}
|
|
221
221
|
async connect() {
|
|
222
|
-
await
|
|
223
|
-
waitForSocketOpen(this.control),
|
|
224
|
-
waitForSocketOpen(this.stream)
|
|
225
|
-
]);
|
|
222
|
+
await waitForSocketOpen(this.socket);
|
|
226
223
|
return this;
|
|
227
224
|
}
|
|
228
225
|
close() {
|
|
@@ -230,8 +227,7 @@ class AppServerClient {
|
|
|
230
227
|
return;
|
|
231
228
|
this.explicitlyClosed = true;
|
|
232
229
|
this.rejectAllPending("App-server client closed");
|
|
233
|
-
this.
|
|
234
|
-
this.stream.close();
|
|
230
|
+
this.socket.close();
|
|
235
231
|
}
|
|
236
232
|
onMessage(handler) {
|
|
237
233
|
this.messageHandlers.add(handler);
|
|
@@ -256,7 +252,7 @@ class AppServerClient {
|
|
|
256
252
|
for (const handler of this.sendHandlers) {
|
|
257
253
|
handler(command);
|
|
258
254
|
}
|
|
259
|
-
this.
|
|
255
|
+
this.socket.send(JSON.stringify(command));
|
|
260
256
|
}
|
|
261
257
|
sendRaw(command) {
|
|
262
258
|
this.writeCommand(command);
|
|
@@ -528,4 +524,4 @@ function createAppServerClient(options) {
|
|
|
528
524
|
return new AppServerClient(options);
|
|
529
525
|
}
|
|
530
526
|
|
|
531
|
-
//# debugId=
|
|
527
|
+
//# debugId=6A8C34B21871B15E64756E2164756E21
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
"sources": ["../src/types/app-server-info.ts", "../src/app-server-client.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"export const APP_SERVER_PROTOCOL_VERSION = 1;\n\nexport interface AppServerInfoCommand {\n type: \"app_server_info\";\n /** Echoed back in the response for request correlation. */\n request_id: string;\n}\n\nexport interface AppServerInfoResponseMessage {\n type: \"app_server_info_response\";\n request_id: string;\n /** Synchronous post-auth capability discovery has no domain failure variant. */\n success: true;\n backend: \"local\" | \"api\";\n letta_code_version: string;\n /** Wire value reported by the server; clients compare it with their supported version. */\n protocol_version: number;\n capabilities: {\n agent_management: boolean;\n conversation_management: boolean;\n memory_management: boolean;\n runtime_start: boolean;\n split_channels: boolean;\n };\n}\n\nexport function isAppServerInfoResponseMessage(\n message: unknown,\n): message is AppServerInfoResponseMessage {\n if (!message || typeof message !== \"object\" || Array.isArray(message)) {\n return false;\n }\n\n const candidate = message as Record<string, unknown>;\n const capabilities = candidate.capabilities;\n if (\n !capabilities ||\n typeof capabilities !== \"object\" ||\n Array.isArray(capabilities)\n ) {\n return false;\n }\n\n const capabilityRecord = capabilities as Record<string, unknown>;\n return (\n candidate.type === \"app_server_info_response\" &&\n typeof candidate.request_id === \"string\" &&\n candidate.request_id.length > 0 &&\n candidate.success === true &&\n (candidate.backend === \"local\" || candidate.backend === \"api\") &&\n typeof candidate.letta_code_version === \"string\" &&\n typeof candidate.protocol_version === \"number\" &&\n Number.isInteger(candidate.protocol_version) &&\n typeof capabilityRecord.agent_management === \"boolean\" &&\n typeof capabilityRecord.conversation_management === \"boolean\" &&\n typeof capabilityRecord.memory_management === \"boolean\" &&\n typeof capabilityRecord.runtime_start === \"boolean\" &&\n typeof capabilityRecord.split_channels === \"boolean\"\n );\n}\n",
|
|
6
|
-
"import { isAppServerInfoResponseMessage } from \"./types/app-server-info\";\n\nexport type { AppServerInfoResponseMessage } from \"./types/app-server-info\";\nexport { isAppServerInfoResponseMessage } from \"./types/app-server-info\";\n\nimport type {\n AbortMessageCommand,\n AbortMessageResponseMessage,\n AppServerInfoResponseMessage,\n ConversationListCommand,\n ConversationListResponseMessage,\n ExternalToolCallRequestMessage,\n ExternalToolCallResult,\n InputCommand,\n LoopStatusUpdateMessage,\n RuntimeScope,\n RuntimeStartCommand,\n RuntimeStartResponseMessage,\n StreamDeltaMessage,\n SyncCommand,\n SyncResponseMessage,\n WsProtocolCommand,\n WsProtocolMessage,\n} from \"./types/app-server-protocol\";\n\nexport type AppServerChannel = \"control\" | \"stream\";\n\nexport type AppServerRawCommand = Record<string, unknown> & {\n type: string;\n request_id?: string;\n};\n\nexport type AppServerRawResponse = Record<string, unknown> & {\n type: string;\n request_id?: string;\n};\n\nexport type AppServerSendCommand = WsProtocolCommand | AppServerRawCommand;\n\n/**\n * Receives every parsed protocol frame from both app-server websocket channels.\n * Treat this as the primary event stream: app-server may emit replay or turn\n * updates on the same channel that sent the triggering command, not only on the\n * stream channel. The channel argument is diagnostic/routing context.\n */\nexport type AppServerMessageHandler = (\n message: WsProtocolMessage,\n channel: AppServerChannel,\n) => void;\n\n/** Called synchronously before a typed or raw command is written to the control socket. */\nexport type AppServerSendHandler = (command: AppServerSendCommand) => void;\n\nexport interface AppServerDisconnectEvent {\n channel: AppServerChannel;\n event: unknown;\n}\n\n/** Called once when either websocket closes before client.close(). */\nexport type AppServerDisconnectHandler = (\n disconnect: AppServerDisconnectEvent,\n) => void;\n\nexport type AppServerExternalToolCallHandler = (\n request: ExternalToolCallRequestMessage,\n) => Promise<ExternalToolCallResult> | ExternalToolCallResult;\n\nexport interface AppServerSocketLike {\n readyState: number;\n send(data: string): void;\n close(): void;\n addEventListener?(type: string, listener: (event: unknown) => void): void;\n removeEventListener?(type: string, listener: (event: unknown) => void): void;\n on?(type: string, listener: (event: unknown) => void): void;\n off?(type: string, listener: (event: unknown) => void): void;\n once?(type: string, listener: (event: unknown) => void): void;\n}\n\nexport interface AppServerSocketOptions {\n headers?: Record<string, string>;\n}\n\nexport type AppServerSocketConstructor = new (\n url: string,\n options?: AppServerSocketOptions,\n) => AppServerSocketLike;\n\nexport interface AppServerClientOptions {\n /** Base app-server URL, e.g. ws://127.0.0.1:4500 or http://127.0.0.1:4500. */\n url: string;\n /** Optional capability token sent as Authorization: Bearer <token>; requires a WebSocket implementation with header support. */\n authToken?: string;\n /** Optional WebSocket constructor for Node/tests. Browsers use globalThis.WebSocket. */\n WebSocket?: AppServerSocketConstructor;\n /** Default timeout for request_id-correlated control requests. */\n requestTimeoutMs?: number;\n}\n\nexport interface AppServerRequestOptions<TMessage extends WsProtocolMessage> {\n timeoutMs?: number;\n predicate?: (message: WsProtocolMessage) => message is TMessage;\n}\n\nexport type AppServerRequestCommand = Extract<\n WsProtocolCommand,\n { request_id?: string }\n>;\n\nexport type AppServerRequestCommandWithId = AppServerRequestCommand & {\n request_id: string;\n};\n\nexport type AppServerRequestBody = Record<string, unknown> & {\n request_id?: string;\n};\n\nexport interface AppServerRawRequestOptions<\n TResponse extends AppServerRawResponse,\n> {\n timeoutMs?: number;\n predicate: (message: unknown) => message is TResponse;\n}\n\ntype PendingRequest = {\n resolve: (message: WsProtocolMessage) => void;\n reject: (error: Error) => void;\n predicate?: (message: WsProtocolMessage) => boolean;\n timeout: ReturnType<typeof setTimeout>;\n};\n\nexport type AppServerTurnCompletionSource =\n | \"stop_reason\"\n | \"loop_status_waiting_on_approval\"\n | \"loop_status_waiting_fallback\";\n\nexport interface AppServerTurnResult {\n runtime: RuntimeScope;\n stopReason: string | null;\n runIds: string[];\n clientMessageIds: string[];\n completedBy: AppServerTurnCompletionSource;\n terminalMessage: WsProtocolMessage;\n}\n\nexport interface AppServerRunTurnOptions {\n timeoutMs?: number;\n /**\n * Prefer explicit stream terminal events. This fallback is only used after\n * the client has seen stream/run evidence for this runtime, never from idle\n * loop status alone.\n */\n allowLoopStatusFallback?: boolean;\n}\n\nconst DEFAULT_REQUEST_TIMEOUT_MS = 30_000;\nconst WEBSOCKET_OPEN_STATE = 1;\n\nfunction getGlobalWebSocket(): AppServerSocketConstructor | undefined {\n return (globalThis as { WebSocket?: AppServerSocketConstructor }).WebSocket;\n}\n\nfunction normalizeBaseUrl(url: string): URL {\n const parsed = new URL(url);\n if (parsed.protocol === \"http:\") parsed.protocol = \"ws:\";\n if (parsed.protocol === \"https:\") parsed.protocol = \"wss:\";\n if (parsed.protocol !== \"ws:\" && parsed.protocol !== \"wss:\") {\n throw new Error(`Unsupported app-server URL protocol: ${parsed.protocol}`);\n }\n if (!parsed.pathname || parsed.pathname === \"/\") {\n parsed.pathname = \"/ws\";\n }\n return parsed;\n}\n\nexport function resolveAppServerChannelUrl(\n url: string,\n channel: AppServerChannel,\n): string {\n const parsed = normalizeBaseUrl(url);\n parsed.searchParams.set(\"channel\", channel);\n return parsed.toString();\n}\n\nfunction attachSocketListener(\n socket: AppServerSocketLike,\n type: string,\n listener: (event: unknown) => void,\n): () => void {\n if (socket.addEventListener && socket.removeEventListener) {\n socket.addEventListener(type, listener);\n return () => socket.removeEventListener?.(type, listener);\n }\n\n if (socket.on) {\n socket.on(type, listener);\n return () => socket.off?.(type, listener);\n }\n\n throw new Error(\"WebSocket implementation does not support event listeners\");\n}\n\nfunction onceSocketEvent(\n socket: AppServerSocketLike,\n type: string,\n listener: (event: unknown) => void,\n): () => void {\n if (socket.once) {\n socket.once(type, listener);\n return () => socket.off?.(type, listener);\n }\n\n let detach = () => {};\n detach = attachSocketListener(socket, type, (event) => {\n detach();\n listener(event);\n });\n return detach;\n}\n\nfunction waitForSocketOpen(socket: AppServerSocketLike): Promise<void> {\n if (socket.readyState === WEBSOCKET_OPEN_STATE) {\n return Promise.resolve();\n }\n\n return new Promise((resolve, reject) => {\n let detachOpen = () => {};\n let detachError = () => {};\n const cleanup = () => {\n detachOpen();\n detachError();\n };\n detachOpen = onceSocketEvent(socket, \"open\", () => {\n cleanup();\n resolve();\n });\n detachError = onceSocketEvent(socket, \"error\", (event) => {\n cleanup();\n reject(\n new Error(`App-server WebSocket failed to open: ${String(event)}`),\n );\n });\n });\n}\n\nfunction rawEventData(event: unknown): unknown {\n if (event && typeof event === \"object\" && \"data\" in event) {\n return (event as { data: unknown }).data;\n }\n return event;\n}\n\nfunction messageDataToString(data: unknown): string {\n const raw = rawEventData(data);\n if (typeof raw === \"string\") return raw;\n if (raw instanceof ArrayBuffer) {\n return new TextDecoder().decode(raw);\n }\n if (raw instanceof Uint8Array) {\n return new TextDecoder().decode(raw);\n }\n if (ArrayBuffer.isView(raw)) {\n return new TextDecoder().decode(\n new Uint8Array(raw.buffer as ArrayBuffer, raw.byteOffset, raw.byteLength),\n );\n }\n return String(raw);\n}\n\nfunction parseProtocolMessage(event: unknown): WsProtocolMessage {\n return JSON.parse(messageDataToString(event)) as WsProtocolMessage;\n}\n\nfunction appServerSocketOptions(\n authToken: string | undefined,\n): AppServerSocketOptions | undefined {\n if (authToken === undefined) {\n return undefined;\n }\n const token = authToken.trim();\n if (!token) {\n throw new Error(\"app-server auth token must not be empty\");\n }\n return { headers: { Authorization: `Bearer ${token}` } };\n}\n\nfunction sameRuntime(a: RuntimeScope | undefined, b: RuntimeScope): boolean {\n return a?.agent_id === b.agent_id && a?.conversation_id === b.conversation_id;\n}\n\nfunction isWaitingLoopStatus(message: LoopStatusUpdateMessage): boolean {\n return message.loop_status.status === \"WAITING_ON_INPUT\";\n}\n\nfunction isWaitingOnApprovalLoopStatus(\n message: LoopStatusUpdateMessage,\n): boolean {\n return message.loop_status.status === \"WAITING_ON_APPROVAL\";\n}\n\nfunction streamDeltaRunId(message: StreamDeltaMessage): string | null {\n const runId = (message.delta as { run_id?: unknown }).run_id;\n return typeof runId === \"string\" ? runId : null;\n}\n\nfunction streamDeltaMessageType(message: StreamDeltaMessage): string | null {\n const messageType = (message.delta as { message_type?: unknown })\n .message_type;\n return typeof messageType === \"string\" ? messageType : null;\n}\n\nfunction streamDeltaStopReason(message: StreamDeltaMessage): string | null {\n const stopReason = (message.delta as { stop_reason?: unknown }).stop_reason;\n return typeof stopReason === \"string\" ? stopReason : null;\n}\n\nfunction streamDeltaErrorMessage(message: StreamDeltaMessage): string {\n const delta = message.delta as {\n message?: unknown;\n api_error?: { message?: unknown; detail?: unknown };\n };\n const apiMessage = delta.api_error?.message ?? delta.api_error?.detail;\n if (typeof apiMessage === \"string\" && apiMessage.length > 0)\n return apiMessage;\n if (typeof delta.message === \"string\" && delta.message.length > 0)\n return delta.message;\n return \"App-server turn failed\";\n}\n\nexport class AppServerClient {\n readonly control: AppServerSocketLike;\n readonly stream: AppServerSocketLike;\n\n private readonly requestTimeoutMs: number;\n private readonly pending = new Map<string, PendingRequest>();\n private readonly messageHandlers = new Set<AppServerMessageHandler>();\n private readonly sendHandlers = new Set<AppServerSendHandler>();\n private readonly disconnectHandlers = new Set<AppServerDisconnectHandler>();\n private readonly activeTurnRuntimes = new Set<string>();\n private explicitlyClosed = false;\n private disconnectNotified = false;\n private nextRequestNumber = 0;\n\n constructor(options: AppServerClientOptions) {\n const WebSocket = options.WebSocket ?? getGlobalWebSocket();\n if (!WebSocket) {\n throw new Error(\"No WebSocket implementation available\");\n }\n\n this.requestTimeoutMs =\n options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;\n const socketOptions = appServerSocketOptions(options.authToken);\n this.control = new WebSocket(\n resolveAppServerChannelUrl(options.url, \"control\"),\n socketOptions,\n );\n this.stream = new WebSocket(\n resolveAppServerChannelUrl(options.url, \"stream\"),\n socketOptions,\n );\n\n attachSocketListener(this.control, \"message\", (event) => {\n this.handleMessage(event, \"control\");\n });\n attachSocketListener(this.stream, \"message\", (event) => {\n this.handleMessage(event, \"stream\");\n });\n attachSocketListener(this.control, \"close\", (event) => {\n this.handleDisconnect(\"control\", event);\n });\n attachSocketListener(this.stream, \"close\", (event) => {\n this.handleDisconnect(\"stream\", event);\n });\n }\n\n async connect(): Promise<this> {\n await Promise.all([\n waitForSocketOpen(this.control),\n waitForSocketOpen(this.stream),\n ]);\n return this;\n }\n\n close(): void {\n if (this.explicitlyClosed) return;\n this.explicitlyClosed = true;\n this.rejectAllPending(\"App-server client closed\");\n this.control.close();\n this.stream.close();\n }\n\n onMessage(handler: AppServerMessageHandler): () => void {\n this.messageHandlers.add(handler);\n return () => this.messageHandlers.delete(handler);\n }\n\n onSend(handler: AppServerSendHandler): () => void {\n this.sendHandlers.add(handler);\n return () => this.sendHandlers.delete(handler);\n }\n\n onDisconnect(handler: AppServerDisconnectHandler): () => void {\n this.disconnectHandlers.add(handler);\n return () => this.disconnectHandlers.delete(handler);\n }\n\n nextRequestId(prefix = \"req\"): string {\n this.nextRequestNumber += 1;\n return `${prefix}-${this.nextRequestNumber}`;\n }\n\n send(command: WsProtocolCommand): void {\n this.writeCommand(command);\n }\n\n private writeCommand(command: AppServerSendCommand): void {\n for (const handler of this.sendHandlers) {\n handler(command);\n }\n this.control.send(JSON.stringify(command));\n }\n\n /**\n * Send a forward-compatible protocol command from a compatibility adapter.\n * Prefer the typed wrappers above this boundary for normal product code.\n */\n sendRaw(command: AppServerRawCommand): void {\n this.writeCommand(command);\n }\n\n /**\n * Request a forward-compatible response without mirroring the full protocol\n * union in a downstream compatibility adapter.\n */\n requestRaw<TResponse extends AppServerRawResponse>(\n command: AppServerRawCommand & { request_id: string },\n options: AppServerRawRequestOptions<TResponse>,\n ): Promise<TResponse> {\n const timeoutMs = options.timeoutMs ?? this.requestTimeoutMs;\n return new Promise((resolve, reject) => {\n const timeout = setTimeout(() => {\n this.pending.delete(command.request_id);\n reject(new Error(`Timed out waiting for ${command.request_id}`));\n }, timeoutMs);\n\n this.pending.set(command.request_id, {\n resolve: (message) => resolve(message as unknown as TResponse),\n reject,\n predicate: options.predicate,\n timeout,\n });\n\n try {\n this.sendRaw(command);\n } catch (error) {\n clearTimeout(timeout);\n this.pending.delete(command.request_id);\n reject(error instanceof Error ? error : new Error(String(error)));\n }\n });\n }\n\n request<TMessage extends WsProtocolMessage = WsProtocolMessage>(\n command: AppServerRequestCommandWithId,\n options?: AppServerRequestOptions<TMessage>,\n ): Promise<TMessage>;\n\n request<\n TType extends AppServerRequestCommand[\"type\"],\n TMessage extends WsProtocolMessage = WsProtocolMessage,\n >(\n type: TType,\n body?: AppServerRequestBody,\n options?: AppServerRequestOptions<TMessage>,\n ): Promise<TMessage>;\n\n request<TMessage extends WsProtocolMessage = WsProtocolMessage>(\n commandOrType:\n | AppServerRequestCommandWithId\n | AppServerRequestCommand[\"type\"],\n bodyOrOptions:\n | AppServerRequestBody\n | AppServerRequestOptions<TMessage> = {},\n maybeOptions: AppServerRequestOptions<TMessage> = {},\n ): Promise<TMessage> {\n const isTypeRequest = typeof commandOrType === \"string\";\n const command = isTypeRequest\n ? ({\n type: commandOrType,\n request_id:\n (bodyOrOptions as { request_id?: string }).request_id ??\n this.nextRequestId(commandOrType),\n ...(bodyOrOptions as object),\n } as AppServerRequestCommandWithId)\n : commandOrType;\n const options = isTypeRequest\n ? maybeOptions\n : (bodyOrOptions as AppServerRequestOptions<TMessage>);\n const timeoutMs = options.timeoutMs ?? this.requestTimeoutMs;\n\n return new Promise((resolve, reject) => {\n const timeout = setTimeout(() => {\n this.pending.delete(command.request_id);\n reject(new Error(`Timed out waiting for ${command.request_id}`));\n }, timeoutMs);\n\n this.pending.set(command.request_id, {\n resolve: (message) => resolve(message as TMessage),\n reject,\n predicate: options.predicate,\n timeout,\n });\n\n try {\n this.send(command);\n } catch (error) {\n clearTimeout(timeout);\n this.pending.delete(command.request_id);\n reject(error instanceof Error ? error : new Error(String(error)));\n }\n });\n }\n\n info(\n options: Omit<\n AppServerRequestOptions<AppServerInfoResponseMessage>,\n \"predicate\"\n > = {},\n ): Promise<AppServerInfoResponseMessage> {\n return this.request(\n {\n type: \"app_server_info\",\n request_id: this.nextRequestId(\"app-server-info\"),\n },\n {\n ...options,\n predicate: isAppServerInfoResponseMessage,\n },\n );\n }\n\n runtimeStart(\n command: Omit<RuntimeStartCommand, \"type\" | \"request_id\"> & {\n request_id?: string;\n },\n options: Omit<\n AppServerRequestOptions<RuntimeStartResponseMessage>,\n \"predicate\"\n > = {},\n ): Promise<RuntimeStartResponseMessage> {\n return this.request(\n {\n type: \"runtime_start\",\n request_id: command.request_id ?? this.nextRequestId(\"runtime-start\"),\n ...command,\n },\n {\n ...options,\n predicate: (message): message is RuntimeStartResponseMessage =>\n message.type === \"runtime_start_response\",\n },\n );\n }\n\n sync(\n command: Omit<SyncCommand, \"type\" | \"request_id\"> & { request_id?: string },\n options: Omit<\n AppServerRequestOptions<SyncResponseMessage>,\n \"predicate\"\n > = {},\n ): Promise<SyncResponseMessage> {\n return this.request(\n {\n type: \"sync\",\n request_id: command.request_id ?? this.nextRequestId(\"sync\"),\n ...command,\n },\n {\n ...options,\n predicate: (message): message is SyncResponseMessage =>\n message.type === \"sync_response\",\n },\n );\n }\n\n abort(\n command: Omit<AbortMessageCommand, \"type\" | \"request_id\"> & {\n request_id?: string;\n },\n options: Omit<\n AppServerRequestOptions<AbortMessageResponseMessage>,\n \"predicate\"\n > = {},\n ): Promise<AbortMessageResponseMessage> {\n return this.request(\n {\n type: \"abort_message\",\n request_id: command.request_id ?? this.nextRequestId(\"abort\"),\n ...command,\n },\n {\n ...options,\n predicate: (message): message is AbortMessageResponseMessage =>\n message.type === \"abort_message_response\",\n },\n );\n }\n\n conversationList(\n command: Omit<ConversationListCommand, \"type\" | \"request_id\"> & {\n request_id?: string;\n } = {},\n options: Omit<\n AppServerRequestOptions<ConversationListResponseMessage>,\n \"predicate\"\n > = {},\n ): Promise<ConversationListResponseMessage> {\n return this.request(\n {\n type: \"conversation_list\",\n request_id:\n command.request_id ?? this.nextRequestId(\"conversation-list\"),\n ...command,\n },\n {\n ...options,\n predicate: (message): message is ConversationListResponseMessage =>\n message.type === \"conversation_list_response\",\n },\n );\n }\n\n onExternalToolCall(handler: AppServerExternalToolCallHandler): () => void {\n return this.onMessage((message, channel) => {\n if (\n channel !== \"control\" ||\n message.type !== \"external_tool_call_request\"\n ) {\n return;\n }\n\n void Promise.resolve(handler(message))\n .then((result) => {\n this.send({\n type: \"external_tool_call_response\",\n request_id: message.request_id,\n result,\n });\n })\n .catch((error) => {\n this.send({\n type: \"external_tool_call_response\",\n request_id: message.request_id,\n error: error instanceof Error ? error.message : String(error),\n });\n });\n });\n }\n\n input(command: Omit<InputCommand, \"type\">): void {\n this.send({ type: \"input\", ...command });\n }\n\n runTurn(\n command: Omit<InputCommand, \"type\">,\n options: AppServerRunTurnOptions = {},\n ): Promise<AppServerTurnResult> {\n const runtimeKey = `${command.runtime.agent_id}/${command.runtime.conversation_id}`;\n if (this.activeTurnRuntimes.has(runtimeKey)) {\n return Promise.reject(\n new Error(`A turn is already in flight for ${runtimeKey}`),\n );\n }\n this.activeTurnRuntimes.add(runtimeKey);\n const timeoutMs = options.timeoutMs ?? this.requestTimeoutMs;\n const commandWithIds = this.withClientMessageIds(command);\n const runIds = new Set<string>();\n let observedTurnEvidence = false;\n let observedRequiresApprovalStop = false;\n\n return new Promise((resolve, reject) => {\n const timeout = setTimeout(() => {\n cleanup();\n reject(\n new Error(\n `Timed out waiting for app-server turn on ${command.runtime.agent_id}/${command.runtime.conversation_id}`,\n ),\n );\n }, timeoutMs);\n\n const cleanup = () => {\n clearTimeout(timeout);\n this.activeTurnRuntimes.delete(runtimeKey);\n offMessage();\n };\n\n const finish = (\n completedBy: AppServerTurnCompletionSource,\n terminalMessage: WsProtocolMessage,\n stopReason: string | null,\n ) => {\n cleanup();\n resolve({\n runtime: command.runtime,\n stopReason,\n runIds: [...runIds],\n clientMessageIds: commandWithIds.clientMessageIds,\n completedBy,\n terminalMessage,\n });\n };\n\n const fail = (error: Error) => {\n cleanup();\n reject(error);\n };\n\n const offMessage = this.onMessage((message) => {\n if (\n !sameRuntime(\n (message as { runtime?: RuntimeScope }).runtime,\n command.runtime,\n )\n ) {\n return;\n }\n\n if (message.type === \"stream_delta\") {\n observedTurnEvidence = true;\n const runId = streamDeltaRunId(message);\n if (runId) runIds.add(runId);\n\n const messageType = streamDeltaMessageType(message);\n if (messageType === \"loop_error\" || messageType === \"error_message\") {\n fail(new Error(streamDeltaErrorMessage(message)));\n return;\n }\n if (messageType === \"stop_reason\") {\n const stopReason = streamDeltaStopReason(message);\n if (stopReason === \"requires_approval\") {\n observedRequiresApprovalStop = true;\n return;\n }\n finish(\"stop_reason\", message, stopReason);\n }\n return;\n }\n\n if (message.type === \"update_loop_status\") {\n const hadTurnEvidenceBeforeLoopStatus =\n observedTurnEvidence || observedRequiresApprovalStop;\n if (\n !hadTurnEvidenceBeforeLoopStatus &&\n (isWaitingOnApprovalLoopStatus(message) ||\n (options.allowLoopStatusFallback === true &&\n isWaitingLoopStatus(message)))\n ) {\n return;\n }\n for (const runId of message.loop_status.active_run_ids) {\n observedTurnEvidence = true;\n runIds.add(runId);\n }\n if (\n hadTurnEvidenceBeforeLoopStatus &&\n isWaitingOnApprovalLoopStatus(message)\n ) {\n finish(\n \"loop_status_waiting_on_approval\",\n message,\n \"requires_approval\",\n );\n return;\n }\n if (\n options.allowLoopStatusFallback === true &&\n hadTurnEvidenceBeforeLoopStatus &&\n isWaitingLoopStatus(message)\n ) {\n finish(\"loop_status_waiting_fallback\", message, null);\n }\n }\n });\n\n try {\n this.input(commandWithIds.command);\n } catch (error) {\n fail(error instanceof Error ? error : new Error(String(error)));\n }\n });\n }\n\n private withClientMessageIds(command: Omit<InputCommand, \"type\">): {\n command: Omit<InputCommand, \"type\">;\n clientMessageIds: string[];\n } {\n if (command.payload.kind !== \"create_message\") {\n return { command, clientMessageIds: [] };\n }\n\n const clientMessageIds: string[] = [];\n const messages = command.payload.messages.map((message) => {\n if (message.role !== \"user\") return message;\n const existing = (message as { client_message_id?: unknown })\n .client_message_id;\n const clientMessageId =\n typeof existing === \"string\" && existing.length > 0\n ? existing\n : this.nextRequestId(\"client-message\");\n clientMessageIds.push(clientMessageId);\n return { ...message, client_message_id: clientMessageId };\n });\n\n return {\n command: {\n ...command,\n payload: { ...command.payload, messages },\n },\n clientMessageIds,\n };\n }\n\n private handleMessage(event: unknown, channel: AppServerChannel): void {\n const message = parseProtocolMessage(event);\n\n for (const handler of this.messageHandlers) {\n handler(message, channel);\n }\n\n const requestId =\n message && typeof message === \"object\" && \"request_id\" in message\n ? (message as { request_id?: unknown }).request_id\n : undefined;\n if (channel !== \"control\" || typeof requestId !== \"string\") {\n return;\n }\n\n const pending = this.pending.get(requestId);\n if (!pending || (pending.predicate && !pending.predicate(message))) {\n return;\n }\n\n clearTimeout(pending.timeout);\n this.pending.delete(requestId);\n pending.resolve(message);\n }\n\n private rejectAllPending(reason: string): void {\n for (const [requestId, pending] of this.pending) {\n clearTimeout(pending.timeout);\n this.pending.delete(requestId);\n pending.reject(new Error(reason));\n }\n }\n\n private handleDisconnect(channel: AppServerChannel, event: unknown): void {\n this.rejectAllPending(\"App-server socket closed\");\n if (this.explicitlyClosed || this.disconnectNotified) return;\n this.disconnectNotified = true;\n for (const handler of this.disconnectHandlers) {\n handler({ channel, event });\n }\n }\n}\n\nexport function createAppServerClient(\n options: AppServerClientOptions,\n): AppServerClient {\n return new AppServerClient(options);\n}\n"
|
|
6
|
+
"import { isAppServerInfoResponseMessage } from \"./types/app-server-info\";\n\nexport type { AppServerInfoResponseMessage } from \"./types/app-server-info\";\nexport { isAppServerInfoResponseMessage } from \"./types/app-server-info\";\n\nimport type {\n AbortMessageCommand,\n AbortMessageResponseMessage,\n AppServerInfoResponseMessage,\n ConversationListCommand,\n ConversationListResponseMessage,\n ExternalToolCallRequestMessage,\n ExternalToolCallResult,\n InputCommand,\n LoopStatusUpdateMessage,\n RuntimeScope,\n RuntimeStartCommand,\n RuntimeStartResponseMessage,\n StreamDeltaMessage,\n SyncCommand,\n SyncResponseMessage,\n WsProtocolCommand,\n WsProtocolMessage,\n} from \"./types/app-server-protocol\";\n\nexport type AppServerChannel = \"control\" | \"stream\";\n\nexport type AppServerRawCommand = Record<string, unknown> & {\n type: string;\n request_id?: string;\n};\n\nexport type AppServerRawResponse = Record<string, unknown> & {\n type: string;\n request_id?: string;\n};\n\nexport type AppServerSendCommand = WsProtocolCommand | AppServerRawCommand;\n\n/** Receives every parsed protocol frame from the app-server WebSocket. */\nexport type AppServerMessageHandler = (\n message: WsProtocolMessage,\n channel: AppServerChannel,\n) => void;\n\n/** Called synchronously before a typed or raw command is written to the socket. */\nexport type AppServerSendHandler = (command: AppServerSendCommand) => void;\n\nexport interface AppServerDisconnectEvent {\n channel: AppServerChannel;\n event: unknown;\n}\n\n/** Called once when the WebSocket closes before client.close(). */\nexport type AppServerDisconnectHandler = (\n disconnect: AppServerDisconnectEvent,\n) => void;\n\nexport type AppServerExternalToolCallHandler = (\n request: ExternalToolCallRequestMessage,\n) => Promise<ExternalToolCallResult> | ExternalToolCallResult;\n\nexport interface AppServerSocketLike {\n readyState: number;\n send(data: string): void;\n close(): void;\n addEventListener?(type: string, listener: (event: unknown) => void): void;\n removeEventListener?(type: string, listener: (event: unknown) => void): void;\n on?(type: string, listener: (event: unknown) => void): void;\n off?(type: string, listener: (event: unknown) => void): void;\n once?(type: string, listener: (event: unknown) => void): void;\n}\n\nexport interface AppServerSocketOptions {\n headers?: Record<string, string>;\n}\n\nexport type AppServerSocketConstructor = new (\n url: string,\n options?: AppServerSocketOptions,\n) => AppServerSocketLike;\n\nexport interface AppServerClientOptions {\n /** Base app-server URL, e.g. ws://127.0.0.1:4500 or http://127.0.0.1:4500. */\n url: string;\n /** Optional capability token sent as Authorization: Bearer <token>; requires a WebSocket implementation with header support. */\n authToken?: string;\n /** Optional WebSocket constructor for Node/tests. Browsers use globalThis.WebSocket. */\n WebSocket?: AppServerSocketConstructor;\n /** Default timeout for request_id-correlated control requests. */\n requestTimeoutMs?: number;\n}\n\nexport interface AppServerRequestOptions<TMessage extends WsProtocolMessage> {\n timeoutMs?: number;\n predicate?: (message: WsProtocolMessage) => message is TMessage;\n}\n\nexport type AppServerRequestCommand = Extract<\n WsProtocolCommand,\n { request_id?: string }\n>;\n\nexport type AppServerRequestCommandWithId = AppServerRequestCommand & {\n request_id: string;\n};\n\nexport type AppServerRequestBody = Record<string, unknown> & {\n request_id?: string;\n};\n\nexport interface AppServerRawRequestOptions<\n TResponse extends AppServerRawResponse,\n> {\n timeoutMs?: number;\n predicate: (message: unknown) => message is TResponse;\n}\n\ntype PendingRequest = {\n resolve: (message: WsProtocolMessage) => void;\n reject: (error: Error) => void;\n predicate?: (message: WsProtocolMessage) => boolean;\n timeout: ReturnType<typeof setTimeout>;\n};\n\nexport type AppServerTurnCompletionSource =\n | \"stop_reason\"\n | \"loop_status_waiting_on_approval\"\n | \"loop_status_waiting_fallback\";\n\nexport interface AppServerTurnResult {\n runtime: RuntimeScope;\n stopReason: string | null;\n runIds: string[];\n clientMessageIds: string[];\n completedBy: AppServerTurnCompletionSource;\n terminalMessage: WsProtocolMessage;\n}\n\nexport interface AppServerRunTurnOptions {\n timeoutMs?: number;\n /**\n * Prefer explicit stream terminal events. This fallback is only used after\n * the client has seen stream/run evidence for this runtime, never from idle\n * loop status alone.\n */\n allowLoopStatusFallback?: boolean;\n}\n\nconst DEFAULT_REQUEST_TIMEOUT_MS = 30_000;\nconst WEBSOCKET_OPEN_STATE = 1;\n\nfunction getGlobalWebSocket(): AppServerSocketConstructor | undefined {\n return (globalThis as { WebSocket?: AppServerSocketConstructor }).WebSocket;\n}\n\nfunction normalizeBaseUrl(url: string): URL {\n const parsed = new URL(url);\n if (parsed.protocol === \"http:\") parsed.protocol = \"ws:\";\n if (parsed.protocol === \"https:\") parsed.protocol = \"wss:\";\n if (parsed.protocol !== \"ws:\" && parsed.protocol !== \"wss:\") {\n throw new Error(`Unsupported app-server URL protocol: ${parsed.protocol}`);\n }\n if (!parsed.pathname || parsed.pathname === \"/\") {\n parsed.pathname = \"/ws\";\n }\n return parsed;\n}\n\nexport function resolveAppServerUrl(url: string): string {\n const parsed = normalizeBaseUrl(url);\n parsed.searchParams.delete(\"channel\");\n return parsed.toString();\n}\n\n/**\n * @deprecated App-server uses one bidirectional WebSocket. Both historical\n * channel names resolve to that same socket URL.\n */\nexport function resolveAppServerChannelUrl(\n url: string,\n _channel: AppServerChannel,\n): string {\n return resolveAppServerUrl(url);\n}\n\nfunction attachSocketListener(\n socket: AppServerSocketLike,\n type: string,\n listener: (event: unknown) => void,\n): () => void {\n if (socket.addEventListener && socket.removeEventListener) {\n socket.addEventListener(type, listener);\n return () => socket.removeEventListener?.(type, listener);\n }\n\n if (socket.on) {\n socket.on(type, listener);\n return () => socket.off?.(type, listener);\n }\n\n throw new Error(\"WebSocket implementation does not support event listeners\");\n}\n\nfunction onceSocketEvent(\n socket: AppServerSocketLike,\n type: string,\n listener: (event: unknown) => void,\n): () => void {\n if (socket.once) {\n socket.once(type, listener);\n return () => socket.off?.(type, listener);\n }\n\n let detach = () => {};\n detach = attachSocketListener(socket, type, (event) => {\n detach();\n listener(event);\n });\n return detach;\n}\n\nfunction waitForSocketOpen(socket: AppServerSocketLike): Promise<void> {\n if (socket.readyState === WEBSOCKET_OPEN_STATE) {\n return Promise.resolve();\n }\n\n return new Promise((resolve, reject) => {\n let detachOpen = () => {};\n let detachError = () => {};\n const cleanup = () => {\n detachOpen();\n detachError();\n };\n detachOpen = onceSocketEvent(socket, \"open\", () => {\n cleanup();\n resolve();\n });\n detachError = onceSocketEvent(socket, \"error\", (event) => {\n cleanup();\n reject(\n new Error(`App-server WebSocket failed to open: ${String(event)}`),\n );\n });\n });\n}\n\nfunction rawEventData(event: unknown): unknown {\n if (event && typeof event === \"object\" && \"data\" in event) {\n return (event as { data: unknown }).data;\n }\n return event;\n}\n\nfunction messageDataToString(data: unknown): string {\n const raw = rawEventData(data);\n if (typeof raw === \"string\") return raw;\n if (raw instanceof ArrayBuffer) {\n return new TextDecoder().decode(raw);\n }\n if (raw instanceof Uint8Array) {\n return new TextDecoder().decode(raw);\n }\n if (ArrayBuffer.isView(raw)) {\n return new TextDecoder().decode(\n new Uint8Array(raw.buffer as ArrayBuffer, raw.byteOffset, raw.byteLength),\n );\n }\n return String(raw);\n}\n\nfunction parseProtocolMessage(event: unknown): WsProtocolMessage {\n return JSON.parse(messageDataToString(event)) as WsProtocolMessage;\n}\n\nfunction appServerSocketOptions(\n authToken: string | undefined,\n): AppServerSocketOptions | undefined {\n if (authToken === undefined) {\n return undefined;\n }\n const token = authToken.trim();\n if (!token) {\n throw new Error(\"app-server auth token must not be empty\");\n }\n return { headers: { Authorization: `Bearer ${token}` } };\n}\n\nfunction sameRuntime(a: RuntimeScope | undefined, b: RuntimeScope): boolean {\n return a?.agent_id === b.agent_id && a?.conversation_id === b.conversation_id;\n}\n\nfunction isWaitingLoopStatus(message: LoopStatusUpdateMessage): boolean {\n return message.loop_status.status === \"WAITING_ON_INPUT\";\n}\n\nfunction isWaitingOnApprovalLoopStatus(\n message: LoopStatusUpdateMessage,\n): boolean {\n return message.loop_status.status === \"WAITING_ON_APPROVAL\";\n}\n\nfunction streamDeltaRunId(message: StreamDeltaMessage): string | null {\n const runId = (message.delta as { run_id?: unknown }).run_id;\n return typeof runId === \"string\" ? runId : null;\n}\n\nfunction streamDeltaMessageType(message: StreamDeltaMessage): string | null {\n const messageType = (message.delta as { message_type?: unknown })\n .message_type;\n return typeof messageType === \"string\" ? messageType : null;\n}\n\nfunction streamDeltaStopReason(message: StreamDeltaMessage): string | null {\n const stopReason = (message.delta as { stop_reason?: unknown }).stop_reason;\n return typeof stopReason === \"string\" ? stopReason : null;\n}\n\nfunction streamDeltaErrorMessage(message: StreamDeltaMessage): string {\n const delta = message.delta as {\n message?: unknown;\n api_error?: { message?: unknown; detail?: unknown };\n };\n const apiMessage = delta.api_error?.message ?? delta.api_error?.detail;\n if (typeof apiMessage === \"string\" && apiMessage.length > 0)\n return apiMessage;\n if (typeof delta.message === \"string\" && delta.message.length > 0)\n return delta.message;\n return \"App-server turn failed\";\n}\n\nexport class AppServerClient {\n readonly socket: AppServerSocketLike;\n /** @deprecated Alias for socket. */\n readonly control: AppServerSocketLike;\n /** @deprecated Alias for socket; no second stream connection is created. */\n readonly stream: AppServerSocketLike;\n\n private readonly requestTimeoutMs: number;\n private readonly pending = new Map<string, PendingRequest>();\n private readonly messageHandlers = new Set<AppServerMessageHandler>();\n private readonly sendHandlers = new Set<AppServerSendHandler>();\n private readonly disconnectHandlers = new Set<AppServerDisconnectHandler>();\n private readonly activeTurnRuntimes = new Set<string>();\n private explicitlyClosed = false;\n private disconnectNotified = false;\n private nextRequestNumber = 0;\n\n constructor(options: AppServerClientOptions) {\n const WebSocket = options.WebSocket ?? getGlobalWebSocket();\n if (!WebSocket) {\n throw new Error(\"No WebSocket implementation available\");\n }\n\n this.requestTimeoutMs =\n options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;\n const socketOptions = appServerSocketOptions(options.authToken);\n this.socket = new WebSocket(\n resolveAppServerUrl(options.url),\n socketOptions,\n );\n this.control = this.socket;\n this.stream = this.socket;\n\n attachSocketListener(this.socket, \"message\", (event) => {\n this.handleMessage(event, \"control\");\n });\n attachSocketListener(this.socket, \"close\", (event) => {\n this.handleDisconnect(\"control\", event);\n });\n }\n\n async connect(): Promise<this> {\n await waitForSocketOpen(this.socket);\n return this;\n }\n\n close(): void {\n if (this.explicitlyClosed) return;\n this.explicitlyClosed = true;\n this.rejectAllPending(\"App-server client closed\");\n this.socket.close();\n }\n\n onMessage(handler: AppServerMessageHandler): () => void {\n this.messageHandlers.add(handler);\n return () => this.messageHandlers.delete(handler);\n }\n\n onSend(handler: AppServerSendHandler): () => void {\n this.sendHandlers.add(handler);\n return () => this.sendHandlers.delete(handler);\n }\n\n onDisconnect(handler: AppServerDisconnectHandler): () => void {\n this.disconnectHandlers.add(handler);\n return () => this.disconnectHandlers.delete(handler);\n }\n\n nextRequestId(prefix = \"req\"): string {\n this.nextRequestNumber += 1;\n return `${prefix}-${this.nextRequestNumber}`;\n }\n\n send(command: WsProtocolCommand): void {\n this.writeCommand(command);\n }\n\n private writeCommand(command: AppServerSendCommand): void {\n for (const handler of this.sendHandlers) {\n handler(command);\n }\n this.socket.send(JSON.stringify(command));\n }\n\n /**\n * Send a forward-compatible protocol command from a compatibility adapter.\n * Prefer the typed wrappers above this boundary for normal product code.\n */\n sendRaw(command: AppServerRawCommand): void {\n this.writeCommand(command);\n }\n\n /**\n * Request a forward-compatible response without mirroring the full protocol\n * union in a downstream compatibility adapter.\n */\n requestRaw<TResponse extends AppServerRawResponse>(\n command: AppServerRawCommand & { request_id: string },\n options: AppServerRawRequestOptions<TResponse>,\n ): Promise<TResponse> {\n const timeoutMs = options.timeoutMs ?? this.requestTimeoutMs;\n return new Promise((resolve, reject) => {\n const timeout = setTimeout(() => {\n this.pending.delete(command.request_id);\n reject(new Error(`Timed out waiting for ${command.request_id}`));\n }, timeoutMs);\n\n this.pending.set(command.request_id, {\n resolve: (message) => resolve(message as unknown as TResponse),\n reject,\n predicate: options.predicate,\n timeout,\n });\n\n try {\n this.sendRaw(command);\n } catch (error) {\n clearTimeout(timeout);\n this.pending.delete(command.request_id);\n reject(error instanceof Error ? error : new Error(String(error)));\n }\n });\n }\n\n request<TMessage extends WsProtocolMessage = WsProtocolMessage>(\n command: AppServerRequestCommandWithId,\n options?: AppServerRequestOptions<TMessage>,\n ): Promise<TMessage>;\n\n request<\n TType extends AppServerRequestCommand[\"type\"],\n TMessage extends WsProtocolMessage = WsProtocolMessage,\n >(\n type: TType,\n body?: AppServerRequestBody,\n options?: AppServerRequestOptions<TMessage>,\n ): Promise<TMessage>;\n\n request<TMessage extends WsProtocolMessage = WsProtocolMessage>(\n commandOrType:\n | AppServerRequestCommandWithId\n | AppServerRequestCommand[\"type\"],\n bodyOrOptions:\n | AppServerRequestBody\n | AppServerRequestOptions<TMessage> = {},\n maybeOptions: AppServerRequestOptions<TMessage> = {},\n ): Promise<TMessage> {\n const isTypeRequest = typeof commandOrType === \"string\";\n const command = isTypeRequest\n ? ({\n type: commandOrType,\n request_id:\n (bodyOrOptions as { request_id?: string }).request_id ??\n this.nextRequestId(commandOrType),\n ...(bodyOrOptions as object),\n } as AppServerRequestCommandWithId)\n : commandOrType;\n const options = isTypeRequest\n ? maybeOptions\n : (bodyOrOptions as AppServerRequestOptions<TMessage>);\n const timeoutMs = options.timeoutMs ?? this.requestTimeoutMs;\n\n return new Promise((resolve, reject) => {\n const timeout = setTimeout(() => {\n this.pending.delete(command.request_id);\n reject(new Error(`Timed out waiting for ${command.request_id}`));\n }, timeoutMs);\n\n this.pending.set(command.request_id, {\n resolve: (message) => resolve(message as TMessage),\n reject,\n predicate: options.predicate,\n timeout,\n });\n\n try {\n this.send(command);\n } catch (error) {\n clearTimeout(timeout);\n this.pending.delete(command.request_id);\n reject(error instanceof Error ? error : new Error(String(error)));\n }\n });\n }\n\n info(\n options: Omit<\n AppServerRequestOptions<AppServerInfoResponseMessage>,\n \"predicate\"\n > = {},\n ): Promise<AppServerInfoResponseMessage> {\n return this.request(\n {\n type: \"app_server_info\",\n request_id: this.nextRequestId(\"app-server-info\"),\n },\n {\n ...options,\n predicate: isAppServerInfoResponseMessage,\n },\n );\n }\n\n runtimeStart(\n command: Omit<RuntimeStartCommand, \"type\" | \"request_id\"> & {\n request_id?: string;\n },\n options: Omit<\n AppServerRequestOptions<RuntimeStartResponseMessage>,\n \"predicate\"\n > = {},\n ): Promise<RuntimeStartResponseMessage> {\n return this.request(\n {\n type: \"runtime_start\",\n request_id: command.request_id ?? this.nextRequestId(\"runtime-start\"),\n ...command,\n },\n {\n ...options,\n predicate: (message): message is RuntimeStartResponseMessage =>\n message.type === \"runtime_start_response\",\n },\n );\n }\n\n sync(\n command: Omit<SyncCommand, \"type\" | \"request_id\"> & { request_id?: string },\n options: Omit<\n AppServerRequestOptions<SyncResponseMessage>,\n \"predicate\"\n > = {},\n ): Promise<SyncResponseMessage> {\n return this.request(\n {\n type: \"sync\",\n request_id: command.request_id ?? this.nextRequestId(\"sync\"),\n ...command,\n },\n {\n ...options,\n predicate: (message): message is SyncResponseMessage =>\n message.type === \"sync_response\",\n },\n );\n }\n\n abort(\n command: Omit<AbortMessageCommand, \"type\" | \"request_id\"> & {\n request_id?: string;\n },\n options: Omit<\n AppServerRequestOptions<AbortMessageResponseMessage>,\n \"predicate\"\n > = {},\n ): Promise<AbortMessageResponseMessage> {\n return this.request(\n {\n type: \"abort_message\",\n request_id: command.request_id ?? this.nextRequestId(\"abort\"),\n ...command,\n },\n {\n ...options,\n predicate: (message): message is AbortMessageResponseMessage =>\n message.type === \"abort_message_response\",\n },\n );\n }\n\n conversationList(\n command: Omit<ConversationListCommand, \"type\" | \"request_id\"> & {\n request_id?: string;\n } = {},\n options: Omit<\n AppServerRequestOptions<ConversationListResponseMessage>,\n \"predicate\"\n > = {},\n ): Promise<ConversationListResponseMessage> {\n return this.request(\n {\n type: \"conversation_list\",\n request_id:\n command.request_id ?? this.nextRequestId(\"conversation-list\"),\n ...command,\n },\n {\n ...options,\n predicate: (message): message is ConversationListResponseMessage =>\n message.type === \"conversation_list_response\",\n },\n );\n }\n\n onExternalToolCall(handler: AppServerExternalToolCallHandler): () => void {\n return this.onMessage((message, channel) => {\n if (\n channel !== \"control\" ||\n message.type !== \"external_tool_call_request\"\n ) {\n return;\n }\n\n void Promise.resolve(handler(message))\n .then((result) => {\n this.send({\n type: \"external_tool_call_response\",\n request_id: message.request_id,\n result,\n });\n })\n .catch((error) => {\n this.send({\n type: \"external_tool_call_response\",\n request_id: message.request_id,\n error: error instanceof Error ? error.message : String(error),\n });\n });\n });\n }\n\n input(command: Omit<InputCommand, \"type\">): void {\n this.send({ type: \"input\", ...command });\n }\n\n runTurn(\n command: Omit<InputCommand, \"type\">,\n options: AppServerRunTurnOptions = {},\n ): Promise<AppServerTurnResult> {\n const runtimeKey = `${command.runtime.agent_id}/${command.runtime.conversation_id}`;\n if (this.activeTurnRuntimes.has(runtimeKey)) {\n return Promise.reject(\n new Error(`A turn is already in flight for ${runtimeKey}`),\n );\n }\n this.activeTurnRuntimes.add(runtimeKey);\n const timeoutMs = options.timeoutMs ?? this.requestTimeoutMs;\n const commandWithIds = this.withClientMessageIds(command);\n const runIds = new Set<string>();\n let observedTurnEvidence = false;\n let observedRequiresApprovalStop = false;\n\n return new Promise((resolve, reject) => {\n const timeout = setTimeout(() => {\n cleanup();\n reject(\n new Error(\n `Timed out waiting for app-server turn on ${command.runtime.agent_id}/${command.runtime.conversation_id}`,\n ),\n );\n }, timeoutMs);\n\n const cleanup = () => {\n clearTimeout(timeout);\n this.activeTurnRuntimes.delete(runtimeKey);\n offMessage();\n };\n\n const finish = (\n completedBy: AppServerTurnCompletionSource,\n terminalMessage: WsProtocolMessage,\n stopReason: string | null,\n ) => {\n cleanup();\n resolve({\n runtime: command.runtime,\n stopReason,\n runIds: [...runIds],\n clientMessageIds: commandWithIds.clientMessageIds,\n completedBy,\n terminalMessage,\n });\n };\n\n const fail = (error: Error) => {\n cleanup();\n reject(error);\n };\n\n const offMessage = this.onMessage((message) => {\n if (\n !sameRuntime(\n (message as { runtime?: RuntimeScope }).runtime,\n command.runtime,\n )\n ) {\n return;\n }\n\n if (message.type === \"stream_delta\") {\n observedTurnEvidence = true;\n const runId = streamDeltaRunId(message);\n if (runId) runIds.add(runId);\n\n const messageType = streamDeltaMessageType(message);\n if (messageType === \"loop_error\" || messageType === \"error_message\") {\n fail(new Error(streamDeltaErrorMessage(message)));\n return;\n }\n if (messageType === \"stop_reason\") {\n const stopReason = streamDeltaStopReason(message);\n if (stopReason === \"requires_approval\") {\n observedRequiresApprovalStop = true;\n return;\n }\n finish(\"stop_reason\", message, stopReason);\n }\n return;\n }\n\n if (message.type === \"update_loop_status\") {\n const hadTurnEvidenceBeforeLoopStatus =\n observedTurnEvidence || observedRequiresApprovalStop;\n if (\n !hadTurnEvidenceBeforeLoopStatus &&\n (isWaitingOnApprovalLoopStatus(message) ||\n (options.allowLoopStatusFallback === true &&\n isWaitingLoopStatus(message)))\n ) {\n return;\n }\n for (const runId of message.loop_status.active_run_ids) {\n observedTurnEvidence = true;\n runIds.add(runId);\n }\n if (\n hadTurnEvidenceBeforeLoopStatus &&\n isWaitingOnApprovalLoopStatus(message)\n ) {\n finish(\n \"loop_status_waiting_on_approval\",\n message,\n \"requires_approval\",\n );\n return;\n }\n if (\n options.allowLoopStatusFallback === true &&\n hadTurnEvidenceBeforeLoopStatus &&\n isWaitingLoopStatus(message)\n ) {\n finish(\"loop_status_waiting_fallback\", message, null);\n }\n }\n });\n\n try {\n this.input(commandWithIds.command);\n } catch (error) {\n fail(error instanceof Error ? error : new Error(String(error)));\n }\n });\n }\n\n private withClientMessageIds(command: Omit<InputCommand, \"type\">): {\n command: Omit<InputCommand, \"type\">;\n clientMessageIds: string[];\n } {\n if (command.payload.kind !== \"create_message\") {\n return { command, clientMessageIds: [] };\n }\n\n const clientMessageIds: string[] = [];\n const messages = command.payload.messages.map((message) => {\n if (message.role !== \"user\") return message;\n const existing = (message as { client_message_id?: unknown })\n .client_message_id;\n const clientMessageId =\n typeof existing === \"string\" && existing.length > 0\n ? existing\n : this.nextRequestId(\"client-message\");\n clientMessageIds.push(clientMessageId);\n return { ...message, client_message_id: clientMessageId };\n });\n\n return {\n command: {\n ...command,\n payload: { ...command.payload, messages },\n },\n clientMessageIds,\n };\n }\n\n private handleMessage(event: unknown, channel: AppServerChannel): void {\n const message = parseProtocolMessage(event);\n\n for (const handler of this.messageHandlers) {\n handler(message, channel);\n }\n\n const requestId =\n message && typeof message === \"object\" && \"request_id\" in message\n ? (message as { request_id?: unknown }).request_id\n : undefined;\n if (channel !== \"control\" || typeof requestId !== \"string\") {\n return;\n }\n\n const pending = this.pending.get(requestId);\n if (!pending || (pending.predicate && !pending.predicate(message))) {\n return;\n }\n\n clearTimeout(pending.timeout);\n this.pending.delete(requestId);\n pending.resolve(message);\n }\n\n private rejectAllPending(reason: string): void {\n for (const [requestId, pending] of this.pending) {\n clearTimeout(pending.timeout);\n this.pending.delete(requestId);\n pending.reject(new Error(reason));\n }\n }\n\n private handleDisconnect(channel: AppServerChannel, event: unknown): void {\n this.rejectAllPending(\"App-server socket closed\");\n if (this.explicitlyClosed || this.disconnectNotified) return;\n this.disconnectNotified = true;\n for (const handler of this.disconnectHandlers) {\n handler({ channel, event });\n }\n }\n}\n\nexport function createAppServerClient(\n options: AppServerClientOptions,\n): AppServ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ClC;AAAA;AAAA,EAGM,gBAAgB,CAAC,SAA2B,OAAsB;AAAA,IACxE,KAAK,iBAAiB,0BAA0B;AAAA,IAChD,IAAI,KAAK,oBAAoB,KAAK;AAAA,MAAoB;AAAA,IACtD,KAAK,qBAAqB;AAAA,IAC1B,WAAW,WAAW,KAAK,oBAAoB;AAAA,MAC7C,QAAQ,EAAE,SAAS,MAAM,CAAC;AAAA,IAC5B;AAAA;AAEJ;AAEO,SAAS,qBAAqB,CACnC,SACiB;AAAA,EACjB,OAAO,IAAI,gBAAgB,OAAO;AAAA;",
|
|
9
|
+
"debugId": "6A8C34B21871B15E64756E2164756E21",
|
|
10
10
|
"names": []
|
|
11
11
|
}
|
|
@@ -32,11 +32,14 @@ function normalizeBaseUrl(url) {
|
|
|
32
32
|
}
|
|
33
33
|
return parsed;
|
|
34
34
|
}
|
|
35
|
-
function
|
|
35
|
+
function resolveAppServerUrl(url) {
|
|
36
36
|
const parsed = normalizeBaseUrl(url);
|
|
37
|
-
parsed.searchParams.
|
|
37
|
+
parsed.searchParams.delete("channel");
|
|
38
38
|
return parsed.toString();
|
|
39
39
|
}
|
|
40
|
+
function resolveAppServerChannelUrl(url, _channel) {
|
|
41
|
+
return resolveAppServerUrl(url);
|
|
42
|
+
}
|
|
40
43
|
function attachSocketListener(socket, type, listener) {
|
|
41
44
|
if (socket.addEventListener && socket.removeEventListener) {
|
|
42
45
|
socket.addEventListener(type, listener);
|
|
@@ -147,6 +150,7 @@ function streamDeltaErrorMessage(message) {
|
|
|
147
150
|
}
|
|
148
151
|
|
|
149
152
|
class AppServerClient {
|
|
153
|
+
socket;
|
|
150
154
|
control;
|
|
151
155
|
stream;
|
|
152
156
|
requestTimeoutMs;
|
|
@@ -165,26 +169,18 @@ class AppServerClient {
|
|
|
165
169
|
}
|
|
166
170
|
this.requestTimeoutMs = options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
|
|
167
171
|
const socketOptions = appServerSocketOptions(options.authToken);
|
|
168
|
-
this.
|
|
169
|
-
this.
|
|
170
|
-
|
|
172
|
+
this.socket = new WebSocket(resolveAppServerUrl(options.url), socketOptions);
|
|
173
|
+
this.control = this.socket;
|
|
174
|
+
this.stream = this.socket;
|
|
175
|
+
attachSocketListener(this.socket, "message", (event) => {
|
|
171
176
|
this.handleMessage(event, "control");
|
|
172
177
|
});
|
|
173
|
-
attachSocketListener(this.
|
|
174
|
-
this.handleMessage(event, "stream");
|
|
175
|
-
});
|
|
176
|
-
attachSocketListener(this.control, "close", (event) => {
|
|
178
|
+
attachSocketListener(this.socket, "close", (event) => {
|
|
177
179
|
this.handleDisconnect("control", event);
|
|
178
180
|
});
|
|
179
|
-
attachSocketListener(this.stream, "close", (event) => {
|
|
180
|
-
this.handleDisconnect("stream", event);
|
|
181
|
-
});
|
|
182
181
|
}
|
|
183
182
|
async connect() {
|
|
184
|
-
await
|
|
185
|
-
waitForSocketOpen(this.control),
|
|
186
|
-
waitForSocketOpen(this.stream)
|
|
187
|
-
]);
|
|
183
|
+
await waitForSocketOpen(this.socket);
|
|
188
184
|
return this;
|
|
189
185
|
}
|
|
190
186
|
close() {
|
|
@@ -192,8 +188,7 @@ class AppServerClient {
|
|
|
192
188
|
return;
|
|
193
189
|
this.explicitlyClosed = true;
|
|
194
190
|
this.rejectAllPending("App-server client closed");
|
|
195
|
-
this.
|
|
196
|
-
this.stream.close();
|
|
191
|
+
this.socket.close();
|
|
197
192
|
}
|
|
198
193
|
onMessage(handler) {
|
|
199
194
|
this.messageHandlers.add(handler);
|
|
@@ -218,7 +213,7 @@ class AppServerClient {
|
|
|
218
213
|
for (const handler of this.sendHandlers) {
|
|
219
214
|
handler(command);
|
|
220
215
|
}
|
|
221
|
-
this.
|
|
216
|
+
this.socket.send(JSON.stringify(command));
|
|
222
217
|
}
|
|
223
218
|
sendRaw(command) {
|
|
224
219
|
this.writeCommand(command);
|
|
@@ -490,10 +485,11 @@ function createAppServerClient(options) {
|
|
|
490
485
|
return new AppServerClient(options);
|
|
491
486
|
}
|
|
492
487
|
export {
|
|
488
|
+
resolveAppServerUrl,
|
|
493
489
|
resolveAppServerChannelUrl,
|
|
494
490
|
isAppServerInfoResponseMessage,
|
|
495
491
|
createAppServerClient,
|
|
496
492
|
AppServerClient
|
|
497
493
|
};
|
|
498
494
|
|
|
499
|
-
//# debugId=
|
|
495
|
+
//# debugId=EE19AA1F1A0B059C64756E2164756E21
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
"sources": ["../src/types/app-server-info.ts", "../src/app-server-client.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"export const APP_SERVER_PROTOCOL_VERSION = 1;\n\nexport interface AppServerInfoCommand {\n type: \"app_server_info\";\n /** Echoed back in the response for request correlation. */\n request_id: string;\n}\n\nexport interface AppServerInfoResponseMessage {\n type: \"app_server_info_response\";\n request_id: string;\n /** Synchronous post-auth capability discovery has no domain failure variant. */\n success: true;\n backend: \"local\" | \"api\";\n letta_code_version: string;\n /** Wire value reported by the server; clients compare it with their supported version. */\n protocol_version: number;\n capabilities: {\n agent_management: boolean;\n conversation_management: boolean;\n memory_management: boolean;\n runtime_start: boolean;\n split_channels: boolean;\n };\n}\n\nexport function isAppServerInfoResponseMessage(\n message: unknown,\n): message is AppServerInfoResponseMessage {\n if (!message || typeof message !== \"object\" || Array.isArray(message)) {\n return false;\n }\n\n const candidate = message as Record<string, unknown>;\n const capabilities = candidate.capabilities;\n if (\n !capabilities ||\n typeof capabilities !== \"object\" ||\n Array.isArray(capabilities)\n ) {\n return false;\n }\n\n const capabilityRecord = capabilities as Record<string, unknown>;\n return (\n candidate.type === \"app_server_info_response\" &&\n typeof candidate.request_id === \"string\" &&\n candidate.request_id.length > 0 &&\n candidate.success === true &&\n (candidate.backend === \"local\" || candidate.backend === \"api\") &&\n typeof candidate.letta_code_version === \"string\" &&\n typeof candidate.protocol_version === \"number\" &&\n Number.isInteger(candidate.protocol_version) &&\n typeof capabilityRecord.agent_management === \"boolean\" &&\n typeof capabilityRecord.conversation_management === \"boolean\" &&\n typeof capabilityRecord.memory_management === \"boolean\" &&\n typeof capabilityRecord.runtime_start === \"boolean\" &&\n typeof capabilityRecord.split_channels === \"boolean\"\n );\n}\n",
|
|
6
|
-
"import { isAppServerInfoResponseMessage } from \"./types/app-server-info\";\n\nexport type { AppServerInfoResponseMessage } from \"./types/app-server-info\";\nexport { isAppServerInfoResponseMessage } from \"./types/app-server-info\";\n\nimport type {\n AbortMessageCommand,\n AbortMessageResponseMessage,\n AppServerInfoResponseMessage,\n ConversationListCommand,\n ConversationListResponseMessage,\n ExternalToolCallRequestMessage,\n ExternalToolCallResult,\n InputCommand,\n LoopStatusUpdateMessage,\n RuntimeScope,\n RuntimeStartCommand,\n RuntimeStartResponseMessage,\n StreamDeltaMessage,\n SyncCommand,\n SyncResponseMessage,\n WsProtocolCommand,\n WsProtocolMessage,\n} from \"./types/app-server-protocol\";\n\nexport type AppServerChannel = \"control\" | \"stream\";\n\nexport type AppServerRawCommand = Record<string, unknown> & {\n type: string;\n request_id?: string;\n};\n\nexport type AppServerRawResponse = Record<string, unknown> & {\n type: string;\n request_id?: string;\n};\n\nexport type AppServerSendCommand = WsProtocolCommand | AppServerRawCommand;\n\n/**\n * Receives every parsed protocol frame from both app-server websocket channels.\n * Treat this as the primary event stream: app-server may emit replay or turn\n * updates on the same channel that sent the triggering command, not only on the\n * stream channel. The channel argument is diagnostic/routing context.\n */\nexport type AppServerMessageHandler = (\n message: WsProtocolMessage,\n channel: AppServerChannel,\n) => void;\n\n/** Called synchronously before a typed or raw command is written to the control socket. */\nexport type AppServerSendHandler = (command: AppServerSendCommand) => void;\n\nexport interface AppServerDisconnectEvent {\n channel: AppServerChannel;\n event: unknown;\n}\n\n/** Called once when either websocket closes before client.close(). */\nexport type AppServerDisconnectHandler = (\n disconnect: AppServerDisconnectEvent,\n) => void;\n\nexport type AppServerExternalToolCallHandler = (\n request: ExternalToolCallRequestMessage,\n) => Promise<ExternalToolCallResult> | ExternalToolCallResult;\n\nexport interface AppServerSocketLike {\n readyState: number;\n send(data: string): void;\n close(): void;\n addEventListener?(type: string, listener: (event: unknown) => void): void;\n removeEventListener?(type: string, listener: (event: unknown) => void): void;\n on?(type: string, listener: (event: unknown) => void): void;\n off?(type: string, listener: (event: unknown) => void): void;\n once?(type: string, listener: (event: unknown) => void): void;\n}\n\nexport interface AppServerSocketOptions {\n headers?: Record<string, string>;\n}\n\nexport type AppServerSocketConstructor = new (\n url: string,\n options?: AppServerSocketOptions,\n) => AppServerSocketLike;\n\nexport interface AppServerClientOptions {\n /** Base app-server URL, e.g. ws://127.0.0.1:4500 or http://127.0.0.1:4500. */\n url: string;\n /** Optional capability token sent as Authorization: Bearer <token>; requires a WebSocket implementation with header support. */\n authToken?: string;\n /** Optional WebSocket constructor for Node/tests. Browsers use globalThis.WebSocket. */\n WebSocket?: AppServerSocketConstructor;\n /** Default timeout for request_id-correlated control requests. */\n requestTimeoutMs?: number;\n}\n\nexport interface AppServerRequestOptions<TMessage extends WsProtocolMessage> {\n timeoutMs?: number;\n predicate?: (message: WsProtocolMessage) => message is TMessage;\n}\n\nexport type AppServerRequestCommand = Extract<\n WsProtocolCommand,\n { request_id?: string }\n>;\n\nexport type AppServerRequestCommandWithId = AppServerRequestCommand & {\n request_id: string;\n};\n\nexport type AppServerRequestBody = Record<string, unknown> & {\n request_id?: string;\n};\n\nexport interface AppServerRawRequestOptions<\n TResponse extends AppServerRawResponse,\n> {\n timeoutMs?: number;\n predicate: (message: unknown) => message is TResponse;\n}\n\ntype PendingRequest = {\n resolve: (message: WsProtocolMessage) => void;\n reject: (error: Error) => void;\n predicate?: (message: WsProtocolMessage) => boolean;\n timeout: ReturnType<typeof setTimeout>;\n};\n\nexport type AppServerTurnCompletionSource =\n | \"stop_reason\"\n | \"loop_status_waiting_on_approval\"\n | \"loop_status_waiting_fallback\";\n\nexport interface AppServerTurnResult {\n runtime: RuntimeScope;\n stopReason: string | null;\n runIds: string[];\n clientMessageIds: string[];\n completedBy: AppServerTurnCompletionSource;\n terminalMessage: WsProtocolMessage;\n}\n\nexport interface AppServerRunTurnOptions {\n timeoutMs?: number;\n /**\n * Prefer explicit stream terminal events. This fallback is only used after\n * the client has seen stream/run evidence for this runtime, never from idle\n * loop status alone.\n */\n allowLoopStatusFallback?: boolean;\n}\n\nconst DEFAULT_REQUEST_TIMEOUT_MS = 30_000;\nconst WEBSOCKET_OPEN_STATE = 1;\n\nfunction getGlobalWebSocket(): AppServerSocketConstructor | undefined {\n return (globalThis as { WebSocket?: AppServerSocketConstructor }).WebSocket;\n}\n\nfunction normalizeBaseUrl(url: string): URL {\n const parsed = new URL(url);\n if (parsed.protocol === \"http:\") parsed.protocol = \"ws:\";\n if (parsed.protocol === \"https:\") parsed.protocol = \"wss:\";\n if (parsed.protocol !== \"ws:\" && parsed.protocol !== \"wss:\") {\n throw new Error(`Unsupported app-server URL protocol: ${parsed.protocol}`);\n }\n if (!parsed.pathname || parsed.pathname === \"/\") {\n parsed.pathname = \"/ws\";\n }\n return parsed;\n}\n\nexport function resolveAppServerChannelUrl(\n url: string,\n channel: AppServerChannel,\n): string {\n const parsed = normalizeBaseUrl(url);\n parsed.searchParams.set(\"channel\", channel);\n return parsed.toString();\n}\n\nfunction attachSocketListener(\n socket: AppServerSocketLike,\n type: string,\n listener: (event: unknown) => void,\n): () => void {\n if (socket.addEventListener && socket.removeEventListener) {\n socket.addEventListener(type, listener);\n return () => socket.removeEventListener?.(type, listener);\n }\n\n if (socket.on) {\n socket.on(type, listener);\n return () => socket.off?.(type, listener);\n }\n\n throw new Error(\"WebSocket implementation does not support event listeners\");\n}\n\nfunction onceSocketEvent(\n socket: AppServerSocketLike,\n type: string,\n listener: (event: unknown) => void,\n): () => void {\n if (socket.once) {\n socket.once(type, listener);\n return () => socket.off?.(type, listener);\n }\n\n let detach = () => {};\n detach = attachSocketListener(socket, type, (event) => {\n detach();\n listener(event);\n });\n return detach;\n}\n\nfunction waitForSocketOpen(socket: AppServerSocketLike): Promise<void> {\n if (socket.readyState === WEBSOCKET_OPEN_STATE) {\n return Promise.resolve();\n }\n\n return new Promise((resolve, reject) => {\n let detachOpen = () => {};\n let detachError = () => {};\n const cleanup = () => {\n detachOpen();\n detachError();\n };\n detachOpen = onceSocketEvent(socket, \"open\", () => {\n cleanup();\n resolve();\n });\n detachError = onceSocketEvent(socket, \"error\", (event) => {\n cleanup();\n reject(\n new Error(`App-server WebSocket failed to open: ${String(event)}`),\n );\n });\n });\n}\n\nfunction rawEventData(event: unknown): unknown {\n if (event && typeof event === \"object\" && \"data\" in event) {\n return (event as { data: unknown }).data;\n }\n return event;\n}\n\nfunction messageDataToString(data: unknown): string {\n const raw = rawEventData(data);\n if (typeof raw === \"string\") return raw;\n if (raw instanceof ArrayBuffer) {\n return new TextDecoder().decode(raw);\n }\n if (raw instanceof Uint8Array) {\n return new TextDecoder().decode(raw);\n }\n if (ArrayBuffer.isView(raw)) {\n return new TextDecoder().decode(\n new Uint8Array(raw.buffer as ArrayBuffer, raw.byteOffset, raw.byteLength),\n );\n }\n return String(raw);\n}\n\nfunction parseProtocolMessage(event: unknown): WsProtocolMessage {\n return JSON.parse(messageDataToString(event)) as WsProtocolMessage;\n}\n\nfunction appServerSocketOptions(\n authToken: string | undefined,\n): AppServerSocketOptions | undefined {\n if (authToken === undefined) {\n return undefined;\n }\n const token = authToken.trim();\n if (!token) {\n throw new Error(\"app-server auth token must not be empty\");\n }\n return { headers: { Authorization: `Bearer ${token}` } };\n}\n\nfunction sameRuntime(a: RuntimeScope | undefined, b: RuntimeScope): boolean {\n return a?.agent_id === b.agent_id && a?.conversation_id === b.conversation_id;\n}\n\nfunction isWaitingLoopStatus(message: LoopStatusUpdateMessage): boolean {\n return message.loop_status.status === \"WAITING_ON_INPUT\";\n}\n\nfunction isWaitingOnApprovalLoopStatus(\n message: LoopStatusUpdateMessage,\n): boolean {\n return message.loop_status.status === \"WAITING_ON_APPROVAL\";\n}\n\nfunction streamDeltaRunId(message: StreamDeltaMessage): string | null {\n const runId = (message.delta as { run_id?: unknown }).run_id;\n return typeof runId === \"string\" ? runId : null;\n}\n\nfunction streamDeltaMessageType(message: StreamDeltaMessage): string | null {\n const messageType = (message.delta as { message_type?: unknown })\n .message_type;\n return typeof messageType === \"string\" ? messageType : null;\n}\n\nfunction streamDeltaStopReason(message: StreamDeltaMessage): string | null {\n const stopReason = (message.delta as { stop_reason?: unknown }).stop_reason;\n return typeof stopReason === \"string\" ? stopReason : null;\n}\n\nfunction streamDeltaErrorMessage(message: StreamDeltaMessage): string {\n const delta = message.delta as {\n message?: unknown;\n api_error?: { message?: unknown; detail?: unknown };\n };\n const apiMessage = delta.api_error?.message ?? delta.api_error?.detail;\n if (typeof apiMessage === \"string\" && apiMessage.length > 0)\n return apiMessage;\n if (typeof delta.message === \"string\" && delta.message.length > 0)\n return delta.message;\n return \"App-server turn failed\";\n}\n\nexport class AppServerClient {\n readonly control: AppServerSocketLike;\n readonly stream: AppServerSocketLike;\n\n private readonly requestTimeoutMs: number;\n private readonly pending = new Map<string, PendingRequest>();\n private readonly messageHandlers = new Set<AppServerMessageHandler>();\n private readonly sendHandlers = new Set<AppServerSendHandler>();\n private readonly disconnectHandlers = new Set<AppServerDisconnectHandler>();\n private readonly activeTurnRuntimes = new Set<string>();\n private explicitlyClosed = false;\n private disconnectNotified = false;\n private nextRequestNumber = 0;\n\n constructor(options: AppServerClientOptions) {\n const WebSocket = options.WebSocket ?? getGlobalWebSocket();\n if (!WebSocket) {\n throw new Error(\"No WebSocket implementation available\");\n }\n\n this.requestTimeoutMs =\n options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;\n const socketOptions = appServerSocketOptions(options.authToken);\n this.control = new WebSocket(\n resolveAppServerChannelUrl(options.url, \"control\"),\n socketOptions,\n );\n this.stream = new WebSocket(\n resolveAppServerChannelUrl(options.url, \"stream\"),\n socketOptions,\n );\n\n attachSocketListener(this.control, \"message\", (event) => {\n this.handleMessage(event, \"control\");\n });\n attachSocketListener(this.stream, \"message\", (event) => {\n this.handleMessage(event, \"stream\");\n });\n attachSocketListener(this.control, \"close\", (event) => {\n this.handleDisconnect(\"control\", event);\n });\n attachSocketListener(this.stream, \"close\", (event) => {\n this.handleDisconnect(\"stream\", event);\n });\n }\n\n async connect(): Promise<this> {\n await Promise.all([\n waitForSocketOpen(this.control),\n waitForSocketOpen(this.stream),\n ]);\n return this;\n }\n\n close(): void {\n if (this.explicitlyClosed) return;\n this.explicitlyClosed = true;\n this.rejectAllPending(\"App-server client closed\");\n this.control.close();\n this.stream.close();\n }\n\n onMessage(handler: AppServerMessageHandler): () => void {\n this.messageHandlers.add(handler);\n return () => this.messageHandlers.delete(handler);\n }\n\n onSend(handler: AppServerSendHandler): () => void {\n this.sendHandlers.add(handler);\n return () => this.sendHandlers.delete(handler);\n }\n\n onDisconnect(handler: AppServerDisconnectHandler): () => void {\n this.disconnectHandlers.add(handler);\n return () => this.disconnectHandlers.delete(handler);\n }\n\n nextRequestId(prefix = \"req\"): string {\n this.nextRequestNumber += 1;\n return `${prefix}-${this.nextRequestNumber}`;\n }\n\n send(command: WsProtocolCommand): void {\n this.writeCommand(command);\n }\n\n private writeCommand(command: AppServerSendCommand): void {\n for (const handler of this.sendHandlers) {\n handler(command);\n }\n this.control.send(JSON.stringify(command));\n }\n\n /**\n * Send a forward-compatible protocol command from a compatibility adapter.\n * Prefer the typed wrappers above this boundary for normal product code.\n */\n sendRaw(command: AppServerRawCommand): void {\n this.writeCommand(command);\n }\n\n /**\n * Request a forward-compatible response without mirroring the full protocol\n * union in a downstream compatibility adapter.\n */\n requestRaw<TResponse extends AppServerRawResponse>(\n command: AppServerRawCommand & { request_id: string },\n options: AppServerRawRequestOptions<TResponse>,\n ): Promise<TResponse> {\n const timeoutMs = options.timeoutMs ?? this.requestTimeoutMs;\n return new Promise((resolve, reject) => {\n const timeout = setTimeout(() => {\n this.pending.delete(command.request_id);\n reject(new Error(`Timed out waiting for ${command.request_id}`));\n }, timeoutMs);\n\n this.pending.set(command.request_id, {\n resolve: (message) => resolve(message as unknown as TResponse),\n reject,\n predicate: options.predicate,\n timeout,\n });\n\n try {\n this.sendRaw(command);\n } catch (error) {\n clearTimeout(timeout);\n this.pending.delete(command.request_id);\n reject(error instanceof Error ? error : new Error(String(error)));\n }\n });\n }\n\n request<TMessage extends WsProtocolMessage = WsProtocolMessage>(\n command: AppServerRequestCommandWithId,\n options?: AppServerRequestOptions<TMessage>,\n ): Promise<TMessage>;\n\n request<\n TType extends AppServerRequestCommand[\"type\"],\n TMessage extends WsProtocolMessage = WsProtocolMessage,\n >(\n type: TType,\n body?: AppServerRequestBody,\n options?: AppServerRequestOptions<TMessage>,\n ): Promise<TMessage>;\n\n request<TMessage extends WsProtocolMessage = WsProtocolMessage>(\n commandOrType:\n | AppServerRequestCommandWithId\n | AppServerRequestCommand[\"type\"],\n bodyOrOptions:\n | AppServerRequestBody\n | AppServerRequestOptions<TMessage> = {},\n maybeOptions: AppServerRequestOptions<TMessage> = {},\n ): Promise<TMessage> {\n const isTypeRequest = typeof commandOrType === \"string\";\n const command = isTypeRequest\n ? ({\n type: commandOrType,\n request_id:\n (bodyOrOptions as { request_id?: string }).request_id ??\n this.nextRequestId(commandOrType),\n ...(bodyOrOptions as object),\n } as AppServerRequestCommandWithId)\n : commandOrType;\n const options = isTypeRequest\n ? maybeOptions\n : (bodyOrOptions as AppServerRequestOptions<TMessage>);\n const timeoutMs = options.timeoutMs ?? this.requestTimeoutMs;\n\n return new Promise((resolve, reject) => {\n const timeout = setTimeout(() => {\n this.pending.delete(command.request_id);\n reject(new Error(`Timed out waiting for ${command.request_id}`));\n }, timeoutMs);\n\n this.pending.set(command.request_id, {\n resolve: (message) => resolve(message as TMessage),\n reject,\n predicate: options.predicate,\n timeout,\n });\n\n try {\n this.send(command);\n } catch (error) {\n clearTimeout(timeout);\n this.pending.delete(command.request_id);\n reject(error instanceof Error ? error : new Error(String(error)));\n }\n });\n }\n\n info(\n options: Omit<\n AppServerRequestOptions<AppServerInfoResponseMessage>,\n \"predicate\"\n > = {},\n ): Promise<AppServerInfoResponseMessage> {\n return this.request(\n {\n type: \"app_server_info\",\n request_id: this.nextRequestId(\"app-server-info\"),\n },\n {\n ...options,\n predicate: isAppServerInfoResponseMessage,\n },\n );\n }\n\n runtimeStart(\n command: Omit<RuntimeStartCommand, \"type\" | \"request_id\"> & {\n request_id?: string;\n },\n options: Omit<\n AppServerRequestOptions<RuntimeStartResponseMessage>,\n \"predicate\"\n > = {},\n ): Promise<RuntimeStartResponseMessage> {\n return this.request(\n {\n type: \"runtime_start\",\n request_id: command.request_id ?? this.nextRequestId(\"runtime-start\"),\n ...command,\n },\n {\n ...options,\n predicate: (message): message is RuntimeStartResponseMessage =>\n message.type === \"runtime_start_response\",\n },\n );\n }\n\n sync(\n command: Omit<SyncCommand, \"type\" | \"request_id\"> & { request_id?: string },\n options: Omit<\n AppServerRequestOptions<SyncResponseMessage>,\n \"predicate\"\n > = {},\n ): Promise<SyncResponseMessage> {\n return this.request(\n {\n type: \"sync\",\n request_id: command.request_id ?? this.nextRequestId(\"sync\"),\n ...command,\n },\n {\n ...options,\n predicate: (message): message is SyncResponseMessage =>\n message.type === \"sync_response\",\n },\n );\n }\n\n abort(\n command: Omit<AbortMessageCommand, \"type\" | \"request_id\"> & {\n request_id?: string;\n },\n options: Omit<\n AppServerRequestOptions<AbortMessageResponseMessage>,\n \"predicate\"\n > = {},\n ): Promise<AbortMessageResponseMessage> {\n return this.request(\n {\n type: \"abort_message\",\n request_id: command.request_id ?? this.nextRequestId(\"abort\"),\n ...command,\n },\n {\n ...options,\n predicate: (message): message is AbortMessageResponseMessage =>\n message.type === \"abort_message_response\",\n },\n );\n }\n\n conversationList(\n command: Omit<ConversationListCommand, \"type\" | \"request_id\"> & {\n request_id?: string;\n } = {},\n options: Omit<\n AppServerRequestOptions<ConversationListResponseMessage>,\n \"predicate\"\n > = {},\n ): Promise<ConversationListResponseMessage> {\n return this.request(\n {\n type: \"conversation_list\",\n request_id:\n command.request_id ?? this.nextRequestId(\"conversation-list\"),\n ...command,\n },\n {\n ...options,\n predicate: (message): message is ConversationListResponseMessage =>\n message.type === \"conversation_list_response\",\n },\n );\n }\n\n onExternalToolCall(handler: AppServerExternalToolCallHandler): () => void {\n return this.onMessage((message, channel) => {\n if (\n channel !== \"control\" ||\n message.type !== \"external_tool_call_request\"\n ) {\n return;\n }\n\n void Promise.resolve(handler(message))\n .then((result) => {\n this.send({\n type: \"external_tool_call_response\",\n request_id: message.request_id,\n result,\n });\n })\n .catch((error) => {\n this.send({\n type: \"external_tool_call_response\",\n request_id: message.request_id,\n error: error instanceof Error ? error.message : String(error),\n });\n });\n });\n }\n\n input(command: Omit<InputCommand, \"type\">): void {\n this.send({ type: \"input\", ...command });\n }\n\n runTurn(\n command: Omit<InputCommand, \"type\">,\n options: AppServerRunTurnOptions = {},\n ): Promise<AppServerTurnResult> {\n const runtimeKey = `${command.runtime.agent_id}/${command.runtime.conversation_id}`;\n if (this.activeTurnRuntimes.has(runtimeKey)) {\n return Promise.reject(\n new Error(`A turn is already in flight for ${runtimeKey}`),\n );\n }\n this.activeTurnRuntimes.add(runtimeKey);\n const timeoutMs = options.timeoutMs ?? this.requestTimeoutMs;\n const commandWithIds = this.withClientMessageIds(command);\n const runIds = new Set<string>();\n let observedTurnEvidence = false;\n let observedRequiresApprovalStop = false;\n\n return new Promise((resolve, reject) => {\n const timeout = setTimeout(() => {\n cleanup();\n reject(\n new Error(\n `Timed out waiting for app-server turn on ${command.runtime.agent_id}/${command.runtime.conversation_id}`,\n ),\n );\n }, timeoutMs);\n\n const cleanup = () => {\n clearTimeout(timeout);\n this.activeTurnRuntimes.delete(runtimeKey);\n offMessage();\n };\n\n const finish = (\n completedBy: AppServerTurnCompletionSource,\n terminalMessage: WsProtocolMessage,\n stopReason: string | null,\n ) => {\n cleanup();\n resolve({\n runtime: command.runtime,\n stopReason,\n runIds: [...runIds],\n clientMessageIds: commandWithIds.clientMessageIds,\n completedBy,\n terminalMessage,\n });\n };\n\n const fail = (error: Error) => {\n cleanup();\n reject(error);\n };\n\n const offMessage = this.onMessage((message) => {\n if (\n !sameRuntime(\n (message as { runtime?: RuntimeScope }).runtime,\n command.runtime,\n )\n ) {\n return;\n }\n\n if (message.type === \"stream_delta\") {\n observedTurnEvidence = true;\n const runId = streamDeltaRunId(message);\n if (runId) runIds.add(runId);\n\n const messageType = streamDeltaMessageType(message);\n if (messageType === \"loop_error\" || messageType === \"error_message\") {\n fail(new Error(streamDeltaErrorMessage(message)));\n return;\n }\n if (messageType === \"stop_reason\") {\n const stopReason = streamDeltaStopReason(message);\n if (stopReason === \"requires_approval\") {\n observedRequiresApprovalStop = true;\n return;\n }\n finish(\"stop_reason\", message, stopReason);\n }\n return;\n }\n\n if (message.type === \"update_loop_status\") {\n const hadTurnEvidenceBeforeLoopStatus =\n observedTurnEvidence || observedRequiresApprovalStop;\n if (\n !hadTurnEvidenceBeforeLoopStatus &&\n (isWaitingOnApprovalLoopStatus(message) ||\n (options.allowLoopStatusFallback === true &&\n isWaitingLoopStatus(message)))\n ) {\n return;\n }\n for (const runId of message.loop_status.active_run_ids) {\n observedTurnEvidence = true;\n runIds.add(runId);\n }\n if (\n hadTurnEvidenceBeforeLoopStatus &&\n isWaitingOnApprovalLoopStatus(message)\n ) {\n finish(\n \"loop_status_waiting_on_approval\",\n message,\n \"requires_approval\",\n );\n return;\n }\n if (\n options.allowLoopStatusFallback === true &&\n hadTurnEvidenceBeforeLoopStatus &&\n isWaitingLoopStatus(message)\n ) {\n finish(\"loop_status_waiting_fallback\", message, null);\n }\n }\n });\n\n try {\n this.input(commandWithIds.command);\n } catch (error) {\n fail(error instanceof Error ? error : new Error(String(error)));\n }\n });\n }\n\n private withClientMessageIds(command: Omit<InputCommand, \"type\">): {\n command: Omit<InputCommand, \"type\">;\n clientMessageIds: string[];\n } {\n if (command.payload.kind !== \"create_message\") {\n return { command, clientMessageIds: [] };\n }\n\n const clientMessageIds: string[] = [];\n const messages = command.payload.messages.map((message) => {\n if (message.role !== \"user\") return message;\n const existing = (message as { client_message_id?: unknown })\n .client_message_id;\n const clientMessageId =\n typeof existing === \"string\" && existing.length > 0\n ? existing\n : this.nextRequestId(\"client-message\");\n clientMessageIds.push(clientMessageId);\n return { ...message, client_message_id: clientMessageId };\n });\n\n return {\n command: {\n ...command,\n payload: { ...command.payload, messages },\n },\n clientMessageIds,\n };\n }\n\n private handleMessage(event: unknown, channel: AppServerChannel): void {\n const message = parseProtocolMessage(event);\n\n for (const handler of this.messageHandlers) {\n handler(message, channel);\n }\n\n const requestId =\n message && typeof message === \"object\" && \"request_id\" in message\n ? (message as { request_id?: unknown }).request_id\n : undefined;\n if (channel !== \"control\" || typeof requestId !== \"string\") {\n return;\n }\n\n const pending = this.pending.get(requestId);\n if (!pending || (pending.predicate && !pending.predicate(message))) {\n return;\n }\n\n clearTimeout(pending.timeout);\n this.pending.delete(requestId);\n pending.resolve(message);\n }\n\n private rejectAllPending(reason: string): void {\n for (const [requestId, pending] of this.pending) {\n clearTimeout(pending.timeout);\n this.pending.delete(requestId);\n pending.reject(new Error(reason));\n }\n }\n\n private handleDisconnect(channel: AppServerChannel, event: unknown): void {\n this.rejectAllPending(\"App-server socket closed\");\n if (this.explicitlyClosed || this.disconnectNotified) return;\n this.disconnectNotified = true;\n for (const handler of this.disconnectHandlers) {\n handler({ channel, event });\n }\n }\n}\n\nexport function createAppServerClient(\n options: AppServerClientOptions,\n): AppServerClient {\n return new AppServerClient(options);\n}\n"
|
|
6
|
+
"import { isAppServerInfoResponseMessage } from \"./types/app-server-info\";\n\nexport type { AppServerInfoResponseMessage } from \"./types/app-server-info\";\nexport { isAppServerInfoResponseMessage } from \"./types/app-server-info\";\n\nimport type {\n AbortMessageCommand,\n AbortMessageResponseMessage,\n AppServerInfoResponseMessage,\n ConversationListCommand,\n ConversationListResponseMessage,\n ExternalToolCallRequestMessage,\n ExternalToolCallResult,\n InputCommand,\n LoopStatusUpdateMessage,\n RuntimeScope,\n RuntimeStartCommand,\n RuntimeStartResponseMessage,\n StreamDeltaMessage,\n SyncCommand,\n SyncResponseMessage,\n WsProtocolCommand,\n WsProtocolMessage,\n} from \"./types/app-server-protocol\";\n\nexport type AppServerChannel = \"control\" | \"stream\";\n\nexport type AppServerRawCommand = Record<string, unknown> & {\n type: string;\n request_id?: string;\n};\n\nexport type AppServerRawResponse = Record<string, unknown> & {\n type: string;\n request_id?: string;\n};\n\nexport type AppServerSendCommand = WsProtocolCommand | AppServerRawCommand;\n\n/** Receives every parsed protocol frame from the app-server WebSocket. */\nexport type AppServerMessageHandler = (\n message: WsProtocolMessage,\n channel: AppServerChannel,\n) => void;\n\n/** Called synchronously before a typed or raw command is written to the socket. */\nexport type AppServerSendHandler = (command: AppServerSendCommand) => void;\n\nexport interface AppServerDisconnectEvent {\n channel: AppServerChannel;\n event: unknown;\n}\n\n/** Called once when the WebSocket closes before client.close(). */\nexport type AppServerDisconnectHandler = (\n disconnect: AppServerDisconnectEvent,\n) => void;\n\nexport type AppServerExternalToolCallHandler = (\n request: ExternalToolCallRequestMessage,\n) => Promise<ExternalToolCallResult> | ExternalToolCallResult;\n\nexport interface AppServerSocketLike {\n readyState: number;\n send(data: string): void;\n close(): void;\n addEventListener?(type: string, listener: (event: unknown) => void): void;\n removeEventListener?(type: string, listener: (event: unknown) => void): void;\n on?(type: string, listener: (event: unknown) => void): void;\n off?(type: string, listener: (event: unknown) => void): void;\n once?(type: string, listener: (event: unknown) => void): void;\n}\n\nexport interface AppServerSocketOptions {\n headers?: Record<string, string>;\n}\n\nexport type AppServerSocketConstructor = new (\n url: string,\n options?: AppServerSocketOptions,\n) => AppServerSocketLike;\n\nexport interface AppServerClientOptions {\n /** Base app-server URL, e.g. ws://127.0.0.1:4500 or http://127.0.0.1:4500. */\n url: string;\n /** Optional capability token sent as Authorization: Bearer <token>; requires a WebSocket implementation with header support. */\n authToken?: string;\n /** Optional WebSocket constructor for Node/tests. Browsers use globalThis.WebSocket. */\n WebSocket?: AppServerSocketConstructor;\n /** Default timeout for request_id-correlated control requests. */\n requestTimeoutMs?: number;\n}\n\nexport interface AppServerRequestOptions<TMessage extends WsProtocolMessage> {\n timeoutMs?: number;\n predicate?: (message: WsProtocolMessage) => message is TMessage;\n}\n\nexport type AppServerRequestCommand = Extract<\n WsProtocolCommand,\n { request_id?: string }\n>;\n\nexport type AppServerRequestCommandWithId = AppServerRequestCommand & {\n request_id: string;\n};\n\nexport type AppServerRequestBody = Record<string, unknown> & {\n request_id?: string;\n};\n\nexport interface AppServerRawRequestOptions<\n TResponse extends AppServerRawResponse,\n> {\n timeoutMs?: number;\n predicate: (message: unknown) => message is TResponse;\n}\n\ntype PendingRequest = {\n resolve: (message: WsProtocolMessage) => void;\n reject: (error: Error) => void;\n predicate?: (message: WsProtocolMessage) => boolean;\n timeout: ReturnType<typeof setTimeout>;\n};\n\nexport type AppServerTurnCompletionSource =\n | \"stop_reason\"\n | \"loop_status_waiting_on_approval\"\n | \"loop_status_waiting_fallback\";\n\nexport interface AppServerTurnResult {\n runtime: RuntimeScope;\n stopReason: string | null;\n runIds: string[];\n clientMessageIds: string[];\n completedBy: AppServerTurnCompletionSource;\n terminalMessage: WsProtocolMessage;\n}\n\nexport interface AppServerRunTurnOptions {\n timeoutMs?: number;\n /**\n * Prefer explicit stream terminal events. This fallback is only used after\n * the client has seen stream/run evidence for this runtime, never from idle\n * loop status alone.\n */\n allowLoopStatusFallback?: boolean;\n}\n\nconst DEFAULT_REQUEST_TIMEOUT_MS = 30_000;\nconst WEBSOCKET_OPEN_STATE = 1;\n\nfunction getGlobalWebSocket(): AppServerSocketConstructor | undefined {\n return (globalThis as { WebSocket?: AppServerSocketConstructor }).WebSocket;\n}\n\nfunction normalizeBaseUrl(url: string): URL {\n const parsed = new URL(url);\n if (parsed.protocol === \"http:\") parsed.protocol = \"ws:\";\n if (parsed.protocol === \"https:\") parsed.protocol = \"wss:\";\n if (parsed.protocol !== \"ws:\" && parsed.protocol !== \"wss:\") {\n throw new Error(`Unsupported app-server URL protocol: ${parsed.protocol}`);\n }\n if (!parsed.pathname || parsed.pathname === \"/\") {\n parsed.pathname = \"/ws\";\n }\n return parsed;\n}\n\nexport function resolveAppServerUrl(url: string): string {\n const parsed = normalizeBaseUrl(url);\n parsed.searchParams.delete(\"channel\");\n return parsed.toString();\n}\n\n/**\n * @deprecated App-server uses one bidirectional WebSocket. Both historical\n * channel names resolve to that same socket URL.\n */\nexport function resolveAppServerChannelUrl(\n url: string,\n _channel: AppServerChannel,\n): string {\n return resolveAppServerUrl(url);\n}\n\nfunction attachSocketListener(\n socket: AppServerSocketLike,\n type: string,\n listener: (event: unknown) => void,\n): () => void {\n if (socket.addEventListener && socket.removeEventListener) {\n socket.addEventListener(type, listener);\n return () => socket.removeEventListener?.(type, listener);\n }\n\n if (socket.on) {\n socket.on(type, listener);\n return () => socket.off?.(type, listener);\n }\n\n throw new Error(\"WebSocket implementation does not support event listeners\");\n}\n\nfunction onceSocketEvent(\n socket: AppServerSocketLike,\n type: string,\n listener: (event: unknown) => void,\n): () => void {\n if (socket.once) {\n socket.once(type, listener);\n return () => socket.off?.(type, listener);\n }\n\n let detach = () => {};\n detach = attachSocketListener(socket, type, (event) => {\n detach();\n listener(event);\n });\n return detach;\n}\n\nfunction waitForSocketOpen(socket: AppServerSocketLike): Promise<void> {\n if (socket.readyState === WEBSOCKET_OPEN_STATE) {\n return Promise.resolve();\n }\n\n return new Promise((resolve, reject) => {\n let detachOpen = () => {};\n let detachError = () => {};\n const cleanup = () => {\n detachOpen();\n detachError();\n };\n detachOpen = onceSocketEvent(socket, \"open\", () => {\n cleanup();\n resolve();\n });\n detachError = onceSocketEvent(socket, \"error\", (event) => {\n cleanup();\n reject(\n new Error(`App-server WebSocket failed to open: ${String(event)}`),\n );\n });\n });\n}\n\nfunction rawEventData(event: unknown): unknown {\n if (event && typeof event === \"object\" && \"data\" in event) {\n return (event as { data: unknown }).data;\n }\n return event;\n}\n\nfunction messageDataToString(data: unknown): string {\n const raw = rawEventData(data);\n if (typeof raw === \"string\") return raw;\n if (raw instanceof ArrayBuffer) {\n return new TextDecoder().decode(raw);\n }\n if (raw instanceof Uint8Array) {\n return new TextDecoder().decode(raw);\n }\n if (ArrayBuffer.isView(raw)) {\n return new TextDecoder().decode(\n new Uint8Array(raw.buffer as ArrayBuffer, raw.byteOffset, raw.byteLength),\n );\n }\n return String(raw);\n}\n\nfunction parseProtocolMessage(event: unknown): WsProtocolMessage {\n return JSON.parse(messageDataToString(event)) as WsProtocolMessage;\n}\n\nfunction appServerSocketOptions(\n authToken: string | undefined,\n): AppServerSocketOptions | undefined {\n if (authToken === undefined) {\n return undefined;\n }\n const token = authToken.trim();\n if (!token) {\n throw new Error(\"app-server auth token must not be empty\");\n }\n return { headers: { Authorization: `Bearer ${token}` } };\n}\n\nfunction sameRuntime(a: RuntimeScope | undefined, b: RuntimeScope): boolean {\n return a?.agent_id === b.agent_id && a?.conversation_id === b.conversation_id;\n}\n\nfunction isWaitingLoopStatus(message: LoopStatusUpdateMessage): boolean {\n return message.loop_status.status === \"WAITING_ON_INPUT\";\n}\n\nfunction isWaitingOnApprovalLoopStatus(\n message: LoopStatusUpdateMessage,\n): boolean {\n return message.loop_status.status === \"WAITING_ON_APPROVAL\";\n}\n\nfunction streamDeltaRunId(message: StreamDeltaMessage): string | null {\n const runId = (message.delta as { run_id?: unknown }).run_id;\n return typeof runId === \"string\" ? runId : null;\n}\n\nfunction streamDeltaMessageType(message: StreamDeltaMessage): string | null {\n const messageType = (message.delta as { message_type?: unknown })\n .message_type;\n return typeof messageType === \"string\" ? messageType : null;\n}\n\nfunction streamDeltaStopReason(message: StreamDeltaMessage): string | null {\n const stopReason = (message.delta as { stop_reason?: unknown }).stop_reason;\n return typeof stopReason === \"string\" ? stopReason : null;\n}\n\nfunction streamDeltaErrorMessage(message: StreamDeltaMessage): string {\n const delta = message.delta as {\n message?: unknown;\n api_error?: { message?: unknown; detail?: unknown };\n };\n const apiMessage = delta.api_error?.message ?? delta.api_error?.detail;\n if (typeof apiMessage === \"string\" && apiMessage.length > 0)\n return apiMessage;\n if (typeof delta.message === \"string\" && delta.message.length > 0)\n return delta.message;\n return \"App-server turn failed\";\n}\n\nexport class AppServerClient {\n readonly socket: AppServerSocketLike;\n /** @deprecated Alias for socket. */\n readonly control: AppServerSocketLike;\n /** @deprecated Alias for socket; no second stream connection is created. */\n readonly stream: AppServerSocketLike;\n\n private readonly requestTimeoutMs: number;\n private readonly pending = new Map<string, PendingRequest>();\n private readonly messageHandlers = new Set<AppServerMessageHandler>();\n private readonly sendHandlers = new Set<AppServerSendHandler>();\n private readonly disconnectHandlers = new Set<AppServerDisconnectHandler>();\n private readonly activeTurnRuntimes = new Set<string>();\n private explicitlyClosed = false;\n private disconnectNotified = false;\n private nextRequestNumber = 0;\n\n constructor(options: AppServerClientOptions) {\n const WebSocket = options.WebSocket ?? getGlobalWebSocket();\n if (!WebSocket) {\n throw new Error(\"No WebSocket implementation available\");\n }\n\n this.requestTimeoutMs =\n options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;\n const socketOptions = appServerSocketOptions(options.authToken);\n this.socket = new WebSocket(\n resolveAppServerUrl(options.url),\n socketOptions,\n );\n this.control = this.socket;\n this.stream = this.socket;\n\n attachSocketListener(this.socket, \"message\", (event) => {\n this.handleMessage(event, \"control\");\n });\n attachSocketListener(this.socket, \"close\", (event) => {\n this.handleDisconnect(\"control\", event);\n });\n }\n\n async connect(): Promise<this> {\n await waitForSocketOpen(this.socket);\n return this;\n }\n\n close(): void {\n if (this.explicitlyClosed) return;\n this.explicitlyClosed = true;\n this.rejectAllPending(\"App-server client closed\");\n this.socket.close();\n }\n\n onMessage(handler: AppServerMessageHandler): () => void {\n this.messageHandlers.add(handler);\n return () => this.messageHandlers.delete(handler);\n }\n\n onSend(handler: AppServerSendHandler): () => void {\n this.sendHandlers.add(handler);\n return () => this.sendHandlers.delete(handler);\n }\n\n onDisconnect(handler: AppServerDisconnectHandler): () => void {\n this.disconnectHandlers.add(handler);\n return () => this.disconnectHandlers.delete(handler);\n }\n\n nextRequestId(prefix = \"req\"): string {\n this.nextRequestNumber += 1;\n return `${prefix}-${this.nextRequestNumber}`;\n }\n\n send(command: WsProtocolCommand): void {\n this.writeCommand(command);\n }\n\n private writeCommand(command: AppServerSendCommand): void {\n for (const handler of this.sendHandlers) {\n handler(command);\n }\n this.socket.send(JSON.stringify(command));\n }\n\n /**\n * Send a forward-compatible protocol command from a compatibility adapter.\n * Prefer the typed wrappers above this boundary for normal product code.\n */\n sendRaw(command: AppServerRawCommand): void {\n this.writeCommand(command);\n }\n\n /**\n * Request a forward-compatible response without mirroring the full protocol\n * union in a downstream compatibility adapter.\n */\n requestRaw<TResponse extends AppServerRawResponse>(\n command: AppServerRawCommand & { request_id: string },\n options: AppServerRawRequestOptions<TResponse>,\n ): Promise<TResponse> {\n const timeoutMs = options.timeoutMs ?? this.requestTimeoutMs;\n return new Promise((resolve, reject) => {\n const timeout = setTimeout(() => {\n this.pending.delete(command.request_id);\n reject(new Error(`Timed out waiting for ${command.request_id}`));\n }, timeoutMs);\n\n this.pending.set(command.request_id, {\n resolve: (message) => resolve(message as unknown as TResponse),\n reject,\n predicate: options.predicate,\n timeout,\n });\n\n try {\n this.sendRaw(command);\n } catch (error) {\n clearTimeout(timeout);\n this.pending.delete(command.request_id);\n reject(error instanceof Error ? error : new Error(String(error)));\n }\n });\n }\n\n request<TMessage extends WsProtocolMessage = WsProtocolMessage>(\n command: AppServerRequestCommandWithId,\n options?: AppServerRequestOptions<TMessage>,\n ): Promise<TMessage>;\n\n request<\n TType extends AppServerRequestCommand[\"type\"],\n TMessage extends WsProtocolMessage = WsProtocolMessage,\n >(\n type: TType,\n body?: AppServerRequestBody,\n options?: AppServerRequestOptions<TMessage>,\n ): Promise<TMessage>;\n\n request<TMessage extends WsProtocolMessage = WsProtocolMessage>(\n commandOrType:\n | AppServerRequestCommandWithId\n | AppServerRequestCommand[\"type\"],\n bodyOrOptions:\n | AppServerRequestBody\n | AppServerRequestOptions<TMessage> = {},\n maybeOptions: AppServerRequestOptions<TMessage> = {},\n ): Promise<TMessage> {\n const isTypeRequest = typeof commandOrType === \"string\";\n const command = isTypeRequest\n ? ({\n type: commandOrType,\n request_id:\n (bodyOrOptions as { request_id?: string }).request_id ??\n this.nextRequestId(commandOrType),\n ...(bodyOrOptions as object),\n } as AppServerRequestCommandWithId)\n : commandOrType;\n const options = isTypeRequest\n ? maybeOptions\n : (bodyOrOptions as AppServerRequestOptions<TMessage>);\n const timeoutMs = options.timeoutMs ?? this.requestTimeoutMs;\n\n return new Promise((resolve, reject) => {\n const timeout = setTimeout(() => {\n this.pending.delete(command.request_id);\n reject(new Error(`Timed out waiting for ${command.request_id}`));\n }, timeoutMs);\n\n this.pending.set(command.request_id, {\n resolve: (message) => resolve(message as TMessage),\n reject,\n predicate: options.predicate,\n timeout,\n });\n\n try {\n this.send(command);\n } catch (error) {\n clearTimeout(timeout);\n this.pending.delete(command.request_id);\n reject(error instanceof Error ? error : new Error(String(error)));\n }\n });\n }\n\n info(\n options: Omit<\n AppServerRequestOptions<AppServerInfoResponseMessage>,\n \"predicate\"\n > = {},\n ): Promise<AppServerInfoResponseMessage> {\n return this.request(\n {\n type: \"app_server_info\",\n request_id: this.nextRequestId(\"app-server-info\"),\n },\n {\n ...options,\n predicate: isAppServerInfoResponseMessage,\n },\n );\n }\n\n runtimeStart(\n command: Omit<RuntimeStartCommand, \"type\" | \"request_id\"> & {\n request_id?: string;\n },\n options: Omit<\n AppServerRequestOptions<RuntimeStartResponseMessage>,\n \"predicate\"\n > = {},\n ): Promise<RuntimeStartResponseMessage> {\n return this.request(\n {\n type: \"runtime_start\",\n request_id: command.request_id ?? this.nextRequestId(\"runtime-start\"),\n ...command,\n },\n {\n ...options,\n predicate: (message): message is RuntimeStartResponseMessage =>\n message.type === \"runtime_start_response\",\n },\n );\n }\n\n sync(\n command: Omit<SyncCommand, \"type\" | \"request_id\"> & { request_id?: string },\n options: Omit<\n AppServerRequestOptions<SyncResponseMessage>,\n \"predicate\"\n > = {},\n ): Promise<SyncResponseMessage> {\n return this.request(\n {\n type: \"sync\",\n request_id: command.request_id ?? this.nextRequestId(\"sync\"),\n ...command,\n },\n {\n ...options,\n predicate: (message): message is SyncResponseMessage =>\n message.type === \"sync_response\",\n },\n );\n }\n\n abort(\n command: Omit<AbortMessageCommand, \"type\" | \"request_id\"> & {\n request_id?: string;\n },\n options: Omit<\n AppServerRequestOptions<AbortMessageResponseMessage>,\n \"predicate\"\n > = {},\n ): Promise<AbortMessageResponseMessage> {\n return this.request(\n {\n type: \"abort_message\",\n request_id: command.request_id ?? this.nextRequestId(\"abort\"),\n ...command,\n },\n {\n ...options,\n predicate: (message): message is AbortMessageResponseMessage =>\n message.type === \"abort_message_response\",\n },\n );\n }\n\n conversationList(\n command: Omit<ConversationListCommand, \"type\" | \"request_id\"> & {\n request_id?: string;\n } = {},\n options: Omit<\n AppServerRequestOptions<ConversationListResponseMessage>,\n \"predicate\"\n > = {},\n ): Promise<ConversationListResponseMessage> {\n return this.request(\n {\n type: \"conversation_list\",\n request_id:\n command.request_id ?? this.nextRequestId(\"conversation-list\"),\n ...command,\n },\n {\n ...options,\n predicate: (message): message is ConversationListResponseMessage =>\n message.type === \"conversation_list_response\",\n },\n );\n }\n\n onExternalToolCall(handler: AppServerExternalToolCallHandler): () => void {\n return this.onMessage((message, channel) => {\n if (\n channel !== \"control\" ||\n message.type !== \"external_tool_call_request\"\n ) {\n return;\n }\n\n void Promise.resolve(handler(message))\n .then((result) => {\n this.send({\n type: \"external_tool_call_response\",\n request_id: message.request_id,\n result,\n });\n })\n .catch((error) => {\n this.send({\n type: \"external_tool_call_response\",\n request_id: message.request_id,\n error: error instanceof Error ? error.message : String(error),\n });\n });\n });\n }\n\n input(command: Omit<InputCommand, \"type\">): void {\n this.send({ type: \"input\", ...command });\n }\n\n runTurn(\n command: Omit<InputCommand, \"type\">,\n options: AppServerRunTurnOptions = {},\n ): Promise<AppServerTurnResult> {\n const runtimeKey = `${command.runtime.agent_id}/${command.runtime.conversation_id}`;\n if (this.activeTurnRuntimes.has(runtimeKey)) {\n return Promise.reject(\n new Error(`A turn is already in flight for ${runtimeKey}`),\n );\n }\n this.activeTurnRuntimes.add(runtimeKey);\n const timeoutMs = options.timeoutMs ?? this.requestTimeoutMs;\n const commandWithIds = this.withClientMessageIds(command);\n const runIds = new Set<string>();\n let observedTurnEvidence = false;\n let observedRequiresApprovalStop = false;\n\n return new Promise((resolve, reject) => {\n const timeout = setTimeout(() => {\n cleanup();\n reject(\n new Error(\n `Timed out waiting for app-server turn on ${command.runtime.agent_id}/${command.runtime.conversation_id}`,\n ),\n );\n }, timeoutMs);\n\n const cleanup = () => {\n clearTimeout(timeout);\n this.activeTurnRuntimes.delete(runtimeKey);\n offMessage();\n };\n\n const finish = (\n completedBy: AppServerTurnCompletionSource,\n terminalMessage: WsProtocolMessage,\n stopReason: string | null,\n ) => {\n cleanup();\n resolve({\n runtime: command.runtime,\n stopReason,\n runIds: [...runIds],\n clientMessageIds: commandWithIds.clientMessageIds,\n completedBy,\n terminalMessage,\n });\n };\n\n const fail = (error: Error) => {\n cleanup();\n reject(error);\n };\n\n const offMessage = this.onMessage((message) => {\n if (\n !sameRuntime(\n (message as { runtime?: RuntimeScope }).runtime,\n command.runtime,\n )\n ) {\n return;\n }\n\n if (message.type === \"stream_delta\") {\n observedTurnEvidence = true;\n const runId = streamDeltaRunId(message);\n if (runId) runIds.add(runId);\n\n const messageType = streamDeltaMessageType(message);\n if (messageType === \"loop_error\" || messageType === \"error_message\") {\n fail(new Error(streamDeltaErrorMessage(message)));\n return;\n }\n if (messageType === \"stop_reason\") {\n const stopReason = streamDeltaStopReason(message);\n if (stopReason === \"requires_approval\") {\n observedRequiresApprovalStop = true;\n return;\n }\n finish(\"stop_reason\", message, stopReason);\n }\n return;\n }\n\n if (message.type === \"update_loop_status\") {\n const hadTurnEvidenceBeforeLoopStatus =\n observedTurnEvidence || observedRequiresApprovalStop;\n if (\n !hadTurnEvidenceBeforeLoopStatus &&\n (isWaitingOnApprovalLoopStatus(message) ||\n (options.allowLoopStatusFallback === true &&\n isWaitingLoopStatus(message)))\n ) {\n return;\n }\n for (const runId of message.loop_status.active_run_ids) {\n observedTurnEvidence = true;\n runIds.add(runId);\n }\n if (\n hadTurnEvidenceBeforeLoopStatus &&\n isWaitingOnApprovalLoopStatus(message)\n ) {\n finish(\n \"loop_status_waiting_on_approval\",\n message,\n \"requires_approval\",\n );\n return;\n }\n if (\n options.allowLoopStatusFallback === true &&\n hadTurnEvidenceBeforeLoopStatus &&\n isWaitingLoopStatus(message)\n ) {\n finish(\"loop_status_waiting_fallback\", message, null);\n }\n }\n });\n\n try {\n this.input(commandWithIds.command);\n } catch (error) {\n fail(error instanceof Error ? error : new Error(String(error)));\n }\n });\n }\n\n private withClientMessageIds(command: Omit<InputCommand, \"type\">): {\n command: Omit<InputCommand, \"type\">;\n clientMessageIds: string[];\n } {\n if (command.payload.kind !== \"create_message\") {\n return { command, clientMessageIds: [] };\n }\n\n const clientMessageIds: string[] = [];\n const messages = command.payload.messages.map((message) => {\n if (message.role !== \"user\") return message;\n const existing = (message as { client_message_id?: unknown })\n .client_message_id;\n const clientMessageId =\n typeof existing === \"string\" && existing.length > 0\n ? existing\n : this.nextRequestId(\"client-message\");\n clientMessageIds.push(clientMessageId);\n return { ...message, client_message_id: clientMessageId };\n });\n\n return {\n command: {\n ...command,\n payload: { ...command.payload, messages },\n },\n clientMessageIds,\n };\n }\n\n private handleMessage(event: unknown, channel: AppServerChannel): void {\n const message = parseProtocolMessage(event);\n\n for (const handler of this.messageHandlers) {\n handler(message, channel);\n }\n\n const requestId =\n message && typeof message === \"object\" && \"request_id\" in message\n ? (message as { request_id?: unknown }).request_id\n : undefined;\n if (channel !== \"control\" || typeof requestId !== \"string\") {\n return;\n }\n\n const pending = this.pending.get(requestId);\n if (!pending || (pending.predicate && !pending.predicate(message))) {\n return;\n }\n\n clearTimeout(pending.timeout);\n this.pending.delete(requestId);\n pending.resolve(message);\n }\n\n private rejectAllPending(reason: string): void {\n for (const [requestId, pending] of this.pending) {\n clearTimeout(pending.timeout);\n this.pending.delete(requestId);\n pending.reject(new Error(reason));\n }\n }\n\n private handleDisconnect(channel: AppServerChannel, event: unknown): void {\n this.rejectAllPending(\"App-server socket closed\");\n if (this.explicitlyClosed || this.disconnectNotified) return;\n this.disconnectNotified = true;\n for (const handler of this.disconnectHandlers) {\n handler({ channel, event });\n }\n }\n}\n\nexport function createAppServerClient(\n options: AppServerClientOptions,\n): AppServerClient {\n return new AppServerClient(options);\n}\n"
|
|
7
7
|
],
|
|
8
|
-
"mappings": ";AA0BO,SAAS,8BAA8B,CAC5C,SACyC;AAAA,EACzC,IAAI,CAAC,WAAW,OAAO,YAAY,YAAY,MAAM,QAAQ,OAAO,GAAG;AAAA,IACrE,OAAO;AAAA,EACT;AAAA,EAEA,MAAM,YAAY;AAAA,EAClB,MAAM,eAAe,UAAU;AAAA,EAC/B,IACE,CAAC,gBACD,OAAO,iBAAiB,YACxB,MAAM,QAAQ,YAAY,GAC1B;AAAA,IACA,OAAO;AAAA,EACT;AAAA,EAEA,MAAM,mBAAmB;AAAA,EACzB,OACE,UAAU,SAAS,8BACnB,OAAO,UAAU,eAAe,YAChC,UAAU,WAAW,SAAS,KAC9B,UAAU,YAAY,SACrB,UAAU,YAAY,WAAW,UAAU,YAAY,UACxD,OAAO,UAAU,uBAAuB,YACxC,OAAO,UAAU,qBAAqB,YACtC,OAAO,UAAU,UAAU,gBAAgB,KAC3C,OAAO,iBAAiB,qBAAqB,aAC7C,OAAO,iBAAiB,4BAA4B,aACpD,OAAO,iBAAiB,sBAAsB,aAC9C,OAAO,iBAAiB,kBAAkB,aAC1C,OAAO,iBAAiB,mBAAmB;AAAA;;;ACiG/C,IAAM,6BAA6B;AACnC,IAAM,uBAAuB;AAE7B,SAAS,kBAAkB,GAA2C;AAAA,EACpE,OAAQ,WAA0D;AAAA;AAGpE,SAAS,gBAAgB,CAAC,KAAkB;AAAA,EAC1C,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