@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.umd.js CHANGED
@@ -646,12 +646,12 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
646
646
  function isZodError(error) {
647
647
  return error !== null && typeof error === "object" && "name" in error && error.name === "ZodError";
648
648
  }
649
- function isAbortError(error) {
649
+ function isAbortError$1(error) {
650
650
  return (error instanceof DOMException || error instanceof Error) && error.name === "AbortError";
651
651
  }
652
652
  function withAbortErrorHandling(observable) {
653
653
  return observable.pipe((0, rxjs_operators.catchError)((error) => {
654
- if (isZodError(error) || isAbortError(error)) return rxjs.EMPTY;
654
+ if (isZodError(error) || isAbortError$1(error)) return rxjs.EMPTY;
655
655
  throw error;
656
656
  }));
657
657
  }
@@ -1013,6 +1013,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1013
1013
  _defineProperty(this, "_runtimeMode", _copilotkit_shared.RUNTIME_MODE_SSE);
1014
1014
  _defineProperty(this, "_intelligence", void 0);
1015
1015
  _defineProperty(this, "_threadEndpoints", void 0);
1016
+ _defineProperty(this, "_suggestions", void 0);
1016
1017
  _defineProperty(this, "_a2uiEnabled", false);
1017
1018
  _defineProperty(this, "_a2uiAgents", void 0);
1018
1019
  _defineProperty(this, "_openGenerativeUIEnabled", false);
@@ -1050,6 +1051,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1050
1051
  get threadEndpoints() {
1051
1052
  return this._threadEndpoints;
1052
1053
  }
1054
+ get suggestions() {
1055
+ return this._suggestions;
1056
+ }
1053
1057
  get a2uiEnabled() {
1054
1058
  return this._a2uiEnabled;
1055
1059
  }
@@ -1237,6 +1241,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1237
1241
  this._runtimeMode = _copilotkit_shared.RUNTIME_MODE_SSE;
1238
1242
  this._intelligence = void 0;
1239
1243
  this._threadEndpoints = void 0;
1244
+ this._suggestions = void 0;
1240
1245
  this._a2uiEnabled = false;
1241
1246
  this._a2uiAgents = void 0;
1242
1247
  this._openGenerativeUIEnabled = false;
@@ -1286,6 +1291,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1286
1291
  this._runtimeMode = (_runtimeInfoResponse$3 = runtimeInfoResponse.mode) !== null && _runtimeInfoResponse$3 !== void 0 ? _runtimeInfoResponse$3 : _copilotkit_shared.RUNTIME_MODE_SSE;
1287
1292
  this._intelligence = runtimeInfoResponse.intelligence;
1288
1293
  this._threadEndpoints = runtimeInfoResponse.threadEndpoints;
1294
+ this._suggestions = runtimeInfoResponse.suggestions;
1289
1295
  const a2uiInfo = runtimeInfoResponse.a2ui;
1290
1296
  this._a2uiEnabled = (_ref = (_a2uiInfo$enabled = a2uiInfo === null || a2uiInfo === void 0 ? void 0 : a2uiInfo.enabled) !== null && _a2uiInfo$enabled !== void 0 ? _a2uiInfo$enabled : runtimeInfoResponse.a2uiEnabled) !== null && _ref !== void 0 ? _ref : false;
1291
1297
  this._a2uiAgents = (a2uiInfo === null || a2uiInfo === void 0 ? void 0 : a2uiInfo.enabled) ? a2uiInfo.agents : void 0;
@@ -1301,6 +1307,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1301
1307
  this._runtimeMode = _copilotkit_shared.RUNTIME_MODE_SSE;
1302
1308
  this._intelligence = void 0;
1303
1309
  this._threadEndpoints = void 0;
1310
+ this._suggestions = void 0;
1304
1311
  this._a2uiEnabled = false;
1305
1312
  this._a2uiAgents = void 0;
1306
1313
  this._openGenerativeUIEnabled = false;
@@ -1551,39 +1558,82 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1551
1558
  };
1552
1559
  }
1553
1560
  /**
1554
- * Generate suggestions using a provider agent
1561
+ * Generate suggestions by running a provider agent and extracting the
1562
+ * `copilotkitSuggest` tool call from its streamed messages.
1563
+ *
1564
+ * Two transports, one set of mechanics: both seed an agent with the
1565
+ * consumer's messages + state and the instruction, then `runAgent` with
1566
+ * forced `copilotkitSuggest` tool choice, parsing suggestions as messages
1567
+ * stream in via `onMessagesChanged`.
1568
+ *
1569
+ * - **Stateless** (runtime advertises `suggestions` and transport isn't
1570
+ * `single`): a stock `HttpAgent` pointed at `/agent/:id/suggest`. That
1571
+ * endpoint runs the provider directly and streams AG-UI SSE **without**
1572
+ * persisting a thread, and a plain `HttpAgent` only ever speaks REST SSE —
1573
+ * it never routes through the Intelligence websocket delegate (which would
1574
+ * persist a thread). This is the path that removes the thread flood.
1575
+ * - **Fallback** (capability absent → old runtime, or `single` transport):
1576
+ * clone the provider agent and run it client-side, as before.
1577
+ *
1578
+ * Gated to non-`single` transports because this client only builds the
1579
+ * multi-route `/agent/:id/suggest` URL; single-route deployments (not the
1580
+ * persisting-thread/Intelligence case) fall through to the clone fallback.
1555
1581
  */
1556
1582
  async generateSuggestions(suggestionId, config, consumerAgentId) {
1557
- let agent = void 0;
1583
+ let runHandle = void 0;
1584
+ let aborted = false;
1558
1585
  try {
1559
- var _config$providerAgent, _this$_runningSuggest3, _config$minSuggestion, _config$maxSuggestion;
1560
- const suggestionsProviderAgent = this.core.getAgent((_config$providerAgent = config.providerAgentId) !== null && _config$providerAgent !== void 0 ? _config$providerAgent : "default");
1561
- if (!suggestionsProviderAgent) throw new Error(`Suggestions provider agent not found: ${config.providerAgentId}`);
1562
- const suggestionsConsumerAgent = this.core.getAgent(consumerAgentId);
1586
+ var _config$providerAgent, _config$minSuggestion, _config$maxSuggestion, _suggestionsConsumerA, _this$_runningSuggest3;
1587
+ const friends = this.core;
1588
+ const resolvedProviderAgentId = (_config$providerAgent = config.providerAgentId) !== null && _config$providerAgent !== void 0 ? _config$providerAgent : "default";
1589
+ const suggestionsProviderAgent = friends.getAgent(resolvedProviderAgentId);
1590
+ if (!suggestionsProviderAgent) throw new Error(`Suggestions provider agent not found: ${resolvedProviderAgentId}`);
1591
+ const suggestionsConsumerAgent = friends.getAgent(consumerAgentId);
1563
1592
  if (!suggestionsConsumerAgent) throw new Error(`Suggestions consumer agent not found: ${consumerAgentId}`);
1564
- agent = suggestionsProviderAgent.clone();
1565
- agent.threadId = suggestionId;
1566
- agent.messages = JSON.parse(JSON.stringify(suggestionsConsumerAgent.messages));
1567
- agent.state = JSON.parse(JSON.stringify(suggestionsConsumerAgent.state));
1593
+ const instructionContent = [
1594
+ `Suggest what the user could say next. Provide clear, highly relevant suggestions by calling the \`copilotkitSuggest\` tool.`,
1595
+ `Provide at least ${(_config$minSuggestion = config.minSuggestions) !== null && _config$minSuggestion !== void 0 ? _config$minSuggestion : 1} and at most ${(_config$maxSuggestion = config.maxSuggestions) !== null && _config$maxSuggestion !== void 0 ? _config$maxSuggestion : 3} suggestions.`,
1596
+ `The user has the following tools available: ${JSON.stringify(friends.buildFrontendTools(consumerAgentId))}.`,
1597
+ ` ${config.instructions}`
1598
+ ].join("\n");
1568
1599
  this._suggestions[consumerAgentId] = {
1569
1600
  ...this._suggestions[consumerAgentId],
1570
1601
  [suggestionId]: []
1571
1602
  };
1572
- this._runningSuggestions[consumerAgentId] = [...(_this$_runningSuggest3 = this._runningSuggestions[consumerAgentId]) !== null && _this$_runningSuggest3 !== void 0 ? _this$_runningSuggest3 : [], agent];
1573
- agent.addMessage({
1603
+ const seededMessages = JSON.parse(JSON.stringify(suggestionsConsumerAgent.messages));
1604
+ const seededState = JSON.parse(JSON.stringify((_suggestionsConsumerA = suggestionsConsumerAgent.state) !== null && _suggestionsConsumerA !== void 0 ? _suggestionsConsumerA : {}));
1605
+ const useStateless = this.core.suggestions === true && this.core.runtimeTransport !== "single";
1606
+ let suggestionAgent;
1607
+ if (useStateless) {
1608
+ const suggestUrl = `${this.core.runtimeUrl}/agent/${encodeURIComponent(resolvedProviderAgentId)}/suggest`;
1609
+ const credentials = this.core.credentials;
1610
+ suggestionAgent = new _ag_ui_client.HttpAgent({
1611
+ agentId: resolvedProviderAgentId,
1612
+ url: suggestUrl,
1613
+ headers: { ...this.core.headers },
1614
+ ...credentials ? { fetch: (url, requestInit) => fetch(url, {
1615
+ ...requestInit,
1616
+ credentials
1617
+ }) } : {}
1618
+ });
1619
+ } else suggestionAgent = suggestionsProviderAgent.clone();
1620
+ suggestionAgent.threadId = suggestionId;
1621
+ suggestionAgent.setMessages(seededMessages);
1622
+ suggestionAgent.setState(seededState);
1623
+ runHandle = { abortRun: () => {
1624
+ aborted = true;
1625
+ suggestionAgent.abortRun();
1626
+ } };
1627
+ this._runningSuggestions[consumerAgentId] = [...(_this$_runningSuggest3 = this._runningSuggestions[consumerAgentId]) !== null && _this$_runningSuggest3 !== void 0 ? _this$_runningSuggest3 : [], runHandle];
1628
+ suggestionAgent.addMessage({
1574
1629
  id: suggestionId,
1575
1630
  role: "user",
1576
- content: [
1577
- `Suggest what the user could say next. Provide clear, highly relevant suggestions by calling the \`copilotkitSuggest\` tool.`,
1578
- `Provide at least ${(_config$minSuggestion = config.minSuggestions) !== null && _config$minSuggestion !== void 0 ? _config$minSuggestion : 1} and at most ${(_config$maxSuggestion = config.maxSuggestions) !== null && _config$maxSuggestion !== void 0 ? _config$maxSuggestion : 3} suggestions.`,
1579
- `The user has the following tools available: ${JSON.stringify(this.core.buildFrontendTools(consumerAgentId))}.`,
1580
- ` ${config.instructions}`
1581
- ].join("\n")
1631
+ content: instructionContent
1582
1632
  });
1583
- await agent.runAgent({
1584
- context: this.core.getContextForAgent(consumerAgentId),
1633
+ await suggestionAgent.runAgent({
1634
+ context: friends.getContextForAgent(consumerAgentId),
1585
1635
  forwardedProps: {
1586
- ...this.core.properties,
1636
+ ...friends.properties,
1587
1637
  toolChoice: {
1588
1638
  type: "function",
1589
1639
  function: { name: "copilotkitSuggest" }
@@ -1594,18 +1644,15 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1594
1644
  this.extractSuggestions(messages, suggestionId, consumerAgentId, true);
1595
1645
  } });
1596
1646
  } catch (error) {
1597
- console.warn("Error generating suggestions:", error);
1647
+ if (!isAbortError(error) && !aborted) console.warn("Error generating suggestions:", error);
1598
1648
  } finally {
1599
1649
  this.finalizeSuggestions(suggestionId, consumerAgentId);
1600
1650
  const runningAgents = this._runningSuggestions[consumerAgentId];
1601
- if (agent && runningAgents) {
1602
- const filteredAgents = runningAgents.filter((a) => a !== agent);
1603
- this._runningSuggestions[consumerAgentId] = filteredAgents;
1604
- if (filteredAgents.length === 0) {
1605
- delete this._runningSuggestions[consumerAgentId];
1606
- await this.notifySuggestionsFinishedLoading(consumerAgentId);
1607
- }
1608
- }
1651
+ const remaining = runHandle ? (runningAgents !== null && runningAgents !== void 0 ? runningAgents : []).filter((a) => a !== runHandle) : runningAgents !== null && runningAgents !== void 0 ? runningAgents : [];
1652
+ if (remaining.length === 0) {
1653
+ delete this._runningSuggestions[consumerAgentId];
1654
+ await this.notifySuggestionsFinishedLoading(consumerAgentId);
1655
+ } else this._runningSuggestions[consumerAgentId] = remaining;
1609
1656
  }
1610
1657
  }
1611
1658
  /**
@@ -1743,6 +1790,13 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1743
1790
  }
1744
1791
  };
1745
1792
  /**
1793
+ * Detects an `AbortController`-driven cancellation so the stateless path can
1794
+ * treat it as an expected (non-error) outcome on clear/reload.
1795
+ */
1796
+ function isAbortError(error) {
1797
+ return typeof error === "object" && error !== null && "name" in error && error.name === "AbortError";
1798
+ }
1799
+ /**
1746
1800
  * Type guard for dynamic suggestions config
1747
1801
  */
1748
1802
  function isDynamicSuggestionsConfig(config) {
@@ -3930,6 +3984,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3930
3984
  get threadEndpoints() {
3931
3985
  return this.agentRegistry.threadEndpoints;
3932
3986
  }
3987
+ get suggestions() {
3988
+ return this.agentRegistry.suggestions;
3989
+ }
3933
3990
  get a2uiEnabled() {
3934
3991
  return this.agentRegistry.a2uiEnabled;
3935
3992
  }
@@ -4560,6 +4617,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4560
4617
  isLoading: false,
4561
4618
  isFetchingNextPage: false,
4562
4619
  error: null,
4620
+ fetchMoreError: null,
4563
4621
  context: null,
4564
4622
  sessionId: 0,
4565
4623
  metadataCredentialsRequested: false,
@@ -4647,6 +4705,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4647
4705
  isLoading: Boolean(context),
4648
4706
  isFetchingNextPage: false,
4649
4707
  error: null,
4708
+ fetchMoreError: null,
4650
4709
  metadataCredentialsRequested: false,
4651
4710
  metadataJoinCode: null,
4652
4711
  nextCursor: null,
@@ -4658,6 +4717,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4658
4717
  isLoading: false,
4659
4718
  isFetchingNextPage: false,
4660
4719
  error: null,
4720
+ fetchMoreError: null,
4661
4721
  metadataCredentialsRequested: false,
4662
4722
  metadataJoinCode: null,
4663
4723
  nextCursor: null,
@@ -4668,7 +4728,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4668
4728
  return {
4669
4729
  ...state,
4670
4730
  isLoading: true,
4671
- error: null
4731
+ error: null,
4732
+ fetchMoreError: null
4672
4733
  };
4673
4734
  }), on(threadRestEvents.listSucceeded, (state, { sessionId, threads, joinCode, nextCursor }) => {
4674
4735
  if (sessionId !== state.sessionId) return state;
@@ -4678,6 +4739,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4678
4739
  threads: sortThreadsByRecency(threads),
4679
4740
  isLoading: false,
4680
4741
  error: null,
4742
+ fetchMoreError: null,
4681
4743
  metadataJoinCode: joinCode,
4682
4744
  metadataCredentialsRequested: joinCodeChanged ? false : state.metadataCredentialsRequested,
4683
4745
  nextCursor
@@ -4697,6 +4759,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4697
4759
  ...state,
4698
4760
  threads: merged,
4699
4761
  isFetchingNextPage: false,
4762
+ fetchMoreError: null,
4700
4763
  nextCursor
4701
4764
  };
4702
4765
  }), on(threadRestEvents.nextPageFailed, (state, { sessionId, error }) => {
@@ -4704,7 +4767,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4704
4767
  return {
4705
4768
  ...state,
4706
4769
  isFetchingNextPage: false,
4707
- error
4770
+ fetchMoreError: error
4708
4771
  };
4709
4772
  }), on(threadRestEvents.metadataCredentialsFailed, (state, { sessionId }) => {
4710
4773
  if (sessionId !== state.sessionId) return state;
@@ -4722,7 +4785,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4722
4785
  if (!state.nextCursor || state.isFetchingNextPage) return state;
4723
4786
  return {
4724
4787
  ...state,
4725
- isFetchingNextPage: true
4788
+ isFetchingNextPage: true,
4789
+ fetchMoreError: null
4726
4790
  };
4727
4791
  }), on(threadAdapterEvents.renameRequested, (state, { threadId, name }) => {
4728
4792
  const existing = state.threads.find((thread) => thread.id === threadId);
@@ -4852,6 +4916,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4852
4916
  threads: createSelector((state) => state.threads),
4853
4917
  isLoading: createSelector((state) => state.isLoading),
4854
4918
  error: createSelector((state) => state.error),
4919
+ fetchMoreError: createSelector((state) => state.fetchMoreError),
4855
4920
  hasNextPage: createSelector((state) => state.nextCursor != null),
4856
4921
  isFetchingNextPage: createSelector((state) => state.isFetchingNextPage),
4857
4922
  isMutating: createSelector((state) => state.inFlightMutationCount > 0)
@@ -4861,6 +4926,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4861
4926
  const selectThreads = standaloneSelectors.threads;
4862
4927
  const selectThreadsIsLoading = standaloneSelectors.isLoading;
4863
4928
  const selectThreadsError = standaloneSelectors.error;
4929
+ const selectFetchMoreError = standaloneSelectors.fetchMoreError;
4864
4930
  const selectHasNextPage = standaloneSelectors.hasNextPage;
4865
4931
  const selectIsFetchingNextPage = standaloneSelectors.isFetchingNextPage;
4866
4932
  const selectIsMutating = standaloneSelectors.isMutating;
@@ -5246,6 +5312,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
5246
5312
  const ɵselectThreads = selectThreads;
5247
5313
  const ɵselectThreadsIsLoading = selectThreadsIsLoading;
5248
5314
  const ɵselectThreadsError = selectThreadsError;
5315
+ const ɵselectFetchMoreError = selectFetchMoreError;
5249
5316
  const ɵselectHasNextPage = selectHasNextPage;
5250
5317
  const ɵselectIsFetchingNextPage = selectIsFetchingNextPage;
5251
5318
  const ɵselectIsMutating = selectIsMutating;
@@ -5325,6 +5392,7 @@ exports.createSelector = createSelector;
5325
5392
  exports.createStore = createStore;
5326
5393
  exports.empty = empty;
5327
5394
  exports.ensureObjectArgs = ensureObjectArgs;
5395
+ exports.isAbortError = isAbortError;
5328
5396
  exports.isRunCompletionAware = isRunCompletionAware;
5329
5397
  exports.ofType = ofType;
5330
5398
  exports.on = on;
@@ -5350,6 +5418,7 @@ exports.ɵobservePhoenixSocketHealth$ = ɵobservePhoenixSocketHealth$;
5350
5418
  exports.ɵobservePhoenixSocketSignals$ = ɵobservePhoenixSocketSignals$;
5351
5419
  exports.ɵphoenixChannel$ = ɵphoenixChannel$;
5352
5420
  exports.ɵphoenixSocket$ = ɵphoenixSocket$;
5421
+ exports.ɵselectFetchMoreError = ɵselectFetchMoreError;
5353
5422
  exports.ɵselectHasNextPage = ɵselectHasNextPage;
5354
5423
  exports.ɵselectIsFetchingNextPage = ɵselectIsFetchingNextPage;
5355
5424
  exports.ɵselectIsMutating = ɵselectIsMutating;