@locusgraph/loop 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +35 -2
- package/dist/agent/index.d.ts +5 -0
- package/dist/agent/index.js +5 -0
- package/dist/agent/pulse/gradient-label.d.ts +7 -0
- package/dist/agent/pulse/gradient-label.js +23 -0
- package/dist/agent/pulse/marks/bars-mark.d.ts +1 -0
- package/dist/agent/pulse/marks/bars-mark.js +15 -0
- package/dist/agent/pulse/marks/glyph-mark.d.ts +4 -0
- package/dist/agent/pulse/marks/glyph-mark.js +17 -0
- package/dist/agent/pulse/marks/locus-mark.d.ts +1 -0
- package/dist/agent/pulse/marks/locus-mark.js +38 -0
- package/dist/agent/pulse/marks/orb-mark.d.ts +1 -0
- package/dist/agent/pulse/marks/orb-mark.js +11 -0
- package/dist/agent/pulse/marks/spinner-mark.d.ts +1 -0
- package/dist/agent/pulse/marks/spinner-mark.js +4 -0
- package/dist/agent/pulse/pulse-tone.d.ts +1 -0
- package/dist/agent/pulse/pulse-tone.js +1 -0
- package/dist/agent/pulse/pulse.d.ts +12 -0
- package/dist/agent/pulse/pulse.js +51 -0
- package/dist/agent/pulse/use-loop-animation.d.ts +2 -0
- package/dist/agent/pulse/use-loop-animation.js +21 -0
- package/dist/agent/shared/status-dot.d.ts +1 -0
- package/dist/agent/shared/status-dot.js +1 -0
- package/dist/agent/steps/step-icon.d.ts +8 -0
- package/dist/agent/steps/step-icon.js +31 -0
- package/dist/agent/steps/steps.d.ts +7 -0
- package/dist/agent/steps/steps.js +39 -0
- package/dist/agent/thinking/thinking.d.ts +6 -0
- package/dist/agent/thinking/thinking.js +31 -0
- package/dist/agent/thinking/thought-duration.d.ts +2 -0
- package/dist/agent/thinking/thought-duration.js +13 -0
- package/dist/agent/tool/json-block.d.ts +5 -0
- package/dist/agent/tool/json-block.js +15 -0
- package/dist/agent/tool/tool-status.d.ts +6 -0
- package/dist/agent/tool/tool-status.js +26 -0
- package/dist/agent/tool/tool.d.ts +7 -0
- package/dist/agent/tool/tool.js +14 -0
- package/dist/approval/inbox/inbox-row.d.ts +11 -0
- package/dist/approval/inbox/inbox-row.js +14 -0
- package/dist/approval/inbox/inbox-selection.d.ts +6 -0
- package/dist/approval/inbox/inbox-selection.js +21 -0
- package/dist/approval/inbox/inbox.d.ts +11 -0
- package/dist/approval/inbox/inbox.js +26 -0
- package/dist/approval/index.d.ts +9 -0
- package/dist/approval/index.js +8 -0
- package/dist/approval/memory/memory-choices.d.ts +10 -0
- package/dist/approval/memory/memory-choices.js +30 -0
- package/dist/approval/memory/memory-review.d.ts +11 -0
- package/dist/approval/memory/memory-review.js +31 -0
- package/dist/approval/memory/memory-row.d.ts +9 -0
- package/dist/approval/memory/memory-row.js +30 -0
- package/dist/approval/plan/plan-review.d.ts +13 -0
- package/dist/approval/plan/plan-review.js +38 -0
- package/dist/approval/plan/plan-step-row.d.ts +13 -0
- package/dist/approval/plan/plan-step-row.js +50 -0
- package/dist/approval/plan/plan-steps.d.ts +8 -0
- package/dist/approval/plan/plan-steps.js +29 -0
- package/dist/approval/plan/question-choices.d.ts +10 -0
- package/dist/approval/plan/question-choices.js +47 -0
- package/dist/approval/plan/question.d.ts +18 -0
- package/dist/approval/plan/question.js +35 -0
- package/dist/approval/run/run-bar.d.ts +13 -0
- package/dist/approval/run/run-bar.js +33 -0
- package/dist/approval/shared/decision-line.d.ts +1 -0
- package/dist/approval/shared/decision-line.js +1 -0
- package/dist/approval/shared/risk-badge.d.ts +10 -0
- package/dist/approval/shared/risk-badge.js +26 -0
- package/dist/approval/shared/time.d.ts +3 -0
- package/dist/approval/shared/time.js +15 -0
- package/dist/approval/shared/use-focus-on-mount.d.ts +2 -0
- package/dist/approval/shared/use-focus-on-mount.js +9 -0
- package/dist/approval/spend/raise-cap-form.d.ts +8 -0
- package/dist/approval/spend/raise-cap-form.js +26 -0
- package/dist/approval/spend/spend-gate.d.ts +16 -0
- package/dist/approval/spend/spend-gate.js +32 -0
- package/dist/approval/spend/spend-math.d.ts +5 -0
- package/dist/approval/spend/spend-math.js +18 -0
- package/dist/approval/spend/spend-meter.d.ts +10 -0
- package/dist/approval/spend/spend-meter.js +49 -0
- package/dist/approval/tool/approval.d.ts +14 -0
- package/dist/approval/tool/approval.js +45 -0
- package/dist/approval/tool/args/args-editor.d.ts +16 -0
- package/dist/approval/tool/args/args-editor.js +37 -0
- package/dist/approval/tool/args/args-field.d.ts +11 -0
- package/dist/approval/tool/args/args-field.js +28 -0
- package/dist/approval/tool/args/args-validation.d.ts +8 -0
- package/dist/approval/tool/args/args-validation.js +59 -0
- package/dist/approval/tool/deny-form.d.ts +6 -0
- package/dist/approval/tool/deny-form.js +15 -0
- package/dist/approval/tool/tool-inputs.d.ts +6 -0
- package/dist/approval/tool/tool-inputs.js +53 -0
- package/dist/approval/types.d.ts +59 -0
- package/dist/approval/types.js +1 -0
- package/dist/chat/chat/chat.d.ts +7 -0
- package/dist/chat/chat/chat.js +11 -0
- package/dist/chat/chat/use-stick-to-bottom.d.ts +7 -0
- package/dist/chat/chat/use-stick-to-bottom.js +57 -0
- package/dist/chat/composer/composer-actions.d.ts +15 -0
- package/dist/chat/composer/composer-actions.js +23 -0
- package/dist/chat/composer/composer.d.ts +20 -0
- package/dist/chat/composer/composer.js +42 -0
- package/dist/chat/composer/use-auto-grow.d.ts +2 -0
- package/dist/chat/composer/use-auto-grow.js +14 -0
- package/dist/chat/files/file-meta.d.ts +13 -0
- package/dist/chat/files/file-meta.js +30 -0
- package/dist/chat/files/files.d.ts +9 -0
- package/dist/chat/files/files.js +39 -0
- package/dist/chat/index.d.ts +7 -0
- package/dist/chat/index.js +7 -0
- package/dist/chat/reply/fenced-code.d.ts +8 -0
- package/dist/chat/reply/fenced-code.js +29 -0
- package/dist/chat/reply/markdown-components.d.ts +2 -0
- package/dist/chat/reply/markdown-components.js +22 -0
- package/dist/chat/reply/reply.d.ts +8 -0
- package/dist/chat/reply/reply.js +21 -0
- package/dist/chat/turn/group-parts.d.ts +24 -0
- package/dist/chat/turn/group-parts.js +35 -0
- package/dist/chat/turn/turn.d.ts +11 -0
- package/dist/chat/turn/turn.js +45 -0
- package/dist/cost/context.d.ts +13 -0
- package/dist/cost/context.js +35 -0
- package/dist/cost/cost-steps.d.ts +17 -0
- package/dist/cost/cost-steps.js +24 -0
- package/dist/cost/cost.d.ts +8 -0
- package/dist/cost/cost.js +37 -0
- package/dist/cost/index.d.ts +4 -0
- package/dist/cost/index.js +4 -0
- package/dist/cost/model-picker.d.ts +11 -0
- package/dist/cost/model-picker.js +9 -0
- package/dist/cost/shared/context-breakdown.d.ts +15 -0
- package/dist/cost/shared/context-breakdown.js +17 -0
- package/dist/cost/shared/meter-marks.d.ts +9 -0
- package/dist/cost/shared/meter-marks.js +16 -0
- package/dist/cost/shared/model-option-row.d.ts +14 -0
- package/dist/cost/shared/model-option-row.js +32 -0
- package/dist/cost/shared/step-cost-row.d.ts +15 -0
- package/dist/cost/shared/step-cost-row.js +34 -0
- package/dist/cost/shared/usage-totals.d.ts +11 -0
- package/dist/cost/shared/usage-totals.js +26 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +7 -0
- package/dist/memory/cite.d.ts +8 -0
- package/dist/memory/cite.js +19 -0
- package/dist/memory/index.d.ts +5 -0
- package/dist/memory/index.js +4 -0
- package/dist/memory/memorized.d.ts +14 -0
- package/dist/memory/memorized.js +19 -0
- package/dist/memory/recall.d.ts +9 -0
- package/dist/memory/recall.js +24 -0
- package/dist/memory/shared/disclosure.d.ts +6 -0
- package/dist/memory/shared/disclosure.js +6 -0
- package/dist/memory/shared/host-label.d.ts +6 -0
- package/dist/memory/shared/host-label.js +34 -0
- package/dist/memory/shared/source-mark.d.ts +5 -0
- package/dist/memory/shared/source-mark.js +6 -0
- package/dist/memory/sources.d.ts +9 -0
- package/dist/memory/sources.js +22 -0
- package/dist/shared/decision-summary.d.ts +18 -0
- package/dist/shared/decision-summary.js +25 -0
- package/dist/shared/panel-empty.d.ts +8 -0
- package/dist/shared/panel-empty.js +5 -0
- package/dist/shared/panel.d.ts +19 -0
- package/dist/shared/panel.js +21 -0
- package/dist/shared/status-dot.d.ts +6 -0
- package/dist/shared/status-dot.js +12 -0
- package/dist/sources.css +1 -0
- package/dist/thread/actions/action-button.d.ts +8 -0
- package/dist/thread/actions/action-button.js +5 -0
- package/dist/thread/actions/actions.d.ts +13 -0
- package/dist/thread/actions/actions.js +21 -0
- package/dist/thread/actions/branch-switcher.d.ts +10 -0
- package/dist/thread/actions/branch-switcher.js +7 -0
- package/dist/thread/canvas/canvas.d.ts +14 -0
- package/dist/thread/canvas/canvas.js +12 -0
- package/dist/thread/canvas/version-switcher.d.ts +12 -0
- package/dist/thread/canvas/version-switcher.js +11 -0
- package/dist/thread/code/code.d.ts +10 -0
- package/dist/thread/code/code.js +33 -0
- package/dist/thread/code/copy-code-button.d.ts +6 -0
- package/dist/thread/code/copy-code-button.js +18 -0
- package/dist/thread/code/highlight.d.ts +1 -0
- package/dist/thread/code/highlight.js +39 -0
- package/dist/thread/history/history-row.d.ts +14 -0
- package/dist/thread/history/history-row.js +17 -0
- package/dist/thread/history/history.d.ts +15 -0
- package/dist/thread/history/history.js +10 -0
- package/dist/thread/history/thread-groups.d.ts +8 -0
- package/dist/thread/history/thread-groups.js +46 -0
- package/dist/thread/history/thread-item-menu.d.ts +7 -0
- package/dist/thread/history/thread-item-menu.js +6 -0
- package/dist/thread/history/thread-title-editor.d.ts +7 -0
- package/dist/thread/history/thread-title-editor.js +25 -0
- package/dist/thread/index.d.ts +8 -0
- package/dist/thread/index.js +5 -0
- package/dist/thread/starters/starters.d.ts +12 -0
- package/dist/thread/starters/starters.js +15 -0
- package/dist/thread/use-copied.d.ts +5 -0
- package/dist/thread/use-copied.js +22 -0
- package/dist/types.d.ts +70 -0
- package/dist/types.js +3 -0
- package/package.json +57 -3
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
+
const bottomThresholdPx = 48;
|
|
3
|
+
function distanceFromBottom(element) {
|
|
4
|
+
return element.scrollHeight - element.scrollTop - element.clientHeight;
|
|
5
|
+
}
|
|
6
|
+
function prefersReducedMotion() {
|
|
7
|
+
return (typeof window !== "undefined" &&
|
|
8
|
+
window.matchMedia?.("(prefers-reduced-motion: reduce)").matches === true);
|
|
9
|
+
}
|
|
10
|
+
export function useStickToBottom() {
|
|
11
|
+
const viewportRef = useRef(null);
|
|
12
|
+
const contentRef = useRef(null);
|
|
13
|
+
const stuckRef = useRef(true);
|
|
14
|
+
const [isAtBottom, setIsAtBottom] = useState(true);
|
|
15
|
+
const pinToBottom = useCallback(() => {
|
|
16
|
+
const viewport = viewportRef.current;
|
|
17
|
+
if (viewport) {
|
|
18
|
+
viewport.scrollTop = viewport.scrollHeight;
|
|
19
|
+
}
|
|
20
|
+
}, []);
|
|
21
|
+
const handleScroll = useCallback(() => {
|
|
22
|
+
const viewport = viewportRef.current;
|
|
23
|
+
if (!viewport) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const atBottom = distanceFromBottom(viewport) <= bottomThresholdPx;
|
|
27
|
+
stuckRef.current = atBottom;
|
|
28
|
+
setIsAtBottom(atBottom);
|
|
29
|
+
}, []);
|
|
30
|
+
const scrollToLatest = useCallback(() => {
|
|
31
|
+
const viewport = viewportRef.current;
|
|
32
|
+
if (!viewport) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
stuckRef.current = true;
|
|
36
|
+
setIsAtBottom(true);
|
|
37
|
+
viewport.scrollTo({
|
|
38
|
+
top: viewport.scrollHeight,
|
|
39
|
+
behavior: prefersReducedMotion() ? "auto" : "smooth",
|
|
40
|
+
});
|
|
41
|
+
}, []);
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
const content = contentRef.current;
|
|
44
|
+
if (!content || typeof ResizeObserver === "undefined") {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
pinToBottom();
|
|
48
|
+
const observer = new ResizeObserver(() => {
|
|
49
|
+
if (stuckRef.current) {
|
|
50
|
+
pinToBottom();
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
observer.observe(content);
|
|
54
|
+
return () => observer.disconnect();
|
|
55
|
+
}, [pinToBottom]);
|
|
56
|
+
return { viewportRef, contentRef, isAtBottom, handleScroll, scrollToLatest };
|
|
57
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type ComposerStatus = "ready" | "submitting" | "streaming" | "error";
|
|
2
|
+
export declare function isComposerBusy(status: ComposerStatus): boolean;
|
|
3
|
+
type ComposerSubmitProps = {
|
|
4
|
+
status: ComposerStatus;
|
|
5
|
+
canSend: boolean;
|
|
6
|
+
onStop?: () => void;
|
|
7
|
+
};
|
|
8
|
+
export declare function ComposerSubmit({ status, canSend, onStop }: ComposerSubmitProps): import("react").JSX.Element;
|
|
9
|
+
type ComposerAttachButtonProps = {
|
|
10
|
+
accept?: string;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
onAttachFiles: (files: File[]) => void;
|
|
13
|
+
};
|
|
14
|
+
export declare function ComposerAttachButton({ accept, disabled, onAttachFiles, }: ComposerAttachButtonProps): import("react").JSX.Element;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ArrowUp as ArrowUpIcon, Attachment as PaperclipIcon, StopFilledAlt as SquareIcon, } from "@carbon/icons-react";
|
|
3
|
+
import { Button } from "@locusgraph/components";
|
|
4
|
+
import { useRef } from "react";
|
|
5
|
+
export function isComposerBusy(status) {
|
|
6
|
+
return status === "submitting" || status === "streaming";
|
|
7
|
+
}
|
|
8
|
+
export function ComposerSubmit({ status, canSend, onStop }) {
|
|
9
|
+
if (isComposerBusy(status)) {
|
|
10
|
+
return (_jsxs(Button, { type: "button", size: "sm", variant: "outline", "data-slot": "composer-stop", "aria-label": "Stop", disabled: !onStop, onClick: onStop, children: [_jsx(SquareIcon, { "aria-hidden": "true", className: "size-2.5 fill-current" }), "Stop"] }));
|
|
11
|
+
}
|
|
12
|
+
return (_jsx(Button, { type: "submit", size: "icon-sm", "data-slot": "composer-send", "aria-label": "Send", disabled: !canSend, children: _jsx(ArrowUpIcon, { "aria-hidden": "true" }) }));
|
|
13
|
+
}
|
|
14
|
+
export function ComposerAttachButton({ accept, disabled, onAttachFiles, }) {
|
|
15
|
+
const inputRef = useRef(null);
|
|
16
|
+
return (_jsxs(_Fragment, { children: [_jsx("input", { ref: inputRef, type: "file", multiple: true, hidden: true, accept: accept, tabIndex: -1, "aria-hidden": "true", onChange: (event) => {
|
|
17
|
+
const picked = Array.from(event.currentTarget.files ?? []);
|
|
18
|
+
event.currentTarget.value = "";
|
|
19
|
+
if (picked.length > 0) {
|
|
20
|
+
onAttachFiles(picked);
|
|
21
|
+
}
|
|
22
|
+
} }), _jsx(Button, { type: "button", size: "icon-sm", variant: "ghost", "data-slot": "composer-attach", "aria-label": "Attach files", className: "text-muted-foreground hover:text-foreground", disabled: disabled, onClick: () => inputRef.current?.click(), children: _jsx(PaperclipIcon, { "aria-hidden": "true" }) })] }));
|
|
23
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { type ComposerStatus } from "./composer-actions.js";
|
|
3
|
+
export type ComposerProps = Omit<React.ComponentProps<"form">, "onSubmit" | "children"> & {
|
|
4
|
+
onSubmit: (text: string, files: File[]) => void;
|
|
5
|
+
onStop?: () => void;
|
|
6
|
+
status?: ComposerStatus;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
value?: string;
|
|
9
|
+
defaultValue?: string;
|
|
10
|
+
onValueChange?: (value: string) => void;
|
|
11
|
+
placeholder?: string;
|
|
12
|
+
label?: string;
|
|
13
|
+
files?: File[];
|
|
14
|
+
onAttachFiles?: (files: File[]) => void;
|
|
15
|
+
accept?: string;
|
|
16
|
+
attachments?: React.ReactNode;
|
|
17
|
+
modelSlot?: React.ReactNode;
|
|
18
|
+
errorMessage?: string;
|
|
19
|
+
};
|
|
20
|
+
export declare function Composer({ onSubmit, onStop, status, disabled, value, defaultValue, onValueChange, placeholder, label, files, onAttachFiles, accept, attachments, modelSlot, errorMessage, className, ...props }: ComposerProps): React.JSX.Element;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { cn, Textarea } from "@locusgraph/components";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
import { ComposerAttachButton, ComposerSubmit, isComposerBusy, } from "./composer-actions.js";
|
|
6
|
+
import { useAutoGrow } from "./use-auto-grow.js";
|
|
7
|
+
const noFiles = [];
|
|
8
|
+
function isSendShortcut(event) {
|
|
9
|
+
return event.key === "Enter" && !event.shiftKey && !event.nativeEvent.isComposing;
|
|
10
|
+
}
|
|
11
|
+
export function Composer({ onSubmit, onStop, status = "ready", disabled = false, value, defaultValue = "", onValueChange, placeholder = "Ask the agent…", label = "Message", files = noFiles, onAttachFiles, accept, attachments, modelSlot, errorMessage, className, ...props }) {
|
|
12
|
+
const [uncontrolledText, setUncontrolledText] = React.useState(defaultValue);
|
|
13
|
+
const text = value ?? uncontrolledText;
|
|
14
|
+
const errorId = React.useId();
|
|
15
|
+
const textareaRef = React.useRef(null);
|
|
16
|
+
useAutoGrow(textareaRef, text);
|
|
17
|
+
const isBusy = isComposerBusy(status);
|
|
18
|
+
const canSend = !disabled && !isBusy && (text.trim().length > 0 || files.length > 0);
|
|
19
|
+
const changeText = (next) => {
|
|
20
|
+
if (value === undefined) {
|
|
21
|
+
setUncontrolledText(next);
|
|
22
|
+
}
|
|
23
|
+
onValueChange?.(next);
|
|
24
|
+
};
|
|
25
|
+
const send = () => {
|
|
26
|
+
if (!canSend) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
onSubmit(text.trim(), files);
|
|
30
|
+
changeText("");
|
|
31
|
+
};
|
|
32
|
+
const showError = status === "error" && errorMessage;
|
|
33
|
+
return (_jsxs("form", { "data-slot": "composer", "data-status": status, "data-disabled": disabled || undefined, "aria-busy": isBusy || undefined, className: cn("flex flex-col bg-card text-card-foreground ring-1 ring-border transition-shadow focus-within:ring-foreground/40 data-[status=error]:ring-destructive/60 data-disabled:opacity-60", className), onSubmit: (event) => {
|
|
34
|
+
event.preventDefault();
|
|
35
|
+
send();
|
|
36
|
+
}, ...props, children: [attachments && (_jsx("div", { "data-slot": "composer-attachments", className: "px-3 pt-3 empty:hidden", children: attachments })), _jsx(Textarea, { ref: textareaRef, "aria-label": label, "aria-invalid": status === "error" || undefined, "aria-describedby": showError ? errorId : undefined, placeholder: placeholder, disabled: disabled, value: text, rows: 1, onChange: (event) => changeText(event.currentTarget.value), onKeyDown: (event) => {
|
|
37
|
+
if (isSendShortcut(event)) {
|
|
38
|
+
event.preventDefault();
|
|
39
|
+
send();
|
|
40
|
+
}
|
|
41
|
+
}, className: "max-h-48 min-h-14 resize-none border-0 bg-transparent px-4 pt-3.5 pb-1 text-sm leading-relaxed shadow-none placeholder:text-muted-foreground/80 focus-visible:ring-0 dark:bg-transparent" }), showError && (_jsx("p", { id: errorId, role: "alert", className: "px-4 pt-1 text-xs text-destructive", children: errorMessage })), _jsxs("div", { "data-slot": "composer-toolbar", className: "flex items-center gap-1 px-2.5 pt-1 pb-2.5", children: [onAttachFiles && (_jsx(ComposerAttachButton, { accept: accept, disabled: disabled || isBusy, onAttachFiles: onAttachFiles })), modelSlot && (_jsx("div", { "data-slot": "composer-model", className: cn("min-w-0", disabled && "pointer-events-none opacity-50"), children: modelSlot })), _jsx("div", { className: "ml-auto", children: _jsx(ComposerSubmit, { status: status, canSend: canSend, onStop: onStop }) })] })] }));
|
|
42
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useLayoutEffect } from "react";
|
|
2
|
+
function supportsFieldSizing() {
|
|
3
|
+
return typeof CSS !== "undefined" && CSS.supports?.("field-sizing", "content") === true;
|
|
4
|
+
}
|
|
5
|
+
export function useAutoGrow(textareaRef, text) {
|
|
6
|
+
useLayoutEffect(() => {
|
|
7
|
+
const textarea = textareaRef.current;
|
|
8
|
+
if (!textarea || supportsFieldSizing() || text === undefined) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
textarea.style.height = "auto";
|
|
12
|
+
textarea.style.height = `${textarea.scrollHeight}px`;
|
|
13
|
+
}, [textareaRef, text]);
|
|
14
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { FilePart } from "../../types.js";
|
|
2
|
+
export type FileItem = {
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
mediaType?: string;
|
|
6
|
+
url?: string;
|
|
7
|
+
sizeBytes?: number;
|
|
8
|
+
};
|
|
9
|
+
export declare function formatBytes(bytes: number): string;
|
|
10
|
+
export declare function isImageFile(item: FileItem): boolean;
|
|
11
|
+
export declare function fileExtensionLabel(item: FileItem): string | undefined;
|
|
12
|
+
export declare function filenameFromUrl(url: string): string;
|
|
13
|
+
export declare function fileFromFilePart(part: FilePart, index: number): FileItem;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const byteUnits = ["B", "KB", "MB", "GB"];
|
|
2
|
+
export function formatBytes(bytes) {
|
|
3
|
+
let value = bytes;
|
|
4
|
+
let unitIndex = 0;
|
|
5
|
+
while (value >= 1024 && unitIndex < byteUnits.length - 1) {
|
|
6
|
+
value /= 1024;
|
|
7
|
+
unitIndex += 1;
|
|
8
|
+
}
|
|
9
|
+
const rounded = unitIndex === 0 || value >= 10 ? Math.round(value) : Math.round(value * 10) / 10;
|
|
10
|
+
return `${rounded} ${byteUnits[unitIndex]}`;
|
|
11
|
+
}
|
|
12
|
+
export function isImageFile(item) {
|
|
13
|
+
return Boolean(item.url && item.mediaType?.startsWith("image/"));
|
|
14
|
+
}
|
|
15
|
+
export function fileExtensionLabel(item) {
|
|
16
|
+
const extension = item.name.includes(".") ? item.name.split(".").at(-1) : undefined;
|
|
17
|
+
return extension ? extension.toUpperCase() : undefined;
|
|
18
|
+
}
|
|
19
|
+
export function filenameFromUrl(url) {
|
|
20
|
+
const lastSegment = url.split(/[?#]/)[0]?.split("/").at(-1);
|
|
21
|
+
return lastSegment && !url.startsWith("data:") ? decodeURIComponent(lastSegment) : "Attachment";
|
|
22
|
+
}
|
|
23
|
+
export function fileFromFilePart(part, index) {
|
|
24
|
+
return {
|
|
25
|
+
id: `${index}:${part.url.slice(0, 64)}`,
|
|
26
|
+
name: part.filename ?? filenameFromUrl(part.url),
|
|
27
|
+
mediaType: part.mediaType,
|
|
28
|
+
url: part.url,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type * as React from "react";
|
|
2
|
+
import { type FileItem } from "./file-meta.js";
|
|
3
|
+
export type FilesLayout = "inline" | "grid";
|
|
4
|
+
export type FilesProps = Omit<React.ComponentProps<"ul">, "children"> & {
|
|
5
|
+
items: FileItem[];
|
|
6
|
+
layout?: FilesLayout;
|
|
7
|
+
onRemove?: (id: string) => void;
|
|
8
|
+
};
|
|
9
|
+
export declare function Files({ items, layout, onRemove, className, ...props }: FilesProps): React.JSX.Element | null;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Code as FileCodeIcon, DocumentBlank as FileIcon, DataTable as FileSpreadsheetIcon, Document as FileTextIcon, Close as XIcon, } from "@carbon/icons-react";
|
|
3
|
+
import { cn } from "@locusgraph/components";
|
|
4
|
+
import { fileExtensionLabel, formatBytes, isImageFile } from "./file-meta.js";
|
|
5
|
+
const iconsByMediaType = [
|
|
6
|
+
[/csv|spreadsheet|excel/, FileSpreadsheetIcon],
|
|
7
|
+
[/json|javascript|typescript|xml|x-python/, FileCodeIcon],
|
|
8
|
+
[/text|pdf|markdown|word/, FileTextIcon],
|
|
9
|
+
];
|
|
10
|
+
function iconForMediaType(mediaType) {
|
|
11
|
+
const match = iconsByMediaType.find(([pattern]) => mediaType && pattern.test(mediaType));
|
|
12
|
+
return match ? match[1] : FileIcon;
|
|
13
|
+
}
|
|
14
|
+
function describeFile(item) {
|
|
15
|
+
const parts = [
|
|
16
|
+
fileExtensionLabel(item),
|
|
17
|
+
item.sizeBytes === undefined ? undefined : formatBytes(item.sizeBytes),
|
|
18
|
+
];
|
|
19
|
+
const description = parts.filter(Boolean).join(" · ");
|
|
20
|
+
return description || undefined;
|
|
21
|
+
}
|
|
22
|
+
function FilePreview({ item, isGrid }) {
|
|
23
|
+
const Icon = iconForMediaType(item.mediaType);
|
|
24
|
+
return (_jsx("span", { "data-slot": "files-preview", className: cn("grid shrink-0 place-items-center overflow-hidden bg-muted text-muted-foreground", isGrid ? "aspect-[16/10] w-full" : "size-10"), children: isImageFile(item) ? (_jsx("img", { src: item.url, alt: "", loading: "lazy", className: "size-full object-cover" })) : (_jsx(Icon, { "aria-hidden": "true", className: isGrid ? "size-6" : "size-4" })) }));
|
|
25
|
+
}
|
|
26
|
+
function RemoveButton({ item, isGrid, onRemove }) {
|
|
27
|
+
return (_jsx("button", { type: "button", "aria-label": `Remove ${item.name}`, onClick: () => onRemove(item.id), 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"), children: _jsx(XIcon, { "aria-hidden": "true", className: "size-3.5" }) }));
|
|
28
|
+
}
|
|
29
|
+
function FileChip({ item, isGrid, onRemove }) {
|
|
30
|
+
const description = describeFile(item);
|
|
31
|
+
return (_jsxs("li", { "data-slot": "files-item", 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"), children: [_jsx(FilePreview, { item: item, isGrid: isGrid }), _jsxs("span", { className: cn("flex min-w-0 flex-1 flex-col gap-0.5", isGrid && "px-2.5 py-2"), children: [_jsx("span", { title: item.name, className: "truncate text-xs leading-tight font-medium", children: item.name }), description && (_jsx("span", { className: "truncate font-mono text-xs leading-tight text-muted-foreground tabular-nums", children: description }))] }), onRemove && _jsx(RemoveButton, { item: item, isGrid: isGrid, onRemove: onRemove })] }));
|
|
32
|
+
}
|
|
33
|
+
export function Files({ items, layout = "inline", onRemove, className, ...props }) {
|
|
34
|
+
if (items.length === 0) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
const isGrid = layout === "grid";
|
|
38
|
+
return (_jsx("ul", { "data-slot": "files", "data-layout": layout, "aria-label": "Files", className: cn(isGrid ? "grid grid-cols-2 gap-2 sm:grid-cols-3" : "flex flex-wrap gap-2", className), ...props, children: items.map((item) => (_jsx(FileChip, { item: item, isGrid: isGrid, onRemove: onRemove }, item.id))) }));
|
|
39
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from "./chat/chat.js";
|
|
2
|
+
export * from "./composer/composer.js";
|
|
3
|
+
export { type ComposerStatus, isComposerBusy } from "./composer/composer-actions.js";
|
|
4
|
+
export { type FileItem, fileFromFilePart, formatBytes } from "./files/file-meta.js";
|
|
5
|
+
export * from "./files/files.js";
|
|
6
|
+
export * from "./reply/reply.js";
|
|
7
|
+
export * from "./turn/turn.js";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from "./chat/chat.js";
|
|
2
|
+
export * from "./composer/composer.js";
|
|
3
|
+
export { isComposerBusy } from "./composer/composer-actions.js";
|
|
4
|
+
export { fileFromFilePart, formatBytes } from "./files/file-meta.js";
|
|
5
|
+
export * from "./files/files.js";
|
|
6
|
+
export * from "./reply/reply.js";
|
|
7
|
+
export * from "./turn/turn.js";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ExtraProps } from "react-markdown";
|
|
2
|
+
type HastNode = NonNullable<ExtraProps["node"]>;
|
|
3
|
+
export declare function fencedCode(node: HastNode | undefined): {
|
|
4
|
+
code: string;
|
|
5
|
+
language: string;
|
|
6
|
+
} | null;
|
|
7
|
+
export declare function FencedCode({ node }: ExtraProps): import("react").JSX.Element | null;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Code } from "../../thread/code/code.js";
|
|
3
|
+
function textOf(child) {
|
|
4
|
+
if (child.type === "text")
|
|
5
|
+
return child.value;
|
|
6
|
+
if (child.type === "element")
|
|
7
|
+
return child.children.map(textOf).join("");
|
|
8
|
+
return "";
|
|
9
|
+
}
|
|
10
|
+
function languageOf(className) {
|
|
11
|
+
const classes = Array.isArray(className) ? className.map(String) : [];
|
|
12
|
+
const language = classes.find((value) => value.startsWith("language-"));
|
|
13
|
+
return language ? language.slice("language-".length) : "text";
|
|
14
|
+
}
|
|
15
|
+
export function fencedCode(node) {
|
|
16
|
+
const code = node?.children.find((child) => child.type === "element" && child.tagName === "code");
|
|
17
|
+
if (!code)
|
|
18
|
+
return null;
|
|
19
|
+
return {
|
|
20
|
+
code: code.children.map(textOf).join("").replace(/\n$/, ""),
|
|
21
|
+
language: languageOf(code.properties.className),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export function FencedCode({ node }) {
|
|
25
|
+
const fenced = fencedCode(node);
|
|
26
|
+
if (!fenced)
|
|
27
|
+
return null;
|
|
28
|
+
return _jsx(Code, { code: fenced.code, language: fenced.language, className: "mt-4 first:mt-0" });
|
|
29
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { cn } from "@locusgraph/components";
|
|
3
|
+
import { FencedCode, fencedCode } from "./fenced-code.js";
|
|
4
|
+
const blockGap = "mt-4 first:mt-0";
|
|
5
|
+
export const markdownComponents = {
|
|
6
|
+
p: ({ node: _node, className, ...props }) => (_jsx("p", { className: cn("leading-relaxed text-pretty [&:not(:first-child)]:mt-3", className), ...props })),
|
|
7
|
+
a: ({ node: _node, className, ...props }) => (_jsx("a", { target: "_blank", rel: "noopener noreferrer", className: cn("font-medium text-foreground underline decoration-muted-foreground/50 underline-offset-3 transition-colors hover:decoration-foreground", className), ...props })),
|
|
8
|
+
h1: ({ node: _node, className, ...props }) => (_jsx("h1", { className: cn("mt-7 mb-2 text-base font-semibold tracking-tight first:mt-0", className), ...props })),
|
|
9
|
+
h2: ({ node: _node, className, ...props }) => (_jsx("h2", { className: cn("mt-6 mb-2 text-base font-semibold tracking-tight first:mt-0", className), ...props })),
|
|
10
|
+
h3: ({ node: _node, className, ...props }) => (_jsx("h3", { className: cn("mt-5 mb-1.5 text-sm font-semibold first:mt-0", className), ...props })),
|
|
11
|
+
h4: ({ node: _node, className, ...props }) => (_jsx("h4", { className: cn("eyebrow mt-5 mb-1.5 first:mt-0", className), ...props })),
|
|
12
|
+
ul: ({ node: _node, className, ...props }) => (_jsx("ul", { className: cn("mt-3 list-disc space-y-1.5 pl-5 first:mt-0 [li_&]:mt-1.5", className), ...props })),
|
|
13
|
+
ol: ({ node: _node, className, ...props }) => (_jsx("ol", { className: cn("mt-3 list-decimal space-y-1.5 pl-5 first:mt-0 marker:tabular-nums [li_&]:mt-1.5", className), ...props })),
|
|
14
|
+
li: ({ node: _node, className, ...props }) => (_jsx("li", { className: cn("pl-1 leading-relaxed marker:text-muted-foreground [&>p]:mt-0", className), ...props })),
|
|
15
|
+
blockquote: ({ node: _node, className, ...props }) => (_jsx("blockquote", { className: cn("border-l-2 border-border pl-4 text-muted-foreground", blockGap, className), ...props })),
|
|
16
|
+
hr: ({ node: _node, className, ...props }) => (_jsx("hr", { className: cn("my-6 border-border", className), ...props })),
|
|
17
|
+
pre: ({ node, className, ...props }) => fencedCode(node) ? (_jsx(FencedCode, { node: node })) : (_jsx("pre", { className: cn("overflow-x-auto bg-muted/40 p-3 font-mono text-xs leading-relaxed", blockGap, className), ...props })),
|
|
18
|
+
code: ({ node: _node, className, ...props }) => (_jsx("code", { className: cn("bg-muted px-1.5 py-0.5 font-mono text-[0.85em] text-foreground [pre_&]:bg-transparent [pre_&]:p-0", className), ...props })),
|
|
19
|
+
table: ({ node: _node, className, ...props }) => (_jsx("div", { "data-slot": "reply-table", className: cn("overflow-x-auto ring-1 ring-border", blockGap), children: _jsx("table", { className: cn("w-full border-collapse text-sm [&_td:not(:first-child)]:tabular-nums", className), ...props }) })),
|
|
20
|
+
th: ({ node: _node, className, ...props }) => (_jsx("th", { className: cn("eyebrow border-b bg-muted/30 px-3 py-2 text-left font-normal", className), ...props })),
|
|
21
|
+
td: ({ node: _node, className, ...props }) => (_jsx("td", { className: cn("border-b px-3 py-2 align-top [tr:last-child_&]:border-b-0", className), ...props })),
|
|
22
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type * as React from "react";
|
|
2
|
+
import type { StreamState } from "../../types.js";
|
|
3
|
+
export type ReplyProps = Omit<React.ComponentProps<"div">, "children"> & {
|
|
4
|
+
children: string;
|
|
5
|
+
state?: StreamState;
|
|
6
|
+
};
|
|
7
|
+
export declare function closeOpenCodeFence(markdown: string): string;
|
|
8
|
+
export declare function Reply({ children, state, className, ...props }: ReplyProps): React.JSX.Element;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { cn } from "@locusgraph/components";
|
|
3
|
+
import { memo } from "react";
|
|
4
|
+
import ReactMarkdown from "react-markdown";
|
|
5
|
+
import remarkGfm from "remark-gfm";
|
|
6
|
+
import { markdownComponents } from "./markdown-components.js";
|
|
7
|
+
const codeFence = /^ {0,3}(```|~~~)/gm;
|
|
8
|
+
export function closeOpenCodeFence(markdown) {
|
|
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
|
+
}
|
|
13
|
+
const Markdown = memo(function Markdown({ markdown }) {
|
|
14
|
+
return (_jsx(ReactMarkdown, { remarkPlugins: [remarkGfm], components: markdownComponents, children: markdown }));
|
|
15
|
+
});
|
|
16
|
+
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({ children, state = "done", className, ...props }) {
|
|
18
|
+
const isStreaming = state === "streaming";
|
|
19
|
+
const markdown = isStreaming ? closeOpenCodeFence(children) : children;
|
|
20
|
+
return (_jsx("div", { "data-slot": "reply", "data-state": state, "aria-live": isStreaming ? "polite" : undefined, className: cn("min-w-0 text-sm leading-relaxed wrap-break-word text-foreground", streamingCaret, className), ...props, children: _jsx(Markdown, { markdown: markdown }) }));
|
|
21
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { FilePart, MessagePart, ReasoningPart, SourceUrlPart, TextPart, ToolPart } from "../../types.js";
|
|
2
|
+
export type PartSegment = {
|
|
3
|
+
kind: "text";
|
|
4
|
+
key: string;
|
|
5
|
+
part: TextPart;
|
|
6
|
+
} | {
|
|
7
|
+
kind: "reasoning";
|
|
8
|
+
key: string;
|
|
9
|
+
part: ReasoningPart;
|
|
10
|
+
} | {
|
|
11
|
+
kind: "tool";
|
|
12
|
+
key: string;
|
|
13
|
+
part: ToolPart;
|
|
14
|
+
} | {
|
|
15
|
+
kind: "files";
|
|
16
|
+
key: string;
|
|
17
|
+
parts: FilePart[];
|
|
18
|
+
} | {
|
|
19
|
+
kind: "sources";
|
|
20
|
+
key: string;
|
|
21
|
+
parts: SourceUrlPart[];
|
|
22
|
+
};
|
|
23
|
+
export declare function isToolPart(part: MessagePart): part is ToolPart;
|
|
24
|
+
export declare function groupParts(parts: MessagePart[]): PartSegment[];
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export function isToolPart(part) {
|
|
2
|
+
return part.type === "dynamic-tool" || part.type.startsWith("tool-");
|
|
3
|
+
}
|
|
4
|
+
function appendToRun(segments, kind, part, key) {
|
|
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, key, parts: [part] }
|
|
12
|
+
: { kind, key, parts: [part] });
|
|
13
|
+
}
|
|
14
|
+
export function groupParts(parts) {
|
|
15
|
+
const segments = [];
|
|
16
|
+
parts.forEach((part, index) => {
|
|
17
|
+
const key = `${part.type}:${index}`;
|
|
18
|
+
if (part.type === "text") {
|
|
19
|
+
segments.push({ kind: "text", key, part });
|
|
20
|
+
}
|
|
21
|
+
else if (part.type === "reasoning") {
|
|
22
|
+
segments.push({ kind: "reasoning", key, part });
|
|
23
|
+
}
|
|
24
|
+
else if (part.type === "file") {
|
|
25
|
+
appendToRun(segments, "files", part, key);
|
|
26
|
+
}
|
|
27
|
+
else if (part.type === "source-url") {
|
|
28
|
+
appendToRun(segments, "sources", part, key);
|
|
29
|
+
}
|
|
30
|
+
else if (isToolPart(part)) {
|
|
31
|
+
segments.push({ kind: "tool", key: part.toolCallId, part });
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
return segments;
|
|
35
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type * as React from "react";
|
|
2
|
+
import type { AgentMessage, ReasoningPart, SourceUrlPart, ToolPart } from "../../types.js";
|
|
3
|
+
export type TurnProps = Omit<React.ComponentProps<"div">, "children"> & {
|
|
4
|
+
message: AgentMessage;
|
|
5
|
+
avatar?: React.ReactNode;
|
|
6
|
+
footer?: React.ReactNode;
|
|
7
|
+
renderReasoning?: (part: ReasoningPart) => React.ReactNode;
|
|
8
|
+
renderTool?: (part: ToolPart) => React.ReactNode;
|
|
9
|
+
renderSources?: (parts: SourceUrlPart[]) => React.ReactNode;
|
|
10
|
+
};
|
|
11
|
+
export declare function Turn({ message, avatar, footer, renderReasoning, renderTool, renderSources, className, ...props }: TurnProps): React.JSX.Element;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { cn, MessageAvatar, MessageContent, MessageFooter, Message as MessageRow, } from "@locusgraph/components";
|
|
3
|
+
import { Thinking } from "../../agent/thinking/thinking.js";
|
|
4
|
+
import { Tool } from "../../agent/tool/tool.js";
|
|
5
|
+
import { Sources } from "../../memory/sources.js";
|
|
6
|
+
import { fileFromFilePart } from "../files/file-meta.js";
|
|
7
|
+
import { Files } from "../files/files.js";
|
|
8
|
+
import { Reply } from "../reply/reply.js";
|
|
9
|
+
import { groupParts } from "./group-parts.js";
|
|
10
|
+
const roleLabels = {
|
|
11
|
+
user: "You said",
|
|
12
|
+
assistant: "Assistant said",
|
|
13
|
+
system: "System note",
|
|
14
|
+
};
|
|
15
|
+
function UserText({ part }) {
|
|
16
|
+
return (_jsx("div", { "data-slot": "message-user-text", className: "max-w-[85%] bg-muted px-3.5 py-2 text-sm leading-relaxed whitespace-pre-wrap wrap-break-word text-foreground", children: part.text }));
|
|
17
|
+
}
|
|
18
|
+
function partClassName(role, kind) {
|
|
19
|
+
if (role === "user") {
|
|
20
|
+
return "w-full items-end";
|
|
21
|
+
}
|
|
22
|
+
if (role === "system") {
|
|
23
|
+
return "border-l-2 border-border pl-3 *:data-[slot=reply]:text-xs *:data-[slot=reply]:text-muted-foreground";
|
|
24
|
+
}
|
|
25
|
+
return cn(kind === "text" && "*:data-[slot=reply]:max-w-[68ch]");
|
|
26
|
+
}
|
|
27
|
+
function renderSegment(segment, isUser, renderers) {
|
|
28
|
+
switch (segment.kind) {
|
|
29
|
+
case "text":
|
|
30
|
+
return isUser ? (_jsx(UserText, { part: segment.part })) : (_jsx(Reply, { state: segment.part.state, children: segment.part.text }));
|
|
31
|
+
case "reasoning":
|
|
32
|
+
return renderers.renderReasoning ? (renderers.renderReasoning(segment.part)) : (_jsx(Thinking, { text: segment.part.text, state: segment.part.state, durationMs: segment.part.durationMs }));
|
|
33
|
+
case "tool":
|
|
34
|
+
return renderers.renderTool ? (renderers.renderTool(segment.part)) : (_jsx(Tool, { part: segment.part }));
|
|
35
|
+
case "sources":
|
|
36
|
+
return renderers.renderSources ? (renderers.renderSources(segment.parts)) : (_jsx(Sources, { sources: segment.parts }));
|
|
37
|
+
case "files":
|
|
38
|
+
return (_jsx(Files, { items: segment.parts.map(fileFromFilePart), className: cn(isUser && "justify-end") }));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export function Turn({ message, avatar, footer, renderReasoning, renderTool, renderSources, className, ...props }) {
|
|
42
|
+
const isUser = message.role === "user";
|
|
43
|
+
const renderers = { renderReasoning, renderTool, renderSources };
|
|
44
|
+
return (_jsxs(MessageRow, { "data-role": message.role, align: isUser ? "end" : "start", "aria-label": roleLabels[message.role], role: "article", className: cn("gap-3 data-[role=system]:text-muted-foreground", className), ...props, children: [avatar && (_jsx(MessageAvatar, { className: "mt-0.5 self-start group-has-data-[slot=message-footer]/message:translate-y-0", children: avatar })), _jsxs(MessageContent, { className: cn("gap-4", isUser && "items-end gap-2"), children: [groupParts(message.parts).map((segment) => (_jsx("div", { "data-slot": "message-part", "data-kind": segment.kind, className: cn("flex min-w-0 flex-col", partClassName(message.role, segment.kind)), children: renderSegment(segment, isUser, renderers) }, segment.key))), footer && _jsx(MessageFooter, { className: "px-0", children: footer })] })] }));
|
|
45
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type ContextSegment } from "./shared/context-breakdown.js";
|
|
2
|
+
export type { ContextSegment } from "./shared/context-breakdown.js";
|
|
3
|
+
export type ContextStatus = "ok" | "near" | "full";
|
|
4
|
+
export type ContextProps = {
|
|
5
|
+
usedTokens: number;
|
|
6
|
+
limitTokens: number;
|
|
7
|
+
breakdown?: ContextSegment[];
|
|
8
|
+
variant?: "bar" | "ring";
|
|
9
|
+
label?: string;
|
|
10
|
+
className?: string;
|
|
11
|
+
};
|
|
12
|
+
export declare function contextStatus(usedTokens: number, limitTokens: number): ContextStatus;
|
|
13
|
+
export declare function Context({ usedTokens, limitTokens, breakdown, variant, label, className, }: ContextProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { cn, HoverCard, HoverCardContent, HoverCardTrigger } from "@locusgraph/components";
|
|
3
|
+
import { formatCount, nearLimitPercent, quotaPercent } from "@locusgraph/utils";
|
|
4
|
+
import { ContextBreakdown } from "./shared/context-breakdown.js";
|
|
5
|
+
import { MeterBar, MeterRing } from "./shared/meter-marks.js";
|
|
6
|
+
import { formatTokensShort } from "./shared/usage-totals.js";
|
|
7
|
+
export function contextStatus(usedTokens, limitTokens) {
|
|
8
|
+
if (usedTokens >= limitTokens)
|
|
9
|
+
return "full";
|
|
10
|
+
const percent = quotaPercent({ used: usedTokens, included: limitTokens });
|
|
11
|
+
return percent >= nearLimitPercent ? "near" : "ok";
|
|
12
|
+
}
|
|
13
|
+
const statusTone = {
|
|
14
|
+
ok: "text-muted-foreground",
|
|
15
|
+
near: "text-warn",
|
|
16
|
+
full: "text-destructive",
|
|
17
|
+
};
|
|
18
|
+
function RingContent({ percent, status }) {
|
|
19
|
+
return (_jsxs(_Fragment, { children: [_jsx(MeterRing, { percent: percent, status: status }), _jsxs("span", { className: "font-mono text-[11px] tabular-nums", children: [percent, "%"] })] }));
|
|
20
|
+
}
|
|
21
|
+
function BarContent({ label, usedTokens, limitTokens, percent, status, }) {
|
|
22
|
+
return (_jsxs(_Fragment, { children: [_jsxs("span", { className: "flex items-baseline justify-between gap-4 font-mono text-[11px] tabular-nums", children: [_jsx("span", { className: "eyebrow", children: label }), _jsxs("span", { className: cn(status === "ok" && "text-foreground"), children: [percent, "% \u00B7 ", formatTokensShort(usedTokens), " / ", formatTokensShort(limitTokens)] })] }), _jsx(MeterBar, { percent: percent, status: status })] }));
|
|
23
|
+
}
|
|
24
|
+
export function Context({ usedTokens, limitTokens, breakdown, variant = "bar", label = "Context", className, }) {
|
|
25
|
+
const percent = quotaPercent({ used: usedTokens, included: limitTokens });
|
|
26
|
+
const status = contextStatus(usedTokens, limitTokens);
|
|
27
|
+
const summary = `${formatCount(usedTokens)} of ${formatCount(limitTokens)} tokens`;
|
|
28
|
+
const hasBreakdown = breakdown !== undefined && breakdown.length > 0;
|
|
29
|
+
const meter = (_jsx("div", { "data-slot": "context", "data-status": status, "data-variant": variant, role: "meter", "aria-label": `${label} window`, "aria-valuemin": 0, "aria-valuemax": 100, "aria-valuenow": percent, "aria-valuetext": `${percent}%, ${summary}`, tabIndex: hasBreakdown ? 0 : undefined, className: cn("outline-none focus-visible:ring-2 focus-visible:ring-ring/70", statusTone[status], variant === "ring"
|
|
30
|
+
? "inline-flex h-6 items-center gap-1.5 rounded-full px-2 transition-colors duration-150 motion-reduce:transition-none"
|
|
31
|
+
: "flex w-full flex-col gap-2", variant === "ring" && hasBreakdown && "cursor-default hover:bg-accent", className), children: variant === "ring" ? (_jsx(RingContent, { percent: percent, status: status })) : (_jsx(BarContent, { label: label, usedTokens: usedTokens, limitTokens: limitTokens, percent: percent, status: status })) }));
|
|
32
|
+
if (!hasBreakdown)
|
|
33
|
+
return meter;
|
|
34
|
+
return (_jsxs(HoverCard, { openDelay: 100, closeDelay: 100, children: [_jsx(HoverCardTrigger, { asChild: true, children: meter }), _jsx(HoverCardContent, { align: "end", sideOffset: 6, className: "w-72 rounded-none border-0 bg-popover p-0 shadow-overlay ring-1 ring-border", children: _jsx(ContextBreakdown, { label: label, usedTokens: usedTokens, limitTokens: limitTokens, percent: percent, status: status, breakdown: breakdown }) })] }));
|
|
35
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type CostStep } from "./shared/step-cost-row.js";
|
|
2
|
+
export type { CostStep, CostStepStatus } from "./shared/step-cost-row.js";
|
|
3
|
+
export type CostStepsProps = {
|
|
4
|
+
steps: CostStep[];
|
|
5
|
+
label?: string;
|
|
6
|
+
emptyText?: string;
|
|
7
|
+
className?: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function stepCostTotals(steps: CostStep[]): {
|
|
10
|
+
inputTokens: number;
|
|
11
|
+
outputTokens: number;
|
|
12
|
+
costMicroUsd: number;
|
|
13
|
+
failedAttempts: number;
|
|
14
|
+
wastedMicroUsd: number;
|
|
15
|
+
durationMs: number;
|
|
16
|
+
};
|
|
17
|
+
export declare function CostSteps({ steps, label, emptyText, className, }: CostStepsProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Roadmap as ChartNoAxesGanttIcon } from "@carbon/icons-react";
|
|
3
|
+
import { formatCount, formatMicroUsd, pluralize } from "@locusgraph/utils";
|
|
4
|
+
import { ApprovalPanel, PanelHeader } from "../shared/panel.js";
|
|
5
|
+
import { PanelEmpty } from "../shared/panel-empty.js";
|
|
6
|
+
import { isWastedStep, StepCostRow } from "./shared/step-cost-row.js";
|
|
7
|
+
import { formatDuration, sumUsage } from "./shared/usage-totals.js";
|
|
8
|
+
export function stepCostTotals(steps) {
|
|
9
|
+
const totals = sumUsage(steps.map((step) => step.usage));
|
|
10
|
+
const wastedMicroUsd = steps
|
|
11
|
+
.filter(isWastedStep)
|
|
12
|
+
.reduce((sum, step) => sum + step.usage.costMicroUsd, 0);
|
|
13
|
+
const durationMs = steps.reduce((sum, step) => sum + (step.durationMs ?? 0), 0);
|
|
14
|
+
return { ...totals, wastedMicroUsd, durationMs };
|
|
15
|
+
}
|
|
16
|
+
function Totals({ totals }) {
|
|
17
|
+
return (_jsxs("div", { "data-slot": "step-cost-totals", className: "flex flex-col gap-1 px-5 pt-2 pb-4", children: [_jsx("span", { className: "text-2xl font-semibold tracking-tight tabular-nums", children: formatMicroUsd(totals.costMicroUsd) }), _jsxs("span", { className: "flex flex-wrap gap-x-3 gap-y-0.5 text-xs text-muted-foreground tabular-nums", children: [_jsxs("span", { children: [formatCount(totals.inputTokens), " in \u00B7 ", formatCount(totals.outputTokens), " out", totals.durationMs > 0 && ` · ${formatDuration(totals.durationMs)}`] }), totals.wastedMicroUsd > 0 && (_jsxs("span", { className: "text-destructive", children: ["Wasted on failures ", formatMicroUsd(totals.wastedMicroUsd)] }))] })] }));
|
|
18
|
+
}
|
|
19
|
+
export function CostSteps({ steps, label = "Cost by step", emptyText = "No steps have run yet.", className, }) {
|
|
20
|
+
const totals = stepCostTotals(steps);
|
|
21
|
+
const maxCost = Math.max(0, ...steps.map((step) => step.usage.costMicroUsd));
|
|
22
|
+
const running = steps.some((step) => step.status === "running");
|
|
23
|
+
return (_jsxs(ApprovalPanel, { "data-slot": "cost-steps", "aria-label": label, className: className, children: [_jsx(PanelHeader, { icon: _jsx(ChartNoAxesGanttIcon, { "aria-hidden": true }), eyebrow: label, aside: steps.length > 0 ? pluralize(steps.length, "step") : undefined, status: running ? "Running" : undefined, tone: "running" }), steps.length === 0 ? (_jsx(PanelEmpty, { icon: _jsx(ChartNoAxesGanttIcon, { "aria-hidden": true }), title: emptyText })) : (_jsxs(_Fragment, { children: [_jsx(Totals, { totals: totals }), _jsx("ol", { className: "flex flex-col divide-y divide-border border-t border-border", children: steps.map((step) => (_jsx(StepCostRow, { step: step, maxCost: maxCost, totalCost: totals.costMicroUsd }, step.id))) })] }))] }));
|
|
24
|
+
}
|