Skip to content

Type definitions emit flat backend_tool() signatures but sandbox only exposes namespace backend.tool() objects #3

@arek-e

Description

@arek-e

Bug

generateTypeDefinitions in src/backends.ts tells the LLM to call tools using flat function syntax:

declare function fetch_fetch(args: FetchInput): Promise<any>;

But wrapCodeWithBindings in src/executor.ts only generates namespace objects, not flat functions:

const fetch = {
  fetch: (args) => SecureExec.bindings.callTool("fetch_fetch", args || {})
};

So the LLM writes await fetch_fetch({url: ...}) based on the type hints, but the sandbox throws ReferenceError: fetch_fetch is not defined at runtime. The correct call is await fetch.fetch({url: ...}).

Impact

Every LLM using the type definitions will call tools incorrectly.

Fix

Two options:

Option A — also generate flat aliases in the sandbox wrapper (minimal change, keeps flat-call ergonomics):

// after generating namespace object, add flat aliases
for (const toolName of tools) {
  const camelName = snakeToCamel(sanitizeName(toolName));
  const flatName  = `${sanitizeName(backendName)}_${sanitizeName(toolName)}`;
  aliases.push(`const ${flatName} = ${sanitizeName(backendName)}.${camelName};`);
}

This makes both fetch.fetch({...}) and fetch_fetch({...}) work.

Option B — change generateTypeDefinitions to emit namespace-style declarations:

declare const fetch: {
  fetch(args: FetchInput): Promise<any>; // Fetch a URL
};

Option A is the path of least resistance since it matches what the type hints already say.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions