@arkitektio/bsx 6.7.0 → 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 (47) hide show
  1. package/dist/bsx/declared.d.ts +10 -3
  2. package/dist/bsx/declared.d.ts.map +1 -1
  3. package/dist/bsx/declared.js +14 -3
  4. package/dist/bsx/declared.js.map +1 -1
  5. package/dist/bsx/expr.d.ts +5 -3
  6. package/dist/bsx/expr.d.ts.map +1 -1
  7. package/dist/bsx/expr.js +18 -7
  8. package/dist/bsx/expr.js.map +1 -1
  9. package/dist/bsx/language.d.ts.map +1 -1
  10. package/dist/bsx/language.js +3 -2
  11. package/dist/bsx/language.js.map +1 -1
  12. package/dist/bsx/parse.d.ts.map +1 -1
  13. package/dist/bsx/parse.js +23 -6
  14. package/dist/bsx/parse.js.map +1 -1
  15. package/dist/bsx/print.d.ts.map +1 -1
  16. package/dist/bsx/print.js +10 -3
  17. package/dist/bsx/print.js.map +1 -1
  18. package/dist/bsx/references.d.ts.map +1 -1
  19. package/dist/bsx/references.js +59 -21
  20. package/dist/bsx/references.js.map +1 -1
  21. package/dist/renderer/bloks/control.js +4 -4
  22. package/dist/renderer/bloks/control.js.map +1 -1
  23. package/dist/spec/bsx_v2.json +813 -19
  24. package/dist/spec/catalogs/base@4.json +7 -5
  25. package/dist/spec/catalogs/base@4.json.js +7 -5
  26. package/dist/spec/vocabulary.d.ts +2 -0
  27. package/dist/spec/vocabulary.d.ts.map +1 -1
  28. package/dist/spec/vocabulary.js +2 -0
  29. package/dist/spec/vocabulary.js.map +1 -1
  30. package/dist/spec/vocabulary.json +14 -12
  31. package/dist/spec/vocabulary.json.js +14 -12
  32. package/package.json +1 -1
  33. package/src/bsx/declared.ts +16 -5
  34. package/src/bsx/expr.ts +17 -8
  35. package/src/bsx/infer.test.ts +1 -1
  36. package/src/bsx/language.test.ts +17 -16
  37. package/src/bsx/language.ts +3 -2
  38. package/src/bsx/parse.ts +23 -4
  39. package/src/bsx/print.ts +9 -2
  40. package/src/bsx/references.test.ts +6 -6
  41. package/src/bsx/references.ts +60 -19
  42. package/src/renderer/bloks/control.tsx +5 -5
  43. package/src/spec/bsx_v2.json +813 -19
  44. package/src/spec/catalogs/base@4.json +7 -5
  45. package/src/spec/spec.test.ts +1 -1
  46. package/src/spec/vocabulary.json +14 -12
  47. package/src/spec/vocabulary.ts +4 -0
@@ -108,7 +108,8 @@ describe('completeBsx: components and props', () => {
108
108
  describe('completeBsx: expressions', () => {
109
109
  it('offers the roots of the kind, locals, records and namespaces', () => {
110
110
  const items = labels('<Text text={|');
111
- expect(items).toEqual(expect.arrayContaining(['deps', 'args', 'queries', 'viewer', 'speed', 'str', 'true']));
111
+ expect(items).toEqual(expect.arrayContaining(['agents', 'args', 'queries', 'viewer', 'speed', 'str', 'true']));
112
+ expect(items).not.toContain('deps');
112
113
  expect(items).not.toContain('self');
113
114
  expect(items).not.toContain('task');
114
115
  expect(items).not.toContain('event');
@@ -116,14 +117,14 @@ describe('completeBsx: expressions', () => {
116
117
  });
117
118
 
118
119
  it('walks agents: states, tasks, assets, fields, and actions only in callbacks', () => {
119
- expect(labels('<Text text={deps.|')).toEqual(['stage']);
120
- expect(labels('<Text text={deps.stage.|')).toEqual(['position', 'tasks', 'assets', 'id', 'name', 'connected']);
121
- expect(labels('<Button onClick={deps.stage.|')).toContain('move');
122
- expect(at('<Button onClick={deps.stage.|').find(item => item.label === 'move')?.insertText).toBe('move(x: ${1}, y: ${2})');
123
- expect(labels('<Text text={deps.stage.position.|')).toEqual(['x', 'y']);
124
- expect(labels('<Text text={deps.stage.tasks.|')).toEqual(['move']);
125
- expect(labels('<Text text={deps.stage.tasks.move.|')).toEqual(expect.arrayContaining(['status', 'running', 'returns', 'args']));
126
- expect(labels('<Text text={deps.stage.tasks.move.returns.|')).toEqual(['arrived']);
120
+ expect(labels('<Text text={agents.|')).toEqual(['stage']);
121
+ expect(labels('<Text text={agents.stage.|')).toEqual(['position', 'tasks', 'assets', 'id', 'name', 'connected']);
122
+ expect(labels('<Button onClick={agents.stage.|')).toContain('move');
123
+ expect(at('<Button onClick={agents.stage.|').find(item => item.label === 'move')?.insertText).toBe('move(x: ${1}, y: ${2})');
124
+ expect(labels('<Text text={agents.stage.position.|')).toEqual(['x', 'y']);
125
+ expect(labels('<Text text={agents.stage.tasks.|')).toEqual(['move']);
126
+ expect(labels('<Text text={agents.stage.tasks.move.|')).toEqual(expect.arrayContaining(['status', 'running', 'returns', 'args']));
127
+ expect(labels('<Text text={agents.stage.tasks.move.returns.|')).toEqual(['arrived']);
127
128
  });
128
129
 
129
130
  it('offers query records and refetch in a callback', () => {
@@ -145,11 +146,11 @@ describe('completeBsx: expressions', () => {
145
146
  });
146
147
 
147
148
  it('offers into names, lets and event fields where they are bound', () => {
148
- expect(labels('<Card><Button onClick={deps.stage.move(x: 1, y: 2) into run} /><Text>{run.|')).toContain('progress');
149
- expect(labels('<Card><Button onClick={deps.stage.move(x: 1, y: 2) into run} /><Text>{|')).toContain('run');
149
+ expect(labels('<Card><Button onClick={agents.stage.move(x: 1, y: 2) into run} /><Text>{run.|')).toContain('progress');
150
+ expect(labels('<Card><Button onClick={agents.stage.move(x: 1, y: 2) into run} /><Text>{|')).toContain('run');
150
151
  expect(labels('<foreach items={args.image} let="p" key={p}><Text text={|')).toContain('p');
151
- expect(labels('<Slider onChange={deps.stage.move(x: |')).toContain('event');
152
- expect(labels('<Slider onChange={deps.stage.move(x: event.|')).toEqual(['value']);
152
+ expect(labels('<Slider onChange={agents.stage.move(x: |')).toContain('event');
153
+ expect(labels('<Slider onChange={agents.stage.move(x: event.|')).toEqual(['value']);
153
154
  expect(labels('<suspense><error><Text text={|')).toContain('error');
154
155
  });
155
156
 
@@ -161,7 +162,7 @@ describe('completeBsx: expressions', () => {
161
162
  });
162
163
 
163
164
  it('offers into after a task call', () => {
164
- expect(labels('<Button onClick={deps.stage.move(x: 1, y: 2) |')).toEqual(['into']);
165
+ expect(labels('<Button onClick={agents.stage.move(x: 1, y: 2) |')).toEqual(['into']);
165
166
  expect(labels("<Text text={str.upper('|")).toEqual([]);
166
167
  });
167
168
  });
@@ -192,11 +193,11 @@ describe('analyzeBsx', () => {
192
193
  const analyze = (source: string, overrides: Partial<BlokCheckScope> = {}) => analyzeBsx(source, {scope: {...scope, ...overrides}});
193
194
 
194
195
  it('marks a finding at its prop, with its code', () => {
195
- const source = '<Blok kind="custom" context="panel"><Text text={deps.stage.speed} /></Blok>';
196
+ const source = '<Blok kind="custom" context="panel"><Text text={agents.stage.speed} /></Blok>';
196
197
  const {markers} = analyze(source);
197
198
  expect(markers).toHaveLength(1);
198
199
  expect(markers[0]).toMatchObject({code: 'deps.unknown_state', severity: 'error'});
199
- expect(source.slice(markers[0].range.start, markers[0].range.end)).toBe('deps.stage.speed');
200
+ expect(source.slice(markers[0].range.start, markers[0].range.end)).toBe('agents.stage.speed');
200
201
  });
201
202
 
202
203
  it('marks warnings as warnings', () => {
@@ -616,7 +616,7 @@ const completeExpression = (env: BsxEnvironment, text: string, expression: strin
616
616
  if (lets.includes(first)) return [];
617
617
  if (into.includes(first)) {
618
618
  // `self.go() with cells into run`: the `with` clause sits between the call and its name.
619
- const call = new RegExp(`(?:self|deps\\.(\\w+))\\.(\\w+)\\([^)]*\\)(?:\\s+with\\s+\\w+)?\\s+${INTO_KEYWORD}\\s+${first}\\b`).exec(text);
619
+ const call = new RegExp(`(?:self|(?:deps|agents)\\.(\\w+))\\.(\\w+)\\([^)]*\\)(?:\\s+with\\s+\\w+)?\\s+${INTO_KEYWORD}\\s+${first}\\b`).exec(text);
620
620
  const dependency = call ? dependencyOf(env, call[1] ?? 'self') : undefined;
621
621
  const action = dependency?.action_dependencies?.find(candidate => candidate.key === call?.[2]);
622
622
  return taskRecord(rest, action?.demand?.return_matches);
@@ -643,6 +643,7 @@ const completeExpression = (env: BsxEnvironment, text: string, expression: strin
643
643
  case 'self':
644
644
  return agent(dependencyOf(env, 'self'), rest);
645
645
  case 'deps':
646
+ case 'agents': // a custom blok's spelling of its bound agents
646
647
  if (rest.length === 0) return dependenciesOf(env).filter(dependency => dependency.key !== 'self').map(dependency => item(dependency.key, 'dependency', 'dependency'));
647
648
  return agent(dependencyOf(env, rest[0]), rest.slice(1));
648
649
  case 'args':
@@ -784,7 +785,7 @@ export const signatureBsx = (text: string, offset: number, env: BsxEnvironment):
784
785
  };
785
786
  }
786
787
  const parts = call.callee.split('.');
787
- const target = parts[0] === 'self' && parts.length === 2 ? ['self', parts[1]] : parts[0] === 'deps' && parts.length === 3 ? [parts[1], parts[2]] : null;
788
+ const target = parts[0] === 'self' && parts.length === 2 ? ['self', parts[1]] : (parts[0] === 'deps' || parts[0] === 'agents') && parts.length === 3 ? [parts[1], parts[2]] : null;
788
789
  if (!target) return null;
789
790
  const action = dependencyOf(env, target[0])?.action_dependencies?.find(candidate => candidate.key === target[1]);
790
791
  if (!action) return null;
package/src/bsx/parse.ts CHANGED
@@ -14,6 +14,7 @@ import {
14
14
  dotted,
15
15
  isLocalName,
16
16
  Locator,
17
+ AGENTS_ROOT,
17
18
  parseAttribute,
18
19
  parseExpression,
19
20
  PICK_VERB,
@@ -75,6 +76,8 @@ export const FETCH_MORE_FUNCTION = 'query.fetch_more';
75
76
  /** What `<key>.pick(<dependency>: <agent id>)` is stored as. */
76
77
  export const PICK_FUNCTION = 'deps.pick';
77
78
  const DEPENDENCIES_COMPONENT = 'dependencies';
79
+ const BLOK_COMPONENT = 'Blok';
80
+ const LIKE_PROP = 'like';
78
81
  export const QUERY_SUGAR: Readonly<Record<string, string>> = {refetch: REFETCH_FUNCTION, fetch_more: FETCH_MORE_FUNCTION};
79
82
 
80
83
  const isQuerySugar = (call: CallExpr): boolean =>
@@ -187,9 +190,14 @@ class Markup {
187
190
 
188
191
  /** The keys of the `<dependencies>` read so far: what a later expression may read through. */
189
192
  readonly references = new Set<string>();
193
+ /** Whether the root is a custom blok: its bound agents are written `agents.<key>`. */
194
+ custom = false;
190
195
 
191
196
  /** A `<dependencies key="cells" />` is read through from here on (`cells.microscope`). */
192
197
  private declares(element: MarkupElement): void {
198
+ if (element.name === BLOK_COMPONENT) {
199
+ this.custom = element.attributes.some(attribute => attribute.name === 'kind' && attribute.value === 'custom');
200
+ }
193
201
  if (element.name !== DEPENDENCIES_COMPONENT) return;
194
202
  const key = element.attributes.find(attribute => attribute.name === 'key')?.value;
195
203
  if (typeof key === 'string' && isLocalName(key)) this.references.add(key);
@@ -264,7 +272,7 @@ class Markup {
264
272
  const inner = this.source.slice(start, end);
265
273
  this.index = end + 1;
266
274
  if (!inner.trim()) throw this.fail('expr.syntax', start, {detail: `the value of ${name} is empty`});
267
- const expression = parseAttribute(inner, start, this.locator, new Set(this.references));
275
+ const expression = parseAttribute(inner, start, this.locator, new Set(this.references), this.custom);
268
276
  return {name, value: expression, offset, nameEnd, valueStart: start, end};
269
277
  }
270
278
  throw this.fail('bsx.syntax', undefined, {detail: `${name}= takes "a string" or {an expression}`});
@@ -324,7 +332,7 @@ class Markup {
324
332
  this.index = end + 1;
325
333
  const stripped = inner.trim();
326
334
  if (!stripped || (stripped.startsWith('/*') && stripped.endsWith('*/'))) continue;
327
- element.children.push({kind: 'container', expression: parseExpression(inner, start, this.locator, new Set(this.references)), offset});
335
+ element.children.push({kind: 'container', expression: parseExpression(inner, start, this.locator, new Set(this.references), this.custom), offset});
328
336
  continue;
329
337
  }
330
338
  if (this.at('}')) throw this.fail('bsx.syntax', undefined, {detail: "unexpected '}' in text; write {'}'}"});
@@ -575,6 +583,9 @@ class Lowering {
575
583
  }
576
584
  if (value === true) return {key: attribute.name, static_value: true};
577
585
  if (typeof value === 'string') {
586
+ if (attribute.name === LIKE_PROP && (component === LOCAL_COMPONENT || component === DEPENDENCIES_COMPONENT) && this.markup.custom) {
587
+ return {key: attribute.name, static_value: this.customLike(value, attribute.offset)};
588
+ }
578
589
  if ((attribute.name === FOREACH_LET_PROP || attribute.name === FOREACH_INDEX_PROP) && component === FOREACH_COMPONENT) {
579
590
  return {key: attribute.name, static_value: value, declares_value: value};
580
591
  }
@@ -585,6 +596,15 @@ class Lowering {
585
596
  return this.value(attribute.name, value, attribute.offset);
586
597
  }
587
598
 
599
+ /** A custom blok's `like="agents.<key>..."` as it is stored: `deps.<key>...`. */
600
+ private customLike(like: string, offset: number): string {
601
+ const dot = like.indexOf('.');
602
+ const root = dot < 0 ? like : like.slice(0, dot);
603
+ const rest = dot < 0 ? '' : like.slice(dot + 1);
604
+ if (root === 'deps') throw this.fail('roots.custom_deps', offset, {path: like});
605
+ return root === AGENTS_ROOT && rest ? `deps.${rest}` : like;
606
+ }
607
+
588
608
  private value(key: string, expression: Expr, offset: number): BlokComponentProp {
589
609
  switch (expression.type) {
590
610
  case 'into': {
@@ -642,7 +662,7 @@ class Lowering {
642
662
  return null;
643
663
  }
644
664
 
645
- /** A task call (`self.<action>(...)`, `deps.<key>.<action>(...)`), or null. */
665
+ /** A task call (`self.<action>(...)`, `deps.<key>.<action>(...)`; a custom blok's `agents.<key>` was read as the latter), or null. */
646
666
  private agentCall(call: CallExpr): BlokAgentCall | null {
647
667
  const {callee} = call;
648
668
  let dependency: string;
@@ -657,7 +677,6 @@ class Lowering {
657
677
  if (call.given !== undefined) throw this.fail('callback.with', call.offset);
658
678
  return null;
659
679
  }
660
- if (call.given !== undefined && dependency !== 'self') throw this.fail('callback.with', call.offset);
661
680
  const args: BlokActionArgument[] = [];
662
681
  const seen = new Set<string>();
663
682
  for (const argument of call.arguments) {
package/src/bsx/print.ts CHANGED
@@ -22,7 +22,7 @@ import {
22
22
  TEMPLATE_FUNCTION,
23
23
  } from './parse';
24
24
  import {declaredDependencies} from './declared';
25
- import {PICK_VERB, REFERENCE_SEPARATOR} from './expr';
25
+ import {AGENTS_ROOT, PICK_VERB, REFERENCE_SEPARATOR} from './expr';
26
26
 
27
27
  /**
28
28
  * Print a stored v2 tree as BSX: the inverse of `parseBsx`, the port of
@@ -283,7 +283,10 @@ class Printer {
283
283
  }
284
284
  const value = prop.static_value;
285
285
  if (value === true) return key;
286
- if (typeof value === 'string') return `${key}=${quoted(value)}`;
286
+ if (typeof value === 'string') {
287
+ const agents = this.custom && key === 'like' && (node.component === 'local' || node.component === 'dependencies') && value.startsWith('deps.');
288
+ return `${key}=${quoted(agents ? `${AGENTS_ROOT}.${value.slice('deps.'.length)}` : value)}`;
289
+ }
287
290
  if (value !== null && typeof value === 'object' && key === CLASS_NAME) {
288
291
  return refuse(`<${node.component}> (${node.id}): a static className list reads back as str.classes`);
289
292
  }
@@ -319,6 +322,8 @@ class Printer {
319
322
 
320
323
  /** The keys of the `<dependencies>` the tree declares: what it reads through, bare. */
321
324
  references: ReadonlySet<string> = new Set();
325
+ /** Whether the tree is a custom blok: its bound agents (stored `deps.<key>`) are written `agents.<key>`. */
326
+ custom = false;
322
327
 
323
328
  /** `path` as BSX writes it: one through declared dependencies (stored `deps.cells__microscope.stage`) reads `cells.microscope.stage`. */
324
329
  private path(path: string): string {
@@ -327,6 +332,7 @@ class Printer {
327
332
  const at = parts[1].indexOf(REFERENCE_SEPARATOR);
328
333
  const key = at < 0 ? '' : parts[1].slice(0, at);
329
334
  if (at >= 0 && this.references.has(key)) return [key, parts[1].slice(at + REFERENCE_SEPARATOR.length), ...parts.slice(2)].join('.');
335
+ if (this.custom) return [AGENTS_ROOT, ...parts.slice(1)].join('.');
330
336
  }
331
337
  return path;
332
338
  }
@@ -435,6 +441,7 @@ export const printBsx = (node: BlokComponentNode, options: {view?: BlokView; ind
435
441
  const lines: string[] = [];
436
442
  const printer = new Printer(options.view ?? defaultBlokView(), options.indent ?? 2);
437
443
  printer.references = new Set(declaredDependencies(node).map(declared => declared.key));
444
+ printer.custom = node.component === 'Blok' && (node.props ?? []).some(prop => prop.key === 'kind' && prop.static_value === 'custom');
438
445
  printer.node(node, `${node.component}[0]`, 0, lines);
439
446
  return lines.join('\n');
440
447
  };
@@ -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,22 +105,22 @@ 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.');
@@ -7,7 +7,7 @@ import type {
7
7
  } from '../renderer/runtime/types';
8
8
  import {blokViewFor, defaultBlokView, type BlokView, type SpecComponent} from '../spec/catalogs';
9
9
  import {PICK_FUNCTION, TEXT_NODE} from './parse';
10
- import {PICK_VERB, REFERENCE_SEPARATOR} from './expr';
10
+ import {AGENTS_ROOT, PICK_VERB, REFERENCE_SEPARATOR} from './expr';
11
11
  import {valueFitsPort} from '../spec/locals';
12
12
  import {LOCAL_ANY, localDeclared, resolveLocals, type ResolvedLocal} from './infer';
13
13
  import {
@@ -17,6 +17,8 @@ import {
17
17
  declarationProblem,
18
18
  declaredDependencies,
19
19
  dependenciesAction,
20
+ dependenciesOwner,
21
+ dependenciesTarget,
20
22
  DEPENDENCIES_COMPONENT,
21
23
  declaredQueries,
22
24
  declaredSubscriptions,
@@ -39,6 +41,7 @@ import {
39
41
  argFits,
40
42
  finding,
41
43
  kindIn,
44
+ kindReads,
42
45
  loadVocabulary,
43
46
  type BlokFinding,
44
47
  type BlokKind,
@@ -267,6 +270,18 @@ export const boundScope = (tree: BlokComponentNode, scope: BlokCheckScope): Blok
267
270
  return borrowed.length ? {...scope, dependencies: [...(scope.dependencies ?? []), ...borrowed]} : scope;
268
271
  };
269
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
+
270
285
  /** A context as a `<Blok context>` spells it (`PANEL` → `panel`). */
271
286
  export const spelledContext = (context: string): string => context.toLowerCase();
272
287
 
@@ -573,10 +588,24 @@ class Checker {
573
588
  this.colour = colourPattern(this.vocabulary);
574
589
  }
575
590
 
576
- 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;
577
596
  this.findings.push(finding(code, fields, {...(nodeId !== null ? {nodeId} : {}), ...(propKey !== undefined ? {propKey} : {})}));
578
597
  }
579
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
+
580
609
  private rootsText(): string {
581
610
  return [...this.kind.roots].sort().join(', ');
582
611
  }
@@ -669,15 +698,15 @@ class Checker {
669
698
  }
670
699
 
671
700
  /**
672
- * A `<dependencies>` is a child of an agent blok's `<Blok>`, keyed once, and
673
- * names one of the app's own actions that has dependencies.
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).
674
703
  */
675
704
  private checkDependencies(tree: BlokComponentNode): void {
676
705
  for (const [node, ancestors] of iterWithParents(tree)) {
677
706
  if (node.component !== DEPENDENCIES_COMPONENT) continue;
678
707
  const literal = (name: string): unknown => node.props?.find(prop => prop.key === name)?.static_value;
679
708
  const key = literal('key');
680
- if (ancestors.length !== 1 || this.kindName !== 'agent') {
709
+ if (ancestors.length !== 1 || (this.kindName !== 'agent' && this.kindName !== CUSTOM_KIND)) {
681
710
  const at = ancestors.length > 1 ? ancestors[ancestors.length - 1].id : `a${article(this.kindName)} ${this.kindName} blok`;
682
711
  this.add('dependencies.position', node.id, {key: typeof key === 'string' ? key : '?', at});
683
712
  continue;
@@ -695,7 +724,14 @@ class Checker {
695
724
  const declared: DeclaredDependencies = {key, node: node.id, like: typeof like === 'string' ? like : null};
696
725
  this.declared.set(key, declared);
697
726
  const workflows = this.scope.workflows ?? null;
698
- if (dependenciesAction(declared) === 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') {
699
735
  this.add('dependencies.like', node.id, {key, like: declared.like ?? '', problem: 'is not self.<action>'});
700
736
  } else if (workflows !== null) {
701
737
  const borrowed = borrowedDependencies(declared, workflows);
@@ -711,15 +747,17 @@ class Checker {
711
747
  private typed(key: string): boolean {
712
748
  const declared = this.declared.get(key);
713
749
  const workflows = this.scope.workflows ?? null;
714
- return declared !== undefined && workflows !== null && typeof borrowedDependencies(declared, workflows) !== 'string';
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';
715
753
  }
716
754
 
717
755
  /**
718
- * Whether `dependency` (stored `<key>__<name>`) is none this agent blok
719
- * declares: its dependencies are the ones in its own tree, mounted or not.
756
+ * Whether `dependency` (stored `<key>__<name>`) is none this blok
757
+ * declares: such dependencies are the ones in its own tree, mounted or not.
720
758
  */
721
759
  private undeclared(dependency: string): boolean {
722
- if (this.kindName !== 'agent' || dependency === 'self') return false;
760
+ if (!this.declares(dependency) || dependency === 'self') return false;
723
761
  const split = splitReference(dependency);
724
762
  if (split === null || !this.declared.has(split[0])) return true;
725
763
  return this.typed(split[0]) && split[1] !== OPTIONS_SEGMENT && !this.dependencies.has(dependency);
@@ -780,12 +818,14 @@ class Checker {
780
818
  this.add('deps.unknown', where.node.id, {path: `with ${given}`, key: given, keys, hint: dependencyHint(given, this.kindName)}, where.key);
781
819
  return;
782
820
  }
821
+ const target = dependenciesTarget(declared);
783
822
  const of = dependenciesAction(declared);
784
- if (of !== null && of !== action) this.add('with.mismatch', where.node.id, {path: whereText(where), key: given, action, of}, where.key);
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);
785
824
  }
786
825
 
787
826
  /** What `key` may read through, for a message: the dependencies declared under it, else the keys the blok declares. */
788
827
  private dependencyKnown(key: string): string {
828
+ if (this.kindName !== 'agent' && !this.declared.has(key)) return [...this.dependencies.keys()].sort().join(', ') || 'none';
789
829
  if (this.declared.has(key) && this.typed(key)) {
790
830
  const prefix = `${key}${REFERENCE_SEPARATOR}`;
791
831
  const names = [...this.dependencies.keys()].filter(name => name.startsWith(prefix)).map(name => `${key}.${name.slice(prefix.length)}`);
@@ -1064,7 +1104,7 @@ class Checker {
1064
1104
  }
1065
1105
  // An effect that is a root's own (port.set) belongs to the kinds that read that root.
1066
1106
  const needs = effect === undefined ? null : (vocabulary.functions.get(effect)?.needs ?? null);
1067
- if (effect !== undefined && needs !== null && !this.kind.roots.includes(needs)) {
1107
+ if (effect !== undefined && needs !== null && !this.reads(needs)) {
1068
1108
  this.notInKind(node.id, effect, needs, prop.key);
1069
1109
  }
1070
1110
  if (prop.key === BIND_PROP) {
@@ -1172,16 +1212,16 @@ class Checker {
1172
1212
  this.notInKind(where.node.id, `self.${action}(...)`, 'self', where.key);
1173
1213
  return;
1174
1214
  }
1175
- } else if (!this.kind.roots.includes('deps')) {
1215
+ } else if (!this.reads('deps')) {
1176
1216
  this.notInKind(where.node.id, `deps.${call.dependency}.${action}(...)`, 'deps', where.key);
1177
1217
  return;
1178
1218
  }
1179
1219
  if (call.given != null) this.checkWith(call, where);
1180
1220
  const dependency = this.undeclared(call.dependency) ? undefined : this.dependencies.get(call.dependency);
1181
1221
  if (!dependency) {
1182
- if (call.dependency !== 'self' && (this.kindName === 'agent' ? this.undeclared(call.dependency) : this.mounted)) {
1183
- // Outside an agent blok a dependency is the mount's, taken as it is keyed.
1184
- const agent = this.kindName === 'agent';
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.
1185
1225
  const written = agent ? (splitReference(call.dependency)?.[0] ?? call.dependency) : call.dependency;
1186
1226
  const key = agent ? call.dependency.split(REFERENCE_SEPARATOR).join('.') : call.dependency;
1187
1227
  const keys = agent ? this.dependencyKnown(written) : [...this.dependencies.keys()].sort().join(', ') || 'none';
@@ -1384,7 +1424,8 @@ class Checker {
1384
1424
  report('roots.unknown', {path, root: namespace ? `${root} (a function namespace)` : root});
1385
1425
  return null;
1386
1426
  }
1387
- 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) {
1388
1429
  this.notInKind(nodeId, path, root, propKey);
1389
1430
  return null;
1390
1431
  }
@@ -1402,7 +1443,7 @@ class Checker {
1402
1443
  // An agent blok's dependencies are in its own tree (`cells.microscope`, stored
1403
1444
  // `deps.cells__microscope`): one it does not declare is unknown, mounted or not;
1404
1445
  // one it declares and this side cannot type is open.
1405
- if (this.kindName === 'agent' && rest[0] !== 'self') {
1446
+ if (this.declares(rest[0]) && rest[0] !== 'self') {
1406
1447
  const split = splitReference(rest[0]);
1407
1448
  const key = split ? split[0] : rest[0];
1408
1449
  if (split && this.declared.has(key) && split[1] === OPTIONS_SEGMENT) return this.options(key, rest.slice(1), path, nodeId, propKey);
@@ -1415,7 +1456,7 @@ class Checker {
1415
1456
  }
1416
1457
  const dependency = this.dependencies.get(rest[0]);
1417
1458
  if (!dependency) {
1418
- if (!this.mounted || this.kindName === 'agent') return openMatch(path);
1459
+ if (!this.mounted || this.declares(rest[0])) return openMatch(path);
1419
1460
  report('deps.unknown', {path, key: rest[0], keys: [...this.dependencies.keys()].sort().join(', ') || 'none', hint: dependencyHint(rest[0], this.kindName)});
1420
1461
  return null;
1421
1462
  }
@@ -393,13 +393,13 @@ export const Dependencies = declaration(
393
393
  z
394
394
  .object({
395
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>.'),
396
+ like: z.string().describe('The action whose dependencies they are: self.<action>, in a custom blok agents.<name>.<action>.'),
397
397
  })
398
398
  .describe(
399
- "Declares the dependencies of one of the app's own actions for an agent blok: 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.",
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
400
  ),
401
401
  false,
402
- {kinds: ['agent'], since: 3},
402
+ {kinds: ['agent', 'custom'], since: 3},
403
403
  );
404
404
 
405
405
  /* -------------------------------------------------------------------------- */
@@ -649,10 +649,10 @@ const depPickerSchema = z
649
649
  .string()
650
650
  .describe('One dependency (`cells.microscope`), or the key alone (`cells`) for every dependency declared under it that no other picker places.'),
651
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. An agent blok only.');
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
653
 
654
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'], since: 3}, ({component, schema}) => {
655
+ export const Deppicker = createBlokComponent({name: 'deppicker', schema: depPickerSchema, kinds: ['agent', 'custom'], since: 3}, ({component, schema}) => {
656
656
  const key = useValue(useBlok(component, schema).key);
657
657
  const host = useBlokRunHost();
658
658
  return <>{typeof key === 'string' ? (host.renderDepPicker?.(key) ?? null) : null}</>;