Bluestep JS Documentation
    Preparing search index...

    Class Ai

    AI services for BSJS scripts. Routes through the web-global usage gate so requests are metered against the tenant's Bluestep API key, unless an apiKey override is supplied (in which case the proxy is bypassed).

    Index

    Other

    experimental

    Other

    • Returns Ai

    experimental

    Helpers that auto-generate AiTools from existing Relate form metadata. See B.ai.tool.forNewEntry().

    • Open a reusable AI agent that maintains connection settings, an accumulated tool registry, an onTurn callback, and a running chatHistory across multiple sendMessage(...) calls. Each sendMessage dispatches through the same usage-gated pipeline as B.ai.call and auto-threads the user message and assistant response into the agent's chatHistory so subsequent calls continue the conversation.

      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);

      const agent = B.ai.agent()
      .addTool(tool)
      .setProvider("anthropic")
      .setModel("claude-sonnet-4-5")
      .setSystemPrompt("You are a helpful assistant.");

      const r1 = agent.sendMessage("What is 2 + 3?");
      const r2 = agent.sendMessage("Now add 10 to that.");

      Returns AiAgent

    • Open a reusable AI agent pre-seeded from options. Equivalent to calling the no-arg agent() and then chaining the corresponding setters / addTool calls — every field on AiClientOptions is copied straight into the agent. After construction, the agent behaves identically to one built via the fluent setters: each sendMessage(...) dispatches through the same usage-gated pipeline as B.ai.call and threads the user message and assistant response into the running chatHistory.

      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);

      const agent = B.ai.agent({
      provider: "anthropic",
      model: "claude-sonnet-4-5",
      systemPrompt: "You are a helpful assistant.",
      tools: [tool],
      });

      const r1 = agent.sendMessage("What is 2 + 3?");
      const r2 = agent.sendMessage("Now add 10 to that.");

      Type Parameters

      Parameters

      Returns AiAgent

    • Sends a request to an AI provider and returns the response.

      The call is metered through the web-global AI usage gate under the tenant's Bluestep API key, with usage attributed to the calling user, the current operating Unit, the optional flag, the model, and the script that triggered the call. Pass an apiKey to bypass the proxy and call the provider directly with your own key (no metering).

      When an onTurn callback is supplied, the conversation continues for as many assistant↔user exchanges as the callback drives — analogous to a state-machine agent loop but owned by the script.

      The type parameter Schemas is inferred from the tools tuple's input_schema literals (preserved by the const modifier), so inline tool literals get a typed executor args parameter — typos in argument names and wrong-shape access fail at compile time, matching the safety of B.ai.tool.custom().

      Type Parameters

      Parameters

      Returns AiCallResult