@copilotkit/core 1.55.0-next.8 → 1.55.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 +176 -48
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +55 -8
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +55 -8
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +176 -48
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +181 -49
- package/dist/index.umd.js.map +1 -1
- package/package.json +12 -15
- package/vitest.config.mjs +1 -1
- package/eslint.config.mjs +0 -3
package/dist/index.umd.js
CHANGED
|
@@ -615,7 +615,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
615
615
|
constructor(config) {
|
|
616
616
|
var _config$transport, _ref, _config$agentId, _config$runtimeMode;
|
|
617
617
|
const normalizedRuntimeUrl = config.runtimeUrl ? config.runtimeUrl.replace(/\/$/, "") : void 0;
|
|
618
|
-
const transport = (_config$transport = config.transport) !== null && _config$transport !== void 0 ? _config$transport : "
|
|
618
|
+
const transport = (_config$transport = config.transport) !== null && _config$transport !== void 0 ? _config$transport : "auto";
|
|
619
619
|
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`;
|
|
620
620
|
if (!runUrl) throw new Error("ProxiedCopilotRuntimeAgent requires a runtimeUrl when transport is set to 'single'.");
|
|
621
621
|
super({
|
|
@@ -773,6 +773,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
773
773
|
}
|
|
774
774
|
async fetchRuntimeInfo() {
|
|
775
775
|
const headers = { ...this.headers };
|
|
776
|
+
if (this.transport === "auto") return this.fetchRuntimeInfoAutoDetect(headers);
|
|
776
777
|
let init;
|
|
777
778
|
let url;
|
|
778
779
|
if (this.transport === "single") {
|
|
@@ -795,6 +796,30 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
795
796
|
if (!response.ok) throw new Error(`Runtime info request failed with status ${response.status}`);
|
|
796
797
|
return await response.json();
|
|
797
798
|
}
|
|
799
|
+
async fetchRuntimeInfoAutoDetect(headers) {
|
|
800
|
+
try {
|
|
801
|
+
const response = await fetch(`${this.runtimeUrl}/info`, {
|
|
802
|
+
headers: { ...headers },
|
|
803
|
+
...this.credentials ? { credentials: this.credentials } : {}
|
|
804
|
+
});
|
|
805
|
+
if (response.status >= 200 && response.status < 300) {
|
|
806
|
+
this.transport = "rest";
|
|
807
|
+
return await response.json();
|
|
808
|
+
}
|
|
809
|
+
} catch (_unused) {}
|
|
810
|
+
const singleHeaders = { ...headers };
|
|
811
|
+
if (!singleHeaders["Content-Type"]) singleHeaders["Content-Type"] = "application/json";
|
|
812
|
+
const response = await fetch(this.runtimeUrl, {
|
|
813
|
+
method: "POST",
|
|
814
|
+
headers: singleHeaders,
|
|
815
|
+
body: JSON.stringify({ method: "info" }),
|
|
816
|
+
...this.credentials ? { credentials: this.credentials } : {}
|
|
817
|
+
});
|
|
818
|
+
if (!response.ok) throw new Error(`Runtime info request failed with status ${response.status}`);
|
|
819
|
+
this.transport = "single";
|
|
820
|
+
this.singleEndpointUrl = this.runtimeUrl;
|
|
821
|
+
return await response.json();
|
|
822
|
+
}
|
|
798
823
|
createSingleRouteRequestInit(input, method, params) {
|
|
799
824
|
var _baseInit$headers, _headers$get;
|
|
800
825
|
if (!this.agentId) throw new Error("ProxiedCopilotRuntimeAgent requires agentId to make runtime requests");
|
|
@@ -878,11 +903,12 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
878
903
|
_defineProperty(this, "_runtimeUrl", void 0);
|
|
879
904
|
_defineProperty(this, "_runtimeVersion", void 0);
|
|
880
905
|
_defineProperty(this, "_runtimeConnectionStatus", CopilotKitCoreRuntimeConnectionStatus.Disconnected);
|
|
881
|
-
_defineProperty(this, "_runtimeTransport", "
|
|
906
|
+
_defineProperty(this, "_runtimeTransport", "auto");
|
|
882
907
|
_defineProperty(this, "_audioFileTranscriptionEnabled", false);
|
|
883
908
|
_defineProperty(this, "_runtimeMode", _copilotkit_shared.RUNTIME_MODE_SSE);
|
|
884
909
|
_defineProperty(this, "_intelligence", void 0);
|
|
885
910
|
_defineProperty(this, "_a2uiEnabled", false);
|
|
911
|
+
_defineProperty(this, "_openGenerativeUIEnabled", false);
|
|
886
912
|
_defineProperty(this, "_licenseStatus", void 0);
|
|
887
913
|
}
|
|
888
914
|
/**
|
|
@@ -915,6 +941,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
915
941
|
get a2uiEnabled() {
|
|
916
942
|
return this._a2uiEnabled;
|
|
917
943
|
}
|
|
944
|
+
get openGenerativeUIEnabled() {
|
|
945
|
+
return this._openGenerativeUIEnabled;
|
|
946
|
+
}
|
|
918
947
|
get licenseStatus() {
|
|
919
948
|
return this._licenseStatus;
|
|
920
949
|
}
|
|
@@ -1027,6 +1056,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1027
1056
|
this._runtimeMode = _copilotkit_shared.RUNTIME_MODE_SSE;
|
|
1028
1057
|
this._intelligence = void 0;
|
|
1029
1058
|
this._a2uiEnabled = false;
|
|
1059
|
+
this._openGenerativeUIEnabled = false;
|
|
1030
1060
|
this.remoteAgents = {};
|
|
1031
1061
|
this._agents = this.localAgents;
|
|
1032
1062
|
await this.notifyRuntimeStatusChanged(CopilotKitCoreRuntimeConnectionStatus.Disconnected);
|
|
@@ -1036,7 +1066,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1036
1066
|
this._runtimeConnectionStatus = CopilotKitCoreRuntimeConnectionStatus.Connecting;
|
|
1037
1067
|
await this.notifyRuntimeStatusChanged(CopilotKitCoreRuntimeConnectionStatus.Connecting);
|
|
1038
1068
|
try {
|
|
1039
|
-
var _runtimeInfoResponse$2, _runtimeInfoResponse$3, _runtimeInfoResponse$4;
|
|
1069
|
+
var _runtimeInfoResponse$2, _runtimeInfoResponse$3, _runtimeInfoResponse$4, _runtimeInfoResponse$5;
|
|
1040
1070
|
const runtimeInfoResponse = await this.fetchRuntimeInfo();
|
|
1041
1071
|
const { version, ...runtimeInfo } = runtimeInfoResponse;
|
|
1042
1072
|
const credentials = this.core.credentials;
|
|
@@ -1064,6 +1094,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1064
1094
|
this._runtimeMode = (_runtimeInfoResponse$3 = runtimeInfoResponse.mode) !== null && _runtimeInfoResponse$3 !== void 0 ? _runtimeInfoResponse$3 : _copilotkit_shared.RUNTIME_MODE_SSE;
|
|
1065
1095
|
this._intelligence = runtimeInfoResponse.intelligence;
|
|
1066
1096
|
this._a2uiEnabled = (_runtimeInfoResponse$4 = runtimeInfoResponse.a2uiEnabled) !== null && _runtimeInfoResponse$4 !== void 0 ? _runtimeInfoResponse$4 : false;
|
|
1097
|
+
this._openGenerativeUIEnabled = (_runtimeInfoResponse$5 = runtimeInfoResponse.openGenerativeUIEnabled) !== null && _runtimeInfoResponse$5 !== void 0 ? _runtimeInfoResponse$5 : false;
|
|
1067
1098
|
this._licenseStatus = runtimeInfoResponse.licenseStatus;
|
|
1068
1099
|
await this.notifyRuntimeStatusChanged(CopilotKitCoreRuntimeConnectionStatus.Connected);
|
|
1069
1100
|
await this.notifyAgentsChanged();
|
|
@@ -1074,6 +1105,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1074
1105
|
this._runtimeMode = _copilotkit_shared.RUNTIME_MODE_SSE;
|
|
1075
1106
|
this._intelligence = void 0;
|
|
1076
1107
|
this._a2uiEnabled = false;
|
|
1108
|
+
this._openGenerativeUIEnabled = false;
|
|
1077
1109
|
this.remoteAgents = {};
|
|
1078
1110
|
this._agents = this.localAgents;
|
|
1079
1111
|
await this.notifyRuntimeStatusChanged(CopilotKitCoreRuntimeConnectionStatus.Error);
|
|
@@ -1093,25 +1125,46 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1093
1125
|
const baseHeaders = this.core.headers;
|
|
1094
1126
|
const credentials = this.core.credentials;
|
|
1095
1127
|
const headers = { ...baseHeaders };
|
|
1096
|
-
if (this._runtimeTransport === "single")
|
|
1097
|
-
|
|
1098
|
-
const response = await fetch(this.runtimeUrl, {
|
|
1099
|
-
method: "POST",
|
|
1100
|
-
headers,
|
|
1101
|
-
body: JSON.stringify({ method: "info" }),
|
|
1102
|
-
...credentials ? { credentials } : {}
|
|
1103
|
-
});
|
|
1104
|
-
if ("ok" in response && !response.ok) throw new Error(`Runtime info request failed with status ${response.status}`);
|
|
1105
|
-
return await response.json();
|
|
1106
|
-
}
|
|
1128
|
+
if (this._runtimeTransport === "single") return this.fetchRuntimeInfoSingle(headers, credentials);
|
|
1129
|
+
if (this._runtimeTransport === "auto") return this.fetchRuntimeInfoAutoDetect(headers, credentials);
|
|
1107
1130
|
const response = await fetch(`${this.runtimeUrl}/info`, {
|
|
1108
1131
|
headers,
|
|
1109
1132
|
...credentials ? { credentials } : {}
|
|
1110
1133
|
});
|
|
1111
|
-
if (
|
|
1134
|
+
if (!response.ok) throw new Error(`Runtime info request failed with status ${response.status}`);
|
|
1135
|
+
return await response.json();
|
|
1136
|
+
}
|
|
1137
|
+
async fetchRuntimeInfoSingle(headers, credentials) {
|
|
1138
|
+
if (!headers["Content-Type"]) headers["Content-Type"] = "application/json";
|
|
1139
|
+
const response = await fetch(this.runtimeUrl, {
|
|
1140
|
+
method: "POST",
|
|
1141
|
+
headers,
|
|
1142
|
+
body: JSON.stringify({ method: "info" }),
|
|
1143
|
+
...credentials ? { credentials } : {}
|
|
1144
|
+
});
|
|
1145
|
+
if (!response.ok) throw new Error(`Runtime info request failed with status ${response.status}`);
|
|
1112
1146
|
return await response.json();
|
|
1113
1147
|
}
|
|
1114
1148
|
/**
|
|
1149
|
+
* Auto-detect transport by trying REST first, then falling back to single-endpoint.
|
|
1150
|
+
* Updates `_runtimeTransport` to the detected value so subsequent requests use it directly.
|
|
1151
|
+
*/
|
|
1152
|
+
async fetchRuntimeInfoAutoDetect(headers, credentials) {
|
|
1153
|
+
try {
|
|
1154
|
+
const response = await fetch(`${this.runtimeUrl}/info`, {
|
|
1155
|
+
headers: { ...headers },
|
|
1156
|
+
...credentials ? { credentials } : {}
|
|
1157
|
+
});
|
|
1158
|
+
if (response.status >= 200 && response.status < 300) {
|
|
1159
|
+
this._runtimeTransport = "rest";
|
|
1160
|
+
return await response.json();
|
|
1161
|
+
}
|
|
1162
|
+
} catch (_unused) {}
|
|
1163
|
+
const result = await this.fetchRuntimeInfoSingle({ ...headers }, credentials);
|
|
1164
|
+
this._runtimeTransport = "single";
|
|
1165
|
+
return result;
|
|
1166
|
+
}
|
|
1167
|
+
/**
|
|
1115
1168
|
* Assign agent IDs to a record of agents
|
|
1116
1169
|
*/
|
|
1117
1170
|
assignAgentIds(agents) {
|
|
@@ -1243,11 +1296,17 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1243
1296
|
/**
|
|
1244
1297
|
* Reload suggestions for a specific agent
|
|
1245
1298
|
* This triggers generation of new suggestions based on current configs
|
|
1299
|
+
*
|
|
1300
|
+
* @param agentId - The consumer agent ID
|
|
1301
|
+
* @param consumerAgent - Optional: the specific agent instance whose messages should be used
|
|
1302
|
+
* for availability filtering and context. When running with per-thread clones, the thread
|
|
1303
|
+
* clone holds the conversation messages; passing it here ensures dynamic suggestions fire
|
|
1304
|
+
* after the first message even though the registry agent has an empty message list.
|
|
1246
1305
|
*/
|
|
1247
|
-
reloadSuggestions(agentId) {
|
|
1306
|
+
reloadSuggestions(agentId, consumerAgent) {
|
|
1248
1307
|
var _agent$messages$lengt, _agent$messages;
|
|
1249
1308
|
this.clearSuggestions(agentId);
|
|
1250
|
-
const agent = this.core.getAgent(agentId);
|
|
1309
|
+
const agent = consumerAgent !== null && consumerAgent !== void 0 ? consumerAgent : this.core.getAgent(agentId);
|
|
1251
1310
|
if (!agent) return;
|
|
1252
1311
|
const messageCount = (_agent$messages$lengt = (_agent$messages = agent.messages) === null || _agent$messages === void 0 ? void 0 : _agent$messages.length) !== null && _agent$messages$lengt !== void 0 ? _agent$messages$lengt : 0;
|
|
1253
1312
|
let hasAnySuggestions = false;
|
|
@@ -1260,7 +1319,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1260
1319
|
hasAnySuggestions = true;
|
|
1261
1320
|
this.notifySuggestionsStartedLoading(agentId);
|
|
1262
1321
|
}
|
|
1263
|
-
this.generateSuggestions(suggestionId, config, agentId);
|
|
1322
|
+
this.generateSuggestions(suggestionId, config, agentId, agent);
|
|
1264
1323
|
} else if (isStaticSuggestionsConfig(config)) this.addStaticSuggestions(suggestionId, config, agentId);
|
|
1265
1324
|
}
|
|
1266
1325
|
}
|
|
@@ -1289,13 +1348,13 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1289
1348
|
/**
|
|
1290
1349
|
* Generate suggestions using a provider agent
|
|
1291
1350
|
*/
|
|
1292
|
-
async generateSuggestions(suggestionId, config, consumerAgentId) {
|
|
1351
|
+
async generateSuggestions(suggestionId, config, consumerAgentId, consumerAgent) {
|
|
1293
1352
|
let agent = void 0;
|
|
1294
1353
|
try {
|
|
1295
1354
|
var _config$providerAgent, _this$_suggestions$co, _this$_runningSuggest3, _config$minSuggestion, _config$maxSuggestion;
|
|
1296
1355
|
const suggestionsProviderAgent = this.core.getAgent((_config$providerAgent = config.providerAgentId) !== null && _config$providerAgent !== void 0 ? _config$providerAgent : "default");
|
|
1297
1356
|
if (!suggestionsProviderAgent) throw new Error(`Suggestions provider agent not found: ${config.providerAgentId}`);
|
|
1298
|
-
const suggestionsConsumerAgent = this.core.getAgent(consumerAgentId);
|
|
1357
|
+
const suggestionsConsumerAgent = consumerAgent !== null && consumerAgent !== void 0 ? consumerAgent : this.core.getAgent(consumerAgentId);
|
|
1299
1358
|
if (!suggestionsConsumerAgent) throw new Error(`Suggestions consumer agent not found: ${consumerAgentId}`);
|
|
1300
1359
|
agent = suggestionsProviderAgent.clone();
|
|
1301
1360
|
agent.threadId = suggestionId;
|
|
@@ -1619,13 +1678,15 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1619
1678
|
});
|
|
1620
1679
|
} catch (error) {
|
|
1621
1680
|
const connectError = error instanceof Error ? error : new Error(String(error));
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1681
|
+
if (!(connectError.name === "AbortError" || connectError.message === "Fetch is aborted" || connectError.message === "signal is aborted without reason" || connectError.message === "component unmounted")) {
|
|
1682
|
+
const context = {};
|
|
1683
|
+
if (agent.agentId) context.agentId = agent.agentId;
|
|
1684
|
+
await this._internal.emitError({
|
|
1685
|
+
error: connectError,
|
|
1686
|
+
code: CopilotKitCoreErrorCode.AGENT_CONNECT_FAILED,
|
|
1687
|
+
context
|
|
1688
|
+
});
|
|
1689
|
+
}
|
|
1629
1690
|
return { newMessages: [] };
|
|
1630
1691
|
}
|
|
1631
1692
|
}
|
|
@@ -1636,6 +1697,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1636
1697
|
if (agent.agentId) this._internal.suggestionEngine.clearSuggestions(agent.agentId);
|
|
1637
1698
|
if (agent instanceof _ag_ui_client.HttpAgent) agent.headers = { ...this._internal.headers };
|
|
1638
1699
|
if (agent.detachActiveRun) await agent.detachActiveRun();
|
|
1700
|
+
this._internal.subscribeAgentToStateManager(agent);
|
|
1639
1701
|
const isTopLevel = this._runDepth === 0;
|
|
1640
1702
|
let originalAbortRun;
|
|
1641
1703
|
if (isTopLevel) {
|
|
@@ -1707,7 +1769,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1707
1769
|
await this._internal.waitForPendingFrameworkUpdates();
|
|
1708
1770
|
return await this.runAgent({ agent });
|
|
1709
1771
|
}
|
|
1710
|
-
this._internal.suggestionEngine.reloadSuggestions(agentId);
|
|
1772
|
+
this._internal.suggestionEngine.reloadSuggestions(agentId, agent);
|
|
1711
1773
|
return runAgentResult;
|
|
1712
1774
|
}
|
|
1713
1775
|
/**
|
|
@@ -2127,6 +2189,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2127
2189
|
this.core = core;
|
|
2128
2190
|
_defineProperty(this, "stateByRun", /* @__PURE__ */ new Map());
|
|
2129
2191
|
_defineProperty(this, "messageToRun", /* @__PURE__ */ new Map());
|
|
2192
|
+
_defineProperty(this, "activeRun", /* @__PURE__ */ new Map());
|
|
2130
2193
|
_defineProperty(this, "agentSubscriptions", /* @__PURE__ */ new Map());
|
|
2131
2194
|
}
|
|
2132
2195
|
/**
|
|
@@ -2134,36 +2197,73 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2134
2197
|
*/
|
|
2135
2198
|
initialize() {}
|
|
2136
2199
|
/**
|
|
2137
|
-
* Subscribe to an agent's events to track state and messages
|
|
2200
|
+
* Subscribe to an agent's events to track state and messages.
|
|
2201
|
+
*
|
|
2202
|
+
* Registry agents (subscribed via `onAgentsChanged`) use the bare `agentId`
|
|
2203
|
+
* key so that `unsubscribeFromAgent(agentId)` can remove them when they
|
|
2204
|
+
* are replaced. Per-thread clones (subscribed via `subscribeAgentToStateManager`)
|
|
2205
|
+
* pass `{ isClone: true }` to use a composite `agentId:threadId` key, keeping
|
|
2206
|
+
* their subscription independent of the registry agent's.
|
|
2138
2207
|
*/
|
|
2139
|
-
subscribeToAgent(agent) {
|
|
2208
|
+
subscribeToAgent(agent, { isClone = false } = {}) {
|
|
2140
2209
|
if (!agent.agentId) return;
|
|
2141
2210
|
const agentId = agent.agentId;
|
|
2142
|
-
|
|
2211
|
+
const subscriptionKey = isClone && agent.threadId ? `${agentId}:${agent.threadId}` : agentId;
|
|
2212
|
+
const existingUnsubscribe = this.agentSubscriptions.get(subscriptionKey);
|
|
2213
|
+
if (existingUnsubscribe) {
|
|
2214
|
+
existingUnsubscribe();
|
|
2215
|
+
this.agentSubscriptions.delete(subscriptionKey);
|
|
2216
|
+
}
|
|
2217
|
+
let revoked = false;
|
|
2218
|
+
let subRunId;
|
|
2219
|
+
let runFinished = false;
|
|
2220
|
+
const effectiveInput = (input) => {
|
|
2221
|
+
var _subRunId;
|
|
2222
|
+
return {
|
|
2223
|
+
...input,
|
|
2224
|
+
runId: (_subRunId = subRunId) !== null && _subRunId !== void 0 ? _subRunId : input.runId
|
|
2225
|
+
};
|
|
2226
|
+
};
|
|
2143
2227
|
const { unsubscribe } = agent.subscribe({
|
|
2144
|
-
onRunStartedEvent: ({
|
|
2145
|
-
|
|
2228
|
+
onRunStartedEvent: ({ input, state }) => {
|
|
2229
|
+
if (revoked) return;
|
|
2230
|
+
if (runFinished && input.runId === subRunId) subRunId = (0, _ag_ui_client.randomUUID)();
|
|
2231
|
+
else subRunId = input.runId;
|
|
2232
|
+
runFinished = false;
|
|
2233
|
+
this.handleRunStarted(agent, effectiveInput(input), state);
|
|
2146
2234
|
},
|
|
2147
|
-
onRunFinishedEvent: ({
|
|
2148
|
-
|
|
2235
|
+
onRunFinishedEvent: ({ input, state }) => {
|
|
2236
|
+
if (revoked) return;
|
|
2237
|
+
runFinished = true;
|
|
2238
|
+
this.handleRunFinished(agent, effectiveInput(input), state);
|
|
2149
2239
|
},
|
|
2150
2240
|
onStateSnapshotEvent: ({ event, input, state }) => {
|
|
2151
|
-
|
|
2241
|
+
if (revoked) return;
|
|
2242
|
+
this.handleStateSnapshot(agent, event, effectiveInput(input), state);
|
|
2152
2243
|
},
|
|
2153
2244
|
onStateDeltaEvent: ({ event, input, state }) => {
|
|
2154
|
-
|
|
2245
|
+
if (revoked) return;
|
|
2246
|
+
this.handleStateDelta(agent, event, effectiveInput(input), state);
|
|
2155
2247
|
},
|
|
2156
2248
|
onMessagesSnapshotEvent: ({ event, input, messages }) => {
|
|
2157
|
-
|
|
2249
|
+
if (revoked) return;
|
|
2250
|
+
this.handleMessagesSnapshot(agent, event, effectiveInput(input), messages);
|
|
2158
2251
|
},
|
|
2159
2252
|
onNewMessage: ({ message, input }) => {
|
|
2160
|
-
|
|
2253
|
+
if (revoked) return;
|
|
2254
|
+
this.handleNewMessage(agent, message, input ? effectiveInput(input) : void 0);
|
|
2161
2255
|
}
|
|
2162
2256
|
});
|
|
2163
|
-
this.agentSubscriptions.set(
|
|
2257
|
+
this.agentSubscriptions.set(subscriptionKey, () => {
|
|
2258
|
+
revoked = true;
|
|
2259
|
+
unsubscribe();
|
|
2260
|
+
});
|
|
2164
2261
|
}
|
|
2165
2262
|
/**
|
|
2166
|
-
* Unsubscribe
|
|
2263
|
+
* Unsubscribe a registry agent's subscription (bare `agentId` key).
|
|
2264
|
+
* Per-thread clone subscriptions use composite `agentId:threadId` keys and
|
|
2265
|
+
* are replaced (not removed) by subsequent subscribeToAgent(agent, { isClone: true })
|
|
2266
|
+
* calls for the same (agentId, threadId) pair.
|
|
2167
2267
|
*/
|
|
2168
2268
|
unsubscribeFromAgent(agentId) {
|
|
2169
2269
|
const unsubscribe = this.agentSubscriptions.get(agentId);
|
|
@@ -2207,18 +2307,20 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2207
2307
|
/**
|
|
2208
2308
|
* Handle run started event
|
|
2209
2309
|
*/
|
|
2210
|
-
handleRunStarted(agent,
|
|
2310
|
+
handleRunStarted(agent, input, state) {
|
|
2211
2311
|
if (!agent.agentId) return;
|
|
2212
|
-
const { threadId, runId } =
|
|
2213
|
-
this.
|
|
2312
|
+
const { threadId, runId } = input;
|
|
2313
|
+
this.activeRun.set(`${agent.agentId}:${threadId}`, runId);
|
|
2314
|
+
if (state && Object.keys(state).length > 0) this.saveState(agent.agentId, threadId, runId, state);
|
|
2214
2315
|
}
|
|
2215
2316
|
/**
|
|
2216
2317
|
* Handle run finished event
|
|
2217
2318
|
*/
|
|
2218
|
-
handleRunFinished(agent,
|
|
2319
|
+
handleRunFinished(agent, input, state) {
|
|
2219
2320
|
if (!agent.agentId) return;
|
|
2220
|
-
const { threadId, runId } =
|
|
2221
|
-
this.
|
|
2321
|
+
const { threadId, runId } = input;
|
|
2322
|
+
this.activeRun.delete(`${agent.agentId}:${threadId}`);
|
|
2323
|
+
if (state && Object.keys(state).length > 0) this.saveState(agent.agentId, threadId, runId, state);
|
|
2222
2324
|
}
|
|
2223
2325
|
/**
|
|
2224
2326
|
* Handle state snapshot event
|
|
@@ -2252,7 +2354,14 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2252
2354
|
* Handle new message event
|
|
2253
2355
|
*/
|
|
2254
2356
|
handleNewMessage(agent, message, input) {
|
|
2255
|
-
if (!agent.agentId
|
|
2357
|
+
if (!agent.agentId) return;
|
|
2358
|
+
if (!input) {
|
|
2359
|
+
var _agent$threadId;
|
|
2360
|
+
const threadId = (_agent$threadId = agent.threadId) !== null && _agent$threadId !== void 0 ? _agent$threadId : "";
|
|
2361
|
+
const runId = this.activeRun.get(`${agent.agentId}:${threadId}`);
|
|
2362
|
+
if (runId) this.associateMessageWithRun(agent.agentId, threadId, message.id, runId);
|
|
2363
|
+
return;
|
|
2364
|
+
}
|
|
2256
2365
|
const { threadId, runId } = input;
|
|
2257
2366
|
this.associateMessageWithRun(agent.agentId, threadId, message.id, runId);
|
|
2258
2367
|
}
|
|
@@ -2335,10 +2444,11 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2335
2444
|
return CopilotKitCoreRuntimeConnectionStatus;
|
|
2336
2445
|
}({});
|
|
2337
2446
|
var CopilotKitCore = class {
|
|
2338
|
-
constructor({ runtimeUrl, runtimeTransport = "
|
|
2447
|
+
constructor({ runtimeUrl, runtimeTransport = "auto", headers = {}, credentials, properties = {}, agents__unsafe_dev_only = {}, tools = [], suggestionsConfig = [] }) {
|
|
2339
2448
|
_defineProperty(this, "_headers", void 0);
|
|
2340
2449
|
_defineProperty(this, "_credentials", void 0);
|
|
2341
2450
|
_defineProperty(this, "_properties", void 0);
|
|
2451
|
+
_defineProperty(this, "_defaultThrottleMs", void 0);
|
|
2342
2452
|
_defineProperty(this, "subscribers", /* @__PURE__ */ new Set());
|
|
2343
2453
|
_defineProperty(this, "agentRegistry", void 0);
|
|
2344
2454
|
_defineProperty(this, "contextStore", void 0);
|
|
@@ -2427,6 +2537,22 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2427
2537
|
get properties() {
|
|
2428
2538
|
return this._properties;
|
|
2429
2539
|
}
|
|
2540
|
+
/**
|
|
2541
|
+
* Default throttle interval (ms) applied by framework hooks (e.g.
|
|
2542
|
+
* `useAgent()`) when the hook/component does not specify an explicit
|
|
2543
|
+
* `throttleMs`. An explicit `0` passed as `throttleMs` to `useAgent()`
|
|
2544
|
+
* or `<CopilotChat>` overrides this default and disables throttling.
|
|
2545
|
+
*/
|
|
2546
|
+
get defaultThrottleMs() {
|
|
2547
|
+
return this._defaultThrottleMs;
|
|
2548
|
+
}
|
|
2549
|
+
setDefaultThrottleMs(value) {
|
|
2550
|
+
if (value !== void 0 && (!Number.isFinite(value) || value < 0)) {
|
|
2551
|
+
this._defaultThrottleMs = void 0;
|
|
2552
|
+
return;
|
|
2553
|
+
}
|
|
2554
|
+
this._defaultThrottleMs = value;
|
|
2555
|
+
}
|
|
2430
2556
|
get runtimeConnectionStatus() {
|
|
2431
2557
|
return this.agentRegistry.runtimeConnectionStatus;
|
|
2432
2558
|
}
|
|
@@ -2442,6 +2568,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2442
2568
|
get a2uiEnabled() {
|
|
2443
2569
|
return this.agentRegistry.a2uiEnabled;
|
|
2444
2570
|
}
|
|
2571
|
+
get openGenerativeUIEnabled() {
|
|
2572
|
+
return this.agentRegistry.openGenerativeUIEnabled;
|
|
2573
|
+
}
|
|
2445
2574
|
get licenseStatus() {
|
|
2446
2575
|
return this.agentRegistry.licenseStatus;
|
|
2447
2576
|
}
|
|
@@ -2572,6 +2701,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2572
2701
|
getRunIdsForThread(agentId, threadId) {
|
|
2573
2702
|
return this.stateManager.getRunIdsForThread(agentId, threadId);
|
|
2574
2703
|
}
|
|
2704
|
+
subscribeAgentToStateManager(agent) {
|
|
2705
|
+
this.stateManager.subscribeToAgent(agent, { isClone: true });
|
|
2706
|
+
}
|
|
2575
2707
|
/**
|
|
2576
2708
|
* Internal method used by RunHandler to build frontend tools
|
|
2577
2709
|
*/
|