(toolName: string, toolUseId: string, argsJson: string)
| 60 | } |
| 61 | |
| 62 | function buildToolCallFrames(toolName: string, toolUseId: string, argsJson: string): Buffer[] { |
| 63 | const frames: Buffer[] = [] |
| 64 | frames.push(encodeFrame("messageStart", { role: "assistant" })) |
| 65 | frames.push( |
| 66 | encodeFrame("contentBlockStart", { |
| 67 | contentBlockIndex: 0, |
| 68 | start: { toolUse: { name: toolName, toolUseId } }, |
| 69 | }), |
| 70 | ) |
| 71 | const CHUNK = 20 |
| 72 | for (let i = 0; i < argsJson.length; i += CHUNK) { |
| 73 | frames.push( |
| 74 | encodeFrame("contentBlockDelta", { |
| 75 | contentBlockIndex: 0, |
| 76 | delta: { toolUse: { input: argsJson.slice(i, i + CHUNK) } }, |
| 77 | }), |
| 78 | ) |
| 79 | } |
| 80 | frames.push(encodeFrame("contentBlockStop", { contentBlockIndex: 0 })) |
| 81 | frames.push(encodeFrame("messageStop", { stopReason: "tool_use" })) |
| 82 | frames.push( |
| 83 | encodeFrame("metadata", { |
| 84 | metrics: { latencyMs: 1 }, |
| 85 | usage: { inputTokens: 100, outputTokens: 10, totalTokens: 110, serverToolUsage: {} }, |
| 86 | }), |
| 87 | ) |
| 88 | return frames |
| 89 | } |
| 90 | |
| 91 | export async function startBedrockMockServer(): Promise<BedrockMockServer> { |
| 92 | // HTTP/2 cleartext (h2c) — matches what @aws-sdk/client-bedrock-runtime uses by default. |
no test coverage detected