@skydiveai/pi-extensions 0.1.259-beta.6 → 0.1.259
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +15 -2
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2731,6 +2731,19 @@ function userContent(content) {
|
|
|
2731
2731
|
};
|
|
2732
2732
|
});
|
|
2733
2733
|
}
|
|
2734
|
+
/**
|
|
2735
|
+
* Anthropic rejects the whole request when any replayed tool_use id fails
|
|
2736
|
+
* `^[a-zA-Z0-9_-]+$` (64 chars max). History written by another seat carries
|
|
2737
|
+
* ids that do not: OpenAI Responses ids look like `call_<32>|fc_<48>`, so a
|
|
2738
|
+
* conversation moved onto a Claude seat 400s on every step. Mirrors pi-ai's
|
|
2739
|
+
* Anthropic `normalizeToolCallId` (private to its provider, so not importable)
|
|
2740
|
+
* so the seat and the direct Anthropic path replay one conversation with the
|
|
2741
|
+
* same ids. Pure and idempotent: a tool_use and its tool_result need no shared
|
|
2742
|
+
* map, and a valid id passes through untouched so the prompt cache holds.
|
|
2743
|
+
*/
|
|
2744
|
+
function seatToolCallId(id) {
|
|
2745
|
+
return id.replace(/[^a-zA-Z0-9_-]/g, "_").slice(0, 64);
|
|
2746
|
+
}
|
|
2734
2747
|
/** Shared Anthropic message projection for SDK replay and provider hooks. */
|
|
2735
2748
|
function seatHistoryMessage({ message, model, toolName }) {
|
|
2736
2749
|
let converted;
|
|
@@ -2746,7 +2759,7 @@ function seatHistoryMessage({ message, model, toolName }) {
|
|
|
2746
2759
|
role: "user",
|
|
2747
2760
|
content: [{
|
|
2748
2761
|
type: "tool_result",
|
|
2749
|
-
tool_use_id: message.toolCallId,
|
|
2762
|
+
tool_use_id: seatToolCallId(message.toolCallId),
|
|
2750
2763
|
content: userContent(message.content),
|
|
2751
2764
|
is_error: message.isError
|
|
2752
2765
|
}]
|
|
@@ -2761,7 +2774,7 @@ function seatHistoryMessage({ message, model, toolName }) {
|
|
|
2761
2774
|
}] : [];
|
|
2762
2775
|
case "toolCall": return [{
|
|
2763
2776
|
type: "tool_use",
|
|
2764
|
-
id: block.id,
|
|
2777
|
+
id: seatToolCallId(block.id),
|
|
2765
2778
|
name: toolName(block.name),
|
|
2766
2779
|
input: block.arguments
|
|
2767
2780
|
}];
|