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

161 lines (159 loc) 6.17 kB
require("reflect-metadata"); const require_runtime = require('../../../_virtual/_rolldown/runtime.cjs'); const require_package$1 = require('../../../package.cjs'); const require_logger = require('../../../lib/logger.cjs'); const require_telemetry_disclosure = require('../../../lib/telemetry-disclosure.cjs'); const require_debug_event_bus = require('./debug-event-bus.cjs'); const require_in_memory = require('../runner/in-memory.cjs'); const require_intelligence = require('../runner/intelligence.cjs'); const require_telemetry_client = require('../telemetry/telemetry-client.cjs'); let _copilotkit_shared = require("@copilotkit/shared"); let _copilotkit_license_verifier = require("@copilotkit/license-verifier"); //#region src/v2/runtime/core/runtime.ts var import_package = /* @__PURE__ */ require_runtime.__toESM(require_package$1.default); 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) { require_telemetry_disclosure.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 require_debug_event_bus.DebugEventBus(); this.debug = (0, _copilotkit_shared.resolveDebugConfig)(options.debug); if (this.debug.enabled) this.debugLogger = require_logger.createLogger({ level: "debug", component: "copilotkit-debug" }); } }; var CopilotSseRuntime = class extends BaseCopilotRuntime { constructor(options) { super(options, options.runner ?? new require_in_memory.InMemoryAgentRunner()); this.intelligence = void 0; this.mode = _copilotkit_shared.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 require_intelligence.IntelligenceAgentRunner({ url: options.intelligence.ɵgetRunnerWsUrl(), authToken: options.intelligence.ɵgetRunnerAuthToken(), maxReconnectMs: options.maxReconnectMs, maxRejoinMs: options.maxRejoinMs })); this.mode = _copilotkit_shared.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 = (0, _copilotkit_license_verifier.createLicenseChecker)(licenseToken); if (licenseToken) require_telemetry_client.default.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 === _copilotkit_shared.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 exports.CopilotIntelligenceRuntime = CopilotIntelligenceRuntime; exports.CopilotRuntime = CopilotRuntime; exports.CopilotSseRuntime = CopilotSseRuntime; exports.VERSION = VERSION; exports.isIntelligenceRuntime = isIntelligenceRuntime; exports.resolveAgents = resolveAgents; //# sourceMappingURL=runtime.cjs.map