@radaros/transport 0.3.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -4,6 +4,16 @@ import { createRequire as createRequire3 } from "module";
4
4
  // src/express/swagger.ts
5
5
  import { createRequire } from "module";
6
6
  var _require = createRequire(import.meta.url);
7
+ function zodSchemaToJsonSchema(schema) {
8
+ try {
9
+ const zodToJsonSchema = _require("zod-to-json-schema").default ?? _require("zod-to-json-schema");
10
+ const result = zodToJsonSchema(schema, { target: "openApi3" });
11
+ const { $schema, ...rest } = result;
12
+ return rest;
13
+ } catch {
14
+ return null;
15
+ }
16
+ }
7
17
  var SCHEMAS = {
8
18
  RunRequest: {
9
19
  type: "object",
@@ -206,6 +216,45 @@ function generateOpenAPISpec(routerOpts, swaggerOpts = {}) {
206
216
  spec.tags.push({ name: "Agents", description: "Agent endpoints for running and streaming AI agents" });
207
217
  for (const [name, agent] of Object.entries(routerOpts.agents)) {
208
218
  const agentDesc = buildAgentDescription(agent);
219
+ let responseSchemaRef = "#/components/schemas/RunOutput";
220
+ const zodSchema = agent.structuredOutputSchema;
221
+ if (zodSchema) {
222
+ const structuredJsonSchema = zodSchemaToJsonSchema(zodSchema);
223
+ if (structuredJsonSchema) {
224
+ const schemaName = `RunOutput_${name}`;
225
+ spec.components.schemas[schemaName] = {
226
+ type: "object",
227
+ properties: {
228
+ text: { type: "string", description: "Raw agent response text" },
229
+ toolCalls: {
230
+ type: "array",
231
+ items: {
232
+ type: "object",
233
+ properties: {
234
+ toolCallId: { type: "string" },
235
+ toolName: { type: "string" },
236
+ result: {}
237
+ }
238
+ }
239
+ },
240
+ usage: {
241
+ type: "object",
242
+ properties: {
243
+ promptTokens: { type: "number" },
244
+ completionTokens: { type: "number" },
245
+ totalTokens: { type: "number" }
246
+ }
247
+ },
248
+ structured: {
249
+ ...structuredJsonSchema,
250
+ description: "Parsed structured output"
251
+ },
252
+ durationMs: { type: "number" }
253
+ }
254
+ };
255
+ responseSchemaRef = `#/components/schemas/${schemaName}`;
256
+ }
257
+ }
209
258
  spec.paths[`${prefix}/agents/${name}/run`] = {
210
259
  post: {
211
260
  tags: ["Agents"],
@@ -228,7 +277,7 @@ function generateOpenAPISpec(routerOpts, swaggerOpts = {}) {
228
277
  description: "Agent run result",
229
278
  content: {
230
279
  "application/json": {
231
- schema: { $ref: "#/components/schemas/RunOutput" }
280
+ schema: { $ref: responseSchemaRef }
232
281
  }
233
282
  }
234
283
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@radaros/transport",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -20,7 +20,7 @@
20
20
  "typescript": "^5.6.0"
21
21
  },
22
22
  "peerDependencies": {
23
- "@radaros/core": "^0.3.0",
23
+ "@radaros/core": "^0.3.2",
24
24
  "@types/express": "^4.0.0 || ^5.0.0",
25
25
  "express": "^4.0.0 || ^5.0.0",
26
26
  "multer": ">=1.4.0",
@@ -3,6 +3,17 @@ import type { RouterOptions, SwaggerOptions } from "./types.js";
3
3
 
4
4
  const _require = createRequire(import.meta.url);
5
5
 
6
+ function zodSchemaToJsonSchema(schema: any): Record<string, unknown> | null {
7
+ try {
8
+ const zodToJsonSchema = _require("zod-to-json-schema").default ?? _require("zod-to-json-schema");
9
+ const result = zodToJsonSchema(schema, { target: "openApi3" });
10
+ const { $schema, ...rest } = result as Record<string, unknown>;
11
+ return rest;
12
+ } catch {
13
+ return null;
14
+ }
15
+ }
16
+
6
17
  interface OpenAPISpec {
7
18
  openapi: string;
8
19
  info: {
@@ -242,6 +253,47 @@ export function generateOpenAPISpec(
242
253
  for (const [name, agent] of Object.entries(routerOpts.agents)) {
243
254
  const agentDesc = buildAgentDescription(agent);
244
255
 
256
+ let responseSchemaRef = "#/components/schemas/RunOutput";
257
+
258
+ const zodSchema = (agent as any).structuredOutputSchema;
259
+ if (zodSchema) {
260
+ const structuredJsonSchema = zodSchemaToJsonSchema(zodSchema);
261
+ if (structuredJsonSchema) {
262
+ const schemaName = `RunOutput_${name}`;
263
+ (spec.components.schemas as Record<string, unknown>)[schemaName] = {
264
+ type: "object",
265
+ properties: {
266
+ text: { type: "string", description: "Raw agent response text" },
267
+ toolCalls: {
268
+ type: "array",
269
+ items: {
270
+ type: "object",
271
+ properties: {
272
+ toolCallId: { type: "string" },
273
+ toolName: { type: "string" },
274
+ result: {},
275
+ },
276
+ },
277
+ },
278
+ usage: {
279
+ type: "object",
280
+ properties: {
281
+ promptTokens: { type: "number" },
282
+ completionTokens: { type: "number" },
283
+ totalTokens: { type: "number" },
284
+ },
285
+ },
286
+ structured: {
287
+ ...structuredJsonSchema,
288
+ description: "Parsed structured output",
289
+ },
290
+ durationMs: { type: "number" },
291
+ },
292
+ };
293
+ responseSchemaRef = `#/components/schemas/${schemaName}`;
294
+ }
295
+ }
296
+
245
297
  spec.paths[`${prefix}/agents/${name}/run`] = {
246
298
  post: {
247
299
  tags: ["Agents"],
@@ -264,7 +316,7 @@ export function generateOpenAPISpec(
264
316
  description: "Agent run result",
265
317
  content: {
266
318
  "application/json": {
267
- schema: { $ref: "#/components/schemas/RunOutput" },
319
+ schema: { $ref: responseSchemaRef },
268
320
  },
269
321
  },
270
322
  },