@letta-ai/letta-code 0.29.2 → 0.29.3

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.
@@ -0,0 +1,531 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __moduleCache = /* @__PURE__ */ new WeakMap;
6
+ var __toCommonJS = (from) => {
7
+ var entry = __moduleCache.get(from), desc;
8
+ if (entry)
9
+ return entry;
10
+ entry = __defProp({}, "__esModule", { value: true });
11
+ if (from && typeof from === "object" || typeof from === "function")
12
+ __getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
13
+ get: () => from[key],
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ }));
16
+ __moduleCache.set(from, entry);
17
+ return entry;
18
+ };
19
+ var __export = (target, all) => {
20
+ for (var name in all)
21
+ __defProp(target, name, {
22
+ get: all[name],
23
+ enumerable: true,
24
+ configurable: true,
25
+ set: (newValue) => all[name] = () => newValue
26
+ });
27
+ };
28
+
29
+ // src/app-server-client.ts
30
+ var exports_app_server_client = {};
31
+ __export(exports_app_server_client, {
32
+ resolveAppServerChannelUrl: () => resolveAppServerChannelUrl,
33
+ isAppServerInfoResponseMessage: () => isAppServerInfoResponseMessage,
34
+ createAppServerClient: () => createAppServerClient,
35
+ AppServerClient: () => AppServerClient
36
+ });
37
+ module.exports = __toCommonJS(exports_app_server_client);
38
+
39
+ // src/types/app-server-info.ts
40
+ function isAppServerInfoResponseMessage(message) {
41
+ if (!message || typeof message !== "object" || Array.isArray(message)) {
42
+ return false;
43
+ }
44
+ const candidate = message;
45
+ const capabilities = candidate.capabilities;
46
+ if (!capabilities || typeof capabilities !== "object" || Array.isArray(capabilities)) {
47
+ return false;
48
+ }
49
+ const capabilityRecord = capabilities;
50
+ return candidate.type === "app_server_info_response" && typeof candidate.request_id === "string" && candidate.request_id.length > 0 && candidate.success === true && (candidate.backend === "local" || candidate.backend === "api") && typeof candidate.letta_code_version === "string" && typeof candidate.protocol_version === "number" && Number.isInteger(candidate.protocol_version) && typeof capabilityRecord.agent_management === "boolean" && typeof capabilityRecord.conversation_management === "boolean" && typeof capabilityRecord.memory_management === "boolean" && typeof capabilityRecord.runtime_start === "boolean" && typeof capabilityRecord.split_channels === "boolean";
51
+ }
52
+
53
+ // src/app-server-client.ts
54
+ var DEFAULT_REQUEST_TIMEOUT_MS = 30000;
55
+ var WEBSOCKET_OPEN_STATE = 1;
56
+ function getGlobalWebSocket() {
57
+ return globalThis.WebSocket;
58
+ }
59
+ function normalizeBaseUrl(url) {
60
+ const parsed = new URL(url);
61
+ if (parsed.protocol === "http:")
62
+ parsed.protocol = "ws:";
63
+ if (parsed.protocol === "https:")
64
+ parsed.protocol = "wss:";
65
+ if (parsed.protocol !== "ws:" && parsed.protocol !== "wss:") {
66
+ throw new Error(`Unsupported app-server URL protocol: ${parsed.protocol}`);
67
+ }
68
+ if (!parsed.pathname || parsed.pathname === "/") {
69
+ parsed.pathname = "/ws";
70
+ }
71
+ return parsed;
72
+ }
73
+ function resolveAppServerChannelUrl(url, channel) {
74
+ const parsed = normalizeBaseUrl(url);
75
+ parsed.searchParams.set("channel", channel);
76
+ return parsed.toString();
77
+ }
78
+ function attachSocketListener(socket, type, listener) {
79
+ if (socket.addEventListener && socket.removeEventListener) {
80
+ socket.addEventListener(type, listener);
81
+ return () => socket.removeEventListener?.(type, listener);
82
+ }
83
+ if (socket.on) {
84
+ socket.on(type, listener);
85
+ return () => socket.off?.(type, listener);
86
+ }
87
+ throw new Error("WebSocket implementation does not support event listeners");
88
+ }
89
+ function onceSocketEvent(socket, type, listener) {
90
+ if (socket.once) {
91
+ socket.once(type, listener);
92
+ return () => socket.off?.(type, listener);
93
+ }
94
+ let detach = () => {};
95
+ detach = attachSocketListener(socket, type, (event) => {
96
+ detach();
97
+ listener(event);
98
+ });
99
+ return detach;
100
+ }
101
+ function waitForSocketOpen(socket) {
102
+ if (socket.readyState === WEBSOCKET_OPEN_STATE) {
103
+ return Promise.resolve();
104
+ }
105
+ return new Promise((resolve, reject) => {
106
+ let detachOpen = () => {};
107
+ let detachError = () => {};
108
+ const cleanup = () => {
109
+ detachOpen();
110
+ detachError();
111
+ };
112
+ detachOpen = onceSocketEvent(socket, "open", () => {
113
+ cleanup();
114
+ resolve();
115
+ });
116
+ detachError = onceSocketEvent(socket, "error", (event) => {
117
+ cleanup();
118
+ reject(new Error(`App-server WebSocket failed to open: ${String(event)}`));
119
+ });
120
+ });
121
+ }
122
+ function rawEventData(event) {
123
+ if (event && typeof event === "object" && "data" in event) {
124
+ return event.data;
125
+ }
126
+ return event;
127
+ }
128
+ function messageDataToString(data) {
129
+ const raw = rawEventData(data);
130
+ if (typeof raw === "string")
131
+ return raw;
132
+ if (raw instanceof ArrayBuffer) {
133
+ return new TextDecoder().decode(raw);
134
+ }
135
+ if (raw instanceof Uint8Array) {
136
+ return new TextDecoder().decode(raw);
137
+ }
138
+ if (ArrayBuffer.isView(raw)) {
139
+ return new TextDecoder().decode(new Uint8Array(raw.buffer, raw.byteOffset, raw.byteLength));
140
+ }
141
+ return String(raw);
142
+ }
143
+ function parseProtocolMessage(event) {
144
+ return JSON.parse(messageDataToString(event));
145
+ }
146
+ function appServerSocketOptions(authToken) {
147
+ if (authToken === undefined) {
148
+ return;
149
+ }
150
+ const token = authToken.trim();
151
+ if (!token) {
152
+ throw new Error("app-server auth token must not be empty");
153
+ }
154
+ return { headers: { Authorization: `Bearer ${token}` } };
155
+ }
156
+ function sameRuntime(a, b) {
157
+ return a?.agent_id === b.agent_id && a?.conversation_id === b.conversation_id;
158
+ }
159
+ function isWaitingLoopStatus(message) {
160
+ return message.loop_status.status === "WAITING_ON_INPUT";
161
+ }
162
+ function isWaitingOnApprovalLoopStatus(message) {
163
+ return message.loop_status.status === "WAITING_ON_APPROVAL";
164
+ }
165
+ function streamDeltaRunId(message) {
166
+ const runId = message.delta.run_id;
167
+ return typeof runId === "string" ? runId : null;
168
+ }
169
+ function streamDeltaMessageType(message) {
170
+ const messageType = message.delta.message_type;
171
+ return typeof messageType === "string" ? messageType : null;
172
+ }
173
+ function streamDeltaStopReason(message) {
174
+ const stopReason = message.delta.stop_reason;
175
+ return typeof stopReason === "string" ? stopReason : null;
176
+ }
177
+ function streamDeltaErrorMessage(message) {
178
+ const delta = message.delta;
179
+ const apiMessage = delta.api_error?.message ?? delta.api_error?.detail;
180
+ if (typeof apiMessage === "string" && apiMessage.length > 0)
181
+ return apiMessage;
182
+ if (typeof delta.message === "string" && delta.message.length > 0)
183
+ return delta.message;
184
+ return "App-server turn failed";
185
+ }
186
+
187
+ class AppServerClient {
188
+ control;
189
+ stream;
190
+ requestTimeoutMs;
191
+ pending = new Map;
192
+ messageHandlers = new Set;
193
+ sendHandlers = new Set;
194
+ disconnectHandlers = new Set;
195
+ activeTurnRuntimes = new Set;
196
+ explicitlyClosed = false;
197
+ disconnectNotified = false;
198
+ nextRequestNumber = 0;
199
+ constructor(options) {
200
+ const WebSocket = options.WebSocket ?? getGlobalWebSocket();
201
+ if (!WebSocket) {
202
+ throw new Error("No WebSocket implementation available");
203
+ }
204
+ this.requestTimeoutMs = options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
205
+ const socketOptions = appServerSocketOptions(options.authToken);
206
+ this.control = new WebSocket(resolveAppServerChannelUrl(options.url, "control"), socketOptions);
207
+ this.stream = new WebSocket(resolveAppServerChannelUrl(options.url, "stream"), socketOptions);
208
+ attachSocketListener(this.control, "message", (event) => {
209
+ this.handleMessage(event, "control");
210
+ });
211
+ attachSocketListener(this.stream, "message", (event) => {
212
+ this.handleMessage(event, "stream");
213
+ });
214
+ attachSocketListener(this.control, "close", (event) => {
215
+ this.handleDisconnect("control", event);
216
+ });
217
+ attachSocketListener(this.stream, "close", (event) => {
218
+ this.handleDisconnect("stream", event);
219
+ });
220
+ }
221
+ async connect() {
222
+ await Promise.all([
223
+ waitForSocketOpen(this.control),
224
+ waitForSocketOpen(this.stream)
225
+ ]);
226
+ return this;
227
+ }
228
+ close() {
229
+ if (this.explicitlyClosed)
230
+ return;
231
+ this.explicitlyClosed = true;
232
+ this.rejectAllPending("App-server client closed");
233
+ this.control.close();
234
+ this.stream.close();
235
+ }
236
+ onMessage(handler) {
237
+ this.messageHandlers.add(handler);
238
+ return () => this.messageHandlers.delete(handler);
239
+ }
240
+ onSend(handler) {
241
+ this.sendHandlers.add(handler);
242
+ return () => this.sendHandlers.delete(handler);
243
+ }
244
+ onDisconnect(handler) {
245
+ this.disconnectHandlers.add(handler);
246
+ return () => this.disconnectHandlers.delete(handler);
247
+ }
248
+ nextRequestId(prefix = "req") {
249
+ this.nextRequestNumber += 1;
250
+ return `${prefix}-${this.nextRequestNumber}`;
251
+ }
252
+ send(command) {
253
+ this.writeCommand(command);
254
+ }
255
+ writeCommand(command) {
256
+ for (const handler of this.sendHandlers) {
257
+ handler(command);
258
+ }
259
+ this.control.send(JSON.stringify(command));
260
+ }
261
+ sendRaw(command) {
262
+ this.writeCommand(command);
263
+ }
264
+ requestRaw(command, options) {
265
+ const timeoutMs = options.timeoutMs ?? this.requestTimeoutMs;
266
+ return new Promise((resolve, reject) => {
267
+ const timeout = setTimeout(() => {
268
+ this.pending.delete(command.request_id);
269
+ reject(new Error(`Timed out waiting for ${command.request_id}`));
270
+ }, timeoutMs);
271
+ this.pending.set(command.request_id, {
272
+ resolve: (message) => resolve(message),
273
+ reject,
274
+ predicate: options.predicate,
275
+ timeout
276
+ });
277
+ try {
278
+ this.sendRaw(command);
279
+ } catch (error) {
280
+ clearTimeout(timeout);
281
+ this.pending.delete(command.request_id);
282
+ reject(error instanceof Error ? error : new Error(String(error)));
283
+ }
284
+ });
285
+ }
286
+ request(commandOrType, bodyOrOptions = {}, maybeOptions = {}) {
287
+ const isTypeRequest = typeof commandOrType === "string";
288
+ const command = isTypeRequest ? {
289
+ type: commandOrType,
290
+ request_id: bodyOrOptions.request_id ?? this.nextRequestId(commandOrType),
291
+ ...bodyOrOptions
292
+ } : commandOrType;
293
+ const options = isTypeRequest ? maybeOptions : bodyOrOptions;
294
+ const timeoutMs = options.timeoutMs ?? this.requestTimeoutMs;
295
+ return new Promise((resolve, reject) => {
296
+ const timeout = setTimeout(() => {
297
+ this.pending.delete(command.request_id);
298
+ reject(new Error(`Timed out waiting for ${command.request_id}`));
299
+ }, timeoutMs);
300
+ this.pending.set(command.request_id, {
301
+ resolve: (message) => resolve(message),
302
+ reject,
303
+ predicate: options.predicate,
304
+ timeout
305
+ });
306
+ try {
307
+ this.send(command);
308
+ } catch (error) {
309
+ clearTimeout(timeout);
310
+ this.pending.delete(command.request_id);
311
+ reject(error instanceof Error ? error : new Error(String(error)));
312
+ }
313
+ });
314
+ }
315
+ info(options = {}) {
316
+ return this.request({
317
+ type: "app_server_info",
318
+ request_id: this.nextRequestId("app-server-info")
319
+ }, {
320
+ ...options,
321
+ predicate: isAppServerInfoResponseMessage
322
+ });
323
+ }
324
+ runtimeStart(command, options = {}) {
325
+ return this.request({
326
+ type: "runtime_start",
327
+ request_id: command.request_id ?? this.nextRequestId("runtime-start"),
328
+ ...command
329
+ }, {
330
+ ...options,
331
+ predicate: (message) => message.type === "runtime_start_response"
332
+ });
333
+ }
334
+ sync(command, options = {}) {
335
+ return this.request({
336
+ type: "sync",
337
+ request_id: command.request_id ?? this.nextRequestId("sync"),
338
+ ...command
339
+ }, {
340
+ ...options,
341
+ predicate: (message) => message.type === "sync_response"
342
+ });
343
+ }
344
+ abort(command, options = {}) {
345
+ return this.request({
346
+ type: "abort_message",
347
+ request_id: command.request_id ?? this.nextRequestId("abort"),
348
+ ...command
349
+ }, {
350
+ ...options,
351
+ predicate: (message) => message.type === "abort_message_response"
352
+ });
353
+ }
354
+ conversationList(command = {}, options = {}) {
355
+ return this.request({
356
+ type: "conversation_list",
357
+ request_id: command.request_id ?? this.nextRequestId("conversation-list"),
358
+ ...command
359
+ }, {
360
+ ...options,
361
+ predicate: (message) => message.type === "conversation_list_response"
362
+ });
363
+ }
364
+ onExternalToolCall(handler) {
365
+ return this.onMessage((message, channel) => {
366
+ if (channel !== "control" || message.type !== "external_tool_call_request") {
367
+ return;
368
+ }
369
+ Promise.resolve(handler(message)).then((result) => {
370
+ this.send({
371
+ type: "external_tool_call_response",
372
+ request_id: message.request_id,
373
+ result
374
+ });
375
+ }).catch((error) => {
376
+ this.send({
377
+ type: "external_tool_call_response",
378
+ request_id: message.request_id,
379
+ error: error instanceof Error ? error.message : String(error)
380
+ });
381
+ });
382
+ });
383
+ }
384
+ input(command) {
385
+ this.send({ type: "input", ...command });
386
+ }
387
+ runTurn(command, options = {}) {
388
+ const runtimeKey = `${command.runtime.agent_id}/${command.runtime.conversation_id}`;
389
+ if (this.activeTurnRuntimes.has(runtimeKey)) {
390
+ return Promise.reject(new Error(`A turn is already in flight for ${runtimeKey}`));
391
+ }
392
+ this.activeTurnRuntimes.add(runtimeKey);
393
+ const timeoutMs = options.timeoutMs ?? this.requestTimeoutMs;
394
+ const commandWithIds = this.withClientMessageIds(command);
395
+ const runIds = new Set;
396
+ let observedTurnEvidence = false;
397
+ let observedRequiresApprovalStop = false;
398
+ return new Promise((resolve, reject) => {
399
+ const timeout = setTimeout(() => {
400
+ cleanup();
401
+ reject(new Error(`Timed out waiting for app-server turn on ${command.runtime.agent_id}/${command.runtime.conversation_id}`));
402
+ }, timeoutMs);
403
+ const cleanup = () => {
404
+ clearTimeout(timeout);
405
+ this.activeTurnRuntimes.delete(runtimeKey);
406
+ offMessage();
407
+ };
408
+ const finish = (completedBy, terminalMessage, stopReason) => {
409
+ cleanup();
410
+ resolve({
411
+ runtime: command.runtime,
412
+ stopReason,
413
+ runIds: [...runIds],
414
+ clientMessageIds: commandWithIds.clientMessageIds,
415
+ completedBy,
416
+ terminalMessage
417
+ });
418
+ };
419
+ const fail = (error) => {
420
+ cleanup();
421
+ reject(error);
422
+ };
423
+ const offMessage = this.onMessage((message) => {
424
+ if (!sameRuntime(message.runtime, command.runtime)) {
425
+ return;
426
+ }
427
+ if (message.type === "stream_delta") {
428
+ observedTurnEvidence = true;
429
+ const runId = streamDeltaRunId(message);
430
+ if (runId)
431
+ runIds.add(runId);
432
+ const messageType = streamDeltaMessageType(message);
433
+ if (messageType === "loop_error" || messageType === "error_message") {
434
+ fail(new Error(streamDeltaErrorMessage(message)));
435
+ return;
436
+ }
437
+ if (messageType === "stop_reason") {
438
+ const stopReason = streamDeltaStopReason(message);
439
+ if (stopReason === "requires_approval") {
440
+ observedRequiresApprovalStop = true;
441
+ return;
442
+ }
443
+ finish("stop_reason", message, stopReason);
444
+ }
445
+ return;
446
+ }
447
+ if (message.type === "update_loop_status") {
448
+ const hadTurnEvidenceBeforeLoopStatus = observedTurnEvidence || observedRequiresApprovalStop;
449
+ if (!hadTurnEvidenceBeforeLoopStatus && (isWaitingOnApprovalLoopStatus(message) || options.allowLoopStatusFallback === true && isWaitingLoopStatus(message))) {
450
+ return;
451
+ }
452
+ for (const runId of message.loop_status.active_run_ids) {
453
+ observedTurnEvidence = true;
454
+ runIds.add(runId);
455
+ }
456
+ if (hadTurnEvidenceBeforeLoopStatus && isWaitingOnApprovalLoopStatus(message)) {
457
+ finish("loop_status_waiting_on_approval", message, "requires_approval");
458
+ return;
459
+ }
460
+ if (options.allowLoopStatusFallback === true && hadTurnEvidenceBeforeLoopStatus && isWaitingLoopStatus(message)) {
461
+ finish("loop_status_waiting_fallback", message, null);
462
+ }
463
+ }
464
+ });
465
+ try {
466
+ this.input(commandWithIds.command);
467
+ } catch (error) {
468
+ fail(error instanceof Error ? error : new Error(String(error)));
469
+ }
470
+ });
471
+ }
472
+ withClientMessageIds(command) {
473
+ if (command.payload.kind !== "create_message") {
474
+ return { command, clientMessageIds: [] };
475
+ }
476
+ const clientMessageIds = [];
477
+ const messages = command.payload.messages.map((message) => {
478
+ if (message.role !== "user")
479
+ return message;
480
+ const existing = message.client_message_id;
481
+ const clientMessageId = typeof existing === "string" && existing.length > 0 ? existing : this.nextRequestId("client-message");
482
+ clientMessageIds.push(clientMessageId);
483
+ return { ...message, client_message_id: clientMessageId };
484
+ });
485
+ return {
486
+ command: {
487
+ ...command,
488
+ payload: { ...command.payload, messages }
489
+ },
490
+ clientMessageIds
491
+ };
492
+ }
493
+ handleMessage(event, channel) {
494
+ const message = parseProtocolMessage(event);
495
+ for (const handler of this.messageHandlers) {
496
+ handler(message, channel);
497
+ }
498
+ const requestId = message && typeof message === "object" && "request_id" in message ? message.request_id : undefined;
499
+ if (channel !== "control" || typeof requestId !== "string") {
500
+ return;
501
+ }
502
+ const pending = this.pending.get(requestId);
503
+ if (!pending || pending.predicate && !pending.predicate(message)) {
504
+ return;
505
+ }
506
+ clearTimeout(pending.timeout);
507
+ this.pending.delete(requestId);
508
+ pending.resolve(message);
509
+ }
510
+ rejectAllPending(reason) {
511
+ for (const [requestId, pending] of this.pending) {
512
+ clearTimeout(pending.timeout);
513
+ this.pending.delete(requestId);
514
+ pending.reject(new Error(reason));
515
+ }
516
+ }
517
+ handleDisconnect(channel, event) {
518
+ this.rejectAllPending("App-server socket closed");
519
+ if (this.explicitlyClosed || this.disconnectNotified)
520
+ return;
521
+ this.disconnectNotified = true;
522
+ for (const handler of this.disconnectHandlers) {
523
+ handler({ channel, event });
524
+ }
525
+ }
526
+ }
527
+ function createAppServerClient(options) {
528
+ return new AppServerClient(options);
529
+ }
530
+
531
+ //# debugId=0802352DE637866F64756E2164756E21
@@ -0,0 +1,11 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/types/app-server-info.ts", "../src/app-server-client.ts"],
4
+ "sourcesContent": [
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"
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;A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AAO;AAAA;",
9
+ "debugId": "0802352DE637866F64756E2164756E21",
10
+ "names": []
11
+ }
@@ -1,3 +1,17 @@
1
+ // src/types/app-server-info.ts
2
+ function isAppServerInfoResponseMessage(message) {
3
+ if (!message || typeof message !== "object" || Array.isArray(message)) {
4
+ return false;
5
+ }
6
+ const candidate = message;
7
+ const capabilities = candidate.capabilities;
8
+ if (!capabilities || typeof capabilities !== "object" || Array.isArray(capabilities)) {
9
+ return false;
10
+ }
11
+ const capabilityRecord = capabilities;
12
+ return candidate.type === "app_server_info_response" && typeof candidate.request_id === "string" && candidate.request_id.length > 0 && candidate.success === true && (candidate.backend === "local" || candidate.backend === "api") && typeof candidate.letta_code_version === "string" && typeof candidate.protocol_version === "number" && Number.isInteger(candidate.protocol_version) && typeof capabilityRecord.agent_management === "boolean" && typeof capabilityRecord.conversation_management === "boolean" && typeof capabilityRecord.memory_management === "boolean" && typeof capabilityRecord.runtime_start === "boolean" && typeof capabilityRecord.split_channels === "boolean";
13
+ }
14
+
1
15
  // src/app-server-client.ts
2
16
  var DEFAULT_REQUEST_TIMEOUT_MS = 30000;
3
17
  var WEBSOCKET_OPEN_STATE = 1;
@@ -198,11 +212,39 @@ class AppServerClient {
198
212
  return `${prefix}-${this.nextRequestNumber}`;
199
213
  }
200
214
  send(command) {
215
+ this.writeCommand(command);
216
+ }
217
+ writeCommand(command) {
201
218
  for (const handler of this.sendHandlers) {
202
219
  handler(command);
203
220
  }
204
221
  this.control.send(JSON.stringify(command));
205
222
  }
223
+ sendRaw(command) {
224
+ this.writeCommand(command);
225
+ }
226
+ requestRaw(command, options) {
227
+ const timeoutMs = options.timeoutMs ?? this.requestTimeoutMs;
228
+ return new Promise((resolve, reject) => {
229
+ const timeout = setTimeout(() => {
230
+ this.pending.delete(command.request_id);
231
+ reject(new Error(`Timed out waiting for ${command.request_id}`));
232
+ }, timeoutMs);
233
+ this.pending.set(command.request_id, {
234
+ resolve: (message) => resolve(message),
235
+ reject,
236
+ predicate: options.predicate,
237
+ timeout
238
+ });
239
+ try {
240
+ this.sendRaw(command);
241
+ } catch (error) {
242
+ clearTimeout(timeout);
243
+ this.pending.delete(command.request_id);
244
+ reject(error instanceof Error ? error : new Error(String(error)));
245
+ }
246
+ });
247
+ }
206
248
  request(commandOrType, bodyOrOptions = {}, maybeOptions = {}) {
207
249
  const isTypeRequest = typeof commandOrType === "string";
208
250
  const command = isTypeRequest ? {
@@ -238,7 +280,7 @@ class AppServerClient {
238
280
  request_id: this.nextRequestId("app-server-info")
239
281
  }, {
240
282
  ...options,
241
- predicate: (message) => message.type === "app_server_info_response"
283
+ predicate: isAppServerInfoResponseMessage
242
284
  });
243
285
  }
244
286
  runtimeStart(command, options = {}) {
@@ -449,8 +491,9 @@ function createAppServerClient(options) {
449
491
  }
450
492
  export {
451
493
  resolveAppServerChannelUrl,
494
+ isAppServerInfoResponseMessage,
452
495
  createAppServerClient,
453
496
  AppServerClient
454
497
  };
455
498
 
456
- //# debugId=8F8A6817B3ED4D9F64756E2164756E21
499
+ //# debugId=FC3843D3CF49A95464756E2164756E21
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/app-server-client.ts"],
3
+ "sources": ["../src/types/app-server-info.ts", "../src/app-server-client.ts"],
4
4
  "sourcesContent": [
5
- "import 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\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 protocol command is written to the control socket. */\nexport type AppServerSendHandler = (command: WsProtocolCommand) => 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\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 for (const handler of this.sendHandlers) {\n handler(command);\n }\n this.control.send(JSON.stringify(command));\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: (message): message is AppServerInfoResponseMessage =>\n message.type === \"app_server_info_response\",\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"
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
7
  ],
7
- "mappings": ";AAkIA,IAAM,6BAA6B;AACnC,IAAM,uBAAuB;AAE7B,SAAS,kBAAkB,GAA2C;AAAA,EACpE,OAAQ,WAA0D;AAAA;AAGpE,SAAS,gBAA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,qBAAqB,CACnC,SACiB;AAAA,EACjB,OAAO,IAAI,gBAAgB,OAAO;AAAA;",
9
+ "debugId": "FC3843D3CF49A95464756E2164756E21",
9
10
  "names": []
10
11
  }
@@ -1,5 +1,16 @@
1
+ export type { AppServerInfoResponseMessage } from "./types/app-server-info";
2
+ export { isAppServerInfoResponseMessage } from "./types/app-server-info";
1
3
  import type { AbortMessageCommand, AbortMessageResponseMessage, AppServerInfoResponseMessage, ConversationListCommand, ConversationListResponseMessage, ExternalToolCallRequestMessage, ExternalToolCallResult, InputCommand, RuntimeScope, RuntimeStartCommand, RuntimeStartResponseMessage, SyncCommand, SyncResponseMessage, WsProtocolCommand, WsProtocolMessage } from "./types/app-server-protocol";
2
4
  export type AppServerChannel = "control" | "stream";
5
+ export type AppServerRawCommand = Record<string, unknown> & {
6
+ type: string;
7
+ request_id?: string;
8
+ };
9
+ export type AppServerRawResponse = Record<string, unknown> & {
10
+ type: string;
11
+ request_id?: string;
12
+ };
13
+ export type AppServerSendCommand = WsProtocolCommand | AppServerRawCommand;
3
14
  /**
4
15
  * Receives every parsed protocol frame from both app-server websocket channels.
5
16
  * Treat this as the primary event stream: app-server may emit replay or turn
@@ -7,8 +18,8 @@ export type AppServerChannel = "control" | "stream";
7
18
  * stream channel. The channel argument is diagnostic/routing context.
8
19
  */
9
20
  export type AppServerMessageHandler = (message: WsProtocolMessage, channel: AppServerChannel) => void;
10
- /** Called synchronously before a protocol command is written to the control socket. */
11
- export type AppServerSendHandler = (command: WsProtocolCommand) => void;
21
+ /** Called synchronously before a typed or raw command is written to the control socket. */
22
+ export type AppServerSendHandler = (command: AppServerSendCommand) => void;
12
23
  export interface AppServerDisconnectEvent {
13
24
  channel: AppServerChannel;
14
25
  event: unknown;
@@ -53,6 +64,10 @@ export type AppServerRequestCommandWithId = AppServerRequestCommand & {
53
64
  export type AppServerRequestBody = Record<string, unknown> & {
54
65
  request_id?: string;
55
66
  };
67
+ export interface AppServerRawRequestOptions<TResponse extends AppServerRawResponse> {
68
+ timeoutMs?: number;
69
+ predicate: (message: unknown) => message is TResponse;
70
+ }
56
71
  export type AppServerTurnCompletionSource = "stop_reason" | "loop_status_waiting_on_approval" | "loop_status_waiting_fallback";
57
72
  export interface AppServerTurnResult {
58
73
  runtime: RuntimeScope;
@@ -92,6 +107,19 @@ export declare class AppServerClient {
92
107
  onDisconnect(handler: AppServerDisconnectHandler): () => void;
93
108
  nextRequestId(prefix?: string): string;
94
109
  send(command: WsProtocolCommand): void;
110
+ private writeCommand;
111
+ /**
112
+ * Send a forward-compatible protocol command from a compatibility adapter.
113
+ * Prefer the typed wrappers above this boundary for normal product code.
114
+ */
115
+ sendRaw(command: AppServerRawCommand): void;
116
+ /**
117
+ * Request a forward-compatible response without mirroring the full protocol
118
+ * union in a downstream compatibility adapter.
119
+ */
120
+ requestRaw<TResponse extends AppServerRawResponse>(command: AppServerRawCommand & {
121
+ request_id: string;
122
+ }, options: AppServerRawRequestOptions<TResponse>): Promise<TResponse>;
95
123
  request<TMessage extends WsProtocolMessage = WsProtocolMessage>(command: AppServerRequestCommandWithId, options?: AppServerRequestOptions<TMessage>): Promise<TMessage>;
96
124
  request<TType extends AppServerRequestCommand["type"], TMessage extends WsProtocolMessage = WsProtocolMessage>(type: TType, body?: AppServerRequestBody, options?: AppServerRequestOptions<TMessage>): Promise<TMessage>;
97
125
  info(options?: Omit<AppServerRequestOptions<AppServerInfoResponseMessage>, "predicate">): Promise<AppServerInfoResponseMessage>;
@@ -1 +1 @@
1
- {"version":3,"file":"app-server-client.d.ts","sourceRoot":"","sources":["../../src/app-server-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,2BAA2B,EAC3B,4BAA4B,EAC5B,uBAAuB,EACvB,+BAA+B,EAC/B,8BAA8B,EAC9B,sBAAsB,EACtB,YAAY,EAEZ,YAAY,EACZ,mBAAmB,EACnB,2BAA2B,EAE3B,WAAW,EACX,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,E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AAO,CAAC,gBAAgB;CAQzB;AAED,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,sBAAsB,GAC9B,eAAe,CAEjB"}
@@ -11,7 +11,8 @@ export interface AppServerInfoResponseMessage {
11
11
  success: true;
12
12
  backend: "local" | "api";
13
13
  letta_code_version: string;
14
- protocol_version: typeof APP_SERVER_PROTOCOL_VERSION;
14
+ /** Wire value reported by the server; clients compare it with their supported version. */
15
+ protocol_version: number;
15
16
  capabilities: {
16
17
  agent_management: boolean;
17
18
  conversation_management: boolean;
@@ -20,4 +21,5 @@ export interface AppServerInfoResponseMessage {
20
21
  split_channels: boolean;
21
22
  };
22
23
  }
24
+ export declare function isAppServerInfoResponseMessage(message: unknown): message is AppServerInfoResponseMessage;
23
25
  //# sourceMappingURL=app-server-info.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"app-server-info.d.ts","sourceRoot":"","sources":["../../../src/types/app-server-info.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,2BAA2B,IAAI,CAAC;AAE7C,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,iBAAiB,CAAC;IACxB,2DAA2D;IAC3D,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,4BAA4B;IAC3C,IAAI,EAAE,0BAA0B,CAAC;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,gFAAgF;IAChF,OAAO,EAAE,IAAI,CAAC;IACd,OAAO,EAAE,OAAO,GAAG,KAAK,CAAC;IACzB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,gBAAgB,EAAE,OAAO,2BAA2B,CAAC;IACrD,YAAY,EAAE;QACZ,gBAAgB,EAAE,OAAO,CAAC;QAC1B,uBAAuB,EAAE,OAAO,CAAC;QACjC,iBAAiB,EAAE,OAAO,CAAC;QAC3B,aAAa,EAAE,OAAO,CAAC;QACvB,cAAc,EAAE,OAAO,CAAC;KACzB,CAAC;CACH"}
1
+ {"version":3,"file":"app-server-info.d.ts","sourceRoot":"","sources":["../../../src/types/app-server-info.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,2BAA2B,IAAI,CAAC;AAE7C,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,iBAAiB,CAAC;IACxB,2DAA2D;IAC3D,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,4BAA4B;IAC3C,IAAI,EAAE,0BAA0B,CAAC;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,gFAAgF;IAChF,OAAO,EAAE,IAAI,CAAC;IACd,OAAO,EAAE,OAAO,GAAG,KAAK,CAAC;IACzB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,0FAA0F;IAC1F,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE;QACZ,gBAAgB,EAAE,OAAO,CAAC;QAC1B,uBAAuB,EAAE,OAAO,CAAC;QACjC,iBAAiB,EAAE,OAAO,CAAC;QAC3B,aAAa,EAAE,OAAO,CAAC;QACvB,cAAc,EAAE,OAAO,CAAC;KACzB,CAAC;CACH;AAED,wBAAgB,8BAA8B,CAC5C,OAAO,EAAE,OAAO,GACf,OAAO,IAAI,4BAA4B,CA+BzC"}
package/letta.js CHANGED
@@ -5462,7 +5462,7 @@ var package_default;
5462
5462
  var init_package = __esm(() => {
5463
5463
  package_default = {
5464
5464
  name: "@letta-ai/letta-code",
5465
- version: "0.29.2",
5465
+ version: "0.29.3",
5466
5466
  description: "Letta Code is a CLI tool for interacting with stateful Letta agents from the terminal.",
5467
5467
  type: "module",
5468
5468
  packageManager: "bun@1.3.0",
@@ -5480,6 +5480,8 @@ var init_package = __esm(() => {
5480
5480
  "vendor",
5481
5481
  "dist/app-server-client.js",
5482
5482
  "dist/app-server-client.js.map",
5483
+ "dist/app-server-client.cjs",
5484
+ "dist/app-server-client.cjs.map",
5483
5485
  "dist/agent-presets.js",
5484
5486
  "dist/agent-presets.js.map",
5485
5487
  "dist/channels-public.js",
@@ -5497,7 +5499,9 @@ var init_package = __esm(() => {
5497
5499
  "./app-server-client": {
5498
5500
  types: "./dist/types/app-server-client.d.ts",
5499
5501
  browser: "./dist/app-server-client.js",
5500
- import: "./dist/app-server-client.js"
5502
+ import: "./dist/app-server-client.js",
5503
+ require: "./dist/app-server-client.cjs",
5504
+ default: "./dist/app-server-client.js"
5501
5505
  },
5502
5506
  "./protocol": {
5503
5507
  types: "./dist/types/types/protocol.d.ts"
@@ -541228,4 +541232,4 @@ function registerBunOAuthFlows() {
541228
541232
  registerBunOAuthFlows();
541229
541233
  await init_src5().then(() => exports_src2);
541230
541234
 
541231
- //# debugId=5A6EDC9BFD941DD864756E2164756E21
541235
+ //# debugId=CFB812BEB8775E6764756E2164756E21
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@letta-ai/letta-code",
3
- "version": "0.29.2",
3
+ "version": "0.29.3",
4
4
  "description": "Letta Code is a CLI tool for interacting with stateful Letta agents from the terminal.",
5
5
  "type": "module",
6
6
  "packageManager": "bun@1.3.0",
@@ -18,6 +18,8 @@
18
18
  "vendor",
19
19
  "dist/app-server-client.js",
20
20
  "dist/app-server-client.js.map",
21
+ "dist/app-server-client.cjs",
22
+ "dist/app-server-client.cjs.map",
21
23
  "dist/agent-presets.js",
22
24
  "dist/agent-presets.js.map",
23
25
  "dist/channels-public.js",
@@ -35,7 +37,9 @@
35
37
  "./app-server-client": {
36
38
  "types": "./dist/types/app-server-client.d.ts",
37
39
  "browser": "./dist/app-server-client.js",
38
- "import": "./dist/app-server-client.js"
40
+ "import": "./dist/app-server-client.js",
41
+ "require": "./dist/app-server-client.cjs",
42
+ "default": "./dist/app-server-client.js"
39
43
  },
40
44
  "./protocol": {
41
45
  "types": "./dist/types/types/protocol.d.ts"