@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oh-my-pi/pi-ai",
3
- "version": "5.6.70",
3
+ "version": "5.7.67",
4
4
  "description": "Unified LLM API with automatic model discovery and provider configuration",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
package/src/cli.ts CHANGED
@@ -98,6 +98,9 @@ async function login(provider: OAuthProvider): Promise<void> {
98
98
  onProgress: (msg) => console.log(msg),
99
99
  });
100
100
  break;
101
+
102
+ default:
103
+ throw new Error(`Unknown provider: ${provider}`);
101
104
  }
102
105
 
103
106
  const auth = loadAuth();
@@ -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
- result.push({
133
- role: "toolResult",
134
- toolCallId: tc.id,
135
- toolName: tc.name,
136
- content: [{ type: "text", text: "Tool execution was aborted" }],
137
- isError: true,
138
- timestamp: Date.now(),
139
- } as ToolResultMessage);
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