codeassembly-agent-logic 0.9.0 → 0.10.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.
Files changed (52) hide show
  1. package/.meta/changelog.json +57 -0
  2. package/CHANGELOG.md +14 -0
  3. package/README.md +34 -21
  4. package/dist/esm/index.d.ts +5 -1
  5. package/dist/esm/index.js +1 -0
  6. package/dist/esm/react/canvas/CanvasKey.d.ts +38 -0
  7. package/dist/esm/react/canvas/CanvasKey.js +33 -0
  8. package/dist/esm/react/hooks/document-types.d.ts +72 -0
  9. package/dist/esm/react/hooks/document-types.js +3 -0
  10. package/dist/esm/react/hooks/file-location.d.ts +10 -0
  11. package/dist/esm/react/hooks/file-location.js +19 -0
  12. package/dist/esm/react/hooks/label-source.js +2 -1
  13. package/dist/esm/react/hooks/load-messages.d.ts +2 -0
  14. package/dist/esm/react/hooks/load-messages.js +3 -0
  15. package/dist/esm/react/hooks/read-document.d.ts +48 -0
  16. package/dist/esm/react/hooks/read-document.js +88 -0
  17. package/dist/esm/react/hooks/stored-base.d.ts +7 -0
  18. package/dist/esm/react/hooks/stored-base.js +8 -0
  19. package/dist/esm/react/hooks/stored-upload.d.ts +9 -0
  20. package/dist/esm/react/hooks/stored-upload.js +16 -0
  21. package/dist/esm/react/hooks/useDocumentState.d.ts +57 -0
  22. package/dist/esm/react/hooks/useDocumentState.js +151 -0
  23. package/dist/esm/react/index.d.ts +18 -1
  24. package/dist/esm/react/index.js +13 -0
  25. package/dist/esm/react/inspector/Inspector.d.ts +13 -0
  26. package/dist/esm/react/inspector/Inspector.js +58 -0
  27. package/dist/esm/react/messages/FindingList.d.ts +18 -0
  28. package/dist/esm/react/messages/FindingList.js +15 -0
  29. package/dist/esm/react/messages/GapList.d.ts +14 -0
  30. package/dist/esm/react/messages/GapList.js +18 -0
  31. package/dist/esm/react/messages/Messages.d.ts +29 -0
  32. package/dist/esm/react/messages/Messages.js +19 -0
  33. package/dist/esm/react/messages/SectionMessage.d.ts +10 -0
  34. package/dist/esm/react/messages/SectionMessage.js +8 -0
  35. package/dist/esm/react/messages/UnconvertedPassages.d.ts +15 -0
  36. package/dist/esm/react/messages/UnconvertedPassages.js +15 -0
  37. package/dist/esm/react/messages/abbreviate.d.ts +2 -0
  38. package/dist/esm/react/messages/abbreviate.js +5 -0
  39. package/dist/esm/react/messages/icons.d.ts +9 -0
  40. package/dist/esm/react/messages/icons.js +10 -0
  41. package/dist/esm/react/slots.d.ts +28 -0
  42. package/dist/esm/react/slots.js +1 -0
  43. package/dist/esm/react/source/SourceLine.d.ts +13 -0
  44. package/dist/esm/react/source/SourceLine.js +49 -0
  45. package/dist/esm/react/source/Workspace.d.ts +32 -0
  46. package/dist/esm/react/source/Workspace.js +22 -0
  47. package/dist/esm/react/source/build-connector.d.ts +39 -0
  48. package/dist/esm/react/source/build-connector.js +23 -0
  49. package/dist/esm/react/styles.css +445 -6
  50. package/dist/esm/schema/agent-logic-file-name.d.ts +4 -0
  51. package/dist/esm/schema/agent-logic-file-name.js +4 -0
  52. package/package.json +3 -2
@@ -0,0 +1,16 @@
1
+ import { AGENT_LOGIC_SUFFIX } from "../../schema/agent-logic-file-name.js";
2
+ import { dropLastExtension, sanitizeStoredBase } from "./stored-base.js";
3
+ export function buildStoredUploadName(origin, config) {
4
+ const base = origin.kind === 'file' ? findFileBase(origin.fileName) : dropSuffix(config.id);
5
+ return `${sanitizeStoredBase(base, FALLBACK_BASE)}${AGENT_LOGIC_SUFFIX}`;
6
+ }
7
+ export function buildStoredUploadText(value) {
8
+ return `${JSON.stringify(value, undefined, 2)}\n`;
9
+ }
10
+ const FALLBACK_BASE = 'agent';
11
+ function dropSuffix(name) {
12
+ return name.endsWith(AGENT_LOGIC_SUFFIX) ? name.slice(0, -AGENT_LOGIC_SUFFIX.length) : name;
13
+ }
14
+ function findFileBase(fileName) {
15
+ return fileName.endsWith(AGENT_LOGIC_SUFFIX) ? dropSuffix(fileName) : dropLastExtension(fileName);
16
+ }
@@ -0,0 +1,57 @@
1
+ import type { FileStore } from '@williamthorsen/toolbelt.text-file-store/proposed';
2
+ import type { Example } from '../../examples/examples.js';
3
+ import { type DocumentReport, type InputOrigin, type LoadFailure, type LoadOptions, type OpenDocument, type OtherDocument, type OtherKindHandlers } from './document-types.js';
4
+ export interface DocumentState<TOther extends OtherDocument = never> {
5
+ /** The open document; absent while the start page shows or a stored file is being read. */
6
+ document: OpenDocument<TOther> | undefined;
7
+ /** Whether a stored file is being read, during which the page shows neither a document nor the start page. */
8
+ isOpening: boolean;
9
+ /** The slug of the open example, which the sidebar marks as current. */
10
+ currentSlug: string | undefined;
11
+ /** The name of the open stored file, which the sidebar marks as current. */
12
+ currentFileName: string | undefined;
13
+ /** Whether the document region shows the Visualizations table, which the sidebar marks as current. */
14
+ isVisualizationsOpen: boolean;
15
+ report: DocumentReport | undefined;
16
+ unknownExample: string | undefined;
17
+ chooseExample: (example: Example) => void;
18
+ chooseStoredFile: (name: string) => void;
19
+ /** Writes the Upload card's text into the store and opens it as a chart, or returns why it did not load. */
20
+ loadText: (text: string, origin: InputOrigin, options?: LoadOptions) => Promise<LoadFailure | undefined>;
21
+ openStart: () => void;
22
+ openVisualizations: () => void;
23
+ /** Clears what a card's load makes stale: the unknown example's warning and a report on a document not opened. */
24
+ prepareLoad: () => void;
25
+ /**
26
+ * Writes a file into the store and opens the document that `buildDocument` returns at the file's URL, or returns
27
+ * what `fail` makes of a name that the store holds or a write that it refused.
28
+ */
29
+ storeAndOpen: (write: StoredWrite, fail: (failure: LoadFailure) => LoadFailure, buildDocument: (key: number) => OpenDocument<TOther>, options?: StoreAndOpenOptions) => Promise<LoadFailure | undefined>;
30
+ }
31
+ /**
32
+ * How `storeAndOpen` completes a write: `afterWrite` runs once the file is stored and returns a note that the
33
+ * announcement adds, and `entry` says whether the document takes a new history entry or the current one.
34
+ */
35
+ export interface StoreAndOpenOptions {
36
+ afterWrite?: (() => Promise<string | undefined>) | undefined;
37
+ entry?: 'push' | 'replace' | undefined;
38
+ }
39
+ /** A write into the store: the name, the text, and whether it overwrites a stored file of that name. */
40
+ export interface StoredWrite {
41
+ name: string;
42
+ text: string;
43
+ replace: boolean;
44
+ }
45
+ /**
46
+ * Owns what the document region shows, the start page, the Visualizations table, or one document, and keeps it in step
47
+ * with the URL and the browser's history. A stored file is read from `fileStore`, and a card's text is written into
48
+ * it. `announce` receives each announcement. `otherKind` opens stored text of a kind that the app defines, which the
49
+ * app stores through `storeAndOpen`; `announce` and `otherKind` keep their identity across renders. `notJsonHint` is
50
+ * added to the problems of Upload text that is not JSON.
51
+ */
52
+ export declare function useDocumentState<TOther extends OtherDocument = never>({ fileStore, announce, otherKind, notJsonHint, }: {
53
+ fileStore: FileStore;
54
+ announce: (text: string) => void;
55
+ otherKind?: OtherKindHandlers<TOther> | undefined;
56
+ notJsonHint?: string | undefined;
57
+ }): DocumentState<TOther>;
@@ -0,0 +1,151 @@
1
+ import { useCallback, useEffect, useRef, useState } from 'react';
2
+ import { describeNotLoaded } from "./describe-load-outcome.js";
3
+ import { isChartDocument, } from "./document-types.js";
4
+ import { buildExampleSearch } from "./example-location.js";
5
+ import { buildFileSearch, buildStartLocation, buildVisualizationsSearch } from "./file-location.js";
6
+ import { labelSource } from "./label-source.js";
7
+ import { describeConflict } from "./load-messages.js";
8
+ import { buildChartDocument, describeShown, isStartPageShown, readConfigText, readExample, readLocation, readStoredFile, } from "./read-document.js";
9
+ import { buildStoredUploadName, buildStoredUploadText } from "./stored-upload.js";
10
+ import { useUnknownExample } from "./useUnknownExample.js";
11
+ export function useDocumentState({ fileStore, announce, otherKind, notJsonHint, }) {
12
+ const [shown, setShown] = useState(() => readLocation(0));
13
+ const loadCount = useRef(0);
14
+ const navigationCount = useRef(0);
15
+ const { unknownExample, clearUnknownExample } = useUnknownExample(announce);
16
+ const show = useCallback((next, note) => {
17
+ navigationCount.current += 1;
18
+ setShown(next);
19
+ const text = [describeShown(next, otherKind), note].filter((part) => part !== undefined).join(' ');
20
+ if (text !== '')
21
+ announce(text);
22
+ }, [announce, otherKind]);
23
+ const showExample = useCallback((example) => {
24
+ loadCount.current += 1;
25
+ show(readExample(example, loadCount.current));
26
+ }, [show]);
27
+ const showStoredFile = useCallback(async (name) => {
28
+ navigationCount.current += 1;
29
+ const navigation = navigationCount.current;
30
+ setShown({ opening: name });
31
+ const read = await fileStore.read(name);
32
+ if (navigation !== navigationCount.current)
33
+ return;
34
+ loadCount.current += 1;
35
+ show(readStoredFile(name, read, loadCount.current, otherKind));
36
+ }, [fileStore, otherKind, show]);
37
+ const initialFile = useRef(shown.opening);
38
+ useEffect(() => {
39
+ if (initialFile.current !== undefined)
40
+ void showStoredFile(initialFile.current);
41
+ initialFile.current = undefined;
42
+ }, [showStoredFile]);
43
+ useEffect(() => {
44
+ function handlePopState() {
45
+ loadCount.current += 1;
46
+ const next = readLocation(loadCount.current);
47
+ if (next.opening === undefined)
48
+ show(next);
49
+ else
50
+ void showStoredFile(next.opening);
51
+ }
52
+ globalThis.addEventListener('popstate', handlePopState);
53
+ return () => {
54
+ globalThis.removeEventListener('popstate', handlePopState);
55
+ };
56
+ }, [show, showStoredFile]);
57
+ const chooseExample = useCallback((example) => {
58
+ const search = buildExampleSearch(example);
59
+ if (globalThis.location.search !== search)
60
+ globalThis.history.pushState(null, '', search);
61
+ clearUnknownExample();
62
+ showExample(example);
63
+ }, [clearUnknownExample, showExample]);
64
+ const chooseStoredFile = useCallback((name) => {
65
+ const search = buildFileSearch(name);
66
+ if (globalThis.location.search !== search)
67
+ globalThis.history.pushState(null, '', search);
68
+ clearUnknownExample();
69
+ void showStoredFile(name);
70
+ }, [clearUnknownExample, showStoredFile]);
71
+ const isStartPage = isStartPageShown(shown);
72
+ const openStart = useCallback(() => {
73
+ if (!isStartPage || globalThis.location.search !== '') {
74
+ globalThis.history.pushState(null, '', buildStartLocation());
75
+ }
76
+ clearUnknownExample();
77
+ navigationCount.current += 1;
78
+ setShown({});
79
+ }, [clearUnknownExample, isStartPage]);
80
+ const openVisualizations = useCallback(() => {
81
+ const search = buildVisualizationsSearch();
82
+ if (globalThis.location.search !== search)
83
+ globalThis.history.pushState(null, '', search);
84
+ clearUnknownExample();
85
+ show({ view: 'visualizations' });
86
+ }, [clearUnknownExample, show]);
87
+ const prepareLoad = useCallback(() => {
88
+ clearUnknownExample();
89
+ if (shown.report === undefined)
90
+ return;
91
+ navigationCount.current += 1;
92
+ setShown({});
93
+ }, [clearUnknownExample, shown.report]);
94
+ const storeAndOpen = useCallback(async (write, fail, buildDocument, { afterWrite, entry = 'push' } = {}) => {
95
+ const navigation = navigationCount.current;
96
+ const result = await fileStore.write(write.name, write.text, { replace: write.replace });
97
+ if (!result.ok) {
98
+ return fail(result.reason === 'exists'
99
+ ? { kind: 'conflict', name: write.name, problems: [{ path: '', message: describeConflict(write.name) }] }
100
+ : { kind: 'store', problems: result.problems });
101
+ }
102
+ const note = await afterWrite?.();
103
+ if (navigation !== navigationCount.current) {
104
+ if (note !== undefined)
105
+ announce(note);
106
+ return undefined;
107
+ }
108
+ const search = buildFileSearch(write.name);
109
+ if (entry === 'replace')
110
+ globalThis.history.replaceState(null, '', search);
111
+ else if (globalThis.location.search !== search)
112
+ globalThis.history.pushState(null, '', search);
113
+ loadCount.current += 1;
114
+ show({ document: buildDocument(loadCount.current) }, note);
115
+ return undefined;
116
+ }, [announce, fileStore, show]);
117
+ const loadText = useCallback(async (text, origin, options = {}) => {
118
+ prepareLoad();
119
+ const label = labelSource(origin);
120
+ function fail(failure) {
121
+ announce(describeNotLoaded(label.source, failure.problems));
122
+ return failure;
123
+ }
124
+ const read = readConfigText(text, origin.kind);
125
+ if (!read.ok) {
126
+ const { failure } = read;
127
+ const hint = failure.kind === 'not-json' && notJsonHint !== undefined ? [{ path: '', message: notJsonHint }] : [];
128
+ return fail({ ...failure, problems: [...failure.problems, ...hint] });
129
+ }
130
+ const { config, value } = read;
131
+ const name = buildStoredUploadName(origin, config);
132
+ return storeAndOpen({ name, text: buildStoredUploadText(value), replace: options.replace === true }, fail, (key) => buildChartDocument(name, config, key));
133
+ }, [announce, notJsonHint, prepareLoad, storeAndOpen]);
134
+ const { document, report, opening, view } = shown;
135
+ return {
136
+ document,
137
+ isOpening: opening !== undefined,
138
+ currentSlug: document !== undefined && isChartDocument(document) ? document.slug : undefined,
139
+ currentFileName: document?.fileName,
140
+ isVisualizationsOpen: view !== undefined,
141
+ report,
142
+ unknownExample,
143
+ chooseExample,
144
+ chooseStoredFile,
145
+ loadText,
146
+ openStart,
147
+ openVisualizations,
148
+ prepareLoad,
149
+ storeAndOpen,
150
+ };
151
+ }
@@ -1,19 +1,36 @@
1
- /** `./react` entry: the statechart canvas, the data of its key, the prompt pane, and the hooks of a chart's page. */
1
+ /**
2
+ * `./react` entry: the statechart canvas and its key, the prompt pane, the inspector, the source line, the workspace
3
+ * that composes them, the messages panel, the props of the app's button and link, the hooks of a chart's page, and the
4
+ * document hooks that open an example or a stored file.
5
+ */
2
6
  export * from './canvas/canvas-key-entries.js';
7
+ export * from './canvas/CanvasKey.js';
3
8
  export * from './canvas/list-chart-marks.js';
4
9
  export * from './canvas/marks.js';
5
10
  export * from './canvas/StatechartCanvas.js';
6
11
  export * from './hooks/describe-load-outcome.js';
12
+ export * from './hooks/document-types.js';
7
13
  export * from './hooks/download-config.js';
8
14
  export * from './hooks/example-location.js';
15
+ export * from './hooks/file-location.js';
9
16
  export * from './hooks/label-source.js';
17
+ export * from './hooks/load-messages.js';
10
18
  export * from './hooks/parse-config-text.js';
19
+ export * from './hooks/read-document.js';
20
+ export * from './hooks/stored-base.js';
21
+ export * from './hooks/stored-upload.js';
11
22
  export * from './hooks/useChartLayout.js';
12
23
  export * from './hooks/useConvertDraft.js';
24
+ export * from './hooks/useDocumentState.js';
13
25
  export * from './hooks/useDocumentTitle.js';
14
26
  export * from './hooks/useEscapeToClear.js';
15
27
  export * from './hooks/useSelection.js';
16
28
  export * from './hooks/useShowAmbient.js';
17
29
  export * from './hooks/useUnknownExample.js';
30
+ export * from './inspector/Inspector.js';
31
+ export * from './messages/Messages.js';
32
+ export * from './slots.js';
18
33
  export * from './source/PromptKey.js';
19
34
  export * from './source/PromptPane.js';
35
+ export * from './source/SourceLine.js';
36
+ export * from './source/Workspace.js';
@@ -1,18 +1,31 @@
1
1
  export * from "./canvas/canvas-key-entries.js";
2
+ export * from "./canvas/CanvasKey.js";
2
3
  export * from "./canvas/list-chart-marks.js";
3
4
  export * from "./canvas/marks.js";
4
5
  export * from "./canvas/StatechartCanvas.js";
5
6
  export * from "./hooks/describe-load-outcome.js";
7
+ export * from "./hooks/document-types.js";
6
8
  export * from "./hooks/download-config.js";
7
9
  export * from "./hooks/example-location.js";
10
+ export * from "./hooks/file-location.js";
8
11
  export * from "./hooks/label-source.js";
12
+ export * from "./hooks/load-messages.js";
9
13
  export * from "./hooks/parse-config-text.js";
14
+ export * from "./hooks/read-document.js";
15
+ export * from "./hooks/stored-base.js";
16
+ export * from "./hooks/stored-upload.js";
10
17
  export * from "./hooks/useChartLayout.js";
11
18
  export * from "./hooks/useConvertDraft.js";
19
+ export * from "./hooks/useDocumentState.js";
12
20
  export * from "./hooks/useDocumentTitle.js";
13
21
  export * from "./hooks/useEscapeToClear.js";
14
22
  export * from "./hooks/useSelection.js";
15
23
  export * from "./hooks/useShowAmbient.js";
16
24
  export * from "./hooks/useUnknownExample.js";
25
+ export * from "./inspector/Inspector.js";
26
+ export * from "./messages/Messages.js";
27
+ export * from "./slots.js";
17
28
  export * from "./source/PromptKey.js";
18
29
  export * from "./source/PromptPane.js";
30
+ export * from "./source/SourceLine.js";
31
+ export * from "./source/Workspace.js";
@@ -0,0 +1,13 @@
1
+ import type { ComponentType, ReactElement } from 'react';
2
+ import { type ConfigDescription, type ElementDescription } from '../../layout/describe-config.js';
3
+ import type { LinkButtonProps } from '../slots.js';
4
+ export interface InspectorProps {
5
+ element: ElementDescription | undefined;
6
+ description: ConfigDescription;
7
+ /** Receives the path of a state or transition named in the inspector when it is clicked. */
8
+ onSelect: (path: string) => void;
9
+ /** The app's in-page link, through which the inspector renders each state and transition that it names. */
10
+ LinkButton: ComponentType<LinkButtonProps>;
11
+ }
12
+ /** The panel that describes the selected state, transition, or ambient instruction and the states that it connects. */
13
+ export declare function Inspector({ element, description, onSelect, LinkButton }: InspectorProps): ReactElement;
@@ -0,0 +1,58 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { listStateKinds, listTransitionKinds, } from "../../layout/describe-config.js";
3
+ export function Inspector({ element, description, onSelect, LinkButton }) {
4
+ const context = { description, onSelect, LinkButton };
5
+ return (_jsx("aside", { "aria-label": "Selection", className: "statechart-inspector", children: element === undefined ? (_jsx("p", { className: "statechart-inspector__empty", children: "Select a state or transition, or a passage in the prompt." })) : element.kind === 'ambient' ? (_jsx(AmbientDetails, { ambient: element, context: context })) : element.kind === 'state' ? (_jsx(StateDetails, { state: element, context: context })) : (_jsx(TransitionDetails, { transition: element, context: context })) }));
6
+ }
7
+ function ActionList({ label, actions }) {
8
+ return (_jsx(Fact, { label: label, children: actions.length === 0 ? (_jsx("span", { className: "statechart-inspector__none", children: "None" })) : (_jsx("ul", { className: "statechart-inspector__actions", children: actions.map(({ text, gate }) => (_jsxs("li", { children: [gate ? (_jsxs(_Fragment, { children: [_jsx("em", { className: "statechart-inspector__aside", children: "gate" }), ' '] })) : undefined, text] }, text))) })) }));
9
+ }
10
+ function AmbientDetails({ ambient, context: { description, onSelect, LinkButton }, }) {
11
+ const container = description.states.find(({ id }) => id === ambient.containerId);
12
+ return (_jsxs(Details, { heading: "Ambient instruction", children: [_jsx(KindList, { kinds: ambient.gate ? ['Gate'] : [] }), _jsx(Fact, { label: "Applies throughout", children: container === undefined ? (_jsx("span", { children: ambient.containerName })) : (_jsx("span", { children: _jsx(LinkButton, { onClick: () => onSelect(container.path), children: container.name }) })) }), _jsx(Fact, { label: "Says", children: _jsx("p", { className: "statechart-inspector__quote", children: ambient.text }) })] }));
13
+ }
14
+ function Details({ heading, children }) {
15
+ return (_jsxs("div", { className: "statechart-inspector__details", children: [_jsx("h2", { className: "statechart-inspector__heading", children: heading }), children] }));
16
+ }
17
+ function Fact({ label, children }) {
18
+ return (_jsxs("div", { className: "statechart-inspector__fact", children: [_jsx("span", { className: "statechart-inspector__aside", children: label }), children] }));
19
+ }
20
+ function KindList({ kinds }) {
21
+ if (kinds.length === 0)
22
+ return undefined;
23
+ return (_jsx("ul", { className: "statechart-inspector__kinds", children: kinds.map((kind) => (_jsx("li", { className: "statechart-inspector__kind", children: kind }, kind))) }));
24
+ }
25
+ function listFlowWideTransitions(state, description) {
26
+ if (state.isCompound)
27
+ return description.transitions.filter(({ sourceId }) => sourceId === state.id);
28
+ const ancestorIds = new Set();
29
+ for (let parentId = state.parentId; parentId !== undefined;) {
30
+ ancestorIds.add(parentId);
31
+ parentId = description.states.find(({ id }) => id === parentId)?.parentId;
32
+ }
33
+ return description.transitions.filter(({ sourceId, isGlobal }) => isGlobal && ancestorIds.has(sourceId));
34
+ }
35
+ function nameTrigger(transition) {
36
+ return transition.event ?? (transition.isFallback ? 'otherwise' : 'always');
37
+ }
38
+ function StateDetails({ state, context }) {
39
+ const { description } = context;
40
+ const leadsTo = state.isCompound ? [] : description.transitions.filter(({ sourceId }) => sourceId === state.id);
41
+ const comesFrom = description.transitions.filter(({ targetId, sourceId }) => targetId === state.id && sourceId !== state.id);
42
+ const flowWide = listFlowWideTransitions(state, description);
43
+ return (_jsxs(Details, { heading: state.name, children: [_jsx(KindList, { kinds: listStateKinds(state) }), state.entry.length > 0 ? _jsx(ActionList, { label: "Does", actions: state.entry }) : undefined, state.exit.length > 0 ? _jsx(ActionList, { label: "On exit", actions: state.exit }) : undefined, state.isCompound ? undefined : (_jsx(Fact, { label: "Leads to", children: _jsx(TransitionList, { transitions: leadsTo, direction: "to", context: context }) })), flowWide.length > 0 ? (_jsx(Fact, { label: "Any time", children: _jsx(TransitionList, { transitions: flowWide, direction: "to", context: context }) })) : undefined, _jsx(Fact, { label: "Comes from", children: _jsx(TransitionList, { transitions: comesFrom, direction: "from", context: context }) })] }));
44
+ }
45
+ function TransitionDetails({ transition, context: { description, onSelect, LinkButton }, }) {
46
+ const source = description.states.find(({ id }) => id === transition.sourceId);
47
+ const target = description.states.find(({ id }) => id === transition.targetId);
48
+ return (_jsxs(Details, { heading: _jsx("span", { className: "statechart-inspector__code", children: nameTrigger(transition) }), children: [_jsxs("div", { className: "statechart-inspector__row", children: [source === undefined ? undefined : (_jsx(LinkButton, { onClick: () => onSelect(source.path), children: source.name })), _jsx("span", { className: "statechart-inspector__aside", children: "to" }), target === undefined ? undefined : (_jsx(LinkButton, { onClick: () => onSelect(target.path), children: target.name }))] }), _jsx(KindList, { kinds: listTransitionKinds(transition) }), _jsx(Fact, { label: "Guard", children: transition.guard === undefined ? (_jsx("span", { className: "statechart-inspector__none", children: transition.isFallback ? 'Otherwise: none of the guarded siblings applies' : 'None' })) : (_jsx("span", { children: transition.guard })) }), _jsx(ActionList, { label: "Does", actions: transition.actions })] }));
49
+ }
50
+ function TransitionList({ transitions, direction, context: { description, onSelect, LinkButton }, }) {
51
+ if (transitions.length === 0)
52
+ return _jsx("span", { className: "statechart-inspector__none", children: "None" });
53
+ return (_jsx("ul", { className: "statechart-inspector__transitions", children: transitions.map((transition) => {
54
+ const otherId = direction === 'to' ? transition.targetId : transition.sourceId;
55
+ const other = description.states.find(({ id }) => id === otherId);
56
+ return (_jsxs("li", { className: "statechart-inspector__row", children: [_jsx(LinkButton, { onClick: () => onSelect(transition.path), children: _jsx("span", { className: "statechart-inspector__code", children: nameTrigger(transition) }) }), transition.guard === undefined ? undefined : (_jsxs("span", { className: "statechart-inspector__aside", children: ["if ", transition.guard] })), transition.isFallback && transition.event !== undefined ? (_jsx("span", { className: "statechart-inspector__aside", children: "otherwise" })) : undefined, _jsx("span", { className: "statechart-inspector__aside", children: direction }), other === undefined ? (_jsx("span", { className: "statechart-inspector__unnamed", children: otherId })) : (_jsx(LinkButton, { onClick: () => onSelect(other.path), children: other.name }))] }, transition.path));
57
+ }) }));
58
+ }
@@ -0,0 +1,18 @@
1
+ import type { ComponentType, ReactElement } from 'react';
2
+ import { type FindingDescription } from '../../layout/describe-config.js';
3
+ import type { Span } from '../../schema/agent-logic-schema.js';
4
+ import type { ButtonProps, LinkButtonProps } from '../slots.js';
5
+ export interface FindingListProps {
6
+ findings: FindingDescription[];
7
+ /** Receives the path of the element that a finding concerns when its name is clicked. */
8
+ onSelect: (path: string) => void;
9
+ /** Receives the quoted passages of a finding on the root when its button is clicked, to mark them in the prompt. */
10
+ onShow: (passages: Span[]) => void;
11
+ Button: ComponentType<ButtonProps>;
12
+ LinkButton: ComponentType<LinkButtonProps>;
13
+ }
14
+ /**
15
+ * The flaws that the converter judged from the prompt's prose, kept apart from the gaps that the chart's structure
16
+ * shows. Each selects the element that it concerns or, for a finding on the root, marks its quotes in the prompt.
17
+ */
18
+ export declare function FindingList({ findings, onSelect, onShow, Button, LinkButton, }: FindingListProps): ReactElement | undefined;
@@ -0,0 +1,15 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { nameElement } from "../../layout/describe-config.js";
3
+ import { abbreviate } from "./abbreviate.js";
4
+ import { SectionMessage } from "./SectionMessage.js";
5
+ export function FindingList({ findings, onSelect, onShow, Button, LinkButton, }) {
6
+ if (findings.length === 0)
7
+ return undefined;
8
+ return (_jsxs(SectionMessage, { appearance: "information", title: `Converter’s findings (${findings.length})`, children: [_jsx("p", { children: "Judged by the model that converted the prompt, not checked against the chart." }), _jsx("ul", { className: "statechart-messages__list", children: findings.map(({ path, kind, reason, sources, element }) => (_jsxs("li", { children: [_jsx("span", { className: "statechart-messages__kind", children: KIND_LABELS[kind] }), reason, ' ', element === undefined ? (_jsx(Button, { "aria-label": `Show in prompt: ${abbreviate(reason)}`, onClick: () => onShow(sources), children: "Show in prompt" })) : (_jsx(LinkButton, { isInline: true, onClick: () => onSelect(element.path), children: nameElement(element) }))] }, path))) })] }));
9
+ }
10
+ const KIND_LABELS = {
11
+ contradiction: 'Contradiction',
12
+ 'inferred-resolution': 'Ambiguity resolved',
13
+ 'unhandled-case': 'Unhandled case',
14
+ 'unused-input': 'Unused input',
15
+ };
@@ -0,0 +1,14 @@
1
+ import type { ComponentType, ReactElement } from 'react';
2
+ import { type ConfigDescription } from '../../layout/describe-config.js';
3
+ import type { LinkButtonProps } from '../slots.js';
4
+ export interface GapListProps {
5
+ description: ConfigDescription;
6
+ /** Receives the path of a listed state or transition when its name is clicked. */
7
+ onSelect: (path: string) => void;
8
+ LinkButton: ComponentType<LinkButtonProps>;
9
+ }
10
+ /**
11
+ * The states without an exit, the unreachable states, and the conditions without an alternative of a loaded config,
12
+ * each of which selects its element.
13
+ */
14
+ export declare function GapList({ description, onSelect, LinkButton }: GapListProps): ReactElement | undefined;
@@ -0,0 +1,18 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { listGaps, nameElement, } from "../../layout/describe-config.js";
3
+ import { SectionMessage } from "./SectionMessage.js";
4
+ export function GapList({ description, onSelect, LinkButton }) {
5
+ const gaps = listGaps(description);
6
+ if (gaps.length === 0)
7
+ return undefined;
8
+ return (_jsx(SectionMessage, { appearance: "warning", title: "Gaps in the logic", children: _jsx("ul", { className: "statechart-messages__list", children: gaps.map((gap) => (_jsxs("li", { children: [_jsx(LinkButton, { isInline: true, onClick: () => onSelect(gap.path), children: nameElement(gap) }), ' ', describeGap(gap)] }, gap.path))) }) }));
9
+ }
10
+ function describeGap(gap) {
11
+ if (gap.kind === 'transition') {
12
+ return `No alternative. Only if ${gap.guard ?? ''}. The prompt does not say what happens otherwise.`;
13
+ }
14
+ return [
15
+ ...(gap.hasNoExit ? ['No exit. Not an end, and none of its own transitions leads to another state.'] : []),
16
+ ...(gap.isUnreachable ? ['Unreachable. No transition leads to it, and no flow starts with it.'] : []),
17
+ ].join(' ');
18
+ }
@@ -0,0 +1,29 @@
1
+ import type { ComponentType, ReactElement } from 'react';
2
+ import { type ConfigDescription } from '../../layout/describe-config.js';
3
+ import type { AgentLogicConfig, Span } from '../../schema/agent-logic-schema.js';
4
+ import type { MessageCounts } from '../canvas/CanvasKey.js';
5
+ import type { ButtonProps, LinkButtonProps } from '../slots.js';
6
+ export interface MessagesProps {
7
+ config: AgentLogicConfig;
8
+ description: ConfigDescription;
9
+ /** Receives the path of a state or transition named in the panel when it is clicked. */
10
+ onSelect: (path: string) => void;
11
+ /** Receives the passages of a finding or an unconverted passage to mark in the prompt. */
12
+ onShow: (passages: Span[]) => void;
13
+ /** The id that the toggle in the canvas key names as the panel that it controls. */
14
+ id: string;
15
+ isOpen: boolean;
16
+ /** The app's button, which the panel renders for each disclosure and each "Show in prompt". */
17
+ Button: ComponentType<ButtonProps>;
18
+ /** The app's in-page link, which the panel renders, inline in its sentence, for each element that it names. */
19
+ LinkButton: ComponentType<LinkButtonProps>;
20
+ }
21
+ /** Returns the number of each kind of message that a converted document has. */
22
+ export declare function countMessages(config: AgentLogicConfig, description: ConfigDescription): MessageCounts;
23
+ /** Reports whether a document has any message to list. */
24
+ export declare function hasMessages({ gaps, findings, unconverted }: MessageCounts): boolean;
25
+ /**
26
+ * The panel below the canvas of a converted document, of a fixed height and hidden until its toggle opens it: its
27
+ * gaps, the converter's findings, and its unconverted passages.
28
+ */
29
+ export declare function Messages({ config, description, onSelect, onShow, id, isOpen, Button, LinkButton, }: MessagesProps): ReactElement;
@@ -0,0 +1,19 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { listGaps } from "../../layout/describe-config.js";
3
+ import { FindingList } from "./FindingList.js";
4
+ import { GapList } from "./GapList.js";
5
+ import { UnconvertedPassages } from "./UnconvertedPassages.js";
6
+ export function countMessages(config, description) {
7
+ return {
8
+ gaps: listGaps(description).length,
9
+ findings: description.findings.length,
10
+ unconverted: config.meta.unconverted.length,
11
+ };
12
+ }
13
+ export function hasMessages({ gaps, findings, unconverted }) {
14
+ return gaps + findings + unconverted > 0;
15
+ }
16
+ export function Messages({ config, description, onSelect, onShow, id, isOpen, Button, LinkButton, }) {
17
+ const { prompt, unconverted } = config.meta;
18
+ return (_jsxs("section", { id: id, "aria-label": "Messages", hidden: !isOpen, className: "statechart-messages", children: [_jsx(GapList, { description: description, onSelect: onSelect, LinkButton: LinkButton }), _jsx(FindingList, { findings: description.findings, onSelect: onSelect, onShow: onShow, Button: Button, LinkButton: LinkButton }), _jsx(UnconvertedPassages, { prompt: prompt, passages: unconverted, onShow: (passage) => onShow([passage]), Button: Button })] }));
19
+ }
@@ -0,0 +1,10 @@
1
+ import { type ReactElement, type ReactNode } from 'react';
2
+ export interface SectionMessageProps {
3
+ /** `warning` for what needs the reader's attention; `information` for what only informs. */
4
+ appearance: 'information' | 'warning';
5
+ /** The heading; a node rather than text so that it can hold a control, such as a disclosure. */
6
+ title: ReactNode;
7
+ children?: ReactNode;
8
+ }
9
+ /** A tinted section with the icon of its appearance beside a heading and its body. */
10
+ export declare function SectionMessage({ appearance, title, children }: SectionMessageProps): ReactElement;
@@ -0,0 +1,8 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useId } from 'react';
3
+ import { InformationIcon, WarningIcon } from "./icons.js";
4
+ export function SectionMessage({ appearance, title, children }) {
5
+ const titleId = useId();
6
+ const Icon = appearance === 'information' ? InformationIcon : WarningIcon;
7
+ return (_jsxs("section", { "aria-labelledby": titleId, className: `statechart-messages__section statechart-messages__section--${appearance}`, children: [_jsx(Icon, {}), _jsxs("div", { className: "statechart-messages__section-body", children: [_jsx("h2", { id: titleId, className: "statechart-messages__section-title", children: title }), children] })] }));
8
+ }
@@ -0,0 +1,15 @@
1
+ import { type ComponentType, type ReactElement } from 'react';
2
+ import type { UnconvertedSpan } from '../../schema/agent-logic-schema.js';
3
+ import type { ButtonProps } from '../slots.js';
4
+ export interface UnconvertedPassagesProps {
5
+ prompt: string;
6
+ passages: UnconvertedSpan[];
7
+ /** Receives the passage whose button was clicked, to show it in the prompt. */
8
+ onShow: (passage: UnconvertedSpan) => void;
9
+ Button: ComponentType<ButtonProps>;
10
+ }
11
+ /**
12
+ * The passages of the prompt that the converter could not turn into logic, quoted with the reason for each, under a
13
+ * disclosure that counts them. The list starts collapsed, because the prompt pane marks the same passages.
14
+ */
15
+ export declare function UnconvertedPassages({ prompt, passages, onShow, Button, }: UnconvertedPassagesProps): ReactElement | undefined;
@@ -0,0 +1,15 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useId, useState } from 'react';
3
+ import { abbreviate } from "./abbreviate.js";
4
+ import { ChevronIcon } from "./icons.js";
5
+ import { SectionMessage } from "./SectionMessage.js";
6
+ export function UnconvertedPassages({ prompt, passages, onShow, Button, }) {
7
+ const [isOpen, setIsOpen] = useState(false);
8
+ const detailsId = useId();
9
+ if (passages.length === 0)
10
+ return undefined;
11
+ return (_jsx(SectionMessage, { appearance: "warning", title: _jsxs(Button, { "aria-expanded": isOpen, "aria-controls": detailsId, isHeading: true, onClick: () => setIsOpen((wasOpen) => !wasOpen), children: [_jsx(ChevronIcon, { isOpen: isOpen }), "Unconverted passages (", passages.length, ")"] }), children: _jsxs("div", { id: detailsId, hidden: !isOpen, className: "statechart-messages__details", children: [_jsx("p", { children: "Absent from the chart. To convert one, rewrite it as a step, a condition, or a rule that applies in every state, then convert the prompt again." }), _jsx("ul", { className: "statechart-messages__passages", children: passages.map((passage) => {
12
+ const text = prompt.slice(passage.start, passage.end);
13
+ return (_jsxs("li", { children: [_jsx(Button, { "aria-label": `Show in prompt: ${abbreviate(text)}`, onClick: () => onShow(passage), children: "Show in prompt" }), ' ', _jsx("q", { className: "statechart-messages__quote", children: text }), passage.reason === undefined ? undefined : ` ${passage.reason}`] }, `${passage.start}-${passage.end}`));
14
+ }) })] }) }));
15
+ }
@@ -0,0 +1,2 @@
1
+ /** Returns the text's first words, with an ellipsis when it has more. */
2
+ export declare function abbreviate(text: string, wordCount?: number): string;
@@ -0,0 +1,5 @@
1
+ export function abbreviate(text, wordCount = 5) {
2
+ const words = text.trim().split(/\s+/);
3
+ const lead = words.slice(0, wordCount).join(' ');
4
+ return words.length > wordCount ? `${lead}…` : lead;
5
+ }
@@ -0,0 +1,9 @@
1
+ import type { ReactElement } from 'react';
2
+ /** The glyph of a disclosure: a chevron that points right while closed and down while open. */
3
+ export declare function ChevronIcon({ isOpen }: {
4
+ isOpen: boolean;
5
+ }): ReactElement;
6
+ /** The glyph of information: a filled circle holding an `i`. */
7
+ export declare function InformationIcon(): ReactElement;
8
+ /** The glyph of a warning: a filled triangle holding an exclamation mark. */
9
+ export declare function WarningIcon(): ReactElement;
@@ -0,0 +1,10 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ export function ChevronIcon({ isOpen }) {
3
+ return (_jsx("svg", { viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", strokeWidth: "1.8", "aria-hidden": "true", className: `statechart-chevron${isOpen ? ' statechart-chevron--open' : ''}`, children: _jsx("path", { d: "M6 3.5L10.5 8 6 12.5" }) }));
4
+ }
5
+ export function InformationIcon() {
6
+ return (_jsxs("svg", { viewBox: "0 0 20 20", "aria-hidden": "true", className: "statechart-messages__icon", children: [_jsx("circle", { cx: "10", cy: "10", r: "8", fill: "currentColor" }), _jsx("path", { d: "M10 9v5", className: "statechart-messages__icon-stroke", strokeWidth: "1.8", strokeLinecap: "round" }), _jsx("circle", { cx: "10", cy: "6.25", r: "1.1", className: "statechart-messages__icon-fill" })] }));
7
+ }
8
+ export function WarningIcon() {
9
+ return (_jsxs("svg", { viewBox: "0 0 20 20", "aria-hidden": "true", className: "statechart-messages__icon", children: [_jsx("path", { d: "M8.27 3.2a2 2 0 0 1 3.46 0l6.1 10.55A2 2 0 0 1 16.1 16.75H3.9a2 2 0 0 1-1.73-3L8.27 3.2Z", fill: "currentColor" }), _jsx("path", { d: "M10 7.5v3.75", className: "statechart-messages__icon-stroke", strokeWidth: "1.8", strokeLinecap: "round" }), _jsx("circle", { cx: "10", cy: "13.75", r: "1.1", className: "statechart-messages__icon-fill" })] }));
10
+ }
@@ -0,0 +1,28 @@
1
+ import type { ReactNode } from 'react';
2
+ /**
3
+ * The props of the app's button. The component renders a `<button type="button">` that looks like a button at rest
4
+ * and shows the pointer, hover, and focus states; it forwards each ARIA attribute that it receives to the button.
5
+ */
6
+ export interface ButtonProps {
7
+ children: ReactNode;
8
+ onClick: () => void;
9
+ 'aria-controls'?: string | undefined;
10
+ 'aria-describedby'?: string | undefined;
11
+ 'aria-expanded'?: boolean | undefined;
12
+ 'aria-label'?: string | undefined;
13
+ /**
14
+ * Whether the button is the title of a section, as a disclosure that heads its list is, for which the button takes
15
+ * the heading's text size; otherwise it sits in a line of text or a toolbar, at the app's compact size.
16
+ */
17
+ isHeading?: boolean | undefined;
18
+ }
19
+ /**
20
+ * The props of the app's in-page link. The component renders a `<button type="button">` that looks like a link and
21
+ * shows the pointer, hover, and focus states; `children` is the name of the element that it selects.
22
+ */
23
+ export interface LinkButtonProps {
24
+ children: ReactNode;
25
+ onClick: () => void;
26
+ /** Whether the link stands inside a sentence, for which the link keeps its underline at rest. */
27
+ isInline?: boolean | undefined;
28
+ }
@@ -0,0 +1 @@
1
+ export {};