@adminforth/completion-adapter-anthropic-messages 1.1.0 → 1.2.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/anthropic.ts +491 -0
- package/dist/anthropic.d.ts +40 -0
- package/dist/anthropic.js +379 -0
- package/dist/index.d.ts +56 -42
- package/dist/index.js +14 -403
- package/dist/langchain.d.ts +28 -0
- package/dist/langchain.js +72 -0
- package/index.ts +27 -555
- package/langchain.ts +126 -0
- package/package.json +3 -2
- package/pnpm-workspace.yaml +5 -0
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
11
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
12
|
+
var m = o[Symbol.asyncIterator], i;
|
|
13
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
14
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
15
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
16
|
+
};
|
|
17
|
+
import Anthropic from "@anthropic-ai/sdk";
|
|
18
|
+
import { jsonSchemaOutputFormat } from "@anthropic-ai/sdk/helpers/json-schema";
|
|
19
|
+
export function getApiKey(options) {
|
|
20
|
+
return options.anthropicApiKey || options.antropicApiKey;
|
|
21
|
+
}
|
|
22
|
+
function getErrorMessage(error) {
|
|
23
|
+
if (error instanceof Error && error.message)
|
|
24
|
+
return error.message;
|
|
25
|
+
return String(error || "Unknown error");
|
|
26
|
+
}
|
|
27
|
+
function normalizeOutputSchema(outputSchema) {
|
|
28
|
+
if (!outputSchema || typeof outputSchema !== "object")
|
|
29
|
+
return undefined;
|
|
30
|
+
const candidate = outputSchema.schema || outputSchema.json_schema || outputSchema;
|
|
31
|
+
if (!candidate || typeof candidate !== "object") {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
if (candidate.type !== "object") {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
return candidate;
|
|
38
|
+
}
|
|
39
|
+
function extractOutputText(data) {
|
|
40
|
+
var _a;
|
|
41
|
+
let text = "";
|
|
42
|
+
for (const block of (_a = data.content) !== null && _a !== void 0 ? _a : []) {
|
|
43
|
+
if ((block === null || block === void 0 ? void 0 : block.type) === "text" && typeof block.text === "string") {
|
|
44
|
+
text += block.text;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return text;
|
|
48
|
+
}
|
|
49
|
+
function extractReasoning(data) {
|
|
50
|
+
var _a;
|
|
51
|
+
let reasoning = "";
|
|
52
|
+
for (const block of (_a = data.content) !== null && _a !== void 0 ? _a : []) {
|
|
53
|
+
if ((block === null || block === void 0 ? void 0 : block.type) === "thinking" && typeof block.thinking === "string") {
|
|
54
|
+
reasoning += block.thinking;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return reasoning || undefined;
|
|
58
|
+
}
|
|
59
|
+
function extractUsedTokens(data) {
|
|
60
|
+
var _a, _b, _c, _d;
|
|
61
|
+
const usage = data.usage;
|
|
62
|
+
if (!usage)
|
|
63
|
+
return undefined;
|
|
64
|
+
const inputTokens = (_a = usage.input_tokens) !== null && _a !== void 0 ? _a : 0;
|
|
65
|
+
const cacheWriteTokens = (_b = usage.cache_creation_input_tokens) !== null && _b !== void 0 ? _b : 0;
|
|
66
|
+
const cacheReadTokens = (_c = usage.cache_read_input_tokens) !== null && _c !== void 0 ? _c : 0;
|
|
67
|
+
return {
|
|
68
|
+
input_uncached: inputTokens + cacheWriteTokens,
|
|
69
|
+
input_cached: cacheReadTokens,
|
|
70
|
+
output: (_d = usage.output_tokens) !== null && _d !== void 0 ? _d : 0,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function extractToolUse(data) {
|
|
74
|
+
var _a;
|
|
75
|
+
for (const block of (_a = data.content) !== null && _a !== void 0 ? _a : []) {
|
|
76
|
+
if ((block === null || block === void 0 ? void 0 : block.type) === "tool_use") {
|
|
77
|
+
return block;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
function stringifyToolResult(toolResult) {
|
|
83
|
+
if (typeof toolResult === "string")
|
|
84
|
+
return toolResult;
|
|
85
|
+
if (typeof toolResult === "undefined")
|
|
86
|
+
return "";
|
|
87
|
+
return JSON.stringify(toolResult);
|
|
88
|
+
}
|
|
89
|
+
function executeToolCall(toolCall, tools) {
|
|
90
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
+
const tool = tools === null || tools === void 0 ? void 0 : tools.find((candidate) => candidate.name === toolCall.name);
|
|
92
|
+
if (!tool) {
|
|
93
|
+
throw new Error(`Tool "${toolCall.name}" not found`);
|
|
94
|
+
}
|
|
95
|
+
const toolResult = yield tool.handler(toolCall.input || {});
|
|
96
|
+
return stringifyToolResult(toolResult);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
function mapTools(tools) {
|
|
100
|
+
if (!(tools === null || tools === void 0 ? void 0 : tools.length))
|
|
101
|
+
return undefined;
|
|
102
|
+
return tools.map((tool) => ({
|
|
103
|
+
name: tool.name,
|
|
104
|
+
description: tool.description,
|
|
105
|
+
input_schema: tool.input_schema,
|
|
106
|
+
}));
|
|
107
|
+
}
|
|
108
|
+
export function mapReasoningToThinking(reasoningEffort, maxTokens) {
|
|
109
|
+
if (reasoningEffort === "none")
|
|
110
|
+
return undefined;
|
|
111
|
+
const availableBudget = maxTokens - 128;
|
|
112
|
+
if (availableBudget < 1024)
|
|
113
|
+
return undefined;
|
|
114
|
+
const ratioByEffort = {
|
|
115
|
+
minimal: 0.25,
|
|
116
|
+
low: 0.35,
|
|
117
|
+
medium: 0.5,
|
|
118
|
+
high: 0.7,
|
|
119
|
+
xhigh: 0.85,
|
|
120
|
+
};
|
|
121
|
+
const targetBudget = Math.floor(maxTokens * ratioByEffort[reasoningEffort]);
|
|
122
|
+
return {
|
|
123
|
+
type: "enabled",
|
|
124
|
+
budget_tokens: Math.max(1024, Math.min(availableBudget, targetBudget)),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
export class AnthropicMessagesService {
|
|
128
|
+
constructor(options) {
|
|
129
|
+
this.options = options;
|
|
130
|
+
}
|
|
131
|
+
validate() {
|
|
132
|
+
if (!getApiKey(this.options)) {
|
|
133
|
+
throw new Error("anthropicApiKey is required");
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
measureTokensCount(content) {
|
|
137
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
138
|
+
const response = yield this.getClient().messages.countTokens({
|
|
139
|
+
model: this.options.model || "claude-sonnet-4-5-20250929",
|
|
140
|
+
messages: [{ role: "user", content }],
|
|
141
|
+
});
|
|
142
|
+
return response.input_tokens;
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
complete(request) {
|
|
146
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
147
|
+
const { content, maxTokens: requestMaxTokens = 50, outputSchema: requestOutputSchema, reasoningEffort: requestReasoningEffort = "low", tools, onChunk: streamChunkCallback, } = request;
|
|
148
|
+
const model = this.options.model || "claude-sonnet-4-5-20250929";
|
|
149
|
+
const isStreaming = typeof streamChunkCallback === "function";
|
|
150
|
+
const normalizedSchema = normalizeOutputSchema(requestOutputSchema);
|
|
151
|
+
const extra = Object.assign({}, (this.options.extraRequestBodyParameters || {}));
|
|
152
|
+
const thinking = extra.thinking || mapReasoningToThinking(requestReasoningEffort, requestMaxTokens);
|
|
153
|
+
const body = Object.assign(Object.assign({ model, max_tokens: requestMaxTokens, messages: [{ role: "user", content }], tools: mapTools(tools) }, (thinking ? { thinking } : {})), extra);
|
|
154
|
+
try {
|
|
155
|
+
if (requestOutputSchema && !normalizedSchema) {
|
|
156
|
+
return {
|
|
157
|
+
error: "Anthropic structured output requires a top-level JSON schema object with type: \"object\"",
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
if (normalizedSchema) {
|
|
161
|
+
return this.completeWithStructuredOutput(body, normalizedSchema, tools, isStreaming, streamChunkCallback);
|
|
162
|
+
}
|
|
163
|
+
if (!isStreaming) {
|
|
164
|
+
return this.completeNonStreaming(body, tools);
|
|
165
|
+
}
|
|
166
|
+
return this.completeStreaming(body, tools, streamChunkCallback);
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
return {
|
|
170
|
+
error: getErrorMessage(error),
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
getClient() {
|
|
176
|
+
if (!this.client) {
|
|
177
|
+
const apiKey = getApiKey(this.options);
|
|
178
|
+
if (!apiKey) {
|
|
179
|
+
throw new Error("anthropicApiKey is required");
|
|
180
|
+
}
|
|
181
|
+
this.client = new Anthropic({ apiKey });
|
|
182
|
+
}
|
|
183
|
+
return this.client;
|
|
184
|
+
}
|
|
185
|
+
completeWithStructuredOutput(body, normalizedSchema, tools, isStreaming, streamChunkCallback) {
|
|
186
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
187
|
+
const parsedMessage = (yield this.getClient().messages.parse(Object.assign(Object.assign({}, body), { output_config: {
|
|
188
|
+
format: jsonSchemaOutputFormat(normalizedSchema),
|
|
189
|
+
} })));
|
|
190
|
+
const parsedOutput = typeof parsedMessage.parsed_output === "undefined"
|
|
191
|
+
? extractOutputText(parsedMessage)
|
|
192
|
+
: JSON.stringify(parsedMessage.parsed_output);
|
|
193
|
+
const parsedReasoning = extractReasoning(parsedMessage);
|
|
194
|
+
const usedTokens = extractUsedTokens(parsedMessage);
|
|
195
|
+
if (parsedReasoning && isStreaming) {
|
|
196
|
+
yield (streamChunkCallback === null || streamChunkCallback === void 0 ? void 0 : streamChunkCallback(parsedReasoning, {
|
|
197
|
+
type: "reasoning",
|
|
198
|
+
delta: parsedReasoning,
|
|
199
|
+
text: parsedReasoning,
|
|
200
|
+
}));
|
|
201
|
+
}
|
|
202
|
+
if (parsedOutput && isStreaming) {
|
|
203
|
+
yield (streamChunkCallback === null || streamChunkCallback === void 0 ? void 0 : streamChunkCallback(parsedOutput, {
|
|
204
|
+
type: "output",
|
|
205
|
+
delta: parsedOutput,
|
|
206
|
+
text: parsedOutput,
|
|
207
|
+
}));
|
|
208
|
+
}
|
|
209
|
+
const toolUse = extractToolUse(parsedMessage);
|
|
210
|
+
if (toolUse) {
|
|
211
|
+
try {
|
|
212
|
+
const toolResult = yield executeToolCall(toolUse, tools);
|
|
213
|
+
if (toolResult && isStreaming) {
|
|
214
|
+
yield (streamChunkCallback === null || streamChunkCallback === void 0 ? void 0 : streamChunkCallback(toolResult, {
|
|
215
|
+
type: "output",
|
|
216
|
+
delta: toolResult,
|
|
217
|
+
text: toolResult,
|
|
218
|
+
}));
|
|
219
|
+
}
|
|
220
|
+
return {
|
|
221
|
+
content: toolResult,
|
|
222
|
+
finishReason: "tool_call",
|
|
223
|
+
used_tokens: usedTokens,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
return {
|
|
228
|
+
error: getErrorMessage(error),
|
|
229
|
+
finishReason: "tool_call",
|
|
230
|
+
used_tokens: usedTokens,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return {
|
|
235
|
+
content: parsedOutput || undefined,
|
|
236
|
+
finishReason: parsedMessage.stop_reason || undefined,
|
|
237
|
+
used_tokens: usedTokens,
|
|
238
|
+
};
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
completeNonStreaming(body, tools) {
|
|
242
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
243
|
+
const message = (yield this.getClient().messages.create(body));
|
|
244
|
+
const usedTokens = extractUsedTokens(message);
|
|
245
|
+
const toolUse = extractToolUse(message);
|
|
246
|
+
if (toolUse) {
|
|
247
|
+
try {
|
|
248
|
+
const toolResult = yield executeToolCall(toolUse, tools);
|
|
249
|
+
return {
|
|
250
|
+
content: toolResult,
|
|
251
|
+
finishReason: "tool_call",
|
|
252
|
+
used_tokens: usedTokens,
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
catch (error) {
|
|
256
|
+
return {
|
|
257
|
+
error: getErrorMessage(error),
|
|
258
|
+
finishReason: "tool_call",
|
|
259
|
+
used_tokens: usedTokens,
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
return {
|
|
264
|
+
content: extractOutputText(message) || undefined,
|
|
265
|
+
finishReason: message.stop_reason || undefined,
|
|
266
|
+
used_tokens: usedTokens,
|
|
267
|
+
};
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
completeStreaming(body, tools, streamChunkCallback) {
|
|
271
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
272
|
+
var _a, e_1, _b, _c;
|
|
273
|
+
var _d, _e;
|
|
274
|
+
const stream = this.getClient().messages.stream(body);
|
|
275
|
+
let fullContent = "";
|
|
276
|
+
let fullReasoning = "";
|
|
277
|
+
try {
|
|
278
|
+
for (var _f = true, _g = __asyncValues(stream), _h; _h = yield _g.next(), _a = _h.done, !_a; _f = true) {
|
|
279
|
+
_c = _h.value;
|
|
280
|
+
_f = false;
|
|
281
|
+
const event = _c;
|
|
282
|
+
if ((event === null || event === void 0 ? void 0 : event.type) !== "content_block_delta")
|
|
283
|
+
continue;
|
|
284
|
+
if (((_d = event.delta) === null || _d === void 0 ? void 0 : _d.type) === "text_delta" && typeof event.delta.text === "string") {
|
|
285
|
+
fullContent += event.delta.text;
|
|
286
|
+
yield (streamChunkCallback === null || streamChunkCallback === void 0 ? void 0 : streamChunkCallback(event.delta.text, {
|
|
287
|
+
type: "output",
|
|
288
|
+
delta: event.delta.text,
|
|
289
|
+
text: fullContent,
|
|
290
|
+
}));
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
if (((_e = event.delta) === null || _e === void 0 ? void 0 : _e.type) === "thinking_delta" &&
|
|
294
|
+
typeof event.delta.thinking === "string") {
|
|
295
|
+
fullReasoning += event.delta.thinking;
|
|
296
|
+
yield (streamChunkCallback === null || streamChunkCallback === void 0 ? void 0 : streamChunkCallback(event.delta.thinking, {
|
|
297
|
+
type: "reasoning",
|
|
298
|
+
delta: event.delta.thinking,
|
|
299
|
+
text: fullReasoning,
|
|
300
|
+
}));
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
305
|
+
finally {
|
|
306
|
+
try {
|
|
307
|
+
if (!_f && !_a && (_b = _g.return)) yield _b.call(_g);
|
|
308
|
+
}
|
|
309
|
+
finally { if (e_1) throw e_1.error; }
|
|
310
|
+
}
|
|
311
|
+
const message = (yield stream.finalMessage());
|
|
312
|
+
const finalContent = extractOutputText(message);
|
|
313
|
+
const finalReasoning = extractReasoning(message) || "";
|
|
314
|
+
const usedTokens = extractUsedTokens(message);
|
|
315
|
+
if (finalReasoning && finalReasoning !== fullReasoning) {
|
|
316
|
+
const delta = finalReasoning.startsWith(fullReasoning)
|
|
317
|
+
? finalReasoning.slice(fullReasoning.length)
|
|
318
|
+
: finalReasoning;
|
|
319
|
+
if (delta) {
|
|
320
|
+
fullReasoning = finalReasoning;
|
|
321
|
+
yield (streamChunkCallback === null || streamChunkCallback === void 0 ? void 0 : streamChunkCallback(delta, {
|
|
322
|
+
type: "reasoning",
|
|
323
|
+
delta,
|
|
324
|
+
text: finalReasoning,
|
|
325
|
+
}));
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
if (finalContent && finalContent !== fullContent) {
|
|
329
|
+
const delta = finalContent.startsWith(fullContent)
|
|
330
|
+
? finalContent.slice(fullContent.length)
|
|
331
|
+
: finalContent;
|
|
332
|
+
if (delta) {
|
|
333
|
+
fullContent = finalContent;
|
|
334
|
+
yield (streamChunkCallback === null || streamChunkCallback === void 0 ? void 0 : streamChunkCallback(delta, {
|
|
335
|
+
type: "output",
|
|
336
|
+
delta,
|
|
337
|
+
text: finalContent,
|
|
338
|
+
}));
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
const toolUse = extractToolUse(message);
|
|
342
|
+
if (toolUse) {
|
|
343
|
+
try {
|
|
344
|
+
const toolResult = yield executeToolCall(toolUse, tools);
|
|
345
|
+
if (toolResult) {
|
|
346
|
+
const delta = toolResult.startsWith(fullContent)
|
|
347
|
+
? toolResult.slice(fullContent.length)
|
|
348
|
+
: toolResult;
|
|
349
|
+
if (delta) {
|
|
350
|
+
yield (streamChunkCallback === null || streamChunkCallback === void 0 ? void 0 : streamChunkCallback(delta, {
|
|
351
|
+
type: "output",
|
|
352
|
+
delta,
|
|
353
|
+
text: toolResult,
|
|
354
|
+
}));
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
return {
|
|
358
|
+
content: toolResult,
|
|
359
|
+
finishReason: "tool_call",
|
|
360
|
+
used_tokens: usedTokens,
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
catch (error) {
|
|
364
|
+
return {
|
|
365
|
+
error: getErrorMessage(error),
|
|
366
|
+
content: fullContent || undefined,
|
|
367
|
+
finishReason: "tool_call",
|
|
368
|
+
used_tokens: usedTokens,
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
return {
|
|
373
|
+
content: fullContent || undefined,
|
|
374
|
+
finishReason: message.stop_reason || undefined,
|
|
375
|
+
used_tokens: usedTokens,
|
|
376
|
+
};
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,57 +1,71 @@
|
|
|
1
1
|
import type { AdapterOptions } from "./types.js";
|
|
2
|
-
import type { CompletionAdapter,
|
|
3
|
-
import {
|
|
2
|
+
import type { CompletionAdapter, CompletionTool } from "adminforth";
|
|
3
|
+
import { type CompletionRequestInput, type CompletionResult, type ReasoningEffort, type StreamChunkCallback } from "./anthropic.js";
|
|
4
|
+
import { type AgentModelPurpose } from "./langchain.js";
|
|
4
5
|
export type { AdapterOptions } from "./types.js";
|
|
5
|
-
|
|
6
|
-
type ReasoningEffort = "none" | "minimal" | "low" | "medium" | "high" | "xhigh";
|
|
7
|
-
type AgentModelPurpose = "primary" | "summary";
|
|
8
|
-
type CompletionRequestInput = {
|
|
9
|
-
content: string;
|
|
10
|
-
maxTokens?: number;
|
|
11
|
-
outputSchema?: any;
|
|
12
|
-
reasoningEffort?: ReasoningEffort;
|
|
13
|
-
tools?: CompletionTool[];
|
|
14
|
-
onChunk?: StreamChunkCallback;
|
|
15
|
-
};
|
|
16
|
-
type LangChainMessageLike = {
|
|
17
|
-
content?: unknown;
|
|
18
|
-
text?: string;
|
|
19
|
-
type?: string;
|
|
20
|
-
getType?: () => string;
|
|
21
|
-
_getType?: () => string;
|
|
22
|
-
};
|
|
23
|
-
type LangChainModelCallRequest = {
|
|
24
|
-
systemMessage: LangChainMessageLike & {
|
|
25
|
-
concat: (content: string) => LangChainMessageLike;
|
|
26
|
-
};
|
|
27
|
-
messages: LangChainMessageLike[];
|
|
28
|
-
};
|
|
29
|
-
type UsedTokens = {
|
|
30
|
-
input_uncached: number;
|
|
31
|
-
input_cached: number;
|
|
32
|
-
output: number;
|
|
33
|
-
};
|
|
34
|
-
export default class CompletionAdapterAnthropicMessages implements CompletionAdapter {
|
|
6
|
+
declare class CompletionAdapterAnthropicMessages implements CompletionAdapter {
|
|
35
7
|
options: AdapterOptions;
|
|
36
|
-
private
|
|
8
|
+
private anthropic;
|
|
37
9
|
constructor(options: AdapterOptions);
|
|
38
|
-
private getClient;
|
|
39
10
|
validate(): void;
|
|
40
11
|
measureTokensCount(content: string): Promise<number>;
|
|
41
12
|
getLangChainAgentSpec(params: {
|
|
42
13
|
maxTokens: number;
|
|
43
14
|
purpose: AgentModelPurpose;
|
|
44
15
|
}): {
|
|
45
|
-
model: ChatAnthropic;
|
|
16
|
+
model: import("@langchain/anthropic").ChatAnthropic;
|
|
46
17
|
middleware: {
|
|
47
18
|
name: string;
|
|
48
|
-
wrapModelCall(request:
|
|
19
|
+
wrapModelCall(request: {
|
|
20
|
+
systemMessage: {
|
|
21
|
+
content?: unknown;
|
|
22
|
+
text?: string;
|
|
23
|
+
type?: string;
|
|
24
|
+
getType?: () => string;
|
|
25
|
+
_getType?: () => string;
|
|
26
|
+
} & {
|
|
27
|
+
concat: (content: string) => {
|
|
28
|
+
content?: unknown;
|
|
29
|
+
text?: string;
|
|
30
|
+
type?: string;
|
|
31
|
+
getType?: () => string;
|
|
32
|
+
_getType?: () => string;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
messages: {
|
|
36
|
+
content?: unknown;
|
|
37
|
+
text?: string;
|
|
38
|
+
type?: string;
|
|
39
|
+
getType?: () => string;
|
|
40
|
+
_getType?: () => string;
|
|
41
|
+
}[];
|
|
42
|
+
}, handler: (request: {
|
|
43
|
+
systemMessage: {
|
|
44
|
+
content?: unknown;
|
|
45
|
+
text?: string;
|
|
46
|
+
type?: string;
|
|
47
|
+
getType?: () => string;
|
|
48
|
+
_getType?: () => string;
|
|
49
|
+
} & {
|
|
50
|
+
concat: (content: string) => {
|
|
51
|
+
content?: unknown;
|
|
52
|
+
text?: string;
|
|
53
|
+
type?: string;
|
|
54
|
+
getType?: () => string;
|
|
55
|
+
_getType?: () => string;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
messages: {
|
|
59
|
+
content?: unknown;
|
|
60
|
+
text?: string;
|
|
61
|
+
type?: string;
|
|
62
|
+
getType?: () => string;
|
|
63
|
+
_getType?: () => string;
|
|
64
|
+
}[];
|
|
65
|
+
}) => unknown): Promise<unknown>;
|
|
49
66
|
}[];
|
|
50
67
|
};
|
|
51
|
-
complete: (requestOrContent: CompletionRequestInput | string, maxTokens?: number, outputSchema?: any, reasoningEffort?: ReasoningEffort, toolsOrOnChunk?: CompletionTool[] | StreamChunkCallback, onChunk?: StreamChunkCallback) => Promise<
|
|
52
|
-
content?: string;
|
|
53
|
-
finishReason?: string;
|
|
54
|
-
error?: string;
|
|
55
|
-
used_tokens?: UsedTokens;
|
|
56
|
-
}>;
|
|
68
|
+
complete: (requestOrContent: CompletionRequestInput | string, maxTokens?: number, outputSchema?: any, reasoningEffort?: ReasoningEffort, toolsOrOnChunk?: CompletionTool[] | StreamChunkCallback, onChunk?: StreamChunkCallback) => Promise<CompletionResult>;
|
|
57
69
|
}
|
|
70
|
+
export { CompletionAdapterAnthropicMessages };
|
|
71
|
+
export default CompletionAdapterAnthropicMessages;
|