@northflare/runner 0.0.33 → 0.0.34

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.
@@ -155,13 +155,44 @@ ${msg.content}`;
155
155
  }
156
156
  var INTERNAL_ORIGINATOR_ENV = "CODEX_INTERNAL_ORIGINATOR_OVERRIDE";
157
157
  var TYPESCRIPT_SDK_ORIGINATOR = "codex_sdk_ts";
158
- var isDebugEnabled = process.env["DEBUG"] === "true";
158
+ function isCodexDebugEnabled() {
159
+ const runnerDebug = process.env["NORTHFLARE_RUNNER_DEBUG"];
160
+ if (runnerDebug && runnerDebug.trim().length > 0) {
161
+ return true;
162
+ }
163
+ const debug = process.env["DEBUG"];
164
+ if (!debug) return false;
165
+ const normalized = debug.toLowerCase();
166
+ if (normalized === "true" || normalized === "1" || normalized === "*") {
167
+ return true;
168
+ }
169
+ return normalized.split(",").map((entry) => entry.trim()).some((entry) => entry === "*" || entry.includes("codex"));
170
+ }
159
171
  var CodexExec = class {
160
172
  executablePath;
173
+ executablePrefixArgs;
174
+ codexRuntimePath;
161
175
  envOverride;
162
176
  constructor(executablePath = null, env) {
163
- this.executablePath = executablePath || findCodexPath();
177
+ if (executablePath) {
178
+ this.executablePath = executablePath;
179
+ this.executablePrefixArgs = [];
180
+ this.codexRuntimePath = executablePath;
181
+ } else {
182
+ const resolved = findCodexPath();
183
+ this.executablePath = resolved.path;
184
+ this.executablePrefixArgs = resolved.prefixArgs;
185
+ this.codexRuntimePath = resolved.runtimePath;
186
+ }
164
187
  this.envOverride = env;
188
+ if (isCodexDebugEnabled()) {
189
+ console.log("[CodexExec] Initialized with Codex runtime path:", this.codexRuntimePath);
190
+ console.log("[CodexExec] Initialized executable path:", this.executablePath);
191
+ console.log(
192
+ "[CodexExec] Initialized executable prefix args:",
193
+ this.executablePrefixArgs
194
+ );
195
+ }
165
196
  }
166
197
  async *run(args) {
167
198
  const commandArgs = ["exec", "--experimental-json"];
@@ -214,8 +245,10 @@ var CodexExec = class {
214
245
  if (args.threadId) {
215
246
  commandArgs.push("resume", args.threadId);
216
247
  }
217
- if (isDebugEnabled) {
248
+ if (isCodexDebugEnabled()) {
249
+ console.log("[CodexExec] Codex runtime path:", this.codexRuntimePath);
218
250
  console.log("[CodexExec] Executable path:", this.executablePath);
251
+ console.log("[CodexExec] Executable prefix args:", this.executablePrefixArgs);
219
252
  console.log("[CodexExec] Command arguments:", commandArgs);
220
253
  }
221
254
  const env = {};
@@ -244,10 +277,14 @@ var CodexExec = class {
244
277
  if (args.apiKey) {
245
278
  env.CODEX_API_KEY = args.apiKey;
246
279
  }
247
- const child = spawn(this.executablePath, commandArgs, {
248
- env,
249
- signal: args.signal
250
- });
280
+ const child = spawn(
281
+ this.executablePath,
282
+ [...this.executablePrefixArgs, ...commandArgs],
283
+ {
284
+ env,
285
+ signal: args.signal
286
+ }
287
+ );
251
288
  let spawnError = null;
252
289
  child.once("error", (err) => spawnError = err);
253
290
  if (!child.stdin) {
@@ -300,7 +337,19 @@ var CodexExec = class {
300
337
  };
301
338
  var moduleRequire = createRequire(import.meta.url);
302
339
  function findCodexPath() {
303
- const candidates = process.platform === "win32" ? ["codex.cmd", "codex.ps1", "codex"] : ["codex"];
340
+ const directCodexSearchPaths = moduleRequire.resolve.paths("@openai/codex") ?? [];
341
+ for (const basePath of directCodexSearchPaths) {
342
+ if (!basePath) continue;
343
+ const entrypoint = path2.join(basePath, "@openai", "codex", "bin", "codex.js");
344
+ if (!existsSync(entrypoint)) continue;
345
+ const resolvedEntrypoint = realpathSync(entrypoint);
346
+ return {
347
+ path: process.execPath,
348
+ prefixArgs: [resolvedEntrypoint],
349
+ runtimePath: resolvedEntrypoint
350
+ };
351
+ }
352
+ const shimCandidates = process.platform === "win32" ? ["codex.cmd", "codex.ps1", "codex"] : ["codex"];
304
353
  const searchPaths = moduleRequire.resolve.paths("@openai/codex-sdk") ?? [];
305
354
  for (const basePath of searchPaths) {
306
355
  if (!basePath) continue;
@@ -308,14 +357,38 @@ function findCodexPath() {
308
357
  if (!existsSync(path2.join(codexSdkPackageRoot, "package.json"))) {
309
358
  continue;
310
359
  }
311
- for (const binName of candidates) {
312
- const binPath = path2.join(codexSdkPackageRoot, "node_modules", ".bin", binName);
313
- if (!existsSync(binPath)) continue;
314
- return realpathSync(binPath);
360
+ const shimRoots = [
361
+ path2.join(codexSdkPackageRoot, "node_modules", ".bin"),
362
+ path2.join(basePath, ".bin")
363
+ ];
364
+ for (const shimRoot of shimRoots) {
365
+ for (const binName of shimCandidates) {
366
+ const binPath = path2.join(shimRoot, binName);
367
+ if (!existsSync(binPath)) continue;
368
+ const resolvedBinPath = realpathSync(binPath);
369
+ return {
370
+ path: resolvedBinPath,
371
+ prefixArgs: [],
372
+ runtimePath: resolvedBinPath
373
+ };
374
+ }
375
+ }
376
+ const jsEntrypoints = [
377
+ path2.join(codexSdkPackageRoot, "node_modules", "@openai", "codex", "bin", "codex.js"),
378
+ path2.join(basePath, "@openai", "codex", "bin", "codex.js")
379
+ ];
380
+ for (const entrypoint of jsEntrypoints) {
381
+ if (!existsSync(entrypoint)) continue;
382
+ const resolvedEntrypoint = realpathSync(entrypoint);
383
+ return {
384
+ path: process.execPath,
385
+ prefixArgs: [resolvedEntrypoint],
386
+ runtimePath: resolvedEntrypoint
387
+ };
315
388
  }
316
389
  }
317
390
  throw new Error(
318
- `[Codex SDK] Unable to locate the Codex CLI entrypoint installed by @openai/codex-sdk. Try re-running \`pnpm install\` and ensure optional dependencies are enabled.`
391
+ `[Codex SDK] Unable to locate the Codex CLI entrypoint from @openai/codex/@openai/codex-sdk. Try re-running \`npm install\` (or \`pnpm install\`) and ensure optional dependencies are enabled.`
319
392
  );
320
393
  }
321
394
  function formatConfigValue(value) {
@@ -363,4 +436,4 @@ export {
363
436
  Codex,
364
437
  Thread
365
438
  };
366
- //# sourceMappingURL=dist-4E3H46W5.js.map
439
+ //# sourceMappingURL=dist-GBG24TS5.js.map
@@ -0,0 +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\";\n\nfunction isCodexDebugEnabled(): boolean {\n const runnerDebug = process.env[\"NORTHFLARE_RUNNER_DEBUG\"];\n if (runnerDebug && runnerDebug.trim().length > 0) {\n return true;\n }\n\n const debug = process.env[\"DEBUG\"];\n if (!debug) return false;\n\n const normalized = debug.toLowerCase();\n if (normalized === \"true\" || normalized === \"1\" || normalized === \"*\") {\n return true;\n }\n\n return normalized\n .split(\",\")\n .map((entry) => entry.trim())\n .some((entry) => entry === \"*\" || entry.includes(\"codex\"));\n}\n\ntype ResolvedCodexExecutable = {\n path: string;\n prefixArgs: string[];\n runtimePath: string;\n};\n\nexport class CodexExec {\n private executablePath: string;\n private executablePrefixArgs: string[];\n private codexRuntimePath: string;\n private envOverride?: Record<string, string>;\n\n constructor(executablePath: string | null = null, env?: Record<string, string>) {\n if (executablePath) {\n this.executablePath = executablePath;\n this.executablePrefixArgs = [];\n this.codexRuntimePath = executablePath;\n } else {\n const resolved = findCodexPath();\n this.executablePath = resolved.path;\n this.executablePrefixArgs = resolved.prefixArgs;\n this.codexRuntimePath = resolved.runtimePath;\n }\n this.envOverride = env;\n\n if (isCodexDebugEnabled()) {\n console.log(\"[CodexExec] Initialized with Codex runtime path:\", this.codexRuntimePath);\n console.log(\"[CodexExec] Initialized executable path:\", this.executablePath);\n console.log(\n \"[CodexExec] Initialized executable prefix args:\",\n this.executablePrefixArgs\n );\n }\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 (isCodexDebugEnabled()) {\n console.log(\"[CodexExec] Codex runtime path:\", this.codexRuntimePath);\n console.log(\"[CodexExec] Executable path:\", this.executablePath);\n console.log(\"[CodexExec] Executable prefix args:\", this.executablePrefixArgs);\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(\n this.executablePath,\n [...this.executablePrefixArgs, ...commandArgs],\n {\n env,\n signal: args.signal,\n }\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(): ResolvedCodexExecutable {\n // Prefer a single canonical runtime source:\n // - @openai/codex/bin/codex.js (invoked with node)\n const directCodexSearchPaths = moduleRequire.resolve.paths(\"@openai/codex\") ?? [];\n for (const basePath of directCodexSearchPaths) {\n if (!basePath) continue;\n const entrypoint = path.join(basePath, \"@openai\", \"codex\", \"bin\", \"codex.js\");\n if (!existsSync(entrypoint)) continue;\n const resolvedEntrypoint = realpathSync(entrypoint);\n return {\n path: process.execPath,\n prefixArgs: [resolvedEntrypoint],\n runtimePath: resolvedEntrypoint,\n };\n }\n\n // Compatibility fallback for mixed npm/pnpm layouts:\n // - pnpm nested shim: @openai/codex-sdk/node_modules/.bin/codex\n // - npm/hoisted shim: <node_modules>/.bin/codex\n // - direct JS entry: @openai/codex/bin/codex.js (invoked with node)\n //\n // We always realpath shims so wrapper-relative paths work correctly.\n const shimCandidates =\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 const shimRoots = [\n path.join(codexSdkPackageRoot, \"node_modules\", \".bin\"),\n path.join(basePath, \".bin\"),\n ];\n\n for (const shimRoot of shimRoots) {\n for (const binName of shimCandidates) {\n const binPath = path.join(shimRoot, binName);\n if (!existsSync(binPath)) continue;\n const resolvedBinPath = realpathSync(binPath);\n return {\n path: resolvedBinPath,\n prefixArgs: [],\n runtimePath: resolvedBinPath,\n };\n }\n }\n\n const jsEntrypoints = [\n path.join(codexSdkPackageRoot, \"node_modules\", \"@openai\", \"codex\", \"bin\", \"codex.js\"),\n path.join(basePath, \"@openai\", \"codex\", \"bin\", \"codex.js\"),\n ];\n\n for (const entrypoint of jsEntrypoints) {\n if (!existsSync(entrypoint)) continue;\n const resolvedEntrypoint = realpathSync(entrypoint);\n return {\n path: process.execPath,\n prefixArgs: [resolvedEntrypoint],\n runtimePath: resolvedEntrypoint,\n };\n }\n }\n\n throw new Error(\n `[Codex SDK] Unable to locate the Codex CLI entrypoint from @openai/codex/@openai/codex-sdk. ` +\n `Try re-running \\`npm install\\` (or \\`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 = {}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B,cAAM,kBAAkB,aAAa,OAAO;AAC5C,eAAO;UACL,MAAM;UACN,YAAY,CAAC;UACb,aAAa;QACf;MACF;IACF;AAEA,UAAM,gBAAgB;MACpBA,MAAK,KAAK,qBAAqB,gBAAgB,WAAW,SAAS,OAAO,UAAU;MACpFA,MAAK,KAAK,UAAU,WAAW,SAAS,OAAO,UAAU;IAC3D;AAEA,eAAW,cAAc,eAAe;AACtC,UAAI,CAAC,WAAW,UAAU,EAAG;AAC7B,YAAM,qBAAqB,aAAa,UAAU;AAClD,aAAO;QACL,MAAM,QAAQ;QACd,YAAY,CAAC,kBAAkB;QAC/B,aAAa;MACf;IACF;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;AC3VO,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
@@ -3323,7 +3323,7 @@ function buildSystemPromptWithNorthflare(basePrompt, northflarePrompt) {
3323
3323
  var codexSdkPromise = null;
3324
3324
  async function loadCodexSdk() {
3325
3325
  if (!codexSdkPromise) {
3326
- codexSdkPromise = import("./dist-4E3H46W5.js");
3326
+ codexSdkPromise = import("./dist-GBG24TS5.js");
3327
3327
  }
3328
3328
  return codexSdkPromise;
3329
3329
  }
@@ -6346,10 +6346,53 @@ Please resolve the conflicts in that directory and complete the in-progress git
6346
6346
  }
6347
6347
  case "result": {
6348
6348
  const resultMsg = message;
6349
- structuredContent = {
6350
- text: resultMsg.content || resultMsg.result || "",
6351
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
6352
- };
6349
+ const resultIsError = resultMsg.is_error === true;
6350
+ const resultSubtype = resultMsg.subtype || "success";
6351
+ const errorMessage = resultMsg.error_message || resultMsg.result || "";
6352
+ if (resultIsError) {
6353
+ context.metadata = context.metadata || {};
6354
+ context.metadata["_sdkError"] = {
6355
+ isError: true,
6356
+ errorMessage,
6357
+ subtype: resultSubtype
6358
+ };
6359
+ console4.log(
6360
+ "[NorthflareAgentManager] SDK result message indicates error",
6361
+ {
6362
+ conversationId: context.conversationId,
6363
+ subtype: resultSubtype,
6364
+ errorMessage: errorMessage?.slice?.(0, 200)
6365
+ }
6366
+ );
6367
+ messageType = "system";
6368
+ subtype = "error";
6369
+ isError = true;
6370
+ structuredContent = {
6371
+ text: errorMessage || "SDK execution error",
6372
+ errorType: resultSubtype,
6373
+ errorDetails: {
6374
+ sdk_subtype: resultSubtype,
6375
+ duration_ms: resultMsg.duration_ms,
6376
+ num_turns: resultMsg.num_turns
6377
+ },
6378
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
6379
+ };
6380
+ } else if (typeof resultMsg.content === "string" || typeof resultMsg.result === "string") {
6381
+ structuredContent = {
6382
+ text: resultMsg.content || resultMsg.result || "",
6383
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
6384
+ };
6385
+ } else {
6386
+ console4.log(
6387
+ "[NorthflareAgentManager] SDK result message (success)",
6388
+ {
6389
+ conversationId: context.conversationId,
6390
+ subtype: resultSubtype,
6391
+ resultPreview: (resultMsg.result || "").slice?.(0, 100)
6392
+ }
6393
+ );
6394
+ skipSend = true;
6395
+ }
6353
6396
  break;
6354
6397
  }
6355
6398
  case "user": {
@@ -6473,52 +6516,6 @@ Please resolve the conflicts in that directory and complete the in-progress git
6473
6516
  };
6474
6517
  break;
6475
6518
  }
6476
- case "result": {
6477
- const resultMsg = message;
6478
- const resultIsError = resultMsg.is_error === true;
6479
- const resultSubtype = resultMsg.subtype || "success";
6480
- const errorMessage = resultMsg.error_message || resultMsg.result || "";
6481
- if (resultIsError) {
6482
- context.metadata = context.metadata || {};
6483
- context.metadata["_sdkError"] = {
6484
- isError: true,
6485
- errorMessage,
6486
- subtype: resultSubtype
6487
- };
6488
- console4.log(
6489
- "[NorthflareAgentManager] SDK result message indicates error",
6490
- {
6491
- conversationId: context.conversationId,
6492
- subtype: resultSubtype,
6493
- errorMessage: errorMessage?.slice?.(0, 200)
6494
- }
6495
- );
6496
- messageType = "system";
6497
- subtype = "error";
6498
- isError = true;
6499
- structuredContent = {
6500
- text: errorMessage || "SDK execution error",
6501
- errorType: resultSubtype,
6502
- errorDetails: {
6503
- sdk_subtype: resultSubtype,
6504
- duration_ms: resultMsg.duration_ms,
6505
- num_turns: resultMsg.num_turns
6506
- },
6507
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
6508
- };
6509
- } else {
6510
- console4.log(
6511
- "[NorthflareAgentManager] SDK result message (success)",
6512
- {
6513
- conversationId: context.conversationId,
6514
- subtype: resultSubtype,
6515
- resultPreview: (resultMsg.result || "").slice?.(0, 100)
6516
- }
6517
- );
6518
- skipSend = true;
6519
- }
6520
- break;
6521
- }
6522
6519
  default: {
6523
6520
  const unknownMsg = message;
6524
6521
  console4.warn(`Unknown message type: ${unknownMsg.type}`, message);