@copilotkit/core 1.62.2-canary.1783457132 → 1.62.3
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 +103 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +39 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +39 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +102 -35
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +104 -35
- package/dist/index.umd.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -544,12 +544,12 @@ function hasCredentials(agent) {
|
|
|
544
544
|
function isZodError(error) {
|
|
545
545
|
return error !== null && typeof error === "object" && "name" in error && error.name === "ZodError";
|
|
546
546
|
}
|
|
547
|
-
function isAbortError(error) {
|
|
547
|
+
function isAbortError$1(error) {
|
|
548
548
|
return (error instanceof DOMException || error instanceof Error) && error.name === "AbortError";
|
|
549
549
|
}
|
|
550
550
|
function withAbortErrorHandling(observable) {
|
|
551
551
|
return observable.pipe((0, rxjs_operators.catchError)((error) => {
|
|
552
|
-
if (isZodError(error) || isAbortError(error)) return rxjs.EMPTY;
|
|
552
|
+
if (isZodError(error) || isAbortError$1(error)) return rxjs.EMPTY;
|
|
553
553
|
throw error;
|
|
554
554
|
}));
|
|
555
555
|
}
|
|
@@ -897,6 +897,7 @@ var AgentRegistry = class {
|
|
|
897
897
|
_runtimeMode = _copilotkit_shared.RUNTIME_MODE_SSE;
|
|
898
898
|
_intelligence;
|
|
899
899
|
_threadEndpoints;
|
|
900
|
+
_suggestions;
|
|
900
901
|
_a2uiEnabled = false;
|
|
901
902
|
_a2uiAgents;
|
|
902
903
|
_openGenerativeUIEnabled = false;
|
|
@@ -946,6 +947,9 @@ var AgentRegistry = class {
|
|
|
946
947
|
get threadEndpoints() {
|
|
947
948
|
return this._threadEndpoints;
|
|
948
949
|
}
|
|
950
|
+
get suggestions() {
|
|
951
|
+
return this._suggestions;
|
|
952
|
+
}
|
|
949
953
|
get a2uiEnabled() {
|
|
950
954
|
return this._a2uiEnabled;
|
|
951
955
|
}
|
|
@@ -1133,6 +1137,7 @@ var AgentRegistry = class {
|
|
|
1133
1137
|
this._runtimeMode = _copilotkit_shared.RUNTIME_MODE_SSE;
|
|
1134
1138
|
this._intelligence = void 0;
|
|
1135
1139
|
this._threadEndpoints = void 0;
|
|
1140
|
+
this._suggestions = void 0;
|
|
1136
1141
|
this._a2uiEnabled = false;
|
|
1137
1142
|
this._a2uiAgents = void 0;
|
|
1138
1143
|
this._openGenerativeUIEnabled = false;
|
|
@@ -1180,6 +1185,7 @@ var AgentRegistry = class {
|
|
|
1180
1185
|
this._runtimeMode = runtimeInfoResponse.mode ?? _copilotkit_shared.RUNTIME_MODE_SSE;
|
|
1181
1186
|
this._intelligence = runtimeInfoResponse.intelligence;
|
|
1182
1187
|
this._threadEndpoints = runtimeInfoResponse.threadEndpoints;
|
|
1188
|
+
this._suggestions = runtimeInfoResponse.suggestions;
|
|
1183
1189
|
const a2uiInfo = runtimeInfoResponse.a2ui;
|
|
1184
1190
|
this._a2uiEnabled = a2uiInfo?.enabled ?? runtimeInfoResponse.a2uiEnabled ?? false;
|
|
1185
1191
|
this._a2uiAgents = a2uiInfo?.enabled ? a2uiInfo.agents : void 0;
|
|
@@ -1195,6 +1201,7 @@ var AgentRegistry = class {
|
|
|
1195
1201
|
this._runtimeMode = _copilotkit_shared.RUNTIME_MODE_SSE;
|
|
1196
1202
|
this._intelligence = void 0;
|
|
1197
1203
|
this._threadEndpoints = void 0;
|
|
1204
|
+
this._suggestions = void 0;
|
|
1198
1205
|
this._a2uiEnabled = false;
|
|
1199
1206
|
this._a2uiAgents = void 0;
|
|
1200
1207
|
this._openGenerativeUIEnabled = false;
|
|
@@ -1434,38 +1441,81 @@ var SuggestionEngine = class {
|
|
|
1434
1441
|
};
|
|
1435
1442
|
}
|
|
1436
1443
|
/**
|
|
1437
|
-
* Generate suggestions
|
|
1444
|
+
* Generate suggestions by running a provider agent and extracting the
|
|
1445
|
+
* `copilotkitSuggest` tool call from its streamed messages.
|
|
1446
|
+
*
|
|
1447
|
+
* Two transports, one set of mechanics: both seed an agent with the
|
|
1448
|
+
* consumer's messages + state and the instruction, then `runAgent` with
|
|
1449
|
+
* forced `copilotkitSuggest` tool choice, parsing suggestions as messages
|
|
1450
|
+
* stream in via `onMessagesChanged`.
|
|
1451
|
+
*
|
|
1452
|
+
* - **Stateless** (runtime advertises `suggestions` and transport isn't
|
|
1453
|
+
* `single`): a stock `HttpAgent` pointed at `/agent/:id/suggest`. That
|
|
1454
|
+
* endpoint runs the provider directly and streams AG-UI SSE **without**
|
|
1455
|
+
* persisting a thread, and a plain `HttpAgent` only ever speaks REST SSE —
|
|
1456
|
+
* it never routes through the Intelligence websocket delegate (which would
|
|
1457
|
+
* persist a thread). This is the path that removes the thread flood.
|
|
1458
|
+
* - **Fallback** (capability absent → old runtime, or `single` transport):
|
|
1459
|
+
* clone the provider agent and run it client-side, as before.
|
|
1460
|
+
*
|
|
1461
|
+
* Gated to non-`single` transports because this client only builds the
|
|
1462
|
+
* multi-route `/agent/:id/suggest` URL; single-route deployments (not the
|
|
1463
|
+
* persisting-thread/Intelligence case) fall through to the clone fallback.
|
|
1438
1464
|
*/
|
|
1439
1465
|
async generateSuggestions(suggestionId, config, consumerAgentId) {
|
|
1440
|
-
let
|
|
1466
|
+
let runHandle = void 0;
|
|
1467
|
+
let aborted = false;
|
|
1441
1468
|
try {
|
|
1442
|
-
const
|
|
1443
|
-
|
|
1444
|
-
const
|
|
1469
|
+
const friends = this.core;
|
|
1470
|
+
const resolvedProviderAgentId = config.providerAgentId ?? "default";
|
|
1471
|
+
const suggestionsProviderAgent = friends.getAgent(resolvedProviderAgentId);
|
|
1472
|
+
if (!suggestionsProviderAgent) throw new Error(`Suggestions provider agent not found: ${resolvedProviderAgentId}`);
|
|
1473
|
+
const suggestionsConsumerAgent = friends.getAgent(consumerAgentId);
|
|
1445
1474
|
if (!suggestionsConsumerAgent) throw new Error(`Suggestions consumer agent not found: ${consumerAgentId}`);
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1475
|
+
const instructionContent = [
|
|
1476
|
+
`Suggest what the user could say next. Provide clear, highly relevant suggestions by calling the \`copilotkitSuggest\` tool.`,
|
|
1477
|
+
`Provide at least ${config.minSuggestions ?? 1} and at most ${config.maxSuggestions ?? 3} suggestions.`,
|
|
1478
|
+
`The user has the following tools available: ${JSON.stringify(friends.buildFrontendTools(consumerAgentId))}.`,
|
|
1479
|
+
` ${config.instructions}`
|
|
1480
|
+
].join("\n");
|
|
1450
1481
|
this._suggestions[consumerAgentId] = {
|
|
1451
1482
|
...this._suggestions[consumerAgentId],
|
|
1452
1483
|
[suggestionId]: []
|
|
1453
1484
|
};
|
|
1454
|
-
|
|
1455
|
-
|
|
1485
|
+
const seededMessages = JSON.parse(JSON.stringify(suggestionsConsumerAgent.messages));
|
|
1486
|
+
const seededState = JSON.parse(JSON.stringify(suggestionsConsumerAgent.state ?? {}));
|
|
1487
|
+
const useStateless = this.core.suggestions === true && this.core.runtimeTransport !== "single";
|
|
1488
|
+
let suggestionAgent;
|
|
1489
|
+
if (useStateless) {
|
|
1490
|
+
const suggestUrl = `${this.core.runtimeUrl}/agent/${encodeURIComponent(resolvedProviderAgentId)}/suggest`;
|
|
1491
|
+
const credentials = this.core.credentials;
|
|
1492
|
+
suggestionAgent = new _ag_ui_client.HttpAgent({
|
|
1493
|
+
agentId: resolvedProviderAgentId,
|
|
1494
|
+
url: suggestUrl,
|
|
1495
|
+
headers: { ...this.core.headers },
|
|
1496
|
+
...credentials ? { fetch: (url, requestInit) => fetch(url, {
|
|
1497
|
+
...requestInit,
|
|
1498
|
+
credentials
|
|
1499
|
+
}) } : {}
|
|
1500
|
+
});
|
|
1501
|
+
} else suggestionAgent = suggestionsProviderAgent.clone();
|
|
1502
|
+
suggestionAgent.threadId = suggestionId;
|
|
1503
|
+
suggestionAgent.setMessages(seededMessages);
|
|
1504
|
+
suggestionAgent.setState(seededState);
|
|
1505
|
+
runHandle = { abortRun: () => {
|
|
1506
|
+
aborted = true;
|
|
1507
|
+
suggestionAgent.abortRun();
|
|
1508
|
+
} };
|
|
1509
|
+
this._runningSuggestions[consumerAgentId] = [...this._runningSuggestions[consumerAgentId] ?? [], runHandle];
|
|
1510
|
+
suggestionAgent.addMessage({
|
|
1456
1511
|
id: suggestionId,
|
|
1457
1512
|
role: "user",
|
|
1458
|
-
content:
|
|
1459
|
-
`Suggest what the user could say next. Provide clear, highly relevant suggestions by calling the \`copilotkitSuggest\` tool.`,
|
|
1460
|
-
`Provide at least ${config.minSuggestions ?? 1} and at most ${config.maxSuggestions ?? 3} suggestions.`,
|
|
1461
|
-
`The user has the following tools available: ${JSON.stringify(this.core.buildFrontendTools(consumerAgentId))}.`,
|
|
1462
|
-
` ${config.instructions}`
|
|
1463
|
-
].join("\n")
|
|
1513
|
+
content: instructionContent
|
|
1464
1514
|
});
|
|
1465
|
-
await
|
|
1466
|
-
context:
|
|
1515
|
+
await suggestionAgent.runAgent({
|
|
1516
|
+
context: friends.getContextForAgent(consumerAgentId),
|
|
1467
1517
|
forwardedProps: {
|
|
1468
|
-
...
|
|
1518
|
+
...friends.properties,
|
|
1469
1519
|
toolChoice: {
|
|
1470
1520
|
type: "function",
|
|
1471
1521
|
function: { name: "copilotkitSuggest" }
|
|
@@ -1476,18 +1526,15 @@ var SuggestionEngine = class {
|
|
|
1476
1526
|
this.extractSuggestions(messages, suggestionId, consumerAgentId, true);
|
|
1477
1527
|
} });
|
|
1478
1528
|
} catch (error) {
|
|
1479
|
-
console.warn("Error generating suggestions:", error);
|
|
1529
|
+
if (!isAbortError(error) && !aborted) console.warn("Error generating suggestions:", error);
|
|
1480
1530
|
} finally {
|
|
1481
1531
|
this.finalizeSuggestions(suggestionId, consumerAgentId);
|
|
1482
1532
|
const runningAgents = this._runningSuggestions[consumerAgentId];
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
this._runningSuggestions[consumerAgentId]
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
await this.notifySuggestionsFinishedLoading(consumerAgentId);
|
|
1489
|
-
}
|
|
1490
|
-
}
|
|
1533
|
+
const remaining = runHandle ? (runningAgents ?? []).filter((a) => a !== runHandle) : runningAgents ?? [];
|
|
1534
|
+
if (remaining.length === 0) {
|
|
1535
|
+
delete this._runningSuggestions[consumerAgentId];
|
|
1536
|
+
await this.notifySuggestionsFinishedLoading(consumerAgentId);
|
|
1537
|
+
} else this._runningSuggestions[consumerAgentId] = remaining;
|
|
1491
1538
|
}
|
|
1492
1539
|
}
|
|
1493
1540
|
/**
|
|
@@ -1607,6 +1654,13 @@ var SuggestionEngine = class {
|
|
|
1607
1654
|
}
|
|
1608
1655
|
};
|
|
1609
1656
|
/**
|
|
1657
|
+
* Detects an `AbortController`-driven cancellation so the stateless path can
|
|
1658
|
+
* treat it as an expected (non-error) outcome on clear/reload.
|
|
1659
|
+
*/
|
|
1660
|
+
function isAbortError(error) {
|
|
1661
|
+
return typeof error === "object" && error !== null && "name" in error && error.name === "AbortError";
|
|
1662
|
+
}
|
|
1663
|
+
/**
|
|
1610
1664
|
* Type guard for dynamic suggestions config
|
|
1611
1665
|
*/
|
|
1612
1666
|
function isDynamicSuggestionsConfig(config) {
|
|
@@ -3787,6 +3841,9 @@ var CopilotKitCore = class {
|
|
|
3787
3841
|
get threadEndpoints() {
|
|
3788
3842
|
return this.agentRegistry.threadEndpoints;
|
|
3789
3843
|
}
|
|
3844
|
+
get suggestions() {
|
|
3845
|
+
return this.agentRegistry.suggestions;
|
|
3846
|
+
}
|
|
3790
3847
|
get a2uiEnabled() {
|
|
3791
3848
|
return this.agentRegistry.a2uiEnabled;
|
|
3792
3849
|
}
|
|
@@ -4409,6 +4466,7 @@ const initialThreadState = {
|
|
|
4409
4466
|
isLoading: false,
|
|
4410
4467
|
isFetchingNextPage: false,
|
|
4411
4468
|
error: null,
|
|
4469
|
+
fetchMoreError: null,
|
|
4412
4470
|
context: null,
|
|
4413
4471
|
sessionId: 0,
|
|
4414
4472
|
metadataCredentialsRequested: false,
|
|
@@ -4494,6 +4552,7 @@ const threadReducer = createReducer(initialThreadState, on(threadAdapterEvents.c
|
|
|
4494
4552
|
isLoading: Boolean(context),
|
|
4495
4553
|
isFetchingNextPage: false,
|
|
4496
4554
|
error: null,
|
|
4555
|
+
fetchMoreError: null,
|
|
4497
4556
|
metadataCredentialsRequested: false,
|
|
4498
4557
|
metadataJoinCode: null,
|
|
4499
4558
|
nextCursor: null,
|
|
@@ -4505,6 +4564,7 @@ const threadReducer = createReducer(initialThreadState, on(threadAdapterEvents.c
|
|
|
4505
4564
|
isLoading: false,
|
|
4506
4565
|
isFetchingNextPage: false,
|
|
4507
4566
|
error: null,
|
|
4567
|
+
fetchMoreError: null,
|
|
4508
4568
|
metadataCredentialsRequested: false,
|
|
4509
4569
|
metadataJoinCode: null,
|
|
4510
4570
|
nextCursor: null,
|
|
@@ -4515,7 +4575,8 @@ const threadReducer = createReducer(initialThreadState, on(threadAdapterEvents.c
|
|
|
4515
4575
|
return {
|
|
4516
4576
|
...state,
|
|
4517
4577
|
isLoading: true,
|
|
4518
|
-
error: null
|
|
4578
|
+
error: null,
|
|
4579
|
+
fetchMoreError: null
|
|
4519
4580
|
};
|
|
4520
4581
|
}), on(threadRestEvents.listSucceeded, (state, { sessionId, threads, joinCode, nextCursor }) => {
|
|
4521
4582
|
if (sessionId !== state.sessionId) return state;
|
|
@@ -4525,6 +4586,7 @@ const threadReducer = createReducer(initialThreadState, on(threadAdapterEvents.c
|
|
|
4525
4586
|
threads: sortThreadsByRecency(threads),
|
|
4526
4587
|
isLoading: false,
|
|
4527
4588
|
error: null,
|
|
4589
|
+
fetchMoreError: null,
|
|
4528
4590
|
metadataJoinCode: joinCode,
|
|
4529
4591
|
metadataCredentialsRequested: joinCodeChanged ? false : state.metadataCredentialsRequested,
|
|
4530
4592
|
nextCursor
|
|
@@ -4544,6 +4606,7 @@ const threadReducer = createReducer(initialThreadState, on(threadAdapterEvents.c
|
|
|
4544
4606
|
...state,
|
|
4545
4607
|
threads: merged,
|
|
4546
4608
|
isFetchingNextPage: false,
|
|
4609
|
+
fetchMoreError: null,
|
|
4547
4610
|
nextCursor
|
|
4548
4611
|
};
|
|
4549
4612
|
}), on(threadRestEvents.nextPageFailed, (state, { sessionId, error }) => {
|
|
@@ -4551,7 +4614,7 @@ const threadReducer = createReducer(initialThreadState, on(threadAdapterEvents.c
|
|
|
4551
4614
|
return {
|
|
4552
4615
|
...state,
|
|
4553
4616
|
isFetchingNextPage: false,
|
|
4554
|
-
error
|
|
4617
|
+
fetchMoreError: error
|
|
4555
4618
|
};
|
|
4556
4619
|
}), on(threadRestEvents.metadataCredentialsFailed, (state, { sessionId }) => {
|
|
4557
4620
|
if (sessionId !== state.sessionId) return state;
|
|
@@ -4569,7 +4632,8 @@ const threadReducer = createReducer(initialThreadState, on(threadAdapterEvents.c
|
|
|
4569
4632
|
if (!state.nextCursor || state.isFetchingNextPage) return state;
|
|
4570
4633
|
return {
|
|
4571
4634
|
...state,
|
|
4572
|
-
isFetchingNextPage: true
|
|
4635
|
+
isFetchingNextPage: true,
|
|
4636
|
+
fetchMoreError: null
|
|
4573
4637
|
};
|
|
4574
4638
|
}), on(threadAdapterEvents.renameRequested, (state, { threadId, name }) => {
|
|
4575
4639
|
const existing = state.threads.find((thread) => thread.id === threadId);
|
|
@@ -4698,6 +4762,7 @@ function createThreadSelectors() {
|
|
|
4698
4762
|
threads: createSelector((state) => state.threads),
|
|
4699
4763
|
isLoading: createSelector((state) => state.isLoading),
|
|
4700
4764
|
error: createSelector((state) => state.error),
|
|
4765
|
+
fetchMoreError: createSelector((state) => state.fetchMoreError),
|
|
4701
4766
|
hasNextPage: createSelector((state) => state.nextCursor != null),
|
|
4702
4767
|
isFetchingNextPage: createSelector((state) => state.isFetchingNextPage),
|
|
4703
4768
|
isMutating: createSelector((state) => state.inFlightMutationCount > 0)
|
|
@@ -4707,6 +4772,7 @@ const standaloneSelectors = createThreadSelectors();
|
|
|
4707
4772
|
const selectThreads = standaloneSelectors.threads;
|
|
4708
4773
|
const selectThreadsIsLoading = standaloneSelectors.isLoading;
|
|
4709
4774
|
const selectThreadsError = standaloneSelectors.error;
|
|
4775
|
+
const selectFetchMoreError = standaloneSelectors.fetchMoreError;
|
|
4710
4776
|
const selectHasNextPage = standaloneSelectors.hasNextPage;
|
|
4711
4777
|
const selectIsFetchingNextPage = standaloneSelectors.isFetchingNextPage;
|
|
4712
4778
|
const selectIsMutating = standaloneSelectors.isMutating;
|
|
@@ -5080,6 +5146,7 @@ const ɵcreateThreadSelectors = createThreadSelectors;
|
|
|
5080
5146
|
const ɵselectThreads = selectThreads;
|
|
5081
5147
|
const ɵselectThreadsIsLoading = selectThreadsIsLoading;
|
|
5082
5148
|
const ɵselectThreadsError = selectThreadsError;
|
|
5149
|
+
const ɵselectFetchMoreError = selectFetchMoreError;
|
|
5083
5150
|
const ɵselectHasNextPage = selectHasNextPage;
|
|
5084
5151
|
const ɵselectIsFetchingNextPage = selectIsFetchingNextPage;
|
|
5085
5152
|
const ɵselectIsMutating = selectIsMutating;
|
|
@@ -5159,6 +5226,7 @@ exports.createSelector = createSelector;
|
|
|
5159
5226
|
exports.createStore = createStore;
|
|
5160
5227
|
exports.empty = empty;
|
|
5161
5228
|
exports.ensureObjectArgs = ensureObjectArgs;
|
|
5229
|
+
exports.isAbortError = isAbortError;
|
|
5162
5230
|
exports.isRunCompletionAware = isRunCompletionAware;
|
|
5163
5231
|
exports.ofType = ofType;
|
|
5164
5232
|
exports.on = on;
|
|
@@ -5184,6 +5252,7 @@ exports.ɵobservePhoenixSocketHealth$ = ɵobservePhoenixSocketHealth$;
|
|
|
5184
5252
|
exports.ɵobservePhoenixSocketSignals$ = ɵobservePhoenixSocketSignals$;
|
|
5185
5253
|
exports.ɵphoenixChannel$ = ɵphoenixChannel$;
|
|
5186
5254
|
exports.ɵphoenixSocket$ = ɵphoenixSocket$;
|
|
5255
|
+
exports.ɵselectFetchMoreError = ɵselectFetchMoreError;
|
|
5187
5256
|
exports.ɵselectHasNextPage = ɵselectHasNextPage;
|
|
5188
5257
|
exports.ɵselectIsFetchingNextPage = ɵselectIsFetchingNextPage;
|
|
5189
5258
|
exports.ɵselectIsMutating = ɵselectIsMutating;
|