@dxos/brain 0.0.1 → 0.12.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 (68) hide show
  1. package/LICENSE +105 -0
  2. package/README.md +32 -1
  3. package/dist/lib/Builtins.mjs +178 -0
  4. package/dist/lib/Builtins.mjs.map +1 -0
  5. package/dist/lib/CompilePrompt.mjs +305 -0
  6. package/dist/lib/CompilePrompt.mjs.map +1 -0
  7. package/dist/lib/Compiler.mjs +212 -0
  8. package/dist/lib/Compiler.mjs.map +1 -0
  9. package/dist/lib/Encoding.mjs +116 -0
  10. package/dist/lib/Encoding.mjs.map +1 -0
  11. package/dist/lib/GoalRules.mjs +161 -0
  12. package/dist/lib/GoalRules.mjs.map +1 -0
  13. package/dist/lib/Vocabulary.mjs +92 -0
  14. package/dist/lib/Vocabulary.mjs.map +1 -0
  15. package/dist/lib/chunk-rolldown-runtime.mjs +13 -0
  16. package/dist/lib/index.mjs +7 -0
  17. package/dist/lib/testing.mjs +831 -0
  18. package/dist/lib/testing.mjs.map +1 -0
  19. package/dist/types/src/Builtins.d.ts +57 -0
  20. package/dist/types/src/Builtins.d.ts.map +1 -0
  21. package/dist/types/src/Builtins.test.d.ts +2 -0
  22. package/dist/types/src/Builtins.test.d.ts.map +1 -0
  23. package/dist/types/src/CompilePrompt.d.ts +107 -0
  24. package/dist/types/src/CompilePrompt.d.ts.map +1 -0
  25. package/dist/types/src/CompilePrompt.test.d.ts +2 -0
  26. package/dist/types/src/CompilePrompt.test.d.ts.map +1 -0
  27. package/dist/types/src/Compiler.d.ts +76 -0
  28. package/dist/types/src/Compiler.d.ts.map +1 -0
  29. package/dist/types/src/Compiler.test.d.ts +2 -0
  30. package/dist/types/src/Compiler.test.d.ts.map +1 -0
  31. package/dist/types/src/Encoding.d.ts +42 -0
  32. package/dist/types/src/Encoding.d.ts.map +1 -0
  33. package/dist/types/src/GoalRules.d.ts +66 -0
  34. package/dist/types/src/GoalRules.d.ts.map +1 -0
  35. package/dist/types/src/GoalRules.test.d.ts +2 -0
  36. package/dist/types/src/GoalRules.test.d.ts.map +1 -0
  37. package/dist/types/src/Vocabulary.d.ts +31 -0
  38. package/dist/types/src/Vocabulary.d.ts.map +1 -0
  39. package/dist/types/src/Vocabulary.test.d.ts +2 -0
  40. package/dist/types/src/Vocabulary.test.d.ts.map +1 -0
  41. package/dist/types/src/index.d.ts +7 -0
  42. package/dist/types/src/index.d.ts.map +1 -0
  43. package/dist/types/src/testing/index.d.ts +4 -0
  44. package/dist/types/src/testing/index.d.ts.map +1 -0
  45. package/dist/types/src/testing/reference.d.ts +9 -0
  46. package/dist/types/src/testing/reference.d.ts.map +1 -0
  47. package/dist/types/src/testing/scenarios.d.ts +73 -0
  48. package/dist/types/src/testing/scenarios.d.ts.map +1 -0
  49. package/dist/types/src/testing/simulate.d.ts +31 -0
  50. package/dist/types/src/testing/simulate.d.ts.map +1 -0
  51. package/dist/types/tsconfig.tsbuildinfo +1 -0
  52. package/package.json +74 -5
  53. package/src/Builtins.test.ts +45 -0
  54. package/src/Builtins.ts +274 -0
  55. package/src/CompilePrompt.test.ts +117 -0
  56. package/src/CompilePrompt.ts +376 -0
  57. package/src/Compiler.test.ts +85 -0
  58. package/src/Compiler.ts +234 -0
  59. package/src/Encoding.ts +99 -0
  60. package/src/GoalRules.test.ts +96 -0
  61. package/src/GoalRules.ts +181 -0
  62. package/src/Vocabulary.test.ts +48 -0
  63. package/src/Vocabulary.ts +88 -0
  64. package/src/index.ts +10 -0
  65. package/src/testing/index.ts +7 -0
  66. package/src/testing/reference.ts +91 -0
  67. package/src/testing/scenarios.ts +604 -0
  68. package/src/testing/simulate.ts +127 -0
@@ -0,0 +1,92 @@
1
+ import { t as __exportAll } from "./chunk-rolldown-runtime.mjs";
2
+ import { Predicate } from "@dxos/pipeline-rdf/types";
3
+ //#region src/Vocabulary.ts
4
+ var Vocabulary_exports = /* @__PURE__ */ __exportAll({
5
+ DEFAULT_ENTRIES: () => DEFAULT_ENTRIES,
6
+ Vocabulary: () => Vocabulary,
7
+ make: () => make,
8
+ normalize: () => normalize
9
+ });
10
+ /**
11
+ * The lookup key for a surface predicate: pipeline-rdf's relation key (case, auxiliaries and head-verb
12
+ * inflection collapse, as the fact store matches them) with words joined by `_`, so `Will-Work-On`,
13
+ * `working on` and `works_on` compare equal.
14
+ */
15
+ var normalize = (surface) => Predicate.normalize(surface.replace(/[_-]+/g, " ")).replace(/\s+/g, "_");
16
+ /** The canonical predicates rules may use as shorthand, and the synonyms that map onto them. */
17
+ var Vocabulary = class {
18
+ entries;
19
+ #canonical = /* @__PURE__ */ new Map();
20
+ #predicates = /* @__PURE__ */ new Set();
21
+ /** @throws Error on an invalid predicate name, a reserved name, or a synonym claimed twice. */
22
+ constructor(entries, reserved = []) {
23
+ this.entries = entries;
24
+ for (const { predicate, synonyms = [] } of entries) {
25
+ if (!/^[a-z][a-z0-9_]*$/.test(predicate)) throw new Error(`Canonical predicate must be a lowercase identifier: ${predicate}`);
26
+ if (reserved.includes(predicate)) throw new Error(`Canonical predicate collides with a reserved name: ${predicate}`);
27
+ this.#predicates.add(predicate);
28
+ for (const surface of [predicate, ...synonyms]) {
29
+ const key = normalize(surface);
30
+ const existing = this.#canonical.get(key);
31
+ if (existing !== void 0 && existing !== predicate) throw new Error(`Synonym ${surface} maps to both ${existing} and ${predicate}`);
32
+ this.#canonical.set(key, predicate);
33
+ }
34
+ }
35
+ }
36
+ /** True if `name` is a canonical predicate. */
37
+ isCanonical(name) {
38
+ return this.#predicates.has(name);
39
+ }
40
+ /** The canonical predicate for a surface form, if the vocabulary knows it. */
41
+ canonical(surface) {
42
+ return this.#canonical.get(normalize(surface));
43
+ }
44
+ /** The stored predicate for a surface form: canonical if known, otherwise the form unchanged. */
45
+ resolve(surface) {
46
+ return this.canonical(surface) ?? surface;
47
+ }
48
+ };
49
+ /** Creates a vocabulary. */
50
+ var make = (entries, reserved = []) => new Vocabulary(entries, reserved);
51
+ /** A starter vocabulary covering the example goals; extraction grows it. */
52
+ var DEFAULT_ENTRIES = [
53
+ {
54
+ predicate: "helps_with",
55
+ synonyms: ["will-help-with", "helping-with"]
56
+ },
57
+ {
58
+ predicate: "works_on",
59
+ synonyms: [
60
+ "working-on",
61
+ "will-work-on",
62
+ "working_on"
63
+ ]
64
+ },
65
+ {
66
+ predicate: "completed",
67
+ synonyms: ["finished", "done"]
68
+ },
69
+ {
70
+ predicate: "shipped",
71
+ synonyms: ["ships", "released"]
72
+ },
73
+ {
74
+ predicate: "proposes",
75
+ synonyms: ["suggests"]
76
+ },
77
+ { predicate: "received" },
78
+ { predicate: "archived" },
79
+ { predicate: "deleted" },
80
+ { predicate: "filed" },
81
+ { predicate: "drafted" },
82
+ { predicate: "notified" },
83
+ { predicate: "relayed" },
84
+ {
85
+ predicate: "awaiting",
86
+ synonyms: ["waiting-for"]
87
+ }
88
+ ];
89
+ //#endregion
90
+ export { DEFAULT_ENTRIES, Vocabulary, make, normalize, Vocabulary_exports as t };
91
+
92
+ //# sourceMappingURL=Vocabulary.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Vocabulary.mjs","names":[],"sources":["../../src/Vocabulary.ts"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\n// @import-as-namespace\n\nimport { Predicate } from '@dxos/pipeline-rdf/types';\n\n/** A canonical predicate and the surface forms extraction maps onto it. */\nexport type Entry = {\n /** Identifier usable as rule shorthand (`helps_with(dima, X)`). */\n readonly predicate: string;\n readonly synonyms?: ReadonlyArray<string>;\n readonly description?: string;\n};\n\n/**\n * The lookup key for a surface predicate: pipeline-rdf's relation key (case, auxiliaries and head-verb\n * inflection collapse, as the fact store matches them) with words joined by `_`, so `Will-Work-On`,\n * `working on` and `works_on` compare equal.\n */\nexport const normalize = (surface: string): string =>\n Predicate.normalize(surface.replace(/[_-]+/g, ' ')).replace(/\\s+/g, '_');\n\n/** The canonical predicates rules may use as shorthand, and the synonyms that map onto them. */\nexport class Vocabulary {\n readonly entries: ReadonlyArray<Entry>;\n readonly #canonical = new Map<string, string>();\n readonly #predicates = new Set<string>();\n\n /** @throws Error on an invalid predicate name, a reserved name, or a synonym claimed twice. */\n constructor(entries: ReadonlyArray<Entry>, reserved: ReadonlyArray<string> = []) {\n this.entries = entries;\n for (const { predicate, synonyms = [] } of entries) {\n if (!/^[a-z][a-z0-9_]*$/.test(predicate)) {\n throw new Error(`Canonical predicate must be a lowercase identifier: ${predicate}`);\n }\n if (reserved.includes(predicate)) {\n throw new Error(`Canonical predicate collides with a reserved name: ${predicate}`);\n }\n this.#predicates.add(predicate);\n for (const surface of [predicate, ...synonyms]) {\n const key = normalize(surface);\n const existing = this.#canonical.get(key);\n if (existing !== undefined && existing !== predicate) {\n throw new Error(`Synonym ${surface} maps to both ${existing} and ${predicate}`);\n }\n this.#canonical.set(key, predicate);\n }\n }\n }\n\n /** True if `name` is a canonical predicate. */\n isCanonical(name: string): boolean {\n return this.#predicates.has(name);\n }\n\n /** The canonical predicate for a surface form, if the vocabulary knows it. */\n canonical(surface: string): string | undefined {\n return this.#canonical.get(normalize(surface));\n }\n\n /** The stored predicate for a surface form: canonical if known, otherwise the form unchanged. */\n resolve(surface: string): string {\n return this.canonical(surface) ?? surface;\n }\n}\n\n/** Creates a vocabulary. */\nexport const make = (entries: ReadonlyArray<Entry>, reserved: ReadonlyArray<string> = []): Vocabulary =>\n new Vocabulary(entries, reserved);\n\n/** A starter vocabulary covering the example goals; extraction grows it. */\nexport const DEFAULT_ENTRIES: ReadonlyArray<Entry> = [\n { predicate: 'helps_with', synonyms: ['will-help-with', 'helping-with'] },\n { predicate: 'works_on', synonyms: ['working-on', 'will-work-on', 'working_on'] },\n { predicate: 'completed', synonyms: ['finished', 'done'] },\n { predicate: 'shipped', synonyms: ['ships', 'released'] },\n { predicate: 'proposes', synonyms: ['suggests'] },\n { predicate: 'received' },\n { predicate: 'archived' },\n { predicate: 'deleted' },\n { predicate: 'filed' },\n { predicate: 'drafted' },\n { predicate: 'notified' },\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,UAAU;GAAC;GAAc;GAAgB;EAAY;CAAE;CAChF;EAAE,WAAW;EAAa,UAAU,CAAC,YAAY,MAAM;CAAE;CACzD;EAAE,WAAW;EAAW,UAAU,CAAC,SAAS,UAAU;CAAE;CACxD;EAAE,WAAW;EAAY,UAAU,CAAC,UAAU;CAAE;CAChD,EAAE,WAAW,WAAW;CACxB,EAAE,WAAW,WAAW;CACxB,EAAE,WAAW,UAAU;CACvB,EAAE,WAAW,QAAQ;CACrB,EAAE,WAAW,UAAU;CACvB,EAAE,WAAW,WAAW;CACxB,EAAE,WAAW,UAAU;CACvB;EAAE,WAAW;EAAY,UAAU,CAAC,aAAa;CAAE;AACrD"}
@@ -0,0 +1,13 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __defProp = Object.defineProperty;
3
+ var __exportAll = (all, no_symbols) => {
4
+ let target = {};
5
+ for (var name in all) __defProp(target, name, {
6
+ get: all[name],
7
+ enumerable: true
8
+ });
9
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
10
+ return target;
11
+ };
12
+ //#endregion
13
+ export { __exportAll as t };
@@ -0,0 +1,7 @@
1
+ import { t as Builtins_exports } from "./Builtins.mjs";
2
+ import { t as Encoding_exports } from "./Encoding.mjs";
3
+ import { t as Vocabulary_exports } from "./Vocabulary.mjs";
4
+ import { t as Compiler_exports } from "./Compiler.mjs";
5
+ import { t as CompilePrompt_exports } from "./CompilePrompt.mjs";
6
+ import { t as GoalRules_exports } from "./GoalRules.mjs";
7
+ export { Builtins_exports as Builtins, CompilePrompt_exports as CompilePrompt, Compiler_exports as Compiler, Encoding_exports as Encoding, GoalRules_exports as GoalRules, Vocabulary_exports as Vocabulary };