@copilotkit/aimock 1.19.1 → 1.19.2
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/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +10 -0
- package/dist/agui-types.d.cts.map +1 -1
- package/dist/agui-types.d.ts.map +1 -1
- package/dist/bedrock-converse.cjs +31 -31
- package/dist/bedrock-converse.cjs.map +1 -1
- package/dist/bedrock-converse.d.cts.map +1 -1
- package/dist/bedrock-converse.d.ts.map +1 -1
- package/dist/bedrock-converse.js +31 -31
- package/dist/bedrock-converse.js.map +1 -1
- package/dist/config-loader.d.cts.map +1 -1
- package/dist/helpers.cjs +17 -0
- package/dist/helpers.cjs.map +1 -1
- package/dist/helpers.d.cts.map +1 -1
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.js +17 -0
- package/dist/helpers.js.map +1 -1
- package/dist/ollama.cjs +42 -26
- package/dist/ollama.cjs.map +1 -1
- package/dist/ollama.d.cts.map +1 -1
- package/dist/ollama.d.ts.map +1 -1
- package/dist/ollama.js +42 -26
- package/dist/ollama.js.map +1 -1
- package/dist/responses.cjs +3 -0
- package/dist/responses.cjs.map +1 -1
- package/dist/responses.d.cts.map +1 -1
- package/dist/responses.d.ts.map +1 -1
- package/dist/responses.js +3 -0
- package/dist/responses.js.map +1 -1
- package/dist/types.d.cts +2 -0
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/vector-types.d.cts.map +1 -1
- package/dist/ws-gemini-live.cjs +1 -1
- package/dist/ws-gemini-live.cjs.map +1 -1
- package/dist/ws-gemini-live.js +1 -1
- package/dist/ws-gemini-live.js.map +1 -1
- package/package.json +1 -1
package/dist/bedrock-converse.js
CHANGED
|
@@ -48,65 +48,65 @@ function parseConverseToolArgumentsForStream(toolCall, logger) {
|
|
|
48
48
|
function buildBedrockStreamTextEvents(content, chunkSize, reasoning, overrides) {
|
|
49
49
|
const events = [{
|
|
50
50
|
eventType: "messageStart",
|
|
51
|
-
payload: {
|
|
51
|
+
payload: { role: "assistant" }
|
|
52
52
|
}];
|
|
53
53
|
if (reasoning) {
|
|
54
54
|
const blockIndex = 0;
|
|
55
55
|
events.push({
|
|
56
56
|
eventType: "contentBlockStart",
|
|
57
|
-
payload: {
|
|
57
|
+
payload: {
|
|
58
58
|
contentBlockIndex: blockIndex,
|
|
59
59
|
start: { type: "thinking" }
|
|
60
|
-
}
|
|
60
|
+
}
|
|
61
61
|
});
|
|
62
62
|
for (let i = 0; i < reasoning.length; i += chunkSize) events.push({
|
|
63
63
|
eventType: "contentBlockDelta",
|
|
64
|
-
payload: {
|
|
64
|
+
payload: {
|
|
65
65
|
contentBlockIndex: blockIndex,
|
|
66
66
|
delta: {
|
|
67
67
|
type: "thinking_delta",
|
|
68
68
|
thinking: reasoning.slice(i, i + chunkSize)
|
|
69
69
|
}
|
|
70
|
-
}
|
|
70
|
+
}
|
|
71
71
|
});
|
|
72
72
|
events.push({
|
|
73
73
|
eventType: "contentBlockStop",
|
|
74
|
-
payload: {
|
|
74
|
+
payload: { contentBlockIndex: blockIndex }
|
|
75
75
|
});
|
|
76
76
|
}
|
|
77
77
|
const textBlockIndex = reasoning ? 1 : 0;
|
|
78
78
|
events.push({
|
|
79
79
|
eventType: "contentBlockStart",
|
|
80
|
-
payload: {
|
|
80
|
+
payload: {
|
|
81
81
|
contentBlockIndex: textBlockIndex,
|
|
82
82
|
start: { type: "text" }
|
|
83
|
-
}
|
|
83
|
+
}
|
|
84
84
|
});
|
|
85
85
|
for (let i = 0; i < content.length; i += chunkSize) events.push({
|
|
86
86
|
eventType: "contentBlockDelta",
|
|
87
|
-
payload: {
|
|
87
|
+
payload: {
|
|
88
88
|
contentBlockIndex: textBlockIndex,
|
|
89
89
|
delta: {
|
|
90
90
|
type: "text_delta",
|
|
91
91
|
text: content.slice(i, i + chunkSize)
|
|
92
92
|
}
|
|
93
|
-
}
|
|
93
|
+
}
|
|
94
94
|
});
|
|
95
95
|
events.push({
|
|
96
96
|
eventType: "contentBlockStop",
|
|
97
|
-
payload: {
|
|
97
|
+
payload: { contentBlockIndex: textBlockIndex }
|
|
98
98
|
});
|
|
99
99
|
events.push({
|
|
100
100
|
eventType: "messageStop",
|
|
101
|
-
payload: {
|
|
101
|
+
payload: { stopReason: converseStopReason(overrides?.finishReason, "end_turn") }
|
|
102
102
|
});
|
|
103
103
|
const usage = converseUsage(overrides);
|
|
104
104
|
events.push({
|
|
105
105
|
eventType: "metadata",
|
|
106
|
-
payload: {
|
|
106
|
+
payload: {
|
|
107
107
|
usage,
|
|
108
108
|
metrics: { latencyMs: 0 }
|
|
109
|
-
}
|
|
109
|
+
}
|
|
110
110
|
});
|
|
111
111
|
return events;
|
|
112
112
|
}
|
|
@@ -119,84 +119,84 @@ function buildBedrockStreamContentWithToolCallsEvents(content, toolCalls, chunkS
|
|
|
119
119
|
const toolUseId = tc.id || generateToolUseId();
|
|
120
120
|
events.push({
|
|
121
121
|
eventType: "contentBlockStart",
|
|
122
|
-
payload: {
|
|
122
|
+
payload: {
|
|
123
123
|
contentBlockIndex: blockIndex,
|
|
124
124
|
start: { toolUse: {
|
|
125
125
|
toolUseId,
|
|
126
126
|
name: tc.name
|
|
127
127
|
} }
|
|
128
|
-
}
|
|
128
|
+
}
|
|
129
129
|
});
|
|
130
130
|
const argsStr = parseConverseToolArgumentsForStream(tc, logger);
|
|
131
131
|
for (let i = 0; i < argsStr.length; i += chunkSize) events.push({
|
|
132
132
|
eventType: "contentBlockDelta",
|
|
133
|
-
payload: {
|
|
133
|
+
payload: {
|
|
134
134
|
contentBlockIndex: blockIndex,
|
|
135
135
|
delta: { toolUse: { input: argsStr.slice(i, i + chunkSize) } }
|
|
136
|
-
}
|
|
136
|
+
}
|
|
137
137
|
});
|
|
138
138
|
events.push({
|
|
139
139
|
eventType: "contentBlockStop",
|
|
140
|
-
payload: {
|
|
140
|
+
payload: { contentBlockIndex: blockIndex }
|
|
141
141
|
});
|
|
142
142
|
blockIndex++;
|
|
143
143
|
}
|
|
144
144
|
events.push({
|
|
145
145
|
eventType: "messageStop",
|
|
146
|
-
payload: {
|
|
146
|
+
payload: { stopReason: converseStopReason(overrides?.finishReason, "tool_use") }
|
|
147
147
|
});
|
|
148
148
|
const usage = converseUsage(overrides);
|
|
149
149
|
events.push({
|
|
150
150
|
eventType: "metadata",
|
|
151
|
-
payload: {
|
|
151
|
+
payload: {
|
|
152
152
|
usage,
|
|
153
153
|
metrics: { latencyMs: 0 }
|
|
154
|
-
}
|
|
154
|
+
}
|
|
155
155
|
});
|
|
156
156
|
return events;
|
|
157
157
|
}
|
|
158
158
|
function buildBedrockStreamToolCallEvents(toolCalls, chunkSize, logger, overrides) {
|
|
159
159
|
const events = [{
|
|
160
160
|
eventType: "messageStart",
|
|
161
|
-
payload: {
|
|
161
|
+
payload: { role: "assistant" }
|
|
162
162
|
}];
|
|
163
163
|
for (let tcIdx = 0; tcIdx < toolCalls.length; tcIdx++) {
|
|
164
164
|
const tc = toolCalls[tcIdx];
|
|
165
165
|
const toolUseId = tc.id || generateToolUseId();
|
|
166
166
|
events.push({
|
|
167
167
|
eventType: "contentBlockStart",
|
|
168
|
-
payload: {
|
|
168
|
+
payload: {
|
|
169
169
|
contentBlockIndex: tcIdx,
|
|
170
170
|
start: { toolUse: {
|
|
171
171
|
toolUseId,
|
|
172
172
|
name: tc.name
|
|
173
173
|
} }
|
|
174
|
-
}
|
|
174
|
+
}
|
|
175
175
|
});
|
|
176
176
|
const argsStr = parseConverseToolArgumentsForStream(tc, logger);
|
|
177
177
|
for (let i = 0; i < argsStr.length; i += chunkSize) events.push({
|
|
178
178
|
eventType: "contentBlockDelta",
|
|
179
|
-
payload: {
|
|
179
|
+
payload: {
|
|
180
180
|
contentBlockIndex: tcIdx,
|
|
181
181
|
delta: { toolUse: { input: argsStr.slice(i, i + chunkSize) } }
|
|
182
|
-
}
|
|
182
|
+
}
|
|
183
183
|
});
|
|
184
184
|
events.push({
|
|
185
185
|
eventType: "contentBlockStop",
|
|
186
|
-
payload: {
|
|
186
|
+
payload: { contentBlockIndex: tcIdx }
|
|
187
187
|
});
|
|
188
188
|
}
|
|
189
189
|
events.push({
|
|
190
190
|
eventType: "messageStop",
|
|
191
|
-
payload: {
|
|
191
|
+
payload: { stopReason: converseStopReason(overrides?.finishReason, "tool_use") }
|
|
192
192
|
});
|
|
193
193
|
const usage = converseUsage(overrides);
|
|
194
194
|
events.push({
|
|
195
195
|
eventType: "metadata",
|
|
196
|
-
payload: {
|
|
196
|
+
payload: {
|
|
197
197
|
usage,
|
|
198
198
|
metrics: { latencyMs: 0 }
|
|
199
|
-
}
|
|
199
|
+
}
|
|
200
200
|
});
|
|
201
201
|
return events;
|
|
202
202
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bedrock-converse.js","names":[],"sources":["../src/bedrock-converse.ts"],"sourcesContent":["/**\n * AWS Bedrock Converse API support.\n *\n * Translates incoming Converse and Converse-stream requests (Bedrock Converse\n * format) into the ChatCompletionRequest format used by the fixture router,\n * and converts fixture responses back into Converse API format — either a\n * single JSON response or an Event Stream binary stream.\n */\n\nimport type * as http from \"node:http\";\nimport type {\n ChatCompletionRequest,\n ChatMessage,\n Fixture,\n HandlerDefaults,\n ResponseOverrides,\n ToolCall,\n ToolDefinition,\n} from \"./types.js\";\nimport {\n generateToolUseId,\n extractOverrides,\n isTextResponse,\n isToolCallResponse,\n isContentWithToolCallsResponse,\n isErrorResponse,\n flattenHeaders,\n getTestId,\n resolveResponse,\n} from \"./helpers.js\";\nimport { matchFixture } from \"./router.js\";\nimport { writeErrorResponse } from \"./sse-writer.js\";\nimport { writeEventStream } from \"./aws-event-stream.js\";\nimport { createInterruptionSignal } from \"./interruption.js\";\nimport type { Journal } from \"./journal.js\";\nimport type { Logger } from \"./logger.js\";\nimport { applyChaos } from \"./chaos.js\";\nimport { proxyAndRecord } from \"./recorder.js\";\n\n// ─── Converse request types ─────────────────────────────────────────────────\n\ninterface ConverseContentBlock {\n text?: string;\n toolUse?: { toolUseId: string; name: string; input: object };\n toolResult?: { toolUseId: string; content: { text?: string }[] };\n}\n\ninterface ConverseMessage {\n role: \"user\" | \"assistant\";\n content: ConverseContentBlock[];\n}\n\ninterface ConverseToolSpec {\n name: string;\n description?: string;\n inputSchema?: object;\n}\n\ninterface ConverseRequest {\n messages: ConverseMessage[];\n system?: { text: string }[];\n inferenceConfig?: { maxTokens?: number; temperature?: number };\n toolConfig?: { tools: { toolSpec: ConverseToolSpec }[] };\n}\n\n// ─── Converse stop_reason mapping ──────────────────────────────────────────\n\nfunction converseStopReason(\n overrideFinishReason: string | undefined,\n defaultReason: string,\n): string {\n if (!overrideFinishReason) return defaultReason;\n if (overrideFinishReason === \"stop\") return \"end_turn\";\n if (overrideFinishReason === \"tool_calls\") return \"tool_use\";\n if (overrideFinishReason === \"length\") return \"max_tokens\";\n return overrideFinishReason;\n}\n\n/**\n * Build Converse-format usage from fixture overrides.\n *\n * When no overrides are provided (the common case for mocks), all token\n * counts default to zero. This is intentional — aimock is a mock server\n * and does not perform real tokenisation. Callers that need non-zero\n * usage should supply explicit `usage` overrides in their fixture.\n */\nfunction converseUsage(overrides?: ResponseOverrides): {\n inputTokens: number;\n outputTokens: number;\n totalTokens: number;\n} {\n if (!overrides?.usage) return { inputTokens: 0, outputTokens: 0, totalTokens: 0 };\n const inputTokens = overrides.usage.input_tokens ?? overrides.usage.prompt_tokens ?? 0;\n const outputTokens = overrides.usage.output_tokens ?? overrides.usage.completion_tokens ?? 0;\n return { inputTokens, outputTokens, totalTokens: inputTokens + outputTokens };\n}\n\nfunction parseConverseToolArgumentsForStream(toolCall: ToolCall, logger: Logger): string {\n try {\n const parsed = JSON.parse(toolCall.arguments || \"{}\");\n return JSON.stringify(parsed);\n } catch {\n logger.warn(\n `Malformed JSON in fixture tool call arguments for \"${toolCall.name}\": ${toolCall.arguments}`,\n );\n return \"{}\";\n }\n}\n\nfunction buildBedrockStreamTextEvents(\n content: string,\n chunkSize: number,\n reasoning?: string,\n overrides?: ResponseOverrides,\n): Array<{ eventType: string; payload: object }> {\n const events: Array<{ eventType: string; payload: object }> = [\n { eventType: \"messageStart\", payload: { messageStart: { role: \"assistant\" } } },\n ];\n\n if (reasoning) {\n const blockIndex = 0;\n events.push({\n eventType: \"contentBlockStart\",\n payload: {\n contentBlockStart: { contentBlockIndex: blockIndex, start: { type: \"thinking\" } },\n },\n });\n for (let i = 0; i < reasoning.length; i += chunkSize) {\n events.push({\n eventType: \"contentBlockDelta\",\n payload: {\n contentBlockDelta: {\n contentBlockIndex: blockIndex,\n delta: { type: \"thinking_delta\", thinking: reasoning.slice(i, i + chunkSize) },\n },\n },\n });\n }\n events.push({\n eventType: \"contentBlockStop\",\n payload: { contentBlockStop: { contentBlockIndex: blockIndex } },\n });\n }\n\n const textBlockIndex = reasoning ? 1 : 0;\n events.push({\n eventType: \"contentBlockStart\",\n payload: {\n contentBlockStart: { contentBlockIndex: textBlockIndex, start: { type: \"text\" } },\n },\n });\n for (let i = 0; i < content.length; i += chunkSize) {\n events.push({\n eventType: \"contentBlockDelta\",\n payload: {\n contentBlockDelta: {\n contentBlockIndex: textBlockIndex,\n delta: { type: \"text_delta\", text: content.slice(i, i + chunkSize) },\n },\n },\n });\n }\n events.push({\n eventType: \"contentBlockStop\",\n payload: { contentBlockStop: { contentBlockIndex: textBlockIndex } },\n });\n events.push({\n eventType: \"messageStop\",\n payload: {\n messageStop: { stopReason: converseStopReason(overrides?.finishReason, \"end_turn\") },\n },\n });\n const usage = converseUsage(overrides);\n events.push({\n eventType: \"metadata\",\n payload: { metadata: { usage, metrics: { latencyMs: 0 } } },\n });\n return events;\n}\n\nfunction buildBedrockStreamContentWithToolCallsEvents(\n content: string,\n toolCalls: ToolCall[],\n chunkSize: number,\n logger: Logger,\n reasoning?: string,\n overrides?: ResponseOverrides,\n): Array<{ eventType: string; payload: object }> {\n const events = buildBedrockStreamTextEvents(content, chunkSize, reasoning, overrides);\n // Remove trailing metadata + messageStop events — we re-emit them after tool blocks\n events.pop(); // metadata\n events.pop(); // messageStop\n let blockIndex = reasoning ? 2 : 1;\n\n for (const tc of toolCalls) {\n const toolUseId = tc.id || generateToolUseId();\n events.push({\n eventType: \"contentBlockStart\",\n payload: {\n contentBlockStart: {\n contentBlockIndex: blockIndex,\n start: { toolUse: { toolUseId, name: tc.name } },\n },\n },\n });\n const argsStr = parseConverseToolArgumentsForStream(tc, logger);\n for (let i = 0; i < argsStr.length; i += chunkSize) {\n events.push({\n eventType: \"contentBlockDelta\",\n payload: {\n contentBlockDelta: {\n contentBlockIndex: blockIndex,\n delta: { toolUse: { input: argsStr.slice(i, i + chunkSize) } },\n },\n },\n });\n }\n events.push({\n eventType: \"contentBlockStop\",\n payload: { contentBlockStop: { contentBlockIndex: blockIndex } },\n });\n blockIndex++;\n }\n events.push({\n eventType: \"messageStop\",\n payload: {\n messageStop: { stopReason: converseStopReason(overrides?.finishReason, \"tool_use\") },\n },\n });\n const usage = converseUsage(overrides);\n events.push({\n eventType: \"metadata\",\n payload: { metadata: { usage, metrics: { latencyMs: 0 } } },\n });\n return events;\n}\n\nfunction buildBedrockStreamToolCallEvents(\n toolCalls: ToolCall[],\n chunkSize: number,\n logger: Logger,\n overrides?: ResponseOverrides,\n): Array<{ eventType: string; payload: object }> {\n const events: Array<{ eventType: string; payload: object }> = [\n { eventType: \"messageStart\", payload: { messageStart: { role: \"assistant\" } } },\n ];\n\n for (let tcIdx = 0; tcIdx < toolCalls.length; tcIdx++) {\n const tc = toolCalls[tcIdx];\n const toolUseId = tc.id || generateToolUseId();\n events.push({\n eventType: \"contentBlockStart\",\n payload: {\n contentBlockStart: {\n contentBlockIndex: tcIdx,\n start: { toolUse: { toolUseId, name: tc.name } },\n },\n },\n });\n const argsStr = parseConverseToolArgumentsForStream(tc, logger);\n for (let i = 0; i < argsStr.length; i += chunkSize) {\n events.push({\n eventType: \"contentBlockDelta\",\n payload: {\n contentBlockDelta: {\n contentBlockIndex: tcIdx,\n delta: { toolUse: { input: argsStr.slice(i, i + chunkSize) } },\n },\n },\n });\n }\n events.push({\n eventType: \"contentBlockStop\",\n payload: { contentBlockStop: { contentBlockIndex: tcIdx } },\n });\n }\n events.push({\n eventType: \"messageStop\",\n payload: {\n messageStop: { stopReason: converseStopReason(overrides?.finishReason, \"tool_use\") },\n },\n });\n const usage = converseUsage(overrides);\n events.push({\n eventType: \"metadata\",\n payload: { metadata: { usage, metrics: { latencyMs: 0 } } },\n });\n return events;\n}\n\n// ─── Input conversion: Converse → ChatCompletionRequest ─────────────────────\n\nexport function converseToCompletionRequest(\n req: ConverseRequest,\n modelId: string,\n logger?: Logger,\n): ChatCompletionRequest {\n const messages: ChatMessage[] = [];\n\n // system field → system message\n if (req.system && req.system.length > 0) {\n const systemText = req.system.map((s) => s.text).join(\"\");\n if (systemText) {\n messages.push({ role: \"system\", content: systemText });\n }\n }\n\n for (const msg of req.messages) {\n if (msg.role === \"user\") {\n // Check for toolResult blocks\n const toolResults = msg.content.filter((b) => b.toolResult);\n const textBlocks = msg.content.filter(\n (b) => b.text !== undefined && b.text !== \"\" && !b.toolResult,\n );\n const unsupportedBlocks = msg.content.filter(\n (b) => b.text === undefined && !b.toolResult && !b.toolUse,\n );\n if (unsupportedBlocks.length > 0 && logger) {\n logger.warn(\n `Converse user message contains unsupported content block types — these will be dropped during conversion`,\n );\n }\n\n if (toolResults.length > 0) {\n for (const block of toolResults) {\n const tr = block.toolResult!;\n const resultContent = tr.content.map((c) => c.text ?? \"\").join(\"\");\n messages.push({\n role: \"tool\",\n content: resultContent,\n tool_call_id: tr.toolUseId,\n });\n }\n if (textBlocks.length > 0) {\n messages.push({\n role: \"user\",\n content: textBlocks.map((b) => b.text ?? \"\").join(\"\"),\n });\n }\n continue;\n }\n\n // Plain user message\n const text = msg.content\n .filter((b) => b.text !== undefined && b.text !== \"\")\n .map((b) => b.text ?? \"\")\n .join(\"\");\n messages.push({ role: \"user\", content: text });\n } else if (msg.role === \"assistant\") {\n const toolUseBlocks = msg.content.filter((b) => b.toolUse);\n const textContent = msg.content\n .filter((b) => b.text !== undefined && b.text !== \"\")\n .map((b) => b.text ?? \"\")\n .join(\"\");\n\n if (toolUseBlocks.length > 0) {\n messages.push({\n role: \"assistant\",\n content: textContent ?? null,\n tool_calls: toolUseBlocks.map((b) => ({\n id: b.toolUse!.toolUseId,\n type: \"function\" as const,\n function: {\n name: b.toolUse!.name,\n arguments: JSON.stringify(b.toolUse!.input),\n },\n })),\n });\n } else {\n messages.push({ role: \"assistant\", content: textContent ?? null });\n }\n } else {\n const warnMsg = `Unexpected message role \"${msg.role}\" in Converse request — skipping`;\n if (logger) {\n logger.warn(warnMsg);\n }\n }\n }\n\n // Convert tools\n let tools: ToolDefinition[] | undefined;\n if (req.toolConfig?.tools && req.toolConfig.tools.length > 0) {\n tools = req.toolConfig.tools.map((t) => ({\n type: \"function\" as const,\n function: {\n name: t.toolSpec.name,\n description: t.toolSpec.description,\n parameters: (t.toolSpec.inputSchema && \"json\" in t.toolSpec.inputSchema\n ? (t.toolSpec.inputSchema as Record<string, unknown>).json\n : t.toolSpec.inputSchema) as object | undefined,\n },\n }));\n }\n\n return {\n model: modelId,\n messages,\n stream: false,\n temperature: req.inferenceConfig?.temperature,\n tools,\n };\n}\n\n// ─── Response builders ──────────────────────────────────────────────────────\n\nfunction buildConverseTextResponse(\n content: string,\n reasoning?: string,\n overrides?: ResponseOverrides,\n): object {\n const contentBlocks: object[] = [];\n if (reasoning) {\n contentBlocks.push({\n reasoningContent: { reasoningText: { text: reasoning } },\n });\n }\n contentBlocks.push({ text: content });\n\n return {\n output: {\n message: {\n role: \"assistant\",\n content: contentBlocks,\n },\n },\n stopReason: converseStopReason(overrides?.finishReason, \"end_turn\"),\n usage: converseUsage(overrides),\n };\n}\n\nfunction buildConverseToolCallResponse(\n toolCalls: ToolCall[],\n logger: Logger,\n overrides?: ResponseOverrides,\n): object {\n return {\n output: {\n message: {\n role: \"assistant\",\n content: toolCalls.map((tc) => {\n let argsObj: unknown;\n try {\n argsObj = JSON.parse(tc.arguments || \"{}\");\n } catch {\n logger.warn(\n `Malformed JSON in fixture tool call arguments for \"${tc.name}\": ${tc.arguments}`,\n );\n argsObj = {};\n }\n return {\n toolUse: {\n toolUseId: tc.id || generateToolUseId(),\n name: tc.name,\n input: argsObj,\n },\n };\n }),\n },\n },\n stopReason: converseStopReason(overrides?.finishReason, \"tool_use\"),\n usage: converseUsage(overrides),\n };\n}\n\nfunction buildConverseContentWithToolCallsResponse(\n content: string,\n toolCalls: ToolCall[],\n logger: Logger,\n reasoning?: string,\n overrides?: ResponseOverrides,\n): object {\n const contentBlocks: object[] = [];\n if (reasoning) {\n contentBlocks.push({\n reasoningContent: { reasoningText: { text: reasoning } },\n });\n }\n contentBlocks.push({ text: content });\n for (const tc of toolCalls) {\n let argsObj: unknown;\n try {\n argsObj = JSON.parse(tc.arguments || \"{}\");\n } catch {\n logger.warn(\n `Malformed JSON in fixture tool call arguments for \"${tc.name}\": ${tc.arguments}`,\n );\n argsObj = {};\n }\n contentBlocks.push({\n toolUse: {\n toolUseId: tc.id || generateToolUseId(),\n name: tc.name,\n input: argsObj,\n },\n });\n }\n\n return {\n output: {\n message: {\n role: \"assistant\",\n content: contentBlocks,\n },\n },\n stopReason: converseStopReason(overrides?.finishReason, \"tool_use\"),\n usage: converseUsage(overrides),\n };\n}\n\n// ─── Request handlers ───────────────────────────────────────────────────────\n\nexport async function handleConverse(\n req: http.IncomingMessage,\n res: http.ServerResponse,\n raw: string,\n modelId: string,\n fixtures: Fixture[],\n journal: Journal,\n defaults: HandlerDefaults,\n setCorsHeaders: (res: http.ServerResponse) => void,\n): Promise<void> {\n const { logger } = defaults;\n setCorsHeaders(res);\n\n const urlPath = req.url ?? `/model/${modelId}/converse`;\n\n let converseReq: ConverseRequest;\n try {\n converseReq = JSON.parse(raw) as ConverseRequest;\n } catch {\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: null,\n response: { status: 400, fixture: null },\n });\n writeErrorResponse(\n res,\n 400,\n JSON.stringify({\n error: {\n message: \"Malformed JSON\",\n type: \"invalid_request_error\",\n },\n }),\n );\n return;\n }\n\n if (!converseReq.messages || !Array.isArray(converseReq.messages)) {\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: null,\n response: { status: 400, fixture: null },\n });\n writeErrorResponse(\n res,\n 400,\n JSON.stringify({\n error: {\n message: \"Invalid request: messages array is required\",\n type: \"invalid_request_error\",\n },\n }),\n );\n return;\n }\n\n const completionReq = converseToCompletionRequest(converseReq, modelId, logger);\n completionReq._endpointType = \"chat\";\n\n const testId = getTestId(req);\n const fixture = matchFixture(\n fixtures,\n completionReq,\n journal.getFixtureMatchCountsForTest(testId),\n defaults.requestTransform,\n );\n\n if (fixture) {\n logger.debug(`Fixture matched: ${JSON.stringify(fixture.match).slice(0, 120)}`);\n } else {\n logger.debug(`No fixture matched for request`);\n }\n\n if (fixture) {\n journal.incrementFixtureMatchCount(fixture, fixtures, testId);\n }\n\n if (\n applyChaos(\n res,\n fixture,\n defaults.chaos,\n req.headers,\n journal,\n {\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n },\n fixture ? \"fixture\" : \"proxy\",\n defaults.registry,\n defaults.logger,\n )\n )\n return;\n\n if (!fixture) {\n if (defaults.record) {\n const outcome = await proxyAndRecord(\n req,\n res,\n completionReq,\n \"bedrock\",\n urlPath,\n fixtures,\n defaults,\n raw,\n );\n if (outcome !== \"not_configured\") {\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: res.statusCode ?? 200, fixture: null, source: \"proxy\" },\n });\n return;\n }\n }\n const strictStatus = defaults.strict ? 503 : 404;\n const strictMessage = defaults.strict\n ? \"Strict mode: no fixture matched\"\n : \"No fixture matched\";\n if (defaults.strict) {\n logger.error(`STRICT: No fixture matched for ${req.method ?? \"POST\"} ${urlPath}`);\n }\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: strictStatus, fixture: null },\n });\n writeErrorResponse(\n res,\n strictStatus,\n JSON.stringify({\n error: {\n message: strictMessage,\n type: \"invalid_request_error\",\n },\n }),\n );\n return;\n }\n\n const response = await resolveResponse(fixture, completionReq);\n\n // Error response\n if (isErrorResponse(response)) {\n const status = response.status ?? 500;\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status, fixture },\n });\n const errBody = {\n type: \"error\",\n error: {\n type: response.error.type ?? \"invalid_request_error\",\n message: response.error.message,\n },\n };\n writeErrorResponse(res, status, JSON.stringify(errBody));\n return;\n }\n\n // Content + tool calls response\n if (isContentWithToolCallsResponse(response)) {\n if (response.webSearches?.length) {\n logger.warn(\n \"webSearches in fixture response are not supported for Bedrock Converse API — ignoring\",\n );\n }\n const overrides = extractOverrides(response);\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: 200, fixture },\n });\n const body = buildConverseContentWithToolCallsResponse(\n response.content,\n response.toolCalls,\n logger,\n response.reasoning,\n overrides,\n );\n res.writeHead(200, { \"Content-Type\": \"application/json\" });\n res.end(JSON.stringify(body));\n return;\n }\n\n // Text response\n if (isTextResponse(response)) {\n if (response.webSearches?.length) {\n logger.warn(\n \"webSearches in fixture response are not supported for Bedrock Converse API — ignoring\",\n );\n }\n const overrides = extractOverrides(response);\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: 200, fixture },\n });\n const body = buildConverseTextResponse(response.content, response.reasoning, overrides);\n res.writeHead(200, { \"Content-Type\": \"application/json\" });\n res.end(JSON.stringify(body));\n return;\n }\n\n // Tool call response\n if (isToolCallResponse(response)) {\n if (\"webSearches\" in response) {\n logger.warn(\n \"webSearches in fixture response are not supported for Bedrock Converse API — ignoring\",\n );\n }\n const overrides = extractOverrides(response);\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: 200, fixture },\n });\n const body = buildConverseToolCallResponse(response.toolCalls, logger, overrides);\n res.writeHead(200, { \"Content-Type\": \"application/json\" });\n res.end(JSON.stringify(body));\n return;\n }\n\n // Unknown response type\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: 500, fixture },\n });\n writeErrorResponse(\n res,\n 500,\n JSON.stringify({\n error: {\n message: \"Fixture response did not match any known type\",\n type: \"server_error\",\n },\n }),\n );\n}\n\nexport async function handleConverseStream(\n req: http.IncomingMessage,\n res: http.ServerResponse,\n raw: string,\n modelId: string,\n fixtures: Fixture[],\n journal: Journal,\n defaults: HandlerDefaults,\n setCorsHeaders: (res: http.ServerResponse) => void,\n): Promise<void> {\n const { logger } = defaults;\n setCorsHeaders(res);\n\n const urlPath = req.url ?? `/model/${modelId}/converse-stream`;\n\n let converseReq: ConverseRequest;\n try {\n converseReq = JSON.parse(raw) as ConverseRequest;\n } catch {\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: null,\n response: { status: 400, fixture: null },\n });\n writeErrorResponse(\n res,\n 400,\n JSON.stringify({\n error: {\n message: \"Malformed JSON\",\n type: \"invalid_request_error\",\n },\n }),\n );\n return;\n }\n\n if (!converseReq.messages || !Array.isArray(converseReq.messages)) {\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: null,\n response: { status: 400, fixture: null },\n });\n writeErrorResponse(\n res,\n 400,\n JSON.stringify({\n error: {\n message: \"Invalid request: messages array is required\",\n type: \"invalid_request_error\",\n },\n }),\n );\n return;\n }\n\n const completionReq = converseToCompletionRequest(converseReq, modelId, logger);\n completionReq.stream = true;\n completionReq._endpointType = \"chat\";\n\n const testId = getTestId(req);\n const fixture = matchFixture(\n fixtures,\n completionReq,\n journal.getFixtureMatchCountsForTest(testId),\n defaults.requestTransform,\n );\n\n if (fixture) {\n logger.debug(`Fixture matched: ${JSON.stringify(fixture.match).slice(0, 120)}`);\n } else {\n logger.debug(`No fixture matched for request`);\n }\n\n if (fixture) {\n journal.incrementFixtureMatchCount(fixture, fixtures, testId);\n }\n\n if (\n applyChaos(\n res,\n fixture,\n defaults.chaos,\n req.headers,\n journal,\n {\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n },\n fixture ? \"fixture\" : \"proxy\",\n defaults.registry,\n defaults.logger,\n )\n )\n return;\n\n if (!fixture) {\n if (defaults.record) {\n const outcome = await proxyAndRecord(\n req,\n res,\n completionReq,\n \"bedrock\",\n urlPath,\n fixtures,\n defaults,\n raw,\n );\n if (outcome !== \"not_configured\") {\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: res.statusCode ?? 200, fixture: null, source: \"proxy\" },\n });\n return;\n }\n }\n const strictStatus = defaults.strict ? 503 : 404;\n const strictMessage = defaults.strict\n ? \"Strict mode: no fixture matched\"\n : \"No fixture matched\";\n if (defaults.strict) {\n logger.error(`STRICT: No fixture matched for ${req.method ?? \"POST\"} ${urlPath}`);\n }\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: strictStatus, fixture: null },\n });\n writeErrorResponse(\n res,\n strictStatus,\n JSON.stringify({\n error: {\n message: strictMessage,\n type: \"invalid_request_error\",\n },\n }),\n );\n return;\n }\n\n const response = await resolveResponse(fixture, completionReq);\n const latency = fixture.latency ?? defaults.latency;\n const chunkSize = Math.max(1, fixture.chunkSize ?? defaults.chunkSize);\n\n // Error response\n if (isErrorResponse(response)) {\n const status = response.status ?? 500;\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status, fixture },\n });\n const errBody = {\n type: \"error\",\n error: {\n type: response.error.type ?? \"invalid_request_error\",\n message: response.error.message,\n },\n };\n writeErrorResponse(res, status, JSON.stringify(errBody));\n return;\n }\n\n // Content + tool calls response — stream as Event Stream\n if (isContentWithToolCallsResponse(response)) {\n if (response.webSearches?.length) {\n logger.warn(\n \"webSearches in fixture response are not supported for Bedrock Converse API — ignoring\",\n );\n }\n const overrides = extractOverrides(response);\n const journalEntry = journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: 200, fixture },\n });\n const events = buildBedrockStreamContentWithToolCallsEvents(\n response.content,\n response.toolCalls,\n chunkSize,\n logger,\n response.reasoning,\n overrides,\n );\n const interruption = createInterruptionSignal(fixture);\n const completed = await writeEventStream(res, events, {\n latency,\n streamingProfile: fixture.streamingProfile,\n signal: interruption?.signal,\n onChunkSent: interruption?.tick,\n });\n if (!completed) {\n if (!res.writableEnded) res.destroy();\n journalEntry.response.interrupted = true;\n journalEntry.response.interruptReason = interruption?.reason();\n }\n interruption?.cleanup();\n return;\n }\n\n // Text response — stream as Event Stream\n if (isTextResponse(response)) {\n if (response.webSearches?.length) {\n logger.warn(\n \"webSearches in fixture response are not supported for Bedrock Converse API — ignoring\",\n );\n }\n const overrides = extractOverrides(response);\n const journalEntry = journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: 200, fixture },\n });\n const events = buildBedrockStreamTextEvents(\n response.content,\n chunkSize,\n response.reasoning,\n overrides,\n );\n const interruption = createInterruptionSignal(fixture);\n const completed = await writeEventStream(res, events, {\n latency,\n streamingProfile: fixture.streamingProfile,\n signal: interruption?.signal,\n onChunkSent: interruption?.tick,\n });\n if (!completed) {\n if (!res.writableEnded) res.destroy();\n journalEntry.response.interrupted = true;\n journalEntry.response.interruptReason = interruption?.reason();\n }\n interruption?.cleanup();\n return;\n }\n\n // Tool call response — stream as Event Stream\n if (isToolCallResponse(response)) {\n if (\"webSearches\" in response) {\n logger.warn(\n \"webSearches in fixture response are not supported for Bedrock Converse API — ignoring\",\n );\n }\n const overrides = extractOverrides(response);\n const journalEntry = journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: 200, fixture },\n });\n const events = buildBedrockStreamToolCallEvents(\n response.toolCalls,\n chunkSize,\n logger,\n overrides,\n );\n const interruption = createInterruptionSignal(fixture);\n const completed = await writeEventStream(res, events, {\n latency,\n streamingProfile: fixture.streamingProfile,\n signal: interruption?.signal,\n onChunkSent: interruption?.tick,\n });\n if (!completed) {\n if (!res.writableEnded) res.destroy();\n journalEntry.response.interrupted = true;\n journalEntry.response.interruptReason = interruption?.reason();\n }\n interruption?.cleanup();\n return;\n }\n\n // Unknown response type\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: 500, fixture },\n });\n writeErrorResponse(\n res,\n 500,\n JSON.stringify({\n error: {\n message: \"Fixture response did not match any known type\",\n type: \"server_error\",\n },\n }),\n );\n}\n"],"mappings":";;;;;;;;;AAmEA,SAAS,mBACP,sBACA,eACQ;AACR,KAAI,CAAC,qBAAsB,QAAO;AAClC,KAAI,yBAAyB,OAAQ,QAAO;AAC5C,KAAI,yBAAyB,aAAc,QAAO;AAClD,KAAI,yBAAyB,SAAU,QAAO;AAC9C,QAAO;;;;;;;;;;AAWT,SAAS,cAAc,WAIrB;AACA,KAAI,CAAC,WAAW,MAAO,QAAO;EAAE,aAAa;EAAG,cAAc;EAAG,aAAa;EAAG;CACjF,MAAM,cAAc,UAAU,MAAM,gBAAgB,UAAU,MAAM,iBAAiB;CACrF,MAAM,eAAe,UAAU,MAAM,iBAAiB,UAAU,MAAM,qBAAqB;AAC3F,QA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Aa,SAAS,kBAAkB,cAAc,QAAQ;;AAEhE,gBAAc,SAAS;AACvB;;AAIF,KAAI,mBAAmB,SAAS,EAAE;AAChC,MAAI,iBAAiB,SACnB,QAAO,KACL,wFACD;EAEH,MAAM,YAAY,iBAAiB,SAAS;EAC5C,MAAM,eAAe,QAAQ,IAAI;GAC/B,QAAQ,IAAI,UAAU;GACtB,MAAM;GACN,SAAS,eAAe,IAAI,QAAQ;GACpC,MAAM;GACN,UAAU;IAAE,QAAQ;IAAK;IAAS;GACnC,CAAC;EACF,MAAM,SAAS,iCACb,SAAS,WACT,WACA,QACA,UACD;EACD,MAAM,eAAe,yBAAyB,QAAQ;AAOtD,MAAI,CANc,MAAM,iBAAiB,KAAK,QAAQ;GACpD;GACA,kBAAkB,QAAQ;GAC1B,QAAQ,cAAc;GACtB,aAAa,cAAc;GAC5B,CAAC,EACc;AACd,OAAI,CAAC,IAAI,cAAe,KAAI,SAAS;AACrC,gBAAa,SAAS,cAAc;AACpC,gBAAa,SAAS,kBAAkB,cAAc,QAAQ;;AAEhE,gBAAc,SAAS;AACvB;;AAIF,SAAQ,IAAI;EACV,QAAQ,IAAI,UAAU;EACtB,MAAM;EACN,SAAS,eAAe,IAAI,QAAQ;EACpC,MAAM;EACN,UAAU;GAAE,QAAQ;GAAK;GAAS;EACnC,CAAC;AACF,oBACE,KACA,KACA,KAAK,UAAU,EACb,OAAO;EACL,SAAS;EACT,MAAM;EACP,EACF,CAAC,CACH"}
|
|
1
|
+
{"version":3,"file":"bedrock-converse.js","names":[],"sources":["../src/bedrock-converse.ts"],"sourcesContent":["/**\n * AWS Bedrock Converse API support.\n *\n * Translates incoming Converse and Converse-stream requests (Bedrock Converse\n * format) into the ChatCompletionRequest format used by the fixture router,\n * and converts fixture responses back into Converse API format — either a\n * single JSON response or an Event Stream binary stream.\n */\n\nimport type * as http from \"node:http\";\nimport type {\n ChatCompletionRequest,\n ChatMessage,\n Fixture,\n HandlerDefaults,\n ResponseOverrides,\n ToolCall,\n ToolDefinition,\n} from \"./types.js\";\nimport {\n generateToolUseId,\n extractOverrides,\n isTextResponse,\n isToolCallResponse,\n isContentWithToolCallsResponse,\n isErrorResponse,\n flattenHeaders,\n getTestId,\n resolveResponse,\n} from \"./helpers.js\";\nimport { matchFixture } from \"./router.js\";\nimport { writeErrorResponse } from \"./sse-writer.js\";\nimport { writeEventStream } from \"./aws-event-stream.js\";\nimport { createInterruptionSignal } from \"./interruption.js\";\nimport type { Journal } from \"./journal.js\";\nimport type { Logger } from \"./logger.js\";\nimport { applyChaos } from \"./chaos.js\";\nimport { proxyAndRecord } from \"./recorder.js\";\n\n// ─── Converse request types ─────────────────────────────────────────────────\n\ninterface ConverseContentBlock {\n text?: string;\n toolUse?: { toolUseId: string; name: string; input: object };\n toolResult?: { toolUseId: string; content: { text?: string }[] };\n}\n\ninterface ConverseMessage {\n role: \"user\" | \"assistant\";\n content: ConverseContentBlock[];\n}\n\ninterface ConverseToolSpec {\n name: string;\n description?: string;\n inputSchema?: object;\n}\n\ninterface ConverseRequest {\n messages: ConverseMessage[];\n system?: { text: string }[];\n inferenceConfig?: { maxTokens?: number; temperature?: number };\n toolConfig?: { tools: { toolSpec: ConverseToolSpec }[] };\n}\n\n// ─── Converse stop_reason mapping ──────────────────────────────────────────\n\nfunction converseStopReason(\n overrideFinishReason: string | undefined,\n defaultReason: string,\n): string {\n if (!overrideFinishReason) return defaultReason;\n if (overrideFinishReason === \"stop\") return \"end_turn\";\n if (overrideFinishReason === \"tool_calls\") return \"tool_use\";\n if (overrideFinishReason === \"length\") return \"max_tokens\";\n return overrideFinishReason;\n}\n\n/**\n * Build Converse-format usage from fixture overrides.\n *\n * When no overrides are provided (the common case for mocks), all token\n * counts default to zero. This is intentional — aimock is a mock server\n * and does not perform real tokenisation. Callers that need non-zero\n * usage should supply explicit `usage` overrides in their fixture.\n */\nfunction converseUsage(overrides?: ResponseOverrides): {\n inputTokens: number;\n outputTokens: number;\n totalTokens: number;\n} {\n if (!overrides?.usage) return { inputTokens: 0, outputTokens: 0, totalTokens: 0 };\n const inputTokens = overrides.usage.input_tokens ?? overrides.usage.prompt_tokens ?? 0;\n const outputTokens = overrides.usage.output_tokens ?? overrides.usage.completion_tokens ?? 0;\n return { inputTokens, outputTokens, totalTokens: inputTokens + outputTokens };\n}\n\nfunction parseConverseToolArgumentsForStream(toolCall: ToolCall, logger: Logger): string {\n try {\n const parsed = JSON.parse(toolCall.arguments || \"{}\");\n return JSON.stringify(parsed);\n } catch {\n logger.warn(\n `Malformed JSON in fixture tool call arguments for \"${toolCall.name}\": ${toolCall.arguments}`,\n );\n return \"{}\";\n }\n}\n\nfunction buildBedrockStreamTextEvents(\n content: string,\n chunkSize: number,\n reasoning?: string,\n overrides?: ResponseOverrides,\n): Array<{ eventType: string; payload: object }> {\n const events: Array<{ eventType: string; payload: object }> = [\n { eventType: \"messageStart\", payload: { role: \"assistant\" } },\n ];\n\n if (reasoning) {\n const blockIndex = 0;\n events.push({\n eventType: \"contentBlockStart\",\n payload: { contentBlockIndex: blockIndex, start: { type: \"thinking\" } },\n });\n for (let i = 0; i < reasoning.length; i += chunkSize) {\n events.push({\n eventType: \"contentBlockDelta\",\n payload: {\n contentBlockIndex: blockIndex,\n delta: { type: \"thinking_delta\", thinking: reasoning.slice(i, i + chunkSize) },\n },\n });\n }\n events.push({\n eventType: \"contentBlockStop\",\n payload: { contentBlockIndex: blockIndex },\n });\n }\n\n const textBlockIndex = reasoning ? 1 : 0;\n events.push({\n eventType: \"contentBlockStart\",\n payload: { contentBlockIndex: textBlockIndex, start: { type: \"text\" } },\n });\n for (let i = 0; i < content.length; i += chunkSize) {\n events.push({\n eventType: \"contentBlockDelta\",\n payload: {\n contentBlockIndex: textBlockIndex,\n delta: { type: \"text_delta\", text: content.slice(i, i + chunkSize) },\n },\n });\n }\n events.push({\n eventType: \"contentBlockStop\",\n payload: { contentBlockIndex: textBlockIndex },\n });\n events.push({\n eventType: \"messageStop\",\n payload: { stopReason: converseStopReason(overrides?.finishReason, \"end_turn\") },\n });\n const usage = converseUsage(overrides);\n events.push({\n eventType: \"metadata\",\n payload: { usage, metrics: { latencyMs: 0 } },\n });\n return events;\n}\n\nfunction buildBedrockStreamContentWithToolCallsEvents(\n content: string,\n toolCalls: ToolCall[],\n chunkSize: number,\n logger: Logger,\n reasoning?: string,\n overrides?: ResponseOverrides,\n): Array<{ eventType: string; payload: object }> {\n const events = buildBedrockStreamTextEvents(content, chunkSize, reasoning, overrides);\n // Remove trailing metadata + messageStop events — we re-emit them after tool blocks\n events.pop(); // metadata\n events.pop(); // messageStop\n let blockIndex = reasoning ? 2 : 1;\n\n for (const tc of toolCalls) {\n const toolUseId = tc.id || generateToolUseId();\n events.push({\n eventType: \"contentBlockStart\",\n payload: {\n contentBlockIndex: blockIndex,\n start: { toolUse: { toolUseId, name: tc.name } },\n },\n });\n const argsStr = parseConverseToolArgumentsForStream(tc, logger);\n for (let i = 0; i < argsStr.length; i += chunkSize) {\n events.push({\n eventType: \"contentBlockDelta\",\n payload: {\n contentBlockIndex: blockIndex,\n delta: { toolUse: { input: argsStr.slice(i, i + chunkSize) } },\n },\n });\n }\n events.push({\n eventType: \"contentBlockStop\",\n payload: { contentBlockIndex: blockIndex },\n });\n blockIndex++;\n }\n events.push({\n eventType: \"messageStop\",\n payload: { stopReason: converseStopReason(overrides?.finishReason, \"tool_use\") },\n });\n const usage = converseUsage(overrides);\n events.push({\n eventType: \"metadata\",\n payload: { usage, metrics: { latencyMs: 0 } },\n });\n return events;\n}\n\nfunction buildBedrockStreamToolCallEvents(\n toolCalls: ToolCall[],\n chunkSize: number,\n logger: Logger,\n overrides?: ResponseOverrides,\n): Array<{ eventType: string; payload: object }> {\n const events: Array<{ eventType: string; payload: object }> = [\n { eventType: \"messageStart\", payload: { role: \"assistant\" } },\n ];\n\n for (let tcIdx = 0; tcIdx < toolCalls.length; tcIdx++) {\n const tc = toolCalls[tcIdx];\n const toolUseId = tc.id || generateToolUseId();\n events.push({\n eventType: \"contentBlockStart\",\n payload: {\n contentBlockIndex: tcIdx,\n start: { toolUse: { toolUseId, name: tc.name } },\n },\n });\n const argsStr = parseConverseToolArgumentsForStream(tc, logger);\n for (let i = 0; i < argsStr.length; i += chunkSize) {\n events.push({\n eventType: \"contentBlockDelta\",\n payload: {\n contentBlockIndex: tcIdx,\n delta: { toolUse: { input: argsStr.slice(i, i + chunkSize) } },\n },\n });\n }\n events.push({\n eventType: \"contentBlockStop\",\n payload: { contentBlockIndex: tcIdx },\n });\n }\n events.push({\n eventType: \"messageStop\",\n payload: { stopReason: converseStopReason(overrides?.finishReason, \"tool_use\") },\n });\n const usage = converseUsage(overrides);\n events.push({\n eventType: \"metadata\",\n payload: { usage, metrics: { latencyMs: 0 } },\n });\n return events;\n}\n\n// ─── Input conversion: Converse → ChatCompletionRequest ─────────────────────\n\nexport function converseToCompletionRequest(\n req: ConverseRequest,\n modelId: string,\n logger?: Logger,\n): ChatCompletionRequest {\n const messages: ChatMessage[] = [];\n\n // system field → system message\n if (req.system && req.system.length > 0) {\n const systemText = req.system.map((s) => s.text).join(\"\");\n if (systemText) {\n messages.push({ role: \"system\", content: systemText });\n }\n }\n\n for (const msg of req.messages) {\n if (msg.role === \"user\") {\n // Check for toolResult blocks\n const toolResults = msg.content.filter((b) => b.toolResult);\n const textBlocks = msg.content.filter(\n (b) => b.text !== undefined && b.text !== \"\" && !b.toolResult,\n );\n const unsupportedBlocks = msg.content.filter(\n (b) => b.text === undefined && !b.toolResult && !b.toolUse,\n );\n if (unsupportedBlocks.length > 0 && logger) {\n logger.warn(\n `Converse user message contains unsupported content block types — these will be dropped during conversion`,\n );\n }\n\n if (toolResults.length > 0) {\n for (const block of toolResults) {\n const tr = block.toolResult!;\n const resultContent = tr.content.map((c) => c.text ?? \"\").join(\"\");\n messages.push({\n role: \"tool\",\n content: resultContent,\n tool_call_id: tr.toolUseId,\n });\n }\n if (textBlocks.length > 0) {\n messages.push({\n role: \"user\",\n content: textBlocks.map((b) => b.text ?? \"\").join(\"\"),\n });\n }\n continue;\n }\n\n // Plain user message\n const text = msg.content\n .filter((b) => b.text !== undefined && b.text !== \"\")\n .map((b) => b.text ?? \"\")\n .join(\"\");\n messages.push({ role: \"user\", content: text });\n } else if (msg.role === \"assistant\") {\n const toolUseBlocks = msg.content.filter((b) => b.toolUse);\n const textContent = msg.content\n .filter((b) => b.text !== undefined && b.text !== \"\")\n .map((b) => b.text ?? \"\")\n .join(\"\");\n\n if (toolUseBlocks.length > 0) {\n messages.push({\n role: \"assistant\",\n content: textContent ?? null,\n tool_calls: toolUseBlocks.map((b) => ({\n id: b.toolUse!.toolUseId,\n type: \"function\" as const,\n function: {\n name: b.toolUse!.name,\n arguments: JSON.stringify(b.toolUse!.input),\n },\n })),\n });\n } else {\n messages.push({ role: \"assistant\", content: textContent ?? null });\n }\n } else {\n const warnMsg = `Unexpected message role \"${msg.role}\" in Converse request — skipping`;\n if (logger) {\n logger.warn(warnMsg);\n }\n }\n }\n\n // Convert tools\n let tools: ToolDefinition[] | undefined;\n if (req.toolConfig?.tools && req.toolConfig.tools.length > 0) {\n tools = req.toolConfig.tools.map((t) => ({\n type: \"function\" as const,\n function: {\n name: t.toolSpec.name,\n description: t.toolSpec.description,\n parameters: (t.toolSpec.inputSchema && \"json\" in t.toolSpec.inputSchema\n ? (t.toolSpec.inputSchema as Record<string, unknown>).json\n : t.toolSpec.inputSchema) as object | undefined,\n },\n }));\n }\n\n return {\n model: modelId,\n messages,\n stream: false,\n temperature: req.inferenceConfig?.temperature,\n tools,\n };\n}\n\n// ─── Response builders ──────────────────────────────────────────────────────\n\nfunction buildConverseTextResponse(\n content: string,\n reasoning?: string,\n overrides?: ResponseOverrides,\n): object {\n const contentBlocks: object[] = [];\n if (reasoning) {\n contentBlocks.push({\n reasoningContent: { reasoningText: { text: reasoning } },\n });\n }\n contentBlocks.push({ text: content });\n\n return {\n output: {\n message: {\n role: \"assistant\",\n content: contentBlocks,\n },\n },\n stopReason: converseStopReason(overrides?.finishReason, \"end_turn\"),\n usage: converseUsage(overrides),\n };\n}\n\nfunction buildConverseToolCallResponse(\n toolCalls: ToolCall[],\n logger: Logger,\n overrides?: ResponseOverrides,\n): object {\n return {\n output: {\n message: {\n role: \"assistant\",\n content: toolCalls.map((tc) => {\n let argsObj: unknown;\n try {\n argsObj = JSON.parse(tc.arguments || \"{}\");\n } catch {\n logger.warn(\n `Malformed JSON in fixture tool call arguments for \"${tc.name}\": ${tc.arguments}`,\n );\n argsObj = {};\n }\n return {\n toolUse: {\n toolUseId: tc.id || generateToolUseId(),\n name: tc.name,\n input: argsObj,\n },\n };\n }),\n },\n },\n stopReason: converseStopReason(overrides?.finishReason, \"tool_use\"),\n usage: converseUsage(overrides),\n };\n}\n\nfunction buildConverseContentWithToolCallsResponse(\n content: string,\n toolCalls: ToolCall[],\n logger: Logger,\n reasoning?: string,\n overrides?: ResponseOverrides,\n): object {\n const contentBlocks: object[] = [];\n if (reasoning) {\n contentBlocks.push({\n reasoningContent: { reasoningText: { text: reasoning } },\n });\n }\n contentBlocks.push({ text: content });\n for (const tc of toolCalls) {\n let argsObj: unknown;\n try {\n argsObj = JSON.parse(tc.arguments || \"{}\");\n } catch {\n logger.warn(\n `Malformed JSON in fixture tool call arguments for \"${tc.name}\": ${tc.arguments}`,\n );\n argsObj = {};\n }\n contentBlocks.push({\n toolUse: {\n toolUseId: tc.id || generateToolUseId(),\n name: tc.name,\n input: argsObj,\n },\n });\n }\n\n return {\n output: {\n message: {\n role: \"assistant\",\n content: contentBlocks,\n },\n },\n stopReason: converseStopReason(overrides?.finishReason, \"tool_use\"),\n usage: converseUsage(overrides),\n };\n}\n\n// ─── Request handlers ───────────────────────────────────────────────────────\n\nexport async function handleConverse(\n req: http.IncomingMessage,\n res: http.ServerResponse,\n raw: string,\n modelId: string,\n fixtures: Fixture[],\n journal: Journal,\n defaults: HandlerDefaults,\n setCorsHeaders: (res: http.ServerResponse) => void,\n): Promise<void> {\n const { logger } = defaults;\n setCorsHeaders(res);\n\n const urlPath = req.url ?? `/model/${modelId}/converse`;\n\n let converseReq: ConverseRequest;\n try {\n converseReq = JSON.parse(raw) as ConverseRequest;\n } catch {\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: null,\n response: { status: 400, fixture: null },\n });\n writeErrorResponse(\n res,\n 400,\n JSON.stringify({\n error: {\n message: \"Malformed JSON\",\n type: \"invalid_request_error\",\n },\n }),\n );\n return;\n }\n\n if (!converseReq.messages || !Array.isArray(converseReq.messages)) {\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: null,\n response: { status: 400, fixture: null },\n });\n writeErrorResponse(\n res,\n 400,\n JSON.stringify({\n error: {\n message: \"Invalid request: messages array is required\",\n type: \"invalid_request_error\",\n },\n }),\n );\n return;\n }\n\n const completionReq = converseToCompletionRequest(converseReq, modelId, logger);\n completionReq._endpointType = \"chat\";\n\n const testId = getTestId(req);\n const fixture = matchFixture(\n fixtures,\n completionReq,\n journal.getFixtureMatchCountsForTest(testId),\n defaults.requestTransform,\n );\n\n if (fixture) {\n logger.debug(`Fixture matched: ${JSON.stringify(fixture.match).slice(0, 120)}`);\n } else {\n logger.debug(`No fixture matched for request`);\n }\n\n if (fixture) {\n journal.incrementFixtureMatchCount(fixture, fixtures, testId);\n }\n\n if (\n applyChaos(\n res,\n fixture,\n defaults.chaos,\n req.headers,\n journal,\n {\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n },\n fixture ? \"fixture\" : \"proxy\",\n defaults.registry,\n defaults.logger,\n )\n )\n return;\n\n if (!fixture) {\n if (defaults.record) {\n const outcome = await proxyAndRecord(\n req,\n res,\n completionReq,\n \"bedrock\",\n urlPath,\n fixtures,\n defaults,\n raw,\n );\n if (outcome !== \"not_configured\") {\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: res.statusCode ?? 200, fixture: null, source: \"proxy\" },\n });\n return;\n }\n }\n const strictStatus = defaults.strict ? 503 : 404;\n const strictMessage = defaults.strict\n ? \"Strict mode: no fixture matched\"\n : \"No fixture matched\";\n if (defaults.strict) {\n logger.error(`STRICT: No fixture matched for ${req.method ?? \"POST\"} ${urlPath}`);\n }\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: strictStatus, fixture: null },\n });\n writeErrorResponse(\n res,\n strictStatus,\n JSON.stringify({\n error: {\n message: strictMessage,\n type: \"invalid_request_error\",\n },\n }),\n );\n return;\n }\n\n const response = await resolveResponse(fixture, completionReq);\n\n // Error response\n if (isErrorResponse(response)) {\n const status = response.status ?? 500;\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status, fixture },\n });\n const errBody = {\n type: \"error\",\n error: {\n type: response.error.type ?? \"invalid_request_error\",\n message: response.error.message,\n },\n };\n writeErrorResponse(res, status, JSON.stringify(errBody));\n return;\n }\n\n // Content + tool calls response\n if (isContentWithToolCallsResponse(response)) {\n if (response.webSearches?.length) {\n logger.warn(\n \"webSearches in fixture response are not supported for Bedrock Converse API — ignoring\",\n );\n }\n const overrides = extractOverrides(response);\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: 200, fixture },\n });\n const body = buildConverseContentWithToolCallsResponse(\n response.content,\n response.toolCalls,\n logger,\n response.reasoning,\n overrides,\n );\n res.writeHead(200, { \"Content-Type\": \"application/json\" });\n res.end(JSON.stringify(body));\n return;\n }\n\n // Text response\n if (isTextResponse(response)) {\n if (response.webSearches?.length) {\n logger.warn(\n \"webSearches in fixture response are not supported for Bedrock Converse API — ignoring\",\n );\n }\n const overrides = extractOverrides(response);\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: 200, fixture },\n });\n const body = buildConverseTextResponse(response.content, response.reasoning, overrides);\n res.writeHead(200, { \"Content-Type\": \"application/json\" });\n res.end(JSON.stringify(body));\n return;\n }\n\n // Tool call response\n if (isToolCallResponse(response)) {\n if (\"webSearches\" in response) {\n logger.warn(\n \"webSearches in fixture response are not supported for Bedrock Converse API — ignoring\",\n );\n }\n const overrides = extractOverrides(response);\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: 200, fixture },\n });\n const body = buildConverseToolCallResponse(response.toolCalls, logger, overrides);\n res.writeHead(200, { \"Content-Type\": \"application/json\" });\n res.end(JSON.stringify(body));\n return;\n }\n\n // Unknown response type\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: 500, fixture },\n });\n writeErrorResponse(\n res,\n 500,\n JSON.stringify({\n error: {\n message: \"Fixture response did not match any known type\",\n type: \"server_error\",\n },\n }),\n );\n}\n\nexport async function handleConverseStream(\n req: http.IncomingMessage,\n res: http.ServerResponse,\n raw: string,\n modelId: string,\n fixtures: Fixture[],\n journal: Journal,\n defaults: HandlerDefaults,\n setCorsHeaders: (res: http.ServerResponse) => void,\n): Promise<void> {\n const { logger } = defaults;\n setCorsHeaders(res);\n\n const urlPath = req.url ?? `/model/${modelId}/converse-stream`;\n\n let converseReq: ConverseRequest;\n try {\n converseReq = JSON.parse(raw) as ConverseRequest;\n } catch {\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: null,\n response: { status: 400, fixture: null },\n });\n writeErrorResponse(\n res,\n 400,\n JSON.stringify({\n error: {\n message: \"Malformed JSON\",\n type: \"invalid_request_error\",\n },\n }),\n );\n return;\n }\n\n if (!converseReq.messages || !Array.isArray(converseReq.messages)) {\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: null,\n response: { status: 400, fixture: null },\n });\n writeErrorResponse(\n res,\n 400,\n JSON.stringify({\n error: {\n message: \"Invalid request: messages array is required\",\n type: \"invalid_request_error\",\n },\n }),\n );\n return;\n }\n\n const completionReq = converseToCompletionRequest(converseReq, modelId, logger);\n completionReq.stream = true;\n completionReq._endpointType = \"chat\";\n\n const testId = getTestId(req);\n const fixture = matchFixture(\n fixtures,\n completionReq,\n journal.getFixtureMatchCountsForTest(testId),\n defaults.requestTransform,\n );\n\n if (fixture) {\n logger.debug(`Fixture matched: ${JSON.stringify(fixture.match).slice(0, 120)}`);\n } else {\n logger.debug(`No fixture matched for request`);\n }\n\n if (fixture) {\n journal.incrementFixtureMatchCount(fixture, fixtures, testId);\n }\n\n if (\n applyChaos(\n res,\n fixture,\n defaults.chaos,\n req.headers,\n journal,\n {\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n },\n fixture ? \"fixture\" : \"proxy\",\n defaults.registry,\n defaults.logger,\n )\n )\n return;\n\n if (!fixture) {\n if (defaults.record) {\n const outcome = await proxyAndRecord(\n req,\n res,\n completionReq,\n \"bedrock\",\n urlPath,\n fixtures,\n defaults,\n raw,\n );\n if (outcome !== \"not_configured\") {\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: res.statusCode ?? 200, fixture: null, source: \"proxy\" },\n });\n return;\n }\n }\n const strictStatus = defaults.strict ? 503 : 404;\n const strictMessage = defaults.strict\n ? \"Strict mode: no fixture matched\"\n : \"No fixture matched\";\n if (defaults.strict) {\n logger.error(`STRICT: No fixture matched for ${req.method ?? \"POST\"} ${urlPath}`);\n }\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: strictStatus, fixture: null },\n });\n writeErrorResponse(\n res,\n strictStatus,\n JSON.stringify({\n error: {\n message: strictMessage,\n type: \"invalid_request_error\",\n },\n }),\n );\n return;\n }\n\n const response = await resolveResponse(fixture, completionReq);\n const latency = fixture.latency ?? defaults.latency;\n const chunkSize = Math.max(1, fixture.chunkSize ?? defaults.chunkSize);\n\n // Error response\n if (isErrorResponse(response)) {\n const status = response.status ?? 500;\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status, fixture },\n });\n const errBody = {\n type: \"error\",\n error: {\n type: response.error.type ?? \"invalid_request_error\",\n message: response.error.message,\n },\n };\n writeErrorResponse(res, status, JSON.stringify(errBody));\n return;\n }\n\n // Content + tool calls response — stream as Event Stream\n if (isContentWithToolCallsResponse(response)) {\n if (response.webSearches?.length) {\n logger.warn(\n \"webSearches in fixture response are not supported for Bedrock Converse API — ignoring\",\n );\n }\n const overrides = extractOverrides(response);\n const journalEntry = journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: 200, fixture },\n });\n const events = buildBedrockStreamContentWithToolCallsEvents(\n response.content,\n response.toolCalls,\n chunkSize,\n logger,\n response.reasoning,\n overrides,\n );\n const interruption = createInterruptionSignal(fixture);\n const completed = await writeEventStream(res, events, {\n latency,\n streamingProfile: fixture.streamingProfile,\n signal: interruption?.signal,\n onChunkSent: interruption?.tick,\n });\n if (!completed) {\n if (!res.writableEnded) res.destroy();\n journalEntry.response.interrupted = true;\n journalEntry.response.interruptReason = interruption?.reason();\n }\n interruption?.cleanup();\n return;\n }\n\n // Text response — stream as Event Stream\n if (isTextResponse(response)) {\n if (response.webSearches?.length) {\n logger.warn(\n \"webSearches in fixture response are not supported for Bedrock Converse API — ignoring\",\n );\n }\n const overrides = extractOverrides(response);\n const journalEntry = journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: 200, fixture },\n });\n const events = buildBedrockStreamTextEvents(\n response.content,\n chunkSize,\n response.reasoning,\n overrides,\n );\n const interruption = createInterruptionSignal(fixture);\n const completed = await writeEventStream(res, events, {\n latency,\n streamingProfile: fixture.streamingProfile,\n signal: interruption?.signal,\n onChunkSent: interruption?.tick,\n });\n if (!completed) {\n if (!res.writableEnded) res.destroy();\n journalEntry.response.interrupted = true;\n journalEntry.response.interruptReason = interruption?.reason();\n }\n interruption?.cleanup();\n return;\n }\n\n // Tool call response — stream as Event Stream\n if (isToolCallResponse(response)) {\n if (\"webSearches\" in response) {\n logger.warn(\n \"webSearches in fixture response are not supported for Bedrock Converse API — ignoring\",\n );\n }\n const overrides = extractOverrides(response);\n const journalEntry = journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: 200, fixture },\n });\n const events = buildBedrockStreamToolCallEvents(\n response.toolCalls,\n chunkSize,\n logger,\n overrides,\n );\n const interruption = createInterruptionSignal(fixture);\n const completed = await writeEventStream(res, events, {\n latency,\n streamingProfile: fixture.streamingProfile,\n signal: interruption?.signal,\n onChunkSent: interruption?.tick,\n });\n if (!completed) {\n if (!res.writableEnded) res.destroy();\n journalEntry.response.interrupted = true;\n journalEntry.response.interruptReason = interruption?.reason();\n }\n interruption?.cleanup();\n return;\n }\n\n // Unknown response type\n journal.add({\n method: req.method ?? \"POST\",\n path: urlPath,\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: 500, fixture },\n });\n writeErrorResponse(\n res,\n 500,\n JSON.stringify({\n error: {\n message: \"Fixture response did not match any known type\",\n type: \"server_error\",\n },\n }),\n );\n}\n"],"mappings":";;;;;;;;;AAmEA,SAAS,mBACP,sBACA,eACQ;AACR,KAAI,CAAC,qBAAsB,QAAO;AAClC,KAAI,yBAAyB,OAAQ,QAAO;AAC5C,KAAI,yBAAyB,aAAc,QAAO;AAClD,KAAI,yBAAyB,SAAU,QAAO;AAC9C,QAAO;;;;;;;;;;AAWT,SAAS,cAAc,WAIrB;AACA,KAAI,CAAC,WAAW,MAAO,QAAO;EAAE,aAAa;EAAG,cAAc;EAAG,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CAAA,EAzCH,gBAyCG,EAAA;gBAEL,CAAA,EA1CW,gBA0CX,EAAA;;AAEC,UAzCQ,SAAA,CAyCR;MACE,CAAA,EAAA,MAAA;EAAY,MAAA,CAAA,EAxCZ,cAwCY,EAAA;AAQvB;AAKsB,UAlDL,iBAAA,CAkDoB;EAAA,KAAA,EAAA;IAC3B,OAAA,CAAA,EAAA,MAAA;IAEW,QAAA,CAAA,EAAA,MAAA;IAAlB,QAAA,CAAA,EAAA,MAAA;EAAO,CAAA;;WAlDC;;;UAIM,UAAA;;aAEJ;;UAGI,sBAAA;;;YAGL;;;eAGG;;iBAEE;;UAGA,YAAA;;gBAED;;UAGC,YAAA;;;YAGL;aACC;;QAEL;QACA;SACC;WACE;;;;;;;;;;;iBAQK,UAAA,sBAAgC;iBAK1B,eAAA,SACZ;;;IAEP;UAAkB"}
|
package/dist/helpers.cjs
CHANGED
|
@@ -123,6 +123,7 @@ function buildTextChunks(content, model, chunkSize, reasoning, overrides) {
|
|
|
123
123
|
choices: [{
|
|
124
124
|
index: 0,
|
|
125
125
|
delta: { reasoning_content: slice },
|
|
126
|
+
logprobs: null,
|
|
126
127
|
finish_reason: null
|
|
127
128
|
}],
|
|
128
129
|
...fingerprint !== void 0 && { system_fingerprint: fingerprint }
|
|
@@ -139,6 +140,7 @@ function buildTextChunks(content, model, chunkSize, reasoning, overrides) {
|
|
|
139
140
|
role: overrides?.role ?? "assistant",
|
|
140
141
|
content: ""
|
|
141
142
|
},
|
|
143
|
+
logprobs: null,
|
|
142
144
|
finish_reason: null
|
|
143
145
|
}],
|
|
144
146
|
...fingerprint !== void 0 && { system_fingerprint: fingerprint }
|
|
@@ -153,6 +155,7 @@ function buildTextChunks(content, model, chunkSize, reasoning, overrides) {
|
|
|
153
155
|
choices: [{
|
|
154
156
|
index: 0,
|
|
155
157
|
delta: { content: slice },
|
|
158
|
+
logprobs: null,
|
|
156
159
|
finish_reason: null
|
|
157
160
|
}],
|
|
158
161
|
...fingerprint !== void 0 && { system_fingerprint: fingerprint }
|
|
@@ -166,6 +169,7 @@ function buildTextChunks(content, model, chunkSize, reasoning, overrides) {
|
|
|
166
169
|
choices: [{
|
|
167
170
|
index: 0,
|
|
168
171
|
delta: {},
|
|
172
|
+
logprobs: null,
|
|
169
173
|
finish_reason: overrides?.finishReason ?? "stop"
|
|
170
174
|
}],
|
|
171
175
|
...fingerprint !== void 0 && { system_fingerprint: fingerprint }
|
|
@@ -189,6 +193,7 @@ function buildToolCallChunks(toolCalls, model, chunkSize, overrides) {
|
|
|
189
193
|
role: overrides?.role ?? "assistant",
|
|
190
194
|
content: null
|
|
191
195
|
},
|
|
196
|
+
logprobs: null,
|
|
192
197
|
finish_reason: null
|
|
193
198
|
}],
|
|
194
199
|
...fingerprint !== void 0 && { system_fingerprint: fingerprint }
|
|
@@ -212,6 +217,7 @@ function buildToolCallChunks(toolCalls, model, chunkSize, overrides) {
|
|
|
212
217
|
arguments: ""
|
|
213
218
|
}
|
|
214
219
|
}] },
|
|
220
|
+
logprobs: null,
|
|
215
221
|
finish_reason: null
|
|
216
222
|
}],
|
|
217
223
|
...fingerprint !== void 0 && { system_fingerprint: fingerprint }
|
|
@@ -230,6 +236,7 @@ function buildToolCallChunks(toolCalls, model, chunkSize, overrides) {
|
|
|
230
236
|
index: tcIdx,
|
|
231
237
|
function: { arguments: slice }
|
|
232
238
|
}] },
|
|
239
|
+
logprobs: null,
|
|
233
240
|
finish_reason: null
|
|
234
241
|
}],
|
|
235
242
|
...fingerprint !== void 0 && { system_fingerprint: fingerprint }
|
|
@@ -244,6 +251,7 @@ function buildToolCallChunks(toolCalls, model, chunkSize, overrides) {
|
|
|
244
251
|
choices: [{
|
|
245
252
|
index: 0,
|
|
246
253
|
delta: {},
|
|
254
|
+
logprobs: null,
|
|
247
255
|
finish_reason: overrides?.finishReason ?? "tool_calls"
|
|
248
256
|
}],
|
|
249
257
|
...fingerprint !== void 0 && { system_fingerprint: fingerprint }
|
|
@@ -269,6 +277,7 @@ function buildTextCompletion(content, model, reasoning, overrides) {
|
|
|
269
277
|
refusal: null,
|
|
270
278
|
...reasoning ? { reasoning_content: reasoning } : {}
|
|
271
279
|
},
|
|
280
|
+
logprobs: null,
|
|
272
281
|
finish_reason: overrides?.finishReason ?? "stop"
|
|
273
282
|
}],
|
|
274
283
|
usage: overrides?.usage ? {
|
|
@@ -305,6 +314,7 @@ function buildToolCallCompletion(toolCalls, model, overrides) {
|
|
|
305
314
|
}
|
|
306
315
|
}))
|
|
307
316
|
},
|
|
317
|
+
logprobs: null,
|
|
308
318
|
finish_reason: overrides?.finishReason ?? "tool_calls"
|
|
309
319
|
}],
|
|
310
320
|
usage: overrides?.usage ? {
|
|
@@ -331,6 +341,7 @@ function buildContentWithToolCallsChunks(content, toolCalls, model, chunkSize, r
|
|
|
331
341
|
choices: [{
|
|
332
342
|
index: 0,
|
|
333
343
|
delta: { reasoning_content: slice },
|
|
344
|
+
logprobs: null,
|
|
334
345
|
finish_reason: null
|
|
335
346
|
}],
|
|
336
347
|
...fingerprint !== void 0 && { system_fingerprint: fingerprint }
|
|
@@ -347,6 +358,7 @@ function buildContentWithToolCallsChunks(content, toolCalls, model, chunkSize, r
|
|
|
347
358
|
role: overrides?.role ?? "assistant",
|
|
348
359
|
content: ""
|
|
349
360
|
},
|
|
361
|
+
logprobs: null,
|
|
350
362
|
finish_reason: null
|
|
351
363
|
}],
|
|
352
364
|
...fingerprint !== void 0 && { system_fingerprint: fingerprint }
|
|
@@ -361,6 +373,7 @@ function buildContentWithToolCallsChunks(content, toolCalls, model, chunkSize, r
|
|
|
361
373
|
choices: [{
|
|
362
374
|
index: 0,
|
|
363
375
|
delta: { content: slice },
|
|
376
|
+
logprobs: null,
|
|
364
377
|
finish_reason: null
|
|
365
378
|
}],
|
|
366
379
|
...fingerprint !== void 0 && { system_fingerprint: fingerprint }
|
|
@@ -385,6 +398,7 @@ function buildContentWithToolCallsChunks(content, toolCalls, model, chunkSize, r
|
|
|
385
398
|
arguments: ""
|
|
386
399
|
}
|
|
387
400
|
}] },
|
|
401
|
+
logprobs: null,
|
|
388
402
|
finish_reason: null
|
|
389
403
|
}],
|
|
390
404
|
...fingerprint !== void 0 && { system_fingerprint: fingerprint }
|
|
@@ -403,6 +417,7 @@ function buildContentWithToolCallsChunks(content, toolCalls, model, chunkSize, r
|
|
|
403
417
|
index: tcIdx,
|
|
404
418
|
function: { arguments: slice }
|
|
405
419
|
}] },
|
|
420
|
+
logprobs: null,
|
|
406
421
|
finish_reason: null
|
|
407
422
|
}],
|
|
408
423
|
...fingerprint !== void 0 && { system_fingerprint: fingerprint }
|
|
@@ -417,6 +432,7 @@ function buildContentWithToolCallsChunks(content, toolCalls, model, chunkSize, r
|
|
|
417
432
|
choices: [{
|
|
418
433
|
index: 0,
|
|
419
434
|
delta: {},
|
|
435
|
+
logprobs: null,
|
|
420
436
|
finish_reason: overrides?.finishReason ?? "tool_calls"
|
|
421
437
|
}],
|
|
422
438
|
...fingerprint !== void 0 && { system_fingerprint: fingerprint }
|
|
@@ -450,6 +466,7 @@ function buildContentWithToolCallsCompletion(content, toolCalls, model, reasonin
|
|
|
450
466
|
}
|
|
451
467
|
}))
|
|
452
468
|
},
|
|
469
|
+
logprobs: null,
|
|
453
470
|
finish_reason: overrides?.finishReason ?? "tool_calls"
|
|
454
471
|
}],
|
|
455
472
|
usage: overrides?.usage ? {
|