@swirls/looms 0.9.0 → 0.11.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 (118) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/dist/actor/cell.d.ts +3 -1
  3. package/dist/actor/cell.js +1 -0
  4. package/dist/actor/host.d.ts +3 -1
  5. package/dist/actor/host.js +1 -0
  6. package/dist/actor/routing.js +2 -1
  7. package/dist/agent/debugger/agent-chat.js +6 -5
  8. package/dist/agent/debugger/index.js +2 -1
  9. package/dist/agent/module.d.ts +207 -1
  10. package/dist/agent/module.js +31 -0
  11. package/dist/agent/scope.js +1 -0
  12. package/dist/agent/signals.d.ts +108 -15
  13. package/dist/agent/signals.js +70 -47
  14. package/dist/approval/debugger/approvals-view.js +1 -1
  15. package/dist/approval/index.d.ts +1 -0
  16. package/dist/approval/index.js +1 -0
  17. package/dist/approval/module.d.ts +42 -1
  18. package/dist/approval/module.js +53 -0
  19. package/dist/approval/scope.js +1 -0
  20. package/dist/approval/signals.d.ts +19 -13
  21. package/dist/approval/signals.js +25 -45
  22. package/dist/approval/steps.d.ts +11 -0
  23. package/dist/approval/steps.js +39 -0
  24. package/dist/cli/commands.d.ts +1 -1
  25. package/dist/cli/commands.js +49 -14
  26. package/dist/client/client.d.ts +231 -21
  27. package/dist/client/client.js +20 -2
  28. package/dist/cloudflare/delete-terminal-run-storage.d.ts +39 -0
  29. package/dist/cloudflare/delete-terminal-run-storage.js +98 -0
  30. package/dist/cloudflare/durable-object.d.ts +11 -1
  31. package/dist/cloudflare/durable-object.js +23 -0
  32. package/dist/cloudflare/index.d.ts +1 -0
  33. package/dist/cloudflare/index.js +1 -0
  34. package/dist/core/index.d.ts +1 -0
  35. package/dist/core/index.js +1 -0
  36. package/dist/core/module-scope.d.ts +50 -5
  37. package/dist/core/module-scope.js +22 -2
  38. package/dist/core/module.d.ts +29 -2
  39. package/dist/core/projection.d.ts +1 -0
  40. package/dist/core/published.d.ts +59 -1
  41. package/dist/core/published.js +97 -1
  42. package/dist/core/run-context.d.ts +50 -0
  43. package/dist/core/run-context.js +21 -1
  44. package/dist/core/signals.d.ts +56 -0
  45. package/dist/core/signals.js +93 -0
  46. package/dist/core/validate-event.d.ts +12 -1
  47. package/dist/core/validate-event.js +34 -11
  48. package/dist/debugger/app/assets/index-CO5gIvV8.css +2 -0
  49. package/dist/debugger/app/assets/{index-CMRl_aWQ.js → index-VTotlHcm.js} +2 -2
  50. package/dist/debugger/app/assets/routes-CEdsN9DO.js +47 -0
  51. package/dist/debugger/app/index.html +2 -2
  52. package/dist/debugger/index.d.ts +1 -1
  53. package/dist/debugger/index.js +1 -1
  54. package/dist/debugger/lib/cn.d.ts +1 -1
  55. package/dist/debugger/lib/cn.js +12 -1
  56. package/dist/debugger/plugin.d.ts +11 -1
  57. package/dist/debugger/plugin.js +41 -0
  58. package/dist/debugger/shell/debugger-shell.js +1 -1
  59. package/dist/debugger/shell/form-fields.d.ts +17 -0
  60. package/dist/debugger/shell/form-fields.js +38 -0
  61. package/dist/debugger/shell/run-action.d.ts +6 -0
  62. package/dist/debugger/shell/run-action.js +15 -0
  63. package/dist/debugger/shell/run-controls.js +3 -55
  64. package/dist/debugger/shell/schema-form.d.ts +10 -1
  65. package/dist/debugger/shell/schema-form.js +108 -10
  66. package/dist/debugger/shell/signal-form.d.ts +18 -0
  67. package/dist/debugger/shell/signal-form.js +185 -0
  68. package/dist/debugger/shell/start-form.js +2 -32
  69. package/dist/debugger/shell/use-debounced-preview.d.ts +22 -0
  70. package/dist/debugger/shell/use-debounced-preview.js +68 -0
  71. package/dist/evaluator/index.d.ts +1 -1
  72. package/dist/evaluator/index.js +1 -1
  73. package/dist/evaluator/module.d.ts +8 -1
  74. package/dist/evaluator/module.js +33 -0
  75. package/dist/evaluator/scope.js +1 -0
  76. package/dist/projectors/event-log-ops.d.ts +0 -6
  77. package/dist/projectors/event-log-ops.js +2 -12
  78. package/dist/projectors/event-log.d.ts +10 -5
  79. package/dist/projectors/event-log.js +26 -22
  80. package/dist/projectors/replica/columns.d.ts +41 -0
  81. package/dist/projectors/replica/columns.js +77 -0
  82. package/dist/projectors/replica/drizzle.d.ts +328 -57
  83. package/dist/projectors/replica/drizzle.js +18 -14
  84. package/dist/projectors/replica/migrations.d.ts +25 -5
  85. package/dist/projectors/replica/migrations.js +62 -14
  86. package/dist/projectors/replica/postgres.d.ts +12 -11
  87. package/dist/projectors/replica/postgres.js +12 -26
  88. package/dist/projectors/replica/sqlite-bun.d.ts +3 -1
  89. package/dist/projectors/replica/sqlite-bun.js +6 -2
  90. package/dist/projectors/replica/sqlite-migrations.d.ts +5 -5
  91. package/dist/projectors/replica/sqlite-migrations.js +22 -9
  92. package/dist/projectors/replica/sqlite.d.ts +12 -11
  93. package/dist/projectors/replica/sqlite.js +23 -16
  94. package/dist/runtime/looms.d.ts +27 -36
  95. package/dist/runtime/looms.js +1 -0
  96. package/dist/runtime/runtime.js +7 -1
  97. package/dist/runtime/server/http.js +4 -2
  98. package/dist/runtime/server/routes/definitions.d.ts +1 -1
  99. package/dist/runtime/server/routes/definitions.js +58 -2
  100. package/dist/runtime/server/routes/runs.js +25 -1
  101. package/dist/runtime/types.d.ts +6 -1
  102. package/dist/schedule/module.d.ts +117 -1
  103. package/dist/schedule/module.js +30 -0
  104. package/dist/schedule/scope.js +1 -0
  105. package/dist/schedule/signals.d.ts +59 -7
  106. package/dist/schedule/signals.js +35 -17
  107. package/dist/testing/corpus-module.d.ts +1 -1
  108. package/dist/testing/index.js +2 -1
  109. package/dist/testing/module-examples.d.ts +6 -0
  110. package/dist/testing/module-examples.js +66 -0
  111. package/dist/workflow/module.d.ts +3 -1
  112. package/dist/workflow/module.js +13 -0
  113. package/dist/workflow/scope.js +1 -0
  114. package/package.json +1 -1
  115. package/dist/debugger/app/assets/index-B7GdT1UA.css +0 -2
  116. package/dist/debugger/app/assets/routes-CfXxKG45.js +0 -47
  117. /package/dist/evaluator/{signals.d.ts → steps.d.ts} +0 -0
  118. /package/dist/evaluator/{signals.js → steps.js} +0 -0
@@ -4,9 +4,9 @@
4
4
  <meta charset="UTF-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>Looms debugger</title>
7
- <script type="module" crossorigin src="./assets/index-CMRl_aWQ.js"></script>
7
+ <script type="module" crossorigin src="./assets/index-VTotlHcm.js"></script>
8
8
  <link rel="modulepreload" crossorigin href="./assets/rolldown-runtime-CbXtAM7H.js">
9
- <link rel="stylesheet" crossorigin href="./assets/index-B7GdT1UA.css">
9
+ <link rel="stylesheet" crossorigin href="./assets/index-CO5gIvV8.css">
10
10
  </head>
11
11
  <body>
12
12
  <div id="root"></div>
@@ -2,7 +2,7 @@ export type { DebuggerEvent, EventStreamCatalog, EventSummary, ReplayLoader, Rep
2
2
  export { createEventCatalog, defaultEventCatalog } from './events/catalog';
3
3
  export { summarizeProtocolEvent } from './events/protocol-summarize';
4
4
  export { DebuggerProvider, useDebugger, type DebuggerContextValue, type OpenRunTarget, } from './context';
5
- export { projectionFor, workspaceFor, type DebuggerPlugin, type EventFamilyView, type ProjectionView, type WorkspaceContext, type WorkspaceView, } from './plugin';
5
+ export { debuggerConformance, projectionFor, workspaceFor, type DebuggerPlugin, type EventFamilyView, type ProjectionView, type WorkspaceContext, type WorkspaceView, } from './plugin';
6
6
  export { DebuggerShell, type DebuggerSelection } from './shell/debugger-shell';
7
7
  export { StartForm } from './shell/start-form';
8
8
  export { useStartRun, type StartRun } from './shell/use-start-run';
@@ -1,7 +1,7 @@
1
1
  export { createEventCatalog, defaultEventCatalog } from './events/catalog.js';
2
2
  export { summarizeProtocolEvent } from './events/protocol-summarize.js';
3
3
  export { DebuggerProvider, useDebugger, } from './context.js';
4
- export { projectionFor, workspaceFor, } from './plugin.js';
4
+ export { debuggerConformance, projectionFor, workspaceFor, } from './plugin.js';
5
5
  export { DebuggerShell } from './shell/debugger-shell.js';
6
6
  export { StartForm } from './shell/start-form.js';
7
7
  export { useStartRun } from './shell/use-start-run.js';
@@ -1,5 +1,5 @@
1
1
  import { type ClassValue } from 'clsx';
2
- import type { JsonValue } from '@swirls/looms/core';
2
+ import { type JsonValue } from '@swirls/looms/core';
3
3
  export declare function cn(...inputs: ClassValue[]): string;
4
4
  export declare function shortId(id: string): string;
5
5
  export declare function compactJson(value: JsonValue): string;
@@ -1,5 +1,6 @@
1
1
  import { clsx } from 'clsx';
2
2
  import { twMerge } from 'tailwind-merge';
3
+ import { isJsonObject, isJsonString } from '@swirls/looms/core';
3
4
  export function cn(...inputs) {
4
5
  return twMerge(clsx(inputs));
5
6
  }
@@ -16,5 +17,15 @@ export function compactJson(value) {
16
17
  return text.length > 96 ? `${text.slice(0, 93)}…` : text;
17
18
  }
18
19
  export function errorMessage(cause) {
19
- return cause instanceof Error ? cause.message : String(cause);
20
+ const raw = cause instanceof Error ? cause.message : String(cause);
21
+ try {
22
+ const parsed = JSON.parse(raw);
23
+ if (isJsonObject(parsed) && isJsonString(parsed.error) && parsed.error.length > 0) {
24
+ return parsed.error;
25
+ }
26
+ }
27
+ catch {
28
+ // Not a JSON error body; use the raw message.
29
+ }
30
+ return raw;
20
31
  }
@@ -1,5 +1,5 @@
1
1
  import type { ComponentType } from 'react';
2
- import type { PublishedDefinition } from '@swirls/looms/core';
2
+ import type { AnyRuntimeModule, PublishedDefinition } from '@swirls/looms/core';
3
3
  import type { DebuggerEvent, EventSummary } from './contracts';
4
4
  export interface EventFamilyView {
5
5
  readonly family: string;
@@ -31,6 +31,16 @@ export interface DebuggerPlugin {
31
31
  readonly families?: readonly EventFamilyView[];
32
32
  readonly workspace?: WorkspaceView;
33
33
  readonly projections?: readonly ProjectionView[];
34
+ /**
35
+ * Projections this plugin renders inside a workspace, or leaves as data.
36
+ * `debuggerConformance` requires every module projection to be a pane or listed here.
37
+ */
38
+ readonly headlessProjections?: readonly string[];
34
39
  }
35
40
  export declare function workspaceFor(plugins: readonly DebuggerPlugin[], definition: PublishedDefinition): WorkspaceView | undefined;
41
+ /**
42
+ * The debugger plugin covers the module when every catalog event has a family and every
43
+ * projection is a pane or named in `headlessProjections`.
44
+ */
45
+ export declare function debuggerConformance(module: AnyRuntimeModule, plugin: DebuggerPlugin): readonly string[];
36
46
  export declare function projectionFor(plugins: readonly DebuggerPlugin[], name: string): ProjectionView | undefined;
@@ -3,6 +3,47 @@ export function workspaceFor(plugins, definition) {
3
3
  plugin.workspace.kinds.includes(definition.kind) &&
4
4
  (plugin.workspace.matches?.(definition) ?? true))?.workspace;
5
5
  }
6
+ /**
7
+ * The debugger plugin covers the module when every catalog event has a family and every
8
+ * projection is a pane or named in `headlessProjections`.
9
+ */
10
+ export function debuggerConformance(module, plugin) {
11
+ const errors = [];
12
+ if (plugin.name !== module.namespace) {
13
+ errors.push(`debugger plugin ${plugin.name} does not match module namespace ${module.namespace}`);
14
+ }
15
+ const families = plugin.families ?? [];
16
+ const namespace = module.events?.namespace ?? module.namespace;
17
+ for (const key of Object.keys(module.events?.entries ?? {}).toSorted()) {
18
+ const type = `${namespace}.${key}`;
19
+ const covered = families.some((family) => type.startsWith(family.prefix ?? `${family.family}.`));
20
+ if (!covered) {
21
+ errors.push(`event ${type} has no debugger family`);
22
+ }
23
+ }
24
+ const panes = new Set((plugin.projections ?? []).map((view) => view.name));
25
+ const headless = new Set(plugin.headlessProjections ?? []);
26
+ const declared = new Set(Object.values(module.projections ?? {}).map((projection) => projection.name));
27
+ for (const name of [...panes].toSorted()) {
28
+ if (!declared.has(name)) {
29
+ errors.push(`debugger pane ${name} is not a projection of ${module.namespace}`);
30
+ }
31
+ if (headless.has(name)) {
32
+ errors.push(`projection ${name} is both a debugger pane and headless`);
33
+ }
34
+ }
35
+ for (const name of [...headless].toSorted()) {
36
+ if (!declared.has(name)) {
37
+ errors.push(`headless projection ${name} is not declared by ${module.namespace}`);
38
+ }
39
+ }
40
+ for (const name of [...declared].toSorted()) {
41
+ if (!panes.has(name) && !headless.has(name)) {
42
+ errors.push(`projection ${name} has no debugger pane or headlessProjections entry`);
43
+ }
44
+ }
45
+ return errors;
46
+ }
6
47
  export function projectionFor(plugins, name) {
7
48
  for (const plugin of plugins) {
8
49
  const view = plugin.projections?.find((candidate) => candidate.name === name);
@@ -13,7 +13,7 @@ import { RunControls } from './run-controls.js';
13
13
  import { RunSearch } from './run-search.js';
14
14
  import { RunTypeMenu } from './run-type-menu.js';
15
15
  import { Workspace } from './workspace.js';
16
- const emptyCatalog = { definitions: [], projections: [] };
16
+ const emptyCatalog = { definitions: [], projections: [], modules: [] };
17
17
  function useDefinitionCatalog() {
18
18
  const { client } = useDebugger();
19
19
  const [catalog, setCatalog] = useState(emptyCatalog);
@@ -0,0 +1,17 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { FormField, FormValues, InputForm } from './schema-form';
3
+ export declare function Field({ label, hint, children, }: {
4
+ label: string;
5
+ hint?: string;
6
+ children: ReactNode;
7
+ }): import("react").JSX.Element;
8
+ export declare function FieldInput({ field, value, onChange, }: {
9
+ field: FormField;
10
+ value: string;
11
+ onChange: (value: string) => void;
12
+ }): import("react").JSX.Element;
13
+ export declare function InputFields({ form, values, onChange, }: {
14
+ form: InputForm;
15
+ values: FormValues;
16
+ onChange: (values: FormValues) => void;
17
+ }): import("react").JSX.Element[] | import("react").JSX.Element;
@@ -0,0 +1,38 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Checkbox } from '../ui/checkbox.js';
3
+ import { Input } from '../ui/input.js';
4
+ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../ui/select.js';
5
+ import { Textarea } from '../ui/textarea.js';
6
+ export function Field({ label, hint, children, }) {
7
+ return (_jsxs("label", { className: "grid gap-1.5", children: [_jsxs("span", { className: "flex items-baseline justify-between text-[11px]", children: [_jsx("span", { className: "text-foreground font-medium", children: label }), hint ? _jsx("span", { className: "text-muted-foreground", children: hint }) : null] }), children] }));
8
+ }
9
+ export function FieldInput({ field, value, onChange, }) {
10
+ switch (field.type) {
11
+ case 'boolean':
12
+ return (_jsx(Checkbox, { checked: value === 'true', onCheckedChange: (checked) => onChange(String(checked === true)) }));
13
+ case 'number':
14
+ return (_jsx(Input, { type: "number", className: "h-8 font-mono text-xs", value: value, onChange: (event) => onChange(event.target.value) }));
15
+ case 'select':
16
+ return (_jsxs(Select, { value: value, onValueChange: onChange, children: [_jsx(SelectTrigger, { className: "h-8 w-full font-mono text-xs", children: _jsx(SelectValue, {}) }), _jsx(SelectContent, { children: (field.options ?? []).map((option) => (_jsx(SelectItem, { value: option, children: option }, option))) })] }));
17
+ case 'string':
18
+ return (_jsx(Input, { className: "h-8 text-[13px]", value: value, onChange: (event) => onChange(event.target.value) }));
19
+ default: {
20
+ const exhaustive = field.type;
21
+ return exhaustive;
22
+ }
23
+ }
24
+ }
25
+ export function InputFields({ form, values, onChange, }) {
26
+ switch (form.kind) {
27
+ case 'text':
28
+ return (_jsx(Textarea, { className: "max-h-64 min-h-20", value: values.source, onChange: (event) => onChange({ ...values, source: event.target.value }), "aria-label": "Input" }));
29
+ case 'fields':
30
+ return form.fields.map((field) => (_jsxs("label", { className: field.type === 'boolean' ? 'flex items-center gap-2 text-xs' : 'grid gap-1.5 text-xs', children: [_jsxs("span", { className: "text-foreground font-medium", children: [field.label, field.required ? _jsx("span", { className: "text-status-failed", children: " *" }) : null] }), _jsx(FieldInput, { field: field, value: values.fields[field.name] ?? '', onChange: (value) => onChange({ ...values, fields: { ...values.fields, [field.name]: value } }) })] }, field.name)));
31
+ case 'json':
32
+ return (_jsx(Textarea, { className: "max-h-80 min-h-28 font-mono text-xs", value: values.source, onChange: (event) => onChange({ ...values, source: event.target.value }), "aria-label": "JSON input", spellCheck: false }));
33
+ default: {
34
+ const exhaustive = form;
35
+ return exhaustive;
36
+ }
37
+ }
38
+ }
@@ -0,0 +1,6 @@
1
+ export declare function useRunAction(): {
2
+ run: <T>(action: () => Promise<T>, onDone?: (value: T) => void) => void;
3
+ pending: boolean;
4
+ error: string | null;
5
+ setError: import("react").Dispatch<import("react").SetStateAction<string | null>>;
6
+ };
@@ -0,0 +1,15 @@
1
+ import { useState } from 'react';
2
+ import { errorMessage } from '../lib/cn.js';
3
+ export function useRunAction() {
4
+ const [error, setError] = useState(null);
5
+ const [pending, setPending] = useState(false);
6
+ function run(action, onDone) {
7
+ setPending(true);
8
+ setError(null);
9
+ action()
10
+ .then((value) => onDone?.(value))
11
+ .catch((cause) => setError(errorMessage(cause)))
12
+ .finally(() => setPending(false));
13
+ }
14
+ return { run, pending, error, setError };
15
+ }
@@ -2,65 +2,13 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Effect, Fiber } from 'effect';
3
3
  import { AlarmClock, CircleStop, GitFork, Radio } from 'lucide-react';
4
4
  import { useEffect, useState } from 'react';
5
- import { cleanUndefined } from '@swirls/looms/core';
6
5
  import { useRunStore, useRunSummary } from '@swirls/looms/react';
7
6
  import { useDebugger } from '../context.js';
8
- import { errorMessage } from '../lib/cn.js';
9
7
  import { Button } from '../ui/button.js';
10
- import { Input } from '../ui/input.js';
11
- import { Kbd } from '../ui/panel.js';
12
8
  import { Popover, PopoverContent, PopoverTrigger } from '../ui/popover.js';
13
- import { Textarea } from '../ui/textarea.js';
9
+ import { useRunAction } from './run-action.js';
10
+ import { SignalForm } from './signal-form.js';
14
11
  const NOTICE_MS = 3_000;
15
- function useRunAction() {
16
- const [error, setError] = useState(null);
17
- const [pending, setPending] = useState(false);
18
- function run(action, onDone) {
19
- setPending(true);
20
- setError(null);
21
- action()
22
- .then((value) => onDone?.(value))
23
- .catch((cause) => setError(errorMessage(cause)))
24
- .finally(() => setPending(false));
25
- }
26
- return { run, pending, error, setError };
27
- }
28
- function Field({ label, hint, children }) {
29
- return (_jsxs("label", { className: "grid gap-1.5", children: [_jsxs("span", { className: "flex items-baseline justify-between text-[11px]", children: [_jsx("span", { className: "text-foreground font-medium", children: label }), hint ? _jsx("span", { className: "text-muted-foreground", children: hint }) : null] }), children] }));
30
- }
31
- function SignalForm({ runId, rootThreadId }) {
32
- const { client } = useDebugger();
33
- const [type, setType] = useState('');
34
- const [payload, setPayload] = useState('{}');
35
- const [thread, setThread] = useState('');
36
- const [sent, setSent] = useState(false);
37
- const { run, pending, error, setError } = useRunAction();
38
- function submit() {
39
- setSent(false);
40
- let parsed;
41
- try {
42
- parsed = {
43
- type,
44
- payload: cleanUndefined(JSON.parse(payload)),
45
- threadId: thread || rootThreadId,
46
- };
47
- }
48
- catch (cause) {
49
- setError(errorMessage(cause));
50
- return;
51
- }
52
- run(() => client.signal(runId, [parsed]), () => setSent(true));
53
- }
54
- return (_jsxs("form", { className: "grid gap-3", onSubmit: (event) => {
55
- event.preventDefault();
56
- submit();
57
- }, children: [_jsxs("div", { children: [_jsx("p", { className: "text-[13px] font-medium", children: "Send a signal" }), _jsx("p", { className: "text-muted-foreground text-xs", children: "Append an event to this run's log." })] }), _jsx(Field, { label: "Type", children: _jsx(Input, { value: type, placeholder: "module.event", onChange: (event) => setType(event.target.value), className: "h-7 font-mono text-xs", autoFocus: true }) }), _jsx(Field, { label: "Thread", hint: "defaults to root", children: _jsx(Input, { value: thread, placeholder: rootThreadId ?? 'thread id', onChange: (event) => setThread(event.target.value), className: "h-7 font-mono text-xs" }) }), _jsx(Field, { label: "Payload", hint: "JSON", children: _jsx(Textarea, { value: payload, onChange: (event) => setPayload(event.target.value), onKeyDown: (event) => {
58
- if (event.key === 'Enter' && (event.metaKey || event.ctrlKey)) {
59
- event.preventDefault();
60
- submit();
61
- }
62
- }, className: "max-h-48 min-h-20 font-mono text-xs", spellCheck: false }) }), _jsxs("div", { className: "flex items-center gap-2", children: [error ? (_jsx("p", { className: "text-status-failed min-w-0 flex-1 truncate text-[11px]", title: error, children: error })) : sent ? (_jsx("p", { className: "text-status-completed flex-1 text-[11px]", children: "Signal sent" })) : (_jsxs("p", { className: "text-muted-foreground flex flex-1 items-center gap-1 text-[11px]", children: [_jsx(Kbd, { children: "\u2318" }), _jsx(Kbd, { children: "\u21B5" })] })), _jsx(Button, { type: "submit", size: "sm", disabled: pending || type.length === 0, children: "Send signal" })] })] }));
63
- }
64
12
  /** Run-scoped actions that live beside the run switcher. */
65
13
  export function RunControls({ runId, onForked, }) {
66
14
  const { client } = useDebugger();
@@ -95,5 +43,5 @@ export function RunControls({ runId, onForked, }) {
95
43
  setNotice(null);
96
44
  waking.setError(null);
97
45
  cancelling.run(() => client.cancel(runId));
98
- }, children: [_jsx(CircleStop, {}), "Cancel"] })), _jsxs(Popover, { children: [_jsx(PopoverTrigger, { asChild: true, children: _jsxs(Button, { variant: "ghost", size: "sm", className: "data-[state=open]:bg-accent data-[state=open]:text-foreground", children: [_jsx(Radio, {}), "Signal"] }) }), _jsx(PopoverContent, { align: "end", className: "w-80", children: _jsx(SignalForm, { runId: runId, rootThreadId: rootThreadId }) })] })] }));
46
+ }, children: [_jsx(CircleStop, {}), "Cancel"] })), _jsxs(Popover, { children: [_jsx(PopoverTrigger, { asChild: true, children: _jsxs(Button, { variant: "ghost", size: "sm", className: "data-[state=open]:bg-accent data-[state=open]:text-foreground", children: [_jsx(Radio, {}), "Signal"] }) }), _jsx(PopoverContent, { align: "end", className: "w-[28rem]", children: _jsx(SignalForm, { runId: runId, rootThreadId: rootThreadId }) })] })] }));
99
47
  }
@@ -2,8 +2,10 @@ import { type JsonValue } from '@swirls/looms/core';
2
2
  export interface FormField {
3
3
  readonly name: string;
4
4
  readonly label: string;
5
- readonly type: 'string' | 'number' | 'boolean';
5
+ readonly type: 'string' | 'number' | 'boolean' | 'select';
6
6
  readonly defaultValue: string;
7
+ readonly required: boolean;
8
+ readonly options?: readonly string[];
7
9
  }
8
10
  /** How a definition's input is edited: one text box, flat scalar fields, or raw JSON. */
9
11
  export type InputForm = {
@@ -25,6 +27,13 @@ export declare function formFields(schema: JsonValue | undefined): readonly Form
25
27
  export declare function inputForm(schema: JsonValue | undefined): InputForm;
26
28
  export declare function initialValues(form: InputForm): FormValues;
27
29
  export declare function valuesToInput(fields: readonly FormField[], values: Readonly<Record<string, string>>): JsonValue;
30
+ export declare function parseFormInput(form: InputForm, values: FormValues): {
31
+ readonly ok: true;
32
+ readonly value: JsonValue;
33
+ } | {
34
+ readonly ok: false;
35
+ readonly error: string;
36
+ };
28
37
  /** Input for the form's current values. Throws when the JSON source does not parse. */
29
38
  export declare function formInput(form: InputForm, values: FormValues): JsonValue;
30
39
  /** Input carrying a single chat message, when the form has exactly one string to put it in. */
@@ -12,29 +12,107 @@ function fieldType(value) {
12
12
  }
13
13
  return undefined;
14
14
  }
15
+ /** Effect `Schema.optional` often publishes `anyOf: [{ type: T }, { type: "null" }]`. */
16
+ function scalarTypeOfProperty(property) {
17
+ if (isJsonString(property.type)) {
18
+ return fieldType(property.type);
19
+ }
20
+ if (Array.isArray(property.type)) {
21
+ const scalars = property.type.filter((entry) => entry !== 'null');
22
+ if (scalars.length === 1) {
23
+ return fieldType(scalars[0]);
24
+ }
25
+ return undefined;
26
+ }
27
+ for (const key of ['anyOf', 'oneOf']) {
28
+ const variants = property[key];
29
+ if (!Array.isArray(variants)) {
30
+ continue;
31
+ }
32
+ const nonNull = variants.filter((variant) => isJsonObject(variant) && variant.type !== 'null');
33
+ if (nonNull.length !== 1 || !isJsonObject(nonNull[0])) {
34
+ return undefined;
35
+ }
36
+ return scalarTypeOfProperty(nonNull[0]);
37
+ }
38
+ return undefined;
39
+ }
40
+ function stringEnumOptions(property) {
41
+ if (isJsonString(property.const)) {
42
+ return [property.const];
43
+ }
44
+ if (!Array.isArray(property.enum)) {
45
+ return undefined;
46
+ }
47
+ const options = [];
48
+ for (const value of property.enum) {
49
+ if (!isJsonString(value)) {
50
+ return undefined;
51
+ }
52
+ options.push(value);
53
+ }
54
+ return options.length > 0 ? options : undefined;
55
+ }
56
+ function requiredPropertyNames(schema) {
57
+ if (!Array.isArray(schema.required)) {
58
+ return new Set();
59
+ }
60
+ const names = [];
61
+ for (const name of schema.required) {
62
+ if (isJsonString(name)) {
63
+ names.push(name);
64
+ }
65
+ }
66
+ return new Set(names);
67
+ }
68
+ function selectDefaultValue(options, fallback) {
69
+ if (isJsonString(fallback) && options.includes(fallback)) {
70
+ return fallback;
71
+ }
72
+ return options[0] ?? '';
73
+ }
15
74
  /** Flat object fields, or undefined when the schema needs the raw JSON editor. */
16
75
  export function formFields(schema) {
17
76
  if (!isJsonObject(schema) || schema.type !== 'object' || !isJsonObject(schema.properties)) {
18
77
  return undefined;
19
78
  }
20
79
  const fields = [];
80
+ const required = requiredPropertyNames(schema);
21
81
  for (const [name, property] of Object.entries(schema.properties)) {
22
- if (!isJsonObject(property) || !isJsonString(property.type)) {
82
+ if (!isJsonObject(property)) {
23
83
  return undefined;
24
84
  }
25
- const type = fieldType(property.type);
85
+ const enumOptions = stringEnumOptions(property);
86
+ if (enumOptions) {
87
+ fields.push({
88
+ name,
89
+ label: isJsonString(property.title) ? property.title : name,
90
+ type: 'select',
91
+ defaultValue: selectDefaultValue(enumOptions, property.default),
92
+ required: required.has(name),
93
+ options: enumOptions,
94
+ });
95
+ continue;
96
+ }
97
+ const type = scalarTypeOfProperty(property);
26
98
  if (!type) {
27
99
  return undefined;
28
100
  }
29
101
  const fallback = property.default;
30
- const defaultValue = isJsonString(fallback) || isJsonNumber(fallback) || Predicate.isBoolean(fallback)
31
- ? String(fallback)
32
- : '';
102
+ let defaultValue = '';
103
+ if (isJsonString(fallback) || isJsonNumber(fallback) || Predicate.isBoolean(fallback)) {
104
+ defaultValue = String(fallback);
105
+ }
106
+ else if (type === 'boolean') {
107
+ // Checkboxes are two-state; start unchecked so the control matches emitted `false`.
108
+ defaultValue = 'false';
109
+ }
33
110
  fields.push({
34
111
  name,
35
112
  label: isJsonString(property.title) ? property.title : name,
36
113
  type,
37
114
  defaultValue,
115
+ required: required.has(name),
38
116
  });
39
117
  }
40
118
  return fields;
@@ -67,19 +145,39 @@ export function valuesToInput(fields, values) {
67
145
  const input = {};
68
146
  for (const field of fields) {
69
147
  const raw = values[field.name] ?? field.defaultValue;
70
- if (field.type === 'number') {
71
- const parsed = Number(raw);
72
- input[field.name] = Number.isFinite(parsed) ? parsed : 0;
73
- continue;
74
- }
148
+ // Checkboxes always emit a boolean so the control matches preview/send input.
75
149
  if (field.type === 'boolean') {
76
150
  input[field.name] = raw === 'true';
77
151
  continue;
78
152
  }
153
+ // Optional empty strings/numbers are omitted; required empties fail below.
154
+ if (!field.required && raw === '') {
155
+ continue;
156
+ }
157
+ if (field.required && raw.trim() === '') {
158
+ throw new Error(`${field.label} is required`);
159
+ }
160
+ if (field.type === 'number') {
161
+ const parsed = Number(raw);
162
+ if (!Number.isFinite(parsed)) {
163
+ throw new Error(`${field.label} must be a number`);
164
+ }
165
+ input[field.name] = parsed;
166
+ continue;
167
+ }
79
168
  input[field.name] = raw;
80
169
  }
81
170
  return input;
82
171
  }
172
+ export function parseFormInput(form, values) {
173
+ try {
174
+ return { ok: true, value: formInput(form, values) };
175
+ }
176
+ catch (cause) {
177
+ const message = cause instanceof Error ? cause.message : String(cause);
178
+ return { ok: false, error: message };
179
+ }
180
+ }
83
181
  /** Input for the form's current values. Throws when the JSON source does not parse. */
84
182
  export function formInput(form, values) {
85
183
  switch (form.kind) {
@@ -0,0 +1,18 @@
1
+ export declare function useSignalCatalog(): {
2
+ signals: readonly {
3
+ readonly namespace: string;
4
+ readonly name: string;
5
+ readonly description?: string | undefined;
6
+ readonly inputSchema?: import("effect/Schema").Json | undefined;
7
+ }[];
8
+ events: readonly {
9
+ readonly type: string;
10
+ readonly namespace: string;
11
+ readonly payloadSchema?: import("effect/Schema").Json | undefined;
12
+ }[];
13
+ error: string | null;
14
+ };
15
+ export declare function SignalForm({ runId, rootThreadId }: {
16
+ runId: string;
17
+ rootThreadId?: string;
18
+ }): import("react").JSX.Element;