@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.cjs +426 -55
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +175 -25
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +175 -25
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +424 -56
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +433 -58
- package/dist/index.umd.js.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -25,6 +25,15 @@ function ɵisHttpAgent(agent) {
|
|
|
25
25
|
|
|
26
26
|
//#endregion
|
|
27
27
|
//#region src/utils/connect-replay.ts
|
|
28
|
+
const connectRunErrorPhases = /* @__PURE__ */ new WeakMap();
|
|
29
|
+
/**
|
|
30
|
+
* The phase in which a connection received `event`, as recorded when it
|
|
31
|
+
* arrived. Events that did not come through a connection with replay
|
|
32
|
+
* boundaries report `unknown`.
|
|
33
|
+
*/
|
|
34
|
+
function ɵgetConnectRunErrorPhase(event) {
|
|
35
|
+
return connectRunErrorPhases.get(event) ?? "unknown";
|
|
36
|
+
}
|
|
28
37
|
/**
|
|
29
38
|
* Runs an agent's `connect()` stream through the AbstractAgent apply pipeline
|
|
30
39
|
* with the `verifyEvents` step omitted.
|
|
@@ -79,6 +88,7 @@ async function ɵconnectWithoutEventVerification(agent, parameters, subscriber,
|
|
|
79
88
|
let result;
|
|
80
89
|
const previousMessageIds = new Set(agent.messages.map((m) => m.id));
|
|
81
90
|
let isReplaying = true;
|
|
91
|
+
let reportsReplayPhase = false;
|
|
82
92
|
const liveErrors = /* @__PURE__ */ new WeakSet();
|
|
83
93
|
const subscribers = [
|
|
84
94
|
{
|
|
@@ -126,15 +136,19 @@ async function ɵconnectWithoutEventVerification(agent, parameters, subscriber,
|
|
|
126
136
|
};
|
|
127
137
|
const lifecycle = {
|
|
128
138
|
onReplayStarted: () => {
|
|
139
|
+
reportsReplayPhase = true;
|
|
129
140
|
isReplaying = true;
|
|
130
141
|
agent.isRunning = true;
|
|
131
142
|
},
|
|
132
143
|
onReplayFinished: () => {
|
|
144
|
+
reportsReplayPhase = true;
|
|
133
145
|
isReplaying = false;
|
|
134
146
|
}
|
|
135
147
|
};
|
|
136
148
|
const source$ = defer(() => new CompatibilityBoundary().run(input, { run: () => connect ? connect(input, lifecycle) : self.connect(input) })).pipe(tap((event) => {
|
|
137
|
-
if (
|
|
149
|
+
if (event.type !== EventType.RUN_ERROR) return;
|
|
150
|
+
if (!isReplaying) liveErrors.add(event);
|
|
151
|
+
if (reportsReplayPhase) connectRunErrorPhases.set(event, isReplaying ? "replay" : "live");
|
|
138
152
|
}), transformChunks(self.debugLogger), takeUntil(activeRunDetach$));
|
|
139
153
|
const applied$ = self.apply(input, source$, subscribers);
|
|
140
154
|
await lastValueFrom(self.processApplyEvents(input, applied$, subscribers).pipe(catchError((error) => {
|
|
@@ -301,6 +315,20 @@ var AgentThreadLockedError = class extends Error {
|
|
|
301
315
|
}
|
|
302
316
|
};
|
|
303
317
|
/**
|
|
318
|
+
* The gateway could not replay a live run's events, so the client cannot
|
|
319
|
+
* verify the run it is following. The run itself may still be going on the
|
|
320
|
+
* server; reconnecting to the thread shows its real state.
|
|
321
|
+
*/
|
|
322
|
+
var IntelligenceReplayFailedError = class extends Error {
|
|
323
|
+
code = "INTELLIGENCE_REPLAY_FAILED";
|
|
324
|
+
constructor(threadId, runId) {
|
|
325
|
+
super("The run's events could not be replayed. Reconnect to the thread to check the run's status.");
|
|
326
|
+
this.threadId = threadId;
|
|
327
|
+
this.runId = runId;
|
|
328
|
+
this.name = "IntelligenceReplayFailedError";
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
/**
|
|
304
332
|
* Type guard for {@link RunCompletionAware}. Returns true when `agent` exposes
|
|
305
333
|
* an `activeRunCompletionPromise` property, so callers can await an in-flight
|
|
306
334
|
* run without an `as unknown as` cast. Returns false for agents that don't
|
|
@@ -626,6 +654,7 @@ var IntelligenceAgent = class IntelligenceAgent extends AbstractAgent {
|
|
|
626
654
|
};
|
|
627
655
|
const replayFailed$ = channel$.pipe(switchMap$1(({ channel }) => this.observeChannelEvent$(channel, REPLAY_FAILED_EVENT)), tap(() => {
|
|
628
656
|
controlCursor.replayFailed = true;
|
|
657
|
+
if (options.streamMode === "run") throw new IntelligenceReplayFailedError(credentials.threadId, credentials.runId);
|
|
629
658
|
}));
|
|
630
659
|
const replayComplete$ = this.observeControlEvent$(input.threadId, channel$, REPLAY_COMPLETE_EVENT, controlCursor).pipe(tap(() => {
|
|
631
660
|
replayFinished = true;
|
|
@@ -1103,7 +1132,7 @@ var ProxiedCopilotRuntimeAgent = class ProxiedCopilotRuntimeAgent extends HttpAg
|
|
|
1103
1132
|
...this.headers,
|
|
1104
1133
|
"Content-Type": "application/json"
|
|
1105
1134
|
});
|
|
1106
|
-
fetch(this.singleEndpointUrl, {
|
|
1135
|
+
this.fetch(this.singleEndpointUrl, {
|
|
1107
1136
|
method: "POST",
|
|
1108
1137
|
headers,
|
|
1109
1138
|
body: JSON.stringify({
|
|
@@ -1114,7 +1143,8 @@ var ProxiedCopilotRuntimeAgent = class ProxiedCopilotRuntimeAgent extends HttpAg
|
|
|
1114
1143
|
},
|
|
1115
1144
|
...runId === void 0 ? {} : { body: { runId } }
|
|
1116
1145
|
}),
|
|
1117
|
-
...this.credentials ? { credentials: this.credentials } : {}
|
|
1146
|
+
...this.credentials ? { credentials: this.credentials } : {},
|
|
1147
|
+
ɵruntimeRequest: { nonCritical: true }
|
|
1118
1148
|
}).catch((error) => {
|
|
1119
1149
|
console.error("ProxiedCopilotRuntimeAgent: stop request failed", error);
|
|
1120
1150
|
});
|
|
@@ -1125,14 +1155,15 @@ var ProxiedCopilotRuntimeAgent = class ProxiedCopilotRuntimeAgent extends HttpAg
|
|
|
1125
1155
|
const origin = typeof window !== "undefined" && window.location ? window.location.origin : "http://localhost";
|
|
1126
1156
|
const base = new URL(this.runtimeUrl, origin);
|
|
1127
1157
|
const stopUrl = new URL(stopPath, base);
|
|
1128
|
-
fetch(stopUrl.toString(), {
|
|
1158
|
+
this.fetch(stopUrl.toString(), {
|
|
1129
1159
|
method: "POST",
|
|
1130
1160
|
headers: {
|
|
1131
1161
|
"Content-Type": "application/json",
|
|
1132
1162
|
...this.headers
|
|
1133
1163
|
},
|
|
1134
1164
|
...runId === void 0 ? {} : { body: JSON.stringify({ runId }) },
|
|
1135
|
-
...this.credentials ? { credentials: this.credentials } : {}
|
|
1165
|
+
...this.credentials ? { credentials: this.credentials } : {},
|
|
1166
|
+
ɵruntimeRequest: { nonCritical: true }
|
|
1136
1167
|
}).catch((error) => {
|
|
1137
1168
|
console.error("ProxiedCopilotRuntimeAgent: stop request failed", error);
|
|
1138
1169
|
});
|
|
@@ -1548,6 +1579,183 @@ async function createSingleRouteResourceRequest(input, init, runtimeUrl) {
|
|
|
1548
1579
|
};
|
|
1549
1580
|
}
|
|
1550
1581
|
|
|
1582
|
+
//#endregion
|
|
1583
|
+
//#region src/core/header-source.ts
|
|
1584
|
+
var CopilotKitHeaderResolutionError = class extends Error {
|
|
1585
|
+
name = "CopilotKitHeaderResolutionError";
|
|
1586
|
+
constructor(cause) {
|
|
1587
|
+
super("[CopilotKit] Failed to resolve request headers", { cause });
|
|
1588
|
+
}
|
|
1589
|
+
};
|
|
1590
|
+
function isHeaderResolutionError(error) {
|
|
1591
|
+
let current = error;
|
|
1592
|
+
for (let depth = 0; depth < 5 && current; depth++) {
|
|
1593
|
+
if (current instanceof CopilotKitHeaderResolutionError) return true;
|
|
1594
|
+
current = current.cause;
|
|
1595
|
+
}
|
|
1596
|
+
return false;
|
|
1597
|
+
}
|
|
1598
|
+
function isPromiseLike(value) {
|
|
1599
|
+
return typeof value === "object" && value !== null && typeof value.then === "function";
|
|
1600
|
+
}
|
|
1601
|
+
/**
|
|
1602
|
+
* Normalize a header map to a `Record<string, string>` with no `null` or
|
|
1603
|
+
* `undefined` values. Dropping an entry is how a header is cleared.
|
|
1604
|
+
*/
|
|
1605
|
+
function normalizeHeaders(headers) {
|
|
1606
|
+
return Object.fromEntries(Object.entries(headers).filter((entry) => entry[1] != null));
|
|
1607
|
+
}
|
|
1608
|
+
/** Same keys, same values (order-independent). */
|
|
1609
|
+
function shallowEqualRecord(a, b) {
|
|
1610
|
+
const aKeys = Object.keys(a);
|
|
1611
|
+
const bKeys = Object.keys(b);
|
|
1612
|
+
if (aKeys.length !== bKeys.length) return false;
|
|
1613
|
+
return aKeys.every((key) => a[key] === b[key]);
|
|
1614
|
+
}
|
|
1615
|
+
function isHeaderRecordInput(value) {
|
|
1616
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1617
|
+
}
|
|
1618
|
+
/**
|
|
1619
|
+
* Owns the headers source for one core. Resolution is synchronous for a
|
|
1620
|
+
* record or a sync builder, so those callers never pay an extra await.
|
|
1621
|
+
*/
|
|
1622
|
+
var HeaderSourceResolver = class {
|
|
1623
|
+
source = {};
|
|
1624
|
+
sourceGeneration = 0;
|
|
1625
|
+
snapshot = {};
|
|
1626
|
+
inFlight;
|
|
1627
|
+
constructor(onFailure) {
|
|
1628
|
+
this.onFailure = onFailure;
|
|
1629
|
+
}
|
|
1630
|
+
/** The last resolved headers. Not necessarily current for a builder. */
|
|
1631
|
+
get headers() {
|
|
1632
|
+
return this.snapshot;
|
|
1633
|
+
}
|
|
1634
|
+
/** Bumped on every accepted `setSource`, never by a new token. */
|
|
1635
|
+
get generation() {
|
|
1636
|
+
return this.sourceGeneration;
|
|
1637
|
+
}
|
|
1638
|
+
/**
|
|
1639
|
+
* Returns false when a builder with the same identity is set again, or
|
|
1640
|
+
* when a record replaces another record with equal normalized values (a
|
|
1641
|
+
* caller re-passing an equivalent literal on every re-render must not
|
|
1642
|
+
* bump the generation). A record replacing a builder, a builder replacing
|
|
1643
|
+
* a record, and a new builder function all still count as a change.
|
|
1644
|
+
*/
|
|
1645
|
+
setSource(source) {
|
|
1646
|
+
if (typeof source === "function" && source === this.source) return false;
|
|
1647
|
+
const nextSnapshot = typeof source === "function" ? {} : normalizeHeaders(source);
|
|
1648
|
+
if (typeof source !== "function" && typeof this.source !== "function" && shallowEqualRecord(nextSnapshot, this.snapshot)) return false;
|
|
1649
|
+
this.source = source;
|
|
1650
|
+
this.sourceGeneration += 1;
|
|
1651
|
+
this.inFlight = void 0;
|
|
1652
|
+
this.snapshot = nextSnapshot;
|
|
1653
|
+
return true;
|
|
1654
|
+
}
|
|
1655
|
+
resolve() {
|
|
1656
|
+
const source = this.source;
|
|
1657
|
+
if (typeof source !== "function") return this.snapshot;
|
|
1658
|
+
const generation = this.sourceGeneration;
|
|
1659
|
+
if (this.inFlight?.generation === generation) return this.inFlight.promise;
|
|
1660
|
+
let value;
|
|
1661
|
+
try {
|
|
1662
|
+
value = source();
|
|
1663
|
+
} catch (error) {
|
|
1664
|
+
throw this.fail(error);
|
|
1665
|
+
}
|
|
1666
|
+
if (!isPromiseLike(value)) return this.accept(value, generation);
|
|
1667
|
+
const promise = Promise.resolve(value).then((resolved) => this.accept(resolved, generation), (error) => {
|
|
1668
|
+
throw this.fail(error);
|
|
1669
|
+
}).finally(() => {
|
|
1670
|
+
if (this.inFlight?.promise === promise) this.inFlight = void 0;
|
|
1671
|
+
});
|
|
1672
|
+
this.inFlight = {
|
|
1673
|
+
generation,
|
|
1674
|
+
promise
|
|
1675
|
+
};
|
|
1676
|
+
return promise;
|
|
1677
|
+
}
|
|
1678
|
+
accept(value, generation) {
|
|
1679
|
+
if (!isHeaderRecordInput(value)) throw this.fail(/* @__PURE__ */ new TypeError("headers builder must return an object of header values"));
|
|
1680
|
+
const normalized = normalizeHeaders(value);
|
|
1681
|
+
if (generation === this.sourceGeneration) {
|
|
1682
|
+
if (!shallowEqualRecord(normalized, this.snapshot)) this.snapshot = normalized;
|
|
1683
|
+
return this.snapshot;
|
|
1684
|
+
}
|
|
1685
|
+
return normalized;
|
|
1686
|
+
}
|
|
1687
|
+
fail(cause) {
|
|
1688
|
+
if (cause instanceof CopilotKitHeaderResolutionError) return cause;
|
|
1689
|
+
const error = new CopilotKitHeaderResolutionError(cause);
|
|
1690
|
+
this.onFailure(error);
|
|
1691
|
+
return error;
|
|
1692
|
+
}
|
|
1693
|
+
};
|
|
1694
|
+
const PROTOCOL_HEADERS = new Set(["content-type", "accept"]);
|
|
1695
|
+
/**
|
|
1696
|
+
* Put fresh core headers on top of a request's headers, keeping the input's
|
|
1697
|
+
* shape. Core beats an agent's own headers (#5635). A site's Content-Type and
|
|
1698
|
+
* Accept are never overridden, matching every site's existing spread order.
|
|
1699
|
+
*/
|
|
1700
|
+
function ɵoverlayCoreHeaders(existing, core) {
|
|
1701
|
+
if (existing instanceof Headers) {
|
|
1702
|
+
const headers = new Headers(existing);
|
|
1703
|
+
for (const [key, value] of Object.entries(core)) {
|
|
1704
|
+
if (PROTOCOL_HEADERS.has(key.toLowerCase()) && headers.has(key)) continue;
|
|
1705
|
+
headers.set(key, value);
|
|
1706
|
+
}
|
|
1707
|
+
return headers;
|
|
1708
|
+
}
|
|
1709
|
+
const base = Array.isArray(existing) ? Object.fromEntries(existing) : { ...existing };
|
|
1710
|
+
const keyByLower = new Map(Object.keys(base).map((k) => [k.toLowerCase(), k]));
|
|
1711
|
+
for (const [key, value] of Object.entries(core)) {
|
|
1712
|
+
const existingKey = keyByLower.get(key.toLowerCase());
|
|
1713
|
+
if (existingKey !== void 0) {
|
|
1714
|
+
if (PROTOCOL_HEADERS.has(key.toLowerCase())) continue;
|
|
1715
|
+
delete base[existingKey];
|
|
1716
|
+
}
|
|
1717
|
+
base[key] = value;
|
|
1718
|
+
}
|
|
1719
|
+
return base;
|
|
1720
|
+
}
|
|
1721
|
+
/** Reject with the signal's AbortError if it aborts before `value` settles. */
|
|
1722
|
+
async function abortable(value, signal) {
|
|
1723
|
+
if (!signal || !isPromiseLike(value)) return value;
|
|
1724
|
+
if (signal.aborted) throw abortError(signal);
|
|
1725
|
+
return new Promise((resolve, reject) => {
|
|
1726
|
+
const onAbort = () => reject(abortError(signal));
|
|
1727
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
1728
|
+
Promise.resolve(value).then((v) => {
|
|
1729
|
+
signal.removeEventListener("abort", onAbort);
|
|
1730
|
+
resolve(v);
|
|
1731
|
+
}, (e) => {
|
|
1732
|
+
signal.removeEventListener("abort", onAbort);
|
|
1733
|
+
reject(e);
|
|
1734
|
+
});
|
|
1735
|
+
});
|
|
1736
|
+
}
|
|
1737
|
+
function abortError(signal) {
|
|
1738
|
+
return signal.reason instanceof Error ? signal.reason : new DOMException("The operation was aborted.", "AbortError");
|
|
1739
|
+
}
|
|
1740
|
+
/**
|
|
1741
|
+
* Add default headers (e.g. the public API key) to a source, only where the
|
|
1742
|
+
* source left the key unset or empty. The single shared replacement for the
|
|
1743
|
+
* React, Vue and Angular providers' own merges.
|
|
1744
|
+
*/
|
|
1745
|
+
function ɵwithHeaderDefaults(source, defaults) {
|
|
1746
|
+
if (Object.keys(defaults).length === 0) return source;
|
|
1747
|
+
const fill = (headers) => {
|
|
1748
|
+
const out = { ...headers };
|
|
1749
|
+
for (const [key, value] of Object.entries(defaults)) if (!out[key]) out[key] = value;
|
|
1750
|
+
return out;
|
|
1751
|
+
};
|
|
1752
|
+
if (typeof source !== "function") return fill(source);
|
|
1753
|
+
return (() => {
|
|
1754
|
+
const value = source();
|
|
1755
|
+
return isPromiseLike(value) ? Promise.resolve(value).then((resolved) => isHeaderRecordInput(resolved) ? fill(resolved) : resolved) : isHeaderRecordInput(value) ? fill(value) : value;
|
|
1756
|
+
});
|
|
1757
|
+
}
|
|
1758
|
+
|
|
1551
1759
|
//#endregion
|
|
1552
1760
|
//#region src/core/agent-registry.ts
|
|
1553
1761
|
/** Maximum wait for optional Inspector metadata before degrading to absence. */
|
|
@@ -1882,27 +2090,83 @@ var AgentRegistry = class {
|
|
|
1882
2090
|
console.warn(`Agent ${id} not found`);
|
|
1883
2091
|
}
|
|
1884
2092
|
/**
|
|
1885
|
-
*
|
|
1886
|
-
* construction-time headers (the per-agent baseline in
|
|
1887
|
-
*
|
|
1888
|
-
*
|
|
2093
|
+
* Shared core-and-own-header merge for a single agent. Captures the
|
|
2094
|
+
* agent's construction-time headers once (the per-agent baseline in
|
|
2095
|
+
* `agentOwnHeaders`), then either keeps only that baseline — a
|
|
2096
|
+
* `ProxiedCopilotRuntimeAgent`, whose core headers are added by
|
|
2097
|
+
* `ɵruntimeFetch` when each request is actually sent instead, so a key the
|
|
2098
|
+
* builder stops returning can never ride along from a stale copy baked
|
|
2099
|
+
* onto the agent (see #1937) — or merges `coreHeaders` on top of it (any
|
|
2100
|
+
* other `HttpAgent`; core wins on a key conflict, see #5635).
|
|
2101
|
+
*/
|
|
2102
|
+
applyHeaderRecordToAgent(agent, coreHeaders) {
|
|
2103
|
+
if (!this.agentOwnHeaders.has(agent)) this.agentOwnHeaders.set(agent, { ...agent.headers });
|
|
2104
|
+
const own = this.agentOwnHeaders.get(agent);
|
|
2105
|
+
if (agent instanceof ProxiedCopilotRuntimeAgent) {
|
|
2106
|
+
agent.headers = { ...own };
|
|
2107
|
+
this.applyRuntimeFetchToAgent(agent);
|
|
2108
|
+
return;
|
|
2109
|
+
}
|
|
2110
|
+
agent.headers = {
|
|
2111
|
+
...own,
|
|
2112
|
+
...coreHeaders
|
|
2113
|
+
};
|
|
2114
|
+
}
|
|
2115
|
+
/**
|
|
2116
|
+
* Apply the last resolved header snapshot to an agent, merged ON TOP of
|
|
2117
|
+
* the agent's own construction-time headers. Non-`HttpAgent` agents are
|
|
2118
|
+
* left untouched because only `HttpAgent` carries a `headers` field. See
|
|
2119
|
+
* #5635.
|
|
2120
|
+
*
|
|
2121
|
+
* Never invokes the headers builder — safe to call from anywhere (dev-only
|
|
2122
|
+
* registration helpers, a React effect that re-runs on every render)
|
|
2123
|
+
* without risking a synchronous throw or an unhandled async rejection from
|
|
2124
|
+
* a user-supplied builder. Use `prepareAgentHeadersForRun` (friends-only)
|
|
2125
|
+
* on the run/connect path, where a builder failure can be awaited and
|
|
2126
|
+
* reported once.
|
|
1889
2127
|
*/
|
|
1890
2128
|
applyHeadersToAgent(agent) {
|
|
1891
|
-
if (
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
...this.agentOwnHeaders.get(agent),
|
|
1895
|
-
...this.core.headers
|
|
1896
|
-
};
|
|
1897
|
-
}
|
|
2129
|
+
if (!ɵisHttpAgent(agent)) return;
|
|
2130
|
+
const friends = this.core;
|
|
2131
|
+
this.applyHeaderRecordToAgent(agent, friends.headers);
|
|
1898
2132
|
}
|
|
1899
2133
|
/**
|
|
1900
|
-
* Apply
|
|
2134
|
+
* Apply the last resolved header snapshot to every agent, without
|
|
2135
|
+
* triggering a builder call per agent. Used by `initialize` and
|
|
2136
|
+
* `setHeaders`; a run re-applies with fresh headers anyway (see
|
|
2137
|
+
* `prepareAgentHeadersForRun`).
|
|
1901
2138
|
*/
|
|
1902
2139
|
applyHeadersToAgents(agents) {
|
|
2140
|
+
const friends = this.core;
|
|
1903
2141
|
Object.values(agents).forEach((agent) => {
|
|
1904
|
-
this.
|
|
2142
|
+
if (ɵisHttpAgent(agent)) this.applyHeaderRecordToAgent(agent, friends.headers);
|
|
2143
|
+
});
|
|
2144
|
+
}
|
|
2145
|
+
/**
|
|
2146
|
+
* Resolve headers fresh and apply them to `agent` right before a run or
|
|
2147
|
+
* connect actually sends (#1937) — the resolving counterpart to
|
|
2148
|
+
* `applyHeadersToAgent`. Friends-only: only the run handler should call
|
|
2149
|
+
* this, since resolving can invoke a user-supplied builder that throws
|
|
2150
|
+
* synchronously or returns a rejecting promise. Resolution is synchronous
|
|
2151
|
+
* for a record or a sync builder; this returns a promise only when an
|
|
2152
|
+
* async builder must be awaited first, and callers that need the write to
|
|
2153
|
+
* have landed before continuing must await a returned promise.
|
|
2154
|
+
*
|
|
2155
|
+
* A `ProxiedCopilotRuntimeAgent` never invokes the builder here: its core
|
|
2156
|
+
* headers are added by `ɵruntimeFetch` at send time instead, so only its
|
|
2157
|
+
* own headers are (re)applied.
|
|
2158
|
+
*/
|
|
2159
|
+
prepareAgentHeadersForRun(agent) {
|
|
2160
|
+
if (!ɵisHttpAgent(agent)) return;
|
|
2161
|
+
if (agent instanceof ProxiedCopilotRuntimeAgent) {
|
|
2162
|
+
this.applyHeaderRecordToAgent(agent, {});
|
|
2163
|
+
return;
|
|
2164
|
+
}
|
|
2165
|
+
const resolved = this.core.resolveHeaders();
|
|
2166
|
+
if (isPromiseLike(resolved)) return Promise.resolve(resolved).then((headers) => {
|
|
2167
|
+
this.applyHeaderRecordToAgent(agent, headers);
|
|
1905
2168
|
});
|
|
2169
|
+
this.applyHeaderRecordToAgent(agent, resolved);
|
|
1906
2170
|
}
|
|
1907
2171
|
/**
|
|
1908
2172
|
* Apply current credentials to an agent
|
|
@@ -1963,6 +2227,13 @@ var AgentRegistry = class {
|
|
|
1963
2227
|
}
|
|
1964
2228
|
createRuntimeFetch() {
|
|
1965
2229
|
if (!this.runtimeFetch) this.runtimeFetch = (async (input, init) => {
|
|
2230
|
+
const friends = this.core;
|
|
2231
|
+
const coreHeaders = await abortable(friends.resolveHeaders(), init?.signal);
|
|
2232
|
+
const requestHeaders = ɵoverlayCoreHeaders(init?.headers ?? (input instanceof Request ? input.headers : void 0), coreHeaders);
|
|
2233
|
+
init = {
|
|
2234
|
+
...init,
|
|
2235
|
+
headers: requestHeaders
|
|
2236
|
+
};
|
|
1966
2237
|
const meta = () => runtimeRequestMeta(init);
|
|
1967
2238
|
const watchdog = this.armRuntimeRequestWatchdog(meta());
|
|
1968
2239
|
try {
|
|
@@ -2032,7 +2303,15 @@ var AgentRegistry = class {
|
|
|
2032
2303
|
const headersGeneration = this.inspectorMetadataHeadersGeneration;
|
|
2033
2304
|
const credentialsGeneration = this.inspectorMetadataCredentialsGeneration;
|
|
2034
2305
|
const friends = this.core;
|
|
2035
|
-
|
|
2306
|
+
let headers;
|
|
2307
|
+
try {
|
|
2308
|
+
const resolved = friends.resolveHeaders();
|
|
2309
|
+
headers = { ...isPromiseLike(resolved) ? await resolved : resolved };
|
|
2310
|
+
} catch {
|
|
2311
|
+
if (generation === this.inspectorMetadataGeneration) this.setInspectorMetadata(void 0);
|
|
2312
|
+
return;
|
|
2313
|
+
}
|
|
2314
|
+
if (generation !== this.inspectorMetadataGeneration) return;
|
|
2036
2315
|
const credentials = friends.credentials;
|
|
2037
2316
|
const abortController = new AbortController();
|
|
2038
2317
|
this.inspectorMetadataAbortController = abortController;
|
|
@@ -2193,6 +2472,10 @@ var AgentRegistry = class {
|
|
|
2193
2472
|
async markRuntimeUnreachable(error) {
|
|
2194
2473
|
this.setRuntimeConnectionStatus(CopilotKitCoreRuntimeConnectionStatus.Error);
|
|
2195
2474
|
await this.notifyRuntimeStatusChanged(CopilotKitCoreRuntimeConnectionStatus.Error);
|
|
2475
|
+
if (isHeaderResolutionError(error)) {
|
|
2476
|
+
logger.warn(`Could not resolve request headers for the identification request (${this._runtimeUrl}/info). Check the headers builder passed to CopilotKit.`);
|
|
2477
|
+
return;
|
|
2478
|
+
}
|
|
2196
2479
|
const runtimeStatus = isRuntimeInfoRequestError(error) ? error.runtimeInfoStatus : void 0;
|
|
2197
2480
|
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.`);
|
|
2198
2481
|
await this.core.emitError({
|
|
@@ -2453,9 +2736,10 @@ var AgentRegistry = class {
|
|
|
2453
2736
|
}
|
|
2454
2737
|
}
|
|
2455
2738
|
async fetchRuntimeInfo(runtimeUrl, runtimeTransport, signal) {
|
|
2456
|
-
const
|
|
2457
|
-
const credentials =
|
|
2458
|
-
const
|
|
2739
|
+
const friends = this.core;
|
|
2740
|
+
const credentials = friends.credentials;
|
|
2741
|
+
const resolved = friends.resolveHeaders();
|
|
2742
|
+
const headers = { ...isPromiseLike(resolved) ? await abortable(resolved, signal) : resolved };
|
|
2459
2743
|
if (runtimeTransport === "single") return {
|
|
2460
2744
|
runtimeInfo: await this.fetchRuntimeInfoSingle(this.singleEndpointUrlFor(runtimeUrl), headers, credentials, signal),
|
|
2461
2745
|
resolvedTransport: "single"
|
|
@@ -2743,18 +3027,19 @@ var SuggestionEngine = class {
|
|
|
2743
3027
|
const seededState = JSON.parse(JSON.stringify(suggestionsConsumerAgent.state ?? {}));
|
|
2744
3028
|
const useStateless = this.core.suggestions === true && this.core.runtimeTransport !== "single";
|
|
2745
3029
|
let suggestionAgent;
|
|
3030
|
+
let statelessAgent;
|
|
2746
3031
|
if (useStateless) {
|
|
2747
3032
|
const suggestUrl = `${this.core.runtimeUrl}/agent/${encodeURIComponent(resolvedProviderAgentId)}/suggest`;
|
|
2748
3033
|
const credentials = this.core.credentials;
|
|
2749
|
-
|
|
3034
|
+
statelessAgent = new HttpAgent({
|
|
2750
3035
|
agentId: resolvedProviderAgentId,
|
|
2751
3036
|
url: suggestUrl,
|
|
2752
|
-
headers: { ...this.core.headers },
|
|
2753
3037
|
...credentials ? { fetch: (url, requestInit) => fetch(url, {
|
|
2754
3038
|
...requestInit,
|
|
2755
3039
|
credentials
|
|
2756
3040
|
}) } : {}
|
|
2757
3041
|
});
|
|
3042
|
+
suggestionAgent = statelessAgent;
|
|
2758
3043
|
} else {
|
|
2759
3044
|
suggestionAgent = suggestionsProviderAgent.clone();
|
|
2760
3045
|
if (suggestionAgent instanceof ProxiedCopilotRuntimeAgent) suggestionAgent.messageFilter = void 0;
|
|
@@ -2767,6 +3052,9 @@ var SuggestionEngine = class {
|
|
|
2767
3052
|
suggestionAgent.abortRun();
|
|
2768
3053
|
} };
|
|
2769
3054
|
this._runningSuggestions[consumerAgentId] = [...this._runningSuggestions[consumerAgentId] ?? [], runHandle];
|
|
3055
|
+
if (statelessAgent) statelessAgent.headers = { ...await this.core.resolveHeaders() };
|
|
3056
|
+
else await this.core.prepareAgentHeadersForRun(suggestionAgent);
|
|
3057
|
+
if (aborted) return;
|
|
2770
3058
|
suggestionAgent.addMessage({
|
|
2771
3059
|
id: suggestionId,
|
|
2772
3060
|
role: "user",
|
|
@@ -3513,7 +3801,8 @@ var RunHandler = class {
|
|
|
3513
3801
|
if (typeof cursorAware.clearReconnectCursor === "function") cursorAware.clearReconnectCursor(incomingThreadId);
|
|
3514
3802
|
}
|
|
3515
3803
|
}
|
|
3516
|
-
this._internal.
|
|
3804
|
+
const headersApplied = this._internal.prepareAgentHeadersForRun(agent);
|
|
3805
|
+
if (headersApplied) await headersApplied;
|
|
3517
3806
|
await this._internal.notifySubscribers((subscriber) => subscriber.onAgentRunStarted?.({
|
|
3518
3807
|
copilotkit: this.core,
|
|
3519
3808
|
agent
|
|
@@ -3526,7 +3815,7 @@ var RunHandler = class {
|
|
|
3526
3815
|
forwardedProps: this._internal.properties,
|
|
3527
3816
|
tools: this.buildFrontendTools(agent.agentId),
|
|
3528
3817
|
context: this._internal.getContextForAgent(agent.agentId)
|
|
3529
|
-
}, this.createAgentErrorSubscriber(agent));
|
|
3818
|
+
}, this.createAgentErrorSubscriber(agent, "connect"));
|
|
3530
3819
|
if (this._connectionGenerations.get(agent) !== connection || (agent.threadId ?? null) !== incomingThreadId) return runAgentResult;
|
|
3531
3820
|
const controller = new AbortController();
|
|
3532
3821
|
const replay = this._interactionAbortControllers.get(agent) ?? {
|
|
@@ -3577,7 +3866,16 @@ var RunHandler = class {
|
|
|
3577
3866
|
*/
|
|
3578
3867
|
async runAgent({ agent, forwardedProps, resume, runId }, continuationHandoff) {
|
|
3579
3868
|
if (agent.agentId) this._internal.suggestionEngine.clearSuggestions(agent.agentId);
|
|
3580
|
-
|
|
3869
|
+
try {
|
|
3870
|
+
const headersApplied = this._internal.prepareAgentHeadersForRun(agent);
|
|
3871
|
+
if (headersApplied) await headersApplied;
|
|
3872
|
+
} catch {
|
|
3873
|
+
continuationHandoff?.cancel();
|
|
3874
|
+
return {
|
|
3875
|
+
result: void 0,
|
|
3876
|
+
newMessages: []
|
|
3877
|
+
};
|
|
3878
|
+
}
|
|
3581
3879
|
if (agent.detachActiveRun) try {
|
|
3582
3880
|
await agent.detachActiveRun();
|
|
3583
3881
|
} catch (error) {
|
|
@@ -3608,7 +3906,7 @@ var RunHandler = class {
|
|
|
3608
3906
|
this._runDepth++;
|
|
3609
3907
|
try {
|
|
3610
3908
|
let logicalRunId = resumedRunId ?? runId;
|
|
3611
|
-
const agentSubscriber = this.createAgentErrorSubscriber(agent);
|
|
3909
|
+
const agentSubscriber = this.createAgentErrorSubscriber(agent, "run");
|
|
3612
3910
|
let started = false;
|
|
3613
3911
|
const onRunStartedEvent = agentSubscriber.onRunStartedEvent;
|
|
3614
3912
|
const onRunInitialized = agentSubscriber.onRunInitialized;
|
|
@@ -4113,7 +4411,7 @@ var RunHandler = class {
|
|
|
4113
4411
|
/**
|
|
4114
4412
|
* Create an agent error subscriber
|
|
4115
4413
|
*/
|
|
4116
|
-
createAgentErrorSubscriber(agent) {
|
|
4414
|
+
createAgentErrorSubscriber(agent, stream) {
|
|
4117
4415
|
const emitAgentError = async (error, code, extraContext = {}) => {
|
|
4118
4416
|
const context = { ...extraContext };
|
|
4119
4417
|
if (agent.agentId) context.agentId = agent.agentId;
|
|
@@ -4136,7 +4434,8 @@ var RunHandler = class {
|
|
|
4136
4434
|
await emitAgentError(rawError, CopilotKitCoreErrorCode.AGENT_RUN_ERROR_EVENT, {
|
|
4137
4435
|
source: "onRunErrorEvent",
|
|
4138
4436
|
event,
|
|
4139
|
-
runtimeErrorCode: event?.code
|
|
4437
|
+
runtimeErrorCode: event?.code,
|
|
4438
|
+
phase: stream === "run" ? "live" : ɵgetConnectRunErrorPhase(event)
|
|
4140
4439
|
});
|
|
4141
4440
|
}
|
|
4142
4441
|
};
|
|
@@ -4744,6 +5043,9 @@ var TrajectoryConnection = class {
|
|
|
4744
5043
|
stop() {
|
|
4745
5044
|
const session = this.session;
|
|
4746
5045
|
if (!session) return;
|
|
5046
|
+
const collector = session.collector;
|
|
5047
|
+
session.collector = void 0;
|
|
5048
|
+
collector?.stop();
|
|
4747
5049
|
if (session.ready && session.connection) this.flush(session, session.connection);
|
|
4748
5050
|
this.end(session, {
|
|
4749
5051
|
status: "error",
|
|
@@ -4843,18 +5145,19 @@ var TrajectoryConnection = class {
|
|
|
4843
5145
|
} finally {
|
|
4844
5146
|
if (socket) {
|
|
4845
5147
|
socket.off(connection.socketRefs);
|
|
5148
|
+
socket.connect = () => void 0;
|
|
4846
5149
|
socket.disconnect();
|
|
4847
5150
|
}
|
|
4848
5151
|
}
|
|
4849
5152
|
}
|
|
4850
5153
|
fail(session, connection, code, retryable = true) {
|
|
4851
5154
|
if (!this.current(session, connection)) return;
|
|
4852
|
-
session.collector?.stop();
|
|
4853
|
-
session.collector = void 0;
|
|
4854
5155
|
if (session.ready && session.started) session.promise = new Promise((resolve) => {
|
|
4855
5156
|
session.resolve = resolve;
|
|
4856
5157
|
});
|
|
4857
5158
|
session.ready = false;
|
|
5159
|
+
session.collector?.stop();
|
|
5160
|
+
session.collector = void 0;
|
|
4858
5161
|
this.discardQueue(session);
|
|
4859
5162
|
session.linkedThreads.clear();
|
|
4860
5163
|
for (const pending of connection.pending) pending.finish("PERSISTENCE_UNKNOWN");
|
|
@@ -4898,12 +5201,15 @@ var TrajectoryConnection = class {
|
|
|
4898
5201
|
if (!this.current(session, connection)) return;
|
|
4899
5202
|
}
|
|
4900
5203
|
const rest = transport === "rest";
|
|
5204
|
+
const resolved = this.core.resolveHeaders();
|
|
5205
|
+
const coreHeaders = isPromiseLike(resolved) ? await abortable(resolved, connection.abort.signal) : resolved;
|
|
5206
|
+
if (!this.current(session, connection)) return;
|
|
4901
5207
|
const response = await fetch(rest ? `${runtimeUrl}/trajectory/${encodeURIComponent(session.trajectoryId)}/connect` : this.core.ɵruntimeEndpointUrl ?? runtimeUrl, {
|
|
4902
5208
|
method: "POST",
|
|
4903
5209
|
redirect: "error",
|
|
4904
5210
|
signal: connection.abort.signal,
|
|
4905
5211
|
headers: {
|
|
4906
|
-
...
|
|
5212
|
+
...coreHeaders,
|
|
4907
5213
|
"Content-Type": "application/json"
|
|
4908
5214
|
},
|
|
4909
5215
|
credentials: this.core.credentials,
|
|
@@ -5012,7 +5318,11 @@ var TrajectoryConnection = class {
|
|
|
5012
5318
|
return connection.socket?.isConnected() === true && connection.channel?.state === "joined";
|
|
5013
5319
|
}
|
|
5014
5320
|
send(session, connection, event) {
|
|
5015
|
-
if (!this.current(session, connection)
|
|
5321
|
+
if (!this.current(session, connection)) return;
|
|
5322
|
+
if (!session.ready) {
|
|
5323
|
+
this.addDropped(session, 1, false);
|
|
5324
|
+
return;
|
|
5325
|
+
}
|
|
5016
5326
|
if (!this.connected(connection)) {
|
|
5017
5327
|
this.addDropped(session, 1);
|
|
5018
5328
|
this.fail(session, connection, "CONNECTION_LOST");
|
|
@@ -5181,7 +5491,7 @@ var LearningBridge = class {
|
|
|
5181
5491
|
});
|
|
5182
5492
|
}
|
|
5183
5493
|
if (config.sink === void 0) {
|
|
5184
|
-
if (options.learningContainerIds !== void 0) console.warn("[CopilotKit] learningContainerIds is supported only with a custom sink. Authenticated Trajectory capture
|
|
5494
|
+
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.");
|
|
5185
5495
|
this.stopLegacy();
|
|
5186
5496
|
return this.connection.start(options.trajectoryId, config);
|
|
5187
5497
|
}
|
|
@@ -6490,6 +6800,12 @@ let CopilotKitCoreErrorCode = /* @__PURE__ */ function(CopilotKitCoreErrorCode)
|
|
|
6490
6800
|
CopilotKitCoreErrorCode["AGENT_CONNECT_FAILED"] = "agent_connect_failed";
|
|
6491
6801
|
CopilotKitCoreErrorCode["AGENT_RUN_FAILED"] = "agent_run_failed";
|
|
6492
6802
|
CopilotKitCoreErrorCode["AGENT_RUN_FAILED_EVENT"] = "agent_run_failed_event";
|
|
6803
|
+
/**
|
|
6804
|
+
* An agent emitted RUN_ERROR. `context.phase` (`RunErrorPhase`) is
|
|
6805
|
+
* `"replay"` when the error belongs to stored thread history replayed on
|
|
6806
|
+
* connect, `"live"` when the run is happening now, and `"unknown"` when the
|
|
6807
|
+
* transport cannot tell. Show a live-failure notice only for `"live"`.
|
|
6808
|
+
*/
|
|
6493
6809
|
CopilotKitCoreErrorCode["AGENT_RUN_ERROR_EVENT"] = "agent_run_error_event";
|
|
6494
6810
|
CopilotKitCoreErrorCode["TOOL_ARGUMENT_PARSE_FAILED"] = "tool_argument_parse_failed";
|
|
6495
6811
|
CopilotKitCoreErrorCode["TOOL_HANDLER_FAILED"] = "tool_handler_failed";
|
|
@@ -6518,6 +6834,11 @@ let CopilotKitCoreErrorCode = /* @__PURE__ */ function(CopilotKitCoreErrorCode)
|
|
|
6518
6834
|
CopilotKitCoreErrorCode["TRANSCRIPTION_AUTH_FAILED"] = "transcription_auth_failed";
|
|
6519
6835
|
CopilotKitCoreErrorCode["TRANSCRIPTION_NETWORK_ERROR"] = "transcription_network_error";
|
|
6520
6836
|
CopilotKitCoreErrorCode["SUBSCRIBER_CALLBACK_FAILED"] = "subscriber_callback_failed";
|
|
6837
|
+
/**
|
|
6838
|
+
* The `headers` builder threw, rejected, or returned something other than
|
|
6839
|
+
* an object. The request was not sent. `error.cause` is the builder's error.
|
|
6840
|
+
*/
|
|
6841
|
+
CopilotKitCoreErrorCode["HEADER_RESOLUTION_FAILED"] = "header_resolution_failed";
|
|
6521
6842
|
return CopilotKitCoreErrorCode;
|
|
6522
6843
|
}({});
|
|
6523
6844
|
/**
|
|
@@ -6540,17 +6861,8 @@ let CopilotKitCoreRuntimeConnectionStatus = /* @__PURE__ */ function(CopilotKitC
|
|
|
6540
6861
|
CopilotKitCoreRuntimeConnectionStatus["Error"] = "error";
|
|
6541
6862
|
return CopilotKitCoreRuntimeConnectionStatus;
|
|
6542
6863
|
}({});
|
|
6543
|
-
/**
|
|
6544
|
-
* Normalize a header map to the internal invariant: a `Record<string, string>`
|
|
6545
|
-
* with no `null`/`undefined` values. Entries whose value is `null`/`undefined`
|
|
6546
|
-
* are dropped (this is how a header is cleared). Shared by the constructor and
|
|
6547
|
-
* `setHeaders` so both write paths into `_headers` enforce the same invariant.
|
|
6548
|
-
*/
|
|
6549
|
-
function normalizeHeaders(headers) {
|
|
6550
|
-
return Object.fromEntries(Object.entries(headers).filter((entry) => entry[1] != null));
|
|
6551
|
-
}
|
|
6552
6864
|
var CopilotKitCore = class {
|
|
6553
|
-
|
|
6865
|
+
headerSource;
|
|
6554
6866
|
_credentials;
|
|
6555
6867
|
_messageFilter;
|
|
6556
6868
|
_properties;
|
|
@@ -6581,7 +6893,14 @@ var CopilotKitCore = class {
|
|
|
6581
6893
|
*/
|
|
6582
6894
|
previousAgentIds = /* @__PURE__ */ new Set();
|
|
6583
6895
|
constructor({ runtimeUrl, runtimeTransport = "auto", deferInitialConnection = false, headers = {}, credentials, messageFilter, properties = {}, agents__unsafe_dev_only = {}, tools = [], suggestionsConfig = [], debug, learning }) {
|
|
6584
|
-
this.
|
|
6896
|
+
this.headerSource = new HeaderSourceResolver((error) => {
|
|
6897
|
+
this.emitError({
|
|
6898
|
+
error,
|
|
6899
|
+
code: CopilotKitCoreErrorCode.HEADER_RESOLUTION_FAILED,
|
|
6900
|
+
context: { source: "headers" }
|
|
6901
|
+
});
|
|
6902
|
+
});
|
|
6903
|
+
this.headerSource.setSource(headers);
|
|
6585
6904
|
this._credentials = credentials;
|
|
6586
6905
|
this._messageFilter = messageFilter;
|
|
6587
6906
|
this._properties = properties;
|
|
@@ -6639,6 +6958,7 @@ var CopilotKitCore = class {
|
|
|
6639
6958
|
* Internal method used by delegate classes to emit errors
|
|
6640
6959
|
*/
|
|
6641
6960
|
async emitError({ error, code, context = {} }) {
|
|
6961
|
+
if (code !== CopilotKitCoreErrorCode.HEADER_RESOLUTION_FAILED && isHeaderResolutionError(error)) return;
|
|
6642
6962
|
await this.notifySubscribers((subscriber) => subscriber.onError?.({
|
|
6643
6963
|
copilotkit: this,
|
|
6644
6964
|
error,
|
|
@@ -6698,8 +7018,24 @@ var CopilotKitCore = class {
|
|
|
6698
7018
|
get runtimeVersion() {
|
|
6699
7019
|
return this.agentRegistry.runtimeVersion;
|
|
6700
7020
|
}
|
|
7021
|
+
/**
|
|
7022
|
+
* The last resolved headers. With a builder this is the value from the most
|
|
7023
|
+
* recent request, not necessarily current; call `resolveHeaders()` for that.
|
|
7024
|
+
*/
|
|
6701
7025
|
get headers() {
|
|
6702
|
-
return this.
|
|
7026
|
+
return this.headerSource.headers;
|
|
7027
|
+
}
|
|
7028
|
+
/**
|
|
7029
|
+
* Resolve the current headers. Synchronous for a record or a sync builder,
|
|
7030
|
+
* a promise for an async builder. Concurrent calls share one builder call.
|
|
7031
|
+
* The returned object is shared; copy it before modifying.
|
|
7032
|
+
*/
|
|
7033
|
+
resolveHeaders() {
|
|
7034
|
+
return this.headerSource.resolve();
|
|
7035
|
+
}
|
|
7036
|
+
/** Changes only on `setHeaders` or a new source, never on a new token. */
|
|
7037
|
+
get ɵheadersGeneration() {
|
|
7038
|
+
return this.headerSource.generation;
|
|
6703
7039
|
}
|
|
6704
7040
|
get credentials() {
|
|
6705
7041
|
return this._credentials;
|
|
@@ -6840,9 +7176,17 @@ var CopilotKitCore = class {
|
|
|
6840
7176
|
* with, set it at the provider/core level instead of on the agent, or update
|
|
6841
7177
|
* it on the agent directly. The clear-on-logout pattern above is for
|
|
6842
7178
|
* core-level headers.
|
|
7179
|
+
*
|
|
7180
|
+
* Pass a function to have headers evaluated when each request is sent
|
|
7181
|
+
* (sync or async). Setting the same function again is a no-op. A new token
|
|
7182
|
+
* from the builder doesn't notify `onHeadersChanged`. On a user switch,
|
|
7183
|
+
* call `setHeaders` with a NEW function (or a record), or remount.
|
|
7184
|
+
*
|
|
7185
|
+
* Passing a record equal (by value) to the currently applied record is
|
|
7186
|
+
* also a no-op — safe to call on every render with a fresh object literal.
|
|
6843
7187
|
*/
|
|
6844
7188
|
setHeaders(headers) {
|
|
6845
|
-
this.
|
|
7189
|
+
if (!this.headerSource.setSource(headers)) return;
|
|
6846
7190
|
if (this._memoryStore) this.syncMemoryContext();
|
|
6847
7191
|
this.agentRegistry.applyHeadersToAgents(this.agentRegistry.agents);
|
|
6848
7192
|
this.agentRegistry.handleHeadersChanged();
|
|
@@ -6989,8 +7333,8 @@ var CopilotKitCore = class {
|
|
|
6989
7333
|
return this.learningBridge.registerOpenThread(params);
|
|
6990
7334
|
}
|
|
6991
7335
|
/**
|
|
6992
|
-
* Re-apply the
|
|
6993
|
-
* AgentRegistry). Core headers are merged on top of the agent's own
|
|
7336
|
+
* Re-apply the last resolved header snapshot to a single agent (delegated
|
|
7337
|
+
* to AgentRegistry). Core headers are merged on top of the agent's own
|
|
6994
7338
|
* construction-time headers rather than replacing them, so headers
|
|
6995
7339
|
* configured directly on an `HttpAgent` (e.g. an `Authorization` for a
|
|
6996
7340
|
* self-hosted backend) survive header updates instead of being silently
|
|
@@ -7001,11 +7345,31 @@ var CopilotKitCore = class {
|
|
|
7001
7345
|
* afterwards is `setHeaders` (which re-applies to every agent), not mutating
|
|
7002
7346
|
* `agent.headers` directly — a direct mutation is overwritten on the next
|
|
7003
7347
|
* re-apply.
|
|
7348
|
+
*
|
|
7349
|
+
* A `ProxiedCopilotRuntimeAgent` keeps only its own construction-time
|
|
7350
|
+
* headers here — core headers are added by `ɵruntimeFetch` when each
|
|
7351
|
+
* request is sent (see #1937), so `agent.headers` never carries a stale
|
|
7352
|
+
* copy of a core header the builder has since stopped returning.
|
|
7353
|
+
*
|
|
7354
|
+
* Never invokes the headers builder (unlike the run/connect path's
|
|
7355
|
+
* internal `prepareAgentHeadersForRun`): safe to call from a dev-only
|
|
7356
|
+
* registration helper or a React effect that re-runs on every render
|
|
7357
|
+
* without risking a synchronous throw or an unhandled async rejection from
|
|
7358
|
+
* a user-supplied builder.
|
|
7004
7359
|
*/
|
|
7005
7360
|
applyHeadersToAgent(agent) {
|
|
7006
7361
|
this.agentRegistry.applyHeadersToAgent(agent);
|
|
7007
7362
|
}
|
|
7008
7363
|
/**
|
|
7364
|
+
* Resolve headers fresh and apply them to `agent` right before a run or
|
|
7365
|
+
* connect actually sends (#1937). Friends-only (delegated to
|
|
7366
|
+
* AgentRegistry) — the run handler is the sole caller, since resolving can
|
|
7367
|
+
* invoke a user-supplied builder that throws or rejects.
|
|
7368
|
+
*/
|
|
7369
|
+
prepareAgentHeadersForRun(agent) {
|
|
7370
|
+
return this.agentRegistry.prepareAgentHeadersForRun(agent);
|
|
7371
|
+
}
|
|
7372
|
+
/**
|
|
7009
7373
|
* Context management (delegated to ContextStore).
|
|
7010
7374
|
* Pass `agentIds` to restrict the entry to runs of specific agents;
|
|
7011
7375
|
* omit it for context every agent should receive.
|
|
@@ -7065,16 +7429,20 @@ var CopilotKitCore = class {
|
|
|
7065
7429
|
/**
|
|
7066
7430
|
* Pushes the current runtime wiring into the memory store. When the runtime
|
|
7067
7431
|
* is connected and both the intelligence WebSocket URL and runtime URL are
|
|
7068
|
-
* available, the store receives a context (runtime URL, WebSocket URL
|
|
7069
|
-
*
|
|
7070
|
-
*
|
|
7432
|
+
* available, the store receives a context (runtime URL, WebSocket URL);
|
|
7433
|
+
* otherwise its context is cleared. No-op when the store has not been
|
|
7434
|
+
* created yet.
|
|
7435
|
+
*
|
|
7436
|
+
* Headers are deliberately NOT part of this context: the store's `fetch` is
|
|
7437
|
+
* `ɵruntimeFetch` (see `ensureMemoryStore`), which already resolves and
|
|
7438
|
+
* overlays the current core headers at send time (#1937) — a header
|
|
7439
|
+
* snapshot copied here would go stale between context syncs.
|
|
7071
7440
|
*/
|
|
7072
7441
|
syncMemoryContext() {
|
|
7073
7442
|
if (!this._memoryStore) return;
|
|
7074
7443
|
if (this.runtimeConnectionStatus === CopilotKitCoreRuntimeConnectionStatus.Connected && this.intelligence?.wsUrl && this.runtimeUrl) this._memoryStore.setContext({
|
|
7075
7444
|
runtimeUrl: this.runtimeUrl,
|
|
7076
|
-
wsUrl: this.intelligence.wsUrl
|
|
7077
|
-
headers: { ...this.headers }
|
|
7445
|
+
wsUrl: this.intelligence.wsUrl
|
|
7078
7446
|
});
|
|
7079
7447
|
else this._memoryStore.setContext(null);
|
|
7080
7448
|
}
|
|
@@ -8499,5 +8867,5 @@ function onInspectorViewThreadResult(handler) {
|
|
|
8499
8867
|
}
|
|
8500
8868
|
|
|
8501
8869
|
//#endregion
|
|
8502
|
-
export { AgentRegistry, AgentThreadLockedError, ContextStore, CopilotKitCore, CopilotKitCoreErrorCode, CopilotKitCoreRuntimeConnectionStatus, INSPECTOR_THREAD_BRIDGE_PLUGIN_ID, IntelligenceAgent, MEMORY_ERROR_REGISTRY, MemoryError, ProxiedCopilotRuntimeAgent, RunHandler, StateManager, SuggestionEngine, ToolCallStatus, WebMCPRegistry, completePartialMarkdown, createActionGroup, createEffect, createInspectorThreadRequestId, createReducer, createSelector, createStore, emitInspectorActiveThread, emitInspectorStopViewing, emitInspectorViewThread, emitInspectorViewThreadResult, empty, ensureObjectArgs, getWebMCPModelContext, isAbortError, isInspectorThreadBridgeEnabled, isRunCompletionAware, ofType, on, onInspectorActiveThread, onInspectorStopViewing, onInspectorViewThread, onInspectorViewThreadResult, parseToolArguments, props, select, ɵCOPILOTKIT_FEATURES, ɵInterruptState, ɵMAX_SOCKET_RETRIES, ɵRUNTIME_PROBE_TIMEOUT_MS, ɵTHREAD_REQUEST_TIMEOUT_MS, createMemoryStore as ɵcreateMemoryStore, ɵcreateThreadSelectors, createThreadStore as ɵcreateThreadStore, ɵisCopilotKitFeature, ɵisHttpAgent, isRetryableStatus as ɵisRetryableMemoryStatus, ɵjoinPhoenixChannel$, ɵmapMemoryMetadataEvent, ɵmemoryAdapterEvents, ɵmemoryDomainEvents, ɵmemoryReducer, ɵmemoryRestEvents, ɵobservePhoenixEvent$, ɵobservePhoenixJoinOutcome$, ɵobservePhoenixSocketHealth$, ɵobservePhoenixSocketSignals$, ɵphoenixChannel$, ɵphoenixSocket$, ɵselectFetchMoreError, ɵselectHasNextPage, ɵselectIsFetchingNextPage, ɵselectIsMutating, ɵselectMemories, ɵselectMemoriesAvailable, ɵselectMemoriesError, ɵselectMemoriesIsLoading, ɵselectMemoriesIsMutating, ɵselectMemoriesRealtimeStatus, ɵselectThreads, ɵselectThreadsError, ɵselectThreadsIsLoading, ɵthreadAdapterEvents };
|
|
8870
|
+
export { AgentRegistry, AgentThreadLockedError, ContextStore, CopilotKitCore, CopilotKitCoreErrorCode, CopilotKitCoreRuntimeConnectionStatus, CopilotKitHeaderResolutionError, INSPECTOR_THREAD_BRIDGE_PLUGIN_ID, IntelligenceAgent, IntelligenceReplayFailedError, MEMORY_ERROR_REGISTRY, MemoryError, ProxiedCopilotRuntimeAgent, RunHandler, StateManager, SuggestionEngine, ToolCallStatus, WebMCPRegistry, completePartialMarkdown, createActionGroup, createEffect, createInspectorThreadRequestId, createReducer, createSelector, createStore, emitInspectorActiveThread, emitInspectorStopViewing, emitInspectorViewThread, emitInspectorViewThreadResult, empty, ensureObjectArgs, getWebMCPModelContext, isAbortError, isInspectorThreadBridgeEnabled, isRunCompletionAware, ofType, on, onInspectorActiveThread, onInspectorStopViewing, onInspectorViewThread, onInspectorViewThreadResult, parseToolArguments, props, select, ɵCOPILOTKIT_FEATURES, ɵInterruptState, ɵMAX_SOCKET_RETRIES, ɵRUNTIME_PROBE_TIMEOUT_MS, ɵTHREAD_REQUEST_TIMEOUT_MS, createMemoryStore as ɵcreateMemoryStore, ɵcreateThreadSelectors, createThreadStore as ɵcreateThreadStore, ɵisCopilotKitFeature, ɵisHttpAgent, isRetryableStatus as ɵisRetryableMemoryStatus, ɵjoinPhoenixChannel$, ɵmapMemoryMetadataEvent, ɵmemoryAdapterEvents, ɵmemoryDomainEvents, ɵmemoryReducer, ɵmemoryRestEvents, ɵobservePhoenixEvent$, ɵobservePhoenixJoinOutcome$, ɵobservePhoenixSocketHealth$, ɵobservePhoenixSocketSignals$, ɵphoenixChannel$, ɵphoenixSocket$, ɵselectFetchMoreError, ɵselectHasNextPage, ɵselectIsFetchingNextPage, ɵselectIsMutating, ɵselectMemories, ɵselectMemoriesAvailable, ɵselectMemoriesError, ɵselectMemoriesIsLoading, ɵselectMemoriesIsMutating, ɵselectMemoriesRealtimeStatus, ɵselectThreads, ɵselectThreadsError, ɵselectThreadsIsLoading, ɵthreadAdapterEvents, ɵwithHeaderDefaults };
|
|
8503
8871
|
//# sourceMappingURL=index.mjs.map
|