import type { Turn } from "../agent/turn.ts"; import type { Pipeline } from "../pipeline/pipeline.ts"; import { type AgentLike } from "../pipeline/stages/agent.ts"; import type { CallerIdentity, Gate } from "../pipeline/types.ts"; /** * One HTTP handler for the whole thing. * * It takes a web-standard Request and returns a web-standard Response, which is * what lets the same function mount unchanged in a Next.js route, Hono, Express * with an adapter, Bun, Deno, and a Cloudflare Worker. Nothing here imports a * web framework. */ /** * Caps on what one request may carry. * * Every one of these is paid for on every step of a tool-calling turn, so an * unbounded request is an unbounded bill. They are generous for a real question * and small enough that nothing pathological gets through. */ export declare const MAX_QUESTION_CHARS = 2000; export declare const MAX_HISTORY_TURNS = 20; export declare const MAX_TURN_CHARS = 4000; /** * What a reader sees when the model fails. * * The provider's own message is written for whoever holds the account. It has * named the hosting company, linked an account page, and told the reader to run * commands on a machine they do not have. Worse, a spent budget reads as * "Current spend: $10.00, limit: $10.00. Please contact your administrator", * which shows the operator's billing state to a person who asked a rules * question and cannot act on any of it. * * So the reader gets one plain sentence and the operator gets the detail, in * the server log where they can read it. */ export declare const AGENT_UNAVAILABLE = "The assistant is unavailable right now. Please try again shortly."; export type AskHandlerOptions = { pipeline: Pipeline; /** The agent, for the streaming path once the earlier stages have missed. */ agent?: AgentLike; /** Quotas and billing. Defaults to a gate that allows everything. */ gate?: Gate; /** Who is asking. Return undefined for an anonymous caller. */ identify?: (request: Request) => Promise | CallerIdentity | undefined; /** Stream the agent's answer as it is written. On by default. */ stream?: boolean; /** * The sentence a reader sees when the model fails. Defaults to * `AGENT_UNAVAILABLE`. An internal tool where every reader is an operator can * pass the provider's own message through by setting this to a function that * returns its argument. */ unavailableMessage?: string | ((detail: string) => string); }; type AskBody = { question?: unknown; history?: unknown; }; /** Read and check the request body, or say exactly what is wrong with it. */ export declare function parseAskBody(body: AskBody): { ok: true; question: string; history: Turn[]; } | { ok: false; error: string; }; export declare function createAskHandler(options: AskHandlerOptions): (request: Request) => Promise; export {}; //# sourceMappingURL=handler.d.ts.map