ai-sdk-provider-claude-code 0.2.1 → 1.0.0-beta.1
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 +68 -10
- package/dist/index.cjs +90 -48
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -19
- package/dist/index.d.ts +21 -19
- package/dist/index.js +90 -48
- package/dist/index.js.map +1 -1
- package/docs/{DEVELOPMENT-STATUS.md → ai-sdk-v4/DEVELOPMENT-STATUS.md} +2 -2
- package/docs/{GUIDE.md → ai-sdk-v4/GUIDE.md} +4 -4
- package/docs/{TROUBLESHOOTING.md → ai-sdk-v4/TROUBLESHOOTING.md} +1 -1
- package/docs/ai-sdk-v5/DEVELOPMENT-STATUS.md +280 -0
- package/docs/ai-sdk-v5/GUIDE.md +912 -0
- package/docs/ai-sdk-v5/TROUBLESHOOTING.md +365 -0
- package/docs/ai-sdk-v5/V5_BREAKING_CHANGES.md +157 -0
- package/docs/ai-sdk-v5/V5_MIGRATION_PLAN.md +22 -0
- package/docs/ai-sdk-v5/V5_MIGRATION_SUMMARY.md +69 -0
- package/docs/ai-sdk-v5/V5_MIGRATION_TASKS.md +46 -0
- package/package.json +10 -9
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
# Community Provider Status Analysis (v5-beta)
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
This document analyzes the requirements for ai-sdk-provider-claude-code to achieve community provider status in the Vercel AI SDK v5-beta ecosystem.
|
|
5
|
+
|
|
6
|
+
## Current Implementation Status
|
|
7
|
+
|
|
8
|
+
### ✅ What We Have
|
|
9
|
+
|
|
10
|
+
#### Core Functionality
|
|
11
|
+
- **SDK Integration**: Uses official `@anthropic-ai/claude-code` SDK for all Claude interactions
|
|
12
|
+
- **Text Generation**: Full support for both streaming and non-streaming text generation with v5 patterns
|
|
13
|
+
- **Object Generation**: Reliable JSON generation through prompt engineering and extraction
|
|
14
|
+
- **Multi-turn Conversations**: Proper message history support with v5 message format
|
|
15
|
+
- **Provider Metadata**: Rich metadata including sessionId, costUsd, durationMs, and rawUsage
|
|
16
|
+
- **Error Handling**: Comprehensive error handling with authentication detection
|
|
17
|
+
- **AbortSignal Support**: Standard AI SDK pattern for timeouts and cancellation
|
|
18
|
+
|
|
19
|
+
#### v5-Beta Specific Features
|
|
20
|
+
- **LanguageModelV2 Implementation**: Fully compliant with `specificationVersion: 'v2'`
|
|
21
|
+
- **Stream-Start Event**: Properly emits initial stream event with warnings
|
|
22
|
+
- **Token Usage Naming**: Uses v5 convention (inputTokens, outputTokens, totalTokens)
|
|
23
|
+
- **Message Format**: Supports v5's array-based content structure
|
|
24
|
+
- **Promise-based Streaming**: Implements v5's new streaming API pattern
|
|
25
|
+
|
|
26
|
+
#### Build & Distribution
|
|
27
|
+
- **TypeScript**: Full TypeScript support with proper type definitions
|
|
28
|
+
- **Dual Formats**: Both CommonJS and ES Module builds via tsup
|
|
29
|
+
- **Source Maps**: Generated for debugging support
|
|
30
|
+
- **Package Structure**: Proper exports configuration for modern Node.js
|
|
31
|
+
- **Beta Tag**: Published with `beta` tag on npm
|
|
32
|
+
|
|
33
|
+
#### Testing
|
|
34
|
+
- **Unit Tests**: Comprehensive test coverage with Vitest
|
|
35
|
+
- **Integration Tests**: Full integration test suite
|
|
36
|
+
- **Edge/Node Tests**: Separate configurations for different environments
|
|
37
|
+
- **Examples**: Extensive example collection demonstrating all v5 features
|
|
38
|
+
|
|
39
|
+
#### Documentation
|
|
40
|
+
- **README**: Comprehensive documentation with version compatibility matrix
|
|
41
|
+
- **CHANGELOG**: Proper version history following Keep a Changelog format
|
|
42
|
+
- **Examples README**: Detailed guide for all example files
|
|
43
|
+
- **API Documentation**: Clear documentation of all configuration options
|
|
44
|
+
- **Migration Guide**: Comprehensive v4 to v5 migration documentation
|
|
45
|
+
|
|
46
|
+
### 🚀 Meeting AI SDK v5-Beta Standards
|
|
47
|
+
|
|
48
|
+
Based on analysis of official v5-beta providers, we now meet all requirements:
|
|
49
|
+
|
|
50
|
+
1. **Provider Pattern** ✅
|
|
51
|
+
- Factory function with provider instance
|
|
52
|
+
- Default export
|
|
53
|
+
- Proper settings interface
|
|
54
|
+
- Protection against `new` keyword misuse
|
|
55
|
+
|
|
56
|
+
2. **Language Model Implementation** ✅
|
|
57
|
+
- `specificationVersion: 'v2'`
|
|
58
|
+
- Correct `doGenerate` and `doStream` methods for v5
|
|
59
|
+
- Proper provider metadata
|
|
60
|
+
- Object generation support
|
|
61
|
+
- Stream-start event emission
|
|
62
|
+
|
|
63
|
+
3. **Build System** ✅
|
|
64
|
+
- tsup for dual format builds
|
|
65
|
+
- Source maps
|
|
66
|
+
- Proper package.json configuration
|
|
67
|
+
- Beta tag in publishConfig
|
|
68
|
+
|
|
69
|
+
4. **Testing** ✅
|
|
70
|
+
- Separate edge/node configurations
|
|
71
|
+
- Unit and integration tests
|
|
72
|
+
- Example test coverage
|
|
73
|
+
- All tests passing with v5 patterns
|
|
74
|
+
|
|
75
|
+
5. **Error Handling** ✅
|
|
76
|
+
- Standard AI SDK error classes
|
|
77
|
+
- Proper `isRetryable` flags
|
|
78
|
+
- AbortSignal support
|
|
79
|
+
|
|
80
|
+
## 📁 Current Project Structure
|
|
81
|
+
|
|
82
|
+
```
|
|
83
|
+
ai-sdk-provider-claude-code/
|
|
84
|
+
├── src/
|
|
85
|
+
│ ├── index.ts # Main exports
|
|
86
|
+
│ ├── claude-code-provider.ts # Provider factory
|
|
87
|
+
│ ├── claude-code-language-model.ts # Language model implementation (v2)
|
|
88
|
+
│ ├── convert-to-claude-code-messages.ts # Message formatting (v5 format)
|
|
89
|
+
│ ├── extract-json.ts # JSON extraction (using jsonc-parser)
|
|
90
|
+
│ ├── errors.ts # Error utilities
|
|
91
|
+
│ └── types.ts # TypeScript definitions
|
|
92
|
+
├── docs/
|
|
93
|
+
│ ├── ai-sdk-v4/ # v4-specific documentation (archived)
|
|
94
|
+
│ │ ├── GUIDE.md
|
|
95
|
+
│ │ ├── TROUBLESHOOTING.md
|
|
96
|
+
│ │ └── DEVELOPMENT-STATUS.md
|
|
97
|
+
│ └── ai-sdk-v5/ # v5-beta documentation
|
|
98
|
+
│ ├── GUIDE.md # v5-specific usage guide
|
|
99
|
+
│ ├── TROUBLESHOOTING.md # v5-specific troubleshooting
|
|
100
|
+
│ ├── DEVELOPMENT-STATUS.md # This document
|
|
101
|
+
│ ├── V5_BREAKING_CHANGES.md # User migration guide
|
|
102
|
+
│ ├── V5_MIGRATION_PLAN.md # Technical migration plan
|
|
103
|
+
│ ├── V5_MIGRATION_SUMMARY.md # Migration implementation summary
|
|
104
|
+
│ └── V5_MIGRATION_TASKS.md # Migration task tracking
|
|
105
|
+
├── examples/
|
|
106
|
+
│ ├── README.md # Examples guide
|
|
107
|
+
│ ├── basic-usage.ts # Simple generation (v5 pattern)
|
|
108
|
+
│ ├── streaming.ts # Streaming demo (v5 pattern)
|
|
109
|
+
│ ├── conversation-history.ts # Multi-turn conversations (v5 format)
|
|
110
|
+
│ ├── custom-config.ts # Configuration options
|
|
111
|
+
│ ├── generate-object-*.ts # Object generation examples
|
|
112
|
+
│ ├── tool-management.ts # Tool access control
|
|
113
|
+
│ ├── long-running-tasks.ts # Timeout handling
|
|
114
|
+
│ ├── abort-signal.ts # Cancellation
|
|
115
|
+
│ ├── integration-test.ts # Test suite
|
|
116
|
+
│ └── check-cli.ts # Setup verification
|
|
117
|
+
├── vitest.config.js # Test configuration
|
|
118
|
+
├── vitest.edge.config.js # Edge runtime tests
|
|
119
|
+
├── vitest.node.config.js # Node runtime tests
|
|
120
|
+
├── tsup.config.ts # Build configuration
|
|
121
|
+
├── package.json # Package metadata (v1.0.0-beta.1)
|
|
122
|
+
├── CHANGELOG.md # Version history
|
|
123
|
+
├── README.md # Main documentation with version matrix
|
|
124
|
+
└── LICENSE # MIT license
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## 🎯 Ready for Community Status
|
|
128
|
+
|
|
129
|
+
The provider now meets all requirements for v5-beta community provider status:
|
|
130
|
+
|
|
131
|
+
### Technical Requirements ✅
|
|
132
|
+
- Implements LanguageModelV2 specification
|
|
133
|
+
- Follows provider factory pattern
|
|
134
|
+
- Uses standard error handling
|
|
135
|
+
- Supports AbortSignal
|
|
136
|
+
- Has proper TypeScript types
|
|
137
|
+
- Includes comprehensive tests
|
|
138
|
+
- Emits stream-start event
|
|
139
|
+
- Uses v5 token naming convention
|
|
140
|
+
|
|
141
|
+
### Build Requirements ✅
|
|
142
|
+
- Uses tsup for builds
|
|
143
|
+
- Generates both CJS and ESM
|
|
144
|
+
- Includes source maps
|
|
145
|
+
- Has proper package.json configuration
|
|
146
|
+
- Published with beta tag
|
|
147
|
+
|
|
148
|
+
### Documentation Requirements ✅
|
|
149
|
+
- Comprehensive README with version compatibility
|
|
150
|
+
- CHANGELOG with version history
|
|
151
|
+
- Extensive examples using v5 patterns
|
|
152
|
+
- Clear setup instructions
|
|
153
|
+
- Migration guide from v4
|
|
154
|
+
|
|
155
|
+
## Version Strategy
|
|
156
|
+
|
|
157
|
+
- **0.x versions**: AI SDK v4 compatibility (maintained on `ai-sdk-v4` branch)
|
|
158
|
+
- **1.x-beta versions**: AI SDK v5-beta compatibility (maintained on `main` branch)
|
|
159
|
+
|
|
160
|
+
## Next Steps for Community Submission
|
|
161
|
+
|
|
162
|
+
1. **Publish to npm with beta tag**
|
|
163
|
+
```bash
|
|
164
|
+
npm publish --tag beta
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
2. **Prepare MDX Documentation**
|
|
168
|
+
Create a documentation file following the v5-beta community provider format (see example below)
|
|
169
|
+
|
|
170
|
+
3. **Submit PR to AI SDK Repository**
|
|
171
|
+
- Add provider to v5-beta community providers list
|
|
172
|
+
- Include MDX documentation
|
|
173
|
+
- Reference npm package with beta tag
|
|
174
|
+
|
|
175
|
+
## Example Community Provider MDX (v5-beta)
|
|
176
|
+
|
|
177
|
+
```mdx
|
|
178
|
+
---
|
|
179
|
+
title: Claude Code (v5-beta)
|
|
180
|
+
description: Use Claude via the official Claude Code SDK with your Pro/Max subscription
|
|
181
|
+
---
|
|
182
|
+
|
|
183
|
+
# Claude Code Provider (v5-beta)
|
|
184
|
+
|
|
185
|
+
[ben-vargas/ai-sdk-provider-claude-code](https://github.com/ben-vargas/ai-sdk-provider-claude-code)
|
|
186
|
+
is a community provider that uses the official [Claude Code SDK](https://www.npmjs.com/package/@anthropic-ai/claude-code)
|
|
187
|
+
to provide language model support for the AI SDK v5-beta.
|
|
188
|
+
|
|
189
|
+
<Note type="warning">
|
|
190
|
+
This is the v5-beta compatible version. For AI SDK v4 support, use version 0.2.x.
|
|
191
|
+
</Note>
|
|
192
|
+
|
|
193
|
+
## Setup
|
|
194
|
+
|
|
195
|
+
The Claude Code provider is available in the `ai-sdk-provider-claude-code` module. You can install it with:
|
|
196
|
+
|
|
197
|
+
<Tabs items={['pnpm', 'npm', 'yarn']}>
|
|
198
|
+
<Tab>
|
|
199
|
+
<Snippet text="pnpm add ai-sdk-provider-claude-code@beta ai@beta" dark />
|
|
200
|
+
</Tab>
|
|
201
|
+
<Tab>
|
|
202
|
+
<Snippet text="npm install ai-sdk-provider-claude-code@beta ai@beta" dark />
|
|
203
|
+
</Tab>
|
|
204
|
+
<Tab>
|
|
205
|
+
<Snippet text="yarn add ai-sdk-provider-claude-code@beta ai@beta" dark />
|
|
206
|
+
</Tab>
|
|
207
|
+
</Tabs>
|
|
208
|
+
|
|
209
|
+
### Prerequisites
|
|
210
|
+
|
|
211
|
+
Install and authenticate the Claude Code SDK:
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
npm install -g @anthropic-ai/claude-code
|
|
215
|
+
claude login
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## Provider Instance
|
|
219
|
+
|
|
220
|
+
You can import the default provider instance `claudeCode` from `ai-sdk-provider-claude-code`:
|
|
221
|
+
|
|
222
|
+
```ts
|
|
223
|
+
import { claudeCode } from 'ai-sdk-provider-claude-code';
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
## Language Models
|
|
227
|
+
|
|
228
|
+
The Claude Code provider supports the following models:
|
|
229
|
+
|
|
230
|
+
- `sonnet` - Claude 4 Sonnet (balanced speed and capability)
|
|
231
|
+
- `opus` - Claude 4 Opus (most capable)
|
|
232
|
+
|
|
233
|
+
```ts
|
|
234
|
+
import { generateText } from 'ai';
|
|
235
|
+
import { claudeCode } from 'ai-sdk-provider-claude-code';
|
|
236
|
+
|
|
237
|
+
const result = await generateText({
|
|
238
|
+
model: claudeCode('sonnet'),
|
|
239
|
+
prompt: 'Explain recursion in one sentence',
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
console.log(result.text);
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
### Model Capabilities
|
|
246
|
+
|
|
247
|
+
| Model | Text Generation | Object Generation | Image Input | AI SDK Tool Calling | MCP Tools |
|
|
248
|
+
|-------|----------------|-------------------|-------------|---------------------|-----------|
|
|
249
|
+
| opus | ✅ | ✅ | ❌ | ❌ | ✅ |
|
|
250
|
+
| sonnet | ✅ | ✅ | ❌ | ❌ | ✅ |
|
|
251
|
+
|
|
252
|
+
<Note>
|
|
253
|
+
The provider uses the official Claude Code SDK. While the models support tool use, this provider
|
|
254
|
+
doesn't implement the AI SDK's tool calling interface. However, you can configure MCP servers
|
|
255
|
+
for tool functionality, and Claude can use built-in tools (Bash, Read, Write, etc.) through
|
|
256
|
+
the Claude Code SDK.
|
|
257
|
+
</Note>
|
|
258
|
+
|
|
259
|
+
## v5-Beta Specific Features
|
|
260
|
+
|
|
261
|
+
This version includes full support for AI SDK v5-beta features:
|
|
262
|
+
|
|
263
|
+
- **New streaming API** with promise-based result objects
|
|
264
|
+
- **Updated token usage** properties (inputTokens, outputTokens, totalTokens)
|
|
265
|
+
- **Stream-start events** for better stream initialization
|
|
266
|
+
- **Array-based message content** format
|
|
267
|
+
|
|
268
|
+
```ts
|
|
269
|
+
// v5 streaming pattern
|
|
270
|
+
const result = streamText({
|
|
271
|
+
model: claudeCode('sonnet'),
|
|
272
|
+
prompt: 'Write a haiku',
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
const text = await result.text;
|
|
276
|
+
const usage = await result.usage;
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
See the [migration guide](https://github.com/ben-vargas/ai-sdk-provider-claude-code/blob/main/docs/ai-sdk-v5/V5_BREAKING_CHANGES.md) for details on upgrading from v0.x to v1.x-beta.
|
|
280
|
+
```
|