oh-my-im 0.1.19 → 0.1.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/dist/agents/pi-agent.js +23 -2
- package/package.json +1 -1
package/dist/agents/pi-agent.js
CHANGED
|
@@ -103,6 +103,7 @@ function runPiOnce(prompt, sessionId, config, callbacks = {}) {
|
|
|
103
103
|
let authoritativeText = "";
|
|
104
104
|
let nextSessionId = sessionId;
|
|
105
105
|
let stderr = "";
|
|
106
|
+
let lastAssistantError = "";
|
|
106
107
|
const toolStats = {};
|
|
107
108
|
const seenToolCalls = new Set();
|
|
108
109
|
const finish = () => {
|
|
@@ -194,13 +195,29 @@ function runPiOnce(prompt, sessionId, config, callbacks = {}) {
|
|
|
194
195
|
return;
|
|
195
196
|
}
|
|
196
197
|
if (event.type === "message_end") {
|
|
198
|
+
const message = asObject(event.message);
|
|
199
|
+
// pi reports model/auth failures as an assistant message with empty
|
|
200
|
+
// content and stopReason "error". Surface errorMessage at settle time
|
|
201
|
+
// instead of returning a bogus successful empty reply ("无输出").
|
|
202
|
+
if (message?.role === "assistant") {
|
|
203
|
+
lastAssistantError = message.stopReason === "error" && typeof message.errorMessage === "string"
|
|
204
|
+
? message.errorMessage.trim()
|
|
205
|
+
: "";
|
|
206
|
+
}
|
|
197
207
|
const text = extractAssistantText(event.message);
|
|
198
208
|
if (text)
|
|
199
209
|
authoritativeText = text;
|
|
200
210
|
return;
|
|
201
211
|
}
|
|
202
|
-
if (event.type === "agent_settled")
|
|
203
|
-
|
|
212
|
+
if (event.type === "agent_settled") {
|
|
213
|
+
// agent_settled is emitted after retries are exhausted, so a pending
|
|
214
|
+
// assistant error here is terminal.
|
|
215
|
+
if (lastAssistantError)
|
|
216
|
+
fail(lastAssistantError);
|
|
217
|
+
else
|
|
218
|
+
finish();
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
204
221
|
});
|
|
205
222
|
child.on("error", (err) => {
|
|
206
223
|
log.error("spawn error", err);
|
|
@@ -217,6 +234,10 @@ function runPiOnce(prompt, sessionId, config, callbacks = {}) {
|
|
|
217
234
|
fail(stderr.trim() || `Pi Agent exited with code ${code}`);
|
|
218
235
|
return;
|
|
219
236
|
}
|
|
237
|
+
if (lastAssistantError) {
|
|
238
|
+
fail(lastAssistantError);
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
220
241
|
finish();
|
|
221
242
|
});
|
|
222
243
|
child.stdin.write(`${JSON.stringify({ id: "state", type: "get_state" })}\n`);
|