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;" />

156 lines (154 loc) 5.74 kB
import "reflect-metadata"; import { __toESM } from "../../../_virtual/_rolldown/runtime.mjs"; import { require_package } from "../../../package.mjs"; import { createLogger } from "../../../lib/logger.mjs"; import { logRuntimeTelemetryDisclosure } from "../../../lib/telemetry-disclosure.mjs"; import { DebugEventBus } from "./debug-event-bus.mjs"; import { InMemoryAgentRunner } from "../runner/in-memory.mjs"; import { IntelligenceAgentRunner } from "../runner/intelligence.mjs"; import telemetry from "../telemetry/telemetry-client.mjs"; import { RUNTIME_MODE_INTELLIGENCE, RUNTIME_MODE_SSE, resolveDebugConfig } from "@copilotkit/shared"; import { createLicenseChecker } from "@copilotkit/license-verifier"; //#region src/v2/runtime/core/runtime.ts var import_package = /* @__PURE__ */ __toESM(require_package()); const VERSION = import_package.default.version; /** * Resolve an AgentsConfig value to a concrete record of agents. * If the config is a factory function, it is called with the given request context. * Otherwise it is awaited directly (static record or Promise). */ async function resolveAgents(agents, request) { if (typeof agents === "function") { if (!request) throw new Error("Agent factory function requires a request context, but none was provided."); return agents({ request }); } return agents; } var BaseCopilotRuntime = class { constructor(options, runner) { logRuntimeTelemetryDisclosure(); const { agents, transcriptionService, beforeRequestMiddleware, afterRequestMiddleware, a2ui, mcpApps, openGenerativeUI } = options; this.agents = agents; this.transcriptionService = transcriptionService; this.beforeRequestMiddleware = beforeRequestMiddleware; this.afterRequestMiddleware = afterRequestMiddleware; this.a2ui = a2ui || void 0; this.mcpApps = mcpApps; this.openGenerativeUI = openGenerativeUI; this.runner = runner; if (process.env.NODE_ENV !== "production") this.debugEventBus = new DebugEventBus(); this.debug = resolveDebugConfig(options.debug); if (this.debug.enabled) this.debugLogger = createLogger({ level: "debug", component: "copilotkit-debug" }); } }; var CopilotSseRuntime = class extends BaseCopilotRuntime { constructor(options) { super(options, options.runner ?? new InMemoryAgentRunner()); this.intelligence = void 0; this.mode = RUNTIME_MODE_SSE; } }; var CopilotIntelligenceRuntime = class CopilotIntelligenceRuntime extends BaseCopilotRuntime { static { this.MAX_LOCK_TTL_SECONDS = 3600; } static { this.MAX_HEARTBEAT_INTERVAL_SECONDS = 3e3; } constructor(options) { super(options, new IntelligenceAgentRunner({ url: options.intelligence.ɵgetRunnerWsUrl(), authToken: options.intelligence.ɵgetRunnerAuthToken(), maxReconnectMs: options.maxReconnectMs, maxRejoinMs: options.maxRejoinMs })); this.mode = RUNTIME_MODE_INTELLIGENCE; this.intelligence = options.intelligence; this.identifyUser = options.identifyUser; this.generateThreadNames = options.generateThreadNames ?? true; const licenseToken = options.licenseToken ?? process.env.COPILOTKIT_LICENSE_TOKEN; this.licenseChecker = createLicenseChecker(licenseToken); if (licenseToken) telemetry.setLicenseToken(licenseToken); this.lockTtlSeconds = Math.min(options.lockTtlSeconds ?? 20, CopilotIntelligenceRuntime.MAX_LOCK_TTL_SECONDS); this.lockKeyPrefix = options.lockKeyPrefix; this.lockHeartbeatIntervalSeconds = Math.min(options.lockHeartbeatIntervalSeconds ?? 15, CopilotIntelligenceRuntime.MAX_HEARTBEAT_INTERVAL_SECONDS); } }; function hasIntelligenceOptions(options) { return "intelligence" in options && !!options.intelligence; } function isIntelligenceRuntime(runtime) { return runtime.mode === RUNTIME_MODE_INTELLIGENCE && !!runtime.intelligence; } /** * Compatibility shim that preserves the legacy `CopilotRuntime` entrypoint. * New code should prefer `CopilotSseRuntime` or `CopilotIntelligenceRuntime`. */ var CopilotRuntime = class { constructor(options) { this.delegate = hasIntelligenceOptions(options) ? new CopilotIntelligenceRuntime(options) : new CopilotSseRuntime(options); } get agents() { return this.delegate.agents; } get transcriptionService() { return this.delegate.transcriptionService; } get beforeRequestMiddleware() { return this.delegate.beforeRequestMiddleware; } get afterRequestMiddleware() { return this.delegate.afterRequestMiddleware; } get runner() { return this.delegate.runner; } get a2ui() { return this.delegate.a2ui; } get mcpApps() { return this.delegate.mcpApps; } get openGenerativeUI() { return this.delegate.openGenerativeUI; } get intelligence() { return this.delegate.intelligence; } get generateThreadNames() { return isIntelligenceRuntime(this.delegate) ? this.delegate.generateThreadNames : void 0; } get identifyUser() { return isIntelligenceRuntime(this.delegate) ? this.delegate.identifyUser : void 0; } get lockTtlSeconds() { return isIntelligenceRuntime(this.delegate) ? this.delegate.lockTtlSeconds : void 0; } get lockKeyPrefix() { return isIntelligenceRuntime(this.delegate) ? this.delegate.lockKeyPrefix : void 0; } get lockHeartbeatIntervalSeconds() { return isIntelligenceRuntime(this.delegate) ? this.delegate.lockHeartbeatIntervalSeconds : void 0; } get mode() { return this.delegate.mode; } get licenseChecker() { return this.delegate.licenseChecker; } get debugEventBus() { return this.delegate.debugEventBus; } get debug() { return this.delegate.debug; } get debugLogger() { return this.delegate.debugLogger; } }; //#endregion export { CopilotIntelligenceRuntime, CopilotRuntime, CopilotSseRuntime, VERSION, isIntelligenceRuntime, resolveAgents }; //# sourceMappingURL=runtime.mjs.map