@copilotkit/core 1.61.2 → 1.62.1

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
@@ -1854,6 +1854,13 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1854
1854
  if (incomingThreadId && typeof proxied.clearReplayCursor === "function") proxied.clearReplayCursor(incomingThreadId);
1855
1855
  }
1856
1856
  this._internal.applyHeadersToAgent(agent);
1857
+ await this._internal.notifySubscribers((subscriber) => {
1858
+ var _subscriber$onAgentRu;
1859
+ return (_subscriber$onAgentRu = subscriber.onAgentRunStarted) === null || _subscriber$onAgentRu === void 0 ? void 0 : _subscriber$onAgentRu.call(subscriber, {
1860
+ copilotkit: this.core,
1861
+ agent
1862
+ });
1863
+ }, "Subscriber onAgentRunStarted error:");
1857
1864
  const runAgentResult = await agent.connectAgent({
1858
1865
  forwardedProps: this._internal.properties,
1859
1866
  tools: this.buildFrontendTools(agent.agentId),
@@ -1897,6 +1904,13 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1897
1904
  controller.abort();
1898
1905
  originalAbortRun();
1899
1906
  };
1907
+ await this._internal.notifySubscribers((subscriber) => {
1908
+ var _subscriber$onAgentRu2;
1909
+ return (_subscriber$onAgentRu2 = subscriber.onAgentRunStarted) === null || _subscriber$onAgentRu2 === void 0 ? void 0 : _subscriber$onAgentRu2.call(subscriber, {
1910
+ copilotkit: this.core,
1911
+ agent
1912
+ });
1913
+ }, "Subscriber onAgentRunStarted error:");
1900
1914
  }
1901
1915
  this._runDepth++;
1902
1916
  try {
@@ -3737,7 +3751,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3737
3751
  sessionId: 0,
3738
3752
  metadataCredentialsRequested: false,
3739
3753
  metadataJoinCode: null,
3740
- nextCursor: null
3754
+ nextCursor: null,
3755
+ inFlightMutationCount: 0,
3756
+ pendingDeletes: {}
3741
3757
  };
3742
3758
  const threadAdapterEvents = createActionGroup("Thread Adapter", {
3743
3759
  started: empty(),
@@ -3747,7 +3763,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3747
3763
  renameRequested: props(),
3748
3764
  archiveRequested: props(),
3749
3765
  unarchiveRequested: props(),
3750
- deleteRequested: props()
3766
+ deleteRequested: props(),
3767
+ newThreadStarted: empty()
3751
3768
  });
3752
3769
  const threadRestEvents = createActionGroup("Thread REST", {
3753
3770
  listRequested: props(),
@@ -3795,7 +3812,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3795
3812
  error: null,
3796
3813
  metadataCredentialsRequested: false,
3797
3814
  metadataJoinCode: null,
3798
- nextCursor: null
3815
+ nextCursor: null,
3816
+ inFlightMutationCount: 0,
3817
+ pendingDeletes: {}
3799
3818
  })), on(threadAdapterEvents.stopped, (state) => ({
3800
3819
  ...state,
3801
3820
  threads: [],
@@ -3804,7 +3823,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3804
3823
  error: null,
3805
3824
  metadataCredentialsRequested: false,
3806
3825
  metadataJoinCode: null,
3807
- nextCursor: null
3826
+ nextCursor: null,
3827
+ inFlightMutationCount: 0,
3828
+ pendingDeletes: {}
3808
3829
  })), on(threadRestEvents.listRequested, (state, { sessionId }) => {
3809
3830
  if (sessionId !== state.sessionId || !state.context) return state;
3810
3831
  return {
@@ -3846,12 +3867,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3846
3867
  isFetchingNextPage: false,
3847
3868
  error
3848
3869
  };
3849
- }), on(threadRestEvents.metadataCredentialsFailed, (state, { sessionId, error }) => {
3870
+ }), on(threadRestEvents.metadataCredentialsFailed, (state, { sessionId }) => {
3850
3871
  if (sessionId !== state.sessionId) return state;
3851
- return {
3852
- ...state,
3853
- error
3854
- };
3872
+ return state;
3855
3873
  }), on(threadRestEvents.metadataCredentialsRequested, (state, { sessionId }) => {
3856
3874
  if (sessionId !== state.sessionId) return state;
3857
3875
  return {
@@ -3864,10 +3882,106 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3864
3882
  ...state,
3865
3883
  isFetchingNextPage: true
3866
3884
  };
3867
- }), on(threadRestEvents.mutationFinished, (state, { outcome }) => ({
3885
+ }), on(threadAdapterEvents.renameRequested, (state, { threadId, name }) => {
3886
+ const existing = state.threads.find((thread) => thread.id === threadId);
3887
+ const inFlightMutationCount = state.inFlightMutationCount + 1;
3888
+ if (!existing) return {
3889
+ ...state,
3890
+ inFlightMutationCount
3891
+ };
3892
+ return {
3893
+ ...state,
3894
+ threads: upsertThread(state.threads, {
3895
+ ...existing,
3896
+ name
3897
+ }),
3898
+ inFlightMutationCount
3899
+ };
3900
+ }), on(threadAdapterEvents.archiveRequested, (state, { threadId }) => {
3901
+ var _state$context;
3902
+ const existing = state.threads.find((thread) => thread.id === threadId);
3903
+ const inFlightMutationCount = state.inFlightMutationCount + 1;
3904
+ if (!existing) return {
3905
+ ...state,
3906
+ inFlightMutationCount
3907
+ };
3908
+ if (!((_state$context = state.context) === null || _state$context === void 0 ? void 0 : _state$context.includeArchived)) return {
3909
+ ...state,
3910
+ threads: state.threads.filter((thread) => thread.id !== threadId),
3911
+ inFlightMutationCount
3912
+ };
3913
+ return {
3914
+ ...state,
3915
+ threads: upsertThread(state.threads, {
3916
+ ...existing,
3917
+ archived: true
3918
+ }),
3919
+ inFlightMutationCount
3920
+ };
3921
+ }), on(threadAdapterEvents.unarchiveRequested, (state, { threadId }) => {
3922
+ const existing = state.threads.find((thread) => thread.id === threadId);
3923
+ const inFlightMutationCount = state.inFlightMutationCount + 1;
3924
+ if (!existing) return {
3925
+ ...state,
3926
+ inFlightMutationCount
3927
+ };
3928
+ return {
3929
+ ...state,
3930
+ threads: upsertThread(state.threads, {
3931
+ ...existing,
3932
+ archived: false
3933
+ }),
3934
+ inFlightMutationCount
3935
+ };
3936
+ }), on(threadAdapterEvents.deleteRequested, (state, { requestId, threadId }) => {
3937
+ const existing = state.threads.find((thread) => thread.id === threadId);
3938
+ const inFlightMutationCount = state.inFlightMutationCount + 1;
3939
+ if (!existing) return {
3940
+ ...state,
3941
+ inFlightMutationCount
3942
+ };
3943
+ return {
3944
+ ...state,
3945
+ threads: state.threads.filter((thread) => thread.id !== threadId),
3946
+ pendingDeletes: {
3947
+ ...state.pendingDeletes,
3948
+ [requestId]: existing
3949
+ },
3950
+ inFlightMutationCount
3951
+ };
3952
+ }), on(threadAdapterEvents.newThreadStarted, (state) => ({
3868
3953
  ...state,
3869
- error: outcome.ok ? state.error : outcome.error
3870
- })), on(threadDomainEvents.threadUpserted, (state, { sessionId, thread }) => {
3954
+ error: null
3955
+ })), on(threadRestEvents.mutationFinished, (state, { outcome }) => {
3956
+ if (outcome.sessionId !== state.sessionId) return state;
3957
+ const inFlightMutationCount = Math.max(0, state.inFlightMutationCount - 1);
3958
+ if (outcome.ok) {
3959
+ if (state.pendingDeletes[outcome.requestId] === void 0) return {
3960
+ ...state,
3961
+ inFlightMutationCount
3962
+ };
3963
+ const { [outcome.requestId]: _settled, ...rest } = state.pendingDeletes;
3964
+ return {
3965
+ ...state,
3966
+ inFlightMutationCount,
3967
+ pendingDeletes: rest
3968
+ };
3969
+ }
3970
+ const rolledBack = state.pendingDeletes[outcome.requestId];
3971
+ if (rolledBack === void 0) return {
3972
+ ...state,
3973
+ inFlightMutationCount,
3974
+ error: outcome.error
3975
+ };
3976
+ const { [outcome.requestId]: _restored, ...rest } = state.pendingDeletes;
3977
+ return {
3978
+ ...state,
3979
+ threads: upsertThread(state.threads, rolledBack),
3980
+ pendingDeletes: rest,
3981
+ inFlightMutationCount,
3982
+ error: outcome.error
3983
+ };
3984
+ }), on(threadDomainEvents.threadUpserted, (state, { sessionId, thread }) => {
3871
3985
  if (sessionId !== state.sessionId) return state;
3872
3986
  return {
3873
3987
  ...state,
@@ -3880,11 +3994,34 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3880
3994
  threads: state.threads.filter((thread) => thread.id !== threadId)
3881
3995
  };
3882
3996
  }));
3883
- const selectThreads = createSelector((state) => state.threads);
3884
- const selectThreadsIsLoading = createSelector((state) => state.isLoading);
3885
- const selectThreadsError = createSelector((state) => state.error);
3886
- const selectHasNextPage = createSelector((state) => state.nextCursor != null);
3887
- const selectIsFetchingNextPage = createSelector((state) => state.isFetchingNextPage);
3997
+ /**
3998
+ * Builds a fresh set of memoized thread selectors.
3999
+ *
4000
+ * Each `createSelector` closure owns a private one-entry cache. Sharing a
4001
+ * single module-level selector instance across multiple concurrent stores
4002
+ * (e.g. a `<CopilotThreadsDrawer>` plus an independent `useThreads`) makes every
4003
+ * cross-store emission a cache miss, defeating memoization and risking
4004
+ * emission instability for any future selector that allocates a new
4005
+ * object/array. Creating a per-store instance keeps each store's cache
4006
+ * isolated so concurrent stores never thrash one another.
4007
+ */
4008
+ function createThreadSelectors() {
4009
+ return {
4010
+ threads: createSelector((state) => state.threads),
4011
+ isLoading: createSelector((state) => state.isLoading),
4012
+ error: createSelector((state) => state.error),
4013
+ hasNextPage: createSelector((state) => state.nextCursor != null),
4014
+ isFetchingNextPage: createSelector((state) => state.isFetchingNextPage),
4015
+ isMutating: createSelector((state) => state.inFlightMutationCount > 0)
4016
+ };
4017
+ }
4018
+ const standaloneSelectors = createThreadSelectors();
4019
+ const selectThreads = standaloneSelectors.threads;
4020
+ const selectThreadsIsLoading = standaloneSelectors.isLoading;
4021
+ const selectThreadsError = standaloneSelectors.error;
4022
+ const selectHasNextPage = standaloneSelectors.hasNextPage;
4023
+ const selectIsFetchingNextPage = standaloneSelectors.isFetchingNextPage;
4024
+ const selectIsMutating = standaloneSelectors.isMutating;
3888
4025
  let threadRequestId = 0;
3889
4026
  function createThreadRequestId() {
3890
4027
  threadRequestId += 1;
@@ -3977,10 +4114,12 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3977
4114
  body: JSON.stringify(request.body)
3978
4115
  }).pipe((0, rxjs_operators.map)(() => threadRestEvents.mutationFinished({ outcome: {
3979
4116
  requestId: request.requestId,
4117
+ sessionId: request.sessionId,
3980
4118
  ok: true
3981
4119
  } })), (0, rxjs_operators.catchError)((error) => {
3982
4120
  return (0, rxjs.of)(threadRestEvents.mutationFinished({ outcome: {
3983
4121
  requestId: request.requestId,
4122
+ sessionId: request.sessionId,
3984
4123
  ok: false,
3985
4124
  error: error instanceof Error ? error : new Error(String(error))
3986
4125
  } }));
@@ -3988,6 +4127,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3988
4127
  });
3989
4128
  }
3990
4129
  function createThreadStore(environment) {
4130
+ const selectors = createThreadSelectors();
3991
4131
  const store = createStore({
3992
4132
  reducer: threadReducer,
3993
4133
  effects: [
@@ -3997,16 +4137,16 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3997
4137
  context
3998
4138
  })), (0, rxjs_operators.takeUntil)(actions$.pipe(ofType(threadAdapterEvents.contextChanged, threadAdapterEvents.stopped))), (0, rxjs_operators.switchMap)(({ action: currentAction, context }) => createThreadFetchObservable(environment, context, currentAction.sessionId)))))),
3999
4139
  createEffect((actions$, state$) => actions$.pipe(ofType(threadRestEvents.listSucceeded), (0, rxjs_operators.withLatestFrom)(state$), (0, rxjs_operators.filter)(([action, state]) => {
4000
- var _state$context;
4001
- return action.sessionId === state.sessionId && !state.metadataCredentialsRequested && Boolean((_state$context = state.context) === null || _state$context === void 0 ? void 0 : _state$context.wsUrl) && Boolean(state.metadataJoinCode);
4140
+ var _state$context2;
4141
+ return action.sessionId === state.sessionId && !state.metadataCredentialsRequested && Boolean((_state$context2 = state.context) === null || _state$context2 === void 0 ? void 0 : _state$context2.wsUrl) && Boolean(state.metadataJoinCode);
4002
4142
  }), (0, rxjs_operators.map)(([action]) => threadRestEvents.metadataCredentialsRequested({ sessionId: action.sessionId })))),
4003
4143
  createEffect((actions$, state$) => actions$.pipe(ofType(threadRestEvents.metadataCredentialsRequested), (0, rxjs_operators.switchMap)((action) => state$.pipe((0, rxjs_operators.map)((state) => state.context), (0, rxjs_operators.filter)((context) => Boolean(context)), (0, rxjs_operators.take)(1), (0, rxjs_operators.map)((context) => ({
4004
4144
  action,
4005
4145
  context
4006
4146
  })), (0, rxjs_operators.takeUntil)(actions$.pipe(ofType(threadAdapterEvents.contextChanged, threadAdapterEvents.stopped))), (0, rxjs_operators.switchMap)(({ action: currentAction, context }) => createThreadMetadataCredentialsObservable(environment, context, currentAction.sessionId)))))),
4007
4147
  createEffect((actions$, state$) => actions$.pipe(ofType(threadRestEvents.metadataCredentialsSucceeded), (0, rxjs_operators.withLatestFrom)(state$), (0, rxjs_operators.filter)(([action, state]) => {
4008
- var _state$context2;
4009
- return action.sessionId === state.sessionId && Boolean((_state$context2 = state.context) === null || _state$context2 === void 0 ? void 0 : _state$context2.wsUrl);
4148
+ var _state$context3;
4149
+ return action.sessionId === state.sessionId && Boolean((_state$context3 = state.context) === null || _state$context3 === void 0 ? void 0 : _state$context3.wsUrl);
4010
4150
  }), (0, rxjs_operators.switchMap)(([action, state]) => {
4011
4151
  const context = state.context;
4012
4152
  const joinToken = action.joinToken;
@@ -4043,12 +4183,12 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4043
4183
  });
4044
4184
  }))),
4045
4185
  createEffect((actions$, state$) => actions$.pipe(ofType(threadSocketEvents.metadataReceived), (0, rxjs_operators.withLatestFrom)(state$), (0, rxjs_operators.filter)(([action, state]) => action.sessionId === state.sessionId), (0, rxjs_operators.map)(([action, state]) => {
4046
- var _state$context3;
4186
+ var _state$context4;
4047
4187
  if (action.payload.operation === "deleted") return threadDomainEvents.threadDeleted({
4048
4188
  sessionId: action.sessionId,
4049
4189
  threadId: action.payload.deleted.id
4050
4190
  });
4051
- if (action.payload.operation === "archived" && !((_state$context3 = state.context) === null || _state$context3 === void 0 ? void 0 : _state$context3.includeArchived)) return threadDomainEvents.threadDeleted({
4191
+ if (action.payload.operation === "archived" && !((_state$context4 = state.context) === null || _state$context4 === void 0 ? void 0 : _state$context4.includeArchived)) return threadDomainEvents.threadDeleted({
4052
4192
  sessionId: action.sessionId,
4053
4193
  threadId: action.payload.threadId
4054
4194
  });
@@ -4057,6 +4197,10 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4057
4197
  thread: action.payload.thread
4058
4198
  });
4059
4199
  }))),
4200
+ createEffect((actions$, state$) => actions$.pipe(ofType(threadSocketEvents.joinFailed, threadSocketEvents.joinTimedOut, threadSocketEvents.errored, threadRestEvents.metadataCredentialsFailed), (0, rxjs_operators.withLatestFrom)(state$), (0, rxjs_operators.filter)(([action, state]) => action.sessionId === state.sessionId), (0, rxjs_operators.tap)(([action]) => {
4201
+ const reason = threadSocketEvents.joinTimedOut.match(action) ? "channel join timed out" : threadSocketEvents.joinFailed.match(action) ? "channel join was rejected" : threadRestEvents.metadataCredentialsFailed.match(action) ? "metadata credentials fetch failed" : "socket errored";
4202
+ console.warn(`[threads] realtime ${reason}; the thread list may be stale until reconnect`);
4203
+ })), { dispatch: false }),
4060
4204
  createEffect((actions$, state$) => actions$.pipe(ofType(threadAdapterEvents.fetchNextPageRequested), (0, rxjs_operators.withLatestFrom)(state$), (0, rxjs_operators.filter)(([, state]) => Boolean(state.context) && Boolean(state.nextCursor)), (0, rxjs_operators.switchMap)(([, state]) => {
4061
4205
  const context = state.context;
4062
4206
  const params = {
@@ -4091,11 +4235,13 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4091
4235
  }))), (0, rxjs_operators.takeUntil)(actions$.pipe(ofType(threadAdapterEvents.contextChanged, threadAdapterEvents.stopped))));
4092
4236
  }))),
4093
4237
  createEffect((actions$, state$) => actions$.pipe(ofType(threadAdapterEvents.renameRequested, threadAdapterEvents.archiveRequested, threadAdapterEvents.unarchiveRequested, threadAdapterEvents.deleteRequested), (0, rxjs_operators.withLatestFrom)(state$), (0, rxjs_operators.mergeMap)(([action, state]) => {
4238
+ const sessionId = state.sessionId;
4094
4239
  const context = state.context;
4095
4240
  if (!(context === null || context === void 0 ? void 0 : context.runtimeUrl)) {
4096
4241
  const requestId = action.requestId;
4097
4242
  return (0, rxjs.of)(threadRestEvents.mutationFinished({ outcome: {
4098
4243
  requestId,
4244
+ sessionId,
4099
4245
  ok: false,
4100
4246
  error: /* @__PURE__ */ new Error("Runtime URL is not configured")
4101
4247
  } }));
@@ -4103,6 +4249,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4103
4249
  const commonBody = { agentId: context.agentId };
4104
4250
  if (threadAdapterEvents.renameRequested.match(action)) return createThreadMutationObservable(environment, context, {
4105
4251
  requestId: action.requestId,
4252
+ sessionId,
4106
4253
  method: "PATCH",
4107
4254
  path: `/threads/${encodeURIComponent(action.threadId)}`,
4108
4255
  body: {
@@ -4112,12 +4259,14 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4112
4259
  });
4113
4260
  if (threadAdapterEvents.archiveRequested.match(action)) return createThreadMutationObservable(environment, context, {
4114
4261
  requestId: action.requestId,
4262
+ sessionId,
4115
4263
  method: "POST",
4116
4264
  path: `/threads/${encodeURIComponent(action.threadId)}/archive`,
4117
4265
  body: commonBody
4118
4266
  });
4119
4267
  if (threadAdapterEvents.unarchiveRequested.match(action)) return createThreadMutationObservable(environment, context, {
4120
4268
  requestId: action.requestId,
4269
+ sessionId,
4121
4270
  method: "PATCH",
4122
4271
  path: `/threads/${encodeURIComponent(action.threadId)}`,
4123
4272
  body: {
@@ -4127,6 +4276,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4127
4276
  });
4128
4277
  return createThreadMutationObservable(environment, context, {
4129
4278
  requestId: action.requestId,
4279
+ sessionId,
4130
4280
  method: "DELETE",
4131
4281
  path: `/threads/${encodeURIComponent(action.threadId)}`,
4132
4282
  body: commonBody
@@ -4137,6 +4287,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4137
4287
  function trackMutation(dispatchAction) {
4138
4288
  const resultPromise = (0, rxjs.firstValueFrom)((0, rxjs.merge)(store.actions$.pipe(ofType(threadRestEvents.mutationFinished), (0, rxjs_operators.filter)((action) => action.outcome.requestId === dispatchAction.requestId), (0, rxjs_operators.map)((action) => action.outcome)), store.actions$.pipe(ofType(threadAdapterEvents.stopped), (0, rxjs_operators.map)(() => ({
4139
4289
  requestId: dispatchAction.requestId,
4290
+ sessionId: store.getState().sessionId,
4140
4291
  ok: false,
4141
4292
  error: /* @__PURE__ */ new Error("Thread store stopped before mutation completed")
4142
4293
  })))).pipe((0, rxjs_operators.take)(1))).then((outcome) => {
@@ -4146,13 +4297,26 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4146
4297
  store.dispatch(dispatchAction);
4147
4298
  return resultPromise;
4148
4299
  }
4300
+ let errorSubscription = null;
4301
+ const subscribeErrors = () => {
4302
+ if (!environment.onError || errorSubscription) return;
4303
+ errorSubscription = store.actions$.pipe(ofType(threadRestEvents.mutationFinished), (0, rxjs_operators.filter)((action) => !action.outcome.ok && action.outcome.sessionId === store.getState().sessionId)).subscribe((action) => {
4304
+ if (!action.outcome.ok) {
4305
+ var _environment$onError;
4306
+ (_environment$onError = environment.onError) === null || _environment$onError === void 0 || _environment$onError.call(environment, action.outcome.error);
4307
+ }
4308
+ });
4309
+ };
4149
4310
  return {
4150
4311
  start() {
4151
4312
  store.init();
4313
+ subscribeErrors();
4152
4314
  store.dispatch(threadAdapterEvents.started());
4153
4315
  },
4154
4316
  stop() {
4155
4317
  store.dispatch(threadAdapterEvents.stopped());
4318
+ errorSubscription === null || errorSubscription === void 0 || errorSubscription.unsubscribe();
4319
+ errorSubscription = null;
4156
4320
  store.stop();
4157
4321
  },
4158
4322
  setContext(context) {
@@ -4163,6 +4327,14 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4163
4327
  if (!context) return;
4164
4328
  store.dispatch(threadRestEvents.listRequested({ sessionId }));
4165
4329
  },
4330
+ refetchThreads() {
4331
+ const { sessionId, context } = store.getState();
4332
+ if (!context) return;
4333
+ store.dispatch(threadRestEvents.listRequested({ sessionId }));
4334
+ },
4335
+ startNewThread() {
4336
+ store.dispatch(threadAdapterEvents.newThreadStarted());
4337
+ },
4166
4338
  fetchNextPage() {
4167
4339
  store.dispatch(threadAdapterEvents.fetchNextPageRequested());
4168
4340
  },
@@ -4194,15 +4366,21 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4194
4366
  getState() {
4195
4367
  return store.getState();
4196
4368
  },
4197
- select: store.select.bind(store)
4369
+ getServerState() {
4370
+ return initialThreadState;
4371
+ },
4372
+ select: store.select.bind(store),
4373
+ selectors
4198
4374
  };
4199
4375
  }
4200
4376
  const ɵthreadAdapterEvents = threadAdapterEvents;
4377
+ const ɵcreateThreadSelectors = createThreadSelectors;
4201
4378
  const ɵselectThreads = selectThreads;
4202
4379
  const ɵselectThreadsIsLoading = selectThreadsIsLoading;
4203
4380
  const ɵselectThreadsError = selectThreadsError;
4204
4381
  const ɵselectHasNextPage = selectHasNextPage;
4205
4382
  const ɵselectIsFetchingNextPage = selectIsFetchingNextPage;
4383
+ const ɵselectIsMutating = selectIsMutating;
4206
4384
  /**
4207
4385
  * Number of consecutive WebSocket connection failures after which the
4208
4386
  * threads channel tears itself down rather than retrying indefinitely.
@@ -4211,6 +4389,51 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4211
4389
  */
4212
4390
  const ɵMAX_SOCKET_RETRIES = MAX_SOCKET_RETRIES;
4213
4391
 
4392
+ //#endregion
4393
+ //#region src/features.ts
4394
+ /**
4395
+ * Central registry of CopilotKit feature names.
4396
+ *
4397
+ * Feature names are the strings passed to a license context's `checkFeature`
4398
+ * (see `@copilotkit/shared`'s `LicenseContextValue`). Historically the only
4399
+ * features referenced by literal were the chat surfaces (`chat`, `sidebar`,
4400
+ * `popup`); this module makes the set explicit and typed so new surfaces —
4401
+ * such as the threads drawer — register a real, discoverable feature name
4402
+ * rather than an ad-hoc string scattered across components.
4403
+ *
4404
+ * `checkFeature` itself still accepts any `string` for backward compatibility;
4405
+ * this registry simply documents and types the names CopilotKit recognises.
4406
+ */
4407
+ /**
4408
+ * The set of feature names CopilotKit recognises.
4409
+ *
4410
+ * Frozen so the array cannot be mutated at runtime. Add new surfaces here when
4411
+ * they begin gating behaviour on `checkFeature`.
4412
+ */
4413
+ const ɵCOPILOTKIT_FEATURES = Object.freeze([
4414
+ "chat",
4415
+ "sidebar",
4416
+ "popup",
4417
+ "threads"
4418
+ ]);
4419
+ const FEATURE_SET = new Set(ɵCOPILOTKIT_FEATURES);
4420
+ /**
4421
+ * Type guard: returns `true` when `name` is a recognised CopilotKit feature.
4422
+ *
4423
+ * @param name - Candidate feature name.
4424
+ * @returns Whether `name` is a registered feature.
4425
+ *
4426
+ * @example
4427
+ * ```ts
4428
+ * if (ɵisCopilotKitFeature("threads")) {
4429
+ * // narrowed to ɵCopilotKitFeature
4430
+ * }
4431
+ * ```
4432
+ */
4433
+ function ɵisCopilotKitFeature(name) {
4434
+ return FEATURE_SET.has(name);
4435
+ }
4436
+
4214
4437
  //#endregion
4215
4438
  exports.AgentRegistry = AgentRegistry;
4216
4439
  exports.AgentThreadLockedError = AgentThreadLockedError;
@@ -4238,8 +4461,11 @@ exports.on = on;
4238
4461
  exports.parseToolArguments = parseToolArguments;
4239
4462
  exports.props = props;
4240
4463
  exports.select = select;
4464
+ exports.ɵCOPILOTKIT_FEATURES = ɵCOPILOTKIT_FEATURES;
4241
4465
  exports.ɵMAX_SOCKET_RETRIES = ɵMAX_SOCKET_RETRIES;
4466
+ exports.ɵcreateThreadSelectors = ɵcreateThreadSelectors;
4242
4467
  exports.ɵcreateThreadStore = createThreadStore;
4468
+ exports.ɵisCopilotKitFeature = ɵisCopilotKitFeature;
4243
4469
  exports.ɵjoinPhoenixChannel$ = ɵjoinPhoenixChannel$;
4244
4470
  exports.ɵobservePhoenixEvent$ = ɵobservePhoenixEvent$;
4245
4471
  exports.ɵobservePhoenixJoinOutcome$ = ɵobservePhoenixJoinOutcome$;
@@ -4249,6 +4475,7 @@ exports.ɵphoenixChannel$ = ɵphoenixChannel$;
4249
4475
  exports.ɵphoenixSocket$ = ɵphoenixSocket$;
4250
4476
  exports.ɵselectHasNextPage = ɵselectHasNextPage;
4251
4477
  exports.ɵselectIsFetchingNextPage = ɵselectIsFetchingNextPage;
4478
+ exports.ɵselectIsMutating = ɵselectIsMutating;
4252
4479
  exports.ɵselectThreads = ɵselectThreads;
4253
4480
  exports.ɵselectThreadsError = ɵselectThreadsError;
4254
4481
  exports.ɵselectThreadsIsLoading = ɵselectThreadsIsLoading;