@agentuity/runtime 1.0.47 → 2.0.0-beta.0

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 (104) hide show
  1. package/dist/_globals.d.ts +58 -0
  2. package/dist/_globals.d.ts.map +1 -0
  3. package/dist/_globals.js +71 -0
  4. package/dist/_globals.js.map +1 -0
  5. package/dist/_metadata.d.ts.map +1 -1
  6. package/dist/_metadata.js +14 -0
  7. package/dist/_metadata.js.map +1 -1
  8. package/dist/_process-protection.d.ts +2 -0
  9. package/dist/_process-protection.d.ts.map +1 -1
  10. package/dist/_process-protection.js +14 -23
  11. package/dist/_process-protection.js.map +1 -1
  12. package/dist/_server.d.ts +4 -0
  13. package/dist/_server.d.ts.map +1 -1
  14. package/dist/_server.js +4 -0
  15. package/dist/_server.js.map +1 -1
  16. package/dist/_services.d.ts +1 -1
  17. package/dist/_services.d.ts.map +1 -1
  18. package/dist/_services.js +5 -1
  19. package/dist/_services.js.map +1 -1
  20. package/dist/_standalone.d.ts.map +1 -1
  21. package/dist/_standalone.js +3 -9
  22. package/dist/_standalone.js.map +1 -1
  23. package/dist/agent.d.ts.map +1 -1
  24. package/dist/agent.js +1 -0
  25. package/dist/agent.js.map +1 -1
  26. package/dist/app.d.ts +149 -71
  27. package/dist/app.d.ts.map +1 -1
  28. package/dist/app.js +121 -156
  29. package/dist/app.js.map +1 -1
  30. package/dist/bootstrap.d.ts +44 -0
  31. package/dist/bootstrap.d.ts.map +1 -0
  32. package/dist/bootstrap.js +256 -0
  33. package/dist/bootstrap.js.map +1 -0
  34. package/dist/dev-patches/aisdk.d.ts.map +1 -1
  35. package/dist/dev-patches/aisdk.js +6 -8
  36. package/dist/dev-patches/aisdk.js.map +1 -1
  37. package/dist/dev-patches/gateway.d.ts.map +1 -1
  38. package/dist/dev-patches/gateway.js +7 -8
  39. package/dist/dev-patches/gateway.js.map +1 -1
  40. package/dist/handlers/_route-meta.d.ts +20 -0
  41. package/dist/handlers/_route-meta.d.ts.map +1 -0
  42. package/dist/handlers/_route-meta.js +25 -0
  43. package/dist/handlers/_route-meta.js.map +1 -0
  44. package/dist/handlers/cron.d.ts.map +1 -1
  45. package/dist/handlers/cron.js +3 -1
  46. package/dist/handlers/cron.js.map +1 -1
  47. package/dist/handlers/sse.d.ts +3 -3
  48. package/dist/handlers/sse.d.ts.map +1 -1
  49. package/dist/handlers/sse.js +4 -16
  50. package/dist/handlers/sse.js.map +1 -1
  51. package/dist/handlers/stream.d.ts.map +1 -1
  52. package/dist/handlers/stream.js +4 -12
  53. package/dist/handlers/stream.js.map +1 -1
  54. package/dist/handlers/websocket.d.ts +3 -1
  55. package/dist/handlers/websocket.d.ts.map +1 -1
  56. package/dist/handlers/websocket.js +6 -37
  57. package/dist/handlers/websocket.js.map +1 -1
  58. package/dist/index.d.ts +1 -1
  59. package/dist/index.d.ts.map +1 -1
  60. package/dist/index.js +1 -1
  61. package/dist/index.js.map +1 -1
  62. package/dist/middleware.d.ts +1 -8
  63. package/dist/middleware.d.ts.map +1 -1
  64. package/dist/middleware.js +29 -71
  65. package/dist/middleware.js.map +1 -1
  66. package/dist/otel/logger.d.ts.map +1 -1
  67. package/dist/otel/logger.js +4 -7
  68. package/dist/otel/logger.js.map +1 -1
  69. package/dist/otel/otel.d.ts +4 -1
  70. package/dist/otel/otel.d.ts.map +1 -1
  71. package/dist/otel/otel.js +13 -2
  72. package/dist/otel/otel.js.map +1 -1
  73. package/dist/router.d.ts +10 -62
  74. package/dist/router.d.ts.map +1 -1
  75. package/dist/router.js +9 -146
  76. package/dist/router.js.map +1 -1
  77. package/dist/workbench.d.ts +1 -1
  78. package/dist/workbench.d.ts.map +1 -1
  79. package/dist/workbench.js +120 -12
  80. package/dist/workbench.js.map +1 -1
  81. package/package.json +7 -7
  82. package/src/_globals.ts +92 -0
  83. package/src/_metadata.ts +14 -0
  84. package/src/_process-protection.ts +17 -28
  85. package/src/_server.ts +4 -0
  86. package/src/_services.ts +6 -2
  87. package/src/_standalone.ts +4 -9
  88. package/src/agent.ts +1 -0
  89. package/src/app.ts +294 -195
  90. package/src/bootstrap.ts +316 -0
  91. package/src/dev-patches/aisdk.ts +8 -11
  92. package/src/dev-patches/gateway.ts +9 -11
  93. package/src/globals.d.ts +28 -0
  94. package/src/handlers/_route-meta.ts +31 -0
  95. package/src/handlers/cron.ts +4 -1
  96. package/src/handlers/sse.ts +8 -19
  97. package/src/handlers/stream.ts +5 -12
  98. package/src/handlers/websocket.ts +11 -37
  99. package/src/index.ts +2 -3
  100. package/src/middleware.ts +40 -99
  101. package/src/otel/logger.ts +5 -8
  102. package/src/otel/otel.ts +14 -2
  103. package/src/router.ts +12 -216
  104. package/src/workbench.ts +135 -12
package/src/workbench.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { Context, Handler, MiddlewareHandler } from 'hono';
2
2
  import { toJSONSchema } from '@agentuity/server';
3
+ import type { JSONSchema } from '@agentuity/schema';
3
4
  import { getAgents, createAgentMiddleware } from './agent';
4
5
  import { createRouter } from './router';
5
6
  import { websocket, type WebSocketConnection } from './handlers/websocket';
@@ -519,24 +520,31 @@ export const createWorkbenchMetadataRoute = (): Handler => {
519
520
  // Try to find runtime agent by name to get JSON schemas
520
521
  const runtimeAgent = agentsByName.get(agent.name);
521
522
 
523
+ const inputJsonSchema = runtimeAgent?.inputSchema
524
+ ? toJSONSchema(runtimeAgent.inputSchema)
525
+ : undefined;
526
+ const outputJsonSchema = runtimeAgent?.outputSchema
527
+ ? toJSONSchema(runtimeAgent.outputSchema)
528
+ : undefined;
529
+
522
530
  schemas.agents[agent.id] = {
523
531
  schema: {
524
- input: agent.schema?.input
532
+ input: inputJsonSchema
525
533
  ? {
526
- code: agent.schema.input,
527
- json: runtimeAgent?.inputSchema
528
- ? toJSONSchema(runtimeAgent.inputSchema)
529
- : undefined,
534
+ code: jsonSchemaToTypeScript(inputJsonSchema),
535
+ json: inputJsonSchema,
530
536
  }
531
- : undefined,
532
- output: agent.schema?.output
537
+ : agent.schema?.input
538
+ ? { code: agent.schema.input, json: undefined }
539
+ : undefined,
540
+ output: outputJsonSchema
533
541
  ? {
534
- code: agent.schema.output,
535
- json: runtimeAgent?.outputSchema
536
- ? toJSONSchema(runtimeAgent.outputSchema)
537
- : undefined,
542
+ code: jsonSchemaToTypeScript(outputJsonSchema),
543
+ json: outputJsonSchema,
538
544
  }
539
- : undefined,
545
+ : agent.schema?.output
546
+ ? { code: agent.schema.output, json: undefined }
547
+ : undefined,
540
548
  },
541
549
  metadata: {
542
550
  id: agent.id,
@@ -600,3 +608,118 @@ export const createWorkbenchWebsocketHandler = () => {
600
608
  * @deprecated Use createWorkbenchWebsocketHandler instead
601
609
  */
602
610
  export const createWorkbenchWebsocketRoute = createWorkbenchWebsocketHandler;
611
+
612
+ /**
613
+ * Convert a JSON Schema object to a TypeScript type string for display.
614
+ * Produces clean, readable type notation for the workbench schema panel.
615
+ *
616
+ * @example
617
+ * ```typescript
618
+ * jsonSchemaToTypeScript({
619
+ * type: 'object',
620
+ * properties: { name: { type: 'string' }, age: { type: 'number' } },
621
+ * required: ['name', 'age'],
622
+ * });
623
+ * // "{\n name: string;\n age: number;\n}"
624
+ * ```
625
+ */
626
+ /** Escape a string for use inside a double-quoted TypeScript string literal. */
627
+ function escapeString(s: string): string {
628
+ return s.replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\n/g, '\\n').replace(/\r/g, '\\r');
629
+ }
630
+
631
+ /** Check if a property key is a valid unquoted TypeScript identifier. */
632
+ function isValidIdentifier(key: string): boolean {
633
+ return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(key);
634
+ }
635
+
636
+ function jsonSchemaToTypeScript(schema: JSONSchema, indent = 0): string {
637
+ const pad = ' '.repeat(indent);
638
+ const inner = ' '.repeat(indent + 1);
639
+
640
+ // Handle const (literal type)
641
+ if (schema.const !== undefined) {
642
+ return typeof schema.const === 'string'
643
+ ? `"${escapeString(schema.const)}"`
644
+ : String(schema.const);
645
+ }
646
+
647
+ // Handle enum (union of literals)
648
+ if (schema.enum) {
649
+ return schema.enum
650
+ .map((v) => (typeof v === 'string' ? `"${escapeString(String(v))}"` : String(v)))
651
+ .join(' | ');
652
+ }
653
+
654
+ // Handle anyOf / oneOf (union types)
655
+ const unionSchemas = schema.anyOf ?? schema.oneOf;
656
+ if (unionSchemas) {
657
+ // Nullable pattern: anyOf with one type and one null
658
+ if (unionSchemas.length === 2) {
659
+ const nullIdx = unionSchemas.findIndex((s) => s.type === 'null');
660
+ if (nullIdx !== -1) {
661
+ const other = unionSchemas[nullIdx === 0 ? 1 : 0];
662
+ if (other) {
663
+ return `${jsonSchemaToTypeScript(other, indent)} | null`;
664
+ }
665
+ }
666
+ }
667
+ return unionSchemas.map((s) => jsonSchemaToTypeScript(s, indent)).join(' | ');
668
+ }
669
+
670
+ // Handle allOf (intersection types)
671
+ if (schema.allOf) {
672
+ return schema.allOf.map((s) => jsonSchemaToTypeScript(s, indent)).join(' & ');
673
+ }
674
+
675
+ switch (schema.type) {
676
+ case 'string':
677
+ return 'string';
678
+ case 'number':
679
+ case 'integer':
680
+ return 'number';
681
+ case 'boolean':
682
+ return 'boolean';
683
+ case 'null':
684
+ return 'null';
685
+
686
+ case 'array': {
687
+ if (!schema.items) return 'unknown[]';
688
+ const itemType = jsonSchemaToTypeScript(schema.items, indent);
689
+ // Wrap union types in parens: (A | B)[]
690
+ return itemType.includes(' | ') ? `(${itemType})[]` : `${itemType}[]`;
691
+ }
692
+
693
+ case 'object': {
694
+ if (!schema.properties || Object.keys(schema.properties).length === 0) {
695
+ if (schema.additionalProperties && typeof schema.additionalProperties === 'object') {
696
+ return `Record<string, ${jsonSchemaToTypeScript(schema.additionalProperties, indent)}>`;
697
+ }
698
+ return 'Record<string, unknown>';
699
+ }
700
+
701
+ const required = new Set(schema.required ?? []);
702
+ const lines: string[] = ['{'];
703
+
704
+ for (const [key, propSchema] of Object.entries(schema.properties)) {
705
+ const optional = !required.has(key);
706
+ const propType = jsonSchemaToTypeScript(propSchema, indent + 1);
707
+ const desc = propSchema.description ? ` // ${propSchema.description}` : '';
708
+ const quotedKey = isValidIdentifier(key) ? key : `"${escapeString(key)}"`;
709
+ lines.push(`${inner}${quotedKey}${optional ? '?' : ''}: ${propType};${desc}`);
710
+ }
711
+
712
+ lines.push(`${pad}}`);
713
+ return lines.join('\n');
714
+ }
715
+
716
+ default:
717
+ if (schema.properties) {
718
+ return jsonSchemaToTypeScript({ ...schema, type: 'object' }, indent);
719
+ }
720
+ if (schema.items) {
721
+ return jsonSchemaToTypeScript({ ...schema, type: 'array' }, indent);
722
+ }
723
+ return 'unknown';
724
+ }
725
+ }