@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.
- package/dist/_globals.d.ts +58 -0
- package/dist/_globals.d.ts.map +1 -0
- package/dist/_globals.js +71 -0
- package/dist/_globals.js.map +1 -0
- package/dist/_metadata.d.ts.map +1 -1
- package/dist/_metadata.js +14 -0
- package/dist/_metadata.js.map +1 -1
- package/dist/_process-protection.d.ts +2 -0
- package/dist/_process-protection.d.ts.map +1 -1
- package/dist/_process-protection.js +14 -23
- package/dist/_process-protection.js.map +1 -1
- package/dist/_server.d.ts +4 -0
- package/dist/_server.d.ts.map +1 -1
- package/dist/_server.js +4 -0
- package/dist/_server.js.map +1 -1
- package/dist/_services.d.ts +1 -1
- package/dist/_services.d.ts.map +1 -1
- package/dist/_services.js +5 -1
- package/dist/_services.js.map +1 -1
- package/dist/_standalone.d.ts.map +1 -1
- package/dist/_standalone.js +3 -9
- package/dist/_standalone.js.map +1 -1
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +1 -0
- package/dist/agent.js.map +1 -1
- package/dist/app.d.ts +149 -71
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js +121 -156
- package/dist/app.js.map +1 -1
- package/dist/bootstrap.d.ts +44 -0
- package/dist/bootstrap.d.ts.map +1 -0
- package/dist/bootstrap.js +256 -0
- package/dist/bootstrap.js.map +1 -0
- package/dist/dev-patches/aisdk.d.ts.map +1 -1
- package/dist/dev-patches/aisdk.js +6 -8
- package/dist/dev-patches/aisdk.js.map +1 -1
- package/dist/dev-patches/gateway.d.ts.map +1 -1
- package/dist/dev-patches/gateway.js +7 -8
- package/dist/dev-patches/gateway.js.map +1 -1
- package/dist/handlers/_route-meta.d.ts +20 -0
- package/dist/handlers/_route-meta.d.ts.map +1 -0
- package/dist/handlers/_route-meta.js +25 -0
- package/dist/handlers/_route-meta.js.map +1 -0
- package/dist/handlers/cron.d.ts.map +1 -1
- package/dist/handlers/cron.js +3 -1
- package/dist/handlers/cron.js.map +1 -1
- package/dist/handlers/sse.d.ts +3 -3
- package/dist/handlers/sse.d.ts.map +1 -1
- package/dist/handlers/sse.js +4 -16
- package/dist/handlers/sse.js.map +1 -1
- package/dist/handlers/stream.d.ts.map +1 -1
- package/dist/handlers/stream.js +4 -12
- package/dist/handlers/stream.js.map +1 -1
- package/dist/handlers/websocket.d.ts +3 -1
- package/dist/handlers/websocket.d.ts.map +1 -1
- package/dist/handlers/websocket.js +6 -37
- package/dist/handlers/websocket.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/middleware.d.ts +1 -8
- package/dist/middleware.d.ts.map +1 -1
- package/dist/middleware.js +29 -71
- package/dist/middleware.js.map +1 -1
- package/dist/otel/logger.d.ts.map +1 -1
- package/dist/otel/logger.js +4 -7
- package/dist/otel/logger.js.map +1 -1
- package/dist/otel/otel.d.ts +4 -1
- package/dist/otel/otel.d.ts.map +1 -1
- package/dist/otel/otel.js +13 -2
- package/dist/otel/otel.js.map +1 -1
- package/dist/router.d.ts +10 -62
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +9 -146
- package/dist/router.js.map +1 -1
- package/dist/workbench.d.ts +1 -1
- package/dist/workbench.d.ts.map +1 -1
- package/dist/workbench.js +120 -12
- package/dist/workbench.js.map +1 -1
- package/package.json +7 -7
- package/src/_globals.ts +92 -0
- package/src/_metadata.ts +14 -0
- package/src/_process-protection.ts +17 -28
- package/src/_server.ts +4 -0
- package/src/_services.ts +6 -2
- package/src/_standalone.ts +4 -9
- package/src/agent.ts +1 -0
- package/src/app.ts +294 -195
- package/src/bootstrap.ts +316 -0
- package/src/dev-patches/aisdk.ts +8 -11
- package/src/dev-patches/gateway.ts +9 -11
- package/src/globals.d.ts +28 -0
- package/src/handlers/_route-meta.ts +31 -0
- package/src/handlers/cron.ts +4 -1
- package/src/handlers/sse.ts +8 -19
- package/src/handlers/stream.ts +5 -12
- package/src/handlers/websocket.ts +11 -37
- package/src/index.ts +2 -3
- package/src/middleware.ts +40 -99
- package/src/otel/logger.ts +5 -8
- package/src/otel/otel.ts +14 -2
- package/src/router.ts +12 -216
- 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:
|
|
532
|
+
input: inputJsonSchema
|
|
525
533
|
? {
|
|
526
|
-
code:
|
|
527
|
-
json:
|
|
528
|
-
? toJSONSchema(runtimeAgent.inputSchema)
|
|
529
|
-
: undefined,
|
|
534
|
+
code: jsonSchemaToTypeScript(inputJsonSchema),
|
|
535
|
+
json: inputJsonSchema,
|
|
530
536
|
}
|
|
531
|
-
:
|
|
532
|
-
|
|
537
|
+
: agent.schema?.input
|
|
538
|
+
? { code: agent.schema.input, json: undefined }
|
|
539
|
+
: undefined,
|
|
540
|
+
output: outputJsonSchema
|
|
533
541
|
? {
|
|
534
|
-
code:
|
|
535
|
-
json:
|
|
536
|
-
? toJSONSchema(runtimeAgent.outputSchema)
|
|
537
|
-
: undefined,
|
|
542
|
+
code: jsonSchemaToTypeScript(outputJsonSchema),
|
|
543
|
+
json: outputJsonSchema,
|
|
538
544
|
}
|
|
539
|
-
:
|
|
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
|
+
}
|