@dxos/brain 0.12.0 → 0.14.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/dist/lib/Builtins.mjs +10 -2
- package/dist/lib/Builtins.mjs.map +1 -1
- package/dist/lib/Encoding.mjs +12 -2
- package/dist/lib/Encoding.mjs.map +1 -1
- package/dist/lib/Evaluator.mjs +144 -0
- package/dist/lib/Evaluator.mjs.map +1 -0
- package/dist/lib/GoalRules.mjs +153 -11
- package/dist/lib/GoalRules.mjs.map +1 -1
- package/dist/lib/Oracle.mjs +169 -0
- package/dist/lib/Oracle.mjs.map +1 -0
- package/dist/lib/index.mjs +3 -1
- package/dist/types/src/Builtins.d.ts +6 -0
- package/dist/types/src/Builtins.d.ts.map +1 -1
- package/dist/types/src/Encoding.d.ts +4 -0
- package/dist/types/src/Encoding.d.ts.map +1 -1
- 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/Evaluator.d.ts +77 -0
- package/dist/types/src/Evaluator.d.ts.map +1 -0
- package/dist/types/src/Evaluator.test.d.ts +2 -0
- package/dist/types/src/Evaluator.test.d.ts.map +1 -0
- package/dist/types/src/GoalRules.d.ts +66 -1
- package/dist/types/src/GoalRules.d.ts.map +1 -1
- package/dist/types/src/Oracle.d.ts +126 -0
- package/dist/types/src/Oracle.d.ts.map +1 -0
- package/dist/types/src/Oracle.test.d.ts +2 -0
- package/dist/types/src/Oracle.test.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +2 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +15 -5
- package/src/Builtins.ts +12 -1
- package/src/Encoding.test.ts +93 -0
- package/src/Encoding.ts +9 -0
- package/src/Evaluator.test.ts +158 -0
- package/src/Evaluator.ts +186 -0
- package/src/GoalRules.test.ts +98 -0
- package/src/GoalRules.ts +212 -10
- package/src/Oracle.test.ts +71 -0
- package/src/Oracle.ts +182 -0
- package/src/index.ts +2 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import * as Schema from 'effect/Schema';
|
|
2
|
+
import { BaseError } from '@dxos/errors';
|
|
3
|
+
/**
|
|
4
|
+
* The replay gate's oracle (BRAIN.md, "Compilation"): a model call that sees only the goal's text and
|
|
5
|
+
* writes a short timeline of statements with what each should do to the goal. A compilation goes active
|
|
6
|
+
* only if it replays that timeline correctly; the oracle never sees the rules, so it cannot share the
|
|
7
|
+
* compiler's misreading of the goal.
|
|
8
|
+
*/
|
|
9
|
+
/** One statement in a test timeline; people and things are named by the ids the goal was given. */
|
|
10
|
+
export declare const Statement: Schema.Struct<{
|
|
11
|
+
readonly speaker: Schema.String;
|
|
12
|
+
readonly quote: Schema.String;
|
|
13
|
+
readonly subject: Schema.String;
|
|
14
|
+
readonly predicate: Schema.String;
|
|
15
|
+
readonly object: Schema.String;
|
|
16
|
+
readonly force: Schema.optional<Schema.Literals<readonly ["assertive", "directive", "commissive", "expressive"]>>;
|
|
17
|
+
readonly polarity: Schema.optional<Schema.Literals<readonly ["+", "-"]>>;
|
|
18
|
+
}>;
|
|
19
|
+
export interface Statement extends Schema.Schema.Type<typeof Statement> {
|
|
20
|
+
}
|
|
21
|
+
/** A step of the timeline: when it happens after the goal is set, what is said, and what should follow. */
|
|
22
|
+
export declare const Step: Schema.Struct<{
|
|
23
|
+
/** A duration after the goal was set, e.g. `10m`, `1h`, `3d`. */
|
|
24
|
+
readonly after: Schema.String;
|
|
25
|
+
readonly says: Schema.$Array<Schema.Struct<{
|
|
26
|
+
readonly speaker: Schema.String;
|
|
27
|
+
readonly quote: Schema.String;
|
|
28
|
+
readonly subject: Schema.String;
|
|
29
|
+
readonly predicate: Schema.String;
|
|
30
|
+
readonly object: Schema.String;
|
|
31
|
+
readonly force: Schema.optional<Schema.Literals<readonly ["assertive", "directive", "commissive", "expressive"]>>;
|
|
32
|
+
readonly polarity: Schema.optional<Schema.Literals<readonly ["+", "-"]>>;
|
|
33
|
+
}>>;
|
|
34
|
+
/** Whether the goal should wake (be judged) at this step. */
|
|
35
|
+
readonly wake: Schema.Boolean;
|
|
36
|
+
/** Whether the goal should be achieved after this step; absent when either is acceptable. */
|
|
37
|
+
readonly achieved: Schema.optional<Schema.Boolean>;
|
|
38
|
+
readonly note: Schema.optional<Schema.String>;
|
|
39
|
+
}>;
|
|
40
|
+
export interface Step extends Schema.Schema.Type<typeof Step> {
|
|
41
|
+
}
|
|
42
|
+
export declare const Reply: Schema.Struct<{
|
|
43
|
+
readonly steps: Schema.$Array<Schema.Struct<{
|
|
44
|
+
/** A duration after the goal was set, e.g. `10m`, `1h`, `3d`. */
|
|
45
|
+
readonly after: Schema.String;
|
|
46
|
+
readonly says: Schema.$Array<Schema.Struct<{
|
|
47
|
+
readonly speaker: Schema.String;
|
|
48
|
+
readonly quote: Schema.String;
|
|
49
|
+
readonly subject: Schema.String;
|
|
50
|
+
readonly predicate: Schema.String;
|
|
51
|
+
readonly object: Schema.String;
|
|
52
|
+
readonly force: Schema.optional<Schema.Literals<readonly ["assertive", "directive", "commissive", "expressive"]>>;
|
|
53
|
+
readonly polarity: Schema.optional<Schema.Literals<readonly ["+", "-"]>>;
|
|
54
|
+
}>>;
|
|
55
|
+
/** Whether the goal should wake (be judged) at this step. */
|
|
56
|
+
readonly wake: Schema.Boolean;
|
|
57
|
+
/** Whether the goal should be achieved after this step; absent when either is acceptable. */
|
|
58
|
+
readonly achieved: Schema.optional<Schema.Boolean>;
|
|
59
|
+
readonly note: Schema.optional<Schema.String>;
|
|
60
|
+
}>>;
|
|
61
|
+
}>;
|
|
62
|
+
export interface Reply extends Schema.Schema.Type<typeof Reply> {
|
|
63
|
+
}
|
|
64
|
+
export type Person = {
|
|
65
|
+
readonly name: string;
|
|
66
|
+
readonly id: string;
|
|
67
|
+
};
|
|
68
|
+
export type Goal = {
|
|
69
|
+
readonly goal: string;
|
|
70
|
+
readonly instructions?: string;
|
|
71
|
+
/** Id of the goal's owner. */
|
|
72
|
+
readonly owner: string;
|
|
73
|
+
/** People the goal may concern, with the ids statements must use for them. */
|
|
74
|
+
readonly people?: ReadonlyArray<Person>;
|
|
75
|
+
};
|
|
76
|
+
declare const ReplyError_base: {
|
|
77
|
+
new (options?: import("@dxos/errors").BaseErrorOptions): {
|
|
78
|
+
cause?: unknown;
|
|
79
|
+
stack?: string;
|
|
80
|
+
name: "OracleReplyError";
|
|
81
|
+
context: Record<string, unknown>;
|
|
82
|
+
readonly message: string;
|
|
83
|
+
readonly _tag: "OracleReplyError";
|
|
84
|
+
};
|
|
85
|
+
isError(error: unknown): error is Error;
|
|
86
|
+
name: "OracleReplyError";
|
|
87
|
+
is(error: unknown): error is BaseError;
|
|
88
|
+
wrap(options?: Omit<import("@dxos/errors").BaseErrorOptions, 'cause'> & {
|
|
89
|
+
ifTypeDiffers?: boolean;
|
|
90
|
+
}): (error: unknown) => {
|
|
91
|
+
cause?: unknown;
|
|
92
|
+
stack?: string;
|
|
93
|
+
name: "OracleReplyError";
|
|
94
|
+
context: Record<string, unknown>;
|
|
95
|
+
readonly message: string;
|
|
96
|
+
readonly _tag: "OracleReplyError";
|
|
97
|
+
};
|
|
98
|
+
extend<Name extends string = string>(name: Name, message?: string): any;
|
|
99
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
100
|
+
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
|
|
101
|
+
stackTraceLimit: number;
|
|
102
|
+
};
|
|
103
|
+
/** Thrown by {@link parseReply} when the reply is not a timeline. */
|
|
104
|
+
export declare class ReplyError extends ReplyError_base {
|
|
105
|
+
}
|
|
106
|
+
/** The oracle's instructions. */
|
|
107
|
+
export declare const SYSTEM_PROMPT: string;
|
|
108
|
+
/** The user message for one goal. */
|
|
109
|
+
export declare const userMessage: ({ goal, instructions, owner, people }: Goal) => string;
|
|
110
|
+
/**
|
|
111
|
+
* Extracts the timeline from the oracle's reply; tolerates a code fence or prose around the JSON.
|
|
112
|
+
* @throws ReplyError if there is no valid timeline.
|
|
113
|
+
*/
|
|
114
|
+
export declare const parseReply: (text: string) => Reply;
|
|
115
|
+
export type Result = {
|
|
116
|
+
readonly ok: boolean;
|
|
117
|
+
/** One line per expectation the rules violate. */
|
|
118
|
+
readonly failures: ReadonlyArray<string>;
|
|
119
|
+
};
|
|
120
|
+
/** Replays the oracle's timeline against compiled rules; a compile error is a failure. */
|
|
121
|
+
export declare const replay: (source: string, { createdAt, steps }: {
|
|
122
|
+
createdAt: number;
|
|
123
|
+
steps: ReadonlyArray<Step>;
|
|
124
|
+
}) => Result;
|
|
125
|
+
export {};
|
|
126
|
+
//# sourceMappingURL=Oracle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Oracle.d.ts","sourceRoot":"","sources":["../../../src/Oracle.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAQzC;;;;;GAKG;AAEH,mGAAmG;AACnG,eAAO,MAAM,SAAS;;;;;;;;EAQpB,CAAC;AACH,MAAM,WAAW,SAAU,SAAQ,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,SAAS,CAAC;CAAG;AAE1E,2GAA2G;AAC3G,eAAO,MAAM,IAAI;IACf,iEAAiE;;;;;;;;;;;IAGjE,6DAA6D;;IAE7D,6FAA6F;;;EAG7F,CAAC;AACH,MAAM,WAAW,IAAK,SAAQ,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC;CAAG;AAEhE,eAAO,MAAM,KAAK;;QAXhB,iEAAiE;;;;;;;;;;;QAGjE,6DAA6D;;QAE7D,6FAA6F;;;;EAM9B,CAAC;AAClE,MAAM,WAAW,KAAM,SAAQ,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,KAAK,CAAC;CAAG;AAElE,MAAM,MAAM,MAAM,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC;AAEpE,MAAM,MAAM,IAAI,GAAG;IACjB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,8BAA8B;IAC9B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,8EAA8E;IAC9E,QAAQ,CAAC,MAAM,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CACzC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEF,qEAAqE;AACrE,qBAAa,UAAW,SAAQ,eAAsE;CAAG;AAEzG,iCAAiC;AACjC,eAAO,MAAM,aAAa,QAqBzB,CAAC;AAEF,qCAAqC;AACrC,eAAO,MAAM,WAAW,0CAAgD,IAAI,KAAG,MAUhE,CAAC;AAIhB;;;GAGG;AACH,eAAO,MAAM,UAAU,SAAU,MAAM,KAAG,KAiBzC,CAAC;AAmBF,MAAM,MAAM,MAAM,GAAG;IACnB,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC;IACrB,kDAAkD;IAClD,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CAC1C,CAAC;AAEF,0FAA0F;AAC1F,eAAO,MAAM,MAAM,WACT,MAAM,wBACQ;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,aAAa,CAAC,IAAI,CAAC,CAAA;CAAE,KACtE,MA2BF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Oracle.test.d.ts","sourceRoot":"","sources":["../../../src/Oracle.test.ts"],"names":[],"mappings":""}
|
|
@@ -2,6 +2,8 @@ export * as Builtins from './Builtins.ts';
|
|
|
2
2
|
export * as CompilePrompt from './CompilePrompt.ts';
|
|
3
3
|
export * as Compiler from './Compiler.ts';
|
|
4
4
|
export * as Encoding from './Encoding.ts';
|
|
5
|
+
export * as Evaluator from './Evaluator.ts';
|
|
5
6
|
export * as GoalRules from './GoalRules.ts';
|
|
7
|
+
export * as Oracle from './Oracle.ts';
|
|
6
8
|
export * as Vocabulary from './Vocabulary.ts';
|
|
7
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAC"}
|