create-agentuity 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.
- package/AGENTS.md +189 -15
- package/README.md +111 -26
- package/package.json +1 -1
package/AGENTS.md
CHANGED
|
@@ -2,25 +2,199 @@
|
|
|
2
2
|
|
|
3
3
|
## Commands
|
|
4
4
|
|
|
5
|
-
- **Build**: `bun run build` (compiles
|
|
6
|
-
- **Dev
|
|
5
|
+
- **Build**: `bun run build` (compiles your application)
|
|
6
|
+
- **Dev**: `bun run dev` (starts development server)
|
|
7
7
|
- **Typecheck**: `bun run typecheck` (runs TypeScript type checking)
|
|
8
|
-
- **Install**: `bun install`
|
|
9
8
|
|
|
10
9
|
## Architecture
|
|
11
10
|
|
|
12
|
-
- **Runtime**: Bun
|
|
13
|
-
- **
|
|
14
|
-
- **
|
|
15
|
-
- **
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
- **Runtime**: Bun server runtime
|
|
12
|
+
- **Framework**: Hono (lightweight web framework)
|
|
13
|
+
- **Build tool**: `@agentuity/bundler` compiles to `.agentuity/` directory
|
|
14
|
+
- **Frontend**: React with `@agentuity/react` hooks
|
|
15
|
+
|
|
16
|
+
## Project Structure
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
{{PROJECT_NAME}}/
|
|
20
|
+
├── src/
|
|
21
|
+
│ ├── agents/ # Agent definitions
|
|
22
|
+
│ │ └── hello/ # Example "hello" agent
|
|
23
|
+
│ │ ├── agent.ts # Agent handler
|
|
24
|
+
│ │ └── route.ts # Agent HTTP routes
|
|
25
|
+
│ ├── apis/ # Custom API routes
|
|
26
|
+
│ │ └── status/ # Example status endpoint
|
|
27
|
+
│ └── web/ # React web application
|
|
28
|
+
│ └── app.tsx # Main React component
|
|
29
|
+
├── app.ts # Application entry point
|
|
30
|
+
├── tsconfig.json # TypeScript configuration
|
|
31
|
+
└── package.json # Dependencies and scripts
|
|
32
|
+
```
|
|
18
33
|
|
|
19
34
|
## Code Style
|
|
20
35
|
|
|
21
|
-
- **TypeScript
|
|
22
|
-
- **
|
|
23
|
-
- **
|
|
24
|
-
- **
|
|
25
|
-
- **
|
|
26
|
-
|
|
36
|
+
- **TypeScript-first** - All code is TypeScript
|
|
37
|
+
- **Async/await** - All agent handlers are async
|
|
38
|
+
- **Zod schemas** - Use Zod for input/output validation
|
|
39
|
+
- **Functional** - Prefer functional patterns over classes
|
|
40
|
+
- **Type-safe** - Leverage TypeScript generics and inference
|
|
41
|
+
|
|
42
|
+
## Creating Agents
|
|
43
|
+
|
|
44
|
+
### Agent Structure
|
|
45
|
+
|
|
46
|
+
Each agent should be in its own folder under `src/agents/`:
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
// src/agents/my-agent/agent.ts
|
|
50
|
+
import { type AgentContext, createAgent } from '@agentuity/server';
|
|
51
|
+
import { z } from 'zod';
|
|
52
|
+
|
|
53
|
+
const agent = createAgent({
|
|
54
|
+
schema: {
|
|
55
|
+
input: z.object({
|
|
56
|
+
message: z.string()
|
|
57
|
+
}),
|
|
58
|
+
output: z.object({
|
|
59
|
+
response: z.string()
|
|
60
|
+
}),
|
|
61
|
+
},
|
|
62
|
+
handler: async (ctx: AgentContext, input) => {
|
|
63
|
+
// Use ctx.logger for logging (not console.log)
|
|
64
|
+
ctx.logger.info('Processing message:', input.message);
|
|
65
|
+
|
|
66
|
+
// Access storage
|
|
67
|
+
await ctx.kv.set('last-message', input.message);
|
|
68
|
+
|
|
69
|
+
return { response: `Processed: ${input.message}` };
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
export default agent;
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Agent Routes (Optional)
|
|
77
|
+
|
|
78
|
+
Add custom HTTP routes for your agent:
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
// src/agents/my-agent/route.ts
|
|
82
|
+
import { createRouter } from '@agentuity/server';
|
|
83
|
+
import { zValidator } from '@hono/zod-validator';
|
|
84
|
+
import agent from './agent';
|
|
85
|
+
|
|
86
|
+
const router = createRouter();
|
|
87
|
+
|
|
88
|
+
// GET endpoint
|
|
89
|
+
router.get('/', async (c) => {
|
|
90
|
+
const result = await c.agent['my-agent'].run({ message: 'Hello!' });
|
|
91
|
+
return c.json(result);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// POST endpoint with validation
|
|
95
|
+
router.post('/', zValidator('json', agent.inputSchema!), async (c) => {
|
|
96
|
+
const data = c.req.valid('json');
|
|
97
|
+
const result = await c.agent['my-agent'].run(data);
|
|
98
|
+
return c.json(result);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
export default router;
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Agent Context API
|
|
105
|
+
|
|
106
|
+
Every agent handler receives an `AgentContext` with:
|
|
107
|
+
|
|
108
|
+
- `ctx.logger` - Structured logger (use instead of console.log)
|
|
109
|
+
- `ctx.tracer` - OpenTelemetry tracer for distributed tracing
|
|
110
|
+
- `ctx.sessionId` - Unique session identifier
|
|
111
|
+
- `ctx.kv` - Key-value storage interface
|
|
112
|
+
- `ctx.objectstore` - Object/blob storage
|
|
113
|
+
- `ctx.stream` - Stream storage
|
|
114
|
+
- `ctx.vector` - Vector embeddings storage
|
|
115
|
+
- `ctx.agent` - Access to other agents
|
|
116
|
+
- `ctx.waitUntil()` - Defer cleanup tasks
|
|
117
|
+
|
|
118
|
+
## Adding API Routes
|
|
119
|
+
|
|
120
|
+
Create custom routes in `src/apis/`:
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
// src/apis/my-route/route.ts
|
|
124
|
+
import { createRouter } from '@agentuity/server';
|
|
125
|
+
|
|
126
|
+
const router = createRouter();
|
|
127
|
+
|
|
128
|
+
router.get('/', (c) => {
|
|
129
|
+
return c.json({ status: 'ok' });
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
export default router;
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Frontend Development
|
|
136
|
+
|
|
137
|
+
Use `@agentuity/react` hooks to call agents from your React components:
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
// src/web/app.tsx
|
|
141
|
+
import { useAgent } from '@agentuity/react';
|
|
142
|
+
|
|
143
|
+
function MyComponent() {
|
|
144
|
+
const { data, run } = useAgent('hello');
|
|
145
|
+
|
|
146
|
+
const handleClick = async () => {
|
|
147
|
+
const result = await run({ name: 'World' });
|
|
148
|
+
console.log(result);
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
return (
|
|
152
|
+
<div>
|
|
153
|
+
<button onClick={handleClick}>Call Agent</button>
|
|
154
|
+
{data && <div>{data}</div>}
|
|
155
|
+
</div>
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Best Practices
|
|
161
|
+
|
|
162
|
+
- **Use structured logging** - Always use `ctx.logger`, never `console.log`
|
|
163
|
+
- **Validate inputs** - Define Zod schemas for all agent inputs/outputs
|
|
164
|
+
- **Handle errors** - Use try/catch and return meaningful error messages
|
|
165
|
+
- **Type everything** - Leverage TypeScript for type safety
|
|
166
|
+
- **Keep agents focused** - One agent should do one thing well
|
|
167
|
+
- **Use storage abstractions** - Use `ctx.kv`, `ctx.objectstore`, etc. instead of direct database access
|
|
168
|
+
|
|
169
|
+
## Environment Variables
|
|
170
|
+
|
|
171
|
+
Create a `.env` file in the project root:
|
|
172
|
+
|
|
173
|
+
```env
|
|
174
|
+
# Example environment variables
|
|
175
|
+
API_KEY=your-api-key
|
|
176
|
+
DATABASE_URL=your-database-url
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Access them in your code:
|
|
180
|
+
|
|
181
|
+
```typescript
|
|
182
|
+
const apiKey = process.env.API_KEY;
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## Deployment
|
|
186
|
+
|
|
187
|
+
Build for production:
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
bun run build
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
The compiled application will be in `.agentuity/`. Deploy this directory to your hosting provider.
|
|
194
|
+
|
|
195
|
+
## Learn More
|
|
196
|
+
|
|
197
|
+
- [Agentuity Documentation](https://agentuity.dev)
|
|
198
|
+
- [Bun Documentation](https://bun.sh/docs)
|
|
199
|
+
- [Hono Documentation](https://hono.dev/)
|
|
200
|
+
- [Zod Documentation](https://zod.dev/)
|
package/README.md
CHANGED
|
@@ -2,57 +2,142 @@
|
|
|
2
2
|
|
|
3
3
|
A new Agentuity project created with `create-agentuity`.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## What You Get
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
A fully configured Agentuity project with:
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
- ✅ **TypeScript** - Full type safety out of the box
|
|
10
|
+
- ✅ **Bun runtime** - Fast JavaScript runtime and package manager
|
|
11
|
+
- ✅ **Hot reload** - Development server with auto-rebuild
|
|
12
|
+
- ✅ **Example agent** - Sample "hello" agent to get started
|
|
13
|
+
- ✅ **React frontend** - Pre-configured web interface
|
|
14
|
+
- ✅ **API routes** - Example API endpoints
|
|
15
|
+
- ✅ **Type checking** - TypeScript configuration ready to go
|
|
14
16
|
|
|
15
|
-
|
|
17
|
+
## Project Structure
|
|
16
18
|
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
+
```
|
|
20
|
+
my-app/
|
|
21
|
+
├── src/
|
|
22
|
+
│ ├── agents/ # Agent definitions
|
|
23
|
+
│ │ └── hello/
|
|
24
|
+
│ │ └── agent.ts # Example agent
|
|
25
|
+
│ ├── apis/ # Custom API routes
|
|
26
|
+
│ │ └── route.ts # Example route
|
|
27
|
+
│ └── web/ # React web application
|
|
28
|
+
│ └── app.tsx # Main React component
|
|
29
|
+
├── app.ts # Application entry point
|
|
30
|
+
├── setup.ts # Initial setup script
|
|
31
|
+
├── tsconfig.json # TypeScript configuration
|
|
32
|
+
├── package.json # Dependencies and scripts
|
|
33
|
+
└── README.md # Project documentation
|
|
19
34
|
```
|
|
20
35
|
|
|
21
|
-
|
|
36
|
+
## Available Commands
|
|
22
37
|
|
|
23
|
-
|
|
38
|
+
After creating your project, you can run:
|
|
24
39
|
|
|
25
|
-
|
|
40
|
+
### Development
|
|
26
41
|
|
|
27
42
|
```bash
|
|
28
43
|
bun run dev
|
|
29
44
|
```
|
|
30
45
|
|
|
31
|
-
|
|
46
|
+
Starts the development server at http://localhost:3000
|
|
32
47
|
|
|
33
|
-
###
|
|
48
|
+
### Build
|
|
34
49
|
|
|
35
|
-
|
|
50
|
+
```bash
|
|
51
|
+
bun run build
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Compiles your application into the `.agentuity/` directory
|
|
55
|
+
|
|
56
|
+
### Type Check
|
|
36
57
|
|
|
37
58
|
```bash
|
|
38
59
|
bun run typecheck
|
|
39
60
|
```
|
|
40
61
|
|
|
41
|
-
|
|
62
|
+
Runs TypeScript type checking
|
|
42
63
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
64
|
+
## Next Steps
|
|
65
|
+
|
|
66
|
+
After creating your project:
|
|
67
|
+
|
|
68
|
+
1. **Customize the example agent** - Edit `src/agents/hello/agent.ts`
|
|
69
|
+
2. **Add new agents** - Create new folders in `src/agents/`
|
|
70
|
+
3. **Add API routes** - Create new routes in `src/apis/`
|
|
71
|
+
4. **Customize the UI** - Edit `src/web/app.tsx`
|
|
72
|
+
5. **Configure your app** - Modify `app.ts` to add middleware, configure services, etc.
|
|
73
|
+
|
|
74
|
+
## Creating Custom Agents
|
|
75
|
+
|
|
76
|
+
Create a new agent by adding a folder in `src/agents/`:
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
// src/agents/my-agent/agent.ts
|
|
80
|
+
import { type AgentContext, createAgent } from '@agentuity/server';
|
|
81
|
+
import { z } from 'zod';
|
|
82
|
+
|
|
83
|
+
const agent = createAgent({
|
|
84
|
+
metadata: {
|
|
85
|
+
description: 'My amazing agent',
|
|
86
|
+
},
|
|
87
|
+
schema: {
|
|
88
|
+
input: z.object({
|
|
89
|
+
message: z.string(),
|
|
90
|
+
}),
|
|
91
|
+
output: z.object({
|
|
92
|
+
response: z.string(),
|
|
93
|
+
}),
|
|
94
|
+
},
|
|
95
|
+
handler: async (ctx: AgentContext, input) => {
|
|
96
|
+
return { response: `Processed: ${input.message}` };
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
export default agent;
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Adding API Routes
|
|
104
|
+
|
|
105
|
+
Create custom routes in `src/apis/` or add routes to an agent folder:
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
// src/agents/my-agent/route.ts
|
|
109
|
+
import { createRouter } from '@agentuity/server';
|
|
110
|
+
import { zValidator } from '@hono/zod-validator';
|
|
111
|
+
import agent from './agent';
|
|
112
|
+
|
|
113
|
+
const router = createRouter();
|
|
114
|
+
|
|
115
|
+
router.get('/', async (c) => {
|
|
116
|
+
const result = await c.agent.myAgent.run({ message: 'Hello!' });
|
|
117
|
+
return c.json(result);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
router.post('/', zValidator('json', agent.inputSchema!), async (c) => {
|
|
121
|
+
const data = c.req.valid('json');
|
|
122
|
+
const result = await c.agent.myAgent.run(data);
|
|
123
|
+
return c.json(result);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
export default router;
|
|
127
|
+
```
|
|
47
128
|
|
|
48
129
|
## Learn More
|
|
49
130
|
|
|
50
131
|
- [Agentuity Documentation](https://agentuity.dev)
|
|
51
132
|
- [Bun Documentation](https://bun.sh/docs)
|
|
133
|
+
- [Hono Documentation](https://hono.dev/)
|
|
134
|
+
- [Zod Documentation](https://zod.dev/)
|
|
52
135
|
|
|
53
|
-
##
|
|
136
|
+
## Requirements
|
|
137
|
+
|
|
138
|
+
- [Bun](https://bun.sh/) v1.0 or higher
|
|
139
|
+
- TypeScript 5+
|
|
140
|
+
|
|
141
|
+
## License
|
|
54
142
|
|
|
55
|
-
|
|
56
|
-
2. Add new routes in `src/apis/`
|
|
57
|
-
3. Customize the web interface in `src/web/app.tsx`
|
|
58
|
-
4. Deploy your application to production
|
|
143
|
+
MIT
|