/** * Plain LangChain JS tool definitions: name, description, schema and func. * No import from "@langchain/core", so this file type-checks and tests without it. * tools.ts wraps each one in tool() from "@langchain/core/tools". * Results are JSON strings, which every LangChain agent accepts as a tool message. */ import { AFTER_CHECKOUT_DESCRIPTION, BEFORE_CHECKOUT_DESCRIPTION, afterCheckout, beforeCheckout, userAgentFor, type ArcOptions } from "../core/arc.ts"; import { afterCheckoutSchema, beforeCheckoutSchema, type AfterCheckoutArgs, type BeforeCheckoutArgs } from "../core/schemas.ts"; export const LANGCHAIN_REF = "int-langchain-js"; export type ArcToolConfig = ArcOptions & { agentName?: string; agentFamily?: string }; export function arcLangChainDefinitions(config: ArcToolConfig = {}) { const options: ArcOptions = { userAgent: userAgentFor("langchain"), ref: LANGCHAIN_REF, ...config }; return { before: { name: "arc_before_checkout", description: BEFORE_CHECKOUT_DESCRIPTION, schema: beforeCheckoutSchema, func: async (args: BeforeCheckoutArgs) => JSON.stringify(await beforeCheckout(args, options)), }, after: { name: "arc_after_checkout", description: AFTER_CHECKOUT_DESCRIPTION, schema: afterCheckoutSchema, func: async (args: AfterCheckoutArgs) => JSON.stringify( await afterCheckout({ ...args, agent_name: config.agentName ?? "langchain-agent", agent_family: config.agentFamily ?? "langchain" }, options), ), }, }; }