@tanstack/ai-anthropic 0.15.9 → 0.15.10
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/dist/esm/adapters/summarize.d.ts +41 -0
- package/dist/esm/adapters/summarize.js +18 -0
- package/dist/esm/adapters/summarize.js.map +1 -0
- package/dist/esm/adapters/text.d.ts +92 -0
- package/dist/esm/adapters/text.js +851 -0
- package/dist/esm/adapters/text.js.map +1 -0
- package/dist/esm/index.d.ts +9 -0
- package/dist/esm/index.js +15 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/message-types.d.ts +84 -0
- package/dist/esm/model-meta.d.ts +410 -0
- package/dist/esm/model-meta.js +81 -0
- package/dist/esm/model-meta.js.map +1 -0
- package/dist/esm/text/text-provider-options.d.ts +258 -0
- package/dist/esm/text/text-provider-options.js +30 -0
- package/dist/esm/text/text-provider-options.js.map +1 -0
- package/dist/esm/tools/bash-tool.d.ts +8 -0
- package/dist/esm/tools/bash-tool.js +17 -0
- package/dist/esm/tools/bash-tool.js.map +1 -0
- package/dist/esm/tools/code-execution-tool.d.ts +34 -0
- package/dist/esm/tools/code-execution-tool.js +39 -0
- package/dist/esm/tools/code-execution-tool.js.map +1 -0
- package/dist/esm/tools/computer-use-tool.d.ts +8 -0
- package/dist/esm/tools/computer-use-tool.js +17 -0
- package/dist/esm/tools/computer-use-tool.js.map +1 -0
- package/dist/esm/tools/custom-tool.d.ts +26 -0
- package/dist/esm/tools/custom-tool.js +34 -0
- package/dist/esm/tools/custom-tool.js.map +1 -0
- package/dist/esm/tools/index.d.ts +17 -0
- package/dist/esm/tools/index.js +22 -0
- package/dist/esm/tools/index.js.map +1 -0
- package/dist/esm/tools/memory-tool.d.ts +8 -0
- package/dist/esm/tools/memory-tool.js +20 -0
- package/dist/esm/tools/memory-tool.js.map +1 -0
- package/dist/esm/tools/text-editor-tool.d.ts +8 -0
- package/dist/esm/tools/text-editor-tool.js +19 -0
- package/dist/esm/tools/text-editor-tool.js.map +1 -0
- package/dist/esm/tools/tool-converter.d.ts +27 -0
- package/dist/esm/tools/tool-converter.js +35 -0
- package/dist/esm/tools/tool-converter.js.map +1 -0
- package/dist/esm/tools/web-fetch-tool.d.ts +8 -0
- package/dist/esm/tools/web-fetch-tool.js +21 -0
- package/dist/esm/tools/web-fetch-tool.js.map +1 -0
- package/dist/esm/tools/web-search-tool.d.ts +8 -0
- package/dist/esm/tools/web-search-tool.js +63 -0
- package/dist/esm/tools/web-search-tool.js.map +1 -0
- package/dist/esm/usage.d.ts +25 -0
- package/dist/esm/usage.js +35 -0
- package/dist/esm/usage.js.map +1 -0
- package/dist/esm/utils/client.d.ts +17 -0
- package/dist/esm/utils/client.js +20 -0
- package/dist/esm/utils/client.js.map +1 -0
- package/dist/esm/utils/index.d.ts +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ChatStreamSummarizeAdapter, InferTextProviderOptions } from '@tanstack/ai/adapters';
|
|
2
|
+
import { AnthropicTextAdapter } from './text.js';
|
|
3
|
+
import { ANTHROPIC_MODELS } from '../model-meta.js';
|
|
4
|
+
import { AnthropicClientConfig } from '../utils.js';
|
|
5
|
+
/**
|
|
6
|
+
* Configuration for Anthropic summarize adapter
|
|
7
|
+
*/
|
|
8
|
+
export interface AnthropicSummarizeConfig extends AnthropicClientConfig {
|
|
9
|
+
}
|
|
10
|
+
/** Model type for Anthropic summarization */
|
|
11
|
+
export type AnthropicSummarizeModel = (typeof ANTHROPIC_MODELS)[number];
|
|
12
|
+
/**
|
|
13
|
+
* Creates an Anthropic summarize adapter with explicit API key.
|
|
14
|
+
* Type resolution happens here at the call site.
|
|
15
|
+
*
|
|
16
|
+
* @param model - The model name (e.g., 'claude-sonnet-4-5', 'claude-3-5-haiku-latest')
|
|
17
|
+
* @param apiKey - Your Anthropic API key
|
|
18
|
+
* @param config - Optional additional configuration
|
|
19
|
+
* @returns Configured Anthropic summarize adapter instance with resolved types
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const adapter = createAnthropicSummarize('claude-sonnet-4-5', 'sk-ant-...');
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function createAnthropicSummarize<TModel extends AnthropicSummarizeModel>(model: TModel, apiKey: string, config?: Omit<AnthropicSummarizeConfig, 'apiKey'>): ChatStreamSummarizeAdapter<TModel, InferTextProviderOptions<AnthropicTextAdapter<TModel>>>;
|
|
27
|
+
/**
|
|
28
|
+
* Creates an Anthropic summarize adapter with automatic API key detection.
|
|
29
|
+
* Type resolution happens here at the call site.
|
|
30
|
+
*
|
|
31
|
+
* @param model - The model name (e.g., 'claude-sonnet-4-5', 'claude-3-5-haiku-latest')
|
|
32
|
+
* @param config - Optional configuration (excluding apiKey which is auto-detected)
|
|
33
|
+
* @returns Configured Anthropic summarize adapter instance with resolved types
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const adapter = anthropicSummarize('claude-sonnet-4-5');
|
|
38
|
+
* await summarize({ adapter, text: 'Long article text...' });
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare function anthropicSummarize<TModel extends AnthropicSummarizeModel>(model: TModel, config?: Omit<AnthropicSummarizeConfig, 'apiKey'>): ChatStreamSummarizeAdapter<TModel, InferTextProviderOptions<AnthropicTextAdapter<TModel>>>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ChatStreamSummarizeAdapter } from "@tanstack/ai/adapters";
|
|
2
|
+
import { getAnthropicApiKeyFromEnv } from "../utils/client.js";
|
|
3
|
+
import { AnthropicTextAdapter } from "./text.js";
|
|
4
|
+
function createAnthropicSummarize(model, apiKey, config) {
|
|
5
|
+
return new ChatStreamSummarizeAdapter(
|
|
6
|
+
new AnthropicTextAdapter({ apiKey, ...config }, model),
|
|
7
|
+
model,
|
|
8
|
+
"anthropic"
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
function anthropicSummarize(model, config) {
|
|
12
|
+
return createAnthropicSummarize(model, getAnthropicApiKeyFromEnv(), config);
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
anthropicSummarize,
|
|
16
|
+
createAnthropicSummarize
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=summarize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"summarize.js","sources":["../../../src/adapters/summarize.ts"],"sourcesContent":["import { ChatStreamSummarizeAdapter } from '@tanstack/ai/adapters'\nimport { getAnthropicApiKeyFromEnv } from '../utils'\nimport { AnthropicTextAdapter } from './text'\nimport type { InferTextProviderOptions } from '@tanstack/ai/adapters'\nimport type { ANTHROPIC_MODELS } from '../model-meta'\nimport type { AnthropicClientConfig } from '../utils'\n\n/**\n * Configuration for Anthropic summarize adapter\n */\nexport interface AnthropicSummarizeConfig extends AnthropicClientConfig {}\n\n/** Model type for Anthropic summarization */\nexport type AnthropicSummarizeModel = (typeof ANTHROPIC_MODELS)[number]\n\n/**\n * Creates an Anthropic summarize adapter with explicit API key.\n * Type resolution happens here at the call site.\n *\n * @param model - The model name (e.g., 'claude-sonnet-4-5', 'claude-3-5-haiku-latest')\n * @param apiKey - Your Anthropic API key\n * @param config - Optional additional configuration\n * @returns Configured Anthropic summarize adapter instance with resolved types\n *\n * @example\n * ```typescript\n * const adapter = createAnthropicSummarize('claude-sonnet-4-5', 'sk-ant-...');\n * ```\n */\nexport function createAnthropicSummarize<\n TModel extends AnthropicSummarizeModel,\n>(\n model: TModel,\n apiKey: string,\n config?: Omit<AnthropicSummarizeConfig, 'apiKey'>,\n): ChatStreamSummarizeAdapter<\n TModel,\n InferTextProviderOptions<AnthropicTextAdapter<TModel>>\n> {\n return new ChatStreamSummarizeAdapter(\n new AnthropicTextAdapter({ apiKey, ...config }, model),\n model,\n 'anthropic',\n )\n}\n\n/**\n * Creates an Anthropic summarize adapter with automatic API key detection.\n * Type resolution happens here at the call site.\n *\n * @param model - The model name (e.g., 'claude-sonnet-4-5', 'claude-3-5-haiku-latest')\n * @param config - Optional configuration (excluding apiKey which is auto-detected)\n * @returns Configured Anthropic summarize adapter instance with resolved types\n *\n * @example\n * ```typescript\n * const adapter = anthropicSummarize('claude-sonnet-4-5');\n * await summarize({ adapter, text: 'Long article text...' });\n * ```\n */\nexport function anthropicSummarize<TModel extends AnthropicSummarizeModel>(\n model: TModel,\n config?: Omit<AnthropicSummarizeConfig, 'apiKey'>,\n): ChatStreamSummarizeAdapter<\n TModel,\n InferTextProviderOptions<AnthropicTextAdapter<TModel>>\n> {\n return createAnthropicSummarize(model, getAnthropicApiKeyFromEnv(), config)\n}\n"],"names":[],"mappings":";;;AA6BO,SAAS,yBAGd,OACA,QACA,QAIA;AACA,SAAO,IAAI;AAAA,IACT,IAAI,qBAAqB,EAAE,QAAQ,GAAG,OAAA,GAAU,KAAK;AAAA,IACrD;AAAA,IACA;AAAA,EAAA;AAEJ;AAgBO,SAAS,mBACd,OACA,QAIA;AACA,SAAO,yBAAyB,OAAO,0BAAA,GAA6B,MAAM;AAC5E;"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { BaseTextAdapter, StructuredOutputOptions, StructuredOutputResult } from '@tanstack/ai/adapters';
|
|
2
|
+
import { ANTHROPIC_MODELS, AnthropicChatModelProviderOptionsByName, AnthropicChatModelToolCapabilitiesByName, AnthropicModelInputModalitiesByName } from '../model-meta.js';
|
|
3
|
+
import { AnthropicBeta } from '@anthropic-ai/sdk/resources/beta/beta';
|
|
4
|
+
import { AnyTool, Modality, StreamChunk, TextOptions } from '@tanstack/ai';
|
|
5
|
+
import { AnthropicSystemPromptMetadata, ExternalTextProviderOptions } from '../text/text-provider-options.js';
|
|
6
|
+
import { AnthropicMessageMetadataByModality } from '../message-types.js';
|
|
7
|
+
import { AnthropicClientConfig } from '../utils.js';
|
|
8
|
+
/**
|
|
9
|
+
* Computes the `betas` array for a Messages request. Unions:
|
|
10
|
+
* - `interleaved-thinking-2025-05-14` when interleaved thinking is enabled,
|
|
11
|
+
* - `code-execution-2025-08-25` when a `code_execution` tool is present,
|
|
12
|
+
* - `skills-2025-10-02` when that tool carries skills.
|
|
13
|
+
* Returns `undefined` when none apply (so the call site omits `betas`).
|
|
14
|
+
*/
|
|
15
|
+
export declare function computeAnthropicBetas(tools: Array<AnyTool> | undefined, modelOptions: {
|
|
16
|
+
thinking?: {
|
|
17
|
+
type?: 'enabled' | 'disabled' | 'adaptive';
|
|
18
|
+
budget_tokens?: number;
|
|
19
|
+
};
|
|
20
|
+
} | undefined): Array<AnthropicBeta> | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Configuration for Anthropic text adapter
|
|
23
|
+
*/
|
|
24
|
+
export interface AnthropicTextConfig extends AnthropicClientConfig {
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Anthropic-specific provider options for text/chat
|
|
28
|
+
*/
|
|
29
|
+
export type AnthropicTextProviderOptions = ExternalTextProviderOptions;
|
|
30
|
+
/**
|
|
31
|
+
* Resolve provider options for a specific model.
|
|
32
|
+
* If the model has explicit options in the map, use those; otherwise use base options.
|
|
33
|
+
*/
|
|
34
|
+
type ResolveProviderOptions<TModel extends string> = TModel extends keyof AnthropicChatModelProviderOptionsByName ? AnthropicChatModelProviderOptionsByName[TModel] : AnthropicTextProviderOptions;
|
|
35
|
+
/**
|
|
36
|
+
* Resolve input modalities for a specific model.
|
|
37
|
+
* If the model has explicit modalities in the map, use those; otherwise use default.
|
|
38
|
+
*/
|
|
39
|
+
type ResolveInputModalities<TModel extends string> = TModel extends keyof AnthropicModelInputModalitiesByName ? AnthropicModelInputModalitiesByName[TModel] : readonly ['text', 'image', 'document'];
|
|
40
|
+
type ResolveToolCapabilities<TModel extends string> = TModel extends keyof AnthropicChatModelToolCapabilitiesByName ? NonNullable<AnthropicChatModelToolCapabilitiesByName[TModel]> : readonly [];
|
|
41
|
+
/**
|
|
42
|
+
* Anthropic Text (Chat) Adapter
|
|
43
|
+
*
|
|
44
|
+
* Tree-shakeable adapter for Anthropic chat/text completion functionality.
|
|
45
|
+
* Import only what you need for smaller bundle sizes.
|
|
46
|
+
*/
|
|
47
|
+
export declare class AnthropicTextAdapter<TModel extends (typeof ANTHROPIC_MODELS)[number], TProviderOptions extends Record<string, any> = ResolveProviderOptions<TModel>, TInputModalities extends ReadonlyArray<Modality> = ResolveInputModalities<TModel>, TToolCapabilities extends ReadonlyArray<string> = ResolveToolCapabilities<TModel>> extends BaseTextAdapter<TModel, TProviderOptions, TInputModalities, AnthropicMessageMetadataByModality, TToolCapabilities, unknown, AnthropicSystemPromptMetadata> {
|
|
48
|
+
readonly kind: "text";
|
|
49
|
+
readonly name: "anthropic";
|
|
50
|
+
private readonly client;
|
|
51
|
+
constructor(config: AnthropicTextConfig, model: TModel);
|
|
52
|
+
chatStream(options: TextOptions<TProviderOptions>): AsyncIterable<StreamChunk>;
|
|
53
|
+
/**
|
|
54
|
+
* Generate structured output using Anthropic's tool-based approach.
|
|
55
|
+
* Anthropic doesn't have native structured output, so we use a tool with the schema
|
|
56
|
+
* and force the model to call it.
|
|
57
|
+
* The outputSchema is already JSON Schema (converted in the ai layer).
|
|
58
|
+
*/
|
|
59
|
+
structuredOutput(options: StructuredOutputOptions<TProviderOptions>): Promise<StructuredOutputResult<unknown>>;
|
|
60
|
+
private mapCommonOptionsToAnthropic;
|
|
61
|
+
/**
|
|
62
|
+
* Anthropic supports `output_config.format` + `tools` in a single streaming
|
|
63
|
+
* Messages request only for Claude 4.5+ (GA 2026-01-29). For 4.4 and
|
|
64
|
+
* earlier we keep the forced-tool-use workaround in
|
|
65
|
+
* {@link structuredOutput} via the engine's finalization path.
|
|
66
|
+
*/
|
|
67
|
+
supportsCombinedToolsAndSchema(): boolean;
|
|
68
|
+
private convertContentPartToAnthropic;
|
|
69
|
+
private formatMessages;
|
|
70
|
+
private appendThinkingBlocks;
|
|
71
|
+
/**
|
|
72
|
+
* Merge consecutive messages of the same role into a single message.
|
|
73
|
+
* Anthropic's API requires strictly alternating user/assistant roles.
|
|
74
|
+
* Tool results are wrapped as role:'user' messages, which can collide
|
|
75
|
+
* with actual user messages in multi-turn conversations.
|
|
76
|
+
*
|
|
77
|
+
* Also filters out empty assistant messages (e.g., from a previous failed request).
|
|
78
|
+
*/
|
|
79
|
+
private mergeConsecutiveSameRoleMessages;
|
|
80
|
+
private processAnthropicStream;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Creates an Anthropic chat adapter with explicit API key.
|
|
84
|
+
* Type resolution happens here at the call site.
|
|
85
|
+
*/
|
|
86
|
+
export declare function createAnthropicChat<TModel extends (typeof ANTHROPIC_MODELS)[number]>(model: TModel, apiKey: string, config?: Omit<AnthropicTextConfig, 'apiKey'>): AnthropicTextAdapter<TModel, ResolveProviderOptions<TModel>, ResolveInputModalities<TModel>>;
|
|
87
|
+
/**
|
|
88
|
+
* Creates an Anthropic text adapter with automatic API key detection.
|
|
89
|
+
* Type resolution happens here at the call site.
|
|
90
|
+
*/
|
|
91
|
+
export declare function anthropicText<TModel extends (typeof ANTHROPIC_MODELS)[number]>(model: TModel, config?: Omit<AnthropicTextConfig, 'apiKey'>): AnthropicTextAdapter<TModel, ResolveProviderOptions<TModel>, ResolveInputModalities<TModel>>;
|
|
92
|
+
export {};
|