@dexto/server 1.6.20 → 1.6.22

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.
Files changed (133) hide show
  1. package/dist/a2a/jsonrpc/methods.cjs +1 -1
  2. package/dist/a2a/jsonrpc/methods.d.ts +14 -4
  3. package/dist/a2a/jsonrpc/methods.d.ts.map +1 -1
  4. package/dist/a2a/jsonrpc/methods.js +1 -1
  5. package/dist/approval/wire-approval-events.cjs +44 -0
  6. package/dist/approval/wire-approval-events.d.ts +4 -0
  7. package/dist/approval/wire-approval-events.d.ts.map +1 -0
  8. package/dist/approval/wire-approval-events.js +20 -0
  9. package/dist/events/session-sse-subscriber.cjs +167 -0
  10. package/dist/events/session-sse-subscriber.d.ts +13 -0
  11. package/dist/events/session-sse-subscriber.d.ts.map +1 -0
  12. package/dist/events/session-sse-subscriber.js +143 -0
  13. package/dist/hono/__tests__/test-fixtures.cjs +8 -0
  14. package/dist/hono/__tests__/test-fixtures.d.ts +1 -0
  15. package/dist/hono/__tests__/test-fixtures.d.ts.map +1 -1
  16. package/dist/hono/__tests__/test-fixtures.js +8 -0
  17. package/dist/hono/index.cjs +40 -8
  18. package/dist/hono/index.d.ts +45 -4531
  19. package/dist/hono/index.d.ts.map +1 -1
  20. package/dist/hono/index.js +43 -9
  21. package/dist/hono/node/index.cjs +51 -6
  22. package/dist/hono/node/index.d.ts.map +1 -1
  23. package/dist/hono/node/index.js +51 -6
  24. package/dist/hono/routes/a2a-jsonrpc.d.ts.map +1 -1
  25. package/dist/hono/routes/a2a-tasks.cjs +158 -32
  26. package/dist/hono/routes/a2a-tasks.d.ts +1 -502
  27. package/dist/hono/routes/a2a-tasks.d.ts.map +1 -1
  28. package/dist/hono/routes/a2a-tasks.js +162 -32
  29. package/dist/hono/routes/a2a.d.ts.map +1 -1
  30. package/dist/hono/routes/agents.cjs +410 -329
  31. package/dist/hono/routes/agents.d.ts +16043 -68
  32. package/dist/hono/routes/agents.d.ts.map +1 -1
  33. package/dist/hono/routes/agents.js +418 -330
  34. package/dist/hono/routes/approvals.cjs +102 -88
  35. package/dist/hono/routes/approvals.d.ts +2089 -142
  36. package/dist/hono/routes/approvals.d.ts.map +1 -1
  37. package/dist/hono/routes/approvals.js +108 -89
  38. package/dist/hono/routes/dexto-auth.cjs +40 -33
  39. package/dist/hono/routes/dexto-auth.d.ts +401 -2
  40. package/dist/hono/routes/dexto-auth.d.ts.map +1 -1
  41. package/dist/hono/routes/dexto-auth.js +40 -33
  42. package/dist/hono/routes/discovery.cjs +16 -14
  43. package/dist/hono/routes/discovery.d.ts +586 -1
  44. package/dist/hono/routes/discovery.d.ts.map +1 -1
  45. package/dist/hono/routes/discovery.js +16 -14
  46. package/dist/hono/routes/greeting.cjs +26 -22
  47. package/dist/hono/routes/greeting.d.ts +787 -3
  48. package/dist/hono/routes/greeting.d.ts.map +1 -1
  49. package/dist/hono/routes/greeting.js +26 -22
  50. package/dist/hono/routes/health.d.ts +1 -1
  51. package/dist/hono/routes/key.cjs +60 -52
  52. package/dist/hono/routes/key.d.ts +1597 -1
  53. package/dist/hono/routes/key.d.ts.map +1 -1
  54. package/dist/hono/routes/key.js +60 -52
  55. package/dist/hono/routes/llm.cjs +382 -349
  56. package/dist/hono/routes/llm.d.ts +12148 -98
  57. package/dist/hono/routes/llm.d.ts.map +1 -1
  58. package/dist/hono/routes/llm.js +386 -349
  59. package/dist/hono/routes/mcp.cjs +257 -226
  60. package/dist/hono/routes/mcp.d.ts +6605 -309
  61. package/dist/hono/routes/mcp.d.ts.map +1 -1
  62. package/dist/hono/routes/mcp.js +263 -225
  63. package/dist/hono/routes/memory.cjs +102 -89
  64. package/dist/hono/routes/memory.d.ts +5368 -4
  65. package/dist/hono/routes/memory.d.ts.map +1 -1
  66. package/dist/hono/routes/memory.js +108 -90
  67. package/dist/hono/routes/messages.cjs +189 -191
  68. package/dist/hono/routes/messages.d.ts +3900 -12
  69. package/dist/hono/routes/messages.d.ts.map +1 -1
  70. package/dist/hono/routes/messages.js +192 -191
  71. package/dist/hono/routes/models.cjs +106 -64
  72. package/dist/hono/routes/models.d.ts +2875 -2
  73. package/dist/hono/routes/models.d.ts.map +1 -1
  74. package/dist/hono/routes/models.js +108 -64
  75. package/dist/hono/routes/openrouter.cjs +79 -65
  76. package/dist/hono/routes/openrouter.d.ts +854 -1
  77. package/dist/hono/routes/openrouter.d.ts.map +1 -1
  78. package/dist/hono/routes/openrouter.js +79 -65
  79. package/dist/hono/routes/prompts.cjs +136 -109
  80. package/dist/hono/routes/prompts.d.ts +2818 -10
  81. package/dist/hono/routes/prompts.d.ts.map +1 -1
  82. package/dist/hono/routes/prompts.js +138 -109
  83. package/dist/hono/routes/queue.cjs +133 -120
  84. package/dist/hono/routes/queue.d.ts +5240 -11
  85. package/dist/hono/routes/queue.d.ts.map +1 -1
  86. package/dist/hono/routes/queue.js +136 -120
  87. package/dist/hono/routes/resources.cjs +65 -46
  88. package/dist/hono/routes/resources.d.ts +1983 -5
  89. package/dist/hono/routes/resources.d.ts.map +1 -1
  90. package/dist/hono/routes/resources.js +72 -47
  91. package/dist/hono/routes/schedules.cjs +233 -226
  92. package/dist/hono/routes/schedules.d.ts +4198 -22
  93. package/dist/hono/routes/schedules.d.ts.map +1 -1
  94. package/dist/hono/routes/schedules.js +233 -226
  95. package/dist/hono/routes/search.cjs +34 -30
  96. package/dist/hono/routes/search.d.ts +3094 -17
  97. package/dist/hono/routes/search.d.ts.map +1 -1
  98. package/dist/hono/routes/search.js +40 -31
  99. package/dist/hono/routes/sessions.cjs +491 -393
  100. package/dist/hono/routes/sessions.d.ts +18263 -65
  101. package/dist/hono/routes/sessions.d.ts.map +1 -1
  102. package/dist/hono/routes/sessions.js +497 -395
  103. package/dist/hono/routes/static.d.ts.map +1 -1
  104. package/dist/hono/routes/system-prompt.cjs +57 -61
  105. package/dist/hono/routes/system-prompt.d.ts +1228 -2
  106. package/dist/hono/routes/system-prompt.d.ts.map +1 -1
  107. package/dist/hono/routes/system-prompt.js +58 -62
  108. package/dist/hono/routes/tools.cjs +29 -34
  109. package/dist/hono/routes/tools.d.ts +1755 -6
  110. package/dist/hono/routes/tools.d.ts.map +1 -1
  111. package/dist/hono/routes/tools.js +33 -33
  112. package/dist/hono/routes/webhooks.cjs +115 -123
  113. package/dist/hono/routes/webhooks.d.ts +2501 -11
  114. package/dist/hono/routes/webhooks.d.ts.map +1 -1
  115. package/dist/hono/routes/webhooks.js +120 -124
  116. package/dist/hono/routes/workspaces.cjs +84 -79
  117. package/dist/hono/routes/workspaces.d.ts +2093 -2
  118. package/dist/hono/routes/workspaces.d.ts.map +1 -1
  119. package/dist/hono/routes/workspaces.js +89 -80
  120. package/dist/hono/schemas/responses.cjs +463 -260
  121. package/dist/hono/schemas/responses.d.ts +1893 -209
  122. package/dist/hono/schemas/responses.d.ts.map +1 -1
  123. package/dist/hono/schemas/responses.js +203 -14
  124. package/dist/hono/start-server.cjs +9 -0
  125. package/dist/hono/start-server.d.ts.map +1 -1
  126. package/dist/hono/start-server.js +9 -0
  127. package/dist/hono/types.d.ts +11 -0
  128. package/dist/hono/types.d.ts.map +1 -1
  129. package/dist/index.cjs +5 -1
  130. package/dist/index.d.ts +2 -0
  131. package/dist/index.d.ts.map +1 -1
  132. package/dist/index.js +2 -0
  133. package/package.json +7 -7
@@ -1 +1 @@
1
- {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../../src/hono/routes/messages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAkB,MAAM,mBAAmB,CAAC;AAGhE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAC;AAQlF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAqB9C,wBAAgB,oBAAoB,CAChC,QAAQ,EAAE,UAAU,EACpB,mBAAmB,CAAC,EAAE,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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O,eAAe,CAAC,CAAA;CAAE,EACzC,0BAA0B,CAAC,OAAO,UAAU,CAAC,CAChD,CAAC;AAEF,KAAK,wBAAwB,GAAG,QAAQ,CACpC,MAAM,EACN,iBAAiB,EACjB;IAAE,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAA;CAAE,EAC3C,0BAA0B,CAAC,OAAO,kBAAkB,CAAC,CACxD,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAC1B,kBAAkB,GAClB,sBAAsB,GACtB,gBAAgB,GAChB,wBAAwB,CAAC"}
@@ -3,6 +3,9 @@ import { streamSSE } from "hono/streaming";
3
3
  import { LLM_PROVIDERS } from "@dexto/core";
4
4
  import {
5
5
  ApiErrorResponseSchema,
6
+ BadRequestErrorResponse,
7
+ InternalErrorResponse,
8
+ NotFoundErrorResponse,
6
9
  PricingStatusSchema,
7
10
  RequestContentSchema,
8
11
  TokenUsageSchema,
@@ -15,158 +18,166 @@ const MessageBodySchema = z.object({
15
18
  const ResetBodySchema = z.object({
16
19
  sessionId: z.string().min(1, "Session ID is required").describe("The ID of the session to reset")
17
20
  }).describe("Request body for resetting a conversation");
18
- function createMessagesRouter(getAgent, approvalCoordinator) {
19
- const app = new OpenAPIHono();
20
- const messageRoute = createRoute({
21
- method: "post",
22
- path: "/message",
23
- summary: "Send Message (async)",
24
- description: "Sends a message and returns immediately. The full response will be sent over SSE",
25
- tags: ["messages"],
26
- request: {
27
- body: {
28
- content: { "application/json": { schema: MessageBodySchema } }
29
- }
30
- },
31
- responses: {
32
- 202: {
33
- description: "Message accepted for async processing; subscribe to SSE for results",
34
- content: {
35
- "application/json": {
36
- schema: z.object({
37
- accepted: z.literal(true).describe("Indicates request was accepted"),
38
- sessionId: z.string().describe("Session ID used for this message")
39
- }).strict()
40
- }
21
+ const MessageAcceptedResponseSchema = z.object({
22
+ accepted: z.literal(true).describe("Indicates request was accepted"),
23
+ sessionId: z.string().describe("Session ID used for this message")
24
+ }).strict().describe("Asynchronous message acceptance response");
25
+ const MessageSyncResponseSchema = z.object({
26
+ response: z.string().describe("Agent response text"),
27
+ sessionId: z.string().describe("Session ID used for this message"),
28
+ tokenUsage: TokenUsageSchema.optional().describe("Token usage statistics"),
29
+ messageId: z.string().uuid().optional().describe("Assistant message ID for this response"),
30
+ usageScopeId: z.string().optional().describe("Optional usage scope identifier for runtime-scoped metering"),
31
+ estimatedCost: z.number().nonnegative().optional().describe("Estimated cost in USD for this response"),
32
+ pricingStatus: PricingStatusSchema.optional().describe(
33
+ "Whether pricing was resolved for this response"
34
+ ),
35
+ reasoning: z.string().optional().describe("Extended thinking content from reasoning models"),
36
+ model: z.string().optional().describe("Model used for this response"),
37
+ provider: z.enum(LLM_PROVIDERS).optional().describe("LLM provider")
38
+ }).strict().describe("Synchronous message response");
39
+ const ResetResponseSchema = z.object({
40
+ status: z.string().describe("Status message indicating reset was initiated"),
41
+ sessionId: z.string().describe("Session ID that was reset")
42
+ }).strict().describe("Session reset response");
43
+ const MessageStreamBusyResponseSchema = z.object({
44
+ busy: z.literal(true).describe("Indicates session is busy"),
45
+ sessionId: z.string().describe("The session ID"),
46
+ queueLength: z.number().describe("Current number of messages in queue"),
47
+ hint: z.string().describe("Instructions for the client")
48
+ }).strict().describe("Busy response for streaming requests");
49
+ const messageRoute = createRoute({
50
+ method: "post",
51
+ path: "/message",
52
+ summary: "Send Message (async)",
53
+ description: "Sends a message and returns immediately. The full response will be sent over SSE",
54
+ tags: ["messages"],
55
+ request: {
56
+ body: {
57
+ content: { "application/json": { schema: MessageBodySchema } }
58
+ }
59
+ },
60
+ responses: {
61
+ 202: {
62
+ description: "Message accepted for async processing; subscribe to SSE for results",
63
+ content: {
64
+ "application/json": {
65
+ schema: MessageAcceptedResponseSchema
41
66
  }
42
- },
43
- 400: {
44
- description: "Validation error",
45
- content: { "application/json": { schema: ApiErrorResponseSchema } }
46
67
  }
47
- }
48
- });
49
- const messageSyncRoute = createRoute({
50
- method: "post",
51
- path: "/message-sync",
52
- summary: "Send Message (sync)",
53
- description: "Sends a message and waits for the full response",
54
- tags: ["messages"],
55
- request: {
56
- body: { content: { "application/json": { schema: MessageBodySchema } } }
57
68
  },
58
- responses: {
59
- 200: {
60
- description: "Synchronous response",
61
- content: {
62
- "application/json": {
63
- schema: z.object({
64
- response: z.string().describe("Agent response text"),
65
- sessionId: z.string().describe("Session ID used for this message"),
66
- tokenUsage: TokenUsageSchema.optional().describe("Token usage statistics"),
67
- messageId: z.string().uuid().optional().describe("Assistant message ID for this response"),
68
- usageScopeId: z.string().optional().describe(
69
- "Optional usage scope identifier for runtime-scoped metering"
70
- ),
71
- estimatedCost: z.number().nonnegative().optional().describe("Estimated cost in USD for this response"),
72
- pricingStatus: PricingStatusSchema.optional().describe(
73
- "Whether pricing was resolved for this response"
74
- ),
75
- reasoning: z.string().optional().describe("Extended thinking content from reasoning models"),
76
- model: z.string().optional().describe("Model used for this response"),
77
- provider: z.enum(LLM_PROVIDERS).optional().describe("LLM provider")
78
- }).strict()
79
- }
69
+ 400: {
70
+ description: "Validation error",
71
+ content: { "application/json": { schema: ApiErrorResponseSchema } }
72
+ },
73
+ 500: InternalErrorResponse
74
+ }
75
+ });
76
+ const messageSyncRoute = createRoute({
77
+ method: "post",
78
+ path: "/message-sync",
79
+ summary: "Send Message (sync)",
80
+ description: "Sends a message and waits for the full response",
81
+ tags: ["messages"],
82
+ request: {
83
+ body: { content: { "application/json": { schema: MessageBodySchema } } }
84
+ },
85
+ responses: {
86
+ 200: {
87
+ description: "Synchronous response",
88
+ content: {
89
+ "application/json": {
90
+ schema: MessageSyncResponseSchema
80
91
  }
81
- },
82
- 400: {
83
- description: "Validation error",
84
- content: { "application/json": { schema: ApiErrorResponseSchema } }
85
92
  }
86
- }
87
- });
88
- const resetRoute = createRoute({
89
- method: "post",
90
- path: "/reset",
91
- summary: "Reset Conversation",
92
- description: "Resets the conversation history for a given session",
93
- tags: ["messages"],
94
- request: {
95
- body: { content: { "application/json": { schema: ResetBodySchema } } }
96
93
  },
97
- responses: {
98
- 200: {
99
- description: "Reset initiated",
100
- content: {
101
- "application/json": {
102
- schema: z.object({
103
- status: z.string().describe("Status message indicating reset was initiated"),
104
- sessionId: z.string().describe("Session ID that was reset")
105
- }).strict()
106
- }
94
+ 400: {
95
+ description: "Validation error",
96
+ content: { "application/json": { schema: ApiErrorResponseSchema } }
97
+ },
98
+ 500: InternalErrorResponse
99
+ }
100
+ });
101
+ const resetRoute = createRoute({
102
+ method: "post",
103
+ path: "/reset",
104
+ summary: "Reset Conversation",
105
+ description: "Resets the conversation history for a given session",
106
+ tags: ["messages"],
107
+ request: {
108
+ body: { content: { "application/json": { schema: ResetBodySchema } } }
109
+ },
110
+ responses: {
111
+ 200: {
112
+ description: "Reset initiated",
113
+ content: {
114
+ "application/json": {
115
+ schema: ResetResponseSchema
107
116
  }
108
117
  }
109
- }
110
- });
111
- const messageStreamRoute = createRoute({
112
- method: "post",
113
- path: "/message-stream",
114
- summary: "Stream message response",
115
- description: "Sends a message and streams the response via Server-Sent Events (SSE). Returns SSE stream directly in response. Events include llm:thinking, llm:chunk, llm:tool-call, llm:tool-result, llm:response, and llm:error. Final llm:response events include token usage, assistant message ID, and pricing metadata when available. If the session is busy processing another message, returns 202 with queue information.",
116
- tags: ["messages"],
117
- request: {
118
- body: {
119
- content: { "application/json": { schema: MessageBodySchema } }
120
- }
121
118
  },
122
- responses: {
123
- 200: {
124
- description: "SSE stream of agent events. Standard SSE format with event type and JSON data.",
125
- headers: {
126
- "Content-Type": {
127
- description: "SSE content type",
128
- schema: { type: "string", example: "text/event-stream" }
129
- },
130
- "Cache-Control": {
131
- description: "Disable caching for stream",
132
- schema: { type: "string", example: "no-cache" }
133
- },
134
- Connection: {
135
- description: "Keep connection alive for streaming",
136
- schema: { type: "string", example: "keep-alive" }
137
- },
138
- "X-Accel-Buffering": {
139
- description: "Disable nginx buffering",
140
- schema: { type: "string", example: "no" }
141
- }
119
+ 400: BadRequestErrorResponse,
120
+ 404: NotFoundErrorResponse,
121
+ 500: InternalErrorResponse
122
+ }
123
+ });
124
+ const messageStreamRoute = createRoute({
125
+ method: "post",
126
+ path: "/message-stream",
127
+ summary: "Stream message response",
128
+ description: "Sends a message and streams the response via Server-Sent Events (SSE). Returns SSE stream directly in response. Events include llm:thinking, llm:chunk, llm:tool-call, llm:tool-result, llm:response, and llm:error. Final llm:response events include token usage, assistant message ID, and pricing metadata when available. If the session is busy processing another message, returns 202 with queue information.",
129
+ tags: ["messages"],
130
+ request: {
131
+ body: {
132
+ content: { "application/json": { schema: MessageBodySchema } }
133
+ }
134
+ },
135
+ responses: {
136
+ 200: {
137
+ description: "SSE stream of agent events. Standard SSE format with event type and JSON data.",
138
+ headers: {
139
+ "Content-Type": {
140
+ description: "SSE content type",
141
+ schema: { type: "string", example: "text/event-stream" }
142
142
  },
143
- content: {
144
- "text/event-stream": {
145
- schema: z.string().describe(
146
- "Server-Sent Events stream. Events: llm:thinking (start), llm:chunk (text fragments), llm:tool-call (tool execution), llm:tool-result (tool output), llm:response (final), llm:error (errors). Final llm:response payloads include token usage, assistant message ID, and pricing metadata when available."
147
- )
148
- }
143
+ "Cache-Control": {
144
+ description: "Disable caching for stream",
145
+ schema: { type: "string", example: "no-cache" }
146
+ },
147
+ Connection: {
148
+ description: "Keep connection alive for streaming",
149
+ schema: { type: "string", example: "keep-alive" }
150
+ },
151
+ "X-Accel-Buffering": {
152
+ description: "Disable nginx buffering",
153
+ schema: { type: "string", example: "no" }
149
154
  }
150
155
  },
151
- 202: {
152
- description: "Session is busy processing another message. Use the queue endpoints to manage pending messages.",
153
- content: {
154
- "application/json": {
155
- schema: z.object({
156
- busy: z.literal(true).describe("Indicates session is busy"),
157
- sessionId: z.string().describe("The session ID"),
158
- queueLength: z.number().describe("Current number of messages in queue"),
159
- hint: z.string().describe("Instructions for the client")
160
- }).strict()
161
- }
156
+ content: {
157
+ "text/event-stream": {
158
+ schema: z.string().describe(
159
+ "Server-Sent Events stream. Events: llm:thinking (start), llm:chunk (text fragments), llm:tool-call (tool execution), llm:tool-result (tool output), llm:response (final), llm:error (errors). Final llm:response payloads include token usage, assistant message ID, and pricing metadata when available."
160
+ )
162
161
  }
163
- },
164
- 400: {
165
- description: "Validation error",
166
- content: { "application/json": { schema: ApiErrorResponseSchema } }
167
162
  }
168
- }
169
- });
163
+ },
164
+ 202: {
165
+ description: "Session is busy processing another message. Use the queue endpoints to manage pending messages.",
166
+ content: {
167
+ "application/json": {
168
+ schema: MessageStreamBusyResponseSchema
169
+ }
170
+ }
171
+ },
172
+ 400: {
173
+ description: "Validation error",
174
+ content: { "application/json": { schema: ApiErrorResponseSchema } }
175
+ },
176
+ 500: InternalErrorResponse
177
+ }
178
+ });
179
+ function createMessagesRouter(getAgent, _approvalCoordinator) {
180
+ const app = new OpenAPIHono();
170
181
  return app.openapi(messageRoute, async (ctx) => {
171
182
  const agent = await getAgent(ctx);
172
183
  agent.logger.info("Received message via POST /api/message");
@@ -206,7 +217,7 @@ function createMessagesRouter(getAgent, approvalCoordinator) {
206
217
  agent.logger.info("Received request via POST /api/reset");
207
218
  const { sessionId } = ctx.req.valid("json");
208
219
  await agent.resetConversation(sessionId);
209
- return ctx.json({ status: "reset initiated", sessionId });
220
+ return ctx.json({ status: "reset initiated", sessionId }, 200);
210
221
  }).openapi(messageStreamRoute, async (ctx) => {
211
222
  const agent = await getAgent(ctx);
212
223
  const { content: rawContent, sessionId } = ctx.req.valid("json");
@@ -226,42 +237,43 @@ function createMessagesRouter(getAgent, approvalCoordinator) {
226
237
  }
227
238
  const abortController = new AbortController();
228
239
  const { signal } = abortController;
229
- const iterator = await agent.stream(content, sessionId, { signal });
240
+ const requestDisconnectSignal = ctx.req.raw.signal;
241
+ const streamWithDisconnectSignal = agent.stream.bind(agent);
242
+ const iterator = await streamWithDisconnectSignal(content, sessionId, {
243
+ disconnectSignal: signal
244
+ });
230
245
  return streamSSE(ctx, async (stream) => {
231
- const pendingApprovalEvents = [];
232
- if (approvalCoordinator) {
233
- approvalCoordinator.onRequest(
234
- (request) => {
235
- if (request.sessionId === sessionId) {
236
- pendingApprovalEvents.push({
237
- event: "approval:request",
238
- data: request
239
- });
240
- }
241
- },
242
- { signal }
243
- );
244
- approvalCoordinator.onResponse(
245
- (response) => {
246
- if (response.sessionId === sessionId) {
247
- pendingApprovalEvents.push({
248
- event: "approval:response",
249
- data: response
250
- });
251
- }
252
- },
253
- { signal }
254
- );
246
+ const abortOnDisconnect = () => {
247
+ abortController.abort();
248
+ };
249
+ stream.onAbort(abortOnDisconnect);
250
+ requestDisconnectSignal.addEventListener("abort", abortOnDisconnect, {
251
+ once: true
252
+ });
253
+ if (requestDisconnectSignal.aborted) {
254
+ abortOnDisconnect();
255
255
  }
256
+ let writeChain = Promise.resolve();
257
+ const enqueueSSEWrite = (event, data) => {
258
+ writeChain = writeChain.then(async () => {
259
+ if (signal.aborted) {
260
+ return;
261
+ }
262
+ await stream.writeSSE({
263
+ event,
264
+ data: JSON.stringify(data)
265
+ });
266
+ }).catch((error) => {
267
+ if (!signal.aborted) {
268
+ agent.logger.warn(
269
+ `Failed to write SSE event '${event}': ${error instanceof Error ? error.message : String(error)}`
270
+ );
271
+ }
272
+ });
273
+ return writeChain;
274
+ };
256
275
  try {
257
276
  for await (const event of iterator) {
258
- while (pendingApprovalEvents.length > 0) {
259
- const approvalEvent = pendingApprovalEvents.shift();
260
- await stream.writeSSE({
261
- event: approvalEvent.event,
262
- data: JSON.stringify(approvalEvent.data)
263
- });
264
- }
265
277
  const eventData = event.name === "llm:error" && event.error instanceof Error ? {
266
278
  ...event,
267
279
  error: {
@@ -270,31 +282,20 @@ function createMessagesRouter(getAgent, approvalCoordinator) {
270
282
  stack: event.error.stack
271
283
  }
272
284
  } : event;
273
- await stream.writeSSE({
274
- event: event.name,
275
- data: JSON.stringify(eventData)
276
- });
277
- }
278
- while (pendingApprovalEvents.length > 0) {
279
- const approvalEvent = pendingApprovalEvents.shift();
280
- await stream.writeSSE({
281
- event: approvalEvent.event,
282
- data: JSON.stringify(approvalEvent.data)
283
- });
285
+ await enqueueSSEWrite(event.name, eventData);
284
286
  }
285
287
  } catch (error) {
286
- await stream.writeSSE({
287
- event: "llm:error",
288
- data: JSON.stringify({
289
- error: {
290
- message: error instanceof Error ? error.message : String(error)
291
- },
292
- recoverable: false,
293
- sessionId
294
- })
288
+ await enqueueSSEWrite("llm:error", {
289
+ error: {
290
+ message: error instanceof Error ? error.message : String(error)
291
+ },
292
+ recoverable: false,
293
+ sessionId
295
294
  });
296
295
  } finally {
296
+ requestDisconnectSignal.removeEventListener("abort", abortOnDisconnect);
297
297
  abortController.abort();
298
+ await writeChain;
298
299
  }
299
300
  });
300
301
  });