@cognipeer/agent-sdk 0.7.1 → 0.7.3
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/README.md +28 -1
- package/dist/index.cjs +346 -59
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +153 -1
- package/dist/index.d.ts +153 -1
- package/dist/index.mjs +335 -60
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -3026,6 +3026,17 @@ function createToolsNode(initialTools, opts) {
|
|
|
3026
3026
|
}
|
|
3027
3027
|
const durationMs = Date.now() - start;
|
|
3028
3028
|
const executionId = nanoid();
|
|
3029
|
+
if (output && typeof output === "object" && Array.isArray(output.__runtimeToolsDelta)) {
|
|
3030
|
+
const delta = output.__runtimeToolsDelta;
|
|
3031
|
+
delete output.__runtimeToolsDelta;
|
|
3032
|
+
const currentRuntime = state.agent || runtime;
|
|
3033
|
+
const currentTools = currentRuntime?.tools ?? [];
|
|
3034
|
+
const present = new Set(currentTools.map((tool2) => tool2?.name));
|
|
3035
|
+
const additions = delta.filter((tool2) => tool2 && tool2.name && !present.has(tool2.name));
|
|
3036
|
+
if (additions.length > 0 && currentRuntime) {
|
|
3037
|
+
state.agent = { ...currentRuntime, tools: [...currentTools, ...additions] };
|
|
3038
|
+
}
|
|
3039
|
+
}
|
|
3029
3040
|
if (output && typeof output === "object" && output.__handoff && output.__handoff.runtime) {
|
|
3030
3041
|
toolHistory.push({ executionId, toolName, args, output: "handoff:ok", rawOutput: output, timestamp: (/* @__PURE__ */ new Date()).toISOString(), tool_call_id: tc.id, status: "handoff" });
|
|
3031
3042
|
push({ role: "tool", content: "ok", tool_call_id: tc.id || `${tc.name}_${toolCount}`, name: tc.name });
|
|
@@ -6183,6 +6194,190 @@ async function writeSummaryFactsToMemory(store, config, summary, sourceTurn) {
|
|
|
6183
6194
|
return store.get(config.memory.scope, { limit: config.context.lastTurnsToKeep + summary.stable_facts.length });
|
|
6184
6195
|
}
|
|
6185
6196
|
|
|
6197
|
+
// src/smart/skills/types.ts
|
|
6198
|
+
var DEFAULT_SKILL_POLICY = {
|
|
6199
|
+
maxOpenSkills: 4,
|
|
6200
|
+
maxBoundToolsPerSkill: 12,
|
|
6201
|
+
maxBoundToolsTotal: 40
|
|
6202
|
+
};
|
|
6203
|
+
var SMALL_TIER_SKILL_POLICY = {
|
|
6204
|
+
maxOpenSkills: 1,
|
|
6205
|
+
maxBoundToolsPerSkill: 6,
|
|
6206
|
+
maxBoundToolsTotal: 18,
|
|
6207
|
+
modelTier: "small"
|
|
6208
|
+
};
|
|
6209
|
+
function createSkillRegistryRef() {
|
|
6210
|
+
return { openedSkillKeys: [], boundSkillTools: [] };
|
|
6211
|
+
}
|
|
6212
|
+
|
|
6213
|
+
// src/smart/skills/registry.ts
|
|
6214
|
+
function composeToolSets(input) {
|
|
6215
|
+
const without = [...input.base, ...input.boundSkillTools];
|
|
6216
|
+
const withRec = input.recoveryTool ? [...without, input.recoveryTool] : [...without];
|
|
6217
|
+
return { toolsWithoutRecovery: without, toolsWithRecovery: withRec };
|
|
6218
|
+
}
|
|
6219
|
+
function appendBoundTools(ref, newTools, policy) {
|
|
6220
|
+
const present = new Set(ref.boundSkillTools.map((tool) => tool.name));
|
|
6221
|
+
const added = [];
|
|
6222
|
+
for (const tool of newTools) {
|
|
6223
|
+
if (ref.boundSkillTools.length >= policy.maxBoundToolsTotal) break;
|
|
6224
|
+
if (present.has(tool.name)) continue;
|
|
6225
|
+
present.add(tool.name);
|
|
6226
|
+
ref.boundSkillTools.push(tool);
|
|
6227
|
+
added.push(tool);
|
|
6228
|
+
}
|
|
6229
|
+
return added;
|
|
6230
|
+
}
|
|
6231
|
+
function canOpenSkill(ref, policy) {
|
|
6232
|
+
if (ref.openedSkillKeys.length >= policy.maxOpenSkills) {
|
|
6233
|
+
return { ok: false, reason: `max ${policy.maxOpenSkills} skill(s) already open` };
|
|
6234
|
+
}
|
|
6235
|
+
if (ref.boundSkillTools.length >= policy.maxBoundToolsTotal) {
|
|
6236
|
+
return { ok: false, reason: "skill tool budget exhausted" };
|
|
6237
|
+
}
|
|
6238
|
+
return { ok: true };
|
|
6239
|
+
}
|
|
6240
|
+
async function resolveAvailableSkills(skills, opts = {}) {
|
|
6241
|
+
const out = [];
|
|
6242
|
+
for (const skill of skills) {
|
|
6243
|
+
if (skill.minModelTier === "large" && opts.modelTier === "small") continue;
|
|
6244
|
+
const available = skill.isAvailable ? await skill.isAvailable() : true;
|
|
6245
|
+
if (available) out.push(skill);
|
|
6246
|
+
}
|
|
6247
|
+
return out;
|
|
6248
|
+
}
|
|
6249
|
+
function buildSkillHeaderBlock(skills) {
|
|
6250
|
+
if (skills.length === 0) return "";
|
|
6251
|
+
const lines = skills.map((skill) => `- ${skill.key}: ${skill.header}`);
|
|
6252
|
+
return [
|
|
6253
|
+
"<available_skills>",
|
|
6254
|
+
"Open a skill with open_skill(skillKey) to load its tools on demand. Only open what the task needs; close nothing \u2014 opened skills stay available for the rest of the run.",
|
|
6255
|
+
...lines,
|
|
6256
|
+
"</available_skills>"
|
|
6257
|
+
].join("\n");
|
|
6258
|
+
}
|
|
6259
|
+
function dedupeToolsByName(tools) {
|
|
6260
|
+
const seen = /* @__PURE__ */ new Set();
|
|
6261
|
+
const out = [];
|
|
6262
|
+
for (const tool of tools) {
|
|
6263
|
+
if (seen.has(tool.name)) continue;
|
|
6264
|
+
seen.add(tool.name);
|
|
6265
|
+
out.push(tool);
|
|
6266
|
+
}
|
|
6267
|
+
return out;
|
|
6268
|
+
}
|
|
6269
|
+
|
|
6270
|
+
// src/smart/skills/skillTools.ts
|
|
6271
|
+
var MAX_RETURNED_INDEX = 40;
|
|
6272
|
+
var OPEN_SKILL_DESCRIPTION = "Load a capability on demand. Pass a skillKey from <available_skills>. A small skill binds all its tools immediately; a large one returns a tool index \u2014 then call bind_skill_tools with only the tools you need. Open only what the task needs.";
|
|
6273
|
+
var BIND_SKILL_TOOLS_DESCRIPTION = "After open_skill on a large skill, bind a chosen subset of its tools by name. Pick the few tools the task actually needs.";
|
|
6274
|
+
function findSkill(deps, key) {
|
|
6275
|
+
return deps.skills.find((skill) => skill.key === key);
|
|
6276
|
+
}
|
|
6277
|
+
function createOpenSkillTool(deps) {
|
|
6278
|
+
const tool = createTool({
|
|
6279
|
+
name: "open_skill",
|
|
6280
|
+
description: OPEN_SKILL_DESCRIPTION,
|
|
6281
|
+
schema: z.object({
|
|
6282
|
+
skillKey: z.string().min(1).describe("A key from <available_skills>."),
|
|
6283
|
+
query: z.string().optional().describe("What you need from the skill \u2014 used to rank a large skill's tools.")
|
|
6284
|
+
}).strict(),
|
|
6285
|
+
func: async ({ skillKey, query }) => {
|
|
6286
|
+
const { registryRef: ref, policy } = tool._deps;
|
|
6287
|
+
const skill = findSkill(tool._deps, skillKey);
|
|
6288
|
+
if (!skill) {
|
|
6289
|
+
return { error: `Unknown skill: ${skillKey}. Choose a key listed in <available_skills>.` };
|
|
6290
|
+
}
|
|
6291
|
+
if (skill.isAvailable && !await skill.isAvailable()) {
|
|
6292
|
+
return { error: `Skill ${skillKey} is not available in this workspace.` };
|
|
6293
|
+
}
|
|
6294
|
+
const alreadyOpen = ref.openedSkillKeys.includes(skillKey);
|
|
6295
|
+
if (!alreadyOpen) {
|
|
6296
|
+
const guard = canOpenSkill(ref, policy);
|
|
6297
|
+
if (!guard.ok) {
|
|
6298
|
+
return {
|
|
6299
|
+
error: `Cannot open ${skillKey}: ${guard.reason}. Work with the skills already open.`
|
|
6300
|
+
};
|
|
6301
|
+
}
|
|
6302
|
+
ref.openedSkillKeys.push(skillKey);
|
|
6303
|
+
}
|
|
6304
|
+
const prompt = typeof skill.prompt === "function" ? await skill.prompt() : skill.prompt;
|
|
6305
|
+
const index = await skill.listToolIndex();
|
|
6306
|
+
if (index.length <= policy.maxBoundToolsPerSkill) {
|
|
6307
|
+
const bound = await skill.bindTools();
|
|
6308
|
+
const added = appendBoundTools(ref, bound, policy);
|
|
6309
|
+
if (added.length > 0) ref.__onToolsChanged?.();
|
|
6310
|
+
return {
|
|
6311
|
+
skillKey,
|
|
6312
|
+
prompt,
|
|
6313
|
+
needsSandbox: Boolean(skill.needsSandbox),
|
|
6314
|
+
boundTools: added.map((t) => t.name),
|
|
6315
|
+
// Inject the bound tools into the live runtime for this loop.
|
|
6316
|
+
__runtimeToolsDelta: added
|
|
6317
|
+
};
|
|
6318
|
+
}
|
|
6319
|
+
let defaultBound = [];
|
|
6320
|
+
let defaultAdded = [];
|
|
6321
|
+
if ((!query || query.trim().length < 3) && skill.defaultBindNames?.length) {
|
|
6322
|
+
const bound = await skill.bindTools(skill.defaultBindNames.slice(0, policy.maxBoundToolsPerSkill));
|
|
6323
|
+
defaultAdded = appendBoundTools(ref, bound, policy);
|
|
6324
|
+
if (defaultAdded.length > 0) ref.__onToolsChanged?.();
|
|
6325
|
+
defaultBound = defaultAdded.map((t) => t.name);
|
|
6326
|
+
}
|
|
6327
|
+
const headers = query && query.trim().length >= 3 && skill.rankToolHeaders ? await skill.rankToolHeaders(query, index) : index;
|
|
6328
|
+
return {
|
|
6329
|
+
skillKey,
|
|
6330
|
+
prompt,
|
|
6331
|
+
needsSandbox: Boolean(skill.needsSandbox),
|
|
6332
|
+
boundTools: defaultBound,
|
|
6333
|
+
toolIndex: headers.slice(0, MAX_RETURNED_INDEX).map((h) => ({ name: h.name, description: h.description })),
|
|
6334
|
+
hint: "Call bind_skill_tools(skillKey, toolNames) with only the tools you need.",
|
|
6335
|
+
...defaultAdded.length > 0 ? { __runtimeToolsDelta: defaultAdded } : {}
|
|
6336
|
+
};
|
|
6337
|
+
}
|
|
6338
|
+
});
|
|
6339
|
+
tool._deps = deps;
|
|
6340
|
+
tool.__source = "smart-skills";
|
|
6341
|
+
return tool;
|
|
6342
|
+
}
|
|
6343
|
+
function createBindSkillToolsTool(deps) {
|
|
6344
|
+
const tool = createTool({
|
|
6345
|
+
name: "bind_skill_tools",
|
|
6346
|
+
description: BIND_SKILL_TOOLS_DESCRIPTION,
|
|
6347
|
+
schema: z.object({
|
|
6348
|
+
skillKey: z.string().min(1),
|
|
6349
|
+
toolNames: z.array(z.string().min(1)).min(1).describe("Tool names from the skill's index.")
|
|
6350
|
+
}).strict(),
|
|
6351
|
+
func: async ({ skillKey, toolNames }) => {
|
|
6352
|
+
const { registryRef: ref, policy } = tool._deps;
|
|
6353
|
+
const skill = findSkill(tool._deps, skillKey);
|
|
6354
|
+
if (!skill) {
|
|
6355
|
+
return { error: `Unknown skill: ${skillKey}.` };
|
|
6356
|
+
}
|
|
6357
|
+
if (!ref.openedSkillKeys.includes(skillKey)) {
|
|
6358
|
+
return { error: `Call open_skill("${skillKey}") before binding its tools.` };
|
|
6359
|
+
}
|
|
6360
|
+
const capped = toolNames.slice(0, policy.maxBoundToolsPerSkill);
|
|
6361
|
+
const bound = await skill.bindTools(capped);
|
|
6362
|
+
const added = appendBoundTools(ref, bound, policy);
|
|
6363
|
+
if (added.length > 0) ref.__onToolsChanged?.();
|
|
6364
|
+
return {
|
|
6365
|
+
skillKey,
|
|
6366
|
+
boundTools: added.map((t) => t.name),
|
|
6367
|
+
requested: capped.length,
|
|
6368
|
+
truncated: toolNames.length > capped.length,
|
|
6369
|
+
...added.length > 0 ? { __runtimeToolsDelta: added } : {}
|
|
6370
|
+
};
|
|
6371
|
+
}
|
|
6372
|
+
});
|
|
6373
|
+
tool._deps = deps;
|
|
6374
|
+
tool.__source = "smart-skills";
|
|
6375
|
+
return tool;
|
|
6376
|
+
}
|
|
6377
|
+
function createSkillTools(deps) {
|
|
6378
|
+
return [createOpenSkillTool(deps), createBindSkillToolsTool(deps)];
|
|
6379
|
+
}
|
|
6380
|
+
|
|
6186
6381
|
// src/smart/index.ts
|
|
6187
6382
|
function createSmartAgent(opts) {
|
|
6188
6383
|
const resolved = normalizeSmartAgentOptions(opts);
|
|
@@ -6217,6 +6412,9 @@ function createSmartAgent(opts) {
|
|
|
6217
6412
|
if (askUserConfig) {
|
|
6218
6413
|
factoryToolsWithoutRecovery.push(createAskUserQuestionTool(factoryStateRef, askUserConfig));
|
|
6219
6414
|
}
|
|
6415
|
+
const skills = opts.skills ?? [];
|
|
6416
|
+
const skillPolicy = opts.skillPolicy ?? DEFAULT_SKILL_POLICY;
|
|
6417
|
+
const skillsEnabled = skills.length > 0;
|
|
6220
6418
|
const soManagerFactory = opts.outputSchema ? new StructuredOutputManager(opts.outputSchema, resolveStrategy(opts.model)) : void 0;
|
|
6221
6419
|
const modelCapabilities = opts.outputSchema ? getModelCapabilities(opts.model) : void 0;
|
|
6222
6420
|
const responseFinalizeTool = soManagerFactory && modelCapabilities?.structuredOutput !== "native" ? soManagerFactory.getResponseTool() : void 0;
|
|
@@ -6224,12 +6422,31 @@ function createSmartAgent(opts) {
|
|
|
6224
6422
|
const ref = { toolHistory: void 0, toolHistoryArchived: void 0, todoList: void 0, planVersion: 0, adherenceScore: 0 };
|
|
6225
6423
|
const ctxTools = createContextTools(ref, { planningEnabled, includeGetToolResponse: false });
|
|
6226
6424
|
const recoveryTool = createGetToolResponseTool(ref);
|
|
6227
|
-
const
|
|
6228
|
-
if (responseFinalizeTool)
|
|
6229
|
-
if (askUserConfig)
|
|
6230
|
-
|
|
6231
|
-
|
|
6232
|
-
|
|
6425
|
+
const coreBase = [...userTools, ...ctxTools];
|
|
6426
|
+
if (responseFinalizeTool) coreBase.push(responseFinalizeTool);
|
|
6427
|
+
if (askUserConfig) coreBase.push(createAskUserQuestionTool(ref, askUserConfig));
|
|
6428
|
+
if (!skillsEnabled) {
|
|
6429
|
+
const without = coreBase;
|
|
6430
|
+
const withRec = [...without, recoveryTool];
|
|
6431
|
+
return { stateRef: ref, toolsWithoutRecovery: without, toolsWithRecovery: withRec };
|
|
6432
|
+
}
|
|
6433
|
+
const toolSet = { stateRef: ref, toolsWithoutRecovery: [], toolsWithRecovery: [] };
|
|
6434
|
+
const skillRegistryRef = createSkillRegistryRef();
|
|
6435
|
+
const skillMetaTools = createSkillTools({ registryRef: skillRegistryRef, skills, policy: skillPolicy });
|
|
6436
|
+
const baseWithMeta = [...coreBase, ...skillMetaTools];
|
|
6437
|
+
const rebuild = () => {
|
|
6438
|
+
const composed = composeToolSets({
|
|
6439
|
+
base: baseWithMeta,
|
|
6440
|
+
boundSkillTools: skillRegistryRef.boundSkillTools,
|
|
6441
|
+
recoveryTool
|
|
6442
|
+
});
|
|
6443
|
+
toolSet.toolsWithoutRecovery = composed.toolsWithoutRecovery;
|
|
6444
|
+
toolSet.toolsWithRecovery = composed.toolsWithRecovery;
|
|
6445
|
+
};
|
|
6446
|
+
skillRegistryRef.__onToolsChanged = rebuild;
|
|
6447
|
+
toolSet.skillRegistryRef = skillRegistryRef;
|
|
6448
|
+
rebuild();
|
|
6449
|
+
return toolSet;
|
|
6233
6450
|
};
|
|
6234
6451
|
const base = createAgent({ ...runtimeOpts, tools: factoryToolsWithoutRecovery });
|
|
6235
6452
|
base.__runtime.runtimeProfile = resolved.runtimeProfile;
|
|
@@ -6280,9 +6497,9 @@ function createSmartAgent(opts) {
|
|
|
6280
6497
|
planVersion: ref.planVersion || state.planVersion || 1
|
|
6281
6498
|
};
|
|
6282
6499
|
}
|
|
6283
|
-
function systemMessage2() {
|
|
6500
|
+
function systemMessage2(extraBlock) {
|
|
6284
6501
|
const sys = buildSystemPrompt(
|
|
6285
|
-
[opts.systemPrompt, runtimeHint, structuredOutputHint].filter(Boolean).join("\n"),
|
|
6502
|
+
[opts.systemPrompt, runtimeHint, structuredOutputHint, extraBlock].filter(Boolean).join("\n"),
|
|
6286
6503
|
planningEnabled,
|
|
6287
6504
|
opts.name || "Agent",
|
|
6288
6505
|
opts.todoListPrompt
|
|
@@ -6332,8 +6549,10 @@ function createSmartAgent(opts) {
|
|
|
6332
6549
|
stateRef.planVersion = input.planVersion || input.plan?.version || 0;
|
|
6333
6550
|
stateRef.adherenceScore = input.plan?.adherenceScore || 0;
|
|
6334
6551
|
const syncPlanFromRef = (state2) => syncPlanStateWith(stateRef, state2);
|
|
6552
|
+
const availableSkills = skillsEnabled ? await resolveAvailableSkills(skills, { modelTier: skillPolicy.modelTier }) : [];
|
|
6553
|
+
const skillBlock = availableSkills.length > 0 ? buildSkillHeaderBlock(availableSkills) : void 0;
|
|
6335
6554
|
const alreadyHasSystem = Array.isArray(input.messages) && input.messages[0]?.role === "system";
|
|
6336
|
-
const seedMessages = alreadyHasSystem ? [...input.messages || []] : [systemMessage2(), ...input.messages || []];
|
|
6555
|
+
const seedMessages = alreadyHasSystem ? [...input.messages || []] : [systemMessage2(skillBlock), ...input.messages || []];
|
|
6337
6556
|
let state = syncRuntimeTools(await syncMemory({ ...input, messages: seedMessages }), seedMessages, toolSet);
|
|
6338
6557
|
let lastResult = null;
|
|
6339
6558
|
let rawMessages = [...seedMessages];
|
|
@@ -7599,7 +7818,7 @@ var AnthropicProvider = class extends BaseProvider {
|
|
|
7599
7818
|
const { system, messages } = this.splitSystemMessages(request.messages);
|
|
7600
7819
|
const body = {
|
|
7601
7820
|
model: request.model || this.defaultModel,
|
|
7602
|
-
messages:
|
|
7821
|
+
messages: this.toAnthropicMessages(messages),
|
|
7603
7822
|
max_tokens: request.maxTokens ?? 4096,
|
|
7604
7823
|
stream
|
|
7605
7824
|
};
|
|
@@ -7655,20 +7874,44 @@ var AnthropicProvider = class extends BaseProvider {
|
|
|
7655
7874
|
messages: rest
|
|
7656
7875
|
};
|
|
7657
7876
|
}
|
|
7658
|
-
|
|
7659
|
-
|
|
7660
|
-
|
|
7661
|
-
|
|
7662
|
-
|
|
7663
|
-
|
|
7664
|
-
|
|
7665
|
-
|
|
7666
|
-
|
|
7667
|
-
|
|
7668
|
-
|
|
7669
|
-
|
|
7670
|
-
|
|
7877
|
+
/**
|
|
7878
|
+
* Converts unified messages to Anthropic format, coalescing consecutive
|
|
7879
|
+
* tool-result messages into a single `user` turn.
|
|
7880
|
+
*
|
|
7881
|
+
* The unified message list carries one `role: "tool"` entry per tool call
|
|
7882
|
+
* (mirroring OpenAI's shape). Anthropic's Messages API expects every
|
|
7883
|
+
* `tool_result` block answering a single assistant turn's `tool_use`
|
|
7884
|
+
* block(s) to be batched into ONE `user` message rather than sent as
|
|
7885
|
+
* separate consecutive `user` messages.
|
|
7886
|
+
*/
|
|
7887
|
+
toAnthropicMessages(messages) {
|
|
7888
|
+
const result = [];
|
|
7889
|
+
let mergingToolResults = false;
|
|
7890
|
+
for (const m of messages) {
|
|
7891
|
+
if (m.role === "tool" && m.toolCallId) {
|
|
7892
|
+
const toolResult = this.toAnthropicToolResult(m);
|
|
7893
|
+
if (mergingToolResults) {
|
|
7894
|
+
result[result.length - 1].content.push(toolResult);
|
|
7895
|
+
} else {
|
|
7896
|
+
result.push({ role: "user", content: [toolResult] });
|
|
7897
|
+
mergingToolResults = true;
|
|
7898
|
+
}
|
|
7899
|
+
continue;
|
|
7900
|
+
}
|
|
7901
|
+
mergingToolResults = false;
|
|
7902
|
+
result.push(this.toAnthropicMessage(m));
|
|
7671
7903
|
}
|
|
7904
|
+
return result;
|
|
7905
|
+
}
|
|
7906
|
+
toAnthropicToolResult(m) {
|
|
7907
|
+
const content = typeof m.content === "string" ? m.content : JSON.stringify(m.content);
|
|
7908
|
+
return {
|
|
7909
|
+
type: "tool_result",
|
|
7910
|
+
tool_use_id: m.toolCallId,
|
|
7911
|
+
content
|
|
7912
|
+
};
|
|
7913
|
+
}
|
|
7914
|
+
toAnthropicMessage(m) {
|
|
7672
7915
|
if (m.role === "assistant" && m.toolCalls?.length) {
|
|
7673
7916
|
const content = [];
|
|
7674
7917
|
appendReasoningBlocks(content, m.reasoning?.blocks);
|
|
@@ -8053,7 +8296,7 @@ var BedrockProvider = class extends BaseProvider {
|
|
|
8053
8296
|
buildConverseBody(request) {
|
|
8054
8297
|
const { system, messages } = this.splitSystemMessages(request.messages);
|
|
8055
8298
|
const body = {
|
|
8056
|
-
messages:
|
|
8299
|
+
messages: this.toBedrockMessages(messages)
|
|
8057
8300
|
};
|
|
8058
8301
|
if (system.length > 0) {
|
|
8059
8302
|
const systemBlocks = system.map((s) => ({ text: s }));
|
|
@@ -8103,22 +8346,47 @@ var BedrockProvider = class extends BaseProvider {
|
|
|
8103
8346
|
}
|
|
8104
8347
|
return { system, messages: rest };
|
|
8105
8348
|
}
|
|
8106
|
-
|
|
8107
|
-
|
|
8108
|
-
|
|
8109
|
-
|
|
8110
|
-
|
|
8111
|
-
|
|
8112
|
-
|
|
8113
|
-
|
|
8114
|
-
|
|
8115
|
-
|
|
8116
|
-
|
|
8117
|
-
|
|
8118
|
-
|
|
8119
|
-
|
|
8120
|
-
|
|
8349
|
+
/**
|
|
8350
|
+
* Converts unified messages to Bedrock Converse format, coalescing
|
|
8351
|
+
* consecutive tool-result messages into a single `user` turn.
|
|
8352
|
+
*
|
|
8353
|
+
* The unified message list carries one `role: "tool"` entry per tool call
|
|
8354
|
+
* (mirroring OpenAI's shape). Bedrock's Converse API requires every
|
|
8355
|
+
* `toolResult` block answering a single assistant turn's `toolUse`
|
|
8356
|
+
* block(s) to be batched into ONE `user` message — sending them as
|
|
8357
|
+
* separate consecutive `user` messages triggers: "Expected toolResult
|
|
8358
|
+
* blocks at messages.N.content for the following Ids: ...".
|
|
8359
|
+
*/
|
|
8360
|
+
toBedrockMessages(messages) {
|
|
8361
|
+
const result = [];
|
|
8362
|
+
let mergingToolResults = false;
|
|
8363
|
+
for (const m of messages) {
|
|
8364
|
+
if (m.role === "tool" && m.toolCallId) {
|
|
8365
|
+
const toolResult = this.toBedrockToolResult(m);
|
|
8366
|
+
if (mergingToolResults) {
|
|
8367
|
+
result[result.length - 1].content.push(toolResult);
|
|
8368
|
+
} else {
|
|
8369
|
+
result.push({ role: "user", content: [toolResult] });
|
|
8370
|
+
mergingToolResults = true;
|
|
8371
|
+
}
|
|
8372
|
+
continue;
|
|
8373
|
+
}
|
|
8374
|
+
mergingToolResults = false;
|
|
8375
|
+
result.push(this.toBedrockMessage(m));
|
|
8121
8376
|
}
|
|
8377
|
+
return result;
|
|
8378
|
+
}
|
|
8379
|
+
toBedrockToolResult(m) {
|
|
8380
|
+
const text = typeof m.content === "string" ? m.content : JSON.stringify(m.content);
|
|
8381
|
+
return {
|
|
8382
|
+
toolResult: {
|
|
8383
|
+
toolUseId: m.toolCallId,
|
|
8384
|
+
content: [{ text }],
|
|
8385
|
+
status: "success"
|
|
8386
|
+
}
|
|
8387
|
+
};
|
|
8388
|
+
}
|
|
8389
|
+
toBedrockMessage(m) {
|
|
8122
8390
|
if (m.role === "assistant" && m.toolCalls?.length) {
|
|
8123
8391
|
const content2 = [];
|
|
8124
8392
|
appendBedrockReasoning(content2, m.reasoning?.blocks);
|
|
@@ -8424,12 +8692,24 @@ var VertexProvider = class extends BaseProvider {
|
|
|
8424
8692
|
buildContents(messages) {
|
|
8425
8693
|
const systemParts = [];
|
|
8426
8694
|
const contents = [];
|
|
8695
|
+
let mergingToolResults = false;
|
|
8427
8696
|
for (const m of messages) {
|
|
8428
8697
|
if (m.role === "system") {
|
|
8429
8698
|
const text = typeof m.content === "string" ? m.content : m.content.filter((p) => p.type === "text").map((p) => p.text).join("\n");
|
|
8430
8699
|
if (text) systemParts.push(text);
|
|
8431
8700
|
continue;
|
|
8432
8701
|
}
|
|
8702
|
+
if (m.role === "tool" && m.toolCallId) {
|
|
8703
|
+
const part = this.toGeminiFunctionResponsePart(m);
|
|
8704
|
+
if (mergingToolResults) {
|
|
8705
|
+
contents[contents.length - 1].parts.push(part);
|
|
8706
|
+
} else {
|
|
8707
|
+
contents.push({ role: "user", parts: [part] });
|
|
8708
|
+
mergingToolResults = true;
|
|
8709
|
+
}
|
|
8710
|
+
continue;
|
|
8711
|
+
}
|
|
8712
|
+
mergingToolResults = false;
|
|
8433
8713
|
contents.push(this.toGeminiContent(m));
|
|
8434
8714
|
}
|
|
8435
8715
|
return {
|
|
@@ -8437,27 +8717,22 @@ var VertexProvider = class extends BaseProvider {
|
|
|
8437
8717
|
contents
|
|
8438
8718
|
};
|
|
8439
8719
|
}
|
|
8440
|
-
|
|
8441
|
-
|
|
8442
|
-
|
|
8443
|
-
|
|
8444
|
-
|
|
8445
|
-
|
|
8446
|
-
|
|
8447
|
-
response = { result: text };
|
|
8448
|
-
}
|
|
8449
|
-
return {
|
|
8450
|
-
role: "user",
|
|
8451
|
-
parts: [
|
|
8452
|
-
{
|
|
8453
|
-
functionResponse: {
|
|
8454
|
-
name: m.name ?? m.toolCallId,
|
|
8455
|
-
response
|
|
8456
|
-
}
|
|
8457
|
-
}
|
|
8458
|
-
]
|
|
8459
|
-
};
|
|
8720
|
+
toGeminiFunctionResponsePart(m) {
|
|
8721
|
+
const text = typeof m.content === "string" ? m.content : JSON.stringify(m.content);
|
|
8722
|
+
let response;
|
|
8723
|
+
try {
|
|
8724
|
+
response = JSON.parse(text);
|
|
8725
|
+
} catch {
|
|
8726
|
+
response = { result: text };
|
|
8460
8727
|
}
|
|
8728
|
+
return {
|
|
8729
|
+
functionResponse: {
|
|
8730
|
+
name: m.name ?? m.toolCallId,
|
|
8731
|
+
response
|
|
8732
|
+
}
|
|
8733
|
+
};
|
|
8734
|
+
}
|
|
8735
|
+
toGeminiContent(m) {
|
|
8461
8736
|
if (m.role === "assistant" && m.toolCalls?.length) {
|
|
8462
8737
|
const parts2 = [];
|
|
8463
8738
|
if (typeof m.content === "string" && m.content) {
|
|
@@ -9114,6 +9389,6 @@ function createProvider(config) {
|
|
|
9114
9389
|
}
|
|
9115
9390
|
}
|
|
9116
9391
|
|
|
9117
|
-
export { AnthropicProvider, AzureProvider, BaseProvider, BedrockProvider, DEFAULT_PROFILE_CONFIGS, GuardrailPhase, InMemoryMemoryStore, NativeJsonSchemaStrategy, OpenAICompatibleProvider, OpenAIProvider, ProviderError, StructuredOutputManager, ToolBasedStrategy, VertexProvider, agentVerdictRule, buildSystemPrompt, captureSnapshot, codePresenceRule, cognipeerSink, countApproxTokens, countMessagesTokens, createAgent, createAgentNode, createAskUserQuestionTool, createCodeGuardrail, createContextSummarizeNode, createContextTools, createGetToolResponseTool, createGuardrail, createJsonGuardrail, createManageTodoTool, createProvider, createRegexGuardrail, createResolverNode, createSmartAgent, createTool, createToolLimitFinalizeNode, createToolsNode, customCallbackRule, customSink, defaultTokenCounter, emptyUsage, evaluateGuardrails, fileSink, formatZodError, fromLangchainModel, fromLangchainTools, fromNativeProvider, generateSpanId, generateTraceId, getModelCapabilities, getNestedValue, getResolvedSmartConfig, getTokenCounter, hasToolResponseRecoveryReference, httpSink, isSmartModel, jsonSchemaRule, normalizeSmartAgentOptions, otlpSink, readMemoryFacts, regexRule, resolveMemoryStore, resolveReasoning, resolveStrategy, resolveToolApprovalState, resolveUserQuestionState, restoreSnapshot, runSmartAgentEvalHarness, setTokenCounter, startStreamingSession, traceSessionToOtlp, validateReasoningConfig, withTools, writeSummaryFactsToMemory };
|
|
9392
|
+
export { AnthropicProvider, AzureProvider, BaseProvider, BedrockProvider, DEFAULT_PROFILE_CONFIGS, DEFAULT_SKILL_POLICY, GuardrailPhase, InMemoryMemoryStore, NativeJsonSchemaStrategy, OpenAICompatibleProvider, OpenAIProvider, ProviderError, SMALL_TIER_SKILL_POLICY, StructuredOutputManager, ToolBasedStrategy, VertexProvider, agentVerdictRule, appendBoundTools, buildSkillHeaderBlock, buildSystemPrompt, canOpenSkill, captureSnapshot, codePresenceRule, cognipeerSink, composeToolSets, countApproxTokens, countMessagesTokens, createAgent, createAgentNode, createAskUserQuestionTool, createBindSkillToolsTool, createCodeGuardrail, createContextSummarizeNode, createContextTools, createGetToolResponseTool, createGuardrail, createJsonGuardrail, createManageTodoTool, createOpenSkillTool, createProvider, createRegexGuardrail, createResolverNode, createSkillRegistryRef, createSkillTools, createSmartAgent, createTool, createToolLimitFinalizeNode, createToolsNode, customCallbackRule, customSink, dedupeToolsByName, defaultTokenCounter, emptyUsage, evaluateGuardrails, fileSink, formatZodError, fromLangchainModel, fromLangchainTools, fromNativeProvider, generateSpanId, generateTraceId, getModelCapabilities, getNestedValue, getResolvedSmartConfig, getTokenCounter, hasToolResponseRecoveryReference, httpSink, isSmartModel, jsonSchemaRule, normalizeSmartAgentOptions, otlpSink, readMemoryFacts, regexRule, resolveAvailableSkills, resolveMemoryStore, resolveReasoning, resolveStrategy, resolveToolApprovalState, resolveUserQuestionState, restoreSnapshot, runSmartAgentEvalHarness, setTokenCounter, startStreamingSession, traceSessionToOtlp, validateReasoningConfig, withTools, writeSummaryFactsToMemory };
|
|
9118
9393
|
//# sourceMappingURL=index.mjs.map
|
|
9119
9394
|
//# sourceMappingURL=index.mjs.map
|