Misc SDK fixes (#4752)
Remove codex-level workingDirectory Throw on turn.failed in `run()` Cleanup readme
This commit is contained in:
@@ -2,5 +2,4 @@ export type CodexOptions = {
|
||||
codexPathOverride?: string;
|
||||
baseUrl?: string;
|
||||
apiKey?: string;
|
||||
workingDirectory?: string;
|
||||
};
|
||||
|
||||
@@ -30,4 +30,4 @@ export { Codex } from "./codex";
|
||||
|
||||
export type { CodexOptions } from "./codexOptions";
|
||||
|
||||
export type { ThreadOptions as TheadOptions, ApprovalMode, SandboxMode } from "./threadOptions";
|
||||
export type { ThreadOptions, ApprovalMode, SandboxMode } from "./threadOptions";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { CodexOptions } from "./codexOptions";
|
||||
import { ThreadEvent, Usage } from "./events";
|
||||
import { ThreadEvent, ThreadError, Usage } from "./events";
|
||||
import { CodexExec } from "./exec";
|
||||
import { ThreadItem } from "./items";
|
||||
import { ThreadOptions } from "./threadOptions";
|
||||
@@ -87,6 +87,7 @@ export class Thread {
|
||||
const items: ThreadItem[] = [];
|
||||
let finalResponse: string = "";
|
||||
let usage: Usage | null = null;
|
||||
let turnFailure: ThreadError | null = null;
|
||||
for await (const event of generator) {
|
||||
if (event.type === "item.completed") {
|
||||
if (event.item.type === "agent_message") {
|
||||
@@ -95,8 +96,14 @@ export class Thread {
|
||||
items.push(event.item);
|
||||
} else if (event.type === "turn.completed") {
|
||||
usage = event.usage;
|
||||
} else if (event.type === "turn.failed") {
|
||||
turnFailure = event.error;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (turnFailure) {
|
||||
throw new Error(turnFailure.message);
|
||||
}
|
||||
return { items, finalResponse, usage };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user