ai-pro-sdk 2.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Ben Vargas
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,84 @@
1
+ <p align="center">
2
+ <img src="https://img.shields.io/badge/status-stable-00A79E" alt="stable status">
3
+ <a href="https://www.npmjs.com/package/ai-pro-sdk"><img src="https://img.shields.io/npm/v/ai-pro-sdk?color=00A79E" alt="npm version" /></a>
4
+ <a href="https://www.npmjs.com/package/ai-pro-sdk"><img src="https://img.shields.io/npm/unpacked-size/ai-pro-sdk?color=00A79E" alt="install size" /></a>
5
+ <a href="https://www.npmjs.com/package/ai-pro-sdk"><img src="https://img.shields.io/npm/dy/ai-pro-sdk.svg?color=00A79E" alt="npm downloads" /></a>
6
+ <a href="https://nodejs.org/en/about/releases/"><img src="https://img.shields.io/badge/node-%3E%3D22-00A79E" alt="Node.js ≥ 22" /></a>
7
+ <a href="https://www.npmjs.com/package/ai-pro-sdk"><img src="https://img.shields.io/npm/l/ai-pro-sdk?color=00A79E" alt="License: MIT" /></a>
8
+ </p>
9
+
10
+ # AI Pro SDK
11
+
12
+ AI Pro SDK is a Vercel AI SDK provider for Claude that uses the Claude Agent SDK and the Claude Code CLI. It is designed for Claude Pro and Max workflows and exposes the Claude Code experience through the standard AI SDK model interface.
13
+
14
+ ## Features
15
+
16
+ - AI SDK v7 compatibility
17
+ - Streaming responses with tool and session support
18
+ - Structured output support via the AI SDK output API
19
+ - Claude Agent SDK callbacks, hooks, MCP integration, and session controls
20
+ - Support for Claude Code CLI authentication and configuration
21
+
22
+ ## Installation
23
+
24
+ Install the package alongside the AI SDK and Zod:
25
+
26
+ ```bash
27
+ npm install ai-pro-sdk ai zod@^4.1.8
28
+ ```
29
+
30
+ Authenticate the Claude Code CLI:
31
+
32
+ ```bash
33
+ curl -fsSL https://claude.ai/install.sh | bash
34
+ claude auth login
35
+ ```
36
+
37
+ ## Quick start
38
+
39
+ ```ts
40
+ import { streamText } from 'ai';
41
+ import { claudeCode } from 'ai-pro-sdk';
42
+
43
+ const result = streamText({
44
+ model: claudeCode('haiku'),
45
+ prompt: 'Hello from AI Pro SDK!',
46
+ });
47
+
48
+ console.log(await result.text);
49
+ ```
50
+
51
+ ## Configuration example
52
+
53
+ You can pass Claude Code settings directly when you create the model:
54
+
55
+ ```ts
56
+ import { streamText } from 'ai';
57
+ import { claudeCode } from 'ai-pro-sdk';
58
+
59
+ const result = streamText({
60
+ model: claudeCode('sonnet', {
61
+ persistSession: false,
62
+ settingSources: ['user', 'project'],
63
+ }),
64
+ prompt: 'Summarize the latest deployment log.',
65
+ });
66
+
67
+ console.log(await result.text);
68
+ ```
69
+
70
+ ## Documentation
71
+
72
+ - [Session management](docs/sessions.md)
73
+ - [AI SDK v5 migration notes](docs/ai-sdk-v5/V5_MIGRATION_SUMMARY.md)
74
+ - [Development status](docs/ai-sdk-v5/DEVELOPMENT-STATUS.md)
75
+
76
+ ## Notes
77
+
78
+ - Requires Node.js 22 or newer.
79
+ - This package is unofficial and community-maintained; it is not affiliated with Anthropic or Vercel.
80
+ - For advanced usage, refer to the Claude Code CLI documentation and the examples in the repository.
81
+
82
+ ## License
83
+
84
+ MIT
@@ -0,0 +1,231 @@
1
+ # Community Provider Status Analysis
2
+
3
+ ## Overview
4
+
5
+ This document analyzes the requirements for ai-sdk-provider-claude-code to achieve community provider status in the Vercel AI SDK ecosystem.
6
+
7
+ ## Current Implementation Status
8
+
9
+ ### ✅ What We Have
10
+
11
+ #### Core Functionality
12
+
13
+ - **SDK Integration**: Uses official `@anthropic-ai/claude-code` SDK for all Claude interactions
14
+ - **Text Generation**: Full support for both streaming and non-streaming text generation
15
+ - **Object Generation**: Reliable JSON generation through prompt engineering and extraction
16
+ - **Multi-turn Conversations**: Proper message history support (recommended AI SDK pattern)
17
+ - **Provider Metadata**: Rich metadata including sessionId, costUsd, durationMs, and rawUsage
18
+ - **Error Handling**: Comprehensive error handling with authentication detection
19
+ - **AbortSignal Support**: Standard AI SDK pattern for timeouts and cancellation
20
+
21
+ #### Build & Distribution
22
+
23
+ - **TypeScript**: Full TypeScript support with proper type definitions
24
+ - **Dual Formats**: Both CommonJS and ES Module builds via tsup
25
+ - **Source Maps**: Generated for debugging support
26
+ - **Package Structure**: Proper exports configuration for modern Node.js
27
+
28
+ #### Testing
29
+
30
+ - **Unit Tests**: Comprehensive test coverage with Vitest
31
+ - **Integration Tests**: Full integration test suite
32
+ - **Edge/Node Tests**: Separate configurations for different environments
33
+ - **Examples**: Extensive example collection demonstrating all features
34
+
35
+ #### Documentation
36
+
37
+ - **README**: Comprehensive documentation with examples
38
+ - **CHANGELOG**: Proper version history following Keep a Changelog format
39
+ - **Examples README**: Detailed guide for all example files
40
+ - **API Documentation**: Clear documentation of all configuration options
41
+
42
+ ### 🚀 Meeting AI SDK Standards
43
+
44
+ Based on analysis of official providers (Mistral, OpenAI, etc.), we now meet all requirements:
45
+
46
+ 1. **Provider Pattern** ✅
47
+ - Factory function with provider instance
48
+ - Default export
49
+ - Proper settings interface
50
+ - Protection against `new` keyword misuse
51
+
52
+ 2. **Language Model Implementation** ✅
53
+ - `specificationVersion: 'v1'`
54
+ - Correct `doGenerate` and `doStream` methods
55
+ - Proper provider metadata
56
+ - Object generation support
57
+
58
+ 3. **Build System** ✅
59
+ - tsup for dual format builds
60
+ - Source maps
61
+ - Proper package.json configuration
62
+
63
+ 4. **Testing** ✅
64
+ - Separate edge/node configurations
65
+ - Unit and integration tests
66
+ - Example test coverage
67
+
68
+ 5. **Error Handling** ✅
69
+ - Standard AI SDK error classes
70
+ - Proper `isRetryable` flags
71
+ - AbortSignal support
72
+
73
+ ## 📁 Current Project Structure
74
+
75
+ ```
76
+ ai-sdk-provider-claude-code/
77
+ ├── src/
78
+ │ ├── index.ts # Main exports
79
+ │ ├── claude-code-provider.ts # Provider factory
80
+ │ ├── claude-code-language-model.ts # Language model implementation
81
+ │ ├── convert-to-claude-code-messages.ts # Message formatting
82
+ │ ├── extract-json.ts # JSON extraction (using jsonc-parser)
83
+ │ ├── errors.ts # Error utilities
84
+ │ └── types.ts # TypeScript definitions
85
+ ├── docs/
86
+ │ ├── GUIDE.md # Comprehensive usage guide
87
+ │ ├── TROUBLESHOOTING.md # Common issues and solutions
88
+ │ └── DEVELOPMENT-STATUS.md # This document
89
+ ├── examples/
90
+ │ ├── README.md # Examples guide
91
+ │ ├── basic-usage.ts # Simple generation
92
+ │ ├── streaming.ts # Streaming demo
93
+ │ ├── conversation-history.ts # Multi-turn conversations
94
+ │ ├── custom-config.ts # Configuration options
95
+ │ ├── generate-object-*.ts # Object generation examples
96
+ │ ├── tool-management.ts # Tool access control
97
+ │ ├── long-running-tasks.ts # Timeout handling
98
+ │ ├── abort-signal.ts # Cancellation
99
+ │ ├── integration-test.ts # Test suite
100
+ │ └── check-cli.ts # Setup verification
101
+ ├── vitest.config.js # Test configuration
102
+ ├── vitest.edge.config.js # Edge runtime tests
103
+ ├── vitest.node.config.js # Node runtime tests
104
+ ├── tsup.config.ts # Build configuration
105
+ ├── package.json # Package metadata
106
+ ├── CHANGELOG.md # Version history
107
+ ├── README.md # Concise getting started guide
108
+ └── LICENSE # MIT license
109
+ ```
110
+
111
+ ## 🎯 Ready for Community Status
112
+
113
+ The provider now meets all requirements for community provider status:
114
+
115
+ ### Technical Requirements ✅
116
+
117
+ - Implements LanguageModelV1 specification
118
+ - Follows provider factory pattern
119
+ - Uses standard error handling
120
+ - Supports AbortSignal
121
+ - Has proper TypeScript types
122
+ - Includes comprehensive tests
123
+
124
+ ### Build Requirements ✅
125
+
126
+ - Uses tsup for builds
127
+ - Generates both CJS and ESM
128
+ - Includes source maps
129
+ - Has proper package.json configuration
130
+
131
+ ### Documentation Requirements ✅
132
+
133
+ - Comprehensive README
134
+ - CHANGELOG with version history
135
+ - Extensive examples
136
+ - Clear setup instructions
137
+
138
+ ## Next Steps for Community Submission
139
+
140
+ 1. **Publish to npm**
141
+
142
+ ```bash
143
+ npm publish
144
+ ```
145
+
146
+ 2. **Prepare MDX Documentation**
147
+ Create a documentation file following the community provider format (see example below)
148
+
149
+ 3. **Submit PR to AI SDK Repository**
150
+ - Add provider to community providers list
151
+ - Include MDX documentation
152
+ - Reference npm package
153
+
154
+ ## Example Community Provider MDX
155
+
156
+ ````mdx
157
+ ---
158
+ title: Claude Code
159
+ description: Use Claude via the official Claude Code SDK with your Pro/Max subscription
160
+ ---
161
+
162
+ # Claude Code Provider
163
+
164
+ [ben-vargas/ai-sdk-provider-claude-code](https://github.com/ben-vargas/ai-sdk-provider-claude-code)
165
+ is a community provider that uses the official [Claude Code SDK](https://www.npmjs.com/package/@anthropic-ai/claude-code)
166
+ to provide language model support for the AI SDK.
167
+
168
+ ## Setup
169
+
170
+ The Claude Code provider is available in the `ai-sdk-provider-claude-code` module. You can install it with:
171
+
172
+ <Tabs items={['pnpm', 'npm', 'yarn']}>
173
+ <Tab>
174
+ <Snippet text="pnpm add ai-sdk-provider-claude-code" dark />
175
+ </Tab>
176
+ <Tab>
177
+ <Snippet text="npm install ai-sdk-provider-claude-code" dark />
178
+ </Tab>
179
+ <Tab>
180
+ <Snippet text="yarn add ai-sdk-provider-claude-code" dark />
181
+ </Tab>
182
+ </Tabs>
183
+
184
+ ### Prerequisites
185
+
186
+ Install and authenticate the Claude Code SDK:
187
+
188
+ ```bash
189
+ npm install -g @anthropic-ai/claude-code
190
+ claude login
191
+ ```
192
+ ````
193
+
194
+ ## Provider Instance
195
+
196
+ You can import the default provider instance `claudeCode` from `ai-sdk-provider-claude-code`:
197
+
198
+ ```ts
199
+ import { claudeCode } from 'ai-sdk-provider-claude-code';
200
+ ```
201
+
202
+ ## Language Models
203
+
204
+ The Claude Code provider supports the following models:
205
+
206
+ - `sonnet` - Claude 4 Sonnet (balanced speed and capability)
207
+ - `opus` - Claude 4 Opus (most capable)
208
+
209
+ ```ts
210
+ import { generateText } from 'ai';
211
+ import { claudeCode } from 'ai-sdk-provider-claude-code';
212
+
213
+ const { text } = await generateText({
214
+ model: claudeCode('sonnet'),
215
+ prompt: 'Explain recursion in one sentence',
216
+ });
217
+ ```
218
+
219
+ ### Model Capabilities
220
+
221
+ | Model | Text Generation | Object Generation | Image Input | AI SDK Tool Calling | MCP Tools |
222
+ | ------ | --------------- | ----------------- | ----------- | ------------------- | --------- |
223
+ | opus | ✅ | ✅ | ❌ | ❌ | ✅ |
224
+ | sonnet | ✅ | ✅ | ❌ | ❌ | ✅ |
225
+
226
+ <Note>
227
+ The provider uses the official Claude Code SDK. While the models support tool use, this provider
228
+ doesn't implement the AI SDK's tool calling interface. However, you can configure MCP servers
229
+ for tool functionality, and Claude can use built-in tools (Bash, Read, Write, etc.) through
230
+ the Claude Code SDK.
231
+ </Note>