@flink-app/anthropic-adapter 2.0.0-alpha.48
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 +284 -0
- package/dist/AnthropicAdapter.d.ts +135 -0
- package/dist/AnthropicAdapter.d.ts.map +1 -0
- package/dist/AnthropicAdapter.js +352 -0
- package/dist/AnthropicAdapter.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/package.json +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Frost Experience AB https://www.frost.se
|
|
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
|
|
13
|
+
all 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
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
# @flink-app/anthropic-adapter
|
|
2
|
+
|
|
3
|
+
Anthropic Claude adapter for the Flink AI framework. Provides seamless integration with Anthropic's Claude models.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @flink-app/anthropic-adapter
|
|
9
|
+
# or
|
|
10
|
+
pnpm add @flink-app/anthropic-adapter
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
The `@anthropic-ai/sdk` package is included as a dependency, so you don't need to install it separately.
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
### Basic Setup
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { AnthropicAdapter } from "@flink-app/anthropic-adapter";
|
|
21
|
+
import { FlinkApp } from "@flink-app/flink";
|
|
22
|
+
|
|
23
|
+
const app = new FlinkApp({
|
|
24
|
+
ai: {
|
|
25
|
+
llms: {
|
|
26
|
+
default: new AnthropicAdapter({
|
|
27
|
+
apiKey: process.env.ANTHROPIC_API_KEY!,
|
|
28
|
+
model: "claude-sonnet-4-5-20250929"
|
|
29
|
+
}),
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
await app.start();
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
**Legacy API (still supported):**
|
|
38
|
+
```typescript
|
|
39
|
+
// Backward-compatible constructor
|
|
40
|
+
new AnthropicAdapter(process.env.ANTHROPIC_API_KEY!, "claude-sonnet-4-5-20250929")
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Agent Instructions
|
|
44
|
+
|
|
45
|
+
Define your agent's behavior using the `instructions` property:
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
// src/agents/support_agent.ts
|
|
49
|
+
export const Agent: FlinkAgentProps = {
|
|
50
|
+
name: "support_agent",
|
|
51
|
+
instructions: "You are a helpful customer support agent.",
|
|
52
|
+
tools: ["get_order_status"],
|
|
53
|
+
model: { adapterId: "default" },
|
|
54
|
+
};
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**How it works:**
|
|
58
|
+
- Instructions are prepended as a system message to every conversation
|
|
59
|
+
- Follows Vercel AI SDK pattern for consistency
|
|
60
|
+
- Provides stable agent behavior across all interactions
|
|
61
|
+
|
|
62
|
+
#### Dynamic Context with System Messages
|
|
63
|
+
|
|
64
|
+
For per-request context, add system messages to the conversation:
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
const result = await ctx.agents.myAgent.execute({
|
|
68
|
+
message: [
|
|
69
|
+
{ role: "system", content: "Current user tier: Premium" },
|
|
70
|
+
{ role: "user", content: "What can I do?" }
|
|
71
|
+
]
|
|
72
|
+
});
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
**Order of messages sent to Anthropic:**
|
|
76
|
+
1. Agent `instructions` (as system message)
|
|
77
|
+
2. User-provided system messages (if any)
|
|
78
|
+
3. Conversation messages
|
|
79
|
+
|
|
80
|
+
This gives you both static agent behavior and dynamic per-request context.
|
|
81
|
+
|
|
82
|
+
## Multiple Adapters
|
|
83
|
+
|
|
84
|
+
You can register multiple Anthropic adapters with different configurations:
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
import { AnthropicAdapter } from "@flink-app/anthropic-adapter";
|
|
88
|
+
import { FlinkApp } from "@flink-app/flink";
|
|
89
|
+
|
|
90
|
+
const app = new FlinkApp({
|
|
91
|
+
ai: {
|
|
92
|
+
llms: {
|
|
93
|
+
// Default Sonnet 4.5 model - best balance of intelligence, speed, and cost
|
|
94
|
+
default: new AnthropicAdapter({
|
|
95
|
+
apiKey: process.env.ANTHROPIC_API_KEY!,
|
|
96
|
+
model: "claude-sonnet-4-5-20250929"
|
|
97
|
+
}),
|
|
98
|
+
|
|
99
|
+
// Fast Haiku 4.5 model for simple tasks - near-frontier performance at lower cost
|
|
100
|
+
fast: new AnthropicAdapter({
|
|
101
|
+
apiKey: process.env.ANTHROPIC_API_KEY!,
|
|
102
|
+
model: "claude-haiku-4-5-20251001"
|
|
103
|
+
}),
|
|
104
|
+
|
|
105
|
+
// Opus 4.5 model for complex tasks - maximum intelligence
|
|
106
|
+
smart: new AnthropicAdapter({
|
|
107
|
+
apiKey: process.env.ANTHROPIC_API_KEY!,
|
|
108
|
+
model: "claude-opus-4-5-20251101"
|
|
109
|
+
}),
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Using in Agents
|
|
116
|
+
|
|
117
|
+
Reference the adapter by its registered ID in your agent configuration:
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
// src/agents/support_agent.ts
|
|
121
|
+
import { FlinkAgentProps } from "@flink-app/flink";
|
|
122
|
+
|
|
123
|
+
export const Agent: FlinkAgentProps = {
|
|
124
|
+
name: "support_agent",
|
|
125
|
+
description: "Customer support assistant",
|
|
126
|
+
instructions: "You are a helpful customer support agent.",
|
|
127
|
+
tools: ["get_order_status"],
|
|
128
|
+
model: {
|
|
129
|
+
adapterId: "default", // Uses the "default" adapter
|
|
130
|
+
maxTokens: 1000,
|
|
131
|
+
temperature: 0.7,
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Supported Models
|
|
137
|
+
|
|
138
|
+
This adapter works with all Claude models. The latest Claude 4.5 models offer significant improvements over previous generations:
|
|
139
|
+
|
|
140
|
+
### Claude 4.5 Models (Recommended)
|
|
141
|
+
|
|
142
|
+
- **Claude Sonnet 4.5**: `claude-sonnet-4-5-20250929` (recommended for most use cases)
|
|
143
|
+
- Best balance of intelligence, speed, and cost
|
|
144
|
+
- Exceptional performance in coding and agentic tasks
|
|
145
|
+
- 200K context window (1M in beta with header)
|
|
146
|
+
- Pricing: $3/MTok input, $15/MTok output
|
|
147
|
+
|
|
148
|
+
- **Claude Haiku 4.5**: `claude-haiku-4-5-20251001` (fastest)
|
|
149
|
+
- Near-frontier performance at a fraction of the cost
|
|
150
|
+
- Optimized for speed and cost-efficiency
|
|
151
|
+
- 200K context window
|
|
152
|
+
- Pricing: $1/MTok input, $5/MTok output
|
|
153
|
+
|
|
154
|
+
- **Claude Opus 4.5**: `claude-opus-4-5-20251101` (most capable)
|
|
155
|
+
- Maximum intelligence for complex tasks
|
|
156
|
+
- Industry leader in coding, agents, and enterprise workflows
|
|
157
|
+
- 200K context window
|
|
158
|
+
- Pricing: $5/MTok input, $25/MTok output
|
|
159
|
+
|
|
160
|
+
### Legacy Models
|
|
161
|
+
|
|
162
|
+
For backwards compatibility, legacy Claude 3 and 4 models are still supported:
|
|
163
|
+
|
|
164
|
+
- **Claude Opus 4.1**: `claude-opus-4-1-20250805`
|
|
165
|
+
- **Claude Sonnet 4**: `claude-sonnet-4-20250514`
|
|
166
|
+
- **Claude 3.7 Sonnet**: `claude-3-7-sonnet-20250219`
|
|
167
|
+
- **Claude Opus 4**: `claude-opus-4-20250514`
|
|
168
|
+
- **Claude 3 Haiku**: `claude-3-haiku-20240307`
|
|
169
|
+
|
|
170
|
+
We recommend migrating to Claude 4.5 models for improved performance and capabilities.
|
|
171
|
+
|
|
172
|
+
### Model Aliases vs Specific Versions
|
|
173
|
+
|
|
174
|
+
Anthropic provides both specific version IDs and aliases:
|
|
175
|
+
|
|
176
|
+
- **Specific versions** (e.g., `claude-sonnet-4-5-20250929`): Fixed model snapshots that never change
|
|
177
|
+
- Recommended for production to ensure consistent behavior
|
|
178
|
+
- Snapshot date indicates the exact model version
|
|
179
|
+
|
|
180
|
+
- **Aliases** (e.g., `claude-sonnet-4-5`): Automatically point to the latest snapshot
|
|
181
|
+
- Useful for development and experimentation
|
|
182
|
+
- Updated within a week of new releases
|
|
183
|
+
- May change behavior when new snapshots are released
|
|
184
|
+
|
|
185
|
+
Example:
|
|
186
|
+
```typescript
|
|
187
|
+
// Production: Use specific version for stability
|
|
188
|
+
new AnthropicAdapter(apiKey, "claude-sonnet-4-5-20250929")
|
|
189
|
+
|
|
190
|
+
// Development: Use alias to always get latest improvements
|
|
191
|
+
new AnthropicAdapter(apiKey, "claude-sonnet-4-5")
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## Features
|
|
195
|
+
|
|
196
|
+
- ✅ Full tool calling support with automatic schema sanitization
|
|
197
|
+
- ✅ Streaming with event-based updates
|
|
198
|
+
- ✅ Proper message conversion and system instruction handling
|
|
199
|
+
- ✅ Comprehensive error handling with helpful messages
|
|
200
|
+
- ✅ Token usage tracking
|
|
201
|
+
- ✅ Debug logging for tool calls
|
|
202
|
+
- ✅ Support for all Claude 4.5 models
|
|
203
|
+
- ✅ 200K token context window (1M in beta)
|
|
204
|
+
- ✅ Extended thinking capabilities
|
|
205
|
+
|
|
206
|
+
### Claude 4.5 Capabilities
|
|
207
|
+
|
|
208
|
+
All Claude 4.5 models support:
|
|
209
|
+
- **Extended Thinking**: Enhanced reasoning for complex problems
|
|
210
|
+
- **Vision**: Process and analyze images alongside text
|
|
211
|
+
- **Multilingual**: Strong performance across multiple languages
|
|
212
|
+
- **Long Context**: 200K tokens standard, 1M tokens in beta
|
|
213
|
+
- **Tool Use**: Sophisticated function calling and tool integration
|
|
214
|
+
|
|
215
|
+
## API
|
|
216
|
+
|
|
217
|
+
### `AnthropicAdapter`
|
|
218
|
+
|
|
219
|
+
```typescript
|
|
220
|
+
interface AnthropicAdapterOptions {
|
|
221
|
+
apiKey: string;
|
|
222
|
+
model: string;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
class AnthropicAdapter implements LLMAdapter {
|
|
226
|
+
constructor(options: AnthropicAdapterOptions);
|
|
227
|
+
constructor(apiKey: string, model: string); // Legacy
|
|
228
|
+
}
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
#### Parameters
|
|
232
|
+
|
|
233
|
+
- `apiKey`: Your Anthropic API key
|
|
234
|
+
- `model`: The Claude model to use (e.g., "claude-sonnet-4-5-20250929")
|
|
235
|
+
|
|
236
|
+
### Error Handling
|
|
237
|
+
|
|
238
|
+
The adapter provides comprehensive error handling with helpful messages:
|
|
239
|
+
|
|
240
|
+
- **400 Bad Request**: Invalid model name, malformed messages, or invalid tool schemas
|
|
241
|
+
- **401 Unauthorized**: Invalid API key - check your ANTHROPIC_API_KEY
|
|
242
|
+
- **403 Forbidden**: Insufficient permissions or account limitations
|
|
243
|
+
- **429 Too Many Requests**: Rate limit exceeded - consider retry logic
|
|
244
|
+
- **500/529 Server Error**: Temporary issue with Anthropic's servers - retry recommended
|
|
245
|
+
|
|
246
|
+
All errors include the model name and specific guidance for resolution.
|
|
247
|
+
|
|
248
|
+
#### Model Selection Tips
|
|
249
|
+
|
|
250
|
+
- Use **Sonnet 4.5** (`claude-sonnet-4-5-20250929`) as your default - it provides the best balance for most applications
|
|
251
|
+
- Use **Haiku 4.5** (`claude-haiku-4-5-20251001`) for high-volume, cost-sensitive workloads where speed matters
|
|
252
|
+
- Use **Opus 4.5** (`claude-opus-4-5-20251101`) for complex reasoning, advanced coding, or when maximum intelligence is required
|
|
253
|
+
|
|
254
|
+
You can also use model aliases like `claude-sonnet-4-5` which automatically point to the latest snapshot, though specific version IDs are recommended for production to ensure consistent behavior.
|
|
255
|
+
|
|
256
|
+
## Migrating from Claude 3 to Claude 4.5
|
|
257
|
+
|
|
258
|
+
If you're currently using Claude 3 models, simply update the model ID in your adapter configuration:
|
|
259
|
+
|
|
260
|
+
```typescript
|
|
261
|
+
// Before (Claude 3.5 Sonnet)
|
|
262
|
+
new AnthropicAdapter(apiKey, "claude-3-5-sonnet-20241022")
|
|
263
|
+
|
|
264
|
+
// After (Claude Sonnet 4.5)
|
|
265
|
+
new AnthropicAdapter(apiKey, "claude-sonnet-4-5-20250929")
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
Benefits of upgrading to Claude 4.5:
|
|
269
|
+
- **Better performance**: Improved reasoning and coding capabilities
|
|
270
|
+
- **Extended thinking**: Built-in support for complex problem-solving
|
|
271
|
+
- **Lower latency**: Faster response times (especially Haiku 4.5)
|
|
272
|
+
- **Better cost efficiency**: Haiku 4.5 offers near-frontier performance at lower cost
|
|
273
|
+
|
|
274
|
+
The adapter handles all API differences automatically - no code changes required beyond the model ID.
|
|
275
|
+
|
|
276
|
+
## Requirements
|
|
277
|
+
|
|
278
|
+
- Node.js >= 18
|
|
279
|
+
- @flink-app/flink >= 1.0.0
|
|
280
|
+
- @anthropic-ai/sdk >= 0.30.0
|
|
281
|
+
|
|
282
|
+
## License
|
|
283
|
+
|
|
284
|
+
MIT
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import type { FlinkToolSchema, LLMAdapter, LLMMessage, LLMStreamChunk } from "@flink-app/flink/ai";
|
|
2
|
+
export interface AnthropicAdapterOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Anthropic API key
|
|
5
|
+
*/
|
|
6
|
+
apiKey: string;
|
|
7
|
+
/**
|
|
8
|
+
* Model to use (e.g., "claude-sonnet-4-5-20250929", "claude-opus-4-5-20251101")
|
|
9
|
+
*/
|
|
10
|
+
model: string;
|
|
11
|
+
/**
|
|
12
|
+
* Optional: Enable debug logging for development and troubleshooting
|
|
13
|
+
*
|
|
14
|
+
* When enabled, logs:
|
|
15
|
+
* - Full request parameters sent to Anthropic
|
|
16
|
+
* - Tool call decisions made by the LLM
|
|
17
|
+
* - Token usage and performance metrics
|
|
18
|
+
*
|
|
19
|
+
* @default false
|
|
20
|
+
*/
|
|
21
|
+
debug?: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Anthropic Claude adapter for Flink AI framework
|
|
25
|
+
*
|
|
26
|
+
* Provides integration with Anthropic's Claude models via the Messages API.
|
|
27
|
+
* Supports tool calling, handles message formatting between Flink's standardized
|
|
28
|
+
* format and Anthropic's API format, and provides robust error handling.
|
|
29
|
+
*
|
|
30
|
+
* ## Architecture
|
|
31
|
+
*
|
|
32
|
+
* This adapter implements the LLMAdapter interface and handles:
|
|
33
|
+
* - Message conversion from Flink format to Anthropic format
|
|
34
|
+
* - System instructions merging (instructions + system messages)
|
|
35
|
+
* - Tool schema sanitization for Anthropic compatibility
|
|
36
|
+
* - Streaming event processing
|
|
37
|
+
* - Comprehensive error handling
|
|
38
|
+
*
|
|
39
|
+
* ## System Instructions
|
|
40
|
+
*
|
|
41
|
+
* The adapter prepends Flink's `instructions` parameter as a system message,
|
|
42
|
+
* following the Vercel AI SDK pattern. Additional system messages in the
|
|
43
|
+
* messages array are also included and merged into the system prompt.
|
|
44
|
+
*
|
|
45
|
+
* ## Basic Usage
|
|
46
|
+
* ```typescript
|
|
47
|
+
* import { AnthropicAdapter } from "@flink-app/anthropic-adapter";
|
|
48
|
+
* import { FlinkApp } from "@flink-app/flink";
|
|
49
|
+
*
|
|
50
|
+
* const app = new FlinkApp({
|
|
51
|
+
* ai: {
|
|
52
|
+
* llms: {
|
|
53
|
+
* default: new AnthropicAdapter({
|
|
54
|
+
* apiKey: process.env.ANTHROPIC_API_KEY!,
|
|
55
|
+
* model: "claude-sonnet-4-5-20250929"
|
|
56
|
+
* }),
|
|
57
|
+
* },
|
|
58
|
+
* },
|
|
59
|
+
* });
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* ## Features
|
|
63
|
+
* - ✅ Full tool calling support
|
|
64
|
+
* - ✅ Streaming with event-based updates
|
|
65
|
+
* - ✅ Proper message conversion and system instruction handling
|
|
66
|
+
* - ✅ Schema sanitization for tool compatibility
|
|
67
|
+
* - ✅ Comprehensive error handling with helpful messages
|
|
68
|
+
* - ✅ Token usage tracking
|
|
69
|
+
* - ✅ Debug logging for tool calls
|
|
70
|
+
*/
|
|
71
|
+
export declare class AnthropicAdapter implements LLMAdapter<FlinkToolSchema> {
|
|
72
|
+
private client;
|
|
73
|
+
private model;
|
|
74
|
+
debug: boolean;
|
|
75
|
+
constructor(options: AnthropicAdapterOptions);
|
|
76
|
+
constructor(apiKey: string, model: string);
|
|
77
|
+
stream(params: {
|
|
78
|
+
instructions: string;
|
|
79
|
+
messages: LLMMessage[];
|
|
80
|
+
tools: FlinkToolSchema[];
|
|
81
|
+
maxTokens: number;
|
|
82
|
+
temperature: number;
|
|
83
|
+
}): AsyncGenerator<LLMStreamChunk>;
|
|
84
|
+
/**
|
|
85
|
+
* Convert Flink messages to Anthropic format
|
|
86
|
+
*
|
|
87
|
+
* Anthropic requires:
|
|
88
|
+
* 1. System instructions in top-level 'system' parameter (not in messages array)
|
|
89
|
+
* 2. Messages array with user/assistant alternation
|
|
90
|
+
* 3. Tool results must be in user messages as content blocks
|
|
91
|
+
*
|
|
92
|
+
* This method:
|
|
93
|
+
* - Merges instructions + system messages into a single system prompt
|
|
94
|
+
* - Converts content blocks to Anthropic format
|
|
95
|
+
* - Handles text, tool_use, and tool_result blocks
|
|
96
|
+
*/
|
|
97
|
+
private convertMessagesToAnthropicFormat;
|
|
98
|
+
/**
|
|
99
|
+
* Convert Flink tools to Anthropic format
|
|
100
|
+
*
|
|
101
|
+
* Anthropic uses the format:
|
|
102
|
+
* { name: "...", description: "...", input_schema: {...} }
|
|
103
|
+
*
|
|
104
|
+
* This method also sanitizes the schema to ensure compatibility.
|
|
105
|
+
*/
|
|
106
|
+
private convertToolsToAnthropicFormat;
|
|
107
|
+
/**
|
|
108
|
+
* Sanitize JSON Schema for Anthropic's tool use
|
|
109
|
+
*
|
|
110
|
+
* While Anthropic is generally permissive with JSON Schema, some edge cases
|
|
111
|
+
* can cause issues. This ensures compatibility by:
|
|
112
|
+
* - Removing $schema meta property
|
|
113
|
+
* - Cleaning up nested structures recursively
|
|
114
|
+
*
|
|
115
|
+
* Note: Anthropic supports most JSON Schema features including:
|
|
116
|
+
* - Type constraints (string, number, object, array)
|
|
117
|
+
* - Validation keywords (minLength, maxLength, pattern, etc.)
|
|
118
|
+
* - Format hints (email, uri, date-time, etc.)
|
|
119
|
+
* - Nested objects and arrays
|
|
120
|
+
*
|
|
121
|
+
* This sanitization focuses on removing only problematic metadata.
|
|
122
|
+
*/
|
|
123
|
+
private sanitizeSchemaForAnthropic;
|
|
124
|
+
/**
|
|
125
|
+
* Normalize stop reason from Anthropic to Flink format
|
|
126
|
+
*
|
|
127
|
+
* Maps Anthropic's stop_reason values to Flink's standardized format:
|
|
128
|
+
* - "end_turn" → "end_turn" (natural completion)
|
|
129
|
+
* - "tool_use" → "tool_use" (model wants to call tools)
|
|
130
|
+
* - "max_tokens" → "max_tokens" (hit token limit)
|
|
131
|
+
* - "stop_sequence" → "end_turn" (user-defined stop sequence)
|
|
132
|
+
*/
|
|
133
|
+
private normalizeStopReason;
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=AnthropicAdapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AnthropicAdapter.d.ts","sourceRoot":"","sources":["../src/AnthropicAdapter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAmB,UAAU,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAEpH,MAAM,WAAW,uBAAuB;IACpC;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;;;;;;;OASG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,qBAAa,gBAAiB,YAAW,UAAU,CAAC,eAAe,CAAC;IAChE,OAAO,CAAC,MAAM,CAAY;IAC1B,OAAO,CAAC,KAAK,CAAS;IACf,KAAK,EAAE,OAAO,CAAC;gBAEV,OAAO,EAAE,uBAAuB;gBAChC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAelC,MAAM,CAAC,MAAM,EAAE;QAClB,YAAY,EAAE,MAAM,CAAC;QACrB,QAAQ,EAAE,UAAU,EAAE,CAAC;QACvB,KAAK,EAAE,eAAe,EAAE,CAAC;QACzB,SAAS,EAAE,MAAM,CAAC;QAClB,WAAW,EAAE,MAAM,CAAC;KACvB,GAAG,cAAc,CAAC,cAAc,CAAC;IAwHlC;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,gCAAgC;IA4FxC;;;;;;;OAOG;IACH,OAAO,CAAC,6BAA6B;IAQrC;;;;;;;;;;;;;;;OAeG;IACH,OAAO,CAAC,0BAA0B;IAmClC;;;;;;;;OAQG;IACH,OAAO,CAAC,mBAAmB;CAY9B"}
|
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AnthropicAdapter = void 0;
|
|
7
|
+
const sdk_1 = __importDefault(require("@anthropic-ai/sdk"));
|
|
8
|
+
const flink_1 = require("@flink-app/flink");
|
|
9
|
+
/**
|
|
10
|
+
* Anthropic Claude adapter for Flink AI framework
|
|
11
|
+
*
|
|
12
|
+
* Provides integration with Anthropic's Claude models via the Messages API.
|
|
13
|
+
* Supports tool calling, handles message formatting between Flink's standardized
|
|
14
|
+
* format and Anthropic's API format, and provides robust error handling.
|
|
15
|
+
*
|
|
16
|
+
* ## Architecture
|
|
17
|
+
*
|
|
18
|
+
* This adapter implements the LLMAdapter interface and handles:
|
|
19
|
+
* - Message conversion from Flink format to Anthropic format
|
|
20
|
+
* - System instructions merging (instructions + system messages)
|
|
21
|
+
* - Tool schema sanitization for Anthropic compatibility
|
|
22
|
+
* - Streaming event processing
|
|
23
|
+
* - Comprehensive error handling
|
|
24
|
+
*
|
|
25
|
+
* ## System Instructions
|
|
26
|
+
*
|
|
27
|
+
* The adapter prepends Flink's `instructions` parameter as a system message,
|
|
28
|
+
* following the Vercel AI SDK pattern. Additional system messages in the
|
|
29
|
+
* messages array are also included and merged into the system prompt.
|
|
30
|
+
*
|
|
31
|
+
* ## Basic Usage
|
|
32
|
+
* ```typescript
|
|
33
|
+
* import { AnthropicAdapter } from "@flink-app/anthropic-adapter";
|
|
34
|
+
* import { FlinkApp } from "@flink-app/flink";
|
|
35
|
+
*
|
|
36
|
+
* const app = new FlinkApp({
|
|
37
|
+
* ai: {
|
|
38
|
+
* llms: {
|
|
39
|
+
* default: new AnthropicAdapter({
|
|
40
|
+
* apiKey: process.env.ANTHROPIC_API_KEY!,
|
|
41
|
+
* model: "claude-sonnet-4-5-20250929"
|
|
42
|
+
* }),
|
|
43
|
+
* },
|
|
44
|
+
* },
|
|
45
|
+
* });
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* ## Features
|
|
49
|
+
* - ✅ Full tool calling support
|
|
50
|
+
* - ✅ Streaming with event-based updates
|
|
51
|
+
* - ✅ Proper message conversion and system instruction handling
|
|
52
|
+
* - ✅ Schema sanitization for tool compatibility
|
|
53
|
+
* - ✅ Comprehensive error handling with helpful messages
|
|
54
|
+
* - ✅ Token usage tracking
|
|
55
|
+
* - ✅ Debug logging for tool calls
|
|
56
|
+
*/
|
|
57
|
+
class AnthropicAdapter {
|
|
58
|
+
constructor(optionsOrApiKey, model) {
|
|
59
|
+
if (typeof optionsOrApiKey === "string") {
|
|
60
|
+
// Legacy constructor: new AnthropicAdapter(apiKey, model)
|
|
61
|
+
this.client = new sdk_1.default({ apiKey: optionsOrApiKey });
|
|
62
|
+
this.model = model;
|
|
63
|
+
this.debug = false; // Default: no debug logging
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
// New constructor: new AnthropicAdapter({ apiKey, model, debug })
|
|
67
|
+
this.client = new sdk_1.default({ apiKey: optionsOrApiKey.apiKey });
|
|
68
|
+
this.model = optionsOrApiKey.model;
|
|
69
|
+
this.debug = optionsOrApiKey.debug ?? false; // Default: no debug logging
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
async *stream(params) {
|
|
73
|
+
try {
|
|
74
|
+
// Convert Flink messages to Anthropic format
|
|
75
|
+
const { system, messages } = this.convertMessagesToAnthropicFormat(params.instructions, params.messages);
|
|
76
|
+
// Convert tools to Anthropic format
|
|
77
|
+
const tools = params.tools.length > 0 ? this.convertToolsToAnthropicFormat(params.tools) : undefined;
|
|
78
|
+
// Start streaming from Anthropic
|
|
79
|
+
const stream = await this.client.messages.stream({
|
|
80
|
+
model: this.model,
|
|
81
|
+
max_tokens: params.maxTokens,
|
|
82
|
+
temperature: params.temperature,
|
|
83
|
+
system: system,
|
|
84
|
+
messages: messages,
|
|
85
|
+
tools: tools,
|
|
86
|
+
});
|
|
87
|
+
let totalInputTokens = 0;
|
|
88
|
+
let totalOutputTokens = 0;
|
|
89
|
+
// Process streaming events
|
|
90
|
+
for await (const event of stream) {
|
|
91
|
+
switch (event.type) {
|
|
92
|
+
case "content_block_delta":
|
|
93
|
+
if (event.delta.type === "text_delta") {
|
|
94
|
+
yield { type: "text", delta: event.delta.text };
|
|
95
|
+
}
|
|
96
|
+
break;
|
|
97
|
+
case "content_block_start":
|
|
98
|
+
if (event.content_block.type === "tool_use") {
|
|
99
|
+
// Log the tool call decision from LLM (if debug enabled)
|
|
100
|
+
if (this.debug) {
|
|
101
|
+
flink_1.log.debug(`[Anthropic Stream] LLM decided to call tool:`, JSON.stringify({
|
|
102
|
+
name: event.content_block.name,
|
|
103
|
+
id: event.content_block.id,
|
|
104
|
+
input: event.content_block.input,
|
|
105
|
+
}, null, 2));
|
|
106
|
+
}
|
|
107
|
+
yield {
|
|
108
|
+
type: "tool_call",
|
|
109
|
+
toolCall: {
|
|
110
|
+
id: event.content_block.id,
|
|
111
|
+
name: event.content_block.name,
|
|
112
|
+
input: event.content_block.input,
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
break;
|
|
117
|
+
case "message_delta":
|
|
118
|
+
if (event.usage) {
|
|
119
|
+
totalOutputTokens += event.usage.output_tokens || 0;
|
|
120
|
+
}
|
|
121
|
+
break;
|
|
122
|
+
case "message_start":
|
|
123
|
+
totalInputTokens = event.message.usage.input_tokens || 0;
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// Get final message to access stop reason
|
|
128
|
+
const finalMessage = await stream.finalMessage();
|
|
129
|
+
// Final usage stats
|
|
130
|
+
yield {
|
|
131
|
+
type: "usage",
|
|
132
|
+
usage: {
|
|
133
|
+
inputTokens: totalInputTokens,
|
|
134
|
+
outputTokens: totalOutputTokens,
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
yield {
|
|
138
|
+
type: "done",
|
|
139
|
+
stopReason: this.normalizeStopReason(finalMessage.stop_reason || "end_turn"),
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
// Enhanced error handling for Anthropic API errors
|
|
144
|
+
if (error.status === 400) {
|
|
145
|
+
throw new Error(`Anthropic API error (400 Bad Request): ${error.message || "Invalid request"}. ` +
|
|
146
|
+
`Common causes: invalid model name, malformed messages, or invalid tool schemas. ` +
|
|
147
|
+
`Model: ${this.model}`);
|
|
148
|
+
}
|
|
149
|
+
else if (error.status === 401) {
|
|
150
|
+
throw new Error(`Anthropic API authentication error (401 Unauthorized): Invalid API key. ` +
|
|
151
|
+
`Verify your ANTHROPIC_API_KEY environment variable is set correctly.`);
|
|
152
|
+
}
|
|
153
|
+
else if (error.status === 403) {
|
|
154
|
+
throw new Error(`Anthropic API permission error (403 Forbidden): ${error.message || "Access denied"}. ` +
|
|
155
|
+
`This may indicate insufficient permissions or account limitations.`);
|
|
156
|
+
}
|
|
157
|
+
else if (error.status === 429) {
|
|
158
|
+
throw new Error(`Anthropic API rate limit exceeded (429 Too Many Requests): ${error.message || "Rate limit hit"}. ` +
|
|
159
|
+
`Consider implementing retry logic with exponential backoff or upgrading your rate limits.`);
|
|
160
|
+
}
|
|
161
|
+
else if (error.status === 500 || error.status === 529) {
|
|
162
|
+
throw new Error(`Anthropic API server error (${error.status}): ${error.message || "Internal server error"}. ` +
|
|
163
|
+
`This is a temporary issue with Anthropic's servers. Please retry your request.`);
|
|
164
|
+
}
|
|
165
|
+
throw error;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Convert Flink messages to Anthropic format
|
|
170
|
+
*
|
|
171
|
+
* Anthropic requires:
|
|
172
|
+
* 1. System instructions in top-level 'system' parameter (not in messages array)
|
|
173
|
+
* 2. Messages array with user/assistant alternation
|
|
174
|
+
* 3. Tool results must be in user messages as content blocks
|
|
175
|
+
*
|
|
176
|
+
* This method:
|
|
177
|
+
* - Merges instructions + system messages into a single system prompt
|
|
178
|
+
* - Converts content blocks to Anthropic format
|
|
179
|
+
* - Handles text, tool_use, and tool_result blocks
|
|
180
|
+
*/
|
|
181
|
+
convertMessagesToAnthropicFormat(instructions, messages) {
|
|
182
|
+
const systemParts = [];
|
|
183
|
+
const anthropicMessages = [];
|
|
184
|
+
// 1. Prepend instructions as system message (Vercel AI SDK pattern)
|
|
185
|
+
if (instructions) {
|
|
186
|
+
systemParts.push(instructions);
|
|
187
|
+
}
|
|
188
|
+
for (const msg of messages) {
|
|
189
|
+
// 2. Collect additional system messages (for dynamic context)
|
|
190
|
+
if (msg.role === "system") {
|
|
191
|
+
systemParts.push(msg.content);
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
// 3. Handle user messages
|
|
195
|
+
if (msg.role === "user") {
|
|
196
|
+
if (typeof msg.content === "string") {
|
|
197
|
+
anthropicMessages.push({
|
|
198
|
+
role: "user",
|
|
199
|
+
content: msg.content,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
// Convert content blocks
|
|
204
|
+
const content = msg.content;
|
|
205
|
+
const blocks = [];
|
|
206
|
+
for (const block of content) {
|
|
207
|
+
if (block.type === "text") {
|
|
208
|
+
blocks.push({ type: "text", text: block.text });
|
|
209
|
+
}
|
|
210
|
+
else if (block.type === "tool_result") {
|
|
211
|
+
blocks.push({
|
|
212
|
+
type: "tool_result",
|
|
213
|
+
tool_use_id: block.tool_use_id,
|
|
214
|
+
content: block.content,
|
|
215
|
+
is_error: block.is_error,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
anthropicMessages.push({
|
|
220
|
+
role: "user",
|
|
221
|
+
content: blocks,
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
// 4. Handle assistant messages
|
|
227
|
+
if (msg.role === "assistant") {
|
|
228
|
+
if (typeof msg.content === "string") {
|
|
229
|
+
anthropicMessages.push({
|
|
230
|
+
role: "assistant",
|
|
231
|
+
content: msg.content,
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
// Convert content blocks
|
|
236
|
+
const content = msg.content;
|
|
237
|
+
const blocks = [];
|
|
238
|
+
for (const block of content) {
|
|
239
|
+
if (block.type === "text") {
|
|
240
|
+
blocks.push({ type: "text", text: block.text });
|
|
241
|
+
}
|
|
242
|
+
else if (block.type === "tool_use") {
|
|
243
|
+
blocks.push({
|
|
244
|
+
type: "tool_use",
|
|
245
|
+
id: block.id,
|
|
246
|
+
name: block.name,
|
|
247
|
+
input: block.input,
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
anthropicMessages.push({
|
|
252
|
+
role: "assistant",
|
|
253
|
+
content: blocks,
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return {
|
|
260
|
+
system: systemParts.join("\n\n"),
|
|
261
|
+
messages: anthropicMessages,
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Convert Flink tools to Anthropic format
|
|
266
|
+
*
|
|
267
|
+
* Anthropic uses the format:
|
|
268
|
+
* { name: "...", description: "...", input_schema: {...} }
|
|
269
|
+
*
|
|
270
|
+
* This method also sanitizes the schema to ensure compatibility.
|
|
271
|
+
*/
|
|
272
|
+
convertToolsToAnthropicFormat(tools) {
|
|
273
|
+
return tools.map((tool) => ({
|
|
274
|
+
name: tool.name,
|
|
275
|
+
description: tool.description,
|
|
276
|
+
input_schema: this.sanitizeSchemaForAnthropic(tool.inputSchema),
|
|
277
|
+
}));
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Sanitize JSON Schema for Anthropic's tool use
|
|
281
|
+
*
|
|
282
|
+
* While Anthropic is generally permissive with JSON Schema, some edge cases
|
|
283
|
+
* can cause issues. This ensures compatibility by:
|
|
284
|
+
* - Removing $schema meta property
|
|
285
|
+
* - Cleaning up nested structures recursively
|
|
286
|
+
*
|
|
287
|
+
* Note: Anthropic supports most JSON Schema features including:
|
|
288
|
+
* - Type constraints (string, number, object, array)
|
|
289
|
+
* - Validation keywords (minLength, maxLength, pattern, etc.)
|
|
290
|
+
* - Format hints (email, uri, date-time, etc.)
|
|
291
|
+
* - Nested objects and arrays
|
|
292
|
+
*
|
|
293
|
+
* This sanitization focuses on removing only problematic metadata.
|
|
294
|
+
*/
|
|
295
|
+
sanitizeSchemaForAnthropic(schema) {
|
|
296
|
+
// Deep clone to avoid mutating the original schema
|
|
297
|
+
const sanitized = JSON.parse(JSON.stringify(schema));
|
|
298
|
+
const sanitizeNode = (node) => {
|
|
299
|
+
if (!node || typeof node !== "object")
|
|
300
|
+
return;
|
|
301
|
+
// Remove $schema meta property if present
|
|
302
|
+
delete node.$schema;
|
|
303
|
+
// Recursively sanitize nested structures
|
|
304
|
+
if (node.properties) {
|
|
305
|
+
for (const key in node.properties) {
|
|
306
|
+
sanitizeNode(node.properties[key]);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
if (node.items) {
|
|
310
|
+
if (Array.isArray(node.items)) {
|
|
311
|
+
node.items.forEach(sanitizeNode);
|
|
312
|
+
}
|
|
313
|
+
else {
|
|
314
|
+
sanitizeNode(node.items);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
if (node.allOf)
|
|
318
|
+
node.allOf.forEach(sanitizeNode);
|
|
319
|
+
if (node.anyOf)
|
|
320
|
+
node.anyOf.forEach(sanitizeNode);
|
|
321
|
+
if (node.oneOf)
|
|
322
|
+
node.oneOf.forEach(sanitizeNode);
|
|
323
|
+
if (node.not)
|
|
324
|
+
sanitizeNode(node.not);
|
|
325
|
+
};
|
|
326
|
+
sanitizeNode(sanitized);
|
|
327
|
+
return sanitized;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Normalize stop reason from Anthropic to Flink format
|
|
331
|
+
*
|
|
332
|
+
* Maps Anthropic's stop_reason values to Flink's standardized format:
|
|
333
|
+
* - "end_turn" → "end_turn" (natural completion)
|
|
334
|
+
* - "tool_use" → "tool_use" (model wants to call tools)
|
|
335
|
+
* - "max_tokens" → "max_tokens" (hit token limit)
|
|
336
|
+
* - "stop_sequence" → "end_turn" (user-defined stop sequence)
|
|
337
|
+
*/
|
|
338
|
+
normalizeStopReason(stopReason) {
|
|
339
|
+
switch (stopReason) {
|
|
340
|
+
case "tool_use":
|
|
341
|
+
return "tool_use";
|
|
342
|
+
case "max_tokens":
|
|
343
|
+
return "max_tokens";
|
|
344
|
+
case "end_turn":
|
|
345
|
+
case "stop_sequence":
|
|
346
|
+
default:
|
|
347
|
+
return "end_turn";
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
exports.AnthropicAdapter = AnthropicAdapter;
|
|
352
|
+
//# sourceMappingURL=AnthropicAdapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AnthropicAdapter.js","sourceRoot":"","sources":["../src/AnthropicAdapter.ts"],"names":[],"mappings":";;;;;;AAAA,4DAA0C;AAC1C,4CAAuC;AA2BvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,MAAa,gBAAgB;IAO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uBAAuB,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AnthropicAdapter = void 0;
|
|
4
|
+
var AnthropicAdapter_1 = require("./AnthropicAdapter");
|
|
5
|
+
Object.defineProperty(exports, "AnthropicAdapter", { enumerable: true, get: function () { return AnthropicAdapter_1.AnthropicAdapter; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,uDAAoF;AAA3E,oHAAA,gBAAgB,OAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@flink-app/anthropic-adapter",
|
|
3
|
+
"version": "2.0.0-alpha.48",
|
|
4
|
+
"description": "Anthropic Claude adapter for Flink AI framework",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"flink",
|
|
9
|
+
"anthropic",
|
|
10
|
+
"claude",
|
|
11
|
+
"ai",
|
|
12
|
+
"llm",
|
|
13
|
+
"adapter"
|
|
14
|
+
],
|
|
15
|
+
"author": "Frost Digital",
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@anthropic-ai/sdk": "^0.72.1"
|
|
19
|
+
},
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"@flink-app/flink": ">=2.0.0-alpha.48"
|
|
22
|
+
},
|
|
23
|
+
"peerDependenciesMeta": {
|
|
24
|
+
"@flink-app/flink": {
|
|
25
|
+
"optional": false
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"typescript": "^5.6.2",
|
|
30
|
+
"@flink-app/flink": "2.0.0-alpha.48"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist",
|
|
34
|
+
"README.md"
|
|
35
|
+
],
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "https://github.com/FrostDigital/flink-framework.git",
|
|
39
|
+
"directory": "packages/anthropic-adapter"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsc --project tsconfig.dist.json",
|
|
43
|
+
"watch": "tsc --project tsconfig.dist.json --watch",
|
|
44
|
+
"test": "echo \"No tests yet\" && exit 0",
|
|
45
|
+
"clean": "rm -rf dist"
|
|
46
|
+
}
|
|
47
|
+
}
|