@codex-native/sdk 0.0.23 → 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
@@ -78,6 +78,7 @@ __export(src_exports, {
78
78
  formatFileList: () => formatFileList,
79
79
  formatStream: () => formatStream,
80
80
  getCodexToolExecutor: () => getCodexToolExecutor,
81
+ getNativeBinding: () => getNativeBinding,
81
82
  gradeReverieRelevance: () => gradeReverieRelevance,
82
83
  gradeReveriesInParallel: () => gradeReveriesInParallel,
83
84
  isValidReverieExcerpt: () => isValidReverieExcerpt,
@@ -2605,10 +2606,21 @@ var CodexModel = class {
2605
2606
  };
2606
2607
  this.codex.registerTool(nativeToolDef);
2607
2608
  this.registeredTools.add(tool2.name);
2608
- 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
+ }
2609
2617
  } catch (error) {
2610
2618
  const errorMessage = `Failed to register tool ${tool2.name}: ${error instanceof Error ? error.message : String(error)}`;
2611
- console.error(errorMessage);
2619
+ try {
2620
+ process.stderr.write(`[codex-native] ${errorMessage}
2621
+ `);
2622
+ } catch {
2623
+ }
2612
2624
  }
2613
2625
  }
2614
2626
  }
@@ -2633,11 +2645,21 @@ var CodexModel = class {
2633
2645
  * but the framework integration is not yet complete.
2634
2646
  */
2635
2647
  async executeToolViaFramework(invocation) {
2636
- console.log("[DEBUG executeToolViaFramework] invocation:", JSON.stringify(invocation, null, 2));
2637
- console.log("[DEBUG executeToolViaFramework] invocation type:", typeof invocation);
2638
- 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
+ }
2639
2658
  if (!invocation) {
2640
- 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
+ }
2641
2663
  return {
2642
2664
  output: JSON.stringify({
2643
2665
  message: "Tool invocation payload missing",
@@ -2647,13 +2669,23 @@ var CodexModel = class {
2647
2669
  error: "Missing tool invocation data from Codex"
2648
2670
  };
2649
2671
  }
2650
- console.log(
2651
- `Tool execution requested by Codex: ${invocation.toolName} (callId: ${invocation.callId})`
2652
- );
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
+ }
2653
2681
  const executor = this.toolExecutors.get(invocation.toolName) ?? getCodexToolExecutor(invocation.toolName);
2654
2682
  if (!executor) {
2655
2683
  const message = `No Codex executor registered for tool '${invocation.toolName}'. Use codexTool() or provide a codexExecute handler.`;
2656
- console.warn(message);
2684
+ try {
2685
+ process.stderr.write(`[codex-native] ${message}
2686
+ `);
2687
+ } catch {
2688
+ }
2657
2689
  return {
2658
2690
  success: false,
2659
2691
  error: message,
@@ -2698,7 +2730,15 @@ var CodexModel = class {
2698
2730
  if (typeof result === "string") {
2699
2731
  return { success: true, output: result };
2700
2732
  }
2701
- 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)) {
2702
2742
  return {
2703
2743
  success: result.success ?? !result.error,
2704
2744
  output: result.output,
@@ -5005,6 +5045,7 @@ function sse(events) {
5005
5045
  formatFileList,
5006
5046
  formatStream,
5007
5047
  getCodexToolExecutor,
5048
+ getNativeBinding,
5008
5049
  gradeReverieRelevance,
5009
5050
  gradeReveriesInParallel,
5010
5051
  isValidReverieExcerpt,