@arvo-tools/agentic 1.2.2 → 1.2.4
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/Agent/index.d.ts +1 -1
- package/dist/Agent/index.d.ts.map +1 -1
- package/dist/Agent/index.js +2 -1
- package/dist/Agent/index.js.map +1 -1
- package/dist/Agent/stream/schema.d.ts +331 -7
- package/dist/Agent/stream/schema.d.ts.map +1 -1
- package/dist/Agent/stream/schema.js +51 -1
- package/dist/Agent/stream/schema.js.map +1 -1
- package/dist/Agent/types.d.ts +7 -1
- package/dist/Agent/types.d.ts.map +1 -1
- package/dist/Integrations/anthropic/index.d.ts.map +1 -1
- package/dist/Integrations/anthropic/index.js +40 -84
- package/dist/Integrations/anthropic/index.js.map +1 -1
- package/dist/Integrations/anthropic/nonstreamable.d.ts +7 -0
- package/dist/Integrations/anthropic/nonstreamable.d.ts.map +1 -0
- package/dist/Integrations/anthropic/nonstreamable.js +112 -0
- package/dist/Integrations/anthropic/nonstreamable.js.map +1 -0
- package/dist/Integrations/anthropic/streamable.d.ts +9 -0
- package/dist/Integrations/anthropic/streamable.d.ts.map +1 -0
- package/dist/Integrations/anthropic/streamable.js +245 -0
- package/dist/Integrations/anthropic/streamable.js.map +1 -0
- package/dist/Integrations/anthropic/types.d.ts +1 -1
- package/dist/Integrations/anthropic/types.d.ts.map +1 -1
- package/dist/Integrations/defaultContextTransformer.d.ts +3 -0
- package/dist/Integrations/defaultContextTransformer.d.ts.map +1 -0
- package/dist/Integrations/defaultContextTransformer.js +62 -0
- package/dist/Integrations/defaultContextTransformer.js.map +1 -0
- package/dist/Integrations/openai/index.d.ts.map +1 -1
- package/dist/Integrations/openai/index.js +48 -92
- package/dist/Integrations/openai/index.js.map +1 -1
- package/dist/Integrations/openai/nonstreamable.d.ts +10 -0
- package/dist/Integrations/openai/nonstreamable.d.ts.map +1 -0
- package/dist/Integrations/openai/nonstreamable.js +129 -0
- package/dist/Integrations/openai/nonstreamable.js.map +1 -0
- package/dist/Integrations/openai/streamable.d.ts +12 -0
- package/dist/Integrations/openai/streamable.d.ts.map +1 -0
- package/dist/Integrations/openai/streamable.js +321 -0
- package/dist/Integrations/openai/streamable.js.map +1 -0
- package/dist/Integrations/openai/types.d.ts +1 -1
- package/dist/Integrations/openai/types.d.ts.map +1 -1
- package/dist/Integrations/types.d.ts +5 -0
- package/dist/Integrations/types.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/package.json +5 -4
|
@@ -64,7 +64,10 @@ var api_1 = require("@opentelemetry/api");
|
|
|
64
64
|
var arvo_core_1 = require("arvo-core");
|
|
65
65
|
var zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
66
66
|
var utils_1 = require("../../Agent/utils");
|
|
67
|
+
var defaultContextTransformer_1 = require("../defaultContextTransformer");
|
|
67
68
|
var prompts_1 = require("../prompts");
|
|
69
|
+
var nonstreamable_1 = require("./nonstreamable");
|
|
70
|
+
var streamable_1 = require("./streamable");
|
|
68
71
|
var utils_2 = require("./utils");
|
|
69
72
|
/**
|
|
70
73
|
* Creates an Arvo-compatible LLM Adapter for Anthropic Claude models.
|
|
@@ -88,7 +91,7 @@ var utils_2 = require("./utils");
|
|
|
88
91
|
var anthropicLLMIntegration = function (client, config) {
|
|
89
92
|
return function (_a, _b) { return __awaiter(void 0, [_a, _b], void 0, function (_c, _d) {
|
|
90
93
|
var _e;
|
|
91
|
-
var _messages = _c.messages, _system = _c.system, tools = _c.tools, outputFormat = _c.outputFormat, lifecycle = _c.lifecycle, toolInteractions = _c.toolInteractions;
|
|
94
|
+
var _messages = _c.messages, _system = _c.system, tools = _c.tools, outputFormat = _c.outputFormat, lifecycle = _c.lifecycle, toolInteractions = _c.toolInteractions, onStream = _c.onStream;
|
|
92
95
|
var otelInfo = _d.otelInfo;
|
|
93
96
|
return __generator(this, function (_f) {
|
|
94
97
|
switch (_f.label) {
|
|
@@ -105,40 +108,21 @@ var anthropicLLMIntegration = function (client, config) {
|
|
|
105
108
|
_e),
|
|
106
109
|
},
|
|
107
110
|
fn: function (span) { return __awaiter(void 0, void 0, void 0, function () {
|
|
108
|
-
var messageCreateParams, _a, messages, system, limitMessage, jsonSchema, schemaInstruction, toolDef, tools_1, tools_1_1, tool, formattedMessages,
|
|
109
|
-
var e_2, _b
|
|
110
|
-
var _d, _e, _f, _g, _h, _j, _k;
|
|
111
|
+
var messageCreateParams, _a, messages, system, limitMessage, jsonSchema, schemaInstruction, toolDef, tools_1, tools_1_1, tool, formattedMessages, enableStreaming, result, llmUsage, executionUnits, content, e_1;
|
|
112
|
+
var e_2, _b;
|
|
113
|
+
var _c, _d, _e, _f, _g, _h, _j, _k;
|
|
111
114
|
return __generator(this, function (_l) {
|
|
112
115
|
switch (_l.label) {
|
|
113
116
|
case 0:
|
|
114
|
-
messageCreateParams = (
|
|
115
|
-
|
|
116
|
-
max_tokens: 4096,
|
|
117
|
-
temperature: 0,
|
|
118
|
-
};
|
|
119
|
-
return [4 /*yield*/, ((_e = config === null || config === void 0 ? void 0 : config.contextTransformer) === null || _e === void 0 ? void 0 : _e.call(config, {
|
|
117
|
+
messageCreateParams = __assign({ model: 'claude-sonnet-4-20250514', max_tokens: 4096, temperature: 0, stream: true }, ((_c = config === null || config === void 0 ? void 0 : config.invocationParam) !== null && _c !== void 0 ? _c : {}));
|
|
118
|
+
return [4 /*yield*/, ((_d = config === null || config === void 0 ? void 0 : config.contextTransformer) !== null && _d !== void 0 ? _d : defaultContextTransformer_1.defaultContextTransformer)({
|
|
120
119
|
messages: _messages,
|
|
121
120
|
system: _system,
|
|
122
|
-
})
|
|
121
|
+
})];
|
|
123
122
|
case 1:
|
|
124
|
-
_a =
|
|
125
|
-
messages: _messages.map(function (item) {
|
|
126
|
-
if (item.content.type === 'media' && item.seenCount > 0) {
|
|
127
|
-
return {
|
|
128
|
-
role: item.role,
|
|
129
|
-
content: {
|
|
130
|
-
type: 'text',
|
|
131
|
-
content: "Media file (type: ".concat(item.content.contentType.type, "@").concat(item.content.contentType.format, ") already parsed and looked at. No need for you to look at it again"),
|
|
132
|
-
},
|
|
133
|
-
seenCount: item.seenCount,
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
return item;
|
|
137
|
-
}),
|
|
138
|
-
system: _system,
|
|
139
|
-
}, messages = _a.messages, system = _a.system;
|
|
123
|
+
_a = _l.sent(), messages = _a.messages, system = _a.system;
|
|
140
124
|
if (toolInteractions.exhausted) {
|
|
141
|
-
limitMessage = (
|
|
125
|
+
limitMessage = (_f = (_e = config === null || config === void 0 ? void 0 : config.toolLimitPrompt) === null || _e === void 0 ? void 0 : _e.call(config, toolInteractions)) !== null && _f !== void 0 ? _f : prompts_1.DEFAULT_TOOL_LIMIT_PROMPT;
|
|
142
126
|
messages.push({
|
|
143
127
|
role: 'user',
|
|
144
128
|
content: {
|
|
@@ -149,7 +133,6 @@ var anthropicLLMIntegration = function (client, config) {
|
|
|
149
133
|
});
|
|
150
134
|
system = "".concat(system, "\n\n").concat(limitMessage);
|
|
151
135
|
}
|
|
152
|
-
// For JSON output format, append schema instructions to the system prompt
|
|
153
136
|
if (outputFormat.type === 'json') {
|
|
154
137
|
jsonSchema = (0, zod_to_json_schema_1.zodToJsonSchema)(outputFormat.format);
|
|
155
138
|
schemaInstruction = (0, prompts_1.jsonPrompt)(JSON.stringify(jsonSchema));
|
|
@@ -168,7 +151,7 @@ var anthropicLLMIntegration = function (client, config) {
|
|
|
168
151
|
}, span);
|
|
169
152
|
_l.label = 2;
|
|
170
153
|
case 2:
|
|
171
|
-
_l.trys.push([2,
|
|
154
|
+
_l.trys.push([2, 7, 8, 9]);
|
|
172
155
|
toolDef = [];
|
|
173
156
|
try {
|
|
174
157
|
for (tools_1 = __values(tools), tools_1_1 = tools_1.next(); !tools_1_1.done; tools_1_1 = tools_1.next()) {
|
|
@@ -188,65 +171,37 @@ var anthropicLLMIntegration = function (client, config) {
|
|
|
188
171
|
finally { if (e_2) throw e_2.error; }
|
|
189
172
|
}
|
|
190
173
|
formattedMessages = (0, utils_2.formatMessagesForAnthropic)(messages);
|
|
191
|
-
|
|
174
|
+
enableStreaming = (_h = (_g = config === null || config === void 0 ? void 0 : config.invocationParam) === null || _g === void 0 ? void 0 : _g.stream) !== null && _h !== void 0 ? _h : false;
|
|
175
|
+
result = void 0;
|
|
176
|
+
if (!enableStreaming) return [3 /*break*/, 4];
|
|
177
|
+
return [4 /*yield*/, (0, streamable_1.streamableAnthropic)(client, __assign(__assign({}, messageCreateParams), { stream: true, system: system !== null && system !== void 0 ? system : undefined, tools: toolDef.length ? toolDef : undefined, messages: formattedMessages }), { span: span, onStream: onStream })];
|
|
192
178
|
case 3:
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
179
|
+
result = _l.sent();
|
|
180
|
+
return [3 /*break*/, 6];
|
|
181
|
+
case 4: return [4 /*yield*/, (0, nonstreamable_1.nonStreamableAnthropic)(client, __assign(__assign({}, messageCreateParams), { stream: false, system: system !== null && system !== void 0 ? system : undefined, tools: toolDef.length ? toolDef : undefined, messages: formattedMessages }), { span: span })];
|
|
182
|
+
case 5:
|
|
183
|
+
result = _l.sent();
|
|
184
|
+
_l.label = 6;
|
|
185
|
+
case 6:
|
|
186
|
+
llmUsage = result.usage;
|
|
200
187
|
executionUnits = (_k = (_j = config === null || config === void 0 ? void 0 : config.executionunits) === null || _j === void 0 ? void 0 : _j.call(config, llmUsage.tokens.prompt, llmUsage.tokens.completion)) !== null && _k !== void 0 ? _k : llmUsage.tokens.prompt + llmUsage.tokens.completion;
|
|
201
188
|
(0, utils_1.setOpenInferenceUsageOutputAttr)(llmUsage, span);
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
toolUseId: toolCall.id,
|
|
211
|
-
name: toolCall.name,
|
|
212
|
-
input: toolCall.input,
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
catch (err) {
|
|
216
|
-
(0, arvo_core_1.exceptionToSpan)(err, span);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
221
|
-
finally {
|
|
222
|
-
try {
|
|
223
|
-
if (toolUseBlocks_1_1 && !toolUseBlocks_1_1.done && (_c = toolUseBlocks_1.return)) _c.call(toolUseBlocks_1);
|
|
224
|
-
}
|
|
225
|
-
finally { if (e_3) throw e_3.error; }
|
|
226
|
-
}
|
|
227
|
-
if (toolRequests.length) {
|
|
228
|
-
(0, utils_1.setOpenInferenceToolCallOutputAttr)({ toolCalls: toolRequests }, span);
|
|
229
|
-
return [2 /*return*/, {
|
|
230
|
-
type: 'tool_call',
|
|
231
|
-
toolRequests: toolRequests,
|
|
232
|
-
usage: llmUsage,
|
|
233
|
-
executionUnits: executionUnits,
|
|
234
|
-
}];
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
textBlocks = response.content.filter(function (block) { return block.type === 'text'; });
|
|
238
|
-
content = textBlocks.map(function (block) { return block.text; }).join('');
|
|
239
|
-
// Handle stop reasons
|
|
240
|
-
if (response.stop_reason === 'max_tokens') {
|
|
241
|
-
content = "".concat(content, " [Max response token limit (<= ").concat(messageCreateParams.max_tokens, ") reached]");
|
|
242
|
-
throw new Error("Agent reached max token limit. The partial response is \"".concat(content, "\""));
|
|
189
|
+
if (result.toolRequests && result.toolRequests.length > 0) {
|
|
190
|
+
(0, utils_1.setOpenInferenceToolCallOutputAttr)({ toolCalls: result.toolRequests }, span);
|
|
191
|
+
return [2 /*return*/, {
|
|
192
|
+
type: 'tool_call',
|
|
193
|
+
toolRequests: result.toolRequests,
|
|
194
|
+
usage: llmUsage,
|
|
195
|
+
executionUnits: executionUnits,
|
|
196
|
+
}];
|
|
243
197
|
}
|
|
198
|
+
content = result.response || '';
|
|
244
199
|
(0, utils_1.setOpenInferenceResponseOutputAttr)({ response: content }, span);
|
|
245
200
|
if (outputFormat.type === 'json') {
|
|
246
201
|
return [2 /*return*/, {
|
|
247
202
|
type: 'json',
|
|
248
|
-
content: content || '
|
|
249
|
-
parsedContent: (0, utils_1.tryParseJson)(content || '
|
|
203
|
+
content: content || '',
|
|
204
|
+
parsedContent: (0, utils_1.tryParseJson)(content || ''),
|
|
250
205
|
usage: llmUsage,
|
|
251
206
|
executionUnits: executionUnits,
|
|
252
207
|
}];
|
|
@@ -257,14 +212,15 @@ var anthropicLLMIntegration = function (client, config) {
|
|
|
257
212
|
usage: llmUsage,
|
|
258
213
|
executionUnits: executionUnits,
|
|
259
214
|
}];
|
|
260
|
-
case
|
|
215
|
+
case 7:
|
|
261
216
|
e_1 = _l.sent();
|
|
262
217
|
span.setStatus({ code: api_1.SpanStatusCode.ERROR, message: e_1 === null || e_1 === void 0 ? void 0 : e_1.message });
|
|
218
|
+
(0, arvo_core_1.exceptionToSpan)(e_1, span);
|
|
263
219
|
throw e_1;
|
|
264
|
-
case
|
|
220
|
+
case 8:
|
|
265
221
|
span.end();
|
|
266
222
|
return [7 /*endfinally*/];
|
|
267
|
-
case
|
|
223
|
+
case 9: return [2 /*return*/];
|
|
268
224
|
}
|
|
269
225
|
});
|
|
270
226
|
}); },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Integrations/anthropic/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,kGAGqD;AACrD,0CAAoD;AACpD,uCAA+D;AAC/D,yDAAqD;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Integrations/anthropic/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,kGAGqD;AACrD,0CAAoD;AACp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AI,CAAC,CAAC;wCAClC,MAAM,GAAC,CAAC;;wCAER,IAAI,CAAC,GAAG,EAAE,CAAC;;;;;6BAEd;qBACF,CAAC,EAAA;wBArJF,sBAAA,SAqJE,EAAA;;;SAAA;AAjKJ,CAiKI,CAAC;AAnKM,QAAA,uBAAuB,2BAmK7B"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type Anthropic from '@anthropic-ai/sdk';
|
|
2
|
+
import type { Span } from '@opentelemetry/api';
|
|
3
|
+
import type { LLMExecutionResult } from '../types';
|
|
4
|
+
export declare const nonStreamableAnthropic: (client: Anthropic, param: Anthropic.MessageCreateParamsNonStreaming, config: {
|
|
5
|
+
span: Span;
|
|
6
|
+
}) => Promise<LLMExecutionResult>;
|
|
7
|
+
//# sourceMappingURL=nonstreamable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nonstreamable.d.ts","sourceRoot":"","sources":["../../../src/Integrations/anthropic/nonstreamable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,mBAAmB,CAAC;AAC/C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAG/C,OAAO,KAAK,EAA6B,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAE9E,eAAO,MAAM,sBAAsB,GACjC,QAAQ,SAAS,EACjB,OAAO,SAAS,CAAC,+BAA+B,EAChD,QAAQ;IACN,IAAI,EAAE,IAAI,CAAC;CACZ,KACA,OAAO,CAAC,kBAAkB,CAsD5B,CAAC"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __values = (this && this.__values) || function(o) {
|
|
39
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
40
|
+
if (m) return m.call(o);
|
|
41
|
+
if (o && typeof o.length === "number") return {
|
|
42
|
+
next: function () {
|
|
43
|
+
if (o && i >= o.length) o = void 0;
|
|
44
|
+
return { value: o && o[i++], done: !o };
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
48
|
+
};
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
exports.nonStreamableAnthropic = void 0;
|
|
51
|
+
var arvo_core_1 = require("arvo-core");
|
|
52
|
+
var nonStreamableAnthropic = function (client, param, config) { return __awaiter(void 0, void 0, void 0, function () {
|
|
53
|
+
var response, llmUsage, toolUseBlocks, toolRequests, toolUseBlocks_1, toolUseBlocks_1_1, toolCall, textBlocks, content;
|
|
54
|
+
var e_1, _a;
|
|
55
|
+
return __generator(this, function (_b) {
|
|
56
|
+
switch (_b.label) {
|
|
57
|
+
case 0: return [4 /*yield*/, client.messages.create(param)];
|
|
58
|
+
case 1:
|
|
59
|
+
response = _b.sent();
|
|
60
|
+
llmUsage = {
|
|
61
|
+
tokens: {
|
|
62
|
+
prompt: response.usage.input_tokens,
|
|
63
|
+
completion: response.usage.output_tokens,
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
toolUseBlocks = response.content.filter(function (block) { return block.type === 'tool_use'; });
|
|
67
|
+
if (toolUseBlocks.length > 0) {
|
|
68
|
+
toolRequests = [];
|
|
69
|
+
try {
|
|
70
|
+
for (toolUseBlocks_1 = __values(toolUseBlocks), toolUseBlocks_1_1 = toolUseBlocks_1.next(); !toolUseBlocks_1_1.done; toolUseBlocks_1_1 = toolUseBlocks_1.next()) {
|
|
71
|
+
toolCall = toolUseBlocks_1_1.value;
|
|
72
|
+
toolRequests.push({
|
|
73
|
+
toolUseId: toolCall.id,
|
|
74
|
+
name: toolCall.name,
|
|
75
|
+
input: toolCall.input,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
80
|
+
finally {
|
|
81
|
+
try {
|
|
82
|
+
if (toolUseBlocks_1_1 && !toolUseBlocks_1_1.done && (_a = toolUseBlocks_1.return)) _a.call(toolUseBlocks_1);
|
|
83
|
+
}
|
|
84
|
+
finally { if (e_1) throw e_1.error; }
|
|
85
|
+
}
|
|
86
|
+
return [2 /*return*/, {
|
|
87
|
+
toolRequests: toolRequests,
|
|
88
|
+
response: null,
|
|
89
|
+
usage: llmUsage,
|
|
90
|
+
}];
|
|
91
|
+
}
|
|
92
|
+
textBlocks = response.content.filter(function (block) { return block.type === 'text'; });
|
|
93
|
+
content = textBlocks.map(function (block) { return block.text; }).join('');
|
|
94
|
+
if (response.stop_reason === 'max_tokens') {
|
|
95
|
+
content = content
|
|
96
|
+
? "".concat(content, "\n\n[Response truncated: Maximum token limit reached]")
|
|
97
|
+
: '[Response truncated: Maximum token limit reached]';
|
|
98
|
+
(0, arvo_core_1.logToSpan)({
|
|
99
|
+
level: 'WARNING',
|
|
100
|
+
message: 'Max token limit reached. Response truncated',
|
|
101
|
+
}, config.span);
|
|
102
|
+
}
|
|
103
|
+
return [2 /*return*/, {
|
|
104
|
+
toolRequests: null,
|
|
105
|
+
response: content,
|
|
106
|
+
usage: llmUsage,
|
|
107
|
+
}];
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}); };
|
|
111
|
+
exports.nonStreamableAnthropic = nonStreamableAnthropic;
|
|
112
|
+
//# sourceMappingURL=nonstreamable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nonstreamable.js","sourceRoot":"","sources":["../../../src/Integrations/anthropic/nonstreamable.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,uCAAsC;AAI/B,IAAM,sBAAsB,GAAG,UACpC,MAAiB,EACjB,KAAgD,EAChD,MAEC;;;;;oBAEgB,qBAAM,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,EAAA;;gBAA9C,QAAQ,GAAG,SAAmC;gBAE9C,QAAQ,GAAoD;oBAChE,MAAM,EAAE;wBACN,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,YAAY;wBACnC,UAAU,EAAE,QAAQ,CAAC,KAAK,CAAC,aAAa;qBACzC;iBACF,CAAC;gBAEI,aAAa,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,CAC3C,UAAC,KAAK,IAAsC,OAAA,KAAK,CAAC,IAAI,KAAK,UAAU,EAAzB,CAAyB,CACtE,CAAC;gBAEF,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;oBACvB,YAAY,GAAyC,EAAE,CAAC;;wBAC9D,KAAuB,kBAAA,SAAA,aAAa,CAAA,mHAAE,CAAC;4BAA5B,QAAQ;4BACjB,YAAY,CAAC,IAAI,CAAC;gCAChB,SAAS,EAAE,QAAQ,CAAC,EAAE;gCACtB,IAAI,EAAE,QAAQ,CAAC,IAAI;gCACnB,KAAK,EAAE,QAAQ,CAAC,KAAgC;6BACjD,CAAC,CAAC;wBACL,CAAC;;;;;;;;;oBACD,sBAAO;4BACL,YAAY,cAAA;4BACZ,QAAQ,EAAE,IAAI;4BACd,KAAK,EAAE,QAAQ;yBAChB,EAAC;gBACJ,CAAC;gBAEK,UAAU,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,CACxC,UAAC,KAAK,IAAmC,OAAA,KAAK,CAAC,IAAI,KAAK,MAAM,EAArB,CAAqB,CAC/D,CAAC;gBACE,OAAO,GAAG,UAAU,CAAC,GAAG,CAAC,UAAC,KAAK,IAAK,OAAA,KAAK,CAAC,IAAI,EAAV,CAAU,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBAE7D,IAAI,QAAQ,CAAC,WAAW,KAAK,YAAY,EAAE,CAAC;oBAC1C,OAAO,GAAG,OAAO;wBACf,CAAC,CAAC,UAAG,OAAO,0DAAuD;wBACnE,CAAC,CAAC,mDAAmD,CAAC;oBAExD,IAAA,qBAAS,EACP;wBACE,KAAK,EAAE,SAAS;wBAChB,OAAO,EAAE,6CAA6C;qBACvD,EACD,MAAM,CAAC,IAAI,CACZ,CAAC;gBACJ,CAAC;gBAED,sBAAO;wBACL,YAAY,EAAE,IAAI;wBAClB,QAAQ,EAAE,OAAO;wBACjB,KAAK,EAAE,QAAQ;qBAChB,EAAC;;;KACH,CAAC;AA5DW,QAAA,sBAAsB,0BA4DjC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type Anthropic from '@anthropic-ai/sdk';
|
|
2
|
+
import type { Span } from '@opentelemetry/api';
|
|
3
|
+
import type { AgentEventStreamer } from '../../Agent/stream/types';
|
|
4
|
+
import type { LLMExecutionResult } from '../types';
|
|
5
|
+
export declare const streamableAnthropic: (client: Anthropic, param: Anthropic.MessageCreateParamsStreaming, config: {
|
|
6
|
+
span: Span;
|
|
7
|
+
onStream: AgentEventStreamer;
|
|
8
|
+
}) => Promise<LLMExecutionResult>;
|
|
9
|
+
//# sourceMappingURL=streamable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streamable.d.ts","sourceRoot":"","sources":["../../../src/Integrations/anthropic/streamable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,mBAAmB,CAAC;AAC/C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE/C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAEnE,OAAO,KAAK,EAA6B,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAE9E,eAAO,MAAM,mBAAmB,GAC9B,QAAQ,SAAS,EACjB,OAAO,SAAS,CAAC,4BAA4B,EAC7C,QAAQ;IACN,IAAI,EAAE,IAAI,CAAC;IACX,QAAQ,EAAE,kBAAkB,CAAC;CAC9B,KACA,OAAO,CAAC,kBAAkB,CAkK5B,CAAC"}
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
39
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
40
|
+
var m = o[Symbol.asyncIterator], i;
|
|
41
|
+
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);
|
|
42
|
+
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); }); }; }
|
|
43
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
44
|
+
};
|
|
45
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
+
exports.streamableAnthropic = void 0;
|
|
47
|
+
var arvo_core_1 = require("arvo-core");
|
|
48
|
+
var streamableAnthropic = function (client, param, config) { return __awaiter(void 0, void 0, void 0, function () {
|
|
49
|
+
var otelHeaders, stream, toolRequests, finalResponse, stopReason, inputTokens, outputTokens, toolUseBlocks, _a, stream_1, stream_1_1, event, block, block, e_1_1, llmUsage, processedResponse;
|
|
50
|
+
var _b, e_1, _c, _d;
|
|
51
|
+
var _e;
|
|
52
|
+
return __generator(this, function (_f) {
|
|
53
|
+
switch (_f.label) {
|
|
54
|
+
case 0:
|
|
55
|
+
otelHeaders = (0, arvo_core_1.getOtelHeaderFromSpan)(config.span);
|
|
56
|
+
return [4 /*yield*/, client.messages.create(param)];
|
|
57
|
+
case 1:
|
|
58
|
+
stream = _f.sent();
|
|
59
|
+
toolRequests = [];
|
|
60
|
+
finalResponse = '';
|
|
61
|
+
stopReason = null;
|
|
62
|
+
inputTokens = 0;
|
|
63
|
+
outputTokens = 0;
|
|
64
|
+
toolUseBlocks = new Map();
|
|
65
|
+
_f.label = 2;
|
|
66
|
+
case 2:
|
|
67
|
+
_f.trys.push([2, 7, 8, 13]);
|
|
68
|
+
_a = true, stream_1 = __asyncValues(stream);
|
|
69
|
+
_f.label = 3;
|
|
70
|
+
case 3: return [4 /*yield*/, stream_1.next()];
|
|
71
|
+
case 4:
|
|
72
|
+
if (!(stream_1_1 = _f.sent(), _b = stream_1_1.done, !_b)) return [3 /*break*/, 6];
|
|
73
|
+
_d = stream_1_1.value;
|
|
74
|
+
_a = false;
|
|
75
|
+
event = _d;
|
|
76
|
+
if (event.type === 'message_start') {
|
|
77
|
+
inputTokens = event.message.usage.input_tokens;
|
|
78
|
+
outputTokens = event.message.usage.output_tokens;
|
|
79
|
+
}
|
|
80
|
+
else if (event.type === 'content_block_start') {
|
|
81
|
+
if (event.content_block.type === 'tool_use') {
|
|
82
|
+
toolUseBlocks.set(event.index, {
|
|
83
|
+
id: event.content_block.id,
|
|
84
|
+
name: event.content_block.name,
|
|
85
|
+
input: '',
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else if (event.type === 'content_block_delta') {
|
|
90
|
+
if (event.delta.type === 'text_delta') {
|
|
91
|
+
finalResponse += event.delta.text;
|
|
92
|
+
config.onStream({
|
|
93
|
+
type: 'agent.llm.delta.text',
|
|
94
|
+
data: {
|
|
95
|
+
comment: 'Generating response',
|
|
96
|
+
content: finalResponse,
|
|
97
|
+
delta: event.delta.text,
|
|
98
|
+
meta: {
|
|
99
|
+
error: null,
|
|
100
|
+
token: {
|
|
101
|
+
prompt: inputTokens,
|
|
102
|
+
completion: outputTokens,
|
|
103
|
+
},
|
|
104
|
+
otel: otelHeaders,
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
else if (event.delta.type === 'input_json_delta') {
|
|
110
|
+
block = toolUseBlocks.get(event.index);
|
|
111
|
+
if (block) {
|
|
112
|
+
block.input += event.delta.partial_json;
|
|
113
|
+
config.onStream({
|
|
114
|
+
type: 'agent.llm.delta.tool',
|
|
115
|
+
data: {
|
|
116
|
+
comment: "Preparing tool call `".concat(block.name, "`"),
|
|
117
|
+
toolname: block.name,
|
|
118
|
+
toolUseId: block.id,
|
|
119
|
+
input: block.input,
|
|
120
|
+
meta: {
|
|
121
|
+
error: null,
|
|
122
|
+
token: {
|
|
123
|
+
prompt: inputTokens,
|
|
124
|
+
completion: outputTokens,
|
|
125
|
+
},
|
|
126
|
+
otel: otelHeaders,
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
else if (event.type === 'content_block_stop') {
|
|
134
|
+
block = toolUseBlocks.get(event.index);
|
|
135
|
+
if (block) {
|
|
136
|
+
try {
|
|
137
|
+
toolRequests.push({
|
|
138
|
+
name: block.name,
|
|
139
|
+
toolUseId: block.id,
|
|
140
|
+
input: JSON.parse(block.input),
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
catch (e) {
|
|
144
|
+
config.onStream({
|
|
145
|
+
type: 'agent.llm.delta.tool',
|
|
146
|
+
data: {
|
|
147
|
+
comment: "Skipping tool call ".concat(block.name, " due to technical issues."),
|
|
148
|
+
toolname: block.name,
|
|
149
|
+
input: block.input,
|
|
150
|
+
toolUseId: block.id,
|
|
151
|
+
meta: {
|
|
152
|
+
error: e.message,
|
|
153
|
+
token: {
|
|
154
|
+
prompt: inputTokens,
|
|
155
|
+
completion: outputTokens,
|
|
156
|
+
},
|
|
157
|
+
otel: otelHeaders,
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
(0, arvo_core_1.logToSpan)({
|
|
162
|
+
level: 'WARNING',
|
|
163
|
+
message: "Failed to parse tool call input for tool '".concat(block.name, "' (id: ").concat(block.id, "). Tool call will be dropped. Error: ").concat(e.message),
|
|
164
|
+
}, config.span);
|
|
165
|
+
}
|
|
166
|
+
toolUseBlocks.delete(event.index);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
else if (event.type === 'message_delta') {
|
|
170
|
+
stopReason = (_e = event.delta.stop_reason) !== null && _e !== void 0 ? _e : stopReason;
|
|
171
|
+
outputTokens += event.usage.output_tokens;
|
|
172
|
+
config.onStream({
|
|
173
|
+
type: 'agent.llm.delta',
|
|
174
|
+
data: {
|
|
175
|
+
comment: 'Generating response',
|
|
176
|
+
finishReason: stopReason,
|
|
177
|
+
meta: {
|
|
178
|
+
error: null,
|
|
179
|
+
token: {
|
|
180
|
+
prompt: inputTokens,
|
|
181
|
+
completion: outputTokens,
|
|
182
|
+
},
|
|
183
|
+
otel: otelHeaders,
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
_f.label = 5;
|
|
189
|
+
case 5:
|
|
190
|
+
_a = true;
|
|
191
|
+
return [3 /*break*/, 3];
|
|
192
|
+
case 6: return [3 /*break*/, 13];
|
|
193
|
+
case 7:
|
|
194
|
+
e_1_1 = _f.sent();
|
|
195
|
+
e_1 = { error: e_1_1 };
|
|
196
|
+
return [3 /*break*/, 13];
|
|
197
|
+
case 8:
|
|
198
|
+
_f.trys.push([8, , 11, 12]);
|
|
199
|
+
if (!(!_a && !_b && (_c = stream_1.return))) return [3 /*break*/, 10];
|
|
200
|
+
return [4 /*yield*/, _c.call(stream_1)];
|
|
201
|
+
case 9:
|
|
202
|
+
_f.sent();
|
|
203
|
+
_f.label = 10;
|
|
204
|
+
case 10: return [3 /*break*/, 12];
|
|
205
|
+
case 11:
|
|
206
|
+
if (e_1) throw e_1.error;
|
|
207
|
+
return [7 /*endfinally*/];
|
|
208
|
+
case 12: return [7 /*endfinally*/];
|
|
209
|
+
case 13:
|
|
210
|
+
llmUsage = {
|
|
211
|
+
tokens: {
|
|
212
|
+
prompt: inputTokens,
|
|
213
|
+
completion: outputTokens,
|
|
214
|
+
},
|
|
215
|
+
};
|
|
216
|
+
if (toolRequests.length) {
|
|
217
|
+
return [2 /*return*/, {
|
|
218
|
+
toolRequests: toolRequests,
|
|
219
|
+
response: null,
|
|
220
|
+
usage: llmUsage,
|
|
221
|
+
}];
|
|
222
|
+
}
|
|
223
|
+
processedResponse = finalResponse;
|
|
224
|
+
if (stopReason === 'max_tokens') {
|
|
225
|
+
(0, arvo_core_1.logToSpan)({
|
|
226
|
+
level: 'WARNING',
|
|
227
|
+
message: 'Max token limit reached. Response truncated',
|
|
228
|
+
}, config.span);
|
|
229
|
+
}
|
|
230
|
+
if (stopReason === 'max_tokens' && finalResponse) {
|
|
231
|
+
processedResponse = "".concat(finalResponse, "\n\n[Response truncated: Maximum token limit reached]");
|
|
232
|
+
}
|
|
233
|
+
else if (!finalResponse && stopReason === 'max_tokens') {
|
|
234
|
+
processedResponse = '[Response truncated: Maximum token limit reached]';
|
|
235
|
+
}
|
|
236
|
+
return [2 /*return*/, {
|
|
237
|
+
toolRequests: null,
|
|
238
|
+
response: processedResponse,
|
|
239
|
+
usage: llmUsage,
|
|
240
|
+
}];
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
}); };
|
|
244
|
+
exports.streamableAnthropic = streamableAnthropic;
|
|
245
|
+
//# sourceMappingURL=streamable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streamable.js","sourceRoot":"","sources":["../../../src/Integrations/anthropic/streamable.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,uCAA6D;AAKtD,IAAM,mBAAmB,GAAG,UACjC,MAAiB,EACjB,KAA6C,EAC7C,MAGC;;;;;;;gBAEK,WAAW,GAAG,IAAA,iCAAqB,EAAC,MAAM,CAAC,IAAI,CAAC,CAAC;gBACxC,qBAAM,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,EAAA;;gBAA5C,MAAM,GAAG,SAAmC;gBAE5C,YAAY,GAAyC,EAAE,CAAC;gBAC1D,aAAa,GAAG,EAAE,CAAC;gBACnB,UAAU,GAAkB,IAAI,CAAC;gBACjC,WAAW,GAAG,CAAC,CAAC;gBAChB,YAAY,GAAG,CAAC,CAAC;gBAEf,aAAa,GAA6D,IAAI,GAAG,EAAE,CAAC;;;;2BAEhE,WAAA,cAAA,MAAM,CAAA;;;;;gBAAN,sBAAM;gBAAN,WAAM;gBAAf,KAAK,KAAA,CAAA;gBACpB,IAAI,KAAK,CAAC,IAAI,KAAK,eAAe,EAAE,CAAC;oBACnC,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC;oBAC/C,YAAY,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC;gBACnD,CAAC;qBAAM,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