@fulldivevr/workcord-cli 3.0.1 → 3.0.2
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.
|
@@ -63,6 +63,7 @@ export async function runCodex(input) {
|
|
|
63
63
|
let turnId = "";
|
|
64
64
|
let finalText = "";
|
|
65
65
|
let lastText = "";
|
|
66
|
+
const earlyTurns = new Map();
|
|
66
67
|
let settle;
|
|
67
68
|
const done = new Promise((resolve, reject) => { settle = { resolve, reject }; });
|
|
68
69
|
done.catch(() => undefined);
|
|
@@ -109,16 +110,23 @@ export async function runCodex(input) {
|
|
|
109
110
|
lastText = text;
|
|
110
111
|
}
|
|
111
112
|
}
|
|
112
|
-
else if (message.method === "turn/completed" && params.turn?.id
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
settle.reject(new Error(String(turn.error?.message || `Codex ended the turn as ${turn.status}`)));
|
|
113
|
+
else if (message.method === "turn/completed" && params.turn?.id) {
|
|
114
|
+
// Readline emits every line of one stdout chunk synchronously, so a turn that ends
|
|
115
|
+
// in the chunk carrying the turn/start answer completes before turnId is set.
|
|
116
|
+
if (!turnId)
|
|
117
|
+
earlyTurns.set(String(params.turn.id), params.turn);
|
|
118
|
+
else if (params.turn.id === turnId)
|
|
119
|
+
finishTurn(params.turn);
|
|
120
120
|
}
|
|
121
121
|
});
|
|
122
|
+
const finishTurn = (turn) => {
|
|
123
|
+
if (turn.status === "completed")
|
|
124
|
+
settle.resolve(finalText || lastText);
|
|
125
|
+
else if (turn.status === "interrupted")
|
|
126
|
+
settle.reject(new Error("The task was stopped."));
|
|
127
|
+
else
|
|
128
|
+
settle.reject(new Error(String(turn.error?.message || `Codex ended the turn as ${turn.status}`)));
|
|
129
|
+
};
|
|
122
130
|
child.on("error", (error) => {
|
|
123
131
|
settle.reject(new Error(error.code === "ENOENT" ? "Codex is not installed on this machine (no `codex` on PATH)." : error.message));
|
|
124
132
|
});
|
|
@@ -152,6 +160,8 @@ export async function runCodex(input) {
|
|
|
152
160
|
input.onThread?.(threadId);
|
|
153
161
|
const started = await request("turn/start", { threadId, input: [{ type: "text", text: input.prompt, text_elements: [] }] });
|
|
154
162
|
turnId = String(started?.turn?.id || "");
|
|
163
|
+
if (earlyTurns.has(turnId))
|
|
164
|
+
finishTurn(earlyTurns.get(turnId));
|
|
155
165
|
if (signal.aborted)
|
|
156
166
|
onAbort();
|
|
157
167
|
return await done;
|