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

1 lines 2.75 kB
{"version":3,"file":"auto-start-channels.cjs","names":[],"sources":["../../../../src/v2/runtime/endpoints/auto-start-channels.ts"],"sourcesContent":["import { logger } from \"@copilotkit/shared\";\nimport type { ChannelsControl } from \"../core/channel-manager\";\n\n/**\n * Begin activation of a runtime's declared managed Channels on behalf of a\n * LONG-RUNNING host (OSS-641).\n *\n * The generic Fetch handler deliberately defers activation to the first\n * `channels.ready()`: it is the serverless/edge entry point, where an isolate\n * freezes and recycles per request and separate cold starts would mint\n * competing listeners for the same Channel. That constraint does not apply to a\n * host that owns its own lifetime — a Node server or an Express app — so those\n * wrappers start activation as soon as they are created and leave `ready()` as\n * a pure await-and-observe call.\n *\n * Fire-and-forget by necessity: a factory is synchronous, so the activation\n * outcome cannot be returned. That is a deliberate trade against the failure\n * mode it replaces — a process that serves HTTP, looks healthy, and is silently\n * disconnected because nothing ever called `ready()`. Here the worst case is an\n * activation error in the logs. `ready()` is idempotent and one-shot, so a host\n * that DOES await it afterwards observes THIS activation's outcome (including\n * its rejection reason) rather than triggering a second one.\n *\n * The rejection is logged at `error`, not swallowed: an up-front\n * misconfiguration (duplicate or missing Channel names) rejects `ready()`\n * synchronously-ish from `activate()` and would otherwise be invisible to a\n * host that never awaits `ready()` — the exact silence this change exists to\n * remove. Per-Channel activation failures ALSO emit their own `warn`\n * breadcrumbs through the manager's log bridge (see `fetch-handler.ts`), so the\n * `error` here is the set-level summary, not the only signal.\n *\n * @param channels - The handler's control surface, or `undefined` when the\n * runtime declares no Channels or opted out via `activateChannels: false`\n * (both no-op, so the opt-out stays a genuine \"open no socket\").\n */\nexport function autoStartChannels(channels: ChannelsControl | undefined): void {\n if (!channels) {\n return;\n }\n channels.ready().catch((err) => {\n logger.error(\n { err },\n \"CopilotKit managed Channels failed to activate. The runtime is serving \" +\n \"requests but one or more declared Channels are not connected.\",\n );\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,SAAgB,kBAAkB,UAA6C;AAC7E,KAAI,CAAC,SACH;AAEF,UAAS,OAAO,CAAC,OAAO,QAAQ;AAC9B,4BAAO,MACL,EAAE,KAAK,EACP,uIAED;GACD"}