@copilotkit/core 2.0.0-rc.5 → 2.0.0-rc.50

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.
Files changed (47) hide show
  1. package/dist/a2ui-markdown-BxZr1mEU.mjs +1360 -0
  2. package/dist/a2ui-markdown-BxZr1mEU.mjs.map +1 -0
  3. package/dist/a2ui-markdown-DkMXFQih.cjs +1419 -0
  4. package/dist/a2ui-markdown-DkMXFQih.cjs.map +1 -0
  5. package/dist/chat-configuration.cjs +269 -0
  6. package/dist/chat-configuration.cjs.map +1 -0
  7. package/dist/chat-configuration.d.cts +123 -0
  8. package/dist/chat-configuration.d.cts.map +1 -0
  9. package/dist/chat-configuration.d.mts +123 -0
  10. package/dist/chat-configuration.d.mts.map +1 -0
  11. package/dist/chat-configuration.mjs +268 -0
  12. package/dist/chat-configuration.mjs.map +1 -0
  13. package/dist/generative-ui/index.cjs +3786 -0
  14. package/dist/generative-ui/index.cjs.map +1 -0
  15. package/dist/generative-ui/index.d.cts +1139 -0
  16. package/dist/generative-ui/index.d.cts.map +1 -0
  17. package/dist/generative-ui/index.d.mts +1139 -0
  18. package/dist/generative-ui/index.d.mts.map +1 -0
  19. package/dist/generative-ui/index.mjs +3737 -0
  20. package/dist/generative-ui/index.mjs.map +1 -0
  21. package/dist/index.cjs +10227 -2255
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.d.cts +3 -3908
  24. package/dist/index.d.mts +3 -3908
  25. package/dist/index.mjs +9973 -2246
  26. package/dist/index.mjs.map +1 -1
  27. package/dist/index.umd.js +13753 -2220
  28. package/dist/index.umd.js.map +1 -1
  29. package/dist/learning-bridge-DEVwyO7F.d.cts +10553 -0
  30. package/dist/learning-bridge-DEVwyO7F.d.cts.map +1 -0
  31. package/dist/learning-bridge-DZOhtLs1.d.mts +10553 -0
  32. package/dist/learning-bridge-DZOhtLs1.d.mts.map +1 -0
  33. package/dist/styles.cjs +1 -1
  34. package/dist/styles.cjs.map +1 -1
  35. package/dist/styles.css +1 -1
  36. package/dist/styles.mjs +1 -1
  37. package/dist/styles.mjs.map +1 -1
  38. package/dist/viewport-CksL5y8p.mjs +954 -0
  39. package/dist/viewport-CksL5y8p.mjs.map +1 -0
  40. package/dist/viewport-D-tuKCeb.cjs +1182 -0
  41. package/dist/viewport-D-tuKCeb.cjs.map +1 -0
  42. package/package.json +35 -8
  43. package/stryker.config.mjs +6 -0
  44. package/tsdown.config.ts +12 -2
  45. package/vitest.mutation.config.mjs +6 -0
  46. package/dist/index.d.cts.map +0 -1
  47. package/dist/index.d.mts.map +0 -1
@@ -0,0 +1,123 @@
1
+ import { r as OpenThreadRegistration } from "./learning-bridge-DZOhtLs1.mjs";
2
+
3
+ //#region src/chat/chat-configuration.d.ts
4
+ /**
5
+ * Chat configuration state shared by React `CopilotChatConfigurationProvider`,
6
+ * Vue `CopilotChatConfigurationProvider` and Angular
7
+ * `provideCopilotChatConfiguration`: which agent and thread a chat shows, the
8
+ * chat modal's open state, and the thread-list drawer.
9
+ *
10
+ * Internal (`ɵ`): framework packages use it, and it can change in any release.
11
+ */
12
+ /** The props a chat configuration provider takes. */
13
+ interface ɵChatConfigurationOptions {
14
+ agentId?: string;
15
+ /**
16
+ * The thread to show. It is controlled (imperative thread changes are
17
+ * ignored with a warning) unless `hasExplicitThreadId` is `false`, which
18
+ * marks it as a seed that a picked or new thread may replace.
19
+ */
20
+ threadId?: string;
21
+ hasExplicitThreadId?: boolean;
22
+ /**
23
+ * Set to give this provider its own modal state, starting open or closed.
24
+ * Unset, the provider shares its parent's modal state.
25
+ */
26
+ isModalDefaultOpen?: boolean;
27
+ /** The app-wide default agent (`<CopilotKitProvider agentId>`). */
28
+ providerAgentId?: string;
29
+ }
30
+ /** What a chat reads from its configuration. */
31
+ interface ɵChatConfigurationSnapshot {
32
+ agentId: string;
33
+ threadId: string;
34
+ /** `true` when a caller chose the thread (not a minted placeholder). */
35
+ hasExplicitThreadId: boolean;
36
+ isModalOpen: boolean;
37
+ drawerOpen: boolean;
38
+ /** `true` while at least one threads drawer is mounted. */
39
+ drawerRegistered: boolean;
40
+ }
41
+ /** The core part {@link ɵChatConfigurationStore.bindOpenThread} needs. */
42
+ interface ɵOpenThreadRegistry {
43
+ registerOpenThread(params: {
44
+ agentId: string;
45
+ threadId: string;
46
+ }): OpenThreadRegistration;
47
+ }
48
+ type ModalCloser = (open: boolean) => void;
49
+ /**
50
+ * One chat configuration provider's state. A nested provider passes its
51
+ * parent store, and the chain behaves as one:
52
+ *
53
+ * - **Thread**: a controlled `threadId` wins; then a picked or new thread;
54
+ * then the parent's thread; then a seed `threadId`; then a UUID minted once
55
+ * per store. Picking a thread or starting a new one is owned by the top-most
56
+ * store; nested stores pass the call up, after their own controlled check.
57
+ * - **Agent**: own `agentId`, then the parent's, then the provider default,
58
+ * then `DEFAULT_AGENT_ID`.
59
+ * - **Modal**: own state when `isModalDefaultOpen` is set (changes also go to
60
+ * the parent, and parent changes after creation come down); otherwise the
61
+ * parent's state; a store without either starts open.
62
+ * - **Drawer**: owned by the top-most store, so one drawer serves the chain.
63
+ * On a mobile-width viewport, opening the drawer closes the modal that is
64
+ * on screen and opening the modal closes the drawer.
65
+ *
66
+ * The store links to its parent (and registers its modal closer there) while
67
+ * it has subscribers, so a discarded store holds nothing.
68
+ */
69
+ declare class ɵChatConfigurationStore {
70
+ #private;
71
+ constructor(options: ɵChatConfigurationOptions, parent?: ɵChatConfigurationStore | null);
72
+ /**
73
+ * The current values, read through the parent and the latest options, so a
74
+ * render always sees them. Same object until one of them changes.
75
+ */
76
+ getSnapshot: () => ɵChatConfigurationSnapshot;
77
+ /** Listen for changes. Returns unsubscribe. */
78
+ subscribe: (listener: () => void) => () => void;
79
+ /**
80
+ * Take the provider's current props without notifying: for a render phase,
81
+ * where `getSnapshot()` already reflects them. Call {@link update} after
82
+ * the commit so subscribers hear about the change.
83
+ */
84
+ ɵsetOptions(options: ɵChatConfigurationOptions): void;
85
+ /** Give the provider's current props and notify subscribers. */
86
+ update(options: ɵChatConfigurationOptions): void;
87
+ /**
88
+ * Show `threadId`. `explicit` (default `true`) marks it as a caller
89
+ * choice; `false` keeps the welcome screen for a fresh thread. Ignored with
90
+ * a warning when the thread is controlled.
91
+ */
92
+ setActiveThreadId: (threadId: string, options?: {
93
+ explicit?: boolean;
94
+ }) => void;
95
+ /**
96
+ * Show a fresh client-side thread (new UUID, not explicit). Ignored with a
97
+ * warning when the thread is controlled.
98
+ */
99
+ startNewThread: () => void;
100
+ /** Open or close the chat modal (closing the drawer on mobile). */
101
+ setModalOpen: (open: boolean) => void;
102
+ /** Open or close the drawer (closing the on-screen modal on mobile). */
103
+ setDrawerOpen: (open: boolean) => void;
104
+ /**
105
+ * Announce a mounted threads drawer; `drawerRegistered` stays `true` until
106
+ * every returned cleanup has run. Each cleanup runs once.
107
+ */
108
+ registerDrawer: () => (() => void);
109
+ /**
110
+ * Register the setter of the modal that is actually rendered, so the
111
+ * drawer's mobile exclusion closes it. The latest registration wins.
112
+ */
113
+ registerModalCloser: (closeModal: ModalCloser) => (() => void);
114
+ /**
115
+ * Tell core which thread this chat shows, so captured interactions link to
116
+ * it. Re-registers when the agent changes. Returns the cleanup.
117
+ */
118
+ bindOpenThread(registry: ɵOpenThreadRegistry): () => void;
119
+ dispose(): void;
120
+ }
121
+ //#endregion
122
+ export { ɵChatConfigurationOptions, ɵChatConfigurationSnapshot, ɵChatConfigurationStore, ɵOpenThreadRegistry };
123
+ //# sourceMappingURL=chat-configuration.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chat-configuration.d.mts","names":[],"sources":["../src/chat/chat-configuration.ts"],"mappings":";;;;;AAcA;;;;;;;UAAiB,yBAAA;EACf,OAAA;EAce;;AAIjB;;;EAZE,QAAA;EACA,mBAAA;EAaA;;;;EARA,kBAAA;EAcgB;EAZhB,eAAA;AAAA;;UAIe,0BAAA;EACf,OAAA;EACA,QAAA;EAYE;EAVF,mBAAA;EACA,WAAA;EACA,UAAA;EAU0B;EAR1B,gBAAA;AAAA;;UAIe,mBAAA;EACf,kBAAA,CAAmB,MAAA;IACjB,OAAA;IACA,QAAA;EAAA,IACE,sBAAA;AAAA;AAAA,KAUD,WAAA,IAAe,IAAA;;;;;;;;;;;;;;;;;;;;;cAoCP,uBAAA;EAAA;cAgBT,OAAA,EAAS,yBAAA,EACT,MAAA,GAAQ,uBAAA;EAwCH;;;;EA1BP,WAAA,QAAW,0BAAA;EA0DX;EAnDA,SAAA,GAAa,QAAA;EAiEG;;;;;EAnDhB,WAAA,CAAY,OAAA,EAAS,yBAAA;EA2FE;EAtFvB,MAAA,CAAO,OAAA,EAAS,yBAAA;EAmGS;;;;;EApFzB,iBAAA,GAAqB,QAAA,UAAkB,OAAA;IAAY,QAAA;EAAA;;;;;EAiBnD,cAAA;;EAcA,YAAA,GAAgB,IAAA;;EAMhB,aAAA,GAAiB,IAAA;;;;;EAiBjB,cAAA;;;;;EAiBA,mBAAA,GAAuB,UAAA,EAAY,WAAA;;;;;EAanC,cAAA,CAAe,QAAA,EAAU,mBAAA;EAsBzB,OAAA,CAAA;AAAA"}
@@ -0,0 +1,268 @@
1
+ import { o as ɵisMobileViewport } from "./viewport-CksL5y8p.mjs";
2
+ import { DEFAULT_AGENT_ID, randomUUID } from "@copilotkit/shared";
3
+
4
+ //#region src/chat/chat-configuration.ts
5
+ const CONTROLLED_SET_WARNING = "[CopilotKit] Ignoring setActiveThreadId(): threadId is controlled via the `threadId` prop on CopilotChatConfigurationProvider.";
6
+ const CONTROLLED_NEW_WARNING = "[CopilotKit] Ignoring startNewThread(): threadId is controlled via the `threadId` prop on CopilotChatConfigurationProvider.";
7
+ function isSameSnapshot(a, b) {
8
+ return a.agentId === b.agentId && a.threadId === b.threadId && a.hasExplicitThreadId === b.hasExplicitThreadId && a.isModalOpen === b.isModalOpen && a.drawerOpen === b.drawerOpen && a.drawerRegistered === b.drawerRegistered;
9
+ }
10
+ /**
11
+ * One chat configuration provider's state. A nested provider passes its
12
+ * parent store, and the chain behaves as one:
13
+ *
14
+ * - **Thread**: a controlled `threadId` wins; then a picked or new thread;
15
+ * then the parent's thread; then a seed `threadId`; then a UUID minted once
16
+ * per store. Picking a thread or starting a new one is owned by the top-most
17
+ * store; nested stores pass the call up, after their own controlled check.
18
+ * - **Agent**: own `agentId`, then the parent's, then the provider default,
19
+ * then `DEFAULT_AGENT_ID`.
20
+ * - **Modal**: own state when `isModalDefaultOpen` is set (changes also go to
21
+ * the parent, and parent changes after creation come down); otherwise the
22
+ * parent's state; a store without either starts open.
23
+ * - **Drawer**: owned by the top-most store, so one drawer serves the chain.
24
+ * On a mobile-width viewport, opening the drawer closes the modal that is
25
+ * on screen and opening the modal closes the drawer.
26
+ *
27
+ * The store links to its parent (and registers its modal closer there) while
28
+ * it has subscribers, so a discarded store holds nothing.
29
+ */
30
+ var ɵChatConfigurationStore = class {
31
+ #options;
32
+ #parent;
33
+ #fallbackThreadId = randomUUID();
34
+ #override = null;
35
+ #ownModalOpen;
36
+ #ownDrawerOpen = false;
37
+ #drawerCount = 0;
38
+ #modalClosers = [];
39
+ #listeners = /* @__PURE__ */ new Set();
40
+ #disconnectParent = null;
41
+ #lastParentModalOpen;
42
+ #snapshot;
43
+ #notified;
44
+ constructor(options, parent = null) {
45
+ this.#options = options;
46
+ this.#parent = parent;
47
+ this.#ownModalOpen = options.isModalDefaultOpen ?? true;
48
+ this.#lastParentModalOpen = parent?.getSnapshot().isModalOpen;
49
+ this.#snapshot = this.#compute();
50
+ this.#notified = this.#snapshot;
51
+ }
52
+ /**
53
+ * The current values, read through the parent and the latest options, so a
54
+ * render always sees them. Same object until one of them changes.
55
+ */
56
+ getSnapshot = () => {
57
+ const next = this.#compute();
58
+ if (!isSameSnapshot(next, this.#snapshot)) this.#snapshot = next;
59
+ return this.#snapshot;
60
+ };
61
+ /** Listen for changes. Returns unsubscribe. */
62
+ subscribe = (listener) => {
63
+ this.#listeners.add(listener);
64
+ if (this.#listeners.size === 1) this.#connect();
65
+ return () => {
66
+ this.#listeners.delete(listener);
67
+ if (this.#listeners.size === 0) this.#disconnect();
68
+ };
69
+ };
70
+ /**
71
+ * Take the provider's current props without notifying: for a render phase,
72
+ * where `getSnapshot()` already reflects them. Call {@link update} after
73
+ * the commit so subscribers hear about the change.
74
+ */
75
+ ɵsetOptions(options) {
76
+ this.#options = options;
77
+ }
78
+ /** Give the provider's current props and notify subscribers. */
79
+ update(options) {
80
+ const hadOwnModal = this.#hasOwnModal;
81
+ this.#options = options;
82
+ if (hadOwnModal !== this.#hasOwnModal && this.#listeners.size > 0) {
83
+ this.#disconnect();
84
+ this.#connect();
85
+ }
86
+ this.#refresh();
87
+ }
88
+ /**
89
+ * Show `threadId`. `explicit` (default `true`) marks it as a caller
90
+ * choice; `false` keeps the welcome screen for a fresh thread. Ignored with
91
+ * a warning when the thread is controlled.
92
+ */
93
+ setActiveThreadId = (threadId, options) => {
94
+ if (this.#isThreadControlled) {
95
+ console.warn(CONTROLLED_SET_WARNING);
96
+ return;
97
+ }
98
+ if (this.#parent) {
99
+ this.#parent.setActiveThreadId(threadId, options);
100
+ return;
101
+ }
102
+ this.#override = {
103
+ threadId,
104
+ explicit: options?.explicit ?? true
105
+ };
106
+ this.#refresh();
107
+ };
108
+ /**
109
+ * Show a fresh client-side thread (new UUID, not explicit). Ignored with a
110
+ * warning when the thread is controlled.
111
+ */
112
+ startNewThread = () => {
113
+ if (this.#isThreadControlled) {
114
+ console.warn(CONTROLLED_NEW_WARNING);
115
+ return;
116
+ }
117
+ if (this.#parent) {
118
+ this.#parent.startNewThread();
119
+ return;
120
+ }
121
+ this.#override = {
122
+ threadId: randomUUID(),
123
+ explicit: false
124
+ };
125
+ this.#refresh();
126
+ };
127
+ /** Open or close the chat modal (closing the drawer on mobile). */
128
+ setModalOpen = (open) => {
129
+ if (open && ɵisMobileViewport()) this.setDrawerOpen(false);
130
+ this.#setModalState(open);
131
+ };
132
+ /** Open or close the drawer (closing the on-screen modal on mobile). */
133
+ setDrawerOpen = (open) => {
134
+ if (this.#parent) {
135
+ this.#parent.setDrawerOpen(open);
136
+ return;
137
+ }
138
+ this.#ownDrawerOpen = open;
139
+ this.#refresh();
140
+ if (!open || !ɵisMobileViewport()) return;
141
+ (this.#modalClosers[this.#modalClosers.length - 1] ?? ((next) => this.#setModalState(next)))(false);
142
+ };
143
+ /**
144
+ * Announce a mounted threads drawer; `drawerRegistered` stays `true` until
145
+ * every returned cleanup has run. Each cleanup runs once.
146
+ */
147
+ registerDrawer = () => {
148
+ if (this.#parent) return this.#parent.registerDrawer();
149
+ this.#drawerCount++;
150
+ this.#refresh();
151
+ let active = true;
152
+ return () => {
153
+ if (!active) return;
154
+ active = false;
155
+ this.#drawerCount = Math.max(0, this.#drawerCount - 1);
156
+ this.#refresh();
157
+ };
158
+ };
159
+ /**
160
+ * Register the setter of the modal that is actually rendered, so the
161
+ * drawer's mobile exclusion closes it. The latest registration wins.
162
+ */
163
+ registerModalCloser = (closeModal) => {
164
+ if (this.#parent) return this.#parent.registerModalCloser(closeModal);
165
+ this.#modalClosers.push(closeModal);
166
+ return () => {
167
+ const index = this.#modalClosers.lastIndexOf(closeModal);
168
+ if (index !== -1) this.#modalClosers.splice(index, 1);
169
+ };
170
+ };
171
+ /**
172
+ * Tell core which thread this chat shows, so captured interactions link to
173
+ * it. Re-registers when the agent changes. Returns the cleanup.
174
+ */
175
+ bindOpenThread(registry) {
176
+ let agentId = this.getSnapshot().agentId;
177
+ let registration = registry.registerOpenThread({
178
+ agentId,
179
+ threadId: this.getSnapshot().threadId
180
+ });
181
+ const unsubscribe = this.subscribe(() => {
182
+ const { agentId: nextAgentId, threadId } = this.getSnapshot();
183
+ if (nextAgentId === agentId) {
184
+ registration.update(threadId);
185
+ return;
186
+ }
187
+ registration.unregister();
188
+ agentId = nextAgentId;
189
+ registration = registry.registerOpenThread({
190
+ agentId,
191
+ threadId
192
+ });
193
+ });
194
+ return () => {
195
+ unsubscribe();
196
+ registration.unregister();
197
+ };
198
+ }
199
+ dispose() {
200
+ this.#disconnect();
201
+ this.#listeners.clear();
202
+ }
203
+ get #hasOwnModal() {
204
+ return this.#options.isModalDefaultOpen !== void 0;
205
+ }
206
+ get #isThreadControlled() {
207
+ const { threadId, hasExplicitThreadId } = this.#options;
208
+ return threadId !== void 0 && hasExplicitThreadId !== false;
209
+ }
210
+ #setModalState(open) {
211
+ if (this.#hasOwnModal || !this.#parent) {
212
+ this.#ownModalOpen = open;
213
+ this.#refresh();
214
+ if (this.#hasOwnModal) this.#parent?.setModalOpen(open);
215
+ return;
216
+ }
217
+ this.#parent.setModalOpen(open);
218
+ }
219
+ #connect() {
220
+ const parent = this.#parent;
221
+ if (!parent) return;
222
+ const offParent = parent.subscribe(() => this.#onParentChange());
223
+ const offCloser = this.#hasOwnModal ? parent.registerModalCloser((open) => this.#setModalState(open)) : null;
224
+ this.#disconnectParent = () => {
225
+ offParent();
226
+ offCloser?.();
227
+ };
228
+ this.#refresh();
229
+ }
230
+ #disconnect() {
231
+ this.#disconnectParent?.();
232
+ this.#disconnectParent = null;
233
+ }
234
+ #onParentChange() {
235
+ const parentModalOpen = this.#parent?.getSnapshot().isModalOpen;
236
+ const parentModalChanged = parentModalOpen !== this.#lastParentModalOpen;
237
+ this.#lastParentModalOpen = parentModalOpen;
238
+ if (parentModalChanged && this.#hasOwnModal && parentModalOpen !== void 0) this.#ownModalOpen = parentModalOpen;
239
+ this.#refresh();
240
+ }
241
+ #compute() {
242
+ const options = this.#options;
243
+ const parent = this.#parent?.getSnapshot() ?? null;
244
+ const isControlled = this.#isThreadControlled;
245
+ const threadId = isControlled ? options.threadId : this.#override?.threadId ?? (parent?.threadId || options.threadId || this.#fallbackThreadId);
246
+ const ownExplicit = isControlled ? true : this.#override?.explicit ?? options.hasExplicitThreadId ?? false;
247
+ const ownsDrawer = parent === null;
248
+ return {
249
+ agentId: options.agentId ?? parent?.agentId ?? options.providerAgentId ?? DEFAULT_AGENT_ID,
250
+ threadId,
251
+ hasExplicitThreadId: ownExplicit || !!parent?.hasExplicitThreadId,
252
+ isModalOpen: this.#hasOwnModal || !parent ? this.#ownModalOpen : parent.isModalOpen,
253
+ drawerOpen: ownsDrawer ? this.#ownDrawerOpen : parent.drawerOpen,
254
+ drawerRegistered: ownsDrawer ? this.#drawerCount > 0 : parent.drawerRegistered
255
+ };
256
+ }
257
+ #refresh() {
258
+ const snapshot = this.getSnapshot();
259
+ if (snapshot === this.#notified) return;
260
+ this.#notified = snapshot;
261
+ const listeners = [...this.#listeners];
262
+ for (const listener of listeners) listener();
263
+ }
264
+ };
265
+
266
+ //#endregion
267
+ export { ɵChatConfigurationStore };
268
+ //# sourceMappingURL=chat-configuration.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chat-configuration.mjs","names":["#parent","#fallbackThreadId","#modalClosers","#listeners","#options","#ownModalOpen","#lastParentModalOpen","#snapshot","#compute","#notified","#connect","#disconnect","#hasOwnModal","#refresh","#isThreadControlled","#override","#setModalState","#ownDrawerOpen","#drawerCount","#onParentChange","#disconnectParent"],"sources":["../src/chat/chat-configuration.ts"],"sourcesContent":["import { DEFAULT_AGENT_ID, randomUUID } from \"@copilotkit/shared\";\nimport type { OpenThreadRegistration } from \"../core/learning-bridge\";\nimport { ɵisMobileViewport } from \"./viewport\";\n\n/**\n * Chat configuration state shared by React `CopilotChatConfigurationProvider`,\n * Vue `CopilotChatConfigurationProvider` and Angular\n * `provideCopilotChatConfiguration`: which agent and thread a chat shows, the\n * chat modal's open state, and the thread-list drawer.\n *\n * Internal (`ɵ`): framework packages use it, and it can change in any release.\n */\n\n/** The props a chat configuration provider takes. */\nexport interface ɵChatConfigurationOptions {\n agentId?: string;\n /**\n * The thread to show. It is controlled (imperative thread changes are\n * ignored with a warning) unless `hasExplicitThreadId` is `false`, which\n * marks it as a seed that a picked or new thread may replace.\n */\n threadId?: string;\n hasExplicitThreadId?: boolean;\n /**\n * Set to give this provider its own modal state, starting open or closed.\n * Unset, the provider shares its parent's modal state.\n */\n isModalDefaultOpen?: boolean;\n /** The app-wide default agent (`<CopilotKitProvider agentId>`). */\n providerAgentId?: string;\n}\n\n/** What a chat reads from its configuration. */\nexport interface ɵChatConfigurationSnapshot {\n agentId: string;\n threadId: string;\n /** `true` when a caller chose the thread (not a minted placeholder). */\n hasExplicitThreadId: boolean;\n isModalOpen: boolean;\n drawerOpen: boolean;\n /** `true` while at least one threads drawer is mounted. */\n drawerRegistered: boolean;\n}\n\n/** The core part {@link ɵChatConfigurationStore.bindOpenThread} needs. */\nexport interface ɵOpenThreadRegistry {\n registerOpenThread(params: {\n agentId: string;\n threadId: string;\n }): OpenThreadRegistration;\n}\n\nconst CONTROLLED_SET_WARNING =\n \"[CopilotKit] Ignoring setActiveThreadId(): threadId is controlled \" +\n \"via the `threadId` prop on CopilotChatConfigurationProvider.\";\nconst CONTROLLED_NEW_WARNING =\n \"[CopilotKit] Ignoring startNewThread(): threadId is controlled via \" +\n \"the `threadId` prop on CopilotChatConfigurationProvider.\";\n\ntype ModalCloser = (open: boolean) => void;\n\nfunction isSameSnapshot(\n a: ɵChatConfigurationSnapshot,\n b: ɵChatConfigurationSnapshot,\n) {\n return (\n a.agentId === b.agentId &&\n a.threadId === b.threadId &&\n a.hasExplicitThreadId === b.hasExplicitThreadId &&\n a.isModalOpen === b.isModalOpen &&\n a.drawerOpen === b.drawerOpen &&\n a.drawerRegistered === b.drawerRegistered\n );\n}\n\n/**\n * One chat configuration provider's state. A nested provider passes its\n * parent store, and the chain behaves as one:\n *\n * - **Thread**: a controlled `threadId` wins; then a picked or new thread;\n * then the parent's thread; then a seed `threadId`; then a UUID minted once\n * per store. Picking a thread or starting a new one is owned by the top-most\n * store; nested stores pass the call up, after their own controlled check.\n * - **Agent**: own `agentId`, then the parent's, then the provider default,\n * then `DEFAULT_AGENT_ID`.\n * - **Modal**: own state when `isModalDefaultOpen` is set (changes also go to\n * the parent, and parent changes after creation come down); otherwise the\n * parent's state; a store without either starts open.\n * - **Drawer**: owned by the top-most store, so one drawer serves the chain.\n * On a mobile-width viewport, opening the drawer closes the modal that is\n * on screen and opening the modal closes the drawer.\n *\n * The store links to its parent (and registers its modal closer there) while\n * it has subscribers, so a discarded store holds nothing.\n */\nexport class ɵChatConfigurationStore {\n #options: ɵChatConfigurationOptions;\n readonly #parent: ɵChatConfigurationStore | null;\n readonly #fallbackThreadId = randomUUID();\n #override: { threadId: string; explicit: boolean } | null = null;\n #ownModalOpen: boolean;\n #ownDrawerOpen = false;\n #drawerCount = 0;\n readonly #modalClosers: ModalCloser[] = [];\n readonly #listeners = new Set<() => void>();\n #disconnectParent: (() => void) | null = null;\n #lastParentModalOpen: boolean | undefined;\n #snapshot: ɵChatConfigurationSnapshot;\n #notified: ɵChatConfigurationSnapshot;\n\n constructor(\n options: ɵChatConfigurationOptions,\n parent: ɵChatConfigurationStore | null = null,\n ) {\n this.#options = options;\n this.#parent = parent;\n this.#ownModalOpen = options.isModalDefaultOpen ?? true;\n this.#lastParentModalOpen = parent?.getSnapshot().isModalOpen;\n this.#snapshot = this.#compute();\n this.#notified = this.#snapshot;\n }\n\n /**\n * The current values, read through the parent and the latest options, so a\n * render always sees them. Same object until one of them changes.\n */\n getSnapshot = () => {\n const next = this.#compute();\n if (!isSameSnapshot(next, this.#snapshot)) this.#snapshot = next;\n return this.#snapshot;\n };\n\n /** Listen for changes. Returns unsubscribe. */\n subscribe = (listener: () => void) => {\n this.#listeners.add(listener);\n if (this.#listeners.size === 1) this.#connect();\n return () => {\n this.#listeners.delete(listener);\n if (this.#listeners.size === 0) this.#disconnect();\n };\n };\n\n /**\n * Take the provider's current props without notifying: for a render phase,\n * where `getSnapshot()` already reflects them. Call {@link update} after\n * the commit so subscribers hear about the change.\n */\n ɵsetOptions(options: ɵChatConfigurationOptions) {\n this.#options = options;\n }\n\n /** Give the provider's current props and notify subscribers. */\n update(options: ɵChatConfigurationOptions) {\n const hadOwnModal = this.#hasOwnModal;\n this.#options = options;\n if (hadOwnModal !== this.#hasOwnModal && this.#listeners.size > 0) {\n this.#disconnect();\n this.#connect();\n }\n this.#refresh();\n }\n\n /**\n * Show `threadId`. `explicit` (default `true`) marks it as a caller\n * choice; `false` keeps the welcome screen for a fresh thread. Ignored with\n * a warning when the thread is controlled.\n */\n setActiveThreadId = (threadId: string, options?: { explicit?: boolean }) => {\n if (this.#isThreadControlled) {\n console.warn(CONTROLLED_SET_WARNING);\n return;\n }\n if (this.#parent) {\n this.#parent.setActiveThreadId(threadId, options);\n return;\n }\n this.#override = { threadId, explicit: options?.explicit ?? true };\n this.#refresh();\n };\n\n /**\n * Show a fresh client-side thread (new UUID, not explicit). Ignored with a\n * warning when the thread is controlled.\n */\n startNewThread = () => {\n if (this.#isThreadControlled) {\n console.warn(CONTROLLED_NEW_WARNING);\n return;\n }\n if (this.#parent) {\n this.#parent.startNewThread();\n return;\n }\n this.#override = { threadId: randomUUID(), explicit: false };\n this.#refresh();\n };\n\n /** Open or close the chat modal (closing the drawer on mobile). */\n setModalOpen = (open: boolean) => {\n if (open && ɵisMobileViewport()) this.setDrawerOpen(false);\n this.#setModalState(open);\n };\n\n /** Open or close the drawer (closing the on-screen modal on mobile). */\n setDrawerOpen = (open: boolean) => {\n if (this.#parent) {\n this.#parent.setDrawerOpen(open);\n return;\n }\n this.#ownDrawerOpen = open;\n this.#refresh();\n if (!open || !ɵisMobileViewport()) return;\n const latestCloser = this.#modalClosers[this.#modalClosers.length - 1];\n const closeModal = latestCloser ?? ((next) => this.#setModalState(next));\n closeModal(false);\n };\n\n /**\n * Announce a mounted threads drawer; `drawerRegistered` stays `true` until\n * every returned cleanup has run. Each cleanup runs once.\n */\n registerDrawer = (): (() => void) => {\n if (this.#parent) return this.#parent.registerDrawer();\n this.#drawerCount++;\n this.#refresh();\n let active = true;\n return () => {\n if (!active) return;\n active = false;\n this.#drawerCount = Math.max(0, this.#drawerCount - 1);\n this.#refresh();\n };\n };\n\n /**\n * Register the setter of the modal that is actually rendered, so the\n * drawer's mobile exclusion closes it. The latest registration wins.\n */\n registerModalCloser = (closeModal: ModalCloser): (() => void) => {\n if (this.#parent) return this.#parent.registerModalCloser(closeModal);\n this.#modalClosers.push(closeModal);\n return () => {\n const index = this.#modalClosers.lastIndexOf(closeModal);\n if (index !== -1) this.#modalClosers.splice(index, 1);\n };\n };\n\n /**\n * Tell core which thread this chat shows, so captured interactions link to\n * it. Re-registers when the agent changes. Returns the cleanup.\n */\n bindOpenThread(registry: ɵOpenThreadRegistry) {\n let agentId = this.getSnapshot().agentId;\n let registration = registry.registerOpenThread({\n agentId,\n threadId: this.getSnapshot().threadId,\n });\n const unsubscribe = this.subscribe(() => {\n const { agentId: nextAgentId, threadId } = this.getSnapshot();\n if (nextAgentId === agentId) {\n registration.update(threadId);\n return;\n }\n registration.unregister();\n agentId = nextAgentId;\n registration = registry.registerOpenThread({ agentId, threadId });\n });\n return () => {\n unsubscribe();\n registration.unregister();\n };\n }\n\n dispose() {\n this.#disconnect();\n this.#listeners.clear();\n }\n\n get #hasOwnModal() {\n return this.#options.isModalDefaultOpen !== undefined;\n }\n\n get #isThreadControlled() {\n const { threadId, hasExplicitThreadId } = this.#options;\n return threadId !== undefined && hasExplicitThreadId !== false;\n }\n\n #setModalState(open: boolean) {\n if (this.#hasOwnModal || !this.#parent) {\n this.#ownModalOpen = open;\n this.#refresh();\n if (this.#hasOwnModal) this.#parent?.setModalOpen(open);\n return;\n }\n this.#parent.setModalOpen(open);\n }\n\n #connect() {\n const parent = this.#parent;\n if (!parent) return;\n const offParent = parent.subscribe(() => this.#onParentChange());\n const offCloser = this.#hasOwnModal\n ? parent.registerModalCloser((open) => this.#setModalState(open))\n : null;\n this.#disconnectParent = () => {\n offParent();\n offCloser?.();\n };\n // The parent may have changed while this store had no subscribers.\n this.#refresh();\n }\n\n #disconnect() {\n this.#disconnectParent?.();\n this.#disconnectParent = null;\n }\n\n #onParentChange() {\n const parentModalOpen = this.#parent?.getSnapshot().isModalOpen;\n const parentModalChanged = parentModalOpen !== this.#lastParentModalOpen;\n this.#lastParentModalOpen = parentModalOpen;\n // An owned modal follows changes made above it, not the parent's value\n // at creation (that would override `isModalDefaultOpen`).\n if (\n parentModalChanged &&\n this.#hasOwnModal &&\n parentModalOpen !== undefined\n ) {\n this.#ownModalOpen = parentModalOpen;\n }\n this.#refresh();\n }\n\n #compute(): ɵChatConfigurationSnapshot {\n const options = this.#options;\n const parent = this.#parent?.getSnapshot() ?? null;\n const isControlled = this.#isThreadControlled;\n const threadId = isControlled\n ? (options.threadId as string)\n : (this.#override?.threadId ??\n (parent?.threadId || options.threadId || this.#fallbackThreadId));\n const ownExplicit = isControlled\n ? true\n : (this.#override?.explicit ?? options.hasExplicitThreadId ?? false);\n const ownsDrawer = parent === null;\n return {\n agentId:\n options.agentId ??\n parent?.agentId ??\n options.providerAgentId ??\n DEFAULT_AGENT_ID,\n threadId,\n hasExplicitThreadId: ownExplicit || !!parent?.hasExplicitThreadId,\n isModalOpen:\n this.#hasOwnModal || !parent ? this.#ownModalOpen : parent.isModalOpen,\n drawerOpen: ownsDrawer ? this.#ownDrawerOpen : parent.drawerOpen,\n drawerRegistered: ownsDrawer\n ? this.#drawerCount > 0\n : parent.drawerRegistered,\n };\n }\n\n #refresh() {\n const snapshot = this.getSnapshot();\n if (snapshot === this.#notified) return;\n this.#notified = snapshot;\n const listeners = [...this.#listeners];\n for (const listener of listeners) listener();\n }\n}\n"],"mappings":";;;;AAoDA,MAAM,yBACJ;AAEF,MAAM,yBACJ;AAKF,SAAS,eACP,GACA,GACA;AACA,QACE,EAAE,YAAY,EAAE,WAChB,EAAE,aAAa,EAAE,YACjB,EAAE,wBAAwB,EAAE,uBAC5B,EAAE,gBAAgB,EAAE,eACpB,EAAE,eAAe,EAAE,cACnB,EAAE,qBAAqB,EAAE;;;;;;;;;;;;;;;;;;;;;;AAwB7B,IAAa,0BAAb,MAAqC;CACnC;CACA,CAASA;CACT,CAASC,mBAAoB,YAAY;CACzC,YAA4D;CAC5D;CACA,iBAAiB;CACjB,eAAe;CACf,CAASC,eAA+B,EAAE;CAC1C,CAASC,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