@locusgraph/loop 0.1.0 → 0.2.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/README.md +2 -0
- package/dist/agent/pulse/gradient-label.js +36 -15
- package/dist/agent/pulse/marks/bars-mark.js +24 -10
- package/dist/agent/pulse/marks/glyph-mark.js +17 -11
- package/dist/agent/pulse/marks/locus-mark.js +39 -28
- package/dist/agent/pulse/marks/orb-mark.js +21 -8
- package/dist/agent/pulse/marks/spinner-mark.js +20 -1
- package/dist/agent/pulse/pulse.js +63 -35
- package/dist/agent/pulse/use-loop-animation.js +14 -16
- package/dist/agent/steps/step-icon.js +40 -24
- package/dist/agent/steps/steps.js +72 -25
- package/dist/agent/thinking/thinking.js +203 -23
- package/dist/agent/thinking/thought-duration.js +7 -9
- package/dist/agent/tool/json-block.js +18 -11
- package/dist/agent/tool/tool-status.js +28 -18
- package/dist/agent/tool/tool.js +184 -6
- package/dist/approval/inbox/inbox-row.d.ts +3 -2
- package/dist/approval/inbox/inbox-row.js +96 -7
- package/dist/approval/inbox/inbox-selection.js +7 -13
- package/dist/approval/inbox/inbox.d.ts +2 -1
- package/dist/approval/inbox/inbox.js +99 -18
- package/dist/approval/inbox/virtual-inbox-list.d.ts +13 -0
- package/dist/approval/inbox/virtual-inbox-list.js +53 -0
- package/dist/approval/memory/memory-choices.js +27 -22
- package/dist/approval/memory/memory-review.js +108 -17
- package/dist/approval/memory/memory-row.js +80 -19
- package/dist/approval/plan/plan-review.js +129 -28
- package/dist/approval/plan/plan-step-row.js +91 -44
- package/dist/approval/plan/plan-steps.js +24 -23
- package/dist/approval/plan/question-choices.js +73 -40
- package/dist/approval/plan/question.d.ts +1 -1
- package/dist/approval/plan/question.js +108 -27
- package/dist/approval/run/run-bar.js +94 -22
- package/dist/approval/shared/decision-line.js +1 -1
- package/dist/approval/shared/risk-badge.js +32 -16
- package/dist/approval/shared/time.js +5 -8
- package/dist/approval/shared/use-focus-on-mount.js +7 -6
- package/dist/approval/spend/raise-cap-form.js +64 -19
- package/dist/approval/spend/spend-gate.js +124 -21
- package/dist/approval/spend/spend-math.js +7 -8
- package/dist/approval/spend/spend-meter.js +136 -35
- package/dist/approval/tool/approval.js +113 -27
- package/dist/approval/tool/args/args-editor.js +104 -26
- package/dist/approval/tool/args/args-field.js +79 -22
- package/dist/approval/tool/args/args-validation.js +38 -47
- package/dist/approval/tool/deny-form.js +43 -10
- package/dist/approval/tool/tool-inputs.js +62 -38
- package/dist/chat/chat/chat-item-spacing.d.ts +3 -0
- package/dist/chat/chat/chat-item-spacing.js +19 -0
- package/dist/chat/chat/chat.d.ts +2 -1
- package/dist/chat/chat/chat.js +181 -5
- package/dist/chat/chat/use-stick-to-bottom.js +71 -48
- package/dist/chat/chat/virtual-chat-items.d.ts +8 -0
- package/dist/chat/chat/virtual-chat-items.js +60 -0
- package/dist/chat/composer/composer-actions.js +69 -17
- package/dist/chat/composer/composer.js +330 -32
- package/dist/chat/composer/use-auto-grow.js +9 -9
- package/dist/chat/files/file-meta.js +19 -19
- package/dist/chat/files/files.js +92 -29
- package/dist/chat/reply/fenced-code.js +23 -21
- package/dist/chat/reply/markdown-components.js +137 -17
- package/dist/chat/reply/reply.js +30 -10
- package/dist/chat/turn/group-parts.js +43 -29
- package/dist/chat/turn/turn.js +87 -30
- package/dist/cost/context.js +104 -23
- package/dist/cost/cost-steps.js +67 -14
- package/dist/cost/cost.js +128 -23
- package/dist/cost/model-picker.js +51 -6
- package/dist/cost/shared/context-breakdown.js +83 -10
- package/dist/cost/shared/meter-marks.js +49 -9
- package/dist/cost/shared/model-option-row.js +56 -22
- package/dist/cost/shared/step-cost-row.js +65 -22
- package/dist/cost/shared/usage-totals.js +22 -18
- package/dist/memory/cite.js +62 -12
- package/dist/memory/memorized.js +65 -11
- package/dist/memory/recall.js +101 -17
- package/dist/memory/shared/host-label.js +19 -22
- package/dist/memory/shared/source-mark.js +11 -3
- package/dist/memory/sources.js +78 -14
- package/dist/shared/decision-summary.js +51 -14
- package/dist/shared/panel-empty.js +20 -3
- package/dist/shared/panel.js +69 -13
- package/dist/shared/status-dot.js +16 -8
- package/dist/shared/virtual/use-list-virtualizer.d.ts +24 -0
- package/dist/shared/virtual/use-list-virtualizer.js +68 -0
- package/dist/thread/actions/action-button.js +22 -3
- package/dist/thread/actions/actions.js +184 -13
- package/dist/thread/actions/branch-switcher.js +28 -5
- package/dist/thread/canvas/canvas.js +205 -5
- package/dist/thread/canvas/version-switcher.js +54 -8
- package/dist/thread/code/code.js +186 -24
- package/dist/thread/code/copy-code-button.js +30 -14
- package/dist/thread/code/highlight.js +30 -29
- package/dist/thread/history/history-rows.d.ts +16 -0
- package/dist/thread/history/history-rows.js +23 -0
- package/dist/thread/history/history.d.ts +3 -2
- package/dist/thread/history/history.js +174 -5
- package/dist/thread/history/{history-row.d.ts → row/history-row.d.ts} +3 -2
- package/dist/thread/history/row/history-row.js +58 -0
- package/dist/thread/history/row/thread-item-menu.js +31 -0
- package/dist/thread/history/row/thread-title-editor.js +38 -0
- package/dist/thread/history/thread-groups.d.ts +1 -1
- package/dist/thread/history/thread-groups.js +40 -34
- package/dist/thread/history/virtual-history-list.d.ts +11 -0
- package/dist/thread/history/virtual-history-list.js +71 -0
- package/dist/thread/index.d.ts +1 -1
- package/dist/thread/starters/starters.js +33 -8
- package/dist/thread/use-copied.js +18 -16
- package/dist/types.js +1 -1
- package/package.json +6 -4
- package/dist/thread/history/history-row.js +0 -17
- package/dist/thread/history/thread-item-menu.js +0 -6
- package/dist/thread/history/thread-title-editor.js +0 -25
- /package/dist/thread/history/{thread-item-menu.d.ts → row/thread-item-menu.d.ts} +0 -0
- /package/dist/thread/history/{thread-title-editor.d.ts → row/thread-title-editor.d.ts} +0 -0
package/dist/chat/files/files.js
CHANGED
|
@@ -1,39 +1,102 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Code as FileCodeIcon, DocumentBlank as FileIcon, DataTable as FileSpreadsheetIcon, Document as FileTextIcon, Close as XIcon, } from "@carbon/icons-react";
|
|
1
|
+
import { Code as FileCodeIcon, DocumentBlank as FileIcon, DataTable as FileSpreadsheetIcon, Document as FileTextIcon, Close as XIcon } from "@carbon/icons-react";
|
|
3
2
|
import { cn } from "@locusgraph/components";
|
|
4
3
|
import { fileExtensionLabel, formatBytes, isImageFile } from "./file-meta.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
[/json|javascript|typescript|xml|x-python/, FileCodeIcon],
|
|
8
|
-
[/text|pdf|markdown|word/, FileTextIcon],
|
|
9
|
-
];
|
|
4
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
5
|
+
const iconsByMediaType = [[/csv|spreadsheet|excel/, FileSpreadsheetIcon], [/json|javascript|typescript|xml|x-python/, FileCodeIcon], [/text|pdf|markdown|word/, FileTextIcon]];
|
|
10
6
|
function iconForMediaType(mediaType) {
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
const match = iconsByMediaType.find(([pattern]) => mediaType && pattern.test(mediaType));
|
|
8
|
+
return match ? match[1] : FileIcon;
|
|
13
9
|
}
|
|
14
10
|
function describeFile(item) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
];
|
|
19
|
-
const description = parts.filter(Boolean).join(" · ");
|
|
20
|
-
return description || undefined;
|
|
11
|
+
const parts = [fileExtensionLabel(item), item.sizeBytes === undefined ? undefined : formatBytes(item.sizeBytes)];
|
|
12
|
+
const description = parts.filter(Boolean).join(" · ");
|
|
13
|
+
return description || undefined;
|
|
21
14
|
}
|
|
22
|
-
function FilePreview({
|
|
23
|
-
|
|
24
|
-
|
|
15
|
+
function FilePreview({
|
|
16
|
+
item,
|
|
17
|
+
isGrid
|
|
18
|
+
}) {
|
|
19
|
+
const Icon = iconForMediaType(item.mediaType);
|
|
20
|
+
return /*#__PURE__*/_jsx("span", {
|
|
21
|
+
"data-slot": "files-preview",
|
|
22
|
+
className: cn("grid shrink-0 place-items-center overflow-hidden bg-muted text-muted-foreground", isGrid ? "aspect-[16/10] w-full" : "size-10"),
|
|
23
|
+
children: isImageFile(item) ? /*#__PURE__*/_jsx("img", {
|
|
24
|
+
src: item.url,
|
|
25
|
+
alt: "",
|
|
26
|
+
loading: "lazy",
|
|
27
|
+
className: "size-full object-cover"
|
|
28
|
+
}) : /*#__PURE__*/_jsx(Icon, {
|
|
29
|
+
"aria-hidden": "true",
|
|
30
|
+
className: isGrid ? "size-6" : "size-4"
|
|
31
|
+
})
|
|
32
|
+
});
|
|
25
33
|
}
|
|
26
|
-
function RemoveButton({
|
|
27
|
-
|
|
34
|
+
function RemoveButton({
|
|
35
|
+
item,
|
|
36
|
+
isGrid,
|
|
37
|
+
onRemove
|
|
38
|
+
}) {
|
|
39
|
+
return /*#__PURE__*/_jsx("button", {
|
|
40
|
+
type: "button",
|
|
41
|
+
"aria-label": `Remove ${item.name}`,
|
|
42
|
+
onClick: () => onRemove(item.id),
|
|
43
|
+
className: cn("grid size-6 shrink-0 place-items-center text-muted-foreground outline-none transition-colors hover:bg-accent hover:text-foreground focus-visible:ring-1 focus-visible:ring-ring", isGrid && "absolute top-1 right-1 bg-card/90"),
|
|
44
|
+
children: /*#__PURE__*/_jsx(XIcon, {
|
|
45
|
+
"aria-hidden": "true",
|
|
46
|
+
className: "size-3.5"
|
|
47
|
+
})
|
|
48
|
+
});
|
|
28
49
|
}
|
|
29
|
-
function FileChip({
|
|
30
|
-
|
|
31
|
-
|
|
50
|
+
function FileChip({
|
|
51
|
+
item,
|
|
52
|
+
isGrid,
|
|
53
|
+
onRemove
|
|
54
|
+
}) {
|
|
55
|
+
const description = describeFile(item);
|
|
56
|
+
return /*#__PURE__*/_jsxs("li", {
|
|
57
|
+
"data-slot": "files-item",
|
|
58
|
+
className: cn("relative flex min-w-0 bg-card text-card-foreground ring-1 ring-border", isGrid ? "flex-col" : "w-60 max-w-full items-center gap-2.5 pr-1", !isGrid && !onRemove && "pr-3"),
|
|
59
|
+
children: [/*#__PURE__*/_jsx(FilePreview, {
|
|
60
|
+
item: item,
|
|
61
|
+
isGrid: isGrid
|
|
62
|
+
}), /*#__PURE__*/_jsxs("span", {
|
|
63
|
+
className: cn("flex min-w-0 flex-1 flex-col gap-0.5", isGrid && "px-2.5 py-2"),
|
|
64
|
+
children: [/*#__PURE__*/_jsx("span", {
|
|
65
|
+
title: item.name,
|
|
66
|
+
className: "truncate text-xs leading-tight font-medium",
|
|
67
|
+
children: item.name
|
|
68
|
+
}), description && /*#__PURE__*/_jsx("span", {
|
|
69
|
+
className: "truncate font-mono text-xs leading-tight text-muted-foreground tabular-nums",
|
|
70
|
+
children: description
|
|
71
|
+
})]
|
|
72
|
+
}), onRemove && /*#__PURE__*/_jsx(RemoveButton, {
|
|
73
|
+
item: item,
|
|
74
|
+
isGrid: isGrid,
|
|
75
|
+
onRemove: onRemove
|
|
76
|
+
})]
|
|
77
|
+
});
|
|
32
78
|
}
|
|
33
|
-
export function Files({
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
79
|
+
export function Files({
|
|
80
|
+
items,
|
|
81
|
+
layout = "inline",
|
|
82
|
+
onRemove,
|
|
83
|
+
className,
|
|
84
|
+
...props
|
|
85
|
+
}) {
|
|
86
|
+
if (items.length === 0) {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
const isGrid = layout === "grid";
|
|
90
|
+
return /*#__PURE__*/_jsx("ul", {
|
|
91
|
+
"data-slot": "files",
|
|
92
|
+
"data-layout": layout,
|
|
93
|
+
"aria-label": "Files",
|
|
94
|
+
className: cn(isGrid ? "grid grid-cols-2 gap-2 sm:grid-cols-3" : "flex flex-wrap gap-2", className),
|
|
95
|
+
...props,
|
|
96
|
+
children: items.map(item => /*#__PURE__*/_jsx(FileChip, {
|
|
97
|
+
item: item,
|
|
98
|
+
isGrid: isGrid,
|
|
99
|
+
onRemove: onRemove
|
|
100
|
+
}, item.id))
|
|
101
|
+
});
|
|
39
102
|
}
|
|
@@ -1,29 +1,31 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
1
|
import { Code } from "../../thread/code/code.js";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
function textOf(child) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return child.children.map(textOf).join("");
|
|
8
|
-
return "";
|
|
4
|
+
if (child.type === "text") return child.value;
|
|
5
|
+
if (child.type === "element") return child.children.map(textOf).join("");
|
|
6
|
+
return "";
|
|
9
7
|
}
|
|
10
8
|
function languageOf(className) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
const classes = Array.isArray(className) ? className.map(String) : [];
|
|
10
|
+
const language = classes.find(value => value.startsWith("language-"));
|
|
11
|
+
return language ? language.slice("language-".length) : "text";
|
|
14
12
|
}
|
|
15
13
|
export function fencedCode(node) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
};
|
|
14
|
+
const code = node?.children.find(child => child.type === "element" && child.tagName === "code");
|
|
15
|
+
if (!code) return null;
|
|
16
|
+
return {
|
|
17
|
+
code: code.children.map(textOf).join("").replace(/\n$/, ""),
|
|
18
|
+
language: languageOf(code.properties.className)
|
|
19
|
+
};
|
|
23
20
|
}
|
|
24
|
-
export function FencedCode({
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
21
|
+
export function FencedCode({
|
|
22
|
+
node
|
|
23
|
+
}) {
|
|
24
|
+
const fenced = fencedCode(node);
|
|
25
|
+
if (!fenced) return null;
|
|
26
|
+
return /*#__PURE__*/_jsx(Code, {
|
|
27
|
+
code: fenced.code,
|
|
28
|
+
language: fenced.language,
|
|
29
|
+
className: "mt-4 first:mt-0"
|
|
30
|
+
});
|
|
29
31
|
}
|
|
@@ -1,22 +1,142 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
1
|
import { cn } from "@locusgraph/components";
|
|
3
2
|
import { FencedCode, fencedCode } from "./fenced-code.js";
|
|
3
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
4
|
const blockGap = "mt-4 first:mt-0";
|
|
5
5
|
export const markdownComponents = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
6
|
+
p: ({
|
|
7
|
+
node: _node,
|
|
8
|
+
className,
|
|
9
|
+
...props
|
|
10
|
+
}) => /*#__PURE__*/_jsx("p", {
|
|
11
|
+
className: cn("leading-relaxed text-pretty [&:not(:first-child)]:mt-3", className),
|
|
12
|
+
...props
|
|
13
|
+
}),
|
|
14
|
+
a: ({
|
|
15
|
+
node: _node,
|
|
16
|
+
className,
|
|
17
|
+
...props
|
|
18
|
+
}) => /*#__PURE__*/_jsx("a", {
|
|
19
|
+
target: "_blank",
|
|
20
|
+
rel: "noopener noreferrer",
|
|
21
|
+
className: cn("font-medium text-foreground underline decoration-muted-foreground/50 underline-offset-3 transition-colors hover:decoration-foreground", className),
|
|
22
|
+
...props
|
|
23
|
+
}),
|
|
24
|
+
h1: ({
|
|
25
|
+
node: _node,
|
|
26
|
+
className,
|
|
27
|
+
...props
|
|
28
|
+
}) => /*#__PURE__*/_jsx("h1", {
|
|
29
|
+
className: cn("mt-7 mb-2 text-base font-semibold tracking-tight first:mt-0", className),
|
|
30
|
+
...props
|
|
31
|
+
}),
|
|
32
|
+
h2: ({
|
|
33
|
+
node: _node,
|
|
34
|
+
className,
|
|
35
|
+
...props
|
|
36
|
+
}) => /*#__PURE__*/_jsx("h2", {
|
|
37
|
+
className: cn("mt-6 mb-2 text-base font-semibold tracking-tight first:mt-0", className),
|
|
38
|
+
...props
|
|
39
|
+
}),
|
|
40
|
+
h3: ({
|
|
41
|
+
node: _node,
|
|
42
|
+
className,
|
|
43
|
+
...props
|
|
44
|
+
}) => /*#__PURE__*/_jsx("h3", {
|
|
45
|
+
className: cn("mt-5 mb-1.5 text-sm font-semibold first:mt-0", className),
|
|
46
|
+
...props
|
|
47
|
+
}),
|
|
48
|
+
h4: ({
|
|
49
|
+
node: _node,
|
|
50
|
+
className,
|
|
51
|
+
...props
|
|
52
|
+
}) => /*#__PURE__*/_jsx("h4", {
|
|
53
|
+
className: cn("eyebrow mt-5 mb-1.5 first:mt-0", className),
|
|
54
|
+
...props
|
|
55
|
+
}),
|
|
56
|
+
ul: ({
|
|
57
|
+
node: _node,
|
|
58
|
+
className,
|
|
59
|
+
...props
|
|
60
|
+
}) => /*#__PURE__*/_jsx("ul", {
|
|
61
|
+
className: cn("mt-3 list-disc space-y-1.5 pl-5 first:mt-0 [li_&]:mt-1.5", className),
|
|
62
|
+
...props
|
|
63
|
+
}),
|
|
64
|
+
ol: ({
|
|
65
|
+
node: _node,
|
|
66
|
+
className,
|
|
67
|
+
...props
|
|
68
|
+
}) => /*#__PURE__*/_jsx("ol", {
|
|
69
|
+
className: cn("mt-3 list-decimal space-y-1.5 pl-5 first:mt-0 marker:tabular-nums [li_&]:mt-1.5", className),
|
|
70
|
+
...props
|
|
71
|
+
}),
|
|
72
|
+
li: ({
|
|
73
|
+
node: _node,
|
|
74
|
+
className,
|
|
75
|
+
...props
|
|
76
|
+
}) => /*#__PURE__*/_jsx("li", {
|
|
77
|
+
className: cn("pl-1 leading-relaxed marker:text-muted-foreground [&>p]:mt-0", className),
|
|
78
|
+
...props
|
|
79
|
+
}),
|
|
80
|
+
blockquote: ({
|
|
81
|
+
node: _node,
|
|
82
|
+
className,
|
|
83
|
+
...props
|
|
84
|
+
}) => /*#__PURE__*/_jsx("blockquote", {
|
|
85
|
+
className: cn("border-l-2 border-border pl-4 text-muted-foreground", blockGap, className),
|
|
86
|
+
...props
|
|
87
|
+
}),
|
|
88
|
+
hr: ({
|
|
89
|
+
node: _node,
|
|
90
|
+
className,
|
|
91
|
+
...props
|
|
92
|
+
}) => /*#__PURE__*/_jsx("hr", {
|
|
93
|
+
className: cn("my-6 border-border", className),
|
|
94
|
+
...props
|
|
95
|
+
}),
|
|
96
|
+
pre: ({
|
|
97
|
+
node,
|
|
98
|
+
className,
|
|
99
|
+
...props
|
|
100
|
+
}) => fencedCode(node) ? /*#__PURE__*/_jsx(FencedCode, {
|
|
101
|
+
node: node
|
|
102
|
+
}) : /*#__PURE__*/_jsx("pre", {
|
|
103
|
+
className: cn("overflow-x-auto bg-muted/40 p-3 font-mono text-xs leading-relaxed", blockGap, className),
|
|
104
|
+
...props
|
|
105
|
+
}),
|
|
106
|
+
code: ({
|
|
107
|
+
node: _node,
|
|
108
|
+
className,
|
|
109
|
+
...props
|
|
110
|
+
}) => /*#__PURE__*/_jsx("code", {
|
|
111
|
+
className: cn("bg-muted px-1.5 py-0.5 font-mono text-[0.85em] text-foreground [pre_&]:bg-transparent [pre_&]:p-0", className),
|
|
112
|
+
...props
|
|
113
|
+
}),
|
|
114
|
+
table: ({
|
|
115
|
+
node: _node,
|
|
116
|
+
className,
|
|
117
|
+
...props
|
|
118
|
+
}) => /*#__PURE__*/_jsx("div", {
|
|
119
|
+
"data-slot": "reply-table",
|
|
120
|
+
className: cn("overflow-x-auto ring-1 ring-border", blockGap),
|
|
121
|
+
children: /*#__PURE__*/_jsx("table", {
|
|
122
|
+
className: cn("w-full border-collapse text-sm [&_td:not(:first-child)]:tabular-nums", className),
|
|
123
|
+
...props
|
|
124
|
+
})
|
|
125
|
+
}),
|
|
126
|
+
th: ({
|
|
127
|
+
node: _node,
|
|
128
|
+
className,
|
|
129
|
+
...props
|
|
130
|
+
}) => /*#__PURE__*/_jsx("th", {
|
|
131
|
+
className: cn("eyebrow border-b bg-muted/30 px-3 py-2 text-left font-normal", className),
|
|
132
|
+
...props
|
|
133
|
+
}),
|
|
134
|
+
td: ({
|
|
135
|
+
node: _node,
|
|
136
|
+
className,
|
|
137
|
+
...props
|
|
138
|
+
}) => /*#__PURE__*/_jsx("td", {
|
|
139
|
+
className: cn("border-b px-3 py-2 align-top [tr:last-child_&]:border-b-0", className),
|
|
140
|
+
...props
|
|
141
|
+
})
|
|
22
142
|
};
|
package/dist/chat/reply/reply.js
CHANGED
|
@@ -1,21 +1,41 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
1
|
import { cn } from "@locusgraph/components";
|
|
3
2
|
import { memo } from "react";
|
|
4
3
|
import ReactMarkdown from "react-markdown";
|
|
5
4
|
import remarkGfm from "remark-gfm";
|
|
6
5
|
import { markdownComponents } from "./markdown-components.js";
|
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
7
|
const codeFence = /^ {0,3}(```|~~~)/gm;
|
|
8
8
|
export function closeOpenCodeFence(markdown) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
const fences = markdown.match(codeFence) ?? [];
|
|
10
|
+
const lastFence = fences.at(-1)?.trim().slice(0, 3);
|
|
11
|
+
return fences.length % 2 === 1 ? `${markdown}\n${lastFence}` : markdown;
|
|
12
12
|
}
|
|
13
|
-
const Markdown = memo(function Markdown({
|
|
14
|
-
|
|
13
|
+
const Markdown = memo(function Markdown({
|
|
14
|
+
markdown
|
|
15
|
+
}) {
|
|
16
|
+
return /*#__PURE__*/_jsx(ReactMarkdown, {
|
|
17
|
+
remarkPlugins: [remarkGfm],
|
|
18
|
+
components: markdownComponents,
|
|
19
|
+
children: markdown
|
|
20
|
+
});
|
|
15
21
|
});
|
|
16
22
|
const streamingCaret = "data-[state=streaming]:[&>:last-child]:after:ml-0.5 data-[state=streaming]:[&>:last-child]:after:inline-block data-[state=streaming]:[&>:last-child]:after:h-[1em] data-[state=streaming]:[&>:last-child]:after:w-[0.5ch] data-[state=streaming]:[&>:last-child]:after:translate-y-[0.15em] data-[state=streaming]:[&>:last-child]:after:bg-foreground/70 data-[state=streaming]:[&>:last-child]:after:content-[''] motion-safe:data-[state=streaming]:[&>:last-child]:after:animate-pulse";
|
|
17
|
-
export function Reply({
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
23
|
+
export function Reply({
|
|
24
|
+
children,
|
|
25
|
+
state = "done",
|
|
26
|
+
className,
|
|
27
|
+
...props
|
|
28
|
+
}) {
|
|
29
|
+
const isStreaming = state === "streaming";
|
|
30
|
+
const markdown = isStreaming ? closeOpenCodeFence(children) : children;
|
|
31
|
+
return /*#__PURE__*/_jsx("div", {
|
|
32
|
+
"data-slot": "reply",
|
|
33
|
+
"data-state": state,
|
|
34
|
+
"aria-live": isStreaming ? "polite" : undefined,
|
|
35
|
+
className: cn("min-w-0 text-sm leading-relaxed wrap-break-word text-foreground", streamingCaret, className),
|
|
36
|
+
...props,
|
|
37
|
+
children: /*#__PURE__*/_jsx(Markdown, {
|
|
38
|
+
markdown: markdown
|
|
39
|
+
})
|
|
40
|
+
});
|
|
21
41
|
}
|
|
@@ -1,35 +1,49 @@
|
|
|
1
1
|
export function isToolPart(part) {
|
|
2
|
-
|
|
2
|
+
return part.type === "dynamic-tool" || part.type.startsWith("tool-");
|
|
3
3
|
}
|
|
4
4
|
function appendToRun(segments, kind, part, key) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
const previous = segments.at(-1);
|
|
6
|
+
if (previous?.kind === kind) {
|
|
7
|
+
previous.parts.push(part);
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
segments.push(kind === "files" ? {
|
|
11
|
+
kind,
|
|
12
|
+
key,
|
|
13
|
+
parts: [part]
|
|
14
|
+
} : {
|
|
15
|
+
kind,
|
|
16
|
+
key,
|
|
17
|
+
parts: [part]
|
|
18
|
+
});
|
|
13
19
|
}
|
|
14
20
|
export function groupParts(parts) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
21
|
+
const segments = [];
|
|
22
|
+
parts.forEach((part, index) => {
|
|
23
|
+
const key = `${part.type}:${index}`;
|
|
24
|
+
if (part.type === "text") {
|
|
25
|
+
segments.push({
|
|
26
|
+
kind: "text",
|
|
27
|
+
key,
|
|
28
|
+
part
|
|
29
|
+
});
|
|
30
|
+
} else if (part.type === "reasoning") {
|
|
31
|
+
segments.push({
|
|
32
|
+
kind: "reasoning",
|
|
33
|
+
key,
|
|
34
|
+
part
|
|
35
|
+
});
|
|
36
|
+
} else if (part.type === "file") {
|
|
37
|
+
appendToRun(segments, "files", part, key);
|
|
38
|
+
} else if (part.type === "source-url") {
|
|
39
|
+
appendToRun(segments, "sources", part, key);
|
|
40
|
+
} else if (isToolPart(part)) {
|
|
41
|
+
segments.push({
|
|
42
|
+
kind: "tool",
|
|
43
|
+
key: part.toolCallId,
|
|
44
|
+
part
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
return segments;
|
|
35
49
|
}
|
package/dist/chat/turn/turn.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { cn, MessageAvatar, MessageContent, MessageFooter, Message as MessageRow, } from "@locusgraph/components";
|
|
1
|
+
import { cn, MessageAvatar, MessageContent, MessageFooter, Message as MessageRow } from "@locusgraph/components";
|
|
3
2
|
import { Thinking } from "../../agent/thinking/thinking.js";
|
|
4
3
|
import { Tool } from "../../agent/tool/tool.js";
|
|
5
4
|
import { Sources } from "../../memory/sources.js";
|
|
@@ -7,39 +6,97 @@ import { fileFromFilePart } from "../files/file-meta.js";
|
|
|
7
6
|
import { Files } from "../files/files.js";
|
|
8
7
|
import { Reply } from "../reply/reply.js";
|
|
9
8
|
import { groupParts } from "./group-parts.js";
|
|
9
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
10
10
|
const roleLabels = {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
user: "You said",
|
|
12
|
+
assistant: "Assistant said",
|
|
13
|
+
system: "System note"
|
|
14
14
|
};
|
|
15
|
-
function UserText({
|
|
16
|
-
|
|
15
|
+
function UserText({
|
|
16
|
+
part
|
|
17
|
+
}) {
|
|
18
|
+
return /*#__PURE__*/_jsx("div", {
|
|
19
|
+
"data-slot": "message-user-text",
|
|
20
|
+
className: "max-w-[85%] bg-muted px-3.5 py-2 text-sm leading-relaxed whitespace-pre-wrap wrap-break-word text-foreground",
|
|
21
|
+
children: part.text
|
|
22
|
+
});
|
|
17
23
|
}
|
|
18
24
|
function partClassName(role, kind) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
if (role === "user") {
|
|
26
|
+
return "w-full items-end";
|
|
27
|
+
}
|
|
28
|
+
if (role === "system") {
|
|
29
|
+
return "border-l-2 border-border pl-3 *:data-[slot=reply]:text-xs *:data-[slot=reply]:text-muted-foreground";
|
|
30
|
+
}
|
|
31
|
+
return cn(kind === "text" && "*:data-[slot=reply]:max-w-[68ch]");
|
|
26
32
|
}
|
|
27
33
|
function renderSegment(segment, isUser, renderers) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
switch (segment.kind) {
|
|
35
|
+
case "text":
|
|
36
|
+
return isUser ? /*#__PURE__*/_jsx(UserText, {
|
|
37
|
+
part: segment.part
|
|
38
|
+
}) : /*#__PURE__*/_jsx(Reply, {
|
|
39
|
+
state: segment.part.state,
|
|
40
|
+
children: segment.part.text
|
|
41
|
+
});
|
|
42
|
+
case "reasoning":
|
|
43
|
+
return renderers.renderReasoning ? renderers.renderReasoning(segment.part) : /*#__PURE__*/_jsx(Thinking, {
|
|
44
|
+
text: segment.part.text,
|
|
45
|
+
state: segment.part.state,
|
|
46
|
+
durationMs: segment.part.durationMs
|
|
47
|
+
});
|
|
48
|
+
case "tool":
|
|
49
|
+
return renderers.renderTool ? renderers.renderTool(segment.part) : /*#__PURE__*/_jsx(Tool, {
|
|
50
|
+
part: segment.part
|
|
51
|
+
});
|
|
52
|
+
case "sources":
|
|
53
|
+
return renderers.renderSources ? renderers.renderSources(segment.parts) : /*#__PURE__*/_jsx(Sources, {
|
|
54
|
+
sources: segment.parts
|
|
55
|
+
});
|
|
56
|
+
case "files":
|
|
57
|
+
return /*#__PURE__*/_jsx(Files, {
|
|
58
|
+
items: segment.parts.map(fileFromFilePart),
|
|
59
|
+
className: cn(isUser && "justify-end")
|
|
60
|
+
});
|
|
61
|
+
}
|
|
40
62
|
}
|
|
41
|
-
export function Turn({
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
63
|
+
export function Turn({
|
|
64
|
+
message,
|
|
65
|
+
avatar,
|
|
66
|
+
footer,
|
|
67
|
+
renderReasoning,
|
|
68
|
+
renderTool,
|
|
69
|
+
renderSources,
|
|
70
|
+
className,
|
|
71
|
+
...props
|
|
72
|
+
}) {
|
|
73
|
+
const isUser = message.role === "user";
|
|
74
|
+
const renderers = {
|
|
75
|
+
renderReasoning,
|
|
76
|
+
renderTool,
|
|
77
|
+
renderSources
|
|
78
|
+
};
|
|
79
|
+
return /*#__PURE__*/_jsxs(MessageRow, {
|
|
80
|
+
"data-role": message.role,
|
|
81
|
+
align: isUser ? "end" : "start",
|
|
82
|
+
"aria-label": roleLabels[message.role],
|
|
83
|
+
role: "article",
|
|
84
|
+
className: cn("gap-3 data-[role=system]:text-muted-foreground", className),
|
|
85
|
+
...props,
|
|
86
|
+
children: [avatar && /*#__PURE__*/_jsx(MessageAvatar, {
|
|
87
|
+
className: "mt-0.5 self-start group-has-data-[slot=message-footer]/message:translate-y-0",
|
|
88
|
+
children: avatar
|
|
89
|
+
}), /*#__PURE__*/_jsxs(MessageContent, {
|
|
90
|
+
className: cn("gap-4", isUser && "items-end gap-2"),
|
|
91
|
+
children: [groupParts(message.parts).map(segment => /*#__PURE__*/_jsx("div", {
|
|
92
|
+
"data-slot": "message-part",
|
|
93
|
+
"data-kind": segment.kind,
|
|
94
|
+
className: cn("flex min-w-0 flex-col", partClassName(message.role, segment.kind)),
|
|
95
|
+
children: renderSegment(segment, isUser, renderers)
|
|
96
|
+
}, segment.key)), footer && /*#__PURE__*/_jsx(MessageFooter, {
|
|
97
|
+
className: "px-0",
|
|
98
|
+
children: footer
|
|
99
|
+
})]
|
|
100
|
+
})]
|
|
101
|
+
});
|
|
45
102
|
}
|