@girardmedia/bootspring 1.2.0 → 2.0.3
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/README.md +107 -14
- package/bin/bootspring.js +166 -27
- package/cli/agent.js +189 -17
- package/cli/analyze.js +499 -0
- package/cli/audit.js +557 -0
- package/cli/auth.js +495 -38
- package/cli/billing.js +302 -0
- package/cli/build.js +695 -0
- package/cli/business.js +109 -26
- package/cli/checkpoint-utils.js +168 -0
- package/cli/checkpoint.js +639 -0
- package/cli/cloud-sync.js +447 -0
- package/cli/content.js +198 -0
- package/cli/context.js +1 -1
- package/cli/deploy.js +543 -0
- package/cli/fundraise.js +112 -50
- package/cli/github-cmd.js +435 -0
- package/cli/health.js +477 -0
- package/cli/init.js +84 -13
- package/cli/legal.js +107 -95
- package/cli/log.js +2 -2
- package/cli/loop.js +976 -73
- package/cli/manager.js +711 -0
- package/cli/metrics.js +480 -0
- package/cli/monitor.js +812 -0
- package/cli/onboard.js +521 -0
- package/cli/orchestrator.js +12 -24
- package/cli/prd.js +594 -0
- package/cli/preseed-start.js +1483 -0
- package/cli/preseed.js +2302 -0
- package/cli/project.js +436 -0
- package/cli/quality.js +233 -0
- package/cli/security.js +913 -0
- package/cli/seed.js +1441 -5
- package/cli/skill.js +273 -211
- package/cli/suggest.js +989 -0
- package/cli/switch.js +453 -0
- package/cli/visualize.js +527 -0
- package/cli/watch.js +769 -0
- package/cli/workspace.js +607 -0
- package/core/analyze-workflow.js +1134 -0
- package/core/api-client.js +535 -22
- package/core/audit-workflow.js +1350 -0
- package/core/build-orchestrator.js +480 -0
- package/core/build-state.js +577 -0
- package/core/checkpoint-engine.js +408 -0
- package/core/config.js +1109 -26
- package/core/context-loader.js +21 -1
- package/core/deploy-workflow.js +836 -0
- package/core/entitlements.js +93 -22
- package/core/github-sync.js +610 -0
- package/core/index.js +8 -1
- package/core/ingest.js +1111 -0
- package/core/metrics-engine.js +768 -0
- package/core/onboard-workflow.js +1007 -0
- package/core/preseed-workflow.js +934 -0
- package/core/preseed.js +1617 -0
- package/core/project-context.js +325 -0
- package/core/project-state.js +694 -0
- package/core/r2-sync.js +583 -0
- package/core/scaffold.js +525 -7
- package/core/session.js +258 -0
- package/core/task-extractor.js +758 -0
- package/core/telemetry.js +28 -6
- package/core/tier-enforcement.js +737 -0
- package/core/utils.js +38 -14
- package/generators/questionnaire.js +15 -12
- package/generators/sections/ai.js +7 -7
- package/generators/sections/content.js +300 -0
- package/generators/sections/index.js +3 -0
- package/generators/sections/plugins.js +7 -6
- package/generators/templates/build-planning.template.js +596 -0
- package/generators/templates/content.template.js +819 -0
- package/generators/templates/index.js +2 -1
- package/hooks/git-autopilot.js +1250 -0
- package/hooks/index.js +9 -0
- package/intelligence/agent-collab.js +2057 -0
- package/intelligence/auto-suggest.js +634 -0
- package/intelligence/content-gen.js +1589 -0
- package/intelligence/cross-project.js +1647 -0
- package/intelligence/index.js +184 -0
- package/intelligence/learning/insights.json +517 -7
- package/intelligence/learning/pattern-learner.js +1008 -14
- package/intelligence/memory/decision-tracker.js +1431 -31
- package/intelligence/memory/decisions.jsonl +0 -0
- package/intelligence/orchestrator.js +2896 -1
- package/intelligence/prd.js +92 -1
- package/intelligence/recommendation-weights.json +14 -2
- package/intelligence/recommendations.js +463 -9
- package/intelligence/workflow-composer.js +1451 -0
- package/marketplace/index.d.ts +324 -0
- package/marketplace/index.js +1921 -0
- package/mcp/contracts/mcp-contract.v1.json +342 -4
- package/mcp/registry.js +680 -3
- package/mcp/response-formatter.js +23 -0
- package/mcp/tools/assist-tool.js +78 -4
- package/mcp/tools/autopilot-tool.js +408 -0
- package/mcp/tools/content-tool.js +571 -0
- package/mcp/tools/dashboard-tool.js +251 -5
- package/mcp/tools/mvp-tool.js +344 -0
- package/mcp/tools/plugin-tool.js +23 -1
- package/mcp/tools/prd-tool.js +579 -0
- package/mcp/tools/seed-tool.js +447 -0
- package/mcp/tools/skill-tool.js +43 -14
- package/mcp/tools/suggest-tool.js +147 -0
- package/package.json +15 -6
- package/agents/README.md +0 -93
- package/agents/ai-integration-expert/context.md +0 -386
- package/agents/api-expert/context.md +0 -416
- package/agents/architecture-expert/context.md +0 -454
- package/agents/auth-expert/context.md +0 -399
- package/agents/backend-expert/context.md +0 -483
- package/agents/business-strategy-expert/context.md +0 -180
- package/agents/code-review-expert/context.md +0 -365
- package/agents/competitive-analysis-expert/context.md +0 -239
- package/agents/data-modeling-expert/context.md +0 -352
- package/agents/database-expert/context.md +0 -250
- package/agents/devops-expert/context.md +0 -446
- package/agents/email-expert/context.md +0 -379
- package/agents/financial-expert/context.md +0 -213
- package/agents/frontend-expert/context.md +0 -364
- package/agents/fundraising-expert/context.md +0 -257
- package/agents/growth-expert/context.md +0 -249
- package/agents/index.js +0 -140
- package/agents/investor-relations-expert/context.md +0 -266
- package/agents/legal-expert/context.md +0 -284
- package/agents/marketing-expert/context.md +0 -236
- package/agents/monitoring-expert/context.md +0 -362
- package/agents/operations-expert/context.md +0 -279
- package/agents/partnerships-expert/context.md +0 -286
- package/agents/payment-expert/context.md +0 -340
- package/agents/performance-expert/context.md +0 -377
- package/agents/private-equity-expert/context.md +0 -246
- package/agents/railway-expert/context.md +0 -284
- package/agents/research-expert/context.md +0 -245
- package/agents/sales-expert/context.md +0 -241
- package/agents/security-expert/context.md +0 -343
- package/agents/testing-expert/context.md +0 -414
- package/agents/ui-ux-expert/context.md +0 -448
- package/agents/vercel-expert/context.md +0 -426
- package/skills/index.js +0 -787
- package/skills/patterns/README.md +0 -163
- package/skills/patterns/ai/agents.md +0 -281
- package/skills/patterns/ai/claude.md +0 -138
- package/skills/patterns/ai/embeddings.md +0 -150
- package/skills/patterns/ai/rag.md +0 -266
- package/skills/patterns/ai/streaming.md +0 -170
- package/skills/patterns/ai/structured-output.md +0 -162
- package/skills/patterns/ai/tools.md +0 -154
- package/skills/patterns/analytics/tracking.md +0 -220
- package/skills/patterns/api/errors.md +0 -296
- package/skills/patterns/api/graphql.md +0 -440
- package/skills/patterns/api/middleware.md +0 -279
- package/skills/patterns/api/openapi.md +0 -285
- package/skills/patterns/api/rate-limiting.md +0 -231
- package/skills/patterns/api/route-handler.md +0 -217
- package/skills/patterns/api/server-action.md +0 -249
- package/skills/patterns/api/versioning.md +0 -443
- package/skills/patterns/api/webhooks.md +0 -247
- package/skills/patterns/auth/clerk.md +0 -132
- package/skills/patterns/auth/mfa.md +0 -313
- package/skills/patterns/auth/nextauth.md +0 -140
- package/skills/patterns/auth/oauth.md +0 -237
- package/skills/patterns/auth/rbac.md +0 -152
- package/skills/patterns/auth/session-management.md +0 -367
- package/skills/patterns/auth/session.md +0 -120
- package/skills/patterns/database/audit.md +0 -177
- package/skills/patterns/database/migrations.md +0 -177
- package/skills/patterns/database/pagination.md +0 -230
- package/skills/patterns/database/pooling.md +0 -357
- package/skills/patterns/database/prisma.md +0 -180
- package/skills/patterns/database/relations.md +0 -187
- package/skills/patterns/database/seeding.md +0 -246
- package/skills/patterns/database/soft-delete.md +0 -153
- package/skills/patterns/database/transactions.md +0 -162
- package/skills/patterns/deployment/ci-cd.md +0 -231
- package/skills/patterns/deployment/docker.md +0 -188
- package/skills/patterns/deployment/monitoring.md +0 -387
- package/skills/patterns/deployment/vercel.md +0 -160
- package/skills/patterns/email/resend.md +0 -143
- package/skills/patterns/email/templates.md +0 -245
- package/skills/patterns/email/transactional.md +0 -503
- package/skills/patterns/email/verification.md +0 -176
- package/skills/patterns/files/download.md +0 -243
- package/skills/patterns/files/upload.md +0 -239
- package/skills/patterns/i18n/nextintl.md +0 -188
- package/skills/patterns/logging/structured.md +0 -292
- package/skills/patterns/notifications/email-queue.md +0 -248
- package/skills/patterns/notifications/push.md +0 -279
- package/skills/patterns/payments/checkout.md +0 -303
- package/skills/patterns/payments/invoices.md +0 -287
- package/skills/patterns/payments/portal.md +0 -245
- package/skills/patterns/payments/stripe.md +0 -272
- package/skills/patterns/payments/subscriptions.md +0 -300
- package/skills/patterns/payments/usage.md +0 -279
- package/skills/patterns/performance/caching.md +0 -276
- package/skills/patterns/performance/code-splitting.md +0 -233
- package/skills/patterns/performance/edge.md +0 -254
- package/skills/patterns/performance/isr.md +0 -266
- package/skills/patterns/performance/lazy-loading.md +0 -281
- package/skills/patterns/realtime/sse.md +0 -327
- package/skills/patterns/realtime/websockets.md +0 -336
- package/skills/patterns/search/filtering.md +0 -329
- package/skills/patterns/search/fulltext.md +0 -260
- package/skills/patterns/security/audit-logging.md +0 -444
- package/skills/patterns/security/csrf.md +0 -234
- package/skills/patterns/security/headers.md +0 -252
- package/skills/patterns/security/sanitization.md +0 -258
- package/skills/patterns/security/secrets.md +0 -261
- package/skills/patterns/security/validation.md +0 -268
- package/skills/patterns/security/xss.md +0 -229
- package/skills/patterns/seo/metadata.md +0 -252
- package/skills/patterns/state/context.md +0 -349
- package/skills/patterns/state/react-query.md +0 -313
- package/skills/patterns/state/url-state.md +0 -482
- package/skills/patterns/state/zustand.md +0 -262
- package/skills/patterns/testing/api.md +0 -259
- package/skills/patterns/testing/component.md +0 -233
- package/skills/patterns/testing/coverage.md +0 -207
- package/skills/patterns/testing/fixtures.md +0 -225
- package/skills/patterns/testing/integration.md +0 -436
- package/skills/patterns/testing/mocking.md +0 -177
- package/skills/patterns/testing/playwright.md +0 -162
- package/skills/patterns/testing/snapshot.md +0 -175
- package/skills/patterns/testing/vitest.md +0 -307
- package/skills/patterns/ui/accordions.md +0 -395
- package/skills/patterns/ui/cards.md +0 -299
- package/skills/patterns/ui/dropdowns.md +0 -476
- package/skills/patterns/ui/empty-states.md +0 -320
- package/skills/patterns/ui/forms.md +0 -405
- package/skills/patterns/ui/inputs.md +0 -319
- package/skills/patterns/ui/layouts.md +0 -282
- package/skills/patterns/ui/loading.md +0 -291
- package/skills/patterns/ui/modals.md +0 -338
- package/skills/patterns/ui/navigation.md +0 -374
- package/skills/patterns/ui/tables.md +0 -407
- package/skills/patterns/ui/toasts.md +0 -300
- package/skills/patterns/ui/tooltips.md +0 -396
- package/skills/patterns/utils/dates.md +0 -435
- package/skills/patterns/utils/errors.md +0 -451
- package/skills/patterns/utils/formatting.md +0 -345
- package/skills/patterns/utils/validation.md +0 -434
- package/templates/bootspring.config.js +0 -83
- package/templates/business/business-model-canvas.md +0 -246
- package/templates/business/business-plan.md +0 -266
- package/templates/business/competitive-analysis.md +0 -312
- package/templates/fundraising/data-room-checklist.md +0 -300
- package/templates/fundraising/investor-research.md +0 -243
- package/templates/fundraising/pitch-deck-outline.md +0 -253
- package/templates/legal/gdpr-checklist.md +0 -339
- package/templates/legal/privacy-policy.md +0 -285
- package/templates/legal/terms-of-service.md +0 -222
- package/templates/mcp.json +0 -9
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
# Bootspring Skill Patterns
|
|
2
|
-
|
|
3
|
-
Battle-tested code patterns for common development tasks.
|
|
4
|
-
|
|
5
|
-
## Available Patterns
|
|
6
|
-
|
|
7
|
-
### Authentication
|
|
8
|
-
| Pattern | Description |
|
|
9
|
-
|---------|-------------|
|
|
10
|
-
| [auth/clerk](./auth/clerk.md) | Clerk authentication - server auth, middleware, user sync |
|
|
11
|
-
|
|
12
|
-
### Database
|
|
13
|
-
| Pattern | Description |
|
|
14
|
-
|---------|-------------|
|
|
15
|
-
| [database/prisma](./database/prisma.md) | Prisma ORM - client setup, queries, transactions, migrations |
|
|
16
|
-
|
|
17
|
-
### API Development
|
|
18
|
-
| Pattern | Description |
|
|
19
|
-
|---------|-------------|
|
|
20
|
-
| [api/route-handler](./api/route-handler.md) | Next.js route handlers - CRUD, error handling, rate limiting |
|
|
21
|
-
| [api/server-action](./api/server-action.md) | Server actions - forms, optimistic updates, useActionState |
|
|
22
|
-
|
|
23
|
-
### Payments
|
|
24
|
-
| Pattern | Description |
|
|
25
|
-
|---------|-------------|
|
|
26
|
-
| [payments/stripe](./payments/stripe.md) | Stripe - checkout, subscriptions, webhooks, customer portal |
|
|
27
|
-
|
|
28
|
-
### Security
|
|
29
|
-
| Pattern | Description |
|
|
30
|
-
|---------|-------------|
|
|
31
|
-
| [security/validation](./security/validation.md) | Input validation - Zod schemas, sanitization, CSRF, rate limiting |
|
|
32
|
-
|
|
33
|
-
### Testing
|
|
34
|
-
| Pattern | Description |
|
|
35
|
-
|---------|-------------|
|
|
36
|
-
| [testing/vitest](./testing/vitest.md) | Vitest - setup, unit tests, component tests, mocking |
|
|
37
|
-
|
|
38
|
-
## Usage
|
|
39
|
-
|
|
40
|
-
### Via CLI
|
|
41
|
-
```bash
|
|
42
|
-
# List all patterns
|
|
43
|
-
bootspring skill list
|
|
44
|
-
|
|
45
|
-
# Include curated external skills catalog (skills/external)
|
|
46
|
-
bootspring skill list --external
|
|
47
|
-
|
|
48
|
-
# Search for patterns
|
|
49
|
-
bootspring skill search "auth"
|
|
50
|
-
bootspring skill search "vercel" --external
|
|
51
|
-
|
|
52
|
-
# Show a specific pattern
|
|
53
|
-
bootspring skill show auth/clerk
|
|
54
|
-
|
|
55
|
-
# Show concise summary
|
|
56
|
-
bootspring skill show auth/clerk --summary
|
|
57
|
-
|
|
58
|
-
# Show only matching sections and cap output size
|
|
59
|
-
bootspring skill show api/route-handler --sections "basic crud,error handling" --max-chars 1200
|
|
60
|
-
|
|
61
|
-
# Show an external skill by id
|
|
62
|
-
bootspring skill show external/vercel-automation
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
### Via MCP Tool
|
|
66
|
-
```text
|
|
67
|
-
bootspring_skill { action: "show", name: "auth/clerk" }
|
|
68
|
-
bootspring_skill { action: "show", name: "auth/clerk", summary: true }
|
|
69
|
-
bootspring_skill { action: "show", name: "api/route-handler", sections: "basic crud", maxChars: 1200 }
|
|
70
|
-
bootspring_skill { action: "search", query: "database" }
|
|
71
|
-
bootspring_skill { action: "list", includeExternal: true, limit: 20 }
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
### Direct Reference
|
|
75
|
-
Patterns are markdown files with code blocks. Reference them in prompts:
|
|
76
|
-
```text
|
|
77
|
-
Using the pattern from bootspring/skills/patterns/api/server-action.md,
|
|
78
|
-
implement a server action for updating user profile.
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
## Pattern Structure
|
|
82
|
-
|
|
83
|
-
Each pattern includes:
|
|
84
|
-
- **Setup code** - Configuration and initialization
|
|
85
|
-
- **Common patterns** - Frequently used implementations
|
|
86
|
-
- **Best practices** - Security and performance considerations
|
|
87
|
-
- **When to use** - Guidance on appropriate use cases
|
|
88
|
-
|
|
89
|
-
## Adding Custom Patterns
|
|
90
|
-
|
|
91
|
-
Create a markdown file in the appropriate category:
|
|
92
|
-
```text
|
|
93
|
-
skills/patterns/
|
|
94
|
-
├── auth/
|
|
95
|
-
│ └── my-custom-auth.md
|
|
96
|
-
├── database/
|
|
97
|
-
├── api/
|
|
98
|
-
└── ...
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
Pattern template:
|
|
102
|
-
```markdown
|
|
103
|
-
# Pattern Name
|
|
104
|
-
|
|
105
|
-
Brief description.
|
|
106
|
-
|
|
107
|
-
## Setup
|
|
108
|
-
|
|
109
|
-
~~~typescript
|
|
110
|
-
// Configuration code
|
|
111
|
-
~~~
|
|
112
|
-
|
|
113
|
-
## Common Patterns
|
|
114
|
-
|
|
115
|
-
~~~typescript
|
|
116
|
-
// Implementation examples
|
|
117
|
-
~~~
|
|
118
|
-
|
|
119
|
-
## When to Use
|
|
120
|
-
|
|
121
|
-
- Use case 1
|
|
122
|
-
- Use case 2
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
## External Catalog (Curated)
|
|
126
|
-
|
|
127
|
-
If `skills/external/` exists, Bootspring indexes it as an optional external catalog:
|
|
128
|
-
|
|
129
|
-
- `bootspring skill list --external`
|
|
130
|
-
- `bootspring skill search <query> --external`
|
|
131
|
-
- `bootspring skill show external/<skill-id>`
|
|
132
|
-
|
|
133
|
-
This catalog is optional. If you want a leaner repo, you can remove `skills/external/` without affecting built-in patterns.
|
|
134
|
-
|
|
135
|
-
### Entitlement Policy
|
|
136
|
-
|
|
137
|
-
External skills are checked through `core/entitlements.js`:
|
|
138
|
-
|
|
139
|
-
- `BOOTSPRING_SKILL_ACCESS_MODE=local` (default): external skills are accessible.
|
|
140
|
-
- `BOOTSPRING_SKILL_ACCESS_MODE=server`: external skills require entitlement.
|
|
141
|
-
- Entitlement in server mode is granted by either:
|
|
142
|
-
- `BOOTSPRING_SKILLS_ENTITLED=true`
|
|
143
|
-
- `BOOTSPRING_USER_TIER=pro|team|enterprise`
|
|
144
|
-
|
|
145
|
-
### Remote Catalog Sync
|
|
146
|
-
|
|
147
|
-
For lightweight npm installs, sync protected skills from your backend into local cache:
|
|
148
|
-
|
|
149
|
-
```bash
|
|
150
|
-
bootspring skill sync \
|
|
151
|
-
--manifest-url https://api.bootspring.com/skills/manifest.json \
|
|
152
|
-
--content-base-url https://api.bootspring.com/skills/content
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
Relevant environment variables:
|
|
156
|
-
|
|
157
|
-
- `BOOTSPRING_SKILL_MANIFEST_URL`
|
|
158
|
-
- `BOOTSPRING_SKILL_CONTENT_BASE_URL`
|
|
159
|
-
- `BOOTSPRING_SKILL_TOKEN`
|
|
160
|
-
- `BOOTSPRING_SKILL_CACHE_DIR`
|
|
161
|
-
- `BOOTSPRING_SKILL_CATALOG_SOURCE=auto|cache|local`
|
|
162
|
-
- `BOOTSPRING_SKILL_MANIFEST_PUBLIC_KEY`
|
|
163
|
-
- `BOOTSPRING_SKILL_MANIFEST_REQUIRE_SIGNATURE=true|false`
|
|
@@ -1,281 +0,0 @@
|
|
|
1
|
-
# AI Agents Patterns
|
|
2
|
-
|
|
3
|
-
Patterns for building AI agents.
|
|
4
|
-
|
|
5
|
-
## Basic Agent Loop
|
|
6
|
-
|
|
7
|
-
```typescript
|
|
8
|
-
// lib/agents/base.ts
|
|
9
|
-
import Anthropic from '@anthropic-ai/sdk'
|
|
10
|
-
|
|
11
|
-
const client = new Anthropic()
|
|
12
|
-
|
|
13
|
-
interface Tool {
|
|
14
|
-
name: string
|
|
15
|
-
description: string
|
|
16
|
-
input_schema: object
|
|
17
|
-
execute: (input: any) => Promise<string>
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export async function runAgent(
|
|
21
|
-
systemPrompt: string,
|
|
22
|
-
userMessage: string,
|
|
23
|
-
tools: Tool[],
|
|
24
|
-
maxIterations = 10
|
|
25
|
-
) {
|
|
26
|
-
const messages: Anthropic.MessageParam[] = [
|
|
27
|
-
{ role: 'user', content: userMessage }
|
|
28
|
-
]
|
|
29
|
-
|
|
30
|
-
const anthropicTools = tools.map(t => ({
|
|
31
|
-
name: t.name,
|
|
32
|
-
description: t.description,
|
|
33
|
-
input_schema: t.input_schema
|
|
34
|
-
}))
|
|
35
|
-
|
|
36
|
-
for (let i = 0; i < maxIterations; i++) {
|
|
37
|
-
const response = await client.messages.create({
|
|
38
|
-
model: 'claude-sonnet-4-20250514',
|
|
39
|
-
max_tokens: 4096,
|
|
40
|
-
system: systemPrompt,
|
|
41
|
-
tools: anthropicTools,
|
|
42
|
-
messages
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
// Check if we're done
|
|
46
|
-
if (response.stop_reason === 'end_turn') {
|
|
47
|
-
const textBlock = response.content.find(b => b.type === 'text')
|
|
48
|
-
return textBlock?.text ?? ''
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// Process tool uses
|
|
52
|
-
const toolUses = response.content.filter(b => b.type === 'tool_use')
|
|
53
|
-
|
|
54
|
-
if (toolUses.length === 0) {
|
|
55
|
-
const textBlock = response.content.find(b => b.type === 'text')
|
|
56
|
-
return textBlock?.text ?? ''
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Add assistant message
|
|
60
|
-
messages.push({ role: 'assistant', content: response.content })
|
|
61
|
-
|
|
62
|
-
// Execute tools and add results
|
|
63
|
-
const toolResults = await Promise.all(
|
|
64
|
-
toolUses.map(async (toolUse) => {
|
|
65
|
-
const tool = tools.find(t => t.name === toolUse.name)
|
|
66
|
-
if (!tool) {
|
|
67
|
-
return {
|
|
68
|
-
type: 'tool_result' as const,
|
|
69
|
-
tool_use_id: toolUse.id,
|
|
70
|
-
content: `Error: Tool ${toolUse.name} not found`
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
try {
|
|
75
|
-
const result = await tool.execute(toolUse.input)
|
|
76
|
-
return {
|
|
77
|
-
type: 'tool_result' as const,
|
|
78
|
-
tool_use_id: toolUse.id,
|
|
79
|
-
content: result
|
|
80
|
-
}
|
|
81
|
-
} catch (error) {
|
|
82
|
-
return {
|
|
83
|
-
type: 'tool_result' as const,
|
|
84
|
-
tool_use_id: toolUse.id,
|
|
85
|
-
content: `Error: ${error instanceof Error ? error.message : 'Unknown error'}`
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
})
|
|
89
|
-
)
|
|
90
|
-
|
|
91
|
-
messages.push({ role: 'user', content: toolResults })
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
throw new Error('Max iterations reached')
|
|
95
|
-
}
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
## Research Agent
|
|
99
|
-
|
|
100
|
-
```typescript
|
|
101
|
-
// lib/agents/research.ts
|
|
102
|
-
import { runAgent } from './base'
|
|
103
|
-
|
|
104
|
-
const webSearchTool = {
|
|
105
|
-
name: 'web_search',
|
|
106
|
-
description: 'Search the web for information',
|
|
107
|
-
input_schema: {
|
|
108
|
-
type: 'object',
|
|
109
|
-
properties: {
|
|
110
|
-
query: { type: 'string', description: 'The search query' }
|
|
111
|
-
},
|
|
112
|
-
required: ['query']
|
|
113
|
-
},
|
|
114
|
-
execute: async (input: { query: string }) => {
|
|
115
|
-
const response = await fetch(
|
|
116
|
-
`https://api.search.com/search?q=${encodeURIComponent(input.query)}`
|
|
117
|
-
)
|
|
118
|
-
const data = await response.json()
|
|
119
|
-
return JSON.stringify(data.results.slice(0, 5))
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const readUrlTool = {
|
|
124
|
-
name: 'read_url',
|
|
125
|
-
description: 'Read the contents of a URL',
|
|
126
|
-
input_schema: {
|
|
127
|
-
type: 'object',
|
|
128
|
-
properties: {
|
|
129
|
-
url: { type: 'string', description: 'The URL to read' }
|
|
130
|
-
},
|
|
131
|
-
required: ['url']
|
|
132
|
-
},
|
|
133
|
-
execute: async (input: { url: string }) => {
|
|
134
|
-
const response = await fetch(input.url)
|
|
135
|
-
const html = await response.text()
|
|
136
|
-
// Extract text from HTML
|
|
137
|
-
return extractText(html).slice(0, 5000)
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
export async function researchTopic(topic: string) {
|
|
142
|
-
const systemPrompt = `You are a research assistant. Your job is to research topics thoroughly using web search and URL reading tools. Provide comprehensive, well-sourced information.`
|
|
143
|
-
|
|
144
|
-
return runAgent(
|
|
145
|
-
systemPrompt,
|
|
146
|
-
`Research the following topic and provide a detailed summary: ${topic}`,
|
|
147
|
-
[webSearchTool, readUrlTool]
|
|
148
|
-
)
|
|
149
|
-
}
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
## Task Execution Agent
|
|
153
|
-
|
|
154
|
-
```typescript
|
|
155
|
-
// lib/agents/task.ts
|
|
156
|
-
import { runAgent } from './base'
|
|
157
|
-
import { prisma } from '@/lib/db'
|
|
158
|
-
|
|
159
|
-
const createTaskTool = {
|
|
160
|
-
name: 'create_task',
|
|
161
|
-
description: 'Create a new task in the system',
|
|
162
|
-
input_schema: {
|
|
163
|
-
type: 'object',
|
|
164
|
-
properties: {
|
|
165
|
-
title: { type: 'string' },
|
|
166
|
-
description: { type: 'string' },
|
|
167
|
-
priority: { type: 'string', enum: ['low', 'medium', 'high'] },
|
|
168
|
-
dueDate: { type: 'string', description: 'ISO date string' }
|
|
169
|
-
},
|
|
170
|
-
required: ['title']
|
|
171
|
-
},
|
|
172
|
-
execute: async (input: any) => {
|
|
173
|
-
const task = await prisma.task.create({
|
|
174
|
-
data: {
|
|
175
|
-
title: input.title,
|
|
176
|
-
description: input.description,
|
|
177
|
-
priority: input.priority ?? 'medium',
|
|
178
|
-
dueDate: input.dueDate ? new Date(input.dueDate) : null
|
|
179
|
-
}
|
|
180
|
-
})
|
|
181
|
-
return `Created task: ${task.id}`
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
const listTasksTool = {
|
|
186
|
-
name: 'list_tasks',
|
|
187
|
-
description: 'List all tasks',
|
|
188
|
-
input_schema: {
|
|
189
|
-
type: 'object',
|
|
190
|
-
properties: {
|
|
191
|
-
status: { type: 'string', enum: ['pending', 'completed', 'all'] }
|
|
192
|
-
}
|
|
193
|
-
},
|
|
194
|
-
execute: async (input: any) => {
|
|
195
|
-
const where = input.status === 'all' ? {} : { status: input.status }
|
|
196
|
-
const tasks = await prisma.task.findMany({ where })
|
|
197
|
-
return JSON.stringify(tasks)
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
export async function processTaskRequest(userRequest: string) {
|
|
202
|
-
const systemPrompt = `You are a task management assistant. Help users create, list, and manage their tasks using the available tools.`
|
|
203
|
-
|
|
204
|
-
return runAgent(
|
|
205
|
-
systemPrompt,
|
|
206
|
-
userRequest,
|
|
207
|
-
[createTaskTool, listTasksTool]
|
|
208
|
-
)
|
|
209
|
-
}
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
## Streaming Agent
|
|
213
|
-
|
|
214
|
-
```typescript
|
|
215
|
-
// lib/agents/streaming.ts
|
|
216
|
-
import Anthropic from '@anthropic-ai/sdk'
|
|
217
|
-
|
|
218
|
-
export async function* streamingAgent(
|
|
219
|
-
systemPrompt: string,
|
|
220
|
-
userMessage: string,
|
|
221
|
-
tools: Tool[]
|
|
222
|
-
) {
|
|
223
|
-
const client = new Anthropic()
|
|
224
|
-
const messages: Anthropic.MessageParam[] = [
|
|
225
|
-
{ role: 'user', content: userMessage }
|
|
226
|
-
]
|
|
227
|
-
|
|
228
|
-
while (true) {
|
|
229
|
-
let currentToolUse: any = null
|
|
230
|
-
let currentToolInput = ''
|
|
231
|
-
|
|
232
|
-
const stream = client.messages.stream({
|
|
233
|
-
model: 'claude-sonnet-4-20250514',
|
|
234
|
-
max_tokens: 4096,
|
|
235
|
-
system: systemPrompt,
|
|
236
|
-
tools: tools.map(t => ({
|
|
237
|
-
name: t.name,
|
|
238
|
-
description: t.description,
|
|
239
|
-
input_schema: t.input_schema
|
|
240
|
-
})),
|
|
241
|
-
messages
|
|
242
|
-
})
|
|
243
|
-
|
|
244
|
-
for await (const event of stream) {
|
|
245
|
-
if (event.type === 'content_block_start' && event.content_block.type === 'text') {
|
|
246
|
-
yield { type: 'text_start' }
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
if (event.type === 'content_block_delta') {
|
|
250
|
-
if (event.delta.type === 'text_delta') {
|
|
251
|
-
yield { type: 'text', content: event.delta.text }
|
|
252
|
-
}
|
|
253
|
-
if (event.delta.type === 'input_json_delta') {
|
|
254
|
-
currentToolInput += event.delta.partial_json
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
if (event.type === 'content_block_start' && event.content_block.type === 'tool_use') {
|
|
259
|
-
currentToolUse = event.content_block
|
|
260
|
-
yield { type: 'tool_start', name: currentToolUse.name }
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
const finalMessage = await stream.finalMessage()
|
|
265
|
-
|
|
266
|
-
if (finalMessage.stop_reason === 'end_turn') {
|
|
267
|
-
break
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
// Handle tool execution
|
|
271
|
-
// ... similar to non-streaming version
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
```
|
|
275
|
-
|
|
276
|
-
## When to Use
|
|
277
|
-
|
|
278
|
-
- Autonomous tasks
|
|
279
|
-
- Research assistants
|
|
280
|
-
- Multi-step workflows
|
|
281
|
-
- Tool orchestration
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
# Claude API Integration Patterns
|
|
2
|
-
|
|
3
|
-
Patterns for integrating Anthropic Claude in Next.js.
|
|
4
|
-
|
|
5
|
-
## Client Setup
|
|
6
|
-
|
|
7
|
-
```typescript
|
|
8
|
-
// lib/anthropic.ts
|
|
9
|
-
import Anthropic from '@anthropic-ai/sdk'
|
|
10
|
-
|
|
11
|
-
export const anthropic = new Anthropic({
|
|
12
|
-
apiKey: process.env.ANTHROPIC_API_KEY
|
|
13
|
-
})
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
## Basic Message
|
|
17
|
-
|
|
18
|
-
```typescript
|
|
19
|
-
// lib/anthropic.ts
|
|
20
|
-
export async function chat(prompt: string) {
|
|
21
|
-
const response = await anthropic.messages.create({
|
|
22
|
-
model: 'claude-sonnet-4-20250514',
|
|
23
|
-
max_tokens: 1024,
|
|
24
|
-
messages: [{ role: 'user', content: prompt }]
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
return response.content[0].type === 'text'
|
|
28
|
-
? response.content[0].text
|
|
29
|
-
: null
|
|
30
|
-
}
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
## With System Prompt
|
|
34
|
-
|
|
35
|
-
```typescript
|
|
36
|
-
// lib/anthropic.ts
|
|
37
|
-
export async function chatWithSystem(
|
|
38
|
-
system: string,
|
|
39
|
-
prompt: string
|
|
40
|
-
) {
|
|
41
|
-
const response = await anthropic.messages.create({
|
|
42
|
-
model: 'claude-sonnet-4-20250514',
|
|
43
|
-
max_tokens: 1024,
|
|
44
|
-
system,
|
|
45
|
-
messages: [{ role: 'user', content: prompt }]
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
return response.content[0].type === 'text'
|
|
49
|
-
? response.content[0].text
|
|
50
|
-
: null
|
|
51
|
-
}
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
## Multi-Turn Conversation
|
|
55
|
-
|
|
56
|
-
```typescript
|
|
57
|
-
// lib/anthropic.ts
|
|
58
|
-
type Message = {
|
|
59
|
-
role: 'user' | 'assistant'
|
|
60
|
-
content: string
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export async function conversation(messages: Message[]) {
|
|
64
|
-
const response = await anthropic.messages.create({
|
|
65
|
-
model: 'claude-sonnet-4-20250514',
|
|
66
|
-
max_tokens: 1024,
|
|
67
|
-
messages
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
return response.content[0].type === 'text'
|
|
71
|
-
? response.content[0].text
|
|
72
|
-
: null
|
|
73
|
-
}
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
## API Route Handler
|
|
77
|
-
|
|
78
|
-
```typescript
|
|
79
|
-
// app/api/chat/route.ts
|
|
80
|
-
import { anthropic } from '@/lib/anthropic'
|
|
81
|
-
|
|
82
|
-
export async function POST(req: Request) {
|
|
83
|
-
const { messages, system } = await req.json()
|
|
84
|
-
|
|
85
|
-
const response = await anthropic.messages.create({
|
|
86
|
-
model: 'claude-sonnet-4-20250514',
|
|
87
|
-
max_tokens: 1024,
|
|
88
|
-
system,
|
|
89
|
-
messages
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
const text = response.content[0].type === 'text'
|
|
93
|
-
? response.content[0].text
|
|
94
|
-
: ''
|
|
95
|
-
|
|
96
|
-
return Response.json({ response: text })
|
|
97
|
-
}
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
## Error Handling
|
|
101
|
-
|
|
102
|
-
```typescript
|
|
103
|
-
// lib/anthropic.ts
|
|
104
|
-
import Anthropic from '@anthropic-ai/sdk'
|
|
105
|
-
|
|
106
|
-
export async function safeChatcompletion(prompt: string) {
|
|
107
|
-
try {
|
|
108
|
-
const response = await anthropic.messages.create({
|
|
109
|
-
model: 'claude-sonnet-4-20250514',
|
|
110
|
-
max_tokens: 1024,
|
|
111
|
-
messages: [{ role: 'user', content: prompt }]
|
|
112
|
-
})
|
|
113
|
-
|
|
114
|
-
return {
|
|
115
|
-
success: true,
|
|
116
|
-
text: response.content[0].type === 'text'
|
|
117
|
-
? response.content[0].text
|
|
118
|
-
: null
|
|
119
|
-
}
|
|
120
|
-
} catch (error) {
|
|
121
|
-
if (error instanceof Anthropic.APIError) {
|
|
122
|
-
return {
|
|
123
|
-
success: false,
|
|
124
|
-
error: error.message,
|
|
125
|
-
status: error.status
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
throw error
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
## When to Use
|
|
134
|
-
|
|
135
|
-
- Chatbots and assistants
|
|
136
|
-
- Content generation
|
|
137
|
-
- Data extraction
|
|
138
|
-
- Code generation
|