@agentuity/server 0.0.3 → 0.0.4

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 (3) hide show
  1. package/AGENTS.md +124 -0
  2. package/README.md +220 -0
  3. package/package.json +2 -1
package/AGENTS.md ADDED
@@ -0,0 +1,124 @@
1
+ # Agent Guidelines for @agentuity/server
2
+
3
+ ## Package Overview
4
+
5
+ Server runtime for building Agentuity applications. Built on Hono framework and optimized for Bun runtime with OpenTelemetry observability.
6
+
7
+ ## Commands
8
+
9
+ - **Build**: `bun run build` (compiles for Bun target)
10
+ - **Typecheck**: `bun run typecheck` (runs TypeScript type checking)
11
+ - **Clean**: `bun run clean` (removes dist/)
12
+
13
+ ## Architecture
14
+
15
+ - **Runtime**: Bun server runtime
16
+ - **Framework**: Hono (lightweight web framework)
17
+ - **Build target**: Bun runtime
18
+ - **Dependencies**: `@agentuity/core`, Hono, OpenTelemetry
19
+ - **Observability**: Built-in OpenTelemetry for logs, traces, and metrics
20
+
21
+ ## Structure
22
+
23
+ ```
24
+ src/
25
+ ├── index.ts # Main exports
26
+ ├── app.ts # createApp() function
27
+ ├── agent.ts # Agent types and defineAgent()
28
+ ├── router.ts # createRouter() with extended methods
29
+ ├── logger.ts # Logging utilities
30
+ ├── _server.ts # Internal server creation
31
+ ├── _context.ts # Internal context management
32
+ └── _util.ts # Internal utilities
33
+ ```
34
+
35
+ ## Code Style
36
+
37
+ - **Hono patterns** - Follow Hono's context-based API design
38
+ - **Type safety** - Extensive use of TypeScript generics
39
+ - **Middleware pattern** - Support Hono middleware
40
+ - **Async handlers** - All handlers can be async
41
+ - **OpenTelemetry** - Use tracer/logger from context
42
+
43
+ ## Important Conventions
44
+
45
+ - **Agent context** - Every agent handler receives `AgentContext` as first parameter
46
+ - **Schema validation** - Support StandardSchemaV1 (works with Zod, Valibot, etc.)
47
+ - **Streaming support** - Agents can return ReadableStream for streaming responses
48
+ - **WebSocket support** - Use `router.websocket()` for WebSocket routes
49
+ - **SSE support** - Use `router.sse()` for Server-Sent Events
50
+ - **Session tracking** - Each request gets unique sessionId
51
+ - **Storage abstractions** - Provide kv, objectstore, stream, vector interfaces
52
+
53
+ ## Agent Definition Pattern
54
+
55
+ ```typescript
56
+ import { defineAgent } from '@agentuity/server';
57
+ import { z } from 'zod';
58
+
59
+ export default defineAgent({
60
+ metadata: {
61
+ id: 'unique-id',
62
+ identifier: 'folder-name',
63
+ name: 'Human Name',
64
+ description: 'What it does',
65
+ filename: __filename,
66
+ version: 'hash-or-version'
67
+ },
68
+ inputSchema: z.object({ /* ... */ }),
69
+ outputSchema: z.object({ /* ... */ }),
70
+ handler: async (ctx, input) => {
71
+ // ctx.logger, ctx.tracer, ctx.kv, etc.
72
+ return output;
73
+ }
74
+ });
75
+ ```
76
+
77
+ ## Router Extensions
78
+
79
+ The `createRouter()` function returns an extended Hono instance with:
80
+
81
+ - **Standard HTTP methods**: `get`, `post`, `put`, `delete`, `patch`
82
+ - **Streaming**: `stream(path, handler)` - Returns ReadableStream
83
+ - **WebSocket**: `websocket(path, handler)` - WebSocket connections
84
+ - **SSE**: `sse(path, handler)` - Server-Sent Events
85
+
86
+ ## AgentContext API
87
+
88
+ Every agent handler receives:
89
+
90
+ ```typescript
91
+ interface AgentContext {
92
+ logger: Logger; // Structured logger
93
+ tracer: Tracer; // OpenTelemetry tracer
94
+ sessionId: string; // Unique session ID
95
+ kv: KeyValueStorage; // Key-value storage
96
+ objectstore: ObjectStorage; // Object storage
97
+ stream: StreamStorage; // Stream storage
98
+ vector: VectorStorage; // Vector storage
99
+ agent: AgentRegistry; // Access other agents
100
+ waitUntil: (promise) => void; // Background tasks
101
+ }
102
+ ```
103
+
104
+ ## Observability
105
+
106
+ - **Logging**: Use `ctx.logger.info/warn/error()` not console.log
107
+ - **Tracing**: Create spans with `ctx.tracer.startSpan()`
108
+ - **Metrics**: Access via `c.var.meter` in Hono context
109
+ - **Environment**: Metrics/traces sent to OTLP endpoints
110
+
111
+ ## Testing
112
+
113
+ - Use Bun's test runner: `bun test`
114
+ - Mock storage interfaces (kv, objectstore, etc.)
115
+ - Test agent handlers with mock context
116
+ - Use Hono's testing utilities for routes
117
+
118
+ ## Publishing Checklist
119
+
120
+ 1. Run `bun run build` to compile for Bun runtime
121
+ 2. Verify OpenTelemetry dependencies are correct versions
122
+ 3. Test with real Hono server
123
+ 4. Must publish **after** @agentuity/core
124
+ 5. Ensure React is only in devDependencies (for type checking web components)
package/README.md ADDED
@@ -0,0 +1,220 @@
1
+ # @agentuity/server
2
+
3
+ Server runtime for building Agentuity applications with Bun and Hono.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ bun add @agentuity/server
9
+ ```
10
+
11
+ ## Overview
12
+
13
+ `@agentuity/server` provides the server-side runtime for Agentuity applications. Built on [Hono](https://hono.dev/) and optimized for [Bun](https://bun.sh/), it enables you to create type-safe agents with automatic routing, validation, and observability.
14
+
15
+ ## Quick Start
16
+
17
+ ### Creating an Application
18
+
19
+ ```typescript
20
+ import { createApp } from '@agentuity/server';
21
+
22
+ const { app, server, logger } = createApp();
23
+
24
+ // Start the server
25
+ server.listen(3000);
26
+ logger.info('Server running on http://localhost:3000');
27
+ ```
28
+
29
+ ### Defining an Agent
30
+
31
+ ```typescript
32
+ import { defineAgent } from '@agentuity/server';
33
+ import { z } from 'zod';
34
+
35
+ const myAgent = defineAgent({
36
+ metadata: {
37
+ id: 'my-agent',
38
+ identifier: 'my-agent',
39
+ name: 'My Agent',
40
+ description: 'Example agent',
41
+ filename: 'src/agents/my-agent/agent.ts',
42
+ version: '1.0.0'
43
+ },
44
+ inputSchema: z.object({
45
+ message: z.string()
46
+ }),
47
+ outputSchema: z.object({
48
+ response: z.string()
49
+ }),
50
+ handler: async (ctx, input) => {
51
+ ctx.logger.info('Processing message:', input.message);
52
+ return { response: `You said: ${input.message}` };
53
+ }
54
+ });
55
+
56
+ export default myAgent;
57
+ ```
58
+
59
+ ### Creating Custom Routes
60
+
61
+ ```typescript
62
+ import { createRouter } from '@agentuity/server';
63
+
64
+ const router = createRouter();
65
+
66
+ router.get('/hello', (c) => {
67
+ return c.json({ message: 'Hello, world!' });
68
+ });
69
+
70
+ router.post('/data', async (c) => {
71
+ const body = await c.req.json();
72
+ return c.json({ received: body });
73
+ });
74
+
75
+ export default router;
76
+ ```
77
+
78
+ ### Streaming Responses
79
+
80
+ ```typescript
81
+ router.stream('/events', async (c) => {
82
+ return new ReadableStream({
83
+ start(controller) {
84
+ controller.enqueue('Event 1\n');
85
+ controller.enqueue('Event 2\n');
86
+ controller.close();
87
+ }
88
+ });
89
+ });
90
+ ```
91
+
92
+ ### WebSocket Support
93
+
94
+ ```typescript
95
+ router.websocket('/chat', (c) => (ws) => {
96
+ ws.onOpen(() => {
97
+ console.log('Client connected');
98
+ });
99
+
100
+ ws.onMessage((event) => {
101
+ const data = JSON.parse(event.data);
102
+ ws.send(JSON.stringify({ echo: data }));
103
+ });
104
+
105
+ ws.onClose(() => {
106
+ console.log('Client disconnected');
107
+ });
108
+ });
109
+ ```
110
+
111
+ ### Server-Sent Events (SSE)
112
+
113
+ ```typescript
114
+ router.sse('/updates', (c) => async (stream) => {
115
+ for (let i = 0; i < 10; i++) {
116
+ await stream.writeSSE({
117
+ data: JSON.stringify({ count: i }),
118
+ event: 'update'
119
+ });
120
+ await stream.sleep(1000);
121
+ }
122
+ });
123
+ ```
124
+
125
+ ## API Reference
126
+
127
+ ### createApp(config?)
128
+
129
+ Creates a new Agentuity application instance.
130
+
131
+ **Returns:**
132
+ - `app` - Hono application instance
133
+ - `server` - Server instance with `listen()` method
134
+ - `logger` - Structured logger
135
+
136
+ ### defineAgent(config)
137
+
138
+ Defines a type-safe agent with input/output validation.
139
+
140
+ **Config:**
141
+ - `metadata` - Agent metadata (id, name, description, etc.)
142
+ - `inputSchema?` - Schema for input validation (Zod, Valibot, etc.)
143
+ - `outputSchema?` - Schema for output validation
144
+ - `stream?` - Whether the agent returns a stream
145
+ - `handler` - Agent handler function
146
+
147
+ ### createRouter()
148
+
149
+ Creates a new router for defining custom API routes.
150
+
151
+ **Methods:**
152
+ - `get/post/put/delete/patch` - HTTP method handlers
153
+ - `stream(path, handler)` - Streaming response handler
154
+ - `websocket(path, handler)` - WebSocket handler
155
+ - `sse(path, handler)` - Server-Sent Events handler
156
+
157
+ ### AgentContext
158
+
159
+ Context object available in agent handlers:
160
+
161
+ ```typescript
162
+ interface AgentContext {
163
+ logger: Logger; // Structured logger
164
+ tracer: Tracer; // OpenTelemetry tracer
165
+ sessionId: string; // Unique session ID
166
+ kv: KeyValueStorage; // Key-value storage
167
+ objectstore: ObjectStorage; // Object storage
168
+ stream: StreamStorage; // Stream storage
169
+ vector: VectorStorage; // Vector storage
170
+ agent: AgentRegistry; // Access to other agents
171
+ waitUntil: (promise) => void; // Defer cleanup tasks
172
+ }
173
+ ```
174
+
175
+ ## Storage Services
176
+
177
+ Agentuity provides built-in storage abstractions:
178
+
179
+ - **KeyValueStorage** - Simple key-value storage
180
+ - **ObjectStorage** - Object/blob storage
181
+ - **StreamStorage** - Streaming data storage
182
+ - **VectorStorage** - Vector embeddings storage
183
+
184
+ Access these via the agent context:
185
+
186
+ ```typescript
187
+ const myAgent = defineAgent({
188
+ handler: async (ctx, input) => {
189
+ await ctx.kv.set('key', 'value');
190
+ const value = await ctx.kv.get('key');
191
+ return { value };
192
+ }
193
+ });
194
+ ```
195
+
196
+ ## Observability
197
+
198
+ Built-in OpenTelemetry support for logging, tracing, and metrics:
199
+
200
+ ```typescript
201
+ const myAgent = defineAgent({
202
+ handler: async (ctx, input) => {
203
+ ctx.logger.info('Processing request');
204
+
205
+ const span = ctx.tracer.startSpan('custom-operation');
206
+ // ... do work ...
207
+ span.end();
208
+
209
+ return { success: true };
210
+ }
211
+ });
212
+ ```
213
+
214
+ ## TypeScript
215
+
216
+ Fully typed with TypeScript. Input and output types are automatically inferred from your schemas.
217
+
218
+ ## License
219
+
220
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentuity/server",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "type": "module",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./dist/index.d.ts",
@@ -11,6 +11,7 @@
11
11
  }
12
12
  },
13
13
  "files": [
14
+ "AGENTS.md",
14
15
  "README.md",
15
16
  "src",
16
17
  "dist"