@copilotkit/core 1.55.3-canary.1776243725 → 1.55.3-canary.1776979102
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 +29 -100
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -47
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +6 -47
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +29 -100
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +29 -111
- package/dist/index.umd.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -516,7 +516,6 @@ var ProxiedCopilotRuntimeAgent = class ProxiedCopilotRuntimeAgent extends _ag_ui
|
|
|
516
516
|
singleEndpointUrl;
|
|
517
517
|
runtimeMode;
|
|
518
518
|
intelligence;
|
|
519
|
-
_capabilities;
|
|
520
519
|
delegate;
|
|
521
520
|
runtimeInfoPromise;
|
|
522
521
|
constructor(config) {
|
|
@@ -533,15 +532,8 @@ var ProxiedCopilotRuntimeAgent = class ProxiedCopilotRuntimeAgent extends _ag_ui
|
|
|
533
532
|
this.transport = transport;
|
|
534
533
|
this.runtimeMode = config.runtimeMode ?? _copilotkit_shared.RUNTIME_MODE_SSE;
|
|
535
534
|
this.intelligence = config.intelligence;
|
|
536
|
-
this._capabilities = config.capabilities;
|
|
537
535
|
if (this.transport === "single") this.singleEndpointUrl = this.runtimeUrl;
|
|
538
536
|
}
|
|
539
|
-
get capabilities() {
|
|
540
|
-
return this._capabilities;
|
|
541
|
-
}
|
|
542
|
-
async getCapabilities() {
|
|
543
|
-
return this._capabilities ?? {};
|
|
544
|
-
}
|
|
545
537
|
async detachActiveRun() {
|
|
546
538
|
if (this.delegate) await this.delegate.detachActiveRun();
|
|
547
539
|
await super.detachActiveRun();
|
|
@@ -669,8 +661,7 @@ var ProxiedCopilotRuntimeAgent = class ProxiedCopilotRuntimeAgent extends _ag_ui
|
|
|
669
661
|
credentials: this.credentials,
|
|
670
662
|
transport: this.transport,
|
|
671
663
|
runtimeMode: this.runtimeMode,
|
|
672
|
-
intelligence: this.intelligence
|
|
673
|
-
capabilities: this._capabilities
|
|
664
|
+
intelligence: this.intelligence
|
|
674
665
|
});
|
|
675
666
|
cloned.threadId = this.threadId;
|
|
676
667
|
cloned.setState(this.state);
|
|
@@ -972,7 +963,7 @@ var AgentRegistry = class {
|
|
|
972
963
|
const runtimeInfoResponse = await this.fetchRuntimeInfo();
|
|
973
964
|
const { version, ...runtimeInfo } = runtimeInfoResponse;
|
|
974
965
|
const credentials = this.core.credentials;
|
|
975
|
-
this.remoteAgents = Object.fromEntries(Object.entries(runtimeInfo.agents).map(([id, { description
|
|
966
|
+
this.remoteAgents = Object.fromEntries(Object.entries(runtimeInfo.agents).map(([id, { description }]) => {
|
|
976
967
|
const agent = new ProxiedCopilotRuntimeAgent({
|
|
977
968
|
runtimeUrl: this.runtimeUrl,
|
|
978
969
|
agentId: id,
|
|
@@ -980,8 +971,7 @@ var AgentRegistry = class {
|
|
|
980
971
|
transport: this._runtimeTransport,
|
|
981
972
|
credentials,
|
|
982
973
|
runtimeMode: runtimeInfoResponse.mode ?? _copilotkit_shared.RUNTIME_MODE_SSE,
|
|
983
|
-
intelligence: runtimeInfoResponse.intelligence
|
|
984
|
-
capabilities
|
|
974
|
+
intelligence: runtimeInfoResponse.intelligence
|
|
985
975
|
});
|
|
986
976
|
this.applyHeadersToAgent(agent);
|
|
987
977
|
return [id, agent];
|
|
@@ -1189,16 +1179,10 @@ var SuggestionEngine = class {
|
|
|
1189
1179
|
/**
|
|
1190
1180
|
* Reload suggestions for a specific agent
|
|
1191
1181
|
* This triggers generation of new suggestions based on current configs
|
|
1192
|
-
*
|
|
1193
|
-
* @param agentId - The consumer agent ID
|
|
1194
|
-
* @param consumerAgent - Optional: the specific agent instance whose messages should be used
|
|
1195
|
-
* for availability filtering and context. When running with per-thread clones, the thread
|
|
1196
|
-
* clone holds the conversation messages; passing it here ensures dynamic suggestions fire
|
|
1197
|
-
* after the first message even though the registry agent has an empty message list.
|
|
1198
1182
|
*/
|
|
1199
|
-
reloadSuggestions(agentId
|
|
1183
|
+
reloadSuggestions(agentId) {
|
|
1200
1184
|
this.clearSuggestions(agentId);
|
|
1201
|
-
const agent =
|
|
1185
|
+
const agent = this.core.getAgent(agentId);
|
|
1202
1186
|
if (!agent) return;
|
|
1203
1187
|
const messageCount = agent.messages?.length ?? 0;
|
|
1204
1188
|
let hasAnySuggestions = false;
|
|
@@ -1211,7 +1195,7 @@ var SuggestionEngine = class {
|
|
|
1211
1195
|
hasAnySuggestions = true;
|
|
1212
1196
|
this.notifySuggestionsStartedLoading(agentId);
|
|
1213
1197
|
}
|
|
1214
|
-
this.generateSuggestions(suggestionId, config, agentId
|
|
1198
|
+
this.generateSuggestions(suggestionId, config, agentId);
|
|
1215
1199
|
} else if (isStaticSuggestionsConfig(config)) this.addStaticSuggestions(suggestionId, config, agentId);
|
|
1216
1200
|
}
|
|
1217
1201
|
}
|
|
@@ -1239,12 +1223,12 @@ var SuggestionEngine = class {
|
|
|
1239
1223
|
/**
|
|
1240
1224
|
* Generate suggestions using a provider agent
|
|
1241
1225
|
*/
|
|
1242
|
-
async generateSuggestions(suggestionId, config, consumerAgentId
|
|
1226
|
+
async generateSuggestions(suggestionId, config, consumerAgentId) {
|
|
1243
1227
|
let agent = void 0;
|
|
1244
1228
|
try {
|
|
1245
1229
|
const suggestionsProviderAgent = this.core.getAgent(config.providerAgentId ?? "default");
|
|
1246
1230
|
if (!suggestionsProviderAgent) throw new Error(`Suggestions provider agent not found: ${config.providerAgentId}`);
|
|
1247
|
-
const suggestionsConsumerAgent =
|
|
1231
|
+
const suggestionsConsumerAgent = this.core.getAgent(consumerAgentId);
|
|
1248
1232
|
if (!suggestionsConsumerAgent) throw new Error(`Suggestions consumer agent not found: ${consumerAgentId}`);
|
|
1249
1233
|
agent = suggestionsProviderAgent.clone();
|
|
1250
1234
|
agent.threadId = suggestionId;
|
|
@@ -1549,10 +1533,6 @@ var RunHandler = class {
|
|
|
1549
1533
|
agent.setMessages([]);
|
|
1550
1534
|
agent.setState({});
|
|
1551
1535
|
if (agent instanceof _ag_ui_client.HttpAgent) agent.headers = { ...this._internal.headers };
|
|
1552
|
-
await this._internal.notifySubscribers((subscriber) => subscriber.onAgentRunStarted?.({
|
|
1553
|
-
copilotkit: this.core,
|
|
1554
|
-
agent
|
|
1555
|
-
}), "Subscriber onAgentRunStarted error:");
|
|
1556
1536
|
const runAgentResult = await agent.connectAgent({
|
|
1557
1537
|
forwardedProps: this._internal.properties,
|
|
1558
1538
|
tools: this.buildFrontendTools(agent.agentId),
|
|
@@ -1583,11 +1563,6 @@ var RunHandler = class {
|
|
|
1583
1563
|
if (agent.agentId) this._internal.suggestionEngine.clearSuggestions(agent.agentId);
|
|
1584
1564
|
if (agent instanceof _ag_ui_client.HttpAgent) agent.headers = { ...this._internal.headers };
|
|
1585
1565
|
if (agent.detachActiveRun) await agent.detachActiveRun();
|
|
1586
|
-
this._internal.subscribeAgentToStateManager(agent);
|
|
1587
|
-
await this._internal.notifySubscribers((subscriber) => subscriber.onAgentRunStarted?.({
|
|
1588
|
-
copilotkit: this.core,
|
|
1589
|
-
agent
|
|
1590
|
-
}), "Subscriber onAgentRunStarted error:");
|
|
1591
1566
|
const isTopLevel = this._runDepth === 0;
|
|
1592
1567
|
let originalAbortRun;
|
|
1593
1568
|
if (isTopLevel) {
|
|
@@ -1658,7 +1633,7 @@ var RunHandler = class {
|
|
|
1658
1633
|
await this._internal.waitForPendingFrameworkUpdates();
|
|
1659
1634
|
return await this.runAgent({ agent });
|
|
1660
1635
|
}
|
|
1661
|
-
this._internal.suggestionEngine.reloadSuggestions(agentId
|
|
1636
|
+
this._internal.suggestionEngine.reloadSuggestions(agentId);
|
|
1662
1637
|
return runAgentResult;
|
|
1663
1638
|
}
|
|
1664
1639
|
/**
|
|
@@ -2059,7 +2034,6 @@ function parseToolArguments(rawArgs, toolName) {
|
|
|
2059
2034
|
var StateManager = class {
|
|
2060
2035
|
stateByRun = /* @__PURE__ */ new Map();
|
|
2061
2036
|
messageToRun = /* @__PURE__ */ new Map();
|
|
2062
|
-
activeRun = /* @__PURE__ */ new Map();
|
|
2063
2037
|
agentSubscriptions = /* @__PURE__ */ new Map();
|
|
2064
2038
|
constructor(core) {
|
|
2065
2039
|
this.core = core;
|
|
@@ -2069,42 +2043,18 @@ var StateManager = class {
|
|
|
2069
2043
|
*/
|
|
2070
2044
|
initialize() {}
|
|
2071
2045
|
/**
|
|
2072
|
-
* Subscribe to an agent's events to track state and messages
|
|
2073
|
-
*
|
|
2074
|
-
* Registry agents (subscribed via `onAgentsChanged`) use the bare `agentId`
|
|
2075
|
-
* key so that `unsubscribeFromAgent(agentId)` can remove them when they
|
|
2076
|
-
* are replaced. Per-thread clones (subscribed via `subscribeAgentToStateManager`)
|
|
2077
|
-
* pass `{ isClone: true }` to use a composite `agentId:threadId` key, keeping
|
|
2078
|
-
* their subscription independent of the registry agent's.
|
|
2046
|
+
* Subscribe to an agent's events to track state and messages
|
|
2079
2047
|
*/
|
|
2080
|
-
subscribeToAgent(agent
|
|
2048
|
+
subscribeToAgent(agent) {
|
|
2081
2049
|
if (!agent.agentId) return;
|
|
2082
2050
|
const agentId = agent.agentId;
|
|
2083
|
-
|
|
2084
|
-
const existingUnsubscribe = this.agentSubscriptions.get(subscriptionKey);
|
|
2085
|
-
if (existingUnsubscribe) {
|
|
2086
|
-
existingUnsubscribe();
|
|
2087
|
-
this.agentSubscriptions.delete(subscriptionKey);
|
|
2088
|
-
}
|
|
2089
|
-
let revoked = false;
|
|
2090
|
-
let subRunId;
|
|
2091
|
-
let runFinished = false;
|
|
2092
|
-
const effectiveInput = (input) => ({
|
|
2093
|
-
...input,
|
|
2094
|
-
runId: subRunId ?? input.runId
|
|
2095
|
-
});
|
|
2051
|
+
this.unsubscribeFromAgent(agentId);
|
|
2096
2052
|
const { unsubscribe } = agent.subscribe({
|
|
2097
|
-
onRunStartedEvent: ({
|
|
2098
|
-
|
|
2099
|
-
if (runFinished && input.runId === subRunId) subRunId = (0, _ag_ui_client.randomUUID)();
|
|
2100
|
-
else subRunId = input.runId;
|
|
2101
|
-
runFinished = false;
|
|
2102
|
-
this.handleRunStarted(agent, effectiveInput(input), state);
|
|
2053
|
+
onRunStartedEvent: ({ event, state }) => {
|
|
2054
|
+
this.handleRunStarted(agent, event, state);
|
|
2103
2055
|
},
|
|
2104
|
-
onRunFinishedEvent: ({
|
|
2105
|
-
|
|
2106
|
-
runFinished = true;
|
|
2107
|
-
this.handleRunFinished(agent, effectiveInput(input), state);
|
|
2056
|
+
onRunFinishedEvent: ({ event, state }) => {
|
|
2057
|
+
this.handleRunFinished(agent, event, state);
|
|
2108
2058
|
},
|
|
2109
2059
|
onRunErrorEvent: ({ input, state }) => {
|
|
2110
2060
|
if (revoked) return;
|
|
@@ -2112,32 +2062,22 @@ var StateManager = class {
|
|
|
2112
2062
|
this.handleRunFinished(agent, effectiveInput(input), state);
|
|
2113
2063
|
},
|
|
2114
2064
|
onStateSnapshotEvent: ({ event, input, state }) => {
|
|
2115
|
-
|
|
2116
|
-
this.handleStateSnapshot(agent, event, effectiveInput(input), state);
|
|
2065
|
+
this.handleStateSnapshot(agent, event, input, state);
|
|
2117
2066
|
},
|
|
2118
2067
|
onStateDeltaEvent: ({ event, input, state }) => {
|
|
2119
|
-
|
|
2120
|
-
this.handleStateDelta(agent, event, effectiveInput(input), state);
|
|
2068
|
+
this.handleStateDelta(agent, event, input, state);
|
|
2121
2069
|
},
|
|
2122
2070
|
onMessagesSnapshotEvent: ({ event, input, messages }) => {
|
|
2123
|
-
|
|
2124
|
-
this.handleMessagesSnapshot(agent, event, effectiveInput(input), messages);
|
|
2071
|
+
this.handleMessagesSnapshot(agent, event, input, messages);
|
|
2125
2072
|
},
|
|
2126
2073
|
onNewMessage: ({ message, input }) => {
|
|
2127
|
-
|
|
2128
|
-
this.handleNewMessage(agent, message, input ? effectiveInput(input) : void 0);
|
|
2074
|
+
this.handleNewMessage(agent, message, input);
|
|
2129
2075
|
}
|
|
2130
2076
|
});
|
|
2131
|
-
this.agentSubscriptions.set(
|
|
2132
|
-
revoked = true;
|
|
2133
|
-
unsubscribe();
|
|
2134
|
-
});
|
|
2077
|
+
this.agentSubscriptions.set(agentId, unsubscribe);
|
|
2135
2078
|
}
|
|
2136
2079
|
/**
|
|
2137
|
-
* Unsubscribe
|
|
2138
|
-
* Per-thread clone subscriptions use composite `agentId:threadId` keys and
|
|
2139
|
-
* are replaced (not removed) by subsequent subscribeToAgent(agent, { isClone: true })
|
|
2140
|
-
* calls for the same (agentId, threadId) pair.
|
|
2080
|
+
* Unsubscribe from an agent's events
|
|
2141
2081
|
*/
|
|
2142
2082
|
unsubscribeFromAgent(agentId) {
|
|
2143
2083
|
const unsubscribe = this.agentSubscriptions.get(agentId);
|
|
@@ -2177,20 +2117,18 @@ var StateManager = class {
|
|
|
2177
2117
|
/**
|
|
2178
2118
|
* Handle run started event
|
|
2179
2119
|
*/
|
|
2180
|
-
handleRunStarted(agent,
|
|
2120
|
+
handleRunStarted(agent, event, state) {
|
|
2181
2121
|
if (!agent.agentId) return;
|
|
2182
|
-
const { threadId, runId } =
|
|
2183
|
-
this.
|
|
2184
|
-
if (state && Object.keys(state).length > 0) this.saveState(agent.agentId, threadId, runId, state);
|
|
2122
|
+
const { threadId, runId } = event;
|
|
2123
|
+
this.saveState(agent.agentId, threadId, runId, state);
|
|
2185
2124
|
}
|
|
2186
2125
|
/**
|
|
2187
2126
|
* Handle run finished event
|
|
2188
2127
|
*/
|
|
2189
|
-
handleRunFinished(agent,
|
|
2128
|
+
handleRunFinished(agent, event, state) {
|
|
2190
2129
|
if (!agent.agentId) return;
|
|
2191
|
-
const { threadId, runId } =
|
|
2192
|
-
this.
|
|
2193
|
-
if (state && Object.keys(state).length > 0) this.saveState(agent.agentId, threadId, runId, state);
|
|
2130
|
+
const { threadId, runId } = event;
|
|
2131
|
+
this.saveState(agent.agentId, threadId, runId, state);
|
|
2194
2132
|
}
|
|
2195
2133
|
/**
|
|
2196
2134
|
* Handle state snapshot event
|
|
@@ -2224,13 +2162,7 @@ var StateManager = class {
|
|
|
2224
2162
|
* Handle new message event
|
|
2225
2163
|
*/
|
|
2226
2164
|
handleNewMessage(agent, message, input) {
|
|
2227
|
-
if (!agent.agentId) return;
|
|
2228
|
-
if (!input) {
|
|
2229
|
-
const threadId = agent.threadId ?? "";
|
|
2230
|
-
const runId = this.activeRun.get(`${agent.agentId}:${threadId}`);
|
|
2231
|
-
if (runId) this.associateMessageWithRun(agent.agentId, threadId, message.id, runId);
|
|
2232
|
-
return;
|
|
2233
|
-
}
|
|
2165
|
+
if (!agent.agentId || !input) return;
|
|
2234
2166
|
const { threadId, runId } = input;
|
|
2235
2167
|
this.associateMessageWithRun(agent.agentId, threadId, message.id, runId);
|
|
2236
2168
|
}
|
|
@@ -2560,9 +2492,6 @@ var CopilotKitCore = class {
|
|
|
2560
2492
|
getRunIdsForThread(agentId, threadId) {
|
|
2561
2493
|
return this.stateManager.getRunIdsForThread(agentId, threadId);
|
|
2562
2494
|
}
|
|
2563
|
-
subscribeAgentToStateManager(agent) {
|
|
2564
|
-
this.stateManager.subscribeToAgent(agent, { isClone: true });
|
|
2565
|
-
}
|
|
2566
2495
|
/**
|
|
2567
2496
|
* Internal method used by RunHandler to build frontend tools
|
|
2568
2497
|
*/
|