@agentuity/runtime 0.0.68 → 0.0.70
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/AGENTS.md +130 -10
- package/README.md +6 -8
- package/dist/_config.d.ts +16 -0
- package/dist/_config.d.ts.map +1 -1
- package/dist/_config.js +16 -0
- package/dist/_config.js.map +1 -1
- package/dist/_context.d.ts +17 -15
- package/dist/_context.d.ts.map +1 -1
- package/dist/_context.js +17 -8
- package/dist/_context.js.map +1 -1
- package/dist/_server.d.ts.map +1 -1
- package/dist/_server.js +27 -14
- package/dist/_server.js.map +1 -1
- package/dist/_services.d.ts.map +1 -1
- package/dist/_services.js +2 -29
- package/dist/_services.js.map +1 -1
- package/dist/_validation.d.ts +89 -0
- package/dist/_validation.d.ts.map +1 -0
- package/dist/_validation.js +29 -0
- package/dist/_validation.js.map +1 -0
- package/dist/agent.d.ts +476 -104
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +293 -97
- package/dist/agent.js.map +1 -1
- package/dist/app.d.ts +6 -18
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js +1 -1
- package/dist/app.js.map +1 -1
- package/dist/eval.d.ts +4 -4
- package/dist/eval.d.ts.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/otel/config.d.ts.map +1 -1
- package/dist/otel/config.js +5 -2
- package/dist/otel/config.js.map +1 -1
- package/dist/otel/console.d.ts +10 -6
- package/dist/otel/console.d.ts.map +1 -1
- package/dist/otel/console.js +31 -13
- package/dist/otel/console.js.map +1 -1
- package/dist/otel/logger.d.ts.map +1 -1
- package/dist/otel/logger.js +0 -19
- package/dist/otel/logger.js.map +1 -1
- package/dist/otel/otel.d.ts +2 -1
- package/dist/otel/otel.d.ts.map +1 -1
- package/dist/otel/otel.js +28 -15
- package/dist/otel/otel.js.map +1 -1
- package/dist/services/local/_db.d.ts.map +1 -1
- package/dist/services/local/_db.js +1 -22
- package/dist/services/local/_db.js.map +1 -1
- package/dist/services/local/_router.d.ts.map +1 -1
- package/dist/services/local/_router.js +0 -32
- package/dist/services/local/_router.js.map +1 -1
- package/dist/services/local/index.d.ts +0 -1
- package/dist/services/local/index.d.ts.map +1 -1
- package/dist/services/local/index.js +0 -1
- package/dist/services/local/index.js.map +1 -1
- package/dist/session.d.ts +18 -2
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +6 -0
- package/dist/session.js.map +1 -1
- package/dist/validator.d.ts +140 -0
- package/dist/validator.d.ts.map +1 -0
- package/dist/validator.js +146 -0
- package/dist/validator.js.map +1 -0
- package/dist/workbench.d.ts.map +1 -1
- package/dist/workbench.js +38 -29
- package/dist/workbench.js.map +1 -1
- package/package.json +6 -6
- package/src/_config.ts +19 -0
- package/src/_context.ts +25 -31
- package/src/_server.ts +30 -14
- package/src/_services.ts +0 -28
- package/src/_validation.ts +119 -0
- package/src/agent.ts +872 -272
- package/src/app.ts +5 -18
- package/src/eval.ts +6 -6
- package/src/index.ts +3 -1
- package/src/otel/config.ts +5 -2
- package/src/otel/console.ts +34 -20
- package/src/otel/logger.ts +0 -18
- package/src/otel/otel.ts +43 -29
- package/src/services/local/_db.ts +1 -27
- package/src/services/local/_router.ts +0 -46
- package/src/services/local/index.ts +0 -1
- package/src/session.ts +22 -2
- package/src/validator.ts +277 -0
- package/src/workbench.ts +38 -32
- package/dist/services/local/objectstore.d.ts +0 -19
- package/dist/services/local/objectstore.d.ts.map +0 -1
- package/dist/services/local/objectstore.js +0 -117
- package/dist/services/local/objectstore.js.map +0 -1
- package/src/services/local/objectstore.ts +0 -177
package/AGENTS.md
CHANGED
|
@@ -44,17 +44,59 @@ src/
|
|
|
44
44
|
|
|
45
45
|
- **Agent context** - Every agent handler receives `AgentContext` as first parameter
|
|
46
46
|
- **Schema validation** - Support StandardSchemaV1 (works with Zod, Valibot, etc.)
|
|
47
|
+
- **Route validation** - Use `agent.validator()` for automatic input validation with full type safety
|
|
47
48
|
- **Streaming support** - Agents can return ReadableStream for streaming responses
|
|
48
49
|
- **WebSocket support** - Use `router.websocket()` for WebSocket routes
|
|
49
50
|
- **SSE support** - Use `router.sse()` for Server-Sent Events
|
|
50
51
|
- **Session tracking** - Each request gets unique sessionId
|
|
51
|
-
- **Storage abstractions** - Provide kv,
|
|
52
|
+
- **Storage abstractions** - Provide kv, stream, vector interfaces
|
|
53
|
+
|
|
54
|
+
## Route Validation
|
|
55
|
+
|
|
56
|
+
Routes can use `agent.validator()` to automatically validate request input using the agent's schema:
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
import { createRouter } from '@agentuity/runtime';
|
|
60
|
+
import myAgent from './my-agent';
|
|
61
|
+
|
|
62
|
+
const router = createRouter();
|
|
63
|
+
|
|
64
|
+
// Automatic validation using agent's input schema
|
|
65
|
+
router.post('/', myAgent.validator(), async (c) => {
|
|
66
|
+
const data = c.req.valid('json'); // Fully typed from agent schema!
|
|
67
|
+
const output = await myAgent.run(data);
|
|
68
|
+
return c.json(output);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// Override with custom schema
|
|
72
|
+
router.post(
|
|
73
|
+
'/custom',
|
|
74
|
+
agent.validator({
|
|
75
|
+
input: z.object({ custom: z.string() }),
|
|
76
|
+
}),
|
|
77
|
+
async (c) => {
|
|
78
|
+
const data = c.req.valid('json'); // Typed as { custom: string }
|
|
79
|
+
return c.json(data);
|
|
80
|
+
}
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
// GET routes don't need validation
|
|
84
|
+
router.get('/', async (c) => {
|
|
85
|
+
return c.json({ hello: 'world' });
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
The validator supports three overload signatures:
|
|
90
|
+
|
|
91
|
+
- `agent.validator()` - Uses agent's input/output schemas
|
|
92
|
+
- `agent.validator({ output: schema })` - Output-only validation (GET-compatible)
|
|
93
|
+
- `agent.validator({ input: schema, output?: schema })` - Custom input/output schemas
|
|
52
94
|
|
|
53
95
|
## Agent Definition Pattern
|
|
54
96
|
|
|
55
97
|
```typescript
|
|
56
98
|
import { createAgent } from '@agentuity/runtime';
|
|
57
|
-
import {
|
|
99
|
+
import { s } from '@agentuity/schema';
|
|
58
100
|
|
|
59
101
|
export default createAgent({
|
|
60
102
|
metadata: {
|
|
@@ -66,10 +108,10 @@ export default createAgent({
|
|
|
66
108
|
version: 'hash-or-version',
|
|
67
109
|
},
|
|
68
110
|
schema: {
|
|
69
|
-
input:
|
|
111
|
+
input: s.object({
|
|
70
112
|
/* ... */
|
|
71
113
|
}),
|
|
72
|
-
output:
|
|
114
|
+
output: s.object({
|
|
73
115
|
/* ... */
|
|
74
116
|
}),
|
|
75
117
|
},
|
|
@@ -99,10 +141,8 @@ interface AgentContext {
|
|
|
99
141
|
tracer: Tracer; // OpenTelemetry tracer
|
|
100
142
|
sessionId: string; // Unique session ID
|
|
101
143
|
kv: KeyValueStorage; // Key-value storage
|
|
102
|
-
objectstore: ObjectStorage; // Object storage
|
|
103
144
|
stream: StreamStorage; // Stream storage
|
|
104
145
|
vector: VectorStorage; // Vector storage
|
|
105
|
-
agent: AgentRegistry; // Access other agents
|
|
106
146
|
waitUntil: (promise) => void; // Background tasks
|
|
107
147
|
}
|
|
108
148
|
```
|
|
@@ -114,12 +154,92 @@ interface AgentContext {
|
|
|
114
154
|
- **Metrics**: Access via `c.var.meter` in Hono context
|
|
115
155
|
- **Environment**: Metrics/traces sent to OTLP endpoints
|
|
116
156
|
|
|
157
|
+
## Type Safety
|
|
158
|
+
|
|
159
|
+
**End-to-end type safety is a core feature of the runtime.** When you use `createAgent()` with schemas and `agent.validator()` in routes, TypeScript automatically infers correct types throughout your application.
|
|
160
|
+
|
|
161
|
+
### What IS Type-Safe ✅
|
|
162
|
+
|
|
163
|
+
1. **Route handler input types** - `c.req.valid('json')` is automatically typed from agent schema
|
|
164
|
+
2. **Agent handler types** - Both `ctx` and `input` parameters are fully typed
|
|
165
|
+
3. **Runtime validation** - Input/output validation happens automatically
|
|
166
|
+
4. **Schema overrides** - Custom schemas in `agent.validator({ input, output })` maintain type safety
|
|
167
|
+
5. **Multiple agents** - Each route maintains independent type safety
|
|
168
|
+
|
|
169
|
+
### Type Inference Best Practices
|
|
170
|
+
|
|
171
|
+
**CRITICAL:** Do NOT add type annotations to agent handler parameters - let TypeScript infer them:
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
// ✅ CORRECT: Let TypeScript infer types from schema
|
|
175
|
+
const agent = createAgent('user', {
|
|
176
|
+
schema: {
|
|
177
|
+
input: z.object({ name: z.string(), age: z.number() }),
|
|
178
|
+
output: z.object({ id: z.string() }),
|
|
179
|
+
},
|
|
180
|
+
handler: async (ctx, input) => {
|
|
181
|
+
// ctx is typed as AgentContext
|
|
182
|
+
// input is typed as { name: string, age: number }
|
|
183
|
+
return { id: `user-${input.name}` };
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
// ❌ WRONG: Explicit types defeat inference
|
|
188
|
+
handler: async (ctx: AgentContext, input: any) => { ... }
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### Hono Method Chaining
|
|
192
|
+
|
|
193
|
+
For best type inference with Hono, use method chaining:
|
|
194
|
+
|
|
195
|
+
```typescript
|
|
196
|
+
// ✅ RECOMMENDED: Method chaining preserves types
|
|
197
|
+
const app = new Hono()
|
|
198
|
+
.post('/users', userAgent.validator(), handler)
|
|
199
|
+
.get('/users/:id', userAgent.validator({ output: UserSchema }), handler);
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Testing Type Safety
|
|
203
|
+
|
|
204
|
+
**IMPORTANT:** Due to Hono's `testClient()` type inference limitations with method-chained apps, use `app.request()` for testing:
|
|
205
|
+
|
|
206
|
+
```typescript
|
|
207
|
+
// ✅ CORRECT: Use app.request() for testing
|
|
208
|
+
test('creates user', async () => {
|
|
209
|
+
const app = new Hono().post('/users', agent.validator(), async (c) => {
|
|
210
|
+
const data = c.req.valid('json'); // Fully typed!
|
|
211
|
+
return c.json({ id: `user-${data.name}` });
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
const res = await app.request('/users', {
|
|
215
|
+
method: 'POST',
|
|
216
|
+
headers: { 'Content-Type': 'application/json' },
|
|
217
|
+
body: JSON.stringify({ name: 'Alice', age: 30 }),
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
expect(res.status).toBe(200);
|
|
221
|
+
const result = await res.json();
|
|
222
|
+
expect(result.id).toBe('user-Alice');
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
// ❌ AVOID: testClient has type inference issues
|
|
226
|
+
import { testClient } from 'hono/testing';
|
|
227
|
+
const client = testClient(app); // Returns unknown type
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
See `test/agent-type-safety.test.ts` for comprehensive type-safe testing examples.
|
|
231
|
+
|
|
232
|
+
For detailed type safety documentation, see `TYPE_SAFETY.md`.
|
|
233
|
+
|
|
117
234
|
## Testing
|
|
118
235
|
|
|
119
|
-
- Use Bun's test runner: `bun test`
|
|
120
|
-
-
|
|
121
|
-
- Test
|
|
122
|
-
-
|
|
236
|
+
- **Test runner**: Use Bun's test runner: `bun test`
|
|
237
|
+
- **Test structure**: All tests in `test/` folder parallel to `src/`
|
|
238
|
+
- **Test imports**: Import from `../src/` not `../`
|
|
239
|
+
- **Mock contexts**: Use `TestAgentContext` from `test/helpers/test-context.ts`
|
|
240
|
+
- **Mock services**: Use mock storage interfaces (kv, stream, vector, etc.)
|
|
241
|
+
- **Route testing**: Use `app.request()` for testing routes (NOT `testClient()`)
|
|
242
|
+
- **Type verification**: Let TypeScript infer agent handler types - do NOT add type annotations
|
|
123
243
|
|
|
124
244
|
## Publishing Checklist
|
|
125
245
|
|
package/README.md
CHANGED
|
@@ -30,15 +30,15 @@ logger.info('Server running on http://localhost:3500');
|
|
|
30
30
|
|
|
31
31
|
```typescript
|
|
32
32
|
import { createAgent } from '@agentuity/runtime';
|
|
33
|
-
import {
|
|
33
|
+
import { s } from '@agentuity/schema';
|
|
34
34
|
|
|
35
35
|
const agent = createAgent({
|
|
36
36
|
schema: {
|
|
37
|
-
input:
|
|
38
|
-
message:
|
|
37
|
+
input: s.object({
|
|
38
|
+
message: s.string(),
|
|
39
39
|
}),
|
|
40
|
-
output:
|
|
41
|
-
response:
|
|
40
|
+
output: s.object({
|
|
41
|
+
response: s.string(),
|
|
42
42
|
}),
|
|
43
43
|
},
|
|
44
44
|
handler: async (ctx, input) => {
|
|
@@ -136,7 +136,7 @@ Creates a type-safe agent with input/output validation.
|
|
|
136
136
|
|
|
137
137
|
- `schema.input?` - Schema for input validation (Zod, Valibot, etc.)
|
|
138
138
|
- `schema.output?` - Schema for output validation
|
|
139
|
-
- `handler` - Agent handler function `(ctx
|
|
139
|
+
- `handler` - Agent handler function `(ctx, input) => output`
|
|
140
140
|
|
|
141
141
|
### createRouter()
|
|
142
142
|
|
|
@@ -159,7 +159,6 @@ interface AgentContext {
|
|
|
159
159
|
tracer: Tracer; // OpenTelemetry tracer
|
|
160
160
|
sessionId: string; // Unique session ID
|
|
161
161
|
kv: KeyValueStorage; // Key-value storage
|
|
162
|
-
objectstore: ObjectStorage; // Object storage
|
|
163
162
|
stream: StreamStorage; // Stream storage
|
|
164
163
|
vector: VectorStorage; // Vector storage
|
|
165
164
|
agent: AgentRegistry; // Access to other agents
|
|
@@ -172,7 +171,6 @@ interface AgentContext {
|
|
|
172
171
|
Agentuity provides built-in storage abstractions:
|
|
173
172
|
|
|
174
173
|
- **KeyValueStorage** - Simple key-value storage
|
|
175
|
-
- **ObjectStorage** - Object/blob storage
|
|
176
174
|
- **StreamStorage** - Streaming data storage
|
|
177
175
|
- **VectorStorage** - Vector embeddings storage
|
|
178
176
|
|
package/dist/_config.d.ts
CHANGED
|
@@ -65,4 +65,20 @@ export declare function getEnvironment(): string;
|
|
|
65
65
|
* @returns boolean
|
|
66
66
|
*/
|
|
67
67
|
export declare function isAuthenticated(): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Symbol for accessing internal runtime state.
|
|
70
|
+
* Defined here to avoid circular dependency.
|
|
71
|
+
*/
|
|
72
|
+
export declare const AGENT_RUNTIME: unique symbol;
|
|
73
|
+
/**
|
|
74
|
+
* Symbol for accessing internal agent from AgentRunner.
|
|
75
|
+
* @internal
|
|
76
|
+
*/
|
|
77
|
+
export declare const INTERNAL_AGENT: unique symbol;
|
|
78
|
+
/**
|
|
79
|
+
* Symbol for tracking the current executing agent (for telemetry).
|
|
80
|
+
* Not exposed on public AgentContext interface.
|
|
81
|
+
* @internal
|
|
82
|
+
*/
|
|
83
|
+
export declare const CURRENT_AGENT: unique symbol;
|
|
68
84
|
//# sourceMappingURL=_config.d.ts.map
|
package/dist/_config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_config.d.ts","sourceRoot":"","sources":["../src/_config.ts"],"names":[],"mappings":"AAMA,wBAAgB,IAAI,SAWnB;AAED;;;;GAIG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAED;;;;GAIG;AACH,wBAAgB,UAAU,IAAI,MAAM,CAEnC;AAED;;;;GAIG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,GAAG,SAAS,CAEtD;AAED;;;;GAIG;AACH,wBAAgB,YAAY,IAAI,MAAM,GAAG,SAAS,CAEjD;AAED;;;;GAIG;AACH,wBAAgB,eAAe,IAAI,MAAM,GAAG,SAAS,CAEpD;AAED;;;;GAIG;AACH,wBAAgB,SAAS,IAAI,OAAO,CAEnC;AAED;;;;GAIG;AACH,wBAAgB,YAAY,IAAI,OAAO,CAEtC;AAED;;;;GAIG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAED;;;;GAIG;AACH,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAED;;;;GAIG;AACH,wBAAgB,eAAe,IAAI,OAAO,CAEzC"}
|
|
1
|
+
{"version":3,"file":"_config.d.ts","sourceRoot":"","sources":["../src/_config.ts"],"names":[],"mappings":"AAMA,wBAAgB,IAAI,SAWnB;AAED;;;;GAIG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAED;;;;GAIG;AACH,wBAAgB,UAAU,IAAI,MAAM,CAEnC;AAED;;;;GAIG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,GAAG,SAAS,CAEtD;AAED;;;;GAIG;AACH,wBAAgB,YAAY,IAAI,MAAM,GAAG,SAAS,CAEjD;AAED;;;;GAIG;AACH,wBAAgB,eAAe,IAAI,MAAM,GAAG,SAAS,CAEpD;AAED;;;;GAIG;AACH,wBAAgB,SAAS,IAAI,OAAO,CAEnC;AAED;;;;GAIG;AACH,wBAAgB,YAAY,IAAI,OAAO,CAEtC;AAED;;;;GAIG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAED;;;;GAIG;AACH,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAED;;;;GAIG;AACH,wBAAgB,eAAe,IAAI,OAAO,CAEzC;AAED;;;GAGG;AACH,eAAO,MAAM,aAAa,eAA0B,CAAC;AAErD;;;GAGG;AACH,eAAO,MAAM,cAAc,eAA2B,CAAC;AAEvD;;;;GAIG;AACH,eAAO,MAAM,aAAa,eAA0B,CAAC"}
|
package/dist/_config.js
CHANGED
|
@@ -103,4 +103,20 @@ export function getEnvironment() {
|
|
|
103
103
|
export function isAuthenticated() {
|
|
104
104
|
return !!process.env.AGENTUITY_SDK_KEY;
|
|
105
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Symbol for accessing internal runtime state.
|
|
108
|
+
* Defined here to avoid circular dependency.
|
|
109
|
+
*/
|
|
110
|
+
export const AGENT_RUNTIME = Symbol('AGENT_RUNTIME');
|
|
111
|
+
/**
|
|
112
|
+
* Symbol for accessing internal agent from AgentRunner.
|
|
113
|
+
* @internal
|
|
114
|
+
*/
|
|
115
|
+
export const INTERNAL_AGENT = Symbol('INTERNAL_AGENT');
|
|
116
|
+
/**
|
|
117
|
+
* Symbol for tracking the current executing agent (for telemetry).
|
|
118
|
+
* Not exposed on public AgentContext interface.
|
|
119
|
+
* @internal
|
|
120
|
+
*/
|
|
121
|
+
export const CURRENT_AGENT = Symbol('CURRENT_AGENT');
|
|
106
122
|
//# sourceMappingURL=_config.js.map
|
package/dist/_config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_config.js","sourceRoot":"","sources":["../src/_config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,IAAI,OAA2B,CAAC;AAChC,IAAI,UAA8B,CAAC;AAEnC,MAAM,UAAU,IAAI;IACnB,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,kBAAkB,CAAC,CAAC;IACpD,IAAI,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC;QACnB,IAAI,CAAC;YACJ,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;YACjD,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC;YACnB,UAAU,GAAG,GAAG,CAAC,OAAO,CAAC;QAC1B,CAAC;QAAC,MAAM,CAAC;YACR,wCAAwC;QACzC,CAAC;IACF,CAAC;AACF,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa;IAC5B,OAAO,OAAO,CAAC,GAAG,CAAC,2BAA2B,IAAI,SAAS,CAAC;AAC7D,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU;IACzB,OAAO,OAAO,IAAI,SAAS,CAAC;AAC7B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa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,CAAC,SAAS,EAAE,CAAC;AAC9D,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa;IAC5B,OAAO,OAAO,CAAC,GAAG,CAAC,qBAAqB,IAAI,SAAS,CAAC;AACvD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc;IAC7B,OAAO,OAAO,CAAC,GAAG,CAAC,qBAAqB,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,aAAa,CAAC;AACnF,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe;IAC9B,OAAO,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;AACxC,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;AAErD;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAEvD;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC"}
|
package/dist/_context.d.ts
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
2
|
import type { Context as HonoContext } from 'hono';
|
|
3
3
|
import type { Tracer } from '@opentelemetry/api';
|
|
4
|
-
import { type KeyValueStorage, type
|
|
5
|
-
import type { AgentContext,
|
|
4
|
+
import { type KeyValueStorage, type StreamStorage, type VectorStorage } from '@agentuity/core';
|
|
5
|
+
import type { AgentContext, AgentRegistry, AgentRunner, AgentRuntimeState } from './agent';
|
|
6
|
+
import { AGENT_RUNTIME } from './_config';
|
|
6
7
|
import type { Logger } from './logger';
|
|
7
8
|
import type WaitUntilHandler from './_waituntil';
|
|
8
9
|
import type { Thread, Session } from './session';
|
|
9
|
-
export interface RequestAgentContextArgs<TAgentMap extends AgentRegistry = AgentRegistry,
|
|
10
|
+
export interface RequestAgentContextArgs<TAgentMap extends AgentRegistry = AgentRegistry, TConfig = unknown, TAppState = Record<string, never>> {
|
|
10
11
|
sessionId: string;
|
|
11
12
|
agent: TAgentMap;
|
|
12
|
-
current: TCurrent;
|
|
13
|
-
parent: TParent;
|
|
14
|
-
agentName: AgentName;
|
|
15
13
|
logger: Logger;
|
|
16
14
|
tracer: Tracer;
|
|
17
15
|
session: Session;
|
|
@@ -19,17 +17,14 @@ export interface RequestAgentContextArgs<TAgentMap extends AgentRegistry = Agent
|
|
|
19
17
|
handler: WaitUntilHandler;
|
|
20
18
|
config: TConfig;
|
|
21
19
|
app: TAppState;
|
|
20
|
+
runtime: AgentRuntimeState;
|
|
22
21
|
}
|
|
23
|
-
export declare class RequestAgentContext<TAgentMap extends AgentRegistry = AgentRegistry,
|
|
22
|
+
export declare class RequestAgentContext<TAgentMap extends AgentRegistry = AgentRegistry, TConfig = unknown, TAppState = Record<string, never>> implements AgentContext<TAgentMap, TConfig, TAppState> {
|
|
24
23
|
agent: TAgentMap;
|
|
25
|
-
current: TCurrent;
|
|
26
|
-
parent: TParent;
|
|
27
|
-
agentName: AgentName;
|
|
28
24
|
logger: Logger;
|
|
29
25
|
sessionId: string;
|
|
30
26
|
tracer: Tracer;
|
|
31
27
|
kv: KeyValueStorage;
|
|
32
|
-
objectstore: ObjectStorage;
|
|
33
28
|
stream: StreamStorage;
|
|
34
29
|
vector: VectorStorage;
|
|
35
30
|
state: Map<string, unknown>;
|
|
@@ -37,16 +32,23 @@ export declare class RequestAgentContext<TAgentMap extends AgentRegistry = Agent
|
|
|
37
32
|
thread: Thread;
|
|
38
33
|
config: TConfig;
|
|
39
34
|
app: TAppState;
|
|
35
|
+
[AGENT_RUNTIME]: AgentRuntimeState;
|
|
40
36
|
private handler;
|
|
41
|
-
constructor(args: RequestAgentContextArgs<TAgentMap,
|
|
37
|
+
constructor(args: RequestAgentContextArgs<TAgentMap, TConfig, TAppState>);
|
|
42
38
|
waitUntil(callback: Promise<void> | (() => void | Promise<void>)): void;
|
|
43
39
|
}
|
|
44
40
|
export declare const inAgentContext: () => boolean;
|
|
45
41
|
export declare const inHTTPContext: () => boolean;
|
|
46
|
-
export declare const getAgentContext: () => AgentContext<any, any, any
|
|
42
|
+
export declare const getAgentContext: () => AgentContext<any, any, any>;
|
|
47
43
|
export declare const getHTTPContext: () => HonoContext;
|
|
48
|
-
export declare const getAgentAsyncLocalStorage: () => AsyncLocalStorage<AgentContext<any, any, any
|
|
44
|
+
export declare const getAgentAsyncLocalStorage: () => AsyncLocalStorage<AgentContext<any, any, any>>;
|
|
49
45
|
export declare const getHTTPAsyncLocalStorage: () => AsyncLocalStorage<HonoContext<any, any, {}>>;
|
|
50
|
-
|
|
46
|
+
/**
|
|
47
|
+
* Get the current executing agent's metadata (for internal telemetry use only).
|
|
48
|
+
* Returns undefined if not in an agent context or no agent is executing.
|
|
49
|
+
* @internal
|
|
50
|
+
*/
|
|
51
|
+
export declare const getCurrentAgentMetadata: () => AgentRunner["metadata"] | undefined;
|
|
52
|
+
export declare const setupRequestAgentContext: <TAgentMap extends AgentRegistry = AgentRegistry, TConfig = unknown, TAppState = Record<string, never>>(ctxObject: Record<string, unknown>, args: RequestAgentContextArgs<TAgentMap, TConfig, TAppState>, next: () => Promise<void>) => Promise<void>;
|
|
51
53
|
export declare const runInHTTPContext: <HonoContext>(ctx: HonoContext, next: () => Promise<void>) => Promise<void>;
|
|
52
54
|
//# sourceMappingURL=_context.d.ts.map
|
package/dist/_context.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_context.d.ts","sourceRoot":"","sources":["../src/_context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,MAAM,CAAC;AACnD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAEN,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAA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,EACjB,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAEjC,WAAW,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClC,MAAM,uBAAuB,CAAC,SAAS,EAAE,OAAO,EAAE,SAAS,CAAC,EAC5D,MAAM,MAAM,OAAO,CAAC,IAAI,CAAC,kBA4BzB,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAU,WAAW,EACjD,KAAK,WAAW,EAChB,MAAM,MAAM,OAAO,CAAC,IAAI,CAAC,kBAIzB,CAAC"}
|
package/dist/_context.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
2
|
import { StructuredError, } from '@agentuity/core';
|
|
3
|
+
import { AGENT_RUNTIME, CURRENT_AGENT } from './_config';
|
|
3
4
|
import { registerServices } from './_services';
|
|
4
5
|
export class RequestAgentContext {
|
|
5
6
|
agent;
|
|
6
|
-
current;
|
|
7
|
-
parent;
|
|
8
|
-
agentName;
|
|
9
7
|
logger;
|
|
10
8
|
sessionId;
|
|
11
9
|
tracer;
|
|
12
10
|
kv;
|
|
13
|
-
objectstore;
|
|
14
11
|
stream;
|
|
15
12
|
vector;
|
|
16
13
|
state;
|
|
@@ -18,12 +15,10 @@ export class RequestAgentContext {
|
|
|
18
15
|
thread;
|
|
19
16
|
config;
|
|
20
17
|
app;
|
|
18
|
+
[AGENT_RUNTIME];
|
|
21
19
|
handler;
|
|
22
20
|
constructor(args) {
|
|
23
21
|
this.agent = args.agent;
|
|
24
|
-
this.current = args.current;
|
|
25
|
-
this.parent = args.parent;
|
|
26
|
-
this.agentName = args.agentName;
|
|
27
22
|
this.logger = args.logger;
|
|
28
23
|
this.sessionId = args.sessionId;
|
|
29
24
|
this.tracer = args.tracer;
|
|
@@ -31,6 +26,7 @@ export class RequestAgentContext {
|
|
|
31
26
|
this.session = args.session;
|
|
32
27
|
this.config = args.config;
|
|
33
28
|
this.app = args.app;
|
|
29
|
+
this[AGENT_RUNTIME] = args.runtime;
|
|
34
30
|
this.state = new Map();
|
|
35
31
|
this.handler = args.handler;
|
|
36
32
|
registerServices(this, false); // agents already populated via args.agent
|
|
@@ -69,7 +65,20 @@ export const getHTTPContext = () => {
|
|
|
69
65
|
};
|
|
70
66
|
export const getAgentAsyncLocalStorage = () => agentAsyncLocalStorage;
|
|
71
67
|
export const getHTTPAsyncLocalStorage = () => httpAsyncLocalStorage;
|
|
72
|
-
|
|
68
|
+
/**
|
|
69
|
+
* Get the current executing agent's metadata (for internal telemetry use only).
|
|
70
|
+
* Returns undefined if not in an agent context or no agent is executing.
|
|
71
|
+
* @internal
|
|
72
|
+
*/
|
|
73
|
+
export const getCurrentAgentMetadata = () => {
|
|
74
|
+
const context = agentAsyncLocalStorage.getStore();
|
|
75
|
+
if (!context)
|
|
76
|
+
return undefined;
|
|
77
|
+
// Access internal symbol property
|
|
78
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
79
|
+
return context[CURRENT_AGENT]?.metadata;
|
|
80
|
+
};
|
|
81
|
+
export const setupRequestAgentContext = (ctxObject, args, next) => {
|
|
73
82
|
const ctx = new RequestAgentContext(args);
|
|
74
83
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
75
84
|
const _ctx = ctx;
|
package/dist/_context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_context.js","sourceRoot":"","sources":["../src/_context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGrD,OAAO,EACN,eAAe,
|
|
1
|
+
{"version":3,"file":"_context.js","sourceRoot":"","sources":["../src/_context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGrD,OAAO,EACN,eAAe,GAIf,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC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;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,EACpC,GAAgB,EAChB,IAAyB,EACxB,EAAE;IACH,8DAA8D;IAC9D,OAAO,qBAAqB,CAAC,GAAG,CAAC,GAAU,EAAE,IAAI,CAAC,CAAC;AACpD,CAAC,CAAC"}
|
package/dist/_server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_server.d.ts","sourceRoot":"","sources":["../src/_server.ts"],"names":[],"mappings":"AAAA,OAAO,EAKN,KAAK,MAAM,EAIX,MAAM,oBAAoB,CAAC;AAG5B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAInE,OAAO,EAAE,IAAI,EAAE,KAAK,OAAO,IAAI,WAAW,EAAE,MAAM,MAAM,CAAC;AAEzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAIjD,OAAO,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAG9D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"_server.d.ts","sourceRoot":"","sources":["../src/_server.ts"],"names":[],"mappings":"AAAA,OAAO,EAKN,KAAK,MAAM,EAIX,MAAM,oBAAoB,CAAC;AAG5B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAInE,OAAO,EAAE,IAAI,EAAE,KAAK,OAAO,IAAI,WAAW,EAAE,MAAM,MAAM,CAAC;AAEzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAIjD,OAAO,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAG9D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AA0BvC,wBAAgB,SAAS,wCAExB;AAED,wBAAgB,SAAS,mFAExB;AAID,wBAAgB,SAAS,kBAExB;AAED,wBAAgB,SAAS,kBAExB;AAED,wBAAgB,WAAW,QAE1B;AAcD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,aAAa,QAExD;AA+CD,wBAAgB,cAAc,CAAC,CAAC,SAAS,GAAG,EAAE,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,GACvC,WAAW,CAAC;IAAE,SAAS,EAAE,gBAAgB,CAAA;CAAE,CAAC,CACnE;AAMD,eAAO,MAAM,WAAW,YAEvB,CAAC;AAEF,eAAO,MAAM,YAAY,GAAU,SAAS,EAC3C,QAAQ,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,EAC5B,qBAAqB,MAAM,OAAO,CAAC,SAAS,CAAC,EAC7C,SAAS,SAAS,CAAC,SAAS,CAAC,KAC3B,OAAO,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,gBAAgB,CAAC,EAAE,SAAS,CAAC,CA8RnD,CAAC"}
|
package/dist/_server.js
CHANGED
|
@@ -12,7 +12,8 @@ import { extractTraceContextFromRequest } from './otel/http';
|
|
|
12
12
|
import { register } from './otel/config';
|
|
13
13
|
import { isIdle } from './_idle';
|
|
14
14
|
import * as runtimeConfig from './_config';
|
|
15
|
-
import { inAgentContext,
|
|
15
|
+
import { inAgentContext, runInHTTPContext } from './_context';
|
|
16
|
+
import { runAgentShutdowns, createAgentMiddleware } from './agent';
|
|
16
17
|
import { createServices, getThreadProvider, getSessionProvider, getSessionEventProvider, } from './_services';
|
|
17
18
|
import { generateId } from './session';
|
|
18
19
|
import WaitUntilHandler from './_waituntil';
|
|
@@ -72,12 +73,14 @@ function registerAgentuitySpanProcessor() {
|
|
|
72
73
|
'@agentuity/environment': environment,
|
|
73
74
|
};
|
|
74
75
|
if (inAgentContext()) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
attrs['@agentuity/
|
|
80
|
-
attrs['@agentuity/
|
|
76
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
77
|
+
const { getCurrentAgentMetadata } = require('./_context');
|
|
78
|
+
const current = getCurrentAgentMetadata();
|
|
79
|
+
if (current) {
|
|
80
|
+
attrs['@agentuity/agentId'] = current.id;
|
|
81
|
+
attrs['@agentuity/agentInstanceId'] = current.agentId;
|
|
82
|
+
attrs['@agentuity/agentDescription'] = current.description;
|
|
83
|
+
attrs['@agentuity/agentName'] = current.name;
|
|
81
84
|
}
|
|
82
85
|
}
|
|
83
86
|
span.setAttributes(attrs);
|
|
@@ -214,9 +217,12 @@ export const createServer = async (router, appStateInitializer, config) => {
|
|
|
214
217
|
}
|
|
215
218
|
const file = Bun.file(routeMappingPath);
|
|
216
219
|
if (!(await file.exists())) {
|
|
217
|
-
c.var.logger.
|
|
220
|
+
c.var.logger.warn('Route mapping file not found at %s. Route tracking will be disabled.', routeMappingPath);
|
|
221
|
+
routeMapping = {}; // Empty mapping, no route tracking
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
routeMapping = (await file.json());
|
|
218
225
|
}
|
|
219
|
-
routeMapping = (await file.json());
|
|
220
226
|
}
|
|
221
227
|
const matches = matchedRoutes(c).filter((m) => m.method !== 'ALL' && (m.path.startsWith('/api') || m.path.startsWith('/agent/')));
|
|
222
228
|
const _c = privateContext(c);
|
|
@@ -233,11 +239,9 @@ export const createServer = async (router, appStateInitializer, config) => {
|
|
|
233
239
|
_c.set('trigger', 'api'); // will get overwritten below if another trigger
|
|
234
240
|
return next();
|
|
235
241
|
});
|
|
236
|
-
router.use('/agent/*', routePathMapper);
|
|
237
242
|
router.use('/api/*', routePathMapper);
|
|
238
243
|
// Attach services and agent registry to context for API routes
|
|
239
244
|
router.use('/api/*', async (c, next) => {
|
|
240
|
-
const { createAgentMiddleware } = await import('./agent');
|
|
241
245
|
// Use a null agent name to just populate the agent registry without setting current agent
|
|
242
246
|
return createAgentMiddleware('')(c, next);
|
|
243
247
|
});
|
|
@@ -249,10 +253,16 @@ export const createServer = async (router, appStateInitializer, config) => {
|
|
|
249
253
|
await next();
|
|
250
254
|
});
|
|
251
255
|
router.use(`/api/${trigger}/*`, middleware);
|
|
252
|
-
router.use(`/agent/${trigger}/*`, middleware);
|
|
253
256
|
}
|
|
254
257
|
router.use('/api/*', otelMiddleware);
|
|
255
|
-
|
|
258
|
+
// Apply otelMiddleware to workbench routes for full telemetry and session tracking
|
|
259
|
+
if (config?.services?.workbench) {
|
|
260
|
+
router.use('/_agentuity/workbench/*', async (c, next) => {
|
|
261
|
+
// Use a null agent name to just populate the agent registry without setting current agent
|
|
262
|
+
return createAgentMiddleware('')(c, next);
|
|
263
|
+
});
|
|
264
|
+
router.use('/_agentuity/workbench/*', otelMiddleware);
|
|
265
|
+
}
|
|
256
266
|
const shutdown = async () => {
|
|
257
267
|
if (isShutdown) {
|
|
258
268
|
return;
|
|
@@ -282,7 +292,6 @@ export const createServer = async (router, appStateInitializer, config) => {
|
|
|
282
292
|
}
|
|
283
293
|
otel.logger.debug('no more pending connections');
|
|
284
294
|
// Run agent shutdowns first
|
|
285
|
-
const { runAgentShutdowns } = await import('./agent');
|
|
286
295
|
await runAgentShutdowns(globalAppState);
|
|
287
296
|
// Run app shutdown if provided
|
|
288
297
|
if (config?.shutdown && globalAppState) {
|
|
@@ -432,6 +441,7 @@ const otelMiddleware = createMiddleware(async (c, next) => {
|
|
|
432
441
|
sessionEventProvider
|
|
433
442
|
.complete({
|
|
434
443
|
id: sessionId,
|
|
444
|
+
threadId: thread.empty() ? null : thread.id,
|
|
435
445
|
statusCode: c.res.status,
|
|
436
446
|
agentIds: Array.from(agentIds),
|
|
437
447
|
userData,
|
|
@@ -456,6 +466,7 @@ const otelMiddleware = createMiddleware(async (c, next) => {
|
|
|
456
466
|
sessionEventProvider
|
|
457
467
|
.complete({
|
|
458
468
|
id: sessionId,
|
|
469
|
+
threadId: thread.empty() ? null : thread.id,
|
|
459
470
|
statusCode: c.res.status,
|
|
460
471
|
error: message,
|
|
461
472
|
agentIds: Array.from(agentIds),
|
|
@@ -476,6 +487,7 @@ const otelMiddleware = createMiddleware(async (c, next) => {
|
|
|
476
487
|
sessionEventProvider
|
|
477
488
|
.complete({
|
|
478
489
|
id: sessionId,
|
|
490
|
+
threadId: thread.empty() ? null : thread.id,
|
|
479
491
|
statusCode: c.res.status,
|
|
480
492
|
agentIds: Array.from(agentIds),
|
|
481
493
|
userData,
|
|
@@ -500,6 +512,7 @@ const otelMiddleware = createMiddleware(async (c, next) => {
|
|
|
500
512
|
sessionEventProvider
|
|
501
513
|
.complete({
|
|
502
514
|
id: sessionId,
|
|
515
|
+
threadId: thread.empty() ? null : thread.id,
|
|
503
516
|
statusCode: c.res.status,
|
|
504
517
|
error: message,
|
|
505
518
|
agentIds: Array.from(agentIds),
|