@northflare/runner 0.0.32 → 0.0.33
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/dist/{chunk-7D4SUZUM.js → chunk-54HOGCFN.js} +2 -1
- package/dist/{chunk-3QTLJ4CG.js → chunk-B47WUOBY.js} +4 -3
- package/dist/{chunk-3QTLJ4CG.js.map → chunk-B47WUOBY.js.map} +1 -1
- package/dist/{dist-W7DZRE4U.js → dist-4E3H46W5.js} +3 -2
- package/dist/{dist-W7DZRE4U.js.map → dist-4E3H46W5.js.map} +1 -1
- package/dist/index.js +11 -4
- package/dist/index.js.map +1 -1
- package/dist/sdk-query-TRMSGGID-V7NQOFUG.js +15 -0
- package/package.json +7 -1
- package/tsup.config.ts +5 -1
- package/dist/sdk-query-TRMSGGID-EIENWDKW.js +0 -14
- /package/dist/{chunk-7D4SUZUM.js.map → chunk-54HOGCFN.js.map} +0 -0
- /package/dist/{sdk-query-TRMSGGID-EIENWDKW.js.map → sdk-query-TRMSGGID-V7NQOFUG.js.map} +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { createRequire as __createRequire } from 'module'; const require = __createRequire(import.meta.url);
|
|
2
|
+
import "./chunk-54HOGCFN.js";
|
|
2
3
|
|
|
3
4
|
// ../codex-sdk/dist/index.js
|
|
4
5
|
import { promises as fs } from "fs";
|
|
@@ -362,4 +363,4 @@ export {
|
|
|
362
363
|
Codex,
|
|
363
364
|
Thread
|
|
364
365
|
};
|
|
365
|
-
//# sourceMappingURL=dist-
|
|
366
|
+
//# sourceMappingURL=dist-4E3H46W5.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../codex-sdk/src/outputSchemaFile.ts","../../codex-sdk/src/thread.ts","../../codex-sdk/src/exec.ts","../../codex-sdk/src/codex.ts"],"sourcesContent":["import { promises as fs } from \"node:fs\";\nimport os from \"node:os\";\nimport path from \"node:path\";\n\nexport type OutputSchemaFile = {\n schemaPath?: string;\n cleanup: () => Promise<void>;\n};\n\nexport async function createOutputSchemaFile(schema: unknown): Promise<OutputSchemaFile> {\n if (schema === undefined) {\n return { cleanup: async () => {} };\n }\n\n if (!isJsonObject(schema)) {\n throw new Error(\"outputSchema must be a plain JSON object\");\n }\n\n const schemaDir = await fs.mkdtemp(path.join(os.tmpdir(), \"codex-output-schema-\"));\n const schemaPath = path.join(schemaDir, \"schema.json\");\n const cleanup = async () => {\n try {\n await fs.rm(schemaDir, { recursive: true, force: true });\n } catch {\n // suppress\n }\n };\n\n try {\n await fs.writeFile(schemaPath, JSON.stringify(schema), \"utf8\");\n return { schemaPath, cleanup };\n } catch (error) {\n await cleanup();\n throw error;\n }\n}\n\nfunction isJsonObject(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n","import { CodexOptions } from \"./codexOptions\";\nimport { ThreadEvent, ThreadError, Usage } from \"./events\";\nimport { CodexExec } from \"./exec\";\nimport { ThreadItem } from \"./items\";\nimport { ThreadOptions } from \"./threadOptions\";\nimport { TurnOptions } from \"./turnOptions\";\nimport { createOutputSchemaFile } from \"./outputSchemaFile\";\n\n/** Completed turn. */\nexport type Turn = {\n items: ThreadItem[];\n finalResponse: string;\n usage: Usage | null;\n};\n\n/** Alias for `Turn` to describe the result of `run()`. */\nexport type RunResult = Turn;\n\n/** The result of the `runStreamed` method. */\nexport type StreamedTurn = {\n events: AsyncGenerator<ThreadEvent>;\n};\n\n/** Alias for `StreamedTurn` to describe the result of `runStreamed()`. */\nexport type RunStreamedResult = StreamedTurn;\n\n/** An input to send to the agent. */\nexport type UserInput =\n | {\n type: \"text\";\n text: string;\n }\n | {\n type: \"local_image\";\n path: string;\n };\n\nexport type Input = string | UserInput[];\n\n/** Respesent a thread of conversation with the agent. One thread can have multiple consecutive turns. */\nexport class Thread {\n private _exec: CodexExec;\n private _options: CodexOptions;\n private _id: string | null;\n private _threadOptions: ThreadOptions;\n private _initialMessagesSent: boolean = false;\n\n /** Returns the ID of the thread. Populated after the first turn starts. */\n public get id(): string | null {\n return this._id;\n }\n\n /* @internal */\n constructor(\n exec: CodexExec,\n options: CodexOptions,\n threadOptions: ThreadOptions,\n id: string | null = null,\n ) {\n this._exec = exec;\n this._options = options;\n this._id = id;\n this._threadOptions = threadOptions;\n // If resuming an existing thread, initial messages have already been sent\n this._initialMessagesSent = id !== null;\n }\n\n /** Provides the input to the agent and streams events as they are produced during the turn. */\n async runStreamed(input: Input, turnOptions: TurnOptions = {}): Promise<StreamedTurn> {\n return { events: this.runStreamedInternal(input, turnOptions) };\n }\n\n private async *runStreamedInternal(\n input: Input,\n turnOptions: TurnOptions = {},\n ): AsyncGenerator<ThreadEvent> {\n const { schemaPath, cleanup } = await createOutputSchemaFile(turnOptions.outputSchema);\n const options = this._threadOptions;\n const { prompt, images } = normalizeInput(input);\n\n // Prepend initial messages on the first turn only\n let finalPrompt = prompt;\n if (!this._initialMessagesSent && options.initialMessages?.length) {\n const formattedMessages = formatInitialMessages(options.initialMessages);\n finalPrompt = formattedMessages + \"\\n\\n\" + prompt;\n this._initialMessagesSent = true;\n }\n\n const generator = this._exec.run({\n input: finalPrompt,\n baseUrl: this._options.baseUrl,\n apiKey: this._options.apiKey,\n threadId: this._id,\n images,\n model: options?.model,\n sandboxMode: options?.sandboxMode,\n workingDirectory: options?.workingDirectory,\n skipGitRepoCheck: options?.skipGitRepoCheck,\n outputSchemaFile: schemaPath,\n modelReasoningEffort: options?.modelReasoningEffort,\n signal: turnOptions.signal,\n networkAccessEnabled: options?.networkAccessEnabled,\n webSearchEnabled: options?.webSearchEnabled,\n approvalPolicy: options?.approvalPolicy,\n additionalDirectories: options?.additionalDirectories,\n configOverrides: options?.configOverrides,\n });\n try {\n for await (const item of generator) {\n let parsed: ThreadEvent;\n try {\n parsed = JSON.parse(item) as ThreadEvent;\n } catch (error) {\n throw new Error(`Failed to parse item: ${item}`, { cause: error });\n }\n if (parsed.type === \"thread.started\") {\n this._id = parsed.thread_id;\n }\n yield parsed;\n }\n } finally {\n await cleanup();\n }\n }\n\n /** Provides the input to the agent and returns the completed turn. */\n async run(input: Input, turnOptions: TurnOptions = {}): Promise<Turn> {\n const generator = this.runStreamedInternal(input, turnOptions);\n const items: ThreadItem[] = [];\n let finalResponse: string = \"\";\n let usage: Usage | null = null;\n let turnFailure: ThreadError | null = null;\n for await (const event of generator) {\n if (event.type === \"item.completed\") {\n if (event.item.type === \"agent_message\") {\n finalResponse = event.item.text;\n }\n items.push(event.item);\n } else if (event.type === \"turn.completed\") {\n usage = event.usage;\n } else if (event.type === \"turn.failed\") {\n turnFailure = event.error;\n break;\n }\n }\n if (turnFailure) {\n throw new Error(turnFailure.message);\n }\n return { items, finalResponse, usage };\n }\n}\n\nfunction normalizeInput(input: Input): { prompt: string; images: string[] } {\n if (typeof input === \"string\") {\n return { prompt: input, images: [] };\n }\n const promptParts: string[] = [];\n const images: string[] = [];\n for (const item of input) {\n if (item.type === \"text\") {\n promptParts.push(item.text);\n } else if (item.type === \"local_image\") {\n images.push(item.path);\n }\n }\n return { prompt: promptParts.join(\"\\n\\n\"), images };\n}\n\nimport type { InitialMessage } from \"./threadOptions\";\n\n/**\n * Format initial messages into a structured prompt section.\n * Each message is wrapped with role markers to preserve semantic meaning.\n */\nfunction formatInitialMessages(messages: InitialMessage[]): string {\n return messages\n .map((msg) => {\n const roleLabel = msg.role.charAt(0).toUpperCase() + msg.role.slice(1);\n return `[${roleLabel}]\\n${msg.content}`;\n })\n .join(\"\\n\\n\");\n}\n","import { spawn } from \"node:child_process\";\nimport { existsSync, realpathSync } from \"node:fs\";\nimport path from \"node:path\";\nimport readline from \"node:readline\";\nimport { createRequire } from \"node:module\";\n\nimport { SandboxMode, ModelReasoningEffort, ApprovalMode } from \"./threadOptions\";\n\nexport type CodexExecArgs = {\n input: string;\n\n baseUrl?: string;\n apiKey?: string;\n threadId?: string | null;\n images?: string[];\n // --model\n model?: string;\n // --sandbox\n sandboxMode?: SandboxMode;\n // --cd\n workingDirectory?: string;\n // --add-dir\n additionalDirectories?: string[];\n // --skip-git-repo-check\n skipGitRepoCheck?: boolean;\n // --output-schema\n outputSchemaFile?: string;\n // --config model_reasoning_effort\n modelReasoningEffort?: ModelReasoningEffort;\n // AbortSignal to cancel the execution\n signal?: AbortSignal;\n // --config sandbox_workspace_write.network_access\n networkAccessEnabled?: boolean;\n // --config features.web_search_request\n webSearchEnabled?: boolean;\n // --config approval_policy\n approvalPolicy?: ApprovalMode;\n // Generic config overrides for `-c key=value`\n configOverrides?: Record<string, unknown>;\n};\n\nconst INTERNAL_ORIGINATOR_ENV = \"CODEX_INTERNAL_ORIGINATOR_OVERRIDE\";\nconst TYPESCRIPT_SDK_ORIGINATOR = \"codex_sdk_ts\";\nconst isDebugEnabled = process.env[\"DEBUG\"] === \"true\";\n\nexport class CodexExec {\n private executablePath: string;\n private envOverride?: Record<string, string>;\n\n constructor(executablePath: string | null = null, env?: Record<string, string>) {\n this.executablePath = executablePath || findCodexPath();\n this.envOverride = env;\n }\n\n async *run(args: CodexExecArgs): AsyncGenerator<string> {\n const commandArgs: string[] = [\"exec\", \"--experimental-json\"];\n\n if (args.model) {\n commandArgs.push(\"--model\", args.model);\n }\n\n if (args.sandboxMode) {\n commandArgs.push(\"--sandbox\", args.sandboxMode);\n }\n\n if (args.workingDirectory) {\n commandArgs.push(\"--cd\", args.workingDirectory);\n }\n\n if (args.additionalDirectories?.length) {\n for (const dir of args.additionalDirectories) {\n commandArgs.push(\"--add-dir\", dir);\n }\n }\n\n if (args.skipGitRepoCheck) {\n commandArgs.push(\"--skip-git-repo-check\");\n }\n\n if (args.outputSchemaFile) {\n commandArgs.push(\"--output-schema\", args.outputSchemaFile);\n }\n\n if (args.modelReasoningEffort) {\n commandArgs.push(\"--config\", `model_reasoning_effort=\"${args.modelReasoningEffort}\"`);\n }\n\n if (args.networkAccessEnabled !== undefined) {\n commandArgs.push(\n \"--config\",\n `sandbox_workspace_write.network_access=${args.networkAccessEnabled}`,\n );\n }\n\n if (args.webSearchEnabled !== undefined) {\n commandArgs.push(\"--config\", `features.web_search_request=${args.webSearchEnabled}`);\n }\n\n if (args.approvalPolicy) {\n commandArgs.push(\"--config\", `approval_policy=\"${args.approvalPolicy}\"`);\n }\n\n if (args.configOverrides) {\n for (const [key, value] of Object.entries(args.configOverrides)) {\n const formatted = formatConfigValue(value);\n commandArgs.push(\"--config\", `${key}=${formatted}`);\n }\n }\n\n if (args.images?.length) {\n for (const image of args.images) {\n commandArgs.push(\"--image\", image);\n }\n }\n\n if (args.threadId) {\n commandArgs.push(\"resume\", args.threadId);\n }\n\n if (isDebugEnabled) {\n console.log(\"[CodexExec] Executable path:\", this.executablePath);\n console.log(\"[CodexExec] Command arguments:\", commandArgs);\n }\n\n const env: Record<string, string> = {};\n if (this.envOverride) {\n Object.assign(env, this.envOverride);\n const hasPathKey = Object.keys(env).some((key) => key.toUpperCase() === \"PATH\");\n if (!hasPathKey) {\n const inheritedPathKey = Object.keys(process.env).find((key) => key.toUpperCase() === \"PATH\");\n if (inheritedPathKey && process.env[inheritedPathKey]) {\n env.PATH = process.env[inheritedPathKey]!;\n }\n }\n } else {\n for (const [key, value] of Object.entries(process.env)) {\n if (value !== undefined) {\n env[key] = value;\n }\n }\n }\n if (!env[INTERNAL_ORIGINATOR_ENV]) {\n env[INTERNAL_ORIGINATOR_ENV] = TYPESCRIPT_SDK_ORIGINATOR;\n }\n if (args.baseUrl) {\n env.OPENAI_BASE_URL = args.baseUrl;\n }\n if (args.apiKey) {\n env.CODEX_API_KEY = args.apiKey;\n }\n\n const child = spawn(this.executablePath, commandArgs, {\n env,\n signal: args.signal,\n });\n\n let spawnError: unknown | null = null;\n child.once(\"error\", (err) => (spawnError = err));\n\n if (!child.stdin) {\n child.kill();\n throw new Error(\"Child process has no stdin\");\n }\n child.stdin.write(args.input);\n child.stdin.end();\n\n if (!child.stdout) {\n child.kill();\n throw new Error(\"Child process has no stdout\");\n }\n const stderrChunks: Buffer[] = [];\n\n if (child.stderr) {\n child.stderr.on(\"data\", (data) => {\n stderrChunks.push(data);\n });\n }\n\n const rl = readline.createInterface({\n input: child.stdout,\n crlfDelay: Infinity,\n });\n\n try {\n for await (const line of rl) {\n // `line` is a string (Node sets default encoding to utf8 for readline)\n yield line as string;\n }\n\n const exitCode = new Promise((resolve, reject) => {\n child.once(\"exit\", (code) => {\n if (code === 0) {\n resolve(code);\n } else {\n const stderrBuffer = Buffer.concat(stderrChunks);\n reject(\n new Error(`Codex Exec exited with code ${code}: ${stderrBuffer.toString(\"utf8\")}`),\n );\n }\n });\n });\n\n if (spawnError) throw spawnError;\n await exitCode;\n } finally {\n rl.close();\n child.removeAllListeners();\n try {\n if (!child.killed) child.kill();\n } catch {\n // ignore\n }\n }\n }\n}\n\nconst moduleRequire = createRequire(import.meta.url);\n\nfunction findCodexPath() {\n // `@openai/codex-sdk` provides a `codex` executable shim under\n // `@openai/codex-sdk/node_modules/.bin/codex`, which in turn launches\n // `@openai/codex/bin/codex.js` and the platform-specific native binary.\n //\n // IMPORTANT: in pnpm workspaces, the path we find here is often a symlink\n // (e.g. `packages/*/node_modules/...`). The shim script uses `$0` to compute\n // relative paths into pnpm's `.pnpm/` store, so we must spawn the *realpath*\n // of the shim or it will look in the wrong place (leading to ENOENT / MODULE_NOT_FOUND).\n\n const candidates =\n process.platform === \"win32\" ? [\"codex.cmd\", \"codex.ps1\", \"codex\"] : [\"codex\"];\n\n const searchPaths = moduleRequire.resolve.paths(\"@openai/codex-sdk\") ?? [];\n for (const basePath of searchPaths) {\n if (!basePath) continue;\n const codexSdkPackageRoot = path.join(basePath, \"@openai\", \"codex-sdk\");\n if (!existsSync(path.join(codexSdkPackageRoot, \"package.json\"))) {\n continue;\n }\n\n for (const binName of candidates) {\n const binPath = path.join(codexSdkPackageRoot, \"node_modules\", \".bin\", binName);\n if (!existsSync(binPath)) continue;\n return realpathSync(binPath);\n }\n }\n\n throw new Error(\n `[Codex SDK] Unable to locate the Codex CLI entrypoint installed by @openai/codex-sdk. ` +\n `Try re-running \\`pnpm install\\` and ensure optional dependencies are enabled.`,\n );\n}\n\nfunction formatConfigValue(value: unknown): string {\n if (typeof value === \"string\") {\n return JSON.stringify(value);\n }\n if (typeof value === \"number\" || typeof value === \"boolean\") {\n return String(value);\n }\n if (value === null || value === undefined) {\n return \"null\";\n }\n try {\n return JSON.stringify(value);\n } catch {\n return JSON.stringify(String(value));\n }\n}\n","import { CodexOptions } from \"./codexOptions\";\nimport { CodexExec } from \"./exec\";\nimport { Thread } from \"./thread\";\nimport { ThreadOptions } from \"./threadOptions\";\n\n/**\n * Codex is the main class for interacting with the Codex agent.\n *\n * Use the `startThread()` method to start a new thread or `resumeThread()` to resume a previously started thread.\n */\nexport class Codex {\n private exec: CodexExec;\n private options: CodexOptions;\n\n constructor(options: CodexOptions = {}) {\n this.exec = new CodexExec(options.codexPathOverride, options.env);\n this.options = options;\n }\n\n /**\n * Starts a new conversation with an agent.\n * @returns A new thread instance.\n */\n startThread(options: ThreadOptions = {}): Thread {\n return new Thread(this.exec, this.options, options);\n }\n\n /**\n * Resumes a conversation with an agent based on the thread id.\n * Threads are persisted in ~/.codex/sessions.\n *\n * @param id The id of the thread to resume.\n * @returns A new thread instance.\n */\n resumeThread(id: string, options: ThreadOptions = {}): Thread {\n return new Thread(this.exec, this.options, options, id);\n }\n}\n"],"mappings":";;;AAAA,SAAS,YAAY,UAAU;AAC/B,OAAO,QAAQ;AACf,OAAO,UAAU;AEFjB,SAAS,aAAa;AACtB,SAAS,YAAY,oBAAoB;AACzC,OAAOA,WAAU;AACjB,OAAO,cAAc;AACrB,SAAS,qBAAqB;AFK9B,eAAsB,uBAAuB,QAA4C;AACvF,MAAI,WAAW,QAAW;AACxB,WAAO,EAAE,SAAS,YAAY;IAAC,EAAE;EACnC;AAEA,MAAI,CAAC,aAAa,MAAM,GAAG;AACzB,UAAM,IAAI,MAAM,0CAA0C;EAC5D;AAEA,QAAM,YAAY,MAAM,GAAG,QAAQ,KAAK,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O,IAAI,UAAU,QAAQ,mBAAmB,QAAQ,GAAG;AAChE,SAAK,UAAU;EACjB;;;;;EAMA,YAAY,UAAyB,CAAC,GAAW;AAC/C,WAAO,IAAI,OAAO,KAAK,MAAM,KAAK,SAAS,OAAO;EACpD;;;;;;;;EASA,aAAa,IAAY,UAAyB,CAAC,GAAW;AAC5D,WAAO,IAAI,OAAO,KAAK,MAAM,KAAK,SAAS,SAAS,EAAE;EACxD;AACF;","names":["path"]}
|
|
1
|
+
{"version":3,"sources":["../../codex-sdk/src/outputSchemaFile.ts","../../codex-sdk/src/thread.ts","../../codex-sdk/src/exec.ts","../../codex-sdk/src/codex.ts"],"sourcesContent":["import { promises as fs } from \"node:fs\";\nimport os from \"node:os\";\nimport path from \"node:path\";\n\nexport type OutputSchemaFile = {\n schemaPath?: string;\n cleanup: () => Promise<void>;\n};\n\nexport async function createOutputSchemaFile(schema: unknown): Promise<OutputSchemaFile> {\n if (schema === undefined) {\n return { cleanup: async () => {} };\n }\n\n if (!isJsonObject(schema)) {\n throw new Error(\"outputSchema must be a plain JSON object\");\n }\n\n const schemaDir = await fs.mkdtemp(path.join(os.tmpdir(), \"codex-output-schema-\"));\n const schemaPath = path.join(schemaDir, \"schema.json\");\n const cleanup = async () => {\n try {\n await fs.rm(schemaDir, { recursive: true, force: true });\n } catch {\n // suppress\n }\n };\n\n try {\n await fs.writeFile(schemaPath, JSON.stringify(schema), \"utf8\");\n return { schemaPath, cleanup };\n } catch (error) {\n await cleanup();\n throw error;\n }\n}\n\nfunction isJsonObject(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n","import { CodexOptions } from \"./codexOptions\";\nimport { ThreadEvent, ThreadError, Usage } from \"./events\";\nimport { CodexExec } from \"./exec\";\nimport { ThreadItem } from \"./items\";\nimport { ThreadOptions } from \"./threadOptions\";\nimport { TurnOptions } from \"./turnOptions\";\nimport { createOutputSchemaFile } from \"./outputSchemaFile\";\n\n/** Completed turn. */\nexport type Turn = {\n items: ThreadItem[];\n finalResponse: string;\n usage: Usage | null;\n};\n\n/** Alias for `Turn` to describe the result of `run()`. */\nexport type RunResult = Turn;\n\n/** The result of the `runStreamed` method. */\nexport type StreamedTurn = {\n events: AsyncGenerator<ThreadEvent>;\n};\n\n/** Alias for `StreamedTurn` to describe the result of `runStreamed()`. */\nexport type RunStreamedResult = StreamedTurn;\n\n/** An input to send to the agent. */\nexport type UserInput =\n | {\n type: \"text\";\n text: string;\n }\n | {\n type: \"local_image\";\n path: string;\n };\n\nexport type Input = string | UserInput[];\n\n/** Respesent a thread of conversation with the agent. One thread can have multiple consecutive turns. */\nexport class Thread {\n private _exec: CodexExec;\n private _options: CodexOptions;\n private _id: string | null;\n private _threadOptions: ThreadOptions;\n private _initialMessagesSent: boolean = false;\n\n /** Returns the ID of the thread. Populated after the first turn starts. */\n public get id(): string | null {\n return this._id;\n }\n\n /* @internal */\n constructor(\n exec: CodexExec,\n options: CodexOptions,\n threadOptions: ThreadOptions,\n id: string | null = null,\n ) {\n this._exec = exec;\n this._options = options;\n this._id = id;\n this._threadOptions = threadOptions;\n // If resuming an existing thread, initial messages have already been sent\n this._initialMessagesSent = id !== null;\n }\n\n /** Provides the input to the agent and streams events as they are produced during the turn. */\n async runStreamed(input: Input, turnOptions: TurnOptions = {}): Promise<StreamedTurn> {\n return { events: this.runStreamedInternal(input, turnOptions) };\n }\n\n private async *runStreamedInternal(\n input: Input,\n turnOptions: TurnOptions = {},\n ): AsyncGenerator<ThreadEvent> {\n const { schemaPath, cleanup } = await createOutputSchemaFile(turnOptions.outputSchema);\n const options = this._threadOptions;\n const { prompt, images } = normalizeInput(input);\n\n // Prepend initial messages on the first turn only\n let finalPrompt = prompt;\n if (!this._initialMessagesSent && options.initialMessages?.length) {\n const formattedMessages = formatInitialMessages(options.initialMessages);\n finalPrompt = formattedMessages + \"\\n\\n\" + prompt;\n this._initialMessagesSent = true;\n }\n\n const generator = this._exec.run({\n input: finalPrompt,\n baseUrl: this._options.baseUrl,\n apiKey: this._options.apiKey,\n threadId: this._id,\n images,\n model: options?.model,\n sandboxMode: options?.sandboxMode,\n workingDirectory: options?.workingDirectory,\n skipGitRepoCheck: options?.skipGitRepoCheck,\n outputSchemaFile: schemaPath,\n modelReasoningEffort: options?.modelReasoningEffort,\n signal: turnOptions.signal,\n networkAccessEnabled: options?.networkAccessEnabled,\n webSearchEnabled: options?.webSearchEnabled,\n approvalPolicy: options?.approvalPolicy,\n additionalDirectories: options?.additionalDirectories,\n configOverrides: options?.configOverrides,\n });\n try {\n for await (const item of generator) {\n let parsed: ThreadEvent;\n try {\n parsed = JSON.parse(item) as ThreadEvent;\n } catch (error) {\n throw new Error(`Failed to parse item: ${item}`, { cause: error });\n }\n if (parsed.type === \"thread.started\") {\n this._id = parsed.thread_id;\n }\n yield parsed;\n }\n } finally {\n await cleanup();\n }\n }\n\n /** Provides the input to the agent and returns the completed turn. */\n async run(input: Input, turnOptions: TurnOptions = {}): Promise<Turn> {\n const generator = this.runStreamedInternal(input, turnOptions);\n const items: ThreadItem[] = [];\n let finalResponse: string = \"\";\n let usage: Usage | null = null;\n let turnFailure: ThreadError | null = null;\n for await (const event of generator) {\n if (event.type === \"item.completed\") {\n if (event.item.type === \"agent_message\") {\n finalResponse = event.item.text;\n }\n items.push(event.item);\n } else if (event.type === \"turn.completed\") {\n usage = event.usage;\n } else if (event.type === \"turn.failed\") {\n turnFailure = event.error;\n break;\n }\n }\n if (turnFailure) {\n throw new Error(turnFailure.message);\n }\n return { items, finalResponse, usage };\n }\n}\n\nfunction normalizeInput(input: Input): { prompt: string; images: string[] } {\n if (typeof input === \"string\") {\n return { prompt: input, images: [] };\n }\n const promptParts: string[] = [];\n const images: string[] = [];\n for (const item of input) {\n if (item.type === \"text\") {\n promptParts.push(item.text);\n } else if (item.type === \"local_image\") {\n images.push(item.path);\n }\n }\n return { prompt: promptParts.join(\"\\n\\n\"), images };\n}\n\nimport type { InitialMessage } from \"./threadOptions\";\n\n/**\n * Format initial messages into a structured prompt section.\n * Each message is wrapped with role markers to preserve semantic meaning.\n */\nfunction formatInitialMessages(messages: InitialMessage[]): string {\n return messages\n .map((msg) => {\n const roleLabel = msg.role.charAt(0).toUpperCase() + msg.role.slice(1);\n return `[${roleLabel}]\\n${msg.content}`;\n })\n .join(\"\\n\\n\");\n}\n","import { spawn } from \"node:child_process\";\nimport { existsSync, realpathSync } from \"node:fs\";\nimport path from \"node:path\";\nimport readline from \"node:readline\";\nimport { createRequire } from \"node:module\";\n\nimport { SandboxMode, ModelReasoningEffort, ApprovalMode } from \"./threadOptions\";\n\nexport type CodexExecArgs = {\n input: string;\n\n baseUrl?: string;\n apiKey?: string;\n threadId?: string | null;\n images?: string[];\n // --model\n model?: string;\n // --sandbox\n sandboxMode?: SandboxMode;\n // --cd\n workingDirectory?: string;\n // --add-dir\n additionalDirectories?: string[];\n // --skip-git-repo-check\n skipGitRepoCheck?: boolean;\n // --output-schema\n outputSchemaFile?: string;\n // --config model_reasoning_effort\n modelReasoningEffort?: ModelReasoningEffort;\n // AbortSignal to cancel the execution\n signal?: AbortSignal;\n // --config sandbox_workspace_write.network_access\n networkAccessEnabled?: boolean;\n // --config features.web_search_request\n webSearchEnabled?: boolean;\n // --config approval_policy\n approvalPolicy?: ApprovalMode;\n // Generic config overrides for `-c key=value`\n configOverrides?: Record<string, unknown>;\n};\n\nconst INTERNAL_ORIGINATOR_ENV = \"CODEX_INTERNAL_ORIGINATOR_OVERRIDE\";\nconst TYPESCRIPT_SDK_ORIGINATOR = \"codex_sdk_ts\";\nconst isDebugEnabled = process.env[\"DEBUG\"] === \"true\";\n\nexport class CodexExec {\n private executablePath: string;\n private envOverride?: Record<string, string>;\n\n constructor(executablePath: string | null = null, env?: Record<string, string>) {\n this.executablePath = executablePath || findCodexPath();\n this.envOverride = env;\n }\n\n async *run(args: CodexExecArgs): AsyncGenerator<string> {\n const commandArgs: string[] = [\"exec\", \"--experimental-json\"];\n\n if (args.model) {\n commandArgs.push(\"--model\", args.model);\n }\n\n if (args.sandboxMode) {\n commandArgs.push(\"--sandbox\", args.sandboxMode);\n }\n\n if (args.workingDirectory) {\n commandArgs.push(\"--cd\", args.workingDirectory);\n }\n\n if (args.additionalDirectories?.length) {\n for (const dir of args.additionalDirectories) {\n commandArgs.push(\"--add-dir\", dir);\n }\n }\n\n if (args.skipGitRepoCheck) {\n commandArgs.push(\"--skip-git-repo-check\");\n }\n\n if (args.outputSchemaFile) {\n commandArgs.push(\"--output-schema\", args.outputSchemaFile);\n }\n\n if (args.modelReasoningEffort) {\n commandArgs.push(\"--config\", `model_reasoning_effort=\"${args.modelReasoningEffort}\"`);\n }\n\n if (args.networkAccessEnabled !== undefined) {\n commandArgs.push(\n \"--config\",\n `sandbox_workspace_write.network_access=${args.networkAccessEnabled}`,\n );\n }\n\n if (args.webSearchEnabled !== undefined) {\n commandArgs.push(\"--config\", `features.web_search_request=${args.webSearchEnabled}`);\n }\n\n if (args.approvalPolicy) {\n commandArgs.push(\"--config\", `approval_policy=\"${args.approvalPolicy}\"`);\n }\n\n if (args.configOverrides) {\n for (const [key, value] of Object.entries(args.configOverrides)) {\n const formatted = formatConfigValue(value);\n commandArgs.push(\"--config\", `${key}=${formatted}`);\n }\n }\n\n if (args.images?.length) {\n for (const image of args.images) {\n commandArgs.push(\"--image\", image);\n }\n }\n\n if (args.threadId) {\n commandArgs.push(\"resume\", args.threadId);\n }\n\n if (isDebugEnabled) {\n console.log(\"[CodexExec] Executable path:\", this.executablePath);\n console.log(\"[CodexExec] Command arguments:\", commandArgs);\n }\n\n const env: Record<string, string> = {};\n if (this.envOverride) {\n Object.assign(env, this.envOverride);\n const hasPathKey = Object.keys(env).some((key) => key.toUpperCase() === \"PATH\");\n if (!hasPathKey) {\n const inheritedPathKey = Object.keys(process.env).find((key) => key.toUpperCase() === \"PATH\");\n if (inheritedPathKey && process.env[inheritedPathKey]) {\n env.PATH = process.env[inheritedPathKey]!;\n }\n }\n } else {\n for (const [key, value] of Object.entries(process.env)) {\n if (value !== undefined) {\n env[key] = value;\n }\n }\n }\n if (!env[INTERNAL_ORIGINATOR_ENV]) {\n env[INTERNAL_ORIGINATOR_ENV] = TYPESCRIPT_SDK_ORIGINATOR;\n }\n if (args.baseUrl) {\n env.OPENAI_BASE_URL = args.baseUrl;\n }\n if (args.apiKey) {\n env.CODEX_API_KEY = args.apiKey;\n }\n\n const child = spawn(this.executablePath, commandArgs, {\n env,\n signal: args.signal,\n });\n\n let spawnError: unknown | null = null;\n child.once(\"error\", (err) => (spawnError = err));\n\n if (!child.stdin) {\n child.kill();\n throw new Error(\"Child process has no stdin\");\n }\n child.stdin.write(args.input);\n child.stdin.end();\n\n if (!child.stdout) {\n child.kill();\n throw new Error(\"Child process has no stdout\");\n }\n const stderrChunks: Buffer[] = [];\n\n if (child.stderr) {\n child.stderr.on(\"data\", (data) => {\n stderrChunks.push(data);\n });\n }\n\n const rl = readline.createInterface({\n input: child.stdout,\n crlfDelay: Infinity,\n });\n\n try {\n for await (const line of rl) {\n // `line` is a string (Node sets default encoding to utf8 for readline)\n yield line as string;\n }\n\n const exitCode = new Promise((resolve, reject) => {\n child.once(\"exit\", (code) => {\n if (code === 0) {\n resolve(code);\n } else {\n const stderrBuffer = Buffer.concat(stderrChunks);\n reject(\n new Error(`Codex Exec exited with code ${code}: ${stderrBuffer.toString(\"utf8\")}`),\n );\n }\n });\n });\n\n if (spawnError) throw spawnError;\n await exitCode;\n } finally {\n rl.close();\n child.removeAllListeners();\n try {\n if (!child.killed) child.kill();\n } catch {\n // ignore\n }\n }\n }\n}\n\nconst moduleRequire = createRequire(import.meta.url);\n\nfunction findCodexPath() {\n // `@openai/codex-sdk` provides a `codex` executable shim under\n // `@openai/codex-sdk/node_modules/.bin/codex`, which in turn launches\n // `@openai/codex/bin/codex.js` and the platform-specific native binary.\n //\n // IMPORTANT: in pnpm workspaces, the path we find here is often a symlink\n // (e.g. `packages/*/node_modules/...`). The shim script uses `$0` to compute\n // relative paths into pnpm's `.pnpm/` store, so we must spawn the *realpath*\n // of the shim or it will look in the wrong place (leading to ENOENT / MODULE_NOT_FOUND).\n\n const candidates =\n process.platform === \"win32\" ? [\"codex.cmd\", \"codex.ps1\", \"codex\"] : [\"codex\"];\n\n const searchPaths = moduleRequire.resolve.paths(\"@openai/codex-sdk\") ?? [];\n for (const basePath of searchPaths) {\n if (!basePath) continue;\n const codexSdkPackageRoot = path.join(basePath, \"@openai\", \"codex-sdk\");\n if (!existsSync(path.join(codexSdkPackageRoot, \"package.json\"))) {\n continue;\n }\n\n for (const binName of candidates) {\n const binPath = path.join(codexSdkPackageRoot, \"node_modules\", \".bin\", binName);\n if (!existsSync(binPath)) continue;\n return realpathSync(binPath);\n }\n }\n\n throw new Error(\n `[Codex SDK] Unable to locate the Codex CLI entrypoint installed by @openai/codex-sdk. ` +\n `Try re-running \\`pnpm install\\` and ensure optional dependencies are enabled.`,\n );\n}\n\nfunction formatConfigValue(value: unknown): string {\n if (typeof value === \"string\") {\n return JSON.stringify(value);\n }\n if (typeof value === \"number\" || typeof value === \"boolean\") {\n return String(value);\n }\n if (value === null || value === undefined) {\n return \"null\";\n }\n try {\n return JSON.stringify(value);\n } catch {\n return JSON.stringify(String(value));\n }\n}\n","import { CodexOptions } from \"./codexOptions\";\nimport { CodexExec } from \"./exec\";\nimport { Thread } from \"./thread\";\nimport { ThreadOptions } from \"./threadOptions\";\n\n/**\n * Codex is the main class for interacting with the Codex agent.\n *\n * Use the `startThread()` method to start a new thread or `resumeThread()` to resume a previously started thread.\n */\nexport class Codex {\n private exec: CodexExec;\n private options: CodexOptions;\n\n constructor(options: CodexOptions = {}) {\n this.exec = new CodexExec(options.codexPathOverride, options.env);\n this.options = options;\n }\n\n /**\n * Starts a new conversation with an agent.\n * @returns A new thread instance.\n */\n startThread(options: ThreadOptions = {}): Thread {\n return new Thread(this.exec, this.options, options);\n }\n\n /**\n * Resumes a conversation with an agent based on the thread id.\n * Threads are persisted in ~/.codex/sessions.\n *\n * @param id The id of the thread to resume.\n * @returns A new thread instance.\n */\n resumeThread(id: string, options: ThreadOptions = {}): Thread {\n return new Thread(this.exec, this.options, options, id);\n }\n}\n"],"mappings":";;;;AAAA,SAAS,YAAY,UAAU;AAC/B,OAAO,QAAQ;AACf,OAAO,UAAU;AEFjB,SAAS,aAAa;AACtB,SAAS,YAAY,oBAAoB;AACzC,OAAOA,WAAU;AACjB,OAAO,cAAc;AACrB,SAAS,qBAAqB;AFK9B,eAAsB,uBAAuB,QAA4C;AACvF,MAAI,WAAW,QAAW;AACxB,WAAO,EAAE,SAAS,YAAY;IAAC,EAAE;EACnC;AAEA,MAAI,CAAC,aAAa,MAAM,GAAG;AACzB,UAAM,IAAI,MAAM,0CAA0C;EAC5D;AAEA,QAAM,YAAY,MAAM,GAAG,QAAQ,KAAK,KAAK,GAAG,OAAO,GAAG,sBAAsB,CAAC;AACjF,QAAM,aAAa,KAAK,KAAK,WAAW,aAAa;AACrD,QAAM,UAAU,YAAY;AAC1B,QAAI;AACF,YAAM,GAAG,GAAG,WAAW,EAAE,WAAW,MAAM,OAAO,KAAK,CAAC;IACzD,QAAQ;IAER;EACF;AAEA,MAAI;AACF,UAAM,GAAG,UAAU,YAAY,KAAK,UAAU,MAAM,GAAG,MAAM;AAC7D,WAAO,EAAE,YAAY,QAAQ;EAC/B,SAAS,OAAO;AACd,UAAM,QAAQ;AACd,UAAM;EACR;AACF;AAEA,SAAS,aAAa,OAAkD;AACtE,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;ACCO,IAAM,SAAN,MAAa;EACV;EACA;EACA;EACA;EACA,uBAAgC;;EAGxC,IAAW,KAAoB;AAC7B,WAAO,KAAK;EACd;;EAGA,YACE,MACA,SACA,eACA,KAAoB,MACpB;AACA,SAAK,QAAQ;AACb,SAAK,WAAW;AAChB,SAAK,MAAM;AACX,SAAK,iBAAiB;AAEtB,SAAK,uBAAuB,OAAO;EACrC;;EAGA,MAAM,YAAY,OAAc,cAA2B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AAC1B,aAAO,aAAa,OAAO;IAC7B;EACF;AAEA,QAAM,IAAI;IACR;EAEF;AACF;AAEA,SAAS,kBAAkB,OAAwB;AACjD,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO,KAAK,UAAU,KAAK;EAC7B;AACA,MAAI,OAAO,UAAU,YAAY,OAAO,UAAU,WAAW;AAC3D,WAAO,OAAO,KAAK;EACrB;AACA,MAAI,UAAU,QAAQ,UAAU,QAAW;AACzC,WAAO;EACT;AACA,MAAI;AACF,WAAO,KAAK,UAAU,KAAK;EAC7B,QAAQ;AACN,WAAO,KAAK,UAAU,OAAO,KAAK,CAAC;EACrC;AACF;ACjQO,IAAM,QAAN,MAAY;EACT;EACA;EAER,YAAY,UAAwB,CAAC,GAAG;AACtC,SAAK,OAAO,IAAI,UAAU,QAAQ,mBAAmB,QAAQ,GAAG;AAChE,SAAK,UAAU;EACjB;;;;;EAMA,YAAY,UAAyB,CAAC,GAAW;AAC/C,WAAO,IAAI,OAAO,KAAK,MAAM,KAAK,SAAS,OAAO;EACpD;;;;;;;;EASA,aAAa,IAAY,UAAyB,CAAC,GAAW;AAC5D,WAAO,IAAI,OAAO,KAAK,MAAM,KAAK,SAAS,SAAS,EAAE;EACxD;AACF;","names":["path"]}
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { createRequire as __createRequire } from 'module'; const require = __createRequire(import.meta.url);
|
|
1
2
|
import {
|
|
2
3
|
query,
|
|
3
4
|
sanitizeImageId
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-
|
|
5
|
+
} from "./chunk-B47WUOBY.js";
|
|
6
|
+
import "./chunk-54HOGCFN.js";
|
|
6
7
|
|
|
7
8
|
// src/utils/logger.ts
|
|
8
9
|
import winston from "winston";
|
|
@@ -3322,7 +3323,7 @@ function buildSystemPromptWithNorthflare(basePrompt, northflarePrompt) {
|
|
|
3322
3323
|
var codexSdkPromise = null;
|
|
3323
3324
|
async function loadCodexSdk() {
|
|
3324
3325
|
if (!codexSdkPromise) {
|
|
3325
|
-
codexSdkPromise = import("./dist-
|
|
3326
|
+
codexSdkPromise = import("./dist-4E3H46W5.js");
|
|
3326
3327
|
}
|
|
3327
3328
|
return codexSdkPromise;
|
|
3328
3329
|
}
|
|
@@ -8297,7 +8298,13 @@ import { spawn } from "child_process";
|
|
|
8297
8298
|
// src/utils/version.ts
|
|
8298
8299
|
import { createRequire } from "module";
|
|
8299
8300
|
var require2 = createRequire(import.meta.url);
|
|
8300
|
-
var pkg =
|
|
8301
|
+
var pkg = (() => {
|
|
8302
|
+
try {
|
|
8303
|
+
return require2("../package.json");
|
|
8304
|
+
} catch {
|
|
8305
|
+
return require2("../../package.json");
|
|
8306
|
+
}
|
|
8307
|
+
})();
|
|
8301
8308
|
var RUNNER_VERSION = pkg.version;
|
|
8302
8309
|
function isNewerVersion(serverVersion, currentVersion) {
|
|
8303
8310
|
const parse = (v) => {
|