@copilotkit/react-core 2.0.0-rc.20 → 2.0.0-rc.21
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/{MarkdownSurfaces-CoUoPhR9.cjs → MarkdownSurfaces-CGW92DCL.cjs} +49 -178
- package/dist/MarkdownSurfaces-CGW92DCL.cjs.map +1 -0
- package/dist/{MarkdownSurfaces-Bt7TD_U1.mjs → MarkdownSurfaces-DveOwhaW.mjs} +52 -181
- package/dist/MarkdownSurfaces-DveOwhaW.mjs.map +1 -0
- package/dist/context.cjs +43 -46
- package/dist/context.cjs.map +1 -1
- package/dist/context.d.cts +15 -11
- package/dist/context.d.cts.map +1 -1
- package/dist/context.d.mts +15 -11
- package/dist/context.d.mts.map +1 -1
- package/dist/context.mjs +44 -47
- package/dist/context.mjs.map +1 -1
- package/dist/generative-ui.cjs +1 -1
- package/dist/generative-ui.mjs +1 -1
- package/dist/headless.cjs +235 -941
- package/dist/headless.cjs.map +1 -1
- package/dist/headless.d.cts +67 -26
- package/dist/headless.d.cts.map +1 -1
- package/dist/headless.d.mts +53 -16
- package/dist/headless.d.mts.map +1 -1
- package/dist/headless.mjs +236 -943
- package/dist/headless.mjs.map +1 -1
- package/dist/index.cjs +1847 -3433
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +120 -277
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +121 -278
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +924 -3379
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +1866 -3583
- package/dist/index.umd.js.map +1 -1
- package/package.json +8 -8
- package/dist/MarkdownSurfaces-Bt7TD_U1.mjs.map +0 -1
- package/dist/MarkdownSurfaces-CoUoPhR9.cjs.map +0 -1
|
@@ -1,20 +1,13 @@
|
|
|
1
|
-
import { CopilotChatDefaultLabels, extractFenceOperations, flattenInformationalCards, getMarkdownOperationSurfaceId, prepareSurfaceOperations, segmentSurfaceProse, splitA2UIMarkdown, ɵcn as cn, ɵcopilotIconSvgAttributes, ɵcopilotIcons, ɵshallowEqualRecord } from "@copilotkit/core";
|
|
1
|
+
import { CopilotChatDefaultLabels, extractFenceOperations, flattenInformationalCards, getMarkdownOperationSurfaceId, prepareSurfaceOperations, segmentSurfaceProse, splitA2UIMarkdown, ɵChatConfigurationStore, ɵcn as cn, ɵcopilotIconSvgAttributes, ɵcopilotIcons, ɵshallowEqualRecord } from "@copilotkit/core";
|
|
2
2
|
import React, { Component, createContext, createElement, forwardRef, memo, useCallback, useContext, useEffect, useInsertionEffect, useLayoutEffect, useMemo, useReducer, useRef, useState, useSyncExternalStore } from "react";
|
|
3
|
-
import { StreamingMarkdownRenderer
|
|
4
|
-
import { warnUnsupportedRichSyntaxOnce } from "@copilotkit/markdown";
|
|
3
|
+
import { StreamingMarkdownRenderer } from "@copilotkit/markdown/react";
|
|
4
|
+
import { CHAT_MARKDOWN_NODE_CLASS_NAMES, warnUnsupportedRichSyntaxOnce } from "@copilotkit/markdown";
|
|
5
5
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
-
import { A2UI_COMPONENT_ENVELOPE_KEYS, A2UI_INDEX_FUNCTION, A2UI_VERSION, DEFAULT_AGENT_ID, GENERATIVE_UI_ACTIVITY_TYPE, GENERATIVE_UI_CHAT_TARGET, GENERATIVE_UI_FUNCTIONS, GENERATIVE_UI_FUNCTION_CALL_ACTIVITY_TYPE, GENERATIVE_UI_RENDER_TOOL, GENERATIVE_UI_ROOT_ID, applyChildRefMarks, childIdsAtRefs, collectChildRefs, functionCallers, getOperationKind, hasBoundChildRef, isActionBinding, isCallBinding, isPathBinding, isValidationResult, mapAtChildRef, randomUUID, schemaToJsonSchema, validateOperation, ɵanySchema } from "@copilotkit/shared";
|
|
7
6
|
import { CopilotKitContext, useCopilotKit, useDefaultAgentId } from "@copilotkit/react-core/context";
|
|
7
|
+
import { A2UI_COMPONENT_ENVELOPE_KEYS, A2UI_INDEX_FUNCTION, A2UI_VERSION, GENERATIVE_UI_ACTIVITY_TYPE, GENERATIVE_UI_CHAT_TARGET, GENERATIVE_UI_FUNCTIONS, GENERATIVE_UI_FUNCTION_CALL_ACTIVITY_TYPE, GENERATIVE_UI_RENDER_TOOL, GENERATIVE_UI_ROOT_ID, applyChildRefMarks, childIdsAtRefs, collectChildRefs, functionCallers, getOperationKind, hasBoundChildRef, isActionBinding, isCallBinding, isPathBinding, isValidationResult, mapAtChildRef, schemaToJsonSchema, validateOperation, ɵanySchema } from "@copilotkit/shared";
|
|
8
8
|
import * as z from "zod";
|
|
9
9
|
|
|
10
10
|
//#region src/components/chat/StreamingMarkdownDefaultRenderer.tsx
|
|
11
|
-
const defaultNodeRenderers = createStreamingMarkdownNodeRenderers({ codeBlock: ({ node }) => /* @__PURE__ */ jsx("pre", {
|
|
12
|
-
className: "cpk-markdown-code-block",
|
|
13
|
-
children: /* @__PURE__ */ jsx("code", {
|
|
14
|
-
"data-code-info": node.info ?? void 0,
|
|
15
|
-
children: node.text
|
|
16
|
-
})
|
|
17
|
-
}) });
|
|
18
11
|
/**
|
|
19
12
|
* react-core's built-in default markdown renderer — a thin adapter over
|
|
20
13
|
* `@copilotkit/markdown`'s streaming renderer. Maps the pluggable
|
|
@@ -23,17 +16,14 @@ const defaultNodeRenderers = createStreamingMarkdownNodeRenderers({ codeBlock: (
|
|
|
23
16
|
* Still overridable via the slot/provider pluggable interface.
|
|
24
17
|
*/
|
|
25
18
|
function StreamingMarkdownDefaultRenderer({ content, isStreaming, className, nodeRenderers, caret, options, onLinkClick, onCitationClick }) {
|
|
26
|
-
const mergedNodeRenderers = useMemo(() => nodeRenderers ? createStreamingMarkdownNodeRenderers({
|
|
27
|
-
...defaultNodeRenderers,
|
|
28
|
-
...nodeRenderers
|
|
29
|
-
}) : defaultNodeRenderers, [nodeRenderers]);
|
|
30
19
|
if (!content) return null;
|
|
31
20
|
warnUnsupportedRichSyntaxOnce(content);
|
|
32
21
|
return /* @__PURE__ */ jsx(StreamingMarkdownRenderer, {
|
|
33
22
|
className,
|
|
34
23
|
isComplete: !isStreaming,
|
|
35
24
|
caret: caret ?? !!isStreaming,
|
|
36
|
-
nodeRenderers
|
|
25
|
+
nodeRenderers,
|
|
26
|
+
nodeClassNames: CHAT_MARKDOWN_NODE_CLASS_NAMES,
|
|
37
27
|
options,
|
|
38
28
|
onLinkClick,
|
|
39
29
|
onCitationClick,
|
|
@@ -145,25 +135,6 @@ function useShallowStableRef(value) {
|
|
|
145
135
|
|
|
146
136
|
//#endregion
|
|
147
137
|
//#region src/providers/CopilotChatConfigurationProvider.tsx
|
|
148
|
-
/**
|
|
149
|
-
* Mobile breakpoint below which the chat modal and the thread-list drawer are
|
|
150
|
-
* mutually exclusive. At or above this width both surfaces may coexist. This
|
|
151
|
-
* mirrors the `(max-width: 767px)` / `(min-width: 768px)` split already used by
|
|
152
|
-
* CopilotChatInput and CopilotSidebarView.
|
|
153
|
-
*/
|
|
154
|
-
const MOBILE_MAX_WIDTH_PX = 767;
|
|
155
|
-
/**
|
|
156
|
-
* Reports whether the current viewport is in the mobile range (`<768px`), where
|
|
157
|
-
* the chat modal and drawer must not be open simultaneously. SSR-safe and
|
|
158
|
-
* defensive against environments without `matchMedia` (treated as desktop, so
|
|
159
|
-
* no mutual-exclusion constraint is applied).
|
|
160
|
-
*
|
|
161
|
-
* @returns `true` when the viewport is mobile-width, `false` otherwise.
|
|
162
|
-
*/
|
|
163
|
-
function isMobileViewport() {
|
|
164
|
-
if (typeof window === "undefined" || typeof window.matchMedia !== "function") return false;
|
|
165
|
-
return window.matchMedia(`(max-width: ${MOBILE_MAX_WIDTH_PX}px)`).matches;
|
|
166
|
-
}
|
|
167
138
|
const CopilotChatConfiguration = createContext(null);
|
|
168
139
|
const CopilotChatConfigurationProvider = ({ children, labels, agentId, threadId, hasExplicitThreadId, isModalDefaultOpen }) => {
|
|
169
140
|
const parentConfig = useContext(CopilotChatConfiguration);
|
|
@@ -174,167 +145,67 @@ const CopilotChatConfigurationProvider = ({ children, labels, agentId, threadId,
|
|
|
174
145
|
...stableLabels
|
|
175
146
|
}), [stableLabels, parentConfig?.labels]);
|
|
176
147
|
const providerAgentId = useDefaultAgentId();
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
148
|
+
const options = {
|
|
149
|
+
agentId,
|
|
150
|
+
threadId,
|
|
151
|
+
hasExplicitThreadId,
|
|
152
|
+
isModalDefaultOpen,
|
|
153
|
+
providerAgentId
|
|
154
|
+
};
|
|
155
|
+
const parentStore = parentConfig?.ɵstore ?? null;
|
|
156
|
+
const [store] = useState(() => new ɵChatConfigurationStore(options, parentStore));
|
|
157
|
+
store.ɵsetOptions(options);
|
|
158
|
+
const snapshot = useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);
|
|
159
|
+
useEffect(() => {
|
|
160
|
+
store.update({
|
|
161
|
+
agentId,
|
|
162
|
+
threadId,
|
|
163
|
+
hasExplicitThreadId,
|
|
164
|
+
isModalDefaultOpen,
|
|
165
|
+
providerAgentId
|
|
166
|
+
});
|
|
187
167
|
}, [
|
|
188
|
-
|
|
168
|
+
store,
|
|
169
|
+
agentId,
|
|
189
170
|
threadId,
|
|
190
|
-
|
|
191
|
-
|
|
171
|
+
hasExplicitThreadId,
|
|
172
|
+
isModalDefaultOpen,
|
|
173
|
+
providerAgentId
|
|
192
174
|
]);
|
|
193
175
|
const copilotkit = useContext(CopilotKitContext)?.copilotkit;
|
|
194
|
-
const openThreadRef = useRef(null);
|
|
195
|
-
const latestThreadIdRef = useRef(resolvedThreadId);
|
|
196
|
-
latestThreadIdRef.current = resolvedThreadId;
|
|
197
176
|
useEffect(() => {
|
|
198
177
|
if (copilotkit === void 0) return;
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
registration.unregister();
|
|
206
|
-
openThreadRef.current = null;
|
|
207
|
-
};
|
|
208
|
-
}, [copilotkit, resolvedAgentId]);
|
|
209
|
-
useEffect(() => {
|
|
210
|
-
openThreadRef.current?.update(resolvedThreadId);
|
|
211
|
-
}, [resolvedThreadId]);
|
|
212
|
-
const resolvedHasExplicitThreadId = (threadIdPropIsAuthoritative ? true : activeThreadOverride?.explicit ?? hasExplicitThreadId ?? false) || !!parentConfig?.hasExplicitThreadId;
|
|
213
|
-
const [internalModalOpen, setInternalModalOpen] = useState(isModalDefaultOpen ?? true);
|
|
214
|
-
const hasExplicitDefault = isModalDefaultOpen !== void 0;
|
|
215
|
-
const setAndSync = useCallback((open) => {
|
|
216
|
-
setInternalModalOpen(open);
|
|
217
|
-
parentConfig?.setModalOpen(open);
|
|
218
|
-
}, [parentConfig?.setModalOpen]);
|
|
219
|
-
const isMounted = useRef(false);
|
|
220
|
-
useEffect(() => {
|
|
221
|
-
if (!hasExplicitDefault) return;
|
|
222
|
-
if (!isMounted.current) {
|
|
223
|
-
isMounted.current = true;
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
|
-
if (parentConfig?.isModalOpen === void 0) return;
|
|
227
|
-
setInternalModalOpen(parentConfig.isModalOpen);
|
|
228
|
-
}, [parentConfig?.isModalOpen, hasExplicitDefault]);
|
|
229
|
-
const resolvedIsModalOpen = hasExplicitDefault ? internalModalOpen : parentConfig?.isModalOpen ?? internalModalOpen;
|
|
230
|
-
const resolvedSetModalOpen = hasExplicitDefault ? setAndSync : parentConfig?.setModalOpen ?? setInternalModalOpen;
|
|
231
|
-
const [ownDrawerOpen, setOwnDrawerOpen] = useState(false);
|
|
232
|
-
const [ownDrawerCount, setOwnDrawerCount] = useState(0);
|
|
233
|
-
const modalCloseRef = useRef(() => {});
|
|
234
|
-
modalCloseRef.current = resolvedSetModalOpen;
|
|
235
|
-
const registeredModalClosersRef = useRef([]);
|
|
236
|
-
const ownRegisterModalCloser = useCallback((closeModal) => {
|
|
237
|
-
registeredModalClosersRef.current.push(closeModal);
|
|
238
|
-
return () => {
|
|
239
|
-
registeredModalClosersRef.current = registeredModalClosersRef.current.filter((entry) => entry !== closeModal);
|
|
240
|
-
};
|
|
241
|
-
}, []);
|
|
242
|
-
const ownSetDrawerOpen = useCallback((open) => {
|
|
243
|
-
setOwnDrawerOpen(open);
|
|
244
|
-
if (open && isMobileViewport()) {
|
|
245
|
-
const registered = registeredModalClosersRef.current;
|
|
246
|
-
(registered.length > 0 ? registered[registered.length - 1] : modalCloseRef.current)(false);
|
|
247
|
-
}
|
|
248
|
-
}, []);
|
|
249
|
-
const ownRegisterDrawer = useCallback(() => {
|
|
250
|
-
setOwnDrawerCount((count) => count + 1);
|
|
251
|
-
return () => {
|
|
252
|
-
setOwnDrawerCount((count) => Math.max(0, count - 1));
|
|
253
|
-
};
|
|
254
|
-
}, []);
|
|
255
|
-
const resolvedDrawerOpen = parentConfig ? parentConfig.drawerOpen : ownDrawerOpen;
|
|
256
|
-
const resolvedSetDrawerOpen = parentConfig ? parentConfig.setDrawerOpen : ownSetDrawerOpen;
|
|
257
|
-
const resolvedDrawerRegistered = parentConfig ? parentConfig.drawerRegistered : ownDrawerCount > 0;
|
|
258
|
-
const resolvedRegisterDrawer = parentConfig ? parentConfig.registerDrawer : ownRegisterDrawer;
|
|
259
|
-
const resolvedRegisterModalCloser = parentConfig ? parentConfig.ɵregisterModalCloser : ownRegisterModalCloser;
|
|
260
|
-
useEffect(() => {
|
|
261
|
-
if (!hasExplicitDefault) return;
|
|
262
|
-
return resolvedRegisterModalCloser(resolvedSetModalOpen);
|
|
263
|
-
}, [
|
|
264
|
-
hasExplicitDefault,
|
|
265
|
-
resolvedRegisterModalCloser,
|
|
266
|
-
resolvedSetModalOpen
|
|
267
|
-
]);
|
|
268
|
-
const isThreadIdControlledRef = useRef(isThreadIdControlled);
|
|
269
|
-
isThreadIdControlledRef.current = isThreadIdControlled;
|
|
270
|
-
const ownSetActiveThreadId = useCallback((id, options) => {
|
|
271
|
-
setActiveThreadOverride({
|
|
272
|
-
threadId: id,
|
|
273
|
-
explicit: options?.explicit ?? true
|
|
274
|
-
});
|
|
275
|
-
}, []);
|
|
276
|
-
const ownStartNewThread = useCallback(() => {
|
|
277
|
-
setActiveThreadOverride({
|
|
278
|
-
threadId: randomUUID(),
|
|
279
|
-
explicit: false
|
|
280
|
-
});
|
|
281
|
-
}, []);
|
|
282
|
-
const parentSetActiveThreadId = parentConfig?.setActiveThreadId;
|
|
283
|
-
const parentStartNewThread = parentConfig?.startNewThread;
|
|
284
|
-
const resolvedSetActiveThreadId = useCallback((id, options) => {
|
|
285
|
-
if (isThreadIdControlledRef.current) {
|
|
286
|
-
console.warn("[CopilotKit] Ignoring setActiveThreadId(): threadId is controlled via the `threadId` prop on CopilotChatConfigurationProvider.");
|
|
287
|
-
return;
|
|
288
|
-
}
|
|
289
|
-
if (parentSetActiveThreadId) {
|
|
290
|
-
parentSetActiveThreadId(id, options);
|
|
291
|
-
return;
|
|
292
|
-
}
|
|
293
|
-
ownSetActiveThreadId(id, options);
|
|
294
|
-
}, [parentSetActiveThreadId, ownSetActiveThreadId]);
|
|
295
|
-
const resolvedStartNewThread = useCallback(() => {
|
|
296
|
-
if (isThreadIdControlledRef.current) {
|
|
297
|
-
console.warn("[CopilotKit] Ignoring startNewThread(): threadId is controlled via the `threadId` prop on CopilotChatConfigurationProvider.");
|
|
298
|
-
return;
|
|
299
|
-
}
|
|
300
|
-
if (parentStartNewThread) {
|
|
301
|
-
parentStartNewThread();
|
|
302
|
-
return;
|
|
303
|
-
}
|
|
304
|
-
ownStartNewThread();
|
|
305
|
-
}, [parentStartNewThread, ownStartNewThread]);
|
|
306
|
-
const setModalOpenWithDrawerExclusion = useCallback((open) => {
|
|
307
|
-
if (open && isMobileViewport()) resolvedSetDrawerOpen(false);
|
|
308
|
-
resolvedSetModalOpen(open);
|
|
309
|
-
}, [resolvedSetModalOpen, resolvedSetDrawerOpen]);
|
|
178
|
+
return store.bindOpenThread(copilotkit);
|
|
179
|
+
}, [copilotkit, store]);
|
|
180
|
+
const ownsModal = isModalDefaultOpen !== void 0;
|
|
181
|
+
const isModalOpen = ownsModal || !parentConfig ? snapshot.isModalOpen : parentConfig.isModalOpen;
|
|
182
|
+
const setModalOpen = ownsModal || !parentConfig ? store.setModalOpen : parentConfig.setModalOpen;
|
|
183
|
+
const { agentId: resolvedAgentId, threadId: resolvedThreadId, hasExplicitThreadId: resolvedHasExplicitThreadId, drawerOpen, drawerRegistered } = snapshot;
|
|
310
184
|
const configurationValue = useMemo(() => ({
|
|
311
185
|
labels: mergedLabels,
|
|
312
186
|
agentId: resolvedAgentId,
|
|
313
187
|
threadId: resolvedThreadId,
|
|
314
188
|
hasExplicitThreadId: resolvedHasExplicitThreadId,
|
|
315
|
-
isModalOpen
|
|
316
|
-
setModalOpen
|
|
317
|
-
drawerOpen
|
|
318
|
-
setDrawerOpen:
|
|
319
|
-
drawerRegistered
|
|
320
|
-
registerDrawer:
|
|
321
|
-
ɵregisterModalCloser:
|
|
322
|
-
setActiveThreadId:
|
|
323
|
-
startNewThread:
|
|
189
|
+
isModalOpen,
|
|
190
|
+
setModalOpen,
|
|
191
|
+
drawerOpen,
|
|
192
|
+
setDrawerOpen: store.setDrawerOpen,
|
|
193
|
+
drawerRegistered,
|
|
194
|
+
registerDrawer: store.registerDrawer,
|
|
195
|
+
ɵregisterModalCloser: store.registerModalCloser,
|
|
196
|
+
setActiveThreadId: store.setActiveThreadId,
|
|
197
|
+
startNewThread: store.startNewThread,
|
|
198
|
+
ɵstore: store
|
|
324
199
|
}), [
|
|
325
200
|
mergedLabels,
|
|
326
201
|
resolvedAgentId,
|
|
327
202
|
resolvedThreadId,
|
|
328
203
|
resolvedHasExplicitThreadId,
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
resolvedRegisterDrawer,
|
|
335
|
-
resolvedRegisterModalCloser,
|
|
336
|
-
resolvedSetActiveThreadId,
|
|
337
|
-
resolvedStartNewThread
|
|
204
|
+
isModalOpen,
|
|
205
|
+
setModalOpen,
|
|
206
|
+
drawerOpen,
|
|
207
|
+
drawerRegistered,
|
|
208
|
+
store
|
|
338
209
|
]);
|
|
339
210
|
return /* @__PURE__ */ jsx(CopilotChatConfiguration.Provider, {
|
|
340
211
|
value: configurationValue,
|
|
@@ -3714,4 +3585,4 @@ function MarkdownSurfaces({ content, messageId, isStreaming = false, ...markdown
|
|
|
3714
3585
|
|
|
3715
3586
|
//#endregion
|
|
3716
3587
|
export { ExpressionError as A, renderSlot as B, issueKey as C, getMarkdownSurfaceSource as D, containsDynamicValue as E, toJsonSchema as F, CopilotIcon as G, CopilotChatConfigurationProvider as H, defineToolCallRenderer as I, StreamingMarkdownDefaultRenderer as J, IconSvg as K, MarkdownRendererProvider as L, catalogIdsOf as M, componentCatalogIds as N, isRecord as O, createGenerativeUI as P, useMarkdownRenderer as R, isAsyncIssue as S, withoutRejectedNulls as T, useCopilotChatConfiguration as U, ControlledModalOpenScope as V, useShallowStableRef as W, GenerativeUINodeContext as _, GenerativeUIToolCallRenderer as a, useRequiredGenerativeUIRuntime as b, SurfaceView as c, namedRole as d, useGenerativeUIAccessibility as f, useManagerVersion as g, useGenerativeUIState as h, GenerativeUIChatSlotContext as i, GenerativeUIError as j, BASIC_FUNCTIONS as k, DARK_THEME_CSS as l, useGenerativeUIFunction as m, ProviderMarkdown as n, createGenerativeUIActivityRenderer as o, wrapperAria as p, cn as q, DefaultGenerativeUIChatCard as r, createGenerativeUIFunctionCallActivityRenderer as s, MarkdownSurfaces as t, controlAria as u, GenerativeUIRuntimeContext as v, validateSchemaSync as w, formatIssues as x, useGenerativeUIRuntime as y, isReactComponentType as z };
|
|
3717
|
-
//# sourceMappingURL=MarkdownSurfaces-
|
|
3588
|
+
//# sourceMappingURL=MarkdownSurfaces-DveOwhaW.mjs.map
|