@almadar/std 16.245.0 → 16.246.1

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 (70) hide show
  1. package/behaviors/behaviors-registry.json +534 -176
  2. package/behaviors/lolo/agent/atoms/std-agent-context.lolo +9 -4
  3. package/behaviors/lolo/agent/atoms/std-agent-memory.lolo +9 -4
  4. package/behaviors/lolo/agent/atoms/std-agent-proposal.lolo +9 -4
  5. package/behaviors/lolo/agent/atoms/std-agent-session.lolo +9 -4
  6. package/behaviors/lolo/agent/atoms/std-agent-suggestions.lolo +9 -4
  7. package/behaviors/lolo/agent/atoms/std-agent-tool-loop.lolo +9 -4
  8. package/behaviors/lolo/agent/organisms/std-agent-assistant.lolo +9 -4
  9. package/behaviors/lolo/ui/core/atoms/ui-svg-flow.lolo +1 -1
  10. package/behaviors/lolo/ui/core/molecules/ui-import-progress.lolo +1 -1
  11. package/behaviors/lolo/ui/game/atoms/ui-canvas.lolo +3 -3
  12. package/behaviors/lolo/ui/game/atoms/ui-control-grid.lolo +3 -3
  13. package/behaviors/lolo/ui/game/atoms/ui-draw-group.lolo +1 -1
  14. package/behaviors/lolo/ui/game/atoms/ui-draw-mesh.lolo +1 -1
  15. package/behaviors/lolo/ui/game/atoms/ui-draw-skinned-mesh.lolo +3 -3
  16. package/behaviors/lolo/ui/learning/atoms/ui-biology-canvas.lolo +3 -3
  17. package/behaviors/lolo/ui/learning/atoms/ui-chemistry-canvas.lolo +3 -3
  18. package/behaviors/lolo/ui/learning/atoms/ui-physics-canvas.lolo +3 -3
  19. package/behaviors/lolo-behavior-contracts.json +1 -1
  20. package/behaviors/registry/agent/atoms/std-agent-context.orb +53 -67
  21. package/behaviors/registry/agent/atoms/std-agent-memory.orb +14 -51
  22. package/behaviors/registry/agent/atoms/std-agent-proposal.orb +50 -20
  23. package/behaviors/registry/agent/atoms/std-agent-session.orb +84 -91
  24. package/behaviors/registry/agent/atoms/std-agent-suggestions.orb +61 -24
  25. package/behaviors/registry/agent/atoms/std-agent-tool-loop.orb +61 -45
  26. package/behaviors/registry/agent/organisms/std-agent-assistant.orb +63 -26
  27. package/behaviors/registry/factory-signatures.json +1 -1
  28. package/behaviors/registry/ui/avl/atoms/ui-avl-state-machine.orb +2 -2
  29. package/behaviors/registry/ui/avl/atoms/ui-avl-transition-explainer.orb +2 -2
  30. package/behaviors/registry/ui/avl/atoms/ui-behavior-view.orb +2 -2
  31. package/behaviors/registry/ui/avl/atoms/ui-module-card.orb +2 -2
  32. package/behaviors/registry/ui/core/atoms/ui-svg-flow.orb +11 -4
  33. package/behaviors/registry/ui/core/molecules/ui-agent-chat-feed.orb +1 -1
  34. package/behaviors/registry/ui/core/molecules/ui-data-grid.orb +2 -2
  35. package/behaviors/registry/ui/core/molecules/ui-import-progress.orb +1 -1
  36. package/behaviors/registry/ui/core/molecules/ui-swipeable-row.orb +2 -2
  37. package/behaviors/registry/ui/core/molecules/ui-table-view.orb +2 -2
  38. package/behaviors/registry/ui/core/molecules/ui-wizard-container.orb +3 -3
  39. package/behaviors/registry/ui/core/organisms/ui-detail-panel.orb +4 -4
  40. package/behaviors/registry/ui/core/organisms/ui-form-section.orb +4 -4
  41. package/behaviors/registry/ui/core/organisms/ui-form.orb +4 -4
  42. package/behaviors/registry/ui/core/organisms/ui-state-machine-view.orb +136 -2
  43. package/behaviors/registry/ui/core/templates/ui-dashboard-layout.orb +3 -2
  44. package/behaviors/registry/ui/game/atoms/ui-canvas.orb +51 -18
  45. package/behaviors/registry/ui/game/atoms/ui-control-grid.orb +3 -3
  46. package/behaviors/registry/ui/game/atoms/ui-draw-group.orb +12 -5
  47. package/behaviors/registry/ui/game/atoms/ui-draw-mesh.orb +12 -5
  48. package/behaviors/registry/ui/game/atoms/ui-draw-skinned-mesh.orb +39 -14
  49. package/behaviors/registry/ui/learning/atoms/ui-biology-canvas.orb +51 -18
  50. package/behaviors/registry/ui/learning/atoms/ui-chemistry-canvas.orb +51 -18
  51. package/behaviors/registry/ui/learning/atoms/ui-physics-canvas.orb +51 -18
  52. package/canonical-operators.json +5 -5
  53. package/dist/behaviors/exports-reader.js +228 -218
  54. package/dist/behaviors/functions/index.d.ts +8 -8
  55. package/dist/behaviors/functions/index.js +228 -218
  56. package/dist/behaviors/index.js +274 -255
  57. package/dist/behaviors/knob-embeddings.d.ts +16 -2
  58. package/dist/behaviors/knob-embeddings.js +47 -38
  59. package/dist/behaviors/query.js +228 -218
  60. package/dist/behaviors-embeddings.hash.json +3 -3
  61. package/dist/behaviors-embeddings.json +1 -1
  62. package/dist/behaviors-registry.json +534 -176
  63. package/dist/index.js +278 -259
  64. package/dist/knob-embeddings.hash.json +3 -3
  65. package/dist/knob-embeddings.json +7 -3
  66. package/dist/modules/array.js +4 -4
  67. package/dist/modules/index.js +4 -4
  68. package/dist/registry/factory-signatures.json +1 -1
  69. package/dist/registry.js +4 -4
  70. package/package.json +2 -2
@@ -15,11 +15,15 @@
15
15
  *
16
16
  * @packageDocumentation
17
17
  */
18
+ /** Each knob's vector as int8, all views over one shared buffer — the on-disk
19
+ * bytes, never widened to a float per dimension (that was 8× the memory and
20
+ * OOM-killed the builder server). The per-vector scale is dropped, so a
21
+ * vector here is a direction: compare it with cosine similarity only. */
18
22
  interface KnobEmbeddingsManifest {
19
23
  version: string;
20
24
  model: string;
21
25
  dimensions: number;
22
- vectors: Record<string, ReadonlyArray<number>>;
26
+ vectors: Readonly<Record<string, Int8Array>>;
23
27
  }
24
28
  /** Int8-quantized vector: `d` = base64 of one signed byte per dimension,
25
29
  * `s` = per-vector max-abs scale; value = byte × s ÷ 127. Landed when the
@@ -43,6 +47,16 @@ interface StoredKnobEmbeddingsFile {
43
47
  table?: StoredKnobVector[];
44
48
  keys?: Record<string, number>;
45
49
  }
50
+ /**
51
+ * Decode a parsed `knob-embeddings.json` into int8 vectors over one buffer
52
+ * sized (stored vectors × dimensions). Interned table entries are written
53
+ * once and shared by every key that points at them. Returns `null` for a
54
+ * file missing its model, dimensions or vectors, or holding a vector whose
55
+ * length is not `dimensions`.
56
+ */
57
+ declare function decodeKnobEmbeddingsFile(parsed: Partial<StoredKnobEmbeddingsFile>): KnobEmbeddingsManifest | null;
58
+ /** Read and decode a `knob-embeddings.json` at `path`; `null` when it is missing or invalid. */
59
+ declare function readKnobEmbeddingsFile(path: string): Promise<KnobEmbeddingsManifest | null>;
46
60
  /**
47
61
  * Return the typed knob embeddings manifest. Returns `null` when the
48
62
  * JSON sidecar is missing (older std checkout, or a dev build with
@@ -51,4 +65,4 @@ interface StoredKnobEmbeddingsFile {
51
65
  */
52
66
  declare function getKnobEmbeddings(): Promise<KnobEmbeddingsManifest | null>;
53
67
 
54
- export { type KnobEmbeddingsManifest, type QuantizedKnobVector, type StoredKnobEmbeddingsFile, type StoredKnobVector, getKnobEmbeddings };
68
+ export { type KnobEmbeddingsManifest, type QuantizedKnobVector, type StoredKnobEmbeddingsFile, type StoredKnobVector, decodeKnobEmbeddingsFile, getKnobEmbeddings, readKnobEmbeddingsFile };
@@ -23,29 +23,56 @@ async function resolveStdDataDirUncached() {
23
23
 
24
24
  // behaviors/knob-embeddings.ts
25
25
  var pending2 = null;
26
- function decodeVector(stored) {
27
- if (!("d" in stored)) return stored;
28
- const bytes = Buffer.from(stored.d, "base64");
29
- const out = new Array(bytes.length);
30
- for (let i = 0; i < bytes.length; i++) {
31
- out[i] = bytes.readInt8(i) * stored.s / 127;
26
+ function writeVector(stored, slot) {
27
+ if ("d" in stored) {
28
+ const bytes = Buffer.from(stored.d, "base64");
29
+ if (bytes.length !== slot.length) return false;
30
+ slot.set(new Int8Array(bytes.buffer, bytes.byteOffset, bytes.length));
31
+ return true;
32
32
  }
33
- return out;
33
+ if (stored.length !== slot.length) return false;
34
+ let maxAbs = 0;
35
+ for (const v of stored) maxAbs = Math.max(maxAbs, Math.abs(v));
36
+ for (let i = 0; i < stored.length; i++) {
37
+ slot[i] = maxAbs === 0 ? 0 : Math.round(stored[i] * 127 / maxAbs);
38
+ }
39
+ return true;
34
40
  }
35
- function reconstructVectors(parsed) {
41
+ function decodeKnobEmbeddingsFile(parsed) {
42
+ const interned = typeof parsed?.table === "object" && typeof parsed?.keys === "object";
43
+ const nonInterned = typeof parsed?.vectors === "object" && parsed.vectors !== null;
44
+ if (typeof parsed?.model !== "string" || typeof parsed?.dimensions !== "number" || !interned && !nonInterned) {
45
+ return null;
46
+ }
47
+ const dims = parsed.dimensions;
48
+ const stored = interned ? parsed.table ?? [] : Object.values(parsed.vectors ?? {});
49
+ const backing = new Int8Array(stored.length * dims);
50
+ const slots = [];
51
+ for (let i = 0; i < stored.length; i++) {
52
+ const slot = backing.subarray(i * dims, (i + 1) * dims);
53
+ if (!writeVector(stored[i], slot)) return null;
54
+ slots.push(slot);
55
+ }
36
56
  const vectors = {};
37
- if (parsed.table && parsed.keys) {
38
- const decoded = parsed.table.map(decodeVector);
39
- for (const [key, idx] of Object.entries(parsed.keys)) {
40
- const vec = decoded[idx];
41
- if (vec) vectors[key] = vec;
57
+ if (interned) {
58
+ for (const [key, idx] of Object.entries(parsed.keys ?? {})) {
59
+ const slot = slots[idx];
60
+ if (slot) vectors[key] = slot;
42
61
  }
43
- return vectors;
62
+ } else {
63
+ Object.keys(parsed.vectors ?? {}).forEach((key, i) => {
64
+ vectors[key] = slots[i];
65
+ });
44
66
  }
45
- for (const [key, stored] of Object.entries(parsed.vectors ?? {})) {
46
- vectors[key] = decodeVector(stored);
67
+ return { version: parsed.version ?? "", model: parsed.model, dimensions: dims, vectors };
68
+ }
69
+ async function readKnobEmbeddingsFile(path) {
70
+ try {
71
+ const { readFileSync } = await import('fs');
72
+ return decodeKnobEmbeddingsFile(JSON.parse(readFileSync(path, "utf-8")));
73
+ } catch {
74
+ return null;
47
75
  }
48
- return vectors;
49
76
  }
50
77
  function loadManifest() {
51
78
  pending2 ?? (pending2 = loadManifestUncached().then((m) => {
@@ -55,29 +82,11 @@ function loadManifest() {
55
82
  return pending2;
56
83
  }
57
84
  async function loadManifestUncached() {
58
- try {
59
- const { readFileSync } = await import('fs');
60
- const { resolve } = await import('path');
61
- const dir = await resolveStdDataDir();
62
- const raw = readFileSync(resolve(dir, "knob-embeddings.json"), "utf-8");
63
- const parsed = JSON.parse(raw);
64
- const interned = typeof parsed?.table === "object" && typeof parsed?.keys === "object";
65
- const nonInterned = typeof parsed?.vectors === "object" && parsed.vectors !== null;
66
- if (typeof parsed?.model !== "string" || typeof parsed?.dimensions !== "number" || !interned && !nonInterned) {
67
- return null;
68
- }
69
- return {
70
- version: parsed.version,
71
- model: parsed.model,
72
- dimensions: parsed.dimensions,
73
- vectors: reconstructVectors(parsed)
74
- };
75
- } catch {
76
- return null;
77
- }
85
+ const { resolve } = await import('path');
86
+ return readKnobEmbeddingsFile(resolve(await resolveStdDataDir(), "knob-embeddings.json"));
78
87
  }
79
88
  async function getKnobEmbeddings() {
80
89
  return loadManifest();
81
90
  }
82
91
 
83
- export { getKnobEmbeddings };
92
+ export { decodeKnobEmbeddingsFile, getKnobEmbeddings, readKnobEmbeddingsFile };