UNPKG

@tanstack/ai

Version:

Type-safe TypeScript AI SDK for streaming chat, tool calling, agents, structured outputs, and multimodal generation.

87 lines (86 loc) 2.75 kB
const CATEGORY_EMOJI = { request: "📤", provider: "📥", output: "📨", middleware: "🧩", tools: "🔧", agentLoop: "🔁", config: "⚙️", errors: "❌" }; class InternalLogger { constructor(logger, categories) { this.logger = logger; this.categories = categories; } logger; categories; /** Whether a category is enabled. Cheap, safe to call on hot paths. */ isEnabled(category) { return this.categories[category]; } emit(level, category, message, meta) { if (!this.categories[category]) return; const emoji = CATEGORY_EMOJI[category]; const prefixed = `${emoji} [tanstack-ai:${category}] ${emoji} ${message}`; try { if (level === "error") this.logger.error(prefixed, meta); else this.logger.debug(prefixed, meta); } catch { } } /** Log a raw chunk/frame received from a provider SDK. */ provider(message, meta) { this.emit("debug", "provider", message, meta); } /** Log a chunk/result yielded to the consumer after middleware. */ output(message, meta) { this.emit("debug", "output", message, meta); } /** Log inputs/outputs around a middleware hook invocation. Chat-only. */ middleware(message, meta) { this.emit("debug", "middleware", message, meta); } /** Log before/after a tool-call execution. Chat-only. */ tools(message, meta) { this.emit("debug", "tools", message, meta); } /** Log an agent-loop iteration marker or phase transition. Chat-only. */ agentLoop(message, meta) { this.emit("debug", "agentLoop", message, meta); } /** Log a config transform returned by a middleware `onConfig` hook. Chat-only. */ config(message, meta) { this.emit("debug", "config", message, meta); } /** * Log a caught error. Defaults to on even when `debug` is unspecified. * Uses the underlying logger's `error` level. */ errors(message, meta) { this.emit("error", "errors", message, meta); } /** Log outgoing request metadata before an adapter SDK call. */ request(message, meta) { this.emit("debug", "request", message, meta); } /** * Log a non-fatal misconfiguration or recoverable anomaly. Gated by the * `errors` category — on by default (and when `debug` is unspecified), so * silent-drop conditions surface, but still silenced by `debug: false`, * which honors the "disable everything including errors" contract. Routes to * the underlying logger's `warn` level. */ warn(message, meta) { if (!this.categories.errors) return; const prefixed = `⚠️ [tanstack-ai:warn] ⚠️ ${message}`; try { this.logger.warn(prefixed, meta); } catch { } } } export { InternalLogger }; //# sourceMappingURL=internal-logger.js.map