@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.cjs CHANGED
@@ -2606,10 +2606,21 @@ var CodexModel = class {
2606
2606
  };
2607
2607
  this.codex.registerTool(nativeToolDef);
2608
2608
  this.registeredTools.add(tool2.name);
2609
- console.log(`Registered tool with Codex: ${tool2.name}`);
2609
+ const DEBUG = process.env.DEBUG === "1" || process.env.DEBUG === "true";
2610
+ if (DEBUG) {
2611
+ try {
2612
+ process.stderr.write(`[codex-native] Registered tool with Codex: ${tool2.name}
2613
+ `);
2614
+ } catch {
2615
+ }
2616
+ }
2610
2617
  } catch (error) {
2611
2618
  const errorMessage = `Failed to register tool ${tool2.name}: ${error instanceof Error ? error.message : String(error)}`;
2612
- console.error(errorMessage);
2619
+ try {
2620
+ process.stderr.write(`[codex-native] ${errorMessage}
2621
+ `);
2622
+ } catch {
2623
+ }
2613
2624
  }
2614
2625
  }
2615
2626
  }
@@ -2634,11 +2645,21 @@ var CodexModel = class {
2634
2645
  * but the framework integration is not yet complete.
2635
2646
  */
2636
2647
  async executeToolViaFramework(invocation) {
2637
- console.log("[DEBUG executeToolViaFramework] invocation:", JSON.stringify(invocation, null, 2));
2638
- console.log("[DEBUG executeToolViaFramework] invocation type:", typeof invocation);
2639
- console.log("[DEBUG executeToolViaFramework] invocation keys:", invocation ? Object.keys(invocation) : "null/undefined");
2648
+ const DEBUG = process.env.DEBUG === "1" || process.env.DEBUG === "true";
2649
+ if (DEBUG) {
2650
+ try {
2651
+ process.stderr.write(
2652
+ `[codex-native] executeToolViaFramework invocation: ${JSON.stringify(invocation)}
2653
+ `
2654
+ );
2655
+ } catch {
2656
+ }
2657
+ }
2640
2658
  if (!invocation) {
2641
- console.warn("Codex requested a tool execution without invocation data.");
2659
+ try {
2660
+ process.stderr.write("[codex-native] Codex requested a tool execution without invocation data.\n");
2661
+ } catch {
2662
+ }
2642
2663
  return {
2643
2664
  output: JSON.stringify({
2644
2665
  message: "Tool invocation payload missing",
@@ -2648,13 +2669,23 @@ var CodexModel = class {
2648
2669
  error: "Missing tool invocation data from Codex"
2649
2670
  };
2650
2671
  }
2651
- console.log(
2652
- `Tool execution requested by Codex: ${invocation.toolName} (callId: ${invocation.callId})`
2653
- );
2672
+ if (DEBUG) {
2673
+ try {
2674
+ process.stderr.write(
2675
+ `[codex-native] Tool execution requested: ${invocation.toolName} (callId: ${invocation.callId})
2676
+ `
2677
+ );
2678
+ } catch {
2679
+ }
2680
+ }
2654
2681
  const executor = this.toolExecutors.get(invocation.toolName) ?? getCodexToolExecutor(invocation.toolName);
2655
2682
  if (!executor) {
2656
2683
  const message = `No Codex executor registered for tool '${invocation.toolName}'. Use codexTool() or provide a codexExecute handler.`;
2657
- console.warn(message);
2684
+ try {
2685
+ process.stderr.write(`[codex-native] ${message}
2686
+ `);
2687
+ } catch {
2688
+ }
2658
2689
  return {
2659
2690
  success: false,
2660
2691
  error: message,
@@ -2699,7 +2730,15 @@ var CodexModel = class {
2699
2730
  if (typeof result === "string") {
2700
2731
  return { success: true, output: result };
2701
2732
  }
2702
- if (typeof result === "object" && ("output" in result || "error" in result || "success" in result)) {
2733
+ const isNativeToolResultLike = (value) => {
2734
+ if (!value || typeof value !== "object") return false;
2735
+ if (!("output" in value) && !("error" in value) && !("success" in value)) return false;
2736
+ if ("success" in value && value.success != null && typeof value.success !== "boolean") return false;
2737
+ if ("output" in value && value.output != null && typeof value.output !== "string") return false;
2738
+ if ("error" in value && value.error != null && typeof value.error !== "string") return false;
2739
+ return true;
2740
+ };
2741
+ if (isNativeToolResultLike(result)) {
2703
2742
  return {
2704
2743
  success: result.success ?? !result.error,
2705
2744
  output: result.output,