@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.
Files changed (67) hide show
  1. package/README.md +61 -35
  2. package/dist/_config.d.ts.map +1 -1
  3. package/dist/_config.js +9 -2
  4. package/dist/_config.js.map +1 -1
  5. package/dist/agent.d.ts.map +1 -1
  6. package/dist/agent.js +6 -0
  7. package/dist/agent.js.map +1 -1
  8. package/dist/app.d.ts +5 -2
  9. package/dist/app.d.ts.map +1 -1
  10. package/dist/app.js.map +1 -1
  11. package/dist/eval.d.ts +2 -0
  12. package/dist/eval.d.ts.map +1 -1
  13. package/dist/handlers/cron.d.ts +47 -0
  14. package/dist/handlers/cron.d.ts.map +1 -0
  15. package/dist/handlers/cron.js +49 -0
  16. package/dist/handlers/cron.js.map +1 -0
  17. package/dist/handlers/index.d.ts +5 -0
  18. package/dist/handlers/index.d.ts.map +1 -0
  19. package/dist/handlers/index.js +5 -0
  20. package/dist/handlers/index.js.map +1 -0
  21. package/dist/handlers/sse.d.ts +74 -0
  22. package/dist/handlers/sse.d.ts.map +1 -0
  23. package/dist/handlers/sse.js +70 -0
  24. package/dist/handlers/sse.js.map +1 -0
  25. package/dist/handlers/stream.d.ts +52 -0
  26. package/dist/handlers/stream.d.ts.map +1 -0
  27. package/dist/handlers/stream.js +75 -0
  28. package/dist/handlers/stream.js.map +1 -0
  29. package/dist/handlers/websocket.d.ts +49 -0
  30. package/dist/handlers/websocket.d.ts.map +1 -0
  31. package/dist/handlers/websocket.js +130 -0
  32. package/dist/handlers/websocket.js.map +1 -0
  33. package/dist/index.d.ts +2 -2
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +4 -2
  36. package/dist/index.js.map +1 -1
  37. package/dist/otel/logger.d.ts +1 -4
  38. package/dist/otel/logger.d.ts.map +1 -1
  39. package/dist/otel/logger.js +11 -2
  40. package/dist/otel/logger.js.map +1 -1
  41. package/dist/router.d.ts +46 -236
  42. package/dist/router.d.ts.map +1 -1
  43. package/dist/router.js +82 -349
  44. package/dist/router.js.map +1 -1
  45. package/dist/workbench.d.ts +6 -2
  46. package/dist/workbench.d.ts.map +1 -1
  47. package/dist/workbench.js +29 -26
  48. package/dist/workbench.js.map +1 -1
  49. package/package.json +5 -7
  50. package/src/_config.ts +9 -2
  51. package/src/agent.ts +6 -0
  52. package/src/app.ts +7 -2
  53. package/src/eval.ts +2 -0
  54. package/src/handlers/cron.ts +70 -0
  55. package/src/handlers/index.ts +4 -0
  56. package/src/handlers/sse.ts +118 -0
  57. package/src/handlers/stream.ts +86 -0
  58. package/src/handlers/websocket.ts +153 -0
  59. package/src/index.ts +16 -3
  60. package/src/otel/logger.ts +13 -2
  61. package/src/router.ts +110 -597
  62. package/src/workbench.ts +30 -27
  63. package/dist/io/email.d.ts +0 -77
  64. package/dist/io/email.d.ts.map +0 -1
  65. package/dist/io/email.js +0 -162
  66. package/dist/io/email.js.map +0 -1
  67. package/src/io/email.ts +0 -191
package/dist/router.d.ts CHANGED
@@ -1,232 +1,64 @@
1
- import { type Context, Hono, type MiddlewareHandler, type Schema, type Env as HonoEnv } from 'hono';
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 interface WebSocketConnection {
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
- * Register a route to handle incoming emails at a specific address.
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
- * router.websocket('/ws', (c) => (ws) => {
136
- * ws.onOpen((event) => {
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, handler: (c: Context) => (ws: WebSocketConnection) => void): this;
15
+ websocket(path: string, ...args: any[]): this;
153
16
  /**
154
- * Create a WebSocket route with middleware.
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
- * router.websocket('/ws', authMiddleware, (c) => (ws) => {
163
- * ws.onMessage((event) => {
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
- websocket(path: string, middleware: MiddlewareHandler, handler: (c: Context) => (ws: WebSocketConnection) => void): this;
23
+ sse(path: string, ...args: any[]): this;
170
24
  /**
171
- * Create a Server-Sent Events (SSE) route for streaming updates to clients.
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
- * router.sse('/notifications', (c) => async (stream) => {
179
- * let count = 0;
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
- sse(path: string, handler: (c: Context) => (stream: any) => void): this;
31
+ stream(path: string, ...args: any[]): this;
194
32
  /**
195
- * Create an SSE route with middleware.
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
- * router.sse('/protected-events', authMiddleware, (c) => async (stream) => {
204
- * stream.writeSSE({ data: 'Secure event', event: 'update' });
205
- * stream.close();
206
- * });
35
+ * import { cron } from '@agentuity/runtime';
36
+ * router.post('/job', cron('0 0 * * *', (c) => { ... }));
207
37
  * ```
208
38
  */
209
- sse(path: string, middleware: MiddlewareHandler, handler: (c: Context) => (stream: any) => void): this;
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
- * In addition to standard HTTP methods (get, post, put, delete, patch), the router includes:
216
- * - **stream()** - Stream responses with ReadableStream
217
- * - **websocket()** - WebSocket connections
218
- * - **sse()** - Server-Sent Events
219
- * - **email()** - Email handler routing
220
- * - **sms()** - SMS handler routing
221
- * - **cron()** - Scheduled task routing
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 with custom methods
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.websocket('/ws', (c) => (ws) => {
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.sse('/notifications', (c) => async (stream) => {
260
- * let count = 0;
261
- * const interval = setInterval(() => {
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
- * // SMS routing
278
- * router.sms({ number: '+1234567890' }, (c) => {
279
- * return c.text('SMS received');
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
- * // Scheduled cron
283
- * router.cron('0 0 * * *', (c) => {
284
- * console.log('Daily task running');
285
- * return c.text('OK');
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>;
@@ -1 +1 @@
1
- {"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AAEA,OAAO,EACN,KAAK,OAAO,EACZ,IAAI,EAEJ,KAAK,iBAAiB,EACtB,KAAK,MAAM,EACX,KAAK,GAAG,IAAI,OAAO,EACnB,MAAM,MAAM,CAAC;AAId,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAEjC,OAAO,EAAc,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAGpD,YAAY,EAAE,GAAG,EAAE,CAAC;AACpB,YAAY,EAAE,OAAO,EAAE,CAAC;AAexB,MAAM,WAAW,mBAAmB;IACnC,MAAM,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,I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