@ai-sdk/anthropic 3.0.21 → 3.0.23

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.
Files changed (50) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/index.d.mts +7 -0
  3. package/dist/index.d.ts +7 -0
  4. package/dist/index.js +20 -9
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +21 -9
  7. package/dist/index.mjs.map +1 -1
  8. package/package.json +9 -5
  9. package/src/anthropic-provider.ts +32 -7
  10. package/src/__fixtures__/anthropic-code-execution-20250825.1.chunks.txt +0 -248
  11. package/src/__fixtures__/anthropic-code-execution-20250825.1.json +0 -70
  12. package/src/__fixtures__/anthropic-code-execution-20250825.2.chunks.txt +0 -984
  13. package/src/__fixtures__/anthropic-code-execution-20250825.2.json +0 -111
  14. package/src/__fixtures__/anthropic-code-execution-20250825.pptx-skill.chunks.txt +0 -691
  15. package/src/__fixtures__/anthropic-code-execution-20250825.pptx-skill.json +0 -1801
  16. package/src/__fixtures__/anthropic-json-other-tool.1.chunks.txt +0 -13
  17. package/src/__fixtures__/anthropic-json-other-tool.1.json +0 -26
  18. package/src/__fixtures__/anthropic-json-output-format.1.chunks.txt +0 -120
  19. package/src/__fixtures__/anthropic-json-output-format.1.json +0 -25
  20. package/src/__fixtures__/anthropic-json-tool.1.chunks.txt +0 -9
  21. package/src/__fixtures__/anthropic-json-tool.1.json +0 -37
  22. package/src/__fixtures__/anthropic-json-tool.2.chunks.txt +0 -14
  23. package/src/__fixtures__/anthropic-mcp.1.chunks.txt +0 -17
  24. package/src/__fixtures__/anthropic-mcp.1.json +0 -39
  25. package/src/__fixtures__/anthropic-memory-20250818.1.json +0 -28
  26. package/src/__fixtures__/anthropic-message-delta-input-tokens.chunks.txt +0 -8
  27. package/src/__fixtures__/anthropic-programmatic-tool-calling.1.chunks.txt +0 -278
  28. package/src/__fixtures__/anthropic-programmatic-tool-calling.1.json +0 -106
  29. package/src/__fixtures__/anthropic-tool-no-args.chunks.txt +0 -13
  30. package/src/__fixtures__/anthropic-tool-no-args.json +0 -31
  31. package/src/__fixtures__/anthropic-tool-search-bm25.1.chunks.txt +0 -47
  32. package/src/__fixtures__/anthropic-tool-search-bm25.1.json +0 -67
  33. package/src/__fixtures__/anthropic-tool-search-deferred-bm25.2.json +0 -65
  34. package/src/__fixtures__/anthropic-tool-search-deferred-bm25.chunks.txt +0 -115
  35. package/src/__fixtures__/anthropic-tool-search-deferred-regex.2.json +0 -69
  36. package/src/__fixtures__/anthropic-tool-search-deferred-regex.chunks.txt +0 -119
  37. package/src/__fixtures__/anthropic-tool-search-regex.1.chunks.txt +0 -51
  38. package/src/__fixtures__/anthropic-tool-search-regex.1.json +0 -65
  39. package/src/__fixtures__/anthropic-web-fetch-tool.1.chunks.txt +0 -64
  40. package/src/__fixtures__/anthropic-web-fetch-tool.1.json +0 -54
  41. package/src/__fixtures__/anthropic-web-fetch-tool.2.json +0 -56
  42. package/src/__fixtures__/anthropic-web-fetch-tool.error.json +0 -46
  43. package/src/__fixtures__/anthropic-web-search-tool.1.chunks.txt +0 -120
  44. package/src/__fixtures__/anthropic-web-search-tool.1.json +0 -181
  45. package/src/__snapshots__/anthropic-messages-language-model.test.ts.snap +0 -16719
  46. package/src/anthropic-error.test.ts +0 -42
  47. package/src/anthropic-messages-language-model.test.ts +0 -7368
  48. package/src/anthropic-prepare-tools.test.ts +0 -1219
  49. package/src/anthropic-provider.test.ts +0 -162
  50. package/src/convert-to-anthropic-messages-prompt.test.ts +0 -2902
@@ -1,162 +0,0 @@
1
- /* eslint-disable turbo/no-undeclared-env-vars */
2
- import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
3
- import { LanguageModelV3Prompt } from '@ai-sdk/provider';
4
- import { createAnthropic } from './anthropic-provider';
5
-
6
- vi.mock('./version', () => ({
7
- VERSION: '0.0.0-test',
8
- }));
9
-
10
- const TEST_PROMPT: LanguageModelV3Prompt = [
11
- { role: 'user', content: [{ type: 'text', text: 'Hello' }] },
12
- ];
13
-
14
- const createSuccessfulResponse = () =>
15
- new Response(
16
- JSON.stringify({
17
- type: 'message',
18
- id: 'msg_123',
19
- model: 'claude-3-haiku-20240307',
20
- content: [{ type: 'text', text: 'Hi' }],
21
- stop_reason: null,
22
- stop_sequence: null,
23
- usage: { input_tokens: 1, output_tokens: 1 },
24
- }),
25
- {
26
- status: 200,
27
- headers: { 'Content-Type': 'application/json' },
28
- },
29
- );
30
-
31
- const createFetchMock = () =>
32
- vi.fn().mockResolvedValue(createSuccessfulResponse());
33
-
34
- describe('createAnthropic', () => {
35
- describe('baseURL configuration', () => {
36
- const originalBaseUrl = process.env.ANTHROPIC_BASE_URL;
37
-
38
- beforeEach(() => {
39
- vi.restoreAllMocks();
40
- });
41
-
42
- afterEach(() => {
43
- if (originalBaseUrl === undefined) {
44
- delete process.env.ANTHROPIC_BASE_URL;
45
- } else {
46
- process.env.ANTHROPIC_BASE_URL = originalBaseUrl;
47
- }
48
- });
49
-
50
- it('uses the default Anthropic base URL when not provided', async () => {
51
- delete process.env.ANTHROPIC_BASE_URL;
52
-
53
- const fetchMock = createFetchMock();
54
- const provider = createAnthropic({
55
- apiKey: 'test-api-key',
56
- fetch: fetchMock,
57
- });
58
-
59
- await provider('claude-3-haiku-20240307').doGenerate({
60
- prompt: TEST_PROMPT,
61
- });
62
-
63
- expect(fetchMock).toHaveBeenCalledTimes(1);
64
- const [requestUrl] = fetchMock.mock.calls[0]!;
65
- expect(requestUrl).toBe('https://api.anthropic.com/v1/messages');
66
- });
67
-
68
- it('uses ANTHROPIC_BASE_URL when set', async () => {
69
- process.env.ANTHROPIC_BASE_URL = 'https://proxy.anthropic.example/v1/';
70
-
71
- const fetchMock = createFetchMock();
72
- const provider = createAnthropic({
73
- apiKey: 'test-api-key',
74
- fetch: fetchMock,
75
- });
76
-
77
- await provider('claude-3-haiku-20240307').doGenerate({
78
- prompt: TEST_PROMPT,
79
- });
80
-
81
- expect(fetchMock).toHaveBeenCalledTimes(1);
82
- const [requestUrl] = fetchMock.mock.calls[0]!;
83
- expect(requestUrl).toBe('https://proxy.anthropic.example/v1/messages');
84
- });
85
-
86
- it('prefers the baseURL option over ANTHROPIC_BASE_URL', async () => {
87
- process.env.ANTHROPIC_BASE_URL = 'https://env.anthropic.example/v1';
88
-
89
- const fetchMock = createFetchMock();
90
- const provider = createAnthropic({
91
- apiKey: 'test-api-key',
92
- baseURL: 'https://option.anthropic.example/v1/',
93
- fetch: fetchMock,
94
- });
95
-
96
- await provider('claude-3-haiku-20240307').doGenerate({
97
- prompt: TEST_PROMPT,
98
- });
99
-
100
- expect(fetchMock).toHaveBeenCalledTimes(1);
101
- const [requestUrl] = fetchMock.mock.calls[0]!;
102
- expect(requestUrl).toBe('https://option.anthropic.example/v1/messages');
103
- });
104
- });
105
- });
106
-
107
- describe('anthropic provider - custom provider name', () => {
108
- beforeEach(() => {
109
- vi.clearAllMocks();
110
- });
111
-
112
- it('should use custom provider name when specified', () => {
113
- const provider = createAnthropic({
114
- name: 'my-claude-proxy',
115
- apiKey: 'test-api-key',
116
- });
117
-
118
- const model = provider('claude-3-haiku-20240307');
119
- expect(model.provider).toBe('my-claude-proxy');
120
- });
121
-
122
- it('should default to anthropic.messages when name not specified', () => {
123
- const provider = createAnthropic({
124
- apiKey: 'test-api-key',
125
- });
126
-
127
- const model = provider('claude-3-haiku-20240307');
128
- expect(model.provider).toBe('anthropic.messages');
129
- });
130
- });
131
-
132
- describe('anthropic provider - supportedUrls', () => {
133
- it('should support image/* URLs', async () => {
134
- const provider = createAnthropic({
135
- apiKey: 'test-api-key',
136
- });
137
-
138
- const model = provider('claude-3-haiku-20240307');
139
- const supportedUrls = await model.supportedUrls;
140
-
141
- expect(supportedUrls['image/*']).toBeDefined();
142
- expect(
143
- supportedUrls['image/*']![0]!.test('https://example.com/image.png'),
144
- ).toBe(true);
145
- });
146
-
147
- it('should support application/pdf URLs', async () => {
148
- const provider = createAnthropic({
149
- apiKey: 'test-api-key',
150
- });
151
-
152
- const model = provider('claude-3-haiku-20240307');
153
- const supportedUrls = await model.supportedUrls;
154
-
155
- expect(supportedUrls['application/pdf']).toBeDefined();
156
- expect(
157
- supportedUrls['application/pdf']![0]!.test(
158
- 'https://arxiv.org/pdf/2401.00001',
159
- ),
160
- ).toBe(true);
161
- });
162
- });