UNPKG

@copilotkit/runtime

Version:

<img src="https://github.com/user-attachments/assets/0a6b64d9-e193-4940-a3f6-60334ac34084" alt="banner" style="border-radius: 12px; border: 2px solid #d6d4fa;" />

72 lines (70 loc) 2.3 kB
require("reflect-metadata"); //#region src/v2/runtime/core/runtime-error-reporter.ts const runtimeErrorReporterOption = Symbol("copilotkit.runtimeErrorReporter"); const SENSITIVE_REQUEST_HEADERS = new Set([ "authorization", "proxy-authorization", "cookie", "set-cookie", "x-api-key", "api-key", "x-copilotcloud-public-api-key" ]); function sanitizeRequestHeaders(headers) { const sanitized = {}; headers.forEach((value, key) => { if (!SENSITIVE_REQUEST_HEADERS.has(key.toLowerCase())) sanitized[key] = value; }); return sanitized; } function createRuntimeErrorReporter(handler) { return { report({ request, error, operation, agentId, threadId, runId, phase, startTime }) { if (!handler) return; try { const result = handler({ type: "error", timestamp: Date.now(), context: { source: "runtime", ...threadId ? { threadId } : {}, ...runId ? { runId } : {}, request: { operation, method: request.method, url: request.url, path: new URL(request.url).pathname, headers: sanitizeRequestHeaders(request.headers), startTime: startTime ?? Date.now() }, ...agentId ? { agent: { name: agentId } } : {}, ...phase ? { metadata: { phase } } : {} }, error }); if (result && typeof result.catch === "function") result.catch((handlerError) => { console.error("CopilotRuntime onError reporting failed:", handlerError); }); } catch (handlerError) { console.error("CopilotRuntime onError reporting failed:", handlerError); } } }; } function getRuntimeErrorReporterFromOptions(options) { return options[runtimeErrorReporterOption]; } function attachRuntimeErrorReporter(runtime, reporter) { Object.defineProperty(runtime, runtimeErrorReporterOption, { configurable: true, value: reporter }); } function getRuntimeErrorReporter(runtime) { return runtime[runtimeErrorReporterOption]; } //#endregion exports.attachRuntimeErrorReporter = attachRuntimeErrorReporter; exports.createRuntimeErrorReporter = createRuntimeErrorReporter; exports.getRuntimeErrorReporter = getRuntimeErrorReporter; exports.getRuntimeErrorReporterFromOptions = getRuntimeErrorReporterFromOptions; exports.runtimeErrorReporterOption = runtimeErrorReporterOption; //# sourceMappingURL=runtime-error-reporter.cjs.map