@mappies/miniwat-provider-bedrock 0.12.0 → 0.13.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/dist/index.cjs +67 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +69 -13
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -83,13 +83,14 @@ var BedrockAdapter = class {
|
|
|
83
83
|
if ((m.content ?? "").trim().length > 0) {
|
|
84
84
|
content.push({ text: m.content });
|
|
85
85
|
} else if (m.toolUse?.length) {
|
|
86
|
-
|
|
86
|
+
const names = m.toolUse.map((t) => t.name).filter(Boolean).join(", ");
|
|
87
|
+
content.push({ text: names ? `Completed action: ${names}.` : "Completed an action." });
|
|
87
88
|
}
|
|
88
89
|
if (m.toolResult?.length) {
|
|
89
90
|
content.push(...m.toolResult.map((r) => ({
|
|
90
91
|
text: [
|
|
91
|
-
r.status ? "
|
|
92
|
-
this.toolResultToText(r.content)
|
|
92
|
+
r.status ? "Outcome: succeeded" : "Outcome: failed",
|
|
93
|
+
`Result: ${this.toolResultToText(r.content)}`
|
|
93
94
|
].join("\n")
|
|
94
95
|
})));
|
|
95
96
|
}
|
|
@@ -116,6 +117,12 @@ var BedrockAdapter = class {
|
|
|
116
117
|
}
|
|
117
118
|
static toolResultToText(content) {
|
|
118
119
|
const maxLength = 12e3;
|
|
120
|
+
const structured = (0, import_miniwat_agent_core2.readStructuredToolResult)(content);
|
|
121
|
+
if (structured) {
|
|
122
|
+
const text2 = structured.text;
|
|
123
|
+
return text2.length > maxLength ? `${text2.slice(0, maxLength)}
|
|
124
|
+
[Tool result truncated]` : text2;
|
|
125
|
+
}
|
|
119
126
|
const text = !Array.isArray(content) ? typeof content === "string" ? content : JSON.stringify(content) ?? String(content) : content.map((item) => {
|
|
120
127
|
if (typeof item?.text === "string") {
|
|
121
128
|
return item.text;
|
|
@@ -210,20 +217,42 @@ var BedrockModel = class {
|
|
|
210
217
|
}
|
|
211
218
|
async executeTools(toolUses, opts) {
|
|
212
219
|
const results = [];
|
|
220
|
+
let blocked = false;
|
|
221
|
+
let stop = false;
|
|
213
222
|
for (const toolUse of toolUses) {
|
|
223
|
+
const tool = await this.toolDispatcher.get(toolUse.name);
|
|
224
|
+
const sideEffecting = tool ? tool.readOnly !== true : true;
|
|
214
225
|
try {
|
|
215
|
-
const resultPromise = this.toolDispatcher.execute(toolUse.name, toolUse.input);
|
|
226
|
+
const resultPromise = this.toolDispatcher.execute(toolUse.name, toolUse.input, opts?.authorization);
|
|
216
227
|
if (opts?.onThinking && toolUse.name) {
|
|
217
228
|
const inputText = await this.toolDispatcher.getInputText(toolUse.name, toolUse.input);
|
|
218
229
|
if (inputText && opts.onThinking) await opts.onThinking(inputText);
|
|
219
230
|
}
|
|
220
231
|
const result = await resultPromise;
|
|
232
|
+
if ((0, import_miniwat_agent_core3.isToolAuthorizationBlock)(result)) {
|
|
233
|
+
blocked = true;
|
|
234
|
+
results.push({
|
|
235
|
+
toolUseId: toolUse.toolUseId,
|
|
236
|
+
content: BedrockAdapter.toToolResultContent(result.text, false),
|
|
237
|
+
status: false
|
|
238
|
+
});
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
const outcome = (0, import_miniwat_agent_core3.toExecutionStatus)(result);
|
|
242
|
+
const succeeded = outcome === "succeeded";
|
|
243
|
+
if (!succeeded && sideEffecting) {
|
|
244
|
+
stop = true;
|
|
245
|
+
}
|
|
221
246
|
results.push({
|
|
222
247
|
toolUseId: toolUse.toolUseId,
|
|
223
|
-
content: BedrockAdapter.toToolResultContent(result,
|
|
224
|
-
status:
|
|
248
|
+
content: BedrockAdapter.toToolResultContent((0, import_miniwat_agent_core3.toVerdictText)(result), succeeded),
|
|
249
|
+
status: succeeded,
|
|
250
|
+
outcome
|
|
225
251
|
});
|
|
226
252
|
} catch (err) {
|
|
253
|
+
if (sideEffecting) {
|
|
254
|
+
stop = true;
|
|
255
|
+
}
|
|
227
256
|
results.push({
|
|
228
257
|
toolUseId: toolUse.toolUseId,
|
|
229
258
|
content: BedrockAdapter.toToolResultContent(err, false),
|
|
@@ -231,7 +260,7 @@ var BedrockModel = class {
|
|
|
231
260
|
});
|
|
232
261
|
}
|
|
233
262
|
}
|
|
234
|
-
return results;
|
|
263
|
+
return { results, blocked, stop };
|
|
235
264
|
}
|
|
236
265
|
async runConversationLoop(messages, inference, options, instruction) {
|
|
237
266
|
let currentMessages = [...messages];
|
|
@@ -272,6 +301,19 @@ var BedrockModel = class {
|
|
|
272
301
|
topP: inference?.topP
|
|
273
302
|
}
|
|
274
303
|
};
|
|
304
|
+
if (process.env.MINIWAT_TRACE_REQUEST) {
|
|
305
|
+
console.log("[miniwat-trace-request]", JSON.stringify({
|
|
306
|
+
iteration: iterations,
|
|
307
|
+
canUseTools,
|
|
308
|
+
flattenToolHistory: !canUseTools,
|
|
309
|
+
toolsOffered: canUseTools,
|
|
310
|
+
systemPrompt,
|
|
311
|
+
messages: brMessages.map((m) => ({
|
|
312
|
+
role: m.role,
|
|
313
|
+
content: (m.content ?? []).map((c) => c?.text !== void 0 ? { text: c.text } : c?.toolUse !== void 0 ? { toolUse: c.toolUse?.name } : c?.toolResult !== void 0 ? { toolResult: true } : { other: Object.keys(c ?? {}) })
|
|
314
|
+
}))
|
|
315
|
+
}, null, 2));
|
|
316
|
+
}
|
|
275
317
|
if (this.guardrailConfig) {
|
|
276
318
|
converseCommandInput.guardrailConfig = this.guardrailConfig;
|
|
277
319
|
}
|
|
@@ -338,12 +380,18 @@ var BedrockModel = class {
|
|
|
338
380
|
if (options?.onTooling) {
|
|
339
381
|
await options.onTooling(toolUseMessage);
|
|
340
382
|
}
|
|
341
|
-
const toolResults = await this.executeTools(toolUses, options);
|
|
383
|
+
const { results: toolResults, blocked, stop } = await this.executeTools(toolUses, options);
|
|
342
384
|
const toolResultMessage = BedrockMessage.toToolResultMessage(toolResults);
|
|
343
385
|
currentMessages.push(toolResultMessage);
|
|
344
386
|
if (options?.onTooling) {
|
|
345
387
|
await options.onTooling(toolResultMessage);
|
|
346
388
|
}
|
|
389
|
+
if (blocked || stop) {
|
|
390
|
+
return {
|
|
391
|
+
message: BedrockMessage.toAssistantMessage(assistantText),
|
|
392
|
+
stopReason: "tool_use"
|
|
393
|
+
};
|
|
394
|
+
}
|
|
347
395
|
break;
|
|
348
396
|
}
|
|
349
397
|
if (typeof reason === "string") {
|
|
@@ -381,12 +429,18 @@ var BedrockModel = class {
|
|
|
381
429
|
if (options?.onTooling) {
|
|
382
430
|
await options.onTooling(toolUseMessage);
|
|
383
431
|
}
|
|
384
|
-
const toolResults = await this.executeTools(toolUses, options);
|
|
432
|
+
const { results: toolResults, blocked, stop } = await this.executeTools(toolUses, options);
|
|
385
433
|
const toolResultMessage = BedrockMessage.toToolResultMessage(toolResults);
|
|
386
434
|
currentMessages.push(toolResultMessage);
|
|
387
435
|
if (options?.onTooling) {
|
|
388
436
|
await options.onTooling(toolResultMessage);
|
|
389
437
|
}
|
|
438
|
+
if (blocked || stop) {
|
|
439
|
+
return {
|
|
440
|
+
message: BedrockMessage.toAssistantMessage(text),
|
|
441
|
+
stopReason: res.stopReason
|
|
442
|
+
};
|
|
443
|
+
}
|
|
390
444
|
continue;
|
|
391
445
|
}
|
|
392
446
|
const msg = BedrockMessage.toAssistantMessage(text);
|
|
@@ -408,7 +462,8 @@ var BedrockModel = class {
|
|
|
408
462
|
onTooling: option?.event?.onTooling,
|
|
409
463
|
maxToolCalls: option?.maxToolCalls,
|
|
410
464
|
toolsEnabled: option?.toolsEnabled,
|
|
411
|
-
allowedTools: option?.allowedTools
|
|
465
|
+
allowedTools: option?.allowedTools,
|
|
466
|
+
authorization: option?.authorization
|
|
412
467
|
},
|
|
413
468
|
option?.instruction
|
|
414
469
|
);
|
|
@@ -432,7 +487,8 @@ var BedrockModel = class {
|
|
|
432
487
|
onTooling: option?.event?.onTooling,
|
|
433
488
|
maxToolCalls: option?.maxToolCalls,
|
|
434
489
|
toolsEnabled: option?.toolsEnabled,
|
|
435
|
-
allowedTools: option?.allowedTools
|
|
490
|
+
allowedTools: option?.allowedTools,
|
|
491
|
+
authorization: option?.authorization
|
|
436
492
|
},
|
|
437
493
|
option?.instruction
|
|
438
494
|
);
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/bedrockModel.ts","../src/bedrockMessage.ts","../src/bedrockAdapter.ts"],"sourcesContent":["export { BedrockModel } from './bedrockModel';","import { PassThrough, Readable } from \"stream\";\nimport { ResponseMessage, Message, InferenceOptions, ToolUse, ToolResult, Model, ModelOption, resolveInstructionValue, Instruction } from '@mappies/miniwat-agent-core'\nimport { McpConfig, ToolDispatcher } from '@mappies/miniwat-mcp-core'\nimport BedrockMessage from \"./bedrockMessage\";\nimport { BedrockRuntimeClient, ConverseCommand, ConverseStreamCommand, Message as BrMessage, StopReason, BedrockRuntimeClientConfig, ConverseStreamCommandInput, GuardrailConfiguration } from \"@aws-sdk/client-bedrock-runtime\";\nimport { BedrockAdapter } from \"./bedrockAdapter\";\n\nexport class BedrockModel implements Model\n{\n private modelId: string;\n private toolDispatcher: ToolDispatcher;\n private client: BedrockRuntimeClient;\n private guardrailConfig?: GuardrailConfiguration;\n\n constructor(options: { region?: string; modelId: string; mcpConfig?:McpConfig, clientConfig?: BedrockRuntimeClientConfig; guardrailConfig?: { guardrailIdentifier: string; guardrailVersion?: string; }; })\n {\n this.toolDispatcher = new ToolDispatcher(options?.mcpConfig);\n this.modelId = options.modelId;\n\n if (options?.guardrailConfig?.guardrailIdentifier)\n {\n this.guardrailConfig = {\n guardrailIdentifier: options.guardrailConfig.guardrailIdentifier,\n guardrailVersion: options.guardrailConfig.guardrailVersion\n };\n }\n\n this.client = new BedrockRuntimeClient({\n region: options?.region ?? process.env.DEFAULT_AWS_REGION ?? process.env.AWS_REGION,\n ...options?.clientConfig\n });\n }\n\n private async streamBufferedText(chunks: string[], write: (chunk: string) => void)\n {\n for(const chunk of chunks)\n {\n write(chunk);\n await new Promise(r => setTimeout(r, 8 + Math.random() * 12));\n }\n }\n\n private extractAssistantText(res: any, messages: BrMessage[]): string\n {\n const content = res?.output?.message?.content ?? [];\n let text = content.map((c: any) => c.text ?? \"\").join(\"\");\n\n if(!text)\n {\n text = BedrockAdapter.getResponseFromStopReasonWhenResponseIsEmpty(res.stopReason);\n }\n\n return text;\n }\n\n private async executeTools(toolUses: ToolUse[], opts?: any): Promise<ToolResult[]>\n {\n const results: ToolResult[] = [];\n\n for(const toolUse of toolUses)\n {\n try\n {\n const resultPromise = this.toolDispatcher.execute(toolUse.name, toolUse.input);\n\n // Show a thinking message for the tool\n if (opts?.onThinking && toolUse.name)\n {\n const inputText = await this.toolDispatcher.getInputText(toolUse.name, toolUse.input);\n if(inputText && opts.onThinking) await opts.onThinking(inputText);\n }\n\n const result = await resultPromise;\n\n results.push({\n toolUseId: toolUse.toolUseId,\n content: BedrockAdapter.toToolResultContent(result, true),\n status: true\n });\n }\n catch(err: any)\n {\n results.push({\n toolUseId: toolUse.toolUseId,\n content: BedrockAdapter.toToolResultContent(err, false),\n status: false\n });\n }\n }\n\n return results;\n }\n\n private async runConversationLoop(messages: Message[],\n inference?: InferenceOptions,\n options?: { streaming?: boolean;\n onChunk?: (chunk: string) => void,\n onThinking?: (msg: string) => Promise<void>,\n onTooling?: (msg: Message) => Promise<void>,\n maxToolCalls?: number,\n toolsEnabled?: boolean,\n allowedTools?: string[]\n },\n instruction?: Instruction): Promise<{ message: Message; stopReason?: StopReason; usage?: any }>\n {\n let currentMessages = [...messages];\n let iterations = 0;\n\n const toolsEnabled = options?.toolsEnabled ?? true;\n const maxToolCalls = toolsEnabled ? Math.max(0, options?.maxToolCalls ?? 3) : 0;\n const maxIterations = 20;\n let toolCalls = 0;\n\n while(true)\n {\n if (++iterations > maxIterations)\n {\n throw new Error(\"Too many conversation iterations\");\n }\n\n const remainingToolCalls = Math.max(0, maxToolCalls - toolCalls);\n const canUseTools = toolsEnabled && remainingToolCalls > 0 && iterations < maxIterations;\n\n const brMessages = BedrockAdapter.toBedrockMessages(currentMessages, !canUseTools);\n\n let systemPrompt = await resolveInstructionValue(instruction?.system?.value, undefined);\n\n if (!canUseTools && toolCalls > 0)\n {\n systemPrompt = [\n systemPrompt,\n [\n \"You have reached the tool-use limit.\",\n \"Tool use is no longer available.\",\n \"Do not output tool calls, function-call syntax, tool-call markup, or special tokens such as <|tool_calls_section_begin|>.\",\n \"Do not request or suggest performing additional searches.\",\n \"Do not say that you will search for more information.\",\n \"Use only the information already available in the conversation and the tool results above.\",\n \"Complete the CURRENT TASK using the available information.\"\n ].join(\" \")\n ]\n .filter(Boolean)\n .join(\"\\n\\n\");\n }\n\n const converseCommandInput:ConverseStreamCommandInput = {\n modelId: this.modelId,\n messages: brMessages,\n system: systemPrompt ? [{ text: systemPrompt }] : undefined,\n inferenceConfig: {\n temperature: inference?.temperature,\n maxTokens: inference?.maxTokens,\n topP: inference?.topP\n }\n }\n\n if (this.guardrailConfig)\n {\n converseCommandInput.guardrailConfig = this.guardrailConfig;\n }\n\n const allowed = options?.allowedTools;\n const tools = canUseTools\n ? (await this.toolDispatcher.list())\n .filter(tool => allowed === undefined || (tool.name !== undefined && allowed.includes(tool.name)))\n .map(BedrockAdapter.toBedrockTool)\n : [];\n\n if(tools.length > 0)\n {\n converseCommandInput.toolConfig = { tools }\n }\n\n if (options?.streaming)\n {\n const res = await this.client.send(new ConverseStreamCommand(converseCommandInput));\n\n let chunks: string[] = [];\n let streamingStarted = false;\n let toolUses: ToolUse[] = [];\n let currentToolUse: ToolUse | undefined;\n let assistantText = '';\n\n for await (const event of res.stream ?? [])\n {\n\n if (event.modelStreamErrorException)\n {\n throw new Error(event.modelStreamErrorException?.message ?? \"Model stream error\");\n }\n\n if (event.contentBlockDelta?.delta?.text)\n {\n const chunk = event.contentBlockDelta.delta.text;\n assistantText += chunk;\n\n if (!streamingStarted)\n {\n chunks.push(chunk);\n\n if (chunks.length > 20)\n {\n streamingStarted = true;\n await this.streamBufferedText(chunks, options.onChunk!);\n chunks = [];\n }\n }\n else\n {\n options.onChunk?.(chunk);\n }\n }\n\n if (event.contentBlockStart?.start?.toolUse)\n {\n currentToolUse = {\n toolUseId: event.contentBlockStart.start.toolUse.toolUseId as string,\n name: event.contentBlockStart.start.toolUse.name as string,\n inputBuffer: \"\"\n };\n toolUses.push(currentToolUse);\n }\n\n if (currentToolUse && event.contentBlockDelta?.delta?.toolUse?.input)\n {\n currentToolUse.inputBuffer += event.contentBlockDelta.delta.toolUse.input;\n }\n\n if (event.contentBlockStop && currentToolUse?.inputBuffer)\n {\n try\n {\n currentToolUse.input = JSON.parse(currentToolUse.inputBuffer);\n }\n catch (error)\n {\n throw new Error(`Invalid arguments for tool \"${currentToolUse.name}\": ${currentToolUse.inputBuffer}.`);\n }\n\n delete currentToolUse.inputBuffer;\n currentToolUse = undefined;\n }\n\n if (event.messageStop)\n {\n const reason = event.messageStop.stopReason;\n\n if (reason === \"tool_use\")\n {\n\n if (!streamingStarted && chunks.length > 0)\n {\n await options.onThinking?.(chunks.join(\"\"));\n chunks = [];\n }\n\n toolCalls += toolUses.length;\n\n const toolUseMessage = BedrockMessage.toToolUseMessage(assistantText, toolUses);\n currentMessages.push(toolUseMessage);\n if(options?.onTooling) { await options.onTooling(toolUseMessage)}\n\n const toolResults = await this.executeTools(toolUses, options);\n\n const toolResultMessage = BedrockMessage.toToolResultMessage(toolResults);\n currentMessages.push(toolResultMessage);\n if(options?.onTooling) { await options.onTooling(toolResultMessage)}\n\n break;\n }\n\n if (typeof reason === \"string\")\n {\n if (/content|filter|guardrail/i.test(reason))\n {\n throw new Error(\"Output blocked by content filtering policy: \" + reason);\n }\n else if (reason === \"max_tokens\")\n {\n options.onChunk?.(BedrockAdapter.getResponseFromStopReasonWhenResponseIsEmpty(reason));\n }\n else if (!streamingStarted)\n {\n if (chunks.length > 0)\n {\n await this.streamBufferedText(chunks, options.onChunk!);\n } else\n {\n options.onChunk?.(BedrockAdapter.getResponseFromStopReasonWhenResponseIsEmpty(reason));\n }\n }\n }\n\n return {\n message: BedrockMessage.toAssistantMessage(assistantText),\n stopReason: reason\n };\n }\n }\n }\n else\n {\n const res = await this.client.send(new ConverseCommand(converseCommandInput));\n const text = this.extractAssistantText(res, brMessages);\n\n const content = res?.output?.message?.content ?? [];\n\n if (res.stopReason === \"tool_use\")\n {\n const toolUses = content.filter((c: any) => c.toolUse)\n .map((c: any) => ({\n toolUseId: c.toolUse.toolUseId,\n name: c.toolUse.name,\n input: c.toolUse.input\n }));\n\n toolCalls += toolUses.length;\n\n const toolUseMessage = BedrockMessage.toToolUseMessage(text, toolUses);\n currentMessages.push(toolUseMessage);\n if(options?.onTooling) { await options.onTooling(toolUseMessage)}\n\n const toolResults = await this.executeTools(toolUses, options);\n\n const toolResultMessage = BedrockMessage.toToolResultMessage(toolResults);\n currentMessages.push(toolResultMessage);\n if(options?.onTooling) { await options.onTooling(toolResultMessage)}\n\n continue;\n }\n\n const msg = BedrockMessage.toAssistantMessage(text);\n\n return {\n message: msg,\n stopReason: res.stopReason,\n usage: res.usage\n };\n }\n }\n }\n\n async invoke(messages: Message[], option?: ModelOption): Promise<ResponseMessage>\n {\n const response = await this.runConversationLoop(messages, option?.inference, {\n streaming: false,\n onThinking: option?.event?.onThinking,\n onTooling: option?.event?.onTooling,\n maxToolCalls: option?.maxToolCalls,\n toolsEnabled: option?.toolsEnabled,\n allowedTools: option?.allowedTools\n },\n option?.instruction);\n\n return new ResponseMessage({\n stopReason: response.stopReason as StopReason,\n tokenUsage: response.usage,\n message: response.message\n });\n }\n\n async stream(messages: Message[], option?: ModelOption): Promise<Readable>\n {\n const out = new PassThrough({ encoding: \"utf8\" });\n\n (async () =>\n {\n try\n {\n await this.runConversationLoop(messages, option?.inference, {\n streaming: true,\n onChunk: c => out.write(c),\n onThinking: option?.event?.onThinking,\n onTooling: option?.event?.onTooling,\n maxToolCalls: option?.maxToolCalls,\n toolsEnabled: option?.toolsEnabled,\n allowedTools: option?.allowedTools\n },\n option?.instruction);\n\n out.write('');\n out.end();\n }\n catch (e)\n {\n out.emit(\"throw\", e);\n out.write('');\n out.end();\n }\n })();\n\n return out;\n }\n}","import { MessageType, Message, ToolUse, ToolResult } from '@mappies/miniwat-agent-core'\n\nexport default class BedrockMessage extends Message\n{\n constructor(data:Partial<Message>)\n {\n super(data)\n }\n \n public static toAssistantMessage(text: string): Message\n {\n return new Message({\n type: MessageType.Agent,\n content: text,\n createdTimestamp: new Date().toISOString(),\n });\n }\n \n public static toToolUseMessage(text:string, toolUses: ToolUse[]): Message\n {\n return new Message({\n type: MessageType.Agent,\n content: text,\n createdTimestamp: new Date().toISOString(),\n toolUse: toolUses.map(({ toolUseId, name, input }) => (<ToolUse>{ toolUseId, name, input })),\n });\n }\n \n public static toToolResultMessage(toolResult: ToolResult[]): Message\n {\n return new Message({\n type: MessageType.ToolResult,\n toolResult\n });\n }\n}","import { MessageType, Message, Tool } from '@mappies/miniwat-agent-core'\nimport { Message as BrMessage, StopReason, Tool as BedrockTool } from \"@aws-sdk/client-bedrock-runtime\";\n\nexport class BedrockAdapter\n{\n static toBedrockTool(tool: Tool): BedrockTool\n {\n return {\n toolSpec: {\n name: tool.name,\n description: tool.description,\n inputSchema: { json: tool.schema } as any\n }\n };\n }\n\n static toBedrockMessages(history: Message[], flattenToolHistory = false): BrMessage[]\n {\n return history\n .filter(m =>\n (m.content ?? \"\").trim().length > 0 ||\n (m.toolUse?.length ?? 0) > 0 ||\n (m.toolResult?.length ?? 0) > 0\n )\n .map(m =>\n {\n const role = m.type === MessageType.User || m.type === MessageType.ToolResult\n ? \"user\"\n : \"assistant\";\n\n const content: any[] = [];\n\n if (flattenToolHistory)\n {\n if ((m.content ?? \"\").trim().length > 0)\n {\n content.push({ text: m.content });\n }\n else if (m.toolUse?.length)\n {\n content.push({ text: \"I used the available tools to gather information.\" });\n }\n\n if (m.toolResult?.length)\n {\n content.push(...m.toolResult.map(r => ({\n text: [\n r.status ? \"Tool result:\" : \"Tool result (failed):\",\n this.toolResultToText(r.content)\n ].join(\"\\n\")\n })));\n }\n }\n else\n {\n if (m.toolUse?.length)\n {\n content.push(...m.toolUse.map(t => ({ toolUse: t })));\n }\n else if ((m.content ?? \"\").trim().length > 0)\n {\n content.push({ text: m.content });\n }\n\n if (m.toolResult?.length)\n {\n content.push(...m.toolResult.map(r => ({\n toolResult: {\n ...r,\n status: r.status ? \"success\" : \"error\"\n }\n })));\n }\n }\n\n if (content.length === 0)\n {\n content.push({ text: \"\" });\n }\n\n return { role, content };\n });\n }\n\n private static toolResultToText(content: unknown): string\n {\n const maxLength = 12000;\n\n const text = !Array.isArray(content)\n ? (typeof content === \"string\" ? content : (JSON.stringify(content) ?? String(content)))\n : content\n .map((item: any) =>\n {\n if (typeof item?.text === \"string\")\n {\n return item.text;\n }\n\n if (item?.json !== undefined)\n {\n return JSON.stringify(item.json);\n }\n\n return JSON.stringify(item);\n })\n .filter(Boolean)\n .join(\"\\n\");\n\n return text.length > maxLength\n ? `${text.slice(0, maxLength)}\\n[Tool result truncated]`\n : text;\n }\n\n static toToolResultContent(result: unknown, status = true): { text?: string; json?: object }[]\n {\n const emptyResultText = status\n ? \"The tool completed successfully but returned no results.\"\n : \"The tool failed and returned no additional error details.\";\n\n try\n {\n if(result instanceof Error)\n {\n const message = result.message.trim();\n return [{ text: message.length > 0 ? message : emptyResultText }];\n }\n\n if(result === null || result === undefined || (typeof result === \"string\" && result.trim().length === 0))\n {\n return [{ text: emptyResultText }];\n }\n\n if(typeof result === \"object\")\n {\n let json = JSON.parse(JSON.stringify(result));\n\n if(Array.isArray(json))\n {\n json = { result: json };\n }\n\n return [{ json }];\n }\n\n return [{ text: String(result) }];\n }\n catch (e: unknown)\n {\n const message = e instanceof Error ? e.message : String(e);\n\n return [{\n json: {\n error: \"Failed to serialize tool result\",\n message\n }\n }];\n }\n }\n\n static getResponseFromStopReasonWhenResponseIsEmpty(stopReason: StopReason): string\n {\n switch (stopReason)\n {\n case \"max_tokens\":\n return \"My response was cut off due to length limits. Would you like me to continue or summarize the remaining information?\";\n case \"stop_sequence\":\n return \"I've reached a natural stopping point in my response. Please let me know if you need additional information.\";\n case \"guardrail_intervened\":\n return \"I'm unable to provide a response to this request as it doesn't align with my usage guidelines. Please rephrase your question or ask something else.\";\n case \"content_filtered\":\n return \"I cannot generate a response for this request due to content policy restrictions. Please try rephrasing your question.\";\n case \"model_context_window_exceeded\":\n return \"The conversation or request is too long for me to process. Please try with a shorter input or start a new conversation.\";\n case \"end_turn\":\n return \"What can I help with?\";\n case \"tool_use\":\n return \"\";\n default:\n return \"I couldn't complete the response. Please try again.\";\n }\n }\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAsC;AACtC,IAAAA,6BAA0I;AAC1I,8BAA0C;;;ACF1C,gCAA0D;AAE1D,IAAqB,iBAArB,cAA4C,kCAC5C;AAAA,EACI,YAAY,MACZ;AACI,UAAM,IAAI;AAAA,EACd;AAAA,EAEA,OAAc,mBAAmB,MACjC;AACI,WAAO,IAAI,kCAAQ;AAAA,MACf,MAAM,sCAAY;AAAA,MAClB,SAAS;AAAA,MACT,mBAAkB,oBAAI,KAAK,GAAE,YAAY;AAAA,IAC7C,CAAC;AAAA,EACL;AAAA,EAEA,OAAc,iBAAiB,MAAa,UAC5C;AACI,WAAO,IAAI,kCAAQ;AAAA,MACX,MAAM,sCAAY;AAAA,MAClB,SAAS;AAAA,MACT,mBAAkB,oBAAI,KAAK,GAAE,YAAY;AAAA,MACzC,SAAS,SAAS,IAAI,CAAC,EAAE,WAAW,MAAM,MAAM,OAAgB,EAAE,WAAW,MAAM,MAAM,EAAE;AAAA,IACnG,CAAC;AAAA,EACL;AAAA,EAEA,OAAc,oBAAoB,YAClC;AACI,WAAO,IAAI,kCAAQ;AAAA,MACf,MAAM,sCAAY;AAAA,MAClB;AAAA,IACJ,CAAC;AAAA,EACL;AACJ;;;AD/BA,oCAA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qB,QAClC;AACI,UAAM,MAAM,IAAI,0BAAY,EAAE,UAAU,OAAO,CAAC;AAEhD,KAAC,YACD;AACI,UACA;AACI,cAAM,KAAK;AAAA,UAAoB;AAAA,UAAU,QAAQ;AAAA,UAAW;AAAA,YACxD,WAAW;AAAA,YACX,SAAS,OAAK,IAAI,MAAM,CAAC;AAAA,YACzB,YAAY,QAAQ,OAAO;AAAA,YAC3B,WAAW,QAAQ,OAAO;AAAA,YAC1B,cAAc,QAAQ;AAAA,YACtB,cAAc,QAAQ;AAAA,YACtB,cAAc,QAAQ;AAAA,UAC1B;AAAA,UACA,QAAQ;AAAA,QAAW;AAEnB,YAAI,MAAM,EAAE;AACZ,YAAI,IAAI;AAAA,MACZ,SACO,GACP;AACI,YAAI,KAAK,SAAS,CAAC;AACnB,YAAI,MAAM,EAAE;AACZ,YAAI,IAAI;AAAA,MACZ;AAAA,IACJ,GAAG;AAEH,WAAO;AAAA,EACX;AACJ;","names":["import_miniwat_agent_core","import_miniwat_agent_core"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/bedrockModel.ts","../src/bedrockMessage.ts","../src/bedrockAdapter.ts"],"sourcesContent":["export { BedrockModel } from './bedrockModel';","import { PassThrough, Readable } from \"stream\";\nimport { ResponseMessage, Message, InferenceOptions, ToolUse, ToolResult, Model, ModelOption, ToolAuthorizationOptions, isToolAuthorizationBlock, toExecutionStatus, toVerdictText, resolveInstructionValue, Instruction } from '@mappies/miniwat-agent-core'\nimport { McpConfig, ToolDispatcher } from '@mappies/miniwat-mcp-core'\nimport BedrockMessage from \"./bedrockMessage\";\nimport { BedrockRuntimeClient, ConverseCommand, ConverseStreamCommand, Message as BrMessage, StopReason, BedrockRuntimeClientConfig, ConverseStreamCommandInput, GuardrailConfiguration } from \"@aws-sdk/client-bedrock-runtime\";\nimport { BedrockAdapter } from \"./bedrockAdapter\";\n\nexport class BedrockModel implements Model\n{\n private modelId: string;\n private toolDispatcher: ToolDispatcher;\n private client: BedrockRuntimeClient;\n private guardrailConfig?: GuardrailConfiguration;\n\n constructor(options: { region?: string; modelId: string; mcpConfig?:McpConfig, clientConfig?: BedrockRuntimeClientConfig; guardrailConfig?: { guardrailIdentifier: string; guardrailVersion?: string; }; })\n {\n this.toolDispatcher = new ToolDispatcher(options?.mcpConfig);\n this.modelId = options.modelId;\n\n if (options?.guardrailConfig?.guardrailIdentifier)\n {\n this.guardrailConfig = {\n guardrailIdentifier: options.guardrailConfig.guardrailIdentifier,\n guardrailVersion: options.guardrailConfig.guardrailVersion\n };\n }\n\n this.client = new BedrockRuntimeClient({\n region: options?.region ?? process.env.DEFAULT_AWS_REGION ?? process.env.AWS_REGION,\n ...options?.clientConfig\n });\n }\n\n private async streamBufferedText(chunks: string[], write: (chunk: string) => void)\n {\n for(const chunk of chunks)\n {\n write(chunk);\n await new Promise(r => setTimeout(r, 8 + Math.random() * 12));\n }\n }\n\n private extractAssistantText(res: any, messages: BrMessage[]): string\n {\n const content = res?.output?.message?.content ?? [];\n let text = content.map((c: any) => c.text ?? \"\").join(\"\");\n\n if(!text)\n {\n text = BedrockAdapter.getResponseFromStopReasonWhenResponseIsEmpty(res.stopReason);\n }\n\n return text;\n }\n\n private async executeTools(toolUses: ToolUse[], opts?: any): Promise<{ results: ToolResult[]; blocked: boolean; stop: boolean }>\n {\n const results: ToolResult[] = [];\n let blocked = false;\n let stop = false;\n\n for(const toolUse of toolUses)\n {\n // A side-effecting tool must NOT be auto-retried after a failed/uncertain execution: the\n // effect may have partially happened, so re-calling risks a duplicate. Resolve the tool's\n // read-only nature (unknown ⇒ treat as side-effecting) so a failure stops the turn's tool\n // loop rather than letting the model re-propose the same call within this invocation.\n const tool = await this.toolDispatcher.get(toolUse.name);\n const sideEffecting = tool ? tool.readOnly !== true : true;\n\n try\n {\n const resultPromise = this.toolDispatcher.execute(toolUse.name, toolUse.input, opts?.authorization);\n\n // Show a thinking message for the tool\n if (opts?.onThinking && toolUse.name)\n {\n const inputText = await this.toolDispatcher.getInputText(toolUse.name, toolUse.input);\n if(inputText && opts.onThinking) await opts.onThinking(inputText);\n }\n\n const result = await resultPromise;\n\n // Dispatch-boundary authorization blocked this call (defer/deny). The model sees the\n // structured block text as a failed tool result, and the turn's tool loop stops so a\n // deferred side effect is not retried.\n if(isToolAuthorizationBlock(result))\n {\n blocked = true;\n\n results.push({\n toolUseId: toolUse.toolUseId,\n content: BedrockAdapter.toToolResultContent(result.text, false),\n status: false\n });\n\n continue;\n }\n\n // Use the output guardrail's verdict to determine whether the tool succeeded.\n // Save the outcome so the execution ledger knows if it succeeded, failed, or is unknown.\n // If a side-effecting tool did not succeed, stop the tool loop to avoid retrying\n // an operation that may have already executed.\n const outcome = toExecutionStatus(result);\n const succeeded = outcome === \"succeeded\";\n\n if(!succeeded && sideEffecting)\n {\n stop = true;\n }\n\n results.push({\n toolUseId: toolUse.toolUseId,\n content: BedrockAdapter.toToolResultContent(toVerdictText(result), succeeded),\n status: succeeded,\n outcome\n });\n }\n catch(err: any)\n {\n // A side-effecting tool failed: stop the loop so it is not re-attempted this turn.\n if(sideEffecting)\n {\n stop = true;\n }\n\n results.push({\n toolUseId: toolUse.toolUseId,\n content: BedrockAdapter.toToolResultContent(err, false),\n status: false\n });\n }\n }\n\n return { results, blocked, stop };\n }\n\n private async runConversationLoop(messages: Message[],\n inference?: InferenceOptions,\n options?: { streaming?: boolean;\n onChunk?: (chunk: string) => void,\n onThinking?: (msg: string) => Promise<void>,\n onTooling?: (msg: Message) => Promise<void>,\n maxToolCalls?: number,\n toolsEnabled?: boolean,\n allowedTools?: string[],\n authorization?: ToolAuthorizationOptions\n },\n instruction?: Instruction): Promise<{ message: Message; stopReason?: StopReason; usage?: any }>\n {\n let currentMessages = [...messages];\n let iterations = 0;\n\n const toolsEnabled = options?.toolsEnabled ?? true;\n const maxToolCalls = toolsEnabled ? Math.max(0, options?.maxToolCalls ?? 3) : 0;\n const maxIterations = 20;\n let toolCalls = 0;\n\n while(true)\n {\n if (++iterations > maxIterations)\n {\n throw new Error(\"Too many conversation iterations\");\n }\n\n const remainingToolCalls = Math.max(0, maxToolCalls - toolCalls);\n const canUseTools = toolsEnabled && remainingToolCalls > 0 && iterations < maxIterations;\n\n const brMessages = BedrockAdapter.toBedrockMessages(currentMessages, !canUseTools);\n\n let systemPrompt = await resolveInstructionValue(instruction?.system?.value, undefined);\n\n if (!canUseTools && toolCalls > 0)\n {\n systemPrompt = [\n systemPrompt,\n [\n \"You have reached the tool-use limit.\",\n \"Tool use is no longer available.\",\n \"Do not output tool calls, function-call syntax, tool-call markup, or special tokens such as <|tool_calls_section_begin|>.\",\n \"Do not request or suggest performing additional searches.\",\n \"Do not say that you will search for more information.\",\n \"Use only the information already available in the conversation and the tool results above.\",\n \"Complete the CURRENT TASK using the available information.\"\n ].join(\" \")\n ]\n .filter(Boolean)\n .join(\"\\n\\n\");\n }\n\n const converseCommandInput:ConverseStreamCommandInput = {\n modelId: this.modelId,\n messages: brMessages,\n system: systemPrompt ? [{ text: systemPrompt }] : undefined,\n inferenceConfig: {\n temperature: inference?.temperature,\n maxTokens: inference?.maxTokens,\n topP: inference?.topP\n }\n }\n\n // Dev-gated request trace (set MINIWAT_TRACE_REQUEST=1). Logs the EXACT messages the model\n // receives — roles, flatten mode, per-message content — plus the system prompt and whether\n // tools are offered. Used to tell a model-side transcript-continuation leak apart from an\n // adapter role-boundary problem on a FINALIZE (tools-disabled) call. No effect unless the\n // env var is set.\n if (process.env.MINIWAT_TRACE_REQUEST)\n {\n console.log(\"[miniwat-trace-request]\", JSON.stringify({\n iteration: iterations,\n canUseTools,\n flattenToolHistory: !canUseTools,\n toolsOffered: canUseTools,\n systemPrompt,\n messages: brMessages.map(m => ({\n role: m.role,\n content: (m.content ?? []).map((c: any) =>\n c?.text !== undefined ? { text: c.text }\n : c?.toolUse !== undefined ? { toolUse: c.toolUse?.name }\n : c?.toolResult !== undefined ? { toolResult: true }\n : { other: Object.keys(c ?? {}) })\n }))\n }, null, 2));\n }\n\n if (this.guardrailConfig)\n {\n converseCommandInput.guardrailConfig = this.guardrailConfig;\n }\n\n const allowed = options?.allowedTools;\n const tools = canUseTools\n ? (await this.toolDispatcher.list())\n .filter(tool => allowed === undefined || (tool.name !== undefined && allowed.includes(tool.name)))\n .map(BedrockAdapter.toBedrockTool)\n : [];\n\n if(tools.length > 0)\n {\n converseCommandInput.toolConfig = { tools }\n }\n\n if (options?.streaming)\n {\n const res = await this.client.send(new ConverseStreamCommand(converseCommandInput));\n\n let chunks: string[] = [];\n let streamingStarted = false;\n let toolUses: ToolUse[] = [];\n let currentToolUse: ToolUse | undefined;\n let assistantText = '';\n\n for await (const event of res.stream ?? [])\n {\n\n if (event.modelStreamErrorException)\n {\n throw new Error(event.modelStreamErrorException?.message ?? \"Model stream error\");\n }\n\n if (event.contentBlockDelta?.delta?.text)\n {\n const chunk = event.contentBlockDelta.delta.text;\n assistantText += chunk;\n\n if (!streamingStarted)\n {\n chunks.push(chunk);\n\n if (chunks.length > 20)\n {\n streamingStarted = true;\n await this.streamBufferedText(chunks, options.onChunk!);\n chunks = [];\n }\n }\n else\n {\n options.onChunk?.(chunk);\n }\n }\n\n if (event.contentBlockStart?.start?.toolUse)\n {\n currentToolUse = {\n toolUseId: event.contentBlockStart.start.toolUse.toolUseId as string,\n name: event.contentBlockStart.start.toolUse.name as string,\n inputBuffer: \"\"\n };\n toolUses.push(currentToolUse);\n }\n\n if (currentToolUse && event.contentBlockDelta?.delta?.toolUse?.input)\n {\n currentToolUse.inputBuffer += event.contentBlockDelta.delta.toolUse.input;\n }\n\n if (event.contentBlockStop && currentToolUse?.inputBuffer)\n {\n try\n {\n currentToolUse.input = JSON.parse(currentToolUse.inputBuffer);\n }\n catch (error)\n {\n throw new Error(`Invalid arguments for tool \"${currentToolUse.name}\": ${currentToolUse.inputBuffer}.`);\n }\n\n delete currentToolUse.inputBuffer;\n currentToolUse = undefined;\n }\n\n if (event.messageStop)\n {\n const reason = event.messageStop.stopReason;\n\n if (reason === \"tool_use\")\n {\n\n if (!streamingStarted && chunks.length > 0)\n {\n await options.onThinking?.(chunks.join(\"\"));\n chunks = [];\n }\n\n toolCalls += toolUses.length;\n\n const toolUseMessage = BedrockMessage.toToolUseMessage(assistantText, toolUses);\n currentMessages.push(toolUseMessage);\n if(options?.onTooling) { await options.onTooling(toolUseMessage)}\n\n const { results: toolResults, blocked, stop } = await this.executeTools(toolUses, options);\n\n const toolResultMessage = BedrockMessage.toToolResultMessage(toolResults);\n currentMessages.push(toolResultMessage);\n if(options?.onTooling) { await options.onTooling(toolResultMessage)}\n\n // Stop the turn's tool loop when a call was blocked by authorization\n // (deferred/denied) OR a SIDE-EFFECTING call failed — in either case the\n // model must not re-propose it this turn (a retry risks a duplicate side\n // effect). End the turn with the text so far.\n if(blocked || stop)\n {\n return {\n message: BedrockMessage.toAssistantMessage(assistantText),\n stopReason: \"tool_use\"\n };\n }\n\n break;\n }\n\n if (typeof reason === \"string\")\n {\n if (/content|filter|guardrail/i.test(reason))\n {\n throw new Error(\"Output blocked by content filtering policy: \" + reason);\n }\n else if (reason === \"max_tokens\")\n {\n options.onChunk?.(BedrockAdapter.getResponseFromStopReasonWhenResponseIsEmpty(reason));\n }\n else if (!streamingStarted)\n {\n if (chunks.length > 0)\n {\n await this.streamBufferedText(chunks, options.onChunk!);\n } else\n {\n options.onChunk?.(BedrockAdapter.getResponseFromStopReasonWhenResponseIsEmpty(reason));\n }\n }\n }\n\n return {\n message: BedrockMessage.toAssistantMessage(assistantText),\n stopReason: reason\n };\n }\n }\n }\n else\n {\n const res = await this.client.send(new ConverseCommand(converseCommandInput));\n const text = this.extractAssistantText(res, brMessages);\n\n const content = res?.output?.message?.content ?? [];\n\n if (res.stopReason === \"tool_use\")\n {\n const toolUses = content.filter((c: any) => c.toolUse)\n .map((c: any) => ({\n toolUseId: c.toolUse.toolUseId,\n name: c.toolUse.name,\n input: c.toolUse.input\n }));\n\n toolCalls += toolUses.length;\n\n const toolUseMessage = BedrockMessage.toToolUseMessage(text, toolUses);\n currentMessages.push(toolUseMessage);\n if(options?.onTooling) { await options.onTooling(toolUseMessage)}\n\n const { results: toolResults, blocked, stop } = await this.executeTools(toolUses, options);\n\n const toolResultMessage = BedrockMessage.toToolResultMessage(toolResults);\n currentMessages.push(toolResultMessage);\n if(options?.onTooling) { await options.onTooling(toolResultMessage)}\n\n // Stop on authorization block OR a failed side-effecting call (see streaming path).\n if(blocked || stop)\n {\n return {\n message: BedrockMessage.toAssistantMessage(text),\n stopReason: res.stopReason\n };\n }\n\n continue;\n }\n\n const msg = BedrockMessage.toAssistantMessage(text);\n\n return {\n message: msg,\n stopReason: res.stopReason,\n usage: res.usage\n };\n }\n }\n }\n\n async invoke(messages: Message[], option?: ModelOption): Promise<ResponseMessage>\n {\n const response = await this.runConversationLoop(messages, option?.inference, {\n streaming: false,\n onThinking: option?.event?.onThinking,\n onTooling: option?.event?.onTooling,\n maxToolCalls: option?.maxToolCalls,\n toolsEnabled: option?.toolsEnabled,\n allowedTools: option?.allowedTools,\n authorization: option?.authorization\n },\n option?.instruction);\n\n return new ResponseMessage({\n stopReason: response.stopReason as StopReason,\n tokenUsage: response.usage,\n message: response.message\n });\n }\n\n async stream(messages: Message[], option?: ModelOption): Promise<Readable>\n {\n const out = new PassThrough({ encoding: \"utf8\" });\n\n (async () =>\n {\n try\n {\n await this.runConversationLoop(messages, option?.inference, {\n streaming: true,\n onChunk: c => out.write(c),\n onThinking: option?.event?.onThinking,\n onTooling: option?.event?.onTooling,\n maxToolCalls: option?.maxToolCalls,\n toolsEnabled: option?.toolsEnabled,\n allowedTools: option?.allowedTools,\n authorization: option?.authorization\n },\n option?.instruction);\n\n out.write('');\n out.end();\n }\n catch (e)\n {\n out.emit(\"throw\", e);\n out.write('');\n out.end();\n }\n })();\n\n return out;\n }\n}","import { MessageType, Message, ToolUse, ToolResult } from '@mappies/miniwat-agent-core'\n\nexport default class BedrockMessage extends Message\n{\n constructor(data:Partial<Message>)\n {\n super(data)\n }\n \n public static toAssistantMessage(text: string): Message\n {\n return new Message({\n type: MessageType.Agent,\n content: text,\n createdTimestamp: new Date().toISOString(),\n });\n }\n \n public static toToolUseMessage(text:string, toolUses: ToolUse[]): Message\n {\n return new Message({\n type: MessageType.Agent,\n content: text,\n createdTimestamp: new Date().toISOString(),\n toolUse: toolUses.map(({ toolUseId, name, input }) => (<ToolUse>{ toolUseId, name, input })),\n });\n }\n \n public static toToolResultMessage(toolResult: ToolResult[]): Message\n {\n return new Message({\n type: MessageType.ToolResult,\n toolResult\n });\n }\n}","import { MessageType, Message, Tool, readStructuredToolResult } from '@mappies/miniwat-agent-core'\nimport { Message as BrMessage, StopReason, Tool as BedrockTool } from \"@aws-sdk/client-bedrock-runtime\";\n\nexport class BedrockAdapter\n{\n static toBedrockTool(tool: Tool): BedrockTool\n {\n return {\n toolSpec: {\n name: tool.name,\n description: tool.description,\n inputSchema: { json: tool.schema } as any\n }\n };\n }\n\n static toBedrockMessages(history: Message[], flattenToolHistory = false): BrMessage[]\n {\n return history\n .filter(m =>\n (m.content ?? \"\").trim().length > 0 ||\n (m.toolUse?.length ?? 0) > 0 ||\n (m.toolResult?.length ?? 0) > 0\n )\n .map(m =>\n {\n const role = m.type === MessageType.User || m.type === MessageType.ToolResult\n ? \"user\"\n : \"assistant\";\n\n const content: any[] = [];\n\n if (flattenToolHistory)\n {\n if ((m.content ?? \"\").trim().length > 0)\n {\n content.push({ text: m.content });\n }\n else if (m.toolUse?.length)\n {\n // Frame prior tool activity as COMPLETED history, not an in-progress call.\n // \"Tool result:\" / \"I used the tools\" reads like an ongoing tool exchange and\n // intermittently prompts the model to continue calling tools during FINALIZE\n // (where tools are disabled). A completed-operation framing removes that cue.\n const names = m.toolUse.map(t => t.name).filter(Boolean).join(\", \");\n content.push({ text: names ? `Completed action: ${names}.` : \"Completed an action.\" });\n }\n\n if (m.toolResult?.length)\n {\n content.push(...m.toolResult.map(r => ({\n text: [\n r.status ? \"Outcome: succeeded\" : \"Outcome: failed\",\n `Result: ${this.toolResultToText(r.content)}`\n ].join(\"\\n\")\n })));\n }\n }\n else\n {\n if (m.toolUse?.length)\n {\n content.push(...m.toolUse.map(t => ({ toolUse: t })));\n }\n else if ((m.content ?? \"\").trim().length > 0)\n {\n content.push({ text: m.content });\n }\n\n if (m.toolResult?.length)\n {\n content.push(...m.toolResult.map(r => ({\n toolResult: {\n ...r,\n status: r.status ? \"success\" : \"error\"\n }\n })));\n }\n }\n\n if (content.length === 0)\n {\n content.push({ text: \"\" });\n }\n\n return { role, content };\n });\n }\n\n private static toolResultToText(content: unknown): string\n {\n const maxLength = 12000;\n\n // When the tool returned a StructuredToolResult, ground FINALIZE on its human-readable\n // `text` — NOT the raw JSON. Feeding the model the JSON object invites it to echo the whole\n // {\"succeeded\":...,\"text\":...} blob back as the reply; the `text` is what it should relay.\n const structured = readStructuredToolResult(content);\n if (structured)\n {\n const text = structured.text;\n return text.length > maxLength ? `${text.slice(0, maxLength)}\\n[Tool result truncated]` : text;\n }\n\n const text = !Array.isArray(content)\n ? (typeof content === \"string\" ? content : (JSON.stringify(content) ?? String(content)))\n : content\n .map((item: any) =>\n {\n if (typeof item?.text === \"string\")\n {\n return item.text;\n }\n\n if (item?.json !== undefined)\n {\n return JSON.stringify(item.json);\n }\n\n return JSON.stringify(item);\n })\n .filter(Boolean)\n .join(\"\\n\");\n\n return text.length > maxLength\n ? `${text.slice(0, maxLength)}\\n[Tool result truncated]`\n : text;\n }\n\n static toToolResultContent(result: unknown, status = true): { text?: string; json?: object }[]\n {\n const emptyResultText = status\n ? \"The tool completed successfully but returned no results.\"\n : \"The tool failed and returned no additional error details.\";\n\n try\n {\n if(result instanceof Error)\n {\n const message = result.message.trim();\n return [{ text: message.length > 0 ? message : emptyResultText }];\n }\n\n if(result === null || result === undefined || (typeof result === \"string\" && result.trim().length === 0))\n {\n return [{ text: emptyResultText }];\n }\n\n if(typeof result === \"object\")\n {\n let json = JSON.parse(JSON.stringify(result));\n\n if(Array.isArray(json))\n {\n json = { result: json };\n }\n\n return [{ json }];\n }\n\n return [{ text: String(result) }];\n }\n catch (e: unknown)\n {\n const message = e instanceof Error ? e.message : String(e);\n\n return [{\n json: {\n error: \"Failed to serialize tool result\",\n message\n }\n }];\n }\n }\n\n static getResponseFromStopReasonWhenResponseIsEmpty(stopReason: StopReason): string\n {\n switch (stopReason)\n {\n case \"max_tokens\":\n return \"My response was cut off due to length limits. Would you like me to continue or summarize the remaining information?\";\n case \"stop_sequence\":\n return \"I've reached a natural stopping point in my response. Please let me know if you need additional information.\";\n case \"guardrail_intervened\":\n return \"I'm unable to provide a response to this request as it doesn't align with my usage guidelines. Please rephrase your question or ask something else.\";\n case \"content_filtered\":\n return \"I cannot generate a response for this request due to content policy restrictions. Please try rephrasing your question.\";\n case \"model_context_window_exceeded\":\n return \"The conversation or request is too long for me to process. Please try with a shorter input or start a new conversation.\";\n case \"end_turn\":\n return \"What can I help with?\";\n case \"tool_use\":\n return \"\";\n default:\n return \"I couldn't complete the response. Please try again.\";\n }\n }\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAsC;AACtC,IAAAA,6BAAgO;AAChO,8BAA0C;;;ACF1C,gCAA0D;AAE1D,IAAqB,iBAArB,cAA4C,kCAC5C;AAAA,EACI,YAAY,MACZ;AACI,UAAM,IAAI;AAAA,EACd;AAAA,EAEA,OAAc,mBAAmB,MACjC;AACI,WAAO,IAAI,kCAAQ;AAAA,MACf,MAAM,sCAAY;AAAA,MAClB,SAAS;AAAA,MACT,mBAAkB,oBAAI,KAAK,GAAE,YAAY;AAAA,IAC7C,CAAC;AAAA,EACL;AAAA,EAEA,OAAc,iBAAiB,MAAa,UAC5C;AACI,WAAO,IAAI,kCAAQ;AAAA,MACX,MAAM,sCAAY;AAAA,MAClB,SAAS;AAAA,MACT,mBAAkB,oBAAI,KAAK,GAAE,YAAY;AAAA,MACzC,SAAS,SAAS,IAAI,CAAC,EAAE,WAAW,MAAM,MAAM,OAAgB,EAAE,WAAW,MAAM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A,MACZ;AAAA,IACJ,GAAG;AAEH,WAAO;AAAA,EACX;AACJ;","names":["import_miniwat_agent_core","import_miniwat_agent_core","text"]}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/bedrockModel.ts
|
|
2
2
|
import { PassThrough } from "stream";
|
|
3
|
-
import { ResponseMessage, resolveInstructionValue } from "@mappies/miniwat-agent-core";
|
|
3
|
+
import { ResponseMessage, isToolAuthorizationBlock, toExecutionStatus, toVerdictText, resolveInstructionValue } from "@mappies/miniwat-agent-core";
|
|
4
4
|
import { ToolDispatcher } from "@mappies/miniwat-mcp-core";
|
|
5
5
|
|
|
6
6
|
// src/bedrockMessage.ts
|
|
@@ -36,7 +36,7 @@ var BedrockMessage = class extends Message {
|
|
|
36
36
|
import { BedrockRuntimeClient, ConverseCommand, ConverseStreamCommand } from "@aws-sdk/client-bedrock-runtime";
|
|
37
37
|
|
|
38
38
|
// src/bedrockAdapter.ts
|
|
39
|
-
import { MessageType as MessageType2 } from "@mappies/miniwat-agent-core";
|
|
39
|
+
import { MessageType as MessageType2, readStructuredToolResult } from "@mappies/miniwat-agent-core";
|
|
40
40
|
var BedrockAdapter = class {
|
|
41
41
|
static toBedrockTool(tool) {
|
|
42
42
|
return {
|
|
@@ -57,13 +57,14 @@ var BedrockAdapter = class {
|
|
|
57
57
|
if ((m.content ?? "").trim().length > 0) {
|
|
58
58
|
content.push({ text: m.content });
|
|
59
59
|
} else if (m.toolUse?.length) {
|
|
60
|
-
|
|
60
|
+
const names = m.toolUse.map((t) => t.name).filter(Boolean).join(", ");
|
|
61
|
+
content.push({ text: names ? `Completed action: ${names}.` : "Completed an action." });
|
|
61
62
|
}
|
|
62
63
|
if (m.toolResult?.length) {
|
|
63
64
|
content.push(...m.toolResult.map((r) => ({
|
|
64
65
|
text: [
|
|
65
|
-
r.status ? "
|
|
66
|
-
this.toolResultToText(r.content)
|
|
66
|
+
r.status ? "Outcome: succeeded" : "Outcome: failed",
|
|
67
|
+
`Result: ${this.toolResultToText(r.content)}`
|
|
67
68
|
].join("\n")
|
|
68
69
|
})));
|
|
69
70
|
}
|
|
@@ -90,6 +91,12 @@ var BedrockAdapter = class {
|
|
|
90
91
|
}
|
|
91
92
|
static toolResultToText(content) {
|
|
92
93
|
const maxLength = 12e3;
|
|
94
|
+
const structured = readStructuredToolResult(content);
|
|
95
|
+
if (structured) {
|
|
96
|
+
const text2 = structured.text;
|
|
97
|
+
return text2.length > maxLength ? `${text2.slice(0, maxLength)}
|
|
98
|
+
[Tool result truncated]` : text2;
|
|
99
|
+
}
|
|
93
100
|
const text = !Array.isArray(content) ? typeof content === "string" ? content : JSON.stringify(content) ?? String(content) : content.map((item) => {
|
|
94
101
|
if (typeof item?.text === "string") {
|
|
95
102
|
return item.text;
|
|
@@ -184,20 +191,42 @@ var BedrockModel = class {
|
|
|
184
191
|
}
|
|
185
192
|
async executeTools(toolUses, opts) {
|
|
186
193
|
const results = [];
|
|
194
|
+
let blocked = false;
|
|
195
|
+
let stop = false;
|
|
187
196
|
for (const toolUse of toolUses) {
|
|
197
|
+
const tool = await this.toolDispatcher.get(toolUse.name);
|
|
198
|
+
const sideEffecting = tool ? tool.readOnly !== true : true;
|
|
188
199
|
try {
|
|
189
|
-
const resultPromise = this.toolDispatcher.execute(toolUse.name, toolUse.input);
|
|
200
|
+
const resultPromise = this.toolDispatcher.execute(toolUse.name, toolUse.input, opts?.authorization);
|
|
190
201
|
if (opts?.onThinking && toolUse.name) {
|
|
191
202
|
const inputText = await this.toolDispatcher.getInputText(toolUse.name, toolUse.input);
|
|
192
203
|
if (inputText && opts.onThinking) await opts.onThinking(inputText);
|
|
193
204
|
}
|
|
194
205
|
const result = await resultPromise;
|
|
206
|
+
if (isToolAuthorizationBlock(result)) {
|
|
207
|
+
blocked = true;
|
|
208
|
+
results.push({
|
|
209
|
+
toolUseId: toolUse.toolUseId,
|
|
210
|
+
content: BedrockAdapter.toToolResultContent(result.text, false),
|
|
211
|
+
status: false
|
|
212
|
+
});
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
const outcome = toExecutionStatus(result);
|
|
216
|
+
const succeeded = outcome === "succeeded";
|
|
217
|
+
if (!succeeded && sideEffecting) {
|
|
218
|
+
stop = true;
|
|
219
|
+
}
|
|
195
220
|
results.push({
|
|
196
221
|
toolUseId: toolUse.toolUseId,
|
|
197
|
-
content: BedrockAdapter.toToolResultContent(result,
|
|
198
|
-
status:
|
|
222
|
+
content: BedrockAdapter.toToolResultContent(toVerdictText(result), succeeded),
|
|
223
|
+
status: succeeded,
|
|
224
|
+
outcome
|
|
199
225
|
});
|
|
200
226
|
} catch (err) {
|
|
227
|
+
if (sideEffecting) {
|
|
228
|
+
stop = true;
|
|
229
|
+
}
|
|
201
230
|
results.push({
|
|
202
231
|
toolUseId: toolUse.toolUseId,
|
|
203
232
|
content: BedrockAdapter.toToolResultContent(err, false),
|
|
@@ -205,7 +234,7 @@ var BedrockModel = class {
|
|
|
205
234
|
});
|
|
206
235
|
}
|
|
207
236
|
}
|
|
208
|
-
return results;
|
|
237
|
+
return { results, blocked, stop };
|
|
209
238
|
}
|
|
210
239
|
async runConversationLoop(messages, inference, options, instruction) {
|
|
211
240
|
let currentMessages = [...messages];
|
|
@@ -246,6 +275,19 @@ var BedrockModel = class {
|
|
|
246
275
|
topP: inference?.topP
|
|
247
276
|
}
|
|
248
277
|
};
|
|
278
|
+
if (process.env.MINIWAT_TRACE_REQUEST) {
|
|
279
|
+
console.log("[miniwat-trace-request]", JSON.stringify({
|
|
280
|
+
iteration: iterations,
|
|
281
|
+
canUseTools,
|
|
282
|
+
flattenToolHistory: !canUseTools,
|
|
283
|
+
toolsOffered: canUseTools,
|
|
284
|
+
systemPrompt,
|
|
285
|
+
messages: brMessages.map((m) => ({
|
|
286
|
+
role: m.role,
|
|
287
|
+
content: (m.content ?? []).map((c) => c?.text !== void 0 ? { text: c.text } : c?.toolUse !== void 0 ? { toolUse: c.toolUse?.name } : c?.toolResult !== void 0 ? { toolResult: true } : { other: Object.keys(c ?? {}) })
|
|
288
|
+
}))
|
|
289
|
+
}, null, 2));
|
|
290
|
+
}
|
|
249
291
|
if (this.guardrailConfig) {
|
|
250
292
|
converseCommandInput.guardrailConfig = this.guardrailConfig;
|
|
251
293
|
}
|
|
@@ -312,12 +354,18 @@ var BedrockModel = class {
|
|
|
312
354
|
if (options?.onTooling) {
|
|
313
355
|
await options.onTooling(toolUseMessage);
|
|
314
356
|
}
|
|
315
|
-
const toolResults = await this.executeTools(toolUses, options);
|
|
357
|
+
const { results: toolResults, blocked, stop } = await this.executeTools(toolUses, options);
|
|
316
358
|
const toolResultMessage = BedrockMessage.toToolResultMessage(toolResults);
|
|
317
359
|
currentMessages.push(toolResultMessage);
|
|
318
360
|
if (options?.onTooling) {
|
|
319
361
|
await options.onTooling(toolResultMessage);
|
|
320
362
|
}
|
|
363
|
+
if (blocked || stop) {
|
|
364
|
+
return {
|
|
365
|
+
message: BedrockMessage.toAssistantMessage(assistantText),
|
|
366
|
+
stopReason: "tool_use"
|
|
367
|
+
};
|
|
368
|
+
}
|
|
321
369
|
break;
|
|
322
370
|
}
|
|
323
371
|
if (typeof reason === "string") {
|
|
@@ -355,12 +403,18 @@ var BedrockModel = class {
|
|
|
355
403
|
if (options?.onTooling) {
|
|
356
404
|
await options.onTooling(toolUseMessage);
|
|
357
405
|
}
|
|
358
|
-
const toolResults = await this.executeTools(toolUses, options);
|
|
406
|
+
const { results: toolResults, blocked, stop } = await this.executeTools(toolUses, options);
|
|
359
407
|
const toolResultMessage = BedrockMessage.toToolResultMessage(toolResults);
|
|
360
408
|
currentMessages.push(toolResultMessage);
|
|
361
409
|
if (options?.onTooling) {
|
|
362
410
|
await options.onTooling(toolResultMessage);
|
|
363
411
|
}
|
|
412
|
+
if (blocked || stop) {
|
|
413
|
+
return {
|
|
414
|
+
message: BedrockMessage.toAssistantMessage(text),
|
|
415
|
+
stopReason: res.stopReason
|
|
416
|
+
};
|
|
417
|
+
}
|
|
364
418
|
continue;
|
|
365
419
|
}
|
|
366
420
|
const msg = BedrockMessage.toAssistantMessage(text);
|
|
@@ -382,7 +436,8 @@ var BedrockModel = class {
|
|
|
382
436
|
onTooling: option?.event?.onTooling,
|
|
383
437
|
maxToolCalls: option?.maxToolCalls,
|
|
384
438
|
toolsEnabled: option?.toolsEnabled,
|
|
385
|
-
allowedTools: option?.allowedTools
|
|
439
|
+
allowedTools: option?.allowedTools,
|
|
440
|
+
authorization: option?.authorization
|
|
386
441
|
},
|
|
387
442
|
option?.instruction
|
|
388
443
|
);
|
|
@@ -406,7 +461,8 @@ var BedrockModel = class {
|
|
|
406
461
|
onTooling: option?.event?.onTooling,
|
|
407
462
|
maxToolCalls: option?.maxToolCalls,
|
|
408
463
|
toolsEnabled: option?.toolsEnabled,
|
|
409
|
-
allowedTools: option?.allowedTools
|
|
464
|
+
allowedTools: option?.allowedTools,
|
|
465
|
+
authorization: option?.authorization
|
|
410
466
|
},
|
|
411
467
|
option?.instruction
|
|
412
468
|
);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/bedrockModel.ts","../src/bedrockMessage.ts","../src/bedrockAdapter.ts"],"sourcesContent":["import { PassThrough, Readable } from \"stream\";\nimport { ResponseMessage, Message, InferenceOptions, ToolUse, ToolResult, Model, ModelOption, resolveInstructionValue, Instruction } from '@mappies/miniwat-agent-core'\nimport { McpConfig, ToolDispatcher } from '@mappies/miniwat-mcp-core'\nimport BedrockMessage from \"./bedrockMessage\";\nimport { BedrockRuntimeClient, ConverseCommand, ConverseStreamCommand, Message as BrMessage, StopReason, BedrockRuntimeClientConfig, ConverseStreamCommandInput, GuardrailConfiguration } from \"@aws-sdk/client-bedrock-runtime\";\nimport { BedrockAdapter } from \"./bedrockAdapter\";\n\nexport class BedrockModel implements Model\n{\n private modelId: string;\n private toolDispatcher: ToolDispatcher;\n private client: BedrockRuntimeClient;\n private guardrailConfig?: GuardrailConfiguration;\n\n constructor(options: { region?: string; modelId: string; mcpConfig?:McpConfig, clientConfig?: BedrockRuntimeClientConfig; guardrailConfig?: { guardrailIdentifier: string; guardrailVersion?: string; }; })\n {\n this.toolDispatcher = new ToolDispatcher(options?.mcpConfig);\n this.modelId = options.modelId;\n\n if (options?.guardrailConfig?.guardrailIdentifier)\n {\n this.guardrailConfig = {\n guardrailIdentifier: options.guardrailConfig.guardrailIdentifier,\n guardrailVersion: options.guardrailConfig.guardrailVersion\n };\n }\n\n this.client = new BedrockRuntimeClient({\n region: options?.region ?? process.env.DEFAULT_AWS_REGION ?? process.env.AWS_REGION,\n ...options?.clientConfig\n });\n }\n\n private async streamBufferedText(chunks: string[], write: (chunk: string) => void)\n {\n for(const chunk of chunks)\n {\n write(chunk);\n await new Promise(r => setTimeout(r, 8 + Math.random() * 12));\n }\n }\n\n private extractAssistantText(res: any, messages: BrMessage[]): string\n {\n const content = res?.output?.message?.content ?? [];\n let text = content.map((c: any) => c.text ?? \"\").join(\"\");\n\n if(!text)\n {\n text = BedrockAdapter.getResponseFromStopReasonWhenResponseIsEmpty(res.stopReason);\n }\n\n return text;\n }\n\n private async executeTools(toolUses: ToolUse[], opts?: any): Promise<ToolResult[]>\n {\n const results: ToolResult[] = [];\n\n for(const toolUse of toolUses)\n {\n try\n {\n const resultPromise = this.toolDispatcher.execute(toolUse.name, toolUse.input);\n\n // Show a thinking message for the tool\n if (opts?.onThinking && toolUse.name)\n {\n const inputText = await this.toolDispatcher.getInputText(toolUse.name, toolUse.input);\n if(inputText && opts.onThinking) await opts.onThinking(inputText);\n }\n\n const result = await resultPromise;\n\n results.push({\n toolUseId: toolUse.toolUseId,\n content: BedrockAdapter.toToolResultContent(result, true),\n status: true\n });\n }\n catch(err: any)\n {\n results.push({\n toolUseId: toolUse.toolUseId,\n content: BedrockAdapter.toToolResultContent(err, false),\n status: false\n });\n }\n }\n\n return results;\n }\n\n private async runConversationLoop(messages: Message[],\n inference?: InferenceOptions,\n options?: { streaming?: boolean;\n onChunk?: (chunk: string) => void,\n onThinking?: (msg: string) => Promise<void>,\n onTooling?: (msg: Message) => Promise<void>,\n maxToolCalls?: number,\n toolsEnabled?: boolean,\n allowedTools?: string[]\n },\n instruction?: Instruction): Promise<{ message: Message; stopReason?: StopReason; usage?: any }>\n {\n let currentMessages = [...messages];\n let iterations = 0;\n\n const toolsEnabled = options?.toolsEnabled ?? true;\n const maxToolCalls = toolsEnabled ? Math.max(0, options?.maxToolCalls ?? 3) : 0;\n const maxIterations = 20;\n let toolCalls = 0;\n\n while(true)\n {\n if (++iterations > maxIterations)\n {\n throw new Error(\"Too many conversation iterations\");\n }\n\n const remainingToolCalls = Math.max(0, maxToolCalls - toolCalls);\n const canUseTools = toolsEnabled && remainingToolCalls > 0 && iterations < maxIterations;\n\n const brMessages = BedrockAdapter.toBedrockMessages(currentMessages, !canUseTools);\n\n let systemPrompt = await resolveInstructionValue(instruction?.system?.value, undefined);\n\n if (!canUseTools && toolCalls > 0)\n {\n systemPrompt = [\n systemPrompt,\n [\n \"You have reached the tool-use limit.\",\n \"Tool use is no longer available.\",\n \"Do not output tool calls, function-call syntax, tool-call markup, or special tokens such as <|tool_calls_section_begin|>.\",\n \"Do not request or suggest performing additional searches.\",\n \"Do not say that you will search for more information.\",\n \"Use only the information already available in the conversation and the tool results above.\",\n \"Complete the CURRENT TASK using the available information.\"\n ].join(\" \")\n ]\n .filter(Boolean)\n .join(\"\\n\\n\");\n }\n\n const converseCommandInput:ConverseStreamCommandInput = {\n modelId: this.modelId,\n messages: brMessages,\n system: systemPrompt ? [{ text: systemPrompt }] : undefined,\n inferenceConfig: {\n temperature: inference?.temperature,\n maxTokens: inference?.maxTokens,\n topP: inference?.topP\n }\n }\n\n if (this.guardrailConfig)\n {\n converseCommandInput.guardrailConfig = this.guardrailConfig;\n }\n\n const allowed = options?.allowedTools;\n const tools = canUseTools\n ? (await this.toolDispatcher.list())\n .filter(tool => allowed === undefined || (tool.name !== undefined && allowed.includes(tool.name)))\n .map(BedrockAdapter.toBedrockTool)\n : [];\n\n if(tools.length > 0)\n {\n converseCommandInput.toolConfig = { tools }\n }\n\n if (options?.streaming)\n {\n const res = await this.client.send(new ConverseStreamCommand(converseCommandInput));\n\n let chunks: string[] = [];\n let streamingStarted = false;\n let toolUses: ToolUse[] = [];\n let currentToolUse: ToolUse | undefined;\n let assistantText = '';\n\n for await (const event of res.stream ?? [])\n {\n\n if (event.modelStreamErrorException)\n {\n throw new Error(event.modelStreamErrorException?.message ?? \"Model stream error\");\n }\n\n if (event.contentBlockDelta?.delta?.text)\n {\n const chunk = event.contentBlockDelta.delta.text;\n assistantText += chunk;\n\n if (!streamingStarted)\n {\n chunks.push(chunk);\n\n if (chunks.length > 20)\n {\n streamingStarted = true;\n await this.streamBufferedText(chunks, options.onChunk!);\n chunks = [];\n }\n }\n else\n {\n options.onChunk?.(chunk);\n }\n }\n\n if (event.contentBlockStart?.start?.toolUse)\n {\n currentToolUse = {\n toolUseId: event.contentBlockStart.start.toolUse.toolUseId as string,\n name: event.contentBlockStart.start.toolUse.name as string,\n inputBuffer: \"\"\n };\n toolUses.push(currentToolUse);\n }\n\n if (currentToolUse && event.contentBlockDelta?.delta?.toolUse?.input)\n {\n currentToolUse.inputBuffer += event.contentBlockDelta.delta.toolUse.input;\n }\n\n if (event.contentBlockStop && currentToolUse?.inputBuffer)\n {\n try\n {\n currentToolUse.input = JSON.parse(currentToolUse.inputBuffer);\n }\n catch (error)\n {\n throw new Error(`Invalid arguments for tool \"${currentToolUse.name}\": ${currentToolUse.inputBuffer}.`);\n }\n\n delete currentToolUse.inputBuffer;\n currentToolUse = undefined;\n }\n\n if (event.messageStop)\n {\n const reason = event.messageStop.stopReason;\n\n if (reason === \"tool_use\")\n {\n\n if (!streamingStarted && chunks.length > 0)\n {\n await options.onThinking?.(chunks.join(\"\"));\n chunks = [];\n }\n\n toolCalls += toolUses.length;\n\n const toolUseMessage = BedrockMessage.toToolUseMessage(assistantText, toolUses);\n currentMessages.push(toolUseMessage);\n if(options?.onTooling) { await options.onTooling(toolUseMessage)}\n\n const toolResults = await this.executeTools(toolUses, options);\n\n const toolResultMessage = BedrockMessage.toToolResultMessage(toolResults);\n currentMessages.push(toolResultMessage);\n if(options?.onTooling) { await options.onTooling(toolResultMessage)}\n\n break;\n }\n\n if (typeof reason === \"string\")\n {\n if (/content|filter|guardrail/i.test(reason))\n {\n throw new Error(\"Output blocked by content filtering policy: \" + reason);\n }\n else if (reason === \"max_tokens\")\n {\n options.onChunk?.(BedrockAdapter.getResponseFromStopReasonWhenResponseIsEmpty(reason));\n }\n else if (!streamingStarted)\n {\n if (chunks.length > 0)\n {\n await this.streamBufferedText(chunks, options.onChunk!);\n } else\n {\n options.onChunk?.(BedrockAdapter.getResponseFromStopReasonWhenResponseIsEmpty(reason));\n }\n }\n }\n\n return {\n message: BedrockMessage.toAssistantMessage(assistantText),\n stopReason: reason\n };\n }\n }\n }\n else\n {\n const res = await this.client.send(new ConverseCommand(converseCommandInput));\n const text = this.extractAssistantText(res, brMessages);\n\n const content = res?.output?.message?.content ?? [];\n\n if (res.stopReason === \"tool_use\")\n {\n const toolUses = content.filter((c: any) => c.toolUse)\n .map((c: any) => ({\n toolUseId: c.toolUse.toolUseId,\n name: c.toolUse.name,\n input: c.toolUse.input\n }));\n\n toolCalls += toolUses.length;\n\n const toolUseMessage = BedrockMessage.toToolUseMessage(text, toolUses);\n currentMessages.push(toolUseMessage);\n if(options?.onTooling) { await options.onTooling(toolUseMessage)}\n\n const toolResults = await this.executeTools(toolUses, options);\n\n const toolResultMessage = BedrockMessage.toToolResultMessage(toolResults);\n currentMessages.push(toolResultMessage);\n if(options?.onTooling) { await options.onTooling(toolResultMessage)}\n\n continue;\n }\n\n const msg = BedrockMessage.toAssistantMessage(text);\n\n return {\n message: msg,\n stopReason: res.stopReason,\n usage: res.usage\n };\n }\n }\n }\n\n async invoke(messages: Message[], option?: ModelOption): Promise<ResponseMessage>\n {\n const response = await this.runConversationLoop(messages, option?.inference, {\n streaming: false,\n onThinking: option?.event?.onThinking,\n onTooling: option?.event?.onTooling,\n maxToolCalls: option?.maxToolCalls,\n toolsEnabled: option?.toolsEnabled,\n allowedTools: option?.allowedTools\n },\n option?.instruction);\n\n return new ResponseMessage({\n stopReason: response.stopReason as StopReason,\n tokenUsage: response.usage,\n message: response.message\n });\n }\n\n async stream(messages: Message[], option?: ModelOption): Promise<Readable>\n {\n const out = new PassThrough({ encoding: \"utf8\" });\n\n (async () =>\n {\n try\n {\n await this.runConversationLoop(messages, option?.inference, {\n streaming: true,\n onChunk: c => out.write(c),\n onThinking: option?.event?.onThinking,\n onTooling: option?.event?.onTooling,\n maxToolCalls: option?.maxToolCalls,\n toolsEnabled: option?.toolsEnabled,\n allowedTools: option?.allowedTools\n },\n option?.instruction);\n\n out.write('');\n out.end();\n }\n catch (e)\n {\n out.emit(\"throw\", e);\n out.write('');\n out.end();\n }\n })();\n\n return out;\n }\n}","import { MessageType, Message, ToolUse, ToolResult } from '@mappies/miniwat-agent-core'\n\nexport default class BedrockMessage extends Message\n{\n constructor(data:Partial<Message>)\n {\n super(data)\n }\n \n public static toAssistantMessage(text: string): Message\n {\n return new Message({\n type: MessageType.Agent,\n content: text,\n createdTimestamp: new Date().toISOString(),\n });\n }\n \n public static toToolUseMessage(text:string, toolUses: ToolUse[]): Message\n {\n return new Message({\n type: MessageType.Agent,\n content: text,\n createdTimestamp: new Date().toISOString(),\n toolUse: toolUses.map(({ toolUseId, name, input }) => (<ToolUse>{ toolUseId, name, input })),\n });\n }\n \n public static toToolResultMessage(toolResult: ToolResult[]): Message\n {\n return new Message({\n type: MessageType.ToolResult,\n toolResult\n });\n }\n}","import { MessageType, Message, Tool } from '@mappies/miniwat-agent-core'\nimport { Message as BrMessage, StopReason, Tool as BedrockTool } from \"@aws-sdk/client-bedrock-runtime\";\n\nexport class BedrockAdapter\n{\n static toBedrockTool(tool: Tool): BedrockTool\n {\n return {\n toolSpec: {\n name: tool.name,\n description: tool.description,\n inputSchema: { json: tool.schema } as any\n }\n };\n }\n\n static toBedrockMessages(history: Message[], flattenToolHistory = false): BrMessage[]\n {\n return history\n .filter(m =>\n (m.content ?? \"\").trim().length > 0 ||\n (m.toolUse?.length ?? 0) > 0 ||\n (m.toolResult?.length ?? 0) > 0\n )\n .map(m =>\n {\n const role = m.type === MessageType.User || m.type === MessageType.ToolResult\n ? \"user\"\n : \"assistant\";\n\n const content: any[] = [];\n\n if (flattenToolHistory)\n {\n if ((m.content ?? \"\").trim().length > 0)\n {\n content.push({ text: m.content });\n }\n else if (m.toolUse?.length)\n {\n content.push({ text: \"I used the available tools to gather information.\" });\n }\n\n if (m.toolResult?.length)\n {\n content.push(...m.toolResult.map(r => ({\n text: [\n r.status ? \"Tool result:\" : \"Tool result (failed):\",\n this.toolResultToText(r.content)\n ].join(\"\\n\")\n })));\n }\n }\n else\n {\n if (m.toolUse?.length)\n {\n content.push(...m.toolUse.map(t => ({ toolUse: t })));\n }\n else if ((m.content ?? \"\").trim().length > 0)\n {\n content.push({ text: m.content });\n }\n\n if (m.toolResult?.length)\n {\n content.push(...m.toolResult.map(r => ({\n toolResult: {\n ...r,\n status: r.status ? \"success\" : \"error\"\n }\n })));\n }\n }\n\n if (content.length === 0)\n {\n content.push({ text: \"\" });\n }\n\n return { role, content };\n });\n }\n\n private static toolResultToText(content: unknown): string\n {\n const maxLength = 12000;\n\n const text = !Array.isArray(content)\n ? (typeof content === \"string\" ? content : (JSON.stringify(content) ?? String(content)))\n : content\n .map((item: any) =>\n {\n if (typeof item?.text === \"string\")\n {\n return item.text;\n }\n\n if (item?.json !== undefined)\n {\n return JSON.stringify(item.json);\n }\n\n return JSON.stringify(item);\n })\n .filter(Boolean)\n .join(\"\\n\");\n\n return text.length > maxLength\n ? `${text.slice(0, maxLength)}\\n[Tool result truncated]`\n : text;\n }\n\n static toToolResultContent(result: unknown, status = true): { text?: string; json?: object }[]\n {\n const emptyResultText = status\n ? \"The tool completed successfully but returned no results.\"\n : \"The tool failed and returned no additional error details.\";\n\n try\n {\n if(result instanceof Error)\n {\n const message = result.message.trim();\n return [{ text: message.length > 0 ? message : emptyResultText }];\n }\n\n if(result === null || result === undefined || (typeof result === \"string\" && result.trim().length === 0))\n {\n return [{ text: emptyResultText }];\n }\n\n if(typeof result === \"object\")\n {\n let json = JSON.parse(JSON.stringify(result));\n\n if(Array.isArray(json))\n {\n json = { result: json };\n }\n\n return [{ json }];\n }\n\n return [{ text: String(result) }];\n }\n catch (e: unknown)\n {\n const message = e instanceof Error ? e.message : String(e);\n\n return [{\n json: {\n error: \"Failed to serialize tool result\",\n message\n }\n }];\n }\n }\n\n static getResponseFromStopReasonWhenResponseIsEmpty(stopReason: StopReason): string\n {\n switch (stopReason)\n {\n case \"max_tokens\":\n return \"My response was cut off due to length limits. Would you like me to continue or summarize the remaining information?\";\n case \"stop_sequence\":\n return \"I've reached a natural stopping point in my response. Please let me know if you need additional information.\";\n case \"guardrail_intervened\":\n return \"I'm unable to provide a response to this request as it doesn't align with my usage guidelines. Please rephrase your question or ask something else.\";\n case \"content_filtered\":\n return \"I cannot generate a response for this request due to content policy restrictions. Please try rephrasing your question.\";\n case \"model_context_window_exceeded\":\n return \"The conversation or request is too long for me to process. Please try with a shorter input or start a new conversation.\";\n case \"end_turn\":\n return \"What can I help with?\";\n case \"tool_use\":\n return \"\";\n default:\n return \"I couldn't complete the response. Please try again.\";\n }\n }\n}"],"mappings":";AAAA,SAAS,mBAA6B;AACtC,SAAS,iBAAqF,+BAA4C;AAC1I,SAAoB,sBAAsB;;;ACF1C,SAAS,aAAa,eAAoC;AAE1D,IAAqB,iBAArB,cAA4C,QAC5C;AAAA,EACI,YAAY,MACZ;AACI,UAAM,IAAI;AAAA,EACd;AAAA,EAEA,OAAc,mBAAmB,MACjC;AACI,WAAO,IAAI,QAAQ;AAAA,MACf,MAAM,YAAY;AAAA,MAClB,SAAS;AAAA,MACT,mBAAkB,oBAAI,KAAK,GAAE,YAAY;AAAA,IAC7C,CAAC;AAAA,EACL;AAAA,EAEA,OA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,UAAM,WAAW,MAAM,KAAK;AAAA,MAAoB;AAAA,MAAU,QAAQ;AAAA,MAAW;AAAA,QACzE,WAAW;AAAA,QACX,YAAY,QAAQ,OAAO;AAAA,QAC3B,WAAW,QAAQ,OAAO;AAAA,QAC1B,cAAc,QAAQ;AAAA,QACtB,cAAc,QAAQ;AAAA,QACtB,cAAc,QAAQ;AAAA,MAC1B;AAAA,MACA,QAAQ;AAAA,IAAW;AAEnB,WAAO,IAAI,gBAAgB;AAAA,MACvB,YAAY,SAAS;AAAA,MACrB,YAAY,SAAS;AAAA,MACrB,SAAS,SAAS;AAAA,IACtB,CAAC;AAAA,EACL;AAAA,EAEA,MAAM,OAAO,UAAqB,QAClC;AACI,UAAM,MAAM,IAAI,YAAY,EAAE,UAAU,OAAO,CAAC;AAEhD,KAAC,YACD;AACI,UACA;AACI,cAAM,KAAK;AAAA,UAAoB;AAAA,UAAU,QAAQ;AAAA,UAAW;AAAA,YACxD,WAAW;AAAA,YACX,SAAS,OAAK,IAAI,MAAM,CAAC;AAAA,YACzB,YAAY,QAAQ,OAAO;AAAA,YAC3B,WAAW,QAAQ,OAAO;AAAA,YAC1B,cAAc,QAAQ;AAAA,YACtB,cAAc,QAAQ;AAAA,YACtB,cAAc,QAAQ;AAAA,UAC1B;AAAA,UACA,QAAQ;AAAA,QAAW;AAEnB,YAAI,MAAM,EAAE;AACZ,YAAI,IAAI;AAAA,MACZ,SACO,GACP;AACI,YAAI,KAAK,SAAS,CAAC;AACnB,YAAI,MAAM,EAAE;AACZ,YAAI,IAAI;AAAA,MACZ;AAAA,IACJ,GAAG;AAEH,WAAO;AAAA,EACX;AACJ;","names":["MessageType"]}
|
|
1
|
+
{"version":3,"sources":["../src/bedrockModel.ts","../src/bedrockMessage.ts","../src/bedrockAdapter.ts"],"sourcesContent":["import { PassThrough, Readable } from \"stream\";\nimport { ResponseMessage, Message, InferenceOptions, ToolUse, ToolResult, Model, ModelOption, ToolAuthorizationOptions, isToolAuthorizationBlock, toExecutionStatus, toVerdictText, resolveInstructionValue, Instruction } from '@mappies/miniwat-agent-core'\nimport { McpConfig, ToolDispatcher } from '@mappies/miniwat-mcp-core'\nimport BedrockMessage from \"./bedrockMessage\";\nimport { BedrockRuntimeClient, ConverseCommand, ConverseStreamCommand, Message as BrMessage, StopReason, BedrockRuntimeClientConfig, ConverseStreamCommandInput, GuardrailConfiguration } from \"@aws-sdk/client-bedrock-runtime\";\nimport { BedrockAdapter } from \"./bedrockAdapter\";\n\nexport class BedrockModel implements Model\n{\n private modelId: string;\n private toolDispatcher: ToolDispatcher;\n private client: BedrockRuntimeClient;\n private guardrailConfig?: GuardrailConfiguration;\n\n constructor(options: { region?: string; modelId: string; mcpConfig?:McpConfig, clientConfig?: BedrockRuntimeClientConfig; guardrailConfig?: { guardrailIdentifier: string; guardrailVersion?: string; }; })\n {\n this.toolDispatcher = new ToolDispatcher(options?.mcpConfig);\n this.modelId = options.modelId;\n\n if (options?.guardrailConfig?.guardrailIdentifier)\n {\n this.guardrailConfig = {\n guardrailIdentifier: options.guardrailConfig.guardrailIdentifier,\n guardrailVersion: options.guardrailConfig.guardrailVersion\n };\n }\n\n this.client = new BedrockRuntimeClient({\n region: options?.region ?? process.env.DEFAULT_AWS_REGION ?? process.env.AWS_REGION,\n ...options?.clientConfig\n });\n }\n\n private async streamBufferedText(chunks: string[], write: (chunk: string) => void)\n {\n for(const chunk of chunks)\n {\n write(chunk);\n await new Promise(r => setTimeout(r, 8 + Math.random() * 12));\n }\n }\n\n private extractAssistantText(res: any, messages: BrMessage[]): string\n {\n const content = res?.output?.message?.content ?? [];\n let text = content.map((c: any) => c.text ?? \"\").join(\"\");\n\n if(!text)\n {\n text = BedrockAdapter.getResponseFromStopReasonWhenResponseIsEmpty(res.stopReason);\n }\n\n return text;\n }\n\n private async executeTools(toolUses: ToolUse[], opts?: any): Promise<{ results: ToolResult[]; blocked: boolean; stop: boolean }>\n {\n const results: ToolResult[] = [];\n let blocked = false;\n let stop = false;\n\n for(const toolUse of toolUses)\n {\n // A side-effecting tool must NOT be auto-retried after a failed/uncertain execution: the\n // effect may have partially happened, so re-calling risks a duplicate. Resolve the tool's\n // read-only nature (unknown ⇒ treat as side-effecting) so a failure stops the turn's tool\n // loop rather than letting the model re-propose the same call within this invocation.\n const tool = await this.toolDispatcher.get(toolUse.name);\n const sideEffecting = tool ? tool.readOnly !== true : true;\n\n try\n {\n const resultPromise = this.toolDispatcher.execute(toolUse.name, toolUse.input, opts?.authorization);\n\n // Show a thinking message for the tool\n if (opts?.onThinking && toolUse.name)\n {\n const inputText = await this.toolDispatcher.getInputText(toolUse.name, toolUse.input);\n if(inputText && opts.onThinking) await opts.onThinking(inputText);\n }\n\n const result = await resultPromise;\n\n // Dispatch-boundary authorization blocked this call (defer/deny). The model sees the\n // structured block text as a failed tool result, and the turn's tool loop stops so a\n // deferred side effect is not retried.\n if(isToolAuthorizationBlock(result))\n {\n blocked = true;\n\n results.push({\n toolUseId: toolUse.toolUseId,\n content: BedrockAdapter.toToolResultContent(result.text, false),\n status: false\n });\n\n continue;\n }\n\n // Use the output guardrail's verdict to determine whether the tool succeeded.\n // Save the outcome so the execution ledger knows if it succeeded, failed, or is unknown.\n // If a side-effecting tool did not succeed, stop the tool loop to avoid retrying\n // an operation that may have already executed.\n const outcome = toExecutionStatus(result);\n const succeeded = outcome === \"succeeded\";\n\n if(!succeeded && sideEffecting)\n {\n stop = true;\n }\n\n results.push({\n toolUseId: toolUse.toolUseId,\n content: BedrockAdapter.toToolResultContent(toVerdictText(result), succeeded),\n status: succeeded,\n outcome\n });\n }\n catch(err: any)\n {\n // A side-effecting tool failed: stop the loop so it is not re-attempted this turn.\n if(sideEffecting)\n {\n stop = true;\n }\n\n results.push({\n toolUseId: toolUse.toolUseId,\n content: BedrockAdapter.toToolResultContent(err, false),\n status: false\n });\n }\n }\n\n return { results, blocked, stop };\n }\n\n private async runConversationLoop(messages: Message[],\n inference?: InferenceOptions,\n options?: { streaming?: boolean;\n onChunk?: (chunk: string) => void,\n onThinking?: (msg: string) => Promise<void>,\n onTooling?: (msg: Message) => Promise<void>,\n maxToolCalls?: number,\n toolsEnabled?: boolean,\n allowedTools?: string[],\n authorization?: ToolAuthorizationOptions\n },\n instruction?: Instruction): Promise<{ message: Message; stopReason?: StopReason; usage?: any }>\n {\n let currentMessages = [...messages];\n let iterations = 0;\n\n const toolsEnabled = options?.toolsEnabled ?? true;\n const maxToolCalls = toolsEnabled ? Math.max(0, options?.maxToolCalls ?? 3) : 0;\n const maxIterations = 20;\n let toolCalls = 0;\n\n while(true)\n {\n if (++iterations > maxIterations)\n {\n throw new Error(\"Too many conversation iterations\");\n }\n\n const remainingToolCalls = Math.max(0, maxToolCalls - toolCalls);\n const canUseTools = toolsEnabled && remainingToolCalls > 0 && iterations < maxIterations;\n\n const brMessages = BedrockAdapter.toBedrockMessages(currentMessages, !canUseTools);\n\n let systemPrompt = await resolveInstructionValue(instruction?.system?.value, undefined);\n\n if (!canUseTools && toolCalls > 0)\n {\n systemPrompt = [\n systemPrompt,\n [\n \"You have reached the tool-use limit.\",\n \"Tool use is no longer available.\",\n \"Do not output tool calls, function-call syntax, tool-call markup, or special tokens such as <|tool_calls_section_begin|>.\",\n \"Do not request or suggest performing additional searches.\",\n \"Do not say that you will search for more information.\",\n \"Use only the information already available in the conversation and the tool results above.\",\n \"Complete the CURRENT TASK using the available information.\"\n ].join(\" \")\n ]\n .filter(Boolean)\n .join(\"\\n\\n\");\n }\n\n const converseCommandInput:ConverseStreamCommandInput = {\n modelId: this.modelId,\n messages: brMessages,\n system: systemPrompt ? [{ text: systemPrompt }] : undefined,\n inferenceConfig: {\n temperature: inference?.temperature,\n maxTokens: inference?.maxTokens,\n topP: inference?.topP\n }\n }\n\n // Dev-gated request trace (set MINIWAT_TRACE_REQUEST=1). Logs the EXACT messages the model\n // receives — roles, flatten mode, per-message content — plus the system prompt and whether\n // tools are offered. Used to tell a model-side transcript-continuation leak apart from an\n // adapter role-boundary problem on a FINALIZE (tools-disabled) call. No effect unless the\n // env var is set.\n if (process.env.MINIWAT_TRACE_REQUEST)\n {\n console.log(\"[miniwat-trace-request]\", JSON.stringify({\n iteration: iterations,\n canUseTools,\n flattenToolHistory: !canUseTools,\n toolsOffered: canUseTools,\n systemPrompt,\n messages: brMessages.map(m => ({\n role: m.role,\n content: (m.content ?? []).map((c: any) =>\n c?.text !== undefined ? { text: c.text }\n : c?.toolUse !== undefined ? { toolUse: c.toolUse?.name }\n : c?.toolResult !== undefined ? { toolResult: true }\n : { other: Object.keys(c ?? {}) })\n }))\n }, null, 2));\n }\n\n if (this.guardrailConfig)\n {\n converseCommandInput.guardrailConfig = this.guardrailConfig;\n }\n\n const allowed = options?.allowedTools;\n const tools = canUseTools\n ? (await this.toolDispatcher.list())\n .filter(tool => allowed === undefined || (tool.name !== undefined && allowed.includes(tool.name)))\n .map(BedrockAdapter.toBedrockTool)\n : [];\n\n if(tools.length > 0)\n {\n converseCommandInput.toolConfig = { tools }\n }\n\n if (options?.streaming)\n {\n const res = await this.client.send(new ConverseStreamCommand(converseCommandInput));\n\n let chunks: string[] = [];\n let streamingStarted = false;\n let toolUses: ToolUse[] = [];\n let currentToolUse: ToolUse | undefined;\n let assistantText = '';\n\n for await (const event of res.stream ?? [])\n {\n\n if (event.modelStreamErrorException)\n {\n throw new Error(event.modelStreamErrorException?.message ?? \"Model stream error\");\n }\n\n if (event.contentBlockDelta?.delta?.text)\n {\n const chunk = event.contentBlockDelta.delta.text;\n assistantText += chunk;\n\n if (!streamingStarted)\n {\n chunks.push(chunk);\n\n if (chunks.length > 20)\n {\n streamingStarted = true;\n await this.streamBufferedText(chunks, options.onChunk!);\n chunks = [];\n }\n }\n else\n {\n options.onChunk?.(chunk);\n }\n }\n\n if (event.contentBlockStart?.start?.toolUse)\n {\n currentToolUse = {\n toolUseId: event.contentBlockStart.start.toolUse.toolUseId as string,\n name: event.contentBlockStart.start.toolUse.name as string,\n inputBuffer: \"\"\n };\n toolUses.push(currentToolUse);\n }\n\n if (currentToolUse && event.contentBlockDelta?.delta?.toolUse?.input)\n {\n currentToolUse.inputBuffer += event.contentBlockDelta.delta.toolUse.input;\n }\n\n if (event.contentBlockStop && currentToolUse?.inputBuffer)\n {\n try\n {\n currentToolUse.input = JSON.parse(currentToolUse.inputBuffer);\n }\n catch (error)\n {\n throw new Error(`Invalid arguments for tool \"${currentToolUse.name}\": ${currentToolUse.inputBuffer}.`);\n }\n\n delete currentToolUse.inputBuffer;\n currentToolUse = undefined;\n }\n\n if (event.messageStop)\n {\n const reason = event.messageStop.stopReason;\n\n if (reason === \"tool_use\")\n {\n\n if (!streamingStarted && chunks.length > 0)\n {\n await options.onThinking?.(chunks.join(\"\"));\n chunks = [];\n }\n\n toolCalls += toolUses.length;\n\n const toolUseMessage = BedrockMessage.toToolUseMessage(assistantText, toolUses);\n currentMessages.push(toolUseMessage);\n if(options?.onTooling) { await options.onTooling(toolUseMessage)}\n\n const { results: toolResults, blocked, stop } = await this.executeTools(toolUses, options);\n\n const toolResultMessage = BedrockMessage.toToolResultMessage(toolResults);\n currentMessages.push(toolResultMessage);\n if(options?.onTooling) { await options.onTooling(toolResultMessage)}\n\n // Stop the turn's tool loop when a call was blocked by authorization\n // (deferred/denied) OR a SIDE-EFFECTING call failed — in either case the\n // model must not re-propose it this turn (a retry risks a duplicate side\n // effect). End the turn with the text so far.\n if(blocked || stop)\n {\n return {\n message: BedrockMessage.toAssistantMessage(assistantText),\n stopReason: \"tool_use\"\n };\n }\n\n break;\n }\n\n if (typeof reason === \"string\")\n {\n if (/content|filter|guardrail/i.test(reason))\n {\n throw new Error(\"Output blocked by content filtering policy: \" + reason);\n }\n else if (reason === \"max_tokens\")\n {\n options.onChunk?.(BedrockAdapter.getResponseFromStopReasonWhenResponseIsEmpty(reason));\n }\n else if (!streamingStarted)\n {\n if (chunks.length > 0)\n {\n await this.streamBufferedText(chunks, options.onChunk!);\n } else\n {\n options.onChunk?.(BedrockAdapter.getResponseFromStopReasonWhenResponseIsEmpty(reason));\n }\n }\n }\n\n return {\n message: BedrockMessage.toAssistantMessage(assistantText),\n stopReason: reason\n };\n }\n }\n }\n else\n {\n const res = await this.client.send(new ConverseCommand(converseCommandInput));\n const text = this.extractAssistantText(res, brMessages);\n\n const content = res?.output?.message?.content ?? [];\n\n if (res.stopReason === \"tool_use\")\n {\n const toolUses = content.filter((c: any) => c.toolUse)\n .map((c: any) => ({\n toolUseId: c.toolUse.toolUseId,\n name: c.toolUse.name,\n input: c.toolUse.input\n }));\n\n toolCalls += toolUses.length;\n\n const toolUseMessage = BedrockMessage.toToolUseMessage(text, toolUses);\n currentMessages.push(toolUseMessage);\n if(options?.onTooling) { await options.onTooling(toolUseMessage)}\n\n const { results: toolResults, blocked, stop } = await this.executeTools(toolUses, options);\n\n const toolResultMessage = BedrockMessage.toToolResultMessage(toolResults);\n currentMessages.push(toolResultMessage);\n if(options?.onTooling) { await options.onTooling(toolResultMessage)}\n\n // Stop on authorization block OR a failed side-effecting call (see streaming path).\n if(blocked || stop)\n {\n return {\n message: BedrockMessage.toAssistantMessage(text),\n stopReason: res.stopReason\n };\n }\n\n continue;\n }\n\n const msg = BedrockMessage.toAssistantMessage(text);\n\n return {\n message: msg,\n stopReason: res.stopReason,\n usage: res.usage\n };\n }\n }\n }\n\n async invoke(messages: Message[], option?: ModelOption): Promise<ResponseMessage>\n {\n const response = await this.runConversationLoop(messages, option?.inference, {\n streaming: false,\n onThinking: option?.event?.onThinking,\n onTooling: option?.event?.onTooling,\n maxToolCalls: option?.maxToolCalls,\n toolsEnabled: option?.toolsEnabled,\n allowedTools: option?.allowedTools,\n authorization: option?.authorization\n },\n option?.instruction);\n\n return new ResponseMessage({\n stopReason: response.stopReason as StopReason,\n tokenUsage: response.usage,\n message: response.message\n });\n }\n\n async stream(messages: Message[], option?: ModelOption): Promise<Readable>\n {\n const out = new PassThrough({ encoding: \"utf8\" });\n\n (async () =>\n {\n try\n {\n await this.runConversationLoop(messages, option?.inference, {\n streaming: true,\n onChunk: c => out.write(c),\n onThinking: option?.event?.onThinking,\n onTooling: option?.event?.onTooling,\n maxToolCalls: option?.maxToolCalls,\n toolsEnabled: option?.toolsEnabled,\n allowedTools: option?.allowedTools,\n authorization: option?.authorization\n },\n option?.instruction);\n\n out.write('');\n out.end();\n }\n catch (e)\n {\n out.emit(\"throw\", e);\n out.write('');\n out.end();\n }\n })();\n\n return out;\n }\n}","import { MessageType, Message, ToolUse, ToolResult } from '@mappies/miniwat-agent-core'\n\nexport default class BedrockMessage extends Message\n{\n constructor(data:Partial<Message>)\n {\n super(data)\n }\n \n public static toAssistantMessage(text: string): Message\n {\n return new Message({\n type: MessageType.Agent,\n content: text,\n createdTimestamp: new Date().toISOString(),\n });\n }\n \n public static toToolUseMessage(text:string, toolUses: ToolUse[]): Message\n {\n return new Message({\n type: MessageType.Agent,\n content: text,\n createdTimestamp: new Date().toISOString(),\n toolUse: toolUses.map(({ toolUseId, name, input }) => (<ToolUse>{ toolUseId, name, input })),\n });\n }\n \n public static toToolResultMessage(toolResult: ToolResult[]): Message\n {\n return new Message({\n type: MessageType.ToolResult,\n toolResult\n });\n }\n}","import { MessageType, Message, Tool, readStructuredToolResult } from '@mappies/miniwat-agent-core'\nimport { Message as BrMessage, StopReason, Tool as BedrockTool } from \"@aws-sdk/client-bedrock-runtime\";\n\nexport class BedrockAdapter\n{\n static toBedrockTool(tool: Tool): BedrockTool\n {\n return {\n toolSpec: {\n name: tool.name,\n description: tool.description,\n inputSchema: { json: tool.schema } as any\n }\n };\n }\n\n static toBedrockMessages(history: Message[], flattenToolHistory = false): BrMessage[]\n {\n return history\n .filter(m =>\n (m.content ?? \"\").trim().length > 0 ||\n (m.toolUse?.length ?? 0) > 0 ||\n (m.toolResult?.length ?? 0) > 0\n )\n .map(m =>\n {\n const role = m.type === MessageType.User || m.type === MessageType.ToolResult\n ? \"user\"\n : \"assistant\";\n\n const content: any[] = [];\n\n if (flattenToolHistory)\n {\n if ((m.content ?? \"\").trim().length > 0)\n {\n content.push({ text: m.content });\n }\n else if (m.toolUse?.length)\n {\n // Frame prior tool activity as COMPLETED history, not an in-progress call.\n // \"Tool result:\" / \"I used the tools\" reads like an ongoing tool exchange and\n // intermittently prompts the model to continue calling tools during FINALIZE\n // (where tools are disabled). A completed-operation framing removes that cue.\n const names = m.toolUse.map(t => t.name).filter(Boolean).join(\", \");\n content.push({ text: names ? `Completed action: ${names}.` : \"Completed an action.\" });\n }\n\n if (m.toolResult?.length)\n {\n content.push(...m.toolResult.map(r => ({\n text: [\n r.status ? \"Outcome: succeeded\" : \"Outcome: failed\",\n `Result: ${this.toolResultToText(r.content)}`\n ].join(\"\\n\")\n })));\n }\n }\n else\n {\n if (m.toolUse?.length)\n {\n content.push(...m.toolUse.map(t => ({ toolUse: t })));\n }\n else if ((m.content ?? \"\").trim().length > 0)\n {\n content.push({ text: m.content });\n }\n\n if (m.toolResult?.length)\n {\n content.push(...m.toolResult.map(r => ({\n toolResult: {\n ...r,\n status: r.status ? \"success\" : \"error\"\n }\n })));\n }\n }\n\n if (content.length === 0)\n {\n content.push({ text: \"\" });\n }\n\n return { role, content };\n });\n }\n\n private static toolResultToText(content: unknown): string\n {\n const maxLength = 12000;\n\n // When the tool returned a StructuredToolResult, ground FINALIZE on its human-readable\n // `text` — NOT the raw JSON. Feeding the model the JSON object invites it to echo the whole\n // {\"succeeded\":...,\"text\":...} blob back as the reply; the `text` is what it should relay.\n const structured = readStructuredToolResult(content);\n if (structured)\n {\n const text = structured.text;\n return text.length > maxLength ? `${text.slice(0, maxLength)}\\n[Tool result truncated]` : text;\n }\n\n const text = !Array.isArray(content)\n ? (typeof content === \"string\" ? content : (JSON.stringify(content) ?? String(content)))\n : content\n .map((item: any) =>\n {\n if (typeof item?.text === \"string\")\n {\n return item.text;\n }\n\n if (item?.json !== undefined)\n {\n return JSON.stringify(item.json);\n }\n\n return JSON.stringify(item);\n })\n .filter(Boolean)\n .join(\"\\n\");\n\n return text.length > maxLength\n ? `${text.slice(0, maxLength)}\\n[Tool result truncated]`\n : text;\n }\n\n static toToolResultContent(result: unknown, status = true): { text?: string; json?: object }[]\n {\n const emptyResultText = status\n ? \"The tool completed successfully but returned no results.\"\n : \"The tool failed and returned no additional error details.\";\n\n try\n {\n if(result instanceof Error)\n {\n const message = result.message.trim();\n return [{ text: message.length > 0 ? message : emptyResultText }];\n }\n\n if(result === null || result === undefined || (typeof result === \"string\" && result.trim().length === 0))\n {\n return [{ text: emptyResultText }];\n }\n\n if(typeof result === \"object\")\n {\n let json = JSON.parse(JSON.stringify(result));\n\n if(Array.isArray(json))\n {\n json = { result: json };\n }\n\n return [{ json }];\n }\n\n return [{ text: String(result) }];\n }\n catch (e: unknown)\n {\n const message = e instanceof Error ? e.message : String(e);\n\n return [{\n json: {\n error: \"Failed to serialize tool result\",\n message\n }\n }];\n }\n }\n\n static getResponseFromStopReasonWhenResponseIsEmpty(stopReason: StopReason): string\n {\n switch (stopReason)\n {\n case \"max_tokens\":\n return \"My response was cut off due to length limits. Would you like me to continue or summarize the remaining information?\";\n case \"stop_sequence\":\n return \"I've reached a natural stopping point in my response. Please let me know if you need additional information.\";\n case \"guardrail_intervened\":\n return \"I'm unable to provide a response to this request as it doesn't align with my usage guidelines. Please rephrase your question or ask something else.\";\n case \"content_filtered\":\n return \"I cannot generate a response for this request due to content policy restrictions. Please try rephrasing your question.\";\n case \"model_context_window_exceeded\":\n return \"The conversation or request is too long for me to process. Please try with a shorter input or start a new conversation.\";\n case \"end_turn\":\n return \"What can I help with?\";\n case \"tool_use\":\n return \"\";\n default:\n return \"I couldn't complete the response. Please try again.\";\n }\n }\n}"],"mappings":";AAAA,SAAS,mBAA6B;AACtC,SAAS,iBAA+G,0BAA0B,mBAAmB,eAAe,+BAA4C;AAChO,SAAoB,sBAAsB;;;ACF1C,SAAS,aAAa,eAAoC;AAE1D,IAAqB,iBAArB,cAA4C,QAC5C;AAAA,EACI,YAAY,MACZ;AACI,UAAM,IAAI;AAAA,EACd;AAAA,EAEA,OAAc,mBAAmB,MACjC;AACI,WAAO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AAA,YACX,SAAS,OAAK,IAAI,MAAM,CAAC;AAAA,YACzB,YAAY,QAAQ,OAAO;AAAA,YAC3B,WAAW,QAAQ,OAAO;AAAA,YAC1B,cAAc,QAAQ;AAAA,YACtB,cAAc,QAAQ;AAAA,YACtB,cAAc,QAAQ;AAAA,YACtB,eAAe,QAAQ;AAAA,UAC3B;AAAA,UACA,QAAQ;AAAA,QAAW;AAEnB,YAAI,MAAM,EAAE;AACZ,YAAI,IAAI;AAAA,MACZ,SACO,GACP;AACI,YAAI,KAAK,SAAS,CAAC;AACnB,YAAI,MAAM,EAAE;AACZ,YAAI,IAAI;AAAA,MACZ;AAAA,IACJ,GAAG;AAEH,WAAO;AAAA,EACX;AACJ;","names":["MessageType","text"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mappies/miniwat-provider-bedrock",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "Bedrock provider for Miniwat",
|
|
5
5
|
"homepage": "https://gitlab.com/mappies/miniwat-provider-bedrock#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@aws-sdk/client-bedrock-runtime": "^3.908.0",
|
|
47
|
-
"@mappies/miniwat-agent-core": "^0.
|
|
48
|
-
"@mappies/miniwat-mcp-core": "^0.
|
|
47
|
+
"@mappies/miniwat-agent-core": "^0.22.0",
|
|
48
|
+
"@mappies/miniwat-mcp-core": "^0.12.0"
|
|
49
49
|
}
|
|
50
50
|
}
|