@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
@@ -68,423 +68,456 @@ function mapSessionMetadata(sessionId, metadata, defaults) {
68
68
  parentSessionId: metadata?.parentSessionId ?? defaults?.parentSessionId ?? null
69
69
  };
70
70
  }
71
- function createSessionsRouter(getAgent) {
72
- const app = new import_zod_openapi.OpenAPIHono({
73
- defaultHook: (result, ctx) => {
74
- if (!result.success) {
75
- const issues = (0, import_core.zodToIssues)(result.error);
76
- return (0, import_error.handleHonoError)(
77
- ctx,
78
- new import_core.DextoRuntimeError(
79
- "validation_failed",
80
- "validation",
81
- import_core.ErrorType.USER,
82
- issues[0]?.message ?? "Validation failed",
83
- { issues }
84
- )
85
- );
86
- }
87
- }
88
- });
89
- app.onError((err, ctx) => (0, import_error.handleHonoError)(ctx, err));
90
- const listRoute = (0, import_zod_openapi.createRoute)({
91
- method: "get",
92
- path: "/sessions",
93
- summary: "List Sessions",
94
- description: "Retrieves a list of all active sessions",
95
- tags: ["sessions"],
96
- responses: {
97
- 200: {
98
- description: "List of all active sessions",
99
- content: {
100
- "application/json": {
101
- schema: import_zod_openapi.z.object({
102
- sessions: import_zod_openapi.z.array(import_responses.SessionMetadataSchema).describe("Array of session metadata objects")
103
- }).strict()
104
- }
71
+ const listRoute = (0, import_zod_openapi.createRoute)({
72
+ method: "get",
73
+ path: "/sessions",
74
+ summary: "List Sessions",
75
+ description: "Retrieves a list of all active sessions",
76
+ tags: ["sessions"],
77
+ responses: {
78
+ 200: {
79
+ description: "List of all active sessions",
80
+ content: {
81
+ "application/json": {
82
+ schema: import_zod_openapi.z.object({
83
+ sessions: import_zod_openapi.z.array(import_responses.SessionMetadataSchema).describe("Array of session metadata objects")
84
+ }).strict()
105
85
  }
106
86
  }
107
- }
108
- });
109
- const createRouteDef = (0, import_zod_openapi.createRoute)({
110
- method: "post",
111
- path: "/sessions",
112
- summary: "Create Session",
113
- description: "Creates a new session",
114
- tags: ["sessions"],
115
- request: { body: { content: { "application/json": { schema: CreateSessionSchema } } } },
116
- responses: {
117
- 201: {
118
- description: "Session created successfully",
119
- content: {
120
- "application/json": {
121
- schema: import_zod_openapi.z.object({
122
- session: import_responses.SessionMetadataSchema.describe(
123
- "Newly created session metadata"
124
- )
125
- }).strict()
126
- }
87
+ },
88
+ 400: import_responses.BadRequestErrorResponse,
89
+ 500: import_responses.InternalErrorResponse
90
+ }
91
+ });
92
+ const createRouteDef = (0, import_zod_openapi.createRoute)({
93
+ method: "post",
94
+ path: "/sessions",
95
+ summary: "Create Session",
96
+ description: "Creates a new session",
97
+ tags: ["sessions"],
98
+ request: { body: { content: { "application/json": { schema: CreateSessionSchema } } } },
99
+ responses: {
100
+ 201: {
101
+ description: "Session created successfully",
102
+ content: {
103
+ "application/json": {
104
+ schema: import_zod_openapi.z.object({
105
+ session: import_responses.SessionMetadataSchema.describe(
106
+ "Newly created session metadata"
107
+ )
108
+ }).strict()
127
109
  }
128
110
  }
129
- }
130
- });
131
- const getRoute = (0, import_zod_openapi.createRoute)({
132
- method: "get",
133
- path: "/sessions/{sessionId}",
134
- summary: "Get Session Details",
135
- description: "Fetches details for a specific session",
136
- tags: ["sessions"],
137
- request: { params: import_zod_openapi.z.object({ sessionId: import_zod_openapi.z.string().describe("Session identifier") }) },
138
- responses: {
139
- 200: {
140
- description: "Session details with metadata",
141
- content: {
142
- "application/json": {
143
- schema: import_zod_openapi.z.object({
144
- session: import_responses.SessionMetadataSchema.extend({
145
- history: import_zod_openapi.z.number().int().nonnegative().describe("Number of messages in history")
146
- }).strict().describe("Session metadata with history count")
147
- }).strict()
148
- }
111
+ },
112
+ 400: import_responses.BadRequestErrorResponse,
113
+ 500: import_responses.InternalErrorResponse
114
+ }
115
+ });
116
+ const getRoute = (0, import_zod_openapi.createRoute)({
117
+ method: "get",
118
+ path: "/sessions/{sessionId}",
119
+ summary: "Get Session Details",
120
+ description: "Fetches details for a specific session",
121
+ tags: ["sessions"],
122
+ request: { params: import_zod_openapi.z.object({ sessionId: import_zod_openapi.z.string().describe("Session identifier") }) },
123
+ responses: {
124
+ 200: {
125
+ description: "Session details with metadata",
126
+ content: {
127
+ "application/json": {
128
+ schema: import_zod_openapi.z.object({
129
+ session: import_responses.SessionMetadataSchema.extend({
130
+ history: import_zod_openapi.z.number().int().nonnegative().describe("Number of messages in history")
131
+ }).strict().describe("Session metadata with history count")
132
+ }).strict()
149
133
  }
150
134
  }
151
- }
152
- });
153
- const forkRoute = (0, import_zod_openapi.createRoute)({
154
- method: "post",
155
- path: "/sessions/{sessionId}/fork",
156
- summary: "Fork Session",
157
- description: "Creates a new child session by cloning the specified parent session history and metadata lineage.",
158
- tags: ["sessions"],
159
- request: {
160
- params: import_zod_openapi.z.object({
161
- sessionId: import_zod_openapi.z.string().describe("Parent session identifier")
162
- })
163
135
  },
164
- responses: {
165
- 201: {
166
- description: "Forked session created successfully",
167
- content: {
168
- "application/json": {
169
- schema: import_zod_openapi.z.object({
170
- session: import_responses.SessionMetadataSchema.describe(
171
- "Newly created child session metadata"
172
- )
173
- }).strict()
174
- }
175
- }
176
- },
177
- 400: {
178
- description: "Invalid fork request (for example, max session limit reached)",
179
- content: {
180
- "application/json": {
181
- schema: import_responses.StandardErrorEnvelopeSchema
182
- }
183
- }
184
- },
185
- 404: {
186
- description: "Parent session not found",
187
- content: {
188
- "application/json": {
189
- schema: import_responses.StandardErrorEnvelopeSchema
190
- }
136
+ 400: import_responses.BadRequestErrorResponse,
137
+ 404: import_responses.NotFoundErrorResponse,
138
+ 500: import_responses.InternalErrorResponse
139
+ }
140
+ });
141
+ const forkRoute = (0, import_zod_openapi.createRoute)({
142
+ method: "post",
143
+ path: "/sessions/{sessionId}/fork",
144
+ summary: "Fork Session",
145
+ description: "Creates a new child session by cloning the specified parent session history and metadata lineage.",
146
+ tags: ["sessions"],
147
+ request: {
148
+ params: import_zod_openapi.z.object({
149
+ sessionId: import_zod_openapi.z.string().describe("Parent session identifier")
150
+ })
151
+ },
152
+ responses: {
153
+ 201: {
154
+ description: "Forked session created successfully",
155
+ content: {
156
+ "application/json": {
157
+ schema: import_zod_openapi.z.object({
158
+ session: import_responses.SessionMetadataSchema.describe(
159
+ "Newly created child session metadata"
160
+ )
161
+ }).strict()
191
162
  }
192
163
  }
193
- }
194
- });
195
- const historyRoute = (0, import_zod_openapi.createRoute)({
196
- method: "get",
197
- path: "/sessions/{sessionId}/history",
198
- summary: "Get Session History",
199
- description: "Retrieves the conversation history for a session along with processing status",
200
- tags: ["sessions"],
201
- request: { params: import_zod_openapi.z.object({ sessionId: import_zod_openapi.z.string().describe("Session identifier") }) },
202
- responses: {
203
- 200: {
204
- description: "Session conversation history",
205
- content: {
206
- "application/json": {
207
- schema: import_zod_openapi.z.object({
208
- history: import_zod_openapi.z.array(import_responses.InternalMessageSchema).describe("Array of messages in conversation history"),
209
- isBusy: import_zod_openapi.z.boolean().describe(
210
- "Whether the session is currently processing a message"
211
- )
212
- }).strict()
213
- }
164
+ },
165
+ 400: {
166
+ ...import_responses.BadRequestErrorResponse
167
+ },
168
+ 404: {
169
+ ...import_responses.NotFoundErrorResponse
170
+ },
171
+ 500: import_responses.InternalErrorResponse
172
+ }
173
+ });
174
+ const historyRoute = (0, import_zod_openapi.createRoute)({
175
+ method: "get",
176
+ path: "/sessions/{sessionId}/history",
177
+ summary: "Get Session History",
178
+ description: "Retrieves the conversation history for a session along with processing status",
179
+ tags: ["sessions"],
180
+ request: { params: import_zod_openapi.z.object({ sessionId: import_zod_openapi.z.string().describe("Session identifier") }) },
181
+ responses: {
182
+ 200: {
183
+ description: "Session conversation history",
184
+ content: {
185
+ "application/json": {
186
+ schema: import_zod_openapi.z.object({
187
+ history: import_zod_openapi.z.array(import_responses.InternalMessageSchema).describe("Array of messages in conversation history"),
188
+ isBusy: import_zod_openapi.z.boolean().describe("Whether the session is currently processing a message")
189
+ }).strict()
214
190
  }
215
191
  }
216
- }
217
- });
218
- const listSessionPromptContributorsRoute = (0, import_zod_openapi.createRoute)({
219
- method: "get",
220
- path: "/sessions/{sessionId}/system-prompt/contributors",
221
- summary: "List Session System Prompt Contributors",
222
- description: "Lists static system prompt contributors that apply only to the specified session.",
223
- tags: ["sessions", "config"],
224
- request: { params: import_zod_openapi.z.object({ sessionId: import_zod_openapi.z.string().describe("Session identifier") }) },
225
- responses: {
226
- 200: {
227
- description: "Current session contributor list",
228
- content: {
229
- "application/json": {
230
- schema: import_zod_openapi.z.object({
231
- contributors: import_zod_openapi.z.array(SessionPromptContributorInfoSchema).describe("Registered session prompt contributors.")
232
- }).strict()
233
- }
192
+ },
193
+ 400: import_responses.BadRequestErrorResponse,
194
+ 404: import_responses.NotFoundErrorResponse,
195
+ 500: import_responses.InternalErrorResponse
196
+ }
197
+ });
198
+ const listSessionPromptContributorsRoute = (0, import_zod_openapi.createRoute)({
199
+ method: "get",
200
+ path: "/sessions/{sessionId}/system-prompt/contributors",
201
+ summary: "List Session System Prompt Contributors",
202
+ description: "Lists static system prompt contributors that apply only to the specified session.",
203
+ tags: ["sessions", "config"],
204
+ request: { params: import_zod_openapi.z.object({ sessionId: import_zod_openapi.z.string().describe("Session identifier") }) },
205
+ responses: {
206
+ 200: {
207
+ description: "Current session contributor list",
208
+ content: {
209
+ "application/json": {
210
+ schema: import_zod_openapi.z.object({
211
+ contributors: import_zod_openapi.z.array(SessionPromptContributorInfoSchema).describe("Registered session prompt contributors.")
212
+ }).strict()
234
213
  }
235
- },
236
- 404: {
237
- description: "Session not found",
238
- content: {
239
- "application/json": {
240
- schema: import_responses.StandardErrorEnvelopeSchema
241
- }
214
+ }
215
+ },
216
+ 404: {
217
+ ...import_responses.NotFoundErrorResponse
218
+ },
219
+ 500: import_responses.InternalErrorResponse
220
+ }
221
+ });
222
+ const upsertSessionPromptContributorRoute = (0, import_zod_openapi.createRoute)({
223
+ method: "post",
224
+ path: "/sessions/{sessionId}/system-prompt/contributors",
225
+ summary: "Upsert Session System Prompt Contributor",
226
+ description: "Adds or updates a static system prompt contributor that applies only to the specified session. Set enabled=false to remove it.",
227
+ tags: ["sessions", "config"],
228
+ request: {
229
+ params: import_zod_openapi.z.object({ sessionId: import_zod_openapi.z.string().describe("Session identifier") }),
230
+ body: {
231
+ required: true,
232
+ content: {
233
+ "application/json": {
234
+ schema: UpsertSessionPromptContributorSchema
242
235
  }
243
236
  }
244
237
  }
245
- });
246
- const upsertSessionPromptContributorRoute = (0, import_zod_openapi.createRoute)({
247
- method: "post",
248
- path: "/sessions/{sessionId}/system-prompt/contributors",
249
- summary: "Upsert Session System Prompt Contributor",
250
- description: "Adds or updates a static system prompt contributor that applies only to the specified session. Set enabled=false to remove it.",
251
- tags: ["sessions", "config"],
252
- request: {
253
- params: import_zod_openapi.z.object({ sessionId: import_zod_openapi.z.string().describe("Session identifier") }),
254
- body: {
255
- required: true,
256
- content: {
257
- "application/json": {
258
- schema: UpsertSessionPromptContributorSchema
259
- }
238
+ },
239
+ responses: {
240
+ 200: {
241
+ description: "Session contributor upsert result",
242
+ content: {
243
+ "application/json": {
244
+ schema: import_zod_openapi.z.object({
245
+ id: import_zod_openapi.z.string().describe("Contributor identifier"),
246
+ enabled: import_zod_openapi.z.boolean().describe("Whether the contributor remains enabled"),
247
+ priority: import_zod_openapi.z.number().optional().describe("Contributor priority"),
248
+ replaced: import_zod_openapi.z.boolean().optional().describe("Whether an existing contributor was replaced"),
249
+ removed: import_zod_openapi.z.boolean().optional().describe("Whether the contributor was removed"),
250
+ contentLength: import_zod_openapi.z.number().optional().describe("Stored content length in characters"),
251
+ truncated: import_zod_openapi.z.boolean().optional().describe("Whether the submitted content was truncated")
252
+ }).strict()
260
253
  }
261
254
  }
262
255
  },
263
- responses: {
264
- 200: {
265
- description: "Session contributor upsert result",
266
- content: {
267
- "application/json": {
268
- schema: import_zod_openapi.z.object({
269
- id: import_zod_openapi.z.string().describe("Contributor identifier"),
270
- enabled: import_zod_openapi.z.boolean().describe("Whether the contributor remains enabled"),
271
- priority: import_zod_openapi.z.number().optional().describe("Contributor priority"),
272
- replaced: import_zod_openapi.z.boolean().optional().describe("Whether an existing contributor was replaced"),
273
- removed: import_zod_openapi.z.boolean().optional().describe("Whether the contributor was removed"),
274
- contentLength: import_zod_openapi.z.number().optional().describe("Stored content length in characters"),
275
- truncated: import_zod_openapi.z.boolean().optional().describe("Whether the submitted content was truncated")
276
- }).strict()
277
- }
256
+ 400: {
257
+ ...import_responses.BadRequestErrorResponse
258
+ },
259
+ 404: {
260
+ ...import_responses.NotFoundErrorResponse
261
+ },
262
+ 500: import_responses.InternalErrorResponse
263
+ }
264
+ });
265
+ const deleteRoute = (0, import_zod_openapi.createRoute)({
266
+ method: "delete",
267
+ path: "/sessions/{sessionId}",
268
+ summary: "Delete Session",
269
+ description: "Permanently deletes a session and all its conversation history. This action cannot be undone",
270
+ tags: ["sessions"],
271
+ request: { params: import_zod_openapi.z.object({ sessionId: import_zod_openapi.z.string().describe("Session identifier") }) },
272
+ responses: {
273
+ 200: {
274
+ description: "Session deleted successfully",
275
+ content: {
276
+ "application/json": {
277
+ schema: import_zod_openapi.z.object({
278
+ status: import_zod_openapi.z.literal("deleted").describe("Deletion status"),
279
+ sessionId: import_zod_openapi.z.string().describe("ID of the deleted session")
280
+ }).strict()
278
281
  }
279
- },
280
- 400: {
281
- description: "Invalid session contributor request",
282
- content: {
283
- "application/json": {
284
- schema: import_responses.StandardErrorEnvelopeSchema
285
- }
282
+ }
283
+ },
284
+ 400: import_responses.BadRequestErrorResponse,
285
+ 404: import_responses.NotFoundErrorResponse,
286
+ 500: import_responses.InternalErrorResponse
287
+ }
288
+ });
289
+ const cancelRoute = (0, import_zod_openapi.createRoute)({
290
+ method: "post",
291
+ path: "/sessions/{sessionId}/cancel",
292
+ summary: "Cancel Session Run",
293
+ description: "Cancels an in-flight agent run for the specified session. By default (soft cancel), only the current LLM call is cancelled and queued messages continue processing. Set clearQueue=true for hard cancel to also clear any queued messages.",
294
+ tags: ["sessions"],
295
+ request: {
296
+ params: import_zod_openapi.z.object({ sessionId: import_zod_openapi.z.string().describe("Session identifier") }),
297
+ body: {
298
+ content: {
299
+ "application/json": {
300
+ schema: import_zod_openapi.z.object({
301
+ clearQueue: import_zod_openapi.z.boolean().optional().default(false).describe(
302
+ "If true (hard cancel), clears queued messages. If false (soft cancel, default), queued messages continue processing."
303
+ )
304
+ }).strict()
286
305
  }
287
306
  },
288
- 404: {
289
- description: "Session not found",
290
- content: {
291
- "application/json": {
292
- schema: import_responses.StandardErrorEnvelopeSchema
293
- }
294
- }
295
- }
307
+ required: false
296
308
  }
297
- });
298
- const deleteRoute = (0, import_zod_openapi.createRoute)({
299
- method: "delete",
300
- path: "/sessions/{sessionId}",
301
- summary: "Delete Session",
302
- description: "Permanently deletes a session and all its conversation history. This action cannot be undone",
303
- tags: ["sessions"],
304
- request: { params: import_zod_openapi.z.object({ sessionId: import_zod_openapi.z.string().describe("Session identifier") }) },
305
- responses: {
306
- 200: {
307
- description: "Session deleted successfully",
308
- content: {
309
- "application/json": {
310
- schema: import_zod_openapi.z.object({
311
- status: import_zod_openapi.z.literal("deleted").describe("Deletion status"),
312
- sessionId: import_zod_openapi.z.string().describe("ID of the deleted session")
313
- }).strict()
314
- }
309
+ },
310
+ responses: {
311
+ 200: {
312
+ description: "Cancel operation result",
313
+ content: {
314
+ "application/json": {
315
+ schema: import_zod_openapi.z.object({
316
+ cancelled: import_zod_openapi.z.boolean().describe("Whether a run was cancelled"),
317
+ sessionId: import_zod_openapi.z.string().describe("Session ID"),
318
+ queueCleared: import_zod_openapi.z.boolean().describe("Whether queued messages were cleared"),
319
+ clearedCount: import_zod_openapi.z.number().describe("Number of queued messages cleared (0 if soft cancel)")
320
+ }).strict()
315
321
  }
316
322
  }
317
- }
318
- });
319
- const cancelRoute = (0, import_zod_openapi.createRoute)({
320
- method: "post",
321
- path: "/sessions/{sessionId}/cancel",
322
- summary: "Cancel Session Run",
323
- description: "Cancels an in-flight agent run for the specified session. By default (soft cancel), only the current LLM call is cancelled and queued messages continue processing. Set clearQueue=true for hard cancel to also clear any queued messages.",
324
- tags: ["sessions"],
325
- request: {
326
- params: import_zod_openapi.z.object({ sessionId: import_zod_openapi.z.string().describe("Session identifier") }),
327
- body: {
328
- content: {
329
- "application/json": {
330
- schema: import_zod_openapi.z.object({
331
- clearQueue: import_zod_openapi.z.boolean().optional().default(false).describe(
332
- "If true (hard cancel), clears queued messages. If false (soft cancel, default), queued messages continue processing."
333
- )
334
- }).strict()
335
- }
323
+ },
324
+ 400: import_responses.BadRequestErrorResponse,
325
+ 404: import_responses.NotFoundErrorResponse,
326
+ 409: import_responses.ConflictErrorResponse,
327
+ 500: import_responses.InternalErrorResponse
328
+ }
329
+ });
330
+ const eventsRoute = (0, import_zod_openapi.createRoute)({
331
+ method: "get",
332
+ path: "/sessions/{sessionId}/events",
333
+ summary: "Attach Session Event Stream",
334
+ description: "Attaches to the live SSE event stream for an already-running session without starting a new run. Use this to reattach after a page reload or connection interruption.",
335
+ tags: ["sessions"],
336
+ request: {
337
+ params: import_zod_openapi.z.object({ sessionId: import_zod_openapi.z.string().describe("Session identifier") })
338
+ },
339
+ responses: {
340
+ 200: {
341
+ description: "SSE stream of live session events",
342
+ headers: {
343
+ "Content-Type": {
344
+ description: "SSE content type",
345
+ schema: { type: "string", example: "text/event-stream" }
346
+ },
347
+ "Cache-Control": {
348
+ description: "Disable caching for stream",
349
+ schema: { type: "string", example: "no-cache" }
350
+ },
351
+ Connection: {
352
+ description: "Keep connection alive for streaming",
353
+ schema: { type: "string", example: "keep-alive" }
336
354
  },
337
- required: false
355
+ "X-Accel-Buffering": {
356
+ description: "Disable nginx buffering",
357
+ schema: { type: "string", example: "no" }
358
+ }
359
+ },
360
+ content: {
361
+ "text/event-stream": {
362
+ schema: import_zod_openapi.z.string().describe(
363
+ "Server-Sent Events stream for an active session. Events use the same payloads as /message-stream."
364
+ )
365
+ }
338
366
  }
339
367
  },
340
- responses: {
341
- 200: {
342
- description: "Cancel operation result",
343
- content: {
344
- "application/json": {
345
- schema: import_zod_openapi.z.object({
346
- cancelled: import_zod_openapi.z.boolean().describe("Whether a run was cancelled"),
347
- sessionId: import_zod_openapi.z.string().describe("Session ID"),
348
- queueCleared: import_zod_openapi.z.boolean().describe("Whether queued messages were cleared"),
349
- clearedCount: import_zod_openapi.z.number().describe(
350
- "Number of queued messages cleared (0 if soft cancel)"
368
+ 400: import_responses.BadRequestErrorResponse,
369
+ 404: import_responses.NotFoundErrorResponse,
370
+ 409: import_responses.ConflictErrorResponse,
371
+ 500: import_responses.InternalErrorResponse
372
+ }
373
+ });
374
+ const loadRoute = (0, import_zod_openapi.createRoute)({
375
+ method: "get",
376
+ path: "/sessions/{sessionId}/load",
377
+ summary: "Load Session",
378
+ description: "Validates and retrieves session information including processing status. The client should track the active session.",
379
+ tags: ["sessions"],
380
+ request: {
381
+ params: import_zod_openapi.z.object({ sessionId: import_zod_openapi.z.string().describe("Session identifier") })
382
+ },
383
+ responses: {
384
+ 200: {
385
+ description: "Session information retrieved successfully",
386
+ content: {
387
+ "application/json": {
388
+ schema: import_zod_openapi.z.object({
389
+ session: import_responses.SessionMetadataSchema.extend({
390
+ isBusy: import_zod_openapi.z.boolean().describe(
391
+ "Whether the session is currently processing a message"
392
+ ),
393
+ usageSummary: import_responses.UsageSummarySchema.describe(
394
+ "Exact usage summary derived from assistant message history"
395
+ ),
396
+ activeUsageScopeId: import_zod_openapi.z.string().nullable().describe(
397
+ "Current runtime usage scope identifier, if configured"
398
+ ),
399
+ activeUsageScope: import_responses.ScopedUsageSummarySchema.nullable().describe(
400
+ "Usage summary for the current runtime scope, if configured"
351
401
  )
352
- }).strict()
353
- }
402
+ }).describe("Session metadata with processing status")
403
+ }).strict()
354
404
  }
355
405
  }
356
- }
357
- });
358
- const loadRoute = (0, import_zod_openapi.createRoute)({
359
- method: "get",
360
- path: "/sessions/{sessionId}/load",
361
- summary: "Load Session",
362
- description: "Validates and retrieves session information including processing status. The client should track the active session.",
363
- tags: ["sessions"],
364
- request: {
365
- params: import_zod_openapi.z.object({ sessionId: import_zod_openapi.z.string().describe("Session identifier") })
366
406
  },
367
- responses: {
368
- 200: {
369
- description: "Session information retrieved successfully",
370
- content: {
371
- "application/json": {
372
- schema: import_zod_openapi.z.object({
373
- session: import_responses.SessionMetadataSchema.extend({
374
- isBusy: import_zod_openapi.z.boolean().describe(
375
- "Whether the session is currently processing a message"
376
- ),
377
- usageSummary: import_responses.UsageSummarySchema.describe(
378
- "Exact usage summary derived from assistant message history"
379
- ),
380
- activeUsageScopeId: import_zod_openapi.z.string().nullable().describe(
381
- "Current runtime usage scope identifier, if configured"
382
- ),
383
- activeUsageScope: import_responses.ScopedUsageSummarySchema.nullable().describe(
384
- "Usage summary for the current runtime scope, if configured"
385
- )
386
- }).describe("Session metadata with processing status")
387
- }).strict()
388
- }
389
- }
390
- },
391
- 404: {
392
- description: "Session not found",
393
- content: {
394
- "application/json": {
395
- schema: import_zod_openapi.z.object({
396
- error: import_zod_openapi.z.string().describe("Error message")
397
- }).strict()
398
- }
407
+ 404: {
408
+ ...import_responses.NotFoundErrorResponse
409
+ },
410
+ 400: import_responses.BadRequestErrorResponse,
411
+ 500: import_responses.InternalErrorResponse
412
+ }
413
+ });
414
+ const clearContextRoute = (0, import_zod_openapi.createRoute)({
415
+ method: "post",
416
+ path: "/sessions/{sessionId}/clear-context",
417
+ summary: "Clear Session Context",
418
+ description: "Clears the model context window for a session while preserving conversation history for review.",
419
+ tags: ["sessions"],
420
+ request: {
421
+ params: import_zod_openapi.z.object({ sessionId: import_zod_openapi.z.string().describe("Session identifier") })
422
+ },
423
+ responses: {
424
+ 200: {
425
+ description: "Session context cleared successfully",
426
+ content: {
427
+ "application/json": {
428
+ schema: import_zod_openapi.z.object({
429
+ status: import_zod_openapi.z.literal("context cleared").describe("Context clear status"),
430
+ sessionId: import_zod_openapi.z.string().describe("Session ID")
431
+ }).strict()
399
432
  }
400
433
  }
401
- }
402
- });
403
- const clearContextRoute = (0, import_zod_openapi.createRoute)({
404
- method: "post",
405
- path: "/sessions/{sessionId}/clear-context",
406
- summary: "Clear Session Context",
407
- description: "Clears the model context window for a session while preserving conversation history for review.",
408
- tags: ["sessions"],
409
- request: {
410
- params: import_zod_openapi.z.object({ sessionId: import_zod_openapi.z.string().describe("Session identifier") })
411
434
  },
412
- responses: {
413
- 200: {
414
- description: "Session context cleared successfully",
415
- content: {
416
- "application/json": {
417
- schema: import_zod_openapi.z.object({
418
- status: import_zod_openapi.z.literal("context cleared").describe("Context clear status"),
419
- sessionId: import_zod_openapi.z.string().describe("Session ID")
420
- }).strict()
421
- }
435
+ 400: import_responses.BadRequestErrorResponse,
436
+ 404: import_responses.NotFoundErrorResponse,
437
+ 500: import_responses.InternalErrorResponse
438
+ }
439
+ });
440
+ const patchRoute = (0, import_zod_openapi.createRoute)({
441
+ method: "patch",
442
+ path: "/sessions/{sessionId}",
443
+ summary: "Update Session Title",
444
+ description: "Updates the title of an existing session",
445
+ tags: ["sessions"],
446
+ request: {
447
+ params: import_zod_openapi.z.object({ sessionId: import_zod_openapi.z.string().describe("Session identifier") }),
448
+ body: {
449
+ content: {
450
+ "application/json": {
451
+ schema: import_zod_openapi.z.object({
452
+ title: import_zod_openapi.z.string().min(1, "Title is required").max(120, "Title too long").describe("New title for the session (maximum 120 characters)")
453
+ })
422
454
  }
423
455
  }
424
456
  }
425
- });
426
- const patchRoute = (0, import_zod_openapi.createRoute)({
427
- method: "patch",
428
- path: "/sessions/{sessionId}",
429
- summary: "Update Session Title",
430
- description: "Updates the title of an existing session",
431
- tags: ["sessions"],
432
- request: {
433
- params: import_zod_openapi.z.object({ sessionId: import_zod_openapi.z.string().describe("Session identifier") }),
434
- body: {
435
- content: {
436
- "application/json": {
437
- schema: import_zod_openapi.z.object({
438
- title: import_zod_openapi.z.string().min(1, "Title is required").max(120, "Title too long").describe("New title for the session (maximum 120 characters)")
439
- })
440
- }
457
+ },
458
+ responses: {
459
+ 200: {
460
+ description: "Session updated successfully",
461
+ content: {
462
+ "application/json": {
463
+ schema: import_zod_openapi.z.object({
464
+ session: import_responses.SessionMetadataSchema.describe("Updated session metadata")
465
+ }).strict()
441
466
  }
442
467
  }
443
468
  },
444
- responses: {
445
- 200: {
446
- description: "Session updated successfully",
447
- content: {
448
- "application/json": {
449
- schema: import_zod_openapi.z.object({
450
- session: import_responses.SessionMetadataSchema.describe("Updated session metadata")
451
- }).strict()
452
- }
469
+ 400: import_responses.BadRequestErrorResponse,
470
+ 404: import_responses.NotFoundErrorResponse,
471
+ 500: import_responses.InternalErrorResponse
472
+ }
473
+ });
474
+ const generateTitleRoute = (0, import_zod_openapi.createRoute)({
475
+ method: "post",
476
+ path: "/sessions/{sessionId}/generate-title",
477
+ summary: "Generate Session Title",
478
+ description: "Generates a descriptive title for the session using the first user message. Returns existing title if already set.",
479
+ tags: ["sessions"],
480
+ request: {
481
+ params: import_zod_openapi.z.object({ sessionId: import_zod_openapi.z.string().describe("Session identifier") })
482
+ },
483
+ responses: {
484
+ 200: {
485
+ description: "Title generated successfully",
486
+ content: {
487
+ "application/json": {
488
+ schema: import_zod_openapi.z.object({
489
+ title: import_zod_openapi.z.string().nullable().describe("Generated title, or null if generation failed"),
490
+ sessionId: import_zod_openapi.z.string().describe("Session ID")
491
+ }).strict()
453
492
  }
454
493
  }
455
- }
456
- });
457
- const generateTitleRoute = (0, import_zod_openapi.createRoute)({
458
- method: "post",
459
- path: "/sessions/{sessionId}/generate-title",
460
- summary: "Generate Session Title",
461
- description: "Generates a descriptive title for the session using the first user message. Returns existing title if already set.",
462
- tags: ["sessions"],
463
- request: {
464
- params: import_zod_openapi.z.object({ sessionId: import_zod_openapi.z.string().describe("Session identifier") })
465
494
  },
466
- responses: {
467
- 200: {
468
- description: "Title generated successfully",
469
- content: {
470
- "application/json": {
471
- schema: import_zod_openapi.z.object({
472
- title: import_zod_openapi.z.string().nullable().describe("Generated title, or null if generation failed"),
473
- sessionId: import_zod_openapi.z.string().describe("Session ID")
474
- }).strict()
475
- }
476
- }
477
- },
478
- 404: {
479
- description: "Session not found",
480
- content: {
481
- "application/json": {
482
- schema: import_responses.StandardErrorEnvelopeSchema
483
- }
484
- }
495
+ 404: {
496
+ ...import_responses.NotFoundErrorResponse
497
+ },
498
+ 400: import_responses.BadRequestErrorResponse,
499
+ 500: import_responses.InternalErrorResponse
500
+ }
501
+ });
502
+ function createSessionsRouter(getAgent, sessionSseSubscriber) {
503
+ const app = new import_zod_openapi.OpenAPIHono({
504
+ defaultHook: (result, ctx) => {
505
+ if (!result.success) {
506
+ const issues = (0, import_core.zodToIssues)(result.error);
507
+ return (0, import_error.handleHonoError)(
508
+ ctx,
509
+ new import_core.DextoRuntimeError(
510
+ "validation_failed",
511
+ "validation",
512
+ import_core.ErrorType.USER,
513
+ issues[0]?.message ?? "Validation failed",
514
+ { issues }
515
+ )
516
+ );
485
517
  }
486
518
  }
487
519
  });
520
+ app.onError((err, ctx) => (0, import_error.handleHonoError)(ctx, err));
488
521
  return app.openapi(listRoute, async (ctx) => {
489
522
  const agent = await getAgent(ctx);
490
523
  const sessionIds = await agent.listSessions();
@@ -498,7 +531,7 @@ function createSessionsRouter(getAgent) {
498
531
  }
499
532
  })
500
533
  );
501
- return ctx.json({ sessions });
534
+ return ctx.json({ sessions }, 200);
502
535
  }).openapi(createRouteDef, async (ctx) => {
503
536
  const agent = await getAgent(ctx);
504
537
  const { sessionId } = ctx.req.valid("json");
@@ -529,12 +562,15 @@ function createSessionsRouter(getAgent) {
529
562
  const { sessionId } = ctx.req.param();
530
563
  const metadata = await agent.getSessionMetadata(sessionId);
531
564
  const history = await agent.getSessionHistory(sessionId);
532
- return ctx.json({
533
- session: {
534
- ...mapSessionMetadata(sessionId, metadata),
535
- history: history.length
536
- }
537
- });
565
+ return ctx.json(
566
+ {
567
+ session: {
568
+ ...mapSessionMetadata(sessionId, metadata),
569
+ history: history.length
570
+ }
571
+ },
572
+ 200
573
+ );
538
574
  }).openapi(historyRoute, async (ctx) => {
539
575
  const agent = await getAgent(ctx);
540
576
  const { sessionId } = ctx.req.param();
@@ -542,10 +578,26 @@ function createSessionsRouter(getAgent) {
542
578
  agent.getSessionHistory(sessionId),
543
579
  agent.isSessionBusy(sessionId)
544
580
  ]);
545
- return ctx.json({
546
- history,
547
- isBusy
548
- });
581
+ const apiHistory = history.map((message) => (0, import_responses.toApiInternalMessage)(message));
582
+ for (const [index, message] of apiHistory.entries()) {
583
+ const parsed = import_responses.InternalMessageSchema.safeParse(message);
584
+ if (!parsed.success) {
585
+ throw new import_core.DextoRuntimeError(
586
+ "session_history_serialization_failed",
587
+ import_core.ErrorScope.SESSION,
588
+ import_core.ErrorType.SYSTEM,
589
+ "Failed to serialize session history",
590
+ { sessionId, index, issues: (0, import_core.zodToIssues)(parsed.error) }
591
+ );
592
+ }
593
+ }
594
+ return ctx.json(
595
+ {
596
+ history: apiHistory,
597
+ isBusy
598
+ },
599
+ 200
600
+ );
549
601
  }).openapi(listSessionPromptContributorsRoute, async (ctx) => {
550
602
  const agent = await getAgent(ctx);
551
603
  const { sessionId } = ctx.req.valid("param");
@@ -625,7 +677,7 @@ function createSessionsRouter(getAgent) {
625
677
  const agent = await getAgent(ctx);
626
678
  const { sessionId } = ctx.req.param();
627
679
  await agent.deleteSession(sessionId);
628
- return ctx.json({ status: "deleted", sessionId });
680
+ return ctx.json({ status: "deleted", sessionId }, 200);
629
681
  }).openapi(cancelRoute, async (ctx) => {
630
682
  const agent = await getAgent(ctx);
631
683
  const { sessionId } = ctx.req.valid("param");
@@ -649,18 +701,61 @@ function createSessionsRouter(getAgent) {
649
701
  if (!cancelled) {
650
702
  agent.logger.debug(`No in-flight run to cancel for session: ${sessionId}`);
651
703
  }
652
- return ctx.json({
653
- cancelled,
654
- sessionId,
655
- queueCleared: clearQueue,
656
- clearedCount
704
+ return ctx.json(
705
+ {
706
+ cancelled,
707
+ sessionId,
708
+ queueCleared: clearQueue,
709
+ clearedCount
710
+ },
711
+ 200
712
+ );
713
+ }).openapi(eventsRoute, async (ctx) => {
714
+ const agent = await getAgent(ctx);
715
+ const { sessionId } = ctx.req.valid("param");
716
+ const sessionIds = await agent.listSessions();
717
+ if (!sessionIds.includes(sessionId)) {
718
+ throw new import_core.DextoRuntimeError(
719
+ "session_not_found",
720
+ import_core.ErrorScope.SESSION,
721
+ import_core.ErrorType.NOT_FOUND,
722
+ `Session not found: ${sessionId}`,
723
+ { sessionId }
724
+ );
725
+ }
726
+ const isBusy = await agent.isSessionBusy(sessionId);
727
+ if (!isBusy) {
728
+ throw new import_core.DextoRuntimeError(
729
+ "session_not_busy",
730
+ import_core.ErrorScope.SESSION,
731
+ import_core.ErrorType.CONFLICT,
732
+ `Session is not running: ${sessionId}`,
733
+ { sessionId }
734
+ );
735
+ }
736
+ const eventStream = sessionSseSubscriber.createStream(
737
+ sessionId
738
+ );
739
+ return new Response(eventStream, {
740
+ headers: {
741
+ "Content-Type": "text/event-stream",
742
+ "Cache-Control": "no-cache",
743
+ Connection: "keep-alive",
744
+ "X-Accel-Buffering": "no"
745
+ }
657
746
  });
658
747
  }).openapi(loadRoute, async (ctx) => {
659
748
  const agent = await getAgent(ctx);
660
749
  const { sessionId } = ctx.req.valid("param");
661
750
  const sessionIds = await agent.listSessions();
662
751
  if (!sessionIds.includes(sessionId)) {
663
- return ctx.json({ error: `Session not found: ${sessionId}` }, 404);
752
+ throw new import_core.DextoRuntimeError(
753
+ "session_not_found",
754
+ import_core.ErrorScope.SESSION,
755
+ import_core.ErrorType.NOT_FOUND,
756
+ `Session not found: ${sessionId}`,
757
+ { sessionId }
758
+ );
664
759
  }
665
760
  const metadata = await agent.getSessionMetadata(sessionId);
666
761
  const isBusy = await agent.isSessionBusy(sessionId);
@@ -686,16 +781,19 @@ function createSessionsRouter(getAgent) {
686
781
  const agent = await getAgent(ctx);
687
782
  const { sessionId } = ctx.req.valid("param");
688
783
  await agent.clearContext(sessionId);
689
- return ctx.json({ status: "context cleared", sessionId });
784
+ return ctx.json({ status: "context cleared", sessionId }, 200);
690
785
  }).openapi(patchRoute, async (ctx) => {
691
786
  const agent = await getAgent(ctx);
692
787
  const { sessionId } = ctx.req.valid("param");
693
788
  const { title } = ctx.req.valid("json");
694
789
  await agent.setSessionTitle(sessionId, title);
695
790
  const metadata = await agent.getSessionMetadata(sessionId);
696
- return ctx.json({
697
- session: mapSessionMetadata(sessionId, metadata, { title })
698
- });
791
+ return ctx.json(
792
+ {
793
+ session: mapSessionMetadata(sessionId, metadata, { title })
794
+ },
795
+ 200
796
+ );
699
797
  }).openapi(generateTitleRoute, async (ctx) => {
700
798
  const agent = await getAgent(ctx);
701
799
  const { sessionId } = ctx.req.valid("param");