@dxos/assistant 0.8.0 → 0.8.1-main.81238a8
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/browser/chunk-RFTY3OMK.mjs +2276 -0
- package/dist/lib/browser/chunk-RFTY3OMK.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +33 -1236
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +17 -3
- package/dist/lib/browser/testing/index.mjs.map +4 -4
- package/dist/lib/node/chunk-4ZDZUCAS.cjs +2287 -0
- package/dist/lib/node/chunk-4ZDZUCAS.cjs.map +7 -0
- package/dist/lib/node/index.cjs +40 -1236
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +40 -29
- package/dist/lib/node/testing/index.cjs.map +4 -4
- package/dist/lib/node-esm/chunk-JUVGBQBL.mjs +2278 -0
- package/dist/lib/node-esm/chunk-JUVGBQBL.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +33 -1236
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +17 -3
- package/dist/lib/node-esm/testing/index.mjs.map +4 -4
- package/dist/types/src/ai-service/defs.d.ts +8 -2
- package/dist/types/src/ai-service/defs.d.ts.map +1 -1
- package/dist/types/src/ai-service/edge-client.d.ts +19 -0
- package/dist/types/src/ai-service/edge-client.d.ts.map +1 -0
- package/dist/types/src/ai-service/index.d.ts +4 -1
- package/dist/types/src/ai-service/index.d.ts.map +1 -1
- package/dist/types/src/ai-service/message-collector.d.ts +88 -0
- package/dist/types/src/ai-service/message-collector.d.ts.map +1 -0
- package/dist/types/src/ai-service/ollama-client.d.ts +39 -0
- package/dist/types/src/ai-service/ollama-client.d.ts.map +1 -0
- package/dist/types/src/ai-service/parser.d.ts +11 -9
- package/dist/types/src/ai-service/parser.d.ts.map +1 -1
- package/dist/types/src/ai-service/service.d.ts +9 -0
- package/dist/types/src/ai-service/service.d.ts.map +1 -0
- package/dist/types/src/ai-service/stream.d.ts +2 -1
- package/dist/types/src/ai-service/stream.d.ts.map +1 -1
- package/dist/types/src/ai-service/testing/mock.d.ts +2 -2
- package/dist/types/src/ai-service/testing/mock.d.ts.map +1 -1
- package/dist/types/src/ai-service/types.d.ts +91 -157
- package/dist/types/src/ai-service/types.d.ts.map +1 -1
- package/dist/types/src/conversation/conversation.d.ts +11 -9
- package/dist/types/src/conversation/conversation.d.ts.map +1 -1
- package/dist/types/src/conversation/types.d.ts +1 -1
- package/dist/types/src/conversation/types.d.ts.map +1 -1
- package/dist/types/src/testing/index.d.ts +1 -0
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/testing/ollama.d.ts +6 -0
- package/dist/types/src/testing/ollama.d.ts.map +1 -0
- package/dist/types/src/testing/query-promts.d.ts +1 -1
- package/dist/types/src/testing/query-promts.d.ts.map +1 -1
- package/dist/types/src/testing/test-data.d.ts +1 -1
- package/dist/types/src/testing/test-data.d.ts.map +1 -1
- package/dist/types/src/testing/test-schema.d.ts +1 -1
- package/dist/types/src/testing/test-schema.d.ts.map +1 -1
- package/package.json +17 -14
- package/src/ai-service/client.test.ts +100 -13
- package/src/ai-service/defs.ts +17 -2
- package/src/ai-service/{client.ts → edge-client.ts} +15 -24
- package/src/ai-service/index.ts +4 -1
- package/src/ai-service/message-collector.ts +84 -0
- package/src/ai-service/ollama-client.ts +499 -0
- package/src/ai-service/parser.ts +7 -2
- package/src/ai-service/service.ts +15 -0
- package/src/ai-service/stream.ts +5 -3
- package/src/ai-service/testing/mock.ts +7 -2
- package/src/ai-service/types.ts +3 -3
- package/src/bin/chat.ts +3 -3
- package/src/conversation/conversation.test.ts +5 -5
- package/src/conversation/conversation.ts +3 -2
- package/src/conversation/types.ts +1 -1
- package/src/testing/artifacts.test.ts +4 -4
- package/src/testing/index.ts +1 -0
- package/src/testing/object-extraction.test.ts +1 -1
- package/src/testing/ollama.ts +15 -0
- package/src/testing/query-promts.ts +1 -1
- package/src/testing/query.test.ts +4 -4
- package/src/testing/test-data.ts +1 -1
- package/src/testing/test-schema.ts +1 -1
- package/dist/lib/browser/chunk-AXUUNA7O.mjs +0 -565
- package/dist/lib/browser/chunk-AXUUNA7O.mjs.map +0 -7
- package/dist/lib/node/chunk-QPHGQINW.cjs +0 -577
- package/dist/lib/node/chunk-QPHGQINW.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-GOVFOBIB.mjs +0 -567
- package/dist/lib/node-esm/chunk-GOVFOBIB.mjs.map +0 -7
- package/dist/types/src/ai-service/client.d.ts +0 -25
- package/dist/types/src/ai-service/client.d.ts.map +0 -1
|
@@ -1,565 +0,0 @@
|
|
|
1
|
-
// packages/experimental/assistant/src/cypher/parjs.ts
|
|
2
|
-
import { parjsCombinators, parjs } from "#parjs";
|
|
3
|
-
|
|
4
|
-
// packages/experimental/assistant/src/cypher/combinators.ts
|
|
5
|
-
var ws = parjs.whitespace();
|
|
6
|
-
var nothing = parjs.string("").pipe(parjsCombinators.map(() => null));
|
|
7
|
-
var optional = (parser) => parser.pipe(parjsCombinators.recover(() => ({
|
|
8
|
-
kind: "Soft"
|
|
9
|
-
})), parjsCombinators.or(nothing));
|
|
10
|
-
var keyword = (word) => parjs.string(word).pipe(parjsCombinators.map(() => word));
|
|
11
|
-
var identifier = parjs.regexp(/[a-zA-Z_][a-zA-Z0-9_]*/).pipe(parjsCombinators.map((match) => ({
|
|
12
|
-
astKind: "Identifier",
|
|
13
|
-
name: match[0]
|
|
14
|
-
})));
|
|
15
|
-
var numberLiteral = parjs.regexp(/-?\d+(\.\d+)?/).pipe(parjsCombinators.map(Number));
|
|
16
|
-
var stringLiteral = parjs.regexp(/"([^"]*)"|'([^']*)'/).pipe(parjsCombinators.map((match) => ({
|
|
17
|
-
astKind: "StringLiteral",
|
|
18
|
-
value: match[1] || match[2]
|
|
19
|
-
})));
|
|
20
|
-
var variableTag = identifier.pipe(parjsCombinators.map((variable) => variable)).expects("variable tag");
|
|
21
|
-
var label = identifier.pipe(parjsCombinators.map((name) => name));
|
|
22
|
-
var property = identifier.pipe(parjsCombinators.then(parjs.string(":"), ws, stringLiteral), parjsCombinators.map(([key, , , value]) => ({
|
|
23
|
-
key,
|
|
24
|
-
value
|
|
25
|
-
})));
|
|
26
|
-
var properties = property.pipe(parjsCombinators.manySepBy(","), parjsCombinators.between("{", "}"), parjsCombinators.map((properties2) => ({
|
|
27
|
-
astKind: "Properties",
|
|
28
|
-
properties: properties2
|
|
29
|
-
})));
|
|
30
|
-
var nodePattern = optional(variableTag).pipe(parjsCombinators.then(":"), parjsCombinators.then(ws, label, ws), parjsCombinators.then(optional(properties)), parjsCombinators.between("(", ")"), parjsCombinators.map(([[[variable], _, label2], properties2]) => ({
|
|
31
|
-
astKind: "NodePattern",
|
|
32
|
-
variable,
|
|
33
|
-
label: label2,
|
|
34
|
-
properties: properties2
|
|
35
|
-
})));
|
|
36
|
-
var relationshipPattern = optional(variableTag).pipe(parjsCombinators.then(":"), parjsCombinators.then(ws, label, ws), parjsCombinators.then(optional(properties)), parjsCombinators.between("[", "]"), parjsCombinators.map(([[[variable], _, label2], properties2]) => ({
|
|
37
|
-
astKind: "RelationshipPattern",
|
|
38
|
-
variable,
|
|
39
|
-
label: label2,
|
|
40
|
-
properties: properties2
|
|
41
|
-
})));
|
|
42
|
-
var graphPatternConnector = parjs.string("->").pipe(parjsCombinators.or("<-", "-"), parjsCombinators.map((x) => ({
|
|
43
|
-
astKind: "GraphPatternConnector",
|
|
44
|
-
direction: x
|
|
45
|
-
})));
|
|
46
|
-
var graphPattern = nodePattern.pipe(parjsCombinators.or(relationshipPattern), parjsCombinators.manySepBy(graphPatternConnector), parjsCombinators.map((segments) => ({
|
|
47
|
-
astKind: "GraphPattern",
|
|
48
|
-
segments
|
|
49
|
-
})));
|
|
50
|
-
var matchClause = keyword("MATCH").pipe(parjsCombinators.then(ws), parjsCombinators.then(graphPattern), parjsCombinators.map(([, pattern]) => ({
|
|
51
|
-
astKind: "MatchClause",
|
|
52
|
-
pattern
|
|
53
|
-
})));
|
|
54
|
-
var memberExpression = identifier.pipe(parjsCombinators.manySepBy("."), parjsCombinators.map((path) => ({
|
|
55
|
-
astKind: "MemberExpression",
|
|
56
|
-
path
|
|
57
|
-
})));
|
|
58
|
-
var equalsPredicate = memberExpression.pipe(parjsCombinators.then(ws, parjs.string("="), ws, stringLiteral), parjsCombinators.map(([left, , , , right]) => ({
|
|
59
|
-
astKind: "EqualsPredicate",
|
|
60
|
-
left,
|
|
61
|
-
right
|
|
62
|
-
})));
|
|
63
|
-
var whereClause = keyword("WHERE").pipe(parjsCombinators.then(ws, equalsPredicate.pipe(parjsCombinators.between(ws, ws), parjsCombinators.manySepBy(parjs.string("AND"))), ws), parjsCombinators.map(([, , predicates]) => ({
|
|
64
|
-
astKind: "WhereClause",
|
|
65
|
-
predicates
|
|
66
|
-
})));
|
|
67
|
-
var returnClause = keyword("RETURN").pipe(parjsCombinators.then(ws, memberExpression.pipe(parjsCombinators.then(optional(parjs.string("AS").pipe(parjsCombinators.between(ws), parjsCombinators.then(identifier))), ws), parjsCombinators.manySepBy(parjs.string(",").pipe(parjsCombinators.then(ws)))), ws), parjsCombinators.map(([, , fields]) => ({
|
|
68
|
-
astKind: "ReturnClause",
|
|
69
|
-
fields: fields.map(([f]) => f)
|
|
70
|
-
})));
|
|
71
|
-
var cypherQuery = ws.pipe(parjsCombinators.then(matchClause, ws, optional(whereClause), ws, returnClause, ws), parjsCombinators.map(([, matchClause2, , whereClause2, , returnClause2]) => ({
|
|
72
|
-
astKind: "CypherQuery",
|
|
73
|
-
matchClause: matchClause2,
|
|
74
|
-
whereClause: whereClause2,
|
|
75
|
-
returnClause: returnClause2
|
|
76
|
-
})));
|
|
77
|
-
|
|
78
|
-
// packages/experimental/assistant/src/cypher/parser.ts
|
|
79
|
-
var parseCypherQuery = (query) => {
|
|
80
|
-
const parseResult = cypherQuery.parse(query);
|
|
81
|
-
if (parseResult.isOk) {
|
|
82
|
-
return {
|
|
83
|
-
ast: parseResult.value
|
|
84
|
-
};
|
|
85
|
-
} else {
|
|
86
|
-
throw new Error(`Failed to parse query: ${parseResult}`);
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
// packages/experimental/assistant/src/cypher/query-executor.ts
|
|
91
|
-
import { log as log2 } from "@dxos/log";
|
|
92
|
-
import { mapValues } from "@dxos/util";
|
|
93
|
-
|
|
94
|
-
// packages/experimental/assistant/src/cypher/execution-plan.ts
|
|
95
|
-
import { invariant } from "@dxos/invariant";
|
|
96
|
-
import { log } from "@dxos/log";
|
|
97
|
-
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/experimental/assistant/src/cypher/execution-plan.ts";
|
|
98
|
-
var createExecutionPlan = (query) => {
|
|
99
|
-
return new ExecutionPlanBuilder().build(query);
|
|
100
|
-
};
|
|
101
|
-
var ExecutionPlanBuilder = class {
|
|
102
|
-
constructor() {
|
|
103
|
-
this.counter = 0;
|
|
104
|
-
}
|
|
105
|
-
newVariable() {
|
|
106
|
-
return `anon_${this.counter++}`;
|
|
107
|
-
}
|
|
108
|
-
build(query) {
|
|
109
|
-
log("Creating execution plan for query", {
|
|
110
|
-
query
|
|
111
|
-
}, {
|
|
112
|
-
F: __dxlog_file,
|
|
113
|
-
L: 76,
|
|
114
|
-
S: this,
|
|
115
|
-
C: (f, a) => f(...a)
|
|
116
|
-
});
|
|
117
|
-
return {
|
|
118
|
-
steps: [
|
|
119
|
-
...this.createStepsForMatchClause(query.ast.matchClause),
|
|
120
|
-
...query.ast.whereClause ? this.createStepsForWhereClause(query.ast.whereClause) : [],
|
|
121
|
-
...this.createStepsForReturnClause(query.ast.returnClause)
|
|
122
|
-
],
|
|
123
|
-
output: {
|
|
124
|
-
fields: this.getOutputFields(query.ast.returnClause)
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
createStepsForMatchClause(match) {
|
|
129
|
-
invariant(match.pattern.segments.length > 0, void 0, {
|
|
130
|
-
F: __dxlog_file,
|
|
131
|
-
L: 90,
|
|
132
|
-
S: this,
|
|
133
|
-
A: [
|
|
134
|
-
"match.pattern.segments.length > 0",
|
|
135
|
-
""
|
|
136
|
-
]
|
|
137
|
-
});
|
|
138
|
-
const firstSegment = match.pattern.segments[0];
|
|
139
|
-
invariant(firstSegment.astKind === "NodePattern", void 0, {
|
|
140
|
-
F: __dxlog_file,
|
|
141
|
-
L: 92,
|
|
142
|
-
S: this,
|
|
143
|
-
A: [
|
|
144
|
-
"firstSegment.astKind === 'NodePattern'",
|
|
145
|
-
""
|
|
146
|
-
]
|
|
147
|
-
});
|
|
148
|
-
let lastNodeVariable = firstSegment.variable?.name ?? this.newVariable();
|
|
149
|
-
const steps = [];
|
|
150
|
-
steps.push({
|
|
151
|
-
type: "NodeScan",
|
|
152
|
-
label: firstSegment.label.name,
|
|
153
|
-
into: lastNodeVariable
|
|
154
|
-
});
|
|
155
|
-
if (firstSegment.properties) {
|
|
156
|
-
for (const property2 of firstSegment.properties.properties) {
|
|
157
|
-
steps.push({
|
|
158
|
-
type: "FilterByProperty",
|
|
159
|
-
variable: lastNodeVariable,
|
|
160
|
-
property: property2.key.name,
|
|
161
|
-
value: property2.value.value
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
for (let i = 1; i < match.pattern.segments.length; i++) {
|
|
166
|
-
const relationshipSegment = match.pattern.segments[i++];
|
|
167
|
-
invariant(relationshipSegment.astKind === "RelationshipPattern", void 0, {
|
|
168
|
-
F: __dxlog_file,
|
|
169
|
-
L: 115,
|
|
170
|
-
S: this,
|
|
171
|
-
A: [
|
|
172
|
-
"relationshipSegment.astKind === 'RelationshipPattern'",
|
|
173
|
-
""
|
|
174
|
-
]
|
|
175
|
-
});
|
|
176
|
-
const nodeSegment = match.pattern.segments[i];
|
|
177
|
-
invariant(nodeSegment.astKind === "NodePattern", void 0, {
|
|
178
|
-
F: __dxlog_file,
|
|
179
|
-
L: 117,
|
|
180
|
-
S: this,
|
|
181
|
-
A: [
|
|
182
|
-
"nodeSegment.astKind === 'NodePattern'",
|
|
183
|
-
""
|
|
184
|
-
]
|
|
185
|
-
});
|
|
186
|
-
const leftSeparator = match.pattern.segments.separators[i - 2];
|
|
187
|
-
const rightSeparator = match.pattern.segments.separators[i - 1];
|
|
188
|
-
const direction = getDirection(leftSeparator.direction, rightSeparator.direction);
|
|
189
|
-
const relationshipVariable = relationshipSegment.variable?.name ?? this.newVariable();
|
|
190
|
-
const nodeVariable = nodeSegment.variable?.name ?? this.newVariable();
|
|
191
|
-
steps.push({
|
|
192
|
-
type: "RelationshipScan",
|
|
193
|
-
label: relationshipSegment.label.name,
|
|
194
|
-
direction,
|
|
195
|
-
anchor: lastNodeVariable,
|
|
196
|
-
relationshipInto: relationshipVariable,
|
|
197
|
-
nodeInto: nodeVariable
|
|
198
|
-
});
|
|
199
|
-
if (relationshipSegment.properties) {
|
|
200
|
-
for (const property2 of relationshipSegment.properties.properties) {
|
|
201
|
-
steps.push({
|
|
202
|
-
type: "FilterByProperty",
|
|
203
|
-
variable: relationshipVariable,
|
|
204
|
-
property: property2.key.name,
|
|
205
|
-
value: property2.value.value
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
if (nodeSegment.label) {
|
|
210
|
-
steps.push({
|
|
211
|
-
type: "FilterByLabel",
|
|
212
|
-
variable: nodeVariable,
|
|
213
|
-
label: nodeSegment.label.name
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
if (nodeSegment.properties) {
|
|
217
|
-
for (const property2 of nodeSegment.properties.properties) {
|
|
218
|
-
steps.push({
|
|
219
|
-
type: "FilterByProperty",
|
|
220
|
-
variable: nodeVariable,
|
|
221
|
-
property: property2.key.name,
|
|
222
|
-
value: property2.value.value
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
lastNodeVariable = nodeVariable;
|
|
227
|
-
}
|
|
228
|
-
return steps;
|
|
229
|
-
}
|
|
230
|
-
createStepsForWhereClause(where) {
|
|
231
|
-
return [];
|
|
232
|
-
}
|
|
233
|
-
createStepsForReturnClause(returnClause2) {
|
|
234
|
-
return [
|
|
235
|
-
{
|
|
236
|
-
type: "ProduceResults",
|
|
237
|
-
fields: returnClause2.fields.map((field) => ({
|
|
238
|
-
name: field.path.map((p) => p.name).join("_"),
|
|
239
|
-
variable: field.path[0].name,
|
|
240
|
-
path: field.path.length > 1 ? field.path.slice(1).map((p) => p.name).join(".") : "$"
|
|
241
|
-
}))
|
|
242
|
-
}
|
|
243
|
-
];
|
|
244
|
-
}
|
|
245
|
-
getOutputFields(returnClause2) {
|
|
246
|
-
return returnClause2.fields.map((field) => field.path.map((p) => p.name).join("_"));
|
|
247
|
-
}
|
|
248
|
-
};
|
|
249
|
-
var getDirection = (left, right) => {
|
|
250
|
-
if (left === "-" && right === "->") {
|
|
251
|
-
return "out";
|
|
252
|
-
} else if (left === "<-" && right === "-") {
|
|
253
|
-
return "in";
|
|
254
|
-
} else if (left === "-" && right === "-") {
|
|
255
|
-
return "both";
|
|
256
|
-
}
|
|
257
|
-
throw new Error(`Invalid direction: ()${left}[]${right}()`);
|
|
258
|
-
};
|
|
259
|
-
|
|
260
|
-
// packages/experimental/assistant/src/cypher/query-executor.ts
|
|
261
|
-
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/experimental/assistant/src/cypher/query-executor.ts";
|
|
262
|
-
var executeQueryPlan = async (dataSource, plan) => {
|
|
263
|
-
let buffer = [];
|
|
264
|
-
const results = [];
|
|
265
|
-
for (const step of plan.steps) {
|
|
266
|
-
log2("begin step", {
|
|
267
|
-
step
|
|
268
|
-
}, {
|
|
269
|
-
F: __dxlog_file2,
|
|
270
|
-
L: 41,
|
|
271
|
-
S: void 0,
|
|
272
|
-
C: (f, a) => f(...a)
|
|
273
|
-
});
|
|
274
|
-
switch (step.type) {
|
|
275
|
-
case "NodeScan": {
|
|
276
|
-
const nodes = await dataSource.getNodes({
|
|
277
|
-
label: step.label
|
|
278
|
-
});
|
|
279
|
-
buffer.push(...nodes.map((node) => ({
|
|
280
|
-
[step.into]: node
|
|
281
|
-
})));
|
|
282
|
-
break;
|
|
283
|
-
}
|
|
284
|
-
case "FilterByLabel": {
|
|
285
|
-
buffer = buffer.filter((item) => {
|
|
286
|
-
const node = item[step.variable];
|
|
287
|
-
return node && node.kind === "node" && node.label === step.label;
|
|
288
|
-
});
|
|
289
|
-
break;
|
|
290
|
-
}
|
|
291
|
-
case "FilterByProperty": {
|
|
292
|
-
buffer = buffer.filter((item) => {
|
|
293
|
-
const node = item[step.variable];
|
|
294
|
-
return node && node.kind === "node" && node.properties[step.property] === step.value;
|
|
295
|
-
});
|
|
296
|
-
break;
|
|
297
|
-
}
|
|
298
|
-
case "RelationshipScan": {
|
|
299
|
-
const relationships = await dataSource.getRelationships({
|
|
300
|
-
label: step.label
|
|
301
|
-
});
|
|
302
|
-
for (const tuple of [
|
|
303
|
-
...buffer
|
|
304
|
-
]) {
|
|
305
|
-
if (tuple[step.anchor].kind !== "node") {
|
|
306
|
-
continue;
|
|
307
|
-
}
|
|
308
|
-
const filteredRelationships = relationships.filter((relationship) => {
|
|
309
|
-
switch (step.direction) {
|
|
310
|
-
case "in":
|
|
311
|
-
return relationship.target.id === tuple[step.anchor].id;
|
|
312
|
-
case "out":
|
|
313
|
-
return relationship.source.id === tuple[step.anchor].id;
|
|
314
|
-
case "both":
|
|
315
|
-
return relationship.source.id === tuple[step.anchor].id || relationship.target.id === tuple[step.anchor].id;
|
|
316
|
-
default:
|
|
317
|
-
throw new Error(`Unknown direction: ${step.direction}`);
|
|
318
|
-
}
|
|
319
|
-
});
|
|
320
|
-
for (let i = 0; i < filteredRelationships.length; i++) {
|
|
321
|
-
const relationship = filteredRelationships[i];
|
|
322
|
-
const newTuple = i === 0 ? tuple : {
|
|
323
|
-
...tuple
|
|
324
|
-
};
|
|
325
|
-
if (newTuple !== tuple) {
|
|
326
|
-
buffer.push(newTuple);
|
|
327
|
-
}
|
|
328
|
-
newTuple[step.relationshipInto] = relationship;
|
|
329
|
-
switch (step.direction) {
|
|
330
|
-
case "in":
|
|
331
|
-
newTuple[step.nodeInto] = relationship.source;
|
|
332
|
-
break;
|
|
333
|
-
case "out":
|
|
334
|
-
newTuple[step.nodeInto] = relationship.target;
|
|
335
|
-
break;
|
|
336
|
-
case "both":
|
|
337
|
-
newTuple[step.nodeInto] = relationship.source.id === newTuple[step.anchor].id ? relationship.target : relationship.source;
|
|
338
|
-
break;
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
break;
|
|
343
|
-
}
|
|
344
|
-
case "ProduceResults": {
|
|
345
|
-
for (const tuple of buffer) {
|
|
346
|
-
const result = {};
|
|
347
|
-
for (const field of step.fields) {
|
|
348
|
-
result[field.name] = jsonPathGet(tuple[field.variable].properties, field.path);
|
|
349
|
-
}
|
|
350
|
-
results.push(result);
|
|
351
|
-
}
|
|
352
|
-
break;
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
log2("finish step", {
|
|
356
|
-
buffer: buffer.map((tuple) => mapValues(tuple, (x) => x.id)),
|
|
357
|
-
results
|
|
358
|
-
}, {
|
|
359
|
-
F: __dxlog_file2,
|
|
360
|
-
L: 118,
|
|
361
|
-
S: void 0,
|
|
362
|
-
C: (f, a) => f(...a)
|
|
363
|
-
});
|
|
364
|
-
}
|
|
365
|
-
return results;
|
|
366
|
-
};
|
|
367
|
-
var executeQuery = (dataSource, query) => {
|
|
368
|
-
const plan = createExecutionPlan(parseCypherQuery(query));
|
|
369
|
-
return executeQueryPlan(dataSource, plan);
|
|
370
|
-
};
|
|
371
|
-
var jsonPathGet = (obj, path) => {
|
|
372
|
-
if (path === "" || path === "$") {
|
|
373
|
-
return obj;
|
|
374
|
-
}
|
|
375
|
-
const parts = path.split(".");
|
|
376
|
-
if (parts[0] === "$") {
|
|
377
|
-
parts.shift();
|
|
378
|
-
}
|
|
379
|
-
let result = obj;
|
|
380
|
-
for (const part of parts) {
|
|
381
|
-
result = result?.[part];
|
|
382
|
-
}
|
|
383
|
-
return result;
|
|
384
|
-
};
|
|
385
|
-
|
|
386
|
-
// packages/experimental/assistant/src/cypher/schema.ts
|
|
387
|
-
import { raise } from "@dxos/debug";
|
|
388
|
-
import { JSON_SCHEMA_ECHO_REF_ID } from "@dxos/echo-schema";
|
|
389
|
-
|
|
390
|
-
// packages/experimental/assistant/src/util/trim.ts
|
|
391
|
-
var trim = (strings, ...values) => {
|
|
392
|
-
const combined = strings.reduce((acc, str, i) => {
|
|
393
|
-
return acc + str + (values[i] || "");
|
|
394
|
-
}, "");
|
|
395
|
-
return combined.replace("/^\n/", "").replace(/\n$/, "");
|
|
396
|
-
};
|
|
397
|
-
|
|
398
|
-
// packages/experimental/assistant/src/cypher/schema.ts
|
|
399
|
-
var formatJsonSchemaForLLM = (schemaTypes) => {
|
|
400
|
-
return schemaTypes.flatMap((schema) => [
|
|
401
|
-
formatNodeSchema(schema),
|
|
402
|
-
...formatInferredRelationships(schema, schemaTypes)
|
|
403
|
-
]);
|
|
404
|
-
};
|
|
405
|
-
var formatNodeSchema = (schema) => {
|
|
406
|
-
const label2 = formatNodeLabel(schema.typename ?? raise(new Error("Schema must have $id")));
|
|
407
|
-
const properties2 = Object.entries(schema.properties).filter(([key, prop]) => key !== "id" && !isReference(prop));
|
|
408
|
-
return trim`
|
|
409
|
-
<node>
|
|
410
|
-
(:${label2})
|
|
411
|
-
|
|
412
|
-
<description>${schema.description}</description>
|
|
413
|
-
|
|
414
|
-
<properties>
|
|
415
|
-
${properties2.map(([key, value]) => {
|
|
416
|
-
return trim`
|
|
417
|
-
<${key}>
|
|
418
|
-
<type>${value.type}</type>
|
|
419
|
-
<description>${value.description}</description>
|
|
420
|
-
</${key}>
|
|
421
|
-
`;
|
|
422
|
-
})}
|
|
423
|
-
</properties>
|
|
424
|
-
</node>
|
|
425
|
-
`;
|
|
426
|
-
};
|
|
427
|
-
var formatInferredRelationships = (schema, allSchema) => {
|
|
428
|
-
const nodeLabel = formatNodeLabel(schema.typename ?? raise(new Error("Schema must have $id")));
|
|
429
|
-
const relationships = Object.entries(schema.properties).filter(([key, prop]) => isReference(prop));
|
|
430
|
-
return relationships.map(([key, value]) => {
|
|
431
|
-
const relationshipLabel = formatInferredRelationshipLabel(schema.typename ?? raise(new Error("Schema must have $id")), key);
|
|
432
|
-
const targetSchema = allSchema.find((schema2) => `dxn:type/${schema2.typename}` === value.reference?.schema.$ref);
|
|
433
|
-
const targetLabel = targetSchema ? formatNodeLabel(targetSchema?.typename ?? "") : "";
|
|
434
|
-
return trim`
|
|
435
|
-
<relationship>
|
|
436
|
-
(:${nodeLabel})-[:${relationshipLabel}]->(:${targetLabel})
|
|
437
|
-
|
|
438
|
-
<description>${value.description}</description>
|
|
439
|
-
</relationship>
|
|
440
|
-
`;
|
|
441
|
-
});
|
|
442
|
-
};
|
|
443
|
-
var formatNodeLabel = (typename) => {
|
|
444
|
-
return typename.replace(/^example\.com\/type\//g, "");
|
|
445
|
-
};
|
|
446
|
-
var formatInferredRelationshipLabel = (typename, property2) => {
|
|
447
|
-
const nodeLabel = formatNodeLabel(typename);
|
|
448
|
-
return `${nodeLabel}_${property2}`.toUpperCase();
|
|
449
|
-
};
|
|
450
|
-
var isReference = (schema) => schema.$id === JSON_SCHEMA_ECHO_REF_ID || schema.type === "array" && !Array.isArray(schema.items) && typeof schema.items === "object" && "$id" in schema.items && schema.items.$id === JSON_SCHEMA_ECHO_REF_ID;
|
|
451
|
-
|
|
452
|
-
// packages/experimental/assistant/src/cypher/echo-data-source.ts
|
|
453
|
-
import { raise as raise2 } from "@dxos/debug";
|
|
454
|
-
import { Filter } from "@dxos/echo-db";
|
|
455
|
-
import { getSchemaTypename, StoredSchema, toJsonSchema } from "@dxos/echo-schema";
|
|
456
|
-
import { getSchema } from "@dxos/live-object";
|
|
457
|
-
import { log as log3 } from "@dxos/log";
|
|
458
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
459
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
460
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
461
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
462
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
463
|
-
}
|
|
464
|
-
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/experimental/assistant/src/cypher/echo-data-source.ts";
|
|
465
|
-
var EchoDataSource = class {
|
|
466
|
-
constructor(_db) {
|
|
467
|
-
this._db = _db;
|
|
468
|
-
}
|
|
469
|
-
async getNodes({ label: label2 }) {
|
|
470
|
-
if (!label2) {
|
|
471
|
-
const { objects: objects2 } = await this._db.query().run();
|
|
472
|
-
return objects2.map(this._objectToNode);
|
|
473
|
-
}
|
|
474
|
-
const schema = (await this._getAllSchema()).find((s) => getSchemaTypename(s)?.endsWith(label2));
|
|
475
|
-
if (!schema) {
|
|
476
|
-
return [];
|
|
477
|
-
}
|
|
478
|
-
const { objects } = await this._db.query(Filter.schema(schema)).run();
|
|
479
|
-
return objects.map(this._objectToNode);
|
|
480
|
-
}
|
|
481
|
-
async getRelationships({ label: label2 }) {
|
|
482
|
-
const syntheticRefRelationships = (await this._getAllSchema()).filter((schema) => getSchemaTypename(schema) !== StoredSchema.typename).flatMap((schema) => {
|
|
483
|
-
const jsonSchema = toJsonSchema(schema);
|
|
484
|
-
const relationships = Object.entries(jsonSchema.properties).filter(([key, prop]) => isReference(prop));
|
|
485
|
-
return relationships.map(([key, value]) => {
|
|
486
|
-
const relationshipLabel = formatInferredRelationshipLabel(jsonSchema.typename ?? raise2(new Error("Schema must have typename")), key);
|
|
487
|
-
return {
|
|
488
|
-
label: relationshipLabel,
|
|
489
|
-
schema,
|
|
490
|
-
property: key
|
|
491
|
-
};
|
|
492
|
-
});
|
|
493
|
-
});
|
|
494
|
-
const relationship = syntheticRefRelationships.find((r) => r.label === label2);
|
|
495
|
-
if (!relationship) {
|
|
496
|
-
return [];
|
|
497
|
-
}
|
|
498
|
-
const { objects } = await this._db.query(Filter.schema(relationship.schema)).run();
|
|
499
|
-
return (await Promise.all(objects.map((object) => this._projectRefRelationship(object, relationship.property)))).flat();
|
|
500
|
-
}
|
|
501
|
-
async _getAllSchema() {
|
|
502
|
-
return [
|
|
503
|
-
...await this._db.schemaRegistry.query().run(),
|
|
504
|
-
// TODO(dmaretskyi): Remove once we can serialize recursive schema.
|
|
505
|
-
...this._db.graph.schemaRegistry.schemas.filter((s) => getSchemaTypename(s)?.startsWith("example.org"))
|
|
506
|
-
].filter((schema) => getSchemaTypename(schema) !== StoredSchema.typename);
|
|
507
|
-
}
|
|
508
|
-
_objectToNode(object) {
|
|
509
|
-
const { id, ...properties2 } = object;
|
|
510
|
-
return {
|
|
511
|
-
id,
|
|
512
|
-
kind: "node",
|
|
513
|
-
label: formatNodeLabel(getSchemaTypename(getSchema(object))),
|
|
514
|
-
properties: properties2
|
|
515
|
-
};
|
|
516
|
-
}
|
|
517
|
-
async _projectRefRelationship(object, prop) {
|
|
518
|
-
if (!object[prop]) {
|
|
519
|
-
return [];
|
|
520
|
-
}
|
|
521
|
-
const value = Array.isArray(object[prop]) ? object[prop] : [
|
|
522
|
-
object[prop]
|
|
523
|
-
];
|
|
524
|
-
return Promise.all(value.map(async (ref) => {
|
|
525
|
-
const target = await ref.load();
|
|
526
|
-
return {
|
|
527
|
-
id: `${object.id}-${prop}-${target.id}`,
|
|
528
|
-
kind: "relationship",
|
|
529
|
-
label: formatInferredRelationshipLabel(getSchemaTypename(getSchema(object)), prop),
|
|
530
|
-
properties: {},
|
|
531
|
-
source: this._objectToNode(object),
|
|
532
|
-
target: this._objectToNode(target)
|
|
533
|
-
};
|
|
534
|
-
}));
|
|
535
|
-
}
|
|
536
|
-
};
|
|
537
|
-
_ts_decorate([
|
|
538
|
-
log3.method(void 0, void 0, {
|
|
539
|
-
F: __dxlog_file3,
|
|
540
|
-
L: 17,
|
|
541
|
-
S: void 0,
|
|
542
|
-
C: (f, a) => f(...a)
|
|
543
|
-
})
|
|
544
|
-
], EchoDataSource.prototype, "getNodes", null);
|
|
545
|
-
_ts_decorate([
|
|
546
|
-
log3.method(void 0, void 0, {
|
|
547
|
-
F: __dxlog_file3,
|
|
548
|
-
L: 34,
|
|
549
|
-
S: void 0,
|
|
550
|
-
C: (f, a) => f(...a)
|
|
551
|
-
})
|
|
552
|
-
], EchoDataSource.prototype, "getRelationships", null);
|
|
553
|
-
|
|
554
|
-
export {
|
|
555
|
-
parseCypherQuery,
|
|
556
|
-
executeQueryPlan,
|
|
557
|
-
executeQuery,
|
|
558
|
-
trim,
|
|
559
|
-
formatJsonSchemaForLLM,
|
|
560
|
-
formatNodeLabel,
|
|
561
|
-
formatInferredRelationshipLabel,
|
|
562
|
-
isReference,
|
|
563
|
-
EchoDataSource
|
|
564
|
-
};
|
|
565
|
-
//# sourceMappingURL=chunk-AXUUNA7O.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/cypher/parjs.ts", "../../../src/cypher/combinators.ts", "../../../src/cypher/parser.ts", "../../../src/cypher/query-executor.ts", "../../../src/cypher/execution-plan.ts", "../../../src/cypher/schema.ts", "../../../src/util/trim.ts", "../../../src/cypher/echo-data-source.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\n// Workaround for https://github.com/vitest-dev/vitest/issues/7174.\nimport type { Parjser } from 'parjs';\n\nimport { parjsCombinators, parjs } from '#parjs';\n\nexport { type Parjser, parjsCombinators, parjs };\n", "//\n// Copyright 2024 DXOS.org\n//\n\n/* eslint-disable unused-imports/no-unused-vars */\n/* eslint-disable @typescript-eslint/consistent-type-imports */\n\nimport type {\n CypherQuery,\n EqualsPredicate,\n GraphPattern,\n GraphPatternConnector,\n Identifier,\n MatchClause,\n MemberExpression,\n NodePattern,\n Properties,\n Property,\n RelationshipPattern,\n ReturnClause,\n StringLiteral,\n WhereClause,\n} from './ast';\nimport { Parjser, parjs, parjsCombinators } from './parjs';\n\n// Helper parsers\nconst ws = parjs.whitespace(); // Parses whitespace\n\nconst nothing = parjs.string('').pipe(parjsCombinators.map(() => null)); // Parses nothing\n\nconst optional = <T>(parser: Parjser<T>) =>\n parser.pipe(\n parjsCombinators.recover(() => ({ kind: 'Soft' })),\n parjsCombinators.or(nothing),\n ); // Makes a parser optional\n\nconst keyword = (word: string) => parjs.string(word).pipe(parjsCombinators.map(() => word)); // Parses specific keywords\n\n// Identifiers (node labels, relationship types, variables, etc.)\nexport const identifier = parjs.regexp(/[a-zA-Z_][a-zA-Z0-9_]*/).pipe(\n parjsCombinators.map((match): Identifier => ({ astKind: 'Identifier', name: match[0] })), // Extract the matched string\n);\n\n// Literals (numbers and strings)\nconst numberLiteral = parjs.regexp(/-?\\d+(\\.\\d+)?/).pipe(parjsCombinators.map(Number)); // Numbers\nconst stringLiteral = parjs.regexp(/\"([^\"]*)\"|'([^']*)'/).pipe(\n parjsCombinators.map((match): StringLiteral => ({ astKind: 'StringLiteral', value: match[1] || match[2] })), // Extract content without quotes\n);\n\n// Node pattern (e.g., \"(n:Person {name: 'John'})\"\nconst variableTag = identifier.pipe(parjsCombinators.map((variable) => variable)).expects('variable tag');\nexport const label = identifier.pipe(parjsCombinators.map((name) => name));\nexport const property = identifier.pipe(\n parjsCombinators.then(parjs.string(':'), ws, stringLiteral),\n parjsCombinators.map(([key, , , value]): Property => ({ key, value })),\n);\nexport const properties = property.pipe(\n parjsCombinators.manySepBy(','),\n parjsCombinators.between('{', '}'),\n parjsCombinators.map((properties): Properties => ({ astKind: 'Properties', properties })),\n);\nexport const nodePattern = optional(variableTag).pipe(\n parjsCombinators.then(':'),\n parjsCombinators.then(ws, label, ws),\n parjsCombinators.then(optional(properties)),\n parjsCombinators.between('(', ')'),\n parjsCombinators.map(\n ([[[variable], _, label], properties]): NodePattern => ({ astKind: 'NodePattern', variable, label, properties }),\n ),\n);\n\nexport const relationshipPattern = optional(variableTag).pipe(\n parjsCombinators.then(':'),\n parjsCombinators.then(ws, label, ws),\n parjsCombinators.then(optional(properties)),\n parjsCombinators.between('[', ']'),\n parjsCombinators.map(\n ([[[variable], _, label], properties]): RelationshipPattern => ({\n astKind: 'RelationshipPattern',\n variable,\n label,\n properties,\n }),\n ),\n);\n\nconst graphPatternConnector = parjs.string('->').pipe(\n parjsCombinators.or('<-' as const, '-' as const),\n parjsCombinators.map((x): GraphPatternConnector => ({ astKind: 'GraphPatternConnector', direction: x })),\n);\n\nexport const graphPattern = nodePattern.pipe(\n parjsCombinators.or(relationshipPattern),\n parjsCombinators.manySepBy(graphPatternConnector),\n parjsCombinators.map((segments): GraphPattern => ({ astKind: 'GraphPattern', segments })),\n);\n\nexport const matchClause = keyword('MATCH').pipe(\n parjsCombinators.then(ws),\n parjsCombinators.then(graphPattern),\n parjsCombinators.map(([, pattern]): MatchClause => ({ astKind: 'MatchClause', pattern })),\n);\n\nconst memberExpression = identifier.pipe(\n parjsCombinators.manySepBy('.'),\n parjsCombinators.map((path): MemberExpression => ({ astKind: 'MemberExpression', path })),\n);\n\nconst equalsPredicate = memberExpression.pipe(\n parjsCombinators.then(ws, parjs.string('='), ws, stringLiteral),\n parjsCombinators.map(([left, , , , right]): EqualsPredicate => ({ astKind: 'EqualsPredicate', left, right })),\n);\n\nexport const whereClause = keyword('WHERE').pipe(\n parjsCombinators.then(\n ws,\n equalsPredicate.pipe(parjsCombinators.between(ws, ws), parjsCombinators.manySepBy(parjs.string('AND'))),\n ws,\n ),\n parjsCombinators.map(([, , predicates]): WhereClause => ({ astKind: 'WhereClause', predicates })),\n);\n\nexport const returnClause = keyword('RETURN').pipe(\n parjsCombinators.then(\n ws,\n memberExpression.pipe(\n parjsCombinators.then(\n optional(parjs.string('AS').pipe(parjsCombinators.between(ws), parjsCombinators.then(identifier))),\n ws,\n ),\n parjsCombinators.manySepBy(parjs.string(',').pipe(parjsCombinators.then(ws))),\n ),\n ws,\n ),\n parjsCombinators.map(([, , fields]): ReturnClause => ({ astKind: 'ReturnClause', fields: fields.map(([f]) => f) })),\n);\n\nexport const cypherQuery = ws.pipe(\n parjsCombinators.then(matchClause, ws, optional(whereClause), ws, returnClause, ws),\n parjsCombinators.map(\n ([, matchClause, , whereClause, , returnClause]): CypherQuery => ({\n astKind: 'CypherQuery',\n matchClause,\n whereClause,\n returnClause,\n }),\n ),\n);\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport type { CypherQuery } from './ast';\nimport { cypherQuery } from './combinators';\n\nexport type ParsedQuery = {\n ast: CypherQuery;\n};\n\nexport const parseCypherQuery = (query: string): ParsedQuery => {\n const parseResult = cypherQuery.parse(query);\n if (parseResult.isOk) {\n return { ast: parseResult.value };\n } else {\n throw new Error(`Failed to parse query: ${parseResult}`);\n }\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport type { JsonPath } from '@dxos/echo-schema';\nimport { log } from '@dxos/log';\nimport { mapValues } from '@dxos/util';\n\nimport { createExecutionPlan, type ExecutionPlan, type VariableName } from './execution-plan';\nimport { parseCypherQuery } from './parser';\n\nexport interface DataSource {\n getNodes: (params: { label?: string }) => Promise<Node[]>;\n getRelationships: (params: { label?: string }) => Promise<Relationship[]>;\n}\n\nexport type Node = {\n id: string;\n kind: 'node';\n label: string;\n properties: Record<string, unknown>;\n};\n\nexport type Relationship = {\n id: string;\n kind: 'relationship';\n label: string;\n properties: Record<string, unknown>;\n source: Node;\n target: Node;\n};\n\nexport const executeQueryPlan = async (\n dataSource: DataSource,\n plan: ExecutionPlan,\n): Promise<Record<string, unknown>[]> => {\n let buffer: Record<VariableName, Node | Relationship>[] = [];\n const results: Record<string, unknown>[] = [];\n\n for (const step of plan.steps) {\n log('begin step', { step });\n\n switch (step.type) {\n case 'NodeScan': {\n const nodes = await dataSource.getNodes({ label: step.label });\n buffer.push(...nodes.map((node) => ({ [step.into]: node })));\n break;\n }\n case 'FilterByLabel': {\n buffer = buffer.filter((item) => {\n const node = item[step.variable];\n return node && node.kind === 'node' && node.label === step.label;\n });\n break;\n }\n case 'FilterByProperty': {\n buffer = buffer.filter((item) => {\n const node = item[step.variable];\n return node && node.kind === 'node' && node.properties[step.property] === step.value;\n });\n break;\n }\n case 'RelationshipScan': {\n const relationships = await dataSource.getRelationships({ label: step.label });\n for (const tuple of [...buffer]) {\n if (tuple[step.anchor].kind !== 'node') {\n continue;\n }\n const filteredRelationships = relationships.filter((relationship) => {\n switch (step.direction) {\n case 'in':\n return relationship.target.id === tuple[step.anchor].id;\n case 'out':\n return relationship.source.id === tuple[step.anchor].id;\n case 'both':\n return (\n relationship.source.id === tuple[step.anchor].id || relationship.target.id === tuple[step.anchor].id\n );\n default:\n throw new Error(`Unknown direction: ${step.direction}`);\n }\n });\n for (let i = 0; i < filteredRelationships.length; i++) {\n const relationship = filteredRelationships[i];\n const newTuple = i === 0 ? tuple : { ...tuple };\n if (newTuple !== tuple) {\n buffer.push(newTuple);\n }\n newTuple[step.relationshipInto] = relationship;\n switch (step.direction) {\n case 'in':\n newTuple[step.nodeInto] = relationship.source;\n break;\n case 'out':\n newTuple[step.nodeInto] = relationship.target;\n break;\n case 'both':\n newTuple[step.nodeInto] =\n relationship.source.id === newTuple[step.anchor].id ? relationship.target : relationship.source;\n break;\n }\n }\n }\n break;\n }\n case 'ProduceResults': {\n for (const tuple of buffer) {\n const result: Record<string, unknown> = {};\n for (const field of step.fields) {\n result[field.name] = jsonPathGet(tuple[field.variable].properties, field.path);\n }\n results.push(result);\n }\n break;\n }\n }\n\n log('finish step', { buffer: buffer.map((tuple) => mapValues(tuple, (x) => x.id)), results });\n }\n\n return results;\n};\n\nexport const executeQuery = (dataSource: DataSource, query: string): Promise<Record<string, unknown>[]> => {\n const plan = createExecutionPlan(parseCypherQuery(query));\n return executeQueryPlan(dataSource, plan);\n};\n\n// TODO(dmaretskyi): Extract.\nconst jsonPathGet = (obj: Record<string, unknown>, path: JsonPath): unknown => {\n if (path === '' || path === '$') {\n return obj;\n }\n\n const parts = path.split('.');\n if (parts[0] === '$') {\n parts.shift();\n }\n\n let result: any = obj;\n for (const part of parts) {\n result = result?.[part];\n }\n return result;\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport type { JsonPath } from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\n\nimport type { GraphPatternConnector, MatchClause, ReturnClause, WhereClause } from './ast';\nimport type { ParsedQuery } from './parser';\n\nexport type VariableName = string & { __VariableName: never };\n\nexport type ExecutionPlanStep =\n | {\n type: 'NodeScan';\n label: string;\n into: VariableName;\n }\n | {\n type: 'FilterByLabel';\n variable: VariableName;\n label: string;\n }\n | {\n type: 'FilterByProperty';\n variable: VariableName;\n property: JsonPath;\n value: unknown;\n }\n | {\n /**\n * Scans (anchor)-[relationshipInto:label]->(nodeInto).\n */\n type: 'RelationshipScan';\n label: string;\n anchor: VariableName;\n relationshipInto: VariableName;\n nodeInto: VariableName;\n\n /**\n * `in`: (anchor)<-[relationshipInto:label]-(nodeInto)\n * `out`: (anchor)-[relationshipInto:label]->(nodeInto)\n * `both`: (anchor)-[relationshipInto:label]-(nodeInto)\n */\n direction: 'in' | 'out' | 'both';\n }\n | {\n type: 'ProduceResults';\n fields: {\n name: string;\n variable: VariableName;\n path: JsonPath;\n }[];\n };\n\nexport type ExecutionPlan = {\n steps: ExecutionPlanStep[];\n output: {\n fields: string[];\n };\n};\n\nexport const createExecutionPlan = (query: ParsedQuery): ExecutionPlan => {\n return new ExecutionPlanBuilder().build(query);\n};\n\nclass ExecutionPlanBuilder {\n private counter = 0;\n\n newVariable(): VariableName {\n return `anon_${this.counter++}` as VariableName;\n }\n\n build(query: ParsedQuery): ExecutionPlan {\n log('Creating execution plan for query', { query });\n return {\n steps: [\n ...this.createStepsForMatchClause(query.ast.matchClause),\n ...(query.ast.whereClause ? this.createStepsForWhereClause(query.ast.whereClause) : []),\n ...this.createStepsForReturnClause(query.ast.returnClause),\n ],\n output: {\n fields: this.getOutputFields(query.ast.returnClause),\n },\n };\n }\n\n createStepsForMatchClause(match: MatchClause): ExecutionPlanStep[] {\n invariant(match.pattern.segments.length > 0);\n const firstSegment = match.pattern.segments[0];\n invariant(firstSegment.astKind === 'NodePattern');\n let lastNodeVariable = (firstSegment.variable?.name as VariableName) ?? this.newVariable();\n\n const steps: ExecutionPlanStep[] = [];\n steps.push({\n type: 'NodeScan',\n label: firstSegment.label.name,\n into: lastNodeVariable,\n });\n\n if (firstSegment.properties) {\n for (const property of firstSegment.properties.properties) {\n steps.push({\n type: 'FilterByProperty',\n variable: lastNodeVariable,\n property: property.key.name as JsonPath,\n value: property.value.value,\n });\n }\n }\n\n for (let i = 1; i < match.pattern.segments.length; i++) {\n const relationshipSegment = match.pattern.segments[i++];\n invariant(relationshipSegment.astKind === 'RelationshipPattern');\n const nodeSegment = match.pattern.segments[i];\n invariant(nodeSegment.astKind === 'NodePattern');\n const leftSeparator = match.pattern.segments.separators[i - 2];\n const rightSeparator = match.pattern.segments.separators[i - 1];\n const direction = getDirection(leftSeparator.direction, rightSeparator.direction);\n\n const relationshipVariable = (relationshipSegment.variable?.name as VariableName) ?? this.newVariable();\n const nodeVariable = (nodeSegment.variable?.name as VariableName) ?? this.newVariable();\n\n steps.push({\n type: 'RelationshipScan',\n label: relationshipSegment.label.name,\n direction,\n anchor: lastNodeVariable,\n relationshipInto: relationshipVariable,\n nodeInto: nodeVariable,\n });\n\n if (relationshipSegment.properties) {\n for (const property of relationshipSegment.properties.properties) {\n steps.push({\n type: 'FilterByProperty',\n variable: relationshipVariable,\n property: property.key.name as JsonPath,\n value: property.value.value,\n });\n }\n }\n if (nodeSegment.label) {\n steps.push({\n type: 'FilterByLabel',\n variable: nodeVariable,\n label: nodeSegment.label.name,\n });\n }\n if (nodeSegment.properties) {\n for (const property of nodeSegment.properties.properties) {\n steps.push({\n type: 'FilterByProperty',\n variable: nodeVariable,\n property: property.key.name as JsonPath,\n value: property.value.value,\n });\n }\n }\n\n lastNodeVariable = nodeVariable;\n }\n\n return steps;\n }\n\n createStepsForWhereClause(where: WhereClause): ExecutionPlanStep[] {\n return [];\n }\n\n createStepsForReturnClause(returnClause: ReturnClause): ExecutionPlanStep[] {\n return [\n {\n type: 'ProduceResults',\n fields: returnClause.fields.map((field) => ({\n name: field.path.map((p) => p.name).join('_'),\n variable: field.path[0].name as VariableName,\n path:\n field.path.length > 1\n ? (field.path\n .slice(1)\n .map((p) => p.name)\n .join('.') as JsonPath)\n : ('$' as JsonPath),\n })),\n },\n ];\n }\n\n getOutputFields(returnClause: ReturnClause): string[] {\n return returnClause.fields.map((field) => field.path.map((p) => p.name).join('_'));\n }\n}\n\nconst getDirection = (\n left: GraphPatternConnector['direction'],\n right: GraphPatternConnector['direction'],\n): 'in' | 'out' | 'both' => {\n if (left === '-' && right === '->') {\n return 'out';\n } else if (left === '<-' && right === '-') {\n return 'in';\n } else if (left === '-' && right === '-') {\n return 'both';\n }\n throw new Error(`Invalid direction: ()${left}[]${right}()`);\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { raise } from '@dxos/debug';\nimport { JSON_SCHEMA_ECHO_REF_ID, type JsonSchemaType } from '@dxos/echo-schema';\n\nimport { trim } from '../util';\n\n/**\n * Formats ECHO schema to be consumed by LLM.\n * Schema is formatted in cypher format.\n * Objects are represented as nodes.\n * References are represented as relationships.\n */\nexport const formatJsonSchemaForLLM = (schemaTypes: JsonSchemaType[]): string[] => {\n return schemaTypes.flatMap((schema) => [\n formatNodeSchema(schema),\n ...formatInferredRelationships(schema, schemaTypes),\n ]);\n};\n\nconst formatNodeSchema = (schema: JsonSchemaType) => {\n const label = formatNodeLabel(schema.typename ?? raise(new Error('Schema must have $id')));\n const properties = Object.entries(schema.properties!).filter(([key, prop]) => key !== 'id' && !isReference(prop));\n\n return trim`\n <node>\n (:${label})\n\n <description>${schema.description}</description>\n\n <properties>\n ${properties.map(([key, value]) => {\n return trim`\n <${key}>\n <type>${value.type}</type>\n <description>${value.description}</description>\n </${key}>\n `;\n })}\n </properties>\n </node>\n `;\n};\n\nconst formatInferredRelationships = (schema: JsonSchemaType, allSchema: JsonSchemaType[]): string[] => {\n const nodeLabel = formatNodeLabel(schema.typename ?? raise(new Error('Schema must have $id')));\n const relationships = Object.entries(schema.properties!).filter(([key, prop]) => isReference(prop));\n\n return relationships.map(([key, value]) => {\n const relationshipLabel = formatInferredRelationshipLabel(\n schema.typename ?? raise(new Error('Schema must have $id')),\n key,\n );\n\n // TODO(dmaretskyi): Registered schema don't get reference types updated.\n const targetSchema = allSchema.find((schema) => `dxn:type/${schema.typename}` === value.reference?.schema.$ref);\n const targetLabel = targetSchema ? formatNodeLabel(targetSchema?.typename ?? '') : '';\n\n return trim`\n <relationship>\n (:${nodeLabel})-[:${relationshipLabel}]->(:${targetLabel})\n\n <description>${value.description}</description>\n </relationship>\n `;\n });\n};\n\nexport const formatNodeLabel = (typename: string) => {\n return typename.replace(/^example\\.com\\/type\\//g, '');\n};\n\nexport const formatInferredRelationshipLabel = (typename: string, property: string) => {\n const nodeLabel = formatNodeLabel(typename);\n return `${nodeLabel}_${property}`.toUpperCase();\n};\n\nexport const isReference = (schema: JsonSchemaType) =>\n schema.$id === JSON_SCHEMA_ECHO_REF_ID ||\n (schema.type === 'array' &&\n !Array.isArray(schema.items) &&\n typeof schema.items === 'object' &&\n '$id' in schema.items &&\n schema.items.$id === JSON_SCHEMA_ECHO_REF_ID);\n", "//\n// Copyright 2024 DXOS.org\n//\n\n/**\n * Trims multiline strings.\n */\n// TODO(burdon): Move to util.\nexport const trim = (strings: TemplateStringsArray, ...values: any[]) => {\n const combined = strings.reduce((acc, str, i) => {\n return acc + str + (values[i] || '');\n }, '');\n\n return combined.replace('/^\\n/', '').replace(/\\n$/, '');\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { raise } from '@dxos/debug';\nimport { type EchoDatabase, Filter, type ReactiveEchoObject } from '@dxos/echo-db';\nimport { type S, getSchemaTypename, StoredSchema, toJsonSchema } from '@dxos/echo-schema';\nimport { getSchema } from '@dxos/live-object';\nimport { log } from '@dxos/log';\n\nimport type { DataSource, Node, Relationship } from './query-executor';\nimport { formatInferredRelationshipLabel, formatNodeLabel, isReference } from './schema';\n\nexport class EchoDataSource implements DataSource {\n constructor(private readonly _db: EchoDatabase) {}\n\n @log.method()\n async getNodes({ label }: { label?: string }): Promise<Node[]> {\n if (!label) {\n const { objects } = await this._db.query().run();\n return objects.map(this._objectToNode);\n }\n\n const schema = (await this._getAllSchema()).find((s) => getSchemaTypename(s)?.endsWith(label));\n\n if (!schema) {\n return [];\n }\n\n const { objects } = await this._db.query(Filter.schema(schema)).run();\n return objects.map(this._objectToNode);\n }\n\n @log.method()\n async getRelationships({ label }: { label?: string }): Promise<Relationship[]> {\n const syntheticRefRelationships = (await this._getAllSchema())\n .filter((schema) => getSchemaTypename(schema) !== StoredSchema.typename)\n .flatMap((schema) => {\n const jsonSchema = toJsonSchema(schema);\n const relationships = Object.entries(jsonSchema.properties!).filter(([key, prop]) => isReference(prop));\n\n return relationships.map(([key, value]) => {\n const relationshipLabel = formatInferredRelationshipLabel(\n jsonSchema.typename ?? raise(new Error('Schema must have typename')),\n key,\n );\n\n return {\n label: relationshipLabel,\n schema,\n property: key,\n };\n });\n });\n const relationship = syntheticRefRelationships.find((r) => r.label === label);\n if (!relationship) {\n return []; // TODO(dmaretskyi): Handle real relationships.\n }\n\n const { objects } = await this._db.query(Filter.schema(relationship.schema)).run();\n return (\n await Promise.all(objects.map((object) => this._projectRefRelationship(object, relationship.property)))\n ).flat();\n }\n\n private async _getAllSchema(): Promise<S.Schema.AnyNoContext[]> {\n return [\n ...(await this._db.schemaRegistry.query().run()),\n // TODO(dmaretskyi): Remove once we can serialize recursive schema.\n ...this._db.graph.schemaRegistry.schemas.filter((s) => getSchemaTypename(s)?.startsWith('example.org')),\n ].filter((schema) => getSchemaTypename(schema) !== StoredSchema.typename);\n }\n\n private _objectToNode(object: ReactiveEchoObject<any>): Node {\n const { id, ...properties } = object;\n return {\n id,\n kind: 'node',\n label: formatNodeLabel(getSchemaTypename(getSchema(object)!)!),\n properties,\n };\n }\n\n private async _projectRefRelationship(object: ReactiveEchoObject<any>, prop: string): Promise<Relationship[]> {\n if (!object[prop]) {\n return [];\n }\n\n const value = Array.isArray(object[prop]) ? object[prop] : [object[prop]];\n\n return Promise.all(\n value.map(async (ref): Promise<Relationship> => {\n const target = await ref.load();\n return {\n id: `${object.id}-${prop}-${target.id}`,\n kind: 'relationship',\n label: formatInferredRelationshipLabel(getSchemaTypename(getSchema(object)!)!, prop),\n properties: {},\n source: this._objectToNode(object),\n target: this._objectToNode(target),\n };\n }),\n );\n }\n}\n"],
|
|
5
|
-
"mappings": ";AAOA,SAASA,kBAAkBC,aAAa;;;ACmBxC,IAAMC,KAAKC,MAAMC,WAAU;AAE3B,IAAMC,UAAUF,MAAMG,OAAO,EAAA,EAAIC,KAAKC,iBAAiBC,IAAI,MAAM,IAAA,CAAA;AAEjE,IAAMC,WAAW,CAAIC,WACnBA,OAAOJ,KACLC,iBAAiBI,QAAQ,OAAO;EAAEC,MAAM;AAAO,EAAA,GAC/CL,iBAAiBM,GAAGT,OAAAA,CAAAA;AAGxB,IAAMU,UAAU,CAACC,SAAiBb,MAAMG,OAAOU,IAAAA,EAAMT,KAAKC,iBAAiBC,IAAI,MAAMO,IAAAA,CAAAA;AAG9E,IAAMC,aAAad,MAAMe,OAAO,wBAAA,EAA0BX,KAC/DC,iBAAiBC,IAAI,CAACU,WAAuB;EAAEC,SAAS;EAAcC,MAAMF,MAAM,CAAA;AAAG,EAAA,CAAA;AAIvF,IAAMG,gBAAgBnB,MAAMe,OAAO,eAAA,EAAiBX,KAAKC,iBAAiBC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K/C,cAAc+C,MAAAA;MAC7B;IACF,CAAA,CAAA;EAEJ;AACF;;EAxFGG,KAAIC,OAAM,QAAA,QAAA;;;;;;GAHA5D,eAAAA,WAAAA,YAAAA,IAAAA;;EAoBV2D,KAAIC,OAAM,QAAA,QAAA;;;;;;GApBA5D,eAAAA,WAAAA,oBAAAA,IAAAA;",
|
|
6
|
-
"names": ["parjsCombinators", "parjs", "ws", "parjs", "whitespace", "nothing", "string", "pipe", "parjsCombinators", "map", "optional", "parser", "recover", "kind", "or", "keyword", "word", "identifier", "regexp", "match", "astKind", "name", "numberLiteral", "Number", "stringLiteral", "value", "variableTag", "variable", "expects", "label", "property", "then", "key", "properties", "manySepBy", "between", "nodePattern", "_", "relationshipPattern", "graphPatternConnector", "x", "direction", "graphPattern", "segments", "matchClause", "pattern", "memberExpression", "path", "equalsPredicate", "left", "right", "whereClause", "predicates", "returnClause", "fields", "f", "cypherQuery", "parseCypherQuery", "query", "parseResult", "cypherQuery", "parse", "isOk", "ast", "value", "Error", "log", "mapValues", "invariant", "log", "createExecutionPlan", "query", "ExecutionPlanBuilder", "build", "counter", "newVariable", "steps", "createStepsForMatchClause", "ast", "matchClause", "whereClause", "createStepsForWhereClause", "createStepsForReturnClause", "returnClause", "output", "fields", "getOutputFields", "match", "pattern", "segments", "length", "firstSegment", "astKind", "lastNodeVariable", "variable", "name", "push", "type", "label", "into", "properties", "property", "key", "value", "i", "relationshipSegment", "nodeSegment", "leftSeparator", "separators", "rightSeparator", "direction", "getDirection", "relationshipVariable", "nodeVariable", "anchor", "relationshipInto", "nodeInto", "where", "map", "field", "path", "p", "join", "slice", "left", "right", "Error", "executeQueryPlan", "dataSource", "plan", "buffer", "results", "step", "steps", "log", "type", "nodes", "getNodes", "label", "push", "map", "node", "into", "filter", "item", "variable", "kind", "properties", "property", "value", "relationships", "getRelationships", "tuple", "anchor", "filteredRelationships", "relationship", "direction", "target", "id", "source", "Error", "i", "length", "newTuple", "relationshipInto", "nodeInto", "result", "field", "fields", "name", "jsonPathGet", "path", "mapValues", "x", "executeQuery", "query", "createExecutionPlan", "parseCypherQuery", "obj", "parts", "split", "shift", "part", "raise", "JSON_SCHEMA_ECHO_REF_ID", "trim", "strings", "values", "combined", "reduce", "acc", "str", "i", "replace", "formatJsonSchemaForLLM", "schemaTypes", "flatMap", "schema", "formatNodeSchema", "formatInferredRelationships", "label", "formatNodeLabel", "typename", "raise", "Error", "properties", "Object", "entries", "filter", "key", "prop", "isReference", "trim", "description", "map", "value", "type", "allSchema", "nodeLabel", "relationships", "relationshipLabel", "formatInferredRelationshipLabel", "targetSchema", "find", "reference", "$ref", "targetLabel", "replace", "property", "toUpperCase", "$id", "JSON_SCHEMA_ECHO_REF_ID", "Array", "isArray", "items", "raise", "Filter", "getSchemaTypename", "StoredSchema", "toJsonSchema", "getSchema", "log", "EchoDataSource", "constructor", "_db", "getNodes", "label", "objects", "query", "run", "map", "_objectToNode", "schema", "_getAllSchema", "find", "s", "getSchemaTypename", "endsWith", "Filter", "getRelationships", "syntheticRefRelationships", "filter", "StoredSchema", "typename", "flatMap", "jsonSchema", "toJsonSchema", "relationships", "Object", "entries", "properties", "key", "prop", "isReference", "value", "relationshipLabel", "formatInferredRelationshipLabel", "raise", "Error", "property", "relationship", "r", "Promise", "all", "object", "_projectRefRelationship", "flat", "schemaRegistry", "graph", "schemas", "startsWith", "id", "kind", "formatNodeLabel", "getSchema", "Array", "isArray", "ref", "target", "load", "source", "log", "method"]
|
|
7
|
-
}
|