@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,33 @@
|
|
|
1
|
+
import { promises as fs } from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
export async function createOutputSchemaFile(schema) {
|
|
5
|
+
if (schema === undefined) {
|
|
6
|
+
return { cleanup: async () => { } };
|
|
7
|
+
}
|
|
8
|
+
if (!isJsonObject(schema)) {
|
|
9
|
+
throw new Error("outputSchema must be a plain JSON object");
|
|
10
|
+
}
|
|
11
|
+
const schemaDir = await fs.mkdtemp(path.join(os.tmpdir(), "codex-output-schema-"));
|
|
12
|
+
const schemaPath = path.join(schemaDir, "schema.json");
|
|
13
|
+
const cleanup = async () => {
|
|
14
|
+
try {
|
|
15
|
+
await fs.rm(schemaDir, { recursive: true, force: true });
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
// suppress
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
try {
|
|
22
|
+
await fs.writeFile(schemaPath, JSON.stringify(schema), "utf8");
|
|
23
|
+
return { schemaPath, cleanup };
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
await cleanup();
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function isJsonObject(value) {
|
|
31
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=outputSchemaFile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"outputSchemaFile.js","sourceRoot":"","sources":["../../src/outputSchemaFile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAO7B,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,MAAe;IAC1D,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,EAAE,OAAO,EAAE,KAAK,IAAI,EAAE,GAAE,CAAC,EAAE,CAAC;IACrC,CAAC;IAED,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;IAC9D,CAAC;IAED,MAAM,SAAS,GAAG,MAAM,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,sBAAsB,CAAC,CAAC,CAAC;IACnF,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;IACvD,MAAM,OAAO,GAAG,KAAK,IAAI,EAAE;QACzB,IAAI,CAAC;YACH,MAAM,EAAE,CAAC,EAAE,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QAC3D,CAAC;QAAC,MAAM,CAAC;YACP,WAAW;QACb,CAAC;IACH,CAAC,CAAC;IAEF,IAAI,CAAC;QACH,MAAM,EAAE,CAAC,SAAS,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC;QAC/D,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC;IACjC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,OAAO,EAAE,CAAC;QAChB,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED,SAAS,YAAY,CAAC,KAAc;IAClC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ThreadEvent, Usage } from "./events";
|
|
2
|
+
import { ThreadItem } from "./items";
|
|
3
|
+
import { TurnOptions } from "./turnOptions";
|
|
4
|
+
/** Completed turn. */
|
|
5
|
+
export type Turn = {
|
|
6
|
+
items: ThreadItem[];
|
|
7
|
+
finalResponse: string;
|
|
8
|
+
usage: Usage | null;
|
|
9
|
+
};
|
|
10
|
+
/** Alias for `Turn` to describe the result of `run()`. */
|
|
11
|
+
export type RunResult = Turn;
|
|
12
|
+
/** The result of the `runStreamed` method. */
|
|
13
|
+
export type StreamedTurn = {
|
|
14
|
+
events: AsyncGenerator<ThreadEvent>;
|
|
15
|
+
};
|
|
16
|
+
/** Alias for `StreamedTurn` to describe the result of `runStreamed()`. */
|
|
17
|
+
export type RunStreamedResult = StreamedTurn;
|
|
18
|
+
/** An input to send to the agent. */
|
|
19
|
+
export type UserInput = {
|
|
20
|
+
type: "text";
|
|
21
|
+
text: string;
|
|
22
|
+
} | {
|
|
23
|
+
type: "local_image";
|
|
24
|
+
path: string;
|
|
25
|
+
};
|
|
26
|
+
export type Input = string | UserInput[];
|
|
27
|
+
/** Respesent a thread of conversation with the agent. One thread can have multiple consecutive turns. */
|
|
28
|
+
export declare class Thread {
|
|
29
|
+
private _exec;
|
|
30
|
+
private _options;
|
|
31
|
+
private _id;
|
|
32
|
+
private _threadOptions;
|
|
33
|
+
/** Returns the ID of the thread. Populated after the first turn starts. */
|
|
34
|
+
get id(): string | null;
|
|
35
|
+
/** Provides the input to the agent and streams events as they are produced during the turn. */
|
|
36
|
+
runStreamed(input: Input, turnOptions?: TurnOptions): Promise<StreamedTurn>;
|
|
37
|
+
private runStreamedInternal;
|
|
38
|
+
/** Provides the input to the agent and returns the completed turn. */
|
|
39
|
+
run(input: Input, turnOptions?: TurnOptions): Promise<Turn>;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=thread.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"thread.d.ts","sourceRoot":"","sources":["../../src/thread.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAe,KAAK,EAAE,MAAM,UAAU,CAAC;AAE3D,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C,sBAAsB;AACtB,MAAM,MAAM,IAAI,GAAG;IACjB,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;CACrB,CAAC;AAEF,0DAA0D;AAC1D,MAAM,MAAM,SAAS,GAAG,IAAI,CAAC;AAE7B,8CAA8C;AAC9C,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,EAAE,cAAc,CAAC,WAAW,CAAC,CAAC;CACrC,CAAC;AAEF,0EAA0E;AAC1E,MAAM,MAAM,iBAAiB,GAAG,YAAY,CAAC;AAE7C,qCAAqC;AACrC,MAAM,MAAM,SAAS,GACjB;IACE,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,GACD;IACE,IAAI,EAAE,aAAa,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEN,MAAM,MAAM,KAAK,GAAG,MAAM,GAAG,SAAS,EAAE,CAAC;AAEzC,yGAAyG;AACzG,qBAAa,MAAM;IACjB,OAAO,CAAC,KAAK,CAAY;IACzB,OAAO,CAAC,QAAQ,CAAe;IAC/B,OAAO,CAAC,GAAG,CAAgB;IAC3B,OAAO,CAAC,cAAc,CAAgB;IAEtC,2EAA2E;IAC3E,IAAW,EAAE,IAAI,MAAM,GAAG,IAAI,CAE7B;IAeD,+FAA+F;IACzF,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,WAAW,GAAE,WAAgB,GAAG,OAAO,CAAC,YAAY,CAAC;YAItE,mBAAmB;IA4ClC,sEAAsE;IAChE,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,WAAW,GAAE,WAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;CAwBtE"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { createOutputSchemaFile } from "./outputSchemaFile";
|
|
2
|
+
/** Respesent a thread of conversation with the agent. One thread can have multiple consecutive turns. */
|
|
3
|
+
export class Thread {
|
|
4
|
+
_exec;
|
|
5
|
+
_options;
|
|
6
|
+
_id;
|
|
7
|
+
_threadOptions;
|
|
8
|
+
/** Returns the ID of the thread. Populated after the first turn starts. */
|
|
9
|
+
get id() {
|
|
10
|
+
return this._id;
|
|
11
|
+
}
|
|
12
|
+
/* @internal */
|
|
13
|
+
constructor(exec, options, threadOptions, id = null) {
|
|
14
|
+
this._exec = exec;
|
|
15
|
+
this._options = options;
|
|
16
|
+
this._id = id;
|
|
17
|
+
this._threadOptions = threadOptions;
|
|
18
|
+
}
|
|
19
|
+
/** Provides the input to the agent and streams events as they are produced during the turn. */
|
|
20
|
+
async runStreamed(input, turnOptions = {}) {
|
|
21
|
+
return { events: this.runStreamedInternal(input, turnOptions) };
|
|
22
|
+
}
|
|
23
|
+
async *runStreamedInternal(input, turnOptions = {}) {
|
|
24
|
+
const { schemaPath, cleanup } = await createOutputSchemaFile(turnOptions.outputSchema);
|
|
25
|
+
const options = this._threadOptions;
|
|
26
|
+
const { prompt, images } = normalizeInput(input);
|
|
27
|
+
const generator = this._exec.run({
|
|
28
|
+
input: prompt,
|
|
29
|
+
baseUrl: this._options.baseUrl,
|
|
30
|
+
apiKey: this._options.apiKey,
|
|
31
|
+
threadId: this._id,
|
|
32
|
+
images,
|
|
33
|
+
model: options?.model,
|
|
34
|
+
sandboxMode: options?.sandboxMode,
|
|
35
|
+
workingDirectory: options?.workingDirectory,
|
|
36
|
+
skipGitRepoCheck: options?.skipGitRepoCheck,
|
|
37
|
+
outputSchemaFile: schemaPath,
|
|
38
|
+
modelReasoningEffort: options?.modelReasoningEffort,
|
|
39
|
+
signal: turnOptions.signal,
|
|
40
|
+
networkAccessEnabled: options?.networkAccessEnabled,
|
|
41
|
+
webSearchEnabled: options?.webSearchEnabled,
|
|
42
|
+
approvalPolicy: options?.approvalPolicy,
|
|
43
|
+
additionalDirectories: options?.additionalDirectories,
|
|
44
|
+
configOverrides: options?.configOverrides,
|
|
45
|
+
});
|
|
46
|
+
try {
|
|
47
|
+
for await (const item of generator) {
|
|
48
|
+
let parsed;
|
|
49
|
+
try {
|
|
50
|
+
parsed = JSON.parse(item);
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
throw new Error(`Failed to parse item: ${item}`, { cause: error });
|
|
54
|
+
}
|
|
55
|
+
if (parsed.type === "thread.started") {
|
|
56
|
+
this._id = parsed.thread_id;
|
|
57
|
+
}
|
|
58
|
+
yield parsed;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
finally {
|
|
62
|
+
await cleanup();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/** Provides the input to the agent and returns the completed turn. */
|
|
66
|
+
async run(input, turnOptions = {}) {
|
|
67
|
+
const generator = this.runStreamedInternal(input, turnOptions);
|
|
68
|
+
const items = [];
|
|
69
|
+
let finalResponse = "";
|
|
70
|
+
let usage = null;
|
|
71
|
+
let turnFailure = null;
|
|
72
|
+
for await (const event of generator) {
|
|
73
|
+
if (event.type === "item.completed") {
|
|
74
|
+
if (event.item.type === "agent_message") {
|
|
75
|
+
finalResponse = event.item.text;
|
|
76
|
+
}
|
|
77
|
+
items.push(event.item);
|
|
78
|
+
}
|
|
79
|
+
else if (event.type === "turn.completed") {
|
|
80
|
+
usage = event.usage;
|
|
81
|
+
}
|
|
82
|
+
else if (event.type === "turn.failed") {
|
|
83
|
+
turnFailure = event.error;
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (turnFailure) {
|
|
88
|
+
throw new Error(turnFailure.message);
|
|
89
|
+
}
|
|
90
|
+
return { items, finalResponse, usage };
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function normalizeInput(input) {
|
|
94
|
+
if (typeof input === "string") {
|
|
95
|
+
return { prompt: input, images: [] };
|
|
96
|
+
}
|
|
97
|
+
const promptParts = [];
|
|
98
|
+
const images = [];
|
|
99
|
+
for (const item of input) {
|
|
100
|
+
if (item.type === "text") {
|
|
101
|
+
promptParts.push(item.text);
|
|
102
|
+
}
|
|
103
|
+
else if (item.type === "local_image") {
|
|
104
|
+
images.push(item.path);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return { prompt: promptParts.join("\n\n"), images };
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=thread.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"thread.js","sourceRoot":"","sources":["../../src/thread.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAiC5D,yGAAyG;AACzG,MAAM,OAAO,MAAM;IACT,KAAK,CAAY;IACjB,QAAQ,CAAe;IACvB,GAAG,CAAgB;IACnB,cAAc,CAAgB;IAEtC,2EAA2E;IAC3E,IAAW,EA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AAC,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;AACtD,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type ApprovalMode = "never" | "on-request" | "on-failure" | "untrusted";
|
|
2
|
+
export type SandboxMode = "read-only" | "workspace-write" | "danger-full-access";
|
|
3
|
+
export type ModelReasoningEffort = "minimal" | "low" | "medium" | "high" | "xhigh";
|
|
4
|
+
export type ThreadOptions = {
|
|
5
|
+
model?: string;
|
|
6
|
+
sandboxMode?: SandboxMode;
|
|
7
|
+
workingDirectory?: string;
|
|
8
|
+
skipGitRepoCheck?: boolean;
|
|
9
|
+
modelReasoningEffort?: ModelReasoningEffort;
|
|
10
|
+
networkAccessEnabled?: boolean;
|
|
11
|
+
webSearchEnabled?: boolean;
|
|
12
|
+
approvalPolicy?: ApprovalMode;
|
|
13
|
+
additionalDirectories?: string[];
|
|
14
|
+
configOverrides?: Record<string, unknown>;
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=threadOptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"threadOptions.d.ts","sourceRoot":"","sources":["../../src/threadOptions.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,YAAY,GAAG,YAAY,GAAG,WAAW,CAAC;AAE/E,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG,iBAAiB,GAAG,oBAAoB,CAAC;AAEjF,MAAM,MAAM,oBAAoB,GAAG,SAAS,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC;AAEnF,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;IAC5C,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,cAAc,CAAC,EAAE,YAAY,CAAC;IAC9B,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAC;IACjC,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC3C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"threadOptions.js","sourceRoot":"","sources":["../../src/threadOptions.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"turnOptions.d.ts","sourceRoot":"","sources":["../../src/turnOptions.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG;IACxB,wDAAwD;IACxD,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,sCAAsC;IACtC,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"turnOptions.js","sourceRoot":"","sources":["../../src/turnOptions.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abort.test.d.ts","sourceRoot":"","sources":["../../tests/abort.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { describe, expect, it } from "@jest/globals";
|
|
3
|
+
import { Codex } from "../src/codex";
|
|
4
|
+
import { assistantMessage, responseCompleted, responseStarted, shell_call as shellCall, sse, startResponsesTestProxy, } from "./responsesProxy";
|
|
5
|
+
const codexExecPath = path.join(process.cwd(), "..", "..", "codex-rs", "target", "debug", "codex");
|
|
6
|
+
function* infiniteShellCall() {
|
|
7
|
+
while (true) {
|
|
8
|
+
yield sse(responseStarted(), shellCall(), responseCompleted());
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
describe("AbortSignal support", () => {
|
|
12
|
+
it("aborts run() when signal is aborted", async () => {
|
|
13
|
+
const { url, close } = await startResponsesTestProxy({
|
|
14
|
+
statusCode: 200,
|
|
15
|
+
responseBodies: infiniteShellCall(),
|
|
16
|
+
});
|
|
17
|
+
try {
|
|
18
|
+
const client = new Codex({ codexPathOverride: codexExecPath, baseUrl: url, apiKey: "test" });
|
|
19
|
+
const thread = client.startThread();
|
|
20
|
+
// Create an abort controller and abort it immediately
|
|
21
|
+
const controller = new AbortController();
|
|
22
|
+
controller.abort("Test abort");
|
|
23
|
+
// The operation should fail because the signal is already aborted
|
|
24
|
+
await expect(thread.run("Hello, world!", { signal: controller.signal })).rejects.toThrow();
|
|
25
|
+
}
|
|
26
|
+
finally {
|
|
27
|
+
await close();
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
it("aborts runStreamed() when signal is aborted", async () => {
|
|
31
|
+
const { url, close } = await startResponsesTestProxy({
|
|
32
|
+
statusCode: 200,
|
|
33
|
+
responseBodies: infiniteShellCall(),
|
|
34
|
+
});
|
|
35
|
+
try {
|
|
36
|
+
const client = new Codex({ codexPathOverride: codexExecPath, baseUrl: url, apiKey: "test" });
|
|
37
|
+
const thread = client.startThread();
|
|
38
|
+
// Create an abort controller and abort it immediately
|
|
39
|
+
const controller = new AbortController();
|
|
40
|
+
controller.abort("Test abort");
|
|
41
|
+
const { events } = await thread.runStreamed("Hello, world!", { signal: controller.signal });
|
|
42
|
+
// Attempting to iterate should fail
|
|
43
|
+
let iterationStarted = false;
|
|
44
|
+
try {
|
|
45
|
+
for await (const event of events) {
|
|
46
|
+
iterationStarted = true;
|
|
47
|
+
// Should not get here
|
|
48
|
+
expect(event).toBeUndefined();
|
|
49
|
+
}
|
|
50
|
+
// If we get here, the test should fail
|
|
51
|
+
throw new Error("Expected iteration to throw due to aborted signal, but it completed successfully");
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
// We expect an error to be thrown
|
|
55
|
+
expect(iterationStarted).toBe(false); // Should fail before any iteration
|
|
56
|
+
expect(error).toBeDefined();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
finally {
|
|
60
|
+
await close();
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
it("aborts run() when signal is aborted during execution", async () => {
|
|
64
|
+
const { url, close } = await startResponsesTestProxy({
|
|
65
|
+
statusCode: 200,
|
|
66
|
+
responseBodies: infiniteShellCall(),
|
|
67
|
+
});
|
|
68
|
+
try {
|
|
69
|
+
const client = new Codex({ codexPathOverride: codexExecPath, baseUrl: url, apiKey: "test" });
|
|
70
|
+
const thread = client.startThread();
|
|
71
|
+
const controller = new AbortController();
|
|
72
|
+
// Start the operation and abort it immediately after
|
|
73
|
+
const runPromise = thread.run("Hello, world!", { signal: controller.signal });
|
|
74
|
+
// Abort after a tiny delay to simulate aborting during execution
|
|
75
|
+
setTimeout(() => controller.abort("Aborted during execution"), 10);
|
|
76
|
+
// The operation should fail
|
|
77
|
+
await expect(runPromise).rejects.toThrow();
|
|
78
|
+
}
|
|
79
|
+
finally {
|
|
80
|
+
await close();
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
it("aborts runStreamed() when signal is aborted during iteration", async () => {
|
|
84
|
+
const { url, close } = await startResponsesTestProxy({
|
|
85
|
+
statusCode: 200,
|
|
86
|
+
responseBodies: infiniteShellCall(),
|
|
87
|
+
});
|
|
88
|
+
try {
|
|
89
|
+
const client = new Codex({ codexPathOverride: codexExecPath, baseUrl: url, apiKey: "test" });
|
|
90
|
+
const thread = client.startThread();
|
|
91
|
+
const controller = new AbortController();
|
|
92
|
+
const { events } = await thread.runStreamed("Hello, world!", { signal: controller.signal });
|
|
93
|
+
// Abort during iteration
|
|
94
|
+
let eventCount = 0;
|
|
95
|
+
await expect((async () => {
|
|
96
|
+
for await (const event of events) {
|
|
97
|
+
void event; // Consume the event
|
|
98
|
+
eventCount++;
|
|
99
|
+
// Abort after first event
|
|
100
|
+
if (eventCount === 5) {
|
|
101
|
+
controller.abort("Aborted during iteration");
|
|
102
|
+
}
|
|
103
|
+
// Continue iterating - should eventually throw
|
|
104
|
+
}
|
|
105
|
+
})()).rejects.toThrow();
|
|
106
|
+
}
|
|
107
|
+
finally {
|
|
108
|
+
await close();
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
it("completes normally when signal is not aborted", async () => {
|
|
112
|
+
const { url, close } = await startResponsesTestProxy({
|
|
113
|
+
statusCode: 200,
|
|
114
|
+
responseBodies: [sse(responseStarted(), assistantMessage("Hi!"), responseCompleted())],
|
|
115
|
+
});
|
|
116
|
+
try {
|
|
117
|
+
const client = new Codex({ codexPathOverride: codexExecPath, baseUrl: url, apiKey: "test" });
|
|
118
|
+
const thread = client.startThread();
|
|
119
|
+
const controller = new AbortController();
|
|
120
|
+
// Don't abort - should complete successfully
|
|
121
|
+
const result = await thread.run("Hello, world!", { signal: controller.signal });
|
|
122
|
+
expect(result.finalResponse).toBe("Hi!");
|
|
123
|
+
expect(result.items).toHaveLength(1);
|
|
124
|
+
}
|
|
125
|
+
finally {
|
|
126
|
+
await close();
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
//# sourceMappingURL=abort.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abort.test.js","sourceRoot":"","sources":["../../tests/abort.test.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,eAAe,CAAC;AAErD,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAErC,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,UAAU,IAAI,SAAS,EACvB,GAAG,EAEH,uBAAuB,GACxB,MAAM,kBAAkB,CAAC;AAE1B,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EA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EAAE,CAAC,CAAC;YAEhF,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACzC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;QACvC,CAAC;gBAAS,CAAC;YACT,MAAM,KAAK,EAAE,CAAC;QAChB,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codexExecSpy.d.ts","sourceRoot":"","sources":["../../tests/codexExecSpy.ts"],"names":[],"mappings":"AAWA,wBAAgB,YAAY,IAAI;IAC9B,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC;IACjB,IAAI,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC,EAAE,CAAC;IAC7C,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAqBA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as child_process from "node:child_process";
|
|
2
|
+
jest.mock("node:child_process", () => {
|
|
3
|
+
const actual = jest.requireActual("node:child_process");
|
|
4
|
+
return { ...actual, spawn: jest.fn(actual.spawn) };
|
|
5
|
+
});
|
|
6
|
+
const actualChildProcess = jest.requireActual("node:child_process");
|
|
7
|
+
const spawnMock = child_process.spawn;
|
|
8
|
+
export function codexExecSpy() {
|
|
9
|
+
const previousImplementation = spawnMock.getMockImplementation() ?? actualChildProcess.spawn;
|
|
10
|
+
const args = [];
|
|
11
|
+
const envs = [];
|
|
12
|
+
spawnMock.mockImplementation(((...spawnArgs) => {
|
|
13
|
+
const commandArgs = spawnArgs[1];
|
|
14
|
+
args.push(Array.isArray(commandArgs) ? [...commandArgs] : []);
|
|
15
|
+
const options = spawnArgs[2];
|
|
16
|
+
envs.push(options?.env);
|
|
17
|
+
return previousImplementation(...spawnArgs);
|
|
18
|
+
}));
|
|
19
|
+
return {
|
|
20
|
+
args,
|
|
21
|
+
envs,
|
|
22
|
+
restore: () => {
|
|
23
|
+
spawnMock.mockClear();
|
|
24
|
+
spawnMock.mockImplementation(previousImplementation);
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=codexExecSpy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codexExecSpy.js","sourceRoot":"","sources":["../../tests/codexExecSpy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAC;AAEpD,IAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE,GAAG,EAAE;IACnC,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,CAAsC,oBAAoB,CAAC,CAAC;IAC7F,OAAO,EAAE,GAAG,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;AACrD,CAAC,CAAC,CAAC;AAEH,MAAM,kBAAkB,GACtB,IAAI,CAAC,aAAa,CAAsC,oBAAoB,CAAC,CAAC;AAChF,MAAM,SAAS,GAAG,aAAa,CAAC,KAA6D,CAAC;AAE9F,MAAM,UAAU,YAAY;IAK1B,MAAM,sBAAsB,GAAG,SAAS,CAAC,qBAAqB,EAAE,IAAI,kBAAkB,CAAC,KAAK,CAAC;IAC7F,MAAM,IAAI,GAAe,EAAE,CAAC;IAC5B,MAAM,IAAI,GAA2C,EAAE,CAAC;IAExD,SAAS,CAAC,kBAAkB,CAAC,CAAC,CAAC,GAAG,SAAiD,EAAE,EAAE;QACrF,MAAM,WAAW,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;QACjC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QAC9D,MAAM,OAAO,GAAG,SAAS,CAAC,CAAC,CAA2C,CAAC;QACvE,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,GAAyC,CAAC,CAAC;QAC9D,OAAO,sBAAsB,CAAC,GAAG,SAAS,CAAC,CAAC;IAC9C,CAAC,CAAoC,CAAC,CAAC;IAEvC,OAAO;QACL,IAAI;QACJ,IAAI;QACJ,OAAO,EAAE,GAAG,EAAE;YACZ,SAAS,CAAC,SAAS,EAAE,CAAC;YACtB,SAAS,CAAC,kBAAkB,CAAC,sBAAsB,CAAC,CAAC;QACvD,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import http from "node:http";
|
|
2
|
+
type ResponseCompletedUsage = {
|
|
3
|
+
input_tokens: number;
|
|
4
|
+
input_tokens_details: {
|
|
5
|
+
cached_tokens: number;
|
|
6
|
+
} | null;
|
|
7
|
+
output_tokens: number;
|
|
8
|
+
output_tokens_details: {
|
|
9
|
+
reasoning_tokens: number;
|
|
10
|
+
} | null;
|
|
11
|
+
total_tokens: number;
|
|
12
|
+
};
|
|
13
|
+
export type SseEvent = {
|
|
14
|
+
type: string;
|
|
15
|
+
[key: string]: unknown;
|
|
16
|
+
};
|
|
17
|
+
export type SseResponseBody = {
|
|
18
|
+
kind: "sse";
|
|
19
|
+
events: SseEvent[];
|
|
20
|
+
};
|
|
21
|
+
export type ResponsesProxyOptions = {
|
|
22
|
+
responseBodies: Generator<SseResponseBody> | SseResponseBody[];
|
|
23
|
+
statusCode?: number;
|
|
24
|
+
};
|
|
25
|
+
export type ResponsesProxy = {
|
|
26
|
+
url: string;
|
|
27
|
+
close: () => Promise<void>;
|
|
28
|
+
requests: RecordedRequest[];
|
|
29
|
+
};
|
|
30
|
+
export type ResponsesApiRequest = {
|
|
31
|
+
model?: string;
|
|
32
|
+
input: Array<{
|
|
33
|
+
role: string;
|
|
34
|
+
content?: Array<{
|
|
35
|
+
type: string;
|
|
36
|
+
text: string;
|
|
37
|
+
}>;
|
|
38
|
+
}>;
|
|
39
|
+
text?: {
|
|
40
|
+
format?: Record<string, unknown>;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
export type RecordedRequest = {
|
|
44
|
+
body: string;
|
|
45
|
+
json: ResponsesApiRequest;
|
|
46
|
+
headers: http.IncomingHttpHeaders;
|
|
47
|
+
};
|
|
48
|
+
export declare function startResponsesTestProxy(options: ResponsesProxyOptions): Promise<ResponsesProxy>;
|
|
49
|
+
export declare function sse(...events: SseEvent[]): SseResponseBody;
|
|
50
|
+
export declare function responseStarted(responseId?: string): SseEvent;
|
|
51
|
+
export declare function assistantMessage(text: string, itemId?: string): SseEvent;
|
|
52
|
+
export declare function shell_call(): SseEvent;
|
|
53
|
+
export declare function responseFailed(errorMessage: string): SseEvent;
|
|
54
|
+
export declare function responseCompleted(responseId?: string, usage?: ResponseCompletedUsage): SseEvent;
|
|
55
|
+
export {};
|
|
56
|
+
//# sourceMappingURL=responsesProxy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"responsesProxy.d.ts","sourceRoot":"","sources":["../../tests/responsesProxy.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAK7B,KAAK,sBAAsB,GAAG;IAC5B,YAAY,EAAE,MAAM,CAAC;IACrB,oBAAoB,EAAE;QAAE,aAAa,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IACvD,aAAa,EAAE,MAAM,CAAC;IACtB,qBAAqB,EAAE;QAAE,gBAAgB,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAC3D,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAUF,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,KAAK,CAAC;IACZ,MAAM,EAAE,QAAQ,EAAE,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