@tanstack/ai-anthropic 0.8.6 → 0.8.7
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 +15 -28
- package/dist/esm/adapters/summarize.js +9 -138
- package/dist/esm/adapters/summarize.js.map +1 -1
- package/dist/esm/adapters/text.js +104 -107
- package/dist/esm/adapters/text.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -2
- package/package.json +3 -3
- package/src/adapters/summarize.ts +29 -197
- package/src/adapters/text.ts +104 -111
- package/src/index.ts +2 -3
|
@@ -1,38 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ChatStreamSummarizeAdapter, InferTextProviderOptions } from '@tanstack/ai/adapters';
|
|
2
|
+
import { AnthropicTextAdapter } from './text.js';
|
|
2
3
|
import { ANTHROPIC_MODELS } from '../model-meta.js';
|
|
3
|
-
import { StreamChunk, SummarizationOptions, SummarizationResult } from '@tanstack/ai';
|
|
4
4
|
import { AnthropicClientConfig } from '../utils.js';
|
|
5
5
|
/**
|
|
6
6
|
* Configuration for Anthropic summarize adapter
|
|
7
7
|
*/
|
|
8
8
|
export interface AnthropicSummarizeConfig extends AnthropicClientConfig {
|
|
9
9
|
}
|
|
10
|
-
/**
|
|
11
|
-
* Anthropic-specific provider options for summarization
|
|
12
|
-
*/
|
|
13
|
-
export interface AnthropicSummarizeProviderOptions {
|
|
14
|
-
/** Temperature for response generation (0-1) */
|
|
15
|
-
temperature?: number;
|
|
16
|
-
/** Maximum tokens in the response */
|
|
17
|
-
maxTokens?: number;
|
|
18
|
-
}
|
|
19
10
|
/** Model type for Anthropic summarization */
|
|
20
11
|
export type AnthropicSummarizeModel = (typeof ANTHROPIC_MODELS)[number];
|
|
21
|
-
/**
|
|
22
|
-
* Anthropic Summarize Adapter
|
|
23
|
-
*
|
|
24
|
-
* Tree-shakeable adapter for Anthropic summarization functionality.
|
|
25
|
-
* Import only what you need for smaller bundle sizes.
|
|
26
|
-
*/
|
|
27
|
-
export declare class AnthropicSummarizeAdapter<TModel extends AnthropicSummarizeModel> extends BaseSummarizeAdapter<TModel, AnthropicSummarizeProviderOptions> {
|
|
28
|
-
readonly kind: "summarize";
|
|
29
|
-
readonly name: "anthropic";
|
|
30
|
-
private client;
|
|
31
|
-
constructor(config: AnthropicSummarizeConfig, model: TModel);
|
|
32
|
-
summarize(options: SummarizationOptions): Promise<SummarizationResult>;
|
|
33
|
-
summarizeStream(options: SummarizationOptions): AsyncIterable<StreamChunk>;
|
|
34
|
-
private buildSummarizationPrompt;
|
|
35
|
-
}
|
|
36
12
|
/**
|
|
37
13
|
* Creates an Anthropic summarize adapter with explicit API key.
|
|
38
14
|
* Type resolution happens here at the call site.
|
|
@@ -41,8 +17,13 @@ export declare class AnthropicSummarizeAdapter<TModel extends AnthropicSummarize
|
|
|
41
17
|
* @param apiKey - Your Anthropic API key
|
|
42
18
|
* @param config - Optional additional configuration
|
|
43
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
|
+
* ```
|
|
44
25
|
*/
|
|
45
|
-
export declare function createAnthropicSummarize<TModel extends AnthropicSummarizeModel>(model: TModel, apiKey: string, config?: Omit<AnthropicSummarizeConfig, 'apiKey'>):
|
|
26
|
+
export declare function createAnthropicSummarize<TModel extends AnthropicSummarizeModel>(model: TModel, apiKey: string, config?: Omit<AnthropicSummarizeConfig, 'apiKey'>): ChatStreamSummarizeAdapter<TModel, InferTextProviderOptions<AnthropicTextAdapter<TModel>>>;
|
|
46
27
|
/**
|
|
47
28
|
* Creates an Anthropic summarize adapter with automatic API key detection.
|
|
48
29
|
* Type resolution happens here at the call site.
|
|
@@ -50,5 +31,11 @@ export declare function createAnthropicSummarize<TModel extends AnthropicSummari
|
|
|
50
31
|
* @param model - The model name (e.g., 'claude-sonnet-4-5', 'claude-3-5-haiku-latest')
|
|
51
32
|
* @param config - Optional configuration (excluding apiKey which is auto-detected)
|
|
52
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
|
+
* ```
|
|
53
40
|
*/
|
|
54
|
-
export declare function anthropicSummarize<TModel extends AnthropicSummarizeModel>(model: TModel, config?: Omit<AnthropicSummarizeConfig, 'apiKey'>):
|
|
41
|
+
export declare function anthropicSummarize<TModel extends AnthropicSummarizeModel>(model: TModel, config?: Omit<AnthropicSummarizeConfig, 'apiKey'>): ChatStreamSummarizeAdapter<TModel, InferTextProviderOptions<AnthropicTextAdapter<TModel>>>;
|
|
@@ -1,146 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
class AnthropicSummarizeAdapter extends BaseSummarizeAdapter {
|
|
5
|
-
constructor(config, model) {
|
|
6
|
-
super({}, model);
|
|
7
|
-
this.kind = "summarize";
|
|
8
|
-
this.name = "anthropic";
|
|
9
|
-
this.client = createAnthropicClient(config);
|
|
10
|
-
}
|
|
11
|
-
async summarize(options) {
|
|
12
|
-
const { logger } = options;
|
|
13
|
-
const systemPrompt = this.buildSummarizationPrompt(options);
|
|
14
|
-
logger.request(`activity=summarize provider=anthropic`, {
|
|
15
|
-
provider: "anthropic",
|
|
16
|
-
model: options.model
|
|
17
|
-
});
|
|
18
|
-
try {
|
|
19
|
-
const response = await this.client.messages.create({
|
|
20
|
-
model: options.model,
|
|
21
|
-
messages: [{ role: "user", content: options.text }],
|
|
22
|
-
system: systemPrompt,
|
|
23
|
-
max_tokens: options.maxLength || 500,
|
|
24
|
-
temperature: 0.3,
|
|
25
|
-
stream: false
|
|
26
|
-
});
|
|
27
|
-
const content = response.content.map((c) => c.type === "text" ? c.text : "").join("");
|
|
28
|
-
return {
|
|
29
|
-
id: response.id,
|
|
30
|
-
model: response.model,
|
|
31
|
-
summary: content,
|
|
32
|
-
usage: {
|
|
33
|
-
promptTokens: response.usage.input_tokens,
|
|
34
|
-
completionTokens: response.usage.output_tokens,
|
|
35
|
-
totalTokens: response.usage.input_tokens + response.usage.output_tokens
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
} catch (error) {
|
|
39
|
-
logger.errors("anthropic.summarize fatal", {
|
|
40
|
-
error,
|
|
41
|
-
source: "anthropic.summarize"
|
|
42
|
-
});
|
|
43
|
-
throw error;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
async *summarizeStream(options) {
|
|
47
|
-
const { logger } = options;
|
|
48
|
-
const systemPrompt = this.buildSummarizationPrompt(options);
|
|
49
|
-
const id = generateId(this.name);
|
|
50
|
-
const model = options.model;
|
|
51
|
-
let accumulatedContent = "";
|
|
52
|
-
let inputTokens = 0;
|
|
53
|
-
let outputTokens = 0;
|
|
54
|
-
logger.request(`activity=summarize provider=anthropic`, {
|
|
55
|
-
provider: "anthropic",
|
|
56
|
-
model,
|
|
57
|
-
stream: true
|
|
58
|
-
});
|
|
59
|
-
try {
|
|
60
|
-
const stream = await this.client.messages.create({
|
|
61
|
-
model: options.model,
|
|
62
|
-
messages: [{ role: "user", content: options.text }],
|
|
63
|
-
system: systemPrompt,
|
|
64
|
-
max_tokens: options.maxLength || 500,
|
|
65
|
-
temperature: 0.3,
|
|
66
|
-
stream: true
|
|
67
|
-
});
|
|
68
|
-
for await (const event of stream) {
|
|
69
|
-
logger.provider(`provider=anthropic type=${event.type}`, {
|
|
70
|
-
chunk: event
|
|
71
|
-
});
|
|
72
|
-
if (event.type === "message_start") {
|
|
73
|
-
inputTokens = event.message.usage.input_tokens;
|
|
74
|
-
} else if (event.type === "content_block_delta") {
|
|
75
|
-
if (event.delta.type === "text_delta") {
|
|
76
|
-
const delta = event.delta.text;
|
|
77
|
-
accumulatedContent += delta;
|
|
78
|
-
yield asChunk({
|
|
79
|
-
type: "TEXT_MESSAGE_CONTENT",
|
|
80
|
-
messageId: id,
|
|
81
|
-
model,
|
|
82
|
-
timestamp: Date.now(),
|
|
83
|
-
delta,
|
|
84
|
-
content: accumulatedContent
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
} else if (event.type === "message_delta") {
|
|
88
|
-
outputTokens = event.usage.output_tokens;
|
|
89
|
-
yield asChunk({
|
|
90
|
-
type: "RUN_FINISHED",
|
|
91
|
-
runId: id,
|
|
92
|
-
model,
|
|
93
|
-
timestamp: Date.now(),
|
|
94
|
-
finishReason: event.delta.stop_reason,
|
|
95
|
-
usage: {
|
|
96
|
-
promptTokens: inputTokens,
|
|
97
|
-
completionTokens: outputTokens,
|
|
98
|
-
totalTokens: inputTokens + outputTokens
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
} catch (error) {
|
|
104
|
-
logger.errors("anthropic.summarize fatal", {
|
|
105
|
-
error,
|
|
106
|
-
source: "anthropic.summarize"
|
|
107
|
-
});
|
|
108
|
-
throw error;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
buildSummarizationPrompt(options) {
|
|
112
|
-
let prompt = "You are a professional summarizer. ";
|
|
113
|
-
switch (options.style) {
|
|
114
|
-
case "bullet-points":
|
|
115
|
-
prompt += "Provide a summary in bullet point format. ";
|
|
116
|
-
break;
|
|
117
|
-
case "paragraph":
|
|
118
|
-
prompt += "Provide a summary in paragraph format. ";
|
|
119
|
-
break;
|
|
120
|
-
case "concise":
|
|
121
|
-
prompt += "Provide a very concise summary in 1-2 sentences. ";
|
|
122
|
-
break;
|
|
123
|
-
default:
|
|
124
|
-
prompt += "Provide a clear and concise summary. ";
|
|
125
|
-
}
|
|
126
|
-
if (options.focus && options.focus.length > 0) {
|
|
127
|
-
prompt += `Focus on the following aspects: ${options.focus.join(", ")}. `;
|
|
128
|
-
}
|
|
129
|
-
if (options.maxLength) {
|
|
130
|
-
prompt += `Keep the summary under ${options.maxLength} tokens. `;
|
|
131
|
-
}
|
|
132
|
-
return prompt;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
1
|
+
import { ChatStreamSummarizeAdapter } from "@tanstack/ai/adapters";
|
|
2
|
+
import { getAnthropicApiKeyFromEnv } from "../utils/client.js";
|
|
3
|
+
import { AnthropicTextAdapter } from "./text.js";
|
|
135
4
|
function createAnthropicSummarize(model, apiKey, config) {
|
|
136
|
-
return new
|
|
5
|
+
return new ChatStreamSummarizeAdapter(
|
|
6
|
+
new AnthropicTextAdapter({ apiKey, ...config }, model),
|
|
7
|
+
model,
|
|
8
|
+
"anthropic"
|
|
9
|
+
);
|
|
137
10
|
}
|
|
138
11
|
function anthropicSummarize(model, config) {
|
|
139
|
-
|
|
140
|
-
return createAnthropicSummarize(model, apiKey, config);
|
|
12
|
+
return createAnthropicSummarize(model, getAnthropicApiKeyFromEnv(), config);
|
|
141
13
|
}
|
|
142
14
|
export {
|
|
143
|
-
AnthropicSummarizeAdapter,
|
|
144
15
|
anthropicSummarize,
|
|
145
16
|
createAnthropicSummarize
|
|
146
17
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"summarize.js","sources":["../../../src/adapters/summarize.ts"],"sourcesContent":["import { BaseSummarizeAdapter } from '@tanstack/ai/adapters'\nimport {\n createAnthropicClient,\n generateId,\n getAnthropicApiKeyFromEnv,\n} from '../utils'\nimport type { ANTHROPIC_MODELS } from '../model-meta'\nimport type {\n StreamChunk,\n SummarizationOptions,\n SummarizationResult,\n} from '@tanstack/ai'\nimport type { AnthropicClientConfig } from '../utils'\n\n/** Cast an event object to StreamChunk. */\nconst asChunk = (chunk: Record<string, unknown>) =>\n chunk as unknown as StreamChunk\n\n/**\n * Configuration for Anthropic summarize adapter\n */\nexport interface AnthropicSummarizeConfig extends AnthropicClientConfig {}\n\n/**\n * Anthropic-specific provider options for summarization\n */\nexport interface AnthropicSummarizeProviderOptions {\n /** Temperature for response generation (0-1) */\n temperature?: number\n /** Maximum tokens in the response */\n maxTokens?: number\n}\n\n/** Model type for Anthropic summarization */\nexport type AnthropicSummarizeModel = (typeof ANTHROPIC_MODELS)[number]\n\n/**\n * Anthropic Summarize Adapter\n *\n * Tree-shakeable adapter for Anthropic summarization functionality.\n * Import only what you need for smaller bundle sizes.\n */\nexport class AnthropicSummarizeAdapter<\n TModel extends AnthropicSummarizeModel,\n> extends BaseSummarizeAdapter<TModel, AnthropicSummarizeProviderOptions> {\n readonly kind = 'summarize' as const\n readonly name = 'anthropic' as const\n\n private client: ReturnType<typeof createAnthropicClient>\n\n constructor(config: AnthropicSummarizeConfig, model: TModel) {\n super({}, model)\n this.client = createAnthropicClient(config)\n }\n\n async summarize(options: SummarizationOptions): Promise<SummarizationResult> {\n const { logger } = options\n const systemPrompt = this.buildSummarizationPrompt(options)\n\n logger.request(`activity=summarize provider=anthropic`, {\n provider: 'anthropic',\n model: options.model,\n })\n\n try {\n const response = await this.client.messages.create({\n model: options.model,\n messages: [{ role: 'user', content: options.text }],\n system: systemPrompt,\n max_tokens: options.maxLength || 500,\n temperature: 0.3,\n stream: false,\n })\n\n const content = response.content\n .map((c) => (c.type === 'text' ? c.text : ''))\n .join('')\n\n return {\n id: response.id,\n model: response.model,\n summary: content,\n usage: {\n promptTokens: response.usage.input_tokens,\n completionTokens: response.usage.output_tokens,\n totalTokens:\n response.usage.input_tokens + response.usage.output_tokens,\n },\n }\n } catch (error) {\n logger.errors('anthropic.summarize fatal', {\n error,\n source: 'anthropic.summarize',\n })\n throw error\n }\n }\n\n async *summarizeStream(\n options: SummarizationOptions,\n ): AsyncIterable<StreamChunk> {\n const { logger } = options\n const systemPrompt = this.buildSummarizationPrompt(options)\n const id = generateId(this.name)\n const model = options.model\n let accumulatedContent = ''\n let inputTokens = 0\n let outputTokens = 0\n\n logger.request(`activity=summarize provider=anthropic`, {\n provider: 'anthropic',\n model,\n stream: true,\n })\n\n try {\n const stream = await this.client.messages.create({\n model: options.model,\n messages: [{ role: 'user', content: options.text }],\n system: systemPrompt,\n max_tokens: options.maxLength || 500,\n temperature: 0.3,\n stream: true,\n })\n\n for await (const event of stream) {\n logger.provider(`provider=anthropic type=${event.type}`, {\n chunk: event,\n })\n\n if (event.type === 'message_start') {\n inputTokens = event.message.usage.input_tokens\n } else if (event.type === 'content_block_delta') {\n if (event.delta.type === 'text_delta') {\n const delta = event.delta.text\n accumulatedContent += delta\n yield asChunk({\n type: 'TEXT_MESSAGE_CONTENT',\n messageId: id,\n model,\n timestamp: Date.now(),\n delta,\n content: accumulatedContent,\n })\n }\n } else if (event.type === 'message_delta') {\n outputTokens = event.usage.output_tokens\n yield asChunk({\n type: 'RUN_FINISHED',\n runId: id,\n model,\n timestamp: Date.now(),\n finishReason: event.delta.stop_reason as\n | 'stop'\n | 'length'\n | 'content_filter'\n | null,\n usage: {\n promptTokens: inputTokens,\n completionTokens: outputTokens,\n totalTokens: inputTokens + outputTokens,\n },\n })\n }\n }\n } catch (error) {\n logger.errors('anthropic.summarize fatal', {\n error,\n source: 'anthropic.summarize',\n })\n throw error\n }\n }\n\n private buildSummarizationPrompt(options: SummarizationOptions): string {\n let prompt = 'You are a professional summarizer. '\n\n switch (options.style) {\n case 'bullet-points':\n prompt += 'Provide a summary in bullet point format. '\n break\n case 'paragraph':\n prompt += 'Provide a summary in paragraph format. '\n break\n case 'concise':\n prompt += 'Provide a very concise summary in 1-2 sentences. '\n break\n default:\n prompt += 'Provide a clear and concise summary. '\n }\n\n if (options.focus && options.focus.length > 0) {\n prompt += `Focus on the following aspects: ${options.focus.join(', ')}. `\n }\n\n if (options.maxLength) {\n prompt += `Keep the summary under ${options.maxLength} tokens. `\n }\n\n return prompt\n }\n}\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 */\nexport function createAnthropicSummarize<\n TModel extends AnthropicSummarizeModel,\n>(\n model: TModel,\n apiKey: string,\n config?: Omit<AnthropicSummarizeConfig, 'apiKey'>,\n): AnthropicSummarizeAdapter<TModel> {\n return new AnthropicSummarizeAdapter({ apiKey, ...config }, model)\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 */\nexport function anthropicSummarize<TModel extends AnthropicSummarizeModel>(\n model: TModel,\n config?: Omit<AnthropicSummarizeConfig, 'apiKey'>,\n): AnthropicSummarizeAdapter<TModel> {\n const apiKey = getAnthropicApiKeyFromEnv()\n return createAnthropicSummarize(model, apiKey, config)\n}\n"],"names":[],"mappings":";;AAeA,MAAM,UAAU,CAAC,UACf;AA0BK,MAAM,kCAEH,qBAAgE;AAAA,EAMxE,YAAY,QAAkC,OAAe;AAC3D,UAAM,CAAA,GAAI,KAAK;AANjB,SAAS,OAAO;AAChB,SAAS,OAAO;AAMd,SAAK,SAAS,sBAAsB,MAAM;AAAA,EAC5C;AAAA,EAEA,MAAM,UAAU,SAA6D;AAC3E,UAAM,EAAE,WAAW;AACnB,UAAM,eAAe,KAAK,yBAAyB,OAAO;AAE1D,WAAO,QAAQ,yCAAyC;AAAA,MACtD,UAAU;AAAA,MACV,OAAO,QAAQ;AAAA,IAAA,CAChB;AAED,QAAI;AACF,YAAM,WAAW,MAAM,KAAK,OAAO,SAAS,OAAO;AAAA,QACjD,OAAO,QAAQ;AAAA,QACf,UAAU,CAAC,EAAE,MAAM,QAAQ,SAAS,QAAQ,MAAM;AAAA,QAClD,QAAQ;AAAA,QACR,YAAY,QAAQ,aAAa;AAAA,QACjC,aAAa;AAAA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ACnE;AAUO,SAAS,mBACd,OACA,QACmC;AACnC,QAAM,SAAS,0BAAA;AACf,SAAO,yBAAyB,OAAO,QAAQ,MAAM;AACvD;"}
|
|
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;"}
|