@copilotkit/core 1.56.5-canary.1777972218 → 1.57.0
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 +49 -120
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +83 -122
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +82 -121
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +49 -120
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +56 -122
- package/dist/index.umd.js.map +1 -1
- package/package.json +2 -2
package/dist/index.umd.js
CHANGED
|
@@ -602,11 +602,10 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
602
602
|
var _ProxiedCopilotRuntimeAgent_brand = /* @__PURE__ */ new WeakSet();
|
|
603
603
|
var ProxiedCopilotRuntimeAgent = class ProxiedCopilotRuntimeAgent extends _ag_ui_client.HttpAgent {
|
|
604
604
|
constructor(config) {
|
|
605
|
-
var _config$transport, _ref, _config$
|
|
605
|
+
var _config$transport, _ref, _config$agentId, _config$runtimeMode;
|
|
606
606
|
const normalizedRuntimeUrl = config.runtimeUrl ? config.runtimeUrl.replace(/\/$/, "") : void 0;
|
|
607
607
|
const transport = (_config$transport = config.transport) !== null && _config$transport !== void 0 ? _config$transport : "auto";
|
|
608
|
-
const
|
|
609
|
-
const runUrl = transport === "single" ? (_ref2 = normalizedRuntimeUrl !== null && normalizedRuntimeUrl !== void 0 ? normalizedRuntimeUrl : config.runtimeUrl) !== null && _ref2 !== void 0 ? _ref2 : "" : `${normalizedRuntimeUrl !== null && normalizedRuntimeUrl !== void 0 ? normalizedRuntimeUrl : config.runtimeUrl}/agent/${encodeURIComponent(routedId)}/run`;
|
|
608
|
+
const runUrl = transport === "single" ? (_ref = normalizedRuntimeUrl !== null && normalizedRuntimeUrl !== void 0 ? normalizedRuntimeUrl : config.runtimeUrl) !== null && _ref !== void 0 ? _ref : "" : `${normalizedRuntimeUrl !== null && normalizedRuntimeUrl !== void 0 ? normalizedRuntimeUrl : config.runtimeUrl}/agent/${encodeURIComponent((_config$agentId = config.agentId) !== null && _config$agentId !== void 0 ? _config$agentId : "")}/run`;
|
|
610
609
|
if (!runUrl) throw new Error("ProxiedCopilotRuntimeAgent requires a runtimeUrl when transport is set to 'single'.");
|
|
611
610
|
super({
|
|
612
611
|
...config,
|
|
@@ -615,7 +614,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
615
614
|
_classPrivateMethodInitSpec(this, _ProxiedCopilotRuntimeAgent_brand);
|
|
616
615
|
_defineProperty(this, "runtimeUrl", void 0);
|
|
617
616
|
_defineProperty(this, "credentials", void 0);
|
|
618
|
-
_defineProperty(this, "remoteAgentId", void 0);
|
|
619
617
|
_defineProperty(this, "transport", void 0);
|
|
620
618
|
_defineProperty(this, "singleEndpointUrl", void 0);
|
|
621
619
|
_defineProperty(this, "runtimeMode", void 0);
|
|
@@ -625,7 +623,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
625
623
|
_defineProperty(this, "runtimeInfoPromise", void 0);
|
|
626
624
|
this.runtimeUrl = normalizedRuntimeUrl !== null && normalizedRuntimeUrl !== void 0 ? normalizedRuntimeUrl : config.runtimeUrl;
|
|
627
625
|
this.credentials = config.credentials;
|
|
628
|
-
this.remoteAgentId = config.remoteAgentId;
|
|
629
626
|
this.transport = transport;
|
|
630
627
|
this.runtimeMode = (_config$runtimeMode = config.runtimeMode) !== null && _config$runtimeMode !== void 0 ? _config$runtimeMode : _copilotkit_shared.RUNTIME_MODE_SSE;
|
|
631
628
|
this.intelligence = config.intelligence;
|
|
@@ -633,22 +630,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
633
630
|
if (config.debug) this.debug = config.debug;
|
|
634
631
|
if (this.transport === "single") this.singleEndpointUrl = this.runtimeUrl;
|
|
635
632
|
}
|
|
636
|
-
/**
|
|
637
|
-
* The agent id used for outbound runtime requests — `remoteAgentId` when
|
|
638
|
-
* set (manually-registered proxy), otherwise `agentId` (registry id
|
|
639
|
-
* matches runtime id). Subscriber bookkeeping keeps using `agentId`
|
|
640
|
-
* directly.
|
|
641
|
-
*
|
|
642
|
-
* Throws when both are unset: a proxy reaching an HTTP path with no
|
|
643
|
-
* routable id is a bug, and a missing id would otherwise produce a
|
|
644
|
-
* malformed `/agent//run` or `/agent/undefined/connect` URL silently.
|
|
645
|
-
*/
|
|
646
|
-
routedAgentId() {
|
|
647
|
-
var _this$remoteAgentId;
|
|
648
|
-
const id = (_this$remoteAgentId = this.remoteAgentId) !== null && _this$remoteAgentId !== void 0 ? _this$remoteAgentId : this.agentId;
|
|
649
|
-
if (!id) throw new Error("ProxiedCopilotRuntimeAgent: cannot make a runtime request without an agentId or remoteAgentId.");
|
|
650
|
-
return id;
|
|
651
|
-
}
|
|
652
633
|
get capabilities() {
|
|
653
634
|
return this._capabilities;
|
|
654
635
|
}
|
|
@@ -669,7 +650,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
669
650
|
}
|
|
670
651
|
if (!this.agentId || !this.threadId) return;
|
|
671
652
|
if (typeof fetch === "undefined") return;
|
|
672
|
-
const routedId = this.routedAgentId();
|
|
673
653
|
if (this.transport === "single") {
|
|
674
654
|
if (!this.singleEndpointUrl) return;
|
|
675
655
|
const headers = new Headers({
|
|
@@ -682,7 +662,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
682
662
|
body: JSON.stringify({
|
|
683
663
|
method: "agent/stop",
|
|
684
664
|
params: {
|
|
685
|
-
agentId:
|
|
665
|
+
agentId: this.agentId,
|
|
686
666
|
threadId: this.threadId
|
|
687
667
|
}
|
|
688
668
|
}),
|
|
@@ -693,7 +673,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
693
673
|
return;
|
|
694
674
|
}
|
|
695
675
|
if (!this.runtimeUrl) return;
|
|
696
|
-
const stopPath = `${this.runtimeUrl}/agent/${encodeURIComponent(
|
|
676
|
+
const stopPath = `${this.runtimeUrl}/agent/${encodeURIComponent(this.agentId)}/stop/${encodeURIComponent(this.threadId)}`;
|
|
697
677
|
const origin = typeof window !== "undefined" && window.location ? window.location.origin : "http://localhost";
|
|
698
678
|
const base = new URL(this.runtimeUrl, origin);
|
|
699
679
|
const stopUrl = new URL(stopPath, base);
|
|
@@ -757,7 +737,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
757
737
|
const cloned = new ProxiedCopilotRuntimeAgent({
|
|
758
738
|
runtimeUrl: this.runtimeUrl,
|
|
759
739
|
agentId: this.agentId,
|
|
760
|
-
remoteAgentId: this.remoteAgentId,
|
|
761
740
|
description: this.description,
|
|
762
741
|
headers: { ...this.headers },
|
|
763
742
|
credentials: this.credentials,
|
|
@@ -870,18 +849,17 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
870
849
|
}
|
|
871
850
|
createIntelligenceDelegate() {
|
|
872
851
|
var _this$intelligence;
|
|
873
|
-
|
|
874
|
-
if (!this.runtimeUrl || !routedId || !((_this$intelligence = this.intelligence) === null || _this$intelligence === void 0 ? void 0 : _this$intelligence.wsUrl)) throw new Error("Intelligence mode requires runtimeUrl, agentId, and intelligence websocket metadata");
|
|
852
|
+
if (!this.runtimeUrl || !this.agentId || !((_this$intelligence = this.intelligence) === null || _this$intelligence === void 0 ? void 0 : _this$intelligence.wsUrl)) throw new Error("Intelligence mode requires runtimeUrl, agentId, and intelligence websocket metadata");
|
|
875
853
|
return new IntelligenceAgent({
|
|
876
854
|
url: this.intelligence.wsUrl,
|
|
877
855
|
runtimeUrl: this.runtimeUrl,
|
|
878
|
-
agentId:
|
|
856
|
+
agentId: this.agentId,
|
|
879
857
|
headers: { ...this.headers },
|
|
880
858
|
credentials: this.credentials
|
|
881
859
|
});
|
|
882
860
|
}
|
|
883
861
|
syncDelegate(delegate) {
|
|
884
|
-
delegate.agentId = this.
|
|
862
|
+
delegate.agentId = this.agentId;
|
|
885
863
|
delegate.description = this.description;
|
|
886
864
|
delegate.threadId = this.threadId;
|
|
887
865
|
delegate.setMessages(this.messages);
|
|
@@ -895,13 +873,12 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
895
873
|
return (0, rxjs.defer)(() => (0, rxjs.from)(this.resolveDelegate())).pipe((0, rxjs_operators.switchMap)((delegate) => withAbortErrorHandling(delegate.connect(input))));
|
|
896
874
|
}
|
|
897
875
|
function _connectViaHttp(input) {
|
|
898
|
-
const routedId = this.routedAgentId();
|
|
899
876
|
if (this.transport === "single") {
|
|
900
877
|
if (!this.singleEndpointUrl) throw new Error("Single endpoint transport requires a runtimeUrl");
|
|
901
|
-
const requestInit = this.createSingleRouteRequestInit(input, "agent/connect", { agentId:
|
|
878
|
+
const requestInit = this.createSingleRouteRequestInit(input, "agent/connect", { agentId: this.agentId });
|
|
902
879
|
return withAbortErrorHandling((0, _ag_ui_client.transformHttpEventStream)((0, _ag_ui_client.runHttpRequest)(this.singleEndpointUrl, requestInit)));
|
|
903
880
|
}
|
|
904
|
-
return withAbortErrorHandling((0, _ag_ui_client.transformHttpEventStream)((0, _ag_ui_client.runHttpRequest)(`${this.runtimeUrl}/agent/${
|
|
881
|
+
return withAbortErrorHandling((0, _ag_ui_client.transformHttpEventStream)((0, _ag_ui_client.runHttpRequest)(`${this.runtimeUrl}/agent/${this.agentId}/connect`, this.requestInit(input))));
|
|
905
882
|
}
|
|
906
883
|
function _runViaDelegate(input) {
|
|
907
884
|
return (0, rxjs.defer)(() => (0, rxjs.from)(this.resolveDelegate())).pipe((0, rxjs_operators.switchMap)((delegate) => withAbortErrorHandling(delegate.run(input))));
|
|
@@ -909,7 +886,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
909
886
|
function _runViaHttp(input) {
|
|
910
887
|
if (this.transport === "single") {
|
|
911
888
|
if (!this.singleEndpointUrl) throw new Error("Single endpoint transport requires a runtimeUrl");
|
|
912
|
-
const requestInit = this.createSingleRouteRequestInit(input, "agent/run", { agentId: this.
|
|
889
|
+
const requestInit = this.createSingleRouteRequestInit(input, "agent/run", { agentId: this.agentId });
|
|
913
890
|
return withAbortErrorHandling((0, _ag_ui_client.transformHttpEventStream)((0, _ag_ui_client.runHttpRequest)(this.singleEndpointUrl, requestInit)));
|
|
914
891
|
}
|
|
915
892
|
return withAbortErrorHandling(_superPropGet(_ProxiedCopilotRuntimeAgent.prototype, "run", this, 2)([input]));
|
|
@@ -1039,52 +1016,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1039
1016
|
this.notifyAgentsChanged();
|
|
1040
1017
|
}
|
|
1041
1018
|
/**
|
|
1042
|
-
* Register a proxied agent that routes outbound runtime requests to an
|
|
1043
|
-
* existing runtime agent (`remoteAgentId`) while exposing a distinct local
|
|
1044
|
-
* registry id (`agentId`). Throws if `agentId` is already taken by either a
|
|
1045
|
-
* local or runtime-discovered agent.
|
|
1046
|
-
*
|
|
1047
|
-
* Use this to mount multiple frontend agents against a single runtime
|
|
1048
|
-
* agent (e.g. a chat-1 / chat-2 pair both proxying to "default") without
|
|
1049
|
-
* implicit per-thread cloning. The returned `unregister` removes the proxy
|
|
1050
|
-
* from the registry and emits `onAgentsChanged`.
|
|
1051
|
-
*/
|
|
1052
|
-
registerProxiedAgent({ agentId, remoteAgentId }) {
|
|
1053
|
-
if (Object.prototype.hasOwnProperty.call(this._agents, agentId)) throw new Error(`CopilotKitCore.registerProxiedAgent: agentId "${agentId}" is already registered. Pick a different agentId, or unregister the existing agent first.`);
|
|
1054
|
-
const friends = this.core;
|
|
1055
|
-
const debug = friends.debug;
|
|
1056
|
-
const agent = new ProxiedCopilotRuntimeAgent({
|
|
1057
|
-
runtimeUrl: this._runtimeUrl,
|
|
1058
|
-
agentId,
|
|
1059
|
-
remoteAgentId,
|
|
1060
|
-
transport: this._runtimeTransport,
|
|
1061
|
-
credentials: friends.credentials,
|
|
1062
|
-
runtimeMode: this._runtimeUrl ? this._runtimeConnectionStatus === CopilotKitCoreRuntimeConnectionStatus.Connected ? this._runtimeMode : "pending" : _copilotkit_shared.RUNTIME_MODE_SSE,
|
|
1063
|
-
intelligence: this._intelligence,
|
|
1064
|
-
debug: debug ? (0, _copilotkit_shared.resolveDebugConfig)(debug) : void 0
|
|
1065
|
-
});
|
|
1066
|
-
this.applyHeadersToAgent(agent);
|
|
1067
|
-
this.localAgents[agentId] = agent;
|
|
1068
|
-
this._agents = {
|
|
1069
|
-
...this.localAgents,
|
|
1070
|
-
...this.remoteAgents
|
|
1071
|
-
};
|
|
1072
|
-
this.notifyAgentsChanged();
|
|
1073
|
-
return {
|
|
1074
|
-
agent,
|
|
1075
|
-
unregister: () => {
|
|
1076
|
-
if (this.localAgents[agentId] === agent) {
|
|
1077
|
-
delete this.localAgents[agentId];
|
|
1078
|
-
this._agents = {
|
|
1079
|
-
...this.localAgents,
|
|
1080
|
-
...this.remoteAgents
|
|
1081
|
-
};
|
|
1082
|
-
this.notifyAgentsChanged();
|
|
1083
|
-
}
|
|
1084
|
-
}
|
|
1085
|
-
};
|
|
1086
|
-
}
|
|
1087
|
-
/**
|
|
1088
1019
|
* Get an agent by ID
|
|
1089
1020
|
*/
|
|
1090
1021
|
getAgent(id) {
|
|
@@ -1375,11 +1306,17 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1375
1306
|
/**
|
|
1376
1307
|
* Reload suggestions for a specific agent
|
|
1377
1308
|
* This triggers generation of new suggestions based on current configs
|
|
1309
|
+
*
|
|
1310
|
+
* @param agentId - The consumer agent ID
|
|
1311
|
+
* @param consumerAgent - Optional: the specific agent instance whose messages should be used
|
|
1312
|
+
* for availability filtering and context. When running with per-thread clones, the thread
|
|
1313
|
+
* clone holds the conversation messages; passing it here ensures dynamic suggestions fire
|
|
1314
|
+
* after the first message even though the registry agent has an empty message list.
|
|
1378
1315
|
*/
|
|
1379
|
-
reloadSuggestions(agentId) {
|
|
1316
|
+
reloadSuggestions(agentId, consumerAgent) {
|
|
1380
1317
|
var _agent$messages$lengt, _agent$messages;
|
|
1381
1318
|
this.clearSuggestions(agentId);
|
|
1382
|
-
const agent = this.core.getAgent(agentId);
|
|
1319
|
+
const agent = consumerAgent !== null && consumerAgent !== void 0 ? consumerAgent : this.core.getAgent(agentId);
|
|
1383
1320
|
const messageCount = (_agent$messages$lengt = agent === null || agent === void 0 || (_agent$messages = agent.messages) === null || _agent$messages === void 0 ? void 0 : _agent$messages.length) !== null && _agent$messages$lengt !== void 0 ? _agent$messages$lengt : 0;
|
|
1384
1321
|
let hasAnySuggestions = false;
|
|
1385
1322
|
for (const config of Object.values(this._suggestionsConfig)) {
|
|
@@ -1392,7 +1329,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1392
1329
|
hasAnySuggestions = true;
|
|
1393
1330
|
this.notifySuggestionsStartedLoading(agentId);
|
|
1394
1331
|
}
|
|
1395
|
-
this.generateSuggestions(suggestionId, config, agentId);
|
|
1332
|
+
this.generateSuggestions(suggestionId, config, agentId, agent);
|
|
1396
1333
|
} else if (isStaticSuggestionsConfig(config)) this.addStaticSuggestions(suggestionId, config, agentId);
|
|
1397
1334
|
}
|
|
1398
1335
|
}
|
|
@@ -1421,13 +1358,13 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1421
1358
|
/**
|
|
1422
1359
|
* Generate suggestions using a provider agent
|
|
1423
1360
|
*/
|
|
1424
|
-
async generateSuggestions(suggestionId, config, consumerAgentId) {
|
|
1361
|
+
async generateSuggestions(suggestionId, config, consumerAgentId, consumerAgent) {
|
|
1425
1362
|
let agent = void 0;
|
|
1426
1363
|
try {
|
|
1427
1364
|
var _config$providerAgent, _this$_runningSuggest3, _config$minSuggestion, _config$maxSuggestion;
|
|
1428
1365
|
const suggestionsProviderAgent = this.core.getAgent((_config$providerAgent = config.providerAgentId) !== null && _config$providerAgent !== void 0 ? _config$providerAgent : "default");
|
|
1429
1366
|
if (!suggestionsProviderAgent) throw new Error(`Suggestions provider agent not found: ${config.providerAgentId}`);
|
|
1430
|
-
const suggestionsConsumerAgent = this.core.getAgent(consumerAgentId);
|
|
1367
|
+
const suggestionsConsumerAgent = consumerAgent !== null && consumerAgent !== void 0 ? consumerAgent : this.core.getAgent(consumerAgentId);
|
|
1431
1368
|
if (!suggestionsConsumerAgent) throw new Error(`Suggestions consumer agent not found: ${consumerAgentId}`);
|
|
1432
1369
|
agent = suggestionsProviderAgent.clone();
|
|
1433
1370
|
agent.threadId = suggestionId;
|
|
@@ -1740,6 +1677,13 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1740
1677
|
agent.setMessages([]);
|
|
1741
1678
|
agent.setState({});
|
|
1742
1679
|
if (agent instanceof _ag_ui_client.HttpAgent) agent.headers = { ...this._internal.headers };
|
|
1680
|
+
await this._internal.notifySubscribers((subscriber) => {
|
|
1681
|
+
var _subscriber$onAgentRu;
|
|
1682
|
+
return (_subscriber$onAgentRu = subscriber.onAgentRunStarted) === null || _subscriber$onAgentRu === void 0 ? void 0 : _subscriber$onAgentRu.call(subscriber, {
|
|
1683
|
+
copilotkit: this.core,
|
|
1684
|
+
agent
|
|
1685
|
+
});
|
|
1686
|
+
}, "Subscriber onAgentRunStarted error:");
|
|
1743
1687
|
const runAgentResult = await agent.connectAgent({
|
|
1744
1688
|
forwardedProps: this._internal.properties,
|
|
1745
1689
|
tools: this.buildFrontendTools(agent.agentId),
|
|
@@ -1770,6 +1714,14 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1770
1714
|
if (agent.agentId) this._internal.suggestionEngine.clearSuggestions(agent.agentId);
|
|
1771
1715
|
if (agent instanceof _ag_ui_client.HttpAgent) agent.headers = { ...this._internal.headers };
|
|
1772
1716
|
if (agent.detachActiveRun) await agent.detachActiveRun();
|
|
1717
|
+
this._internal.subscribeAgentToStateManager(agent);
|
|
1718
|
+
await this._internal.notifySubscribers((subscriber) => {
|
|
1719
|
+
var _subscriber$onAgentRu2;
|
|
1720
|
+
return (_subscriber$onAgentRu2 = subscriber.onAgentRunStarted) === null || _subscriber$onAgentRu2 === void 0 ? void 0 : _subscriber$onAgentRu2.call(subscriber, {
|
|
1721
|
+
copilotkit: this.core,
|
|
1722
|
+
agent
|
|
1723
|
+
});
|
|
1724
|
+
}, "Subscriber onAgentRunStarted error:");
|
|
1773
1725
|
const isTopLevel = this._runDepth === 0;
|
|
1774
1726
|
let originalAbortRun;
|
|
1775
1727
|
if (isTopLevel) {
|
|
@@ -1841,7 +1793,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1841
1793
|
await this._internal.waitForPendingFrameworkUpdates();
|
|
1842
1794
|
return await this.runAgent({ agent });
|
|
1843
1795
|
}
|
|
1844
|
-
this._internal.suggestionEngine.reloadSuggestions(agentId);
|
|
1796
|
+
this._internal.suggestionEngine.reloadSuggestions(agentId, agent);
|
|
1845
1797
|
return runAgentResult;
|
|
1846
1798
|
}
|
|
1847
1799
|
/**
|
|
@@ -2270,14 +2222,21 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2270
2222
|
initialize() {}
|
|
2271
2223
|
/**
|
|
2272
2224
|
* Subscribe to an agent's events to track state and messages.
|
|
2225
|
+
*
|
|
2226
|
+
* Registry agents (subscribed via `onAgentsChanged`) use the bare `agentId`
|
|
2227
|
+
* key so that `unsubscribeFromAgent(agentId)` can remove them when they
|
|
2228
|
+
* are replaced. Per-thread clones (subscribed via `subscribeAgentToStateManager`)
|
|
2229
|
+
* pass `{ isClone: true }` to use a composite `agentId:threadId` key, keeping
|
|
2230
|
+
* their subscription independent of the registry agent's.
|
|
2273
2231
|
*/
|
|
2274
|
-
subscribeToAgent(agent) {
|
|
2232
|
+
subscribeToAgent(agent, { isClone = false } = {}) {
|
|
2275
2233
|
if (!agent.agentId) return;
|
|
2276
2234
|
const agentId = agent.agentId;
|
|
2277
|
-
const
|
|
2235
|
+
const subscriptionKey = isClone && agent.threadId ? `${agentId}:${agent.threadId}` : agentId;
|
|
2236
|
+
const existingUnsubscribe = this.agentSubscriptions.get(subscriptionKey);
|
|
2278
2237
|
if (existingUnsubscribe) {
|
|
2279
2238
|
existingUnsubscribe();
|
|
2280
|
-
this.agentSubscriptions.delete(
|
|
2239
|
+
this.agentSubscriptions.delete(subscriptionKey);
|
|
2281
2240
|
}
|
|
2282
2241
|
let revoked = false;
|
|
2283
2242
|
let subRunId;
|
|
@@ -2324,13 +2283,16 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2324
2283
|
this.handleNewMessage(agent, message, input ? effectiveInput(input) : void 0);
|
|
2325
2284
|
}
|
|
2326
2285
|
});
|
|
2327
|
-
this.agentSubscriptions.set(
|
|
2286
|
+
this.agentSubscriptions.set(subscriptionKey, () => {
|
|
2328
2287
|
revoked = true;
|
|
2329
2288
|
unsubscribe();
|
|
2330
2289
|
});
|
|
2331
2290
|
}
|
|
2332
2291
|
/**
|
|
2333
|
-
* Unsubscribe
|
|
2292
|
+
* Unsubscribe a registry agent's subscription (bare `agentId` key).
|
|
2293
|
+
* Per-thread clone subscriptions use composite `agentId:threadId` keys and
|
|
2294
|
+
* are replaced (not removed) by subsequent subscribeToAgent(agent, { isClone: true })
|
|
2295
|
+
* calls for the same (agentId, threadId) pair.
|
|
2334
2296
|
*/
|
|
2335
2297
|
unsubscribeFromAgent(agentId) {
|
|
2336
2298
|
const unsubscribe = this.agentSubscriptions.get(agentId);
|
|
@@ -2621,16 +2583,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2621
2583
|
if (agent.agentId) this.stateManager.subscribeToAgent(agent);
|
|
2622
2584
|
});
|
|
2623
2585
|
const currentAgentIds = new Set(Object.keys(agents));
|
|
2624
|
-
for (const agentId of Object.keys(this.threadStoreRegistry.getAll())) if (this.previousAgentIds.has(agentId) && !currentAgentIds.has(agentId))
|
|
2625
|
-
this.threadStoreRegistry.unregister(agentId);
|
|
2626
|
-
} catch (err) {
|
|
2627
|
-
console.error(`CopilotKitCore.onAgentsChanged: threadStoreRegistry.unregister failed for "${agentId}":`, err);
|
|
2628
|
-
}
|
|
2629
|
-
for (const agentId of this.previousAgentIds) if (!currentAgentIds.has(agentId)) try {
|
|
2630
|
-
this.stateManager.unsubscribeFromAgent(agentId);
|
|
2631
|
-
} catch (err) {
|
|
2632
|
-
console.error(`CopilotKitCore.onAgentsChanged: stateManager.unsubscribeFromAgent failed for "${agentId}":`, err);
|
|
2633
|
-
}
|
|
2586
|
+
for (const agentId of Object.keys(this.threadStoreRegistry.getAll())) if (this.previousAgentIds.has(agentId) && !currentAgentIds.has(agentId)) this.threadStoreRegistry.unregister(agentId);
|
|
2634
2587
|
this.previousAgentIds = currentAgentIds;
|
|
2635
2588
|
} });
|
|
2636
2589
|
}
|
|
@@ -2802,28 +2755,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2802
2755
|
removeAgent__unsafe_dev_only(id) {
|
|
2803
2756
|
this.agentRegistry.removeAgent__unsafe_dev_only(id);
|
|
2804
2757
|
}
|
|
2805
|
-
/**
|
|
2806
|
-
* Register a proxied agent against an existing runtime agent. The proxy is
|
|
2807
|
-
* exposed under `agentId` (local registry id) and routes outbound runtime
|
|
2808
|
-
* requests to `remoteAgentId`. Throws if `agentId` is already taken.
|
|
2809
|
-
*
|
|
2810
|
-
* Returns the minted proxy and an `unregister` handle for cleanup.
|
|
2811
|
-
*
|
|
2812
|
-
* Use this to mount multiple frontend agents against a single runtime
|
|
2813
|
-
* agent (e.g. one per chat window) without implicit per-thread cloning.
|
|
2814
|
-
*
|
|
2815
|
-
* @example
|
|
2816
|
-
* const { agent, unregister } = copilotkit.registerProxiedAgent({
|
|
2817
|
-
* agentId: "chat-1",
|
|
2818
|
-
* remoteAgentId: "default",
|
|
2819
|
-
* });
|
|
2820
|
-
* // ... <CopilotChat agentId="chat-1" />
|
|
2821
|
-
* // on cleanup:
|
|
2822
|
-
* unregister();
|
|
2823
|
-
*/
|
|
2824
|
-
registerProxiedAgent(params) {
|
|
2825
|
-
return this.agentRegistry.registerProxiedAgent(params);
|
|
2826
|
-
}
|
|
2827
2758
|
getAgent(id) {
|
|
2828
2759
|
return this.agentRegistry.getAgent(id);
|
|
2829
2760
|
}
|
|
@@ -3058,6 +2989,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
3058
2989
|
getRunIdsForThread(agentId, threadId) {
|
|
3059
2990
|
return this.stateManager.getRunIdsForThread(agentId, threadId);
|
|
3060
2991
|
}
|
|
2992
|
+
subscribeAgentToStateManager(agent) {
|
|
2993
|
+
this.stateManager.subscribeToAgent(agent, { isClone: true });
|
|
2994
|
+
}
|
|
3061
2995
|
/**
|
|
3062
2996
|
* Internal method used by RunHandler to build frontend tools
|
|
3063
2997
|
*/
|