codeassembly-agent-logic 0.8.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 (60) hide show
  1. package/.meta/changelog.json +85 -0
  2. package/CHANGELOG.md +24 -0
  3. package/README.md +47 -18
  4. package/dist/esm/agent/convert-with-agent.d.ts +3 -3
  5. package/dist/esm/agent/convert-with-agent.js +2 -1
  6. package/dist/esm/conversion-session/format-conversion-input.d.ts +9 -0
  7. package/dist/esm/conversion-session/format-conversion-input.js +11 -1
  8. package/dist/esm/index.d.ts +5 -1
  9. package/dist/esm/index.js +1 -0
  10. package/dist/esm/job/create-conversion-job.d.ts +10 -1
  11. package/dist/esm/job/create-conversion-job.js +6 -2
  12. package/dist/esm/job/index.d.ts +1 -1
  13. package/dist/esm/job/index.js +1 -1
  14. package/dist/esm/react/canvas/CanvasKey.d.ts +38 -0
  15. package/dist/esm/react/canvas/CanvasKey.js +33 -0
  16. package/dist/esm/react/hooks/document-types.d.ts +72 -0
  17. package/dist/esm/react/hooks/document-types.js +3 -0
  18. package/dist/esm/react/hooks/file-location.d.ts +10 -0
  19. package/dist/esm/react/hooks/file-location.js +19 -0
  20. package/dist/esm/react/hooks/label-source.js +2 -1
  21. package/dist/esm/react/hooks/load-messages.d.ts +2 -0
  22. package/dist/esm/react/hooks/load-messages.js +3 -0
  23. package/dist/esm/react/hooks/read-document.d.ts +48 -0
  24. package/dist/esm/react/hooks/read-document.js +88 -0
  25. package/dist/esm/react/hooks/stored-base.d.ts +7 -0
  26. package/dist/esm/react/hooks/stored-base.js +8 -0
  27. package/dist/esm/react/hooks/stored-upload.d.ts +9 -0
  28. package/dist/esm/react/hooks/stored-upload.js +16 -0
  29. package/dist/esm/react/hooks/useDocumentState.d.ts +57 -0
  30. package/dist/esm/react/hooks/useDocumentState.js +151 -0
  31. package/dist/esm/react/index.d.ts +18 -1
  32. package/dist/esm/react/index.js +13 -0
  33. package/dist/esm/react/inspector/Inspector.d.ts +13 -0
  34. package/dist/esm/react/inspector/Inspector.js +58 -0
  35. package/dist/esm/react/messages/FindingList.d.ts +18 -0
  36. package/dist/esm/react/messages/FindingList.js +15 -0
  37. package/dist/esm/react/messages/GapList.d.ts +14 -0
  38. package/dist/esm/react/messages/GapList.js +18 -0
  39. package/dist/esm/react/messages/Messages.d.ts +29 -0
  40. package/dist/esm/react/messages/Messages.js +19 -0
  41. package/dist/esm/react/messages/SectionMessage.d.ts +10 -0
  42. package/dist/esm/react/messages/SectionMessage.js +8 -0
  43. package/dist/esm/react/messages/UnconvertedPassages.d.ts +15 -0
  44. package/dist/esm/react/messages/UnconvertedPassages.js +15 -0
  45. package/dist/esm/react/messages/abbreviate.d.ts +2 -0
  46. package/dist/esm/react/messages/abbreviate.js +5 -0
  47. package/dist/esm/react/messages/icons.d.ts +9 -0
  48. package/dist/esm/react/messages/icons.js +10 -0
  49. package/dist/esm/react/slots.d.ts +28 -0
  50. package/dist/esm/react/slots.js +1 -0
  51. package/dist/esm/react/source/SourceLine.d.ts +13 -0
  52. package/dist/esm/react/source/SourceLine.js +49 -0
  53. package/dist/esm/react/source/Workspace.d.ts +32 -0
  54. package/dist/esm/react/source/Workspace.js +22 -0
  55. package/dist/esm/react/source/build-connector.d.ts +39 -0
  56. package/dist/esm/react/source/build-connector.js +23 -0
  57. package/dist/esm/react/styles.css +445 -6
  58. package/dist/esm/schema/agent-logic-file-name.d.ts +4 -0
  59. package/dist/esm/schema/agent-logic-file-name.js +4 -0
  60. package/package.json +4 -3
@@ -0,0 +1,3 @@
1
+ export function describeConflict(name) {
2
+ return `The store already holds ${name}. Replace it to open this version.`;
3
+ }
@@ -0,0 +1,48 @@
1
+ import type { StoredFileRead } from '@williamthorsen/toolbelt.text-file-store/proposed';
2
+ import type { Example } from '../../examples/examples.js';
3
+ import type { AgentLogicConfig } from '../../schema/agent-logic-schema.js';
4
+ import { type ChartDocument, type DocumentReport, type LoadFailure, type OpenDocument, type OtherDocument, type OtherKindHandlers } from './document-types.js';
5
+ import { type TextOrigin } from './parse-config-text.js';
6
+ /** Returns the document of a stored agent-logic file. */
7
+ export declare function buildChartDocument(fileName: string, config: AgentLogicConfig, key: number): ChartDocument;
8
+ /** Returns the announcement of a document that opened: a chart's description, or that of the app's own kind. */
9
+ export declare function describeDocument<TOther extends OtherDocument = never>(document: OpenDocument<TOther>, otherKind?: OtherKindHandlers<TOther>): string;
10
+ /** Returns the announcement of a report: its problems when the page read the document, or its message. */
11
+ export declare function describeReport(report: DocumentReport): string;
12
+ /** Returns the announcement of what the document region now shows, or `undefined` for the start page. */
13
+ export declare function describeShown<TOther extends OtherDocument = never>({ document, report, view }: Shown<TOther>, otherKind?: OtherKindHandlers<TOther>): string | undefined;
14
+ /** Reports whether nothing is shown, which is the start page. */
15
+ export declare function isStartPageShown<TOther extends OtherDocument>({ document, report, opening, view, }: Shown<TOther>): boolean;
16
+ /** Returns the config that the text parses and validates to, with its parsed value, or why it did not load. */
17
+ export declare function readConfigText(text: string, origin: TextOrigin): {
18
+ ok: true;
19
+ config: AgentLogicConfig;
20
+ value: unknown;
21
+ } | {
22
+ ok: false;
23
+ failure: LoadFailure;
24
+ };
25
+ /** Returns what the page shows for an example, or the start page when there is none. */
26
+ export declare function readExample(example: Example | undefined, key: number): Shown;
27
+ /**
28
+ * Returns what the page shows first for its URL: the Visualizations table, a stored file to read, an example, or the
29
+ * start page.
30
+ */
31
+ export declare function readLocation(key: number): Shown;
32
+ /**
33
+ * Returns what the page shows for a stored file's read: its document, as the app's own kind when `otherKind` reads it
34
+ * as one and as a chart otherwise, or a report on why it did not open.
35
+ */
36
+ export declare function readStoredFile<TOther extends OtherDocument = never>(name: string, read: StoredFileRead, key: number, otherKind?: OtherKindHandlers<TOther>): Shown<TOther>;
37
+ /**
38
+ * What the document region shows: a document, a report on a document that did not open, the stored file being read,
39
+ * the Visualizations table, or none of them, which is the start page.
40
+ */
41
+ export interface Shown<TOther extends OtherDocument = never> {
42
+ document?: OpenDocument<TOther> | undefined;
43
+ report?: DocumentReport | undefined;
44
+ opening?: string | undefined;
45
+ view?: 'visualizations' | undefined;
46
+ }
47
+ /** The heading of the Visualizations table, which also names it in the tab title and the announcement. */
48
+ export declare const VISUALIZATIONS_TITLE = "All visualizations";
@@ -0,0 +1,88 @@
1
+ import { validateConfig } from "../../schema/validate-config.js";
2
+ import { describeLoaded, describeNotLoaded } from "./describe-load-outcome.js";
3
+ import { isChartDocument, } from "./document-types.js";
4
+ import { findExampleInSearch } from "./example-location.js";
5
+ import { findFileInSearch, isVisualizationsSearch } from "./file-location.js";
6
+ import { labelSource } from "./label-source.js";
7
+ import { parseConfigText } from "./parse-config-text.js";
8
+ export function buildChartDocument(fileName, config, key) {
9
+ const label = labelSource({ kind: 'file', fileName });
10
+ return { ...label, kind: 'chart', key, name: fileName, origin: 'File', fileName, config };
11
+ }
12
+ export function describeDocument(document, otherKind) {
13
+ if (isChartDocument(document))
14
+ return describeLoaded(document.source, document.config);
15
+ return otherKind === undefined ? `Opened ${document.name}.` : otherKind.describe(document);
16
+ }
17
+ export function describeReport(report) {
18
+ return report.source === undefined
19
+ ? `${report.title}: ${report.message ?? ''}`
20
+ : describeNotLoaded(report.source, report.problems);
21
+ }
22
+ export function describeShown({ document, report, view }, otherKind) {
23
+ if (view !== undefined)
24
+ return `Opened ${VISUALIZATIONS_TITLE}.`;
25
+ return document === undefined ? report && describeReport(report) : describeDocument(document, otherKind);
26
+ }
27
+ export function isStartPageShown({ document, report, opening, view, }) {
28
+ return document === undefined && report === undefined && opening === undefined && view === undefined;
29
+ }
30
+ export function readConfigText(text, origin) {
31
+ const read = parseConfigText(text, origin);
32
+ if (!read.ok)
33
+ return { ok: false, failure: { kind: read.isNotJson ? 'not-json' : 'syntax', problems: read.problems } };
34
+ const result = validateConfig(read.value);
35
+ return result.ok
36
+ ? { ok: true, config: result.config, value: read.value }
37
+ : { ok: false, failure: { kind: 'invalid', problems: result.problems } };
38
+ }
39
+ export function readExample(example, key) {
40
+ if (example === undefined)
41
+ return {};
42
+ const origin = { kind: 'example', name: example.name, slug: example.slug };
43
+ const label = labelSource(origin);
44
+ const result = validateConfig(example.value);
45
+ return result.ok
46
+ ? {
47
+ document: {
48
+ ...label,
49
+ kind: 'chart',
50
+ key,
51
+ name: example.name,
52
+ origin: 'Example',
53
+ slug: example.slug,
54
+ config: result.config,
55
+ },
56
+ }
57
+ : { report: { title: 'Example not loaded', source: label.source, problems: result.problems } };
58
+ }
59
+ export function readLocation(key) {
60
+ if (isVisualizationsSearch(globalThis.location.search))
61
+ return { view: 'visualizations' };
62
+ const fileName = findFileInSearch(globalThis.location.search);
63
+ return fileName === undefined
64
+ ? readExample(findExampleInSearch(globalThis.location.search), key)
65
+ : { opening: fileName };
66
+ }
67
+ export function readStoredFile(name, read, key, otherKind) {
68
+ if (!read.ok) {
69
+ return {
70
+ report: read.reason === 'missing'
71
+ ? {
72
+ title: 'File not found',
73
+ message: `The store does not hold ${name}. Choose a file under Recents.`,
74
+ problems: [],
75
+ }
76
+ : { title: 'File not opened', message: read.message, problems: [] },
77
+ };
78
+ }
79
+ const other = otherKind?.read(name, read.text, key);
80
+ if (other !== undefined)
81
+ return { document: other };
82
+ const parsed = readConfigText(read.text, 'file');
83
+ if (parsed.ok)
84
+ return { document: buildChartDocument(name, parsed.config, key) };
85
+ const { source } = labelSource({ kind: 'file', fileName: name });
86
+ return { report: { title: 'File not loaded', source, problems: parsed.failure.problems } };
87
+ }
88
+ export const VISUALIZATIONS_TITLE = 'All visualizations';
@@ -0,0 +1,7 @@
1
+ /** Returns a file name without its last extension when a base precedes it, or the name itself. */
2
+ export declare function dropLastExtension(fileName: string): string;
3
+ /**
4
+ * Replaces each run of characters that a stored name does not take with `-`, and trims leading dots and dashes; a base
5
+ * of which none of its characters remains becomes the fallback.
6
+ */
7
+ export declare function sanitizeStoredBase(base: string, fallback: string): string;
@@ -0,0 +1,8 @@
1
+ export function dropLastExtension(fileName) {
2
+ const dot = fileName.lastIndexOf('.');
3
+ return dot > 0 ? fileName.slice(0, dot) : fileName;
4
+ }
5
+ export function sanitizeStoredBase(base, fallback) {
6
+ const sanitized = base.replaceAll(/[^\w.-]+/g, '-').replace(/^[.-]+/, '');
7
+ return sanitized === '' ? fallback : sanitized;
8
+ }
@@ -0,0 +1,9 @@
1
+ import type { AgentLogicConfig } from '../../schema/agent-logic-schema.js';
2
+ import type { InputOrigin } from './document-types.js';
3
+ /**
4
+ * Returns the name under which an upload is stored: a dropped or picked file's name, with `.agent-logic.json` in place
5
+ * of its last extension, or a pasted config's `id`, each with its base sanitized into a name that the store accepts.
6
+ */
7
+ export declare function buildStoredUploadName(origin: InputOrigin, config: AgentLogicConfig): string;
8
+ /** Returns the text that is stored for an upload: its parsed JSON, re-serialized without any Markdown code fence. */
9
+ export declare function buildStoredUploadText(value: unknown): string;
@@ -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
+ }