@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
@@ -41,7 +41,7 @@ var import_path = __toESM(require("path"), 1);
41
41
  var import_fs = require("fs");
42
42
  var import_core2 = require("@dexto/core");
43
43
  var import_responses = require("../schemas/responses.js");
44
- const AgentConfigSchemaForOpenAPI = import_zod_openapi.z.record(import_zod_openapi.z.any()).describe(
44
+ const AgentConfigSchemaForOpenAPI = import_zod_openapi.z.record(import_zod_openapi.z.string(), import_responses.JsonValueSchema).describe(
45
45
  "Complete agent configuration. See AgentConfig type documentation for full schema details."
46
46
  );
47
47
  const AgentIdentifierSchema = import_zod_openapi.z.object({
@@ -142,296 +142,341 @@ const SaveConfigResponseSchema = import_zod_openapi.z.object({
142
142
  changesApplied: import_zod_openapi.z.array(import_zod_openapi.z.string()).describe("List of changes that were applied"),
143
143
  message: import_zod_openapi.z.string().describe("Success message")
144
144
  }).strict().describe("Configuration save result");
145
- function createAgentsRouter(getAgent, context, getAgentConfigPath) {
146
- const app = new import_zod_openapi.OpenAPIHono();
147
- const { switchAgentById, switchAgentByPath, resolveAgentInfo, getActiveAgentId } = context;
148
- const resolveAgentConfigPath = async (ctx) => {
149
- const configPath = await getAgentConfigPath(ctx);
150
- if (!configPath) {
151
- throw import_core.AgentError.noConfigPath();
152
- }
153
- return configPath;
154
- };
155
- const listRoute = (0, import_zod_openapi.createRoute)({
156
- method: "get",
157
- path: "/agents",
158
- summary: "List Agents",
159
- description: "Retrieves all agents (installed, available, and current active agent)",
160
- tags: ["agents"],
161
- responses: {
162
- 200: {
163
- description: "List all agents",
164
- content: { "application/json": { schema: ListAgentsResponseSchema } }
165
- }
166
- }
167
- });
168
- const currentRoute = (0, import_zod_openapi.createRoute)({
169
- method: "get",
170
- path: "/agents/current",
171
- summary: "Get Current Agent",
172
- description: "Retrieves the currently active agent",
173
- tags: ["agents"],
174
- responses: {
175
- 200: {
176
- description: "Current agent",
177
- content: { "application/json": { schema: AgentInfoNullableSchema } }
178
- }
179
- }
180
- });
181
- const installRoute = (0, import_zod_openapi.createRoute)({
182
- method: "post",
183
- path: "/agents/install",
184
- summary: "Install Agent",
185
- description: "Installs an agent from the registry or from a custom source",
186
- tags: ["agents"],
187
- request: {
188
- body: {
189
- content: {
190
- "application/json": {
191
- schema: import_zod_openapi.z.union([CustomAgentInstallSchema, AgentIdentifierSchema])
192
- }
193
- }
194
- }
145
+ const CreateCustomAgentResponseSchema = import_zod_openapi.z.object({
146
+ created: import_zod_openapi.z.literal(true).describe("Creation success indicator"),
147
+ id: import_zod_openapi.z.string().describe("Agent identifier"),
148
+ name: import_zod_openapi.z.string().describe("Agent name")
149
+ }).strict().describe("Custom agent creation response");
150
+ const ValidateConfigErrorSchema = import_zod_openapi.z.object({
151
+ line: import_zod_openapi.z.number().int().optional().describe("Line number"),
152
+ column: import_zod_openapi.z.number().int().optional().describe("Column number"),
153
+ path: import_zod_openapi.z.string().optional().describe("Configuration path"),
154
+ message: import_zod_openapi.z.string().describe("Error message"),
155
+ code: import_zod_openapi.z.string().describe("Error code")
156
+ }).passthrough().describe("Configuration validation error");
157
+ const ValidateConfigWarningSchema = import_zod_openapi.z.object({
158
+ path: import_zod_openapi.z.string().describe("Configuration path"),
159
+ message: import_zod_openapi.z.string().describe("Warning message"),
160
+ code: import_zod_openapi.z.string().describe("Warning code")
161
+ }).strict().describe("Configuration validation warning");
162
+ const ValidateConfigResponseSchema = import_zod_openapi.z.object({
163
+ valid: import_zod_openapi.z.boolean().describe("Whether configuration is valid"),
164
+ errors: import_zod_openapi.z.array(ValidateConfigErrorSchema).describe("Validation errors"),
165
+ warnings: import_zod_openapi.z.array(ValidateConfigWarningSchema).describe("Configuration warnings")
166
+ }).strict().describe("Configuration validation result");
167
+ const ExportConfigQuerySchema = import_zod_openapi.z.object({
168
+ sessionId: import_zod_openapi.z.string().optional().describe("Session identifier to export session-specific configuration")
169
+ }).describe("Export configuration query");
170
+ const InstallAgentRequestSchema = import_zod_openapi.z.union([CustomAgentInstallSchema, AgentIdentifierSchema]).describe("Agent installation request");
171
+ const listRoute = (0, import_zod_openapi.createRoute)({
172
+ method: "get",
173
+ path: "/agents",
174
+ summary: "List Agents",
175
+ description: "Retrieves all agents (installed, available, and current active agent)",
176
+ tags: ["agents"],
177
+ responses: {
178
+ 200: {
179
+ description: "List all agents",
180
+ content: { "application/json": { schema: ListAgentsResponseSchema } }
195
181
  },
196
- responses: {
197
- 201: {
198
- description: "Agent installed",
199
- content: { "application/json": { schema: InstallAgentResponseSchema } }
200
- }
201
- }
202
- });
203
- const switchRoute = (0, import_zod_openapi.createRoute)({
204
- method: "post",
205
- path: "/agents/switch",
206
- summary: "Switch Agent",
207
- description: "Switches to a different agent by ID or file path",
208
- tags: ["agents"],
209
- request: {
210
- body: {
211
- content: {
212
- "application/json": {
213
- schema: AgentIdentifierSchema
214
- }
215
- }
216
- }
182
+ 400: import_responses.BadRequestErrorResponse,
183
+ 500: import_responses.InternalErrorResponse
184
+ }
185
+ });
186
+ const currentRoute = (0, import_zod_openapi.createRoute)({
187
+ method: "get",
188
+ path: "/agents/current",
189
+ summary: "Get Current Agent",
190
+ description: "Retrieves the currently active agent",
191
+ tags: ["agents"],
192
+ responses: {
193
+ 200: {
194
+ description: "Current agent",
195
+ content: { "application/json": { schema: AgentInfoNullableSchema } }
217
196
  },
218
- responses: {
219
- 200: {
220
- description: "Agent switched",
221
- content: { "application/json": { schema: SwitchAgentResponseSchema } }
197
+ 400: import_responses.BadRequestErrorResponse,
198
+ 500: import_responses.InternalErrorResponse
199
+ }
200
+ });
201
+ const installRoute = (0, import_zod_openapi.createRoute)({
202
+ method: "post",
203
+ path: "/agents/install",
204
+ summary: "Install Agent",
205
+ description: "Installs an agent from the registry or from a custom source",
206
+ tags: ["agents"],
207
+ request: {
208
+ body: {
209
+ content: {
210
+ "application/json": {
211
+ schema: InstallAgentRequestSchema
212
+ }
222
213
  }
223
214
  }
224
- });
225
- const validateNameRoute = (0, import_zod_openapi.createRoute)({
226
- method: "post",
227
- path: "/agents/validate-name",
228
- summary: "Validate Agent Name",
229
- description: "Checks if an agent ID conflicts with existing agents",
230
- tags: ["agents"],
231
- request: {
232
- body: {
233
- content: {
234
- "application/json": {
235
- schema: AgentIdentifierSchema
236
- }
215
+ },
216
+ responses: {
217
+ 201: {
218
+ description: "Agent installed",
219
+ content: { "application/json": { schema: InstallAgentResponseSchema } }
220
+ },
221
+ 400: import_responses.BadRequestErrorResponse,
222
+ 404: import_responses.NotFoundErrorResponse,
223
+ 409: import_responses.ConflictErrorResponse,
224
+ 500: import_responses.InternalErrorResponse
225
+ }
226
+ });
227
+ const switchRoute = (0, import_zod_openapi.createRoute)({
228
+ method: "post",
229
+ path: "/agents/switch",
230
+ summary: "Switch Agent",
231
+ description: "Switches to a different agent by ID or file path",
232
+ tags: ["agents"],
233
+ request: {
234
+ body: {
235
+ content: {
236
+ "application/json": {
237
+ schema: AgentIdentifierSchema
237
238
  }
238
239
  }
240
+ }
241
+ },
242
+ responses: {
243
+ 200: {
244
+ description: "Agent switched",
245
+ content: { "application/json": { schema: SwitchAgentResponseSchema } }
239
246
  },
240
- responses: {
241
- 200: {
242
- description: "Name validation result",
243
- content: { "application/json": { schema: ValidateNameResponseSchema } }
247
+ 400: import_responses.BadRequestErrorResponse,
248
+ 404: import_responses.NotFoundErrorResponse,
249
+ 409: import_responses.ConflictErrorResponse,
250
+ 500: import_responses.InternalErrorResponse
251
+ }
252
+ });
253
+ const validateNameRoute = (0, import_zod_openapi.createRoute)({
254
+ method: "post",
255
+ path: "/agents/validate-name",
256
+ summary: "Validate Agent Name",
257
+ description: "Checks if an agent ID conflicts with existing agents",
258
+ tags: ["agents"],
259
+ request: {
260
+ body: {
261
+ content: {
262
+ "application/json": {
263
+ schema: AgentIdentifierSchema
264
+ }
244
265
  }
245
266
  }
246
- });
247
- const uninstallRoute = (0, import_zod_openapi.createRoute)({
248
- method: "post",
249
- path: "/agents/uninstall",
250
- summary: "Uninstall Agent",
251
- description: "Removes an agent from the system. Custom agents are removed from registry; builtin agents can be reinstalled",
252
- tags: ["agents"],
253
- request: {
254
- body: {
255
- content: {
256
- "application/json": {
257
- schema: UninstallAgentSchema
258
- }
267
+ },
268
+ responses: {
269
+ 200: {
270
+ description: "Name validation result",
271
+ content: { "application/json": { schema: ValidateNameResponseSchema } }
272
+ },
273
+ 400: import_responses.BadRequestErrorResponse,
274
+ 404: import_responses.NotFoundErrorResponse,
275
+ 409: import_responses.ConflictErrorResponse,
276
+ 500: import_responses.InternalErrorResponse
277
+ }
278
+ });
279
+ const uninstallRoute = (0, import_zod_openapi.createRoute)({
280
+ method: "post",
281
+ path: "/agents/uninstall",
282
+ summary: "Uninstall Agent",
283
+ description: "Removes an agent from the system. Custom agents are removed from registry; builtin agents can be reinstalled",
284
+ tags: ["agents"],
285
+ request: {
286
+ body: {
287
+ content: {
288
+ "application/json": {
289
+ schema: UninstallAgentSchema
259
290
  }
260
291
  }
292
+ }
293
+ },
294
+ responses: {
295
+ 200: {
296
+ description: "Agent uninstalled",
297
+ content: { "application/json": { schema: UninstallAgentResponseSchema } }
261
298
  },
262
- responses: {
263
- 200: {
264
- description: "Agent uninstalled",
265
- content: { "application/json": { schema: UninstallAgentResponseSchema } }
299
+ 400: import_responses.BadRequestErrorResponse,
300
+ 404: import_responses.NotFoundErrorResponse,
301
+ 409: import_responses.ConflictErrorResponse,
302
+ 500: import_responses.InternalErrorResponse
303
+ }
304
+ });
305
+ const customCreateRoute = (0, import_zod_openapi.createRoute)({
306
+ method: "post",
307
+ path: "/agents/custom/create",
308
+ summary: "Create Custom Agent",
309
+ description: "Creates a new custom agent from scratch via the UI/API",
310
+ tags: ["agents"],
311
+ request: {
312
+ body: {
313
+ content: {
314
+ "application/json": {
315
+ schema: CustomAgentCreateSchema
316
+ }
266
317
  }
267
318
  }
268
- });
269
- const customCreateRoute = (0, import_zod_openapi.createRoute)({
270
- method: "post",
271
- path: "/agents/custom/create",
272
- summary: "Create Custom Agent",
273
- description: "Creates a new custom agent from scratch via the UI/API",
274
- tags: ["agents"],
275
- request: {
276
- body: {
277
- content: {
278
- "application/json": {
279
- schema: CustomAgentCreateSchema
280
- }
319
+ },
320
+ responses: {
321
+ 201: {
322
+ description: "Custom agent created",
323
+ content: {
324
+ "application/json": {
325
+ schema: CreateCustomAgentResponseSchema
281
326
  }
282
327
  }
283
328
  },
284
- responses: {
285
- 201: {
286
- description: "Custom agent created",
287
- content: {
288
- "application/json": {
289
- schema: import_zod_openapi.z.object({
290
- created: import_zod_openapi.z.literal(true).describe("Creation success indicator"),
291
- id: import_zod_openapi.z.string().describe("Agent identifier"),
292
- name: import_zod_openapi.z.string().describe("Agent name")
293
- }).strict()
294
- }
329
+ 400: import_responses.BadRequestErrorResponse,
330
+ 404: import_responses.NotFoundErrorResponse,
331
+ 409: import_responses.ConflictErrorResponse,
332
+ 500: import_responses.InternalErrorResponse
333
+ }
334
+ });
335
+ const getPathRoute = (0, import_zod_openapi.createRoute)({
336
+ method: "get",
337
+ path: "/agent/path",
338
+ summary: "Get Agent File Path",
339
+ description: "Retrieves the file path of the currently active agent configuration",
340
+ tags: ["agent"],
341
+ responses: {
342
+ 200: {
343
+ description: "Agent file path",
344
+ content: {
345
+ "application/json": {
346
+ schema: AgentPathResponseSchema
295
347
  }
296
348
  }
297
- }
298
- });
299
- const getPathRoute = (0, import_zod_openapi.createRoute)({
300
- method: "get",
301
- path: "/agent/path",
302
- summary: "Get Agent File Path",
303
- description: "Retrieves the file path of the currently active agent configuration",
304
- tags: ["agent"],
305
- responses: {
306
- 200: {
307
- description: "Agent file path",
308
- content: {
309
- "application/json": {
310
- schema: AgentPathResponseSchema
311
- }
349
+ },
350
+ 400: import_responses.BadRequestErrorResponse,
351
+ 404: import_responses.NotFoundErrorResponse,
352
+ 409: import_responses.ConflictErrorResponse,
353
+ 500: import_responses.InternalErrorResponse
354
+ }
355
+ });
356
+ const getConfigRoute = (0, import_zod_openapi.createRoute)({
357
+ method: "get",
358
+ path: "/agent/config",
359
+ summary: "Get Agent Configuration",
360
+ description: "Retrieves the raw YAML configuration of the currently active agent",
361
+ tags: ["agent"],
362
+ responses: {
363
+ 200: {
364
+ description: "Agent configuration",
365
+ content: {
366
+ "application/json": {
367
+ schema: AgentConfigResponseSchema
312
368
  }
313
369
  }
314
- }
315
- });
316
- const getConfigRoute = (0, import_zod_openapi.createRoute)({
317
- method: "get",
318
- path: "/agent/config",
319
- summary: "Get Agent Configuration",
320
- description: "Retrieves the raw YAML configuration of the currently active agent",
321
- tags: ["agent"],
322
- responses: {
323
- 200: {
324
- description: "Agent configuration",
325
- content: {
326
- "application/json": {
327
- schema: AgentConfigResponseSchema
328
- }
370
+ },
371
+ 400: import_responses.BadRequestErrorResponse,
372
+ 404: import_responses.NotFoundErrorResponse,
373
+ 409: import_responses.ConflictErrorResponse,
374
+ 500: import_responses.InternalErrorResponse
375
+ }
376
+ });
377
+ const validateConfigRoute = (0, import_zod_openapi.createRoute)({
378
+ method: "post",
379
+ path: "/agent/validate",
380
+ summary: "Validate Agent Configuration",
381
+ description: "Validates YAML agent configuration without saving it",
382
+ tags: ["agent"],
383
+ request: {
384
+ body: {
385
+ content: {
386
+ "application/json": {
387
+ schema: AgentConfigValidateSchema
329
388
  }
330
389
  }
331
390
  }
332
- });
333
- const validateConfigRoute = (0, import_zod_openapi.createRoute)({
334
- method: "post",
335
- path: "/agent/validate",
336
- summary: "Validate Agent Configuration",
337
- description: "Validates YAML agent configuration without saving it",
338
- tags: ["agent"],
339
- request: {
340
- body: {
341
- content: {
342
- "application/json": {
343
- schema: AgentConfigValidateSchema
344
- }
391
+ },
392
+ responses: {
393
+ 200: {
394
+ description: "Validation result",
395
+ content: {
396
+ "application/json": {
397
+ schema: ValidateConfigResponseSchema
345
398
  }
346
399
  }
347
400
  },
348
- responses: {
349
- 200: {
350
- description: "Validation result",
351
- content: {
352
- "application/json": {
353
- schema: import_zod_openapi.z.object({
354
- valid: import_zod_openapi.z.boolean().describe("Whether configuration is valid"),
355
- errors: import_zod_openapi.z.array(
356
- import_zod_openapi.z.object({
357
- line: import_zod_openapi.z.number().int().optional().describe("Line number"),
358
- column: import_zod_openapi.z.number().int().optional().describe("Column number"),
359
- path: import_zod_openapi.z.string().optional().describe("Configuration path"),
360
- message: import_zod_openapi.z.string().describe("Error message"),
361
- code: import_zod_openapi.z.string().describe("Error code")
362
- }).passthrough()
363
- ).describe("Validation errors"),
364
- warnings: import_zod_openapi.z.array(
365
- import_zod_openapi.z.object({
366
- path: import_zod_openapi.z.string().describe("Configuration path"),
367
- message: import_zod_openapi.z.string().describe("Warning message"),
368
- code: import_zod_openapi.z.string().describe("Warning code")
369
- }).strict()
370
- ).describe("Configuration warnings")
371
- }).strict()
372
- }
401
+ 400: import_responses.BadRequestErrorResponse,
402
+ 404: import_responses.NotFoundErrorResponse,
403
+ 409: import_responses.ConflictErrorResponse,
404
+ 500: import_responses.InternalErrorResponse
405
+ }
406
+ });
407
+ const saveConfigRoute = (0, import_zod_openapi.createRoute)({
408
+ method: "post",
409
+ path: "/agent/config",
410
+ summary: "Save Agent Configuration",
411
+ description: "Saves and applies YAML agent configuration. Creates backup before saving",
412
+ tags: ["agent"],
413
+ request: {
414
+ body: {
415
+ content: {
416
+ "application/json": {
417
+ schema: AgentConfigSaveSchema
373
418
  }
374
419
  }
375
420
  }
376
- });
377
- const saveConfigRoute = (0, import_zod_openapi.createRoute)({
378
- method: "post",
379
- path: "/agent/config",
380
- summary: "Save Agent Configuration",
381
- description: "Saves and applies YAML agent configuration. Creates backup before saving",
382
- tags: ["agent"],
383
- request: {
384
- body: {
385
- content: {
386
- "application/json": {
387
- schema: AgentConfigSaveSchema
388
- }
421
+ },
422
+ responses: {
423
+ 200: {
424
+ description: "Configuration saved",
425
+ content: {
426
+ "application/json": {
427
+ schema: SaveConfigResponseSchema
389
428
  }
390
429
  }
391
430
  },
392
- responses: {
393
- 200: {
394
- description: "Configuration saved",
395
- content: {
396
- "application/json": {
397
- schema: SaveConfigResponseSchema
398
- }
399
- }
400
- }
431
+ 400: import_responses.BadRequestErrorResponse,
432
+ 404: import_responses.NotFoundErrorResponse,
433
+ 409: import_responses.ConflictErrorResponse,
434
+ 500: import_responses.InternalErrorResponse
435
+ }
436
+ });
437
+ const exportConfigRoute = (0, import_zod_openapi.createRoute)({
438
+ method: "get",
439
+ path: "/agent/config/export",
440
+ summary: "Export Agent Configuration",
441
+ description: "Exports the effective agent configuration with sensitive values redacted",
442
+ tags: ["agent"],
443
+ request: {
444
+ query: ExportConfigQuerySchema
445
+ },
446
+ responses: {
447
+ 200: {
448
+ description: "Exported configuration",
449
+ content: { "application/x-yaml": { schema: import_zod_openapi.z.string() } }
401
450
  }
402
- });
403
- const exportConfigRoute = (0, import_zod_openapi.createRoute)({
404
- method: "get",
405
- path: "/agent/config/export",
406
- summary: "Export Agent Configuration",
407
- description: "Exports the effective agent configuration with sensitive values redacted",
408
- tags: ["agent"],
409
- request: {
410
- query: import_zod_openapi.z.object({
411
- sessionId: import_zod_openapi.z.string().optional().describe("Session identifier to export session-specific configuration")
412
- })
413
- },
414
- responses: {
415
- 200: {
416
- description: "Exported configuration",
417
- content: { "application/x-yaml": { schema: import_zod_openapi.z.string() } }
418
- }
451
+ }
452
+ });
453
+ function createAgentsRouter(getAgent, context, getAgentConfigPath) {
454
+ const app = new import_zod_openapi.OpenAPIHono();
455
+ const { switchAgentById, switchAgentByPath, resolveAgentInfo, getActiveAgentId } = context;
456
+ const resolveAgentConfigPath = async (ctx) => {
457
+ const configPath = await getAgentConfigPath(ctx);
458
+ if (!configPath) {
459
+ throw import_core.AgentError.noConfigPath();
419
460
  }
420
- });
461
+ return configPath;
462
+ };
421
463
  return app.openapi(listRoute, async (ctx) => {
422
464
  const agents = await import_agent_management.AgentFactory.listAgents();
423
465
  const currentId = getActiveAgentId() ?? null;
424
- return ctx.json({
425
- installed: agents.installed,
426
- available: agents.available,
427
- current: currentId ? await resolveAgentInfo(currentId) : { id: null, name: null }
428
- });
466
+ return ctx.json(
467
+ {
468
+ installed: agents.installed,
469
+ available: agents.available,
470
+ current: currentId ? await resolveAgentInfo(currentId) : { id: null, name: null }
471
+ },
472
+ 200
473
+ );
429
474
  }).openapi(currentRoute, async (ctx) => {
430
475
  const currentId = getActiveAgentId() ?? null;
431
476
  if (!currentId) {
432
- return ctx.json({ id: null, name: null });
477
+ return ctx.json({ id: null, name: null }, 200);
433
478
  }
434
- return ctx.json(await resolveAgentInfo(currentId));
479
+ return ctx.json(await resolveAgentInfo(currentId), 200);
435
480
  }).openapi(installRoute, async (ctx) => {
436
481
  const body = ctx.req.valid("json");
437
482
  if ("sourcePath" in body && "metadata" in body) {
@@ -462,53 +507,68 @@ function createAgentsRouter(getAgent, context, getAgentConfigPath) {
462
507
  }).openapi(switchRoute, async (ctx) => {
463
508
  const { id, path: filePath } = ctx.req.valid("json");
464
509
  const result = filePath ? await switchAgentByPath(filePath) : await switchAgentById(id);
465
- return ctx.json({ switched: true, ...result });
510
+ return ctx.json({ switched: true, ...result }, 200);
466
511
  }).openapi(validateNameRoute, async (ctx) => {
467
512
  const { id } = ctx.req.valid("json");
468
513
  const agents = await import_agent_management.AgentFactory.listAgents();
469
514
  const installedAgent = agents.installed.find((a) => a.id === id);
470
515
  if (installedAgent) {
471
- return ctx.json({
472
- valid: false,
473
- conflict: installedAgent.type,
474
- message: `Agent id '${id}' already exists (${installedAgent.type})`
475
- });
516
+ return ctx.json(
517
+ {
518
+ valid: false,
519
+ conflict: installedAgent.type,
520
+ message: `Agent id '${id}' already exists (${installedAgent.type})`
521
+ },
522
+ 200
523
+ );
476
524
  }
477
525
  const availableAgent = agents.available.find((a) => a.id === id);
478
526
  if (availableAgent) {
479
- return ctx.json({
480
- valid: false,
481
- conflict: availableAgent.type,
482
- message: `Agent id '${id}' conflicts with ${availableAgent.type} agent`
483
- });
527
+ return ctx.json(
528
+ {
529
+ valid: false,
530
+ conflict: availableAgent.type,
531
+ message: `Agent id '${id}' conflicts with ${availableAgent.type} agent`
532
+ },
533
+ 200
534
+ );
484
535
  }
485
- return ctx.json({ valid: true });
536
+ return ctx.json({ valid: true }, 200);
486
537
  }).openapi(uninstallRoute, async (ctx) => {
487
538
  const { id, force } = ctx.req.valid("json");
488
539
  await import_agent_management.AgentFactory.uninstallAgent(id, force);
489
- return ctx.json({ uninstalled: true, id });
540
+ return ctx.json({ uninstalled: true, id }, 200);
490
541
  }).openapi(customCreateRoute, async (ctx) => {
491
542
  const { id, name, description, author, tags, config } = ctx.req.valid("json");
492
- const provider = config.llm.provider;
493
- let agentConfig = config;
494
- if (config.llm.apiKey && !config.llm.apiKey.startsWith("$")) {
495
- const meta = await (0, import_agent_management.saveProviderApiKey)(provider, config.llm.apiKey, process.cwd());
543
+ const configResult = import_agent_config.AgentConfigSchema.safeParse(config);
544
+ if (!configResult.success) {
545
+ throw new import_core2.DextoValidationError((0, import_core.zodToIssues)(configResult.error));
546
+ }
547
+ const validatedConfig = configResult.data;
548
+ const provider = validatedConfig.llm.provider;
549
+ let agentConfig = validatedConfig;
550
+ if (validatedConfig.llm.apiKey && !validatedConfig.llm.apiKey.startsWith("$")) {
551
+ const meta = await (0, import_agent_management.saveProviderApiKey)(
552
+ provider,
553
+ validatedConfig.llm.apiKey,
554
+ process.cwd()
555
+ );
496
556
  const apiKeyRef = `$${meta.envVar}`;
497
557
  import_core.logger.info(
498
558
  `Stored API key securely for ${provider}, using env var: ${meta.envVar}`
499
559
  );
500
560
  agentConfig = {
501
- ...config,
561
+ ...validatedConfig,
502
562
  llm: {
503
- ...config.llm,
563
+ ...validatedConfig.llm,
504
564
  apiKey: apiKeyRef
505
565
  }
506
566
  };
507
- } else if (!config.llm.apiKey) {
567
+ } else if (!validatedConfig.llm.apiKey) {
508
568
  agentConfig = {
509
- ...config,
569
+ ...validatedConfig,
510
570
  llm: {
511
- ...config.llm,
571
+ ...validatedConfig.llm,
512
572
  apiKey: `$${(0, import_agent_management.getPrimaryApiKeyEnvVar)(provider)}`
513
573
  }
514
574
  };
@@ -540,26 +600,32 @@ function createAgentsRouter(getAgent, context, getAgentConfigPath) {
540
600
  const relativePath = import_path.default.basename(agentPath);
541
601
  const ext = import_path.default.extname(agentPath);
542
602
  const name = import_path.default.basename(agentPath, ext);
543
- return ctx.json({
544
- path: agentPath,
545
- relativePath,
546
- name,
547
- isDefault: name === "coding-agent"
548
- });
603
+ return ctx.json(
604
+ {
605
+ path: agentPath,
606
+ relativePath,
607
+ name,
608
+ isDefault: name === "coding-agent"
609
+ },
610
+ 200
611
+ );
549
612
  }).openapi(getConfigRoute, async (ctx) => {
550
613
  const agentPath = await resolveAgentConfigPath(ctx);
551
614
  const yamlContent = await import_fs.promises.readFile(agentPath, "utf-8");
552
615
  const stats = await import_fs.promises.stat(agentPath);
553
- return ctx.json({
554
- yaml: yamlContent,
555
- path: agentPath,
556
- relativePath: import_path.default.basename(agentPath),
557
- lastModified: stats.mtime,
558
- warnings: [
559
- "Environment variables ($VAR) will be resolved at runtime",
560
- "API keys should use environment variables"
561
- ]
562
- });
616
+ return ctx.json(
617
+ {
618
+ yaml: yamlContent,
619
+ path: agentPath,
620
+ relativePath: import_path.default.basename(agentPath),
621
+ lastModified: stats.mtime,
622
+ warnings: [
623
+ "Environment variables ($VAR) will be resolved at runtime",
624
+ "API keys should use environment variables"
625
+ ]
626
+ },
627
+ 200
628
+ );
563
629
  }).openapi(validateConfigRoute, async (ctx) => {
564
630
  const { yaml } = ctx.req.valid("json");
565
631
  let parsed;
@@ -568,32 +634,38 @@ function createAgentsRouter(getAgent, context, getAgentConfigPath) {
568
634
  } catch (parseError) {
569
635
  const message = parseError instanceof Error ? parseError.message : String(parseError);
570
636
  const linePos = typeof parseError === "object" && parseError !== null && "linePos" in parseError ? parseError.linePos : void 0;
571
- return ctx.json({
572
- valid: false,
573
- errors: [
574
- {
575
- line: linePos?.[0]?.line ?? 1,
576
- column: linePos?.[0]?.col ?? 1,
577
- message,
578
- code: "YAML_PARSE_ERROR"
579
- }
580
- ],
581
- warnings: []
582
- });
637
+ return ctx.json(
638
+ {
639
+ valid: false,
640
+ errors: [
641
+ {
642
+ line: linePos?.[0]?.line ?? 1,
643
+ column: linePos?.[0]?.col ?? 1,
644
+ message,
645
+ code: "YAML_PARSE_ERROR"
646
+ }
647
+ ],
648
+ warnings: []
649
+ },
650
+ 200
651
+ );
583
652
  }
584
653
  if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
585
- return ctx.json({
586
- valid: false,
587
- errors: [
588
- {
589
- line: 1,
590
- column: 1,
591
- message: "Configuration must be a valid YAML object",
592
- code: "INVALID_CONFIG_TYPE"
593
- }
594
- ],
595
- warnings: []
596
- });
654
+ return ctx.json(
655
+ {
656
+ valid: false,
657
+ errors: [
658
+ {
659
+ line: 1,
660
+ column: 1,
661
+ message: "Configuration must be a valid YAML object",
662
+ code: "INVALID_CONFIG_TYPE"
663
+ }
664
+ ],
665
+ warnings: []
666
+ },
667
+ 200
668
+ );
597
669
  }
598
670
  const enriched = (0, import_agent_management.enrichAgentConfig)(parsed, void 0);
599
671
  const result = import_agent_config.AgentConfigSchema.safeParse(enriched);
@@ -604,11 +676,14 @@ function createAgentsRouter(getAgent, context, getAgentConfigPath) {
604
676
  message: issue.message,
605
677
  code: "SCHEMA_VALIDATION_ERROR"
606
678
  }));
607
- return ctx.json({
608
- valid: false,
609
- errors,
610
- warnings: []
611
- });
679
+ return ctx.json(
680
+ {
681
+ valid: false,
682
+ errors,
683
+ warnings: []
684
+ },
685
+ 200
686
+ );
612
687
  }
613
688
  const warnings = [];
614
689
  if (parsed.llm?.apiKey && !parsed.llm.apiKey.startsWith("$")) {
@@ -618,11 +693,14 @@ function createAgentsRouter(getAgent, context, getAgentConfigPath) {
618
693
  code: "SECURITY_WARNING"
619
694
  });
620
695
  }
621
- return ctx.json({
622
- valid: true,
623
- errors: [],
624
- warnings
625
- });
696
+ return ctx.json(
697
+ {
698
+ valid: true,
699
+ errors: [],
700
+ warnings
701
+ },
702
+ 200
703
+ );
626
704
  }).openapi(saveConfigRoute, async (ctx) => {
627
705
  const { yaml } = ctx.req.valid("json");
628
706
  let parsed;
@@ -673,14 +751,17 @@ function createAgentsRouter(getAgent, context, getAgentConfigPath) {
673
751
  await import_fs.promises.unlink(backupPath).catch(() => {
674
752
  });
675
753
  import_core.logger.info(`Agent configuration saved and applied: ${agentPath}`);
676
- return ctx.json({
677
- ok: true,
678
- path: agentPath,
679
- reloaded: true,
680
- restarted: true,
681
- changesApplied: ["restart"],
682
- message: "Configuration saved and applied successfully (agent restarted)"
683
- });
754
+ return ctx.json(
755
+ {
756
+ ok: true,
757
+ path: agentPath,
758
+ reloaded: true,
759
+ restarted: true,
760
+ changesApplied: ["restart"],
761
+ message: "Configuration saved and applied successfully (agent restarted)"
762
+ },
763
+ 200
764
+ );
684
765
  } catch (error) {
685
766
  await import_fs.promises.copyFile(backupPath, agentPath).catch(() => {
686
767
  });