Bluestep JS Documentation
    Preparing search index...

    Interface AiToolBuilder<S>

    Fluent builder for B.ai.tool.custom(). The type parameter S is the literal type of the schema captured by setSchema(); defaults to never, which forces setExecutor() to require a zero-arg function. After setSchema(...) narrows S, setExecutor()'s args parameter is typed via FromSchema.

    interface AiToolBuilder<S = never> {
        setDescription(description: string): AiToolBuilder<S>;
        setExecutor(
            fn: [S] extends [never]
                ? () => unknown
                : (args: FromSchema<S>) => unknown,
        ): AiTool;
        setName(name: string): AiToolBuilder<S>;
        setSchema<const S2 extends JSONSchema>(schema: S2): AiToolBuilder<S2>;
    }

    Type Parameters

    • S = never
    Index

    experimental

    • Set the free-text description shown to the model. Returns this builder for chaining.

      Parameters

      • description: string

        When and how the model should use this tool.

      Returns AiToolBuilder<S>

    • Finalize the custom tool by setting the executor. When a schema was captured via setSchema(...), args is typed via FromSchema<S> — typos in field names and wrong-shape access fail at compile time. When no schema was captured (S = never), the executor must be zero-arg since the model has no input_schema to send. Returns the underlying AiTool.

      const tool = B.ai.tool.custom()
      .setName("add_1")
      .setDescription("adds one!")
      .setSchema({
      type: "object",
      properties: {
      a: { type: "integer" },
      b: { type: "integer" },
      },
      required: ["a", "b"],
      })
      .setExecutor((args) => args.a + args.b + 1);

      Parameters

      • fn: [S] extends [never] ? () => unknown : (args: FromSchema<S>) => unknown

        Executor function. Zero-arg when no schema is set; otherwise args is typed against the schema captured by setSchema(...).

      Returns AiTool

    • Set the tool name. Returns this builder for chaining.

      Parameters

      • name: string

        Tool name. Must be unique within a single B.ai.call invocation.

      Returns AiToolBuilder<S>

    • Set the JSON Schema describing the tool's input arguments. Captures the schema's literal type into the returned builder so the subsequent .setExecutor(...) call can type its args parameter via FromSchema<S>. The const modifier on the generic narrows literal types automatically — as const is only needed on nested arrays (e.g. enum) to preserve their literal members.

      const tool = B.ai.tool.custom()
      .setName("add_1")
      .setDescription("adds one!")
      .setSchema({
      type: "object",
      properties: {
      a: { type: "integer" },
      b: { type: "integer" },
      },
      required: ["a", "b"],
      })
      .setExecutor((args) => args.a + args.b + 1);

      Type Parameters

      Parameters

      • schema: S2

        The JSON Schema literal describing the tool's argument shape. Sent verbatim to the model as the tool's input_schema.

      Returns AiToolBuilder<S2>