@agentuity/runtime 1.0.59 → 2.0.0-beta.1

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 (113) 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 +124 -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 +259 -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 +30 -72
  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/services/sandbox/http.d.ts.map +1 -1
  78. package/dist/services/sandbox/http.js +1 -13
  79. package/dist/services/sandbox/http.js.map +1 -1
  80. package/dist/version-check.d.ts +20 -0
  81. package/dist/version-check.d.ts.map +1 -0
  82. package/dist/version-check.js +133 -0
  83. package/dist/version-check.js.map +1 -0
  84. package/dist/workbench.d.ts +1 -1
  85. package/dist/workbench.d.ts.map +1 -1
  86. package/dist/workbench.js +120 -12
  87. package/dist/workbench.js.map +1 -1
  88. package/package.json +7 -7
  89. package/src/_globals.ts +92 -0
  90. package/src/_metadata.ts +14 -0
  91. package/src/_process-protection.ts +17 -28
  92. package/src/_server.ts +4 -0
  93. package/src/_services.ts +6 -2
  94. package/src/_standalone.ts +4 -9
  95. package/src/agent.ts +1 -0
  96. package/src/app.ts +298 -195
  97. package/src/bootstrap.ts +321 -0
  98. package/src/dev-patches/aisdk.ts +8 -11
  99. package/src/dev-patches/gateway.ts +9 -11
  100. package/src/globals.d.ts +28 -0
  101. package/src/handlers/_route-meta.ts +31 -0
  102. package/src/handlers/cron.ts +4 -1
  103. package/src/handlers/sse.ts +8 -19
  104. package/src/handlers/stream.ts +5 -12
  105. package/src/handlers/websocket.ts +11 -37
  106. package/src/index.ts +2 -3
  107. package/src/middleware.ts +41 -100
  108. package/src/otel/logger.ts +5 -8
  109. package/src/otel/otel.ts +14 -2
  110. package/src/router.ts +12 -216
  111. package/src/services/sandbox/http.ts +0 -37
  112. package/src/version-check.ts +155 -0
  113. package/src/workbench.ts +135 -12
@@ -0,0 +1,155 @@
1
+ /**
2
+ * Version consistency check for @agentuity/* packages.
3
+ *
4
+ * Logs a warning if there are mismatched major versions across SDK packages
5
+ * at runtime startup. This helps developers catch version conflicts early.
6
+ */
7
+
8
+ import type { Logger } from './logger';
9
+ import { isV1Package, showDeprecationWarning } from '@agentuity/core';
10
+
11
+ /**
12
+ * Known @agentuity/* packages that should have consistent versions.
13
+ */
14
+ const KNOWN_PACKAGES = [
15
+ '@agentuity/core',
16
+ '@agentuity/runtime',
17
+ '@agentuity/server',
18
+ '@agentuity/frontend',
19
+ '@agentuity/react',
20
+ '@agentuity/schema',
21
+ '@agentuity/auth',
22
+ '@agentuity/postgres',
23
+ '@agentuity/drizzle',
24
+ '@agentuity/evals',
25
+ '@agentuity/workbench',
26
+ '@agentuity/queue',
27
+ '@agentuity/webhook',
28
+ '@agentuity/schedule',
29
+ '@agentuity/task',
30
+ '@agentuity/keyvalue',
31
+ '@agentuity/vector',
32
+ '@agentuity/stream',
33
+ ];
34
+
35
+ interface PackageVersion {
36
+ name: string;
37
+ version: string;
38
+ major: number;
39
+ }
40
+
41
+ /**
42
+ * Extract major version from semver string.
43
+ */
44
+ function extractMajor(version: string): number {
45
+ const match = version.match(/^(\d+)\.\d+\.\d+/);
46
+ return match && match[1] ? parseInt(match[1], 10) : 0;
47
+ }
48
+
49
+ /**
50
+ * Get version of a package from its package.json (if importable).
51
+ */
52
+ function getPackageVersion(packageName: string): string | null {
53
+ try {
54
+ // Try to import the package.json
55
+ // This works for ESM packages that export their package.json
56
+ const pkg = require(`${packageName}/package.json`);
57
+ return pkg?.version || null;
58
+ } catch {
59
+ // Fallback: try to read from node_modules
60
+ try {
61
+ const fs = require('node:fs');
62
+ const pkgPath = require.resolve(`${packageName}/package.json`);
63
+ if (typeof pkgPath !== 'string') {
64
+ return null;
65
+ }
66
+ const pkgJson = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
67
+ return pkgJson?.version || null;
68
+ } catch {
69
+ return null;
70
+ }
71
+ }
72
+ }
73
+
74
+ /**
75
+ * Check for version consistency across @agentuity/* packages.
76
+ *
77
+ * @param logger - Logger instance to use for warnings
78
+ */
79
+ export function checkVersionConsistency(logger: Logger): void {
80
+ // Skip in development if flag is set (for testing)
81
+ if (process.env.AGENTUITY_SKIP_VERSION_CHECK === 'true') {
82
+ return;
83
+ }
84
+
85
+ // Show deprecation warning for v1 packages
86
+ showDeprecationWarning(logger);
87
+
88
+ // Collect versions of loaded packages
89
+ const versions: PackageVersion[] = [];
90
+
91
+ for (const name of KNOWN_PACKAGES) {
92
+ const version = getPackageVersion(name);
93
+ if (version) {
94
+ versions.push({
95
+ name,
96
+ version,
97
+ major: extractMajor(version),
98
+ });
99
+ }
100
+ }
101
+
102
+ // Need at least 2 packages to check consistency
103
+ if (versions.length < 2) {
104
+ return;
105
+ }
106
+
107
+ // Check for major version mismatches
108
+ const majors = new Set(versions.map((v) => v.major));
109
+ if (majors.size <= 1) {
110
+ return; // All packages have the same major version
111
+ }
112
+
113
+ // Find the most common major version
114
+ const majorCounts = new Map<number, number>();
115
+ for (const v of versions) {
116
+ majorCounts.set(v.major, (majorCounts.get(v.major) || 0) + 1);
117
+ }
118
+ const sortedMajors = [...majorCounts.entries()].sort((a, b) => b[1] - a[1]);
119
+ const expectedMajor = sortedMajors[0]?.[0] ?? 2;
120
+
121
+ // Find mismatched packages
122
+ const mismatched = versions.filter((v) => v.major !== expectedMajor);
123
+
124
+ if (mismatched.length === 0) {
125
+ return;
126
+ }
127
+
128
+ // Log warning
129
+ const mismatchedList = mismatched.map((v) => `${v.name}@${v.version}`).join('\n ');
130
+
131
+ logger.warn(
132
+ 'Version mismatch detected: Some @agentuity/* packages have different major versions.\n' +
133
+ ' This may cause unexpected behavior.\n' +
134
+ '\n' +
135
+ ' Expected: v' +
136
+ expectedMajor +
137
+ '\n' +
138
+ ' Mismatched:\n' +
139
+ ' ' +
140
+ mismatchedList +
141
+ '\n' +
142
+ '\n' +
143
+ ' Run `bun install` to sync versions, or pin all @agentuity/* packages\n' +
144
+ ' to the same major version in your package.json.'
145
+ );
146
+ }
147
+
148
+ /**
149
+ * Check if the project is using v1 SDK packages.
150
+ *
151
+ * @returns true if any v1 packages are detected
152
+ */
153
+ export function hasV1Packages(): boolean {
154
+ return isV1Package();
155
+ }
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
+ }