archetype-engine 2.0.0
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/LICENSE +21 -0
- package/README.md +241 -0
- package/dist/src/ai/adapters/anthropic.d.ts +31 -0
- package/dist/src/ai/adapters/anthropic.d.ts.map +1 -0
- package/dist/src/ai/adapters/anthropic.js +75 -0
- package/dist/src/ai/adapters/openai.d.ts +33 -0
- package/dist/src/ai/adapters/openai.d.ts.map +1 -0
- package/dist/src/ai/adapters/openai.js +120 -0
- package/dist/src/ai/adapters/vercel.d.ts +434 -0
- package/dist/src/ai/adapters/vercel.d.ts.map +1 -0
- package/dist/src/ai/adapters/vercel.js +162 -0
- package/dist/src/ai/index.d.ts +492 -0
- package/dist/src/ai/index.d.ts.map +1 -0
- package/dist/src/ai/index.js +71 -0
- package/dist/src/ai/state.d.ts +13 -0
- package/dist/src/ai/state.d.ts.map +1 -0
- package/dist/src/ai/state.js +215 -0
- package/dist/src/ai/tools.d.ts +13 -0
- package/dist/src/ai/tools.d.ts.map +1 -0
- package/dist/src/ai/tools.js +257 -0
- package/dist/src/ai/types.d.ts +196 -0
- package/dist/src/ai/types.d.ts.map +1 -0
- package/dist/src/ai/types.js +9 -0
- package/dist/src/cli.d.ts +3 -0
- package/dist/src/cli.d.ts.map +1 -0
- package/dist/src/cli.js +540 -0
- package/dist/src/core/utils.d.ts +27 -0
- package/dist/src/core/utils.d.ts.map +1 -0
- package/dist/src/core/utils.js +56 -0
- package/dist/src/entity.d.ts +165 -0
- package/dist/src/entity.d.ts.map +1 -0
- package/dist/src/entity.js +108 -0
- package/dist/src/fields.d.ts +207 -0
- package/dist/src/fields.d.ts.map +1 -0
- package/dist/src/fields.js +291 -0
- package/dist/src/generators/erd-ir.d.ts +10 -0
- package/dist/src/generators/erd-ir.d.ts.map +1 -0
- package/dist/src/generators/erd-ir.js +119 -0
- package/dist/src/index.d.ts +51 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +101 -0
- package/dist/src/init/dependencies.d.ts +31 -0
- package/dist/src/init/dependencies.d.ts.map +1 -0
- package/dist/src/init/dependencies.js +101 -0
- package/dist/src/init/entity-templates.d.ts +42 -0
- package/dist/src/init/entity-templates.d.ts.map +1 -0
- package/dist/src/init/entity-templates.js +367 -0
- package/dist/src/init/index.d.ts +10 -0
- package/dist/src/init/index.d.ts.map +1 -0
- package/dist/src/init/index.js +250 -0
- package/dist/src/init/prompts.d.ts +11 -0
- package/dist/src/init/prompts.d.ts.map +1 -0
- package/dist/src/init/prompts.js +275 -0
- package/dist/src/init/templates.d.ts +24 -0
- package/dist/src/init/templates.d.ts.map +1 -0
- package/dist/src/init/templates.js +587 -0
- package/dist/src/json/index.d.ts +11 -0
- package/dist/src/json/index.d.ts.map +1 -0
- package/dist/src/json/index.js +26 -0
- package/dist/src/json/parser.d.ts +61 -0
- package/dist/src/json/parser.d.ts.map +1 -0
- package/dist/src/json/parser.js +309 -0
- package/dist/src/json/types.d.ts +275 -0
- package/dist/src/json/types.d.ts.map +1 -0
- package/dist/src/json/types.js +10 -0
- package/dist/src/manifest.d.ts +147 -0
- package/dist/src/manifest.d.ts.map +1 -0
- package/dist/src/manifest.js +104 -0
- package/dist/src/relations.d.ts +96 -0
- package/dist/src/relations.d.ts.map +1 -0
- package/dist/src/relations.js +108 -0
- package/dist/src/source.d.ts +93 -0
- package/dist/src/source.d.ts.map +1 -0
- package/dist/src/source.js +89 -0
- package/dist/src/template/context.d.ts +34 -0
- package/dist/src/template/context.d.ts.map +1 -0
- package/dist/src/template/context.js +31 -0
- package/dist/src/template/index.d.ts +6 -0
- package/dist/src/template/index.d.ts.map +1 -0
- package/dist/src/template/index.js +12 -0
- package/dist/src/template/registry.d.ts +18 -0
- package/dist/src/template/registry.d.ts.map +1 -0
- package/dist/src/template/registry.js +89 -0
- package/dist/src/template/runner.d.ts +9 -0
- package/dist/src/template/runner.d.ts.map +1 -0
- package/dist/src/template/runner.js +125 -0
- package/dist/src/template/types.d.ts +73 -0
- package/dist/src/template/types.d.ts.map +1 -0
- package/dist/src/template/types.js +3 -0
- package/dist/src/templates/nextjs-drizzle-trpc/generators/api.d.ts +22 -0
- package/dist/src/templates/nextjs-drizzle-trpc/generators/api.d.ts.map +1 -0
- package/dist/src/templates/nextjs-drizzle-trpc/generators/api.js +866 -0
- package/dist/src/templates/nextjs-drizzle-trpc/generators/auth.d.ts +20 -0
- package/dist/src/templates/nextjs-drizzle-trpc/generators/auth.d.ts.map +1 -0
- package/dist/src/templates/nextjs-drizzle-trpc/generators/auth.js +273 -0
- package/dist/src/templates/nextjs-drizzle-trpc/generators/crud-hooks.d.ts +22 -0
- package/dist/src/templates/nextjs-drizzle-trpc/generators/crud-hooks.d.ts.map +1 -0
- package/dist/src/templates/nextjs-drizzle-trpc/generators/crud-hooks.js +237 -0
- package/dist/src/templates/nextjs-drizzle-trpc/generators/hooks.d.ts +30 -0
- package/dist/src/templates/nextjs-drizzle-trpc/generators/hooks.d.ts.map +1 -0
- package/dist/src/templates/nextjs-drizzle-trpc/generators/hooks.js +345 -0
- package/dist/src/templates/nextjs-drizzle-trpc/generators/i18n.d.ts +25 -0
- package/dist/src/templates/nextjs-drizzle-trpc/generators/i18n.d.ts.map +1 -0
- package/dist/src/templates/nextjs-drizzle-trpc/generators/i18n.js +199 -0
- package/dist/src/templates/nextjs-drizzle-trpc/generators/index.d.ts +8 -0
- package/dist/src/templates/nextjs-drizzle-trpc/generators/index.d.ts.map +1 -0
- package/dist/src/templates/nextjs-drizzle-trpc/generators/index.js +18 -0
- package/dist/src/templates/nextjs-drizzle-trpc/generators/schema.d.ts +22 -0
- package/dist/src/templates/nextjs-drizzle-trpc/generators/schema.d.ts.map +1 -0
- package/dist/src/templates/nextjs-drizzle-trpc/generators/schema.js +270 -0
- package/dist/src/templates/nextjs-drizzle-trpc/generators/service.d.ts +23 -0
- package/dist/src/templates/nextjs-drizzle-trpc/generators/service.d.ts.map +1 -0
- package/dist/src/templates/nextjs-drizzle-trpc/generators/service.js +304 -0
- package/dist/src/templates/nextjs-drizzle-trpc/generators/validation.d.ts +21 -0
- package/dist/src/templates/nextjs-drizzle-trpc/generators/validation.d.ts.map +1 -0
- package/dist/src/templates/nextjs-drizzle-trpc/generators/validation.js +248 -0
- package/dist/src/templates/nextjs-drizzle-trpc/index.d.ts +30 -0
- package/dist/src/templates/nextjs-drizzle-trpc/index.d.ts.map +1 -0
- package/dist/src/templates/nextjs-drizzle-trpc/index.js +71 -0
- package/dist/src/validation/index.d.ts +71 -0
- package/dist/src/validation/index.d.ts.map +1 -0
- package/dist/src/validation/index.js +314 -0
- package/package.json +86 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Archetype Engine Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
<img width="1280" height="640" alt="image" src="https://github.com/user-attachments/assets/eb752f28-ae21-49e6-b0ff-8adc1f4c5cd5" />
|
|
2
|
+
|
|
3
|
+
# Archetype Engine
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/archetype-engine)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
**The missing backend layer for AI-generated frontends.**
|
|
9
|
+
|
|
10
|
+
Define entities in TypeScript. Get production-ready backends instantly.
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
const Product = defineEntity('Product', {
|
|
14
|
+
fields: {
|
|
15
|
+
name: text().required().min(1).max(200),
|
|
16
|
+
price: number().required().positive(),
|
|
17
|
+
stock: number().integer().min(0).default(0),
|
|
18
|
+
}
|
|
19
|
+
})
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Run `npx archetype generate` → get:
|
|
23
|
+
- ✅ **Drizzle ORM schemas** (type-safe database)
|
|
24
|
+
- ✅ **tRPC routers** (CRUD + pagination + filters)
|
|
25
|
+
- ✅ **Zod validation** (runtime safety)
|
|
26
|
+
- ✅ **React hooks** (useProduct, useCreateProduct, etc.)
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## Why use this?
|
|
31
|
+
|
|
32
|
+
| Tool | What it does | What you still write |
|
|
33
|
+
|------|--------------|---------------------|
|
|
34
|
+
| Prisma | Database schema → Types | API, validation, hooks |
|
|
35
|
+
| tRPC | Type-safe API | Schema, validation, CRUD |
|
|
36
|
+
| Zod | Validation schemas | Database, API, hooks |
|
|
37
|
+
| **Archetype** | **Schema → Everything** | Business logic only |
|
|
38
|
+
|
|
39
|
+
You're not replacing tools—you're **generating** the boilerplate.
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## Quick Start (2 minutes)
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
# 1. Create a new Next.js project
|
|
47
|
+
npx create-next-app@latest my-app && cd my-app
|
|
48
|
+
|
|
49
|
+
# 2. Install Archetype
|
|
50
|
+
npm install archetype-engine
|
|
51
|
+
|
|
52
|
+
# 3. Initialize with a template
|
|
53
|
+
npx archetype init
|
|
54
|
+
|
|
55
|
+
# Choose from:
|
|
56
|
+
# - SaaS Multi-Tenant (Workspace, Team, Member)
|
|
57
|
+
# - E-commerce (Product, Order, Customer)
|
|
58
|
+
# - Blog/CMS (Post, Author, Comment)
|
|
59
|
+
# - Task Management (Project, Task, Label)
|
|
60
|
+
|
|
61
|
+
# 4. Generate code
|
|
62
|
+
npx archetype generate
|
|
63
|
+
|
|
64
|
+
# 5. Push to database and run
|
|
65
|
+
npx drizzle-kit push
|
|
66
|
+
npm run dev
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
**🎉 Done!** You now have a fully functional backend with type-safe APIs.
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## What You Get
|
|
74
|
+
|
|
75
|
+
From a single entity definition, Archetype generates:
|
|
76
|
+
|
|
77
|
+
```
|
|
78
|
+
generated/
|
|
79
|
+
├── db/
|
|
80
|
+
│ └── schema.ts # Drizzle ORM tables (type-safe SQL)
|
|
81
|
+
├── schemas/
|
|
82
|
+
│ └── product.ts # Zod validation schemas
|
|
83
|
+
├── trpc/routers/
|
|
84
|
+
│ ├── product.ts # Full CRUD API:
|
|
85
|
+
│ │ # - list (with pagination, filters, search)
|
|
86
|
+
│ │ # - get (by ID)
|
|
87
|
+
│ │ # - create, createMany
|
|
88
|
+
│ │ # - update, updateMany
|
|
89
|
+
│ │ # - remove, removeMany
|
|
90
|
+
│ └── index.ts # Router aggregation
|
|
91
|
+
└── hooks/
|
|
92
|
+
└── useProduct.ts # React Query hooks:
|
|
93
|
+
# - useProducts(), useProduct(id)
|
|
94
|
+
# - useCreateProduct(), useUpdateProduct()
|
|
95
|
+
# - useRemoveProduct(), etc.
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
**15 lines of entity code → 400+ lines of production-ready backend.**
|
|
99
|
+
|
|
100
|
+
### Live Example
|
|
101
|
+
|
|
102
|
+
**Define once:**
|
|
103
|
+
```typescript
|
|
104
|
+
const Order = defineEntity('Order', {
|
|
105
|
+
fields: {
|
|
106
|
+
orderNumber: text().required().unique(),
|
|
107
|
+
status: enumField(['pending', 'paid', 'shipped'] as const),
|
|
108
|
+
total: number().required().positive(),
|
|
109
|
+
},
|
|
110
|
+
relations: {
|
|
111
|
+
customer: hasOne('Customer'),
|
|
112
|
+
items: hasMany('OrderItem'),
|
|
113
|
+
},
|
|
114
|
+
behaviors: {
|
|
115
|
+
timestamps: true,
|
|
116
|
+
},
|
|
117
|
+
protected: 'all', // Requires authentication
|
|
118
|
+
})
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
**Use immediately:**
|
|
122
|
+
```typescript
|
|
123
|
+
// In your React component
|
|
124
|
+
const { data: orders } = useOrders({
|
|
125
|
+
where: { status: 'pending' },
|
|
126
|
+
orderBy: { field: 'createdAt', direction: 'desc' }
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
const { mutate: createOrder } = useCreateOrder()
|
|
130
|
+
createOrder({
|
|
131
|
+
orderNumber: 'ORD-001',
|
|
132
|
+
status: 'pending',
|
|
133
|
+
total: 99.99
|
|
134
|
+
})
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
No API boilerplate. No manual validation. No CRUD repetition. Just works.
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## Features
|
|
142
|
+
|
|
143
|
+
- 🎯 **Type-Safe Everything** - Database ↔ API ↔ Frontend sync guaranteed
|
|
144
|
+
- 🚀 **Production-Ready Templates** - SaaS, E-commerce, Blog, Task Management
|
|
145
|
+
- 🔐 **Built-in Auth** - NextAuth v5 integration with multiple providers
|
|
146
|
+
- 🔍 **Smart Filtering** - Pagination, search, sorting out of the box
|
|
147
|
+
- 🪝 **Lifecycle Hooks** - Add business logic before/after CRUD operations
|
|
148
|
+
- 📊 **Auto ERD** - Visual database diagrams with `npx archetype view`
|
|
149
|
+
- 🌍 **i18n Ready** - Multi-language support for generated code
|
|
150
|
+
- ⚡ **Fast** - Generate 1000+ lines of code in seconds
|
|
151
|
+
|
|
152
|
+
## Use Cases
|
|
153
|
+
|
|
154
|
+
| Template | Perfect For | Entities Included |
|
|
155
|
+
|----------|-------------|-------------------|
|
|
156
|
+
| **SaaS Multi-Tenant** | Team collaboration apps | Workspace, Team, Member + roles |
|
|
157
|
+
| **E-commerce** | Online stores, marketplaces | Product, Customer, Order, OrderItem |
|
|
158
|
+
| **Blog/CMS** | Content platforms, news sites | Post, Author, Comment |
|
|
159
|
+
| **Task Management** | Todo apps, kanban boards | Project, Task, Label |
|
|
160
|
+
|
|
161
|
+
## Documentation
|
|
162
|
+
|
|
163
|
+
📚 **Full docs:** [archetype-engine.vercel.app](https://archetype-engine.vercel.app)
|
|
164
|
+
|
|
165
|
+
**Popular guides:**
|
|
166
|
+
- [Getting Started](https://archetype-engine.vercel.app/docs/getting-started) - 5-minute tutorial
|
|
167
|
+
- [Fields & Validation](https://archetype-engine.vercel.app/docs/fields) - text(), number(), date(), etc.
|
|
168
|
+
- [Relations](https://archetype-engine.vercel.app/docs/relations) - hasOne, hasMany, belongsToMany
|
|
169
|
+
- [Authentication](https://archetype-engine.vercel.app/docs/authentication) - Protect routes & entities
|
|
170
|
+
- [Filtering & Search](https://archetype-engine.vercel.app/docs/filtering) - Build admin panels
|
|
171
|
+
- [Lifecycle Hooks](https://archetype-engine.vercel.app/docs/hooks) - Custom business logic
|
|
172
|
+
- [AI Integration](https://archetype-engine.vercel.app/docs/ai-module) - Build AI app builders
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## Why Archetype?
|
|
177
|
+
|
|
178
|
+
### The Problem: AI Tools Generate Incomplete Backends
|
|
179
|
+
|
|
180
|
+
Tools like **v0.dev**, **Bolt.new**, and **Cursor** generate beautiful UIs but:
|
|
181
|
+
- ❌ Hardcoded mock data
|
|
182
|
+
- ❌ No database integration
|
|
183
|
+
- ❌ No type safety
|
|
184
|
+
- ❌ No production-ready APIs
|
|
185
|
+
|
|
186
|
+
You get a gorgeous frontend that doesn't connect to anything real.
|
|
187
|
+
|
|
188
|
+
### The Solution: Archetype Completes the Stack
|
|
189
|
+
|
|
190
|
+
Archetype generates the **missing backend layer**:
|
|
191
|
+
- ✅ Real database schemas (Drizzle ORM)
|
|
192
|
+
- ✅ Type-safe APIs (tRPC)
|
|
193
|
+
- ✅ Runtime validation (Zod)
|
|
194
|
+
- ✅ React hooks for data fetching
|
|
195
|
+
|
|
196
|
+
**Use case:** Generate UI with v0 → Add backend with Archetype → Deploy to production.
|
|
197
|
+
|
|
198
|
+
---
|
|
199
|
+
|
|
200
|
+
## Roadmap
|
|
201
|
+
|
|
202
|
+
- [x] Core entity system with relations
|
|
203
|
+
- [x] Pagination, filtering, search
|
|
204
|
+
- [x] Authentication integration (NextAuth v5)
|
|
205
|
+
- [x] CRUD lifecycle hooks
|
|
206
|
+
- [x] Batch operations (createMany, updateMany, removeMany)
|
|
207
|
+
- [x] Computed fields
|
|
208
|
+
- [x] Enum support
|
|
209
|
+
- [ ] Multi-tenancy utilities (Q1 2026)
|
|
210
|
+
- [ ] RBAC/permissions framework (Q1 2026)
|
|
211
|
+
- [ ] Rate limiting (Q2 2026)
|
|
212
|
+
- [ ] Admin UI generator (Q2 2026)
|
|
213
|
+
|
|
214
|
+
---
|
|
215
|
+
|
|
216
|
+
## Contributing
|
|
217
|
+
|
|
218
|
+
We welcome contributions! See [CONTRIBUTING.md](CONTRIBUTING.md) for:
|
|
219
|
+
- Architecture overview
|
|
220
|
+
- Development setup
|
|
221
|
+
- How to add features
|
|
222
|
+
- Testing guidelines
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
## License
|
|
227
|
+
|
|
228
|
+
MIT - Use freely in commercial and open-source projects.
|
|
229
|
+
|
|
230
|
+
---
|
|
231
|
+
|
|
232
|
+
## Support
|
|
233
|
+
|
|
234
|
+
- 📖 **Docs:** [archetype-engine.vercel.app](https://archetype-engine.vercel.app)
|
|
235
|
+
- 🐛 **Issues:** [GitHub Issues](https://github.com/IFAKA/archetype-engine/issues)
|
|
236
|
+
- 💬 **Discussions:** [GitHub Discussions](https://github.com/IFAKA/archetype-engine/discussions)
|
|
237
|
+
- 🐦 **Updates:** Follow [@archetype_dev](https://twitter.com/archetype_dev)
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
**Built with ❤️ for developers tired of writing boilerplate.**
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anthropic Tool Use Adapter
|
|
3
|
+
*
|
|
4
|
+
* Converts tool definitions to Anthropic's tool use format.
|
|
5
|
+
*
|
|
6
|
+
* @module ai/adapters/anthropic
|
|
7
|
+
*/
|
|
8
|
+
import type { AnthropicTool, ManifestBuilder, ToolResult } from '../types';
|
|
9
|
+
/**
|
|
10
|
+
* Get all tools in Anthropic format
|
|
11
|
+
*/
|
|
12
|
+
export declare function getAnthropicTools(): AnthropicTool[];
|
|
13
|
+
/**
|
|
14
|
+
* Tool input parameters
|
|
15
|
+
*/
|
|
16
|
+
export interface ToolInput {
|
|
17
|
+
[key: string]: unknown;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Execute a tool call and return the result
|
|
21
|
+
* Reuses OpenAI execution logic since the interface is the same
|
|
22
|
+
*/
|
|
23
|
+
export declare function executeAnthropicTool(builder: ManifestBuilder, toolName: string, input: ToolInput): ToolResult;
|
|
24
|
+
/**
|
|
25
|
+
* Create a handler for Anthropic tool calls
|
|
26
|
+
*/
|
|
27
|
+
export declare function createAnthropicHandler(builder: ManifestBuilder): {
|
|
28
|
+
tools: AnthropicTool[];
|
|
29
|
+
execute: (toolName: string, input: ToolInput) => ToolResult;
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=anthropic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../../../src/ai/adapters/anthropic.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,UAAU,EAAkB,MAAM,UAAU,CAAA;AAkD1F;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,aAAa,EAAE,CAEnD;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,eAAe,EACxB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,SAAS,GACf,UAAU,CAEZ;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,eAAe;;wBAGvC,MAAM,SAAS,SAAS;EAG/C"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Anthropic Tool Use Adapter
|
|
4
|
+
*
|
|
5
|
+
* Converts tool definitions to Anthropic's tool use format.
|
|
6
|
+
*
|
|
7
|
+
* @module ai/adapters/anthropic
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.getAnthropicTools = getAnthropicTools;
|
|
11
|
+
exports.executeAnthropicTool = executeAnthropicTool;
|
|
12
|
+
exports.createAnthropicHandler = createAnthropicHandler;
|
|
13
|
+
const tools_1 = require("../tools");
|
|
14
|
+
const openai_1 = require("./openai");
|
|
15
|
+
/**
|
|
16
|
+
* Convert a tool definition to Anthropic format
|
|
17
|
+
*/
|
|
18
|
+
function toAnthropicSchema(def) {
|
|
19
|
+
const properties = {};
|
|
20
|
+
for (const [name, param] of Object.entries(def.parameters)) {
|
|
21
|
+
if (name.startsWith('['))
|
|
22
|
+
continue; // Skip placeholder properties
|
|
23
|
+
const prop = {
|
|
24
|
+
type: param.type,
|
|
25
|
+
description: param.description,
|
|
26
|
+
};
|
|
27
|
+
if (param.enum) {
|
|
28
|
+
prop.enum = param.enum;
|
|
29
|
+
}
|
|
30
|
+
if (param.type === 'array' && param.items) {
|
|
31
|
+
prop.items = {
|
|
32
|
+
type: param.items.type,
|
|
33
|
+
description: param.items.description,
|
|
34
|
+
};
|
|
35
|
+
if (param.items.enum) {
|
|
36
|
+
prop.items.enum = param.items.enum;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (param.type === 'object' && param.properties) {
|
|
40
|
+
prop.additionalProperties = true;
|
|
41
|
+
}
|
|
42
|
+
properties[name] = prop;
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
name: def.name,
|
|
46
|
+
description: def.description,
|
|
47
|
+
input_schema: {
|
|
48
|
+
type: 'object',
|
|
49
|
+
properties,
|
|
50
|
+
required: def.required,
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Get all tools in Anthropic format
|
|
56
|
+
*/
|
|
57
|
+
function getAnthropicTools() {
|
|
58
|
+
return Object.values(tools_1.toolDefinitions).map(toAnthropicSchema);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Execute a tool call and return the result
|
|
62
|
+
* Reuses OpenAI execution logic since the interface is the same
|
|
63
|
+
*/
|
|
64
|
+
function executeAnthropicTool(builder, toolName, input) {
|
|
65
|
+
return (0, openai_1.executeOpenAITool)(builder, toolName, input);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Create a handler for Anthropic tool calls
|
|
69
|
+
*/
|
|
70
|
+
function createAnthropicHandler(builder) {
|
|
71
|
+
return {
|
|
72
|
+
tools: getAnthropicTools(),
|
|
73
|
+
execute: (toolName, input) => executeAnthropicTool(builder, toolName, input),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI Function Calling Adapter
|
|
3
|
+
*
|
|
4
|
+
* Converts tool definitions to OpenAI's function calling format.
|
|
5
|
+
*
|
|
6
|
+
* @module ai/adapters/openai
|
|
7
|
+
*/
|
|
8
|
+
import type { OpenAITool, ManifestBuilder, ToolResult } from '../types';
|
|
9
|
+
/**
|
|
10
|
+
* Tool input parameters
|
|
11
|
+
*/
|
|
12
|
+
export interface ToolInput {
|
|
13
|
+
[key: string]: unknown;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Get all tools in OpenAI format
|
|
17
|
+
*/
|
|
18
|
+
export declare function getOpenAITools(): OpenAITool[];
|
|
19
|
+
/**
|
|
20
|
+
* Execute a tool call and return the result
|
|
21
|
+
*
|
|
22
|
+
* Note: AI frameworks send untyped JSON. We trust the AI to provide correctly-shaped data
|
|
23
|
+
* and rely on runtime validation within the builder methods to catch errors.
|
|
24
|
+
*/
|
|
25
|
+
export declare function executeOpenAITool(builder: ManifestBuilder, functionName: string, args: ToolInput): ToolResult;
|
|
26
|
+
/**
|
|
27
|
+
* Create a handler for OpenAI tool calls
|
|
28
|
+
*/
|
|
29
|
+
export declare function createOpenAIHandler(builder: ManifestBuilder): {
|
|
30
|
+
tools: OpenAITool[];
|
|
31
|
+
execute: (functionName: string, args: ToolInput) => ToolResult;
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=openai.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../../../src/ai/adapters/openai.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,EAAkB,MAAM,UAAU,CAAA;AAGvF;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAmDD;;GAEG;AACH,wBAAgB,cAAc,IAAI,UAAU,EAAE,CAE7C;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,eAAe,EACxB,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,SAAS,GACd,UAAU,CAkDZ;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,eAAe;;4BAGhC,MAAM,QAAQ,SAAS;EAGlD"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* OpenAI Function Calling Adapter
|
|
4
|
+
*
|
|
5
|
+
* Converts tool definitions to OpenAI's function calling format.
|
|
6
|
+
*
|
|
7
|
+
* @module ai/adapters/openai
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.getOpenAITools = getOpenAITools;
|
|
11
|
+
exports.executeOpenAITool = executeOpenAITool;
|
|
12
|
+
exports.createOpenAIHandler = createOpenAIHandler;
|
|
13
|
+
const tools_1 = require("../tools");
|
|
14
|
+
/**
|
|
15
|
+
* Convert a tool definition to OpenAI format
|
|
16
|
+
*/
|
|
17
|
+
function toOpenAISchema(def) {
|
|
18
|
+
const properties = {};
|
|
19
|
+
for (const [name, param] of Object.entries(def.parameters)) {
|
|
20
|
+
if (name.startsWith('['))
|
|
21
|
+
continue; // Skip placeholder properties
|
|
22
|
+
const prop = {
|
|
23
|
+
type: param.type,
|
|
24
|
+
description: param.description,
|
|
25
|
+
};
|
|
26
|
+
if (param.enum) {
|
|
27
|
+
prop.enum = param.enum;
|
|
28
|
+
}
|
|
29
|
+
if (param.type === 'array' && param.items) {
|
|
30
|
+
prop.items = {
|
|
31
|
+
type: param.items.type,
|
|
32
|
+
description: param.items.description,
|
|
33
|
+
};
|
|
34
|
+
if (param.items.enum) {
|
|
35
|
+
prop.items.enum = param.items.enum;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (param.type === 'object' && param.properties) {
|
|
39
|
+
prop.additionalProperties = true;
|
|
40
|
+
}
|
|
41
|
+
properties[name] = prop;
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
type: 'function',
|
|
45
|
+
function: {
|
|
46
|
+
name: def.name,
|
|
47
|
+
description: def.description,
|
|
48
|
+
parameters: {
|
|
49
|
+
type: 'object',
|
|
50
|
+
properties,
|
|
51
|
+
required: def.required,
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Get all tools in OpenAI format
|
|
58
|
+
*/
|
|
59
|
+
function getOpenAITools() {
|
|
60
|
+
return Object.values(tools_1.toolDefinitions).map(toOpenAISchema);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Execute a tool call and return the result
|
|
64
|
+
*
|
|
65
|
+
* Note: AI frameworks send untyped JSON. We trust the AI to provide correctly-shaped data
|
|
66
|
+
* and rely on runtime validation within the builder methods to catch errors.
|
|
67
|
+
*/
|
|
68
|
+
function executeOpenAITool(builder, functionName, args) {
|
|
69
|
+
switch (functionName) {
|
|
70
|
+
case 'add_entity':
|
|
71
|
+
// AI sends untyped JSON - type assertion required
|
|
72
|
+
return builder.addEntity(args);
|
|
73
|
+
case 'update_entity':
|
|
74
|
+
return builder.updateEntity(args);
|
|
75
|
+
case 'remove_entity':
|
|
76
|
+
return builder.removeEntity(args);
|
|
77
|
+
case 'set_database':
|
|
78
|
+
return builder.setDatabase(args);
|
|
79
|
+
case 'set_auth':
|
|
80
|
+
return builder.setAuth(args);
|
|
81
|
+
case 'validate': {
|
|
82
|
+
const result = builder.validate();
|
|
83
|
+
return {
|
|
84
|
+
success: result.valid,
|
|
85
|
+
message: result.valid
|
|
86
|
+
? 'Manifest is valid'
|
|
87
|
+
: `Found ${result.errors.length} error(s)`,
|
|
88
|
+
data: result,
|
|
89
|
+
errors: result.errors.map(e => ({
|
|
90
|
+
code: e.code,
|
|
91
|
+
message: e.message,
|
|
92
|
+
suggestion: e.suggestion,
|
|
93
|
+
})),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
case 'generate':
|
|
97
|
+
// Note: This is async but we return a sync result for compatibility
|
|
98
|
+
// Caller should handle the promise
|
|
99
|
+
return {
|
|
100
|
+
success: true,
|
|
101
|
+
message: 'Generation started. Call builder.generate() to get files.',
|
|
102
|
+
data: { manifest: builder.toManifest() },
|
|
103
|
+
};
|
|
104
|
+
default:
|
|
105
|
+
return {
|
|
106
|
+
success: false,
|
|
107
|
+
message: `Unknown function: ${functionName}`,
|
|
108
|
+
errors: [{ code: 'UNKNOWN_FUNCTION', message: `Unknown function: ${functionName}` }],
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Create a handler for OpenAI tool calls
|
|
114
|
+
*/
|
|
115
|
+
function createOpenAIHandler(builder) {
|
|
116
|
+
return {
|
|
117
|
+
tools: getOpenAITools(),
|
|
118
|
+
execute: (functionName, args) => executeOpenAITool(builder, functionName, args),
|
|
119
|
+
};
|
|
120
|
+
}
|