@yourgpt/copilot-sdk 2.5.1-beta.1 → 2.5.2-alpha.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/ui/index.cjs CHANGED
@@ -1,9 +1,9 @@
1
1
  'use strict';
2
2
 
3
- var chunk6R63NBNP_cjs = require('../chunk-6R63NBNP.cjs');
3
+ var chunk4PL7TK42_cjs = require('../chunk-4PL7TK42.cjs');
4
4
  var chunkJO4BHPAD_cjs = require('../chunk-JO4BHPAD.cjs');
5
5
  var chunk5EGBIQYS_cjs = require('../chunk-5EGBIQYS.cjs');
6
- var chunkZYLHGNIG_cjs = require('../chunk-ZYLHGNIG.cjs');
6
+ var chunkGW5ZZHJ7_cjs = require('../chunk-GW5ZZHJ7.cjs');
7
7
  var chunk7GWEW2DU_cjs = require('../chunk-7GWEW2DU.cjs');
8
8
  require('../chunk-JGPDQDY4.cjs');
9
9
  require('../chunk-BJYA5NDL.cjs');
@@ -5987,6 +5987,7 @@ function ChatComponent({
5987
5987
  currentThreadId,
5988
5988
  onSwitchThread,
5989
5989
  isThreadBusy,
5990
+ busyThreadIds,
5990
5991
  // Branching
5991
5992
  getBranchInfo,
5992
5993
  onSwitchBranch,
@@ -6228,7 +6229,8 @@ function ChatComponent({
6228
6229
  currentThreadId,
6229
6230
  onSwitchThread,
6230
6231
  onDeleteThread,
6231
- isThreadBusy
6232
+ isThreadBusy,
6233
+ busyThreadIds
6232
6234
  }),
6233
6235
  [
6234
6236
  view,
@@ -6244,7 +6246,8 @@ function ChatComponent({
6244
6246
  currentThreadId,
6245
6247
  onSwitchThread,
6246
6248
  onDeleteThread,
6247
- isThreadBusy
6249
+ isThreadBusy,
6250
+ busyThreadIds
6248
6251
  ]
6249
6252
  );
6250
6253
  return /* @__PURE__ */ jsxRuntime.jsx(MessageActionsProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(CopilotChatContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsxRuntime.jsxs(
@@ -6903,7 +6906,7 @@ function useInternalThreadManager(config = {}) {
6903
6906
  } = config;
6904
6907
  const [state, dispatch] = React19.useReducer(threadReducer, INITIAL_STATE);
6905
6908
  const isLoadingRef = React19.useRef(false);
6906
- const threadManager = chunk6R63NBNP_cjs.useThreadManager({
6909
+ const threadManager = chunk4PL7TK42_cjs.useThreadManager({
6907
6910
  adapter,
6908
6911
  saveDebounce,
6909
6912
  autoRestoreLastThread
@@ -6924,8 +6927,12 @@ function useInternalThreadManager(config = {}) {
6924
6927
  getAllMessages,
6925
6928
  switchBranch,
6926
6929
  threadId: sdkThreadId,
6927
- setActiveThread
6928
- } = chunkZYLHGNIG_cjs.useCopilot();
6930
+ setActiveThread,
6931
+ concurrentThreads,
6932
+ busyThreadIds,
6933
+ assignLocalThreadId,
6934
+ sessionStatus
6935
+ } = chunkGW5ZZHJ7_cjs.useCopilot();
6929
6936
  React19.useEffect(() => {
6930
6937
  if (!enabled || state.initialized || !currentThread) return;
6931
6938
  dispatch({ type: "RESTORE_START" });
@@ -6933,8 +6940,16 @@ function useInternalThreadManager(config = {}) {
6933
6940
  if (currentThread.messages && currentThread.messages.length > 0) {
6934
6941
  const uiMessages = currentThread.messages.map(coreToUI);
6935
6942
  const snapshot = getMessageSnapshot(uiMessages);
6936
- setMessages(uiMessages);
6937
- if (currentThread.activeLeafId) switchBranch(currentThread.activeLeafId);
6943
+ if (concurrentThreads) {
6944
+ setActiveThread(currentThread.id, {
6945
+ hydrateMessages: uiMessages,
6946
+ hydrateActiveLeafId: currentThread.activeLeafId
6947
+ });
6948
+ } else {
6949
+ setMessages(uiMessages);
6950
+ if (currentThread.activeLeafId)
6951
+ switchBranch(currentThread.activeLeafId);
6952
+ }
6938
6953
  onThreadChange?.(currentThread.id);
6939
6954
  dispatch({
6940
6955
  type: "RESTORE_COMPLETE",
@@ -6942,6 +6957,9 @@ function useInternalThreadManager(config = {}) {
6942
6957
  snapshot
6943
6958
  });
6944
6959
  } else {
6960
+ if (concurrentThreads) {
6961
+ setActiveThread(currentThread.id);
6962
+ }
6945
6963
  onThreadChange?.(currentThread.id);
6946
6964
  dispatch({
6947
6965
  type: "RESTORE_COMPLETE",
@@ -6958,7 +6976,9 @@ function useInternalThreadManager(config = {}) {
6958
6976
  state.initialized,
6959
6977
  setMessages,
6960
6978
  switchBranch,
6961
- onThreadChange
6979
+ onThreadChange,
6980
+ concurrentThreads,
6981
+ setActiveThread
6962
6982
  ]);
6963
6983
  React19.useEffect(() => {
6964
6984
  if (!enabled) {
@@ -6973,11 +6993,24 @@ function useInternalThreadManager(config = {}) {
6973
6993
  if (!enabled) return;
6974
6994
  if (state.phase !== "idle") return;
6975
6995
  if (isLoadingRef.current) return;
6976
- if (status === "streaming" || status === "submitted") return;
6977
6996
  if (messages.length === 0) return;
6978
6997
  if (currentThreadId) return;
6998
+ const streaming = status === "streaming" || status === "submitted";
6999
+ if (streaming && !concurrentThreads) return;
7000
+ if (concurrentThreads && sessionStatus === "creating" && !sdkThreadId) {
7001
+ return;
7002
+ }
6979
7003
  dispatch({ type: "FIRST_RESPONSE_COMPLETE" });
6980
- }, [enabled, state.phase, status, messages.length, currentThreadId]);
7004
+ }, [
7005
+ enabled,
7006
+ state.phase,
7007
+ status,
7008
+ messages.length,
7009
+ currentThreadId,
7010
+ concurrentThreads,
7011
+ sdkThreadId,
7012
+ sessionStatus
7013
+ ]);
6981
7014
  React19.useEffect(() => {
6982
7015
  if (state.phase !== "awaiting_server_id") return;
6983
7016
  if (sdkThreadId) {
@@ -6994,11 +7027,15 @@ function useInternalThreadManager(config = {}) {
6994
7027
  );
6995
7028
  const activeLeafId = messages[messages.length - 1]?.id;
6996
7029
  const snapshot = getMessageSnapshot(messages);
7030
+ const usingLocalId = !sdkThreadId;
6997
7031
  createThread({
6998
7032
  id: sdkThreadId ?? void 0,
6999
7033
  messages: coreMessages,
7000
7034
  activeLeafId
7001
7035
  }).then((thread) => {
7036
+ if (concurrentThreads && usingLocalId) {
7037
+ assignLocalThreadId(thread.id);
7038
+ }
7002
7039
  dispatch({ type: "THREAD_CREATED", threadId: thread.id, snapshot });
7003
7040
  onThreadChange?.(thread.id);
7004
7041
  });
@@ -7035,41 +7072,62 @@ function useInternalThreadManager(config = {}) {
7035
7072
  dispatch({ type: "START_SWITCH" });
7036
7073
  isLoadingRef.current = true;
7037
7074
  const thread = await switchThread(threadId);
7038
- if (thread?.messages) {
7039
- const uiMessages = thread.messages.map(coreToUI);
7040
- const snapshot = getMessageSnapshot(uiMessages);
7041
- setMessages(uiMessages);
7042
- if (thread.activeLeafId) switchBranch(thread.activeLeafId);
7043
- onThreadChange?.(threadId);
7044
- dispatch({ type: "SWITCH_COMPLETE", threadId, snapshot });
7075
+ const uiMessages = thread?.messages ? thread.messages.map(coreToUI) : [];
7076
+ const snapshot = thread?.messages ? getMessageSnapshot(uiMessages) : "";
7077
+ if (concurrentThreads) {
7078
+ setActiveThread(threadId, {
7079
+ hydrateMessages: uiMessages,
7080
+ hydrateActiveLeafId: thread?.activeLeafId
7081
+ });
7045
7082
  } else {
7046
- setMessages([]);
7047
- onThreadChange?.(threadId);
7048
- dispatch({ type: "SWITCH_COMPLETE", threadId, snapshot: "" });
7083
+ if (thread?.messages) {
7084
+ setMessages(uiMessages);
7085
+ if (thread.activeLeafId) switchBranch(thread.activeLeafId);
7086
+ } else {
7087
+ setMessages([]);
7088
+ }
7049
7089
  }
7090
+ onThreadChange?.(threadId);
7091
+ dispatch({ type: "SWITCH_COMPLETE", threadId, snapshot });
7050
7092
  requestAnimationFrame(() => {
7051
7093
  isLoadingRef.current = false;
7052
7094
  });
7053
7095
  },
7054
- [switchThread, setMessages, switchBranch, onThreadChange]
7096
+ [
7097
+ switchThread,
7098
+ setMessages,
7099
+ switchBranch,
7100
+ onThreadChange,
7101
+ concurrentThreads,
7102
+ setActiveThread
7103
+ ]
7055
7104
  );
7056
7105
  const handleNewThread = React19.useCallback(async () => {
7057
7106
  isLoadingRef.current = true;
7058
7107
  clearCurrentThread();
7059
- setMessages([]);
7108
+ if (!concurrentThreads) {
7109
+ setMessages([]);
7110
+ }
7060
7111
  setActiveThread(null);
7061
7112
  onThreadChange?.(null);
7062
7113
  dispatch({ type: "NEW_THREAD" });
7063
7114
  requestAnimationFrame(() => {
7064
7115
  isLoadingRef.current = false;
7065
7116
  });
7066
- }, [clearCurrentThread, setMessages, setActiveThread, onThreadChange]);
7067
- const isBusy = isLoading || status === "streaming" || status === "submitted";
7117
+ }, [
7118
+ clearCurrentThread,
7119
+ setMessages,
7120
+ setActiveThread,
7121
+ onThreadChange,
7122
+ concurrentThreads
7123
+ ]);
7124
+ const isBusy = !concurrentThreads && (isLoading || status === "streaming" || status === "submitted");
7068
7125
  return {
7069
7126
  threadManager,
7070
7127
  handleSwitchThread,
7071
7128
  handleNewThread,
7072
- isBusy
7129
+ isBusy,
7130
+ busyThreadIds
7073
7131
  };
7074
7132
  }
7075
7133
  function parsePersistenceConfig(persistence, onThreadChange) {
@@ -7154,8 +7212,9 @@ function CopilotChatBase(props) {
7154
7212
  switchBranch,
7155
7213
  getBranchInfo,
7156
7214
  editMessage,
7157
- error: chatError
7158
- } = chunkZYLHGNIG_cjs.useCopilot();
7215
+ error: chatError,
7216
+ disposeThreadInstance
7217
+ } = chunkGW5ZZHJ7_cjs.useCopilot();
7159
7218
  const toolExecutions = rawToolExecutions.map(
7160
7219
  (exec) => ({
7161
7220
  id: exec.id,
@@ -7307,16 +7366,23 @@ function CopilotChatBase(props) {
7307
7366
  suggestions: classNames.suggestions,
7308
7367
  footer: classNames.footer
7309
7368
  } : void 0;
7310
- const { threadManager, handleSwitchThread, handleNewThread, isBusy } = threadManagerResult;
7369
+ const {
7370
+ threadManager,
7371
+ handleSwitchThread,
7372
+ handleNewThread,
7373
+ isBusy,
7374
+ busyThreadIds
7375
+ } = threadManagerResult;
7311
7376
  const handleDeleteThread = React19__namespace.default.useCallback(
7312
7377
  (threadId) => {
7313
7378
  const isCurrentThread = threadManager.currentThreadId === threadId;
7379
+ disposeThreadInstance(threadId);
7314
7380
  threadManager.deleteThread(threadId);
7315
7381
  if (isCurrentThread) {
7316
7382
  handleNewThread();
7317
7383
  }
7318
7384
  },
7319
- [threadManager, handleNewThread]
7385
+ [threadManager, handleNewThread, disposeThreadInstance]
7320
7386
  );
7321
7387
  const threadPickerElement = isPersistenceEnabled && showThreadPicker ? /* @__PURE__ */ jsxRuntime.jsx(
7322
7388
  ThreadPicker,
@@ -7366,6 +7432,7 @@ function CopilotChatBase(props) {
7366
7432
  currentThreadId: threadManager.currentThreadId,
7367
7433
  onSwitchThread: isPersistenceEnabled ? handleSwitchThread : void 0,
7368
7434
  isThreadBusy: isBusy,
7435
+ busyThreadIds,
7369
7436
  getBranchInfo,
7370
7437
  onSwitchBranch: switchBranch,
7371
7438
  onEditMessage: allowEdit ? editMessage : void 0,