sonamu 0.8.24 → 0.8.25
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/dist/api/__tests__/config.test.js +189 -0
- package/dist/api/config.d.ts.map +1 -1
- package/dist/api/config.js +7 -2
- package/dist/api/sonamu.d.ts.map +1 -1
- package/dist/api/sonamu.js +14 -10
- package/dist/auth/index.d.ts +1 -0
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +2 -1
- package/dist/auth/knex-adapter.d.ts +23 -0
- package/dist/auth/knex-adapter.d.ts.map +1 -0
- package/dist/auth/knex-adapter.js +159 -0
- package/dist/auth/plugins/wrappers/admin.d.ts +2 -2
- package/dist/bin/__tests__/ts-loader-register.test.js +45 -0
- package/dist/bin/cli.js +47 -9
- package/dist/bin/ts-loader-register.js +3 -29
- package/dist/bin/ts-loader-registration.d.ts +2 -0
- package/dist/bin/ts-loader-registration.d.ts.map +1 -0
- package/dist/bin/ts-loader-registration.js +42 -0
- package/package.json +4 -4
- package/src/api/__tests__/config.test.ts +225 -0
- package/src/api/config.ts +10 -4
- package/src/api/sonamu.ts +16 -13
- package/src/auth/index.ts +1 -0
- package/src/auth/knex-adapter.ts +207 -0
- package/src/bin/__tests__/ts-loader-register.test.ts +62 -0
- package/src/bin/cli.ts +52 -9
- package/src/bin/ts-loader-register.ts +2 -32
- package/src/bin/ts-loader-registration.ts +55 -0
- package/src/skills/commands/sonamu-skills.md +20 -0
- package/src/skills/sonamu/SKILL.md +136 -137
- package/src/skills/sonamu/ai-agents.md +69 -69
- package/src/skills/sonamu/api.md +147 -147
- package/src/skills/sonamu/auth-migration.md +220 -220
- package/src/skills/sonamu/auth-plugins.md +83 -83
- package/src/skills/sonamu/auth.md +106 -106
- package/src/skills/sonamu/cdd.md +65 -200
- package/src/skills/sonamu/cone.md +138 -138
- package/src/skills/sonamu/config.md +191 -191
- package/src/skills/sonamu/create-sonamu.md +66 -66
- package/src/skills/sonamu/database.md +158 -158
- package/src/skills/sonamu/entity-basic.md +292 -293
- package/src/skills/sonamu/entity-relations.md +246 -246
- package/src/skills/sonamu/entity-validation-checklist.md +124 -124
- package/src/skills/sonamu/fixture-cli.md +231 -231
- package/src/skills/sonamu/framework-change.md +37 -37
- package/src/skills/sonamu/frontend.md +223 -223
- package/src/skills/sonamu/i18n.md +82 -82
- package/src/skills/sonamu/migration.md +77 -77
- package/src/skills/sonamu/model.md +222 -222
- package/src/skills/sonamu/naite.md +86 -86
- package/src/skills/sonamu/project-init.md +228 -228
- package/src/skills/sonamu/puri.md +122 -122
- package/src/skills/sonamu/scaffolding.md +154 -154
- package/src/skills/sonamu/skill-contribution.md +124 -124
- package/src/skills/sonamu/subset.md +46 -46
- package/src/skills/sonamu/tasks.md +82 -82
- package/src/skills/sonamu/testing-devrunner.md +147 -147
- package/src/skills/sonamu/testing.md +673 -673
- package/src/skills/sonamu/upsert.md +79 -79
- package/src/skills/sonamu/vector.md +67 -67
- package/src/skills/sonamu/workflow.md +0 -317
|
@@ -1,196 +1,195 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: sonamu
|
|
3
|
-
description: Sonamu TypeScript
|
|
3
|
+
description: Sonamu TypeScript full-stack framework development guide. Entity, Model, API, testing, and frontend integration. Use when developing with Sonamu framework.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Sonamu Framework Skills
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
Claude Code skill for developing projects with the Sonamu framework.
|
|
9
9
|
|
|
10
|
-
## CRITICAL:
|
|
10
|
+
## CRITICAL: Ask one question at a time
|
|
11
11
|
|
|
12
12
|
**MUST ask questions one at a time. NEVER overwhelm users with multiple questions.**
|
|
13
13
|
|
|
14
14
|
### MUST DO
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
15
|
+
- One question → wait for user response → next question
|
|
16
|
+
- Keep questions concise
|
|
17
|
+
- Present choices clearly when options are available
|
|
18
18
|
|
|
19
19
|
### NEVER DO
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
-
|
|
20
|
+
- List multiple questions at once
|
|
21
|
+
- Ask questions alongside long explanations
|
|
22
|
+
- Output a checklist of confirmation items all at once
|
|
23
23
|
|
|
24
24
|
---
|
|
25
25
|
|
|
26
|
-
##
|
|
26
|
+
## Development Flow
|
|
27
27
|
|
|
28
28
|
```
|
|
29
|
-
PHASE 0:
|
|
30
|
-
PHASE 1:
|
|
31
|
-
PHASE 2:
|
|
32
|
-
PHASE 3:
|
|
33
|
-
PHASE 4:
|
|
34
|
-
PHASE 5: Fixture
|
|
35
|
-
PHASE 6: Frontend
|
|
29
|
+
PHASE 0: Project creation and initial setup (create project → identify domains → auth generate → Users sequence setup)
|
|
30
|
+
PHASE 1: Domain logic documentation (write contract/{domain}/*.contract.md per domain → user confirmation)
|
|
31
|
+
PHASE 2: Entity design (design with user confirmation)
|
|
32
|
+
PHASE 3: Entity creation and migration (entity.json + migration + cone + scaffolding)
|
|
33
|
+
PHASE 4: Testing and API implementation (contract → Claim → AC → implement, repeat)
|
|
34
|
+
PHASE 5: Fixture generation (generate with LLM after user approval)
|
|
35
|
+
PHASE 6: Frontend development (proceed in batches with user confirmation)
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
**Full details:** see `.claude/workflow/project_init.md`
|
|
39
39
|
|
|
40
|
-
###
|
|
40
|
+
### Starting Point Determination
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
**Begin from the PHASE that matches the user's instruction.** Do not always start from PHASE 0.
|
|
43
43
|
|
|
44
|
-
|
|
|
45
|
-
|
|
46
|
-
| "
|
|
47
|
-
| "contract
|
|
48
|
-
| "
|
|
49
|
-
| "
|
|
50
|
-
| "
|
|
51
|
-
| "
|
|
44
|
+
| User instruction | Starting PHASE | Prerequisites to verify |
|
|
45
|
+
|-----------------|----------------|------------------------|
|
|
46
|
+
| "Create a new project" | PHASE 0 | — |
|
|
47
|
+
| "Write contract" / "Analyze domain" | PHASE 1 | Domain list identified |
|
|
48
|
+
| "Add entity" / "Create entity" | PHASE 2 | Project exists, dev server running, read contract/**/*.contract.md, PHASE 1 complete |
|
|
49
|
+
| "Write tests" / "Implement API" | PHASE 4 | entity.json exists, migration complete, scaffolding complete |
|
|
50
|
+
| "Generate fixtures" | PHASE 5 | Tests passing, cone.note exists |
|
|
51
|
+
| "Develop frontend" | PHASE 6 | API implementation complete, contract/**/*.contract.md reviewed |
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
1. `contract/**/*.contract.md`
|
|
55
|
-
2.
|
|
56
|
-
3.
|
|
57
|
-
4.
|
|
53
|
+
**Mid-entry rules:**
|
|
54
|
+
1. If `contract/**/*.contract.md` and `skills/project/architecture.md` exist, read them first.
|
|
55
|
+
2. Verify prerequisites for the target PHASE.
|
|
56
|
+
3. If prerequisites are not met, inform the user and begin from the required step.
|
|
57
|
+
4. Within a PHASE, follow the numbered steps in `.claude/workflow/project_init.md` in order. Do not skip any step or merge steps on your own judgment.
|
|
58
58
|
|
|
59
59
|
---
|
|
60
60
|
|
|
61
|
-
##
|
|
61
|
+
## Project Document System
|
|
62
62
|
|
|
63
|
-
### CRITICAL:
|
|
63
|
+
### CRITICAL: Read these before starting any task
|
|
64
64
|
|
|
65
|
-
|
|
65
|
+
**Before starting any project task, always read the following documents.**
|
|
66
66
|
|
|
67
67
|
```
|
|
68
68
|
contract/
|
|
69
69
|
└── {domain}/
|
|
70
|
-
└── {domain}.contract.md # PHASE 1:
|
|
70
|
+
└── {domain}.contract.md # PHASE 1: domain rules + decision rationale (permanent; update alongside code changes)
|
|
71
71
|
|
|
72
72
|
.claude/skills/project/
|
|
73
|
-
└── architecture.md #
|
|
73
|
+
└── architecture.md # entity design + system architecture
|
|
74
74
|
|
|
75
|
-
tmp/claims/ #
|
|
75
|
+
tmp/claims/ # in-progress Claim YAML (discard after completion)
|
|
76
76
|
```
|
|
77
77
|
|
|
78
|
-
**
|
|
78
|
+
**Code is the ground truth.** `*.contract.md` records the rationale behind code decisions — it is not a spec that precedes the code. When code and `*.contract.md` conflict, the code takes precedence.
|
|
79
79
|
|
|
80
|
-
###
|
|
80
|
+
### Domain `*.contract.md`
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
Documents domain rules in a cohesive form and captures decision rationale that cannot be inferred from code alone.
|
|
83
83
|
|
|
84
84
|
```markdown
|
|
85
|
-
# {
|
|
85
|
+
# {Domain} Business Logic
|
|
86
86
|
|
|
87
|
-
##
|
|
88
|
-
-
|
|
89
|
-
-
|
|
87
|
+
## Rules
|
|
88
|
+
- Refunds allowed only within 7 days of payment [Rationale: PG provider policy]
|
|
89
|
+
- Order status transitions: pending → confirmed → shipped → completed
|
|
90
90
|
|
|
91
|
-
##
|
|
91
|
+
## Workflow
|
|
92
92
|
1. ...
|
|
93
93
|
```
|
|
94
94
|
|
|
95
|
-
|
|
96
|
-
-
|
|
97
|
-
-
|
|
95
|
+
**Two development paths:**
|
|
96
|
+
- **New**: write `*.contract.md` → Claim → AC (test name) → implement (TDD)
|
|
97
|
+
- **Change**: modify code → register Claim → verify/update `*.contract.md` (record change rationale)
|
|
98
98
|
|
|
99
|
-
|
|
100
|
-
-
|
|
101
|
-
-
|
|
99
|
+
**Update rules:**
|
|
100
|
+
- When code changes, check affected domain rules and update `*.contract.md` together
|
|
101
|
+
- Record the reason and decision rationale — this keeps `*.contract.md` alive
|
|
102
102
|
|
|
103
103
|
### architecture.md
|
|
104
104
|
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
**When:** designing entities or discussing system architecture
|
|
106
|
+
**Content:** entity structure and relationships, database schema, system component structure
|
|
107
107
|
|
|
108
|
-
###
|
|
108
|
+
### Safe after compacting
|
|
109
109
|
|
|
110
|
-
|
|
110
|
+
Documents are persisted as files, so project context is preserved even when the conversation is compacted.
|
|
111
111
|
|
|
112
112
|
---
|
|
113
113
|
|
|
114
|
-
## Skills
|
|
115
|
-
|
|
116
|
-
| Skill |
|
|
117
|
-
|
|
118
|
-
|
|
|
119
|
-
|
|
|
120
|
-
|
|
|
121
|
-
|
|
|
122
|
-
|
|
|
123
|
-
|
|
|
124
|
-
| Entity
|
|
125
|
-
| Entity
|
|
126
|
-
|
|
|
127
|
-
|
|
|
128
|
-
|
|
|
129
|
-
|
|
|
130
|
-
|
|
|
131
|
-
|
|
|
132
|
-
|
|
|
133
|
-
|
|
|
134
|
-
| **
|
|
135
|
-
| **
|
|
136
|
-
| **
|
|
137
|
-
|
|
|
138
|
-
|
|
|
139
|
-
| Auth | `auth.md` |
|
|
140
|
-
| Auth
|
|
141
|
-
| **
|
|
142
|
-
|
|
|
143
|
-
|
|
|
144
|
-
| **
|
|
145
|
-
| **
|
|
146
|
-
|
|
|
147
|
-
| **Framework 변경 판단** | `framework-change.md` | **프레임워크 수정 vs. 프로젝트 우회 판단 기준. @upload 파라미터 패턴** |
|
|
114
|
+
## Skills List
|
|
115
|
+
|
|
116
|
+
| Skill | File | Purpose |
|
|
117
|
+
|-------|------|---------|
|
|
118
|
+
| **CDD (AC+Claim-based development)** | `cdd.md` | **`*.contract.md` (domain rules), AC (test names), Claim (work instructions) — 3-artifact system** |
|
|
119
|
+
| Project creation | `create-sonamu.md` | create-sonamu CLI options |
|
|
120
|
+
| Project initialization | `project-init.md` | Project creation flow and conversation guide |
|
|
121
|
+
| Project configuration | `config.md` | .env, sonamu.config.ts settings |
|
|
122
|
+
| Database | `database.md` | DB setup, port conflict resolution, 3-Tier structure |
|
|
123
|
+
| Entity validation | `entity-validation-checklist.md` | Step-by-step entity creation checklist |
|
|
124
|
+
| Entity basics | `entity-basic.md` | Entity JSON structure, field types |
|
|
125
|
+
| Entity relations | `entity-relations.md` | BelongsToOne, HasMany, ManyToMany, FK code patterns |
|
|
126
|
+
| Subset | `subset.md` | Response field scope definition |
|
|
127
|
+
| Model | `model.md` | BaseModelClass, CRUD patterns |
|
|
128
|
+
| API | `api.md` | @api decorator |
|
|
129
|
+
| Puri | `puri.md` | SQL query builder |
|
|
130
|
+
| i18n | `i18n.md` | Internationalization, SD functions |
|
|
131
|
+
| Upsert | `upsert.md` | Batch saving of relation data |
|
|
132
|
+
| Testing | `testing.md` | Vitest tests (test/testAs), fixture generation tips |
|
|
133
|
+
| **DevRunner** | `testing-devrunner.md` | **sonamu test execution, HMR integration, parallel tests, sonamu.config.ts test settings** |
|
|
134
|
+
| **Naite** | `naite.md` | **Naite.t()/get() tracing system, chaining filters, trace CLI output** |
|
|
135
|
+
| **Cone** | `cone.md` | **Cone metadata generation and management (LLM/template)** |
|
|
136
|
+
| **Fixture CLI** | `fixture-cli.md` | **fixture gen/fetch/explore commands, 3-Tier DB usage** |
|
|
137
|
+
| Migration | `migration.md` | DB schema migration, PK type changes |
|
|
138
|
+
| Auth | `auth.md` | better-auth system (auto entity generation, Guards, Context) |
|
|
139
|
+
| Auth Migration | `auth-migration.md` | User.id type changes for external auth (e.g., better-auth) |
|
|
140
|
+
| **Auth Plugins** | `auth-plugins.md` | **better-auth plugin wrappers (admin, organization, 2fa, passkey, etc. — 10 types), snake_case mapping** |
|
|
141
|
+
| **Vector search** | `vector.md` | **pgvector embeddings (Voyage AI/OpenAI), chunking, hybrid search** |
|
|
142
|
+
| Puri query builder | `puri.md` | SELECT, WHERE, JOIN, FTS, pg_trgm fuzzy search, pgvector |
|
|
143
|
+
| **AI Agents** | `ai-agents.md` | **BaseAgentClass, @tools decorator, ToolLoopAgent, AsyncLocalStorage state** |
|
|
144
|
+
| **Tasks** | `tasks.md` | **Background workflows, cron scheduling, durable steps, retry policies** |
|
|
145
|
+
| **Skill contribution** | `skill-contribution.md` | **Troubleshooting → skill contribution workflow (matching, decision, format, approval)** |
|
|
146
|
+
| **Framework change** | `framework-change.md` | **Criteria for framework fix vs. project workaround. @upload parameter pattern** |
|
|
148
147
|
| Frontend | `frontend.md` | Service, TanStack Query |
|
|
149
|
-
| Scaffolding | `scaffolding.md` | UI
|
|
150
|
-
|
|
151
|
-
##
|
|
152
|
-
|
|
153
|
-
**CRITICAL:
|
|
154
|
-
|
|
155
|
-
|
|
|
156
|
-
|
|
157
|
-
|
|
|
158
|
-
|
|
|
159
|
-
|
|
|
160
|
-
|
|
|
161
|
-
| Sonamu
|
|
162
|
-
| DB
|
|
163
|
-
| **3-Tier DB
|
|
164
|
-
| **Cone
|
|
165
|
-
| Entity
|
|
166
|
-
|
|
|
167
|
-
| **BelongsToOne FK
|
|
168
|
-
| API
|
|
169
|
-
|
|
|
170
|
-
| API
|
|
171
|
-
|
|
|
172
|
-
|
|
|
173
|
-
|
|
|
174
|
-
| **Naite
|
|
175
|
-
| **Fixture
|
|
176
|
-
|
|
|
177
|
-
| DB
|
|
178
|
-
|
|
|
179
|
-
| PK
|
|
180
|
-
|
|
|
181
|
-
|
|
|
182
|
-
|
|
|
183
|
-
| Scaffolding
|
|
184
|
-
|
|
|
148
|
+
| Scaffolding | `scaffolding.md` | Resolving UI scaffolding errors |
|
|
149
|
+
|
|
150
|
+
## Task-to-Skill Reference
|
|
151
|
+
|
|
152
|
+
**CRITICAL: When building a new system from scratch, start with `.claude/workflow/project_init.md`!**
|
|
153
|
+
|
|
154
|
+
| Task | Reference Skill |
|
|
155
|
+
|------|----------------|
|
|
156
|
+
| **Build an entire system from scratch** | **`.claude/workflow/project_init.md` (7-phase master guide)** |
|
|
157
|
+
| **Domain logic documentation / AC+Claim-based development** | **cdd.md** |
|
|
158
|
+
| Project creation | create-sonamu, project-init |
|
|
159
|
+
| Project configuration | config |
|
|
160
|
+
| Sonamu local dev setup | config |
|
|
161
|
+
| DB setup / port conflict | database, config |
|
|
162
|
+
| **3-Tier DB structure** | **database, fixture-cli** |
|
|
163
|
+
| **Cone metadata generation/management** | **cone** |
|
|
164
|
+
| Entity / field definition | entity-basic |
|
|
165
|
+
| Relationship setup | entity-relations |
|
|
166
|
+
| **BelongsToOne FK code usage** | **entity-relations** |
|
|
167
|
+
| API response field composition | subset |
|
|
168
|
+
| Data query / save logic | model, puri |
|
|
169
|
+
| API endpoints | api |
|
|
170
|
+
| Batch saving of relation data | upsert |
|
|
171
|
+
| Writing tests | testing |
|
|
172
|
+
| **Running tests (sonamu test)** | **testing-devrunner** |
|
|
173
|
+
| **Naite tracing / debugging** | **naite** |
|
|
174
|
+
| **Fixture data generation/management** | **fixture-cli** |
|
|
175
|
+
| **Test data generation tips** | **testing (Fixture data generation tips), fixture-cli (practical tips)** |
|
|
176
|
+
| DB schema changes | migration |
|
|
177
|
+
| **Auth setup (auth generate, Guards, Context)** | **auth** |
|
|
178
|
+
| PK type changes (better-auth, etc.) | auth-migration |
|
|
179
|
+
| **Adding auth plugins** | **auth-plugins** |
|
|
180
|
+
| Frontend development | frontend |
|
|
181
|
+
| Internationalization / translation | i18n |
|
|
182
|
+
| Scaffolding errors | scaffolding |
|
|
183
|
+
| **Vector search / embeddings** | **vector** |
|
|
185
184
|
| **pg_trgm Fuzzy Search** | **puri, entity-basic** |
|
|
186
|
-
| **AI Agent
|
|
187
|
-
|
|
|
188
|
-
|
|
|
189
|
-
|
|
|
185
|
+
| **AI Agent development** | **ai-agents** |
|
|
186
|
+
| **Background jobs / scheduling** | **tasks** |
|
|
187
|
+
| **Troubleshooting → skill contribution** | **skill-contribution** |
|
|
188
|
+
| **Framework bug / constraint response** | **framework-change** |
|
|
190
189
|
|
|
191
|
-
##
|
|
190
|
+
## Command Execution Path
|
|
192
191
|
|
|
193
|
-
|
|
192
|
+
All `pnpm` commands are run from the **`packages/api`** directory.
|
|
194
193
|
|
|
195
194
|
```bash
|
|
196
195
|
cd packages/api
|
|
@@ -199,9 +198,9 @@ pnpm dev
|
|
|
199
198
|
pnpm sonamu migrate run
|
|
200
199
|
```
|
|
201
200
|
|
|
202
|
-
##
|
|
201
|
+
## Source Code References
|
|
203
202
|
|
|
204
|
-
- Sonamu
|
|
205
|
-
-
|
|
206
|
-
-
|
|
203
|
+
- Sonamu framework: `sonamu/modules/sonamu/`
|
|
204
|
+
- Example project: `sonamu/examples/miomock/`
|
|
205
|
+
- Official docs: `sonamu/modules/docs/`
|
|
207
206
|
- create-sonamu: `sonamu/modules/create-sonamu/`
|
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: sonamu-ai-agents
|
|
3
|
-
description: AI Agent
|
|
3
|
+
description: AI Agent framework. Extend BaseAgentClass, define tools with @tools decorator, ToolLoopAgent integration, AsyncLocalStorage-based state management. Use when building AI agents with tool-use capabilities.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
# AI Agent
|
|
6
|
+
# AI Agent Guide
|
|
7
7
|
|
|
8
|
-
Sonamu
|
|
8
|
+
Sonamu provides a framework that wraps Vercel AI SDK's `ToolLoopAgent` to build class-based AI Agents.
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
**Source code:** `modules/sonamu/src/ai/agents/`
|
|
11
11
|
|
|
12
12
|
---
|
|
13
13
|
|
|
14
|
-
##
|
|
14
|
+
## Structure
|
|
15
15
|
|
|
16
|
-
|
|
|
16
|
+
| File | Role |
|
|
17
17
|
|------|------|
|
|
18
|
-
| `agent.ts` | `BaseAgentClass`, `tools`
|
|
19
|
-
| `types.ts` | `AgentConfig`, `ToolDecoratorOptions`, `RegisteredToolDefinition
|
|
18
|
+
| `agent.ts` | `BaseAgentClass`, `tools` decorator |
|
|
19
|
+
| `types.ts` | `AgentConfig`, `ToolDecoratorOptions`, `RegisteredToolDefinition`, etc. |
|
|
20
20
|
|
|
21
21
|
---
|
|
22
22
|
|
|
23
23
|
## BaseAgentClass
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
The base class for Agents. Extend it to create a custom Agent.
|
|
26
26
|
|
|
27
27
|
```typescript
|
|
28
28
|
import { BaseAgentClass, tools } from "sonamu/ai/agents";
|
|
@@ -30,11 +30,11 @@ import { z } from "zod/v4";
|
|
|
30
30
|
|
|
31
31
|
class MyAgentClass extends BaseAgentClass<{ count: number }> {
|
|
32
32
|
constructor() {
|
|
33
|
-
super("MyAgent"); // agentName (
|
|
33
|
+
super("MyAgent"); // agentName (used as logger category)
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
@tools({
|
|
37
|
-
description: "
|
|
37
|
+
description: "Adds two numbers",
|
|
38
38
|
schema: {
|
|
39
39
|
input: z.object({ a: z.number(), b: z.number() }),
|
|
40
40
|
output: z.object({ result: z.number() }),
|
|
@@ -48,54 +48,54 @@ class MyAgentClass extends BaseAgentClass<{ count: number }> {
|
|
|
48
48
|
export const MyAgent = new MyAgentClass();
|
|
49
49
|
```
|
|
50
50
|
|
|
51
|
-
###
|
|
51
|
+
### Key Features
|
|
52
52
|
|
|
53
|
-
|
|
|
53
|
+
| Feature | Description |
|
|
54
54
|
|------|------|
|
|
55
|
-
| `this.logger` | LogTape
|
|
56
|
-
| `this.store` | AsyncLocalStorage
|
|
57
|
-
| `this.tools` |
|
|
58
|
-
| `this.use()` | Agent
|
|
55
|
+
| `this.logger` | LogTape logger (agent category) |
|
|
56
|
+
| `this.store` | AsyncLocalStorage-based state access |
|
|
57
|
+
| `this.tools` | Registered toolset (ToolSet) |
|
|
58
|
+
| `this.use()` | Run the Agent (ALS context + ToolLoopAgent) |
|
|
59
59
|
|
|
60
60
|
---
|
|
61
61
|
|
|
62
|
-
## @tools
|
|
62
|
+
## @tools Decorator
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
Registers a method as an AI tool. Define input/output using Zod v4 schema.
|
|
65
65
|
|
|
66
66
|
```typescript
|
|
67
67
|
@tools({
|
|
68
|
-
name?: string, //
|
|
69
|
-
description?: string, //
|
|
68
|
+
name?: string, // Tool name (default: "className.methodName" format)
|
|
69
|
+
description?: string, // Description shown to the LLM
|
|
70
70
|
schema: {
|
|
71
|
-
input: z.ZodType, //
|
|
72
|
-
output?: z.ZodType, //
|
|
71
|
+
input: z.ZodType, // Input schema (required)
|
|
72
|
+
output?: z.ZodType, // Output schema (optional)
|
|
73
73
|
},
|
|
74
|
-
needsApproval?: boolean | function, //
|
|
75
|
-
toModelOutput?: function, //
|
|
76
|
-
providerOptions?: ProviderOptions, //
|
|
74
|
+
needsApproval?: boolean | function, // Whether user approval is required
|
|
75
|
+
toModelOutput?: function, // Transform output returned to the model
|
|
76
|
+
providerOptions?: ProviderOptions, // Provider-specific options
|
|
77
77
|
})
|
|
78
78
|
```
|
|
79
79
|
|
|
80
|
-
###
|
|
80
|
+
### Automatic Name Generation Rule
|
|
81
81
|
|
|
82
|
-
`name
|
|
82
|
+
If `name` is omitted, it is auto-generated as `{ModelName(camelCase)}.{methodName(camelCase)}`.
|
|
83
83
|
|
|
84
84
|
```typescript
|
|
85
85
|
class SearchAgentClass extends BaseAgentClass<...> {
|
|
86
86
|
@tools({ ... })
|
|
87
87
|
async findDocuments(input: ...) { ... }
|
|
88
|
-
// →
|
|
88
|
+
// → Tool name: "searchAgent.findDocuments"
|
|
89
89
|
}
|
|
90
90
|
```
|
|
91
91
|
|
|
92
|
-
|
|
92
|
+
The suffixes `Class`, `Model`, and `Frame` are automatically stripped from the class name.
|
|
93
93
|
|
|
94
94
|
---
|
|
95
95
|
|
|
96
|
-
## Agent
|
|
96
|
+
## Running an Agent (use)
|
|
97
97
|
|
|
98
|
-
`use()`
|
|
98
|
+
Run the Agent with the `use()` method. ToolLoopAgent operates within the AsyncLocalStorage context.
|
|
99
99
|
|
|
100
100
|
```typescript
|
|
101
101
|
import { anthropic } from "@ai-sdk/anthropic";
|
|
@@ -104,64 +104,64 @@ const result = await MyAgent.use(
|
|
|
104
104
|
// AgentConfig
|
|
105
105
|
{
|
|
106
106
|
model: anthropic("claude-sonnet-4-5-20250514"),
|
|
107
|
-
instructions: "
|
|
107
|
+
instructions: "You are a math assistant.",
|
|
108
108
|
toolChoice: "auto", // "auto" | "none" | "required"
|
|
109
109
|
maxOutputTokens: 1000,
|
|
110
110
|
temperature: 0.7,
|
|
111
111
|
},
|
|
112
|
-
//
|
|
112
|
+
// Initial state (stored in AsyncLocalStorage)
|
|
113
113
|
{ count: 0 },
|
|
114
|
-
//
|
|
114
|
+
// Callback (receives Agent instance)
|
|
115
115
|
async (agent) => {
|
|
116
|
-
// agent
|
|
117
|
-
// Vercel AI SDK
|
|
116
|
+
// agent is a ToolLoopAgent instance
|
|
117
|
+
// Use Vercel AI SDK's agent API
|
|
118
118
|
return agent;
|
|
119
119
|
},
|
|
120
120
|
);
|
|
121
121
|
```
|
|
122
122
|
|
|
123
|
-
### AgentConfig
|
|
123
|
+
### AgentConfig Options
|
|
124
124
|
|
|
125
|
-
|
|
|
125
|
+
| Option | Type | Description |
|
|
126
126
|
|------|------|------|
|
|
127
|
-
| `model` | `LanguageModel` | AI SDK
|
|
128
|
-
| `instructions` | `string` |
|
|
129
|
-
| `toolChoice` | `"auto" \| "none" \| "required"` |
|
|
130
|
-
| `stopWhen` | `StopCondition` |
|
|
131
|
-
| `activeTools` | `string[]` |
|
|
132
|
-
| `maxOutputTokens` | `number` |
|
|
133
|
-
| `temperature` | `number` |
|
|
134
|
-
| `topP` / `topK` | `number` |
|
|
135
|
-
| `presencePenalty` / `frequencyPenalty` | `number` |
|
|
136
|
-
| `seed` | `number` |
|
|
137
|
-
| `stopSequences` | `string[]` |
|
|
138
|
-
| `providerOptions` | `ProviderOptions` |
|
|
139
|
-
| `headers` | `Record<string, string>` |
|
|
127
|
+
| `model` | `LanguageModel` | AI SDK model (required) |
|
|
128
|
+
| `instructions` | `string` | System prompt |
|
|
129
|
+
| `toolChoice` | `"auto" \| "none" \| "required"` | Tool selection strategy |
|
|
130
|
+
| `stopWhen` | `StopCondition` | Stop condition |
|
|
131
|
+
| `activeTools` | `string[]` | List of tool names to activate |
|
|
132
|
+
| `maxOutputTokens` | `number` | Maximum output tokens |
|
|
133
|
+
| `temperature` | `number` | Temperature |
|
|
134
|
+
| `topP` / `topK` | `number` | Sampling parameters |
|
|
135
|
+
| `presencePenalty` / `frequencyPenalty` | `number` | Penalties |
|
|
136
|
+
| `seed` | `number` | Seed for reproducibility |
|
|
137
|
+
| `stopSequences` | `string[]` | Generation stop sequences |
|
|
138
|
+
| `providerOptions` | `ProviderOptions` | Additional provider-specific options |
|
|
139
|
+
| `headers` | `Record<string, string>` | Custom HTTP headers |
|
|
140
140
|
|
|
141
141
|
---
|
|
142
142
|
|
|
143
|
-
##
|
|
143
|
+
## State Management (AsyncLocalStorage)
|
|
144
144
|
|
|
145
|
-
`BaseAgentClass
|
|
145
|
+
`BaseAgentClass` defines the state type with the generic `TStore`. When you pass the initial state to `use()`, it can be accessed via `this.store` during tool execution.
|
|
146
146
|
|
|
147
147
|
```typescript
|
|
148
148
|
class StatefulAgentClass extends BaseAgentClass<{ processedItems: string[] }> {
|
|
149
149
|
@tools({ ... })
|
|
150
150
|
async processItem(input: { item: string }) {
|
|
151
|
-
//
|
|
151
|
+
// Access state
|
|
152
152
|
this.store?.processedItems.push(input.item);
|
|
153
153
|
return { ok: true };
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
156
|
```
|
|
157
157
|
|
|
158
|
-
|
|
158
|
+
**Note:** `this.store` is `undefined` outside of a `use()` context.
|
|
159
159
|
|
|
160
160
|
---
|
|
161
161
|
|
|
162
|
-
##
|
|
162
|
+
## Tool Isolation
|
|
163
163
|
|
|
164
|
-
|
|
164
|
+
Tools for each Agent class are isolated per class. The `toolSet` getter filters by `def.from === this.constructor.name`.
|
|
165
165
|
|
|
166
166
|
```typescript
|
|
167
167
|
class AgentA extends BaseAgentClass<void> {
|
|
@@ -171,34 +171,34 @@ class AgentB extends BaseAgentClass<void> {
|
|
|
171
171
|
@tools({ ... }) async toolY() { ... }
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
-
// AgentA.tools → { toolX
|
|
175
|
-
// AgentB.tools → { toolY
|
|
174
|
+
// AgentA.tools → { contains only toolX }
|
|
175
|
+
// AgentB.tools → { contains only toolY }
|
|
176
176
|
```
|
|
177
177
|
|
|
178
178
|
---
|
|
179
179
|
|
|
180
|
-
##
|
|
180
|
+
## Logging
|
|
181
181
|
|
|
182
|
-
`this.logger
|
|
182
|
+
`this.logger` uses LogTape. The category is generated with `convertDomainToCategory(agentName, "agent")`.
|
|
183
183
|
|
|
184
|
-
|
|
184
|
+
Debug logs are automatically recorded on tool execution:
|
|
185
185
|
```
|
|
186
186
|
tools: {model}.{method} with args: {args}
|
|
187
187
|
```
|
|
188
188
|
|
|
189
189
|
---
|
|
190
190
|
|
|
191
|
-
##
|
|
191
|
+
## Related Packages
|
|
192
192
|
|
|
193
193
|
- `ai`: Vercel AI SDK (`ToolLoopAgent`, `Agent`, `ToolSet`)
|
|
194
194
|
- `@ai-sdk/provider-utils`: `tool()`, `Tool`, `ToolExecutionOptions`
|
|
195
|
-
- `zod/v4`:
|
|
196
|
-
- `@logtape/logtape`:
|
|
195
|
+
- `zod/v4`: Schema definitions
|
|
196
|
+
- `@logtape/logtape`: Logging
|
|
197
197
|
|
|
198
198
|
---
|
|
199
199
|
|
|
200
|
-
##
|
|
200
|
+
## References
|
|
201
201
|
|
|
202
|
-
-
|
|
202
|
+
- **Source code**: `modules/sonamu/src/ai/agents/`
|
|
203
203
|
- **Vercel AI SDK**: https://sdk.vercel.ai/docs
|
|
204
|
-
-
|
|
204
|
+
- **Vector search**: `vector.md`
|