@oh-my-pi/pi-ai 5.6.70 → 5.7.67
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/package.json +1 -1
- package/src/cli.ts +3 -0
- package/src/providers/transform-messages.ts +19 -8
package/package.json
CHANGED
package/src/cli.ts
CHANGED
|
@@ -127,16 +127,27 @@ export function transformMessages<TApi extends Api>(messages: Message[], model:
|
|
|
127
127
|
|
|
128
128
|
// For errored/aborted messages with tool calls, insert synthetic results immediately
|
|
129
129
|
// to maintain tool_use/tool_result pairing required by the API
|
|
130
|
+
// BUT only if there aren't already tool results for these calls later in the array
|
|
130
131
|
if (isErroredAssistant && toolCalls.length > 0) {
|
|
132
|
+
// Look ahead to find existing tool results
|
|
133
|
+
const existingResultIds = new Set<string>();
|
|
134
|
+
for (let j = i + 1; j < transformed.length; j++) {
|
|
135
|
+
if (transformed[j].role === "toolResult") {
|
|
136
|
+
existingResultIds.add((transformed[j] as ToolResultMessage).toolCallId);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
// Only add synthetic results for tool calls that don't have results
|
|
131
140
|
for (const tc of toolCalls) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
141
|
+
if (!existingResultIds.has(tc.id)) {
|
|
142
|
+
result.push({
|
|
143
|
+
role: "toolResult",
|
|
144
|
+
toolCallId: tc.id,
|
|
145
|
+
toolName: tc.name,
|
|
146
|
+
content: [{ type: "text", text: "Tool execution was aborted" }],
|
|
147
|
+
isError: true,
|
|
148
|
+
timestamp: Date.now(),
|
|
149
|
+
} as ToolResultMessage);
|
|
150
|
+
}
|
|
140
151
|
}
|
|
141
152
|
} else if (!isErroredAssistant && toolCalls.length > 0) {
|
|
142
153
|
// Track tool calls to check for orphaned calls later
|