@arkitektio/bsx 6.6.2 → 6.8.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 (91) hide show
  1. package/dist/bsx/analyze.d.ts.map +1 -1
  2. package/dist/bsx/analyze.js +2 -2
  3. package/dist/bsx/analyze.js.map +1 -1
  4. package/dist/bsx/declared.d.ts +25 -1
  5. package/dist/bsx/declared.d.ts.map +1 -1
  6. package/dist/bsx/declared.js +34 -2
  7. package/dist/bsx/declared.js.map +1 -1
  8. package/dist/bsx/expr.d.ts +18 -4
  9. package/dist/bsx/expr.d.ts.map +1 -1
  10. package/dist/bsx/expr.js +46 -9
  11. package/dist/bsx/expr.js.map +1 -1
  12. package/dist/bsx/language.d.ts.map +1 -1
  13. package/dist/bsx/language.js +4 -2
  14. package/dist/bsx/language.js.map +1 -1
  15. package/dist/bsx/parse.d.ts +2 -0
  16. package/dist/bsx/parse.d.ts.map +1 -1
  17. package/dist/bsx/parse.js +63 -6
  18. package/dist/bsx/parse.js.map +1 -1
  19. package/dist/bsx/print.d.ts.map +1 -1
  20. package/dist/bsx/print.js +53 -10
  21. package/dist/bsx/print.js.map +1 -1
  22. package/dist/bsx/references.d.ts +23 -1
  23. package/dist/bsx/references.d.ts.map +1 -1
  24. package/dist/bsx/references.js +266 -14
  25. package/dist/bsx/references.js.map +1 -1
  26. package/dist/ports/rekuest.d.ts +1 -0
  27. package/dist/ports/rekuest.d.ts.map +1 -1
  28. package/dist/renderer/BlokRenderer.d.ts +4 -2
  29. package/dist/renderer/BlokRenderer.d.ts.map +1 -1
  30. package/dist/renderer/BlokRenderer.js +5 -1
  31. package/dist/renderer/BlokRenderer.js.map +1 -1
  32. package/dist/renderer/bloks/control.d.ts +5 -1
  33. package/dist/renderer/bloks/control.d.ts.map +1 -1
  34. package/dist/renderer/bloks/control.js +25 -3
  35. package/dist/renderer/bloks/control.js.map +1 -1
  36. package/dist/renderer/bloks/run/host.d.ts +5 -0
  37. package/dist/renderer/bloks/run/host.d.ts.map +1 -1
  38. package/dist/renderer/bloks/run/host.js.map +1 -1
  39. package/dist/renderer/runtime/context.d.ts +2 -1
  40. package/dist/renderer/runtime/context.d.ts.map +1 -1
  41. package/dist/renderer/runtime/context.js +4 -0
  42. package/dist/renderer/runtime/context.js.map +1 -1
  43. package/dist/renderer/runtime/hooks.d.ts +2 -0
  44. package/dist/renderer/runtime/hooks.d.ts.map +1 -1
  45. package/dist/renderer/runtime/hooks.js +12 -0
  46. package/dist/renderer/runtime/hooks.js.map +1 -1
  47. package/dist/renderer/runtime/resolution.d.ts +1 -0
  48. package/dist/renderer/runtime/resolution.d.ts.map +1 -1
  49. package/dist/renderer/runtime/resolution.js +11 -0
  50. package/dist/renderer/runtime/resolution.js.map +1 -1
  51. package/dist/renderer/runtime/schemas.d.ts.map +1 -1
  52. package/dist/renderer/runtime/schemas.js +1 -0
  53. package/dist/renderer/runtime/schemas.js.map +1 -1
  54. package/dist/renderer/runtime/types.d.ts +13 -0
  55. package/dist/renderer/runtime/types.d.ts.map +1 -1
  56. package/dist/renderer/runtime/types.js.map +1 -1
  57. package/dist/spec/bsx_v2.json +4804 -440
  58. package/dist/spec/catalogs/base@4.json +57 -1
  59. package/dist/spec/catalogs/base@4.json.js +57 -1
  60. package/dist/spec/vocabulary.d.ts +2 -0
  61. package/dist/spec/vocabulary.d.ts.map +1 -1
  62. package/dist/spec/vocabulary.js +2 -0
  63. package/dist/spec/vocabulary.js.map +1 -1
  64. package/dist/spec/vocabulary.json +19 -10
  65. package/dist/spec/vocabulary.json.js +19 -10
  66. package/package.json +1 -1
  67. package/src/bsx/analyze.ts +2 -2
  68. package/src/bsx/declared.ts +48 -2
  69. package/src/bsx/expr.ts +55 -11
  70. package/src/bsx/infer.test.ts +1 -1
  71. package/src/bsx/language.test.ts +17 -16
  72. package/src/bsx/language.ts +4 -2
  73. package/src/bsx/parse.ts +61 -5
  74. package/src/bsx/print.ts +50 -8
  75. package/src/bsx/references.test.ts +12 -11
  76. package/src/bsx/references.ts +277 -12
  77. package/src/ports/rekuest.ts +1 -1
  78. package/src/renderer/BlokRenderer.tsx +9 -0
  79. package/src/renderer/bloks/control.tsx +36 -4
  80. package/src/renderer/bloks/run/host.tsx +5 -0
  81. package/src/renderer/runtime/context.tsx +6 -0
  82. package/src/renderer/runtime/hooks.ts +13 -0
  83. package/src/renderer/runtime/resolution.ts +11 -1
  84. package/src/renderer/runtime/schemas.ts +1 -0
  85. package/src/renderer/runtime/types.ts +14 -0
  86. package/src/renderer/unbound.test.tsx +34 -1
  87. package/src/spec/bsx_v2.json +4804 -440
  88. package/src/spec/catalogs/base@4.json +57 -1
  89. package/src/spec/spec.test.ts +2 -2
  90. package/src/spec/vocabulary.json +19 -10
  91. package/src/spec/vocabulary.ts +4 -0
@@ -4,13 +4,13 @@ import {baseBlokView, blokViewFor, type BlokView} from '../spec/catalogs';
4
4
  import {blokCatalog} from './declared';
5
5
  import {resolveLocals} from './infer';
6
6
  import {parseBsx} from './parse';
7
- import {checkBlokTree, dependencyHint, mountedBlokScope, type BlokCheckScope} from './references';
7
+ import {boundScope, checkBlokTree, dependencyHint, mountedBlokScope, type BlokCheckScope} from './references';
8
8
  import type {BlokComponentNode} from '../renderer/runtime/types';
9
9
 
10
10
  /** Where a corpus case is checked: the spec's `mount`, and whether a catalog is read at all. */
11
11
  type CorpusMount = Omit<BlokCheckScope, 'catalog'> & {catalog: boolean};
12
12
 
13
- const scopeOf = (mount: CorpusMount): BlokCheckScope => ({kinds: mount.kinds, dependencies: mount.dependencies, args: mount.args, port: mount.port ?? null});
13
+ const scopeOf = (mount: CorpusMount): BlokCheckScope => ({kinds: mount.kinds, dependencies: mount.dependencies, args: mount.args, port: mount.port ?? null, workflows: mount.workflows ?? null});
14
14
  type CheckedCase = {
15
15
  name: string;
16
16
  source: string;
@@ -79,7 +79,7 @@ describe('the validator against the corpus', () => {
79
79
  describe('inference against the corpus', () => {
80
80
  it.each(checked.map(entry => [entry.name, entry] as const))('%s', (_name, entry) => {
81
81
  const {tree} = parseBsx(entry.source);
82
- const resolved = resolveLocals(tree, entry.mount.dependencies, caseView(entry.mount, tree));
82
+ const resolved = resolveLocals(tree, boundScope(tree, scopeOf(entry.mount)).dependencies, caseView(entry.mount, tree));
83
83
  expect(Object.keys(entry.resolved)).toEqual(['locals']);
84
84
  const locals = Object.fromEntries([...resolved].map(([node, {local}]) => [node, local]));
85
85
  expect(withoutDefaults(locals)).toEqual(withoutDefaults(entry.resolved.locals));
@@ -93,11 +93,11 @@ const mounted = mountedBlokScope();
93
93
 
94
94
  describe('findings', () => {
95
95
  it('name the node and prop they are about, with a filled message', () => {
96
- const {tree} = parseBsx(blok('custom', '<Card><Text text={deps.nope.x} /></Card>'));
96
+ const {tree} = parseBsx(blok('custom', '<Card><Text text={agents.nope.x} /></Card>'));
97
97
  const [found] = checkBlokTree(tree, mounted);
98
98
  expect(found).toMatchObject({code: 'deps.unknown', level: 'error', nodeId: 'Blok[0]/Card[0]/Text[0]', propKey: 'text'});
99
99
  expect(found.message).toBe(
100
- 'deps.nope.x: \'nope\' is not a dependency of the blok (its dependencies: none). Fix: dependencies=[AgentDependencyInput(key="nope")].',
100
+ 'agents.nope.x: \'nope\' is not a dependency of the blok (its dependencies: none). Fix: dependencies=[AgentDependencyInput(key="nope")].',
101
101
  );
102
102
  });
103
103
 
@@ -105,27 +105,28 @@ describe('findings', () => {
105
105
  const {tree} = parseBsx(
106
106
  blok(
107
107
  'custom',
108
- '<query name="positions" service="mikro" document="query { positions { id } }"><var key="agent" value={deps.laser.id} /></query><Card><Text text={queries.positions.status} /><Button onClick={deps.stage.move(x: 1)} /></Card>',
108
+ '<query name="positions" service="mikro" document="query { positions { id } }"><var key="agent" value={agents.laser.id} /></query><Card><Text text={queries.positions.status} /><Button onClick={agents.stage.move(x: 1)} /></Card>',
109
109
  ),
110
110
  );
111
111
  const found = checkBlokTree(tree, mountedBlokScope([], [{key: 'robot'}])).filter(finding => finding.code === 'deps.unknown');
112
112
  expect(found.map(finding => finding.message).sort()).toEqual([
113
113
  'onClick of <Button> (Blok[0]/Card[0]/Button[0]): \'stage\' is not a dependency of the blok (its dependencies: robot). Fix: dependencies=[AgentDependencyInput(key="stage")].',
114
- 'deps.laser.id: \'laser\' is not a dependency of the blok (its dependencies: robot). Fix: dependencies=[AgentDependencyInput(key="laser")].',
114
+ 'agents.laser.id: \'laser\' is not a dependency of the blok (its dependencies: robot). Fix: dependencies=[AgentDependencyInput(key="laser")].',
115
115
  ].sort());
116
116
  });
117
117
 
118
118
  it('take what the mount provides as written where the blok is mounted nowhere', () => {
119
- expect(checkBlokTree(parseBsx(blok('custom', '<Text text={deps.nope.x} /><Button onClick={deps.stage.move(x: 1)} />')).tree)).toEqual([]);
119
+ expect(checkBlokTree(parseBsx(blok('custom', '<Text text={agents.nope.x} /><Button onClick={agents.stage.move(x: 1)} />')).tree)).toEqual([]);
120
120
  });
121
121
 
122
122
  it('hint per kind what a blok reading an undeclared dependency does about it, as the spec does', () => {
123
- const message = (kind: string): string => checkBlokTree(parseBsx(blok(kind, '<Text text={deps.laser.power} />')).tree, mounted)[0]?.message ?? '';
123
+ const message = (kind: string): string => checkBlokTree(parseBsx(blok(kind, `<Text text={${kind === 'custom' ? 'agents' : 'deps'}.laser.power} />`)).tree, mounted)[0]?.message ?? '';
124
124
  expect(message('custom')).toContain('Fix: dependencies=[AgentDependencyInput(key="laser")].');
125
125
  expect(message('task')).toContain('Fix: dependencies=[AgentDependencyInput(key="laser")].');
126
126
  expect(message('action')).toContain('Fix: add a dependency parameter `laser` to the action.');
127
- // An agent blok has no deps root at all (roots.not_in_kind), so only the spec's wording is ported.
128
- expect(dependencyHint('laser', 'agent')).toBe('agent bloks read only `self`');
127
+ // An agent blok's dependencies are in its own tree.
128
+ expect(message('agent')).toContain('Fix: declare it in the blok: <dependencies key="laser" like="self.<action>" />, then read laser.<dependency>.');
129
+ expect(dependencyHint('laser', 'agent')).toBe('declare it in the blok: <dependencies key="laser" like="self.<action>" />, then read laser.<dependency>');
129
130
  });
130
131
 
131
132
  it('scope a let to its loop and an into name to the whole tree', () => {
@@ -6,7 +6,8 @@ import type {
6
6
  BlokUtilCall,
7
7
  } from '../renderer/runtime/types';
8
8
  import {blokViewFor, defaultBlokView, type BlokView, type SpecComponent} from '../spec/catalogs';
9
- import {TEXT_NODE} from './parse';
9
+ import {PICK_FUNCTION, TEXT_NODE} from './parse';
10
+ import {AGENTS_ROOT, PICK_VERB, REFERENCE_SEPARATOR} from './expr';
10
11
  import {valueFitsPort} from '../spec/locals';
11
12
  import {LOCAL_ANY, localDeclared, resolveLocals, type ResolvedLocal} from './infer';
12
13
  import {
@@ -14,6 +15,11 @@ import {
14
15
  blokHeader,
15
16
  content,
16
17
  declarationProblem,
18
+ declaredDependencies,
19
+ dependenciesAction,
20
+ dependenciesOwner,
21
+ dependenciesTarget,
22
+ DEPENDENCIES_COMPONENT,
17
23
  declaredQueries,
18
24
  declaredSubscriptions,
19
25
  headerProblem,
@@ -27,6 +33,7 @@ import {
27
33
  SUBSCRIPTION_COMPONENT,
28
34
  VAR_COMPONENT,
29
35
  type BlokHeader,
36
+ type DeclaredDependencies,
30
37
  type DeclaredQuery,
31
38
  type DeclaredSubscription,
32
39
  } from './declared';
@@ -34,6 +41,7 @@ import {
34
41
  argFits,
35
42
  finding,
36
43
  kindIn,
44
+ kindReads,
37
45
  loadVocabulary,
38
46
  type BlokFinding,
39
47
  type BlokKind,
@@ -81,6 +89,8 @@ export type BlokScopeStateDependency = {
81
89
  /** A dependency of the blok; `self` types `self`. No `*_dependencies` (null) means any. */
82
90
  export type BlokScopeDependency = {
83
91
  key: string;
92
+ app?: string | null;
93
+ version?: string | null;
84
94
  action_dependencies?: readonly BlokScopeActionDependency[] | null;
85
95
  state_dependencies?: readonly BlokScopeStateDependency[] | null;
86
96
  };
@@ -179,6 +189,13 @@ export type BlokCheckScope = {
179
189
  demo?: {deps?: unknown; args?: unknown; task?: unknown} | null;
180
190
  /** The port a port blok is the widget of, as a match: what `port.value` is typed as. Null (or absent) leaves the value open. */
181
191
  port?: BlokPortMatch | null;
192
+ /**
193
+ * Per action of the blok's own agent, that action's dependencies: what an
194
+ * agent blok's `<dependencies key="cells" like="self.<action>" />` declares as
195
+ * `deps.cells__<dependency>`. Null (or absent): not known here, they are then
196
+ * taken as written.
197
+ */
198
+ workflows?: Readonly<Record<string, readonly BlokScopeDependency[]>> | null;
182
199
  };
183
200
 
184
201
  /** A blok checked on its own, mounted nowhere: what an editor checks from the source alone. */
@@ -195,6 +212,76 @@ const LOGO = 'LOGO';
195
212
  const SCENE = 'SCENE';
196
213
  const PANEL = 'PANEL';
197
214
 
215
+ const PICKER_COMPONENT = 'deppicker';
216
+ /** `cells.options.<dependency>`: the agents that fit a declared dependency, to pick among. */
217
+ const OPTIONS_SEGMENT = 'options';
218
+ /** What one of them reads as. */
219
+ const OPTION_FIELDS: readonly BlokPortMatch[] = [
220
+ {key: 'id', kind: 'STRING'},
221
+ {key: 'name', kind: 'STRING', nullable: true},
222
+ {key: 'connected', kind: 'BOOL'},
223
+ {key: 'picked', kind: 'BOOL'},
224
+ ];
225
+
226
+ /** The dependency `<key>.<name>` of declared dependencies, as it is stored. */
227
+ export const referenceKey = (key: string, name: string): string => `${key}${REFERENCE_SEPARATOR}${name}`;
228
+
229
+ /** A stored dependency at its first separator: `[key, name]`, or null when it holds none. */
230
+ const splitReference = (dependency: string): [string, string] | null => {
231
+ const at = dependency.indexOf(REFERENCE_SEPARATOR);
232
+ return at < 0 ? null : [dependency.slice(0, at), dependency.slice(at + REFERENCE_SEPARATOR.length)];
233
+ };
234
+
235
+ /** The dependencies `declared` borrows, each keyed `<key>__<dependency>`; or what is wrong with its `like`. */
236
+ export const borrowedDependencies = (
237
+ declared: DeclaredDependencies,
238
+ workflows: Readonly<Record<string, readonly BlokScopeDependency[]>>,
239
+ ): BlokScopeDependency[] | string => {
240
+ const action = dependenciesAction(declared);
241
+ if (action === null) return 'is not self.<action>';
242
+ if (!Object.prototype.hasOwnProperty.call(workflows, action)) return `names no action of the app ('${action}')`;
243
+ if (!workflows[action].length) return `names an action with no dependencies ('${action}')`;
244
+ const taken = workflows[action].find(each => each.key === OPTIONS_SEGMENT || each.key === PICK_VERB || each.key.includes(REFERENCE_SEPARATOR));
245
+ if (taken) return `names an action with a dependency called '${taken.key}', which cannot be read through a reference: rename that parameter of ${action}`;
246
+ return workflows[action].map(dependency => ({...dependency, key: referenceKey(declared.key, dependency.key)}));
247
+ };
248
+
249
+ /**
250
+ * `scope` with the dependencies an agent blok declares itself (`<dependencies>`)
251
+ * among its dependencies, keyed `<key>__<dependency>` and demanded as their
252
+ * action demands them. A declaration whose `like` does not resolve is left out
253
+ * (the checker says why), as is every one where the app's actions are not
254
+ * known (`workflows` null).
255
+ */
256
+ export const boundScope = (tree: BlokComponentNode, scope: BlokCheckScope): BlokCheckScope => {
257
+ const workflows = scope.workflows ?? null;
258
+ if (workflows === null || blokHeader(tree)?.kind !== 'agent') return scope;
259
+ const known = new Set((scope.dependencies ?? []).map(dependency => dependency.key));
260
+ const borrowed: BlokScopeDependency[] = [];
261
+ for (const declared of declaredDependencies(tree)) {
262
+ const found = borrowedDependencies(declared, workflows);
263
+ if (typeof found === 'string') continue;
264
+ for (const dependency of found) {
265
+ if (known.has(dependency.key)) continue;
266
+ known.add(dependency.key);
267
+ borrowed.push(dependency);
268
+ }
269
+ }
270
+ return borrowed.length ? {...scope, dependencies: [...(scope.dependencies ?? []), ...borrowed]} : scope;
271
+ };
272
+
273
+ const CUSTOM_KIND: BlokKind = 'custom';
274
+
275
+ /**
276
+ * `text` (a path, a call) as a custom blok writes it: a bound agent stored `deps.<key>`
277
+ * reads `agents.<key>`; one through declared dependencies is left.
278
+ */
279
+ const asWritten = (text: string): string => {
280
+ if (!text.startsWith('deps.')) return text;
281
+ const rest = text.slice('deps.'.length);
282
+ return rest.split('.')[0].split('(')[0].includes(REFERENCE_SEPARATOR) ? text : `${AGENTS_ROOT}.${rest}`;
283
+ };
284
+
198
285
  /** A context as a `<Blok context>` spells it (`PANEL` → `panel`). */
199
286
  export const spelledContext = (context: string): string => context.toLowerCase();
200
287
 
@@ -385,11 +472,11 @@ const DIGITS = /^[0-9]+$/;
385
472
  * (the spec's `dependency_hint`):
386
473
  * - a custom or task blok declares it, to copy as it is: `dependencies=[AgentDependencyInput(key="laser")]`;
387
474
  * - an action blok's dependencies are its action's: ``add a dependency parameter `laser` to the action``;
388
- * - an agent blok has none: ``agent bloks read only `self` ``.
475
+ * - an agent blok declares it in its own tree: `<dependencies key="laser" like="self.<action>" />`.
389
476
  */
390
477
  export const dependencyHint = (key: string, kind: BlokKind): string => {
391
478
  if (kind === 'action' || kind === 'assign' || kind === 'port') return `add a dependency parameter \`${key}\` to the action`;
392
- if (kind === 'agent') return 'agent bloks read only `self`';
479
+ if (kind === 'agent') return `declare it in the blok: <dependencies key="${key}" like="self.<action>" />, then read ${key}.<dependency>`;
393
480
  return `dependencies=[AgentDependencyInput(key="${key}")]`;
394
481
  };
395
482
 
@@ -480,6 +567,8 @@ class Checker {
480
567
  /** The id of the root that says `chrome="none"`, when it does. */
481
568
  private readonly chromeless: string | null;
482
569
  private readonly colour: RegExp;
570
+ /** The dependencies an agent blok declares itself, by key. */
571
+ private readonly declared = new Map<string, DeclaredDependencies>();
483
572
 
484
573
  readonly header: BlokHeader;
485
574
  readonly scope: BlokCheckScope;
@@ -499,10 +588,24 @@ class Checker {
499
588
  this.colour = colourPattern(this.vocabulary);
500
589
  }
501
590
 
502
- add(code: string, nodeId: string | null, fields: DiagnosticFields = {}, propKey?: string): void {
591
+ add(code: string, nodeId: string | null, written: DiagnosticFields = {}, propKey?: string): void {
592
+ const fields =
593
+ this.kindName === CUSTOM_KIND
594
+ ? Object.fromEntries(Object.entries(written).map(([key, value]) => [key, typeof value === 'string' ? asWritten(value) : value]))
595
+ : written;
503
596
  this.findings.push(finding(code, fields, {...(nodeId !== null ? {nodeId} : {}), ...(propKey !== undefined ? {propKey} : {})}));
504
597
  }
505
598
 
599
+ /** Whether the kind reads the stored `root`: a custom blok's `agents` is stored `deps`. */
600
+ private reads(root: string): boolean {
601
+ return kindReads(this.kind, root);
602
+ }
603
+
604
+ /** Whether `dependency` (as stored) is declared in the blok's own tree: any of an agent blok, a `<key>__<name>` one of a custom blok. */
605
+ private declares(dependency: string): boolean {
606
+ return this.kindName === 'agent' || (this.kindName === CUSTOM_KIND && dependency.includes(REFERENCE_SEPARATOR));
607
+ }
608
+
506
609
  private rootsText(): string {
507
610
  return [...this.kind.roots].sort().join(', ');
508
611
  }
@@ -534,6 +637,7 @@ class Checker {
534
637
  this.add('blok.content', tree.id, {context: contextName, expected: allowed.map(name => `one <${name}>`).join(' or '), found});
535
638
  }
536
639
  }
640
+ this.checkDependencies(tree);
537
641
  this.checkLocalPositions(tree);
538
642
  this.checkQueries(tree);
539
643
  for (const [name, sites] of intoSites(tree)) {
@@ -593,6 +697,143 @@ class Checker {
593
697
  }
594
698
  }
595
699
 
700
+ /**
701
+ * A `<dependencies>` is a child of an agent or custom blok's `<Blok>`, keyed once, and
702
+ * names an action that has dependencies: one of the app's own, or of a bound agent (custom).
703
+ */
704
+ private checkDependencies(tree: BlokComponentNode): void {
705
+ for (const [node, ancestors] of iterWithParents(tree)) {
706
+ if (node.component !== DEPENDENCIES_COMPONENT) continue;
707
+ const literal = (name: string): unknown => node.props?.find(prop => prop.key === name)?.static_value;
708
+ const key = literal('key');
709
+ if (ancestors.length !== 1 || (this.kindName !== 'agent' && this.kindName !== CUSTOM_KIND)) {
710
+ const at = ancestors.length > 1 ? ancestors[ancestors.length - 1].id : `a${article(this.kindName)} ${this.kindName} blok`;
711
+ this.add('dependencies.position', node.id, {key: typeof key === 'string' ? key : '?', at});
712
+ continue;
713
+ }
714
+ if (typeof key !== 'string' || !LOCAL_NAME.test(key)) {
715
+ this.add('dependencies.key', node.id, {node: node.id, problem: 'has no plain key'});
716
+ continue;
717
+ }
718
+ if (key === 'self' || this.declared.has(key)) {
719
+ const problem = key === 'self' ? "is keyed self, which is the blok's own agent" : `declares '${key}' a second time`;
720
+ this.add('dependencies.key', node.id, {node: node.id, problem});
721
+ continue;
722
+ }
723
+ const like = literal(LIKE_PROP);
724
+ const declared: DeclaredDependencies = {key, node: node.id, like: typeof like === 'string' ? like : null};
725
+ this.declared.set(key, declared);
726
+ const workflows = this.scope.workflows ?? null;
727
+ const owner = dependenciesOwner(declared);
728
+ if (this.kindName === CUSTOM_KIND) {
729
+ if (owner === null || owner === 'self') {
730
+ this.add('dependencies.like', node.id, {key, like: declared.like ?? '', problem: 'is not agents.<name>.<action>'});
731
+ } else if (this.mounted && !this.dependencies.has(owner)) {
732
+ this.add('dependencies.like', node.id, {key, like: declared.like ?? '', problem: `names the agent '${owner}', which the blok is not bound to`});
733
+ }
734
+ } else if (owner !== 'self') {
735
+ this.add('dependencies.like', node.id, {key, like: declared.like ?? '', problem: 'is not self.<action>'});
736
+ } else if (workflows !== null) {
737
+ const borrowed = borrowedDependencies(declared, workflows);
738
+ if (typeof borrowed === 'string') this.add('dependencies.like', node.id, {key, like: declared.like ?? '', problem: borrowed});
739
+ }
740
+ }
741
+ }
742
+
743
+ /**
744
+ * Whether the dependencies declared as `key` are known here: its action is
745
+ * one of the app's, so what is read through it is held to that action's dependencies.
746
+ */
747
+ private typed(key: string): boolean {
748
+ const declared = this.declared.get(key);
749
+ const workflows = this.scope.workflows ?? null;
750
+ // A bound agent's actions are known only where the blok runs.
751
+ if (declared === undefined || dependenciesOwner(declared) !== 'self' || workflows === null) return false;
752
+ return typeof borrowedDependencies(declared, workflows) !== 'string';
753
+ }
754
+
755
+ /**
756
+ * Whether `dependency` (stored `<key>__<name>`) is none this blok
757
+ * declares: such dependencies are the ones in its own tree, mounted or not.
758
+ */
759
+ private undeclared(dependency: string): boolean {
760
+ if (!this.declares(dependency) || dependency === 'self') return false;
761
+ const split = splitReference(dependency);
762
+ if (split === null || !this.declared.has(split[0])) return true;
763
+ return this.typed(split[0]) && split[1] !== OPTIONS_SEGMENT && !this.dependencies.has(dependency);
764
+ }
765
+
766
+ /** `<key>.options.<dependency>`: the agents that fit it, each `{id, name, connected, picked}`. */
767
+ private options(key: string, rest: readonly string[], path: string, nodeId: string, propKey: string | undefined): Match {
768
+ if (!rest.length) {
769
+ this.add('roots.whole', nodeId, {path, root: `${key}.${OPTIONS_SEGMENT}`}, propKey);
770
+ return null;
771
+ }
772
+ if (this.typed(key) && !this.dependencies.has(referenceKey(key, rest[0]))) {
773
+ this.add('deps.unknown', nodeId, {path, key: `${key}.${rest[0]}`, keys: this.dependencyKnown(key), hint: dependencyHint(key, this.kindName)}, propKey);
774
+ return null;
775
+ }
776
+ const listed: BlokPortMatch = {key: rest[0], kind: 'LIST', children: [{key: ITEM, kind: 'DICT', children: OPTION_FIELDS}]};
777
+ return this.descend(listed, rest.slice(1), path, nodeId, propKey);
778
+ }
779
+
780
+ /** `<key>.pick(<dependency>: <agent id>)`: declared dependencies, and dependencies of them. */
781
+ private checkPick(call: BlokUtilCall, where: Where): void {
782
+ const named = (call.arguments ?? []).find(argument => argument.key === 'key');
783
+ const picks = (call.arguments ?? []).find(argument => argument.key === 'picks');
784
+ const key = named?.value_literal;
785
+ if (typeof key !== 'string' || !this.declared.has(key)) {
786
+ const shown = typeof key === 'string' ? key : '?';
787
+ this.add('deps.unknown', where.node.id, {path: `${shown}.${PICK_VERB}(...)`, key: shown, keys: this.dependencyKnown(shown), hint: dependencyHint(shown, this.kindName)}, where.key);
788
+ return;
789
+ }
790
+ if (!this.typed(key)) return;
791
+ for (const pick of picks?.value_dict ?? []) {
792
+ if (pick.key != null && !this.dependencies.has(referenceKey(key, pick.key))) {
793
+ this.add('deps.unknown', where.node.id, {path: `${key}.${PICK_VERB}(...)`, key: `${key}.${pick.key}`, keys: this.dependencyKnown(key), hint: dependencyHint(key, this.kindName)}, where.key);
794
+ }
795
+ }
796
+ }
797
+
798
+ /** `<deppicker key="cells" />` or `key="cells.microscope"`: declared dependencies. */
799
+ private checkPicker(node: BlokComponentNode): void {
800
+ const written = node.props?.find(prop => prop.key === 'key')?.static_value;
801
+ if (typeof written !== 'string') return; // catalog.props says a key is needed
802
+ const dot = written.indexOf('.');
803
+ const key = dot < 0 ? written : written.slice(0, dot);
804
+ const name = dot < 0 ? '' : written.slice(dot + 1);
805
+ const known = this.declared.has(key) && (!name || !this.typed(key) || this.dependencies.has(referenceKey(key, name)));
806
+ if (!known) {
807
+ this.add('deps.unknown', node.id, {path: `${node.component}.key`, key: written, keys: this.dependencyKnown(key), hint: dependencyHint(key, this.kindName)}, 'key');
808
+ }
809
+ }
810
+
811
+ /** `with <key>`: dependencies the blok declares, of the action that is called. */
812
+ private checkWith(call: BlokAgentCall, where: Where): void {
813
+ const given = call.given ?? '';
814
+ const action = actionKeyFor(call);
815
+ const declared = this.declared.get(given);
816
+ if (!declared) {
817
+ const keys = [...this.declared.keys()].sort().join(', ') || 'none';
818
+ this.add('deps.unknown', where.node.id, {path: `with ${given}`, key: given, keys, hint: dependencyHint(given, this.kindName)}, where.key);
819
+ return;
820
+ }
821
+ const target = dependenciesTarget(declared);
822
+ const of = dependenciesAction(declared);
823
+ if (target !== null && (target[0] !== call.dependency || target[1] !== action)) this.add('with.mismatch', where.node.id, {path: whereText(where), key: given, action, of}, where.key);
824
+ }
825
+
826
+ /** What `key` may read through, for a message: the dependencies declared under it, else the keys the blok declares. */
827
+ private dependencyKnown(key: string): string {
828
+ if (this.kindName !== 'agent' && !this.declared.has(key)) return [...this.dependencies.keys()].sort().join(', ') || 'none';
829
+ if (this.declared.has(key) && this.typed(key)) {
830
+ const prefix = `${key}${REFERENCE_SEPARATOR}`;
831
+ const names = [...this.dependencies.keys()].filter(name => name.startsWith(prefix)).map(name => `${key}.${name.slice(prefix.length)}`);
832
+ return names.sort().join(', ') || 'none';
833
+ }
834
+ return [...this.declared.keys()].sort().join(', ') || 'none';
835
+ }
836
+
596
837
  /** Queries and subscriptions are children of the `<Blok>`, each declared once and readable. */
597
838
  private checkQueries(tree: BlokComponentNode): void {
598
839
  const first = new Map<string, string>();
@@ -745,6 +986,7 @@ class Checker {
745
986
  }
746
987
  if (spec) this.checkCatalog(node, spec, ancestors);
747
988
  this.checkHostPart(node, ancestors);
989
+ if (node.component === PICKER_COMPONENT) this.checkPicker(node);
748
990
  for (const prop of node.props ?? []) this.checkProp(node, prop, spec, scope);
749
991
  }
750
992
 
@@ -862,7 +1104,7 @@ class Checker {
862
1104
  }
863
1105
  // An effect that is a root's own (port.set) belongs to the kinds that read that root.
864
1106
  const needs = effect === undefined ? null : (vocabulary.functions.get(effect)?.needs ?? null);
865
- if (effect !== undefined && needs !== null && !this.kind.roots.includes(needs)) {
1107
+ if (effect !== undefined && needs !== null && !this.reads(needs)) {
866
1108
  this.notInKind(node.id, effect, needs, prop.key);
867
1109
  }
868
1110
  if (prop.key === BIND_PROP) {
@@ -970,17 +1212,23 @@ class Checker {
970
1212
  this.notInKind(where.node.id, `self.${action}(...)`, 'self', where.key);
971
1213
  return;
972
1214
  }
973
- } else if (!this.kind.roots.includes('deps')) {
1215
+ } else if (!this.reads('deps')) {
974
1216
  this.notInKind(where.node.id, `deps.${call.dependency}.${action}(...)`, 'deps', where.key);
975
1217
  return;
976
1218
  }
977
- const dependency = this.dependencies.get(call.dependency);
1219
+ if (call.given != null) this.checkWith(call, where);
1220
+ const dependency = this.undeclared(call.dependency) ? undefined : this.dependencies.get(call.dependency);
978
1221
  if (!dependency) {
979
- if (call.dependency !== 'self' && this.mounted) {
1222
+ const agent = this.declares(call.dependency);
1223
+ if (call.dependency !== 'self' && (agent ? this.undeclared(call.dependency) : this.mounted)) {
1224
+ // One the blok does not declare itself is the mount's, taken as it is keyed.
1225
+ const written = agent ? (splitReference(call.dependency)?.[0] ?? call.dependency) : call.dependency;
1226
+ const key = agent ? call.dependency.split(REFERENCE_SEPARATOR).join('.') : call.dependency;
1227
+ const keys = agent ? this.dependencyKnown(written) : [...this.dependencies.keys()].sort().join(', ') || 'none';
980
1228
  this.add(
981
1229
  'deps.unknown',
982
1230
  where.node.id,
983
- {path: owner, key: call.dependency, keys: [...this.dependencies.keys()].sort().join(', ') || 'none', hint: dependencyHint(call.dependency, this.kindName)},
1231
+ {path: owner, key, keys, hint: dependencyHint(written, this.kindName)},
984
1232
  where.key,
985
1233
  );
986
1234
  }
@@ -1044,6 +1292,7 @@ class Checker {
1044
1292
  }
1045
1293
  if (fn.effect && !top) this.add('callback.nested', where.node.id, {what: call.operation}, where.key);
1046
1294
  if (call.operation in VERBS && top) this.checkQueryEffect(call, where);
1295
+ if (call.operation === PICK_FUNCTION) this.checkPick(call, where);
1047
1296
  const keys = new Set((call.arguments ?? []).map(argument => argument.key).filter((key): key is string => key != null));
1048
1297
  const unknown = [...keys].filter(key => !fn.keys.includes(key) && !DIGITS.test(key)).sort();
1049
1298
  if (unknown.length) {
@@ -1175,7 +1424,8 @@ class Checker {
1175
1424
  report('roots.unknown', {path, root: namespace ? `${root} (a function namespace)` : root});
1176
1425
  return null;
1177
1426
  }
1178
- if (!this.kind.roots.includes(root)) {
1427
+ // `agents` is how a custom blok writes `deps`: a stored tree never holds it.
1428
+ if (!this.reads(root) || root === AGENTS_ROOT) {
1179
1429
  this.notInKind(nodeId, path, root, propKey);
1180
1430
  return null;
1181
1431
  }
@@ -1190,9 +1440,23 @@ class Checker {
1190
1440
  report('roots.whole', {path, root: 'deps'});
1191
1441
  return null;
1192
1442
  }
1443
+ // An agent blok's dependencies are in its own tree (`cells.microscope`, stored
1444
+ // `deps.cells__microscope`): one it does not declare is unknown, mounted or not;
1445
+ // one it declares and this side cannot type is open.
1446
+ if (this.declares(rest[0]) && rest[0] !== 'self') {
1447
+ const split = splitReference(rest[0]);
1448
+ const key = split ? split[0] : rest[0];
1449
+ if (split && this.declared.has(key) && split[1] === OPTIONS_SEGMENT) return this.options(key, rest.slice(1), path, nodeId, propKey);
1450
+ if (this.undeclared(rest[0])) {
1451
+ report('deps.unknown', {path, key: split ? `${key}.${split[1]}` : rest[0], keys: this.dependencyKnown(key), hint: dependencyHint(key, this.kindName)});
1452
+ return null;
1453
+ }
1454
+ const found = this.dependencies.get(rest[0]);
1455
+ return found ? this.agent(found, rest[0], rest.slice(1), path, nodeId, propKey) : openMatch(path);
1456
+ }
1193
1457
  const dependency = this.dependencies.get(rest[0]);
1194
1458
  if (!dependency) {
1195
- if (!this.mounted) return openMatch(path);
1459
+ if (!this.mounted || this.declares(rest[0])) return openMatch(path);
1196
1460
  report('deps.unknown', {path, key: rest[0], keys: [...this.dependencies.keys()].sort().join(', ') || 'none', hint: dependencyHint(rest[0], this.kindName)});
1197
1461
  return null;
1198
1462
  }
@@ -1460,7 +1724,8 @@ export const checkBlokTree = (
1460
1724
  const problem = headerProblem(tree);
1461
1725
  if (problem !== null) return [problem];
1462
1726
  const header = blokHeader(tree) as BlokHeader;
1463
- const checker = new Checker(header, scope, view, resolveLocals(tree, scope.dependencies, view));
1727
+ const bound = boundScope(tree, scope);
1728
+ const checker = new Checker(header, bound, view, resolveLocals(tree, bound.dependencies, view));
1464
1729
  checker.checkDeclarations(tree);
1465
1730
  checker.walk(tree);
1466
1731
  if (header.context === LOGO) checker.findings.push(...checkLogo(tree, scope.demo));
@@ -320,7 +320,7 @@ export type BlokArgumentInnerFragment = (
320
320
  export type BlokComponentPropFragment = { __typename?: 'ComponentProp', key: string, staticValue?: any | null, declaresValue?: string | null, dynamicValue?: { __typename?: 'DynamicValue', path?: string | null, literal?: string | null } | null, agentCall?: { __typename?: 'AgentCall', dependency: string, operation: string, arguments?: Array<(
321
321
  { __typename?: 'ActionArgument' }
322
322
  & BlokArgumentFragment
323
- )> | null } | null, utilCall?: { __typename?: 'UtilCall', operation: string, arguments?: Array<(
323
+ )> | null, given?: string | null } | null, utilCall?: { __typename?: 'UtilCall', operation: string, arguments?: Array<(
324
324
  { __typename?: 'ActionArgument' }
325
325
  & BlokArgumentFragment
326
326
  )> | null } | null };
@@ -28,6 +28,7 @@ import {
28
28
  type BlokNodeErrorProps,
29
29
  type BlokDispatchActionHandler,
30
30
  type BlokInvokeFunctionHandler,
31
+ type BlokPickDependenciesHandler,
31
32
  type BlokRefuseActionHandler,
32
33
  type BlokUnavailableDependencies,
33
34
  type BlokLockedActions,
@@ -102,6 +103,8 @@ type BlokRendererProps = {
102
103
  answerTask?: (values: Record<string, unknown>) => unknown;
103
104
  /** Starts the run an assign blok prepares (`assign.start()`). */
104
105
  startRun?: () => unknown;
106
+ /** Binds declared dependencies to agents (`cells.pick(microscope: id)`): the key of the `<dependencies>`, and per dependency an agent id. */
107
+ pickDependencies?: BlokPickDependenciesHandler;
105
108
  /** Writes the port a port blok is the widget of (`port.set(...)`, `port.clear()`, `port.reset()`, `port.touch()`). */
106
109
  writePort?: (operation: BlokPortOperation, value?: unknown) => unknown;
107
110
  /** Cancels, pauses, resumes, steps, interrupts or reruns `task` (`task.cancel()` and its kin). */
@@ -186,6 +189,7 @@ export default function BlokRenderer({
186
189
  readExecutor,
187
190
  answerTask,
188
191
  startRun,
192
+ pickDependencies,
189
193
  writePort,
190
194
  controlTask,
191
195
  componentState = null,
@@ -260,6 +264,7 @@ export default function BlokRenderer({
260
264
  travelAt,
261
265
  answerTask,
262
266
  startRun,
267
+ pickDependencies,
263
268
  writePort,
264
269
  controlTask,
265
270
  });
@@ -289,6 +294,10 @@ export default function BlokRenderer({
289
294
  runtimeStore.getState().setStartRun(startRun);
290
295
  }, [startRun, runtimeStore]);
291
296
 
297
+ useEffect(() => {
298
+ runtimeStore.getState().setPickDependencies(pickDependencies);
299
+ }, [pickDependencies, runtimeStore]);
300
+
292
301
  useEffect(() => {
293
302
  runtimeStore.getState().setWritePort(writePort);
294
303
  }, [writePort, runtimeStore]);
@@ -284,9 +284,9 @@ export const chromeSchema = z
284
284
  );
285
285
 
286
286
  const BLOK_COMPONENT = 'Blok';
287
- const DECLARATIONS: ReadonlySet<string> = new Set(['local', 'query', 'subscription', 'var']);
287
+ const DECLARATIONS: ReadonlySet<string> = new Set(['local', 'query', 'subscription', 'var', 'dependencies']);
288
288
 
289
- /** The children of a node that draw: its declarations (`local`, `query`, `subscription`, `var`) left out. */
289
+ /** The children of a node that draw: its declarations (`local`, `query`, `subscription`, `var`, `dependencies`) left out. */
290
290
  export const drawnChildren = (component: BlokComponentNode): BlokComponentNode[] =>
291
291
  (component.children ?? []).filter(child => !DECLARATIONS.has(child.component));
292
292
 
@@ -323,8 +323,8 @@ export const Blok = createBlokComponent(
323
323
  },
324
324
  );
325
325
 
326
- const declaration = <T extends BlokObjectSchema>(name: string, schema: T, acceptsChildren = false) =>
327
- createBlokComponent({name, acceptsChildren, placement: {inheritsContext: true}, schema}, () => null);
326
+ const declaration = <T extends BlokObjectSchema>(name: string, schema: T, acceptsChildren = false, api: {kinds?: readonly string[]; since?: number} = {}) =>
327
+ createBlokComponent({name, acceptsChildren, placement: {inheritsContext: true}, schema, ...api}, () => null);
328
328
 
329
329
  /** `<local name="x" default={...} persist />`: draws nothing; its parent provides it to its children (`runtime/locals`). */
330
330
  export const Local = declaration(
@@ -387,6 +387,21 @@ export const Var = declaration(
387
387
  .describe('One variable of its query or subscription: an expression over args, blok-level locals and agents, or a literal.'),
388
388
  );
389
389
 
390
+ /** `<dependencies key like>`: draws nothing; the host binds each `deps.<key>__<dependency>` to an agent. */
391
+ export const Dependencies = declaration(
392
+ 'dependencies',
393
+ z
394
+ .object({
395
+ key: z.string().describe('The key they are read through, bare: cells.<dependency>.'),
396
+ like: z.string().describe('The action whose dependencies they are: self.<action>, in a custom blok agents.<name>.<action>.'),
397
+ })
398
+ .describe(
399
+ "Declares the dependencies of one action, for an agent blok one of the app's own, for a custom blok one of an agent it is bound to: read and called through its key (cells.<dependency>), picked by the viewer, and handed to a run of that action with `with <key>`. A child of <Blok>; draws nothing.",
400
+ ),
401
+ false,
402
+ {kinds: ['agent', 'custom'], since: 3},
403
+ );
404
+
390
405
  /* -------------------------------------------------------------------------- */
391
406
  /* match */
392
407
  /* -------------------------------------------------------------------------- */
@@ -628,6 +643,21 @@ export const Dep = createBlokComponent({name: 'dep', schema: depSchema}, ({compo
628
643
  return <>{typeof key === 'string' ? (host.renderDep?.(key) ?? null) : null}</>;
629
644
  });
630
645
 
646
+ const depPickerSchema = z
647
+ .object({
648
+ key: z
649
+ .string()
650
+ .describe('One dependency (`cells.microscope`), or the key alone (`cells`) for every dependency declared under it that no other picker places.'),
651
+ })
652
+ .describe('The ready-made picker of the agent a declared dependency is bound to: the agents that fit, the chosen one shown, always changeable. In an agent or a custom blok.');
653
+
654
+ /** `<deppicker key="cells.microscope" />`: the host's picker of declared dependencies; nothing without a host. */
655
+ export const Deppicker = createBlokComponent({name: 'deppicker', schema: depPickerSchema, kinds: ['agent', 'custom'], since: 3}, ({component, schema}) => {
656
+ const key = useValue(useBlok(component, schema).key);
657
+ const host = useBlokRunHost();
658
+ return <>{typeof key === 'string' ? (host.renderDepPicker?.(key) ?? null) : null}</>;
659
+ });
660
+
631
661
  /* -------------------------------------------------------------------------- */
632
662
  /* returns, status */
633
663
  /* -------------------------------------------------------------------------- */
@@ -719,6 +749,7 @@ export const controlBlokComponents = [
719
749
  Query,
720
750
  Subscription,
721
751
  Var,
752
+ Dependencies,
722
753
  Match,
723
754
  Case,
724
755
  Default,
@@ -730,6 +761,7 @@ export const controlBlokComponents = [
730
761
  Arg,
731
762
  Deps,
732
763
  Dep,
764
+ Deppicker,
733
765
  Returns,
734
766
  Status,
735
767
  Timeline,
@@ -43,6 +43,11 @@ export type BlokRunHost = {
43
43
  renderDeps?: () => React.ReactNode;
44
44
  /** The picker of one dependency of that run, by key (`<dep key="microscope" />`). */
45
45
  renderDep?: (key: string) => React.ReactNode;
46
+ /**
47
+ * The ready-made picker of declared dependencies (`<deppicker key=... />`), by the key as
48
+ * written: one dependency (`cells.microscope`), or every one under a key no other picker places (`cells`).
49
+ */
50
+ renderDepPicker?: (key: string) => React.ReactNode;
46
51
  /** What the run returned, as its return ports show it (`<returns />`); nothing before the first yield. */
47
52
  renderReturns?: (options?: Pick<BlokArgsOptions, 'only' | 'omit'>) => React.ReactNode;
48
53
  /** Where the run stands, as one line (`<status />`). */