@agentuity/runtime 0.0.103 → 0.0.105
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/README.md +61 -35
- package/dist/_config.d.ts.map +1 -1
- package/dist/_config.js +9 -2
- package/dist/_config.js.map +1 -1
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +6 -0
- package/dist/agent.js.map +1 -1
- package/dist/app.d.ts +5 -2
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js.map +1 -1
- package/dist/eval.d.ts +2 -0
- package/dist/eval.d.ts.map +1 -1
- package/dist/handlers/cron.d.ts +47 -0
- package/dist/handlers/cron.d.ts.map +1 -0
- package/dist/handlers/cron.js +49 -0
- package/dist/handlers/cron.js.map +1 -0
- package/dist/handlers/index.d.ts +5 -0
- package/dist/handlers/index.d.ts.map +1 -0
- package/dist/handlers/index.js +5 -0
- package/dist/handlers/index.js.map +1 -0
- package/dist/handlers/sse.d.ts +74 -0
- package/dist/handlers/sse.d.ts.map +1 -0
- package/dist/handlers/sse.js +70 -0
- package/dist/handlers/sse.js.map +1 -0
- package/dist/handlers/stream.d.ts +52 -0
- package/dist/handlers/stream.d.ts.map +1 -0
- package/dist/handlers/stream.js +75 -0
- package/dist/handlers/stream.js.map +1 -0
- package/dist/handlers/websocket.d.ts +49 -0
- package/dist/handlers/websocket.d.ts.map +1 -0
- package/dist/handlers/websocket.js +130 -0
- package/dist/handlers/websocket.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/otel/logger.d.ts +1 -4
- package/dist/otel/logger.d.ts.map +1 -1
- package/dist/otel/logger.js +11 -2
- package/dist/otel/logger.js.map +1 -1
- package/dist/router.d.ts +46 -236
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +82 -349
- package/dist/router.js.map +1 -1
- package/dist/workbench.d.ts +6 -2
- package/dist/workbench.d.ts.map +1 -1
- package/dist/workbench.js +29 -26
- package/dist/workbench.js.map +1 -1
- package/package.json +5 -7
- package/src/_config.ts +9 -2
- package/src/agent.ts +6 -0
- package/src/app.ts +7 -2
- package/src/eval.ts +2 -0
- package/src/handlers/cron.ts +70 -0
- package/src/handlers/index.ts +4 -0
- package/src/handlers/sse.ts +118 -0
- package/src/handlers/stream.ts +86 -0
- package/src/handlers/websocket.ts +153 -0
- package/src/index.ts +16 -3
- package/src/otel/logger.ts +13 -2
- package/src/router.ts +110 -597
- package/src/workbench.ts +30 -27
- package/dist/io/email.d.ts +0 -77
- package/dist/io/email.d.ts.map +0 -1
- package/dist/io/email.js +0 -162
- package/dist/io/email.js.map +0 -1
- package/src/io/email.ts +0 -191
package/dist/router.d.ts
CHANGED
|
@@ -1,232 +1,64 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Hono, type Schema, type Env as HonoEnv } from 'hono';
|
|
2
2
|
import type { Env } from './app';
|
|
3
|
-
import { type Email } from './io/email';
|
|
4
3
|
export type { Env };
|
|
5
4
|
export type { HonoEnv };
|
|
6
|
-
export
|
|
7
|
-
onOpen: (handler: (event: any) => void | Promise<void>) => void;
|
|
8
|
-
onMessage: (handler: (event: any) => void | Promise<void>) => void;
|
|
9
|
-
onClose: (handler: (event: any) => void | Promise<void>) => void;
|
|
10
|
-
send: (data: string | ArrayBuffer | Uint8Array) => void;
|
|
11
|
-
}
|
|
5
|
+
export type { WebSocketConnection } from './handlers/websocket';
|
|
12
6
|
declare module 'hono' {
|
|
13
7
|
interface Hono {
|
|
14
8
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* @param address - The email address to handle (e.g., 'support@example.com')
|
|
18
|
-
* @param handler - Handler function receiving parsed email and context
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* ```typescript
|
|
22
|
-
* router.email('support@example.com', (email, c) => {
|
|
23
|
-
* console.log('From:', email.fromEmail());
|
|
24
|
-
* console.log('Subject:', email.subject());
|
|
25
|
-
* console.log('Body:', email.text());
|
|
26
|
-
* return c.text('Email received');
|
|
27
|
-
* });
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
email(address: string, handler: (email: Email, c: Context) => any): this;
|
|
31
|
-
/**
|
|
32
|
-
* Register a route to handle incoming emails with middleware.
|
|
33
|
-
*
|
|
34
|
-
* @param address - The email address to handle
|
|
35
|
-
* @param middleware - Middleware to run before the handler
|
|
36
|
-
* @param handler - Handler function receiving parsed email and context
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* ```typescript
|
|
40
|
-
* router.email('support@example.com', authMiddleware, (email, c) => {
|
|
41
|
-
* return c.json({ received: email.subject() });
|
|
42
|
-
* });
|
|
43
|
-
* ```
|
|
44
|
-
*/
|
|
45
|
-
email(address: string, middleware: MiddlewareHandler, handler: (email: Email, c: Context) => any): this;
|
|
46
|
-
/**
|
|
47
|
-
* Register a route to handle incoming SMS messages to a phone number.
|
|
48
|
-
*
|
|
49
|
-
* @param params - Configuration object with phone number
|
|
50
|
-
* @param params.number - Phone number to handle (e.g., '+1234567890')
|
|
51
|
-
* @param handler - Handler function receiving context
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* ```typescript
|
|
55
|
-
* router.sms({ number: '+1234567890' }, (c) => {
|
|
56
|
-
* const message = c.req.query('message');
|
|
57
|
-
* console.log('SMS received:', message);
|
|
58
|
-
* return c.text('SMS received');
|
|
59
|
-
* });
|
|
60
|
-
* ```
|
|
61
|
-
*/
|
|
62
|
-
sms(params: {
|
|
63
|
-
number: string;
|
|
64
|
-
}, handler: (c: Context) => any): this;
|
|
65
|
-
/**
|
|
66
|
-
* Schedule a handler to run at specific intervals using cron syntax.
|
|
67
|
-
*
|
|
68
|
-
* @param schedule - Cron expression (e.g., '0 0 * * *' for daily at midnight)
|
|
69
|
-
* @param handler - Handler function to run on schedule
|
|
70
|
-
*
|
|
71
|
-
* @example
|
|
72
|
-
* ```typescript
|
|
73
|
-
* // Run daily at midnight
|
|
74
|
-
* router.cron('0 0 * * *', (c) => {
|
|
75
|
-
* console.log('Daily cleanup running');
|
|
76
|
-
* return c.text('Cleanup complete');
|
|
77
|
-
* });
|
|
78
|
-
*
|
|
79
|
-
* // Run every hour
|
|
80
|
-
* router.cron('0 * * * *', (c) => {
|
|
81
|
-
* console.log('Hourly health check');
|
|
82
|
-
* return c.text('OK');
|
|
83
|
-
* });
|
|
84
|
-
* ```
|
|
85
|
-
*/
|
|
86
|
-
cron(schedule: string, handler: (c: Context) => any): this;
|
|
87
|
-
/**
|
|
88
|
-
* Create a streaming route that returns a ReadableStream.
|
|
89
|
-
*
|
|
90
|
-
* @param path - The route path
|
|
91
|
-
* @param handler - Handler returning a ReadableStream
|
|
92
|
-
*
|
|
93
|
-
* @example
|
|
94
|
-
* ```typescript
|
|
95
|
-
* router.stream('/events', (c) => {
|
|
96
|
-
* return new ReadableStream({
|
|
97
|
-
* start(controller) {
|
|
98
|
-
* controller.enqueue('event 1\n');
|
|
99
|
-
* controller.enqueue('event 2\n');
|
|
100
|
-
* controller.close();
|
|
101
|
-
* }
|
|
102
|
-
* });
|
|
103
|
-
* });
|
|
104
|
-
* ```
|
|
105
|
-
*/
|
|
106
|
-
stream(path: string, handler: (c: Context) => ReadableStream<any> | Promise<ReadableStream<any>>): this;
|
|
107
|
-
/**
|
|
108
|
-
* Create a streaming route with middleware.
|
|
109
|
-
*
|
|
110
|
-
* @param path - The route path
|
|
111
|
-
* @param middleware - Middleware to run before streaming
|
|
112
|
-
* @param handler - Handler returning a ReadableStream
|
|
113
|
-
*
|
|
114
|
-
* @example
|
|
115
|
-
* ```typescript
|
|
116
|
-
* router.stream('/protected-stream', authMiddleware, (c) => {
|
|
117
|
-
* return new ReadableStream({
|
|
118
|
-
* start(controller) {
|
|
119
|
-
* controller.enqueue('secure data\n');
|
|
120
|
-
* controller.close();
|
|
121
|
-
* }
|
|
122
|
-
* });
|
|
123
|
-
* });
|
|
124
|
-
* ```
|
|
125
|
-
*/
|
|
126
|
-
stream(path: string, middleware: MiddlewareHandler, handler: (c: Context) => ReadableStream<any> | Promise<ReadableStream<any>>): this;
|
|
127
|
-
/**
|
|
128
|
-
* Create a WebSocket route for real-time bidirectional communication.
|
|
129
|
-
*
|
|
130
|
-
* @param path - The route path
|
|
131
|
-
* @param handler - Setup function that registers WebSocket event handlers
|
|
132
|
-
*
|
|
133
|
-
* @example
|
|
9
|
+
* @deprecated Use the `websocket` middleware instead:
|
|
134
10
|
* ```typescript
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
* console.log('WebSocket opened');
|
|
138
|
-
* ws.send('Welcome!');
|
|
139
|
-
* });
|
|
140
|
-
*
|
|
141
|
-
* ws.onMessage((event) => {
|
|
142
|
-
* console.log('Received:', event.data);
|
|
143
|
-
* ws.send('Echo: ' + event.data);
|
|
144
|
-
* });
|
|
145
|
-
*
|
|
146
|
-
* ws.onClose((event) => {
|
|
147
|
-
* console.log('WebSocket closed');
|
|
148
|
-
* });
|
|
149
|
-
* });
|
|
11
|
+
* import { websocket } from '@agentuity/runtime';
|
|
12
|
+
* router.get('/ws', websocket((c, ws) => { ... }));
|
|
150
13
|
* ```
|
|
151
14
|
*/
|
|
152
|
-
websocket(path: string,
|
|
15
|
+
websocket(path: string, ...args: any[]): this;
|
|
153
16
|
/**
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
* @param path - The route path
|
|
157
|
-
* @param middleware - Middleware to run before WebSocket upgrade
|
|
158
|
-
* @param handler - Setup function that registers WebSocket event handlers
|
|
159
|
-
*
|
|
160
|
-
* @example
|
|
17
|
+
* @deprecated Use the `sse` middleware instead:
|
|
161
18
|
* ```typescript
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
* ws.send('Authenticated echo: ' + event.data);
|
|
165
|
-
* });
|
|
166
|
-
* });
|
|
19
|
+
* import { sse } from '@agentuity/runtime';
|
|
20
|
+
* router.get('/events', sse((c, stream) => { ... }));
|
|
167
21
|
* ```
|
|
168
22
|
*/
|
|
169
|
-
|
|
23
|
+
sse(path: string, ...args: any[]): this;
|
|
170
24
|
/**
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
* @param path - The route path
|
|
174
|
-
* @param handler - Handler receiving SSE stream writer
|
|
175
|
-
*
|
|
176
|
-
* @example
|
|
25
|
+
* @deprecated Use the `stream` middleware instead:
|
|
177
26
|
* ```typescript
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
* const interval = setInterval(() => {
|
|
181
|
-
* stream.writeSSE({
|
|
182
|
-
* data: `Notification ${++count}`,
|
|
183
|
-
* event: 'notification'
|
|
184
|
-
* });
|
|
185
|
-
* if (count >= 10) {
|
|
186
|
-
* clearInterval(interval);
|
|
187
|
-
* stream.close();
|
|
188
|
-
* }
|
|
189
|
-
* }, 1000);
|
|
190
|
-
* });
|
|
27
|
+
* import { stream } from '@agentuity/runtime';
|
|
28
|
+
* router.post('/data', stream((c) => new ReadableStream({ ... })));
|
|
191
29
|
* ```
|
|
192
30
|
*/
|
|
193
|
-
|
|
31
|
+
stream(path: string, ...args: any[]): this;
|
|
194
32
|
/**
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
* @param path - The route path
|
|
198
|
-
* @param middleware - Middleware to run before SSE streaming
|
|
199
|
-
* @param handler - Handler receiving SSE stream writer
|
|
200
|
-
*
|
|
201
|
-
* @example
|
|
33
|
+
* @deprecated Use the `cron` middleware instead:
|
|
202
34
|
* ```typescript
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
* stream.close();
|
|
206
|
-
* });
|
|
35
|
+
* import { cron } from '@agentuity/runtime';
|
|
36
|
+
* router.post('/job', cron('0 0 * * *', (c) => { ... }));
|
|
207
37
|
* ```
|
|
208
38
|
*/
|
|
209
|
-
|
|
39
|
+
cron(schedule: string, ...args: any[]): this;
|
|
210
40
|
}
|
|
211
41
|
}
|
|
212
42
|
/**
|
|
213
43
|
* Creates a Hono router with extended methods for Agentuity-specific routing patterns.
|
|
214
44
|
*
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
* - **
|
|
219
|
-
* - **
|
|
220
|
-
* - **
|
|
221
|
-
* - **cron()** - Scheduled
|
|
45
|
+
* Standard HTTP methods (get, post, put, delete, patch) are available, plus middleware
|
|
46
|
+
* functions for specialized protocols:
|
|
47
|
+
*
|
|
48
|
+
* - **websocket()** - WebSocket connections (import { websocket } from '@agentuity/runtime')
|
|
49
|
+
* - **sse()** - Server-Sent Events (import { sse } from '@agentuity/runtime')
|
|
50
|
+
* - **stream()** - Streaming responses (import { stream } from '@agentuity/runtime')
|
|
51
|
+
* - **cron()** - Scheduled tasks (import { cron } from '@agentuity/runtime')
|
|
222
52
|
*
|
|
223
53
|
* @template E - Environment type (Hono Env)
|
|
224
54
|
* @template S - Schema type for route definitions
|
|
225
55
|
*
|
|
226
|
-
* @returns Extended Hono router
|
|
56
|
+
* @returns Extended Hono router
|
|
227
57
|
*
|
|
228
58
|
* @example
|
|
229
59
|
* ```typescript
|
|
60
|
+
* import { createRouter, websocket, sse, stream, cron } from '@agentuity/runtime';
|
|
61
|
+
*
|
|
230
62
|
* const router = createRouter();
|
|
231
63
|
*
|
|
232
64
|
* // Standard HTTP routes
|
|
@@ -236,54 +68,32 @@ declare module 'hono' {
|
|
|
236
68
|
* return c.json({ received: body });
|
|
237
69
|
* });
|
|
238
70
|
*
|
|
239
|
-
* // Streaming response
|
|
240
|
-
* router.stream('/events', (c) => {
|
|
241
|
-
* return new ReadableStream({
|
|
242
|
-
* start(controller) {
|
|
243
|
-
* controller.enqueue('event 1\n');
|
|
244
|
-
* controller.enqueue('event 2\n');
|
|
245
|
-
* controller.close();
|
|
246
|
-
* }
|
|
247
|
-
* });
|
|
248
|
-
* });
|
|
249
|
-
*
|
|
250
71
|
* // WebSocket connection
|
|
251
|
-
* router.
|
|
72
|
+
* router.get('/ws', websocket((c, ws) => {
|
|
252
73
|
* ws.onMessage((event) => {
|
|
253
|
-
* console.log('Received:', event.data);
|
|
254
74
|
* ws.send('Echo: ' + event.data);
|
|
255
75
|
* });
|
|
256
|
-
* });
|
|
76
|
+
* }));
|
|
257
77
|
*
|
|
258
78
|
* // Server-Sent Events
|
|
259
|
-
* router.
|
|
260
|
-
*
|
|
261
|
-
*
|
|
262
|
-
* stream.writeSSE({ data: `Message ${++count}` });
|
|
263
|
-
* if (count >= 10) {
|
|
264
|
-
* clearInterval(interval);
|
|
265
|
-
* stream.close();
|
|
266
|
-
* }
|
|
267
|
-
* }, 1000);
|
|
268
|
-
* });
|
|
269
|
-
*
|
|
270
|
-
* // Email routing
|
|
271
|
-
* router.email('support@example.com', (email, c) => {
|
|
272
|
-
* console.log('From:', email.fromEmail());
|
|
273
|
-
* console.log('Subject:', email.subject());
|
|
274
|
-
* return c.text('Email received');
|
|
275
|
-
* });
|
|
79
|
+
* router.get('/events', sse((c, stream) => {
|
|
80
|
+
* stream.writeSSE({ data: 'Hello', event: 'message' });
|
|
81
|
+
* }));
|
|
276
82
|
*
|
|
277
|
-
* //
|
|
278
|
-
* router.
|
|
279
|
-
* return
|
|
280
|
-
*
|
|
83
|
+
* // Streaming response
|
|
84
|
+
* router.post('/stream', stream((c) => {
|
|
85
|
+
* return new ReadableStream({
|
|
86
|
+
* start(controller) {
|
|
87
|
+
* controller.enqueue('data\n');
|
|
88
|
+
* controller.close();
|
|
89
|
+
* }
|
|
90
|
+
* });
|
|
91
|
+
* }));
|
|
281
92
|
*
|
|
282
|
-
* //
|
|
283
|
-
* router.cron('0 0 * * *', (c) => {
|
|
284
|
-
*
|
|
285
|
-
*
|
|
286
|
-
* });
|
|
93
|
+
* // Cron job
|
|
94
|
+
* router.post('/daily', cron('0 0 * * *', (c) => {
|
|
95
|
+
* return { status: 'complete' };
|
|
96
|
+
* }));
|
|
287
97
|
* ```
|
|
288
98
|
*/
|
|
289
99
|
export declare const createRouter: <E extends Env = Env, S extends Schema = Schema>() => Hono<E, S>;
|
package/dist/router.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,IAAI,EAAE,KAAK,MAAM,EAAE,KAAK,GAAG,IAAI,OAAO,EAAE,MAAM,MAAM,CAAC;AAE5E,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAGjC,YAAY,EAAE,GAAG,EAAE,CAAC;AACpB,YAAY,EAAE,OAAO,EAAE,CAAC;AAGxB,YAAY,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAIhE,OAAO,QAAQ,MAAM,CAAC;IACrB,UAAU,IAAI;QACb;;;;;;WAMG;QACH,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;QAE9C;;;;;;WAMG;QACH,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;QAExC;;;;;;WAMG;QACH,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;QAE3C;;;;;;WAMG;QACH,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;KAC7C;CACD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,GAAG,GAAG,GAAG,EAAE,CAAC,SAAS,MAAM,GAAG,MAAM,OAAK,IAAI,CAAC,CAAC,EAAE,CAAC,CAwHxF,CAAC"}
|