@code-yeongyu/senpi 2026.7.20-2 → 2026.7.20
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/CHANGELOG.md +0 -18
- package/dist/core/agent-session.d.ts +0 -32
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +68 -368
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts +2 -2
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +11 -39
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/extensions/builtin/compaction/index.d.ts.map +1 -1
- package/dist/core/extensions/builtin/compaction/index.js +8 -24
- package/dist/core/extensions/builtin/compaction/index.js.map +1 -1
- package/dist/core/extensions/builtin/goal/command-registration.d.ts +2 -2
- package/dist/core/extensions/builtin/goal/command-registration.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/command-registration.js +4 -3
- package/dist/core/extensions/builtin/goal/command-registration.js.map +1 -1
- package/dist/core/extensions/builtin/goal/index.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/index.js +27 -11
- package/dist/core/extensions/builtin/goal/index.js.map +1 -1
- package/dist/core/extensions/builtin/goal/tool-registration.d.ts +2 -2
- package/dist/core/extensions/builtin/goal/tool-registration.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/tool-registration.js +3 -2
- package/dist/core/extensions/builtin/goal/tool-registration.js.map +1 -1
- package/dist/core/extensions/builtin/index.d.ts.map +1 -1
- package/dist/core/extensions/builtin/index.js +0 -2
- package/dist/core/extensions/builtin/index.js.map +1 -1
- package/dist/core/extensions/builtin/nested-agents-md/index.d.ts.map +1 -1
- package/dist/core/extensions/builtin/nested-agents-md/index.js +1 -4
- package/dist/core/extensions/builtin/nested-agents-md/index.js.map +1 -1
- package/dist/core/extensions/builtin/rules/index.d.ts.map +1 -1
- package/dist/core/extensions/builtin/rules/index.js +1 -4
- package/dist/core/extensions/builtin/rules/index.js.map +1 -1
- package/dist/core/extensions/builtin/websearch/websearch/renderers.d.ts.map +1 -1
- package/dist/core/extensions/builtin/websearch/websearch/renderers.js +4 -13
- package/dist/core/extensions/builtin/websearch/websearch/renderers.js.map +1 -1
- package/dist/core/extensions/builtin/websearch/websearch/search.d.ts +2 -3
- package/dist/core/extensions/builtin/websearch/websearch/search.d.ts.map +1 -1
- package/dist/core/extensions/builtin/websearch/websearch/search.js +1 -2
- package/dist/core/extensions/builtin/websearch/websearch/search.js.map +1 -1
- package/dist/core/extensions/builtin/websearch/websearch/tool.d.ts.map +1 -1
- package/dist/core/extensions/builtin/websearch/websearch/tool.js +1 -17
- package/dist/core/extensions/builtin/websearch/websearch/tool.js.map +1 -1
- package/dist/core/extensions/builtin/websearch/websearch/types.d.ts +0 -2
- package/dist/core/extensions/builtin/websearch/websearch/types.d.ts.map +1 -1
- package/dist/core/extensions/builtin/websearch/websearch/types.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +0 -1
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +0 -31
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +10 -67
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +0 -1
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-manager.d.ts +1 -6
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +3 -19
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-manager.d.ts +0 -15
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +1 -80
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts +1 -2
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +2 -21
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +0 -4
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +3 -78
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/docs/extensions.md +0 -28
- package/docs/settings.md +0 -35
- package/node_modules/@code-yeongyu/senpi-codemode/CHANGELOG.md +0 -12
- package/node_modules/@code-yeongyu/senpi-codemode/package.json +3 -3
- package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.js +8 -76
- package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.js.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/agent.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/agent.js +1 -26
- package/node_modules/@earendil-works/pi-agent-core/dist/agent.js.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/agent-harness.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/agent-harness.js +2 -24
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/agent-harness.js.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/types.d.ts +0 -5
- package/node_modules/@earendil-works/pi-agent-core/dist/types.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/types.js.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/package.json +2 -2
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js +25 -68
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/transform-messages.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/transform-messages.js +52 -62
- package/node_modules/@earendil-works/pi-ai/dist/api/transform-messages.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/index.d.ts +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/index.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/index.js +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/index.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/models.generated.d.ts +4 -0
- package/node_modules/@earendil-works/pi-ai/dist/models.generated.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/kimi-coding.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/faux.d.ts +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/faux.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/faux.js +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/faux.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/kimi-coding.models.d.ts +4 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/kimi-coding.models.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/kimi-coding.models.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/types.d.ts +0 -15
- package/node_modules/@earendil-works/pi-ai/dist/types.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/types.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry.js +1 -5
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/package.json +1 -1
- package/node_modules/@earendil-works/pi-pty/package.json +1 -1
- package/node_modules/@earendil-works/pi-tui/package.json +1 -1
- package/package.json +6 -6
- package/dist/core/extensions/builtin/goal/turn-usage.d.ts +0 -20
- package/dist/core/extensions/builtin/goal/turn-usage.d.ts.map +0 -1
- package/dist/core/extensions/builtin/goal/turn-usage.js +0 -61
- package/dist/core/extensions/builtin/goal/turn-usage.js.map +0 -1
- package/dist/core/extensions/builtin/model-fallback/index.d.ts +0 -4
- package/dist/core/extensions/builtin/model-fallback/index.d.ts.map +0 -1
- package/dist/core/extensions/builtin/model-fallback/index.js +0 -55
- package/dist/core/extensions/builtin/model-fallback/index.js.map +0 -1
- package/dist/core/extensions/builtin/model-fallback/settings.d.ts +0 -6
- package/dist/core/extensions/builtin/model-fallback/settings.d.ts.map +0 -1
- package/dist/core/extensions/builtin/model-fallback/settings.js +0 -11
- package/dist/core/extensions/builtin/model-fallback/settings.js.map +0 -1
- package/dist/core/extensions/builtin/model-fallback/ui.d.ts +0 -12
- package/dist/core/extensions/builtin/model-fallback/ui.d.ts.map +0 -1
- package/dist/core/extensions/builtin/model-fallback/ui.js +0 -72
- package/dist/core/extensions/builtin/model-fallback/ui.js.map +0 -1
- package/dist/core/retry-fallback/chains.d.ts +0 -29
- package/dist/core/retry-fallback/chains.d.ts.map +0 -1
- package/dist/core/retry-fallback/chains.js +0 -109
- package/dist/core/retry-fallback/chains.js.map +0 -1
- package/dist/core/retry-fallback/controller.d.ts +0 -77
- package/dist/core/retry-fallback/controller.d.ts.map +0 -1
- package/dist/core/retry-fallback/controller.js +0 -157
- package/dist/core/retry-fallback/controller.js.map +0 -1
- package/dist/core/retry-fallback/cooldown.d.ts +0 -21
- package/dist/core/retry-fallback/cooldown.d.ts.map +0 -1
- package/dist/core/retry-fallback/cooldown.js +0 -49
- package/dist/core/retry-fallback/cooldown.js.map +0 -1
- package/dist/core/retry-fallback/log.d.ts +0 -10
- package/dist/core/retry-fallback/log.d.ts.map +0 -1
- package/dist/core/retry-fallback/log.js +0 -128
- package/dist/core/retry-fallback/log.js.map +0 -1
- package/dist/core/retry-fallback/validate.d.ts +0 -8
- package/dist/core/retry-fallback/validate.d.ts.map +0 -1
- package/dist/core/retry-fallback/validate.js +0 -63
- package/dist/core/retry-fallback/validate.js.map +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/stop-details.d.ts +0 -4
- package/node_modules/@earendil-works/pi-ai/dist/utils/stop-details.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/stop-details.js +0 -6
- package/node_modules/@earendil-works/pi-ai/dist/utils/stop-details.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform-messages.d.ts","sourceRoot":"","sources":["../../src/api/transform-messages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,GAAG,EACH,gBAAgB,EAEhB,OAAO,EACP,KAAK,EAIL,MAAM,aAAa,CAAC;AA+FrB,MAAM,WAAW,wBAAwB;IACxC;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC;;;;OAIG;IACH,wBAAwB,CAAC,EAAE,OAAO,CAAC;CACnC;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,SAAS,GAAG,EACjD,QAAQ,EAAE,OAAO,EAAE,EACnB,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,EAClB,mBAAmB,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,gBAAgB,KAAK,MAAM,EAC1F,OAAO,GAAE,wBAA6B,GACpC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"transform-messages.d.ts","sourceRoot":"","sources":["../../src/api/transform-messages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,GAAG,EACH,gBAAgB,EAEhB,OAAO,EACP,KAAK,EAIL,MAAM,aAAa,CAAC;AA+FrB,MAAM,WAAW,wBAAwB;IACxC;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC;;;;OAIG;IACH,wBAAwB,CAAC,EAAE,OAAO,CAAC;CACnC;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,SAAS,GAAG,EACjD,QAAQ,EAAE,OAAO,EAAE,EACnB,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,EAClB,mBAAmB,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,gBAAgB,KAAK,MAAM,EAC1F,OAAO,GAAE,wBAA6B,GACpC,OAAO,EAAE,CAqKX"}
|
|
@@ -163,76 +163,66 @@ export function transformMessages(messages, model, normalizeToolCallId, options
|
|
|
163
163
|
}
|
|
164
164
|
return msg;
|
|
165
165
|
});
|
|
166
|
-
// Second pass:
|
|
167
|
-
//
|
|
168
|
-
// calls because Anthropic requires that ordering. A reused ID starts a new
|
|
169
|
-
// pairing window, so a later result cannot repair an earlier call.
|
|
166
|
+
// Second pass: insert synthetic empty tool results for orphaned tool calls
|
|
167
|
+
// This preserves thinking signatures and satisfies API requirements
|
|
170
168
|
const result = [];
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
169
|
+
let pendingToolCalls = [];
|
|
170
|
+
let existingToolResultIds = new Set();
|
|
171
|
+
const insertSyntheticToolResults = () => {
|
|
172
|
+
if (pendingToolCalls.length > 0) {
|
|
173
|
+
for (const tc of pendingToolCalls) {
|
|
174
|
+
if (!existingToolResultIds.has(tc.id)) {
|
|
175
|
+
result.push({
|
|
176
|
+
role: "toolResult",
|
|
177
|
+
toolCallId: tc.id,
|
|
178
|
+
toolName: tc.name,
|
|
179
|
+
content: [{ type: "text", text: "No result provided" }],
|
|
180
|
+
isError: true,
|
|
181
|
+
timestamp: Date.now(),
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
pendingToolCalls = [];
|
|
186
|
+
existingToolResultIds = new Set();
|
|
183
187
|
}
|
|
184
|
-
|
|
185
|
-
|
|
188
|
+
};
|
|
189
|
+
for (let i = 0; i < transformed.length; i++) {
|
|
190
|
+
const msg = transformed[i];
|
|
191
|
+
if (msg.role === "assistant") {
|
|
192
|
+
// If we have pending orphaned tool calls from a previous assistant, insert synthetic results now
|
|
193
|
+
insertSyntheticToolResults();
|
|
194
|
+
// Skip errored/aborted assistant messages entirely.
|
|
195
|
+
// These are incomplete turns that shouldn't be replayed:
|
|
196
|
+
// - May have partial content (reasoning without message, incomplete tool calls)
|
|
197
|
+
// - Replaying them can cause API errors (e.g., OpenAI "reasoning without following item")
|
|
198
|
+
// - The model should retry from the last valid state
|
|
199
|
+
const assistantMsg = msg;
|
|
200
|
+
if (assistantMsg.stopReason === "error" || assistantMsg.stopReason === "aborted") {
|
|
186
201
|
continue;
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
202
|
+
}
|
|
203
|
+
// Track tool calls from this assistant message
|
|
204
|
+
const toolCalls = assistantMsg.content.filter((b) => b.type === "toolCall");
|
|
205
|
+
if (toolCalls.length > 0) {
|
|
206
|
+
pendingToolCalls = toolCalls;
|
|
207
|
+
existingToolResultIds = new Set();
|
|
208
|
+
}
|
|
209
|
+
result.push(msg);
|
|
190
210
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
if (message.role === "toolResult") {
|
|
195
|
-
const entry = toolResultsById
|
|
196
|
-
.get(message.toolCallId)
|
|
197
|
-
?.find((candidate) => candidate.sourceIndex === sourceIndex);
|
|
198
|
-
if (!entry?.consumed)
|
|
199
|
-
result.push(message);
|
|
200
|
-
continue;
|
|
211
|
+
else if (msg.role === "toolResult") {
|
|
212
|
+
existingToolResultIds.add(msg.toolCallId);
|
|
213
|
+
result.push(msg);
|
|
201
214
|
}
|
|
202
|
-
if (
|
|
203
|
-
|
|
204
|
-
|
|
215
|
+
else if (msg.role === "user") {
|
|
216
|
+
// User message interrupts tool flow - insert synthetic results for orphaned calls
|
|
217
|
+
insertSyntheticToolResults();
|
|
218
|
+
result.push(msg);
|
|
205
219
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
if (message.stopReason === "error" || message.stopReason === "aborted")
|
|
209
|
-
continue;
|
|
210
|
-
result.push(message);
|
|
211
|
-
for (const block of message.content) {
|
|
212
|
-
if (block.type !== "toolCall")
|
|
213
|
-
continue;
|
|
214
|
-
const laterDeclarations = nextToolCallIndexById.get(block.id) ?? [];
|
|
215
|
-
const nextDeclarationIndex = laterDeclarations.find((index) => index > sourceIndex) ?? Infinity;
|
|
216
|
-
const matchedResult = toolResultsById
|
|
217
|
-
.get(block.id)
|
|
218
|
-
?.find((candidate) => !candidate.consumed &&
|
|
219
|
-
candidate.sourceIndex > sourceIndex &&
|
|
220
|
-
candidate.sourceIndex < nextDeclarationIndex);
|
|
221
|
-
if (matchedResult) {
|
|
222
|
-
matchedResult.consumed = true;
|
|
223
|
-
result.push(matchedResult.message);
|
|
224
|
-
continue;
|
|
225
|
-
}
|
|
226
|
-
result.push({
|
|
227
|
-
role: "toolResult",
|
|
228
|
-
toolCallId: block.id,
|
|
229
|
-
toolName: block.name,
|
|
230
|
-
content: [{ type: "text", text: "No result provided" }],
|
|
231
|
-
isError: true,
|
|
232
|
-
timestamp: Date.now(),
|
|
233
|
-
});
|
|
220
|
+
else {
|
|
221
|
+
result.push(msg);
|
|
234
222
|
}
|
|
235
223
|
}
|
|
224
|
+
// If the conversation ends with unresolved tool calls, synthesize results now.
|
|
225
|
+
insertSyntheticToolResults();
|
|
236
226
|
return result;
|
|
237
227
|
}
|
|
238
228
|
//# sourceMappingURL=transform-messages.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform-messages.js","sourceRoot":"","sources":["../../src/api/transform-messages.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,iCAAiC,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AAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,oBAAoB,EAAE,CAAC;gBACvD,OAAO,EAAE,IAAI;gBACb,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;aACA,CAAC,CAAC;QACzB,CAAC;IACF,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["import type {\n\tApi,\n\tAssistantMessage,\n\tImageContent,\n\tMessage,\n\tModel,\n\tTextContent,\n\tToolCall,\n\tToolResultMessage,\n} from \"../types.ts\";\nimport { isVideoMimeType } from \"../types.ts\";\n\nconst NON_VISION_USER_IMAGE_PLACEHOLDER = \"(image omitted: model does not support images)\";\nconst NON_VISION_TOOL_IMAGE_PLACEHOLDER = \"(tool image omitted: model does not support images)\";\nconst NO_VIDEO_USER_PLACEHOLDER = \"(video omitted: model does not support video input)\";\nconst NO_VIDEO_TOOL_PLACEHOLDER = \"(tool video omitted: model does not support video input)\";\n\nfunction replaceMediaWithPlaceholder(\n\tcontent: (TextContent | ImageContent)[],\n\tplaceholder: string,\n\tmatches: (block: ImageContent) => boolean,\n): (TextContent | ImageContent)[] {\n\tif (!content.some((block) => block.type === \"image\" && matches(block))) {\n\t\treturn content;\n\t}\n\tconst result: (TextContent | ImageContent)[] = [];\n\tlet previousWasPlaceholder = false;\n\n\tfor (const block of content) {\n\t\tif (block.type === \"image\" && matches(block)) {\n\t\t\tif (!previousWasPlaceholder) {\n\t\t\t\tresult.push({ type: \"text\", text: placeholder });\n\t\t\t}\n\t\t\tpreviousWasPlaceholder = true;\n\t\t\tcontinue;\n\t\t}\n\n\t\tresult.push(block);\n\t\tpreviousWasPlaceholder = block.type === \"text\" && block.text === placeholder;\n\t}\n\n\treturn result;\n}\n\nfunction replaceImagesWithPlaceholder(content: (TextContent | ImageContent)[], placeholder: string): TextContent[] {\n\tconst result: TextContent[] = [];\n\tlet previousWasPlaceholder = false;\n\n\tfor (const block of content) {\n\t\tif (block.type === \"image\") {\n\t\t\tif (!previousWasPlaceholder) {\n\t\t\t\tresult.push({ type: \"text\", text: placeholder });\n\t\t\t}\n\t\t\tpreviousWasPlaceholder = true;\n\t\t\tcontinue;\n\t\t}\n\n\t\tresult.push(block);\n\t\tpreviousWasPlaceholder = block.text === placeholder;\n\t}\n\n\treturn result;\n}\n\nfunction downgradeUnsupportedImages<TApi extends Api>(messages: Message[], model: Model<TApi>): Message[] {\n\tconst supportsImages = model.input.includes(\"image\");\n\tconst supportsVideo = model.input.includes(\"video\");\n\tif (supportsImages && supportsVideo) {\n\t\treturn messages;\n\t}\n\n\treturn messages.map((msg) => {\n\t\tif (msg.role === \"user\" && Array.isArray(msg.content)) {\n\t\t\tlet content = msg.content;\n\t\t\t// Video payloads ride ImageContent blocks; strip them first for models\n\t\t\t// without the \"video\" modality so they never hit an incompatible wire.\n\t\t\tif (!supportsVideo) {\n\t\t\t\tcontent = replaceMediaWithPlaceholder(content, NO_VIDEO_USER_PLACEHOLDER, (b) =>\n\t\t\t\t\tisVideoMimeType(b.mimeType),\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (!supportsImages) {\n\t\t\t\tcontent = replaceImagesWithPlaceholder(content, NON_VISION_USER_IMAGE_PLACEHOLDER);\n\t\t\t}\n\t\t\treturn { ...msg, content };\n\t\t}\n\n\t\tif (msg.role === \"toolResult\") {\n\t\t\tlet content = msg.content;\n\t\t\tif (!supportsVideo) {\n\t\t\t\tcontent = replaceMediaWithPlaceholder(content, NO_VIDEO_TOOL_PLACEHOLDER, (b) =>\n\t\t\t\t\tisVideoMimeType(b.mimeType),\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (!supportsImages) {\n\t\t\t\tcontent = replaceImagesWithPlaceholder(content, NON_VISION_TOOL_IMAGE_PLACEHOLDER);\n\t\t\t}\n\t\t\treturn { ...msg, content };\n\t\t}\n\n\t\treturn msg;\n\t});\n}\n\nexport interface TransformMessagesOptions {\n\t/**\n\t * Preserve provider-native thinking/reasoning replay state for the current\n\t * model. When false, standalone same-model thinking is omitted, while\n\t * thinking attached to tool calls is preserved for provider validation.\n\t */\n\tpreserveThinking?: boolean;\n\tpreserveTextSignatures?: boolean;\n\t/**\n\t * Preserve same-model thinking blocks that do not carry a usable signature\n\t * so provider adapters can downgrade them to plain text or provider-specific\n\t * compatibility payloads.\n\t */\n\tpreserveUnsignedThinking?: boolean;\n}\n\n/**\n * Normalize tool call ID for cross-provider compatibility.\n * OpenAI Responses API generates IDs that are 450+ chars with special characters like `|`.\n * Anthropic APIs require IDs matching ^[a-zA-Z0-9_-]+$ (max 64 chars).\n */\nexport function transformMessages<TApi extends Api>(\n\tmessages: Message[],\n\tmodel: Model<TApi>,\n\tnormalizeToolCallId?: (id: string, model: Model<TApi>, source: AssistantMessage) => string,\n\toptions: TransformMessagesOptions = {},\n): Message[] {\n\t// Build a map of original tool call IDs to normalized IDs\n\tconst toolCallIdMap = new Map<string, string>();\n\t// Normalize null/undefined content from untyped callers (custom tools, hand-built\n\t// histories, old session files) so downstream code can rely on the type contract.\n\tconst normalizedMessages = messages.map((msg) => (msg.content == null ? { ...msg, content: [] } : msg));\n\tconst imageAwareMessages = downgradeUnsupportedImages(normalizedMessages, model);\n\tconst preserveThinking = options.preserveThinking ?? true;\n\tconst preserveTextSignatures = options.preserveTextSignatures ?? false;\n\tconst preserveUnsignedThinking = options.preserveUnsignedThinking ?? false;\n\n\t// First pass: transform messages (unsupported image downgrade, thinking blocks, tool call ID normalization)\n\tconst transformed = imageAwareMessages.map((msg) => {\n\t\t// User messages pass through unchanged\n\t\tif (msg.role === \"user\") {\n\t\t\treturn msg;\n\t\t}\n\n\t\t// Handle toolResult messages - normalize toolCallId if we have a mapping\n\t\tif (msg.role === \"toolResult\") {\n\t\t\tconst normalizedId = toolCallIdMap.get(msg.toolCallId);\n\t\t\tif (normalizedId && normalizedId !== msg.toolCallId) {\n\t\t\t\treturn { ...msg, toolCallId: normalizedId };\n\t\t\t}\n\t\t\treturn msg;\n\t\t}\n\n\t\t// Assistant messages need transformation check\n\t\tif (msg.role === \"assistant\") {\n\t\t\tconst assistantMsg = msg as AssistantMessage;\n\t\t\tconst isSameModel =\n\t\t\t\tassistantMsg.provider === model.provider &&\n\t\t\t\tassistantMsg.api === model.api &&\n\t\t\t\tassistantMsg.model === model.id;\n\t\t\tconst hasToolCalls = assistantMsg.content.some((block) => block.type === \"toolCall\");\n\t\t\tconst preserveProviderState = preserveThinking || hasToolCalls;\n\n\t\t\tconst transformedContent = assistantMsg.content.flatMap((block) => {\n\t\t\t\tif (block.type === \"thinking\") {\n\t\t\t\t\t// Redacted thinking is opaque encrypted content, only valid for the same model.\n\t\t\t\t\t// Drop it for cross-model to avoid API errors.\n\t\t\t\t\tif (block.redacted) {\n\t\t\t\t\t\treturn isSameModel && preserveProviderState ? { ...block } : [];\n\t\t\t\t\t}\n\t\t\t\t\tconst hasUsableSignature =\n\t\t\t\t\t\ttypeof block.thinkingSignature === \"string\" && block.thinkingSignature.trim().length > 0;\n\t\t\t\t\t// For same model: keep signed thinking only while replaying provider state.\n\t\t\t\t\t// Empty signed blocks are opaque compatibility state, not visible reasoning.\n\t\t\t\t\tif (isSameModel && hasUsableSignature && (preserveProviderState || block.thinking.trim() === \"\")) {\n\t\t\t\t\t\treturn { ...block };\n\t\t\t\t\t}\n\t\t\t\t\t// Skip empty thinking blocks, convert others to plain text\n\t\t\t\t\tif (!block.thinking || block.thinking.trim() === \"\") return [];\n\t\t\t\t\tif (isSameModel) {\n\t\t\t\t\t\treturn preserveProviderState || (preserveUnsignedThinking && !hasUsableSignature) ? { ...block } : [];\n\t\t\t\t\t}\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\ttext: block.thinking,\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tif (block.type === \"text\") {\n\t\t\t\t\tif (isSameModel && (preserveProviderState || preserveTextSignatures)) return { ...block };\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\ttext: block.text,\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tif (block.type === \"toolCall\") {\n\t\t\t\t\tconst toolCall = block as ToolCall;\n\t\t\t\t\tlet normalizedToolCall: ToolCall = { ...toolCall };\n\n\t\t\t\t\tif ((!isSameModel || !preserveProviderState) && toolCall.thoughtSignature) {\n\t\t\t\t\t\tdelete (normalizedToolCall as { thoughtSignature?: string }).thoughtSignature;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (!isSameModel && normalizeToolCallId) {\n\t\t\t\t\t\tconst normalizedId = normalizeToolCallId(toolCall.id, model, assistantMsg);\n\t\t\t\t\t\tif (normalizedId !== toolCall.id) {\n\t\t\t\t\t\t\ttoolCallIdMap.set(toolCall.id, normalizedId);\n\t\t\t\t\t\t\tnormalizedToolCall = { ...normalizedToolCall, id: normalizedId };\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\treturn normalizedToolCall;\n\t\t\t\t}\n\n\t\t\t\treturn block;\n\t\t\t});\n\n\t\t\treturn {\n\t\t\t\t...assistantMsg,\n\t\t\t\tcontent: transformedContent,\n\t\t\t};\n\t\t}\n\t\treturn msg;\n\t});\n\n\t// Second pass: pair every replayable tool call with the earliest unconsumed\n\t// result after its declaring assistant. Results are emitted adjacent to their\n\t// calls because Anthropic requires that ordering. A reused ID starts a new\n\t// pairing window, so a later result cannot repair an earlier call.\n\tconst result: Message[] = [];\n\tconst toolResultsById = new Map<string, { message: ToolResultMessage; sourceIndex: number; consumed: boolean }[]>();\n\tconst nextToolCallIndexById = new Map<string, number[]>();\n\n\tfor (let sourceIndex = 0; sourceIndex < transformed.length; sourceIndex++) {\n\t\tconst message = transformed[sourceIndex];\n\t\tif (message.role === \"toolResult\") {\n\t\t\tconst entries = toolResultsById.get(message.toolCallId) ?? [];\n\t\t\tentries.push({ message, sourceIndex, consumed: false });\n\t\t\ttoolResultsById.set(message.toolCallId, entries);\n\t\t\tcontinue;\n\t\t}\n\t\tif (message.role !== \"assistant\" || message.stopReason === \"error\" || message.stopReason === \"aborted\") {\n\t\t\tcontinue;\n\t\t}\n\t\tfor (const block of message.content) {\n\t\t\tif (block.type !== \"toolCall\") continue;\n\t\t\tconst indexes = nextToolCallIndexById.get(block.id) ?? [];\n\t\t\tindexes.push(sourceIndex);\n\t\t\tnextToolCallIndexById.set(block.id, indexes);\n\t\t}\n\t}\n\n\tfor (let sourceIndex = 0; sourceIndex < transformed.length; sourceIndex++) {\n\t\tconst message = transformed[sourceIndex];\n\t\tif (message.role === \"toolResult\") {\n\t\t\tconst entry = toolResultsById\n\t\t\t\t.get(message.toolCallId)\n\t\t\t\t?.find((candidate) => candidate.sourceIndex === sourceIndex);\n\t\t\tif (!entry?.consumed) result.push(message);\n\t\t\tcontinue;\n\t\t}\n\t\tif (message.role !== \"assistant\") {\n\t\t\tresult.push(message);\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Skip errored/aborted assistant messages entirely. These incomplete turns\n\t\t// must not be revived merely because a matching result appears later.\n\t\tif (message.stopReason === \"error\" || message.stopReason === \"aborted\") continue;\n\n\t\tresult.push(message);\n\t\tfor (const block of message.content) {\n\t\t\tif (block.type !== \"toolCall\") continue;\n\t\t\tconst laterDeclarations = nextToolCallIndexById.get(block.id) ?? [];\n\t\t\tconst nextDeclarationIndex = laterDeclarations.find((index) => index > sourceIndex) ?? Infinity;\n\t\t\tconst matchedResult = toolResultsById\n\t\t\t\t.get(block.id)\n\t\t\t\t?.find(\n\t\t\t\t\t(candidate) =>\n\t\t\t\t\t\t!candidate.consumed &&\n\t\t\t\t\t\tcandidate.sourceIndex > sourceIndex &&\n\t\t\t\t\t\tcandidate.sourceIndex < nextDeclarationIndex,\n\t\t\t\t);\n\n\t\t\tif (matchedResult) {\n\t\t\t\tmatchedResult.consumed = true;\n\t\t\t\tresult.push(matchedResult.message);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tresult.push({\n\t\t\t\trole: \"toolResult\",\n\t\t\t\ttoolCallId: block.id,\n\t\t\t\ttoolName: block.name,\n\t\t\t\tcontent: [{ type: \"text\", text: \"No result provided\" }],\n\t\t\t\tisError: true,\n\t\t\t\ttimestamp: Date.now(),\n\t\t\t} as ToolResultMessage);\n\t\t}\n\t}\n\n\treturn result;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"transform-messages.js","sourceRoot":"","sources":["../../src/api/transform-messages.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,iCAAiC,GAAG,gDAAgD,CAAC;AAC3F,MAAM,iCAAiC,GAAG,qDAAqD,CAAC;AAChG,MAAM,yBAAyB,GAAG,qDAAqD,CAAC;AACxF,MAAM,yBAAyB,GAAG,0DAA0D,CAAC;AAE7F,SAAS,2BAA2B,CACnC,OAAuC,EACvC,WAAmB,EACnB,OAAyC;IAEzC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,OAAO,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;QACxE,OAAO,OAAO,CAAC;IAChB,CAAC;IACD,MAAM,MAAM,GAAmC,EAAE,CAAC;IAClD,IAAI,sBAAsB,GAAG,KAAK,CAAC;IAEnC,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC7B,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,IAAI,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAC9C,IAAI,CAAC,sBAAsB,EAAE,CAAC;gBAC7B,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CAAC;YAClD,CAAC;YACD,sBAAsB,GAAG,IAAI,CAAC;YAC9B,SAAS;QACV,CAAC;QAED,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACnB,sBAAsB,GAAG,KAAK,CAAC,IAAI,KAAK,MAAM,IAAI,KA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YAC/C,MAAM,SAAS,GAAG,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,UAAU,CAAe,CAAC;YAC1F,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC1B,gBAAgB,GAAG,SAAS,CAAC;gBAC7B,qBAAqB,GAAG,IAAI,GAAG,EAAE,CAAC;YACnC,CAAC;YAED,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAClB,CAAC;aAAM,IAAI,GAAG,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;YACtC,qBAAqB,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;YAC1C,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAClB,CAAC;aAAM,IAAI,GAAG,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YAChC,kFAAkF;YAClF,0BAA0B,EAAE,CAAC;YAC7B,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAClB,CAAC;aAAM,CAAC;YACP,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAClB,CAAC;IACF,CAAC;IAED,+EAA+E;IAC/E,0BAA0B,EAAE,CAAC;IAE7B,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["import type {\n\tApi,\n\tAssistantMessage,\n\tImageContent,\n\tMessage,\n\tModel,\n\tTextContent,\n\tToolCall,\n\tToolResultMessage,\n} from \"../types.ts\";\nimport { isVideoMimeType } from \"../types.ts\";\n\nconst NON_VISION_USER_IMAGE_PLACEHOLDER = \"(image omitted: model does not support images)\";\nconst NON_VISION_TOOL_IMAGE_PLACEHOLDER = \"(tool image omitted: model does not support images)\";\nconst NO_VIDEO_USER_PLACEHOLDER = \"(video omitted: model does not support video input)\";\nconst NO_VIDEO_TOOL_PLACEHOLDER = \"(tool video omitted: model does not support video input)\";\n\nfunction replaceMediaWithPlaceholder(\n\tcontent: (TextContent | ImageContent)[],\n\tplaceholder: string,\n\tmatches: (block: ImageContent) => boolean,\n): (TextContent | ImageContent)[] {\n\tif (!content.some((block) => block.type === \"image\" && matches(block))) {\n\t\treturn content;\n\t}\n\tconst result: (TextContent | ImageContent)[] = [];\n\tlet previousWasPlaceholder = false;\n\n\tfor (const block of content) {\n\t\tif (block.type === \"image\" && matches(block)) {\n\t\t\tif (!previousWasPlaceholder) {\n\t\t\t\tresult.push({ type: \"text\", text: placeholder });\n\t\t\t}\n\t\t\tpreviousWasPlaceholder = true;\n\t\t\tcontinue;\n\t\t}\n\n\t\tresult.push(block);\n\t\tpreviousWasPlaceholder = block.type === \"text\" && block.text === placeholder;\n\t}\n\n\treturn result;\n}\n\nfunction replaceImagesWithPlaceholder(content: (TextContent | ImageContent)[], placeholder: string): TextContent[] {\n\tconst result: TextContent[] = [];\n\tlet previousWasPlaceholder = false;\n\n\tfor (const block of content) {\n\t\tif (block.type === \"image\") {\n\t\t\tif (!previousWasPlaceholder) {\n\t\t\t\tresult.push({ type: \"text\", text: placeholder });\n\t\t\t}\n\t\t\tpreviousWasPlaceholder = true;\n\t\t\tcontinue;\n\t\t}\n\n\t\tresult.push(block);\n\t\tpreviousWasPlaceholder = block.text === placeholder;\n\t}\n\n\treturn result;\n}\n\nfunction downgradeUnsupportedImages<TApi extends Api>(messages: Message[], model: Model<TApi>): Message[] {\n\tconst supportsImages = model.input.includes(\"image\");\n\tconst supportsVideo = model.input.includes(\"video\");\n\tif (supportsImages && supportsVideo) {\n\t\treturn messages;\n\t}\n\n\treturn messages.map((msg) => {\n\t\tif (msg.role === \"user\" && Array.isArray(msg.content)) {\n\t\t\tlet content = msg.content;\n\t\t\t// Video payloads ride ImageContent blocks; strip them first for models\n\t\t\t// without the \"video\" modality so they never hit an incompatible wire.\n\t\t\tif (!supportsVideo) {\n\t\t\t\tcontent = replaceMediaWithPlaceholder(content, NO_VIDEO_USER_PLACEHOLDER, (b) =>\n\t\t\t\t\tisVideoMimeType(b.mimeType),\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (!supportsImages) {\n\t\t\t\tcontent = replaceImagesWithPlaceholder(content, NON_VISION_USER_IMAGE_PLACEHOLDER);\n\t\t\t}\n\t\t\treturn { ...msg, content };\n\t\t}\n\n\t\tif (msg.role === \"toolResult\") {\n\t\t\tlet content = msg.content;\n\t\t\tif (!supportsVideo) {\n\t\t\t\tcontent = replaceMediaWithPlaceholder(content, NO_VIDEO_TOOL_PLACEHOLDER, (b) =>\n\t\t\t\t\tisVideoMimeType(b.mimeType),\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (!supportsImages) {\n\t\t\t\tcontent = replaceImagesWithPlaceholder(content, NON_VISION_TOOL_IMAGE_PLACEHOLDER);\n\t\t\t}\n\t\t\treturn { ...msg, content };\n\t\t}\n\n\t\treturn msg;\n\t});\n}\n\nexport interface TransformMessagesOptions {\n\t/**\n\t * Preserve provider-native thinking/reasoning replay state for the current\n\t * model. When false, standalone same-model thinking is omitted, while\n\t * thinking attached to tool calls is preserved for provider validation.\n\t */\n\tpreserveThinking?: boolean;\n\tpreserveTextSignatures?: boolean;\n\t/**\n\t * Preserve same-model thinking blocks that do not carry a usable signature\n\t * so provider adapters can downgrade them to plain text or provider-specific\n\t * compatibility payloads.\n\t */\n\tpreserveUnsignedThinking?: boolean;\n}\n\n/**\n * Normalize tool call ID for cross-provider compatibility.\n * OpenAI Responses API generates IDs that are 450+ chars with special characters like `|`.\n * Anthropic APIs require IDs matching ^[a-zA-Z0-9_-]+$ (max 64 chars).\n */\nexport function transformMessages<TApi extends Api>(\n\tmessages: Message[],\n\tmodel: Model<TApi>,\n\tnormalizeToolCallId?: (id: string, model: Model<TApi>, source: AssistantMessage) => string,\n\toptions: TransformMessagesOptions = {},\n): Message[] {\n\t// Build a map of original tool call IDs to normalized IDs\n\tconst toolCallIdMap = new Map<string, string>();\n\t// Normalize null/undefined content from untyped callers (custom tools, hand-built\n\t// histories, old session files) so downstream code can rely on the type contract.\n\tconst normalizedMessages = messages.map((msg) => (msg.content == null ? { ...msg, content: [] } : msg));\n\tconst imageAwareMessages = downgradeUnsupportedImages(normalizedMessages, model);\n\tconst preserveThinking = options.preserveThinking ?? true;\n\tconst preserveTextSignatures = options.preserveTextSignatures ?? false;\n\tconst preserveUnsignedThinking = options.preserveUnsignedThinking ?? false;\n\n\t// First pass: transform messages (unsupported image downgrade, thinking blocks, tool call ID normalization)\n\tconst transformed = imageAwareMessages.map((msg) => {\n\t\t// User messages pass through unchanged\n\t\tif (msg.role === \"user\") {\n\t\t\treturn msg;\n\t\t}\n\n\t\t// Handle toolResult messages - normalize toolCallId if we have a mapping\n\t\tif (msg.role === \"toolResult\") {\n\t\t\tconst normalizedId = toolCallIdMap.get(msg.toolCallId);\n\t\t\tif (normalizedId && normalizedId !== msg.toolCallId) {\n\t\t\t\treturn { ...msg, toolCallId: normalizedId };\n\t\t\t}\n\t\t\treturn msg;\n\t\t}\n\n\t\t// Assistant messages need transformation check\n\t\tif (msg.role === \"assistant\") {\n\t\t\tconst assistantMsg = msg as AssistantMessage;\n\t\t\tconst isSameModel =\n\t\t\t\tassistantMsg.provider === model.provider &&\n\t\t\t\tassistantMsg.api === model.api &&\n\t\t\t\tassistantMsg.model === model.id;\n\t\t\tconst hasToolCalls = assistantMsg.content.some((block) => block.type === \"toolCall\");\n\t\t\tconst preserveProviderState = preserveThinking || hasToolCalls;\n\n\t\t\tconst transformedContent = assistantMsg.content.flatMap((block) => {\n\t\t\t\tif (block.type === \"thinking\") {\n\t\t\t\t\t// Redacted thinking is opaque encrypted content, only valid for the same model.\n\t\t\t\t\t// Drop it for cross-model to avoid API errors.\n\t\t\t\t\tif (block.redacted) {\n\t\t\t\t\t\treturn isSameModel && preserveProviderState ? { ...block } : [];\n\t\t\t\t\t}\n\t\t\t\t\tconst hasUsableSignature =\n\t\t\t\t\t\ttypeof block.thinkingSignature === \"string\" && block.thinkingSignature.trim().length > 0;\n\t\t\t\t\t// For same model: keep signed thinking only while replaying provider state.\n\t\t\t\t\t// Empty signed blocks are opaque compatibility state, not visible reasoning.\n\t\t\t\t\tif (isSameModel && hasUsableSignature && (preserveProviderState || block.thinking.trim() === \"\")) {\n\t\t\t\t\t\treturn { ...block };\n\t\t\t\t\t}\n\t\t\t\t\t// Skip empty thinking blocks, convert others to plain text\n\t\t\t\t\tif (!block.thinking || block.thinking.trim() === \"\") return [];\n\t\t\t\t\tif (isSameModel) {\n\t\t\t\t\t\treturn preserveProviderState || (preserveUnsignedThinking && !hasUsableSignature) ? { ...block } : [];\n\t\t\t\t\t}\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\ttext: block.thinking,\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tif (block.type === \"text\") {\n\t\t\t\t\tif (isSameModel && (preserveProviderState || preserveTextSignatures)) return { ...block };\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\ttext: block.text,\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tif (block.type === \"toolCall\") {\n\t\t\t\t\tconst toolCall = block as ToolCall;\n\t\t\t\t\tlet normalizedToolCall: ToolCall = { ...toolCall };\n\n\t\t\t\t\tif ((!isSameModel || !preserveProviderState) && toolCall.thoughtSignature) {\n\t\t\t\t\t\tdelete (normalizedToolCall as { thoughtSignature?: string }).thoughtSignature;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (!isSameModel && normalizeToolCallId) {\n\t\t\t\t\t\tconst normalizedId = normalizeToolCallId(toolCall.id, model, assistantMsg);\n\t\t\t\t\t\tif (normalizedId !== toolCall.id) {\n\t\t\t\t\t\t\ttoolCallIdMap.set(toolCall.id, normalizedId);\n\t\t\t\t\t\t\tnormalizedToolCall = { ...normalizedToolCall, id: normalizedId };\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\treturn normalizedToolCall;\n\t\t\t\t}\n\n\t\t\t\treturn block;\n\t\t\t});\n\n\t\t\treturn {\n\t\t\t\t...assistantMsg,\n\t\t\t\tcontent: transformedContent,\n\t\t\t};\n\t\t}\n\t\treturn msg;\n\t});\n\n\t// Second pass: insert synthetic empty tool results for orphaned tool calls\n\t// This preserves thinking signatures and satisfies API requirements\n\tconst result: Message[] = [];\n\tlet pendingToolCalls: ToolCall[] = [];\n\tlet existingToolResultIds = new Set<string>();\n\tconst insertSyntheticToolResults = () => {\n\t\tif (pendingToolCalls.length > 0) {\n\t\t\tfor (const tc of pendingToolCalls) {\n\t\t\t\tif (!existingToolResultIds.has(tc.id)) {\n\t\t\t\t\tresult.push({\n\t\t\t\t\t\trole: \"toolResult\",\n\t\t\t\t\t\ttoolCallId: tc.id,\n\t\t\t\t\t\ttoolName: tc.name,\n\t\t\t\t\t\tcontent: [{ type: \"text\", text: \"No result provided\" }],\n\t\t\t\t\t\tisError: true,\n\t\t\t\t\t\ttimestamp: Date.now(),\n\t\t\t\t\t} as ToolResultMessage);\n\t\t\t\t}\n\t\t\t}\n\t\t\tpendingToolCalls = [];\n\t\t\texistingToolResultIds = new Set();\n\t\t}\n\t};\n\n\tfor (let i = 0; i < transformed.length; i++) {\n\t\tconst msg = transformed[i];\n\n\t\tif (msg.role === \"assistant\") {\n\t\t\t// If we have pending orphaned tool calls from a previous assistant, insert synthetic results now\n\t\t\tinsertSyntheticToolResults();\n\n\t\t\t// Skip errored/aborted assistant messages entirely.\n\t\t\t// These are incomplete turns that shouldn't be replayed:\n\t\t\t// - May have partial content (reasoning without message, incomplete tool calls)\n\t\t\t// - Replaying them can cause API errors (e.g., OpenAI \"reasoning without following item\")\n\t\t\t// - The model should retry from the last valid state\n\t\t\tconst assistantMsg = msg as AssistantMessage;\n\t\t\tif (assistantMsg.stopReason === \"error\" || assistantMsg.stopReason === \"aborted\") {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Track tool calls from this assistant message\n\t\t\tconst toolCalls = assistantMsg.content.filter((b) => b.type === \"toolCall\") as ToolCall[];\n\t\t\tif (toolCalls.length > 0) {\n\t\t\t\tpendingToolCalls = toolCalls;\n\t\t\t\texistingToolResultIds = new Set();\n\t\t\t}\n\n\t\t\tresult.push(msg);\n\t\t} else if (msg.role === \"toolResult\") {\n\t\t\texistingToolResultIds.add(msg.toolCallId);\n\t\t\tresult.push(msg);\n\t\t} else if (msg.role === \"user\") {\n\t\t\t// User message interrupts tool flow - insert synthetic results for orphaned calls\n\t\t\tinsertSyntheticToolResults();\n\t\t\tresult.push(msg);\n\t\t} else {\n\t\t\tresult.push(msg);\n\t\t}\n\t}\n\n\t// If the conversation ends with unresolved tool calls, synthesize results now.\n\tinsertSyntheticToolResults();\n\n\treturn result;\n}\n"]}
|
|
@@ -28,7 +28,6 @@ export * from "./utils/event-stream.ts";
|
|
|
28
28
|
export * from "./utils/json-parse.ts";
|
|
29
29
|
export * from "./utils/overflow.ts";
|
|
30
30
|
export * from "./utils/retry.ts";
|
|
31
|
-
export * from "./utils/stop-details.ts";
|
|
32
31
|
export * from "./utils/tool-pair-repair.ts";
|
|
33
32
|
export * from "./utils/typebox-helpers.ts";
|
|
34
33
|
export * from "./utils/validation.ts";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAO/B,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AAC/G,YAAY,EAAE,2BAA2B,EAAE,MAAM,iCAAiC,CAAC;AACnF,YAAY,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;AAC/F,YAAY,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACnE,YAAY,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAClE,Y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js";
|
|
16
16
|
export * from "./utils/overflow.js";
|
|
17
17
|
export * from "./utils/retry.js";
|
|
18
|
-
export * from "./utils/stop-details.js";
|
|
19
18
|
export * from "./utils/tool-pair-repair.js";
|
|
20
19
|
export * from "./utils/typebox-helpers.js";
|
|
21
20
|
export * from "./utils/validation.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAa/B,cAAc,eAAe,CAAC;AAM9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAUhC,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,YAAY,CAAC;AAC3B,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAa/B,cAAc,eAAe,CAAC;AAM9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAUhC,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,YAAY,CAAC;AAC3B,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC","sourcesContent":["export type { Static, TSchema } from \"typebox\";\nexport { Type } from \"typebox\";\n\n// Core only, side-effect free: no generated catalogs, no provider factories,\n// no api-registry, no OAuth implementations, no compat. Provider factories\n// live under \"@earendil-works/pi-ai/providers/*\", API implementations under\n// \"@earendil-works/pi-ai/api/*\", the old global API under\n// \"@earendil-works/pi-ai/compat\".\nexport type { AnthropicEffort, AnthropicOptions, AnthropicThinkingDisplay } from \"./api/anthropic-messages.ts\";\nexport type { AzureOpenAIResponsesOptions } from \"./api/azure-openai-responses.ts\";\nexport type { BedrockOptions, BedrockThinkingDisplay } from \"./api/bedrock-converse-stream.ts\";\nexport type { GoogleOptions } from \"./api/google-generative-ai.ts\";\nexport type { GoogleThinkingLevel } from \"./api/google-shared.ts\";\nexport type { GoogleVertexOptions } from \"./api/google-vertex.ts\";\nexport * from \"./api/lazy.ts\";\nexport type { MistralOptions } from \"./api/mistral-conversations.ts\";\nexport type { OpenAICodexResponsesOptions, OpenAICodexWebSocketDebugStats } from \"./api/openai-codex-responses.ts\";\nexport type { OpenAICompletionsOptions } from \"./api/openai-completions.ts\";\nexport type { OpenAIResponsesOptions } from \"./api/openai-responses.ts\";\nexport type { PiMessagesEvent, PiMessagesOptions, PiMessagesRewriteImpact } from \"./api/pi-messages.ts\";\nexport * from \"./auth/context.ts\";\nexport * from \"./auth/credential-store.ts\";\nexport * from \"./auth/helpers.ts\";\nexport * from \"./auth/types.ts\";\nexport type {\n\tOAuthAuthInfo,\n\tOAuthDeviceCodeInfo,\n\tOAuthLoginCallbacks,\n\tOAuthPrompt,\n\tOAuthProviderId,\n\tOAuthSelectOption,\n\tOAuthSelectPrompt,\n} from \"./compat/extension-oauth-types.ts\";\nexport * from \"./images-models.ts\";\nexport * from \"./models.ts\";\nexport * from \"./models-store.ts\";\nexport * from \"./providers/faux.ts\";\nexport * from \"./session-resources.ts\";\nexport * from \"./types.ts\";\nexport * from \"./utils/diagnostics.ts\";\nexport * from \"./utils/event-stream.ts\";\nexport * from \"./utils/json-parse.ts\";\nexport * from \"./utils/overflow.ts\";\nexport * from \"./utils/retry.ts\";\nexport * from \"./utils/tool-pair-repair.ts\";\nexport * from \"./utils/typebox-helpers.ts\";\nexport * from \"./utils/validation.ts\";\n"]}
|
|
@@ -1460,6 +1460,10 @@ export declare const MODELS: {
|
|
|
1460
1460
|
};
|
|
1461
1461
|
};
|
|
1462
1462
|
readonly "kimi-coding": {
|
|
1463
|
+
k2p7: import("./types.ts").Model<"anthropic-messages"> & {
|
|
1464
|
+
id: "k2p7";
|
|
1465
|
+
provider: "kimi-coding";
|
|
1466
|
+
};
|
|
1463
1467
|
k3: import("./types.ts").Model<"anthropic-messages"> & {
|
|
1464
1468
|
id: "k3";
|
|
1465
1469
|
provider: "kimi-coding";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"models.generated.d.ts","sourceRoot":"","sources":["../src/models.generated.ts"],"names":[],"mappings":"AAuCA,eAAO,MAAM,MAAM;aAClB,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aACnB,GAAK;;;;;;;;;;;;;;aACL,MAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;aACR,uBAAuB;;;;;;;;;;;;;;aACvB,sBAAsB;;;;;;;;;;;;;;aACtB,uBAAuB;;;;;;;;;;;;;;aACvB,GAAK;;;;;;;;;;;;;;;;;;;;;;;;;;aACL,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;CACN,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"k3":{"id":"k3","name":"Kimi K3","api":"anthropic-messages","provider":"kimi-coding","baseUrl":"https://api.kimi.com/coding","headers":{"User-Agent":"KimiCLI/1.5"},"compat":{"allowEmptySignature":true,"forceAdaptiveThinking":true},"reasoning":true,"thinkingLevelMap":{"off":null,"minimal":null,"low":null,"medium":null,"high":null,"xhigh":null,"max":"max"},"input":["text","image","video"],"cost":{"input":3,"output":15,"cacheRead":0.3,"cacheWrite":0},"contextWindow":1048576,"maxTokens":131072},"kimi-for-coding":{"id":"kimi-for-coding","name":"Kimi
|
|
1
|
+
{"k2p7":{"id":"k2p7","name":"Kimi K2.7 Code","api":"anthropic-messages","provider":"kimi-coding","baseUrl":"https://api.kimi.com/coding","headers":{"User-Agent":"KimiCLI/1.5"},"compat":{"forceAdaptiveThinking":true},"reasoning":true,"input":["text","image"],"cost":{"input":0.95,"output":4,"cacheRead":0.19,"cacheWrite":0},"contextWindow":262144,"maxTokens":32768},"k3":{"id":"k3","name":"Kimi K3","api":"anthropic-messages","provider":"kimi-coding","baseUrl":"https://api.kimi.com/coding","headers":{"User-Agent":"KimiCLI/1.5"},"compat":{"allowEmptySignature":true,"forceAdaptiveThinking":true},"reasoning":true,"thinkingLevelMap":{"off":null,"minimal":null,"low":null,"medium":null,"high":null,"xhigh":null,"max":"max"},"input":["text","image","video"],"cost":{"input":3,"output":15,"cacheRead":0.3,"cacheWrite":0},"contextWindow":1048576,"maxTokens":131072},"kimi-for-coding":{"id":"kimi-for-coding","name":"Kimi For Coding","api":"anthropic-messages","provider":"kimi-coding","baseUrl":"https://api.kimi.com/coding","headers":{"User-Agent":"KimiCLI/1.5"},"compat":{"allowEmptySignature":true,"forceAdaptiveThinking":true},"reasoning":true,"input":["text","image"],"cost":{"input":0.95,"output":4,"cacheRead":0.19,"cacheWrite":0},"contextWindow":262144,"maxTokens":32768},"kimi-for-coding-highspeed":{"id":"kimi-for-coding-highspeed","name":"Kimi For Coding HighSpeed","api":"anthropic-messages","provider":"kimi-coding","baseUrl":"https://api.kimi.com/coding","headers":{"User-Agent":"KimiCLI/1.5"},"compat":{"forceAdaptiveThinking":true},"reasoning":true,"input":["text","image"],"cost":{"input":1.9,"output":8,"cacheRead":0.38,"cacheWrite":0},"contextWindow":262144,"maxTokens":32768},"kimi-k2-thinking":{"id":"kimi-k2-thinking","name":"Kimi K2 Thinking","api":"anthropic-messages","provider":"kimi-coding","baseUrl":"https://api.kimi.com/coding","headers":{"User-Agent":"KimiCLI/1.5"},"compat":{"forceAdaptiveThinking":true},"reasoning":true,"input":["text"],"cost":{"input":0.6,"output":2.5,"cacheRead":0.15,"cacheWrite":0},"contextWindow":262144,"maxTokens":32768}}
|