alibabacloud-agentcore-sdk 0.1.0
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/LICENSE +202 -0
- package/README.md +189 -0
- package/dist/access-key-CkoHq3S8.d.cts +30 -0
- package/dist/access-key-CkoHq3S8.d.ts +30 -0
- package/dist/agent-sa-token-DD1Sb8P1.d.cts +14 -0
- package/dist/agent-sa-token-DD1Sb8P1.d.ts +14 -0
- package/dist/auth/index.cjs +36 -0
- package/dist/auth/index.cjs.map +1 -0
- package/dist/auth/index.d.cts +34 -0
- package/dist/auth/index.d.ts +34 -0
- package/dist/auth/index.js +36 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/bound-credentials-C1fM0thh.d.cts +39 -0
- package/dist/bound-credentials-DqT64Q2s.d.ts +39 -0
- package/dist/chunk-2E5EWEDG.cjs +142 -0
- package/dist/chunk-2E5EWEDG.cjs.map +1 -0
- package/dist/chunk-55XZZRKO.js +220 -0
- package/dist/chunk-55XZZRKO.js.map +1 -0
- package/dist/chunk-5JXA7JPS.js +29 -0
- package/dist/chunk-5JXA7JPS.js.map +1 -0
- package/dist/chunk-5RKN46UU.cjs +139 -0
- package/dist/chunk-5RKN46UU.cjs.map +1 -0
- package/dist/chunk-5ZOLHQXO.js +296 -0
- package/dist/chunk-5ZOLHQXO.js.map +1 -0
- package/dist/chunk-7Y263YIW.js +298 -0
- package/dist/chunk-7Y263YIW.js.map +1 -0
- package/dist/chunk-A3PF2SPD.cjs +141 -0
- package/dist/chunk-A3PF2SPD.cjs.map +1 -0
- package/dist/chunk-A3WMLVJC.cjs +141 -0
- package/dist/chunk-A3WMLVJC.cjs.map +1 -0
- package/dist/chunk-BVZ7H2F5.cjs +582 -0
- package/dist/chunk-BVZ7H2F5.cjs.map +1 -0
- package/dist/chunk-EGUKJE3Z.cjs +24 -0
- package/dist/chunk-EGUKJE3Z.cjs.map +1 -0
- package/dist/chunk-EKXZKKJJ.js +24 -0
- package/dist/chunk-EKXZKKJJ.js.map +1 -0
- package/dist/chunk-GYLT23D3.js +110 -0
- package/dist/chunk-GYLT23D3.js.map +1 -0
- package/dist/chunk-IF7LMBXC.js +306 -0
- package/dist/chunk-IF7LMBXC.js.map +1 -0
- package/dist/chunk-IUCLCPVV.js +113 -0
- package/dist/chunk-IUCLCPVV.js.map +1 -0
- package/dist/chunk-JSP7ZROS.cjs +95 -0
- package/dist/chunk-JSP7ZROS.cjs.map +1 -0
- package/dist/chunk-JW62DVIC.js +238 -0
- package/dist/chunk-JW62DVIC.js.map +1 -0
- package/dist/chunk-K3TE7625.js +139 -0
- package/dist/chunk-K3TE7625.js.map +1 -0
- package/dist/chunk-LE5P3SJW.cjs +16 -0
- package/dist/chunk-LE5P3SJW.cjs.map +1 -0
- package/dist/chunk-LXHW6OT4.cjs +77 -0
- package/dist/chunk-LXHW6OT4.cjs.map +1 -0
- package/dist/chunk-MICRSJ6R.js +48 -0
- package/dist/chunk-MICRSJ6R.js.map +1 -0
- package/dist/chunk-MWAHO47B.cjs +220 -0
- package/dist/chunk-MWAHO47B.cjs.map +1 -0
- package/dist/chunk-MZ5UWGXS.js +95 -0
- package/dist/chunk-MZ5UWGXS.js.map +1 -0
- package/dist/chunk-NZL3VPJ2.js +16 -0
- package/dist/chunk-NZL3VPJ2.js.map +1 -0
- package/dist/chunk-PC4FM2RP.cjs +180 -0
- package/dist/chunk-PC4FM2RP.cjs.map +1 -0
- package/dist/chunk-PKYET77D.cjs +296 -0
- package/dist/chunk-PKYET77D.cjs.map +1 -0
- package/dist/chunk-PTJPB27L.js +31 -0
- package/dist/chunk-PTJPB27L.js.map +1 -0
- package/dist/chunk-QIZO3A4Y.cjs +306 -0
- package/dist/chunk-QIZO3A4Y.cjs.map +1 -0
- package/dist/chunk-RBAY4MO2.js +202 -0
- package/dist/chunk-RBAY4MO2.js.map +1 -0
- package/dist/chunk-RHY7Y43E.js +582 -0
- package/dist/chunk-RHY7Y43E.js.map +1 -0
- package/dist/chunk-RQRI6RCG.cjs +238 -0
- package/dist/chunk-RQRI6RCG.cjs.map +1 -0
- package/dist/chunk-RYXL25AI.js +141 -0
- package/dist/chunk-RYXL25AI.js.map +1 -0
- package/dist/chunk-RZNQGEGJ.cjs +113 -0
- package/dist/chunk-RZNQGEGJ.cjs.map +1 -0
- package/dist/chunk-S7PWSJNP.cjs +48 -0
- package/dist/chunk-S7PWSJNP.cjs.map +1 -0
- package/dist/chunk-TWEO5XVM.cjs +298 -0
- package/dist/chunk-TWEO5XVM.cjs.map +1 -0
- package/dist/chunk-UBP5CHU7.js +142 -0
- package/dist/chunk-UBP5CHU7.js.map +1 -0
- package/dist/chunk-ULJTQSLE.cjs +35 -0
- package/dist/chunk-ULJTQSLE.cjs.map +1 -0
- package/dist/chunk-UWPKFJYM.js +77 -0
- package/dist/chunk-UWPKFJYM.js.map +1 -0
- package/dist/chunk-WKZUYPDS.js +180 -0
- package/dist/chunk-WKZUYPDS.js.map +1 -0
- package/dist/chunk-YZP55W7S.cjs +29 -0
- package/dist/chunk-YZP55W7S.cjs.map +1 -0
- package/dist/chunk-ZELRQU4J.cjs +31 -0
- package/dist/chunk-ZELRQU4J.cjs.map +1 -0
- package/dist/chunk-ZLKYXRNM.js +141 -0
- package/dist/chunk-ZLKYXRNM.js.map +1 -0
- package/dist/chunk-ZLQ2IBTC.cjs +110 -0
- package/dist/chunk-ZLQ2IBTC.cjs.map +1 -0
- package/dist/chunk-ZTWLCHCO.cjs +202 -0
- package/dist/chunk-ZTWLCHCO.cjs.map +1 -0
- package/dist/chunk-ZWQBAJ5O.js +35 -0
- package/dist/chunk-ZWQBAJ5O.js.map +1 -0
- package/dist/client-DDU4-ygJ.d.cts +72 -0
- package/dist/client-pDzS7EZR.d.ts +72 -0
- package/dist/collaboration/index.cjs +44 -0
- package/dist/collaboration/index.cjs.map +1 -0
- package/dist/collaboration/index.d.cts +73 -0
- package/dist/collaboration/index.d.ts +73 -0
- package/dist/collaboration/index.js +44 -0
- package/dist/collaboration/index.js.map +1 -0
- package/dist/common-BSXkQfxI.d.cts +25 -0
- package/dist/common-BSXkQfxI.d.ts +25 -0
- package/dist/common-DRdI-75k.d.ts +8 -0
- package/dist/common-_vxreiEW.d.cts +8 -0
- package/dist/config-CMkmMtx1.d.cts +20 -0
- package/dist/config-CMkmMtx1.d.ts +20 -0
- package/dist/context-M9rOTifU.d.cts +12 -0
- package/dist/context-M9rOTifU.d.ts +12 -0
- package/dist/controller-DWs3Sy04.d.cts +9 -0
- package/dist/controller-DmI4L4sP.d.ts +9 -0
- package/dist/controlplane/index.cjs +13 -0
- package/dist/controlplane/index.cjs.map +1 -0
- package/dist/controlplane/index.d.cts +66 -0
- package/dist/controlplane/index.d.ts +66 -0
- package/dist/controlplane/index.js +13 -0
- package/dist/controlplane/index.js.map +1 -0
- package/dist/errors-BjGO6N10.d.ts +93 -0
- package/dist/errors-D9OtcR-o.d.cts +93 -0
- package/dist/event-converters-BIn8odqo.d.ts +38 -0
- package/dist/event-converters-Cn_NeGyQ.d.cts +38 -0
- package/dist/google-adk-model-N47R7GB2.js +208 -0
- package/dist/google-adk-model-N47R7GB2.js.map +1 -0
- package/dist/google-adk-model-PDBKY5YZ.cjs +208 -0
- package/dist/google-adk-model-PDBKY5YZ.cjs.map +1 -0
- package/dist/index.cjs +322 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +78 -0
- package/dist/index.d.ts +78 -0
- package/dist/index.js +322 -0
- package/dist/index.js.map +1 -0
- package/dist/integrations/ai-sdk.cjs +15 -0
- package/dist/integrations/ai-sdk.cjs.map +1 -0
- package/dist/integrations/ai-sdk.d.cts +21 -0
- package/dist/integrations/ai-sdk.d.ts +21 -0
- package/dist/integrations/ai-sdk.js +15 -0
- package/dist/integrations/ai-sdk.js.map +1 -0
- package/dist/integrations/google-adk.cjs +90 -0
- package/dist/integrations/google-adk.cjs.map +1 -0
- package/dist/integrations/google-adk.d.cts +46 -0
- package/dist/integrations/google-adk.d.ts +46 -0
- package/dist/integrations/google-adk.js +90 -0
- package/dist/integrations/google-adk.js.map +1 -0
- package/dist/integrations/langchain.cjs +95 -0
- package/dist/integrations/langchain.cjs.map +1 -0
- package/dist/integrations/langchain.d.cts +52 -0
- package/dist/integrations/langchain.d.ts +52 -0
- package/dist/integrations/langchain.js +95 -0
- package/dist/integrations/langchain.js.map +1 -0
- package/dist/integrations/langgraph.cjs +30 -0
- package/dist/integrations/langgraph.cjs.map +1 -0
- package/dist/integrations/langgraph.d.cts +53 -0
- package/dist/integrations/langgraph.d.ts +53 -0
- package/dist/integrations/langgraph.js +30 -0
- package/dist/integrations/langgraph.js.map +1 -0
- package/dist/integrations/mastra.cjs +108 -0
- package/dist/integrations/mastra.cjs.map +1 -0
- package/dist/integrations/mastra.d.cts +47 -0
- package/dist/integrations/mastra.d.ts +47 -0
- package/dist/integrations/mastra.js +108 -0
- package/dist/integrations/mastra.js.map +1 -0
- package/dist/langchain-adapter-DFJdEX04.d.cts +47 -0
- package/dist/langchain-adapter-DJsyjm5V.d.ts +47 -0
- package/dist/langchain-provider-NF5GIDQV.cjs +227 -0
- package/dist/langchain-provider-NF5GIDQV.cjs.map +1 -0
- package/dist/langchain-provider-PHL4UWNF.js +227 -0
- package/dist/langchain-provider-PHL4UWNF.js.map +1 -0
- package/dist/loader-DrIQ37nm.d.ts +38 -0
- package/dist/loader-eWuJ2GSL.d.cts +38 -0
- package/dist/logging-C8GLLg1f.d.cts +9 -0
- package/dist/logging-C8GLLg1f.d.ts +9 -0
- package/dist/managed-CwLx9h4C.d.cts +32 -0
- package/dist/managed-D9eQK1ut.d.ts +32 -0
- package/dist/mcp/index.cjs +12 -0
- package/dist/mcp/index.cjs.map +1 -0
- package/dist/mcp/index.d.cts +62 -0
- package/dist/mcp/index.d.ts +62 -0
- package/dist/mcp/index.js +12 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/memory/index.cjs +12 -0
- package/dist/memory/index.cjs.map +1 -0
- package/dist/memory/index.d.cts +113 -0
- package/dist/memory/index.d.ts +113 -0
- package/dist/memory/index.js +12 -0
- package/dist/memory/index.js.map +1 -0
- package/dist/model/index.cjs +16 -0
- package/dist/model/index.cjs.map +1 -0
- package/dist/model/index.d.cts +129 -0
- package/dist/model/index.d.ts +129 -0
- package/dist/model/index.js +16 -0
- package/dist/model/index.js.map +1 -0
- package/dist/model-CkYHzHPk.d.cts +50 -0
- package/dist/model-CkYHzHPk.d.ts +50 -0
- package/dist/runtime/index.cjs +49 -0
- package/dist/runtime/index.cjs.map +1 -0
- package/dist/runtime/index.d.cts +73 -0
- package/dist/runtime/index.d.ts +73 -0
- package/dist/runtime/index.js +49 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/server/index.cjs +604 -0
- package/dist/server/index.cjs.map +1 -0
- package/dist/server/index.d.cts +69 -0
- package/dist/server/index.d.ts +69 -0
- package/dist/server/index.js +604 -0
- package/dist/server/index.js.map +1 -0
- package/dist/skill/index.cjs +14 -0
- package/dist/skill/index.cjs.map +1 -0
- package/dist/skill/index.d.cts +16 -0
- package/dist/skill/index.d.ts +16 -0
- package/dist/skill/index.js +14 -0
- package/dist/skill/index.js.map +1 -0
- package/package.json +292 -0
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunkJSP7ZROScjs = require('./chunk-JSP7ZROS.cjs');
|
|
5
|
+
|
|
6
|
+
// src/integrations/langchain-provider.ts
|
|
7
|
+
var _chat_models = require('@langchain/core/language_models/chat_models');
|
|
8
|
+
var _messages = require('@langchain/core/messages');
|
|
9
|
+
var _outputs = require('@langchain/core/outputs');
|
|
10
|
+
var _function_calling = require('@langchain/core/utils/function_calling');
|
|
11
|
+
var ProviderChatModel = class extends _chat_models.BaseChatModel {
|
|
12
|
+
constructor(client, defaults = {}) {
|
|
13
|
+
super({ maxRetries: 0 });
|
|
14
|
+
this.client = client;
|
|
15
|
+
this.defaults = defaults;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
_llmType() {
|
|
20
|
+
return "agentcore-provider";
|
|
21
|
+
}
|
|
22
|
+
get callKeys() {
|
|
23
|
+
return [...super.callKeys, "tools", "tool_choice", "maxOutputTokens", "temperature", "topP", "topK", "presencePenalty", "frequencyPenalty", "seed", "responseFormat", "providerOptions", "headers"];
|
|
24
|
+
}
|
|
25
|
+
bindTools(tools, kwargs) {
|
|
26
|
+
return this.withConfig({ ...kwargs, tools });
|
|
27
|
+
}
|
|
28
|
+
async _generate(messages, options) {
|
|
29
|
+
const result = await this.client.languageModel.doGenerate(this.request(messages, options));
|
|
30
|
+
const content = result.content.filter((p) => p.type === "text" || p.type === "reasoning" || p.type === "file").map(outputPart);
|
|
31
|
+
const calls = result.content.filter((p) => p.type === "tool-call");
|
|
32
|
+
const message = new (0, _messages.AIMessageChunk)({
|
|
33
|
+
content,
|
|
34
|
+
tool_calls: calls.map((call) => ({ type: "tool_call", id: call.toolCallId, name: call.toolName, args: JSON.parse(call.input) })),
|
|
35
|
+
additional_kwargs: { agentcore_tool_metadata: Object.fromEntries(calls.map((call) => [call.toolCallId, call.providerMetadata])) },
|
|
36
|
+
usage_metadata: usage(result.usage),
|
|
37
|
+
response_metadata: {
|
|
38
|
+
finish_reason: result.finishReason.unified,
|
|
39
|
+
providerMetadata: result.providerMetadata,
|
|
40
|
+
sources: result.content.filter((p) => p.type === "source")
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
return { generations: [{ text: message.text, message }] };
|
|
44
|
+
}
|
|
45
|
+
async *_streamResponseChunks(messages, options, runManager) {
|
|
46
|
+
const controller = new AbortController();
|
|
47
|
+
const signal = AbortSignal.any([controller.signal, ...options.signal ? [options.signal] : []]);
|
|
48
|
+
try {
|
|
49
|
+
const result = await this.client.languageModel.doStream(this.request(messages, { ...options, signal }));
|
|
50
|
+
const reader = result.stream.getReader();
|
|
51
|
+
const blocks = /* @__PURE__ */ new Map();
|
|
52
|
+
const calls = /* @__PURE__ */ new Map();
|
|
53
|
+
let finished = false;
|
|
54
|
+
try {
|
|
55
|
+
while (true) {
|
|
56
|
+
const next = await reader.read();
|
|
57
|
+
if (next.done) break;
|
|
58
|
+
const part = next.value;
|
|
59
|
+
let message;
|
|
60
|
+
let text = "";
|
|
61
|
+
if (part.type === "error") throw part.error;
|
|
62
|
+
if (part.type === "text-delta" || part.type === "reasoning-delta") {
|
|
63
|
+
const key = `${part.type}:${part.id}`;
|
|
64
|
+
if (!blocks.has(key)) blocks.set(key, blocks.size);
|
|
65
|
+
const index = blocks.get(key);
|
|
66
|
+
text = part.type === "text-delta" ? part.delta : "";
|
|
67
|
+
message = new (0, _messages.AIMessageChunk)({ content: [part.type === "text-delta" ? { type: "text", text, index, providerOptions: part.providerMetadata } : { type: "reasoning", reasoning: part.delta, index, providerOptions: part.providerMetadata }] });
|
|
68
|
+
} else if (part.type === "text-end" || part.type === "reasoning-end") {
|
|
69
|
+
const index = blocks.get(`${part.type === "text-end" ? "text" : "reasoning"}-delta:${part.id}`);
|
|
70
|
+
if (index !== void 0 && part.providerMetadata) message = new (0, _messages.AIMessageChunk)({ content: [{
|
|
71
|
+
type: part.type === "text-end" ? "text" : "reasoning",
|
|
72
|
+
index,
|
|
73
|
+
providerOptions: part.providerMetadata
|
|
74
|
+
}] });
|
|
75
|
+
} else if (part.type === "tool-input-start") {
|
|
76
|
+
const index = calls.size;
|
|
77
|
+
calls.set(part.id, index);
|
|
78
|
+
message = new (0, _messages.AIMessageChunk)({ content: [], tool_call_chunks: [{ type: "tool_call_chunk", index, id: part.id, name: part.toolName, args: "" }] });
|
|
79
|
+
} else if (part.type === "tool-input-delta") {
|
|
80
|
+
message = new (0, _messages.AIMessageChunk)({ content: [], tool_call_chunks: [{ type: "tool_call_chunk", index: calls.get(part.id), args: part.delta }] });
|
|
81
|
+
} else if (part.type === "tool-call") {
|
|
82
|
+
const metadata = { agentcore_tool_metadata: { [part.toolCallId]: part.providerMetadata } };
|
|
83
|
+
message = new (0, _messages.AIMessageChunk)({
|
|
84
|
+
content: [],
|
|
85
|
+
additional_kwargs: metadata,
|
|
86
|
+
tool_call_chunks: calls.has(part.toolCallId) ? [] : [{ type: "tool_call_chunk", index: calls.size, id: part.toolCallId, name: part.toolName, args: part.input }]
|
|
87
|
+
});
|
|
88
|
+
if (!calls.has(part.toolCallId)) calls.set(part.toolCallId, calls.size);
|
|
89
|
+
} else if (part.type === "file") {
|
|
90
|
+
const index = blocks.size;
|
|
91
|
+
blocks.set(`file:${index}`, index);
|
|
92
|
+
message = new (0, _messages.AIMessageChunk)({ content: [{ ...outputPart(part), index }] });
|
|
93
|
+
} else if (part.type === "source") {
|
|
94
|
+
message = new (0, _messages.AIMessageChunk)({ content: [], response_metadata: { sources: [part] } });
|
|
95
|
+
} else if (part.type === "finish") {
|
|
96
|
+
finished = true;
|
|
97
|
+
message = new (0, _messages.AIMessageChunk)({
|
|
98
|
+
content: [],
|
|
99
|
+
usage_metadata: usage(part.usage),
|
|
100
|
+
response_metadata: { finish_reason: part.finishReason.unified, providerMetadata: part.providerMetadata }
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
if (message) {
|
|
104
|
+
const chunk = new (0, _outputs.ChatGenerationChunk)({ text, message });
|
|
105
|
+
yield chunk;
|
|
106
|
+
await _optionalChain([runManager, 'optionalAccess', _ => _.handleLLMNewToken, 'call', _2 => _2(text, void 0, void 0, void 0, void 0, { chunk })]);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (!finished) throw new (0, _chunkJSP7ZROScjs.InvocationError)("model stream ended without a completion event");
|
|
110
|
+
} finally {
|
|
111
|
+
reader.releaseLock();
|
|
112
|
+
}
|
|
113
|
+
} finally {
|
|
114
|
+
controller.abort();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
request(messages, options) {
|
|
118
|
+
const settings = { ...this.defaults, ...options };
|
|
119
|
+
return {
|
|
120
|
+
prompt: prompt(messages),
|
|
121
|
+
abortSignal: options.signal,
|
|
122
|
+
stopSequences: options.stop,
|
|
123
|
+
maxOutputTokens: settings.maxOutputTokens,
|
|
124
|
+
temperature: settings.temperature,
|
|
125
|
+
topP: settings.topP,
|
|
126
|
+
topK: settings.topK,
|
|
127
|
+
presencePenalty: settings.presencePenalty,
|
|
128
|
+
frequencyPenalty: settings.frequencyPenalty,
|
|
129
|
+
seed: settings.seed,
|
|
130
|
+
responseFormat: settings.responseFormat,
|
|
131
|
+
providerOptions: settings.providerOptions,
|
|
132
|
+
headers: settings.headers,
|
|
133
|
+
tools: _optionalChain([options, 'access', _3 => _3.tools, 'optionalAccess', _4 => _4.map, 'call', _5 => _5((item) => {
|
|
134
|
+
const value = _function_calling.convertToOpenAITool.call(void 0, item).function;
|
|
135
|
+
return { type: "function", name: value.name, description: value.description, inputSchema: value.parameters };
|
|
136
|
+
})]),
|
|
137
|
+
toolChoice: toolChoice(options.tool_choice)
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
function prompt(messages) {
|
|
142
|
+
const names = /* @__PURE__ */ new Map();
|
|
143
|
+
const result = [];
|
|
144
|
+
for (const message of messages) {
|
|
145
|
+
const role = message.type;
|
|
146
|
+
if (role === "system") {
|
|
147
|
+
result.push({ role: "system", content: message.text });
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (role === "tool") {
|
|
151
|
+
const id = message.tool_call_id;
|
|
152
|
+
const name = _nullishCoalesce(message.name, () => ( names.get(id)));
|
|
153
|
+
if (!name) throw new (0, _chunkJSP7ZROScjs.ConfigError)("LangChain ToolMessage requires a matching tool call or name");
|
|
154
|
+
result.push({ role: "tool", content: [{
|
|
155
|
+
type: "tool-result",
|
|
156
|
+
toolCallId: id,
|
|
157
|
+
toolName: name,
|
|
158
|
+
output: { type: "text", value: typeof message.content === "string" ? message.content : JSON.stringify(message.content) }
|
|
159
|
+
}] });
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
if (role !== "human" && role !== "ai") throw new (0, _chunkJSP7ZROScjs.ConfigError)(`unsupported LangChain message role: ${role}`);
|
|
163
|
+
const content = typeof message.content === "string" ? [{ type: "text", text: message.content }] : message.content.map(inputPart);
|
|
164
|
+
if (role === "ai") {
|
|
165
|
+
const metadata = message.additional_kwargs.agentcore_tool_metadata;
|
|
166
|
+
for (const call of _nullishCoalesce(message.tool_calls, () => ( []))) {
|
|
167
|
+
if (!call.id) throw new (0, _chunkJSP7ZROScjs.ConfigError)("LangChain tool call requires an id");
|
|
168
|
+
names.set(call.id, call.name);
|
|
169
|
+
content.push({ type: "tool-call", toolCallId: call.id, toolName: call.name, input: call.args, providerOptions: _optionalChain([metadata, 'optionalAccess', _6 => _6[call.id]]) });
|
|
170
|
+
}
|
|
171
|
+
result.push({ role: "assistant", content });
|
|
172
|
+
} else result.push({ role: "user", content });
|
|
173
|
+
}
|
|
174
|
+
return result;
|
|
175
|
+
}
|
|
176
|
+
function inputPart(part) {
|
|
177
|
+
const providerOptions = part.providerOptions;
|
|
178
|
+
if (part.type === "text") return { type: "text", text: part.text, providerOptions };
|
|
179
|
+
if (part.type === "reasoning") return { type: "reasoning", text: part.reasoning, providerOptions };
|
|
180
|
+
if (part.type === "image_url") {
|
|
181
|
+
const url = typeof part.image_url === "string" ? part.image_url : part.image_url.url;
|
|
182
|
+
return filePart(url, "image/*", providerOptions);
|
|
183
|
+
}
|
|
184
|
+
if (["image", "audio", "video", "file"].includes(part.type)) {
|
|
185
|
+
const data = _nullishCoalesce(part.url, () => ( part.data));
|
|
186
|
+
const mediaType = _nullishCoalesce(_nullishCoalesce(part.mimeType, () => ( part.mime_type)), () => ( (part.type === "file" ? void 0 : `${part.type}/*`)));
|
|
187
|
+
if (data !== void 0) return filePart(data, mediaType, providerOptions);
|
|
188
|
+
}
|
|
189
|
+
throw new (0, _chunkJSP7ZROScjs.ConfigError)(`unsupported LangChain provider content block: ${part.type}`);
|
|
190
|
+
}
|
|
191
|
+
function filePart(data, mediaType, providerOptions) {
|
|
192
|
+
if (typeof data === "string" && data.startsWith("data:")) {
|
|
193
|
+
const match = /^data:([^;,]+);base64,(.*)$/s.exec(data);
|
|
194
|
+
if (!match) throw new (0, _chunkJSP7ZROScjs.ConfigError)("data URL must contain base64 data and a media type");
|
|
195
|
+
return { type: "file", mediaType: match[1], data: match[2], providerOptions };
|
|
196
|
+
}
|
|
197
|
+
const url = typeof data === "string" && /^(https?:|gs:)/.test(data) ? new URL(data) : void 0;
|
|
198
|
+
if (!mediaType) throw new (0, _chunkJSP7ZROScjs.ConfigError)("file content requires a media type");
|
|
199
|
+
return { type: "file", mediaType, data: _nullishCoalesce(url, () => ( data)), providerOptions };
|
|
200
|
+
}
|
|
201
|
+
function outputPart(part) {
|
|
202
|
+
if (part.type === "text") return { type: "text", text: part.text, providerOptions: part.providerMetadata };
|
|
203
|
+
if (part.type === "reasoning") return { type: "reasoning", reasoning: part.text, providerOptions: part.providerMetadata };
|
|
204
|
+
return {
|
|
205
|
+
type: "file",
|
|
206
|
+
mimeType: part.mediaType,
|
|
207
|
+
data: typeof part.data === "string" ? part.data : Buffer.from(part.data).toString("base64"),
|
|
208
|
+
providerOptions: part.providerMetadata
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
function usage(value) {
|
|
212
|
+
const input = _nullishCoalesce(value.inputTokens.total, () => ( 0));
|
|
213
|
+
const output = _nullishCoalesce(value.outputTokens.total, () => ( 0));
|
|
214
|
+
return { input_tokens: input, output_tokens: output, total_tokens: input + output };
|
|
215
|
+
}
|
|
216
|
+
function toolChoice(value) {
|
|
217
|
+
if (value === void 0) return void 0;
|
|
218
|
+
if (value === "auto" || value === "none" || value === "required") return { type: value };
|
|
219
|
+
if (value === "any") return { type: "required" };
|
|
220
|
+
if (typeof value === "string") return { type: "tool", toolName: value };
|
|
221
|
+
if (value.type === "function" && typeof _optionalChain([value, 'access', _7 => _7.function, 'optionalAccess', _8 => _8.name]) === "string") return { type: "tool", toolName: value.function.name };
|
|
222
|
+
throw new (0, _chunkJSP7ZROScjs.ConfigError)("unsupported LangChain tool_choice");
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
exports.ProviderChatModel = ProviderChatModel;
|
|
227
|
+
//# sourceMappingURL=langchain-provider-NF5GIDQV.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/zhuoguang/Documents/Code/collaborate/hiclaw/agentcore-sdk-nodejs/dist/langchain-provider-NF5GIDQV.cjs","../src/integrations/langchain-provider.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,wDAA6B;AAC7B;AACA;ACLA,0EAAkF;AAClF,oDAAgF;AAChF,kDAAqD;AAErD,0EAAoC;AAW7B,IAAM,kBAAA,EAAN,MAAA,QAAgC,2BAAuC;AAAA,EAC5E,WAAA,CAA6B,MAAA,EAA8C,SAAA,EAAqC,CAAC,CAAA,EAAG;AAAE,IAAA,KAAA,CAAM,EAAE,UAAA,EAAY,EAAE,CAAC,CAAA;AAAhH,IAAA,IAAA,CAAA,OAAA,EAAA,MAAA;AAA8C,IAAA,IAAA,CAAA,SAAA,EAAA,QAAA;AAAA,EAAqE;AAAA,EAAnH;AAAA,EAA8C;AAAA,EAC3E,QAAA,CAAA,EAAmB;AAAE,IAAA,OAAO,oBAAA;AAAA,EAAsB;AAAA,EAClD,IAAI,QAAA,CAAA,EAAqB;AAAE,IAAA,OAAO,CAAC,GAAG,KAAA,CAAM,QAAA,EAAU,OAAA,EAAS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zhuoguang/Documents/Code/collaborate/hiclaw/agentcore-sdk-nodejs/dist/langchain-provider-NF5GIDQV.cjs","sourcesContent":[null,"import { BaseChatModel, type BaseChatModelCallOptions, type BindToolsInput } from '@langchain/core/language_models/chat_models';\nimport { AIMessage, AIMessageChunk, type BaseMessage, type UsageMetadata } from '@langchain/core/messages';\nimport { ChatGenerationChunk, type ChatResult } from '@langchain/core/outputs';\nimport type { CallbackManagerForLLMRun } from '@langchain/core/callbacks/manager';\nimport { convertToOpenAITool } from '@langchain/core/utils/function_calling';\nimport type { LanguageModelV3CallOptions, LanguageModelV3Content, LanguageModelV3Message, LanguageModelV3Prompt,\n LanguageModelV3ToolChoice, LanguageModelV3Usage, LanguageModelV3FunctionTool, SharedV3ProviderOptions } from '@ai-sdk/provider';\nimport type { ProviderModelClient } from '../model/provider';\nimport { ConfigError, InvocationError } from '../errors';\n\nexport type LangChainProviderOptions = Pick<LanguageModelV3CallOptions,\n 'maxOutputTokens' | 'temperature' | 'topP' | 'topK' | 'presencePenalty' | 'frequencyPenalty' | 'seed' | 'responseFormat' | 'providerOptions' | 'headers'>;\nexport interface ProviderChatCallOptions extends BaseChatModelCallOptions, LangChainProviderOptions { tools?: BindToolsInput[]; }\n\n/** LangChain owns tool execution; this bridge performs one provider call per model step. */\nexport class ProviderChatModel extends BaseChatModel<ProviderChatCallOptions> {\n constructor(private readonly client: ProviderModelClient, private readonly defaults: LangChainProviderOptions = {}) { super({ maxRetries: 0 }); }\n _llmType(): string { return 'agentcore-provider'; }\n get callKeys(): string[] { return [...super.callKeys, 'tools', 'tool_choice', 'maxOutputTokens', 'temperature', 'topP', 'topK', 'presencePenalty', 'frequencyPenalty', 'seed', 'responseFormat', 'providerOptions', 'headers']; }\n bindTools(tools: BindToolsInput[], kwargs?: Partial<ProviderChatCallOptions>) { return this.withConfig({ ...kwargs, tools }); }\n\n async _generate(messages: BaseMessage[], options: this['ParsedCallOptions']): Promise<ChatResult> {\n const result = await this.client.languageModel.doGenerate(this.request(messages, options));\n const content = result.content.filter(p => p.type === 'text' || p.type === 'reasoning' || p.type === 'file').map(outputPart);\n const calls = result.content.filter(p => p.type === 'tool-call');\n const message = new AIMessageChunk({ content, tool_calls: calls.map(call => ({ type: 'tool_call', id: call.toolCallId, name: call.toolName, args: JSON.parse(call.input) })),\n additional_kwargs: { agentcore_tool_metadata: Object.fromEntries(calls.map(call => [call.toolCallId, call.providerMetadata])) },\n usage_metadata: usage(result.usage), response_metadata: { finish_reason: result.finishReason.unified, providerMetadata: result.providerMetadata,\n sources: result.content.filter(p => p.type === 'source') },\n });\n return { generations: [{ text: message.text, message }] };\n }\n async *_streamResponseChunks(messages: BaseMessage[], options: this['ParsedCallOptions'], runManager?: CallbackManagerForLLMRun): AsyncGenerator<ChatGenerationChunk> {\n const controller = new AbortController();\n const signal = AbortSignal.any([controller.signal, ...(options.signal ? [options.signal] : [])]);\n try {\n const result = await this.client.languageModel.doStream(this.request(messages, { ...options, signal }));\n const reader = result.stream.getReader();\n const blocks = new Map<string, number>(); const calls = new Map<string, number>(); let finished = false;\n try {\n while (true) {\n const next = await reader.read(); if (next.done) break;\n const part = next.value; let message: AIMessageChunk | undefined; let text = '';\n if (part.type === 'error') throw part.error;\n if (part.type === 'text-delta' || part.type === 'reasoning-delta') {\n const key = `${part.type}:${part.id}`;\n if (!blocks.has(key)) blocks.set(key, blocks.size);\n const index = blocks.get(key)!;\n text = part.type === 'text-delta' ? part.delta : '';\n message = new AIMessageChunk({ content: [part.type === 'text-delta'\n ? { type: 'text', text, index, providerOptions: part.providerMetadata }\n : { type: 'reasoning', reasoning: part.delta, index, providerOptions: part.providerMetadata }] });\n } else if (part.type === 'text-end' || part.type === 'reasoning-end') {\n const index = blocks.get(`${part.type === 'text-end' ? 'text' : 'reasoning'}-delta:${part.id}`);\n if (index !== undefined && part.providerMetadata) message = new AIMessageChunk({ content: [{\n type: part.type === 'text-end' ? 'text' : 'reasoning', index, providerOptions: part.providerMetadata,\n }] });\n } else if (part.type === 'tool-input-start') {\n const index = calls.size; calls.set(part.id, index);\n message = new AIMessageChunk({ content: [], tool_call_chunks: [{ type: 'tool_call_chunk', index, id: part.id, name: part.toolName, args: '' }] });\n } else if (part.type === 'tool-input-delta') {\n message = new AIMessageChunk({ content: [], tool_call_chunks: [{ type: 'tool_call_chunk', index: calls.get(part.id), args: part.delta }] });\n } else if (part.type === 'tool-call') {\n const metadata = { agentcore_tool_metadata: { [part.toolCallId]: part.providerMetadata } };\n message = new AIMessageChunk({ content: [], additional_kwargs: metadata,\n tool_call_chunks: calls.has(part.toolCallId) ? [] : [{ type: 'tool_call_chunk', index: calls.size, id: part.toolCallId, name: part.toolName, args: part.input }],\n });\n if (!calls.has(part.toolCallId)) calls.set(part.toolCallId, calls.size);\n } else if (part.type === 'file') {\n const index = blocks.size; blocks.set(`file:${index}`, index);\n message = new AIMessageChunk({ content: [{ ...outputPart(part), index }] });\n } else if (part.type === 'source') {\n message = new AIMessageChunk({ content: [], response_metadata: { sources: [part] } });\n } else if (part.type === 'finish') {\n finished = true;\n message = new AIMessageChunk({ content: [], usage_metadata: usage(part.usage),\n response_metadata: { finish_reason: part.finishReason.unified, providerMetadata: part.providerMetadata } });\n }\n if (message) {\n const chunk = new ChatGenerationChunk({ text, message }); yield chunk;\n await runManager?.handleLLMNewToken(text, undefined, undefined, undefined, undefined, { chunk });\n }\n }\n if (!finished) throw new InvocationError('model stream ended without a completion event');\n } finally { reader.releaseLock(); }\n } finally { controller.abort(); }\n }\n private request(messages: BaseMessage[], options: this['ParsedCallOptions']): LanguageModelV3CallOptions {\n const settings = { ...this.defaults, ...options };\n return { prompt: prompt(messages), abortSignal: options.signal, stopSequences: options.stop,\n maxOutputTokens: settings.maxOutputTokens, temperature: settings.temperature, topP: settings.topP, topK: settings.topK,\n presencePenalty: settings.presencePenalty, frequencyPenalty: settings.frequencyPenalty, seed: settings.seed,\n responseFormat: settings.responseFormat, providerOptions: settings.providerOptions, headers: settings.headers,\n tools: options.tools?.map(item => {\n const value = convertToOpenAITool(item).function;\n return { type: 'function', name: value.name, description: value.description, inputSchema: value.parameters as LanguageModelV3FunctionTool['inputSchema'] };\n }), toolChoice: toolChoice(options.tool_choice),\n };\n }\n}\n\ntype ChatPart = Extract<LanguageModelV3Message, { role: 'assistant' }>['content'][number];\ntype UserPart = Extract<LanguageModelV3Message, { role: 'user' }>['content'][number];\nfunction prompt(messages: BaseMessage[]): LanguageModelV3Prompt {\n const names = new Map<string, string>(); const result: LanguageModelV3Prompt = [];\n for (const message of messages) {\n const role = message.type;\n if (role === 'system') { result.push({ role: 'system', content: message.text }); continue; }\n if (role === 'tool') {\n const id = (message as BaseMessage & { tool_call_id: string }).tool_call_id;\n const name = message.name ?? names.get(id);\n if (!name) throw new ConfigError('LangChain ToolMessage requires a matching tool call or name');\n result.push({ role: 'tool', content: [{ type: 'tool-result', toolCallId: id, toolName: name,\n output: { type: 'text', value: typeof message.content === 'string' ? message.content : JSON.stringify(message.content) } }] });\n continue;\n }\n if (role !== 'human' && role !== 'ai') throw new ConfigError(`unsupported LangChain message role: ${role}`);\n const content: ChatPart[] = typeof message.content === 'string' ? [{ type: 'text', text: message.content }] : message.content.map(inputPart);\n if (role === 'ai') {\n const metadata = message.additional_kwargs.agentcore_tool_metadata as Record<string, SharedV3ProviderOptions> | undefined;\n for (const call of (message as AIMessage).tool_calls ?? []) {\n if (!call.id) throw new ConfigError('LangChain tool call requires an id');\n names.set(call.id, call.name);\n content.push({ type: 'tool-call', toolCallId: call.id, toolName: call.name, input: call.args, providerOptions: metadata?.[call.id] });\n }\n result.push({ role: 'assistant', content });\n } else result.push({ role: 'user', content: content as UserPart[] });\n }\n return result;\n}\nfunction inputPart(part: Record<string, any>): ChatPart {\n const providerOptions = part.providerOptions as SharedV3ProviderOptions | undefined;\n if (part.type === 'text') return { type: 'text', text: part.text, providerOptions };\n if (part.type === 'reasoning') return { type: 'reasoning', text: part.reasoning, providerOptions };\n if (part.type === 'image_url') {\n const url = typeof part.image_url === 'string' ? part.image_url : part.image_url.url;\n return filePart(url, 'image/*', providerOptions);\n }\n if (['image', 'audio', 'video', 'file'].includes(part.type)) {\n const data = part.url ?? part.data;\n const mediaType = part.mimeType ?? part.mime_type ?? (part.type === 'file' ? undefined : `${part.type}/*`);\n if (data !== undefined) return filePart(data, mediaType, providerOptions);\n }\n throw new ConfigError(`unsupported LangChain provider content block: ${part.type}`);\n}\nfunction filePart(data: string | Uint8Array, mediaType?: string, providerOptions?: SharedV3ProviderOptions): ChatPart {\n if (typeof data === 'string' && data.startsWith('data:')) {\n const match = /^data:([^;,]+);base64,(.*)$/s.exec(data);\n if (!match) throw new ConfigError('data URL must contain base64 data and a media type');\n return { type: 'file', mediaType: match[1]!, data: match[2]!, providerOptions };\n }\n const url = typeof data === 'string' && /^(https?:|gs:)/.test(data) ? new URL(data) : undefined;\n if (!mediaType) throw new ConfigError('file content requires a media type');\n return { type: 'file', mediaType, data: url ?? data, providerOptions };\n}\nfunction outputPart(part: Extract<LanguageModelV3Content, { type: 'text' | 'reasoning' | 'file' }>): { type: string; [key: string]: unknown } {\n if (part.type === 'text') return { type: 'text', text: part.text, providerOptions: part.providerMetadata };\n if (part.type === 'reasoning') return { type: 'reasoning', reasoning: part.text, providerOptions: part.providerMetadata };\n return { type: 'file', mimeType: part.mediaType,\n data: typeof part.data === 'string' ? part.data : Buffer.from(part.data).toString('base64'), providerOptions: part.providerMetadata };\n}\nfunction usage(value: LanguageModelV3Usage): UsageMetadata {\n const input = value.inputTokens.total ?? 0; const output = value.outputTokens.total ?? 0;\n return { input_tokens: input, output_tokens: output, total_tokens: input + output };\n}\nfunction toolChoice(value: ProviderChatCallOptions['tool_choice']): LanguageModelV3ToolChoice | undefined {\n if (value === undefined) return undefined;\n if (value === 'auto' || value === 'none' || value === 'required') return { type: value };\n if (value === 'any') return { type: 'required' };\n if (typeof value === 'string') return { type: 'tool', toolName: value };\n if (value.type === 'function' && typeof value.function?.name === 'string') return { type: 'tool', toolName: value.function.name };\n throw new ConfigError('unsupported LangChain tool_choice');\n}\n"]}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ConfigError,
|
|
3
|
+
InvocationError
|
|
4
|
+
} from "./chunk-MZ5UWGXS.js";
|
|
5
|
+
|
|
6
|
+
// src/integrations/langchain-provider.ts
|
|
7
|
+
import { BaseChatModel } from "@langchain/core/language_models/chat_models";
|
|
8
|
+
import { AIMessageChunk } from "@langchain/core/messages";
|
|
9
|
+
import { ChatGenerationChunk } from "@langchain/core/outputs";
|
|
10
|
+
import { convertToOpenAITool } from "@langchain/core/utils/function_calling";
|
|
11
|
+
var ProviderChatModel = class extends BaseChatModel {
|
|
12
|
+
constructor(client, defaults = {}) {
|
|
13
|
+
super({ maxRetries: 0 });
|
|
14
|
+
this.client = client;
|
|
15
|
+
this.defaults = defaults;
|
|
16
|
+
}
|
|
17
|
+
client;
|
|
18
|
+
defaults;
|
|
19
|
+
_llmType() {
|
|
20
|
+
return "agentcore-provider";
|
|
21
|
+
}
|
|
22
|
+
get callKeys() {
|
|
23
|
+
return [...super.callKeys, "tools", "tool_choice", "maxOutputTokens", "temperature", "topP", "topK", "presencePenalty", "frequencyPenalty", "seed", "responseFormat", "providerOptions", "headers"];
|
|
24
|
+
}
|
|
25
|
+
bindTools(tools, kwargs) {
|
|
26
|
+
return this.withConfig({ ...kwargs, tools });
|
|
27
|
+
}
|
|
28
|
+
async _generate(messages, options) {
|
|
29
|
+
const result = await this.client.languageModel.doGenerate(this.request(messages, options));
|
|
30
|
+
const content = result.content.filter((p) => p.type === "text" || p.type === "reasoning" || p.type === "file").map(outputPart);
|
|
31
|
+
const calls = result.content.filter((p) => p.type === "tool-call");
|
|
32
|
+
const message = new AIMessageChunk({
|
|
33
|
+
content,
|
|
34
|
+
tool_calls: calls.map((call) => ({ type: "tool_call", id: call.toolCallId, name: call.toolName, args: JSON.parse(call.input) })),
|
|
35
|
+
additional_kwargs: { agentcore_tool_metadata: Object.fromEntries(calls.map((call) => [call.toolCallId, call.providerMetadata])) },
|
|
36
|
+
usage_metadata: usage(result.usage),
|
|
37
|
+
response_metadata: {
|
|
38
|
+
finish_reason: result.finishReason.unified,
|
|
39
|
+
providerMetadata: result.providerMetadata,
|
|
40
|
+
sources: result.content.filter((p) => p.type === "source")
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
return { generations: [{ text: message.text, message }] };
|
|
44
|
+
}
|
|
45
|
+
async *_streamResponseChunks(messages, options, runManager) {
|
|
46
|
+
const controller = new AbortController();
|
|
47
|
+
const signal = AbortSignal.any([controller.signal, ...options.signal ? [options.signal] : []]);
|
|
48
|
+
try {
|
|
49
|
+
const result = await this.client.languageModel.doStream(this.request(messages, { ...options, signal }));
|
|
50
|
+
const reader = result.stream.getReader();
|
|
51
|
+
const blocks = /* @__PURE__ */ new Map();
|
|
52
|
+
const calls = /* @__PURE__ */ new Map();
|
|
53
|
+
let finished = false;
|
|
54
|
+
try {
|
|
55
|
+
while (true) {
|
|
56
|
+
const next = await reader.read();
|
|
57
|
+
if (next.done) break;
|
|
58
|
+
const part = next.value;
|
|
59
|
+
let message;
|
|
60
|
+
let text = "";
|
|
61
|
+
if (part.type === "error") throw part.error;
|
|
62
|
+
if (part.type === "text-delta" || part.type === "reasoning-delta") {
|
|
63
|
+
const key = `${part.type}:${part.id}`;
|
|
64
|
+
if (!blocks.has(key)) blocks.set(key, blocks.size);
|
|
65
|
+
const index = blocks.get(key);
|
|
66
|
+
text = part.type === "text-delta" ? part.delta : "";
|
|
67
|
+
message = new AIMessageChunk({ content: [part.type === "text-delta" ? { type: "text", text, index, providerOptions: part.providerMetadata } : { type: "reasoning", reasoning: part.delta, index, providerOptions: part.providerMetadata }] });
|
|
68
|
+
} else if (part.type === "text-end" || part.type === "reasoning-end") {
|
|
69
|
+
const index = blocks.get(`${part.type === "text-end" ? "text" : "reasoning"}-delta:${part.id}`);
|
|
70
|
+
if (index !== void 0 && part.providerMetadata) message = new AIMessageChunk({ content: [{
|
|
71
|
+
type: part.type === "text-end" ? "text" : "reasoning",
|
|
72
|
+
index,
|
|
73
|
+
providerOptions: part.providerMetadata
|
|
74
|
+
}] });
|
|
75
|
+
} else if (part.type === "tool-input-start") {
|
|
76
|
+
const index = calls.size;
|
|
77
|
+
calls.set(part.id, index);
|
|
78
|
+
message = new AIMessageChunk({ content: [], tool_call_chunks: [{ type: "tool_call_chunk", index, id: part.id, name: part.toolName, args: "" }] });
|
|
79
|
+
} else if (part.type === "tool-input-delta") {
|
|
80
|
+
message = new AIMessageChunk({ content: [], tool_call_chunks: [{ type: "tool_call_chunk", index: calls.get(part.id), args: part.delta }] });
|
|
81
|
+
} else if (part.type === "tool-call") {
|
|
82
|
+
const metadata = { agentcore_tool_metadata: { [part.toolCallId]: part.providerMetadata } };
|
|
83
|
+
message = new AIMessageChunk({
|
|
84
|
+
content: [],
|
|
85
|
+
additional_kwargs: metadata,
|
|
86
|
+
tool_call_chunks: calls.has(part.toolCallId) ? [] : [{ type: "tool_call_chunk", index: calls.size, id: part.toolCallId, name: part.toolName, args: part.input }]
|
|
87
|
+
});
|
|
88
|
+
if (!calls.has(part.toolCallId)) calls.set(part.toolCallId, calls.size);
|
|
89
|
+
} else if (part.type === "file") {
|
|
90
|
+
const index = blocks.size;
|
|
91
|
+
blocks.set(`file:${index}`, index);
|
|
92
|
+
message = new AIMessageChunk({ content: [{ ...outputPart(part), index }] });
|
|
93
|
+
} else if (part.type === "source") {
|
|
94
|
+
message = new AIMessageChunk({ content: [], response_metadata: { sources: [part] } });
|
|
95
|
+
} else if (part.type === "finish") {
|
|
96
|
+
finished = true;
|
|
97
|
+
message = new AIMessageChunk({
|
|
98
|
+
content: [],
|
|
99
|
+
usage_metadata: usage(part.usage),
|
|
100
|
+
response_metadata: { finish_reason: part.finishReason.unified, providerMetadata: part.providerMetadata }
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
if (message) {
|
|
104
|
+
const chunk = new ChatGenerationChunk({ text, message });
|
|
105
|
+
yield chunk;
|
|
106
|
+
await runManager?.handleLLMNewToken(text, void 0, void 0, void 0, void 0, { chunk });
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (!finished) throw new InvocationError("model stream ended without a completion event");
|
|
110
|
+
} finally {
|
|
111
|
+
reader.releaseLock();
|
|
112
|
+
}
|
|
113
|
+
} finally {
|
|
114
|
+
controller.abort();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
request(messages, options) {
|
|
118
|
+
const settings = { ...this.defaults, ...options };
|
|
119
|
+
return {
|
|
120
|
+
prompt: prompt(messages),
|
|
121
|
+
abortSignal: options.signal,
|
|
122
|
+
stopSequences: options.stop,
|
|
123
|
+
maxOutputTokens: settings.maxOutputTokens,
|
|
124
|
+
temperature: settings.temperature,
|
|
125
|
+
topP: settings.topP,
|
|
126
|
+
topK: settings.topK,
|
|
127
|
+
presencePenalty: settings.presencePenalty,
|
|
128
|
+
frequencyPenalty: settings.frequencyPenalty,
|
|
129
|
+
seed: settings.seed,
|
|
130
|
+
responseFormat: settings.responseFormat,
|
|
131
|
+
providerOptions: settings.providerOptions,
|
|
132
|
+
headers: settings.headers,
|
|
133
|
+
tools: options.tools?.map((item) => {
|
|
134
|
+
const value = convertToOpenAITool(item).function;
|
|
135
|
+
return { type: "function", name: value.name, description: value.description, inputSchema: value.parameters };
|
|
136
|
+
}),
|
|
137
|
+
toolChoice: toolChoice(options.tool_choice)
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
function prompt(messages) {
|
|
142
|
+
const names = /* @__PURE__ */ new Map();
|
|
143
|
+
const result = [];
|
|
144
|
+
for (const message of messages) {
|
|
145
|
+
const role = message.type;
|
|
146
|
+
if (role === "system") {
|
|
147
|
+
result.push({ role: "system", content: message.text });
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (role === "tool") {
|
|
151
|
+
const id = message.tool_call_id;
|
|
152
|
+
const name = message.name ?? names.get(id);
|
|
153
|
+
if (!name) throw new ConfigError("LangChain ToolMessage requires a matching tool call or name");
|
|
154
|
+
result.push({ role: "tool", content: [{
|
|
155
|
+
type: "tool-result",
|
|
156
|
+
toolCallId: id,
|
|
157
|
+
toolName: name,
|
|
158
|
+
output: { type: "text", value: typeof message.content === "string" ? message.content : JSON.stringify(message.content) }
|
|
159
|
+
}] });
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
if (role !== "human" && role !== "ai") throw new ConfigError(`unsupported LangChain message role: ${role}`);
|
|
163
|
+
const content = typeof message.content === "string" ? [{ type: "text", text: message.content }] : message.content.map(inputPart);
|
|
164
|
+
if (role === "ai") {
|
|
165
|
+
const metadata = message.additional_kwargs.agentcore_tool_metadata;
|
|
166
|
+
for (const call of message.tool_calls ?? []) {
|
|
167
|
+
if (!call.id) throw new ConfigError("LangChain tool call requires an id");
|
|
168
|
+
names.set(call.id, call.name);
|
|
169
|
+
content.push({ type: "tool-call", toolCallId: call.id, toolName: call.name, input: call.args, providerOptions: metadata?.[call.id] });
|
|
170
|
+
}
|
|
171
|
+
result.push({ role: "assistant", content });
|
|
172
|
+
} else result.push({ role: "user", content });
|
|
173
|
+
}
|
|
174
|
+
return result;
|
|
175
|
+
}
|
|
176
|
+
function inputPart(part) {
|
|
177
|
+
const providerOptions = part.providerOptions;
|
|
178
|
+
if (part.type === "text") return { type: "text", text: part.text, providerOptions };
|
|
179
|
+
if (part.type === "reasoning") return { type: "reasoning", text: part.reasoning, providerOptions };
|
|
180
|
+
if (part.type === "image_url") {
|
|
181
|
+
const url = typeof part.image_url === "string" ? part.image_url : part.image_url.url;
|
|
182
|
+
return filePart(url, "image/*", providerOptions);
|
|
183
|
+
}
|
|
184
|
+
if (["image", "audio", "video", "file"].includes(part.type)) {
|
|
185
|
+
const data = part.url ?? part.data;
|
|
186
|
+
const mediaType = part.mimeType ?? part.mime_type ?? (part.type === "file" ? void 0 : `${part.type}/*`);
|
|
187
|
+
if (data !== void 0) return filePart(data, mediaType, providerOptions);
|
|
188
|
+
}
|
|
189
|
+
throw new ConfigError(`unsupported LangChain provider content block: ${part.type}`);
|
|
190
|
+
}
|
|
191
|
+
function filePart(data, mediaType, providerOptions) {
|
|
192
|
+
if (typeof data === "string" && data.startsWith("data:")) {
|
|
193
|
+
const match = /^data:([^;,]+);base64,(.*)$/s.exec(data);
|
|
194
|
+
if (!match) throw new ConfigError("data URL must contain base64 data and a media type");
|
|
195
|
+
return { type: "file", mediaType: match[1], data: match[2], providerOptions };
|
|
196
|
+
}
|
|
197
|
+
const url = typeof data === "string" && /^(https?:|gs:)/.test(data) ? new URL(data) : void 0;
|
|
198
|
+
if (!mediaType) throw new ConfigError("file content requires a media type");
|
|
199
|
+
return { type: "file", mediaType, data: url ?? data, providerOptions };
|
|
200
|
+
}
|
|
201
|
+
function outputPart(part) {
|
|
202
|
+
if (part.type === "text") return { type: "text", text: part.text, providerOptions: part.providerMetadata };
|
|
203
|
+
if (part.type === "reasoning") return { type: "reasoning", reasoning: part.text, providerOptions: part.providerMetadata };
|
|
204
|
+
return {
|
|
205
|
+
type: "file",
|
|
206
|
+
mimeType: part.mediaType,
|
|
207
|
+
data: typeof part.data === "string" ? part.data : Buffer.from(part.data).toString("base64"),
|
|
208
|
+
providerOptions: part.providerMetadata
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
function usage(value) {
|
|
212
|
+
const input = value.inputTokens.total ?? 0;
|
|
213
|
+
const output = value.outputTokens.total ?? 0;
|
|
214
|
+
return { input_tokens: input, output_tokens: output, total_tokens: input + output };
|
|
215
|
+
}
|
|
216
|
+
function toolChoice(value) {
|
|
217
|
+
if (value === void 0) return void 0;
|
|
218
|
+
if (value === "auto" || value === "none" || value === "required") return { type: value };
|
|
219
|
+
if (value === "any") return { type: "required" };
|
|
220
|
+
if (typeof value === "string") return { type: "tool", toolName: value };
|
|
221
|
+
if (value.type === "function" && typeof value.function?.name === "string") return { type: "tool", toolName: value.function.name };
|
|
222
|
+
throw new ConfigError("unsupported LangChain tool_choice");
|
|
223
|
+
}
|
|
224
|
+
export {
|
|
225
|
+
ProviderChatModel
|
|
226
|
+
};
|
|
227
|
+
//# sourceMappingURL=langchain-provider-PHL4UWNF.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/integrations/langchain-provider.ts"],"sourcesContent":["import { BaseChatModel, type BaseChatModelCallOptions, type BindToolsInput } from '@langchain/core/language_models/chat_models';\nimport { AIMessage, AIMessageChunk, type BaseMessage, type UsageMetadata } from '@langchain/core/messages';\nimport { ChatGenerationChunk, type ChatResult } from '@langchain/core/outputs';\nimport type { CallbackManagerForLLMRun } from '@langchain/core/callbacks/manager';\nimport { convertToOpenAITool } from '@langchain/core/utils/function_calling';\nimport type { LanguageModelV3CallOptions, LanguageModelV3Content, LanguageModelV3Message, LanguageModelV3Prompt,\n LanguageModelV3ToolChoice, LanguageModelV3Usage, LanguageModelV3FunctionTool, SharedV3ProviderOptions } from '@ai-sdk/provider';\nimport type { ProviderModelClient } from '../model/provider';\nimport { ConfigError, InvocationError } from '../errors';\n\nexport type LangChainProviderOptions = Pick<LanguageModelV3CallOptions,\n 'maxOutputTokens' | 'temperature' | 'topP' | 'topK' | 'presencePenalty' | 'frequencyPenalty' | 'seed' | 'responseFormat' | 'providerOptions' | 'headers'>;\nexport interface ProviderChatCallOptions extends BaseChatModelCallOptions, LangChainProviderOptions { tools?: BindToolsInput[]; }\n\n/** LangChain owns tool execution; this bridge performs one provider call per model step. */\nexport class ProviderChatModel extends BaseChatModel<ProviderChatCallOptions> {\n constructor(private readonly client: ProviderModelClient, private readonly defaults: LangChainProviderOptions = {}) { super({ maxRetries: 0 }); }\n _llmType(): string { return 'agentcore-provider'; }\n get callKeys(): string[] { return [...super.callKeys, 'tools', 'tool_choice', 'maxOutputTokens', 'temperature', 'topP', 'topK', 'presencePenalty', 'frequencyPenalty', 'seed', 'responseFormat', 'providerOptions', 'headers']; }\n bindTools(tools: BindToolsInput[], kwargs?: Partial<ProviderChatCallOptions>) { return this.withConfig({ ...kwargs, tools }); }\n\n async _generate(messages: BaseMessage[], options: this['ParsedCallOptions']): Promise<ChatResult> {\n const result = await this.client.languageModel.doGenerate(this.request(messages, options));\n const content = result.content.filter(p => p.type === 'text' || p.type === 'reasoning' || p.type === 'file').map(outputPart);\n const calls = result.content.filter(p => p.type === 'tool-call');\n const message = new AIMessageChunk({ content, tool_calls: calls.map(call => ({ type: 'tool_call', id: call.toolCallId, name: call.toolName, args: JSON.parse(call.input) })),\n additional_kwargs: { agentcore_tool_metadata: Object.fromEntries(calls.map(call => [call.toolCallId, call.providerMetadata])) },\n usage_metadata: usage(result.usage), response_metadata: { finish_reason: result.finishReason.unified, providerMetadata: result.providerMetadata,\n sources: result.content.filter(p => p.type === 'source') },\n });\n return { generations: [{ text: message.text, message }] };\n }\n async *_streamResponseChunks(messages: BaseMessage[], options: this['ParsedCallOptions'], runManager?: CallbackManagerForLLMRun): AsyncGenerator<ChatGenerationChunk> {\n const controller = new AbortController();\n const signal = AbortSignal.any([controller.signal, ...(options.signal ? [options.signal] : [])]);\n try {\n const result = await this.client.languageModel.doStream(this.request(messages, { ...options, signal }));\n const reader = result.stream.getReader();\n const blocks = new Map<string, number>(); const calls = new Map<string, number>(); let finished = false;\n try {\n while (true) {\n const next = await reader.read(); if (next.done) break;\n const part = next.value; let message: AIMessageChunk | undefined; let text = '';\n if (part.type === 'error') throw part.error;\n if (part.type === 'text-delta' || part.type === 'reasoning-delta') {\n const key = `${part.type}:${part.id}`;\n if (!blocks.has(key)) blocks.set(key, blocks.size);\n const index = blocks.get(key)!;\n text = part.type === 'text-delta' ? part.delta : '';\n message = new AIMessageChunk({ content: [part.type === 'text-delta'\n ? { type: 'text', text, index, providerOptions: part.providerMetadata }\n : { type: 'reasoning', reasoning: part.delta, index, providerOptions: part.providerMetadata }] });\n } else if (part.type === 'text-end' || part.type === 'reasoning-end') {\n const index = blocks.get(`${part.type === 'text-end' ? 'text' : 'reasoning'}-delta:${part.id}`);\n if (index !== undefined && part.providerMetadata) message = new AIMessageChunk({ content: [{\n type: part.type === 'text-end' ? 'text' : 'reasoning', index, providerOptions: part.providerMetadata,\n }] });\n } else if (part.type === 'tool-input-start') {\n const index = calls.size; calls.set(part.id, index);\n message = new AIMessageChunk({ content: [], tool_call_chunks: [{ type: 'tool_call_chunk', index, id: part.id, name: part.toolName, args: '' }] });\n } else if (part.type === 'tool-input-delta') {\n message = new AIMessageChunk({ content: [], tool_call_chunks: [{ type: 'tool_call_chunk', index: calls.get(part.id), args: part.delta }] });\n } else if (part.type === 'tool-call') {\n const metadata = { agentcore_tool_metadata: { [part.toolCallId]: part.providerMetadata } };\n message = new AIMessageChunk({ content: [], additional_kwargs: metadata,\n tool_call_chunks: calls.has(part.toolCallId) ? [] : [{ type: 'tool_call_chunk', index: calls.size, id: part.toolCallId, name: part.toolName, args: part.input }],\n });\n if (!calls.has(part.toolCallId)) calls.set(part.toolCallId, calls.size);\n } else if (part.type === 'file') {\n const index = blocks.size; blocks.set(`file:${index}`, index);\n message = new AIMessageChunk({ content: [{ ...outputPart(part), index }] });\n } else if (part.type === 'source') {\n message = new AIMessageChunk({ content: [], response_metadata: { sources: [part] } });\n } else if (part.type === 'finish') {\n finished = true;\n message = new AIMessageChunk({ content: [], usage_metadata: usage(part.usage),\n response_metadata: { finish_reason: part.finishReason.unified, providerMetadata: part.providerMetadata } });\n }\n if (message) {\n const chunk = new ChatGenerationChunk({ text, message }); yield chunk;\n await runManager?.handleLLMNewToken(text, undefined, undefined, undefined, undefined, { chunk });\n }\n }\n if (!finished) throw new InvocationError('model stream ended without a completion event');\n } finally { reader.releaseLock(); }\n } finally { controller.abort(); }\n }\n private request(messages: BaseMessage[], options: this['ParsedCallOptions']): LanguageModelV3CallOptions {\n const settings = { ...this.defaults, ...options };\n return { prompt: prompt(messages), abortSignal: options.signal, stopSequences: options.stop,\n maxOutputTokens: settings.maxOutputTokens, temperature: settings.temperature, topP: settings.topP, topK: settings.topK,\n presencePenalty: settings.presencePenalty, frequencyPenalty: settings.frequencyPenalty, seed: settings.seed,\n responseFormat: settings.responseFormat, providerOptions: settings.providerOptions, headers: settings.headers,\n tools: options.tools?.map(item => {\n const value = convertToOpenAITool(item).function;\n return { type: 'function', name: value.name, description: value.description, inputSchema: value.parameters as LanguageModelV3FunctionTool['inputSchema'] };\n }), toolChoice: toolChoice(options.tool_choice),\n };\n }\n}\n\ntype ChatPart = Extract<LanguageModelV3Message, { role: 'assistant' }>['content'][number];\ntype UserPart = Extract<LanguageModelV3Message, { role: 'user' }>['content'][number];\nfunction prompt(messages: BaseMessage[]): LanguageModelV3Prompt {\n const names = new Map<string, string>(); const result: LanguageModelV3Prompt = [];\n for (const message of messages) {\n const role = message.type;\n if (role === 'system') { result.push({ role: 'system', content: message.text }); continue; }\n if (role === 'tool') {\n const id = (message as BaseMessage & { tool_call_id: string }).tool_call_id;\n const name = message.name ?? names.get(id);\n if (!name) throw new ConfigError('LangChain ToolMessage requires a matching tool call or name');\n result.push({ role: 'tool', content: [{ type: 'tool-result', toolCallId: id, toolName: name,\n output: { type: 'text', value: typeof message.content === 'string' ? message.content : JSON.stringify(message.content) } }] });\n continue;\n }\n if (role !== 'human' && role !== 'ai') throw new ConfigError(`unsupported LangChain message role: ${role}`);\n const content: ChatPart[] = typeof message.content === 'string' ? [{ type: 'text', text: message.content }] : message.content.map(inputPart);\n if (role === 'ai') {\n const metadata = message.additional_kwargs.agentcore_tool_metadata as Record<string, SharedV3ProviderOptions> | undefined;\n for (const call of (message as AIMessage).tool_calls ?? []) {\n if (!call.id) throw new ConfigError('LangChain tool call requires an id');\n names.set(call.id, call.name);\n content.push({ type: 'tool-call', toolCallId: call.id, toolName: call.name, input: call.args, providerOptions: metadata?.[call.id] });\n }\n result.push({ role: 'assistant', content });\n } else result.push({ role: 'user', content: content as UserPart[] });\n }\n return result;\n}\nfunction inputPart(part: Record<string, any>): ChatPart {\n const providerOptions = part.providerOptions as SharedV3ProviderOptions | undefined;\n if (part.type === 'text') return { type: 'text', text: part.text, providerOptions };\n if (part.type === 'reasoning') return { type: 'reasoning', text: part.reasoning, providerOptions };\n if (part.type === 'image_url') {\n const url = typeof part.image_url === 'string' ? part.image_url : part.image_url.url;\n return filePart(url, 'image/*', providerOptions);\n }\n if (['image', 'audio', 'video', 'file'].includes(part.type)) {\n const data = part.url ?? part.data;\n const mediaType = part.mimeType ?? part.mime_type ?? (part.type === 'file' ? undefined : `${part.type}/*`);\n if (data !== undefined) return filePart(data, mediaType, providerOptions);\n }\n throw new ConfigError(`unsupported LangChain provider content block: ${part.type}`);\n}\nfunction filePart(data: string | Uint8Array, mediaType?: string, providerOptions?: SharedV3ProviderOptions): ChatPart {\n if (typeof data === 'string' && data.startsWith('data:')) {\n const match = /^data:([^;,]+);base64,(.*)$/s.exec(data);\n if (!match) throw new ConfigError('data URL must contain base64 data and a media type');\n return { type: 'file', mediaType: match[1]!, data: match[2]!, providerOptions };\n }\n const url = typeof data === 'string' && /^(https?:|gs:)/.test(data) ? new URL(data) : undefined;\n if (!mediaType) throw new ConfigError('file content requires a media type');\n return { type: 'file', mediaType, data: url ?? data, providerOptions };\n}\nfunction outputPart(part: Extract<LanguageModelV3Content, { type: 'text' | 'reasoning' | 'file' }>): { type: string; [key: string]: unknown } {\n if (part.type === 'text') return { type: 'text', text: part.text, providerOptions: part.providerMetadata };\n if (part.type === 'reasoning') return { type: 'reasoning', reasoning: part.text, providerOptions: part.providerMetadata };\n return { type: 'file', mimeType: part.mediaType,\n data: typeof part.data === 'string' ? part.data : Buffer.from(part.data).toString('base64'), providerOptions: part.providerMetadata };\n}\nfunction usage(value: LanguageModelV3Usage): UsageMetadata {\n const input = value.inputTokens.total ?? 0; const output = value.outputTokens.total ?? 0;\n return { input_tokens: input, output_tokens: output, total_tokens: input + output };\n}\nfunction toolChoice(value: ProviderChatCallOptions['tool_choice']): LanguageModelV3ToolChoice | undefined {\n if (value === undefined) return undefined;\n if (value === 'auto' || value === 'none' || value === 'required') return { type: value };\n if (value === 'any') return { type: 'required' };\n if (typeof value === 'string') return { type: 'tool', toolName: value };\n if (value.type === 'function' && typeof value.function?.name === 'string') return { type: 'tool', toolName: value.function.name };\n throw new ConfigError('unsupported LangChain tool_choice');\n}\n"],"mappings":";;;;;;AAAA,SAAS,qBAAyE;AAClF,SAAoB,sBAA4D;AAChF,SAAS,2BAA4C;AAErD,SAAS,2BAA2B;AAW7B,IAAM,oBAAN,cAAgC,cAAuC;AAAA,EAC5E,YAA6B,QAA8C,WAAqC,CAAC,GAAG;AAAE,UAAM,EAAE,YAAY,EAAE,CAAC;AAAhH;AAA8C;AAAA,EAAqE;AAAA,EAAnH;AAAA,EAA8C;AAAA,EAC3E,WAAmB;AAAE,WAAO;AAAA,EAAsB;AAAA,EAClD,IAAI,WAAqB;AAAE,WAAO,CAAC,GAAG,MAAM,UAAU,SAAS,eAAe,mBAAmB,eAAe,QAAQ,QAAQ,mBAAmB,oBAAoB,QAAQ,kBAAkB,mBAAmB,SAAS;AAAA,EAAG;AAAA,EAChO,UAAU,OAAyB,QAA2C;AAAE,WAAO,KAAK,WAAW,EAAE,GAAG,QAAQ,MAAM,CAAC;AAAA,EAAG;AAAA,EAE9H,MAAM,UAAU,UAAyB,SAAyD;AAChG,UAAM,SAAS,MAAM,KAAK,OAAO,cAAc,WAAW,KAAK,QAAQ,UAAU,OAAO,CAAC;AACzF,UAAM,UAAU,OAAO,QAAQ,OAAO,OAAK,EAAE,SAAS,UAAU,EAAE,SAAS,eAAe,EAAE,SAAS,MAAM,EAAE,IAAI,UAAU;AAC3H,UAAM,QAAQ,OAAO,QAAQ,OAAO,OAAK,EAAE,SAAS,WAAW;AAC/D,UAAM,UAAU,IAAI,eAAe;AAAA,MAAE;AAAA,MAAS,YAAY,MAAM,IAAI,WAAS,EAAE,MAAM,aAAa,IAAI,KAAK,YAAY,MAAM,KAAK,UAAU,MAAM,KAAK,MAAM,KAAK,KAAK,EAAE,EAAE;AAAA,MACzK,mBAAmB,EAAE,yBAAyB,OAAO,YAAY,MAAM,IAAI,UAA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,eAAe,QAAQ,cAAc,QAAQ,OAAO;AACpF;AACA,SAAS,WAAW,OAAsF;AACxG,MAAI,UAAU,OAAW,QAAO;AAChC,MAAI,UAAU,UAAU,UAAU,UAAU,UAAU,WAAY,QAAO,EAAE,MAAM,MAAM;AACvF,MAAI,UAAU,MAAO,QAAO,EAAE,MAAM,WAAW;AAC/C,MAAI,OAAO,UAAU,SAAU,QAAO,EAAE,MAAM,QAAQ,UAAU,MAAM;AACtE,MAAI,MAAM,SAAS,cAAc,OAAO,MAAM,UAAU,SAAS,SAAU,QAAO,EAAE,MAAM,QAAQ,UAAU,MAAM,SAAS,KAAK;AAChI,QAAM,IAAI,YAAY,mCAAmC;AAC3D;","names":[]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { SkillArtifact } from './controlplane/index.js';
|
|
2
|
+
import { L as Logger } from './logging-C8GLLg1f.js';
|
|
3
|
+
|
|
4
|
+
interface Skill {
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly description: string;
|
|
7
|
+
readonly version: string;
|
|
8
|
+
readonly instruction: string;
|
|
9
|
+
readonly root: string;
|
|
10
|
+
readonly files: readonly string[];
|
|
11
|
+
readonly source: 'local' | 'agentcore';
|
|
12
|
+
readonly digest?: string;
|
|
13
|
+
readonly workspaceId?: string;
|
|
14
|
+
}
|
|
15
|
+
interface SkillProvider {
|
|
16
|
+
getSkill(name: string, version?: string): Promise<SkillArtifact>;
|
|
17
|
+
}
|
|
18
|
+
interface SkillsOptions {
|
|
19
|
+
workspaceDir?: string;
|
|
20
|
+
runtime?: () => Promise<{
|
|
21
|
+
workspaceId: string;
|
|
22
|
+
provider: SkillProvider;
|
|
23
|
+
}>;
|
|
24
|
+
logger?: Logger;
|
|
25
|
+
}
|
|
26
|
+
declare class Skills {
|
|
27
|
+
private readonly options;
|
|
28
|
+
private readonly pins;
|
|
29
|
+
private readonly workspace;
|
|
30
|
+
private readonly logger;
|
|
31
|
+
constructor(options?: SkillsOptions);
|
|
32
|
+
local(root: string): Promise<Skill[]>;
|
|
33
|
+
managed(name: string, options?: {
|
|
34
|
+
version?: string;
|
|
35
|
+
}): Promise<Skill>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { type Skill as S, Skills as a, type SkillProvider as b, type SkillsOptions as c };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { SkillArtifact } from './controlplane/index.cjs';
|
|
2
|
+
import { L as Logger } from './logging-C8GLLg1f.cjs';
|
|
3
|
+
|
|
4
|
+
interface Skill {
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly description: string;
|
|
7
|
+
readonly version: string;
|
|
8
|
+
readonly instruction: string;
|
|
9
|
+
readonly root: string;
|
|
10
|
+
readonly files: readonly string[];
|
|
11
|
+
readonly source: 'local' | 'agentcore';
|
|
12
|
+
readonly digest?: string;
|
|
13
|
+
readonly workspaceId?: string;
|
|
14
|
+
}
|
|
15
|
+
interface SkillProvider {
|
|
16
|
+
getSkill(name: string, version?: string): Promise<SkillArtifact>;
|
|
17
|
+
}
|
|
18
|
+
interface SkillsOptions {
|
|
19
|
+
workspaceDir?: string;
|
|
20
|
+
runtime?: () => Promise<{
|
|
21
|
+
workspaceId: string;
|
|
22
|
+
provider: SkillProvider;
|
|
23
|
+
}>;
|
|
24
|
+
logger?: Logger;
|
|
25
|
+
}
|
|
26
|
+
declare class Skills {
|
|
27
|
+
private readonly options;
|
|
28
|
+
private readonly pins;
|
|
29
|
+
private readonly workspace;
|
|
30
|
+
private readonly logger;
|
|
31
|
+
constructor(options?: SkillsOptions);
|
|
32
|
+
local(root: string): Promise<Skill[]>;
|
|
33
|
+
managed(name: string, options?: {
|
|
34
|
+
version?: string;
|
|
35
|
+
}): Promise<Skill>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { type Skill as S, Skills as a, type SkillProvider as b, type SkillsOptions as c };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
type LogFields = Readonly<Record<string, string | number | boolean | undefined>>;
|
|
2
|
+
interface Logger {
|
|
3
|
+
debug(event: string, fields?: LogFields): void;
|
|
4
|
+
info(event: string, fields?: LogFields): void;
|
|
5
|
+
warn(event: string, fields?: LogFields): void;
|
|
6
|
+
error(event: string, fields?: LogFields): void;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type { Logger as L, LogFields as a };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
type LogFields = Readonly<Record<string, string | number | boolean | undefined>>;
|
|
2
|
+
interface Logger {
|
|
3
|
+
debug(event: string, fields?: LogFields): void;
|
|
4
|
+
info(event: string, fields?: LogFields): void;
|
|
5
|
+
warn(event: string, fields?: LogFields): void;
|
|
6
|
+
error(event: string, fields?: LogFields): void;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type { Logger as L, LogFields as a };
|