@codex-native/sdk 0.0.24 → 0.0.25

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/index.d.mts CHANGED
@@ -1190,7 +1190,7 @@ type ToolExecutorResult = string | NativeToolResult | {
1190
1190
  output?: string;
1191
1191
  error?: string;
1192
1192
  success?: boolean;
1193
- } | void;
1193
+ } | Record<string, unknown> | unknown[] | number | boolean | null | void;
1194
1194
  type ToolExecutor = (context: ToolExecutionContext) => Promise<ToolExecutorResult> | ToolExecutorResult;
1195
1195
  declare function registerCodexToolExecutor(name: string, executor: ToolExecutor): void;
1196
1196
  declare function getCodexToolExecutor(name: string): ToolExecutor | undefined;
package/dist/index.d.ts CHANGED
@@ -1190,7 +1190,7 @@ type ToolExecutorResult = string | NativeToolResult | {
1190
1190
  output?: string;
1191
1191
  error?: string;
1192
1192
  success?: boolean;
1193
- } | void;
1193
+ } | Record<string, unknown> | unknown[] | number | boolean | null | void;
1194
1194
  type ToolExecutor = (context: ToolExecutionContext) => Promise<ToolExecutorResult> | ToolExecutorResult;
1195
1195
  declare function registerCodexToolExecutor(name: string, executor: ToolExecutor): void;
1196
1196
  declare function getCodexToolExecutor(name: string): ToolExecutor | undefined;
package/dist/index.mjs CHANGED
@@ -264,10 +264,21 @@ var CodexModel = class {
264
264
  };
265
265
  this.codex.registerTool(nativeToolDef);
266
266
  this.registeredTools.add(tool2.name);
267
- console.log(`Registered tool with Codex: ${tool2.name}`);
267
+ const DEBUG = process.env.DEBUG === "1" || process.env.DEBUG === "true";
268
+ if (DEBUG) {
269
+ try {
270
+ process.stderr.write(`[codex-native] Registered tool with Codex: ${tool2.name}
271
+ `);
272
+ } catch {
273
+ }
274
+ }
268
275
  } catch (error) {
269
276
  const errorMessage = `Failed to register tool ${tool2.name}: ${error instanceof Error ? error.message : String(error)}`;
270
- console.error(errorMessage);
277
+ try {
278
+ process.stderr.write(`[codex-native] ${errorMessage}
279
+ `);
280
+ } catch {
281
+ }
271
282
  }
272
283
  }
273
284
  }
@@ -292,11 +303,21 @@ var CodexModel = class {
292
303
  * but the framework integration is not yet complete.
293
304
  */
294
305
  async executeToolViaFramework(invocation) {
295
- console.log("[DEBUG executeToolViaFramework] invocation:", JSON.stringify(invocation, null, 2));
296
- console.log("[DEBUG executeToolViaFramework] invocation type:", typeof invocation);
297
- console.log("[DEBUG executeToolViaFramework] invocation keys:", invocation ? Object.keys(invocation) : "null/undefined");
306
+ const DEBUG = process.env.DEBUG === "1" || process.env.DEBUG === "true";
307
+ if (DEBUG) {
308
+ try {
309
+ process.stderr.write(
310
+ `[codex-native] executeToolViaFramework invocation: ${JSON.stringify(invocation)}
311
+ `
312
+ );
313
+ } catch {
314
+ }
315
+ }
298
316
  if (!invocation) {
299
- console.warn("Codex requested a tool execution without invocation data.");
317
+ try {
318
+ process.stderr.write("[codex-native] Codex requested a tool execution without invocation data.\n");
319
+ } catch {
320
+ }
300
321
  return {
301
322
  output: JSON.stringify({
302
323
  message: "Tool invocation payload missing",
@@ -306,13 +327,23 @@ var CodexModel = class {
306
327
  error: "Missing tool invocation data from Codex"
307
328
  };
308
329
  }
309
- console.log(
310
- `Tool execution requested by Codex: ${invocation.toolName} (callId: ${invocation.callId})`
311
- );
330
+ if (DEBUG) {
331
+ try {
332
+ process.stderr.write(
333
+ `[codex-native] Tool execution requested: ${invocation.toolName} (callId: ${invocation.callId})
334
+ `
335
+ );
336
+ } catch {
337
+ }
338
+ }
312
339
  const executor = this.toolExecutors.get(invocation.toolName) ?? getCodexToolExecutor(invocation.toolName);
313
340
  if (!executor) {
314
341
  const message = `No Codex executor registered for tool '${invocation.toolName}'. Use codexTool() or provide a codexExecute handler.`;
315
- console.warn(message);
342
+ try {
343
+ process.stderr.write(`[codex-native] ${message}
344
+ `);
345
+ } catch {
346
+ }
316
347
  return {
317
348
  success: false,
318
349
  error: message,
@@ -357,7 +388,15 @@ var CodexModel = class {
357
388
  if (typeof result === "string") {
358
389
  return { success: true, output: result };
359
390
  }
360
- if (typeof result === "object" && ("output" in result || "error" in result || "success" in result)) {
391
+ const isNativeToolResultLike = (value) => {
392
+ if (!value || typeof value !== "object") return false;
393
+ if (!("output" in value) && !("error" in value) && !("success" in value)) return false;
394
+ if ("success" in value && value.success != null && typeof value.success !== "boolean") return false;
395
+ if ("output" in value && value.output != null && typeof value.output !== "string") return false;
396
+ if ("error" in value && value.error != null && typeof value.error !== "string") return false;
397
+ return true;
398
+ };
399
+ if (isNativeToolResultLike(result)) {
361
400
  return {
362
401
  success: result.success ?? !result.error,
363
402
  output: result.output,