@northflare/runner 0.0.16 → 0.0.17
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/lib/codex-sdk/dist/src/codex.d.ts +27 -0
- package/lib/codex-sdk/dist/src/codex.d.ts.map +1 -0
- package/lib/codex-sdk/dist/src/codex.js +33 -0
- package/lib/codex-sdk/dist/src/codex.js.map +1 -0
- package/lib/codex-sdk/dist/src/codexOptions.d.ts +11 -0
- package/lib/codex-sdk/dist/src/codexOptions.d.ts.map +1 -0
- package/lib/codex-sdk/dist/src/codexOptions.js +2 -0
- package/lib/codex-sdk/dist/src/codexOptions.js.map +1 -0
- package/lib/codex-sdk/dist/src/events.d.ts +60 -0
- package/lib/codex-sdk/dist/src/events.d.ts.map +1 -0
- package/lib/codex-sdk/dist/src/events.js +3 -0
- package/lib/codex-sdk/dist/src/events.js.map +1 -0
- package/lib/codex-sdk/dist/src/exec.d.ts +27 -0
- package/lib/codex-sdk/dist/src/exec.d.ts.map +1 -0
- package/lib/codex-sdk/dist/src/exec.js +264 -0
- package/lib/codex-sdk/dist/src/exec.js.map +1 -0
- package/lib/codex-sdk/dist/src/index.d.ts +9 -0
- package/lib/codex-sdk/dist/src/index.d.ts.map +1 -0
- package/lib/codex-sdk/dist/src/index.js +3 -0
- package/lib/codex-sdk/dist/src/index.js.map +1 -0
- package/lib/codex-sdk/dist/src/items.d.ts +103 -0
- package/lib/codex-sdk/dist/src/items.d.ts.map +1 -0
- package/lib/codex-sdk/dist/src/items.js +3 -0
- package/lib/codex-sdk/dist/src/items.js.map +1 -0
- package/lib/codex-sdk/dist/src/outputSchemaFile.d.ts +6 -0
- package/lib/codex-sdk/dist/src/outputSchemaFile.d.ts.map +1 -0
- package/lib/codex-sdk/dist/src/outputSchemaFile.js +33 -0
- package/lib/codex-sdk/dist/src/outputSchemaFile.js.map +1 -0
- package/lib/codex-sdk/dist/src/thread.d.ts +41 -0
- package/lib/codex-sdk/dist/src/thread.d.ts.map +1 -0
- package/lib/codex-sdk/dist/src/thread.js +109 -0
- package/lib/codex-sdk/dist/src/thread.js.map +1 -0
- package/lib/codex-sdk/dist/src/threadOptions.d.ts +16 -0
- package/lib/codex-sdk/dist/src/threadOptions.d.ts.map +1 -0
- package/lib/codex-sdk/dist/src/threadOptions.js +2 -0
- package/lib/codex-sdk/dist/src/threadOptions.js.map +1 -0
- package/lib/codex-sdk/dist/src/turnOptions.d.ts +7 -0
- package/lib/codex-sdk/dist/src/turnOptions.d.ts.map +1 -0
- package/lib/codex-sdk/dist/src/turnOptions.js +2 -0
- package/lib/codex-sdk/dist/src/turnOptions.js.map +1 -0
- package/lib/codex-sdk/dist/tests/abort.test.d.ts +2 -0
- package/lib/codex-sdk/dist/tests/abort.test.d.ts.map +1 -0
- package/lib/codex-sdk/dist/tests/abort.test.js +130 -0
- package/lib/codex-sdk/dist/tests/abort.test.js.map +1 -0
- package/lib/codex-sdk/dist/tests/codexExecSpy.d.ts +6 -0
- package/lib/codex-sdk/dist/tests/codexExecSpy.d.ts.map +1 -0
- package/lib/codex-sdk/dist/tests/codexExecSpy.js +28 -0
- package/lib/codex-sdk/dist/tests/codexExecSpy.js.map +1 -0
- package/lib/codex-sdk/dist/tests/responsesProxy.d.ts +56 -0
- package/lib/codex-sdk/dist/tests/responsesProxy.d.ts.map +1 -0
- package/lib/codex-sdk/dist/tests/responsesProxy.js +155 -0
- package/lib/codex-sdk/dist/tests/responsesProxy.js.map +1 -0
- package/lib/codex-sdk/dist/tests/run.test.d.ts +2 -0
- package/lib/codex-sdk/dist/tests/run.test.d.ts.map +1 -0
- package/lib/codex-sdk/dist/tests/run.test.js +524 -0
- package/lib/codex-sdk/dist/tests/run.test.js.map +1 -0
- package/lib/codex-sdk/dist/tests/runStreamed.test.d.ts +2 -0
- package/lib/codex-sdk/dist/tests/runStreamed.test.d.ts.map +1 -0
- package/lib/codex-sdk/dist/tests/runStreamed.test.js +153 -0
- package/lib/codex-sdk/dist/tests/runStreamed.test.js.map +1 -0
- package/lib/codex-sdk/samples/basic_streaming.ts +0 -0
- package/lib/codex-sdk/samples/structured_output.ts +0 -0
- package/lib/codex-sdk/samples/structured_output_zod.ts +0 -0
- package/lib/codex-sdk/src/codex.ts +38 -0
- package/lib/codex-sdk/src/codexOptions.ts +10 -0
- package/lib/codex-sdk/src/events.ts +80 -0
- package/lib/codex-sdk/src/exec.ts +336 -0
- package/lib/codex-sdk/src/index.ts +39 -0
- package/lib/codex-sdk/src/items.ts +127 -0
- package/lib/codex-sdk/src/outputSchemaFile.ts +40 -0
- package/lib/codex-sdk/src/thread.ts +155 -0
- package/lib/codex-sdk/src/threadOptions.ts +18 -0
- package/lib/codex-sdk/src/turnOptions.ts +6 -0
- package/lib/codex-sdk/tests/abort.test.ts +165 -0
- package/lib/codex-sdk/tests/codexExecSpy.ts +37 -0
- package/lib/codex-sdk/tests/responsesProxy.ts +225 -0
- package/lib/codex-sdk/tests/run.test.ts +687 -0
- package/lib/codex-sdk/tests/runStreamed.test.ts +211 -0
- package/package.json +15 -16
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { CodexOptions } from "./codexOptions";
|
|
2
|
+
import { Thread } from "./thread";
|
|
3
|
+
import { ThreadOptions } from "./threadOptions";
|
|
4
|
+
/**
|
|
5
|
+
* Codex is the main class for interacting with the Codex agent.
|
|
6
|
+
*
|
|
7
|
+
* Use the `startThread()` method to start a new thread or `resumeThread()` to resume a previously started thread.
|
|
8
|
+
*/
|
|
9
|
+
export declare class Codex {
|
|
10
|
+
private exec;
|
|
11
|
+
private options;
|
|
12
|
+
constructor(options?: CodexOptions);
|
|
13
|
+
/**
|
|
14
|
+
* Starts a new conversation with an agent.
|
|
15
|
+
* @returns A new thread instance.
|
|
16
|
+
*/
|
|
17
|
+
startThread(options?: ThreadOptions): Thread;
|
|
18
|
+
/**
|
|
19
|
+
* Resumes a conversation with an agent based on the thread id.
|
|
20
|
+
* Threads are persisted in ~/.codex/sessions.
|
|
21
|
+
*
|
|
22
|
+
* @param id The id of the thread to resume.
|
|
23
|
+
* @returns A new thread instance.
|
|
24
|
+
*/
|
|
25
|
+
resumeThread(id: string, options?: ThreadOptions): Thread;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=codex.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codex.d.ts","sourceRoot":"","sources":["../../src/codex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;;GAIG;AACH,qBAAa,KAAK;IAChB,OAAO,CAAC,IAAI,CAAY;IACxB,OAAO,CAAC,OAAO,CAAe;gBAElB,OAAO,GAAE,YAAiB;IAKtC;;;OAGG;IACH,WAAW,CAAC,OAAO,GAAE,aAAkB,GAAG,MAAM;IAIhD;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,MAAM;CAG9D"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { CodexExec } from "./exec";
|
|
2
|
+
import { Thread } from "./thread";
|
|
3
|
+
/**
|
|
4
|
+
* Codex is the main class for interacting with the Codex agent.
|
|
5
|
+
*
|
|
6
|
+
* Use the `startThread()` method to start a new thread or `resumeThread()` to resume a previously started thread.
|
|
7
|
+
*/
|
|
8
|
+
export class Codex {
|
|
9
|
+
exec;
|
|
10
|
+
options;
|
|
11
|
+
constructor(options = {}) {
|
|
12
|
+
this.exec = new CodexExec(options.codexPathOverride, options.env);
|
|
13
|
+
this.options = options;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Starts a new conversation with an agent.
|
|
17
|
+
* @returns A new thread instance.
|
|
18
|
+
*/
|
|
19
|
+
startThread(options = {}) {
|
|
20
|
+
return new Thread(this.exec, this.options, options);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Resumes a conversation with an agent based on the thread id.
|
|
24
|
+
* Threads are persisted in ~/.codex/sessions.
|
|
25
|
+
*
|
|
26
|
+
* @param id The id of the thread to resume.
|
|
27
|
+
* @returns A new thread instance.
|
|
28
|
+
*/
|
|
29
|
+
resumeThread(id, options = {}) {
|
|
30
|
+
return new Thread(this.exec, this.options, options, id);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=codex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codex.js","sourceRoot":"","sources":["../../src/codex.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAGlC;;;;GAIG;AACH,MAAM,OAAO,KAAK;IACR,IAAI,CAAY;IAChB,OAAO,CAAe;IAE9B,YAAY,UAAwB,EAAE;QACpC,IAAI,CAAC,IAAI,GAAG,IAAI,SAAS,CAAC,OAAO,CAAC,iBAAiB,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;QAClE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED;;;OAGG;IACH,WAAW,CAAC,UAAyB,EAAE;QACrC,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACtD,CAAC;IAED;;;;;;OAMG;IACH,YAAY,CAAC,EAAU,EAAE,UAAyB,EAAE;QAClD,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC;IAC1D,CAAC;CACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type CodexOptions = {
|
|
2
|
+
codexPathOverride?: string;
|
|
3
|
+
baseUrl?: string;
|
|
4
|
+
apiKey?: string;
|
|
5
|
+
/**
|
|
6
|
+
* Environment variables passed to the Codex CLI process. When provided, the SDK
|
|
7
|
+
* will not inherit variables from `process.env`.
|
|
8
|
+
*/
|
|
9
|
+
env?: Record<string, string>;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=codexOptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codexOptions.d.ts","sourceRoot":"","sources":["../../src/codexOptions.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG;IACzB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codexOptions.js","sourceRoot":"","sources":["../../src/codexOptions.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { ThreadItem } from "./items";
|
|
2
|
+
/** Emitted when a new thread is started as the first event. */
|
|
3
|
+
export type ThreadStartedEvent = {
|
|
4
|
+
type: "thread.started";
|
|
5
|
+
/** The identifier of the new thread. Can be used to resume the thread later. */
|
|
6
|
+
thread_id: string;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Emitted when a turn is started by sending a new prompt to the model.
|
|
10
|
+
* A turn encompasses all events that happen while the agent is processing the prompt.
|
|
11
|
+
*/
|
|
12
|
+
export type TurnStartedEvent = {
|
|
13
|
+
type: "turn.started";
|
|
14
|
+
};
|
|
15
|
+
/** Describes the usage of tokens during a turn. */
|
|
16
|
+
export type Usage = {
|
|
17
|
+
/** The number of input tokens used during the turn. */
|
|
18
|
+
input_tokens: number;
|
|
19
|
+
/** The number of cached input tokens used during the turn. */
|
|
20
|
+
cached_input_tokens: number;
|
|
21
|
+
/** The number of output tokens used during the turn. */
|
|
22
|
+
output_tokens: number;
|
|
23
|
+
};
|
|
24
|
+
/** Emitted when a turn is completed. Typically right after the assistant's response. */
|
|
25
|
+
export type TurnCompletedEvent = {
|
|
26
|
+
type: "turn.completed";
|
|
27
|
+
usage: Usage;
|
|
28
|
+
};
|
|
29
|
+
/** Indicates that a turn failed with an error. */
|
|
30
|
+
export type TurnFailedEvent = {
|
|
31
|
+
type: "turn.failed";
|
|
32
|
+
error: ThreadError;
|
|
33
|
+
};
|
|
34
|
+
/** Emitted when a new item is added to the thread. Typically the item is initially "in progress". */
|
|
35
|
+
export type ItemStartedEvent = {
|
|
36
|
+
type: "item.started";
|
|
37
|
+
item: ThreadItem;
|
|
38
|
+
};
|
|
39
|
+
/** Emitted when an item is updated. */
|
|
40
|
+
export type ItemUpdatedEvent = {
|
|
41
|
+
type: "item.updated";
|
|
42
|
+
item: ThreadItem;
|
|
43
|
+
};
|
|
44
|
+
/** Signals that an item has reached a terminal state—either success or failure. */
|
|
45
|
+
export type ItemCompletedEvent = {
|
|
46
|
+
type: "item.completed";
|
|
47
|
+
item: ThreadItem;
|
|
48
|
+
};
|
|
49
|
+
/** Fatal error emitted by the stream. */
|
|
50
|
+
export type ThreadError = {
|
|
51
|
+
message: string;
|
|
52
|
+
};
|
|
53
|
+
/** Represents an unrecoverable error emitted directly by the event stream. */
|
|
54
|
+
export type ThreadErrorEvent = {
|
|
55
|
+
type: "error";
|
|
56
|
+
message: string;
|
|
57
|
+
};
|
|
58
|
+
/** Top-level JSONL events emitted by codex exec. */
|
|
59
|
+
export type ThreadEvent = ThreadStartedEvent | TurnStartedEvent | TurnCompletedEvent | TurnFailedEvent | ItemStartedEvent | ItemUpdatedEvent | ItemCompletedEvent | ThreadErrorEvent;
|
|
60
|
+
//# sourceMappingURL=events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/events.ts"],"names":[],"mappings":"AAEA,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O,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,oDAAoD;AACpD,MAAM,MAAM,WAAW,GACnB,kBAAkB,GAClB,gBAAgB,GAChB,kBAAkB,GAClB,eAAe,GACf,gBAAgB,GAChB,gBAAgB,GAChB,kBAAkB,GAClB,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/events.ts"],"names":[],"mappings":"AAAA,6DAA6D"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { SandboxMode, ModelReasoningEffort, ApprovalMode } from "./threadOptions";
|
|
2
|
+
export type CodexExecArgs = {
|
|
3
|
+
input: string;
|
|
4
|
+
baseUrl?: string;
|
|
5
|
+
apiKey?: string;
|
|
6
|
+
threadId?: string | null;
|
|
7
|
+
images?: string[];
|
|
8
|
+
model?: string;
|
|
9
|
+
sandboxMode?: SandboxMode;
|
|
10
|
+
workingDirectory?: string;
|
|
11
|
+
additionalDirectories?: string[];
|
|
12
|
+
skipGitRepoCheck?: boolean;
|
|
13
|
+
outputSchemaFile?: string;
|
|
14
|
+
modelReasoningEffort?: ModelReasoningEffort;
|
|
15
|
+
signal?: AbortSignal;
|
|
16
|
+
networkAccessEnabled?: boolean;
|
|
17
|
+
webSearchEnabled?: boolean;
|
|
18
|
+
approvalPolicy?: ApprovalMode;
|
|
19
|
+
configOverrides?: Record<string, unknown>;
|
|
20
|
+
};
|
|
21
|
+
export declare class CodexExec {
|
|
22
|
+
private executablePath;
|
|
23
|
+
private envOverride?;
|
|
24
|
+
constructor(executablePath?: string | null, env?: Record<string, string>);
|
|
25
|
+
run(args: CodexExecArgs): AsyncGenerator<string>;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=exec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exec.d.ts","sourceRoot":"","sources":["../../src/exec.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAElF,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,EAAE,MAAM,CAAC;IAEd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAElB,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,WAAW,CAAC,EAAE,WAAW,CAAC;IAE1B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAC;IAEjC,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAE3B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;IAE5C,MAAM,CAAC,EAAE,WAAW,CAAC;IAErB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAE/B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAE3B,cAAc,CAAC,EAAE,YAAY,CAAC;IAE9B,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC3C,CAAC;AAMF,qBAAa,SAAS;IACpB,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,WAAW,CAAC,CAAyB;gBAEjC,cAAc,GAAE,MAAM,GAAG,IAAW,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAKvE,GAAG,CAAC,IAAI,EAAE,aAAa,GAAG,cAAc,CAAC,MAAM,CAAC;CAyJxD"}
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import readline from "node:readline";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { createRequire } from "node:module";
|
|
7
|
+
const INTERNAL_ORIGINATOR_ENV = "CODEX_INTERNAL_ORIGINATOR_OVERRIDE";
|
|
8
|
+
const TYPESCRIPT_SDK_ORIGINATOR = "codex_sdk_ts";
|
|
9
|
+
const isDebugEnabled = process.env["DEBUG"] === "true";
|
|
10
|
+
export class CodexExec {
|
|
11
|
+
executablePath;
|
|
12
|
+
envOverride;
|
|
13
|
+
constructor(executablePath = null, env) {
|
|
14
|
+
this.executablePath = executablePath || findCodexPath();
|
|
15
|
+
this.envOverride = env;
|
|
16
|
+
}
|
|
17
|
+
async *run(args) {
|
|
18
|
+
const commandArgs = ["exec", "--experimental-json"];
|
|
19
|
+
if (args.model) {
|
|
20
|
+
commandArgs.push("--model", args.model);
|
|
21
|
+
}
|
|
22
|
+
if (args.sandboxMode) {
|
|
23
|
+
commandArgs.push("--sandbox", args.sandboxMode);
|
|
24
|
+
}
|
|
25
|
+
if (args.workingDirectory) {
|
|
26
|
+
commandArgs.push("--cd", args.workingDirectory);
|
|
27
|
+
}
|
|
28
|
+
if (args.additionalDirectories?.length) {
|
|
29
|
+
for (const dir of args.additionalDirectories) {
|
|
30
|
+
commandArgs.push("--add-dir", dir);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (args.skipGitRepoCheck) {
|
|
34
|
+
commandArgs.push("--skip-git-repo-check");
|
|
35
|
+
}
|
|
36
|
+
if (args.outputSchemaFile) {
|
|
37
|
+
commandArgs.push("--output-schema", args.outputSchemaFile);
|
|
38
|
+
}
|
|
39
|
+
if (args.modelReasoningEffort) {
|
|
40
|
+
commandArgs.push("--config", `model_reasoning_effort="${args.modelReasoningEffort}"`);
|
|
41
|
+
}
|
|
42
|
+
if (args.networkAccessEnabled !== undefined) {
|
|
43
|
+
commandArgs.push("--config", `sandbox_workspace_write.network_access=${args.networkAccessEnabled}`);
|
|
44
|
+
}
|
|
45
|
+
if (args.webSearchEnabled !== undefined) {
|
|
46
|
+
commandArgs.push("--config", `features.web_search_request=${args.webSearchEnabled}`);
|
|
47
|
+
}
|
|
48
|
+
if (args.approvalPolicy) {
|
|
49
|
+
commandArgs.push("--config", `approval_policy="${args.approvalPolicy}"`);
|
|
50
|
+
}
|
|
51
|
+
if (args.configOverrides) {
|
|
52
|
+
for (const [key, value] of Object.entries(args.configOverrides)) {
|
|
53
|
+
const formatted = formatConfigValue(value);
|
|
54
|
+
commandArgs.push("--config", `${key}=${formatted}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (args.images?.length) {
|
|
58
|
+
for (const image of args.images) {
|
|
59
|
+
commandArgs.push("--image", image);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (args.threadId) {
|
|
63
|
+
commandArgs.push("resume", args.threadId);
|
|
64
|
+
}
|
|
65
|
+
if (isDebugEnabled) {
|
|
66
|
+
console.log("[CodexExec] Executable path:", this.executablePath);
|
|
67
|
+
console.log("[CodexExec] Command arguments:", commandArgs);
|
|
68
|
+
}
|
|
69
|
+
const env = {};
|
|
70
|
+
if (this.envOverride) {
|
|
71
|
+
Object.assign(env, this.envOverride);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
for (const [key, value] of Object.entries(process.env)) {
|
|
75
|
+
if (value !== undefined) {
|
|
76
|
+
env[key] = value;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (!env[INTERNAL_ORIGINATOR_ENV]) {
|
|
81
|
+
env[INTERNAL_ORIGINATOR_ENV] = TYPESCRIPT_SDK_ORIGINATOR;
|
|
82
|
+
}
|
|
83
|
+
if (args.baseUrl) {
|
|
84
|
+
env.OPENAI_BASE_URL = args.baseUrl;
|
|
85
|
+
}
|
|
86
|
+
if (args.apiKey) {
|
|
87
|
+
env.CODEX_API_KEY = args.apiKey;
|
|
88
|
+
}
|
|
89
|
+
const child = spawn(this.executablePath, commandArgs, {
|
|
90
|
+
env,
|
|
91
|
+
signal: args.signal,
|
|
92
|
+
});
|
|
93
|
+
let spawnError = null;
|
|
94
|
+
child.once("error", (err) => (spawnError = err));
|
|
95
|
+
if (!child.stdin) {
|
|
96
|
+
child.kill();
|
|
97
|
+
throw new Error("Child process has no stdin");
|
|
98
|
+
}
|
|
99
|
+
child.stdin.write(args.input);
|
|
100
|
+
child.stdin.end();
|
|
101
|
+
if (!child.stdout) {
|
|
102
|
+
child.kill();
|
|
103
|
+
throw new Error("Child process has no stdout");
|
|
104
|
+
}
|
|
105
|
+
const stderrChunks = [];
|
|
106
|
+
if (child.stderr) {
|
|
107
|
+
child.stderr.on("data", (data) => {
|
|
108
|
+
stderrChunks.push(data);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
const rl = readline.createInterface({
|
|
112
|
+
input: child.stdout,
|
|
113
|
+
crlfDelay: Infinity,
|
|
114
|
+
});
|
|
115
|
+
try {
|
|
116
|
+
for await (const line of rl) {
|
|
117
|
+
// `line` is a string (Node sets default encoding to utf8 for readline)
|
|
118
|
+
yield line;
|
|
119
|
+
}
|
|
120
|
+
const exitCode = new Promise((resolve, reject) => {
|
|
121
|
+
child.once("exit", (code) => {
|
|
122
|
+
if (code === 0) {
|
|
123
|
+
resolve(code);
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
const stderrBuffer = Buffer.concat(stderrChunks);
|
|
127
|
+
reject(new Error(`Codex Exec exited with code ${code}: ${stderrBuffer.toString("utf8")}`));
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
if (spawnError)
|
|
132
|
+
throw spawnError;
|
|
133
|
+
await exitCode;
|
|
134
|
+
}
|
|
135
|
+
finally {
|
|
136
|
+
rl.close();
|
|
137
|
+
child.removeAllListeners();
|
|
138
|
+
try {
|
|
139
|
+
if (!child.killed)
|
|
140
|
+
child.kill();
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
// ignore
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const scriptFileName = fileURLToPath(import.meta.url);
|
|
149
|
+
const scriptDirName = path.dirname(scriptFileName);
|
|
150
|
+
const require = createRequire(import.meta.url);
|
|
151
|
+
function findCodexPath() {
|
|
152
|
+
const { platform, arch } = process;
|
|
153
|
+
let targetTriple = null;
|
|
154
|
+
switch (platform) {
|
|
155
|
+
case "linux":
|
|
156
|
+
case "android":
|
|
157
|
+
switch (arch) {
|
|
158
|
+
case "x64":
|
|
159
|
+
targetTriple = "x86_64-unknown-linux-musl";
|
|
160
|
+
break;
|
|
161
|
+
case "arm64":
|
|
162
|
+
targetTriple = "aarch64-unknown-linux-musl";
|
|
163
|
+
break;
|
|
164
|
+
default:
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
break;
|
|
168
|
+
case "darwin":
|
|
169
|
+
switch (arch) {
|
|
170
|
+
case "x64":
|
|
171
|
+
targetTriple = "x86_64-apple-darwin";
|
|
172
|
+
break;
|
|
173
|
+
case "arm64":
|
|
174
|
+
targetTriple = "aarch64-apple-darwin";
|
|
175
|
+
break;
|
|
176
|
+
default:
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
break;
|
|
180
|
+
case "win32":
|
|
181
|
+
switch (arch) {
|
|
182
|
+
case "x64":
|
|
183
|
+
targetTriple = "x86_64-pc-windows-msvc";
|
|
184
|
+
break;
|
|
185
|
+
case "arm64":
|
|
186
|
+
targetTriple = "aarch64-pc-windows-msvc";
|
|
187
|
+
break;
|
|
188
|
+
default:
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
break;
|
|
192
|
+
default:
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
if (!targetTriple) {
|
|
196
|
+
throw new Error(`Unsupported platform: ${platform} (${arch})`);
|
|
197
|
+
}
|
|
198
|
+
const vendorResolution = resolveUpstreamVendorRoot();
|
|
199
|
+
let vendorRoot;
|
|
200
|
+
if (vendorResolution.path) {
|
|
201
|
+
vendorRoot = vendorResolution.path;
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
vendorRoot = path.join(scriptDirName, "..", "vendor");
|
|
205
|
+
const reason = vendorResolution.reason ? `: ${vendorResolution.reason}` : "";
|
|
206
|
+
console.warn(`[Codex SDK] Failed to resolve upstream vendor package${reason}, falling back to local vendor directory`);
|
|
207
|
+
}
|
|
208
|
+
const archRoot = path.join(vendorRoot, targetTriple);
|
|
209
|
+
const codexBinaryName = process.platform === "win32" ? "codex.exe" : "codex";
|
|
210
|
+
const binaryPath = path.join(archRoot, "codex", codexBinaryName);
|
|
211
|
+
return binaryPath;
|
|
212
|
+
}
|
|
213
|
+
function resolveUpstreamVendorRoot() {
|
|
214
|
+
let searchPaths = null;
|
|
215
|
+
try {
|
|
216
|
+
searchPaths = require.resolve.paths("@openai/codex-sdk");
|
|
217
|
+
}
|
|
218
|
+
catch (error) {
|
|
219
|
+
return { path: null, reason: error?.message || String(error) };
|
|
220
|
+
}
|
|
221
|
+
if (!searchPaths?.length) {
|
|
222
|
+
return { path: null, reason: "no module search paths returned" };
|
|
223
|
+
}
|
|
224
|
+
let locatedPackageRoot = null;
|
|
225
|
+
for (const basePath of searchPaths) {
|
|
226
|
+
if (!basePath)
|
|
227
|
+
continue;
|
|
228
|
+
const packageRoot = path.join(basePath, "@openai/codex-sdk");
|
|
229
|
+
const packageJsonPath = path.join(packageRoot, "package.json");
|
|
230
|
+
if (!existsSync(packageJsonPath)) {
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
locatedPackageRoot = packageRoot;
|
|
234
|
+
const vendorPath = path.join(packageRoot, "vendor");
|
|
235
|
+
if (existsSync(vendorPath)) {
|
|
236
|
+
return { path: vendorPath };
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
if (locatedPackageRoot) {
|
|
240
|
+
return { path: null, reason: `vendor directory missing in ${locatedPackageRoot}` };
|
|
241
|
+
}
|
|
242
|
+
return {
|
|
243
|
+
path: null,
|
|
244
|
+
reason: `@openai/codex-sdk not found in node_modules search paths (${searchPaths.join(", ")})`,
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
function formatConfigValue(value) {
|
|
248
|
+
if (typeof value === "string") {
|
|
249
|
+
return JSON.stringify(value);
|
|
250
|
+
}
|
|
251
|
+
if (typeof value === "number" || typeof value === "boolean") {
|
|
252
|
+
return String(value);
|
|
253
|
+
}
|
|
254
|
+
if (value === null || value === undefined) {
|
|
255
|
+
return "null";
|
|
256
|
+
}
|
|
257
|
+
try {
|
|
258
|
+
return JSON.stringify(value);
|
|
259
|
+
}
|
|
260
|
+
catch {
|
|
261
|
+
return JSON.stringify(String(value));
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
//# sourceMappingURL=exec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exec.js","sourceRoot":"","sources":["../../src/exec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,QAAQ,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAqC5C,MAAM,uBAAuB,GAAG,oCAAoC,CAAC;AACrE,MAAM,yBAAyB,GAAG,cAAc,CAAC;AACjD,MAAM,cAAc,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,MAAM,CAAC;AAEvD,MAAM,OAAO,SAAS;IACZ,cAAc,CAAS;IACvB,WAAW,CAA0B;IAE7C,YAAY,iBAAgC,IAAI,EAAE,GAA4B;QAC5E,IAAI,CAAC,cAAc,GAAG,cAAc,IAAI,aAAa,EAAE,CAAC;QACxD,IAAI,CAAC,WAAW,GAAG,GAAG,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,CAAC,GA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,SAAS,EAAE,CAAC;QAC5D,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;IACD,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QAC1C,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IACvC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type { ThreadEvent, ThreadStartedEvent, TurnStartedEvent, TurnCompletedEvent, TurnFailedEvent, ItemStartedEvent, ItemUpdatedEvent, ItemCompletedEvent, ThreadError, ThreadErrorEvent, Usage, } from "./events";
|
|
2
|
+
export type { ThreadItem, AgentMessageItem, ReasoningItem, CommandExecutionItem, FileChangeItem, McpToolCallItem, WebSearchItem, TodoListItem, ErrorItem, } from "./items";
|
|
3
|
+
export { Thread } from "./thread";
|
|
4
|
+
export type { RunResult, RunStreamedResult, Input, UserInput } from "./thread";
|
|
5
|
+
export { Codex } from "./codex";
|
|
6
|
+
export type { CodexOptions } from "./codexOptions";
|
|
7
|
+
export type { ThreadOptions, ApprovalMode, SandboxMode, ModelReasoningEffort, } from "./threadOptions";
|
|
8
|
+
export type { TurnOptions } from "./turnOptions";
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,WAAW,EACX,kBAAkB,EAClB,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,WAAW,EACX,gBAAgB,EAChB,KAAK,GACN,MAAM,UAAU,CAAC;AAClB,YAAY,EACV,UAAU,EACV,gBAAgB,EAChB,aAAa,EACb,oBAAoB,EACpB,cAAc,EACd,eAAe,EACf,aAAa,EACb,YAAY,EACZ,SAAS,GACV,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,YAAY,EAAE,SAAS,EAAE,iBAAiB,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE/E,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,YAAY,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEnD,YAAY,EACV,aAAa,EACb,YAAY,EACZ,WAAW,EACX,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAGlC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { ContentBlock as McpContentBlock } from "@modelcontextprotocol/sdk/types.js";
|
|
2
|
+
/** The status of a command execution. */
|
|
3
|
+
export type CommandExecutionStatus = "in_progress" | "completed" | "failed";
|
|
4
|
+
/** A command executed by the agent. */
|
|
5
|
+
export type CommandExecutionItem = {
|
|
6
|
+
id: string;
|
|
7
|
+
type: "command_execution";
|
|
8
|
+
/** The command line executed by the agent. */
|
|
9
|
+
command: string;
|
|
10
|
+
/** Aggregated stdout and stderr captured while the command was running. */
|
|
11
|
+
aggregated_output: string;
|
|
12
|
+
/** Set when the command exits; omitted while still running. */
|
|
13
|
+
exit_code?: number;
|
|
14
|
+
/** Current status of the command execution. */
|
|
15
|
+
status: CommandExecutionStatus;
|
|
16
|
+
};
|
|
17
|
+
/** Indicates the type of the file change. */
|
|
18
|
+
export type PatchChangeKind = "add" | "delete" | "update";
|
|
19
|
+
/** A set of file changes by the agent. */
|
|
20
|
+
export type FileUpdateChange = {
|
|
21
|
+
path: string;
|
|
22
|
+
kind: PatchChangeKind;
|
|
23
|
+
};
|
|
24
|
+
/** The status of a file change. */
|
|
25
|
+
export type PatchApplyStatus = "completed" | "failed";
|
|
26
|
+
/** A set of file changes by the agent. Emitted once the patch succeeds or fails. */
|
|
27
|
+
export type FileChangeItem = {
|
|
28
|
+
id: string;
|
|
29
|
+
type: "file_change";
|
|
30
|
+
/** Individual file changes that comprise the patch. */
|
|
31
|
+
changes: FileUpdateChange[];
|
|
32
|
+
/** Whether the patch ultimately succeeded or failed. */
|
|
33
|
+
status: PatchApplyStatus;
|
|
34
|
+
};
|
|
35
|
+
/** The status of an MCP tool call. */
|
|
36
|
+
export type McpToolCallStatus = "in_progress" | "completed" | "failed";
|
|
37
|
+
/**
|
|
38
|
+
* Represents a call to an MCP tool. The item starts when the invocation is dispatched
|
|
39
|
+
* and completes when the MCP server reports success or failure.
|
|
40
|
+
*/
|
|
41
|
+
export type McpToolCallItem = {
|
|
42
|
+
id: string;
|
|
43
|
+
type: "mcp_tool_call";
|
|
44
|
+
/** Name of the MCP server handling the request. */
|
|
45
|
+
server: string;
|
|
46
|
+
/** The tool invoked on the MCP server. */
|
|
47
|
+
tool: string;
|
|
48
|
+
/** Arguments forwarded to the tool invocation. */
|
|
49
|
+
arguments: unknown;
|
|
50
|
+
/** Result payload returned by the MCP server for successful calls. */
|
|
51
|
+
result?: {
|
|
52
|
+
content: McpContentBlock[];
|
|
53
|
+
structured_content: unknown;
|
|
54
|
+
};
|
|
55
|
+
/** Error message reported for failed calls. */
|
|
56
|
+
error?: {
|
|
57
|
+
message: string;
|
|
58
|
+
};
|
|
59
|
+
/** Current status of the tool invocation. */
|
|
60
|
+
status: McpToolCallStatus;
|
|
61
|
+
};
|
|
62
|
+
/** Response from the agent. Either natural-language text or JSON when structured output is requested. */
|
|
63
|
+
export type AgentMessageItem = {
|
|
64
|
+
id: string;
|
|
65
|
+
type: "agent_message";
|
|
66
|
+
/** Either natural-language text or JSON when structured output is requested. */
|
|
67
|
+
text: string;
|
|
68
|
+
};
|
|
69
|
+
/** Agent's reasoning summary. */
|
|
70
|
+
export type ReasoningItem = {
|
|
71
|
+
id: string;
|
|
72
|
+
type: "reasoning";
|
|
73
|
+
text: string;
|
|
74
|
+
};
|
|
75
|
+
/** Captures a web search request. Completes when results are returned to the agent. */
|
|
76
|
+
export type WebSearchItem = {
|
|
77
|
+
id: string;
|
|
78
|
+
type: "web_search";
|
|
79
|
+
query: string;
|
|
80
|
+
};
|
|
81
|
+
/** Describes a non-fatal error surfaced as an item. */
|
|
82
|
+
export type ErrorItem = {
|
|
83
|
+
id: string;
|
|
84
|
+
type: "error";
|
|
85
|
+
message: string;
|
|
86
|
+
};
|
|
87
|
+
/** An item in the agent's to-do list. */
|
|
88
|
+
export type TodoItem = {
|
|
89
|
+
text: string;
|
|
90
|
+
completed: boolean;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Tracks the agent's running to-do list. Starts when the plan is issued, updates as steps change,
|
|
94
|
+
* and completes when the turn ends.
|
|
95
|
+
*/
|
|
96
|
+
export type TodoListItem = {
|
|
97
|
+
id: string;
|
|
98
|
+
type: "todo_list";
|
|
99
|
+
items: TodoItem[];
|
|
100
|
+
};
|
|
101
|
+
/** Canonical union of thread items and their type-specific payloads. */
|
|
102
|
+
export type ThreadItem = AgentMessageItem | ReasoningItem | CommandExecutionItem | FileChangeItem | McpToolCallItem | WebSearchItem | TodoListItem | ErrorItem;
|
|
103
|
+
//# sourceMappingURL=items.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"items.d.ts","sourceRoot":"","sources":["../../src/items.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,IAAI,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAE1F,yCAAyC;AACzC,MA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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"items.js","sourceRoot":"","sources":["../../src/items.ts"],"names":[],"mappings":"AAAA,4DAA4D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"outputSchemaFile.d.ts","sourceRoot":"","sources":["../../src/outputSchemaFile.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,gBAAgB,GAAG;IAC7B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B,CAAC;AAEF,wBAAsB,sBAAsB,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC,CA0BvF"}
|