Skip to content

Commit 9a10e80

Browse files
Add modelReasoningEffort option to TypeScript SDK (openai#6237)
## Summary - Adds `ModelReasoningEffort` type to TypeScript SDK with values: `minimal`, `low`, `medium`, `high` - Adds `modelReasoningEffort` option to `ThreadOptions` - Forwards the option to the codex CLI via `--config model_reasoning_effort="<value>"` - Includes test coverage for the new option ## Changes - `sdk/typescript/src/threadOptions.ts`: Define `ModelReasoningEffort` type and add to `ThreadOptions` - `sdk/typescript/src/index.ts`: Export `ModelReasoningEffort` type - `sdk/typescript/src/exec.ts`: Forward `modelReasoningEffort` to CLI as config flag - `sdk/typescript/src/thread.ts`: Pass option through to exec (+ debug logging) - `sdk/typescript/tests/run.test.ts`: Add test for `modelReasoningEffort` flag forwarding --------- Co-authored-by: Eric Traut <[email protected]>
1 parent 9b538a8 commit 9a10e80

File tree

5 files changed

+48
-2
lines changed

5 files changed

+48
-2
lines changed

sdk/typescript/src/exec.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import path from "node:path";
33
import readline from "node:readline";
44
import { fileURLToPath } from "node:url";
55

6-
import { SandboxMode } from "./threadOptions";
6+
import { SandboxMode, ModelReasoningEffort } from "./threadOptions";
77

88
export type CodexExecArgs = {
99
input: string;
@@ -22,6 +22,8 @@ export type CodexExecArgs = {
2222
skipGitRepoCheck?: boolean;
2323
// --output-schema
2424
outputSchemaFile?: string;
25+
// --config model_reasoning_effort
26+
modelReasoningEffort?: ModelReasoningEffort;
2527
};
2628

2729
const INTERNAL_ORIGINATOR_ENV = "CODEX_INTERNAL_ORIGINATOR_OVERRIDE";
@@ -56,6 +58,10 @@ export class CodexExec {
5658
commandArgs.push("--output-schema", args.outputSchemaFile);
5759
}
5860

61+
if (args.modelReasoningEffort) {
62+
commandArgs.push("--config", `model_reasoning_effort="${args.modelReasoningEffort}"`);
63+
}
64+
5965
if (args.images?.length) {
6066
for (const image of args.images) {
6167
commandArgs.push("--image", image);

sdk/typescript/src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,10 @@ export { Codex } from "./codex";
3030

3131
export type { CodexOptions } from "./codexOptions";
3232

33-
export type { ThreadOptions, ApprovalMode, SandboxMode } from "./threadOptions";
33+
export type {
34+
ThreadOptions,
35+
ApprovalMode,
36+
SandboxMode,
37+
ModelReasoningEffort,
38+
} from "./threadOptions";
3439
export type { TurnOptions } from "./turnOptions";

sdk/typescript/src/thread.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export class Thread {
8585
workingDirectory: options?.workingDirectory,
8686
skipGitRepoCheck: options?.skipGitRepoCheck,
8787
outputSchemaFile: schemaPath,
88+
modelReasoningEffort: options?.modelReasoningEffort,
8889
});
8990
try {
9091
for await (const item of generator) {

sdk/typescript/src/threadOptions.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ export type ApprovalMode = "never" | "on-request" | "on-failure" | "untrusted";
22

33
export type SandboxMode = "read-only" | "workspace-write" | "danger-full-access";
44

5+
export type ModelReasoningEffort = "minimal" | "low" | "medium" | "high";
6+
57
export type ThreadOptions = {
68
model?: string;
79
sandboxMode?: SandboxMode;
810
workingDirectory?: string;
911
skipGitRepoCheck?: boolean;
12+
modelReasoningEffort?: ModelReasoningEffort;
1013
};

sdk/typescript/tests/run.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,37 @@ describe("Codex", () => {
223223
}
224224
});
225225

226+
it("passes modelReasoningEffort to exec", async () => {
227+
const { url, close } = await startResponsesTestProxy({
228+
statusCode: 200,
229+
responseBodies: [
230+
sse(
231+
responseStarted("response_1"),
232+
assistantMessage("Reasoning effort applied", "item_1"),
233+
responseCompleted("response_1"),
234+
),
235+
],
236+
});
237+
238+
const { args: spawnArgs, restore } = codexExecSpy();
239+
240+
try {
241+
const client = new Codex({ codexPathOverride: codexExecPath, baseUrl: url, apiKey: "test" });
242+
243+
const thread = client.startThread({
244+
modelReasoningEffort: "high",
245+
});
246+
await thread.run("apply reasoning effort");
247+
248+
const commandArgs = spawnArgs[0];
249+
expect(commandArgs).toBeDefined();
250+
expectPair(commandArgs, ["--config", 'model_reasoning_effort="high"']);
251+
} finally {
252+
restore();
253+
await close();
254+
}
255+
});
256+
226257
it("writes output schema to a temporary file and forwards it", async () => {
227258
const { url, close, requests } = await startResponsesTestProxy({
228259
statusCode: 200,

0 commit comments

Comments
 (0)