@dxos/assistant 0.8.2-main.fbd8ed0 → 0.8.2-staging.4d6ad0f
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/index.mjs +1983 -64
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +1976 -63
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +1984 -64
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/{src/bin → bin}/chat.d.ts.map +1 -1
- package/dist/types/src/blueprint/blueprint.d.ts +79 -0
- package/dist/types/src/blueprint/blueprint.d.ts.map +1 -0
- package/dist/types/src/blueprint/blueprint.test.d.ts +2 -0
- package/dist/types/src/blueprint/blueprint.test.d.ts.map +1 -0
- package/dist/types/src/blueprint/index.d.ts +4 -0
- package/dist/types/src/blueprint/index.d.ts.map +1 -0
- package/dist/types/src/blueprint/logger.d.ts +3 -0
- package/dist/types/src/blueprint/logger.d.ts.map +1 -0
- package/dist/types/src/{ai-service/parser.d.ts → blueprint/machine.d.ts} +46 -68
- package/dist/types/src/blueprint/machine.d.ts.map +1 -0
- package/dist/types/src/blueprint/test-data.d.ts +3 -0
- package/dist/types/src/blueprint/test-data.d.ts.map +1 -0
- package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts +4 -0
- package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts.map +1 -0
- package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.test.d.ts +2 -0
- package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.test.d.ts.map +1 -0
- package/dist/types/src/extraction/extraction-llm-function/index.d.ts +2 -0
- package/dist/types/src/extraction/extraction-llm-function/index.d.ts.map +1 -0
- package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts +210 -0
- package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts.map +1 -0
- package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.test.d.ts +2 -0
- package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.test.d.ts.map +1 -0
- package/dist/types/src/extraction/extraction-ner-function/index.d.ts +3 -0
- package/dist/types/src/extraction/extraction-ner-function/index.d.ts.map +1 -0
- package/dist/types/src/extraction/extraction-ner-function/named-entity-recognition.d.ts +14 -0
- package/dist/types/src/extraction/extraction-ner-function/named-entity-recognition.d.ts.map +1 -0
- package/dist/types/src/extraction/extraction-ner-function/named-entity-recognition.test.d.ts +2 -0
- package/dist/types/src/extraction/extraction-ner-function/named-entity-recognition.test.d.ts.map +1 -0
- package/dist/types/src/extraction/extraction.d.ts +242 -0
- package/dist/types/src/extraction/extraction.d.ts.map +1 -0
- package/dist/types/src/extraction/index.d.ts +5 -0
- package/dist/types/src/extraction/index.d.ts.map +1 -0
- package/dist/types/src/extraction/quotes.d.ts +15 -0
- package/dist/types/src/extraction/quotes.d.ts.map +1 -0
- package/dist/types/src/extraction/quotes.test.d.ts +2 -0
- package/dist/types/src/extraction/quotes.test.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +4 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/research/exa.d.ts +7 -0
- package/dist/types/src/research/exa.d.ts.map +1 -0
- package/dist/types/src/research/graph.d.ts +39 -0
- package/dist/types/src/research/graph.d.ts.map +1 -0
- package/dist/types/src/research/graph.test.d.ts +2 -0
- package/dist/types/src/research/graph.test.d.ts.map +1 -0
- package/dist/types/src/research/index.d.ts +4 -0
- package/dist/types/src/research/index.d.ts.map +1 -0
- package/dist/types/src/research/research.d.ts +10 -0
- package/dist/types/src/research/research.d.ts.map +1 -0
- package/dist/types/src/research/research.test.d.ts.map +1 -0
- package/dist/types/src/session/index.d.ts +0 -1
- package/dist/types/src/session/index.d.ts.map +1 -1
- package/dist/types/src/session/session.d.ts +47 -22
- package/dist/types/src/session/session.d.ts.map +1 -1
- package/dist/types/src/session/version-pin.d.ts +3 -4
- package/dist/types/src/session/version-pin.d.ts.map +1 -1
- package/dist/types/src/summarization/summarization.test.d.ts +2 -0
- package/dist/types/src/summarization/summarization.test.d.ts.map +1 -0
- package/dist/types/src/testing/exa-search-1748337321991.d.ts +38 -0
- package/dist/types/src/testing/exa-search-1748337321991.d.ts.map +1 -0
- package/dist/types/src/testing/exa-search-1748337331526.d.ts +37 -0
- package/dist/types/src/testing/exa-search-1748337331526.d.ts.map +1 -0
- package/dist/types/src/testing/exa-search-1748337344119.d.ts +58 -0
- package/dist/types/src/testing/exa-search-1748337344119.d.ts.map +1 -0
- package/dist/types/src/testing/index.d.ts +2 -7
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +3 -0
- package/dist/types/src/types.d.ts.map +1 -0
- package/package.json +22 -38
- package/src/blueprint/blueprint.test.ts +142 -0
- package/src/blueprint/blueprint.ts +95 -0
- package/src/blueprint/index.ts +7 -0
- package/src/blueprint/logger.ts +66 -0
- package/src/blueprint/machine.ts +208 -0
- package/src/blueprint/test-data.ts +55 -0
- package/src/extraction/extraction-llm-function/extraction-llm-function.test.ts +95 -0
- package/src/extraction/extraction-llm-function/extraction-llm-function.ts +64 -0
- package/src/extraction/extraction-llm-function/index.ts +5 -0
- package/src/extraction/extraction-llm-function/instructions.tpl +28 -0
- package/src/extraction/extraction-ner-function/extraction-ner-function.test.ts +115 -0
- package/src/extraction/extraction-ner-function/extraction-ner-function.ts +54 -0
- package/src/extraction/extraction-ner-function/index.ts +6 -0
- package/src/extraction/extraction-ner-function/named-entity-recognition.test.ts +94 -0
- package/src/extraction/extraction-ner-function/named-entity-recognition.ts +97 -0
- package/src/extraction/extraction.ts +75 -0
- package/src/extraction/index.ts +8 -0
- package/src/extraction/quotes.test.ts +27 -0
- package/src/extraction/quotes.ts +57 -0
- package/src/index.ts +4 -4
- package/src/research/exa.ts +100 -0
- package/src/research/graph.test.ts +15 -0
- package/src/research/graph.ts +291 -0
- package/src/research/index.ts +7 -0
- package/src/research/instructions-research.tpl +97 -0
- package/src/research/research.test.ts +189 -0
- package/src/research/research.ts +89 -0
- package/src/session/index.ts +0 -1
- package/src/session/session.test.ts +7 -7
- package/src/session/session.ts +46 -19
- package/src/session/version-pin.ts +2 -3
- package/src/summarization/summarization.test.ts +216 -0
- package/src/testing/exa-search-1748337321991.ts +131 -0
- package/src/testing/exa-search-1748337331526.ts +144 -0
- package/src/testing/exa-search-1748337344119.ts +133 -0
- package/src/testing/index.ts +8 -8
- package/src/types.ts +8 -0
- package/src/typings.d.ts +8 -0
- package/dist/lib/browser/chunk-B4HAWUFW.mjs +0 -2786
- package/dist/lib/browser/chunk-B4HAWUFW.mjs.map +0 -7
- package/dist/lib/browser/testing/index.mjs +0 -658
- package/dist/lib/browser/testing/index.mjs.map +0 -7
- package/dist/lib/node/chunk-NOB7CIIC.cjs +0 -2791
- package/dist/lib/node/chunk-NOB7CIIC.cjs.map +0 -7
- package/dist/lib/node/testing/index.cjs +0 -672
- package/dist/lib/node/testing/index.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-SAWYU3V5.mjs +0 -2788
- package/dist/lib/node-esm/chunk-SAWYU3V5.mjs.map +0 -7
- package/dist/lib/node-esm/testing/index.mjs +0 -659
- package/dist/lib/node-esm/testing/index.mjs.map +0 -7
- package/dist/types/src/ai-service/client.test.d.ts +0 -2
- package/dist/types/src/ai-service/client.test.d.ts.map +0 -1
- package/dist/types/src/ai-service/defs.d.ts +0 -9
- package/dist/types/src/ai-service/defs.d.ts.map +0 -1
- package/dist/types/src/ai-service/edge-client.d.ts +0 -18
- package/dist/types/src/ai-service/edge-client.d.ts.map +0 -1
- package/dist/types/src/ai-service/index.d.ts +0 -10
- package/dist/types/src/ai-service/index.d.ts.map +0 -1
- package/dist/types/src/ai-service/message-collector.d.ts +0 -82
- package/dist/types/src/ai-service/message-collector.d.ts.map +0 -1
- package/dist/types/src/ai-service/ollama-client.d.ts +0 -43
- package/dist/types/src/ai-service/ollama-client.d.ts.map +0 -1
- package/dist/types/src/ai-service/parser.d.ts.map +0 -1
- package/dist/types/src/ai-service/service.d.ts +0 -25
- package/dist/types/src/ai-service/service.d.ts.map +0 -1
- package/dist/types/src/ai-service/stream.d.ts +0 -40
- package/dist/types/src/ai-service/stream.d.ts.map +0 -1
- package/dist/types/src/ai-service/stream.test.d.ts +0 -2
- package/dist/types/src/ai-service/stream.test.d.ts.map +0 -1
- package/dist/types/src/ai-service/testing/index.d.ts +0 -3
- package/dist/types/src/ai-service/testing/index.d.ts.map +0 -1
- package/dist/types/src/ai-service/testing/mock.d.ts +0 -11
- package/dist/types/src/ai-service/testing/mock.d.ts.map +0 -1
- package/dist/types/src/ai-service/testing/test-stream.d.ts +0 -7
- package/dist/types/src/ai-service/testing/test-stream.d.ts.map +0 -1
- package/dist/types/src/ai-service/transform.d.ts +0 -27
- package/dist/types/src/ai-service/transform.d.ts.map +0 -1
- package/dist/types/src/ai-service/types.d.ts +0 -210
- package/dist/types/src/ai-service/types.d.ts.map +0 -1
- package/dist/types/src/ai-service/util/index.d.ts +0 -2
- package/dist/types/src/ai-service/util/index.d.ts.map +0 -1
- package/dist/types/src/ai-service/util/sse.d.ts +0 -39
- package/dist/types/src/ai-service/util/sse.d.ts.map +0 -1
- package/dist/types/src/experimental/conversation/conversation.d.ts +0 -61
- package/dist/types/src/experimental/conversation/conversation.d.ts.map +0 -1
- package/dist/types/src/experimental/conversation/conversation.test.d.ts +0 -2
- package/dist/types/src/experimental/conversation/conversation.test.d.ts.map +0 -1
- package/dist/types/src/experimental/conversation/index.d.ts +0 -2
- package/dist/types/src/experimental/conversation/index.d.ts.map +0 -1
- package/dist/types/src/experimental/conversation/types.d.ts +0 -78
- package/dist/types/src/experimental/conversation/types.d.ts.map +0 -1
- package/dist/types/src/experimental/cypher/ast.d.ts +0 -56
- package/dist/types/src/experimental/cypher/ast.d.ts.map +0 -1
- package/dist/types/src/experimental/cypher/combinators.d.ts +0 -14
- package/dist/types/src/experimental/cypher/combinators.d.ts.map +0 -1
- package/dist/types/src/experimental/cypher/combinators.test.d.ts +0 -2
- package/dist/types/src/experimental/cypher/combinators.test.d.ts.map +0 -1
- package/dist/types/src/experimental/cypher/echo-data-source.d.ts +0 -16
- package/dist/types/src/experimental/cypher/echo-data-source.d.ts.map +0 -1
- package/dist/types/src/experimental/cypher/execution-plan.d.ts +0 -49
- package/dist/types/src/experimental/cypher/execution-plan.d.ts.map +0 -1
- package/dist/types/src/experimental/cypher/execution-plan.test.d.ts +0 -2
- package/dist/types/src/experimental/cypher/execution-plan.test.d.ts.map +0 -1
- package/dist/types/src/experimental/cypher/index.d.ts +0 -5
- package/dist/types/src/experimental/cypher/index.d.ts.map +0 -1
- package/dist/types/src/experimental/cypher/parjs.d.ts +0 -4
- package/dist/types/src/experimental/cypher/parjs.d.ts.map +0 -1
- package/dist/types/src/experimental/cypher/parser.d.ts +0 -6
- package/dist/types/src/experimental/cypher/parser.d.ts.map +0 -1
- package/dist/types/src/experimental/cypher/query-executor.d.ts +0 -26
- package/dist/types/src/experimental/cypher/query-executor.d.ts.map +0 -1
- package/dist/types/src/experimental/cypher/query-executor.test.d.ts +0 -2
- package/dist/types/src/experimental/cypher/query-executor.test.d.ts.map +0 -1
- package/dist/types/src/experimental/cypher/schema.d.ts +0 -12
- package/dist/types/src/experimental/cypher/schema.d.ts.map +0 -1
- package/dist/types/src/experimental/cypher/schema.test.d.ts +0 -2
- package/dist/types/src/experimental/cypher/schema.test.d.ts.map +0 -1
- package/dist/types/src/experimental/index.d.ts +0 -3
- package/dist/types/src/experimental/index.d.ts.map +0 -1
- package/dist/types/src/experimental/ner/ner.test.d.ts +0 -2
- package/dist/types/src/experimental/ner/ner.test.d.ts.map +0 -1
- package/dist/types/src/experimental/research/exa.d.ts +0 -6
- package/dist/types/src/experimental/research/exa.d.ts.map +0 -1
- package/dist/types/src/experimental/research/research.test.d.ts.map +0 -1
- package/dist/types/src/session/tools.d.ts +0 -18
- package/dist/types/src/session/tools.d.ts.map +0 -1
- package/dist/types/src/testing/artifacts.test.d.ts +0 -1
- package/dist/types/src/testing/artifacts.test.d.ts.map +0 -1
- package/dist/types/src/testing/data.d.ts +0 -2
- package/dist/types/src/testing/data.d.ts.map +0 -1
- package/dist/types/src/testing/defs.d.ts +0 -5
- package/dist/types/src/testing/defs.d.ts.map +0 -1
- package/dist/types/src/testing/logger.d.ts +0 -12
- package/dist/types/src/testing/logger.d.ts.map +0 -1
- package/dist/types/src/testing/object-extraction.test.d.ts +0 -1
- package/dist/types/src/testing/object-extraction.test.d.ts.map +0 -1
- package/dist/types/src/testing/ollama.d.ts +0 -6
- package/dist/types/src/testing/ollama.d.ts.map +0 -1
- package/dist/types/src/testing/printer.d.ts +0 -6
- package/dist/types/src/testing/printer.d.ts.map +0 -1
- package/dist/types/src/testing/query-promts.d.ts +0 -5
- package/dist/types/src/testing/query-promts.d.ts.map +0 -1
- package/dist/types/src/testing/query.test.d.ts +0 -2
- package/dist/types/src/testing/query.test.d.ts.map +0 -1
- package/dist/types/src/testing/test-data.d.ts +0 -29
- package/dist/types/src/testing/test-data.d.ts.map +0 -1
- package/dist/types/src/testing/test-schema.d.ts +0 -52
- package/dist/types/src/testing/test-schema.d.ts.map +0 -1
- package/dist/types/src/util/index.d.ts +0 -2
- package/dist/types/src/util/index.d.ts.map +0 -1
- package/dist/types/src/util/trim.d.ts +0 -5
- package/dist/types/src/util/trim.d.ts.map +0 -1
- package/src/ai-service/client.test.ts +0 -247
- package/src/ai-service/defs.ts +0 -39
- package/src/ai-service/edge-client.ts +0 -60
- package/src/ai-service/index.ts +0 -13
- package/src/ai-service/message-collector.ts +0 -84
- package/src/ai-service/ollama-client.ts +0 -506
- package/src/ai-service/parser.ts +0 -369
- package/src/ai-service/service.ts +0 -31
- package/src/ai-service/stream.test.ts +0 -125
- package/src/ai-service/stream.ts +0 -118
- package/src/ai-service/testing/index.ts +0 -6
- package/src/ai-service/testing/mock.ts +0 -30
- package/src/ai-service/testing/test-stream.ts +0 -93
- package/src/ai-service/transform.ts +0 -121
- package/src/ai-service/types.ts +0 -112
- package/src/ai-service/util/index.ts +0 -5
- package/src/ai-service/util/sse.ts +0 -341
- package/src/bin/chat.ts +0 -79
- package/src/experimental/conversation/conversation.test.ts +0 -73
- package/src/experimental/conversation/conversation.ts +0 -142
- package/src/experimental/conversation/index.ts +0 -5
- package/src/experimental/conversation/types.ts +0 -126
- package/src/experimental/cypher/ast.ts +0 -75
- package/src/experimental/cypher/combinators.test.ts +0 -137
- package/src/experimental/cypher/combinators.ts +0 -148
- package/src/experimental/cypher/echo-data-source.ts +0 -105
- package/src/experimental/cypher/execution-plan.test.ts +0 -44
- package/src/experimental/cypher/execution-plan.ts +0 -208
- package/src/experimental/cypher/index.ts +0 -8
- package/src/experimental/cypher/parjs-shims.d.ts +0 -10
- package/src/experimental/cypher/parjs.ts +0 -10
- package/src/experimental/cypher/parser.ts +0 -19
- package/src/experimental/cypher/query-executor.test.ts +0 -47
- package/src/experimental/cypher/query-executor.ts +0 -145
- package/src/experimental/cypher/schema.test.ts +0 -17
- package/src/experimental/cypher/schema.ts +0 -86
- package/src/experimental/index.ts +0 -6
- package/src/experimental/ner/ner.test.ts +0 -163
- package/src/experimental/research/exa.ts +0 -38
- package/src/experimental/research/instructions.tpl +0 -64
- package/src/experimental/research/research.test.ts +0 -263
- package/src/session/tools.ts +0 -117
- package/src/testing/artifacts.test.ts +0 -182
- package/src/testing/data.ts +0 -13
- package/src/testing/defs.ts +0 -9
- package/src/testing/logger.ts +0 -129
- package/src/testing/object-extraction.test.ts +0 -71
- package/src/testing/ollama.ts +0 -15
- package/src/testing/printer.ts +0 -41
- package/src/testing/query-promts.ts +0 -75
- package/src/testing/query.test.ts +0 -88
- package/src/testing/test-data.ts +0 -379
- package/src/testing/test-schema.ts +0 -79
- package/src/util/index.ts +0 -5
- package/src/util/trim.ts +0 -15
- package/vendor/parjs-browser.mjs +0 -4
- package/vendor/parjs-default.mjs +0 -8
- /package/dist/types/{src/bin → bin}/chat.d.ts +0 -0
- /package/dist/types/src/{experimental/research → research}/research.test.d.ts +0 -0
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import type { JsonPath } from '@dxos/echo-schema';
|
|
6
|
-
import { log } from '@dxos/log';
|
|
7
|
-
import { mapValues } from '@dxos/util';
|
|
8
|
-
|
|
9
|
-
import { createExecutionPlan, type ExecutionPlan, type VariableName } from './execution-plan';
|
|
10
|
-
import { parseCypherQuery } from './parser';
|
|
11
|
-
|
|
12
|
-
export interface DataSource {
|
|
13
|
-
getNodes: (params: { label?: string }) => Promise<Node[]>;
|
|
14
|
-
getRelationships: (params: { label?: string }) => Promise<Relationship[]>;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export type Node = {
|
|
18
|
-
id: string;
|
|
19
|
-
kind: 'node';
|
|
20
|
-
label: string;
|
|
21
|
-
properties: Record<string, unknown>;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export type Relationship = {
|
|
25
|
-
id: string;
|
|
26
|
-
kind: 'relationship';
|
|
27
|
-
label: string;
|
|
28
|
-
properties: Record<string, unknown>;
|
|
29
|
-
source: Node;
|
|
30
|
-
target: Node;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export const executeQueryPlan = async (
|
|
34
|
-
dataSource: DataSource,
|
|
35
|
-
plan: ExecutionPlan,
|
|
36
|
-
): Promise<Record<string, unknown>[]> => {
|
|
37
|
-
let buffer: Record<VariableName, Node | Relationship>[] = [];
|
|
38
|
-
const results: Record<string, unknown>[] = [];
|
|
39
|
-
|
|
40
|
-
for (const step of plan.steps) {
|
|
41
|
-
log('begin step', { step });
|
|
42
|
-
|
|
43
|
-
switch (step.type) {
|
|
44
|
-
case 'NodeScan': {
|
|
45
|
-
const nodes = await dataSource.getNodes({ label: step.label });
|
|
46
|
-
buffer.push(...nodes.map((node) => ({ [step.into]: node })));
|
|
47
|
-
break;
|
|
48
|
-
}
|
|
49
|
-
case 'FilterByLabel': {
|
|
50
|
-
buffer = buffer.filter((item) => {
|
|
51
|
-
const node = item[step.variable];
|
|
52
|
-
return node && node.kind === 'node' && node.label === step.label;
|
|
53
|
-
});
|
|
54
|
-
break;
|
|
55
|
-
}
|
|
56
|
-
case 'FilterByProperty': {
|
|
57
|
-
buffer = buffer.filter((item) => {
|
|
58
|
-
const node = item[step.variable];
|
|
59
|
-
return node && node.kind === 'node' && node.properties[step.property] === step.value;
|
|
60
|
-
});
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
63
|
-
case 'RelationshipScan': {
|
|
64
|
-
const relationships = await dataSource.getRelationships({ label: step.label });
|
|
65
|
-
for (const tuple of [...buffer]) {
|
|
66
|
-
if (tuple[step.anchor].kind !== 'node') {
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
const filteredRelationships = relationships.filter((relationship) => {
|
|
70
|
-
switch (step.direction) {
|
|
71
|
-
case 'in':
|
|
72
|
-
return relationship.target.id === tuple[step.anchor].id;
|
|
73
|
-
case 'out':
|
|
74
|
-
return relationship.source.id === tuple[step.anchor].id;
|
|
75
|
-
case 'both':
|
|
76
|
-
return (
|
|
77
|
-
relationship.source.id === tuple[step.anchor].id || relationship.target.id === tuple[step.anchor].id
|
|
78
|
-
);
|
|
79
|
-
default:
|
|
80
|
-
throw new Error(`Unknown direction: ${step.direction}`);
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
for (let i = 0; i < filteredRelationships.length; i++) {
|
|
84
|
-
const relationship = filteredRelationships[i];
|
|
85
|
-
const newTuple = i === 0 ? tuple : { ...tuple };
|
|
86
|
-
if (newTuple !== tuple) {
|
|
87
|
-
buffer.push(newTuple);
|
|
88
|
-
}
|
|
89
|
-
newTuple[step.relationshipInto] = relationship;
|
|
90
|
-
switch (step.direction) {
|
|
91
|
-
case 'in':
|
|
92
|
-
newTuple[step.nodeInto] = relationship.source;
|
|
93
|
-
break;
|
|
94
|
-
case 'out':
|
|
95
|
-
newTuple[step.nodeInto] = relationship.target;
|
|
96
|
-
break;
|
|
97
|
-
case 'both':
|
|
98
|
-
newTuple[step.nodeInto] =
|
|
99
|
-
relationship.source.id === newTuple[step.anchor].id ? relationship.target : relationship.source;
|
|
100
|
-
break;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
break;
|
|
105
|
-
}
|
|
106
|
-
case 'ProduceResults': {
|
|
107
|
-
for (const tuple of buffer) {
|
|
108
|
-
const result: Record<string, unknown> = {};
|
|
109
|
-
for (const field of step.fields) {
|
|
110
|
-
result[field.name] = jsonPathGet(tuple[field.variable].properties, field.path);
|
|
111
|
-
}
|
|
112
|
-
results.push(result);
|
|
113
|
-
}
|
|
114
|
-
break;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
log('finish step', { buffer: buffer.map((tuple) => mapValues(tuple, (x) => x.id)), results });
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
return results;
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
export const executeQuery = (dataSource: DataSource, query: string): Promise<Record<string, unknown>[]> => {
|
|
125
|
-
const plan = createExecutionPlan(parseCypherQuery(query));
|
|
126
|
-
return executeQueryPlan(dataSource, plan);
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
// TODO(dmaretskyi): Extract.
|
|
130
|
-
const jsonPathGet = (obj: Record<string, unknown>, path: JsonPath): unknown => {
|
|
131
|
-
if (path === '' || path === '$') {
|
|
132
|
-
return obj;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
const parts = path.split('.');
|
|
136
|
-
if (parts[0] === '$') {
|
|
137
|
-
parts.shift();
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
let result: any = obj;
|
|
141
|
-
for (const part of parts) {
|
|
142
|
-
result = result?.[part];
|
|
143
|
-
}
|
|
144
|
-
return result;
|
|
145
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { test } from 'vitest';
|
|
6
|
-
|
|
7
|
-
import { toJsonSchema } from '@dxos/echo-schema';
|
|
8
|
-
|
|
9
|
-
import { formatJsonSchemaForLLM } from './schema';
|
|
10
|
-
import { Contact, Organization, Project, Task } from '../../testing';
|
|
11
|
-
|
|
12
|
-
test('Organization-Project-Task-Contact schema', async ({ expect }) => {
|
|
13
|
-
const jsonSchema = [Organization, Project, Task, Contact].map((schema) => toJsonSchema(schema));
|
|
14
|
-
const result = formatJsonSchemaForLLM(jsonSchema);
|
|
15
|
-
// log('result', { result });
|
|
16
|
-
expect(result).toHaveLength(8);
|
|
17
|
-
});
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { raise } from '@dxos/debug';
|
|
6
|
-
import { JSON_SCHEMA_ECHO_REF_ID, type JsonSchemaType } from '@dxos/echo-schema';
|
|
7
|
-
|
|
8
|
-
import { trim } from '../../util';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Formats ECHO schema to be consumed by LLM.
|
|
12
|
-
* Schema is formatted in cypher format.
|
|
13
|
-
* Objects are represented as nodes.
|
|
14
|
-
* References are represented as relationships.
|
|
15
|
-
*/
|
|
16
|
-
export const formatJsonSchemaForLLM = (schemaTypes: JsonSchemaType[]): string[] => {
|
|
17
|
-
return schemaTypes.flatMap((schema) => [
|
|
18
|
-
formatNodeSchema(schema),
|
|
19
|
-
...formatInferredRelationships(schema, schemaTypes),
|
|
20
|
-
]);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const formatNodeSchema = (schema: JsonSchemaType) => {
|
|
24
|
-
const label = formatNodeLabel(schema.typename ?? raise(new Error('Schema must have $id')));
|
|
25
|
-
const properties = Object.entries(schema.properties!).filter(([key, prop]) => key !== 'id' && !isReference(prop));
|
|
26
|
-
|
|
27
|
-
return trim`
|
|
28
|
-
<node>
|
|
29
|
-
(:${label})
|
|
30
|
-
|
|
31
|
-
<description>${schema.description}</description>
|
|
32
|
-
|
|
33
|
-
<properties>
|
|
34
|
-
${properties.map(([key, value]) => {
|
|
35
|
-
return trim`
|
|
36
|
-
<${key}>
|
|
37
|
-
<type>${value.type}</type>
|
|
38
|
-
<description>${value.description}</description>
|
|
39
|
-
</${key}>
|
|
40
|
-
`;
|
|
41
|
-
})}
|
|
42
|
-
</properties>
|
|
43
|
-
</node>
|
|
44
|
-
`;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const formatInferredRelationships = (schema: JsonSchemaType, allSchema: JsonSchemaType[]): string[] => {
|
|
48
|
-
const nodeLabel = formatNodeLabel(schema.typename ?? raise(new Error('Schema must have $id')));
|
|
49
|
-
const relationships = Object.entries(schema.properties!).filter(([key, prop]) => isReference(prop));
|
|
50
|
-
|
|
51
|
-
return relationships.map(([key, value]) => {
|
|
52
|
-
const relationshipLabel = formatInferredRelationshipLabel(
|
|
53
|
-
schema.typename ?? raise(new Error('Schema must have $id')),
|
|
54
|
-
key,
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
// TODO(dmaretskyi): Registered schema don't get reference types updated.
|
|
58
|
-
const targetSchema = allSchema.find((schema) => `dxn:type/${schema.typename}` === value.reference?.schema.$ref);
|
|
59
|
-
const targetLabel = targetSchema ? formatNodeLabel(targetSchema?.typename ?? '') : '';
|
|
60
|
-
|
|
61
|
-
return trim`
|
|
62
|
-
<relationship>
|
|
63
|
-
(:${nodeLabel})-[:${relationshipLabel}]->(:${targetLabel})
|
|
64
|
-
|
|
65
|
-
<description>${value.description}</description>
|
|
66
|
-
</relationship>
|
|
67
|
-
`;
|
|
68
|
-
});
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
export const formatNodeLabel = (typename: string) => {
|
|
72
|
-
return typename.replace(/^example\.com\/type\//g, '');
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
export const formatInferredRelationshipLabel = (typename: string, property: string) => {
|
|
76
|
-
const nodeLabel = formatNodeLabel(typename);
|
|
77
|
-
return `${nodeLabel}_${property}`.toUpperCase();
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
export const isReference = (schema: JsonSchemaType) =>
|
|
81
|
-
schema.$id === JSON_SCHEMA_ECHO_REF_ID ||
|
|
82
|
-
(schema.type === 'array' &&
|
|
83
|
-
!Array.isArray(schema.items) &&
|
|
84
|
-
typeof schema.items === 'object' &&
|
|
85
|
-
'$id' in schema.items &&
|
|
86
|
-
schema.items.$id === JSON_SCHEMA_ECHO_REF_ID);
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { pipeline } from '@xenova/transformers';
|
|
6
|
-
import { beforeAll, describe, expect, test } from 'vitest';
|
|
7
|
-
|
|
8
|
-
import { log } from '@dxos/log';
|
|
9
|
-
import { createTestData } from '@dxos/schema/testing';
|
|
10
|
-
|
|
11
|
-
type NerToken = {
|
|
12
|
-
entity: string;
|
|
13
|
-
score: number;
|
|
14
|
-
index: number;
|
|
15
|
-
word: string;
|
|
16
|
-
start: number | null;
|
|
17
|
-
end: number | null;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const createTokenGroups = (tokens: NerToken[]): NerToken[][] => {
|
|
21
|
-
const tokenGroups: NerToken[][] = [];
|
|
22
|
-
|
|
23
|
-
const canBeCombined = (prevToken: NerToken, currentToken: NerToken) => {
|
|
24
|
-
const [currentState, currentEntity] = currentToken.entity.split('-'); // B, I, O
|
|
25
|
-
const [prevState, prevEntity] = prevToken.entity.split('-'); // B, I, O
|
|
26
|
-
|
|
27
|
-
if (prevEntity !== currentEntity) {
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (prevState === 'O') {
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (currentState === 'I') {
|
|
36
|
-
return true;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if ((prevState === 'B' || prevState === 'I') && currentState === 'B') {
|
|
40
|
-
return currentToken.word.startsWith('#');
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return false;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
for (const token of tokens) {
|
|
47
|
-
if (tokenGroups.length === 0) {
|
|
48
|
-
tokenGroups.push([token]);
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const lastTokenGroup = tokenGroups.at(-1)!;
|
|
53
|
-
if (canBeCombined(lastTokenGroup.at(-1)!, token)) {
|
|
54
|
-
lastTokenGroup.push(token);
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
tokenGroups.push([token]);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return tokenGroups;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
const combineNerTokens = (group: NerToken[]): NerToken => {
|
|
65
|
-
const combinedToken: NerToken = {
|
|
66
|
-
entity: group.at(0)!.entity.split('-')[1],
|
|
67
|
-
score: group.reduce((acc, token) => acc + token.score, 0) / group.length,
|
|
68
|
-
index: group.at(0)!.index,
|
|
69
|
-
word: group.at(0)!.word,
|
|
70
|
-
start: group.at(0)!.start,
|
|
71
|
-
end: group.at(-1)!.end,
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
for (const token of group.slice(1)) {
|
|
75
|
-
if (token.word.startsWith('#')) {
|
|
76
|
-
combinedToken.word += token.word.replace(/^#+/, '');
|
|
77
|
-
} else {
|
|
78
|
-
combinedToken.word += ' ' + token.word;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return combinedToken;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
describe.skip('Named Entity Recognition', () => {
|
|
86
|
-
let ner: any;
|
|
87
|
-
|
|
88
|
-
beforeAll(async () => {
|
|
89
|
-
// Initialize the NER pipeline
|
|
90
|
-
ner = await pipeline('ner', 'Xenova/bert-base-NER');
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
test.skip('should identify named entities in text', async () => {
|
|
94
|
-
const text = 'Elon Musk is the CEO of SpaceX and Tesla.';
|
|
95
|
-
const result = await ner(text);
|
|
96
|
-
|
|
97
|
-
// Verify the structure of the result
|
|
98
|
-
expect(Array.isArray(result)).toBe(true);
|
|
99
|
-
expect(result.length).toBeGreaterThan(0);
|
|
100
|
-
|
|
101
|
-
log.info('ner', { result });
|
|
102
|
-
|
|
103
|
-
// Check for specific entities
|
|
104
|
-
const entities = result.map((item: any) => ({
|
|
105
|
-
text: item.word,
|
|
106
|
-
entity: item.entity,
|
|
107
|
-
score: item.score,
|
|
108
|
-
}));
|
|
109
|
-
|
|
110
|
-
// Verify Elon Musk is recognized as a person
|
|
111
|
-
const elonMusk = entities.find((e: any) => e.text === 'Elon' || e.text === 'Musk');
|
|
112
|
-
expect(elonMusk).toBeDefined();
|
|
113
|
-
expect(elonMusk?.entity).toMatch(/PER/);
|
|
114
|
-
|
|
115
|
-
// Verify SpaceX and Tesla are recognized as organizations
|
|
116
|
-
const companies = entities.filter((e: any) => e.text === 'SpaceX' || e.text === 'Tesla');
|
|
117
|
-
expect(companies.length).toBe(2);
|
|
118
|
-
companies.forEach((company: any) => {
|
|
119
|
-
expect(company.entity).toMatch(/ORG/);
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
test('own data', async () => {
|
|
124
|
-
const { transcriptWoflram, transcriptJosiah } = await createTestData();
|
|
125
|
-
|
|
126
|
-
const blocks = [...transcriptWoflram, ...transcriptJosiah].flatMap((message) =>
|
|
127
|
-
message.blocks.flatMap((block) => (block.type === 'transcription' ? [block.text] : [])),
|
|
128
|
-
);
|
|
129
|
-
|
|
130
|
-
for (const block of blocks) {
|
|
131
|
-
const result = await ner(block);
|
|
132
|
-
const combinedTokens = createTokenGroups(result).map(combineNerTokens);
|
|
133
|
-
log.info('ner', { text: block, result: combinedTokens });
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
test('more own data', async () => {
|
|
138
|
-
const { transcriptMessages } = await createTestData();
|
|
139
|
-
|
|
140
|
-
const blocks = transcriptMessages.flatMap((message) =>
|
|
141
|
-
message.blocks.flatMap((block) => (block.type === 'transcription' ? [block.text] : [])),
|
|
142
|
-
);
|
|
143
|
-
|
|
144
|
-
for (const block of blocks) {
|
|
145
|
-
const result = await ner(block);
|
|
146
|
-
const combinedTokens = createTokenGroups(result).map(combineNerTokens);
|
|
147
|
-
log.info('ner', { text: block, result: combinedTokens });
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
test('should handle empty text', async () => {
|
|
152
|
-
const result = await ner('');
|
|
153
|
-
expect(Array.isArray(result)).toBe(true);
|
|
154
|
-
expect(result.length).toBe(0);
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
test('should handle text with no named entities', async () => {
|
|
158
|
-
const text = 'The weather is nice today.';
|
|
159
|
-
const result = await ner(text);
|
|
160
|
-
expect(Array.isArray(result)).toBe(true);
|
|
161
|
-
expect(result.length).toBe(0);
|
|
162
|
-
});
|
|
163
|
-
});
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { Schema } from 'effect';
|
|
6
|
-
import Exa from 'exa-js';
|
|
7
|
-
|
|
8
|
-
import { defineTool, ToolResult } from '@dxos/artifact';
|
|
9
|
-
import { log } from '@dxos/log';
|
|
10
|
-
|
|
11
|
-
type CreateExaToolOptions = {
|
|
12
|
-
apiKey: string;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export const createExaTool = ({ apiKey }: CreateExaToolOptions) => {
|
|
16
|
-
const exa = new Exa(apiKey);
|
|
17
|
-
|
|
18
|
-
return defineTool('search', {
|
|
19
|
-
name: 'web_search',
|
|
20
|
-
description: 'Search the web for information',
|
|
21
|
-
schema: Schema.Struct({
|
|
22
|
-
query: Schema.String.annotations({ description: 'The query to search for' }),
|
|
23
|
-
}),
|
|
24
|
-
execute: async ({ query }) => {
|
|
25
|
-
const context = await exa.searchAndContents(query, {
|
|
26
|
-
type: 'auto',
|
|
27
|
-
text: {
|
|
28
|
-
maxCharacters: 3_000,
|
|
29
|
-
},
|
|
30
|
-
livecrawl: 'always',
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
log.info('exa search', { query, costDollars: context.costDollars });
|
|
34
|
-
|
|
35
|
-
return ToolResult.Success(context);
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
};
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
You are an expert research agent. Your job is to assist a user by conducting in-depth research using real-time web search.
|
|
2
|
-
You output the results in a structured format matching the schema provided.
|
|
3
|
-
|
|
4
|
-
You are equipped with the ability to:
|
|
5
|
-
|
|
6
|
-
- Generate precise and effective search queries.
|
|
7
|
-
- Request web pages by query (through a `web_search` tool).
|
|
8
|
-
- Read the full content of retrieved pages.
|
|
9
|
-
- Synthesize accurate, clear, and structured answers using reliable information from the retrieved content.
|
|
10
|
-
|
|
11
|
-
Always follow these principles:
|
|
12
|
-
|
|
13
|
-
- Relevance First: Only return facts that are supported by content in the retrieved web pages. Never fabricate or guess information.
|
|
14
|
-
- Summarize, Don't Copy: Synthesize and rephrase content in your own words. Quote only when necessary.
|
|
15
|
-
- Multiple Sources: Cross-reference at least 2 sources before drawing conclusions, unless the information is directly stated and non-controversial.
|
|
16
|
-
- Transparency: Mention which sources were used and explain how you arrived at your conclusions.
|
|
17
|
-
- Accuracy Over Brevity: Prefer detailed, technically accurate explanations over shallow summaries.
|
|
18
|
-
- If uncertain, say so. It's better to admit uncertainty than to mislead.
|
|
19
|
-
- Pick the most concrete schema types for the extracted information.
|
|
20
|
-
- Fill the schema fields as completely as possible with the information you are confident about, do not fill the fields that you are not confident about.
|
|
21
|
-
- When outputting results, you can add extra data that isn't directly related to the user's question but fits the schema.
|
|
22
|
-
|
|
23
|
-
The user may ask for:
|
|
24
|
-
|
|
25
|
-
- Technical explanations
|
|
26
|
-
- Literature reviews
|
|
27
|
-
- Comparisons
|
|
28
|
-
- Emerging trends
|
|
29
|
-
- Implementation strategies
|
|
30
|
-
|
|
31
|
-
Begin by interpreting the user's request, then:
|
|
32
|
-
|
|
33
|
-
Break it into sub-questions (if applicable).
|
|
34
|
-
|
|
35
|
-
For each sub-question, generate a clear, concise web search query.
|
|
36
|
-
|
|
37
|
-
Use `web_search`(query) to retrieve information.
|
|
38
|
-
|
|
39
|
-
Extract and synthesize relevant answers.
|
|
40
|
-
|
|
41
|
-
Output should include:
|
|
42
|
-
|
|
43
|
-
- A clear, structured answer to the user’s question.
|
|
44
|
-
- A citation list or link list of the sources used.
|
|
45
|
-
|
|
46
|
-
Optionally, follow-up suggestions or questions for deeper inquiry.
|
|
47
|
-
|
|
48
|
-
Here's your operational instructions:
|
|
49
|
-
|
|
50
|
-
1. Analyze user's request and identify key topics to search for (3 or more). Print them out.
|
|
51
|
-
2. Perform a web search for each topic.
|
|
52
|
-
3. Read and analyze the results, cross reference information from multiple sources, in case of conflict, represent the information as a range of possible values.
|
|
53
|
-
4. Create a list of follow-up topics to research. Print them out.
|
|
54
|
-
5. Perform a web search for each follow-up topic.
|
|
55
|
-
6. Read and analyze the results, cross reference information from multiple sources, in case of conflict, represent the information as a range of possible values.
|
|
56
|
-
9. Create a clear, structured answer to the user's question.
|
|
57
|
-
10. Create a citation list or link list of the sources used.
|
|
58
|
-
11. Select the most concrete schema types for the extracted information. You can use multiple different schema types. Print your decision and reasoning.
|
|
59
|
-
12. Submit the results using the specific schema.
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|