@copilotkit/core 1.78.0 → 1.79.1-canary.1792034358

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.umd.js CHANGED
@@ -23,7 +23,17 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
23
23
 
24
24
  //#endregion
25
25
  //#region src/utils/connect-replay.ts
26
- /**
26
+ const connectRunErrorPhases = /* @__PURE__ */ new WeakMap();
27
+ /**
28
+ * The phase in which a connection received `event`, as recorded when it
29
+ * arrived. Events that did not come through a connection with replay
30
+ * boundaries report `unknown`.
31
+ */
32
+ function ɵgetConnectRunErrorPhase(event) {
33
+ var _connectRunErrorPhase;
34
+ return (_connectRunErrorPhase = connectRunErrorPhases.get(event)) !== null && _connectRunErrorPhase !== void 0 ? _connectRunErrorPhase : "unknown";
35
+ }
36
+ /**
27
37
  * Runs an agent's `connect()` stream through the AbstractAgent apply pipeline
28
38
  * with the `verifyEvents` step omitted.
29
39
  *
@@ -78,6 +88,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
78
88
  let result;
79
89
  const previousMessageIds = new Set(agent.messages.map((m) => m.id));
80
90
  let isReplaying = true;
91
+ let reportsReplayPhase = false;
81
92
  const liveErrors = /* @__PURE__ */ new WeakSet();
82
93
  const subscribers = [
83
94
  {
@@ -125,15 +136,19 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
125
136
  };
126
137
  const lifecycle = {
127
138
  onReplayStarted: () => {
139
+ reportsReplayPhase = true;
128
140
  isReplaying = true;
129
141
  agent.isRunning = true;
130
142
  },
131
143
  onReplayFinished: () => {
144
+ reportsReplayPhase = true;
132
145
  isReplaying = false;
133
146
  }
134
147
  };
135
148
  const source$ = (0, rxjs.defer)(() => new _ag_ui_client.CompatibilityBoundary().run(input, { run: () => connect ? connect(input, lifecycle) : self.connect(input) })).pipe((0, rxjs_operators.tap)((event) => {
136
- if (!isReplaying && event.type === _ag_ui_client.EventType.RUN_ERROR) liveErrors.add(event);
149
+ if (event.type !== _ag_ui_client.EventType.RUN_ERROR) return;
150
+ if (!isReplaying) liveErrors.add(event);
151
+ if (reportsReplayPhase) connectRunErrorPhases.set(event, isReplaying ? "replay" : "live");
137
152
  }), (0, _ag_ui_client.transformChunks)(self.debugLogger), (0, rxjs_operators.takeUntil)(activeRunDetach$));
138
153
  const applied$ = self.apply(input, source$, subscribers);
139
154
  await (0, rxjs.lastValueFrom)(self.processApplyEvents(input, applied$, subscribers).pipe((0, rxjs_operators.catchError)((error) => {
@@ -342,6 +357,20 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
342
357
  }
343
358
  };
344
359
  /**
360
+ * The gateway could not replay a live run's events, so the client cannot
361
+ * verify the run it is following. The run itself may still be going on the
362
+ * server; reconnecting to the thread shows its real state.
363
+ */
364
+ var IntelligenceReplayFailedError = class extends Error {
365
+ constructor(threadId, runId) {
366
+ super("The run's events could not be replayed. Reconnect to the thread to check the run's status.");
367
+ this.threadId = threadId;
368
+ this.runId = runId;
369
+ _defineProperty(this, "code", "INTELLIGENCE_REPLAY_FAILED");
370
+ this.name = "IntelligenceReplayFailedError";
371
+ }
372
+ };
373
+ /**
345
374
  * Type guard for {@link RunCompletionAware}. Returns true when `agent` exposes
346
375
  * an `activeRunCompletionPromise` property, so callers can await an in-flight
347
376
  * run without an `as unknown as` cast. Returns false for agents that don't
@@ -672,6 +701,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
672
701
  };
673
702
  const replayFailed$ = channel$.pipe((0, rxjs_operators.switchMap)(({ channel }) => this.observeChannelEvent$(channel, REPLAY_FAILED_EVENT)), (0, rxjs_operators.tap)(() => {
674
703
  controlCursor.replayFailed = true;
704
+ if (options.streamMode === "run") throw new IntelligenceReplayFailedError(credentials.threadId, credentials.runId);
675
705
  }));
676
706
  const replayComplete$ = this.observeControlEvent$(input.threadId, channel$, REPLAY_COMPLETE_EVENT, controlCursor).pipe((0, rxjs_operators.tap)(() => {
677
707
  var _options$lifecycle2, _options$lifecycle2$o;
@@ -1158,7 +1188,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1158
1188
  ...this.headers,
1159
1189
  "Content-Type": "application/json"
1160
1190
  });
1161
- fetch(this.singleEndpointUrl, {
1191
+ this.fetch(this.singleEndpointUrl, {
1162
1192
  method: "POST",
1163
1193
  headers,
1164
1194
  body: JSON.stringify({
@@ -1169,7 +1199,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1169
1199
  },
1170
1200
  ...runId === void 0 ? {} : { body: { runId } }
1171
1201
  }),
1172
- ...this.credentials ? { credentials: this.credentials } : {}
1202
+ ...this.credentials ? { credentials: this.credentials } : {},
1203
+ ɵruntimeRequest: { nonCritical: true }
1173
1204
  }).catch((error) => {
1174
1205
  console.error("ProxiedCopilotRuntimeAgent: stop request failed", error);
1175
1206
  });
@@ -1180,14 +1211,15 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1180
1211
  const origin = typeof window !== "undefined" && window.location ? window.location.origin : "http://localhost";
1181
1212
  const base = new URL(this.runtimeUrl, origin);
1182
1213
  const stopUrl = new URL(stopPath, base);
1183
- fetch(stopUrl.toString(), {
1214
+ this.fetch(stopUrl.toString(), {
1184
1215
  method: "POST",
1185
1216
  headers: {
1186
1217
  "Content-Type": "application/json",
1187
1218
  ...this.headers
1188
1219
  },
1189
1220
  ...runId === void 0 ? {} : { body: JSON.stringify({ runId }) },
1190
- ...this.credentials ? { credentials: this.credentials } : {}
1221
+ ...this.credentials ? { credentials: this.credentials } : {},
1222
+ ɵruntimeRequest: { nonCritical: true }
1191
1223
  }).catch((error) => {
1192
1224
  console.error("ProxiedCopilotRuntimeAgent: stop request failed", error);
1193
1225
  });
@@ -1663,6 +1695,185 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1663
1695
  };
1664
1696
  }
1665
1697
 
1698
+ //#endregion
1699
+ //#region src/core/header-source.ts
1700
+ var CopilotKitHeaderResolutionError = class extends Error {
1701
+ constructor(cause) {
1702
+ super("[CopilotKit] Failed to resolve request headers", { cause });
1703
+ _defineProperty(this, "name", "CopilotKitHeaderResolutionError");
1704
+ }
1705
+ };
1706
+ function isHeaderResolutionError(error) {
1707
+ let current = error;
1708
+ for (let depth = 0; depth < 5 && current; depth++) {
1709
+ if (current instanceof CopilotKitHeaderResolutionError) return true;
1710
+ current = current.cause;
1711
+ }
1712
+ return false;
1713
+ }
1714
+ function isPromiseLike(value) {
1715
+ return typeof value === "object" && value !== null && typeof value.then === "function";
1716
+ }
1717
+ /**
1718
+ * Normalize a header map to a `Record<string, string>` with no `null` or
1719
+ * `undefined` values. Dropping an entry is how a header is cleared.
1720
+ */
1721
+ function normalizeHeaders(headers) {
1722
+ return Object.fromEntries(Object.entries(headers).filter((entry) => entry[1] != null));
1723
+ }
1724
+ /** Same keys, same values (order-independent). */
1725
+ function shallowEqualRecord(a, b) {
1726
+ const aKeys = Object.keys(a);
1727
+ const bKeys = Object.keys(b);
1728
+ if (aKeys.length !== bKeys.length) return false;
1729
+ return aKeys.every((key) => a[key] === b[key]);
1730
+ }
1731
+ function isHeaderRecordInput(value) {
1732
+ return typeof value === "object" && value !== null && !Array.isArray(value);
1733
+ }
1734
+ /**
1735
+ * Owns the headers source for one core. Resolution is synchronous for a
1736
+ * record or a sync builder, so those callers never pay an extra await.
1737
+ */
1738
+ var HeaderSourceResolver = class {
1739
+ constructor(onFailure) {
1740
+ this.onFailure = onFailure;
1741
+ _defineProperty(this, "source", {});
1742
+ _defineProperty(this, "sourceGeneration", 0);
1743
+ _defineProperty(this, "snapshot", {});
1744
+ _defineProperty(this, "inFlight", void 0);
1745
+ }
1746
+ /** The last resolved headers. Not necessarily current for a builder. */
1747
+ get headers() {
1748
+ return this.snapshot;
1749
+ }
1750
+ /** Bumped on every accepted `setSource`, never by a new token. */
1751
+ get generation() {
1752
+ return this.sourceGeneration;
1753
+ }
1754
+ /**
1755
+ * Returns false when a builder with the same identity is set again, or
1756
+ * when a record replaces another record with equal normalized values (a
1757
+ * caller re-passing an equivalent literal on every re-render must not
1758
+ * bump the generation). A record replacing a builder, a builder replacing
1759
+ * a record, and a new builder function all still count as a change.
1760
+ */
1761
+ setSource(source) {
1762
+ if (typeof source === "function" && source === this.source) return false;
1763
+ const nextSnapshot = typeof source === "function" ? {} : normalizeHeaders(source);
1764
+ if (typeof source !== "function" && typeof this.source !== "function" && shallowEqualRecord(nextSnapshot, this.snapshot)) return false;
1765
+ this.source = source;
1766
+ this.sourceGeneration += 1;
1767
+ this.inFlight = void 0;
1768
+ this.snapshot = nextSnapshot;
1769
+ return true;
1770
+ }
1771
+ resolve() {
1772
+ var _this$inFlight;
1773
+ const source = this.source;
1774
+ if (typeof source !== "function") return this.snapshot;
1775
+ const generation = this.sourceGeneration;
1776
+ if (((_this$inFlight = this.inFlight) === null || _this$inFlight === void 0 ? void 0 : _this$inFlight.generation) === generation) return this.inFlight.promise;
1777
+ let value;
1778
+ try {
1779
+ value = source();
1780
+ } catch (error) {
1781
+ throw this.fail(error);
1782
+ }
1783
+ if (!isPromiseLike(value)) return this.accept(value, generation);
1784
+ const promise = Promise.resolve(value).then((resolved) => this.accept(resolved, generation), (error) => {
1785
+ throw this.fail(error);
1786
+ }).finally(() => {
1787
+ var _this$inFlight2;
1788
+ if (((_this$inFlight2 = this.inFlight) === null || _this$inFlight2 === void 0 ? void 0 : _this$inFlight2.promise) === promise) this.inFlight = void 0;
1789
+ });
1790
+ this.inFlight = {
1791
+ generation,
1792
+ promise
1793
+ };
1794
+ return promise;
1795
+ }
1796
+ accept(value, generation) {
1797
+ if (!isHeaderRecordInput(value)) throw this.fail(/* @__PURE__ */ new TypeError("headers builder must return an object of header values"));
1798
+ const normalized = normalizeHeaders(value);
1799
+ if (generation === this.sourceGeneration) {
1800
+ if (!shallowEqualRecord(normalized, this.snapshot)) this.snapshot = normalized;
1801
+ return this.snapshot;
1802
+ }
1803
+ return normalized;
1804
+ }
1805
+ fail(cause) {
1806
+ if (cause instanceof CopilotKitHeaderResolutionError) return cause;
1807
+ const error = new CopilotKitHeaderResolutionError(cause);
1808
+ this.onFailure(error);
1809
+ return error;
1810
+ }
1811
+ };
1812
+ const PROTOCOL_HEADERS = new Set(["content-type", "accept"]);
1813
+ /**
1814
+ * Put fresh core headers on top of a request's headers, keeping the input's
1815
+ * shape. Core beats an agent's own headers (#5635). A site's Content-Type and
1816
+ * Accept are never overridden, matching every site's existing spread order.
1817
+ */
1818
+ function ɵoverlayCoreHeaders(existing, core) {
1819
+ if (existing instanceof Headers) {
1820
+ const headers = new Headers(existing);
1821
+ for (const [key, value] of Object.entries(core)) {
1822
+ if (PROTOCOL_HEADERS.has(key.toLowerCase()) && headers.has(key)) continue;
1823
+ headers.set(key, value);
1824
+ }
1825
+ return headers;
1826
+ }
1827
+ const base = Array.isArray(existing) ? Object.fromEntries(existing) : { ...existing };
1828
+ const keyByLower = new Map(Object.keys(base).map((k) => [k.toLowerCase(), k]));
1829
+ for (const [key, value] of Object.entries(core)) {
1830
+ const existingKey = keyByLower.get(key.toLowerCase());
1831
+ if (existingKey !== void 0) {
1832
+ if (PROTOCOL_HEADERS.has(key.toLowerCase())) continue;
1833
+ delete base[existingKey];
1834
+ }
1835
+ base[key] = value;
1836
+ }
1837
+ return base;
1838
+ }
1839
+ /** Reject with the signal's AbortError if it aborts before `value` settles. */
1840
+ async function abortable(value, signal) {
1841
+ if (!signal || !isPromiseLike(value)) return value;
1842
+ if (signal.aborted) throw abortError(signal);
1843
+ return new Promise((resolve, reject) => {
1844
+ const onAbort = () => reject(abortError(signal));
1845
+ signal.addEventListener("abort", onAbort, { once: true });
1846
+ Promise.resolve(value).then((v) => {
1847
+ signal.removeEventListener("abort", onAbort);
1848
+ resolve(v);
1849
+ }, (e) => {
1850
+ signal.removeEventListener("abort", onAbort);
1851
+ reject(e);
1852
+ });
1853
+ });
1854
+ }
1855
+ function abortError(signal) {
1856
+ return signal.reason instanceof Error ? signal.reason : new DOMException("The operation was aborted.", "AbortError");
1857
+ }
1858
+ /**
1859
+ * Add default headers (e.g. the public API key) to a source, only where the
1860
+ * source left the key unset or empty. The single shared replacement for the
1861
+ * React, Vue and Angular providers' own merges.
1862
+ */
1863
+ function ɵwithHeaderDefaults(source, defaults) {
1864
+ if (Object.keys(defaults).length === 0) return source;
1865
+ const fill = (headers) => {
1866
+ const out = { ...headers };
1867
+ for (const [key, value] of Object.entries(defaults)) if (!out[key]) out[key] = value;
1868
+ return out;
1869
+ };
1870
+ if (typeof source !== "function") return fill(source);
1871
+ return (() => {
1872
+ const value = source();
1873
+ return isPromiseLike(value) ? Promise.resolve(value).then((resolved) => isHeaderRecordInput(resolved) ? fill(resolved) : resolved) : isHeaderRecordInput(value) ? fill(value) : value;
1874
+ });
1875
+ }
1876
+
1666
1877
  //#endregion
1667
1878
  //#region src/core/agent-registry.ts
1668
1879
  /** Maximum wait for optional Inspector metadata before degrading to absence. */
@@ -1988,29 +2199,85 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1988
2199
  console.warn(`Agent ${id} not found`);
1989
2200
  }
1990
2201
  /**
1991
- * Apply current core headers to an agent, merged ON TOP of the agent's own
1992
- * construction-time headers (the per-agent baseline in `agentOwnHeaders`).
1993
- * Core wins on a key conflict. Non-`HttpAgent` agents are left untouched
1994
- * because only `HttpAgent` carries a `headers` field. See #5635.
2202
+ * Shared core-and-own-header merge for a single agent. Captures the
2203
+ * agent's construction-time headers once (the per-agent baseline in
2204
+ * `agentOwnHeaders`), then either keeps only that baseline — a
2205
+ * `ProxiedCopilotRuntimeAgent`, whose core headers are added by
2206
+ * `ɵruntimeFetch` when each request is actually sent instead, so a key the
2207
+ * builder stops returning can never ride along from a stale copy baked
2208
+ * onto the agent (see #1937) — or merges `coreHeaders` on top of it (any
2209
+ * other `HttpAgent`; core wins on a key conflict, see #5635).
1995
2210
  */
1996
- applyHeadersToAgent(agent) {
1997
- if (ɵisHttpAgent(agent)) {
1998
- if (!this.agentOwnHeaders.has(agent)) this.agentOwnHeaders.set(agent, { ...agent.headers });
1999
- agent.headers = {
2000
- ...this.agentOwnHeaders.get(agent),
2001
- ...this.core.headers
2002
- };
2211
+ applyHeaderRecordToAgent(agent, coreHeaders) {
2212
+ if (!this.agentOwnHeaders.has(agent)) this.agentOwnHeaders.set(agent, { ...agent.headers });
2213
+ const own = this.agentOwnHeaders.get(agent);
2214
+ if (agent instanceof ProxiedCopilotRuntimeAgent) {
2215
+ agent.headers = { ...own };
2216
+ this.applyRuntimeFetchToAgent(agent);
2217
+ return;
2003
2218
  }
2219
+ agent.headers = {
2220
+ ...own,
2221
+ ...coreHeaders
2222
+ };
2223
+ }
2224
+ /**
2225
+ * Apply the last resolved header snapshot to an agent, merged ON TOP of
2226
+ * the agent's own construction-time headers. Non-`HttpAgent` agents are
2227
+ * left untouched because only `HttpAgent` carries a `headers` field. See
2228
+ * #5635.
2229
+ *
2230
+ * Never invokes the headers builder — safe to call from anywhere (dev-only
2231
+ * registration helpers, a React effect that re-runs on every render)
2232
+ * without risking a synchronous throw or an unhandled async rejection from
2233
+ * a user-supplied builder. Use `prepareAgentHeadersForRun` (friends-only)
2234
+ * on the run/connect path, where a builder failure can be awaited and
2235
+ * reported once.
2236
+ */
2237
+ applyHeadersToAgent(agent) {
2238
+ if (!ɵisHttpAgent(agent)) return;
2239
+ const friends = this.core;
2240
+ this.applyHeaderRecordToAgent(agent, friends.headers);
2004
2241
  }
2005
2242
  /**
2006
- * Apply current headers to all agents
2243
+ * Apply the last resolved header snapshot to every agent, without
2244
+ * triggering a builder call per agent. Used by `initialize` and
2245
+ * `setHeaders`; a run re-applies with fresh headers anyway (see
2246
+ * `prepareAgentHeadersForRun`).
2007
2247
  */
2008
2248
  applyHeadersToAgents(agents) {
2249
+ const friends = this.core;
2009
2250
  Object.values(agents).forEach((agent) => {
2010
- this.applyHeadersToAgent(agent);
2251
+ if (ɵisHttpAgent(agent)) this.applyHeaderRecordToAgent(agent, friends.headers);
2011
2252
  });
2012
2253
  }
2013
2254
  /**
2255
+ * Resolve headers fresh and apply them to `agent` right before a run or
2256
+ * connect actually sends (#1937) — the resolving counterpart to
2257
+ * `applyHeadersToAgent`. Friends-only: only the run handler should call
2258
+ * this, since resolving can invoke a user-supplied builder that throws
2259
+ * synchronously or returns a rejecting promise. Resolution is synchronous
2260
+ * for a record or a sync builder; this returns a promise only when an
2261
+ * async builder must be awaited first, and callers that need the write to
2262
+ * have landed before continuing must await a returned promise.
2263
+ *
2264
+ * A `ProxiedCopilotRuntimeAgent` never invokes the builder here: its core
2265
+ * headers are added by `ɵruntimeFetch` at send time instead, so only its
2266
+ * own headers are (re)applied.
2267
+ */
2268
+ prepareAgentHeadersForRun(agent) {
2269
+ if (!ɵisHttpAgent(agent)) return;
2270
+ if (agent instanceof ProxiedCopilotRuntimeAgent) {
2271
+ this.applyHeaderRecordToAgent(agent, {});
2272
+ return;
2273
+ }
2274
+ const resolved = this.core.resolveHeaders();
2275
+ if (isPromiseLike(resolved)) return Promise.resolve(resolved).then((headers) => {
2276
+ this.applyHeaderRecordToAgent(agent, headers);
2277
+ });
2278
+ this.applyHeaderRecordToAgent(agent, resolved);
2279
+ }
2280
+ /**
2014
2281
  * Apply current credentials to an agent
2015
2282
  */
2016
2283
  applyCredentialsToAgent(agent) {
@@ -2072,6 +2339,14 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2072
2339
  }
2073
2340
  createRuntimeFetch() {
2074
2341
  if (!this.runtimeFetch) this.runtimeFetch = (async (input, init) => {
2342
+ var _init$headers;
2343
+ const friends = this.core;
2344
+ const coreHeaders = await abortable(friends.resolveHeaders(), init === null || init === void 0 ? void 0 : init.signal);
2345
+ const requestHeaders = ɵoverlayCoreHeaders((_init$headers = init === null || init === void 0 ? void 0 : init.headers) !== null && _init$headers !== void 0 ? _init$headers : input instanceof Request ? input.headers : void 0, coreHeaders);
2346
+ init = {
2347
+ ...init,
2348
+ headers: requestHeaders
2349
+ };
2075
2350
  const meta = () => runtimeRequestMeta(init);
2076
2351
  const watchdog = this.armRuntimeRequestWatchdog(meta());
2077
2352
  try {
@@ -2143,7 +2418,15 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2143
2418
  const headersGeneration = this.inspectorMetadataHeadersGeneration;
2144
2419
  const credentialsGeneration = this.inspectorMetadataCredentialsGeneration;
2145
2420
  const friends = this.core;
2146
- const headers = { ...friends.headers };
2421
+ let headers;
2422
+ try {
2423
+ const resolved = friends.resolveHeaders();
2424
+ headers = { ...isPromiseLike(resolved) ? await resolved : resolved };
2425
+ } catch (_unused) {
2426
+ if (generation === this.inspectorMetadataGeneration) this.setInspectorMetadata(void 0);
2427
+ return;
2428
+ }
2429
+ if (generation !== this.inspectorMetadataGeneration) return;
2147
2430
  const credentials = friends.credentials;
2148
2431
  const abortController = new AbortController();
2149
2432
  this.inspectorMetadataAbortController = abortController;
@@ -2186,7 +2469,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2186
2469
  aborted,
2187
2470
  timeout
2188
2471
  ]);
2189
- } catch (_unused) {
2472
+ } catch (_unused2) {
2190
2473
  nextMetadata = void 0;
2191
2474
  } finally {
2192
2475
  if (timeoutId !== void 0) clearTimeout(timeoutId);
@@ -2305,6 +2588,10 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2305
2588
  async markRuntimeUnreachable(error) {
2306
2589
  this.setRuntimeConnectionStatus(CopilotKitCoreRuntimeConnectionStatus.Error);
2307
2590
  await this.notifyRuntimeStatusChanged(CopilotKitCoreRuntimeConnectionStatus.Error);
2591
+ if (isHeaderResolutionError(error)) {
2592
+ _copilotkit_shared.logger.warn(`Could not resolve request headers for the identification request (${this._runtimeUrl}/info). Check the headers builder passed to CopilotKit.`);
2593
+ return;
2594
+ }
2308
2595
  const runtimeStatus = isRuntimeInfoRequestError(error) ? error.runtimeInfoStatus : void 0;
2309
2596
  _copilotkit_shared.logger.warn(runtimeStatus === void 0 ? `Runtime did not answer the identification request (${this._runtimeUrl}/info): ${error.message}. The runtime appears to be unreachable.` : `Runtime answered the identification request with status ${runtimeStatus} (${this._runtimeUrl}/info): ${error.message}. The runtime is reachable but refused the request — check credentials and authorisation before addresses and ports.`);
2310
2597
  await this.core.emitError({
@@ -2570,9 +2857,10 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2570
2857
  }
2571
2858
  }
2572
2859
  async fetchRuntimeInfo(runtimeUrl, runtimeTransport, signal) {
2573
- const baseHeaders = this.core.headers;
2574
- const credentials = this.core.credentials;
2575
- const headers = { ...baseHeaders };
2860
+ const friends = this.core;
2861
+ const credentials = friends.credentials;
2862
+ const resolved = friends.resolveHeaders();
2863
+ const headers = { ...isPromiseLike(resolved) ? await abortable(resolved, signal) : resolved };
2576
2864
  if (runtimeTransport === "single") return {
2577
2865
  runtimeInfo: await this.fetchRuntimeInfoSingle(this.singleEndpointUrlFor(runtimeUrl), headers, credentials, signal),
2578
2866
  resolvedTransport: "single"
@@ -2625,7 +2913,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2625
2913
  runtimeInfo: await response.json(),
2626
2914
  resolvedTransport: "rest"
2627
2915
  };
2628
- } catch (_unused2) {}
2916
+ } catch (_unused3) {}
2629
2917
  return {
2630
2918
  runtimeInfo: await this.fetchRuntimeInfoSingle(this.singleEndpointUrlFor(runtimeUrl), { ...headers }, credentials, signal),
2631
2919
  resolvedTransport: "single"
@@ -2875,18 +3163,19 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2875
3163
  const seededState = JSON.parse(JSON.stringify((_suggestionsConsumerA = suggestionsConsumerAgent.state) !== null && _suggestionsConsumerA !== void 0 ? _suggestionsConsumerA : {}));
2876
3164
  const useStateless = this.core.suggestions === true && this.core.runtimeTransport !== "single";
2877
3165
  let suggestionAgent;
3166
+ let statelessAgent;
2878
3167
  if (useStateless) {
2879
3168
  const suggestUrl = `${this.core.runtimeUrl}/agent/${encodeURIComponent(resolvedProviderAgentId)}/suggest`;
2880
3169
  const credentials = this.core.credentials;
2881
- suggestionAgent = new _ag_ui_client.HttpAgent({
3170
+ statelessAgent = new _ag_ui_client.HttpAgent({
2882
3171
  agentId: resolvedProviderAgentId,
2883
3172
  url: suggestUrl,
2884
- headers: { ...this.core.headers },
2885
3173
  ...credentials ? { fetch: (url, requestInit) => fetch(url, {
2886
3174
  ...requestInit,
2887
3175
  credentials
2888
3176
  }) } : {}
2889
3177
  });
3178
+ suggestionAgent = statelessAgent;
2890
3179
  } else {
2891
3180
  suggestionAgent = suggestionsProviderAgent.clone();
2892
3181
  if (suggestionAgent instanceof ProxiedCopilotRuntimeAgent) suggestionAgent.messageFilter = void 0;
@@ -2899,6 +3188,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2899
3188
  suggestionAgent.abortRun();
2900
3189
  } };
2901
3190
  this._runningSuggestions[consumerAgentId] = [...(_this$_runningSuggest3 = this._runningSuggestions[consumerAgentId]) !== null && _this$_runningSuggest3 !== void 0 ? _this$_runningSuggest3 : [], runHandle];
3191
+ if (statelessAgent) statelessAgent.headers = { ...await this.core.resolveHeaders() };
3192
+ else await this.core.prepareAgentHeadersForRun(suggestionAgent);
3193
+ if (aborted) return;
2902
3194
  suggestionAgent.addMessage({
2903
3195
  id: suggestionId,
2904
3196
  role: "user",
@@ -3594,7 +3886,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3594
3886
  if (typeof cursorAware.clearReconnectCursor === "function") cursorAware.clearReconnectCursor(incomingThreadId);
3595
3887
  }
3596
3888
  }
3597
- this._internal.applyHeadersToAgent(agent);
3889
+ const headersApplied = this._internal.prepareAgentHeadersForRun(agent);
3890
+ if (headersApplied) await headersApplied;
3598
3891
  await this._internal.notifySubscribers((subscriber) => {
3599
3892
  var _subscriber$onAgentRu;
3600
3893
  return (_subscriber$onAgentRu = subscriber.onAgentRunStarted) === null || _subscriber$onAgentRu === void 0 ? void 0 : _subscriber$onAgentRu.call(subscriber, {
@@ -3610,7 +3903,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3610
3903
  forwardedProps: this._internal.properties,
3611
3904
  tools: this.buildFrontendTools(agent.agentId),
3612
3905
  context: this._internal.getContextForAgent(agent.agentId)
3613
- }, this.createAgentErrorSubscriber(agent));
3906
+ }, this.createAgentErrorSubscriber(agent, "connect"));
3614
3907
  if (this._connectionGenerations.get(agent) !== connection || ((_agent$threadId4 = agent.threadId) !== null && _agent$threadId4 !== void 0 ? _agent$threadId4 : null) !== incomingThreadId) return runAgentResult;
3615
3908
  const controller = new AbortController();
3616
3909
  const replay = (_this$_interactionAbo = this._interactionAbortControllers.get(agent)) !== null && _this$_interactionAbo !== void 0 ? _this$_interactionAbo : {
@@ -3661,7 +3954,16 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3661
3954
  */
3662
3955
  async runAgent({ agent, forwardedProps, resume, runId }, continuationHandoff) {
3663
3956
  if (agent.agentId) this._internal.suggestionEngine.clearSuggestions(agent.agentId);
3664
- this._internal.applyHeadersToAgent(agent);
3957
+ try {
3958
+ const headersApplied = this._internal.prepareAgentHeadersForRun(agent);
3959
+ if (headersApplied) await headersApplied;
3960
+ } catch (_unused) {
3961
+ continuationHandoff === null || continuationHandoff === void 0 || continuationHandoff.cancel();
3962
+ return {
3963
+ result: void 0,
3964
+ newMessages: []
3965
+ };
3966
+ }
3665
3967
  if (agent.detachActiveRun) try {
3666
3968
  await agent.detachActiveRun();
3667
3969
  } catch (error) {
@@ -3695,7 +3997,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3695
3997
  this._runDepth++;
3696
3998
  try {
3697
3999
  let logicalRunId = resumedRunId !== null && resumedRunId !== void 0 ? resumedRunId : runId;
3698
- const agentSubscriber = this.createAgentErrorSubscriber(agent);
4000
+ const agentSubscriber = this.createAgentErrorSubscriber(agent, "run");
3699
4001
  let started = false;
3700
4002
  const onRunStartedEvent = agentSubscriber.onRunStartedEvent;
3701
4003
  const onRunInitialized = agentSubscriber.onRunInitialized;
@@ -4229,7 +4531,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4229
4531
  /**
4230
4532
  * Create an agent error subscriber
4231
4533
  */
4232
- createAgentErrorSubscriber(agent) {
4534
+ createAgentErrorSubscriber(agent, stream) {
4233
4535
  const emitAgentError = async (error, code, extraContext = {}) => {
4234
4536
  const context = { ...extraContext };
4235
4537
  if (agent.agentId) context.agentId = agent.agentId;
@@ -4253,7 +4555,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4253
4555
  await emitAgentError(rawError, CopilotKitCoreErrorCode.AGENT_RUN_ERROR_EVENT, {
4254
4556
  source: "onRunErrorEvent",
4255
4557
  event,
4256
- runtimeErrorCode: event === null || event === void 0 ? void 0 : event.code
4558
+ runtimeErrorCode: event === null || event === void 0 ? void 0 : event.code,
4559
+ phase: stream === "run" ? "live" : ɵgetConnectRunErrorPhase(event)
4257
4560
  });
4258
4561
  }
4259
4562
  };
@@ -4911,6 +5214,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4911
5214
  stop() {
4912
5215
  const session = this.session;
4913
5216
  if (!session) return;
5217
+ const collector = session.collector;
5218
+ session.collector = void 0;
5219
+ collector === null || collector === void 0 || collector.stop();
4914
5220
  if (session.ready && session.connection) this.flush(session, session.connection);
4915
5221
  this.end(session, {
4916
5222
  status: "error",
@@ -5013,6 +5319,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
5013
5319
  } finally {
5014
5320
  if (socket) {
5015
5321
  socket.off(connection.socketRefs);
5322
+ socket.connect = () => void 0;
5016
5323
  socket.disconnect();
5017
5324
  }
5018
5325
  }
@@ -5020,12 +5327,12 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
5020
5327
  fail(session, connection, code, retryable = true) {
5021
5328
  var _session$collector3;
5022
5329
  if (!this.current(session, connection)) return;
5023
- (_session$collector3 = session.collector) === null || _session$collector3 === void 0 || _session$collector3.stop();
5024
- session.collector = void 0;
5025
5330
  if (session.ready && session.started) session.promise = new Promise((resolve) => {
5026
5331
  session.resolve = resolve;
5027
5332
  });
5028
5333
  session.ready = false;
5334
+ (_session$collector3 = session.collector) === null || _session$collector3 === void 0 || _session$collector3.stop();
5335
+ session.collector = void 0;
5029
5336
  this.discardQueue(session);
5030
5337
  session.linkedThreads.clear();
5031
5338
  for (const pending of connection.pending) pending.finish("PERSISTENCE_UNKNOWN");
@@ -5070,12 +5377,15 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
5070
5377
  if (!this.current(session, connection)) return;
5071
5378
  }
5072
5379
  const rest = transport === "rest";
5380
+ const resolved = this.core.resolveHeaders();
5381
+ const coreHeaders = isPromiseLike(resolved) ? await abortable(resolved, connection.abort.signal) : resolved;
5382
+ if (!this.current(session, connection)) return;
5073
5383
  const response = await fetch(rest ? `${runtimeUrl}/trajectory/${encodeURIComponent(session.trajectoryId)}/connect` : (_this$core$ɵruntimeE = this.core.ɵruntimeEndpointUrl) !== null && _this$core$ɵruntimeE !== void 0 ? _this$core$ɵruntimeE : runtimeUrl, {
5074
5384
  method: "POST",
5075
5385
  redirect: "error",
5076
5386
  signal: connection.abort.signal,
5077
5387
  headers: {
5078
- ...this.core.headers,
5388
+ ...coreHeaders,
5079
5389
  "Content-Type": "application/json"
5080
5390
  },
5081
5391
  credentials: this.core.credentials,
@@ -5187,7 +5497,11 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
5187
5497
  return ((_connection$socket = connection.socket) === null || _connection$socket === void 0 ? void 0 : _connection$socket.isConnected()) === true && ((_connection$channel = connection.channel) === null || _connection$channel === void 0 ? void 0 : _connection$channel.state) === "joined";
5188
5498
  }
5189
5499
  send(session, connection, event) {
5190
- if (!this.current(session, connection) || !session.ready) return;
5500
+ if (!this.current(session, connection)) return;
5501
+ if (!session.ready) {
5502
+ this.addDropped(session, 1, false);
5503
+ return;
5504
+ }
5191
5505
  if (!this.connected(connection)) {
5192
5506
  this.addDropped(session, 1);
5193
5507
  this.fail(session, connection, "CONNECTION_LOST");
@@ -5358,7 +5672,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
5358
5672
  });
5359
5673
  }
5360
5674
  if (config.sink === void 0) {
5361
- if (options.learningContainerIds !== void 0) console.warn("[CopilotKit] learningContainerIds is supported only with a custom sink. Authenticated Trajectory capture does not assign Learning Containers; remove learningContainerIds from the capture options.");
5675
+ if (options.learningContainerIds !== void 0) console.warn("[CopilotKit] learningContainerIds is supported only with a custom sink. Authenticated Trajectory capture ignores it; assign Learning Spaces on the server with getTrajectoryLearningContainerIds on CopilotKitIntelligence, and remove learningContainerIds from the capture options.");
5362
5676
  this.stopLegacy();
5363
5677
  return this.connection.start(options.trajectoryId, config);
5364
5678
  }
@@ -6686,6 +7000,12 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
6686
7000
  CopilotKitCoreErrorCode["AGENT_CONNECT_FAILED"] = "agent_connect_failed";
6687
7001
  CopilotKitCoreErrorCode["AGENT_RUN_FAILED"] = "agent_run_failed";
6688
7002
  CopilotKitCoreErrorCode["AGENT_RUN_FAILED_EVENT"] = "agent_run_failed_event";
7003
+ /**
7004
+ * An agent emitted RUN_ERROR. `context.phase` (`RunErrorPhase`) is
7005
+ * `"replay"` when the error belongs to stored thread history replayed on
7006
+ * connect, `"live"` when the run is happening now, and `"unknown"` when the
7007
+ * transport cannot tell. Show a live-failure notice only for `"live"`.
7008
+ */
6689
7009
  CopilotKitCoreErrorCode["AGENT_RUN_ERROR_EVENT"] = "agent_run_error_event";
6690
7010
  CopilotKitCoreErrorCode["TOOL_ARGUMENT_PARSE_FAILED"] = "tool_argument_parse_failed";
6691
7011
  CopilotKitCoreErrorCode["TOOL_HANDLER_FAILED"] = "tool_handler_failed";
@@ -6714,6 +7034,11 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
6714
7034
  CopilotKitCoreErrorCode["TRANSCRIPTION_AUTH_FAILED"] = "transcription_auth_failed";
6715
7035
  CopilotKitCoreErrorCode["TRANSCRIPTION_NETWORK_ERROR"] = "transcription_network_error";
6716
7036
  CopilotKitCoreErrorCode["SUBSCRIBER_CALLBACK_FAILED"] = "subscriber_callback_failed";
7037
+ /**
7038
+ * The `headers` builder threw, rejected, or returned something other than
7039
+ * an object. The request was not sent. `error.cause` is the builder's error.
7040
+ */
7041
+ CopilotKitCoreErrorCode["HEADER_RESOLUTION_FAILED"] = "header_resolution_failed";
6717
7042
  return CopilotKitCoreErrorCode;
6718
7043
  }({});
6719
7044
  /**
@@ -6736,18 +7061,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
6736
7061
  CopilotKitCoreRuntimeConnectionStatus["Error"] = "error";
6737
7062
  return CopilotKitCoreRuntimeConnectionStatus;
6738
7063
  }({});
6739
- /**
6740
- * Normalize a header map to the internal invariant: a `Record<string, string>`
6741
- * with no `null`/`undefined` values. Entries whose value is `null`/`undefined`
6742
- * are dropped (this is how a header is cleared). Shared by the constructor and
6743
- * `setHeaders` so both write paths into `_headers` enforce the same invariant.
6744
- */
6745
- function normalizeHeaders(headers) {
6746
- return Object.fromEntries(Object.entries(headers).filter((entry) => entry[1] != null));
6747
- }
6748
7064
  var CopilotKitCore = class {
6749
7065
  constructor({ runtimeUrl, runtimeTransport = "auto", deferInitialConnection = false, headers = {}, credentials, messageFilter, properties = {}, agents__unsafe_dev_only = {}, tools = [], suggestionsConfig = [], debug, learning }) {
6750
- _defineProperty(this, "_headers", void 0);
7066
+ _defineProperty(this, "headerSource", void 0);
6751
7067
  _defineProperty(this, "_credentials", void 0);
6752
7068
  _defineProperty(this, "_messageFilter", void 0);
6753
7069
  _defineProperty(this, "_properties", void 0);
@@ -6765,7 +7081,14 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
6765
7081
  _defineProperty(this, "learningConfiguredListeners", /* @__PURE__ */ new Set());
6766
7082
  _defineProperty(this, "_memoryStore", void 0);
6767
7083
  _defineProperty(this, "previousAgentIds", /* @__PURE__ */ new Set());
6768
- this._headers = normalizeHeaders(headers);
7084
+ this.headerSource = new HeaderSourceResolver((error) => {
7085
+ this.emitError({
7086
+ error,
7087
+ code: CopilotKitCoreErrorCode.HEADER_RESOLUTION_FAILED,
7088
+ context: { source: "headers" }
7089
+ });
7090
+ });
7091
+ this.headerSource.setSource(headers);
6769
7092
  this._credentials = credentials;
6770
7093
  this._messageFilter = messageFilter;
6771
7094
  this._properties = properties;
@@ -6823,6 +7146,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
6823
7146
  * Internal method used by delegate classes to emit errors
6824
7147
  */
6825
7148
  async emitError({ error, code, context = {} }) {
7149
+ if (code !== CopilotKitCoreErrorCode.HEADER_RESOLUTION_FAILED && isHeaderResolutionError(error)) return;
6826
7150
  await this.notifySubscribers((subscriber) => {
6827
7151
  var _subscriber$onError;
6828
7152
  return (_subscriber$onError = subscriber.onError) === null || _subscriber$onError === void 0 ? void 0 : _subscriber$onError.call(subscriber, {
@@ -6885,8 +7209,24 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
6885
7209
  get runtimeVersion() {
6886
7210
  return this.agentRegistry.runtimeVersion;
6887
7211
  }
7212
+ /**
7213
+ * The last resolved headers. With a builder this is the value from the most
7214
+ * recent request, not necessarily current; call `resolveHeaders()` for that.
7215
+ */
6888
7216
  get headers() {
6889
- return this._headers;
7217
+ return this.headerSource.headers;
7218
+ }
7219
+ /**
7220
+ * Resolve the current headers. Synchronous for a record or a sync builder,
7221
+ * a promise for an async builder. Concurrent calls share one builder call.
7222
+ * The returned object is shared; copy it before modifying.
7223
+ */
7224
+ resolveHeaders() {
7225
+ return this.headerSource.resolve();
7226
+ }
7227
+ /** Changes only on `setHeaders` or a new source, never on a new token. */
7228
+ get ɵheadersGeneration() {
7229
+ return this.headerSource.generation;
6890
7230
  }
6891
7231
  get credentials() {
6892
7232
  return this._credentials;
@@ -7027,9 +7367,17 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
7027
7367
  * with, set it at the provider/core level instead of on the agent, or update
7028
7368
  * it on the agent directly. The clear-on-logout pattern above is for
7029
7369
  * core-level headers.
7370
+ *
7371
+ * Pass a function to have headers evaluated when each request is sent
7372
+ * (sync or async). Setting the same function again is a no-op. A new token
7373
+ * from the builder doesn't notify `onHeadersChanged`. On a user switch,
7374
+ * call `setHeaders` with a NEW function (or a record), or remount.
7375
+ *
7376
+ * Passing a record equal (by value) to the currently applied record is
7377
+ * also a no-op — safe to call on every render with a fresh object literal.
7030
7378
  */
7031
7379
  setHeaders(headers) {
7032
- this._headers = normalizeHeaders(headers);
7380
+ if (!this.headerSource.setSource(headers)) return;
7033
7381
  if (this._memoryStore) this.syncMemoryContext();
7034
7382
  this.agentRegistry.applyHeadersToAgents(this.agentRegistry.agents);
7035
7383
  this.agentRegistry.handleHeadersChanged();
@@ -7185,8 +7533,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
7185
7533
  return this.learningBridge.registerOpenThread(params);
7186
7534
  }
7187
7535
  /**
7188
- * Re-apply the current headers to a single agent (delegated to
7189
- * AgentRegistry). Core headers are merged on top of the agent's own
7536
+ * Re-apply the last resolved header snapshot to a single agent (delegated
7537
+ * to AgentRegistry). Core headers are merged on top of the agent's own
7190
7538
  * construction-time headers rather than replacing them, so headers
7191
7539
  * configured directly on an `HttpAgent` (e.g. an `Authorization` for a
7192
7540
  * self-hosted backend) survive header updates instead of being silently
@@ -7197,11 +7545,31 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
7197
7545
  * afterwards is `setHeaders` (which re-applies to every agent), not mutating
7198
7546
  * `agent.headers` directly — a direct mutation is overwritten on the next
7199
7547
  * re-apply.
7548
+ *
7549
+ * A `ProxiedCopilotRuntimeAgent` keeps only its own construction-time
7550
+ * headers here — core headers are added by `ɵruntimeFetch` when each
7551
+ * request is sent (see #1937), so `agent.headers` never carries a stale
7552
+ * copy of a core header the builder has since stopped returning.
7553
+ *
7554
+ * Never invokes the headers builder (unlike the run/connect path's
7555
+ * internal `prepareAgentHeadersForRun`): safe to call from a dev-only
7556
+ * registration helper or a React effect that re-runs on every render
7557
+ * without risking a synchronous throw or an unhandled async rejection from
7558
+ * a user-supplied builder.
7200
7559
  */
7201
7560
  applyHeadersToAgent(agent) {
7202
7561
  this.agentRegistry.applyHeadersToAgent(agent);
7203
7562
  }
7204
7563
  /**
7564
+ * Resolve headers fresh and apply them to `agent` right before a run or
7565
+ * connect actually sends (#1937). Friends-only (delegated to
7566
+ * AgentRegistry) — the run handler is the sole caller, since resolving can
7567
+ * invoke a user-supplied builder that throws or rejects.
7568
+ */
7569
+ prepareAgentHeadersForRun(agent) {
7570
+ return this.agentRegistry.prepareAgentHeadersForRun(agent);
7571
+ }
7572
+ /**
7205
7573
  * Context management (delegated to ContextStore).
7206
7574
  * Pass `agentIds` to restrict the entry to runs of specific agents;
7207
7575
  * omit it for context every agent should receive.
@@ -7261,17 +7629,21 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
7261
7629
  /**
7262
7630
  * Pushes the current runtime wiring into the memory store. When the runtime
7263
7631
  * is connected and both the intelligence WebSocket URL and runtime URL are
7264
- * available, the store receives a context (runtime URL, WebSocket URL, and a
7265
- * copy of the current headers); otherwise its context is cleared. No-op when
7266
- * the store has not been created yet.
7632
+ * available, the store receives a context (runtime URL, WebSocket URL);
7633
+ * otherwise its context is cleared. No-op when the store has not been
7634
+ * created yet.
7635
+ *
7636
+ * Headers are deliberately NOT part of this context: the store's `fetch` is
7637
+ * `ɵruntimeFetch` (see `ensureMemoryStore`), which already resolves and
7638
+ * overlays the current core headers at send time (#1937) — a header
7639
+ * snapshot copied here would go stale between context syncs.
7267
7640
  */
7268
7641
  syncMemoryContext() {
7269
7642
  var _this$intelligence;
7270
7643
  if (!this._memoryStore) return;
7271
7644
  if (this.runtimeConnectionStatus === CopilotKitCoreRuntimeConnectionStatus.Connected && ((_this$intelligence = this.intelligence) === null || _this$intelligence === void 0 ? void 0 : _this$intelligence.wsUrl) && this.runtimeUrl) this._memoryStore.setContext({
7272
7645
  runtimeUrl: this.runtimeUrl,
7273
- wsUrl: this.intelligence.wsUrl,
7274
- headers: { ...this.headers }
7646
+ wsUrl: this.intelligence.wsUrl
7275
7647
  });
7276
7648
  else this._memoryStore.setContext(null);
7277
7649
  }
@@ -8755,8 +9127,10 @@ exports.ContextStore = ContextStore;
8755
9127
  exports.CopilotKitCore = CopilotKitCore;
8756
9128
  exports.CopilotKitCoreErrorCode = CopilotKitCoreErrorCode;
8757
9129
  exports.CopilotKitCoreRuntimeConnectionStatus = CopilotKitCoreRuntimeConnectionStatus;
9130
+ exports.CopilotKitHeaderResolutionError = CopilotKitHeaderResolutionError;
8758
9131
  exports.INSPECTOR_THREAD_BRIDGE_PLUGIN_ID = INSPECTOR_THREAD_BRIDGE_PLUGIN_ID;
8759
9132
  exports.IntelligenceAgent = IntelligenceAgent;
9133
+ exports.IntelligenceReplayFailedError = IntelligenceReplayFailedError;
8760
9134
  exports.MEMORY_ERROR_REGISTRY = MEMORY_ERROR_REGISTRY;
8761
9135
  exports.MemoryError = MemoryError;
8762
9136
  exports.ProxiedCopilotRuntimeAgent = ProxiedCopilotRuntimeAgent;
@@ -8828,5 +9202,6 @@ exports.ɵselectThreads = ɵselectThreads;
8828
9202
  exports.ɵselectThreadsError = ɵselectThreadsError;
8829
9203
  exports.ɵselectThreadsIsLoading = ɵselectThreadsIsLoading;
8830
9204
  exports.ɵthreadAdapterEvents = ɵthreadAdapterEvents;
9205
+ exports.ɵwithHeaderDefaults = ɵwithHeaderDefaults;
8831
9206
  });
8832
9207
  //# sourceMappingURL=index.umd.js.map