/** * LangChain JS wrapper for Keel governance. * * Targets @langchain/core 1.1.40 (verified on 2026-04-17). * @langchain/core is an OPTIONAL peer dependency — it is NOT listed in * package.json `dependencies`. Install it separately: * npm install @langchain/core@1.1.40 * * Usage: * import { ChatAnthropic } from "@langchain/anthropic"; * import { KeelChatModel } from "keel-sdk/integrations/langchain"; * * const inner = new ChatAnthropic({ model: "claude-3-5-sonnet-latest" }); * const model = new KeelChatModel({ * inner, * keelApiKey: process.env.KEEL_API_KEY!, * keelProjectId: "prj_...", * }); * const response = await model.invoke("Hello"); * * Parent permit chaining (agent loops): * Pass keelParentPermitId explicitly, OR nest calls inside an active * KeelChatModel._generate() — the AsyncLocalStorage propagates automatically. * getCurrentKeelPermitId() returns the active permit ID from within a * tool execute() callback so you can thread it into the next LLM call. * * Detection note: this module uses dynamic import() (not synchronous require()) * so that test harnesses can intercept it via vi.mock() for the "not installed" * scenario. The class that extends BaseChatModel is created lazily inside the * async detection function after BaseChatModel is available. */ export { getCurrentKeelPermitId } from "./_context"; export interface KeelChatModelOptions { /** The underlying LangChain chat model to delegate to. */ inner: any; /** Keel API key. Falls back to KEEL_API_KEY env var. */ keelApiKey?: string; /** Keel project ID. Falls back to KEEL_PROJECT_ID env var. */ keelProjectId?: string; /** Keel API base URL. Falls back to KEEL_BASE_URL env var. */ keelBaseUrl?: string; /** Explicit parent permit ID. Overrides AsyncLocalStorage value. */ keelParentPermitId?: string; /** Keel session ID to group permits. */ keelSessionId?: string; /** Subject for permit requests. Defaults to { type: "api_key", id: "default" }. */ keelSubject?: { type: string; id: string; }; /** Per-call timeout in milliseconds. */ timeout?: number; /** Maximum retries on transient Keel API errors. */ maxRetries?: number; } /** * Awaits the async @langchain/core detection. Call this in beforeAll/beforeEach * in test suites to ensure detection has completed before constructing instances. */ export declare function waitForLangchainDetection(): Promise; export interface KeelChatModel { inner: any; invoke(input: any, options?: any): Promise; stream(input: any, options?: any): AsyncGenerator; bindTools(tools: any[], kwargs?: any): any; _generate(messages: any[], options: any, runManager?: any): Promise; _llmType(): string; } export declare class KeelChatModel { constructor(options: KeelChatModelOptions); }