@copilotkit/core 1.57.0 → 1.57.1
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 +120 -49
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +122 -83
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +121 -82
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +120 -49
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +122 -56
- package/dist/index.umd.js.map +1 -1
- package/package.json +2 -2
package/dist/index.umd.js
CHANGED
|
@@ -602,10 +602,11 @@ 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$runtimeAgentI, _ref2, _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
|
|
608
|
+
const routedId = (_ref = (_config$runtimeAgentI = config.runtimeAgentId) !== null && _config$runtimeAgentI !== void 0 ? _config$runtimeAgentI : config.agentId) !== null && _ref !== void 0 ? _ref : "";
|
|
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`;
|
|
609
610
|
if (!runUrl) throw new Error("ProxiedCopilotRuntimeAgent requires a runtimeUrl when transport is set to 'single'.");
|
|
610
611
|
super({
|
|
611
612
|
...config,
|
|
@@ -614,6 +615,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
614
615
|
_classPrivateMethodInitSpec(this, _ProxiedCopilotRuntimeAgent_brand);
|
|
615
616
|
_defineProperty(this, "runtimeUrl", void 0);
|
|
616
617
|
_defineProperty(this, "credentials", void 0);
|
|
618
|
+
_defineProperty(this, "runtimeAgentId", void 0);
|
|
617
619
|
_defineProperty(this, "transport", void 0);
|
|
618
620
|
_defineProperty(this, "singleEndpointUrl", void 0);
|
|
619
621
|
_defineProperty(this, "runtimeMode", void 0);
|
|
@@ -623,6 +625,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
623
625
|
_defineProperty(this, "runtimeInfoPromise", void 0);
|
|
624
626
|
this.runtimeUrl = normalizedRuntimeUrl !== null && normalizedRuntimeUrl !== void 0 ? normalizedRuntimeUrl : config.runtimeUrl;
|
|
625
627
|
this.credentials = config.credentials;
|
|
628
|
+
this.runtimeAgentId = config.runtimeAgentId;
|
|
626
629
|
this.transport = transport;
|
|
627
630
|
this.runtimeMode = (_config$runtimeMode = config.runtimeMode) !== null && _config$runtimeMode !== void 0 ? _config$runtimeMode : _copilotkit_shared.RUNTIME_MODE_SSE;
|
|
628
631
|
this.intelligence = config.intelligence;
|
|
@@ -630,6 +633,22 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
630
633
|
if (config.debug) this.debug = config.debug;
|
|
631
634
|
if (this.transport === "single") this.singleEndpointUrl = this.runtimeUrl;
|
|
632
635
|
}
|
|
636
|
+
/**
|
|
637
|
+
* The agent id used for outbound runtime requests — `runtimeAgentId` 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$runtimeAgentId;
|
|
648
|
+
const id = (_this$runtimeAgentId = this.runtimeAgentId) !== null && _this$runtimeAgentId !== void 0 ? _this$runtimeAgentId : this.agentId;
|
|
649
|
+
if (!id) throw new Error("ProxiedCopilotRuntimeAgent: cannot make a runtime request without an agentId or runtimeAgentId.");
|
|
650
|
+
return id;
|
|
651
|
+
}
|
|
633
652
|
get capabilities() {
|
|
634
653
|
return this._capabilities;
|
|
635
654
|
}
|
|
@@ -650,6 +669,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
650
669
|
}
|
|
651
670
|
if (!this.agentId || !this.threadId) return;
|
|
652
671
|
if (typeof fetch === "undefined") return;
|
|
672
|
+
const routedId = this.routedAgentId();
|
|
653
673
|
if (this.transport === "single") {
|
|
654
674
|
if (!this.singleEndpointUrl) return;
|
|
655
675
|
const headers = new Headers({
|
|
@@ -662,7 +682,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
662
682
|
body: JSON.stringify({
|
|
663
683
|
method: "agent/stop",
|
|
664
684
|
params: {
|
|
665
|
-
agentId:
|
|
685
|
+
agentId: routedId,
|
|
666
686
|
threadId: this.threadId
|
|
667
687
|
}
|
|
668
688
|
}),
|
|
@@ -673,7 +693,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
673
693
|
return;
|
|
674
694
|
}
|
|
675
695
|
if (!this.runtimeUrl) return;
|
|
676
|
-
const stopPath = `${this.runtimeUrl}/agent/${encodeURIComponent(
|
|
696
|
+
const stopPath = `${this.runtimeUrl}/agent/${encodeURIComponent(routedId)}/stop/${encodeURIComponent(this.threadId)}`;
|
|
677
697
|
const origin = typeof window !== "undefined" && window.location ? window.location.origin : "http://localhost";
|
|
678
698
|
const base = new URL(this.runtimeUrl, origin);
|
|
679
699
|
const stopUrl = new URL(stopPath, base);
|
|
@@ -737,6 +757,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
737
757
|
const cloned = new ProxiedCopilotRuntimeAgent({
|
|
738
758
|
runtimeUrl: this.runtimeUrl,
|
|
739
759
|
agentId: this.agentId,
|
|
760
|
+
runtimeAgentId: this.runtimeAgentId,
|
|
740
761
|
description: this.description,
|
|
741
762
|
headers: { ...this.headers },
|
|
742
763
|
credentials: this.credentials,
|
|
@@ -849,17 +870,18 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
849
870
|
}
|
|
850
871
|
createIntelligenceDelegate() {
|
|
851
872
|
var _this$intelligence;
|
|
852
|
-
|
|
873
|
+
const routedId = this.routedAgentId();
|
|
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");
|
|
853
875
|
return new IntelligenceAgent({
|
|
854
876
|
url: this.intelligence.wsUrl,
|
|
855
877
|
runtimeUrl: this.runtimeUrl,
|
|
856
|
-
agentId:
|
|
878
|
+
agentId: routedId,
|
|
857
879
|
headers: { ...this.headers },
|
|
858
880
|
credentials: this.credentials
|
|
859
881
|
});
|
|
860
882
|
}
|
|
861
883
|
syncDelegate(delegate) {
|
|
862
|
-
delegate.agentId = this.
|
|
884
|
+
delegate.agentId = this.routedAgentId();
|
|
863
885
|
delegate.description = this.description;
|
|
864
886
|
delegate.threadId = this.threadId;
|
|
865
887
|
delegate.setMessages(this.messages);
|
|
@@ -873,12 +895,13 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
873
895
|
return (0, rxjs.defer)(() => (0, rxjs.from)(this.resolveDelegate())).pipe((0, rxjs_operators.switchMap)((delegate) => withAbortErrorHandling(delegate.connect(input))));
|
|
874
896
|
}
|
|
875
897
|
function _connectViaHttp(input) {
|
|
898
|
+
const routedId = this.routedAgentId();
|
|
876
899
|
if (this.transport === "single") {
|
|
877
900
|
if (!this.singleEndpointUrl) throw new Error("Single endpoint transport requires a runtimeUrl");
|
|
878
|
-
const requestInit = this.createSingleRouteRequestInit(input, "agent/connect", { agentId:
|
|
901
|
+
const requestInit = this.createSingleRouteRequestInit(input, "agent/connect", { agentId: routedId });
|
|
879
902
|
return withAbortErrorHandling((0, _ag_ui_client.transformHttpEventStream)((0, _ag_ui_client.runHttpRequest)(this.singleEndpointUrl, requestInit)));
|
|
880
903
|
}
|
|
881
|
-
return withAbortErrorHandling((0, _ag_ui_client.transformHttpEventStream)((0, _ag_ui_client.runHttpRequest)(`${this.runtimeUrl}/agent/${
|
|
904
|
+
return withAbortErrorHandling((0, _ag_ui_client.transformHttpEventStream)((0, _ag_ui_client.runHttpRequest)(`${this.runtimeUrl}/agent/${routedId}/connect`, this.requestInit(input))));
|
|
882
905
|
}
|
|
883
906
|
function _runViaDelegate(input) {
|
|
884
907
|
return (0, rxjs.defer)(() => (0, rxjs.from)(this.resolveDelegate())).pipe((0, rxjs_operators.switchMap)((delegate) => withAbortErrorHandling(delegate.run(input))));
|
|
@@ -886,7 +909,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
886
909
|
function _runViaHttp(input) {
|
|
887
910
|
if (this.transport === "single") {
|
|
888
911
|
if (!this.singleEndpointUrl) throw new Error("Single endpoint transport requires a runtimeUrl");
|
|
889
|
-
const requestInit = this.createSingleRouteRequestInit(input, "agent/run", { agentId: this.
|
|
912
|
+
const requestInit = this.createSingleRouteRequestInit(input, "agent/run", { agentId: this.routedAgentId() });
|
|
890
913
|
return withAbortErrorHandling((0, _ag_ui_client.transformHttpEventStream)((0, _ag_ui_client.runHttpRequest)(this.singleEndpointUrl, requestInit)));
|
|
891
914
|
}
|
|
892
915
|
return withAbortErrorHandling(_superPropGet(_ProxiedCopilotRuntimeAgent.prototype, "run", this, 2)([input]));
|
|
@@ -1016,6 +1039,52 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1016
1039
|
this.notifyAgentsChanged();
|
|
1017
1040
|
}
|
|
1018
1041
|
/**
|
|
1042
|
+
* Register a proxied agent that routes outbound runtime requests to an
|
|
1043
|
+
* existing runtime agent (`runtimeAgentId`) 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, runtimeAgentId }) {
|
|
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
|
+
runtimeAgentId,
|
|
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
|
+
/**
|
|
1019
1088
|
* Get an agent by ID
|
|
1020
1089
|
*/
|
|
1021
1090
|
getAgent(id) {
|
|
@@ -1306,17 +1375,11 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1306
1375
|
/**
|
|
1307
1376
|
* Reload suggestions for a specific agent
|
|
1308
1377
|
* 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.
|
|
1315
1378
|
*/
|
|
1316
|
-
reloadSuggestions(agentId
|
|
1379
|
+
reloadSuggestions(agentId) {
|
|
1317
1380
|
var _agent$messages$lengt, _agent$messages;
|
|
1318
1381
|
this.clearSuggestions(agentId);
|
|
1319
|
-
const agent =
|
|
1382
|
+
const agent = this.core.getAgent(agentId);
|
|
1320
1383
|
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;
|
|
1321
1384
|
let hasAnySuggestions = false;
|
|
1322
1385
|
for (const config of Object.values(this._suggestionsConfig)) {
|
|
@@ -1329,7 +1392,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1329
1392
|
hasAnySuggestions = true;
|
|
1330
1393
|
this.notifySuggestionsStartedLoading(agentId);
|
|
1331
1394
|
}
|
|
1332
|
-
this.generateSuggestions(suggestionId, config, agentId
|
|
1395
|
+
this.generateSuggestions(suggestionId, config, agentId);
|
|
1333
1396
|
} else if (isStaticSuggestionsConfig(config)) this.addStaticSuggestions(suggestionId, config, agentId);
|
|
1334
1397
|
}
|
|
1335
1398
|
}
|
|
@@ -1358,13 +1421,13 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1358
1421
|
/**
|
|
1359
1422
|
* Generate suggestions using a provider agent
|
|
1360
1423
|
*/
|
|
1361
|
-
async generateSuggestions(suggestionId, config, consumerAgentId
|
|
1424
|
+
async generateSuggestions(suggestionId, config, consumerAgentId) {
|
|
1362
1425
|
let agent = void 0;
|
|
1363
1426
|
try {
|
|
1364
1427
|
var _config$providerAgent, _this$_runningSuggest3, _config$minSuggestion, _config$maxSuggestion;
|
|
1365
1428
|
const suggestionsProviderAgent = this.core.getAgent((_config$providerAgent = config.providerAgentId) !== null && _config$providerAgent !== void 0 ? _config$providerAgent : "default");
|
|
1366
1429
|
if (!suggestionsProviderAgent) throw new Error(`Suggestions provider agent not found: ${config.providerAgentId}`);
|
|
1367
|
-
const suggestionsConsumerAgent =
|
|
1430
|
+
const suggestionsConsumerAgent = this.core.getAgent(consumerAgentId);
|
|
1368
1431
|
if (!suggestionsConsumerAgent) throw new Error(`Suggestions consumer agent not found: ${consumerAgentId}`);
|
|
1369
1432
|
agent = suggestionsProviderAgent.clone();
|
|
1370
1433
|
agent.threadId = suggestionId;
|
|
@@ -1677,13 +1740,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1677
1740
|
agent.setMessages([]);
|
|
1678
1741
|
agent.setState({});
|
|
1679
1742
|
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:");
|
|
1687
1743
|
const runAgentResult = await agent.connectAgent({
|
|
1688
1744
|
forwardedProps: this._internal.properties,
|
|
1689
1745
|
tools: this.buildFrontendTools(agent.agentId),
|
|
@@ -1714,14 +1770,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1714
1770
|
if (agent.agentId) this._internal.suggestionEngine.clearSuggestions(agent.agentId);
|
|
1715
1771
|
if (agent instanceof _ag_ui_client.HttpAgent) agent.headers = { ...this._internal.headers };
|
|
1716
1772
|
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:");
|
|
1725
1773
|
const isTopLevel = this._runDepth === 0;
|
|
1726
1774
|
let originalAbortRun;
|
|
1727
1775
|
if (isTopLevel) {
|
|
@@ -1793,7 +1841,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1793
1841
|
await this._internal.waitForPendingFrameworkUpdates();
|
|
1794
1842
|
return await this.runAgent({ agent });
|
|
1795
1843
|
}
|
|
1796
|
-
this._internal.suggestionEngine.reloadSuggestions(agentId
|
|
1844
|
+
this._internal.suggestionEngine.reloadSuggestions(agentId);
|
|
1797
1845
|
return runAgentResult;
|
|
1798
1846
|
}
|
|
1799
1847
|
/**
|
|
@@ -2222,21 +2270,14 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2222
2270
|
initialize() {}
|
|
2223
2271
|
/**
|
|
2224
2272
|
* 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.
|
|
2231
2273
|
*/
|
|
2232
|
-
subscribeToAgent(agent
|
|
2274
|
+
subscribeToAgent(agent) {
|
|
2233
2275
|
if (!agent.agentId) return;
|
|
2234
2276
|
const agentId = agent.agentId;
|
|
2235
|
-
const
|
|
2236
|
-
const existingUnsubscribe = this.agentSubscriptions.get(subscriptionKey);
|
|
2277
|
+
const existingUnsubscribe = this.agentSubscriptions.get(agentId);
|
|
2237
2278
|
if (existingUnsubscribe) {
|
|
2238
2279
|
existingUnsubscribe();
|
|
2239
|
-
this.agentSubscriptions.delete(
|
|
2280
|
+
this.agentSubscriptions.delete(agentId);
|
|
2240
2281
|
}
|
|
2241
2282
|
let revoked = false;
|
|
2242
2283
|
let subRunId;
|
|
@@ -2283,16 +2324,13 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2283
2324
|
this.handleNewMessage(agent, message, input ? effectiveInput(input) : void 0);
|
|
2284
2325
|
}
|
|
2285
2326
|
});
|
|
2286
|
-
this.agentSubscriptions.set(
|
|
2327
|
+
this.agentSubscriptions.set(agentId, () => {
|
|
2287
2328
|
revoked = true;
|
|
2288
2329
|
unsubscribe();
|
|
2289
2330
|
});
|
|
2290
2331
|
}
|
|
2291
2332
|
/**
|
|
2292
|
-
* Unsubscribe
|
|
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.
|
|
2333
|
+
* Unsubscribe an agent's subscription.
|
|
2296
2334
|
*/
|
|
2297
2335
|
unsubscribeFromAgent(agentId) {
|
|
2298
2336
|
const unsubscribe = this.agentSubscriptions.get(agentId);
|
|
@@ -2583,7 +2621,16 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2583
2621
|
if (agent.agentId) this.stateManager.subscribeToAgent(agent);
|
|
2584
2622
|
});
|
|
2585
2623
|
const currentAgentIds = new Set(Object.keys(agents));
|
|
2586
|
-
for (const agentId of Object.keys(this.threadStoreRegistry.getAll())) if (this.previousAgentIds.has(agentId) && !currentAgentIds.has(agentId))
|
|
2624
|
+
for (const agentId of Object.keys(this.threadStoreRegistry.getAll())) if (this.previousAgentIds.has(agentId) && !currentAgentIds.has(agentId)) try {
|
|
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
|
+
}
|
|
2587
2634
|
this.previousAgentIds = currentAgentIds;
|
|
2588
2635
|
} });
|
|
2589
2636
|
}
|
|
@@ -2755,6 +2802,28 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2755
2802
|
removeAgent__unsafe_dev_only(id) {
|
|
2756
2803
|
this.agentRegistry.removeAgent__unsafe_dev_only(id);
|
|
2757
2804
|
}
|
|
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 `runtimeAgentId`. 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
|
+
* runtimeAgentId: "default",
|
|
2819
|
+
* });
|
|
2820
|
+
* // ... <CopilotChat agentId="chat-1" />
|
|
2821
|
+
* // on cleanup:
|
|
2822
|
+
* unregister();
|
|
2823
|
+
*/
|
|
2824
|
+
registerProxiedAgent(params) {
|
|
2825
|
+
return this.agentRegistry.registerProxiedAgent(params);
|
|
2826
|
+
}
|
|
2758
2827
|
getAgent(id) {
|
|
2759
2828
|
return this.agentRegistry.getAgent(id);
|
|
2760
2829
|
}
|
|
@@ -2989,9 +3058,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2989
3058
|
getRunIdsForThread(agentId, threadId) {
|
|
2990
3059
|
return this.stateManager.getRunIdsForThread(agentId, threadId);
|
|
2991
3060
|
}
|
|
2992
|
-
subscribeAgentToStateManager(agent) {
|
|
2993
|
-
this.stateManager.subscribeToAgent(agent, { isClone: true });
|
|
2994
|
-
}
|
|
2995
3061
|
/**
|
|
2996
3062
|
* Internal method used by RunHandler to build frontend tools
|
|
2997
3063
|
*/
|