@arkitektio/bsx 4.1.0 → 4.3.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 (145) hide show
  1. package/dist/bsx/references.d.ts.map +1 -1
  2. package/dist/bsx/references.js +28 -7
  3. package/dist/bsx/references.js.map +1 -1
  4. package/dist/catalogs/index.d.ts +83 -27
  5. package/dist/catalogs/index.d.ts.map +1 -1
  6. package/dist/catalogs/parts/data.d.ts +1 -1
  7. package/dist/catalogs/parts/feedback.d.ts +3 -3
  8. package/dist/catalogs/parts/forms.d.ts +35 -7
  9. package/dist/catalogs/parts/forms.d.ts.map +1 -1
  10. package/dist/catalogs/parts/forms.js +32 -0
  11. package/dist/catalogs/parts/forms.js.map +1 -1
  12. package/dist/catalogs/parts/icons.d.ts +2 -2
  13. package/dist/catalogs/parts/index.d.ts +63 -27
  14. package/dist/catalogs/parts/index.d.ts.map +1 -1
  15. package/dist/catalogs/parts/navigation.d.ts +4 -4
  16. package/dist/catalogs/parts/overlays.d.ts +11 -11
  17. package/dist/catalogs/parts/run.d.ts +8 -0
  18. package/dist/catalogs/parts/run.d.ts.map +1 -1
  19. package/dist/catalogs/parts/scene.d.ts +8 -0
  20. package/dist/catalogs/parts/scene.d.ts.map +1 -1
  21. package/dist/catalogs/parts/scene.js +4 -0
  22. package/dist/catalogs/parts/scene.js.map +1 -1
  23. package/dist/catalogs/props.d.ts +1 -1
  24. package/dist/catalogs/scene.d.ts +8 -0
  25. package/dist/catalogs/scene.d.ts.map +1 -1
  26. package/dist/catalogs/shadcn.d.ts +59 -11
  27. package/dist/catalogs/shadcn.d.ts.map +1 -1
  28. package/dist/catalogs/shadcn.js +2 -0
  29. package/dist/catalogs/shadcn.js.map +1 -1
  30. package/dist/catalogs/ui.d.ts +16 -16
  31. package/dist/ports/dependencies/DependenciesContainer.d.ts +13 -8
  32. package/dist/ports/dependencies/DependenciesContainer.d.ts.map +1 -1
  33. package/dist/ports/dependencies/DependenciesContainer.js +130 -118
  34. package/dist/ports/dependencies/DependenciesContainer.js.map +1 -1
  35. package/dist/ports/dependencies/DependencyTreeNotice.d.ts +3 -2
  36. package/dist/ports/dependencies/DependencyTreeNotice.d.ts.map +1 -1
  37. package/dist/ports/dependencies/DependencyTreeNotice.js +7 -6
  38. package/dist/ports/dependencies/DependencyTreeNotice.js.map +1 -1
  39. package/dist/ports/dependencies/tree.d.ts +24 -0
  40. package/dist/ports/dependencies/tree.d.ts.map +1 -1
  41. package/dist/ports/dependencies/tree.js +52 -0
  42. package/dist/ports/dependencies/tree.js.map +1 -1
  43. package/dist/ports/dependencies/useDependencyTree.d.ts +5 -0
  44. package/dist/ports/dependencies/useDependencyTree.d.ts.map +1 -1
  45. package/dist/ports/dependencies/useDependencyTree.js +11 -5
  46. package/dist/ports/dependencies/useDependencyTree.js.map +1 -1
  47. package/dist/renderer/BlokRenderer.d.ts +4 -1
  48. package/dist/renderer/BlokRenderer.d.ts.map +1 -1
  49. package/dist/renderer/BlokRenderer.js +5 -1
  50. package/dist/renderer/BlokRenderer.js.map +1 -1
  51. package/dist/renderer/bloks/control.d.ts +12 -0
  52. package/dist/renderer/bloks/control.d.ts.map +1 -1
  53. package/dist/renderer/bloks/control.js +92 -5
  54. package/dist/renderer/bloks/control.js.map +1 -1
  55. package/dist/renderer/bloks/data.d.ts +1 -1
  56. package/dist/renderer/bloks/feedback.d.ts +3 -3
  57. package/dist/renderer/bloks/forms.d.ts +31 -7
  58. package/dist/renderer/bloks/forms.d.ts.map +1 -1
  59. package/dist/renderer/bloks/forms.js +56 -0
  60. package/dist/renderer/bloks/forms.js.map +1 -1
  61. package/dist/renderer/bloks/icons.d.ts +1 -1
  62. package/dist/renderer/bloks/index.d.ts +51 -27
  63. package/dist/renderer/bloks/index.d.ts.map +1 -1
  64. package/dist/renderer/bloks/navigation.d.ts +4 -4
  65. package/dist/renderer/bloks/overlays.d.ts +11 -11
  66. package/dist/renderer/bloks/run/components.d.ts +4 -0
  67. package/dist/renderer/bloks/run/components.d.ts.map +1 -1
  68. package/dist/renderer/bloks/run/host.d.ts +32 -3
  69. package/dist/renderer/bloks/run/host.d.ts.map +1 -1
  70. package/dist/renderer/bloks/run/host.js.map +1 -1
  71. package/dist/renderer/bloks/scene/index.d.ts +4 -0
  72. package/dist/renderer/bloks/scene/index.d.ts.map +1 -1
  73. package/dist/renderer/functions/v2/index.d.ts.map +1 -1
  74. package/dist/renderer/functions/v2/index.js +39 -0
  75. package/dist/renderer/functions/v2/index.js.map +1 -1
  76. package/dist/renderer/runtime/context.d.ts +2 -0
  77. package/dist/renderer/runtime/context.d.ts.map +1 -1
  78. package/dist/renderer/runtime/context.js +4 -0
  79. package/dist/renderer/runtime/context.js.map +1 -1
  80. package/dist/renderer/runtime/hooks.d.ts.map +1 -1
  81. package/dist/renderer/runtime/hooks.js +1 -0
  82. package/dist/renderer/runtime/hooks.js.map +1 -1
  83. package/dist/renderer/runtime/resolution.d.ts +2 -0
  84. package/dist/renderer/runtime/resolution.d.ts.map +1 -1
  85. package/dist/renderer/runtime/resolution.js +17 -1
  86. package/dist/renderer/runtime/resolution.js.map +1 -1
  87. package/dist/renderer/runtime/schemas.d.ts +5 -5
  88. package/dist/renderer/runtime/task.d.ts +25 -2
  89. package/dist/renderer/runtime/task.d.ts.map +1 -1
  90. package/dist/renderer/runtime/task.js +11 -2
  91. package/dist/renderer/runtime/task.js.map +1 -1
  92. package/dist/renderer/runtime/types.d.ts +7 -2
  93. package/dist/renderer/runtime/types.d.ts.map +1 -1
  94. package/dist/shadcn.d.ts +51 -27
  95. package/dist/shadcn.d.ts.map +1 -1
  96. package/dist/shadcn.js +2 -0
  97. package/dist/shadcn.js.map +1 -1
  98. package/dist/spec/bsx_v2.json +64 -0
  99. package/dist/spec/catalogs/base@2.json +136 -3
  100. package/dist/spec/catalogs/base@2.json.js +136 -3
  101. package/dist/spec/catalogs/scene@1.json +20 -0
  102. package/dist/spec/catalogs/scene@1.json.js +20 -0
  103. package/dist/spec/catalogs/shadcn@1.json +142 -0
  104. package/dist/spec/catalogs/shadcn@1.json.js +142 -0
  105. package/dist/spec/vocabulary.d.ts +2 -0
  106. package/dist/spec/vocabulary.d.ts.map +1 -1
  107. package/dist/spec/vocabulary.js +1 -0
  108. package/dist/spec/vocabulary.js.map +1 -1
  109. package/dist/spec/vocabulary.json +43 -11
  110. package/dist/spec/vocabulary.json.js +43 -11
  111. package/package.json +1 -1
  112. package/src/bsx/language.test.ts +1 -1
  113. package/src/bsx/references.test.ts +59 -0
  114. package/src/bsx/references.ts +28 -7
  115. package/src/catalogs/parts/forms.ts +32 -0
  116. package/src/catalogs/parts/scene.ts +6 -0
  117. package/src/catalogs/shadcn.ts +2 -0
  118. package/src/ports/dependencies/DependenciesContainer.test.tsx +176 -0
  119. package/src/ports/dependencies/DependenciesContainer.tsx +341 -304
  120. package/src/ports/dependencies/DependencyTreeNotice.tsx +7 -15
  121. package/src/ports/dependencies/tree.test.ts +75 -0
  122. package/src/ports/dependencies/tree.ts +54 -0
  123. package/src/ports/dependencies/useDependencyTree.test.tsx +55 -0
  124. package/src/ports/dependencies/useDependencyTree.ts +11 -5
  125. package/src/renderer/BlokRenderer.tsx +9 -0
  126. package/src/renderer/bloks/control.tsx +116 -5
  127. package/src/renderer/bloks/forms.tsx +126 -0
  128. package/src/renderer/bloks/run/host.tsx +33 -3
  129. package/src/renderer/bloks/run/space.test.tsx +76 -0
  130. package/src/renderer/functions/v2/functions.test.ts +40 -1
  131. package/src/renderer/functions/v2/index.ts +47 -0
  132. package/src/renderer/runtime/context.tsx +6 -0
  133. package/src/renderer/runtime/hooks.ts +1 -0
  134. package/src/renderer/runtime/resolution.test.ts +14 -0
  135. package/src/renderer/runtime/resolution.ts +15 -1
  136. package/src/renderer/runtime/task.ts +33 -4
  137. package/src/renderer/runtime/types.ts +7 -2
  138. package/src/shadcn.ts +2 -0
  139. package/src/spec/bsx_v2.json +64 -0
  140. package/src/spec/catalogs/base@2.json +136 -3
  141. package/src/spec/catalogs/scene@1.json +20 -0
  142. package/src/spec/catalogs/shadcn@1.json +142 -0
  143. package/src/spec/spec.test.ts +20 -0
  144. package/src/spec/vocabulary.json +43 -11
  145. package/src/spec/vocabulary.ts +3 -0
@@ -1,6 +1,7 @@
1
1
  /**
2
- * What stands between a form and its assign, as the dry run sees it: the
3
- * dependencies anywhere in the tree that are not met yet.
2
+ * What the dependency rows cannot say themselves: that the dry run could not
3
+ * be asked, or that it refuses without naming a dependency. An unmet
4
+ * dependency is said at its own row (`DependenciesContainer`), once.
4
5
  */
5
6
  export const DependencyTreeNotice = ({
6
7
  tree,
@@ -13,20 +14,11 @@ export const DependencyTreeNotice = ({
13
14
  }) => {
14
15
  if (tree.error) {
15
16
  return (
16
- <p className="text-xs text-muted-foreground mb-2">
17
- The dependency tree could not be previewed ({tree.error.message}); the assign itself will tell.
17
+ <p className="text-xs text-muted-foreground">
18
+ Which agents this reaches could not be previewed; starting it will tell.
18
19
  </p>
19
20
  );
20
21
  }
21
- if (tree.satisfied !== false) return null;
22
- return (
23
- <div className="text-xs text-destructive mb-2">
24
- {tree.unmet.length === 0 && "A dependency is not met yet."}
25
- {tree.unmet.map(({ path, reason }) => (
26
- <p key={path.join("/")}>
27
- <span className="font-medium">{path.join(" › ")}</span>: {reason}
28
- </p>
29
- ))}
30
- </div>
31
- );
22
+ if (tree.satisfied !== false || tree.unmet.length > 0) return null;
23
+ return <p className="text-xs text-destructive">A dependency is not met yet.</p>;
32
24
  };
@@ -1,7 +1,14 @@
1
1
  import { describe, expect, it } from "vitest";
2
+ import type { ListDependencyFragment } from "../rekuest";
2
3
  import {
3
4
  type DependencyNode,
5
+ agentLabel,
6
+ agentsOf,
7
+ awaitsPick,
4
8
  levelBelow,
9
+ namesAgents,
10
+ pickHint,
11
+ pickLimits,
5
12
  pinsFromFrozen,
6
13
  toPins,
7
14
  unmetDependencies,
@@ -166,3 +173,71 @@ describe("pinsFromFrozen", () => {
166
173
  ]);
167
174
  });
168
175
  });
176
+
177
+ const declared = (over: Partial<ListDependencyFragment> = {}): ListDependencyFragment => ({
178
+ id: "1",
179
+ key: "stage",
180
+ autoResolvable: false,
181
+ optional: false,
182
+ singular: false,
183
+ ...over,
184
+ });
185
+
186
+ describe("how many agents a dependency takes", () => {
187
+ it("is one for a singular dependency, whatever else it says", () => {
188
+ expect(pickLimits(declared({ singular: true, maxViableInstances: 4 }))).toEqual({ min: 1, max: 1 });
189
+ expect(pickHint(declared({ singular: true }))).toBe("One agent");
190
+ });
191
+
192
+ it("reads its bounds, and says nothing when there are none", () => {
193
+ expect(pickLimits(declared({ minViableInstances: 2, maxViableInstances: 3 }))).toEqual({ min: 2, max: 3 });
194
+ expect(pickHint(declared({ minViableInstances: 2, maxViableInstances: 3 }))).toBe("2–3 agents");
195
+ expect(pickHint(declared({ minViableInstances: 2, maxViableInstances: 2 }))).toBe("2 agents");
196
+ expect(pickHint(declared({ maxViableInstances: 3 }))).toBe("Up to 3 agents");
197
+ expect(pickHint(declared({ minViableInstances: 2 }))).toBe("At least 2 agents");
198
+ expect(pickLimits(declared())).toEqual({ min: 1, max: Infinity });
199
+ expect(pickHint(declared())).toBeNull();
200
+ });
201
+
202
+ it("may be none for an optional one", () => {
203
+ expect(pickLimits(declared({ optional: true })).min).toBe(0);
204
+ });
205
+ });
206
+
207
+ describe("agentLabel", () => {
208
+ const agent = { id: "7", connected: true, app: { identifier: "live.mikro" }, release: { version: "1" }, user: { sub: "1" } };
209
+
210
+ it("is the agent's name, else its app, else its id", () => {
211
+ expect(agentLabel({ ...agent, name: "lab-nas" }, "7")).toBe("lab-nas");
212
+ expect(agentLabel({ ...agent, name: " " }, "7")).toBe("live.mikro");
213
+ expect(agentLabel(undefined, "7")).toBe("7");
214
+ });
215
+ });
216
+
217
+ describe("what waits for the user", () => {
218
+ it("is a required dependency that may not resolve by itself and names nobody", () => {
219
+ expect(awaitsPick(declared(), undefined)).toBe(true);
220
+ expect(awaitsPick(declared(), { key: "stage", mappedAgents: [{ key: "stage", agent: "7" }] })).toBe(false);
221
+ expect(awaitsPick(declared({ optional: true }), undefined)).toBe(false);
222
+ });
223
+
224
+ it("is not one that resolves by itself, until that is switched off", () => {
225
+ const auto = declared({ autoResolvable: true });
226
+ expect(awaitsPick(auto, undefined)).toBe(false);
227
+ expect(awaitsPick(auto, { key: "stage", autoResolve: true, mappedAgents: [] })).toBe(false);
228
+ expect(awaitsPick(auto, { key: "stage", autoResolve: false, mappedAgents: [] })).toBe(true);
229
+ });
230
+ });
231
+
232
+ describe("what a level reaches", () => {
233
+ it("names an agent only where a pin does", () => {
234
+ expect(namesAgents([{ key: "stage", autoResolve: true, mappedAgents: [] }])).toBe(false);
235
+ expect(namesAgents([{ key: "stage", mappedAgents: [{ key: "stage", agent: "7" }] }])).toBe(true);
236
+ expect(namesAgents(undefined)).toBe(false);
237
+ });
238
+
239
+ it("lists every agent once, in the order bound", () => {
240
+ expect(agentsOf([bound("a", "7"), bound("b", "8"), bound("c", "7")]).map((agent) => agent.id)).toEqual(["7", "8"]);
241
+ expect(agentsOf(undefined)).toEqual([]);
242
+ });
243
+ });
@@ -159,3 +159,57 @@ export const pinsFromFrozen = (frozen: readonly FrozenDependency[] | null | unde
159
159
  return [{ key: dependency.key, agent, ...(dependencies.length > 0 ? { dependencies } : {}) }];
160
160
  }),
161
161
  }));
162
+
163
+ /** How many agents a dependency takes. */
164
+ export const pickLimits = (dependency: ListDependencyFragment): { min: number; max: number } => {
165
+ if (dependency.singular) return { min: dependency.optional ? 0 : 1, max: 1 };
166
+ return {
167
+ min: dependency.minViableInstances ?? (dependency.optional ? 0 : 1),
168
+ max: dependency.maxViableInstances ?? Infinity,
169
+ };
170
+ };
171
+
172
+ /** The same, as the picker says it; nothing when any number will do. */
173
+ export const pickHint = (dependency: ListDependencyFragment): string | null => {
174
+ if (dependency.singular) return "One agent";
175
+ const min = dependency.minViableInstances;
176
+ const max = dependency.maxViableInstances;
177
+ if (min != null && max != null) return min === max ? `${min} agents` : `${min}–${max} agents`;
178
+ if (min != null) return `At least ${min} agents`;
179
+ if (max != null) return `Up to ${max} agents`;
180
+ return null;
181
+ };
182
+
183
+ /** An agent as people call it: its name, else the app it runs. */
184
+ export const agentLabel = (agent: DependencyAgent | null | undefined, id: string): string =>
185
+ agent?.name?.trim() || agent?.app.identifier || id;
186
+
187
+ /**
188
+ * Whether these pins name an agent: the user chose, where the default is
189
+ * "whoever is there". Pins below sit under a named agent, so this level tells.
190
+ */
191
+ export const namesAgents = (level: readonly Pin[] | null | undefined): boolean =>
192
+ (level ?? []).some((pin) => (pin.mappedAgents ?? []).length > 0);
193
+
194
+ /** The agents a level reaches, each once, in the order they are bound. */
195
+ export const agentsOf = (
196
+ nodes: readonly DependencyNode[] | null | undefined,
197
+ ): { id: string; agent?: DependencyAgent | null }[] => {
198
+ const seen = new Map<string, { id: string; agent?: DependencyAgent | null }>();
199
+ for (const node of nodes ?? []) {
200
+ for (const binding of node.mappedAgents) {
201
+ if (!seen.has(binding.agentId)) seen.set(binding.agentId, { id: binding.agentId, agent: binding.agent });
202
+ }
203
+ }
204
+ return [...seen.values()];
205
+ };
206
+
207
+ /**
208
+ * Whether a dependency still waits for the user: it is required, it may not
209
+ * resolve by itself, and no agent is pinned. The form refuses to submit it.
210
+ */
211
+ export const awaitsPick = (dependency: ListDependencyFragment, pin: Pin | undefined): boolean => {
212
+ if (dependency.optional) return false;
213
+ if ((pin?.mappedAgents ?? []).length > 0) return false;
214
+ return !(dependency.autoResolvable && (pin?.autoResolve || !pin));
215
+ };
@@ -0,0 +1,55 @@
1
+ // @vitest-environment jsdom
2
+ import { act, cleanup, renderHook, waitFor } from "@testing-library/react";
3
+ import { useForm } from "react-hook-form";
4
+ import { afterEach, describe, expect, it, vi } from "vitest";
5
+ import { configurePortHost } from "../host";
6
+ import type { ResolvedDependencyInput } from "./tree";
7
+ import { useDependencyTree } from "./useDependencyTree";
8
+
9
+ afterEach(() => {
10
+ cleanup();
11
+ configurePortHost({});
12
+ });
13
+
14
+ const IMPLEMENTATION = { id: "1", dependencies: [{}] };
15
+
16
+ describe("the dry run of an assign", () => {
17
+ it("keeps the tree of the pins before while a changed pin is asked about", async () => {
18
+ let answerSecond: (data: Record<string, unknown>) => void = () => undefined;
19
+ const query = vi
20
+ .fn()
21
+ .mockResolvedValueOnce({ dependencyTree: { satisfied: false, dependencies: [{ key: "stage", unmet: "Nobody.", mappedAgents: [] }] } })
22
+ .mockImplementationOnce(() => new Promise((resolve) => (answerSecond = resolve)));
23
+ configurePortHost({ useServiceQuery: () => query });
24
+
25
+ const { result } = renderHook(() => {
26
+ const form = useForm<{ dependencies: ResolvedDependencyInput[] }>({ defaultValues: { dependencies: [] } });
27
+ return { form, tree: useDependencyTree(IMPLEMENTATION, form.control) };
28
+ });
29
+ await waitFor(() => expect(result.current.tree.satisfied).toBe(false));
30
+ expect(result.current.tree.pending).toBe(false);
31
+
32
+ act(() => result.current.form.setValue("dependencies", [{ key: "stage", mappedAgents: [{ key: "stage", agent: "7" }] }]));
33
+ await waitFor(() => expect(query).toHaveBeenCalledTimes(2));
34
+ // Still unmet as far as anyone knows: not "met" for the length of a round trip.
35
+ expect(result.current.tree.satisfied).toBe(false);
36
+ expect(result.current.tree.unmet).toHaveLength(1);
37
+ expect(result.current.tree.pending).toBe(true);
38
+
39
+ await act(async () => answerSecond({ dependencyTree: { satisfied: true, dependencies: [{ key: "stage", mappedAgents: [] }] } }));
40
+ expect(result.current.tree.satisfied).toBe(true);
41
+ expect(result.current.tree.pending).toBe(false);
42
+ });
43
+
44
+ it("asks nothing for an implementation without dependencies", () => {
45
+ const query = vi.fn();
46
+ configurePortHost({ useServiceQuery: () => query });
47
+ const { result } = renderHook(() => {
48
+ const form = useForm<{ dependencies: ResolvedDependencyInput[] }>({ defaultValues: { dependencies: [] } });
49
+ return useDependencyTree({ id: "1", dependencies: [] }, form.control);
50
+ });
51
+ expect(query).not.toHaveBeenCalled();
52
+ expect(result.current.pending).toBe(false);
53
+ expect(result.current.satisfied).toBeUndefined();
54
+ });
55
+ });
@@ -46,6 +46,10 @@ type Answer = { dependencyTree?: { satisfied: boolean; dependencies: DependencyN
46
46
  * Asked again whenever a pin changes, and now and then, since agents come
47
47
  * and go.
48
48
  *
49
+ * While a changed pin is asked about, the tree of the pins before it stays
50
+ * (`pending` says so): the rows keep what they show, and an unmet tree does
51
+ * not read as met for the length of a round trip.
52
+ *
49
53
  * A server that cannot answer (an older one) leaves `satisfied` undefined:
50
54
  * the form then shows the root level alone and the assign itself decides.
51
55
  */
@@ -57,11 +61,11 @@ export const useDependencyTree = <TValues extends FieldValues>(
57
61
  const key = JSON.stringify(toPins(watched));
58
62
  const run = portHost().useServiceQuery("rekuest");
59
63
  const id = implementation && implementation.dependencies.length > 0 ? implementation.id : null;
60
- const [answer, setAnswer] = useState<Answer["dependencyTree"]>(undefined);
64
+ // Kept with what it answers: another implementation's tree is nobody's, and an older pin's is stale.
65
+ const [answer, setAnswer] = useState<{ id: string; key: string; tree: Answer["dependencyTree"] } | null>(null);
61
66
  const [error, setError] = useState<Error | null>(null);
62
67
 
63
68
  useEffect(() => {
64
- setAnswer(undefined);
65
69
  setError(null);
66
70
  if (!id) return undefined;
67
71
  let live = true;
@@ -70,7 +74,7 @@ export const useDependencyTree = <TValues extends FieldValues>(
70
74
  run(DEPENDENCY_TREE, { input: { implementation: id, dependencies: JSON.parse(key) } })
71
75
  .then((data) => {
72
76
  if (!live) return;
73
- setAnswer((data as Answer).dependencyTree);
77
+ setAnswer({ id, key, tree: (data as Answer).dependencyTree });
74
78
  timer = setTimeout(ask, POLL_MS);
75
79
  })
76
80
  // A server that refuses once will refuse again: no use asking every ten seconds.
@@ -87,7 +91,9 @@ export const useDependencyTree = <TValues extends FieldValues>(
87
91
  // eslint-disable-next-line react-hooks/exhaustive-deps
88
92
  }, [id, key]);
89
93
 
90
- const nodes = error ? undefined : answer?.dependencies;
94
+ const tree = !error && id && answer?.id === id ? answer.tree : undefined;
95
+ const nodes = tree?.dependencies;
91
96
  const unmet = useMemo(() => unmetDependencies(nodes), [nodes]);
92
- return { nodes, satisfied: error ? undefined : answer?.satisfied, unmet, error };
97
+ const pending = Boolean(id) && !error && answer?.key !== key;
98
+ return { nodes, satisfied: tree?.satisfied, unmet, error, pending };
93
99
  };
@@ -1,3 +1,4 @@
1
+ import type {BlokTaskControl} from './runtime/task';
1
2
  import {useEffect, useId, useMemo, useRef, useState} from 'react';
2
3
  import {cn} from '../vendor/core/util/utils';
3
4
  import {useBlokTailwind} from '../tailwind/useBlokTailwind';
@@ -84,6 +85,8 @@ type BlokRendererProps = {
84
85
  answerTask?: (values: Record<string, unknown>) => unknown;
85
86
  /** Starts the run an assign blok prepares (`assign.start()`). */
86
87
  startRun?: () => unknown;
88
+ /** Cancels, pauses, resumes, steps, interrupts or reruns `task` (`task.cancel()` and its kin). */
89
+ controlTask?: (operation: BlokTaskControl) => unknown;
87
90
  /** Where `persist` components keep their state by id; none: they keep nothing. */
88
91
  componentState?: BlokComponentStateStore | null;
89
92
  children?: React.ReactNode;
@@ -148,6 +151,7 @@ export default function BlokRenderer({
148
151
  readExecutor,
149
152
  answerTask,
150
153
  startRun,
154
+ controlTask,
151
155
  componentState = null,
152
156
  children,
153
157
  }: BlokRendererProps) {
@@ -202,6 +206,7 @@ export default function BlokRenderer({
202
206
  travelAt,
203
207
  answerTask,
204
208
  startRun,
209
+ controlTask,
205
210
  });
206
211
  return store;
207
212
  });
@@ -229,6 +234,10 @@ export default function BlokRenderer({
229
234
  runtimeStore.getState().setStartRun(startRun);
230
235
  }, [startRun, runtimeStore]);
231
236
 
237
+ useEffect(() => {
238
+ runtimeStore.getState().setControlTask(controlTask);
239
+ }, [controlTask, runtimeStore]);
240
+
232
241
  useEffect(() => {
233
242
  if (keptRoots) runtimeStore.getState().setKeptRoots(keptRoots);
234
243
  }, [keptRoots, runtimeStore]);
@@ -238,12 +238,22 @@ export const Fragment = createBlokComponent(
238
238
  ({buildChild, component}) => renderDeclaredChildren(component, buildChild),
239
239
  );
240
240
 
241
+ /** What the host adds around a blok; read by the host off the root, the blok itself draws the same either way. */
242
+ export const chromeSchema = z
243
+ .enum(['auto', 'none'])
244
+ .optional()
245
+ .describe(
246
+ "What the host draws around the blok of its own: `auto` (the default) adds what the blok does not place (the time slider, the open ask, the rest of the argument form, its buttons); `none` adds nothing, the blok places what it wants.",
247
+ );
248
+
241
249
  export const Html = createBlokComponent(
242
250
  {
243
251
  name: 'Html',
244
252
  acceptsChildren: true,
245
253
  placement: {childrenContext: 'html', notDownstreamOf: ['Html']},
246
- schema: z.object({}).describe("The root of an html blok (a panel, a dashboard, a popout's page): lays its children out as a fragment does, and names the blok's context."),
254
+ schema: z
255
+ .object({chrome: chromeSchema})
256
+ .describe("The root of an html blok (a panel, a dashboard, a popout's page): lays its children out as a fragment does, and names the blok's context."),
247
257
  },
248
258
  ({buildChild, component}) => renderDeclaredChildren(component, buildChild),
249
259
  );
@@ -424,14 +434,109 @@ export const Ask = createBlokComponent(
424
434
  /* args */
425
435
  /* -------------------------------------------------------------------------- */
426
436
 
427
- export const Args = createBlokComponent(
437
+ /** Port or dependency keys as a prop holds them: a list, or one string with spaces between. */
438
+ const keysOf = (value: unknown): string[] | undefined => {
439
+ if (Array.isArray(value)) return value.filter((key): key is string => typeof key === 'string');
440
+ if (typeof value === 'string') return value.split(/[\s,]+/).filter(Boolean);
441
+ return undefined;
442
+ };
443
+
444
+ const keyList = (what: string) => z.union([z.string(), z.array(z.string())]).optional().describe(what);
445
+
446
+ const argsSchema = z
447
+ .object({
448
+ only: keyList('Only these port keys: `only="exposure gain"` or `only={["exposure", "gain"]}`.'),
449
+ omit: keyList('Not these port keys.'),
450
+ given: z
451
+ .enum(['hide', 'show'])
452
+ .optional()
453
+ .describe('What to do with the arguments the caller gave (`assign.given.<key>`): `hide` leaves them out (the default), `show` lists them, locked.'),
454
+ })
455
+ .describe(
456
+ "The arguments of the run an assign blok starts, as a form generated from the action's ports: filled in right here, read as `args.<key>`. It draws the rest: every argument the caller did not give and no `<arg />` places.",
457
+ );
458
+
459
+ export const Args = createBlokComponent({name: 'args', schema: argsSchema}, ({component, schema}) => {
460
+ const blok = useBlok(component, schema);
461
+ const only = keysOf(useValue(blok.only));
462
+ const omit = keysOf(useValue(blok.omit));
463
+ const given = useValue(blok.given);
464
+ const host = useBlokRunHost();
465
+ return <>{host.renderArgs?.({only, omit, given: given === 'show' ? 'show' : 'hide'}) ?? null}</>;
466
+ });
467
+
468
+ const argSchema = z
469
+ .object({key: z.string().describe('The port key of the argument: `key="exposure"`.')})
470
+ .describe('One argument of the run an assign blok starts, as its port draws it; `<args />` then leaves it out. Nothing for an argument the caller gave: it is locked.');
471
+
472
+ export const Arg = createBlokComponent({name: 'arg', schema: argSchema}, ({component, schema}) => {
473
+ const key = useValue(useBlok(component, schema).key);
474
+ const host = useBlokRunHost();
475
+ return <>{typeof key === 'string' ? (host.renderArg?.(key) ?? null) : null}</>;
476
+ });
477
+
478
+ /* -------------------------------------------------------------------------- */
479
+ /* deps */
480
+ /* -------------------------------------------------------------------------- */
481
+
482
+ export const Deps = createBlokComponent(
483
+ {
484
+ name: 'deps',
485
+ schema: z
486
+ .object({})
487
+ .describe("The picker of the agents the run an assign blok starts would get: every dependency no `<dep />` places. Without it the host shows the picker beside the blok."),
488
+ },
489
+ () => <>{useBlokRunHost().renderDeps?.() ?? null}</>,
490
+ );
491
+
492
+ const depSchema = z
493
+ .object({key: z.string().describe('The dependency key: `key="microscope"`.')})
494
+ .describe('The picker of one dependency of the run an assign blok starts; `<deps />` then leaves it out.');
495
+
496
+ export const Dep = createBlokComponent({name: 'dep', schema: depSchema}, ({component, schema}) => {
497
+ const key = useValue(useBlok(component, schema).key);
498
+ const host = useBlokRunHost();
499
+ return <>{typeof key === 'string' ? (host.renderDep?.(key) ?? null) : null}</>;
500
+ });
501
+
502
+ /* -------------------------------------------------------------------------- */
503
+ /* returns, status */
504
+ /* -------------------------------------------------------------------------- */
505
+
506
+ const returnsSchema = z
507
+ .object({
508
+ only: keyList('Only these return port keys.'),
509
+ omit: keyList('Not these return port keys.'),
510
+ })
511
+ .describe("What `task` returned, as the action's return ports show it (an image as an image, a table as a table). Nothing before the first yield.");
512
+
513
+ export const Returns = createBlokComponent({name: 'returns', schema: returnsSchema}, ({component, schema}) => {
514
+ const blok = useBlok(component, schema);
515
+ const only = keysOf(useValue(blok.only));
516
+ const omit = keysOf(useValue(blok.omit));
517
+ return <>{useBlokRunHost().renderReturns?.({only, omit}) ?? null}</>;
518
+ });
519
+
520
+ export const Status = createBlokComponent(
521
+ {
522
+ name: 'status',
523
+ schema: z.object({}).describe('Where `task` stands, as one line the host draws: its state, how long it took, what it last said.'),
524
+ },
525
+ () => <>{useBlokRunHost().renderStatus?.() ?? null}</>,
526
+ );
527
+
528
+ /* -------------------------------------------------------------------------- */
529
+ /* timeline */
530
+ /* -------------------------------------------------------------------------- */
531
+
532
+ export const Timeline = createBlokComponent(
428
533
  {
429
- name: 'args',
534
+ name: 'timeline',
430
535
  schema: z
431
536
  .object({})
432
- .describe("The arguments of the run an assign blok starts, as a form generated from the action's ports: filled in right here, read as `args.<key>`."),
537
+ .describe("The time slider of what the blok shows (the run of `task`, or the history of its agents): dragging it shows the whole blok as it was at that moment. Nothing where the host has no clock."),
433
538
  },
434
- () => <>{useBlokRunHost().renderArgs?.() ?? null}</>,
539
+ () => <>{useBlokRunHost().renderTimeline?.() ?? null}</>,
435
540
  );
436
541
 
437
542
  export const controlBlokComponents = [
@@ -448,4 +553,10 @@ export const controlBlokComponents = [
448
553
  ErrorSlot,
449
554
  Ask,
450
555
  Args,
556
+ Arg,
557
+ Deps,
558
+ Dep,
559
+ Returns,
560
+ Status,
561
+ Timeline,
451
562
  ];
@@ -3,6 +3,16 @@ import {Button as ShadButton} from '../../vendor/core/ui/button';
3
3
  import {ButtonGroup as ShadButtonGroup} from '../../vendor/core/ui/button-group';
4
4
  import {Calendar as ShadCalendar} from '../../vendor/core/ui/calendar';
5
5
  import {Checkbox as ShadCheckbox} from '../../vendor/core/ui/checkbox';
6
+ import {
7
+ Command as ShadCommand,
8
+ CommandEmpty as ShadCommandEmpty,
9
+ CommandGroup as ShadCommandGroup,
10
+ CommandInput as ShadCommandInput,
11
+ CommandItem as ShadCommandItem,
12
+ CommandList as ShadCommandList,
13
+ } from '../../vendor/core/ui/command';
14
+ import {Popover as ShadPopover, PopoverContent as ShadPopoverContent, PopoverTrigger as ShadPopoverTrigger} from '../../vendor/core/ui/popover';
15
+ import {CalendarDays, Check, ChevronsUpDown} from 'lucide-react';
6
16
  import {
7
17
  Field as ShadField,
8
18
  FieldDescription as ShadFieldDescription,
@@ -765,6 +775,120 @@ const CalendarRender: BlokRender<Contracts['Calendar']> = ({component, schema})
765
775
  );
766
776
  };
767
777
 
778
+ const optionsOf = (raw: unknown): {value: string; label: string}[] =>
779
+ (Array.isArray(raw) ? raw : []).flatMap(option => {
780
+ if (typeof option === 'string') return [{value: option, label: option}];
781
+ if (option !== null && typeof option === 'object' && typeof (option as {value?: unknown}).value === 'string') {
782
+ const {value, label} = option as {value: string; label?: unknown};
783
+ return [{value, label: typeof label === 'string' ? label : value}];
784
+ }
785
+ return [];
786
+ });
787
+
788
+ const ComboboxRender: BlokRender<Contracts['Combobox']> = ({component, schema}) => {
789
+ const blok = useBlok(component, schema);
790
+ const bind = useValue(blok.bind);
791
+ const value = useValue(blok.value);
792
+ const defaultValue = useValue(blok.defaultValue);
793
+ const options = optionsOf(useValue(blok.options));
794
+ const placeholder = useValue(blok.placeholder);
795
+ const searchPlaceholder = useValue(blok.searchPlaceholder);
796
+ const emptyText = useValue(blok.emptyText);
797
+ const disabled = useValue(blok.disabled);
798
+ const className = useValue(blok.className);
799
+ const onChange = useEventAction(blok.onChange);
800
+ const [open, setOpen] = React.useState(false);
801
+
802
+ const controlled = useControlledValue<string>({bind, value, defaultValue, fallback: '', parse: asString});
803
+ const picked = options.find(option => option.value === controlled.value);
804
+
805
+ return (
806
+ <ShadPopover open={open} onOpenChange={setOpen}>
807
+ <ShadPopoverTrigger asChild>
808
+ <ShadButton
809
+ type="button"
810
+ variant="outline"
811
+ role="combobox"
812
+ aria-expanded={open}
813
+ disabled={disabled === true}
814
+ className={cn('w-full justify-between font-normal', !picked && 'text-muted-foreground', className)}
815
+ >
816
+ <span className="truncate">{picked?.label ?? (asString(placeholder) || 'Pick one')}</span>
817
+ <ChevronsUpDown className="size-4 shrink-0 opacity-50" />
818
+ </ShadButton>
819
+ </ShadPopoverTrigger>
820
+ <ShadPopoverContent className="w-(--radix-popover-trigger-width) p-0" align="start">
821
+ <ShadCommand>
822
+ <ShadCommandInput placeholder={asString(searchPlaceholder) || 'Search'} />
823
+ <ShadCommandList>
824
+ <ShadCommandEmpty>{asString(emptyText) || 'Nothing found'}</ShadCommandEmpty>
825
+ <ShadCommandGroup>
826
+ {options.map(option => (
827
+ <ShadCommandItem
828
+ key={option.value}
829
+ // Typing matches what is read, not the value behind it.
830
+ value={option.label}
831
+ onSelect={() => {
832
+ controlled.setValue(option.value);
833
+ onChange?.(option.value);
834
+ setOpen(false);
835
+ }}
836
+ >
837
+ <span className="truncate">{option.label}</span>
838
+ {option.value === controlled.value ? <Check className="ml-auto size-4" /> : null}
839
+ </ShadCommandItem>
840
+ ))}
841
+ </ShadCommandGroup>
842
+ </ShadCommandList>
843
+ </ShadCommand>
844
+ </ShadPopoverContent>
845
+ </ShadPopover>
846
+ );
847
+ };
848
+
849
+ const DatePickerRender: BlokRender<Contracts['DatePicker']> = ({component, schema}) => {
850
+ const blok = useBlok(component, schema);
851
+ const bind = useValue(blok.bind);
852
+ const value = useValue(blok.value);
853
+ const defaultValue = useValue(blok.defaultValue);
854
+ const placeholder = useValue(blok.placeholder);
855
+ const disabled = useValue(blok.disabled);
856
+ const className = useValue(blok.className);
857
+ const onChange = useEventAction(blok.onChange);
858
+ const [open, setOpen] = React.useState(false);
859
+
860
+ const controlled = useControlledValue<string>({bind, value, defaultValue, fallback: '', parse: asString});
861
+ const picked = parseIsoDate(controlled.value);
862
+
863
+ return (
864
+ <ShadPopover open={open} onOpenChange={setOpen}>
865
+ <ShadPopoverTrigger asChild>
866
+ <ShadButton
867
+ type="button"
868
+ variant="outline"
869
+ disabled={disabled === true}
870
+ className={cn('w-full justify-start gap-2 font-normal', !picked && 'text-muted-foreground', className)}
871
+ >
872
+ <CalendarDays className="size-4 shrink-0 opacity-50" />
873
+ <span className="truncate">{picked ? picked.toLocaleDateString(undefined, {dateStyle: 'medium', timeZone: 'UTC'}) : asString(placeholder) || 'Pick a date'}</span>
874
+ </ShadButton>
875
+ </ShadPopoverTrigger>
876
+ <ShadPopoverContent className="w-auto p-0" align="start">
877
+ <ShadCalendar
878
+ mode="single"
879
+ selected={picked}
880
+ onSelect={next => {
881
+ const nextValue = next ? toIsoDate(next) : '';
882
+ controlled.setValue(nextValue);
883
+ onChange?.(nextValue);
884
+ setOpen(false);
885
+ }}
886
+ />
887
+ </ShadPopoverContent>
888
+ </ShadPopover>
889
+ );
890
+ };
891
+
768
892
  export const formRenders = {
769
893
  Button: ButtonRender,
770
894
  ButtonGroup: ButtonGroupRender,
@@ -791,4 +915,6 @@ export const formRenders = {
791
915
  FieldSet: FieldSetRender,
792
916
  Field: FieldRender,
793
917
  Calendar: CalendarRender,
918
+ Combobox: ComboboxRender,
919
+ DatePicker: DatePickerRender,
794
920
  };