@surfaces-ui/chat 0.0.0-stage → 0.2.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 +202 -0
- package/NOTICE +4 -0
- package/README.md +40 -2
- package/dist/AnalyticsChat.d.ts +82 -0
- package/dist/AnalyticsChat.js +168 -0
- package/dist/AnalyticsChat.js.map +1 -0
- package/dist/Approval.d.ts +18 -0
- package/dist/Approval.js +116 -0
- package/dist/Approval.js.map +1 -0
- package/dist/Chat.d.ts +112 -0
- package/dist/Chat.js +119 -0
- package/dist/Chat.js.map +1 -0
- package/dist/ChatComposer.d.ts +117 -0
- package/dist/ChatComposer.js +186 -0
- package/dist/ChatComposer.js.map +1 -0
- package/dist/ChatPanels.d.ts +34 -0
- package/dist/ChatPanels.js +75 -0
- package/dist/ChatPanels.js.map +1 -0
- package/dist/DataPanel.d.ts +19 -0
- package/dist/DataPanel.js +20 -0
- package/dist/DataPanel.js.map +1 -0
- package/dist/Menu.d.ts +37 -0
- package/dist/Menu.js +85 -0
- package/dist/Menu.js.map +1 -0
- package/dist/PageStudio.d.ts +103 -0
- package/dist/PageStudio.js +166 -0
- package/dist/PageStudio.js.map +1 -0
- package/dist/SessionList.d.ts +64 -0
- package/dist/SessionList.js +225 -0
- package/dist/SessionList.js.map +1 -0
- package/dist/appComponents.d.ts +6 -0
- package/dist/appComponents.js +100 -0
- package/dist/appComponents.js.map +1 -0
- package/dist/conversation.d.ts +66 -0
- package/dist/conversation.js +119 -0
- package/dist/conversation.js.map +1 -0
- package/dist/icons.d.ts +33 -0
- package/dist/icons.js +34 -0
- package/dist/icons.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/selectors.d.ts +106 -0
- package/dist/selectors.js +160 -0
- package/dist/selectors.js.map +1 -0
- package/dist/sessions.d.ts +71 -0
- package/dist/sessions.js +194 -0
- package/dist/sessions.js.map +1 -0
- package/dist/speech.d.ts +43 -0
- package/dist/speech.js +89 -0
- package/dist/speech.js.map +1 -0
- package/dist/thread.d.ts +199 -0
- package/dist/thread.js +225 -0
- package/dist/thread.js.map +1 -0
- package/dist/useChat.d.ts +121 -0
- package/dist/useChat.js +293 -0
- package/dist/useChat.js.map +1 -0
- package/dist/voice.d.ts +41 -0
- package/dist/voice.js +128 -0
- package/dist/voice.js.map +1 -0
- package/package.json +71 -3
package/dist/Menu.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useId, useLayoutEffect, useRef, useState } from "react";
|
|
3
|
+
import { ChatIcon } from "./icons.js";
|
|
4
|
+
/** Space kept between a popover and the window's edge. */
|
|
5
|
+
const EDGE = 8;
|
|
6
|
+
/**
|
|
7
|
+
* A button that opens a small popover above it, or below when there is more
|
|
8
|
+
* room there, kept inside the window: a list of choices, a
|
|
9
|
+
* checklist. It floats over the page (fixed to the window), so a panel that
|
|
10
|
+
* scrolls or clips what it holds does not cut it off. Escape and a press outside close it, and focus goes back to the
|
|
11
|
+
* button. It is a dialog rather than an ARIA menu because it holds checkboxes
|
|
12
|
+
* and links as well as commands; Tab moves through them.
|
|
13
|
+
*/
|
|
14
|
+
export function MenuButton({ label, text, icon, iconOnly, children, disabled, className }) {
|
|
15
|
+
const [open, setOpen] = useState(false);
|
|
16
|
+
const button = useRef(null);
|
|
17
|
+
const panel = useRef(null);
|
|
18
|
+
const id = useId();
|
|
19
|
+
// Which side has room, measured when it opens; the popover scrolls within that room.
|
|
20
|
+
const [place, setPlace] = useState({ below: false, end: false, room: 0 });
|
|
21
|
+
useLayoutEffect(() => {
|
|
22
|
+
if (!open || !button.current)
|
|
23
|
+
return;
|
|
24
|
+
const measure = () => {
|
|
25
|
+
if (!button.current)
|
|
26
|
+
return;
|
|
27
|
+
const at = button.current.getBoundingClientRect();
|
|
28
|
+
const height = window.innerHeight || document.documentElement.clientHeight;
|
|
29
|
+
const width = window.innerWidth || document.documentElement.clientWidth;
|
|
30
|
+
const above = at.top;
|
|
31
|
+
const below = height - at.bottom;
|
|
32
|
+
const wide = panel.current?.offsetWidth ?? 0;
|
|
33
|
+
const end = at.left + wide > width && at.right - wide >= 0;
|
|
34
|
+
// Lined up with the button's start (or its end, when that fits better), then moved inside the window.
|
|
35
|
+
const left = Math.max(EDGE, Math.min((end ? at.right - wide : at.left), width - wide - EDGE));
|
|
36
|
+
const gap = 4;
|
|
37
|
+
setPlace(below > above ? { below: true, end, room: below, left, top: at.bottom + gap } : { below: false, end, room: above, left, bottom: height - at.top + gap });
|
|
38
|
+
};
|
|
39
|
+
measure();
|
|
40
|
+
// A panel scrolled, or the window resized, moves the button; the popover follows it.
|
|
41
|
+
window.addEventListener("resize", measure);
|
|
42
|
+
window.addEventListener("scroll", measure, true);
|
|
43
|
+
return () => {
|
|
44
|
+
window.removeEventListener("resize", measure);
|
|
45
|
+
window.removeEventListener("scroll", measure, true);
|
|
46
|
+
};
|
|
47
|
+
}, [open]);
|
|
48
|
+
const close = () => {
|
|
49
|
+
setOpen(false);
|
|
50
|
+
button.current?.focus();
|
|
51
|
+
};
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
if (!open)
|
|
54
|
+
return;
|
|
55
|
+
const first = panel.current?.querySelector("input, button, a[href], [tabindex='0']");
|
|
56
|
+
first?.focus();
|
|
57
|
+
const outside = (event) => {
|
|
58
|
+
const target = event.target;
|
|
59
|
+
if (!panel.current?.contains(target) && !button.current?.contains(target))
|
|
60
|
+
setOpen(false);
|
|
61
|
+
};
|
|
62
|
+
document.addEventListener("pointerdown", outside);
|
|
63
|
+
return () => document.removeEventListener("pointerdown", outside);
|
|
64
|
+
}, [open]);
|
|
65
|
+
return (_jsxs("span", { className: ["sf-chat-menu", className].filter(Boolean).join(" "), children: [_jsxs("button", { ref: button, type: "button", className: "sf-chat-tool", "data-icon-only": iconOnly || undefined, "aria-label": label, title: iconOnly ? label : undefined, "aria-haspopup": "dialog", "aria-expanded": open, "aria-controls": open ? id : undefined, disabled: disabled, onClick: () => setOpen(!open), children: [icon && _jsx(ChatIcon, { name: icon }), !iconOnly && _jsx("span", { className: "sf-chat-tool-text", children: text ?? label }), !iconOnly && _jsx(ChatIcon, { name: "chevron" })] }), open && (_jsx("div", { ref: panel, id: id, className: "sf-chat-popover", "data-below": place.below || undefined, "data-end": place.end || undefined, style: place.room > 0
|
|
66
|
+
? {
|
|
67
|
+
"--sf-chat-popover-room": `${Math.floor(place.room)}px`,
|
|
68
|
+
...(place.left !== undefined ? { position: "fixed", left: place.left, right: "auto", top: place.top ?? "auto", bottom: place.bottom ?? "auto" } : {}),
|
|
69
|
+
}
|
|
70
|
+
: undefined, role: "dialog", "aria-label": label, onKeyDown: (event) => {
|
|
71
|
+
if (event.key === "Escape") {
|
|
72
|
+
event.stopPropagation();
|
|
73
|
+
close();
|
|
74
|
+
}
|
|
75
|
+
}, children: children(close) }))] }));
|
|
76
|
+
}
|
|
77
|
+
/** One choice in a popover: a command, or with `checked` a toggle. */
|
|
78
|
+
export function MenuItem({ children, detail, onSelect, checked, disabled, role }) {
|
|
79
|
+
return (_jsxs("button", { type: "button", className: "sf-chat-menu-item", role: role, "aria-checked": role ? !!checked : undefined, disabled: disabled, onClick: onSelect, children: [_jsx("span", { className: "sf-chat-menu-mark", children: role && checked ? _jsx(ChatIcon, { name: "check" }) : null }), _jsxs("span", { className: "sf-chat-menu-text", children: [children, detail && _jsx("span", { className: "sf-chat-menu-detail", children: detail })] })] }));
|
|
80
|
+
}
|
|
81
|
+
export function MenuGroup({ label, children }) {
|
|
82
|
+
const id = useId();
|
|
83
|
+
return (_jsxs("div", { className: "sf-chat-menu-group", role: "group", "aria-labelledby": id, children: [_jsx("p", { id: id, className: "sf-chat-menu-heading", children: label }), children] }));
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=Menu.js.map
|
package/dist/Menu.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
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BACxB,KAAK,EAAE,CAAC;oBACV,CAAC;gBACH,CAAC,YAEA,QAAQ,CAAC,KAAK,CAAC,GACZ,CACP,IACI,CACR,CAAC;AACJ,CAAC;AAED,sEAAsE;AACtE,MAAM,UAAU,QAAQ,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAqI;IACjN,OAAO,CACL,kBAAQ,IAAI,EAAC,QAAQ,EAAC,SAAS,EAAC,mBAAmB,EAAC,IAAI,EAAE,IAAI,kBAAgB,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,aAC/I,eAAM,SAAS,EAAC,mBAAmB,YAAE,IAAI,IAAI,OAAO,CAAC,CAAC,CAAC,KAAC,QAAQ,IAAC,IAAI,EAAC,OAAO,GAAG,CAAC,CAAC,CAAC,IAAI,GAAQ,EAC/F,gBAAM,SAAS,EAAC,mBAAmB,aAChC,QAAQ,EACR,MAAM,IAAI,eAAM,SAAS,EAAC,qBAAqB,YAAE,MAAM,GAAQ,IAC3D,IACA,CACV,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,EAAE,KAAK,EAAE,QAAQ,EAA0C;IACnF,MAAM,EAAE,GAAG,KAAK,EAAE,CAAC;IACnB,OAAO,CACL,eAAK,SAAS,EAAC,oBAAoB,EAAC,IAAI,EAAC,OAAO,qBAAkB,EAAE,aAClE,YAAG,EAAE,EAAE,EAAE,EAAE,SAAS,EAAC,sBAAsB,YACxC,KAAK,GACJ,EACH,QAAQ,IACL,CACP,CAAC;AACJ,CAAC","sourcesContent":["import { type CSSProperties, type ReactNode, useEffect, useId, useLayoutEffect, useRef, useState } from \"react\";\nimport { ChatIcon, type ChatIconName } from \"./icons.js\";\n\nexport interface MenuButtonProps {\n /** The button's accessible name, e.g. \"Model: Large\". */\n label: string;\n /** What the button shows; defaults to the label. */\n text?: ReactNode;\n icon?: ChatIconName;\n /** Show only the icon, with the label as its name and tooltip. */\n iconOnly?: boolean;\n /** The popover's content. Given `close` to close it after a choice. */\n children(close: () => void): ReactNode;\n disabled?: boolean;\n className?: string;\n}\n\n/** Space kept between a popover and the window's edge. */\nconst EDGE = 8;\n\n/**\n * A button that opens a small popover above it, or below when there is more\n * room there, kept inside the window: a list of choices, a\n * checklist. It floats over the page (fixed to the window), so a panel that\n * scrolls or clips what it holds does not cut it off. Escape and a press outside close it, and focus goes back to the\n * button. It is a dialog rather than an ARIA menu because it holds checkboxes\n * and links as well as commands; Tab moves through them.\n */\nexport function MenuButton({ label, text, icon, iconOnly, children, disabled, className }: MenuButtonProps) {\n const [open, setOpen] = useState(false);\n const button = useRef<HTMLButtonElement>(null);\n const panel = useRef<HTMLDivElement>(null);\n const id = useId();\n // Which side has room, measured when it opens; the popover scrolls within that room.\n const [place, setPlace] = useState<{ below: boolean; end: boolean; room: number; left?: number; top?: number; bottom?: number }>({ below: false, end: false, room: 0 });\n useLayoutEffect(() => {\n if (!open || !button.current) return;\n const measure = () => {\n if (!button.current) return;\n const at = button.current.getBoundingClientRect();\n const height = window.innerHeight || document.documentElement.clientHeight;\n const width = window.innerWidth || document.documentElement.clientWidth;\n const above = at.top;\n const below = height - at.bottom;\n const wide = panel.current?.offsetWidth ?? 0;\n const end = at.left + wide > width && at.right - wide >= 0;\n // Lined up with the button's start (or its end, when that fits better), then moved inside the window.\n const left = Math.max(EDGE, Math.min((end ? at.right - wide : at.left), width - wide - EDGE));\n const gap = 4;\n setPlace(below > above ? { below: true, end, room: below, left, top: at.bottom + gap } : { below: false, end, room: above, left, bottom: height - at.top + gap });\n };\n measure();\n // A panel scrolled, or the window resized, moves the button; the popover follows it.\n window.addEventListener(\"resize\", measure);\n window.addEventListener(\"scroll\", measure, true);\n return () => {\n window.removeEventListener(\"resize\", measure);\n window.removeEventListener(\"scroll\", measure, true);\n };\n }, [open]);\n const close = () => {\n setOpen(false);\n button.current?.focus();\n };\n useEffect(() => {\n if (!open) return;\n const first = panel.current?.querySelector<HTMLElement>(\"input, button, a[href], [tabindex='0']\");\n first?.focus();\n const outside = (event: PointerEvent) => {\n const target = event.target as Node;\n if (!panel.current?.contains(target) && !button.current?.contains(target)) setOpen(false);\n };\n document.addEventListener(\"pointerdown\", outside);\n return () => document.removeEventListener(\"pointerdown\", outside);\n }, [open]);\n return (\n <span className={[\"sf-chat-menu\", className].filter(Boolean).join(\" \")}>\n <button\n ref={button}\n type=\"button\"\n className=\"sf-chat-tool\"\n data-icon-only={iconOnly || undefined}\n aria-label={label}\n title={iconOnly ? label : undefined}\n aria-haspopup=\"dialog\"\n aria-expanded={open}\n aria-controls={open ? id : undefined}\n disabled={disabled}\n onClick={() => setOpen(!open)}\n >\n {icon && <ChatIcon name={icon} />}\n {!iconOnly && <span className=\"sf-chat-tool-text\">{text ?? label}</span>}\n {!iconOnly && <ChatIcon name=\"chevron\" />}\n </button>\n {open && (\n <div\n ref={panel}\n id={id}\n className=\"sf-chat-popover\"\n data-below={place.below || undefined}\n data-end={place.end || undefined}\n style={\n place.room > 0\n ? ({\n \"--sf-chat-popover-room\": `${Math.floor(place.room)}px`,\n ...(place.left !== undefined ? { position: \"fixed\", left: place.left, right: \"auto\", top: place.top ?? \"auto\", bottom: place.bottom ?? \"auto\" } : {}),\n } as CSSProperties)\n : undefined\n }\n role=\"dialog\"\n aria-label={label}\n onKeyDown={(event) => {\n if (event.key === \"Escape\") {\n event.stopPropagation();\n close();\n }\n }}\n >\n {children(close)}\n </div>\n )}\n </span>\n );\n}\n\n/** One choice in a popover: a command, or with `checked` a toggle. */\nexport function MenuItem({ children, detail, onSelect, checked, disabled, role }: { children: ReactNode; detail?: ReactNode; onSelect(): void; checked?: boolean; disabled?: boolean; role?: \"radio\" | \"checkbox\" }) {\n return (\n <button type=\"button\" className=\"sf-chat-menu-item\" role={role} aria-checked={role ? !!checked : undefined} disabled={disabled} onClick={onSelect}>\n <span className=\"sf-chat-menu-mark\">{role && checked ? <ChatIcon name=\"check\" /> : null}</span>\n <span className=\"sf-chat-menu-text\">\n {children}\n {detail && <span className=\"sf-chat-menu-detail\">{detail}</span>}\n </span>\n </button>\n );\n}\n\nexport function MenuGroup({ label, children }: { label: string; children: ReactNode }) {\n const id = useId();\n return (\n <div className=\"sf-chat-menu-group\" role=\"group\" aria-labelledby={id}>\n <p id={id} className=\"sf-chat-menu-heading\">\n {label}\n </p>\n {children}\n </div>\n );\n}\n"]}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { AgentBackend } from "@surfaces-ui/agent";
|
|
2
|
+
import { type Catalog, type PageDocument, type SurfaceMessage } from "@surfaces-ui/spec";
|
|
3
|
+
import { type ComponentRenderer, type SurfaceNote } from "@surfaces-ui/spec/react";
|
|
4
|
+
import { type Store } from "@surfaces-ui/state";
|
|
5
|
+
import type { ChatProvider } from "./selectors.js";
|
|
6
|
+
import type { ChatActor } from "./thread.js";
|
|
7
|
+
import type { ChatSettings } from "./useChat.js";
|
|
8
|
+
/** What happened when one instruction was applied. */
|
|
9
|
+
export interface StudioChange {
|
|
10
|
+
instruction: string;
|
|
11
|
+
/** The agent's own words about what it did. */
|
|
12
|
+
summary: string;
|
|
13
|
+
/** The model or agent that made the change, or the person who arranged the page by hand. Always shown. */
|
|
14
|
+
generatedBy: string;
|
|
15
|
+
/** True when a person made the change by hand (arranging), not an agent. */
|
|
16
|
+
byPerson?: boolean;
|
|
17
|
+
applied: number;
|
|
18
|
+
/** Changes the catalog refused, and why. */
|
|
19
|
+
rejected: string[];
|
|
20
|
+
error?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The text sent to the agent for one instruction: what the person asked, how
|
|
24
|
+
* to answer, and the page as it is now.
|
|
25
|
+
*/
|
|
26
|
+
export declare function studioPrompt(page: PageDocument, instruction: string): string;
|
|
27
|
+
export interface UsePageStudio {
|
|
28
|
+
page: PageDocument;
|
|
29
|
+
/** The store holding the page, for persistence or URL sync from `@surfaces-ui/state`. */
|
|
30
|
+
store: Store<PageDocument>;
|
|
31
|
+
changes: StudioChange[];
|
|
32
|
+
busy: boolean;
|
|
33
|
+
/** Sends an instruction to the agent and applies the edits it returns. */
|
|
34
|
+
instruct(instruction: string): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Applies a change a person made by hand, such as arranging, as A2UI
|
|
37
|
+
* messages: one undo step, a line in the log by them, and a note the agent
|
|
38
|
+
* reads with the next instruction.
|
|
39
|
+
*/
|
|
40
|
+
arrange(messages: SurfaceMessage[], title: string, by?: string): void;
|
|
41
|
+
stop(): void;
|
|
42
|
+
undo(): void;
|
|
43
|
+
redo(): void;
|
|
44
|
+
canUndo: boolean;
|
|
45
|
+
canRedo: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Records where the drawn page stands: what a person typed, or one
|
|
48
|
+
* component's controls in catalog prop form. Sent with every instruction
|
|
49
|
+
* (`SendRequest.surfaces`), so the agent edits the page as the person sees it.
|
|
50
|
+
*/
|
|
51
|
+
report(state: {
|
|
52
|
+
data?: unknown;
|
|
53
|
+
componentId?: string;
|
|
54
|
+
controls?: Record<string, unknown>;
|
|
55
|
+
note?: SurfaceNote;
|
|
56
|
+
}): void;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Lets an agent configure a page from plain-language instructions. The
|
|
60
|
+
* agent answers with A2UI messages; they are turned into edits, each edit is
|
|
61
|
+
* checked against the catalog, and only valid ones change the page. Every
|
|
62
|
+
* instruction is one undo step.
|
|
63
|
+
*/
|
|
64
|
+
export declare function usePageStudio(agent: AgentBackend, initial: PageDocument, catalog?: Catalog): UsePageStudio;
|
|
65
|
+
export interface PageStudioProps {
|
|
66
|
+
agent: AgentBackend;
|
|
67
|
+
/** The page to start from. A different document starts again. */
|
|
68
|
+
page: PageDocument;
|
|
69
|
+
catalog?: Catalog;
|
|
70
|
+
renderers?: Record<string, ComponentRenderer>;
|
|
71
|
+
/** Instructions offered as one-press examples. */
|
|
72
|
+
starters?: string[];
|
|
73
|
+
/** Called after each change with the page as it is now. */
|
|
74
|
+
onChange?(page: PageDocument): void;
|
|
75
|
+
/** Where models run, when the host can reach several: the box's Model menu groups models by provider. */
|
|
76
|
+
providers?: ChatProvider[];
|
|
77
|
+
settings?: ChatSettings;
|
|
78
|
+
onSettingsChange?(settings: ChatSettings): void;
|
|
79
|
+
onManageProviders?(): void;
|
|
80
|
+
/**
|
|
81
|
+
* Lets a person arrange the page by hand: move components, put two side by
|
|
82
|
+
* side, and drag heights and widths. Off unless given. Each change is one
|
|
83
|
+
* undo step, shows in the log by `user`, and is told to the agent.
|
|
84
|
+
*/
|
|
85
|
+
arrange?: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* With `arrange`: keeps the width handles between a Grid's or Row's columns,
|
|
88
|
+
* and the height handle under a component with a height of its own (a chart or
|
|
89
|
+
* a table, say) or one whose height is set, while nobody
|
|
90
|
+
* is arranging. Each drag is one undo step, the same as in Arrange.
|
|
91
|
+
*/
|
|
92
|
+
resizeWhileViewing?: boolean;
|
|
93
|
+
/** Who is arranging, for the log. */
|
|
94
|
+
user?: ChatActor;
|
|
95
|
+
className?: string;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* A page with an instruction box beside it. A person says what they want
|
|
99
|
+
* ("add a chart of revenue by month", "remove the table") and the agent
|
|
100
|
+
* changes the page. Changes are listed with who made them, anything the
|
|
101
|
+
* catalog refused, and can be undone.
|
|
102
|
+
*/
|
|
103
|
+
export declare function PageStudio(props: PageStudioProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { analyticsCatalog, editPage, editsFromMessages, pageSurface, removeComponentMessages } from "@surfaces-ui/spec";
|
|
3
|
+
import { ArrangeGhost, ArrangeHelp, ArrangeToggle, SurfaceView, lazyAnalyticsRenderers, useArrange } from "@surfaces-ui/spec/react";
|
|
4
|
+
import { createStore } from "@surfaces-ui/state";
|
|
5
|
+
import { useHistory, useStore } from "@surfaces-ui/state/react";
|
|
6
|
+
import { ChatComposer } from "./ChatComposer.js";
|
|
7
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
8
|
+
/**
|
|
9
|
+
* The text sent to the agent for one instruction: what the person asked, how
|
|
10
|
+
* to answer, and the page as it is now.
|
|
11
|
+
*/
|
|
12
|
+
export function studioPrompt(page, instruction) {
|
|
13
|
+
return [
|
|
14
|
+
`Instruction: ${instruction}`,
|
|
15
|
+
"",
|
|
16
|
+
`Change the page "${page.id}" by sending A2UI updateComponents messages for surfaceId "${page.id}".`,
|
|
17
|
+
"Send only the components you add or change. To remove one, send its container without it in children.",
|
|
18
|
+
"Say in one sentence what you changed.",
|
|
19
|
+
"",
|
|
20
|
+
`Page title: ${page.title}`,
|
|
21
|
+
"Current page:",
|
|
22
|
+
JSON.stringify(page.components),
|
|
23
|
+
].join("\n");
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Lets an agent configure a page from plain-language instructions. The
|
|
27
|
+
* agent answers with A2UI messages; they are turned into edits, each edit is
|
|
28
|
+
* checked against the catalog, and only valid ones change the page. Every
|
|
29
|
+
* instruction is one undo step.
|
|
30
|
+
*/
|
|
31
|
+
export function usePageStudio(agent, initial, catalog = analyticsCatalog) {
|
|
32
|
+
const store = useMemo(() => createStore(initial), [initial]);
|
|
33
|
+
const page = useStore(store);
|
|
34
|
+
const history = useHistory(store);
|
|
35
|
+
const [changes, setChanges] = useState([]);
|
|
36
|
+
const [busy, setBusy] = useState(false);
|
|
37
|
+
const controller = useRef(undefined);
|
|
38
|
+
const session = useRef("");
|
|
39
|
+
const local = useRef({ controls: {}, activity: [] });
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
setChanges([]);
|
|
42
|
+
session.current = "";
|
|
43
|
+
local.current = { controls: {}, activity: [] };
|
|
44
|
+
return () => controller.current?.abort();
|
|
45
|
+
}, [store]);
|
|
46
|
+
const instruct = useCallback(async (instruction) => {
|
|
47
|
+
const text = instruction.trim();
|
|
48
|
+
if (!text)
|
|
49
|
+
return;
|
|
50
|
+
controller.current?.abort();
|
|
51
|
+
const current = new AbortController();
|
|
52
|
+
controller.current = current;
|
|
53
|
+
setBusy(true);
|
|
54
|
+
const before = store.get();
|
|
55
|
+
const messages = [];
|
|
56
|
+
const change = { instruction: text, summary: "", generatedBy: "", applied: 0, rejected: [] };
|
|
57
|
+
try {
|
|
58
|
+
const surfaces = [
|
|
59
|
+
{
|
|
60
|
+
surfaceId: before.id,
|
|
61
|
+
dataModel: toJson(local.current.data ?? before.data ?? {}),
|
|
62
|
+
controls: Object.fromEntries(Object.entries(local.current.controls).map(([id, c]) => [id, toJson(c)])),
|
|
63
|
+
// What the person did on the page since the last instruction, told once.
|
|
64
|
+
activity: local.current.activity.map((a) => ({ componentId: a.componentId, kind: a.kind, summary: a.summary, at: a.at, ...(a.subject ? { subject: toJson(a.subject) } : {}) })),
|
|
65
|
+
},
|
|
66
|
+
];
|
|
67
|
+
local.current.activity = [];
|
|
68
|
+
for await (const event of agent.send({ sessionId: session.current, input: { case: "text", value: studioPrompt(before, text) }, surfaces }, { signal: current.signal })) {
|
|
69
|
+
const part = event.event;
|
|
70
|
+
if (part.case === "text")
|
|
71
|
+
change.summary += part.value.delta;
|
|
72
|
+
else if (part.case === "surface")
|
|
73
|
+
messages.push(part.value);
|
|
74
|
+
else if (part.case === "error")
|
|
75
|
+
change.error = part.value.message;
|
|
76
|
+
else if (part.case === "done") {
|
|
77
|
+
change.generatedBy = part.value.generatedBy;
|
|
78
|
+
session.current = part.value.sessionId || session.current;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const edits = editsFromMessages(before, messages);
|
|
82
|
+
const result = editPage(before, edits, catalog);
|
|
83
|
+
change.applied = edits.length - result.rejected.length;
|
|
84
|
+
change.rejected = result.rejected.map((r) => r.reason);
|
|
85
|
+
if (change.applied > 0)
|
|
86
|
+
store.set(result.page);
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
change.error = error instanceof Error ? error.message : String(error);
|
|
90
|
+
}
|
|
91
|
+
finally {
|
|
92
|
+
if (!current.signal.aborted)
|
|
93
|
+
setChanges((previous) => [...previous, { ...change, summary: change.summary.trim() }]);
|
|
94
|
+
if (controller.current === current) {
|
|
95
|
+
controller.current = undefined;
|
|
96
|
+
setBusy(false);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}, [agent, catalog, store]);
|
|
100
|
+
const stop = useCallback(() => {
|
|
101
|
+
controller.current?.abort();
|
|
102
|
+
controller.current = undefined;
|
|
103
|
+
setBusy(false);
|
|
104
|
+
}, []);
|
|
105
|
+
const arrange = useCallback((messages, title, by = "you") => {
|
|
106
|
+
const before = store.get();
|
|
107
|
+
const edits = editsFromMessages(before, messages);
|
|
108
|
+
const result = editPage(before, edits, catalog);
|
|
109
|
+
const applied = edits.length - result.rejected.length;
|
|
110
|
+
if (applied > 0)
|
|
111
|
+
store.set(result.page);
|
|
112
|
+
setChanges((previous) => [...previous, { instruction: title, summary: "", generatedBy: by, byPerson: true, applied, rejected: result.rejected.map((r) => r.reason) }]);
|
|
113
|
+
if (applied === 0)
|
|
114
|
+
return;
|
|
115
|
+
// What changed, as the props that now say where things are: the same form an agent arranges with.
|
|
116
|
+
const changed = edits.flatMap((edit) => (edit.op === "set" ? [edit.component] : []));
|
|
117
|
+
const subject = Object.fromEntries(changed.map(({ id, children, widths, sizes, wrap, gap, padding, height, minHeight }) => [id, Object.fromEntries(Object.entries({ children, widths, sizes, wrap, gap, padding, height, minHeight }).filter(([, v]) => v !== undefined))]));
|
|
118
|
+
local.current.activity = [...local.current.activity, { componentId: changed[0]?.id ?? "root", kind: "layout.changed", summary: `${title}.`, subject, at: new Date().toISOString() }].slice(-40);
|
|
119
|
+
}, [catalog, store]);
|
|
120
|
+
const report = useCallback((state) => {
|
|
121
|
+
if (state.data !== undefined)
|
|
122
|
+
local.current.data = state.data;
|
|
123
|
+
if (state.componentId && state.controls)
|
|
124
|
+
local.current.controls[state.componentId] = state.controls;
|
|
125
|
+
if (state.componentId && state.note)
|
|
126
|
+
local.current.activity = [...local.current.activity, { componentId: state.componentId, ...state.note, at: new Date().toISOString() }].slice(-40);
|
|
127
|
+
}, []);
|
|
128
|
+
return { page, store, changes, busy, instruct, arrange, stop, undo: history.undo, redo: history.redo, canUndo: history.canUndo(), canRedo: history.canRedo(), report };
|
|
129
|
+
}
|
|
130
|
+
const toJson = (value) => {
|
|
131
|
+
const plain = JSON.parse(JSON.stringify(value ?? {}, (_, v) => (typeof v === "bigint" ? String(v) : v)));
|
|
132
|
+
return plain && typeof plain === "object" && !Array.isArray(plain) ? plain : {};
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* A page with an instruction box beside it. A person says what they want
|
|
136
|
+
* ("add a chart of revenue by month", "remove the table") and the agent
|
|
137
|
+
* changes the page. Changes are listed with who made them, anything the
|
|
138
|
+
* catalog refused, and can be undone.
|
|
139
|
+
*/
|
|
140
|
+
export function PageStudio(props) {
|
|
141
|
+
const catalog = props.catalog ?? analyticsCatalog;
|
|
142
|
+
const studio = usePageStudio(props.agent, props.page, catalog);
|
|
143
|
+
const onChange = useRef(props.onChange);
|
|
144
|
+
onChange.current = props.onChange;
|
|
145
|
+
useEffect(() => onChange.current?.(studio.page), [studio.page]);
|
|
146
|
+
const surface = useMemo(() => pageSurface(studio.page), [studio.page]);
|
|
147
|
+
const by = props.user?.name ?? "you";
|
|
148
|
+
const [arrangeStatus, setArrangeStatus] = useState();
|
|
149
|
+
const arrange = useArrange({
|
|
150
|
+
surface,
|
|
151
|
+
catalog,
|
|
152
|
+
apply: (messages, title) => studio.arrange(messages, title, by),
|
|
153
|
+
say: setArrangeStatus,
|
|
154
|
+
remove: (id) => {
|
|
155
|
+
const result = removeComponentMessages(surface, id);
|
|
156
|
+
if ("error" in result)
|
|
157
|
+
setArrangeStatus({ text: result.error, error: true });
|
|
158
|
+
else
|
|
159
|
+
studio.arrange(result.messages, `Removed "${id}"`, by);
|
|
160
|
+
},
|
|
161
|
+
resizeWhileViewing: props.resizeWhileViewing === true,
|
|
162
|
+
});
|
|
163
|
+
const frame = props.arrange === true ? arrange.surfaceFrame : undefined;
|
|
164
|
+
return (_jsxs("div", { className: ["sf-studio", props.className].filter(Boolean).join(" "), children: [_jsxs("section", { className: "sf-studio-page", "aria-label": studio.page.title, "aria-busy": studio.busy, children: [_jsx("h3", { className: "sf-studio-title", children: studio.page.title }), studio.page.description && _jsx("p", { className: "sf-object-muted", children: studio.page.description }), props.arrange && _jsx(ArrangeHelp, { arrange: arrange, status: arrangeStatus }), _jsx("div", { ...(props.arrange ? arrange.region : {}), children: _jsx(SurfaceView, { surface: props.arrange ? arrange.shown(surface) : surface, catalog: catalog, renderers: props.renderers ?? lazyAnalyticsRenderers, onDataChange: (data) => studio.report({ data }), onControlsChange: (componentId, controls) => studio.report({ componentId, controls }), onContext: (componentId, note) => studio.report({ componentId, note }), ...(frame ? { frame } : {}) }) }), props.arrange && _jsx(ArrangeGhost, { arrange: arrange })] }), _jsxs("aside", { className: "sf-studio-side", "aria-label": "Change this page", children: [_jsxs("div", { className: "sf-studio-form", children: [_jsx(ChatComposer, { label: "Describe a change", placeholder: "Add a line chart of revenue by month", onSend: (text) => void studio.instruct(text), onStop: studio.stop, streaming: studio.busy, agents: [], providers: props.providers, settings: props.settings, onSettingsChange: props.onSettingsChange, onManageProviders: props.onManageProviders }), _jsxs("div", { className: "sf-object-buttons", children: [_jsx("button", { type: "button", className: "sf-button", disabled: !studio.canUndo || studio.busy, onClick: studio.undo, children: "Undo" }), _jsx("button", { type: "button", className: "sf-button", disabled: !studio.canRedo || studio.busy, onClick: studio.redo, children: "Redo" }), props.arrange && _jsx(ArrangeToggle, { arrange: arrange })] })] }), props.starters && props.starters.length > 0 && (_jsx("div", { className: "sf-chat-suggestions", role: "group", "aria-label": "Examples", children: props.starters.map((starter) => (_jsx("button", { type: "button", className: "sf-button", disabled: studio.busy, onClick: () => void studio.instruct(starter), children: starter }, starter))) })), _jsxs("ol", { className: "sf-studio-log", "aria-label": "Changes", "aria-live": "polite", children: [studio.changes.map((change, index) => (_jsxs("li", { "data-failed": change.error || change.applied === 0 ? "" : undefined, children: [_jsx("p", { className: "sf-studio-instruction", children: change.instruction }), !change.byPerson && _jsx("p", { children: change.error ?? (change.summary || (change.applied > 0 ? "Changed." : "Nothing was changed.")) }), change.rejected.map((reason) => (_jsxs("p", { className: "sf-studio-rejected", children: ["Not applied: ", reason] }, reason))), change.generatedBy && _jsx("p", { className: "sf-chat-by", children: change.byPerson ? `Arranged by ${change.generatedBy}` : `By ${change.generatedBy}` })] }, index))), studio.busy && _jsx("li", { className: "sf-chat-thinking", children: "Working\u2026" })] })] })] }));
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=PageStudio.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PageStudio.js","sourceRoot":"","sources":["../src/PageStudio.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAwD,gBAAgB,EAAE,QAAQ,EAAE,iBAAiB,EAAE,WAAW,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC9K,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAA4C,WAAW,EAAE,sBAAsB,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC9K,OAAO,EAAc,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAIjD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAiB1E;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,IAAkB,EAAE,WAAmB;IAClE,OAAO;QACL,gBAA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AAW,EAAE,CAAC,CAAC,CAAC,MAAM,MAAM,CAAC,WAAW,EAAE,GAAK,KARlI,KAAK,CAST,CACN,CAAC,EACD,MAAM,CAAC,IAAI,IAAI,aAAI,SAAS,EAAC,kBAAkB,8BAAc,IAC3D,IACC,IACJ,CACP,CAAC;AACJ,CAAC","sourcesContent":["import type { JsonObject } from \"@bufbuild/protobuf\";\nimport type { AgentBackend } from \"@surfaces-ui/agent\";\nimport { type Catalog, type PageDocument, type SurfaceMessage, analyticsCatalog, editPage, editsFromMessages, pageSurface, removeComponentMessages } from \"@surfaces-ui/spec\";\nimport { ArrangeGhost, ArrangeHelp, ArrangeToggle, type ComponentRenderer, type SurfaceNote, SurfaceView, lazyAnalyticsRenderers, useArrange } from \"@surfaces-ui/spec/react\";\nimport { type Store, createStore } from \"@surfaces-ui/state\";\nimport { useHistory, useStore } from \"@surfaces-ui/state/react\";\nimport { ChatComposer } from \"./ChatComposer.js\";\nimport type { ChatProvider } from \"./selectors.js\";\nimport type { ChatActor } from \"./thread.js\";\nimport type { ChatSettings } from \"./useChat.js\";\nimport { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\n\n/** What happened when one instruction was applied. */\nexport interface StudioChange {\n instruction: string;\n /** The agent's own words about what it did. */\n summary: string;\n /** The model or agent that made the change, or the person who arranged the page by hand. Always shown. */\n generatedBy: string;\n /** True when a person made the change by hand (arranging), not an agent. */\n byPerson?: boolean;\n applied: number;\n /** Changes the catalog refused, and why. */\n rejected: string[];\n error?: string;\n}\n\n/**\n * The text sent to the agent for one instruction: what the person asked, how\n * to answer, and the page as it is now.\n */\nexport function studioPrompt(page: PageDocument, instruction: string): string {\n return [\n `Instruction: ${instruction}`,\n \"\",\n `Change the page \"${page.id}\" by sending A2UI updateComponents messages for surfaceId \"${page.id}\".`,\n \"Send only the components you add or change. To remove one, send its container without it in children.\",\n \"Say in one sentence what you changed.\",\n \"\",\n `Page title: ${page.title}`,\n \"Current page:\",\n JSON.stringify(page.components),\n ].join(\"\\n\");\n}\n\nexport interface UsePageStudio {\n page: PageDocument;\n /** The store holding the page, for persistence or URL sync from `@surfaces-ui/state`. */\n store: Store<PageDocument>;\n changes: StudioChange[];\n busy: boolean;\n /** Sends an instruction to the agent and applies the edits it returns. */\n instruct(instruction: string): Promise<void>;\n /**\n * Applies a change a person made by hand, such as arranging, as A2UI\n * messages: one undo step, a line in the log by them, and a note the agent\n * reads with the next instruction.\n */\n arrange(messages: SurfaceMessage[], title: string, by?: string): void;\n stop(): void;\n undo(): void;\n redo(): void;\n canUndo: boolean;\n canRedo: boolean;\n /**\n * Records where the drawn page stands: what a person typed, or one\n * component's controls in catalog prop form. Sent with every instruction\n * (`SendRequest.surfaces`), so the agent edits the page as the person sees it.\n */\n report(state: { data?: unknown; componentId?: string; controls?: Record<string, unknown>; note?: SurfaceNote }): void;\n}\n\n/**\n * Lets an agent configure a page from plain-language instructions. The\n * agent answers with A2UI messages; they are turned into edits, each edit is\n * checked against the catalog, and only valid ones change the page. Every\n * instruction is one undo step.\n */\nexport function usePageStudio(agent: AgentBackend, initial: PageDocument, catalog: Catalog = analyticsCatalog): UsePageStudio {\n const store = useMemo(() => createStore(initial), [initial]);\n const page = useStore(store);\n const history = useHistory(store);\n const [changes, setChanges] = useState<StudioChange[]>([]);\n const [busy, setBusy] = useState(false);\n const controller = useRef<AbortController | undefined>(undefined);\n const session = useRef(\"\");\n const local = useRef<{ data?: unknown; controls: Record<string, Record<string, unknown>>; activity: { componentId: string; kind: string; summary: string; subject?: Record<string, unknown>; at: string }[] }>({ controls: {}, activity: [] });\n\n useEffect(() => {\n setChanges([]);\n session.current = \"\";\n local.current = { controls: {}, activity: [] };\n return () => controller.current?.abort();\n }, [store]);\n\n const instruct = useCallback(\n async (instruction: string) => {\n const text = instruction.trim();\n if (!text) return;\n controller.current?.abort();\n const current = new AbortController();\n controller.current = current;\n setBusy(true);\n const before = store.get();\n const messages: SurfaceMessage[] = [];\n const change: StudioChange = { instruction: text, summary: \"\", generatedBy: \"\", applied: 0, rejected: [] };\n try {\n const surfaces = [\n {\n surfaceId: before.id,\n dataModel: toJson(local.current.data ?? before.data ?? {}),\n controls: Object.fromEntries(Object.entries(local.current.controls).map(([id, c]) => [id, toJson(c)])),\n // What the person did on the page since the last instruction, told once.\n activity: local.current.activity.map((a) => ({ componentId: a.componentId, kind: a.kind, summary: a.summary, at: a.at, ...(a.subject ? { subject: toJson(a.subject) } : {}) })),\n },\n ];\n local.current.activity = [];\n for await (const event of agent.send({ sessionId: session.current, input: { case: \"text\", value: studioPrompt(before, text) }, surfaces }, { signal: current.signal })) {\n const part = event.event;\n if (part.case === \"text\") change.summary += part.value.delta;\n else if (part.case === \"surface\") messages.push(part.value as unknown as SurfaceMessage);\n else if (part.case === \"error\") change.error = part.value.message;\n else if (part.case === \"done\") {\n change.generatedBy = part.value.generatedBy;\n session.current = part.value.sessionId || session.current;\n }\n }\n const edits = editsFromMessages(before, messages);\n const result = editPage(before, edits, catalog);\n change.applied = edits.length - result.rejected.length;\n change.rejected = result.rejected.map((r) => r.reason);\n if (change.applied > 0) store.set(result.page);\n } catch (error) {\n change.error = error instanceof Error ? error.message : String(error);\n } finally {\n if (!current.signal.aborted) setChanges((previous) => [...previous, { ...change, summary: change.summary.trim() }]);\n if (controller.current === current) {\n controller.current = undefined;\n setBusy(false);\n }\n }\n },\n [agent, catalog, store],\n );\n const stop = useCallback(() => {\n controller.current?.abort();\n controller.current = undefined;\n setBusy(false);\n }, []);\n\n const arrange = useCallback<UsePageStudio[\"arrange\"]>(\n (messages, title, by = \"you\") => {\n const before = store.get();\n const edits = editsFromMessages(before, messages);\n const result = editPage(before, edits, catalog);\n const applied = edits.length - result.rejected.length;\n if (applied > 0) store.set(result.page);\n setChanges((previous) => [...previous, { instruction: title, summary: \"\", generatedBy: by, byPerson: true, applied, rejected: result.rejected.map((r) => r.reason) }]);\n if (applied === 0) return;\n // What changed, as the props that now say where things are: the same form an agent arranges with.\n const changed = edits.flatMap((edit) => (edit.op === \"set\" ? [edit.component] : []));\n const subject = Object.fromEntries(changed.map(({ id, children, widths, sizes, wrap, gap, padding, height, minHeight }) => [id, Object.fromEntries(Object.entries({ children, widths, sizes, wrap, gap, padding, height, minHeight }).filter(([, v]) => v !== undefined))]));\n local.current.activity = [...local.current.activity, { componentId: changed[0]?.id ?? \"root\", kind: \"layout.changed\", summary: `${title}.`, subject, at: new Date().toISOString() }].slice(-40);\n },\n [catalog, store],\n );\n\n const report = useCallback<UsePageStudio[\"report\"]>((state) => {\n if (state.data !== undefined) local.current.data = state.data;\n if (state.componentId && state.controls) local.current.controls[state.componentId] = state.controls;\n if (state.componentId && state.note) local.current.activity = [...local.current.activity, { componentId: state.componentId, ...state.note, at: new Date().toISOString() }].slice(-40);\n }, []);\n\n return { page, store, changes, busy, instruct, arrange, stop, undo: history.undo, redo: history.redo, canUndo: history.canUndo(), canRedo: history.canRedo(), report };\n}\n\nconst toJson = (value: unknown): JsonObject => {\n const plain = JSON.parse(JSON.stringify(value ?? {}, (_, v) => (typeof v === \"bigint\" ? String(v) : v))) as unknown;\n return plain && typeof plain === \"object\" && !Array.isArray(plain) ? (plain as JsonObject) : {};\n};\n\nexport interface PageStudioProps {\n agent: AgentBackend;\n /** The page to start from. A different document starts again. */\n page: PageDocument;\n catalog?: Catalog;\n renderers?: Record<string, ComponentRenderer>;\n /** Instructions offered as one-press examples. */\n starters?: string[];\n /** Called after each change with the page as it is now. */\n onChange?(page: PageDocument): void;\n /** Where models run, when the host can reach several: the box's Model menu groups models by provider. */\n providers?: ChatProvider[];\n settings?: ChatSettings;\n onSettingsChange?(settings: ChatSettings): void;\n onManageProviders?(): void;\n /**\n * Lets a person arrange the page by hand: move components, put two side by\n * side, and drag heights and widths. Off unless given. Each change is one\n * undo step, shows in the log by `user`, and is told to the agent.\n */\n arrange?: boolean;\n /**\n * With `arrange`: keeps the width handles between a Grid's or Row's columns,\n * and the height handle under a component with a height of its own (a chart or\n * a table, say) or one whose height is set, while nobody\n * is arranging. Each drag is one undo step, the same as in Arrange.\n */\n resizeWhileViewing?: boolean;\n /** Who is arranging, for the log. */\n user?: ChatActor;\n className?: string;\n}\n\n/**\n * A page with an instruction box beside it. A person says what they want\n * (\"add a chart of revenue by month\", \"remove the table\") and the agent\n * changes the page. Changes are listed with who made them, anything the\n * catalog refused, and can be undone.\n */\nexport function PageStudio(props: PageStudioProps) {\n const catalog = props.catalog ?? analyticsCatalog;\n const studio = usePageStudio(props.agent, props.page, catalog);\n const onChange = useRef(props.onChange);\n onChange.current = props.onChange;\n useEffect(() => onChange.current?.(studio.page), [studio.page]);\n const surface = useMemo(() => pageSurface(studio.page), [studio.page]);\n const by = props.user?.name ?? \"you\";\n const [arrangeStatus, setArrangeStatus] = useState<{ text: string; error?: boolean }>();\n const arrange = useArrange({\n surface,\n catalog,\n apply: (messages, title) => studio.arrange(messages, title, by),\n say: setArrangeStatus,\n remove: (id) => {\n const result = removeComponentMessages(surface, id);\n if (\"error\" in result) setArrangeStatus({ text: result.error, error: true });\n else studio.arrange(result.messages, `Removed \"${id}\"`, by);\n },\n resizeWhileViewing: props.resizeWhileViewing === true,\n });\n const frame = props.arrange === true ? arrange.surfaceFrame : undefined;\n\n return (\n <div className={[\"sf-studio\", props.className].filter(Boolean).join(\" \")}>\n <section className=\"sf-studio-page\" aria-label={studio.page.title} aria-busy={studio.busy}>\n <h3 className=\"sf-studio-title\">{studio.page.title}</h3>\n {studio.page.description && <p className=\"sf-object-muted\">{studio.page.description}</p>}\n {props.arrange && <ArrangeHelp arrange={arrange} status={arrangeStatus} />}\n <div {...(props.arrange ? arrange.region : {})}>\n <SurfaceView\n surface={props.arrange ? arrange.shown(surface) : surface}\n catalog={catalog}\n renderers={props.renderers ?? lazyAnalyticsRenderers}\n onDataChange={(data) => studio.report({ data })}\n onControlsChange={(componentId, controls) => studio.report({ componentId, controls })}\n onContext={(componentId, note) => studio.report({ componentId, note })}\n {...(frame ? { frame } : {})}\n />\n </div>\n {props.arrange && <ArrangeGhost arrange={arrange} />}\n </section>\n\n <aside className=\"sf-studio-side\" aria-label=\"Change this page\">\n <div className=\"sf-studio-form\">\n <ChatComposer\n label=\"Describe a change\"\n placeholder=\"Add a line chart of revenue by month\"\n onSend={(text) => void studio.instruct(text)}\n onStop={studio.stop}\n streaming={studio.busy}\n agents={[]}\n providers={props.providers}\n settings={props.settings}\n onSettingsChange={props.onSettingsChange}\n onManageProviders={props.onManageProviders}\n />\n <div className=\"sf-object-buttons\">\n <button type=\"button\" className=\"sf-button\" disabled={!studio.canUndo || studio.busy} onClick={studio.undo}>\n Undo\n </button>\n <button type=\"button\" className=\"sf-button\" disabled={!studio.canRedo || studio.busy} onClick={studio.redo}>\n Redo\n </button>\n {props.arrange && <ArrangeToggle arrange={arrange} />}\n </div>\n </div>\n {props.starters && props.starters.length > 0 && (\n <div className=\"sf-chat-suggestions\" role=\"group\" aria-label=\"Examples\">\n {props.starters.map((starter) => (\n <button key={starter} type=\"button\" className=\"sf-button\" disabled={studio.busy} onClick={() => void studio.instruct(starter)}>\n {starter}\n </button>\n ))}\n </div>\n )}\n <ol className=\"sf-studio-log\" aria-label=\"Changes\" aria-live=\"polite\">\n {studio.changes.map((change, index) => (\n <li key={index} data-failed={change.error || change.applied === 0 ? \"\" : undefined}>\n <p className=\"sf-studio-instruction\">{change.instruction}</p>\n {!change.byPerson && <p>{change.error ?? (change.summary || (change.applied > 0 ? \"Changed.\" : \"Nothing was changed.\"))}</p>}\n {change.rejected.map((reason) => (\n <p key={reason} className=\"sf-studio-rejected\">\n Not applied: {reason}\n </p>\n ))}\n {change.generatedBy && <p className=\"sf-chat-by\">{change.byPerson ? `Arranged by ${change.generatedBy}` : `By ${change.generatedBy}`}</p>}\n </li>\n ))}\n {studio.busy && <li className=\"sf-chat-thinking\">Working…</li>}\n </ol>\n </aside>\n </div>\n );\n}\n"]}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { ChatSessionSummary } from "./sessions.js";
|
|
3
|
+
export type SessionSort = "updated" | "created" | "title";
|
|
4
|
+
export type SessionGroup = "none" | "day" | "agent" | "source" | "tag";
|
|
5
|
+
/** How recent, relative to today, so a saved list never goes stale. */
|
|
6
|
+
export type SessionSince = "today" | "7d" | "30d" | "older";
|
|
7
|
+
/** Everything a person sets on the list. Plain JSON, so a host can keep it. */
|
|
8
|
+
export interface SessionListState {
|
|
9
|
+
search?: string;
|
|
10
|
+
sort?: SessionSort;
|
|
11
|
+
direction?: "asc" | "desc";
|
|
12
|
+
groupBy?: SessionGroup;
|
|
13
|
+
agents?: string[];
|
|
14
|
+
sources?: string[];
|
|
15
|
+
tags?: string[];
|
|
16
|
+
pinned?: boolean;
|
|
17
|
+
since?: SessionSince;
|
|
18
|
+
}
|
|
19
|
+
/** Whether one session matches the filters and the search. */
|
|
20
|
+
export declare function sessionMatches(session: ChatSessionSummary, state: SessionListState, now?: Date): boolean;
|
|
21
|
+
/** Sorted as the state says; pinned sessions come first. */
|
|
22
|
+
export declare function sortSessions(sessions: ChatSessionSummary[], state: SessionListState): ChatSessionSummary[];
|
|
23
|
+
/** The day a session falls in, in words. */
|
|
24
|
+
export declare function dayBucket(iso: string, now?: Date): string;
|
|
25
|
+
export interface SessionGroupOf {
|
|
26
|
+
label: string;
|
|
27
|
+
sessions: ChatSessionSummary[];
|
|
28
|
+
}
|
|
29
|
+
/** Filtered, sorted and grouped, as the list draws it. A session with several sources or tags is listed under each. */
|
|
30
|
+
export declare function arrangeSessions(sessions: ChatSessionSummary[], state: SessionListState, options?: {
|
|
31
|
+
now?: Date;
|
|
32
|
+
agentName?(id: string): string;
|
|
33
|
+
}): SessionGroupOf[];
|
|
34
|
+
export interface SessionListProps {
|
|
35
|
+
sessions: ChatSessionSummary[];
|
|
36
|
+
/** The conversation open now. */
|
|
37
|
+
current?: string;
|
|
38
|
+
value?: SessionListState;
|
|
39
|
+
defaultValue?: SessionListState;
|
|
40
|
+
onChange?(state: SessionListState): void;
|
|
41
|
+
onOpen(id: string): void;
|
|
42
|
+
onNew?(): void;
|
|
43
|
+
onRename?(id: string, title: string): void;
|
|
44
|
+
onPin?(id: string, pinned: boolean): void;
|
|
45
|
+
onRemove?(id: string): void;
|
|
46
|
+
/** An agent's name for its id. */
|
|
47
|
+
agentName?(id: string): string;
|
|
48
|
+
/** With a height the rows scroll inside and only those in view are drawn. */
|
|
49
|
+
height?: number;
|
|
50
|
+
/** Row height for windowing, in px. Default 56. */
|
|
51
|
+
rowHeight?: number;
|
|
52
|
+
/** Set "now" for tests. */
|
|
53
|
+
now?: Date;
|
|
54
|
+
/** Shown when there are none at all. */
|
|
55
|
+
empty?: ReactNode;
|
|
56
|
+
/** Names the list for assistive technology. Default "Conversations". */
|
|
57
|
+
label?: string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Saved conversations a person can search, filter, sort and group. Each row
|
|
61
|
+
* opens its conversation; rename, pin and delete are on its controls and on
|
|
62
|
+
* its right-click menu, and delete asks first.
|
|
63
|
+
*/
|
|
64
|
+
export declare function SessionList(props: SessionListProps): import("react").JSX.Element;
|