Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion sdk/typescript/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import eslint from "@eslint/js";
import { defineConfig } from "eslint/config";
import tseslint from "typescript-eslint";
import nodeImport from "eslint-plugin-node-import";

export default defineConfig(eslint.configs.recommended, tseslint.configs.recommended);
export default defineConfig(eslint.configs.recommended, tseslint.configs.recommended, {
plugins: {
"node-import": nodeImport,
},

rules: {
"node-import/prefer-node-protocol": 2,
},
});
5 changes: 3 additions & 2 deletions sdk/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@
"eslint": "^9.36.0",
"eslint-config-prettier": "^9.1.2",
"eslint-plugin-jest": "^29.0.1",
"eslint-plugin-node-import": "^1.0.5",
"jest": "^29.7.0",
"prettier": "^3.6.2",
"ts-jest": "^29.3.4",
"ts-jest-mock-import-meta": "^1.3.1",
"ts-node": "^10.9.2",
"tsup": "^8.5.0",
"typescript": "^5.9.2",
"typescript-eslint": "^8.45.0",
"ts-jest-mock-import-meta": "^1.3.1"
"typescript-eslint": "^8.45.0"
}
}
4 changes: 2 additions & 2 deletions sdk/typescript/samples/basic_streaming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import { Codex } from "@openai/codex-sdk";
import type { ThreadEvent, ThreadItem } from "@openai/codex-sdk";
import path from "node:path";

const executablePath =
const codexPathOverride =
process.env.CODEX_EXECUTABLE ??
path.join(process.cwd(), "..", "..", "codex-rs", "target", "debug", "codex");

const codex = new Codex({ executablePath });
const codex = new Codex({ codexPathOverride });
const thread = codex.startThread();
const rl = createInterface({ input, output });

Expand Down
10 changes: 6 additions & 4 deletions sdk/typescript/src/exec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { spawn } from "child_process";
import { spawn } from "node:child_process";

import readline from "node:readline";

Expand Down Expand Up @@ -49,7 +49,7 @@ export class CodexExec {

if (args.threadId) {
commandArgs.push("resume", args.threadId);
}
}

const env = {
...process.env,
Expand All @@ -67,7 +67,7 @@ export class CodexExec {

let spawnError: unknown | null = null;
child.once("error", (err) => (spawnError = err));

if (!child.stdin) {
child.kill();
throw new Error("Child process has no stdin");
Expand Down Expand Up @@ -104,7 +104,9 @@ export class CodexExec {
resolve(code);
} else {
const stderrBuffer = Buffer.concat(stderrChunks);
reject(new Error(`Codex Exec exited with code ${code}: ${stderrBuffer.toString('utf8')}`));
reject(
new Error(`Codex Exec exited with code ${code}: ${stderrBuffer.toString("utf8")}`),
);
}
});
});
Expand Down
8 changes: 4 additions & 4 deletions sdk/typescript/tests/codexExecSpy.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as child_process from "child_process";
import * as child_process from "node:child_process";

jest.mock("child_process", () => {
const actual = jest.requireActual<typeof import("child_process")>("child_process");
jest.mock("node:child_process", () => {
const actual = jest.requireActual<typeof import("node:child_process")>("node:child_process");
return { ...actual, spawn: jest.fn(actual.spawn) };
});

const actualChildProcess = jest.requireActual<typeof import("child_process")>("child_process");
const actualChildProcess = jest.requireActual<typeof import("node:child_process")>("node:child_process");
const spawnMock = child_process.spawn as jest.MockedFunction<typeof actualChildProcess.spawn>;

export function codexExecSpy(): { args: string[][]; restore: () => void } {
Expand Down
6 changes: 3 additions & 3 deletions sdk/typescript/tests/run.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from "fs";
import os from "os";
import path from "path";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";

import { codexExecSpy } from "./codexExecSpy";
import { describe, expect, it } from "@jest/globals";
Expand Down
2 changes: 1 addition & 1 deletion sdk/typescript/tests/runStreamed.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import path from "path";
import path from "node:path";

import { describe, expect, it } from "@jest/globals";

Expand Down
2 changes: 1 addition & 1 deletion sdk/typescript/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
"outDir": "dist",
"stripInternal": true
},
"include": ["src", "tests", "tsup.config.ts"],
"include": ["src", "tests", "tsup.config.ts", "samples"],
"exclude": ["dist", "node_modules"]
}
Loading