@anvia/react-ui 0.4.3 → 0.5.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/attachment/index.js +2 -2
- package/dist/chat/index.d.ts +3 -2
- package/dist/chat/index.js +4 -4
- package/dist/{chunk-657E5BPN.js → chunk-2N5PXLAS.js} +2 -2
- package/dist/{chunk-SE7I6ZXJ.js → chunk-7PBLYIKR.js} +2 -2
- package/dist/{chunk-JUNV3MUR.js → chunk-I4L25QXW.js} +2 -2
- package/dist/{chunk-7L2C5UUZ.js → chunk-L3ZUEIB6.js} +16 -10
- package/dist/chunk-L3ZUEIB6.js.map +1 -0
- package/dist/{chunk-TOBAQM2G.js → chunk-T6GPGCK4.js} +2 -2
- package/dist/{chunk-GXB4VINL.js → chunk-TVWD2LX4.js} +2 -2
- package/dist/{chunk-32QFNRXR.js → chunk-WUMACFYS.js} +2 -2
- package/dist/{chunk-BCCU3VT5.js → chunk-YQJLVBQD.js} +1 -1
- package/dist/chunk-YQJLVBQD.js.map +1 -0
- package/dist/chunk-YUK4ASXB.js +989 -0
- package/dist/chunk-YUK4ASXB.js.map +1 -0
- package/dist/completion/index.js +2 -2
- package/dist/{thread-C2-Xo08o.d.ts → composer-CzsbDFPt.d.ts} +7 -10
- package/dist/human-input/index.js +2 -2
- package/dist/image/index.js +2 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +15 -15
- package/dist/message/index.d.ts +11 -1
- package/dist/message/index.js +3 -3
- package/dist/selection-toolbar/index.js +2 -2
- package/dist/shared.d.ts +2 -1
- package/dist/shared.js +1 -1
- package/dist/thread-list/index.js +2 -2
- package/dist/thread-uEm8hH0s.d.ts +11 -0
- package/package.json +2 -2
- package/dist/chunk-7L2C5UUZ.js.map +0 -1
- package/dist/chunk-BCCU3VT5.js.map +0 -1
- package/dist/chunk-LWH6BMAD.js +0 -580
- package/dist/chunk-LWH6BMAD.js.map +0 -1
- /package/dist/{chunk-657E5BPN.js.map → chunk-2N5PXLAS.js.map} +0 -0
- /package/dist/{chunk-SE7I6ZXJ.js.map → chunk-7PBLYIKR.js.map} +0 -0
- /package/dist/{chunk-JUNV3MUR.js.map → chunk-I4L25QXW.js.map} +0 -0
- /package/dist/{chunk-TOBAQM2G.js.map → chunk-T6GPGCK4.js.map} +0 -0
- /package/dist/{chunk-GXB4VINL.js.map → chunk-TVWD2LX4.js.map} +0 -0
- /package/dist/{chunk-32QFNRXR.js.map → chunk-WUMACFYS.js.map} +0 -0
|
@@ -0,0 +1,989 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Attachment
|
|
3
|
+
} from "./chunk-WUMACFYS.js";
|
|
4
|
+
import {
|
|
5
|
+
renderPrimitive
|
|
6
|
+
} from "./chunk-T3ZFZ3NP.js";
|
|
7
|
+
import {
|
|
8
|
+
InternalAttachmentProvider,
|
|
9
|
+
InternalMessagePartProvider,
|
|
10
|
+
useChatContext,
|
|
11
|
+
useMessage,
|
|
12
|
+
useMessagePart,
|
|
13
|
+
useOptionalMessagePart
|
|
14
|
+
} from "./chunk-YQJLVBQD.js";
|
|
15
|
+
|
|
16
|
+
// src/message/actions.tsx
|
|
17
|
+
import { forwardRef, useCallback, useEffect, useRef, useState } from "react";
|
|
18
|
+
|
|
19
|
+
// src/format/message.ts
|
|
20
|
+
function messageText(message) {
|
|
21
|
+
return message.parts.filter((part) => part.type === "text").map((part) => part.text).join("");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// src/format/value.ts
|
|
25
|
+
function stringifyValue(value) {
|
|
26
|
+
if (value === void 0) {
|
|
27
|
+
return "";
|
|
28
|
+
}
|
|
29
|
+
if (typeof value === "string") {
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
return JSON.stringify(value, null, 2);
|
|
34
|
+
} catch {
|
|
35
|
+
return String(value);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// src/message/actions.tsx
|
|
40
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
41
|
+
var MessageActions = forwardRef(
|
|
42
|
+
function MessageActions2(props, ref) {
|
|
43
|
+
return renderPrimitive(
|
|
44
|
+
"div",
|
|
45
|
+
{
|
|
46
|
+
...props,
|
|
47
|
+
children: props.children ?? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
48
|
+
/* @__PURE__ */ jsx(MessageCopy, {}),
|
|
49
|
+
/* @__PURE__ */ jsx(MessageRegenerate, {})
|
|
50
|
+
] }),
|
|
51
|
+
"data-anvia-message-actions": ""
|
|
52
|
+
},
|
|
53
|
+
ref
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
var MessageCopy = forwardRef(function MessageCopy2({ onClick, ...props }, ref) {
|
|
58
|
+
const { message } = useMessage();
|
|
59
|
+
const [copyState, setCopyState] = useState("idle");
|
|
60
|
+
const text = messageText(message);
|
|
61
|
+
const previousTextRef = useRef(text);
|
|
62
|
+
const disabled = props.disabled ?? text.length === 0;
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
if (previousTextRef.current !== text) {
|
|
65
|
+
previousTextRef.current = text;
|
|
66
|
+
setCopyState("idle");
|
|
67
|
+
}
|
|
68
|
+
}, [text]);
|
|
69
|
+
const handleClick = useCallback(
|
|
70
|
+
async (event) => {
|
|
71
|
+
onClick?.(event);
|
|
72
|
+
if (event.defaultPrevented || disabled) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const writeText = navigator.clipboard?.writeText;
|
|
76
|
+
if (writeText === void 0) {
|
|
77
|
+
setCopyState("error");
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
await writeText.call(navigator.clipboard, text);
|
|
82
|
+
setCopyState("copied");
|
|
83
|
+
} catch {
|
|
84
|
+
setCopyState("error");
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
[disabled, onClick, text]
|
|
88
|
+
);
|
|
89
|
+
return renderPrimitive(
|
|
90
|
+
"button",
|
|
91
|
+
{
|
|
92
|
+
...props,
|
|
93
|
+
children: props.children ?? "Copy",
|
|
94
|
+
disabled,
|
|
95
|
+
onClick: handleClick,
|
|
96
|
+
type: props.type ?? "button",
|
|
97
|
+
"data-anvia-copy": "",
|
|
98
|
+
"data-state": copyState
|
|
99
|
+
},
|
|
100
|
+
ref
|
|
101
|
+
);
|
|
102
|
+
});
|
|
103
|
+
var MessageRegenerate = forwardRef(
|
|
104
|
+
function MessageRegenerate2({ onClick, ...props }, ref) {
|
|
105
|
+
const chat = useChatContext();
|
|
106
|
+
const { message } = useMessage();
|
|
107
|
+
const latestAssistantMessage = [...chat.messages].reverse().find((item) => item.role === "assistant");
|
|
108
|
+
const disabled = props.disabled ?? (chat.status === "streaming" || message.role !== "assistant" || latestAssistantMessage?.id !== message.id);
|
|
109
|
+
const handleClick = useCallback(
|
|
110
|
+
(event) => {
|
|
111
|
+
onClick?.(event);
|
|
112
|
+
if (event.defaultPrevented || disabled) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
void chat.regenerate();
|
|
116
|
+
},
|
|
117
|
+
[chat, disabled, onClick]
|
|
118
|
+
);
|
|
119
|
+
return renderPrimitive(
|
|
120
|
+
"button",
|
|
121
|
+
{
|
|
122
|
+
...props,
|
|
123
|
+
children: props.children ?? "Regenerate",
|
|
124
|
+
disabled,
|
|
125
|
+
onClick: handleClick,
|
|
126
|
+
type: props.type ?? "button",
|
|
127
|
+
"data-anvia-regenerate": "",
|
|
128
|
+
"data-state": disabled ? "disabled" : "idle"
|
|
129
|
+
},
|
|
130
|
+
ref
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
// src/message/entity.tsx
|
|
136
|
+
import { forwardRef as forwardRef2 } from "react";
|
|
137
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
138
|
+
var MessageEntity = forwardRef2(function MessageEntity2({ children, entity, ...props }, ref) {
|
|
139
|
+
return /* @__PURE__ */ jsx2(
|
|
140
|
+
"span",
|
|
141
|
+
{
|
|
142
|
+
...props,
|
|
143
|
+
"data-anvia-message-entity": "",
|
|
144
|
+
"data-entity-id": entity.id,
|
|
145
|
+
"data-trigger-id": entity.triggerId,
|
|
146
|
+
ref,
|
|
147
|
+
children: children ?? entity.text
|
|
148
|
+
}
|
|
149
|
+
);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
// src/message/parts.tsx
|
|
153
|
+
import {
|
|
154
|
+
useSmoothStreamText
|
|
155
|
+
} from "@anvia/react";
|
|
156
|
+
import { createElement, forwardRef as forwardRef3 } from "react";
|
|
157
|
+
import ReactMarkdown from "react-markdown";
|
|
158
|
+
import remarkGfm from "remark-gfm";
|
|
159
|
+
|
|
160
|
+
// src/entities.ts
|
|
161
|
+
function messageTextLayout(parts) {
|
|
162
|
+
const textParts = parts.filter(
|
|
163
|
+
(part) => part.type === "text"
|
|
164
|
+
);
|
|
165
|
+
const segments = [];
|
|
166
|
+
let offset = 0;
|
|
167
|
+
for (const [index, part] of textParts.entries()) {
|
|
168
|
+
const from = offset;
|
|
169
|
+
const to = from + part.text.length;
|
|
170
|
+
segments.push({ part, from, to });
|
|
171
|
+
offset = to + (index === textParts.length - 1 ? 0 : 2);
|
|
172
|
+
}
|
|
173
|
+
return {
|
|
174
|
+
text: textParts.map((part) => part.text).join("\n\n"),
|
|
175
|
+
segments
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
function validComposerEntities(text, metadata) {
|
|
179
|
+
const candidates = composerEntityCandidates(metadata);
|
|
180
|
+
const individuallyValid = candidates.flatMap(
|
|
181
|
+
(entity, index) => isValidComposerEntity(entity, text) ? [{ entity, index }] : []
|
|
182
|
+
);
|
|
183
|
+
individuallyValid.sort(
|
|
184
|
+
(left, right) => left.entity.range.from - right.entity.range.from || left.entity.range.to - right.entity.range.to || left.index - right.index
|
|
185
|
+
);
|
|
186
|
+
const overlapping = /* @__PURE__ */ new Set();
|
|
187
|
+
let groupStart = 0;
|
|
188
|
+
let groupEnd = individuallyValid[0]?.entity.range.to ?? 0;
|
|
189
|
+
let groupHasOverlap = false;
|
|
190
|
+
for (let index = 1; index <= individuallyValid.length; index += 1) {
|
|
191
|
+
const current = individuallyValid[index];
|
|
192
|
+
if (current !== void 0 && current.entity.range.from < groupEnd) {
|
|
193
|
+
groupHasOverlap = true;
|
|
194
|
+
groupEnd = Math.max(groupEnd, current.entity.range.to);
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
if (groupHasOverlap) {
|
|
198
|
+
for (let groupIndex = groupStart; groupIndex < index; groupIndex += 1) {
|
|
199
|
+
const candidate = individuallyValid[groupIndex];
|
|
200
|
+
if (candidate !== void 0) {
|
|
201
|
+
overlapping.add(candidate.index);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
groupStart = index;
|
|
206
|
+
groupEnd = current?.entity.range.to ?? 0;
|
|
207
|
+
groupHasOverlap = false;
|
|
208
|
+
}
|
|
209
|
+
return individuallyValid.filter((candidate) => !overlapping.has(candidate.index)).map((candidate) => candidate.entity);
|
|
210
|
+
}
|
|
211
|
+
function entitiesForTextSegment(entities, segment) {
|
|
212
|
+
return entities.flatMap((entity) => {
|
|
213
|
+
if (entity.range.from < segment.from || entity.range.to > segment.to) {
|
|
214
|
+
return [];
|
|
215
|
+
}
|
|
216
|
+
return [
|
|
217
|
+
{
|
|
218
|
+
...entity,
|
|
219
|
+
range: {
|
|
220
|
+
from: entity.range.from - segment.from,
|
|
221
|
+
to: entity.range.to - segment.from
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
];
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
function shiftComposerEntityRanges(entities, offset) {
|
|
228
|
+
if (offset === 0) {
|
|
229
|
+
return entities;
|
|
230
|
+
}
|
|
231
|
+
return entities.map((entity) => ({
|
|
232
|
+
...entity,
|
|
233
|
+
range: {
|
|
234
|
+
from: entity.range.from + offset,
|
|
235
|
+
to: entity.range.to + offset
|
|
236
|
+
}
|
|
237
|
+
}));
|
|
238
|
+
}
|
|
239
|
+
function composerEntityCandidates(metadata) {
|
|
240
|
+
if (!isRecord(metadata) || !isRecord(metadata.composer)) {
|
|
241
|
+
return [];
|
|
242
|
+
}
|
|
243
|
+
return Array.isArray(metadata.composer.entities) ? metadata.composer.entities : [];
|
|
244
|
+
}
|
|
245
|
+
function isValidComposerEntity(value, text) {
|
|
246
|
+
if (!isRecord(value) || !isRecord(value.range)) {
|
|
247
|
+
return false;
|
|
248
|
+
}
|
|
249
|
+
if (!isNonEmptyString(value.id) || !isNonEmptyString(value.triggerId) || !isNonEmptyString(value.trigger) || !isNonEmptyString(value.label) || !isNonEmptyString(value.text)) {
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
const { from, to } = value.range;
|
|
253
|
+
return typeof from === "number" && typeof to === "number" && Number.isInteger(from) && Number.isInteger(to) && from >= 0 && to > from && to <= text.length && text.slice(from, to) === value.text;
|
|
254
|
+
}
|
|
255
|
+
function isNonEmptyString(value) {
|
|
256
|
+
return typeof value === "string" && value.length > 0;
|
|
257
|
+
}
|
|
258
|
+
function isRecord(value) {
|
|
259
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// src/message/markdown-entities.ts
|
|
263
|
+
var phrasingParentTypes = /* @__PURE__ */ new Set([
|
|
264
|
+
"paragraph",
|
|
265
|
+
"heading",
|
|
266
|
+
"emphasis",
|
|
267
|
+
"strong",
|
|
268
|
+
"delete",
|
|
269
|
+
"link",
|
|
270
|
+
"linkReference",
|
|
271
|
+
"tableCell"
|
|
272
|
+
]);
|
|
273
|
+
var literalNodeTypes = /* @__PURE__ */ new Set(["code", "inlineCode", "html", "yaml"]);
|
|
274
|
+
function createMessageEntityRemarkPlugin(markdown, entities) {
|
|
275
|
+
return function messageEntityRemarkPlugin() {
|
|
276
|
+
return (tree) => {
|
|
277
|
+
const rendered = /* @__PURE__ */ new Set();
|
|
278
|
+
transformNode(tree, markdown, entities, rendered);
|
|
279
|
+
};
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
function messageEntityRehypeOptions() {
|
|
283
|
+
return {
|
|
284
|
+
handlers: {
|
|
285
|
+
messageEntity(_state, node) {
|
|
286
|
+
const entityIndex = node.entityIndex;
|
|
287
|
+
return {
|
|
288
|
+
type: "element",
|
|
289
|
+
tagName: "span",
|
|
290
|
+
properties: {
|
|
291
|
+
dataAnviaMessageEntity: "",
|
|
292
|
+
dataAnviaEntityIndex: entityIndex === void 0 ? "" : String(entityIndex)
|
|
293
|
+
},
|
|
294
|
+
children: [{ type: "text", value: node.value ?? "" }]
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
function transformNode(node, markdown, entities, rendered) {
|
|
301
|
+
if (literalNodeTypes.has(node.type) || node.children === void 0) {
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
for (const child of node.children) {
|
|
305
|
+
transformNode(child, markdown, entities, rendered);
|
|
306
|
+
}
|
|
307
|
+
if (!phrasingParentTypes.has(node.type)) {
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
for (let entityIndex = entities.length - 1; entityIndex >= 0; entityIndex -= 1) {
|
|
311
|
+
if (rendered.has(entityIndex)) {
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
const entity = entities[entityIndex];
|
|
315
|
+
if (entity !== void 0 && replaceEntity(node, markdown, entity, entityIndex)) {
|
|
316
|
+
rendered.add(entityIndex);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
function replaceEntity(parent, markdown, entity, entityIndex) {
|
|
321
|
+
const children = parent.children;
|
|
322
|
+
if (children === void 0) {
|
|
323
|
+
return false;
|
|
324
|
+
}
|
|
325
|
+
const firstIndex = children.findIndex((child) => containsStart(child, entity.range.from));
|
|
326
|
+
const lastIndex = findLastIndex(children, (child) => containsEnd(child, entity.range.to));
|
|
327
|
+
if (firstIndex < 0 || lastIndex < firstIndex) {
|
|
328
|
+
return false;
|
|
329
|
+
}
|
|
330
|
+
const first = children[firstIndex];
|
|
331
|
+
const last = children[lastIndex];
|
|
332
|
+
const firstPosition = offsets(first);
|
|
333
|
+
const lastPosition = offsets(last);
|
|
334
|
+
if (first === void 0 || last === void 0 || firstPosition === void 0 || lastPosition === void 0 || entity.range.from < firstPosition.from || entity.range.to > lastPosition.to) {
|
|
335
|
+
return false;
|
|
336
|
+
}
|
|
337
|
+
if (firstIndex === lastIndex && literalNodeTypes.has(first.type)) {
|
|
338
|
+
return false;
|
|
339
|
+
}
|
|
340
|
+
const before = contentBefore(first, markdown, entity);
|
|
341
|
+
const after = contentAfter(last, markdown, entity);
|
|
342
|
+
if (before === void 0 || after === void 0) {
|
|
343
|
+
return false;
|
|
344
|
+
}
|
|
345
|
+
const replacement = [];
|
|
346
|
+
replacement.push(...before);
|
|
347
|
+
replacement.push({
|
|
348
|
+
type: "messageEntity",
|
|
349
|
+
value: entity.text,
|
|
350
|
+
entityIndex,
|
|
351
|
+
position: {
|
|
352
|
+
start: { offset: entity.range.from },
|
|
353
|
+
end: { offset: entity.range.to }
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
replacement.push(...after);
|
|
357
|
+
children.splice(firstIndex, lastIndex - firstIndex + 1, ...replacement);
|
|
358
|
+
return true;
|
|
359
|
+
}
|
|
360
|
+
function contentBefore(node, markdown, entity) {
|
|
361
|
+
const position = offsets(node);
|
|
362
|
+
if (position === void 0) {
|
|
363
|
+
return void 0;
|
|
364
|
+
}
|
|
365
|
+
if (entity.range.from === position.from) {
|
|
366
|
+
return [];
|
|
367
|
+
}
|
|
368
|
+
if (node.type !== "text" || node.value === void 0) {
|
|
369
|
+
if (node.children === void 0 || literalNodeTypes.has(node.type)) {
|
|
370
|
+
return void 0;
|
|
371
|
+
}
|
|
372
|
+
const childIndex = node.children.findIndex((child2) => containsStart(child2, entity.range.from));
|
|
373
|
+
const child = node.children[childIndex];
|
|
374
|
+
if (child === void 0) {
|
|
375
|
+
return void 0;
|
|
376
|
+
}
|
|
377
|
+
const childContent = contentBefore(child, markdown, entity);
|
|
378
|
+
return childContent === void 0 ? void 0 : [...node.children.slice(0, childIndex), ...childContent];
|
|
379
|
+
}
|
|
380
|
+
const split = textValueRange(node, markdown, entity);
|
|
381
|
+
if (split === void 0) {
|
|
382
|
+
return void 0;
|
|
383
|
+
}
|
|
384
|
+
return [
|
|
385
|
+
{
|
|
386
|
+
...node,
|
|
387
|
+
value: node.value.slice(0, split.from),
|
|
388
|
+
position: {
|
|
389
|
+
start: node.position?.start ?? {},
|
|
390
|
+
end: { offset: entity.range.from }
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
];
|
|
394
|
+
}
|
|
395
|
+
function contentAfter(node, markdown, entity) {
|
|
396
|
+
const position = offsets(node);
|
|
397
|
+
if (position === void 0) {
|
|
398
|
+
return void 0;
|
|
399
|
+
}
|
|
400
|
+
if (entity.range.to === position.to) {
|
|
401
|
+
return [];
|
|
402
|
+
}
|
|
403
|
+
if (node.type !== "text" || node.value === void 0) {
|
|
404
|
+
if (node.children === void 0 || literalNodeTypes.has(node.type)) {
|
|
405
|
+
return void 0;
|
|
406
|
+
}
|
|
407
|
+
const childIndex = findLastIndex(node.children, (child2) => containsEnd(child2, entity.range.to));
|
|
408
|
+
const child = node.children[childIndex];
|
|
409
|
+
if (child === void 0) {
|
|
410
|
+
return void 0;
|
|
411
|
+
}
|
|
412
|
+
const childContent = contentAfter(child, markdown, entity);
|
|
413
|
+
return childContent === void 0 ? void 0 : [...childContent, ...node.children.slice(childIndex + 1)];
|
|
414
|
+
}
|
|
415
|
+
const split = textValueRange(node, markdown, entity);
|
|
416
|
+
if (split === void 0) {
|
|
417
|
+
return void 0;
|
|
418
|
+
}
|
|
419
|
+
return [
|
|
420
|
+
{
|
|
421
|
+
...node,
|
|
422
|
+
value: node.value.slice(split.to),
|
|
423
|
+
position: {
|
|
424
|
+
start: { offset: entity.range.to },
|
|
425
|
+
end: node.position?.end ?? {}
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
];
|
|
429
|
+
}
|
|
430
|
+
function textValueRange(node, markdown, entity) {
|
|
431
|
+
const position = offsets(node);
|
|
432
|
+
const value = node.value;
|
|
433
|
+
if (position === void 0 || value === void 0) {
|
|
434
|
+
return void 0;
|
|
435
|
+
}
|
|
436
|
+
const raw = markdown.slice(position.from, position.to);
|
|
437
|
+
const relativeFrom = entity.range.from - position.from;
|
|
438
|
+
const relativeTo = entity.range.to - position.from;
|
|
439
|
+
if (raw === value) {
|
|
440
|
+
return { from: relativeFrom, to: relativeTo };
|
|
441
|
+
}
|
|
442
|
+
const occurrence = countOccurrences(raw.slice(0, relativeFrom), entity.text);
|
|
443
|
+
const valueFrom = occurrenceIndex(value, entity.text, occurrence);
|
|
444
|
+
return valueFrom === void 0 ? void 0 : { from: valueFrom, to: valueFrom + entity.text.length };
|
|
445
|
+
}
|
|
446
|
+
function countOccurrences(value, search) {
|
|
447
|
+
let count = 0;
|
|
448
|
+
let offset = 0;
|
|
449
|
+
while (offset <= value.length - search.length) {
|
|
450
|
+
const index = value.indexOf(search, offset);
|
|
451
|
+
if (index < 0) {
|
|
452
|
+
break;
|
|
453
|
+
}
|
|
454
|
+
count += 1;
|
|
455
|
+
offset = index + search.length;
|
|
456
|
+
}
|
|
457
|
+
return count;
|
|
458
|
+
}
|
|
459
|
+
function occurrenceIndex(value, search, occurrence) {
|
|
460
|
+
let offset = 0;
|
|
461
|
+
for (let index = 0; index <= occurrence; index += 1) {
|
|
462
|
+
const found = value.indexOf(search, offset);
|
|
463
|
+
if (found < 0) {
|
|
464
|
+
return void 0;
|
|
465
|
+
}
|
|
466
|
+
if (index === occurrence) {
|
|
467
|
+
return found;
|
|
468
|
+
}
|
|
469
|
+
offset = found + search.length;
|
|
470
|
+
}
|
|
471
|
+
return void 0;
|
|
472
|
+
}
|
|
473
|
+
function containsStart(node, offset) {
|
|
474
|
+
const position = offsets(node);
|
|
475
|
+
return position !== void 0 && offset >= position.from && offset < position.to;
|
|
476
|
+
}
|
|
477
|
+
function containsEnd(node, offset) {
|
|
478
|
+
const position = offsets(node);
|
|
479
|
+
return position !== void 0 && offset > position.from && offset <= position.to;
|
|
480
|
+
}
|
|
481
|
+
function offsets(node) {
|
|
482
|
+
const from = node?.position?.start.offset;
|
|
483
|
+
const to = node?.position?.end.offset;
|
|
484
|
+
return typeof from === "number" && typeof to === "number" ? { from, to } : void 0;
|
|
485
|
+
}
|
|
486
|
+
function findLastIndex(items, predicate) {
|
|
487
|
+
for (let index = items.length - 1; index >= 0; index -= 1) {
|
|
488
|
+
const item = items[index];
|
|
489
|
+
if (item !== void 0 && predicate(item)) {
|
|
490
|
+
return index;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
return -1;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
// src/message/parts.tsx
|
|
497
|
+
import { Fragment as Fragment2, jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
498
|
+
var MessageParts = forwardRef3(function MessageParts2({ children, filter, ...props }, ref) {
|
|
499
|
+
const { message } = useMessage();
|
|
500
|
+
const parts = filter === void 0 ? message.parts : message.parts.filter(filter);
|
|
501
|
+
return renderPrimitive(
|
|
502
|
+
"div",
|
|
503
|
+
{
|
|
504
|
+
...props,
|
|
505
|
+
children: parts.map((part) => /* @__PURE__ */ jsx3(InternalMessagePartProvider, { part, children: typeof children === "function" ? children(part) : children ?? /* @__PURE__ */ jsx3(MessagePart, {}) }, part.id)),
|
|
506
|
+
"data-anvia-message-parts": ""
|
|
507
|
+
},
|
|
508
|
+
ref
|
|
509
|
+
);
|
|
510
|
+
});
|
|
511
|
+
var MessagePart = forwardRef3(function MessagePart2({ children, ...props }, ref) {
|
|
512
|
+
const { part } = useMessagePart();
|
|
513
|
+
const renderedChildren = typeof children === "function" ? children(part) : children ?? defaultPart(part);
|
|
514
|
+
return renderPrimitive(
|
|
515
|
+
"div",
|
|
516
|
+
{
|
|
517
|
+
...props,
|
|
518
|
+
children: renderedChildren,
|
|
519
|
+
"data-anvia-part": "",
|
|
520
|
+
"data-part": part.type
|
|
521
|
+
},
|
|
522
|
+
ref
|
|
523
|
+
);
|
|
524
|
+
});
|
|
525
|
+
var MessageText = forwardRef3(function MessageText2(props, ref) {
|
|
526
|
+
const { part } = useMessagePart();
|
|
527
|
+
if (part.type !== "text") {
|
|
528
|
+
return null;
|
|
529
|
+
}
|
|
530
|
+
return /* @__PURE__ */ jsx3(MessageTextContent, { ...props, content: part.text, ref });
|
|
531
|
+
});
|
|
532
|
+
var MessageTextContent = forwardRef3(
|
|
533
|
+
function MessageTextContent2({
|
|
534
|
+
animate = false,
|
|
535
|
+
animationMode = "smooth",
|
|
536
|
+
isStreaming,
|
|
537
|
+
smoothingPreset,
|
|
538
|
+
reducedMotion,
|
|
539
|
+
content,
|
|
540
|
+
...props
|
|
541
|
+
}, ref) {
|
|
542
|
+
const animationEnabled = animate && props.children === void 0;
|
|
543
|
+
const smooth = useSmoothStreamText(content, {
|
|
544
|
+
enabled: animationEnabled,
|
|
545
|
+
mode: animationMode,
|
|
546
|
+
...isStreaming === void 0 ? {} : { isStreaming },
|
|
547
|
+
...smoothingPreset === void 0 ? {} : { preset: smoothingPreset },
|
|
548
|
+
...reducedMotion === void 0 ? {} : { reducedMotion }
|
|
549
|
+
});
|
|
550
|
+
const animationActive = animationEnabled && animationMode !== "none" && isStreaming !== false && reducedMotion !== true;
|
|
551
|
+
return renderPrimitive(
|
|
552
|
+
"span",
|
|
553
|
+
{
|
|
554
|
+
...props,
|
|
555
|
+
children: props.children ?? (animationEnabled ? smooth.text : content),
|
|
556
|
+
"data-anvia-text": "",
|
|
557
|
+
"data-anvia-stream-animation": animationEnabled ? animationMode : void 0,
|
|
558
|
+
"data-streaming": animationActive ? "" : void 0
|
|
559
|
+
},
|
|
560
|
+
ref
|
|
561
|
+
);
|
|
562
|
+
}
|
|
563
|
+
);
|
|
564
|
+
var MessageMarkdown = forwardRef3(function MessageMarkdown2({ children, ...props }, ref) {
|
|
565
|
+
const { message } = useMessage();
|
|
566
|
+
const partContext = useOptionalMessagePart();
|
|
567
|
+
const part = partContext?.part;
|
|
568
|
+
if (part !== void 0 && part.type !== "text") {
|
|
569
|
+
return null;
|
|
570
|
+
}
|
|
571
|
+
const layout = messageTextLayout(message.parts);
|
|
572
|
+
const markdown = children ?? (part?.type === "text" ? part.text : layout.text);
|
|
573
|
+
const expectedMarkdown = part?.type === "text" ? part.text : layout.text;
|
|
574
|
+
const validEntities = children === void 0 || children === expectedMarkdown ? validComposerEntities(layout.text, message.metadata) : [];
|
|
575
|
+
const segment = part?.type === "text" ? layout.segments.find((candidate) => candidate.part.id === part.id) : void 0;
|
|
576
|
+
const entities = segment === void 0 ? validEntities : entitiesForTextSegment(validEntities, segment);
|
|
577
|
+
return /* @__PURE__ */ jsx3(MessageMarkdownContent, { ...props, entities, markdown, ref });
|
|
578
|
+
});
|
|
579
|
+
var MessageMarkdownContent = forwardRef3(
|
|
580
|
+
function MessageMarkdownContent2({
|
|
581
|
+
animate = false,
|
|
582
|
+
animationMode = "smooth",
|
|
583
|
+
isStreaming,
|
|
584
|
+
smoothingPreset,
|
|
585
|
+
reducedMotion,
|
|
586
|
+
components,
|
|
587
|
+
renderEntity,
|
|
588
|
+
remarkPlugins,
|
|
589
|
+
entities,
|
|
590
|
+
markdown,
|
|
591
|
+
...props
|
|
592
|
+
}, ref) {
|
|
593
|
+
const smooth = useSmoothStreamText(markdown, {
|
|
594
|
+
enabled: animate,
|
|
595
|
+
mode: animationMode,
|
|
596
|
+
...isStreaming === void 0 ? {} : { isStreaming },
|
|
597
|
+
...smoothingPreset === void 0 ? {} : { preset: smoothingPreset },
|
|
598
|
+
...reducedMotion === void 0 ? {} : { reducedMotion }
|
|
599
|
+
});
|
|
600
|
+
const animationActive = animate && animationMode !== "none" && isStreaming !== false && reducedMotion !== true;
|
|
601
|
+
const renderedMarkdown = animate ? smooth.text : markdown;
|
|
602
|
+
const renderedEntities = validComposerEntities(renderedMarkdown, {
|
|
603
|
+
composer: { entities }
|
|
604
|
+
});
|
|
605
|
+
return renderPrimitive(
|
|
606
|
+
"div",
|
|
607
|
+
{
|
|
608
|
+
...props,
|
|
609
|
+
children: /* @__PURE__ */ jsx3(
|
|
610
|
+
ReactMarkdown,
|
|
611
|
+
{
|
|
612
|
+
components: markdownComponents(components, renderedEntities, renderEntity),
|
|
613
|
+
remarkPlugins: [
|
|
614
|
+
createMessageEntityRemarkPlugin(renderedMarkdown, renderedEntities),
|
|
615
|
+
...remarkPlugins ?? [remarkGfm]
|
|
616
|
+
],
|
|
617
|
+
remarkRehypeOptions: messageEntityRehypeOptions(),
|
|
618
|
+
children: renderedMarkdown
|
|
619
|
+
}
|
|
620
|
+
),
|
|
621
|
+
"data-anvia-markdown": "",
|
|
622
|
+
"data-anvia-stream-animation": animate ? animationMode : void 0,
|
|
623
|
+
"data-streaming": animationActive ? "" : void 0
|
|
624
|
+
},
|
|
625
|
+
ref
|
|
626
|
+
);
|
|
627
|
+
}
|
|
628
|
+
);
|
|
629
|
+
function markdownComponents(components, entities, renderEntity) {
|
|
630
|
+
const consumerSpan = components?.span;
|
|
631
|
+
return {
|
|
632
|
+
code: defaultCodeComponent,
|
|
633
|
+
pre: defaultPreComponent,
|
|
634
|
+
...components,
|
|
635
|
+
span(spanProps) {
|
|
636
|
+
const internalProps = spanProps;
|
|
637
|
+
const entityIndexValue = internalProps["data-anvia-entity-index"];
|
|
638
|
+
const entityIndex = typeof entityIndexValue === "string" && /^\d+$/.test(entityIndexValue) ? Number(entityIndexValue) : void 0;
|
|
639
|
+
const entity = entityIndex === void 0 ? void 0 : entities[entityIndex];
|
|
640
|
+
const consumerProps = { ...internalProps };
|
|
641
|
+
delete consumerProps["data-anvia-entity-index"];
|
|
642
|
+
if (entity !== void 0) {
|
|
643
|
+
if (renderEntity !== void 0) {
|
|
644
|
+
return renderEntity(entity);
|
|
645
|
+
}
|
|
646
|
+
const entityProps = {
|
|
647
|
+
...consumerProps,
|
|
648
|
+
"data-anvia-message-entity": "",
|
|
649
|
+
"data-entity-id": entity.id,
|
|
650
|
+
"data-trigger-id": entity.triggerId
|
|
651
|
+
};
|
|
652
|
+
if (consumerSpan !== void 0) {
|
|
653
|
+
return createElement(consumerSpan, entityProps);
|
|
654
|
+
}
|
|
655
|
+
const { node: _node2, ...elementProps2 } = entityProps;
|
|
656
|
+
return /* @__PURE__ */ jsx3(MessageEntity, { ...elementProps2, entity });
|
|
657
|
+
}
|
|
658
|
+
if (consumerSpan !== void 0) {
|
|
659
|
+
return createElement(consumerSpan, consumerProps);
|
|
660
|
+
}
|
|
661
|
+
const { node: _node, ...elementProps } = consumerProps;
|
|
662
|
+
return /* @__PURE__ */ jsx3("span", { ...elementProps });
|
|
663
|
+
}
|
|
664
|
+
};
|
|
665
|
+
}
|
|
666
|
+
var MessageCodeBlock = forwardRef3(
|
|
667
|
+
function MessageCodeBlock2({ children, code, language, ...props }, ref) {
|
|
668
|
+
return renderPrimitive(
|
|
669
|
+
"pre",
|
|
670
|
+
{
|
|
671
|
+
...props,
|
|
672
|
+
children: children ?? /* @__PURE__ */ jsx3("code", { "data-anvia-code": "", "data-language": language, children: code ?? "" }),
|
|
673
|
+
"data-anvia-code-block": "",
|
|
674
|
+
"data-language": language
|
|
675
|
+
},
|
|
676
|
+
ref
|
|
677
|
+
);
|
|
678
|
+
}
|
|
679
|
+
);
|
|
680
|
+
var MessageReasoning = forwardRef3(
|
|
681
|
+
function MessageReasoning2(props, ref) {
|
|
682
|
+
const { part } = useMessagePart();
|
|
683
|
+
if (part.type !== "reasoning") {
|
|
684
|
+
return null;
|
|
685
|
+
}
|
|
686
|
+
return renderPrimitive(
|
|
687
|
+
"details",
|
|
688
|
+
{
|
|
689
|
+
...props,
|
|
690
|
+
children: props.children ?? /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
691
|
+
/* @__PURE__ */ jsx3("summary", { children: "Reasoning" }),
|
|
692
|
+
/* @__PURE__ */ jsx3("pre", { children: part.text })
|
|
693
|
+
] }),
|
|
694
|
+
"data-anvia-reasoning": ""
|
|
695
|
+
},
|
|
696
|
+
ref
|
|
697
|
+
);
|
|
698
|
+
}
|
|
699
|
+
);
|
|
700
|
+
var MessageTool = forwardRef3(function MessageTool2({ children, renderWhen = "always", ...props }, ref) {
|
|
701
|
+
const { part } = useMessagePart();
|
|
702
|
+
if (part.type !== "tool" || !shouldRenderTool(part, renderWhen)) {
|
|
703
|
+
return null;
|
|
704
|
+
}
|
|
705
|
+
const renderedChildren = typeof children === "function" ? children(part) : children ?? defaultToolContent();
|
|
706
|
+
return renderPrimitive(
|
|
707
|
+
"div",
|
|
708
|
+
{
|
|
709
|
+
...props,
|
|
710
|
+
children: renderedChildren,
|
|
711
|
+
"data-anvia-tool": "",
|
|
712
|
+
"data-state": part.state
|
|
713
|
+
},
|
|
714
|
+
ref
|
|
715
|
+
);
|
|
716
|
+
});
|
|
717
|
+
var MessageToolName = forwardRef3(
|
|
718
|
+
function MessageToolName2(props, ref) {
|
|
719
|
+
const { part } = useMessagePart();
|
|
720
|
+
if (part.type !== "tool") {
|
|
721
|
+
return null;
|
|
722
|
+
}
|
|
723
|
+
return renderPrimitive(
|
|
724
|
+
"span",
|
|
725
|
+
{
|
|
726
|
+
...props,
|
|
727
|
+
children: props.children ?? part.toolName,
|
|
728
|
+
"data-anvia-tool-name": ""
|
|
729
|
+
},
|
|
730
|
+
ref
|
|
731
|
+
);
|
|
732
|
+
}
|
|
733
|
+
);
|
|
734
|
+
var MessageToolStatus = forwardRef3(
|
|
735
|
+
function MessageToolStatus2(props, ref) {
|
|
736
|
+
const { part } = useMessagePart();
|
|
737
|
+
if (part.type !== "tool") {
|
|
738
|
+
return null;
|
|
739
|
+
}
|
|
740
|
+
return renderPrimitive(
|
|
741
|
+
"span",
|
|
742
|
+
{
|
|
743
|
+
...props,
|
|
744
|
+
children: props.children ?? toolStateLabel(part.state),
|
|
745
|
+
"data-anvia-tool-status": "",
|
|
746
|
+
"data-state": part.state
|
|
747
|
+
},
|
|
748
|
+
ref
|
|
749
|
+
);
|
|
750
|
+
}
|
|
751
|
+
);
|
|
752
|
+
var MessageToolInput = forwardRef3(
|
|
753
|
+
function MessageToolInput2(props, ref) {
|
|
754
|
+
const { part } = useMessagePart();
|
|
755
|
+
if (part.type !== "tool" || part.input === void 0) {
|
|
756
|
+
return null;
|
|
757
|
+
}
|
|
758
|
+
return renderPrimitive(
|
|
759
|
+
"pre",
|
|
760
|
+
{
|
|
761
|
+
...props,
|
|
762
|
+
children: props.children ?? stringifyValue(part.input),
|
|
763
|
+
"data-anvia-tool-input": ""
|
|
764
|
+
},
|
|
765
|
+
ref
|
|
766
|
+
);
|
|
767
|
+
}
|
|
768
|
+
);
|
|
769
|
+
var MessageToolOutput = forwardRef3(
|
|
770
|
+
function MessageToolOutput2(props, ref) {
|
|
771
|
+
const { part } = useMessagePart();
|
|
772
|
+
if (part.type !== "tool" || part.output === void 0) {
|
|
773
|
+
return null;
|
|
774
|
+
}
|
|
775
|
+
return renderPrimitive(
|
|
776
|
+
"pre",
|
|
777
|
+
{
|
|
778
|
+
...props,
|
|
779
|
+
children: props.children ?? stringifyValue(part.output),
|
|
780
|
+
"data-anvia-tool-output": ""
|
|
781
|
+
},
|
|
782
|
+
ref
|
|
783
|
+
);
|
|
784
|
+
}
|
|
785
|
+
);
|
|
786
|
+
var MessageToolError = forwardRef3(
|
|
787
|
+
function MessageToolError2(props, ref) {
|
|
788
|
+
const { part } = useMessagePart();
|
|
789
|
+
if (part.type !== "tool" || part.error === void 0) {
|
|
790
|
+
return null;
|
|
791
|
+
}
|
|
792
|
+
return renderPrimitive(
|
|
793
|
+
"div",
|
|
794
|
+
{
|
|
795
|
+
...props,
|
|
796
|
+
children: props.children ?? part.error.message,
|
|
797
|
+
"data-anvia-tool-error": "",
|
|
798
|
+
role: props.role ?? "alert"
|
|
799
|
+
},
|
|
800
|
+
ref
|
|
801
|
+
);
|
|
802
|
+
}
|
|
803
|
+
);
|
|
804
|
+
var MessageAttachment = forwardRef3(
|
|
805
|
+
function MessageAttachment2({ children, ...props }, ref) {
|
|
806
|
+
const { part } = useMessagePart();
|
|
807
|
+
if (part.type !== "attachment") {
|
|
808
|
+
return null;
|
|
809
|
+
}
|
|
810
|
+
const renderedChildren = typeof children === "function" ? children(part.attachment) : children ?? /* @__PURE__ */ jsx3(Attachment.Root, {});
|
|
811
|
+
return /* @__PURE__ */ jsx3(InternalAttachmentProvider, { value: { attachment: part.attachment }, children: renderPrimitive(
|
|
812
|
+
"div",
|
|
813
|
+
{
|
|
814
|
+
...props,
|
|
815
|
+
children: renderedChildren,
|
|
816
|
+
"data-anvia-message-attachment": ""
|
|
817
|
+
},
|
|
818
|
+
ref
|
|
819
|
+
) });
|
|
820
|
+
}
|
|
821
|
+
);
|
|
822
|
+
var MessageData = forwardRef3(
|
|
823
|
+
function MessageData2(props, ref) {
|
|
824
|
+
const { part } = useMessagePart();
|
|
825
|
+
if (part.type !== "data") {
|
|
826
|
+
return null;
|
|
827
|
+
}
|
|
828
|
+
return renderPrimitive(
|
|
829
|
+
"pre",
|
|
830
|
+
{
|
|
831
|
+
...props,
|
|
832
|
+
children: props.children ?? stringifyValue(part.data),
|
|
833
|
+
"data-anvia-data": "",
|
|
834
|
+
"data-name": part.name
|
|
835
|
+
},
|
|
836
|
+
ref
|
|
837
|
+
);
|
|
838
|
+
}
|
|
839
|
+
);
|
|
840
|
+
var MessageError = forwardRef3(
|
|
841
|
+
function MessageError2(props, ref) {
|
|
842
|
+
const { part } = useMessagePart();
|
|
843
|
+
if (part.type !== "error") {
|
|
844
|
+
return null;
|
|
845
|
+
}
|
|
846
|
+
return renderPrimitive(
|
|
847
|
+
"div",
|
|
848
|
+
{
|
|
849
|
+
...props,
|
|
850
|
+
children: props.children ?? part.error.message,
|
|
851
|
+
"data-anvia-error": "",
|
|
852
|
+
role: props.role ?? "alert"
|
|
853
|
+
},
|
|
854
|
+
ref
|
|
855
|
+
);
|
|
856
|
+
}
|
|
857
|
+
);
|
|
858
|
+
function defaultPart(part) {
|
|
859
|
+
if (part.type === "text") {
|
|
860
|
+
return /* @__PURE__ */ jsx3(MessageText, {});
|
|
861
|
+
}
|
|
862
|
+
if (part.type === "reasoning") {
|
|
863
|
+
return /* @__PURE__ */ jsx3(MessageReasoning, {});
|
|
864
|
+
}
|
|
865
|
+
if (part.type === "tool") {
|
|
866
|
+
return /* @__PURE__ */ jsx3(MessageTool, {});
|
|
867
|
+
}
|
|
868
|
+
if (part.type === "attachment") {
|
|
869
|
+
return /* @__PURE__ */ jsx3(MessageAttachment, {});
|
|
870
|
+
}
|
|
871
|
+
if (part.type === "data") {
|
|
872
|
+
return /* @__PURE__ */ jsx3(MessageData, {});
|
|
873
|
+
}
|
|
874
|
+
return /* @__PURE__ */ jsx3(MessageError, {});
|
|
875
|
+
}
|
|
876
|
+
function defaultToolContent() {
|
|
877
|
+
return /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
878
|
+
/* @__PURE__ */ jsx3(MessageToolName, {}),
|
|
879
|
+
/* @__PURE__ */ jsx3(MessageToolStatus, {}),
|
|
880
|
+
/* @__PURE__ */ jsx3(MessageToolInput, {}),
|
|
881
|
+
/* @__PURE__ */ jsx3(MessageToolOutput, {}),
|
|
882
|
+
/* @__PURE__ */ jsx3(MessageToolError, {})
|
|
883
|
+
] });
|
|
884
|
+
}
|
|
885
|
+
function defaultCodeComponent({
|
|
886
|
+
children,
|
|
887
|
+
className,
|
|
888
|
+
node: _node,
|
|
889
|
+
...props
|
|
890
|
+
}) {
|
|
891
|
+
const language = /language-(\S+)/.exec(className ?? "")?.[1];
|
|
892
|
+
return /* @__PURE__ */ jsx3(
|
|
893
|
+
"code",
|
|
894
|
+
{
|
|
895
|
+
className,
|
|
896
|
+
"data-anvia-code": "",
|
|
897
|
+
"data-anvia-inline-code": language === void 0 ? "" : void 0,
|
|
898
|
+
"data-language": language,
|
|
899
|
+
...props,
|
|
900
|
+
children
|
|
901
|
+
}
|
|
902
|
+
);
|
|
903
|
+
}
|
|
904
|
+
function defaultPreComponent({
|
|
905
|
+
children,
|
|
906
|
+
node: _node,
|
|
907
|
+
...props
|
|
908
|
+
}) {
|
|
909
|
+
return /* @__PURE__ */ jsx3(MessageCodeBlock, { ...props, children });
|
|
910
|
+
}
|
|
911
|
+
function shouldRenderTool(part, renderWhen) {
|
|
912
|
+
if (renderWhen === "always") {
|
|
913
|
+
return true;
|
|
914
|
+
}
|
|
915
|
+
if (renderWhen === "pending") {
|
|
916
|
+
return part.state === "input-streaming" || part.state === "input-available";
|
|
917
|
+
}
|
|
918
|
+
return part.state === "output-available" || part.state === "error";
|
|
919
|
+
}
|
|
920
|
+
function toolStateLabel(state) {
|
|
921
|
+
if (state === "output-available") {
|
|
922
|
+
return "Done";
|
|
923
|
+
}
|
|
924
|
+
if (state === "error") {
|
|
925
|
+
return "Error";
|
|
926
|
+
}
|
|
927
|
+
return "Running";
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
// src/message/root.tsx
|
|
931
|
+
import { forwardRef as forwardRef4 } from "react";
|
|
932
|
+
var MessageRoot = forwardRef4(function MessageRoot2({ children, ...props }, ref) {
|
|
933
|
+
const { message } = useMessage();
|
|
934
|
+
const renderedChildren = typeof children === "function" ? children(message) : children;
|
|
935
|
+
return renderPrimitive(
|
|
936
|
+
"article",
|
|
937
|
+
{
|
|
938
|
+
...props,
|
|
939
|
+
children: renderedChildren,
|
|
940
|
+
"data-anvia-message": "",
|
|
941
|
+
"data-anvia-message-id": message.id,
|
|
942
|
+
"data-role": message.role
|
|
943
|
+
},
|
|
944
|
+
ref
|
|
945
|
+
);
|
|
946
|
+
});
|
|
947
|
+
var MessageContent = forwardRef4(
|
|
948
|
+
function MessageContent2(props, ref) {
|
|
949
|
+
return renderPrimitive(
|
|
950
|
+
"div",
|
|
951
|
+
{
|
|
952
|
+
...props,
|
|
953
|
+
"data-anvia-message-content": ""
|
|
954
|
+
},
|
|
955
|
+
ref
|
|
956
|
+
);
|
|
957
|
+
}
|
|
958
|
+
);
|
|
959
|
+
|
|
960
|
+
// src/message/index.ts
|
|
961
|
+
var Message = {
|
|
962
|
+
Root: MessageRoot,
|
|
963
|
+
Content: MessageContent,
|
|
964
|
+
Parts: MessageParts,
|
|
965
|
+
Part: MessagePart,
|
|
966
|
+
Text: MessageText,
|
|
967
|
+
Markdown: MessageMarkdown,
|
|
968
|
+
Entity: MessageEntity,
|
|
969
|
+
CodeBlock: MessageCodeBlock,
|
|
970
|
+
Reasoning: MessageReasoning,
|
|
971
|
+
Tool: MessageTool,
|
|
972
|
+
ToolName: MessageToolName,
|
|
973
|
+
ToolInput: MessageToolInput,
|
|
974
|
+
ToolOutput: MessageToolOutput,
|
|
975
|
+
ToolError: MessageToolError,
|
|
976
|
+
ToolStatus: MessageToolStatus,
|
|
977
|
+
Attachment: MessageAttachment,
|
|
978
|
+
Data: MessageData,
|
|
979
|
+
Error: MessageError,
|
|
980
|
+
Actions: MessageActions,
|
|
981
|
+
Copy: MessageCopy,
|
|
982
|
+
Regenerate: MessageRegenerate
|
|
983
|
+
};
|
|
984
|
+
|
|
985
|
+
export {
|
|
986
|
+
shiftComposerEntityRanges,
|
|
987
|
+
Message
|
|
988
|
+
};
|
|
989
|
+
//# sourceMappingURL=chunk-YUK4ASXB.js.map
|