@theoremjs/studio 0.3.4-next.735.g8d504c6 → 0.3.4-next.747.g0909061
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/installed.mjs +10 -1
- package/label-areas.d.ts +5 -0
- package/label-areas.js +6 -0
- package/package.json +19 -4
- package/page/assets/Badge-D78MvW22.js +1 -0
- package/page/assets/{BottomSheet-Dbh6A5Vl.js → BottomSheet-CS905Wxu.js} +1 -1
- package/page/assets/Card-D_40unTk.js +1 -0
- package/page/assets/CheckboxInput-MMjt4mDv.js +2 -0
- package/page/assets/CodeBlock-DzXH_9DF.js +3 -0
- package/page/assets/CollapsibleGroup-D1qiJpkR.js +1 -0
- package/page/assets/ConsoleFrame-BoayVeCq.js +3 -0
- package/page/assets/DateInput-BvG86MuZ.js +1 -0
- package/page/assets/{Dialog-Sd04KQS2.js → Dialog-DUNBjHOI.js} +1 -1
- package/page/assets/{HoverCard-DMyWUvwP.js → HoverCard-DMHc1Gh1.js} +1 -1
- package/page/assets/Icon-3c9WmPTH.js +3 -0
- package/page/assets/{IconButton-DVUFx-8p.js → IconButton-BeI1pXEZ.js} +1 -1
- package/page/assets/IconFilter-BO98ezum.js +1 -0
- package/page/assets/IconHistory-VvDVN7WG.js +1 -0
- package/page/assets/{ItemSwipeLayer-Ckn4X6h9.js → ItemSwipeLayer-BzVkYf4E.js} +1 -1
- package/page/assets/{ListItem-QF7KFt0h.js → ListItem-MWWVygeh.js} +1 -1
- package/page/assets/MenuBottomSheet-D5tp1i_-.js +1 -0
- package/page/assets/MenuBottomSheetActionList-CYZ56fty.js +1 -0
- package/page/assets/OverflowList-CoxIfkMv.js +1 -0
- package/page/assets/SchemaFields-tYFYYahf.js +1 -0
- package/page/assets/ScrollableArea-CZpbLBeP.js +1 -0
- package/page/assets/SidePanel-Bp_RI52Y.js +2 -0
- package/page/assets/{Text-BOqCfzZC.js → Text-B74VhVA7.js} +2 -2
- package/page/assets/TextInput-D1GkClqk.js +1 -0
- package/page/assets/{TimestampHoverCard-CDCVpEWM.js → TimestampHoverCard-BNDnoAyp.js} +1 -1
- package/page/assets/ToolResultCharts-BWfWMqlR.js +1 -0
- package/page/assets/Toolbar-DHVYq2_l.js +1 -0
- package/page/assets/{Tooltip-BWs5DLrM.js → Tooltip-DrSpWxD8.js} +1 -1
- package/page/assets/TraceInspector-CHfNL5A-.js +1 -0
- package/page/assets/{TraceOverview-DqCofwm4.js → TraceOverview-D_hfr4c-.js} +4 -4
- package/page/assets/{_virtual_studio-type-sources-nXG6uotl.js → _virtual_studio-type-sources-Cc4WAdgD.js} +50 -17
- package/page/assets/browser-connection-159CdeHX.js +1 -0
- package/page/assets/browser-engine-CEC4HFG-.js +16 -0
- package/page/assets/browser-transport-TSTeQ-sR.js +45 -0
- package/page/assets/compile-iB2CAmRL.js +2 -0
- package/page/assets/{container.stylex-BmOi-8DQ.js → container.stylex-C2nFBhUj.js} +1 -1
- package/page/assets/{embedding-space-view-CN0VHXXH.js → embedding-space-view-JuXKDaFw.js} +1 -1
- package/page/assets/encode-files-CeZxxjYd.js +1 -0
- package/page/assets/{export-agent-BrN5vTz2.js → export-agent-BgFM3Bl8.js} +3 -3
- package/page/assets/{fieldParts-CoOpDoax.js → fieldParts-Dtp1EoJQ.js} +1 -1
- package/page/assets/{focusOutline.stylex-BT0kfa4t.js → focusOutline.stylex-B9nWSXsG.js} +1 -1
- package/page/assets/guardrail-tester-C4z8FjFN.js +9 -0
- package/page/assets/highlightRanges-yrVxbmkN.js +51 -0
- package/page/assets/index-DakRjE8R.css +1 -0
- package/page/assets/index-nkhNFTq4.js +149 -0
- package/page/assets/{labels-provider-uONlWExD.js → labels-provider-Dc-AJqPH.js} +2 -2
- package/page/assets/{live-messages-_FDpxQYF.js → live-messages-Bqz1Qeph.js} +1 -1
- package/page/assets/menuItemRoles-Bod0knkp.js +1 -0
- package/page/assets/prompt-row-B1r2Wl_P.js +71 -0
- package/page/assets/prompt-row-beoYzntJ.css +1 -0
- package/page/assets/reader-Duft1Xr7.js +5 -0
- package/page/assets/registry-DP0ArymS.js +1 -0
- package/page/assets/schema-Cv4HAfBT.js +3 -0
- package/page/assets/shaped-data-DCfLI4gb.js +21 -0
- package/page/assets/{stub-J0Ig6FyA.js → stub-REBz-ZC7.js} +1 -1
- package/page/assets/studio-code-pane-5YnNxTk_.js +10 -0
- package/page/assets/{studio-console-BG1WmM3M.js → studio-console-Dwbc0RtX.js} +1 -1
- package/page/assets/studio-decision-CQcvYjzv.js +1 -0
- package/page/assets/studio-embedding-CwwCUKc9.js +2 -0
- package/page/assets/studio-host-console-CIh1ojgr.js +2 -0
- package/page/assets/studio-labels-APWMRX3W.js +3 -0
- package/page/assets/studio-live-BtCt43TJ.js +5 -0
- package/page/assets/studio-map-SLIQYxJF.js +1 -0
- package/page/assets/studio-trace-replay-lHRB3Hb-.js +3 -0
- package/page/assets/{studio-type-checker-CF7Re1aY.js → studio-type-checker-JZuu4iVI.js} +1 -1
- package/page/assets/{tokens.stylex-DkHf0P9C.js → tokens.stylex-BpCwr7Mf.js} +1 -1
- package/page/assets/tool-schema-BwaPiLtT.js +17 -0
- package/page/assets/{trace-patterns-D6TbkLLr.js → trace-patterns-D5Rcl0G4.js} +1 -1
- package/page/assets/{trace-record-YSvR6YMe.js → trace-record--uEnDt_D.js} +1 -1
- package/page/assets/tree-CL4ETBd5.js +3 -0
- package/page/assets/{turn-client-Xn70kpoZ.js → turn-client-CqKkEDLt.js} +2 -2
- package/page/assets/types-BDx4pnrt.js +1 -0
- package/page/assets/use-one-call-BqUlgQIr.js +1 -0
- package/page/assets/use-second-ticker-DhbZ0Soz.js +1 -0
- package/page/assets/{useAnnounce-DTSHZvjg.js → useAnnounce-DOkF3CS1.js} +1 -1
- package/page/assets/useAnnounceRenderedText-aqUr1P16.js +1 -0
- package/page/assets/{useClipboard-CbN9bb4J.js → useClipboard-BC4cMFBa.js} +1 -1
- package/page/assets/useKeyboardHint-BBkDGjRh.js +1 -0
- package/page/assets/useLocale-D8GRz3lz.js +1 -0
- package/page/assets/useMenuDrillIn-tTYG6Wzi.js +1 -0
- package/page/assets/{useMenuPress-DLG1QOiE.js → useMenuPress-DPpqa6F7.js} +1 -1
- package/page/assets/{useResolvedRequired-DbsOcDqy.js → useResolvedRequired-68GOSl0j.js} +1 -1
- package/page/assets/{useTooltip-c097gL_-.js → useTooltip-BaCjTHk-.js} +1 -1
- package/page/assets/{workspace-Bfoebvk4.js → workspace-B6d08n7C.js} +1 -1
- package/page/index.html +53 -42
- package/prompt-doc.d.ts +24 -0
- package/prompt-doc.js +251 -0
- package/read-source.js +25 -33
- package/section-notes.d.ts +16 -2
- package/section-notes.js +16 -2
- package/server/runs.d.ts +17 -0
- package/server/runs.js +73 -0
- package/server/save-session.d.ts +4 -0
- package/server/save-session.js +10 -6
- package/server/serve.js +41 -8
- package/ui/built/theme.css +1 -1
- package/ui/built/theorem-studio.js +1 -1
- package/ui/inspector-context.d.ts +2 -0
- package/ui/inspector-context.js +2 -0
- package/ui/inspector.d.ts +44 -2
- package/ui/inspector.js +20 -9
- package/ui/profile-editor.js +47 -40
- package/ui/prompt-editor.css +112 -0
- package/ui/prompt-editor.d.ts +16 -0
- package/ui/prompt-editor.js +315 -0
- package/ui/prompt-line-node.d.ts +29 -0
- package/ui/prompt-line-node.js +112 -0
- package/ui/prompt-row.d.ts +9 -0
- package/ui/prompt-row.js +25 -0
- package/ui/provider-editor.js +2 -1
- package/ui/studio-compare.js +13 -6
- package/ui/studio-save.js +3 -3
- package/ui/studio-screen.js +18 -16
- package/ui/studio-theme.d.ts +1 -1
- package/ui/studio-theme.js +2 -0
- package/ui/studio-trace-replay.js +5 -5
- package/ui/studio.css +42 -14
- package/page/assets/Banner-BXQ3eMGX.js +0 -3
- package/page/assets/Card-DruykyeB.js +0 -1
- package/page/assets/CheckboxInput-CFZ_Wq8-.js +0 -2
- package/page/assets/CodeBlock-CfVOtDeO.js +0 -52
- package/page/assets/CollapsibleGroup-BsIYDnJR.js +0 -1
- package/page/assets/ConsoleFrame-DDSgPsZH.js +0 -3
- package/page/assets/DateInput-CalwZl6a.js +0 -1
- package/page/assets/Icon-BqkS-pIq.js +0 -3
- package/page/assets/IconEye-BB5aY-wQ.js +0 -1
- package/page/assets/MenuBottomSheet-CGBoKe8D.js +0 -1
- package/page/assets/SchemaFields-D7ClAIou.js +0 -1
- package/page/assets/ScrollableArea-ChTx-OVZ.js +0 -1
- package/page/assets/SegmentedControlItem-CZs-ycSA.js +0 -1
- package/page/assets/SidePanel-DEd3R1Q3.js +0 -2
- package/page/assets/ToolResultCharts-DiEXUaNn.js +0 -1
- package/page/assets/TraceInspector-CaNKb5tj.js +0 -1
- package/page/assets/browser-connection-Dm_C2k-h.js +0 -3
- package/page/assets/browser-engine-BfnMGcT2.js +0 -16
- package/page/assets/browser-transport-9tBHJSxP.js +0 -45
- package/page/assets/crypto-DbeKCGAB.js +0 -1
- package/page/assets/encode-files-BdORDAbw.js +0 -1
- package/page/assets/guardrail-tester-BrSKPdyb.js +0 -9
- package/page/assets/index-Boxd3JUw.js +0 -149
- package/page/assets/index-C9rhrCGT.css +0 -1
- package/page/assets/reader-CHvIE7jW.js +0 -5
- package/page/assets/shaped-data-B5yHkAzM.js +0 -21
- package/page/assets/studio-code-pane-B4bfZLeO.js +0 -10
- package/page/assets/studio-decision-Ck3RM4xV.js +0 -1
- package/page/assets/studio-embedding-pvHODyby.js +0 -2
- package/page/assets/studio-host-console-DAv2ocEl.js +0 -2
- package/page/assets/studio-labels-DLm-OIlS.js +0 -3
- package/page/assets/studio-live-BBVkUupj.js +0 -5
- package/page/assets/studio-map-DE4o1Dw6.js +0 -1
- package/page/assets/studio-trace-replay-DMnAw57P.js +0 -3
- package/page/assets/tool-schema-CAhMfN4z.js +0 -17
- package/page/assets/tree-sm5ci1wZ.js +0 -3
- package/page/assets/use-one-call-DJQhFDfz.js +0 -1
- package/page/assets/use-second-ticker-B_tRvZF_.js +0 -1
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { DropdownMenu } from '@astryxdesign/core/DropdownMenu';
|
|
3
|
+
import { Icon } from '@astryxdesign/core/Icon';
|
|
4
|
+
import { ToggleButton } from '@astryxdesign/core/ToggleButton';
|
|
5
|
+
import { Tooltip } from '@astryxdesign/core/Tooltip';
|
|
6
|
+
import { RichTextEditor, RichTextEditorToolbar } from '@astryxdesign/richtext';
|
|
7
|
+
import '@astryxdesign/richtext/richtext.css';
|
|
8
|
+
import { $isListItemNode, $isListNode } from '@lexical/list';
|
|
9
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
10
|
+
import { $getSelectionStyleValueForProperty, $patchStyleText } from '@lexical/selection';
|
|
11
|
+
import { IconFilter, IconShareOff } from '@tabler/icons-react';
|
|
12
|
+
import { $getRoot, $getSelection, $isElementNode, $isRangeSelection, $isRootNode, $setSelection, $splitNode, } from 'lexical';
|
|
13
|
+
import { useCallback, useContext, useEffect, useRef, useState, } from 'react';
|
|
14
|
+
import { openedDoc, PRIVATE_NAME, PRIVATE_ON, promptMarkup, samePrompt } from "../prompt-doc.js";
|
|
15
|
+
import { ChangeHeld } from "./inspector-context.js";
|
|
16
|
+
import { $isPromptLine, conditionItems, PromptConditions, PromptLineNode, } from "./prompt-line-node.js";
|
|
17
|
+
import './prompt-editor.css';
|
|
18
|
+
const NODES = [PromptLineNode];
|
|
19
|
+
const MIN_HEIGHT = '16rem';
|
|
20
|
+
const PRIVATE_HINT = 'Private: the model reads this, and a reply that repeats it is stopped.';
|
|
21
|
+
const HINT_DELAY_MS = 200;
|
|
22
|
+
const BLOCK_HINT = 'Text style: paragraph, heading, list or quote';
|
|
23
|
+
const FORMAT_LABELS = new Set(['Bold', 'Italic', 'Underline', 'Strikethrough', 'Inline code']);
|
|
24
|
+
/** Keeps the selection when a toolbar button is pressed. */
|
|
25
|
+
const keepSelection = (event) => {
|
|
26
|
+
event.preventDefault();
|
|
27
|
+
};
|
|
28
|
+
/** The block a node sits in: its list item, or else the child of the root. */
|
|
29
|
+
function $topOf(node) {
|
|
30
|
+
let at = node;
|
|
31
|
+
for (let parent = at.getParent(); parent && !$isRootNode(parent); parent = at.getParent()) {
|
|
32
|
+
if ($isListItemNode(at) && $isRootNode(parent.getParent()))
|
|
33
|
+
return at;
|
|
34
|
+
at = parent;
|
|
35
|
+
}
|
|
36
|
+
return at;
|
|
37
|
+
}
|
|
38
|
+
/** The child of the root a block sits in. */
|
|
39
|
+
const $blockOf = (top) => {
|
|
40
|
+
const list = top.getParent();
|
|
41
|
+
return $isListItemNode(top) && list ? list : top;
|
|
42
|
+
};
|
|
43
|
+
/** The line a block belongs to. */
|
|
44
|
+
function $headOf(block) {
|
|
45
|
+
for (let at = block; at; at = at.getPreviousSibling()) {
|
|
46
|
+
if ($isPromptLine(at))
|
|
47
|
+
return at;
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
/** Splits a block's list after, or before, an item, so the item can stand apart from the rest. */
|
|
52
|
+
function $splitListAt(item, offset) {
|
|
53
|
+
const list = item.getParent();
|
|
54
|
+
if ($isListNode(list))
|
|
55
|
+
$splitNode(list, offset);
|
|
56
|
+
}
|
|
57
|
+
/** The first and last block a selection touches, in reading order. */
|
|
58
|
+
function $selectedEnds(selection) {
|
|
59
|
+
const [from, to] = selection.isBackward()
|
|
60
|
+
? [selection.focus, selection.anchor]
|
|
61
|
+
: [selection.anchor, selection.focus];
|
|
62
|
+
return { first: $topOf(from.getNode()), last: $topOf(to.getNode()) };
|
|
63
|
+
}
|
|
64
|
+
/** The condition of the line a block belongs to. */
|
|
65
|
+
const $whenOf = (top) => $headOf($blockOf(top))?.getWhen() ?? null;
|
|
66
|
+
/** Lets the blocks from `first` to `last` stand apart from the rest of their lists. */
|
|
67
|
+
function $standApart(first, last) {
|
|
68
|
+
if ($isListItemNode(last) && last.getNextSibling()) {
|
|
69
|
+
$splitListAt(last, last.getIndexWithinParent() + 1);
|
|
70
|
+
}
|
|
71
|
+
if ($isListItemNode(first) && first.getPreviousSibling()) {
|
|
72
|
+
$splitListAt(first, first.getIndexWithinParent());
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/** Joins `start` to `end` into one line, and what follows keeps the condition it had. */
|
|
76
|
+
function $closeLine(start, end, tail) {
|
|
77
|
+
for (let at = start; at && !at.is(end);) {
|
|
78
|
+
const after = at.getNextSibling();
|
|
79
|
+
if ($isPromptLine(at))
|
|
80
|
+
at.remove();
|
|
81
|
+
at = after;
|
|
82
|
+
}
|
|
83
|
+
const after = end.getNextSibling();
|
|
84
|
+
if (after && !$isPromptLine(after))
|
|
85
|
+
end.insertAfter(new PromptLineNode(tail));
|
|
86
|
+
}
|
|
87
|
+
/** Starts the line at `start` under `next`, and neighbours under one condition join back up. */
|
|
88
|
+
function $openLine(start, end, next) {
|
|
89
|
+
const before = start.getPreviousSibling();
|
|
90
|
+
const head = $isPromptLine(before) ? before.setWhen(next) : new PromptLineNode(next);
|
|
91
|
+
if (!$isPromptLine(before))
|
|
92
|
+
start.insertBefore(head);
|
|
93
|
+
if (!next)
|
|
94
|
+
return;
|
|
95
|
+
const following = end.getNextSibling();
|
|
96
|
+
if ($isPromptLine(following) && following.getWhen() === next)
|
|
97
|
+
following.remove();
|
|
98
|
+
const above = head.getPreviousSibling();
|
|
99
|
+
if (above && $headOf(above)?.getWhen() === next)
|
|
100
|
+
head.remove();
|
|
101
|
+
}
|
|
102
|
+
/** Sets the condition on what is selected, or on the block the caret is in. */
|
|
103
|
+
function $setCondition(next) {
|
|
104
|
+
const selection = $getSelection();
|
|
105
|
+
if (!$isRangeSelection(selection))
|
|
106
|
+
return;
|
|
107
|
+
const { first, last } = $selectedEnds(selection);
|
|
108
|
+
const when = $whenOf(first);
|
|
109
|
+
const tail = $whenOf(last);
|
|
110
|
+
if (next === when && when === tail)
|
|
111
|
+
return;
|
|
112
|
+
$standApart(first, last);
|
|
113
|
+
const start = $blockOf(first);
|
|
114
|
+
const end = $blockOf(last);
|
|
115
|
+
$closeLine(start, end, tail);
|
|
116
|
+
$openLine(start, end, next);
|
|
117
|
+
}
|
|
118
|
+
/** The Private and Condition buttons, on the toolbar's end. */
|
|
119
|
+
function PromptTools() {
|
|
120
|
+
const [editor] = useLexicalComposerContext();
|
|
121
|
+
const conditions = useContext(PromptConditions);
|
|
122
|
+
const [isPrivate, setIsPrivate] = useState(false);
|
|
123
|
+
const [when, setWhen] = useState(null);
|
|
124
|
+
useEffect(() => editor.registerUpdateListener(({ editorState }) => {
|
|
125
|
+
editorState.read(() => {
|
|
126
|
+
const selection = $getSelection();
|
|
127
|
+
const isRange = $isRangeSelection(selection);
|
|
128
|
+
setIsPrivate(isRange &&
|
|
129
|
+
$getSelectionStyleValueForProperty(selection, PRIVATE_NAME, '') === PRIVATE_ON);
|
|
130
|
+
const block = isRange ? $blockOf($topOf(selection.anchor.getNode())) : null;
|
|
131
|
+
setWhen($headOf(block)?.getWhen() ?? null);
|
|
132
|
+
});
|
|
133
|
+
}), [editor]);
|
|
134
|
+
return (_jsxs(_Fragment, { children: [_jsx(ToggleButton, { label: "Private", tooltip: PRIVATE_HINT, size: "sm", isIconOnly: true, icon: _jsx(Icon, { icon: IconShareOff, size: "sm" }), isPressed: isPrivate, onMouseDown: keepSelection, onPressedChange: () => {
|
|
135
|
+
editor.update(() => {
|
|
136
|
+
const selection = $getSelection();
|
|
137
|
+
if (!$isRangeSelection(selection))
|
|
138
|
+
return;
|
|
139
|
+
$patchStyleText(selection, { [PRIVATE_NAME]: isPrivate ? null : PRIVATE_ON });
|
|
140
|
+
});
|
|
141
|
+
} }), conditions.length > 0 && (_jsx(DropdownMenu, { label: "Condition", renderTrigger: (props) => (_jsx(ToggleButton, { ...props, label: "Condition", tooltip: "Send this part only on turns where a condition fits", size: "sm", isIconOnly: true, icon: _jsx(Icon, { icon: IconFilter, size: "sm" }), isPressed: Boolean(when), onMouseDown: keepSelection })), items: conditionItems(conditions, when, (next) => {
|
|
142
|
+
editor.update(() => {
|
|
143
|
+
$setCondition(next);
|
|
144
|
+
});
|
|
145
|
+
}) }))] }));
|
|
146
|
+
}
|
|
147
|
+
/** Whether every word of a block is private. A block with some private words marks only those. */
|
|
148
|
+
function $isWhollyPrivate(block) {
|
|
149
|
+
if (!block || $isPromptLine(block) || !$isElementNode(block))
|
|
150
|
+
return false;
|
|
151
|
+
const words = block.getAllTextNodes().filter((text) => text.getTextContent().trim() !== '');
|
|
152
|
+
return words.length > 0 && words.every((text) => text.getStyle().includes(PRIVATE_NAME));
|
|
153
|
+
}
|
|
154
|
+
/** Blocks that are wholly private run together, marked at the top of the run. */
|
|
155
|
+
function PrivateRuns() {
|
|
156
|
+
const [editor] = useLexicalComposerContext();
|
|
157
|
+
useEffect(() => editor.registerUpdateListener(({ editorState }) => {
|
|
158
|
+
editorState.read(() => {
|
|
159
|
+
for (const block of $getRoot().getChildren()) {
|
|
160
|
+
const whole = $isWhollyPrivate(block);
|
|
161
|
+
const element = editor.getElementByKey(block.getKey());
|
|
162
|
+
element?.toggleAttribute('data-private', whole);
|
|
163
|
+
element?.toggleAttribute('data-private-start', whole && !$isWhollyPrivate(block.getPreviousSibling()));
|
|
164
|
+
element?.toggleAttribute('data-private-end', whole && !$isWhollyPrivate(block.getNextSibling()));
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
}), [editor]);
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
/** What the pointer rests on, if it is private: the whole block, or else the words. */
|
|
171
|
+
const privateUnder = (target) => target instanceof Element
|
|
172
|
+
? (target.closest('[data-private]') ?? target.closest('[style*="--private"]'))
|
|
173
|
+
: null;
|
|
174
|
+
/**
|
|
175
|
+
* One tooltip for the editor's parts that can't hold their own.
|
|
176
|
+
* why: Lexical owns the blocks' elements and the toolbar package its buttons, so it anchors to a
|
|
177
|
+
* span of its own, moved over what it speaks of.
|
|
178
|
+
*/
|
|
179
|
+
function useEditorHint() {
|
|
180
|
+
const anchor = useRef(null);
|
|
181
|
+
const waiting = useRef(undefined);
|
|
182
|
+
const [shown, setShown] = useState(null);
|
|
183
|
+
const hide = useCallback(() => {
|
|
184
|
+
clearTimeout(waiting.current);
|
|
185
|
+
setShown(null);
|
|
186
|
+
}, []);
|
|
187
|
+
const show = useCallback((text, { left, top, width, height }) => {
|
|
188
|
+
hide();
|
|
189
|
+
const box = anchor.current?.offsetParent?.getBoundingClientRect();
|
|
190
|
+
if (!box)
|
|
191
|
+
return;
|
|
192
|
+
waiting.current = setTimeout(() => {
|
|
193
|
+
const place = { left: left - box.left, top: top - box.top, width, height };
|
|
194
|
+
setShown({ text, place });
|
|
195
|
+
}, HINT_DELAY_MS);
|
|
196
|
+
}, [hide]);
|
|
197
|
+
useEffect(() => hide, [hide]);
|
|
198
|
+
const hint = (_jsxs(_Fragment, { children: [_jsx("span", { ref: anchor, className: "prompt-hint-anchor", style: shown?.place }), _jsx(Tooltip, { anchorRef: anchor, content: shown?.text, isOpen: shown !== null })] }));
|
|
199
|
+
return { hint, show, hide };
|
|
200
|
+
}
|
|
201
|
+
/** What the toolbar's control under the pointer says, for the controls that say nothing. */
|
|
202
|
+
function toolbarHint(control) {
|
|
203
|
+
if (control.matches('.astryx-selector'))
|
|
204
|
+
return BLOCK_HINT;
|
|
205
|
+
const label = control.getAttribute('aria-label');
|
|
206
|
+
return label && FORMAT_LABELS.has(label) ? label : undefined;
|
|
207
|
+
}
|
|
208
|
+
/** The hover of the toolbar's own buttons, which the package leaves without a tooltip. */
|
|
209
|
+
function toolbarHovers({ show, hide }) {
|
|
210
|
+
let over = null;
|
|
211
|
+
return {
|
|
212
|
+
onMouseOver: (event) => {
|
|
213
|
+
const control = event.target instanceof Element ? event.target.closest('.astryx-selector, button') : null;
|
|
214
|
+
if (control === over)
|
|
215
|
+
return;
|
|
216
|
+
over = control;
|
|
217
|
+
hide();
|
|
218
|
+
const text = control && toolbarHint(control);
|
|
219
|
+
if (control && text)
|
|
220
|
+
show(text, control.getBoundingClientRect());
|
|
221
|
+
},
|
|
222
|
+
onMouseLeave: () => {
|
|
223
|
+
over = null;
|
|
224
|
+
hide();
|
|
225
|
+
},
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
/** Says what private text is, at the pointer. */
|
|
229
|
+
function PrivateHint({ show, hide }) {
|
|
230
|
+
const [editor] = useLexicalComposerContext();
|
|
231
|
+
useEffect(() => {
|
|
232
|
+
let over = null;
|
|
233
|
+
const move = (event) => {
|
|
234
|
+
const under = privateUnder(event.target);
|
|
235
|
+
if (under === over)
|
|
236
|
+
return;
|
|
237
|
+
over = under;
|
|
238
|
+
hide();
|
|
239
|
+
if (!under)
|
|
240
|
+
return;
|
|
241
|
+
show(PRIVATE_HINT, { left: event.clientX, top: event.clientY, width: 1, height: 1 });
|
|
242
|
+
};
|
|
243
|
+
let stop = () => { };
|
|
244
|
+
const unregister = editor.registerRootListener((root) => {
|
|
245
|
+
stop();
|
|
246
|
+
stop = () => { };
|
|
247
|
+
if (!root)
|
|
248
|
+
return;
|
|
249
|
+
const page = root.ownerDocument;
|
|
250
|
+
// why: the root's mouseleave fires while the pointer rests on its text.
|
|
251
|
+
page.addEventListener('mousemove', move);
|
|
252
|
+
root.addEventListener('mousedown', hide);
|
|
253
|
+
root.addEventListener('keydown', hide);
|
|
254
|
+
stop = () => {
|
|
255
|
+
page.removeEventListener('mousemove', move);
|
|
256
|
+
root.removeEventListener('mousedown', hide);
|
|
257
|
+
root.removeEventListener('keydown', hide);
|
|
258
|
+
};
|
|
259
|
+
});
|
|
260
|
+
return () => {
|
|
261
|
+
unregister();
|
|
262
|
+
stop();
|
|
263
|
+
};
|
|
264
|
+
}, [editor, show, hide]);
|
|
265
|
+
return null;
|
|
266
|
+
}
|
|
267
|
+
/** The caret stays where it was through the dialog that holds a change. */
|
|
268
|
+
function HeldCaret() {
|
|
269
|
+
const [editor] = useLexicalComposerContext();
|
|
270
|
+
const isChangeHeld = useContext(ChangeHeld);
|
|
271
|
+
const caret = useRef(null);
|
|
272
|
+
useEffect(() => {
|
|
273
|
+
if (isChangeHeld) {
|
|
274
|
+
caret.current = editor.getEditorState().read(() => $getSelection()?.clone() ?? null);
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
const held = caret.current;
|
|
278
|
+
caret.current = null;
|
|
279
|
+
if (held) {
|
|
280
|
+
editor.update(() => {
|
|
281
|
+
$setSelection(held);
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
}, [editor, isChangeHeld]);
|
|
285
|
+
return null;
|
|
286
|
+
}
|
|
287
|
+
function OpenedEditor({ opened, placeholder, status, onEdit, }) {
|
|
288
|
+
const [doc] = useState(() => openedDoc(opened));
|
|
289
|
+
const hint = useEditorHint();
|
|
290
|
+
const [hovers] = useState(() => toolbarHovers(hint));
|
|
291
|
+
return (_jsxs("div", { className: "prompt-editor", children: [hint.hint, _jsx(RichTextEditor, { label: "Prompt", isLabelHidden: true, width: "100%", size: "sm", minHeight: MIN_HEIGHT, placeholder: placeholder, status: status, defaultValue: doc, nodes: NODES, toolbar: _jsx(RichTextEditorToolbar, { size: "sm", hasLink: false, endContent: _jsx(PromptTools, {}), ...hovers }), plugins: _jsxs(_Fragment, { children: [_jsx(PrivateRuns, {}), _jsx(PrivateHint, { ...hint }), _jsx(HeldCaret, {})] }), onChange: (state) => {
|
|
292
|
+
onEdit(promptMarkup(JSON.stringify(state.toJSON())));
|
|
293
|
+
} })] }));
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* The prompt with its private stretches and conditions in view. It is a view of the markup text:
|
|
297
|
+
* it writes back only when the prompt changes, so opening it never dirties the draft, and text
|
|
298
|
+
* changed from outside (another profile, a reload, a kept source) opens afresh.
|
|
299
|
+
*/
|
|
300
|
+
export function PromptEditor({ value, placeholder, status, onChange }) {
|
|
301
|
+
const [held, setHeld] = useState(value);
|
|
302
|
+
const [opening, setOpening] = useState(0);
|
|
303
|
+
// why: a held change is still on screen; Change keeps it and the caret, Cancel reopens the prompt.
|
|
304
|
+
const isChangeHeld = useContext(ChangeHeld);
|
|
305
|
+
if (!isChangeHeld && !samePrompt(value, held)) {
|
|
306
|
+
setHeld(value);
|
|
307
|
+
setOpening(opening + 1);
|
|
308
|
+
}
|
|
309
|
+
return (_jsx(OpenedEditor, { opened: value, placeholder: placeholder, status: status, onEdit: (next) => {
|
|
310
|
+
if (samePrompt(next, held))
|
|
311
|
+
return;
|
|
312
|
+
setHeld(next);
|
|
313
|
+
onChange(next);
|
|
314
|
+
} }, opening));
|
|
315
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type DropdownMenuOption } from '@astryxdesign/core/DropdownMenu';
|
|
2
|
+
import { DecoratorNode, type LexicalNode, type NodeKey, type SerializedLexicalNode, type Spread } from 'lexical';
|
|
3
|
+
import { type ReactNode } from 'react';
|
|
4
|
+
import type { ConditionDraft } from '../draft.ts';
|
|
5
|
+
/** The conditions this profile declares, which the tokens' menus and the toolbar's offer. */
|
|
6
|
+
export declare const PromptConditions: import("react").Context<readonly ConditionDraft[]>;
|
|
7
|
+
export type SetWhen = (when: string | null) => void;
|
|
8
|
+
/** The menu of a line's `when`: one section per condition, with what it holds ticked. */
|
|
9
|
+
export declare function conditionItems(conditions: readonly ConditionDraft[], when: string | null, set: SetWhen): DropdownMenuOption[];
|
|
10
|
+
export type SerializedPromptLine = Spread<{
|
|
11
|
+
when?: string | null;
|
|
12
|
+
}, SerializedLexicalNode>;
|
|
13
|
+
/** Where a prompt line opens: the blocks after it, up to the next one, are that line's body. */
|
|
14
|
+
export declare class PromptLineNode extends DecoratorNode<ReactNode> {
|
|
15
|
+
__when: string | null;
|
|
16
|
+
static getType(): string;
|
|
17
|
+
static clone(node: PromptLineNode): PromptLineNode;
|
|
18
|
+
static importJSON(json: SerializedPromptLine): PromptLineNode;
|
|
19
|
+
constructor(when: string | null, key?: NodeKey);
|
|
20
|
+
exportJSON(): SerializedPromptLine;
|
|
21
|
+
getWhen(): string | null;
|
|
22
|
+
setWhen(when: string | null): this;
|
|
23
|
+
createDOM(): HTMLElement;
|
|
24
|
+
updateDOM(): boolean;
|
|
25
|
+
isInline(): boolean;
|
|
26
|
+
isKeyboardSelectable(): boolean;
|
|
27
|
+
decorate(): ReactNode;
|
|
28
|
+
}
|
|
29
|
+
export declare const $isPromptLine: (node: LexicalNode | null | undefined) => node is PromptLineNode;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { DropdownMenu } from '@astryxdesign/core/DropdownMenu';
|
|
3
|
+
import { Icon } from '@astryxdesign/core/Icon';
|
|
4
|
+
import { Token } from '@astryxdesign/core/Token';
|
|
5
|
+
import { Tooltip } from '@astryxdesign/core/Tooltip';
|
|
6
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
7
|
+
import { IconCheck, IconFilter } from '@tabler/icons-react';
|
|
8
|
+
import { $getNodeByKey, DecoratorNode, } from 'lexical';
|
|
9
|
+
import { createContext, useContext, useState } from 'react';
|
|
10
|
+
import { checksOf, PROMPT_LINE, withCheck, withoutCheck } from "../prompt-doc.js";
|
|
11
|
+
/** The conditions this profile declares, which the tokens' menus and the toolbar's offer. */
|
|
12
|
+
export const PromptConditions = createContext([]);
|
|
13
|
+
/** The menu of a line's `when`: one section per condition, with what it holds ticked. */
|
|
14
|
+
export function conditionItems(conditions, when, set) {
|
|
15
|
+
const have = checksOf(when);
|
|
16
|
+
return [
|
|
17
|
+
...(have.length > 0
|
|
18
|
+
? [
|
|
19
|
+
{
|
|
20
|
+
label: 'Remove condition',
|
|
21
|
+
onClick: () => {
|
|
22
|
+
set(null);
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
]
|
|
26
|
+
: []),
|
|
27
|
+
...conditions.map(({ name, values }) => ({
|
|
28
|
+
type: 'section',
|
|
29
|
+
title: name,
|
|
30
|
+
items: values.map((value) => ({
|
|
31
|
+
label: `${name} is ${value}`,
|
|
32
|
+
onClick: () => {
|
|
33
|
+
set(withCheck(when, name, value));
|
|
34
|
+
},
|
|
35
|
+
endContent: have.includes(`${name} is ${value}`) ? (_jsx(Icon, { icon: IconCheck, size: "sm" })) : undefined,
|
|
36
|
+
})),
|
|
37
|
+
})),
|
|
38
|
+
];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* One check of a line's `when`.
|
|
42
|
+
* why: the menu opens from its own state, since a press-open needs a real button and Token's root
|
|
43
|
+
* is a span.
|
|
44
|
+
*/
|
|
45
|
+
function CheckToken({ check, when, set }) {
|
|
46
|
+
const conditions = useContext(PromptConditions);
|
|
47
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
48
|
+
return (_jsx(DropdownMenu, { label: check, isMenuOpen: isOpen, onOpenChange: setIsOpen, items: conditionItems(conditions, when, set), renderTrigger: ({ ref, id }) => (_jsx(Tooltip, { content: `Sent only on turns where ${when ?? check}. Press to change it.`, children: _jsx(Token, { ref: ref, id: id, size: "sm", label: check, icon: _jsx(Icon, { icon: IconFilter, size: "xsm" }), "aria-haspopup": "menu", "aria-expanded": isOpen, onClick: () => {
|
|
49
|
+
setIsOpen(!isOpen);
|
|
50
|
+
}, onRemove: () => {
|
|
51
|
+
set(withoutCheck(when, check));
|
|
52
|
+
} }) })) }));
|
|
53
|
+
}
|
|
54
|
+
function LineHead({ nodeKey, when }) {
|
|
55
|
+
const [editor] = useLexicalComposerContext();
|
|
56
|
+
const set = (next) => {
|
|
57
|
+
editor.update(() => {
|
|
58
|
+
const node = $getNodeByKey(nodeKey);
|
|
59
|
+
if ($isPromptLine(node))
|
|
60
|
+
node.setWhen(next);
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
const checks = checksOf(when);
|
|
64
|
+
if (checks.length === 0)
|
|
65
|
+
return null;
|
|
66
|
+
return (_jsx("div", { className: "prompt-line-head", contentEditable: false, children: checks.map((check) => (_jsx(CheckToken, { check: check, when: when, set: set }, check))) }));
|
|
67
|
+
}
|
|
68
|
+
/** Where a prompt line opens: the blocks after it, up to the next one, are that line's body. */
|
|
69
|
+
export class PromptLineNode extends DecoratorNode {
|
|
70
|
+
__when;
|
|
71
|
+
static getType() {
|
|
72
|
+
return PROMPT_LINE;
|
|
73
|
+
}
|
|
74
|
+
static clone(node) {
|
|
75
|
+
return new PromptLineNode(node.__when, node.__key);
|
|
76
|
+
}
|
|
77
|
+
static importJSON(json) {
|
|
78
|
+
return new PromptLineNode(json.when ?? null);
|
|
79
|
+
}
|
|
80
|
+
constructor(when, key) {
|
|
81
|
+
super(key);
|
|
82
|
+
this.__when = when;
|
|
83
|
+
}
|
|
84
|
+
exportJSON() {
|
|
85
|
+
return { type: PROMPT_LINE, version: 1, when: this.__when };
|
|
86
|
+
}
|
|
87
|
+
getWhen() {
|
|
88
|
+
return this.getLatest().__when;
|
|
89
|
+
}
|
|
90
|
+
setWhen(when) {
|
|
91
|
+
this.getWritable().__when = when;
|
|
92
|
+
return this;
|
|
93
|
+
}
|
|
94
|
+
createDOM() {
|
|
95
|
+
const slot = document.createElement('div');
|
|
96
|
+
slot.className = 'prompt-line-slot';
|
|
97
|
+
return slot;
|
|
98
|
+
}
|
|
99
|
+
updateDOM() {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
isInline() {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
isKeyboardSelectable() {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
decorate() {
|
|
109
|
+
return _jsx(LineHead, { nodeKey: this.getKey(), when: this.getWhen() });
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
export const $isPromptLine = (node) => node instanceof PromptLineNode;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ConditionDraft } from '../draft.ts';
|
|
2
|
+
/** A profile's prompt: formatted, or as code, which is all a prompt the view can't hold can be. */
|
|
3
|
+
export declare function PromptRow({ value, conditions, rows, placeholder, onChange, }: {
|
|
4
|
+
value: string;
|
|
5
|
+
conditions: readonly ConditionDraft[];
|
|
6
|
+
rows: number;
|
|
7
|
+
placeholder?: string;
|
|
8
|
+
onChange: (next: string) => void;
|
|
9
|
+
}): import("react").JSX.Element;
|
package/ui/prompt-row.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Icon } from '@astryxdesign/core/Icon';
|
|
3
|
+
import { ToggleButton } from '@astryxdesign/core/ToggleButton';
|
|
4
|
+
import { IconCode, IconEye } from '@tabler/icons-react';
|
|
5
|
+
import { useDeferredValue, useMemo, useState } from 'react';
|
|
6
|
+
import { promptDocProblem } from "../prompt-doc.js";
|
|
7
|
+
import { TextAreaRow, useFieldRow, WideRow } from "./inspector.js";
|
|
8
|
+
import { PromptEditor } from "./prompt-editor.js";
|
|
9
|
+
import { PromptConditions } from "./prompt-line-node.js";
|
|
10
|
+
const PATH = 'identity.system';
|
|
11
|
+
/** A profile's prompt: formatted, or as code, which is all a prompt the view can't hold can be. */
|
|
12
|
+
export function PromptRow({ value, conditions, rows, placeholder, onChange, }) {
|
|
13
|
+
const row = { label: 'Prompt', path: PATH, field: 'system' };
|
|
14
|
+
const { status, required } = useFieldRow(row);
|
|
15
|
+
const [wantsCode, setWantsCode] = useState(false);
|
|
16
|
+
// why: the check converts the whole prompt, and a long one mustn't slow each keystroke.
|
|
17
|
+
const settled = useDeferredValue(value);
|
|
18
|
+
const problem = useMemo(() => promptDocProblem(settled), [settled]);
|
|
19
|
+
const isCode = wantsCode || problem !== undefined;
|
|
20
|
+
const toggle = (_jsx(ToggleButton, { label: "Code", tooltip: problem ?? (isCode ? 'Show formatted' : 'Show code'), size: "sm", isIconOnly: true, isDisabled: problem !== undefined, icon: _jsx(Icon, { icon: IconEye, size: "sm" }), pressedIcon: _jsx(Icon, { icon: IconCode, size: "sm" }), isPressed: isCode, onPressedChange: setWantsCode }));
|
|
21
|
+
if (isCode) {
|
|
22
|
+
return (_jsx(TextAreaRow, { ...row, rows: rows, value: value, placeholder: placeholder, status: problem ? { type: 'warning', message: problem } : undefined, action: toggle, onChange: onChange }));
|
|
23
|
+
}
|
|
24
|
+
return (_jsx(WideRow, { label: row.label, path: row.path, isRequired: required, hasIssue: status !== undefined, action: toggle, children: _jsx(PromptConditions.Provider, { value: conditions, children: _jsx(PromptEditor, { value: value, placeholder: placeholder, status: status, onChange: onChange }) }) }));
|
|
25
|
+
}
|
package/ui/provider-editor.js
CHANGED
|
@@ -6,6 +6,7 @@ import { TextInput } from '@astryxdesign/core/TextInput';
|
|
|
6
6
|
import { VStack } from '@astryxdesign/core/VStack';
|
|
7
7
|
import { useState } from 'react';
|
|
8
8
|
import { connectionFields, kernelDefinitions, providerUse, takesKey, } from "../mod.js";
|
|
9
|
+
import { SECTION_HINTS } from "../section-notes.js";
|
|
9
10
|
import { ChoiceRow, InspectorRow, InspectorSection, SetInCode, TextRow } from "./inspector.js";
|
|
10
11
|
import { NodeIssues } from "./inspector-context.js";
|
|
11
12
|
import { IssueBanners, SlotRow } from "./profile-editor.js";
|
|
@@ -80,7 +81,7 @@ export function ProviderEditor({ workspace, provider, issues, onChange, onRename
|
|
|
80
81
|
const fields = held && [...held, ...extra].filter((field) => onChange || provider.connection?.[field.name]);
|
|
81
82
|
// A definition that signs in with no key reads no slot; one set anyway still shows, so its issue can be cleared.
|
|
82
83
|
const slots = ['keySlot', 'fallbackKeySlot'].filter((slot) => provider[slot] || (onChange && takesKey(provider.definition)));
|
|
83
|
-
const rows = (_jsxs(_Fragment, { children: [fields === undefined ? (_jsx(InspectorSection, { title: "Connection", note: "Its definition is the project's own, so what it connects with is the definition's to say.", children: null })) : (fields.length > 0 && (_jsx(InspectorSection, { title: "Connection", children: fields.map((field) => (_jsx(TextRow, { label: settingLabel(field.name), path: `connection.${field.name}`, field: `connection.${field.name}`, isRequired: field.required, value: provider.connection?.[field.name] ?? '', placeholder: field.url ? 'https://' : undefined, onChange: (value) => {
|
|
84
|
+
const rows = (_jsxs(_Fragment, { children: [fields === undefined ? (_jsx(InspectorSection, { title: "Connection", note: "Its definition is the project's own, so what it connects with is the definition's to say.", children: null })) : (fields.length > 0 && (_jsx(InspectorSection, { title: "Connection", hint: SECTION_HINTS.connection, children: fields.map((field) => (_jsx(TextRow, { label: settingLabel(field.name), path: `connection.${field.name}`, field: `connection.${field.name}`, isRequired: field.required, value: provider.connection?.[field.name] ?? '', placeholder: field.url ? 'https://' : undefined, onChange: (value) => {
|
|
84
85
|
set(withConnection(provider, field.name, value.trim()));
|
|
85
86
|
} }, field.name))) }))), slots.length > 0 && (_jsx(InspectorSection, { title: "Keys", note: "The slots its models read their key from, unless a model names its own.", children: slots.map((slot) => (_jsx(SlotRow, { label: slot === 'keySlot' ? 'Key slot' : 'Fallback slot', path: slot, field: slot, value: provider[slot] ?? '', onChange: (next) => {
|
|
86
87
|
set(withText(provider, slot, next));
|
package/ui/studio-compare.js
CHANGED
|
@@ -177,7 +177,7 @@ export function SavedSlot({ isShown, hasDivider, children, }) {
|
|
|
177
177
|
}, [isShown]);
|
|
178
178
|
if (!children || !(isShown || isMounted))
|
|
179
179
|
return null;
|
|
180
|
-
return (_jsxs("div", { ref: slot, className: "studio-saved-slot", "data-moved": hasMoved ? '' : undefined, "data-closed": isShown ? undefined : '', "aria-hidden": isShown ? undefined : true, children: [_jsx("div", { className: "studio-saved-slot-side", children: children }), hasDivider && _jsx(Divider, { orientation: "vertical" })] }));
|
|
180
|
+
return (_jsxs("div", { ref: slot, className: "studio-saved-slot", "data-moved": hasMoved ? '' : undefined, "data-closed": isShown ? undefined : '', "aria-hidden": isShown ? undefined : true, inert: !isShown, children: [_jsx("div", { className: "studio-saved-slot-side", children: children }), hasDivider && _jsx(Divider, { orientation: "vertical" })] }));
|
|
181
181
|
}
|
|
182
182
|
/**
|
|
183
183
|
* The files' side: its run, and while the edits sit beside it, its title and the way to put it
|
|
@@ -536,6 +536,14 @@ function openSides(pair) {
|
|
|
536
536
|
return chat && state ? [{ side, chat, state }] : [];
|
|
537
537
|
});
|
|
538
538
|
}
|
|
539
|
+
/** Which sides show now, whether one message goes to both, and the one it goes to otherwise. */
|
|
540
|
+
function useShownSides({ inFiles, isEditing, isShared }) {
|
|
541
|
+
const isSavedHidden = useSavedHidden();
|
|
542
|
+
const showsSaved = inFiles && !(isEditing && isSavedHidden);
|
|
543
|
+
const both = isShared && showsSaved;
|
|
544
|
+
const only = both ? undefined : showsSaved ? 'saved' : 'edited';
|
|
545
|
+
return { showsSaved, isShared: both, only };
|
|
546
|
+
}
|
|
539
547
|
/**
|
|
540
548
|
* A project's text or image profile, run by the studio's local server. While the builder has
|
|
541
549
|
* edits the files do not hold, one message is answered twice, side by side: by the files, and by
|
|
@@ -547,10 +555,7 @@ export function ProjectChat(props) {
|
|
|
547
555
|
const view = useComparison(props);
|
|
548
556
|
const { pair, isBusy, transports, refused, isReady } = view;
|
|
549
557
|
const loadedStated = useLoadedStated(stated, isReady);
|
|
550
|
-
const
|
|
551
|
-
const showsSaved = view.inFiles && !(view.isEditing && isSavedHidden);
|
|
552
|
-
const isShared = view.isShared && showsSaved;
|
|
553
|
-
const only = isShared ? undefined : showsSaved ? 'saved' : 'edited';
|
|
558
|
+
const { showsSaved, isShared, only } = useShownSides(view);
|
|
554
559
|
const sharedInput = useRef(null);
|
|
555
560
|
useChatHandle(chatRef, pair, only, !isBusy && isReady, sharedInput);
|
|
556
561
|
const shared = openSides(pair);
|
|
@@ -570,7 +575,9 @@ export function ProjectChat(props) {
|
|
|
570
575
|
initialVoice,
|
|
571
576
|
initialPending,
|
|
572
577
|
};
|
|
573
|
-
return (_jsxs(VStack, { height: "100%", children: [_jsx(StackItem, { size: "fill", children: _jsxs(HStack, { height: "100%", children: [_jsx(SavedSlot, { isShown: showsSaved, hasDivider: view.isShared, children: view.inFiles && (_jsx(SavedSide, { isCompared: view.isEditing, children: _jsx(TheoremChat, { ...common,
|
|
578
|
+
return (_jsxs(VStack, { height: "100%", children: [_jsx(StackItem, { size: "fill", children: _jsxs(HStack, { height: "100%", children: [_jsx(SavedSlot, { isShown: showsSaved, hasDivider: view.isShared, children: view.inFiles && (_jsx(SavedSide, { isCompared: view.isEditing, children: _jsx(TheoremChat, { ...common,
|
|
579
|
+
// why: a side on its way out takes no message, or one sent now runs the files.
|
|
580
|
+
composer: showsSaved && !isShared, stated: savedStated, transport: transports.saved,
|
|
574
581
|
// A side that comes back starts from what it had said.
|
|
575
582
|
conversation: view.conversations.current.saved, onConversationChange: view.onChange.saved, chatRef: pair.refs.saved }) })) }), view.isEditing && (_jsx("div", { className: "studio-edited-slot", children: _jsx(EditedSide, { refused: refused, isLoading: !transports.edited && !refused, hasSaved: view.inFiles, children: transports.edited && (_jsx(TheoremChat, { ...common, stated: loadedStated,
|
|
576
583
|
// A new load is a new transport: the chat reads it in place and keeps its transcript.
|
package/ui/studio-save.js
CHANGED
|
@@ -207,9 +207,9 @@ function ProjectProblems({ project, unloaded }) {
|
|
|
207
207
|
const { copy, isCopied } = useClipboard();
|
|
208
208
|
if (!count)
|
|
209
209
|
return null;
|
|
210
|
-
return (_jsx(HoverCard, { label: "What the studio cannot run or shows differently", touchTrigger: "tap", content: _jsx(ScrollableArea, { label: "What the studio cannot run or shows differently", width: ALERTS_WIDTH, style: { maxHeight: ALERTS_MAX_HEIGHT }, children: _jsxs(VStack, { gap: 3,
|
|
211
|
-
|
|
212
|
-
|
|
210
|
+
return (_jsx(HoverCard, { label: "What the studio cannot run or shows differently", touchTrigger: "tap", content: _jsx(ScrollableArea, { label: "What the studio cannot run or shows differently", width: ALERTS_WIDTH, style: { maxHeight: ALERTS_MAX_HEIGHT }, children: _jsxs(VStack, { gap: 3, className: "studio-alerts", children: [_jsx(IconButton, { label: isCopied ? 'Copied' : 'Copy alerts', variant: "ghost", size: "sm", icon: _jsx(Icon, { icon: isCopied ? IconCheck : IconCopy, size: "sm" }), tooltip: "Copy these alerts to send", onClick: () => {
|
|
211
|
+
copy(alertsReport(project, unloaded));
|
|
212
|
+
} }), unloaded !== undefined && (_jsxs(VStack, { gap: 1, children: [_jsx(Text, { weight: "semibold", children: "The studio cannot load your files." }), _jsx(Text, { type: "supporting", color: "secondary", children: "It runs them as they last loaded, until they load again." }), _jsx(CodeBlock, { code: unloaded.trim(), size: "sm", isWrapped: true, maxHeight: 240, hasCopyButton: false })] })), problems.map((problem) => (_jsxs(VStack, { gap: 1, children: [_jsx(Text, { weight: "semibold", children: `The studio cannot run ${problem.profile}.` }), _jsx(Text, { type: "supporting", color: "secondary", children: problem.message })] }, problem.profile))), modelProblems.map((problem) => (_jsxs(VStack, { gap: 1, children: [_jsx(Text, { weight: "semibold", children: `As your files set it, ${problem.profile}'s model '${problem.model}' cannot run.` }), _jsx(Text, { type: "supporting", color: "secondary", children: problem.message })] }, `${problem.profile}:${problem.model}`))), unregistered.length > 0 && (_jsxs(VStack, { gap: 1, children: [_jsx(Text, { weight: "semibold", children: "Your project did not register everything its files define." }), _jsx(Text, { type: "supporting", color: "secondary", children: `${unregistered.length} defined in your files but not registered when the project started, so the studio cannot show them: ${unregistered
|
|
213
213
|
.slice(0, 5)
|
|
214
214
|
.map((each) => each.name)
|
|
215
215
|
.join(', ')}${unregistered.length > 5 ? `, and ${unregistered.length - 5} more` : ''}. A run and Save still use your files. If none of them load, the studio is probably reading a second copy of the Theorem package.` })] })), unheld.length > 0 && (_jsxs(VStack, { gap: 1, children: [_jsx(Text, { weight: "semibold", children: "The studio cannot check what it shows against your files." }), _jsx(Text, { type: "supporting", color: "secondary", children: `A run and Save still use your files. ${[...new Set(unheld)].join(' ')}${unregistered.length > 0 ? ' This usually follows from the profiles above not loading.' : ''}` })] })), differences.map((difference) => (_jsxs(VStack, { gap: 1, children: [_jsx(Text, { weight: "semibold", children: `The studio shows ${difference.of} differently from your files.` }), _jsx(Text, { type: "supporting", color: "secondary", children: `${difference.settings.length} ${difference.settings.length === 1 ? 'setting differs' : 'settings differ'}: ${settingAreas(difference.settings)}. A run and Save still use your files.` })] }, `${difference.kind}:${difference.of}`)))] }) }), children: _jsx(Token, { label: count === 1 ? '1 alert' : `${String(count)} alerts`, color: "orange" }) }));
|
package/ui/studio-screen.js
CHANGED
|
@@ -34,7 +34,7 @@ import { createContext, lazy, memo, Suspense, useCallback, useContext, useEffect
|
|
|
34
34
|
import { flushSync } from 'react-dom';
|
|
35
35
|
import { ActingAsButton } from "./acting-as-button.js";
|
|
36
36
|
import { AddProviderButton } from "./add-provider.js";
|
|
37
|
-
import { GuardrailTest, ISSUE_ROW_ATTRIBUTE, LeavePage, ListBadges, LocalConnection, ProbedAgent, QuestionLink, RowOrigins, RunsOn, WorkspaceContext, } from "./inspector-context.js";
|
|
37
|
+
import { ChangeHeld, GuardrailTest, ISSUE_ROW_ATTRIBUTE, LeavePage, ListBadges, LocalConnection, ProbedAgent, QuestionLink, RowOrigins, RunsOn, WorkspaceContext, } from "./inspector-context.js";
|
|
38
38
|
import { ActingAsContext, chatKeyOf, useActingAsState } from "./lib/acting-as.js";
|
|
39
39
|
import { runsAsConversation } from "./lib/conversation-types.js";
|
|
40
40
|
import { FACET_ICON } from "./lib/facet-icons.js";
|
|
@@ -1767,22 +1767,24 @@ function EditorBody({ state, connection, selected, editing, issues, listBadges,
|
|
|
1767
1767
|
const { workspace, draft, focus, setDraft, update } = state;
|
|
1768
1768
|
const project = useProject();
|
|
1769
1769
|
const workspaceContext = useWorkspaceContext(workspace.agents, focus, update, project !== null);
|
|
1770
|
+
const heldNow = () => state.store.getPending() !== undefined;
|
|
1771
|
+
const isChangeHeld = useSyncExternalStore(state.store.subscribe, heldNow, heldNow);
|
|
1770
1772
|
const provider = shownProvider(workspace, editing, project !== null, connection);
|
|
1771
|
-
return (_jsx(ScrollableArea, { label: "Editor", height: "100%", ref: editorRef, children: _jsx(ListBadges, { value: listBadges, children: _jsx(RunsOn.Provider, { value: connection.on, children: _jsx(LocalConnection.Provider, { value: connection, children: _jsx(WorkspaceContext.Provider, { value: workspaceContext, children: provider ? (_jsx(ProviderEditor, { workspace: workspace, provider: provider, issues: issues.filter((issue) => issue.nodeId === editing),
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1773
|
+
return (_jsx(ScrollableArea, { label: "Editor", height: "100%", ref: editorRef, children: _jsx(ListBadges, { value: listBadges, children: _jsx(RunsOn.Provider, { value: connection.on, children: _jsx(LocalConnection.Provider, { value: connection, children: _jsx(WorkspaceContext.Provider, { value: workspaceContext, children: _jsx(ChangeHeld.Provider, { value: isChangeHeld, children: provider ? (_jsx(ProviderEditor, { workspace: workspace, provider: provider, issues: issues.filter((issue) => issue.nodeId === editing),
|
|
1774
|
+
// The studio's own providers are the same for everyone, so they only show.
|
|
1775
|
+
onChange: project
|
|
1776
|
+
? (next) => {
|
|
1777
|
+
update((current) => withProvider(current, next));
|
|
1778
|
+
}
|
|
1779
|
+
: undefined,
|
|
1780
|
+
// A provider the files do not hold yet is the studio's to name; code names the rest.
|
|
1781
|
+
onRename: project && !project.providers.includes(provider.id)
|
|
1782
|
+
? (id) => {
|
|
1783
|
+
update((current) => renameProvider(current, provider.id, id));
|
|
1784
|
+
}
|
|
1785
|
+
: undefined })) : (_jsx(ProfileEditor, { draft: draft, setDraft: setDraft, selectedId: editing, onSelect: (id) => {
|
|
1786
|
+
open(scopedNodeId(focus, id));
|
|
1787
|
+
}, issues: issues })) }) }) }) }) }) }, selected));
|
|
1786
1788
|
}
|
|
1787
1789
|
/** Clears the conversation and its traces; the profile stays. */
|
|
1788
1790
|
function ClearHistoryButton({ onClear }) {
|
package/ui/studio-theme.d.ts
CHANGED
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
* extends this one, so the studio looks the same on the website and on its own.
|
|
5
5
|
* `npm --prefix studio run theme:build` compiles it to `built/`, which is what a page imports.
|
|
6
6
|
*/
|
|
7
|
-
export declare const studioTheme: import("@astryxdesign/core
|
|
7
|
+
export declare const studioTheme: import("@astryxdesign/core").ResolvedDefinedTheme;
|