@dxos/brain 0.0.1 → 0.13.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.
- package/LICENSE +105 -0
- package/README.md +32 -1
- package/dist/lib/Builtins.mjs +184 -0
- package/dist/lib/Builtins.mjs.map +1 -0
- package/dist/lib/CompilePrompt.mjs +305 -0
- package/dist/lib/CompilePrompt.mjs.map +1 -0
- package/dist/lib/Compiler.mjs +212 -0
- package/dist/lib/Compiler.mjs.map +1 -0
- package/dist/lib/Encoding.mjs +116 -0
- package/dist/lib/Encoding.mjs.map +1 -0
- package/dist/lib/GoalRules.mjs +245 -0
- package/dist/lib/GoalRules.mjs.map +1 -0
- package/dist/lib/Vocabulary.mjs +92 -0
- package/dist/lib/Vocabulary.mjs.map +1 -0
- package/dist/lib/chunk-rolldown-runtime.mjs +13 -0
- package/dist/lib/index.mjs +7 -0
- package/dist/lib/testing.mjs +831 -0
- package/dist/lib/testing.mjs.map +1 -0
- package/dist/types/src/Builtins.d.ts +61 -0
- package/dist/types/src/Builtins.d.ts.map +1 -0
- package/dist/types/src/Builtins.test.d.ts +2 -0
- package/dist/types/src/Builtins.test.d.ts.map +1 -0
- package/dist/types/src/CompilePrompt.d.ts +107 -0
- package/dist/types/src/CompilePrompt.d.ts.map +1 -0
- package/dist/types/src/CompilePrompt.test.d.ts +2 -0
- package/dist/types/src/CompilePrompt.test.d.ts.map +1 -0
- package/dist/types/src/Compiler.d.ts +76 -0
- package/dist/types/src/Compiler.d.ts.map +1 -0
- package/dist/types/src/Compiler.test.d.ts +2 -0
- package/dist/types/src/Compiler.test.d.ts.map +1 -0
- package/dist/types/src/Encoding.d.ts +42 -0
- package/dist/types/src/Encoding.d.ts.map +1 -0
- package/dist/types/src/Encoding.test.d.ts +2 -0
- package/dist/types/src/Encoding.test.d.ts.map +1 -0
- package/dist/types/src/GoalRules.d.ts +125 -0
- package/dist/types/src/GoalRules.d.ts.map +1 -0
- package/dist/types/src/GoalRules.test.d.ts +2 -0
- package/dist/types/src/GoalRules.test.d.ts.map +1 -0
- package/dist/types/src/Vocabulary.d.ts +31 -0
- package/dist/types/src/Vocabulary.d.ts.map +1 -0
- package/dist/types/src/Vocabulary.test.d.ts +2 -0
- package/dist/types/src/Vocabulary.test.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +7 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/dist/types/src/testing/index.d.ts +4 -0
- package/dist/types/src/testing/index.d.ts.map +1 -0
- package/dist/types/src/testing/reference.d.ts +9 -0
- package/dist/types/src/testing/reference.d.ts.map +1 -0
- package/dist/types/src/testing/scenarios.d.ts +73 -0
- package/dist/types/src/testing/scenarios.d.ts.map +1 -0
- package/dist/types/src/testing/simulate.d.ts +31 -0
- package/dist/types/src/testing/simulate.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +74 -5
- package/src/Builtins.test.ts +45 -0
- package/src/Builtins.ts +284 -0
- package/src/CompilePrompt.test.ts +117 -0
- package/src/CompilePrompt.ts +376 -0
- package/src/Compiler.test.ts +85 -0
- package/src/Compiler.ts +234 -0
- package/src/Encoding.test.ts +79 -0
- package/src/Encoding.ts +99 -0
- package/src/GoalRules.test.ts +186 -0
- package/src/GoalRules.ts +306 -0
- package/src/Vocabulary.test.ts +48 -0
- package/src/Vocabulary.ts +88 -0
- package/src/index.ts +10 -0
- package/src/testing/index.ts +7 -0
- package/src/testing/reference.ts +91 -0
- package/src/testing/scenarios.ts +604 -0
- package/src/testing/simulate.ts +127 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.mjs","names":[],"sources":["../../src/testing/reference.ts","../../src/testing/scenarios.ts","../../src/testing/simulate.ts"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\nimport { trim } from '@dxos/util';\n\n/** Hand-written reference compilations of the eight example goals, keyed by scenario number. */\nexport const REFERENCE: Readonly<Record<number, string>> = {\n 1: trim`\n wake(dima_work) :- speaker(F, dima), not force(F, expressive).\n wake(dima_work) :- fact(F, dima, _, _), not speaker(F, dima).\n `,\n 2: trim`\n shipped(F) :- about(F, \"release\"), about(F, \"shipped\"), polarity(F, \"+\"), not mood(F, interrogative), factuality(F, \"CT+\").\n candidate(F) :- fact(F, _, _, _), about(F, \"release\").\n wake(release) :- candidate(F), not achieved(goal).\n achieved(goal) :- shipped(F), fact(N, goal, notified, _), saidAt(F, T1), saidAt(N, T2), T2 >= T1.\n `,\n 3: trim`\n dima(F) :- speaker(F, dima), force(F, commissive), about(F, \"agent plugin\").\n wake(reply) :- dima(F), not achieved(goal).\n wake(reply) :- dima(F), achieved(goal).\n wake(followup) :- elapsed(goal, 2d), not achieved(goal).\n achieved(goal) :- dima(F), polarity(F, \"+\").\n `,\n 4: trim`\n gone(M) :- fact(_, M, archived, inbox).\n gone(M) :- fact(_, M, deleted, inbox).\n waiting(M) :- fact(_, M, received, inbox), not gone(M).\n wake(email) :- fact(F, M, received, inbox).\n holds(goal) :- not waiting(_).\n `,\n 5: trim`\n filed(F) :- about(F, \"tax return\"), about(F, \"filed\"), polarity(F, \"+\"), not speaker(F, alice).\n achieved(goal) :- filed(F).\n wake(remind) :- due(\"2027-04-15T00:00:00Z\", 30d), not achieved(goal).\n wake(remind) :- due(\"2027-04-15T00:00:00Z\", 7d), not achieved(goal).\n wake(overdue) :- due(\"2027-04-15T23:59:59Z\", 0d), not achieved(goal).\n wake(progress) :- subgoal(goal, G), status(G, achieved).\n wake(progress) :- speaker(F, rich), about(F, \"tax\").\n `,\n 6: trim`\n wake(practice) :- every(1d), not achieved(goal).\n `,\n 7: trim`\n meeting(A) :- action(A, book_meeting).\n meeting(A) :- action(A, update_meeting).\n blocks(A) :- meeting(A), actionArg(A, start, T), weekday(T, friday).\n `,\n 8: trim`\n mine(F) :- source(F, \"session:s42\"), speaker(F, rich).\n wake(turn) :- mine(F), not achieved(goal).\n achieved(goal) :- mine(F), force(F, commissive), polarity(F, \"+\"), fact(D, goal, drafted, _).\n `,\n};\n\n/** Plausible but wrong compilations; replaying the scenario must reject each one. */\nexport const WRONG: ReadonlyArray<{ readonly scenario: number; readonly note: string; readonly source: string }> = [\n {\n scenario: 3,\n note: 'achievement ignores polarity, so a refusal achieves the goal',\n source: trim`\n achieved(goal) :- speaker(F, dima), force(F, commissive), about(F, \"agent plugin\").\n wake(followup) :- elapsed(goal, 2d).\n wake(reply) :- speaker(F, dima).\n `,\n },\n {\n scenario: 1,\n note: \"only Dima's own messages wake, missing third-party reports\",\n source: 'wake(x) :- speaker(F, dima).',\n },\n {\n scenario: 7,\n note: 'any action with any Friday argument is blocked',\n source: 'blocks(A) :- action(A, _), actionArg(A, _, T), weekday(T, friday).',\n },\n {\n scenario: 4,\n note: 'holds on any archived email instead of on an empty inbox',\n source: trim`\n holds(goal) :- fact(_, M, archived, inbox).\n wake(e) :- fact(F, _, received, inbox).\n `,\n },\n {\n scenario: 6,\n note: 'elapsed fires once, not daily',\n source: 'wake(p) :- elapsed(goal, 1d).',\n },\n];\n","//\n// Copyright 2026 DXOS.org\n//\n\n/** A scripted fact; `concerns` stubs entity resolution and defaults to the subject. */\nexport type ScenarioFact = {\n readonly id: string;\n /** Handle of who said it, or `agent` for the agent's own actions. */\n readonly speaker: string;\n /** The words as said. */\n readonly quote: string;\n /** Subject entity handle. */\n readonly s: string;\n /** Predicate, before vocabulary canonicalization. */\n readonly p: string;\n /** Object entity handle or literal. */\n readonly o: string;\n /** Speech-act force of the utterance. */\n readonly force: 'assertive' | 'directive' | 'commissive' | 'expressive';\n /** `+` affirmed, `-` negated or refused, `?` open question or unknown. */\n readonly polarity: '+' | '-' | '?';\n readonly mood: 'declarative' | 'interrogative' | 'imperative';\n /** Conversation or message the fact came from, e.g. `chat:general`. */\n readonly source: string;\n /** FactBank factuality: certainty (CT/PR/PS/U) and polarity (+/-/u). */\n readonly factuality: 'CT+' | 'CT-' | 'PR+' | 'PR-' | 'PS+' | 'PS-' | 'CTu' | 'Uu';\n /** Entity handles the fact is about; defaults to the subject. */\n readonly concerns?: ReadonlyArray<string>;\n};\n\nexport type ScenarioAction = {\n readonly id: string;\n /** Action name, e.g. `send_email`. */\n readonly kind: string;\n /** Named action arguments, e.g. `{ to: 'dima' }`. */\n readonly args: Readonly<Record<string, string>>;\n};\n\n/** Expected effects of a step; `null` or absent means either outcome is acceptable. */\nexport type Expectation = {\n readonly wake?: boolean | null;\n readonly achieved?: boolean | null;\n readonly holds?: boolean | null;\n readonly blocks?: boolean | null;\n};\n\nexport type Step = {\n readonly id: string;\n /** Simulated clock time (ISO) the step runs at. */\n readonly at: string;\n /** Human-readable description of what happens in the step. */\n readonly note: string;\n readonly facts?: ReadonlyArray<ScenarioFact>;\n readonly actions?: ReadonlyArray<ScenarioAction>;\n /** Subgoal ids that become `active` from this step on. */\n readonly subgoals?: ReadonlyArray<string>;\n /** Subgoal status overrides by subgoal id, e.g. `{ g_w2: 'achieved' }`. */\n readonly status?: Readonly<Record<string, string>>;\n readonly expect: Expectation;\n};\n\n/** A timeline for one of the BRAIN.md example goals. */\nexport type Scenario = {\n /** Number of the example goal in BRAIN.md. */\n readonly n: number;\n /** Natural-language goal text. */\n readonly goal: string;\n /** Handle of the actor who owns the goal. */\n readonly owner: string;\n /** Source id of the conversation a session goal is scoped to. */\n readonly session?: string;\n readonly createdAt: string;\n /** Owner-written guidance passed to the compiler as the goal's instructions. */\n readonly context?: string;\n readonly steps: ReadonlyArray<Step>;\n /** At least one step of each group must wake (a time-driven wake with a tolerant schedule). */\n readonly wakeOneOf?: ReadonlyArray<ReadonlyArray<string>>;\n};\n\nconst at = (time: string) => `2027-${time}:00Z`;\n\nconst fact = (\n id: string,\n speaker: string,\n quote: string,\n s: string,\n p: string,\n o: string,\n extra: Partial<ScenarioFact> = {},\n): ScenarioFact => ({\n id,\n speaker,\n quote,\n s,\n p,\n o,\n force: 'assertive',\n polarity: '+',\n mood: 'declarative',\n source: 'chat:general',\n factuality: 'CT+',\n ...extra,\n});\n\n/** A record of the agent's own action, in the goal's feed. */\nconst agent = (id: string, p: string, o: string): ScenarioFact =>\n fact(id, 'agent', `(agent action) ${p} ${o}`, 'goal', p, o, { source: 'goal' });\n\n/** The eight BRAIN.md example goals, each a hand-written timeline with near misses. */\nexport const SCENARIOS: ReadonlyArray<Scenario> = [\n {\n n: 1,\n goal: 'Keep me informed about what Dima is working on',\n owner: 'rich',\n createdAt: at('01-04T09:00'),\n steps: [\n {\n id: 's1',\n at: at('01-04T09:10'),\n note: 'Dima states current work',\n facts: [\n fact(\n 'f1',\n 'dima',\n \"I'm working on the sync engine refactor today\",\n 'dima',\n 'working-on',\n 'sync engine refactor',\n ),\n ],\n expect: { wake: true, achieved: false },\n },\n {\n id: 's2',\n at: at('01-04T09:20'),\n note: 'unrelated: Alice proposes lunch',\n facts: [\n fact('f2', 'alice', 'Lunch at noon?', 'alice', 'proposes', 'lunch', {\n force: 'directive',\n mood: 'interrogative',\n polarity: '?',\n }),\n ],\n expect: { wake: false, achieved: false },\n },\n {\n id: 's3',\n at: at('01-04T10:00'),\n note: 'near miss: Bob (not Dima) working on something',\n facts: [fact('f3', 'bob', \"I'm working on the docs site\", 'bob', 'working-on', 'docs site')],\n expect: { wake: false, achieved: false },\n },\n {\n id: 's4',\n at: at('01-04T11:00'),\n note: \"third party reports on Dima's work\",\n facts: [fact('f4', 'alice', 'Dima finished the auth migration', 'dima', 'completed', 'auth migration')],\n expect: { wake: true, achieved: false },\n },\n {\n id: 's5',\n at: at('01-04T12:00'),\n note: 'Dima small talk (noise; either is fine)',\n facts: [fact('f5', 'dima', 'thanks!', 'dima', 'thanks', 'alice', { force: 'expressive' })],\n expect: { wake: null, achieved: false },\n },\n {\n id: 's6',\n at: at('01-04T13:00'),\n note: 'Dima commits to next work item',\n facts: [\n fact('f6', 'dima', \"Next up I'll pick up the indexer bug\", 'dima', 'will-work-on', 'indexer bug', {\n force: 'commissive',\n }),\n ],\n expect: { wake: true, achieved: false },\n },\n ],\n },\n {\n n: 2,\n goal: 'Let me know when the release ships',\n owner: 'rich',\n createdAt: at('01-04T09:00'),\n steps: [\n {\n id: 's1',\n at: at('01-04T10:00'),\n note: 'future plan, not shipped',\n facts: [\n fact('f1', 'dima', 'The release should ship Friday', 'release', 'ships-on', 'friday', {\n force: 'commissive',\n factuality: 'PR+',\n }),\n ],\n expect: { achieved: false },\n },\n {\n id: 's2',\n at: at('01-05T10:00'),\n note: 'negative polarity',\n facts: [\n fact('f2', 'dima', \"The release didn't ship today, CI is red\", 'release', 'shipped', 'today', {\n polarity: '-',\n }),\n ],\n expect: { achieved: false },\n },\n {\n id: 's3',\n at: at('01-05T11:00'),\n note: 'question',\n facts: [\n fact('f3', 'alice', 'Has the release shipped yet?', 'release', 'shipped', 'unknown', {\n mood: 'interrogative',\n polarity: '?',\n force: 'directive',\n factuality: 'Uu',\n }),\n ],\n expect: { achieved: false },\n },\n {\n id: 's4',\n at: at('01-06T09:00'),\n note: 'near miss: something else shipped',\n facts: [fact('f4', 'bob', 'I shipped the docs update', 'bob', 'shipped', 'docs update')],\n expect: { wake: false, achieved: false },\n },\n {\n id: 's5',\n at: at('01-07T16:00'),\n note: 'release shipped',\n facts: [fact('f5', 'dima', 'The v0.9 release shipped to npm', 'release v0.9', 'shipped', 'npm')],\n expect: { wake: true, achieved: null },\n },\n {\n id: 's6',\n at: at('01-07T16:05'),\n note: 'agent notified owner',\n facts: [agent('g1', 'notified', 'rich')],\n expect: { achieved: true },\n },\n ],\n },\n {\n n: 3,\n goal: 'Get Dima to help me with the agent plugin',\n owner: 'rich',\n createdAt: at('01-04T09:00'),\n context: 'Follow up after 2 days without a commitment.',\n steps: [\n {\n id: 's1',\n at: at('01-04T09:01'),\n note: 'agent relays request',\n facts: [agent('g1', 'relayed', 'msg-1'), agent('g2', 'awaiting', 'dima')],\n expect: { achieved: false },\n },\n {\n id: 's2',\n at: at('01-05T10:00'),\n note: 'Dima refuses',\n facts: [\n fact(\n 'f1',\n 'dima',\n \"I'm busy with the release this week, can't help with the agent plugin\",\n 'dima',\n 'helps-with',\n 'agent plugin',\n { force: 'commissive', polarity: '-' },\n ),\n ],\n expect: { wake: true, achieved: false },\n },\n {\n id: 's3',\n at: at('01-05T11:00'),\n note: 'near miss: Dima commits to something else',\n facts: [\n fact('f2', 'dima', \"I'll review the docs PR tomorrow\", 'dima', 'reviews', 'docs PR', { force: 'commissive' }),\n ],\n expect: { wake: false, achieved: false },\n },\n {\n id: 's4',\n at: at('01-05T12:00'),\n note: 'near miss: Alice (not Dima) offers help',\n facts: [\n fact('f3', 'alice', \"I'll help with the agent plugin\", 'alice', 'helps-with', 'agent plugin', {\n force: 'commissive',\n }),\n ],\n expect: { achieved: false },\n },\n { id: 's5', at: at('01-06T08:00'), note: 'tick: under 2 days', expect: { wake: false, achieved: false } },\n { id: 's6', at: at('01-06T09:30'), note: 'tick: 2 days after creation', expect: { achieved: false } },\n { id: 's7', at: at('01-07T10:30'), note: 'tick: 2 days after refusal', expect: { achieved: false } },\n {\n id: 's8',\n at: at('01-07T11:00'),\n note: 'Dima commits',\n facts: [\n fact('f4', 'dima', \"OK, I'll start on the agent plugin\", 'dima', 'helps-with', 'agent plugin', {\n force: 'commissive',\n }),\n ],\n expect: { wake: true, achieved: true },\n },\n {\n id: 's9',\n at: at('01-09T12:00'),\n note: 'tick after achieved: no follow-up',\n expect: { wake: false, achieved: true },\n },\n ],\n wakeOneOf: [['s6', 's7']],\n },\n {\n n: 4,\n goal: 'Keep my inbox empty',\n owner: 'rich',\n createdAt: at('01-04T09:00'),\n steps: [\n { id: 's0', at: at('01-04T09:00'), note: 'empty inbox', expect: { wake: false, holds: true, achieved: false } },\n {\n id: 's1',\n at: at('01-04T09:30'),\n note: 'email arrives',\n facts: [\n fact('f1', 'carol@example.com', 'Subject: Invoice for December', 'email:m1', 'received', 'inbox', {\n source: 'mailbox:rich',\n }),\n ],\n expect: { wake: true, holds: false, achieved: false },\n },\n {\n id: 's2',\n at: at('01-04T09:40'),\n note: 'second email',\n facts: [\n fact('f2', 'news@example.com', 'Subject: Weekly newsletter', 'email:m2', 'received', 'inbox', {\n source: 'mailbox:rich',\n }),\n ],\n expect: { wake: true, holds: false },\n },\n {\n id: 's3',\n at: at('01-04T09:45'),\n note: 'agent archives m1',\n facts: [\n fact('f3', 'agent', '(agent action) archived email:m1', 'email:m1', 'archived', 'inbox', {\n source: 'mailbox:rich',\n }),\n ],\n expect: { holds: false },\n },\n {\n id: 's4',\n at: at('01-04T09:46'),\n note: 'agent archives m2',\n facts: [\n fact('f4', 'agent', '(agent action) archived email:m2', 'email:m2', 'archived', 'inbox', {\n source: 'mailbox:rich',\n }),\n ],\n expect: { holds: true },\n },\n {\n id: 's5',\n at: at('01-04T10:00'),\n note: 'near miss: chat mentions email',\n facts: [\n fact('f5', 'alice', 'Did you see my email?', 'rich', 'saw', 'email', {\n mood: 'interrogative',\n polarity: '?',\n force: 'directive',\n }),\n ],\n expect: { wake: false, holds: true, achieved: false },\n },\n {\n id: 's6',\n at: at('01-04T11:00'),\n note: 'third email',\n facts: [\n fact('f6', 'dan@example.com', 'Subject: Contract draft', 'email:m3', 'received', 'inbox', {\n source: 'mailbox:rich',\n }),\n ],\n expect: { wake: true, holds: false, achieved: false },\n },\n ],\n },\n {\n n: 5,\n goal: 'Complete my taxes by April 15',\n owner: 'rich',\n createdAt: at('02-01T09:00'),\n context: 'Deadline is 2027-04-15.',\n steps: [\n {\n id: 's1',\n at: at('02-01T09:05'),\n note: 'judgment created sub-goals',\n subgoals: ['g_w2', 'g_return', 'g_accountant'],\n status: { g_w2: 'active', g_return: 'active', g_accountant: 'active' },\n expect: { achieved: false },\n },\n { id: 's2', at: at('03-01T09:00'), note: 'tick 45d before deadline', expect: { achieved: false } },\n {\n id: 's3',\n at: at('03-10T09:00'),\n note: 'near miss: Alice filed HER taxes',\n facts: [fact('f1', 'alice', 'I filed my taxes already', 'alice', 'filed', 'taxes')],\n expect: { achieved: false },\n },\n {\n id: 's4',\n at: at('03-12T09:00'),\n note: 'owner progress fact',\n facts: [fact('f2', 'rich', 'I uploaded my W-2s to the tax folder', 'rich', 'uploaded', 'W-2s')],\n expect: { achieved: false },\n },\n {\n id: 's5',\n at: at('03-12T09:10'),\n note: 'sub-goal achieved',\n status: { g_w2: 'achieved' },\n expect: { wake: true, achieved: false },\n },\n { id: 's6', at: at('04-08T09:00'), note: 'tick 7d before', expect: { achieved: false } },\n { id: 's7', at: at('04-14T09:00'), note: 'tick 1d before', expect: { achieved: false } },\n {\n id: 's8',\n at: at('04-14T12:00'),\n note: 'remaining sub-goals achieved',\n status: { g_return: 'achieved', g_accountant: 'achieved' },\n expect: { achieved: null },\n },\n {\n id: 's9',\n at: at('04-14T15:00'),\n note: 'accountant filed the return',\n facts: [\n fact('f3', 'accountant', \"I've filed your 2026 tax return\", 'tax return 2026', 'filed', 'irs', {\n concerns: ['rich'],\n }),\n ],\n expect: { achieved: true },\n },\n {\n id: 's10',\n at: at('04-16T09:00'),\n note: 'after deadline, already achieved: no overdue wake',\n expect: { wake: false, achieved: true },\n },\n ],\n wakeOneOf: [['s2', 's6', 's7']],\n },\n {\n n: 6,\n goal: 'Learn French',\n owner: 'rich',\n createdAt: at('01-04T07:00'),\n context: 'Practise daily.',\n steps: [\n { id: 's1', at: at('01-04T14:00'), note: 'tick same day', expect: { wake: false, achieved: false } },\n { id: 's2', at: at('01-05T07:30'), note: 'tick next day', expect: { wake: true, achieved: false } },\n {\n id: 's3',\n at: at('01-05T12:00'),\n note: 'near miss: French fries',\n facts: [\n fact('f1', 'rich', \"Let's get French fries for lunch\", 'rich', 'wants', 'french fries', {\n force: 'directive',\n }),\n ],\n expect: { achieved: false },\n },\n { id: 's4', at: at('01-05T14:00'), note: 'tick same day', expect: { wake: false, achieved: false } },\n {\n id: 's5',\n at: at('01-05T18:00'),\n note: 'owner practised',\n facts: [fact('f2', 'rich', 'I did 20 minutes of French practice on Duolingo', 'rich', 'practised', 'french')],\n expect: { achieved: false },\n },\n { id: 's6', at: at('01-06T07:30'), note: 'tick next day', expect: { wake: true, achieved: false } },\n ],\n },\n {\n n: 7,\n goal: 'Never book meetings on Fridays',\n owner: 'rich',\n createdAt: at('01-04T09:00'),\n steps: [\n {\n id: 's1',\n at: at('01-04T10:00'),\n note: 'Tuesday meeting',\n actions: [{ id: 'a1', kind: 'book_meeting', args: { start: '2027-01-05T10:00:00Z', title: 'Sync' } }],\n expect: { blocks: false, wake: false },\n },\n {\n id: 's2',\n at: at('01-04T10:05'),\n note: 'Friday meeting',\n actions: [{ id: 'a2', kind: 'book_meeting', args: { start: '2027-01-08T15:00:00Z', title: 'Retro' } }],\n expect: { blocks: true, wake: false },\n },\n {\n id: 's3',\n at: at('01-04T10:10'),\n note: 'near miss: Friday email',\n actions: [{ id: 'a3', kind: 'send_email', args: { sendAt: '2027-01-08T09:00:00Z', to: 'dima' } }],\n expect: { blocks: false, wake: false },\n },\n {\n id: 's4',\n at: at('01-04T10:20'),\n note: 'chat fact mentions Friday meeting',\n facts: [\n fact('f1', 'dima', \"Let's meet Friday\", 'dima', 'proposes', 'meeting on friday', { force: 'directive' }),\n ],\n expect: { blocks: false, wake: false },\n },\n {\n id: 's5',\n at: at('01-04T10:30'),\n note: 'move meeting to Friday (arguably blocked)',\n actions: [{ id: 'a4', kind: 'update_meeting', args: { start: '2027-01-15T11:00:00Z', title: 'Sync' } }],\n expect: { blocks: null },\n },\n ],\n },\n {\n n: 8,\n goal: 'Help me draft this PR description',\n owner: 'rich',\n session: 'session:s42',\n createdAt: at('01-04T09:00'),\n steps: [\n {\n id: 's1',\n at: at('01-04T09:01'),\n note: 'owner asks in session',\n facts: [\n fact('f1', 'rich', \"Here's the diff, draft a PR description\", 'agent', 'drafts', 'PR description', {\n force: 'directive',\n mood: 'imperative',\n source: 'session:s42',\n }),\n ],\n expect: { wake: true, achieved: false },\n },\n {\n id: 's2',\n at: at('01-04T09:03'),\n note: 'agent produced a draft',\n facts: [agent('g1', 'drafted', 'pr description v1')],\n expect: { achieved: false },\n },\n {\n id: 's3',\n at: at('01-04T09:05'),\n note: 'near miss: other source mentions PR descriptions',\n facts: [\n fact('f2', 'alice', 'The PR description template changed', 'pr template', 'changed', 'today', {\n source: 'chat:general',\n }),\n ],\n expect: { wake: false, achieved: false },\n },\n {\n id: 's4',\n at: at('01-04T09:07'),\n note: 'owner asks for revision',\n facts: [\n fact('f3', 'rich', 'Tighten the summary section', 'agent', 'tightens', 'summary section', {\n force: 'directive',\n mood: 'imperative',\n source: 'session:s42',\n }),\n ],\n expect: { wake: true, achieved: false },\n },\n {\n id: 's5',\n at: at('01-04T09:10'),\n note: 'owner accepts',\n facts: [\n fact('f4', 'rich', 'Looks good, posting it now', 'rich', 'posts', 'draft', {\n force: 'commissive',\n source: 'session:s42',\n }),\n ],\n expect: { achieved: true },\n },\n ],\n },\n];\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport type { RDF } from '@dxos/pipeline-rdf';\n\nimport * as Compiler from '../Compiler.ts';\nimport * as GoalRules from '../GoalRules.ts';\nimport type * as Vocabulary from '../Vocabulary.ts';\nimport { type Scenario, type ScenarioFact, type Step } from './scenarios.ts';\n\nexport type StepResult = {\n readonly id: string;\n readonly wake: boolean;\n readonly labels: ReadonlyArray<string>;\n /** The wakes, with the fact ids behind each. */\n readonly wakes: ReadonlyArray<GoalRules.Wake>;\n readonly achieved: boolean;\n readonly holds: boolean;\n readonly blocks: boolean;\n /** Expectations of this step the result violates. */\n readonly failures: ReadonlyArray<string>;\n};\n\nexport type SimulationResult = {\n readonly ok: boolean;\n readonly steps: ReadonlyArray<StepResult>;\n readonly failures: ReadonlyArray<string>;\n};\n\n/** Converts a scripted fact to an `RDF.Fact` said (and recorded) at `saidAt`. */\nexport const toFact = (fact: ScenarioFact, saidAt: string): RDF.Fact => ({\n id: fact.id,\n assertion: {\n subject: { kind: 'entity', entity: fact.s },\n predicate: fact.p,\n object: { kind: 'entity', entity: fact.o },\n quote: fact.quote,\n },\n factuality: { value: fact.factuality, polarity: fact.polarity },\n illocution: { force: fact.force, mood: fact.mood },\n attribution: { agent: fact.speaker, source: fact.source, generatedAtTime: saidAt },\n recordedAt: saidAt,\n extractor: { id: 'scenario', model: 'none', version: '1' },\n sourceHash: fact.id,\n pass: 'scenario',\n});\n\n/**\n * Replays a scenario against compiled goal rules and checks every step's expectations; a\n * compile error or a runtime error is reported as a failure.\n */\nexport const simulate = (\n scenario: Scenario,\n source: string,\n options: { vocabulary?: Vocabulary.Vocabulary } = {},\n): SimulationResult => {\n const concerns = new Map<string, ReadonlyArray<string>>();\n for (const step of scenario.steps) {\n for (const fact of step.facts ?? []) {\n concerns.set(fact.id, fact.concerns ?? [fact.s]);\n }\n }\n\n let rules: GoalRules.GoalRules;\n try {\n rules = GoalRules.make({\n source,\n createdAt: Date.parse(scenario.createdAt),\n vocabulary: options.vocabulary,\n concerns: (fact) => concerns.get(fact.id) ?? [],\n });\n } catch (error) {\n if (error instanceof Compiler.CompileError) {\n return { ok: false, steps: [], failures: error.diagnostics.map(Compiler.formatDiagnostic) };\n }\n throw error;\n }\n\n const statuses: Record<string, string> = {};\n const steps = scenario.steps.map((step): StepResult => {\n for (const subgoal of step.subgoals ?? []) {\n statuses[subgoal] = 'active';\n }\n Object.assign(statuses, step.status ?? {});\n const evaluation = rules.update({\n at: Date.parse(step.at),\n facts: (step.facts ?? []).map((fact) => toFact(fact, step.at)),\n subgoals: { ...statuses },\n });\n const blocks = (step.actions ?? []).some((action) => rules.checkAction(action).blocked);\n const observed = {\n wake: evaluation.wakes.length > 0,\n labels: evaluation.wakes.map(({ label }) => label),\n achieved: evaluation.achieved,\n holds: evaluation.holds,\n blocks,\n };\n return { id: step.id, ...observed, wakes: evaluation.wakes, failures: checkStep(step, observed) };\n });\n\n const failures = [...steps.flatMap((step) => step.failures), ...checkGroups(scenario, steps)];\n return { ok: failures.length === 0, steps, failures };\n};\n\nconst EXPECTATIONS = ['wake', 'achieved', 'holds', 'blocks'] as const;\n\n/** The expectations of `step` that `result` violates. */\nconst checkStep = (step: Step, result: Pick<StepResult, (typeof EXPECTATIONS)[number] | 'labels'>): string[] =>\n EXPECTATIONS.flatMap((key) => {\n const expected = step.expect[key];\n if (expected === undefined || expected === null || result[key] === expected) {\n return [];\n }\n const labels = key === 'wake' && result.labels.length > 0 ? ` [${result.labels.join(', ')}]` : '';\n return [`${step.id} (${step.note}): ${key}=${result[key]} expected ${expected}${labels}`];\n });\n\nconst checkGroups = (scenario: Scenario, results: ReadonlyArray<StepResult>): string[] => {\n const failures: string[] = [];\n for (const group of scenario.wakeOneOf ?? []) {\n if (!group.some((id) => results[scenario.steps.findIndex((step) => step.id === id)]?.wake)) {\n failures.push(`no wake in any of ${group.join(', ')} (time-driven wake expected)`);\n }\n }\n return failures;\n};\n"],"mappings":";;;;;AAOA,IAAa,YAA8C;CACzD,GAAG,IAAI;;;;CAIP,GAAG,IAAI;;;;;;CAMP,GAAG,IAAI;;;;;;;CAOP,GAAG,IAAI;;;;;;;CAOP,GAAG,IAAI;;;;;;;;;CASP,GAAG,IAAI;;;CAGP,GAAG,IAAI;;;;;CAKP,GAAG,IAAI;;;;;AAKT;;AAGA,IAAa,QAAsG;CACjH;EACE,UAAU;EACV,MAAM;EACN,QAAQ,IAAI;;;;;CAKd;CACA;EACE,UAAU;EACV,MAAM;EACN,QAAQ;CACV;CACA;EACE,UAAU;EACV,MAAM;EACN,QAAQ;CACV;CACA;EACE,UAAU;EACV,MAAM;EACN,QAAQ,IAAI;;;;CAId;CACA;EACE,UAAU;EACV,MAAM;EACN,QAAQ;CACV;AACF;;;ACXA,IAAM,MAAM,SAAiB,QAAQ,KAAK;AAE1C,IAAM,QACJ,IACA,SACA,OACA,GACA,GACA,GACA,QAA+B,CAAC,OACd;CAClB;CACA;CACA;CACA;CACA;CACA;CACA,OAAO;CACP,UAAU;CACV,MAAM;CACN,QAAQ;CACR,YAAY;CACZ,GAAG;AACL;;AAGA,IAAM,SAAS,IAAY,GAAW,MACpC,KAAK,IAAI,SAAS,kBAAkB,EAAE,GAAG,KAAK,QAAQ,GAAG,GAAG,EAA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builtin';
|
|
2
|
+
/** Finds facts about a topic; a semantic index replaces the keyword one without touching rules. */
|
|
3
|
+
export interface TextIndex {
|
|
4
|
+
add(factId: string, text: string): void;
|
|
5
|
+
remove(factId: string): void;
|
|
6
|
+
/** True if the fact is about `query`. */
|
|
7
|
+
matches(factId: string, query: string): boolean;
|
|
8
|
+
/** Every fact about `query`. */
|
|
9
|
+
search(query: string): Iterable<string>;
|
|
10
|
+
}
|
|
11
|
+
/** The entities each fact concerns (entity resolution), for scoping possessive goals. */
|
|
12
|
+
export interface EntityIndex {
|
|
13
|
+
add(factId: string, entities: ReadonlyArray<string>): void;
|
|
14
|
+
remove(factId: string): void;
|
|
15
|
+
concerns(factId: string): ReadonlyArray<string>;
|
|
16
|
+
facts(entity: string): Iterable<string>;
|
|
17
|
+
}
|
|
18
|
+
/** What the time built-ins read; `previous` is the time of the evaluation before this one. */
|
|
19
|
+
export type Clock = {
|
|
20
|
+
readonly now: () => number;
|
|
21
|
+
readonly previous: () => number;
|
|
22
|
+
/** When the goal was created; `elapsed(goal, …)` measures from it. */
|
|
23
|
+
readonly createdAt: number;
|
|
24
|
+
/** When a fact was said, for `elapsed(F, …)`. */
|
|
25
|
+
readonly saidAt: (factId: string) => number | undefined;
|
|
26
|
+
};
|
|
27
|
+
export type Context = {
|
|
28
|
+
readonly clock: Clock;
|
|
29
|
+
readonly text: TextIndex;
|
|
30
|
+
readonly entities: EntityIndex;
|
|
31
|
+
};
|
|
32
|
+
/** True if every non-stop keyword of `query` (stemmed, prefix-tolerant) occurs in `text`. */
|
|
33
|
+
export declare const keywordMatch: (text: string, query: string) => boolean;
|
|
34
|
+
/** Keyword stand-in for a semantic index. */
|
|
35
|
+
export declare class KeywordIndex implements TextIndex {
|
|
36
|
+
#private;
|
|
37
|
+
add(factId: string, text: string): void;
|
|
38
|
+
remove(factId: string): void;
|
|
39
|
+
matches(factId: string, query: string): boolean;
|
|
40
|
+
search(query: string): Iterable<string>;
|
|
41
|
+
}
|
|
42
|
+
/** In-memory entity index. */
|
|
43
|
+
export declare class MemoryEntityIndex implements EntityIndex {
|
|
44
|
+
#private;
|
|
45
|
+
add(factId: string, entities: ReadonlyArray<string>): void;
|
|
46
|
+
remove(factId: string): void;
|
|
47
|
+
concerns(factId: string): ReadonlyArray<string>;
|
|
48
|
+
facts(entity: string): Iterable<string>;
|
|
49
|
+
}
|
|
50
|
+
/** Parses `30s`, `5m`, `2h`, `2d`, `1w` (optionally ISO-prefixed `P`/`PT`) to milliseconds. */
|
|
51
|
+
export declare const parseDuration: (duration: string | number) => number | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* The goal built-ins: `about(F, Text)` and `concerns(F, Entity)` (both may bind `F`),
|
|
54
|
+
* `elapsed(Ref, Duration)` (`Ref` is `goal`, a fact id or a time), `every(Duration)` (a period
|
|
55
|
+
* boundary passed since the previous evaluation), `due(Time, Lead)`, `weekday(Time, Day)` and
|
|
56
|
+
* `hour(Time, Hour)` (UTC).
|
|
57
|
+
*/
|
|
58
|
+
export declare const make: ({ clock, text, entities }: Context) => Builtin.Registry;
|
|
59
|
+
/** A context with empty indexes and a frozen clock, for checking rules without evaluating them. */
|
|
60
|
+
export declare const emptyContext: () => Context;
|
|
61
|
+
//# sourceMappingURL=Builtins.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Builtins.d.ts","sourceRoot":"","sources":["../../../src/Builtins.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AAEjD,mGAAmG;AACnG,MAAM,WAAW,SAAS;IACxB,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACxC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,yCAAyC;IACzC,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;IAChD,gCAAgC;IAChC,MAAM,CAAC,K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O,CAE9C;IAEA,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,CAMvC;CACF;AAED,8BAA8B;AAC9B,qBAAa,iBAAkB,YAAW,WAAW;;IAGnD,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,IAAI,CAEzD;IAED,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAE3B;IAED,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,CAE9C;IAEA,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,CAMvC;CACF;AAID,+FAA+F;AAC/F,eAAO,MAAM,aAAa,aAAc,MAAM,GAAG,MAAM,KAAG,MAAM,GAAG,SAIlE,CAAC;AASF;;;;;GAKG;AACH,eAAO,MAAM,IAAI,8BAA+B,OAAO,KAAG,OAAO,CAAC,QAmGjE,CAAC;AAEF,mGAAmG;AACnG,eAAO,MAAM,YAAY,QAAO,OAI9B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Builtins.test.d.ts","sourceRoot":"","sources":["../../../src/Builtins.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import * as Schema from 'effect/Schema';
|
|
2
|
+
import { BaseError } from '@dxos/errors';
|
|
3
|
+
import * as Compiler from './Compiler.ts';
|
|
4
|
+
import * as Encoding from './Encoding.ts';
|
|
5
|
+
import * as Vocabulary from './Vocabulary.ts';
|
|
6
|
+
/** How a goal is satisfied; read from the goal text, never hardcoded in the runtime. */
|
|
7
|
+
export declare const Kind: Schema.Literals<readonly ["outcome", "condition", "constraint"]>;
|
|
8
|
+
export type Kind = Schema.Schema.Type<typeof Kind>;
|
|
9
|
+
/** Runtime mechanisms a goal needs: an index subscription, an alarm, a hook before each action. */
|
|
10
|
+
export declare const Driver: Schema.Literals<readonly ["fact", "time", "action"]>;
|
|
11
|
+
export type Driver = Schema.Schema.Type<typeof Driver>;
|
|
12
|
+
/** Whether `achieved(goal)` closes the goal on its own or only proposes closing it to judgment. */
|
|
13
|
+
export declare const Achievement: Schema.Literals<readonly ["rule", "judgment"]>;
|
|
14
|
+
export type Achievement = Schema.Schema.Type<typeof Achievement>;
|
|
15
|
+
/** A compilation as the model returned it, before `Compiler.compile` checks the rules. */
|
|
16
|
+
export declare const Reply: Schema.Struct<{
|
|
17
|
+
readonly kind: Schema.optional<Schema.Literals<readonly ["outcome", "condition", "constraint"]>>;
|
|
18
|
+
readonly drivers: Schema.$Array<Schema.Literals<readonly ["fact", "time", "action"]>>;
|
|
19
|
+
readonly achievement: Schema.optional<Schema.Literals<readonly ["rule", "judgment"]>>;
|
|
20
|
+
readonly datalog: Schema.String;
|
|
21
|
+
readonly notes: Schema.optional<Schema.String>;
|
|
22
|
+
}>;
|
|
23
|
+
export interface Reply extends Schema.Schema.Type<typeof Reply> {
|
|
24
|
+
}
|
|
25
|
+
/** What the user message tells the compiler about one goal. */
|
|
26
|
+
export type Goal = {
|
|
27
|
+
readonly goal: string;
|
|
28
|
+
/** Owner-written guidance, e.g. "follow up after 2 days". */
|
|
29
|
+
readonly instructions?: string;
|
|
30
|
+
/** Handle of the actor who owns the goal. */
|
|
31
|
+
readonly owner: string;
|
|
32
|
+
/** Creation time (ISO); `elapsed(goal, …)` and `every` count from it. */
|
|
33
|
+
readonly now: string;
|
|
34
|
+
/** Source id of the conversation a session goal is scoped to. */
|
|
35
|
+
readonly session?: string;
|
|
36
|
+
};
|
|
37
|
+
export type ReplyErrorCode = 'missing-datalog' | 'empty-datalog' | 'invalid-kind' | 'invalid-drivers' | 'invalid-achievement';
|
|
38
|
+
declare const ReplyError_base: {
|
|
39
|
+
new (options?: import("@dxos/errors").BaseErrorOptions): {
|
|
40
|
+
cause?: unknown;
|
|
41
|
+
stack?: string;
|
|
42
|
+
name: "ReplyError";
|
|
43
|
+
context: Record<string, unknown>;
|
|
44
|
+
readonly message: string;
|
|
45
|
+
readonly _tag: "ReplyError";
|
|
46
|
+
};
|
|
47
|
+
isError(error: unknown): error is Error;
|
|
48
|
+
name: "ReplyError";
|
|
49
|
+
is(error: unknown): error is BaseError;
|
|
50
|
+
wrap(options?: Omit<import("@dxos/errors").BaseErrorOptions, 'cause'> & {
|
|
51
|
+
ifTypeDiffers?: boolean;
|
|
52
|
+
}): (error: unknown) => {
|
|
53
|
+
cause?: unknown;
|
|
54
|
+
stack?: string;
|
|
55
|
+
name: "ReplyError";
|
|
56
|
+
context: Record<string, unknown>;
|
|
57
|
+
readonly message: string;
|
|
58
|
+
readonly _tag: "ReplyError";
|
|
59
|
+
};
|
|
60
|
+
extend<Name extends string = string>(name: Name, message?: string): any;
|
|
61
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
62
|
+
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
|
|
63
|
+
stackTraceLimit: number;
|
|
64
|
+
};
|
|
65
|
+
/** Thrown by `parseReply` when the model's reply does not follow the output format. */
|
|
66
|
+
export declare class ReplyError extends ReplyError_base {
|
|
67
|
+
readonly code: ReplyErrorCode;
|
|
68
|
+
readonly reason: string;
|
|
69
|
+
constructor(code: ReplyErrorCode, reason: string);
|
|
70
|
+
}
|
|
71
|
+
/** One line per fact relation; typed so a new relation cannot be added without describing it. */
|
|
72
|
+
export declare const FACT_RELATION_DOCS: Readonly<Record<keyof typeof Encoding.FACT_RELATIONS, string>>;
|
|
73
|
+
/** One line per goal-state relation the runtime maintains. */
|
|
74
|
+
export declare const GOAL_RELATION_DOCS: Readonly<Record<keyof typeof Encoding.GOAL_RELATIONS, string>>;
|
|
75
|
+
/** One entry per goal built-in, keyed by its name in `Builtins.make`. */
|
|
76
|
+
export declare const BUILTIN_DOCS: Readonly<Record<string, string>>;
|
|
77
|
+
/** One line per head the runtime reads. */
|
|
78
|
+
export declare const HEAD_DOCS: Readonly<Record<(typeof Compiler.GOAL_HEADS)[number], string>>;
|
|
79
|
+
type Example = {
|
|
80
|
+
readonly goal: string;
|
|
81
|
+
readonly owner: string;
|
|
82
|
+
readonly kind: Kind;
|
|
83
|
+
readonly drivers: ReadonlyArray<Driver>;
|
|
84
|
+
readonly achievement?: Achievement;
|
|
85
|
+
readonly datalog: string;
|
|
86
|
+
readonly notes: string;
|
|
87
|
+
};
|
|
88
|
+
/** Worked examples; tests compile each one so they stay valid in the dialect. */
|
|
89
|
+
export declare const EXAMPLES: ReadonlyArray<Example>;
|
|
90
|
+
export type SystemPromptOptions = {
|
|
91
|
+
/** Canonical predicates the prompt offers as shorthand; defaults to the compiler's vocabulary. */
|
|
92
|
+
readonly vocabulary?: Vocabulary.Vocabulary;
|
|
93
|
+
};
|
|
94
|
+
/** The compile prompt; built from the relations, built-ins and vocabulary so it cannot drift from the compiler. */
|
|
95
|
+
export declare const systemPrompt: ({ vocabulary }?: SystemPromptOptions) => string;
|
|
96
|
+
/** The compile prompt over the default vocabulary. */
|
|
97
|
+
export declare const SYSTEM_PROMPT: string;
|
|
98
|
+
/** The user message for one goal. */
|
|
99
|
+
export declare const userMessage: ({ goal, instructions, owner, now, session }: Goal) => string;
|
|
100
|
+
/**
|
|
101
|
+
* Extracts the rules and metadata from a model reply. Tolerates a code fence inside or instead of the `<datalog>`
|
|
102
|
+
* section; metadata sections are optional, but a present one must hold a valid value.
|
|
103
|
+
* @throws ReplyError if there are no rules or a metadata section is invalid.
|
|
104
|
+
*/
|
|
105
|
+
export declare const parseReply: (text: string) => Reply;
|
|
106
|
+
export {};
|
|
107
|
+
//# sourceMappingURL=CompilePrompt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CompilePrompt.d.ts","sourceRoot":"","sources":["../../../src/CompilePrompt.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,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,UAAU,CAAC;CAC7C,CAAC;AAEF,mHAAmH;AACnH,eAAO,MAAM,YAAY,oBAAmD,mBAAmB,KAAQ,MAsGtG,CAAC;AAEF,sDAAsD;AACtD,eAAO,MAAM,aAAa,EAAE,MAAuB,CAAC;AAEpD,qCAAqC;AACrC,eAAO,MAAM,WAAW,gDAAiD,IAAI,KAAG,MASjE,CAAC;AAEhB;;;;GAIG;AACH,eAAO,MAAM,UAAU,SAAU,MAAM,KAAG,KAsCzC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CompilePrompt.test.d.ts","sourceRoot":"","sources":["../../../src/CompilePrompt.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import * as Ast from '@dxos/datalog/Ast';
|
|
2
|
+
import type * as Builtin from '@dxos/datalog/Builtin';
|
|
3
|
+
import * as Checker from '@dxos/datalog/Checker';
|
|
4
|
+
import { BaseError } from '@dxos/errors';
|
|
5
|
+
import * as Vocabulary from './Vocabulary.ts';
|
|
6
|
+
/** Heads a goal program may define: `achieved(goal)`, `holds(goal)`, `wake(Label)`, `blocks(Action)`. */
|
|
7
|
+
export declare const GOAL_HEADS: readonly ['achieved', 'holds', 'wake', 'blocks'];
|
|
8
|
+
/** Relations goal rules may read; goal heads a program leaves undefined are empty. */
|
|
9
|
+
export declare const RELATIONS: Readonly<Record<string, number>>;
|
|
10
|
+
export type DiagnosticCode = Checker.DiagnosticCode | 'parse' | 'vocabulary' | 'goal';
|
|
11
|
+
export type Diagnostic = {
|
|
12
|
+
readonly code: DiagnosticCode;
|
|
13
|
+
readonly message: string;
|
|
14
|
+
readonly position?: Ast.Position;
|
|
15
|
+
};
|
|
16
|
+
/** A checked goal program ready for evaluation. */
|
|
17
|
+
export type Compilation = {
|
|
18
|
+
readonly source: string;
|
|
19
|
+
readonly program: Ast.Program;
|
|
20
|
+
/** Per-rule wake relations (one tuple per binding) and the label each one wakes. */
|
|
21
|
+
readonly wakes: ReadonlyMap<string, string>;
|
|
22
|
+
};
|
|
23
|
+
export type Options = {
|
|
24
|
+
readonly vocabulary?: Vocabulary.Vocabulary;
|
|
25
|
+
/** Defaults to the goal built-ins over an empty context (signatures are all checking needs). */
|
|
26
|
+
readonly builtins?: Builtin.Registry;
|
|
27
|
+
};
|
|
28
|
+
declare const CompileError_base: {
|
|
29
|
+
new (options?: import("@dxos/errors").BaseErrorOptions): {
|
|
30
|
+
cause?: unknown;
|
|
31
|
+
stack?: string;
|
|
32
|
+
name: "CompileError";
|
|
33
|
+
context: Record<string, unknown>;
|
|
34
|
+
readonly message: string;
|
|
35
|
+
readonly _tag: "CompileError";
|
|
36
|
+
};
|
|
37
|
+
isError(error: unknown): error is Error;
|
|
38
|
+
name: "CompileError";
|
|
39
|
+
is(error: unknown): error is BaseError;
|
|
40
|
+
wrap(options?: Omit<import("@dxos/errors").BaseErrorOptions, 'cause'> & {
|
|
41
|
+
ifTypeDiffers?: boolean;
|
|
42
|
+
}): (error: unknown) => {
|
|
43
|
+
cause?: unknown;
|
|
44
|
+
stack?: string;
|
|
45
|
+
name: "CompileError";
|
|
46
|
+
context: Record<string, unknown>;
|
|
47
|
+
readonly message: string;
|
|
48
|
+
readonly _tag: "CompileError";
|
|
49
|
+
};
|
|
50
|
+
extend<Name extends string = string>(name: Name, message?: string): any;
|
|
51
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
52
|
+
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
|
|
53
|
+
stackTraceLimit: number;
|
|
54
|
+
};
|
|
55
|
+
/** Thrown by `compileOrThrow` and `GoalRules` when compilation reports diagnostics. */
|
|
56
|
+
export declare class CompileError extends CompileError_base {
|
|
57
|
+
readonly diagnostics: ReadonlyArray<Diagnostic>;
|
|
58
|
+
constructor(diagnostics: ReadonlyArray<Diagnostic>);
|
|
59
|
+
}
|
|
60
|
+
/** Formats a diagnostic as `line:column code: message`. */
|
|
61
|
+
export declare const formatDiagnostic: ({ code, message, position }: Diagnostic) => string;
|
|
62
|
+
/** The vocabulary used when none is given. */
|
|
63
|
+
export declare const defaultVocabulary: () => Vocabulary.Vocabulary;
|
|
64
|
+
/**
|
|
65
|
+
* Compiles goal rules: parses, expands predicate shorthand for canonical vocabulary predicates
|
|
66
|
+
* (`helps_with(S, O)` → `fact(_, S, helps_with, O)`, `helps_with(F, S, O)` exposes the id),
|
|
67
|
+
* checks goal heads, then runs the engine's static checks against the fact relations.
|
|
68
|
+
*/
|
|
69
|
+
export declare const compile: (source: string, options?: Options) => {
|
|
70
|
+
compilation?: Compilation;
|
|
71
|
+
diagnostics: Diagnostic[];
|
|
72
|
+
};
|
|
73
|
+
/** Compiles goal rules, throwing on any diagnostic. */
|
|
74
|
+
export declare const compileOrThrow: (source: string, options?: Options) => Compilation;
|
|
75
|
+
export {};
|
|
76
|
+
//# sourceMappingURL=Compiler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Compiler.d.ts","sourceRoot":"","sources":["../../../src/Compiler.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,GAAG,MAAM,mBAAmB,CAAC;AACzC,OAAO,KAAK,KAAK,OAAO,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AAEjD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAIzC,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAC;AAE9C,yGAAyG;AACzG,eAAO,MAAM,UAAU,YAAI,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAU,CAAC;AAE3E,sFAAsF;AACtF,eAAO,MAAM,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAGtD,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,OAAO,CAAC,cAAc,GAAG,OAAO,GAAG,YAAY,GAAG,MAAM,CAAC;AAEtF,MAAM,MAA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{"version":3,"file":"Compiler.test.d.ts","sourceRoot":"","sources":["../../../src/Compiler.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type * as Engine from '@dxos/datalog/Engine';
|
|
2
|
+
import { RDF } from '@dxos/pipeline-rdf';
|
|
3
|
+
import type * as Vocabulary from './Vocabulary.ts';
|
|
4
|
+
/** Relations every fact contributes to, keyed by the fact id `F`. */
|
|
5
|
+
export declare const FACT_RELATIONS: {
|
|
6
|
+
readonly fact: 4;
|
|
7
|
+
readonly speaker: 2;
|
|
8
|
+
readonly force: 2;
|
|
9
|
+
readonly polarity: 2;
|
|
10
|
+
readonly mood: 2;
|
|
11
|
+
readonly factuality: 2;
|
|
12
|
+
readonly addressee: 2;
|
|
13
|
+
readonly quote: 2;
|
|
14
|
+
readonly source: 2;
|
|
15
|
+
readonly saidAt: 2;
|
|
16
|
+
readonly surface: 2;
|
|
17
|
+
readonly supersedes: 2;
|
|
18
|
+
readonly validFrom: 2;
|
|
19
|
+
readonly validTo: 2;
|
|
20
|
+
readonly confidence: 2;
|
|
21
|
+
readonly nature: 2;
|
|
22
|
+
readonly recordedAt: 2;
|
|
23
|
+
readonly pass: 2;
|
|
24
|
+
};
|
|
25
|
+
/** Relations the goal runtime maintains: sub-goal status and proposed actions. */
|
|
26
|
+
export declare const GOAL_RELATIONS: {
|
|
27
|
+
readonly subgoal: 2;
|
|
28
|
+
readonly status: 2;
|
|
29
|
+
readonly action: 2;
|
|
30
|
+
readonly actionArg: 3;
|
|
31
|
+
};
|
|
32
|
+
/** Every base relation a goal rule may read. */
|
|
33
|
+
export declare const RELATIONS: Readonly<Record<string, number>>;
|
|
34
|
+
/**
|
|
35
|
+
* Encodes a fact as `fact(F, S, P, O)` plus one metadata relation per present field. `P` is the
|
|
36
|
+
* canonical predicate when the vocabulary knows the surface form, which `surface(F, …)` keeps; a fact
|
|
37
|
+
* without an illocution is `assertive`, and `supersedes` lists `attribution.wasDerivedFrom`.
|
|
38
|
+
*/
|
|
39
|
+
export declare const encode: (fact: RDF.Fact, vocabulary?: Vocabulary.Vocabulary) => Engine.Entry[];
|
|
40
|
+
/** The fact ids among base entries (from provenance). */
|
|
41
|
+
export declare const factIds: (entries: ReadonlyArray<Engine.Entry>) => string[];
|
|
42
|
+
//# sourceMappingURL=Encoding.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Encoding.d.ts","sourceRoot":"","sources":["../../../src/Encoding.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,KAAK,MAAM,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAEzC,OAAO,KAAK,KAAK,UAAU,MAAM,iBAAiB,CAAC;AAEnD,qEAAqE;AACrE,eAAO,MAAM,cAAc;aACzB,IAAI,EAAE,CAAC;aACP,OAAO,EAAE,CAAC;aACV,KAAK,EAAE,CAAC;aACR,QAAQ,EAAE,CAAC;aACX,IAAI,EAAE,CAAC;aACP,UAAU,EAAE,CAAC;aACb,SAAS,EAAE,CAAC;aACZ,KAAK,EAAE,CAAC;aACR,MAAM,EAAE,CAAC;aACT,MAAM,EAAE,CAAC;aACT,OAAO,EAAE,CAAC;aACV,UAAU,EAAE,CAAC;aACb,SAAS,EAAE,CAAC;aACZ,OAAO,EAAE,CAAC;aACV,UAAU,EAAE,CAAC;aACb,MAAM,EAAE,CAAC;aACT,UAAU,EAAE,CAAC;aACb,IAAI,EAAE,CAAC;CACC,CAAC;AAEX,kFAAkF;AAClF,eAAO,MAAM,cAAc;aACzB,OAAO,EAAE,CAAC;aACV,MAAM,EAAE,CAAC;aACT,MAAM,EAAE,CAAC;aACT,SAAS,EAAE,CAAC;CACJ,CAAC;AAEX,gDAAgD;AAChD,eAAO,MAAM,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAA4C,CAAC;AAEpG;;;;GAIG;AACH,eAAO,MAAM,MAAM,SAAU,GAAG,CAAC,IAAI,eAAe,UAAU,CAAC,UAAU,KAAG,MAAM,CAAC,KAAK,EAwCvF,CAAC;AAEF,yDAAyD;AACzD,eAAO,MAAM,OAAO,YAAa,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC,KAAG,MAAM,EAMpE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Encoding.test.d.ts","sourceRoot":"","sources":["../../../src/Encoding.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { BaseError } from '@dxos/errors';
|
|
2
|
+
import { RDF } from '@dxos/pipeline-rdf';
|
|
3
|
+
import * as Builtins from './Builtins.ts';
|
|
4
|
+
import * as Compiler from './Compiler.ts';
|
|
5
|
+
import type * as Vocabulary from './Vocabulary.ts';
|
|
6
|
+
/**
|
|
7
|
+
* Size of the evaluator's working memory: past it the oldest facts retire, so a goal that runs
|
|
8
|
+
* indefinitely keeps a bounded engine, text and entity index (and bounded queries over them).
|
|
9
|
+
*/
|
|
10
|
+
export declare const MAX_FACTS = 10000;
|
|
11
|
+
/** Most sub-goals one evaluator tracks; sub-goals are structural, so exceeding it is an error. */
|
|
12
|
+
export declare const MAX_SUBGOALS = 256;
|
|
13
|
+
declare const CapacityError_base: {
|
|
14
|
+
new (options?: import("@dxos/errors").BaseErrorOptions): {
|
|
15
|
+
cause?: unknown;
|
|
16
|
+
stack?: string;
|
|
17
|
+
name: "CapacityError";
|
|
18
|
+
context: Record<string, unknown>;
|
|
19
|
+
readonly message: string;
|
|
20
|
+
readonly _tag: "CapacityError";
|
|
21
|
+
};
|
|
22
|
+
isError(error: unknown): error is Error;
|
|
23
|
+
name: "CapacityError";
|
|
24
|
+
is(error: unknown): error is BaseError;
|
|
25
|
+
wrap(options?: Omit<import("@dxos/errors").BaseErrorOptions, 'cause'> & {
|
|
26
|
+
ifTypeDiffers?: boolean;
|
|
27
|
+
}): (error: unknown) => {
|
|
28
|
+
cause?: unknown;
|
|
29
|
+
stack?: string;
|
|
30
|
+
name: "CapacityError";
|
|
31
|
+
context: Record<string, unknown>;
|
|
32
|
+
readonly message: string;
|
|
33
|
+
readonly _tag: "CapacityError";
|
|
34
|
+
};
|
|
35
|
+
extend<Name extends string = string>(name: Name, message?: string): any;
|
|
36
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
37
|
+
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
|
|
38
|
+
stackTraceLimit: number;
|
|
39
|
+
};
|
|
40
|
+
/** Thrown by `GoalRules.update` when an input would take the evaluator past {@link MAX_SUBGOALS}. */
|
|
41
|
+
export declare class CapacityError extends CapacityError_base {
|
|
42
|
+
constructor(context: {
|
|
43
|
+
readonly max: number;
|
|
44
|
+
readonly requested: number;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/** A reason to run judgment on the goal. */
|
|
48
|
+
export type Wake = {
|
|
49
|
+
/** The wake rule's label, `achieved`, or the sub-goal whose status changed. */
|
|
50
|
+
readonly label: string;
|
|
51
|
+
readonly cause: 'rule' | 'achieved' | 'subgoal';
|
|
52
|
+
/** Ids of the facts the waking derivation rests on. */
|
|
53
|
+
readonly facts: ReadonlyArray<string>;
|
|
54
|
+
};
|
|
55
|
+
export type Evaluation = {
|
|
56
|
+
readonly at: number;
|
|
57
|
+
readonly wakes: ReadonlyArray<Wake>;
|
|
58
|
+
readonly achieved: boolean;
|
|
59
|
+
readonly holds: boolean;
|
|
60
|
+
};
|
|
61
|
+
/** An action the agent proposes, checked against the goal's `blocks` rules before it runs. */
|
|
62
|
+
export type Action = {
|
|
63
|
+
readonly id: string;
|
|
64
|
+
readonly kind: string;
|
|
65
|
+
readonly args: Readonly<Record<string, string>>;
|
|
66
|
+
};
|
|
67
|
+
export type ActionCheck = {
|
|
68
|
+
readonly blocked: boolean;
|
|
69
|
+
/** Ids of the facts that contributed to the block (empty when only the action did). */
|
|
70
|
+
readonly facts: ReadonlyArray<string>;
|
|
71
|
+
};
|
|
72
|
+
export type Options = {
|
|
73
|
+
readonly source: string;
|
|
74
|
+
/** When the goal was created (epoch ms); also the clock's starting time. */
|
|
75
|
+
readonly createdAt: number;
|
|
76
|
+
readonly vocabulary?: Vocabulary.Vocabulary;
|
|
77
|
+
readonly text?: Builtins.TextIndex;
|
|
78
|
+
readonly entities?: Builtins.EntityIndex;
|
|
79
|
+
/** Entities a fact concerns; defaults to its subject. */
|
|
80
|
+
readonly concerns?: (fact: RDF.Fact) => ReadonlyArray<string>;
|
|
81
|
+
/**
|
|
82
|
+
* Working-memory size; defaults to {@link MAX_FACTS}. Each `update` first retires facts whose
|
|
83
|
+
* `assertion.validTo` is before the clock, then the oldest (by `generatedAtTime`, then arrival)
|
|
84
|
+
* until at most `maxFacts` remain. Retiring drops a fact from the evaluator only; the feed and any
|
|
85
|
+
* external index keep it, and a re-sent fact with a retired id is admitted again as new.
|
|
86
|
+
* Retirement never wakes the goal, and the facts behind the current `achieved` derivation are
|
|
87
|
+
* never retired, so a goal stays achieved once it is; `holds` and wake bindings may lapse as
|
|
88
|
+
* their facts retire, and a lapsed binding wakes again when new facts restore it.
|
|
89
|
+
*/
|
|
90
|
+
readonly maxFacts?: number;
|
|
91
|
+
/** Overrides {@link MAX_SUBGOALS}. */
|
|
92
|
+
readonly maxSubgoals?: number;
|
|
93
|
+
};
|
|
94
|
+
export type Input = {
|
|
95
|
+
/** Evaluation time (epoch ms); a change re-evaluates time built-ins. */
|
|
96
|
+
readonly at: number;
|
|
97
|
+
readonly facts?: ReadonlyArray<RDF.Fact>;
|
|
98
|
+
/** Current status of each sub-goal; a new id adds the sub-goal. */
|
|
99
|
+
readonly subgoals?: Readonly<Record<string, string>>;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Evaluates one goal's compiled rules over a growing fact stream and a clock. A goal wakes when a
|
|
103
|
+
* wake rule gains a new binding, when `achieved` first becomes true, and when a sub-goal's status
|
|
104
|
+
* changes.
|
|
105
|
+
*/
|
|
106
|
+
export declare class GoalRules {
|
|
107
|
+
#private;
|
|
108
|
+
readonly compilation: Compiler.Compilation;
|
|
109
|
+
/** @throws Compiler.CompileError if the rules do not compile. */
|
|
110
|
+
constructor(options: Options);
|
|
111
|
+
get achieved(): boolean;
|
|
112
|
+
get holds(): boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Adds facts and sub-goal status at time `at`, retiring facts past the working-memory window
|
|
115
|
+
* (see {@link Options.maxFacts}); returns the wakes and the goal's state.
|
|
116
|
+
* @throws CapacityError if the input would exceed the sub-goal cap; nothing is applied.
|
|
117
|
+
*/
|
|
118
|
+
update({ at, facts, subgoals }: Input): Evaluation;
|
|
119
|
+
/** Evaluates the `blocks` rules for a proposed action without keeping it. */
|
|
120
|
+
checkAction(action: Action): ActionCheck;
|
|
121
|
+
}
|
|
122
|
+
/** Creates a goal evaluator. */
|
|
123
|
+
export declare const make: (options: Options) => GoalRules;
|
|
124
|
+
export {};
|
|
125
|
+
//# sourceMappingURL=GoalRules.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GoalRules.d.ts","sourceRoot":"","sources":["../../../src/GoalRules.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAEzC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAE1C,OAAO,KAAK,KAAK,UAAU,MAAM,iBAAiB,CAAC;AAEnD;;;GAGG;AACH,eAAO,MAAM,SAAS,QAAS,CAAC;AAEhC,kGAAkG;AAClG,eAAO,MAAM,YAAY,MAAM,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEhC,qGAAqG;AACrG,qBAAa,aAAc,SAAQ,kBAAqE;IACtG,YAAY,OAAO,EAAE;QAAE,QAAQ,CAAC,GAAG,EAAE,MA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 @@
|
|
|
1
|
+
/** A canonical predicate and the surface forms extraction maps onto it. */
|
|
2
|
+
export type Entry = {
|
|
3
|
+
/** Identifier usable as rule shorthand (`helps_with(dima, X)`). */
|
|
4
|
+
readonly predicate: string;
|
|
5
|
+
readonly synonyms?: ReadonlyArray<string>;
|
|
6
|
+
readonly description?: string;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* The lookup key for a surface predicate: pipeline-rdf's relation key (case, auxiliaries and head-verb
|
|
10
|
+
* inflection collapse, as the fact store matches them) with words joined by `_`, so `Will-Work-On`,
|
|
11
|
+
* `working on` and `works_on` compare equal.
|
|
12
|
+
*/
|
|
13
|
+
export declare const normalize: (surface: string) => string;
|
|
14
|
+
/** The canonical predicates rules may use as shorthand, and the synonyms that map onto them. */
|
|
15
|
+
export declare class Vocabulary {
|
|
16
|
+
#private;
|
|
17
|
+
readonly entries: ReadonlyArray<Entry>;
|
|
18
|
+
/** @throws Error on an invalid predicate name, a reserved name, or a synonym claimed twice. */
|
|
19
|
+
constructor(entries: ReadonlyArray<Entry>, reserved?: ReadonlyArray<string>);
|
|
20
|
+
/** True if `name` is a canonical predicate. */
|
|
21
|
+
isCanonical(name: string): boolean;
|
|
22
|
+
/** The canonical predicate for a surface form, if the vocabulary knows it. */
|
|
23
|
+
canonical(surface: string): string | undefined;
|
|
24
|
+
/** The stored predicate for a surface form: canonical if known, otherwise the form unchanged. */
|
|
25
|
+
resolve(surface: string): string;
|
|
26
|
+
}
|
|
27
|
+
/** Creates a vocabulary. */
|
|
28
|
+
export declare const make: (entries: ReadonlyArray<Entry>, reserved?: ReadonlyArray<string>) => Vocabulary;
|
|
29
|
+
/** A starter vocabulary covering the example goals; extraction grows it. */
|
|
30
|
+
export declare const DEFAULT_ENTRIES: ReadonlyArray<Entry>;
|
|
31
|
+
//# sourceMappingURL=Vocabulary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Vocabulary.d.ts","sourceRoot":"","sources":["../../../src/Vocabulary.ts"],"names":[],"mappings":"AAQA,2EAA2E;AAC3E,MAAM,MAAM,KAAK,GAAG;IAClB,mEAAmE;IACnE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAC1C,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC/B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,SAAS,YAAa,MAAM,KAAG,MAC8B,CAAC;AAE3E,gGAAgG;AAChG,qBAAa,UAAU;;IACrB,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC,KAAK,CAAC,CAAC;IAIvC,+FAA+F;IAC/F,YAAY,OAAO,EAAE,aAAa,CAAC,KAAK,CAAC,EAAE,QAAQ,GAAE,aAAa,CAAC,MAAM,CAAM,EAmB9E;IAED,+CAA+C;IAC/C,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEjC;IAED,8EAA8E;IAC9E,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAE7C;IAED,iGAAiG;IACjG,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAE/B;CACF;AAED,4BAA4B;AAC5B,eAAO,MAAM,IAAI,YAAa,aAAa,CAAC,KAAK,CAAC,aAAY,aAAa,CAAC,MAAM,CAAC,KAAQ,UACxD,CAAC;AAEpC,4EAA4E;AAC5E,eAAO,MAAM,eAAe,EAAE,aAAa,CAAC,KAAK,CAchD,CAAC"}
|