@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
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { inspect } from 'node:util';
|
|
6
|
+
import { beforeAll, describe, test } from 'vitest';
|
|
7
|
+
|
|
8
|
+
import { AIServiceEdgeClient, OllamaClient, structuredOutputParser } from '@dxos/ai';
|
|
9
|
+
import { AI_SERVICE_ENDPOINT, EXA_API_KEY } from '@dxos/ai/testing';
|
|
10
|
+
import { type EchoDatabase } from '@dxos/echo-db';
|
|
11
|
+
import { EchoTestBuilder } from '@dxos/echo-db/testing';
|
|
12
|
+
import { getSchemaDXN } from '@dxos/echo-schema';
|
|
13
|
+
import { ConfiguredCredentialsService, FunctionExecutor, ServiceContainer, TracingService } from '@dxos/functions';
|
|
14
|
+
import { live } from '@dxos/live-object';
|
|
15
|
+
import { DataType, DataTypes } from '@dxos/schema';
|
|
16
|
+
|
|
17
|
+
import { createExtractionSchema, getSanitizedSchemaName } from './graph';
|
|
18
|
+
import { researchFn } from './research';
|
|
19
|
+
|
|
20
|
+
const REMOTE_AI = true;
|
|
21
|
+
const MOCK_SEARCH = false;
|
|
22
|
+
|
|
23
|
+
describe('Research', () => {
|
|
24
|
+
let builder: EchoTestBuilder;
|
|
25
|
+
let db: EchoDatabase;
|
|
26
|
+
let executor: FunctionExecutor;
|
|
27
|
+
|
|
28
|
+
beforeAll(async () => {
|
|
29
|
+
// TODO(dmaretskyi): Helper to scaffold this from a config.
|
|
30
|
+
builder = await new EchoTestBuilder().open();
|
|
31
|
+
const { db: db1 } = await builder.createDatabase({ indexing: { vector: true } });
|
|
32
|
+
db = db1;
|
|
33
|
+
db.graph.schemaRegistry.addSchema(DataTypes);
|
|
34
|
+
executor = new FunctionExecutor(
|
|
35
|
+
new ServiceContainer().setServices({
|
|
36
|
+
ai: {
|
|
37
|
+
client: REMOTE_AI
|
|
38
|
+
? new AIServiceEdgeClient({
|
|
39
|
+
endpoint: AI_SERVICE_ENDPOINT.REMOTE,
|
|
40
|
+
defaultGenerationOptions: {
|
|
41
|
+
// model: '@anthropic/claude-sonnet-4-20250514',
|
|
42
|
+
model: '@anthropic/claude-3-5-sonnet-20241022',
|
|
43
|
+
},
|
|
44
|
+
})
|
|
45
|
+
: new OllamaClient({
|
|
46
|
+
overrides: {
|
|
47
|
+
model: 'llama3.1:8b',
|
|
48
|
+
},
|
|
49
|
+
}),
|
|
50
|
+
},
|
|
51
|
+
credentials: new ConfiguredCredentialsService([{ service: 'exa.ai', apiKey: EXA_API_KEY }]),
|
|
52
|
+
database: { db },
|
|
53
|
+
tracing: TracingService.console,
|
|
54
|
+
}),
|
|
55
|
+
);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('should generate a research report', { timeout: 300_000 }, async () => {
|
|
59
|
+
db.add(
|
|
60
|
+
live(DataType.Organization, {
|
|
61
|
+
name: 'Notion',
|
|
62
|
+
website: 'https://www.notion.com',
|
|
63
|
+
}),
|
|
64
|
+
);
|
|
65
|
+
await db.flush({ indexes: true });
|
|
66
|
+
|
|
67
|
+
const result = await executor.invoke(researchFn, {
|
|
68
|
+
query: 'Who are the founders of Notion?',
|
|
69
|
+
mockSearch: MOCK_SEARCH,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
console.log(inspect(result, { depth: null, colors: true }));
|
|
73
|
+
console.log(JSON.stringify(result, null, 2));
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
describe('misc', () => {
|
|
78
|
+
test('createExtractionSchema', () => {
|
|
79
|
+
const _schema = createExtractionSchema(DataTypes);
|
|
80
|
+
// log.info('schema', { schema });
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test('extract schema json schema', () => {
|
|
84
|
+
const schema = createExtractionSchema(DataTypes);
|
|
85
|
+
const _parser = structuredOutputParser(schema);
|
|
86
|
+
// log.info('schema', { json: parser.tool.parameters });
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test('getSanitizedSchemaName', () => {
|
|
90
|
+
const _names = DataTypes.map(getSanitizedSchemaName);
|
|
91
|
+
// log.info('names', { names });
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test('getTypeAnnotation', () => {
|
|
95
|
+
for (const schema of DataTypes) {
|
|
96
|
+
const _dxn = getSchemaDXN(schema);
|
|
97
|
+
// log.info('dxn', { schema, dxn });
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test.skip('sanitizeObjects', () => {
|
|
102
|
+
const _TEST_DATA = {
|
|
103
|
+
objects_dxos_org_type_Project: [
|
|
104
|
+
{
|
|
105
|
+
name: 'Reor',
|
|
106
|
+
description:
|
|
107
|
+
'A private & local AI personal knowledge management app focused on high entropy thinkers. Features include Q&A chat with full context of notes, automatic connection of ideas, semantic search, and local-first architecture with LLMs and vector databases.',
|
|
108
|
+
image: 'https://reorhomepage-2-cwy0zagzg-reor-team.vercel.app/opengraph-image.jpg',
|
|
109
|
+
id: 'reor-project-01',
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
name: 'Personal AI',
|
|
113
|
+
description:
|
|
114
|
+
'A platform for creating personal AI models with unlimited memory capabilities. Features include memory stacking, data uploads, and personalized language models that can be trained on individual knowledge bases.',
|
|
115
|
+
image: 'https://cdn.prod.website-files.com/5ff65c460ce39f5ec5681c6a/663d12aab1b425e1ad40d3a6_Memory-min.jpg',
|
|
116
|
+
id: 'personal-ai-project-01',
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
name: 'IKI AI',
|
|
120
|
+
description:
|
|
121
|
+
'An AI-native workspace for research, strategy, and creative work. Offers features like AI summarization, content analysis, and team knowledge sharing capabilities.',
|
|
122
|
+
image: 'https://framerusercontent.com/assets/cI6Uo7x4q0W3uxzOt2preXjv6aE.jpg',
|
|
123
|
+
id: 'iki-ai-project-01',
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
name: 'Forethink',
|
|
127
|
+
description:
|
|
128
|
+
'A privacy-first, on-device AI system that proactively links current activities to relevant knowledge. Features real-time learning across teams and local data processing.',
|
|
129
|
+
image: 'https://framerusercontent.com/assets/XDhN6tICnlElB134JWcWXOuXc.jpeg',
|
|
130
|
+
id: 'forethink-project-01',
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
name: 'Amurex',
|
|
134
|
+
description:
|
|
135
|
+
'An invisible AI companion that handles tasks, remembers important information, and supports workflow. Includes features for meeting automation, email categorization, and cross-platform search.',
|
|
136
|
+
image: 'https://amurex.ai/ogimages/og_amurex.jpg',
|
|
137
|
+
id: 'amurex-project-01',
|
|
138
|
+
},
|
|
139
|
+
],
|
|
140
|
+
objects_dxos_org_type_Organization: [
|
|
141
|
+
{
|
|
142
|
+
name: 'Reor',
|
|
143
|
+
description:
|
|
144
|
+
'A technology company focused on developing local-first AI solutions for personal knowledge management.',
|
|
145
|
+
status: 'active',
|
|
146
|
+
website: 'https://www.reorproject.org',
|
|
147
|
+
id: 'reor-org-01',
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
name: 'Personal.ai',
|
|
151
|
+
description: 'A company specializing in personal AI development and memory management solutions.',
|
|
152
|
+
status: 'active',
|
|
153
|
+
website: 'https://www.personal.ai',
|
|
154
|
+
id: 'personal-ai-org-01',
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
name: 'IKI AI',
|
|
158
|
+
description: 'A startup backed by 500 Global, developing AI-native workspaces for knowledge workers.',
|
|
159
|
+
status: 'active',
|
|
160
|
+
website: 'https://iki.ai',
|
|
161
|
+
id: 'iki-ai-org-01',
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
name: 'Forethink.ai',
|
|
165
|
+
description:
|
|
166
|
+
'A company focused on privacy-first AI solutions for knowledge management and team collaboration.',
|
|
167
|
+
status: 'active',
|
|
168
|
+
website: 'https://www.forethink.ai',
|
|
169
|
+
id: 'forethink-org-01',
|
|
170
|
+
},
|
|
171
|
+
],
|
|
172
|
+
objects_dxos_org_type_Text: [
|
|
173
|
+
{
|
|
174
|
+
content:
|
|
175
|
+
'Current trends in AI-powered Personal Knowledge Management (PKM) systems include: 1) Shift from document-based to graph-based systems for better knowledge connection, 2) Integration of large language models for enhanced content understanding and retrieval, 3) Focus on privacy-first and local-first architectures, 4) Emphasis on automatic knowledge connection and discovery, 5) Implementation of semantic search capabilities.',
|
|
176
|
+
id: 'pkm-trends-text-01',
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
content:
|
|
180
|
+
'Key features emerging across modern PKM tools include: automated content categorization, semantic analysis and linking, personalized AI models that learn from user interaction, integration with existing workflows, and robust privacy protection. These tools are increasingly focusing on proactive knowledge surfacing rather than passive storage.',
|
|
181
|
+
id: 'pkm-features-text-01',
|
|
182
|
+
},
|
|
183
|
+
],
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
// const data = await sanitizeObjects(TYPES, TEST_DATA, db);
|
|
187
|
+
// log.info('data', { data });
|
|
188
|
+
});
|
|
189
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Schema } from 'effect';
|
|
6
|
+
|
|
7
|
+
import { AgentStatusReport, ConsolePrinter } from '@dxos/ai';
|
|
8
|
+
import { create } from '@dxos/echo-schema';
|
|
9
|
+
import { AiService, CredentialsService, DatabaseService, defineFunction, TracingService } from '@dxos/functions';
|
|
10
|
+
import { log } from '@dxos/log';
|
|
11
|
+
import { DataTypes } from '@dxos/schema';
|
|
12
|
+
|
|
13
|
+
import { createExaTool, createMockExaTool } from './exa';
|
|
14
|
+
import { createGraphWriterTool } from './graph';
|
|
15
|
+
// TODO(dmaretskyi): Vite build bug with instruction files with the same filename getting mixed-up
|
|
16
|
+
import PROMPT from './instructions-research.tpl?raw';
|
|
17
|
+
import { AISession } from '../session';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Exec external service and return the results as a Subgraph.
|
|
21
|
+
*/
|
|
22
|
+
// TODO(burdon): Rename.
|
|
23
|
+
export const researchFn = defineFunction({
|
|
24
|
+
description: 'Research the web for information',
|
|
25
|
+
inputSchema: Schema.Struct({
|
|
26
|
+
query: Schema.String.annotations({
|
|
27
|
+
description: 'The query to search for.',
|
|
28
|
+
}),
|
|
29
|
+
|
|
30
|
+
// TOOD(burdon): Move to context.
|
|
31
|
+
mockSearch: Schema.optional(Schema.Boolean).annotations({
|
|
32
|
+
description: 'Whether to use the mock search tool.',
|
|
33
|
+
default: false,
|
|
34
|
+
}),
|
|
35
|
+
}),
|
|
36
|
+
outputSchema: Schema.Struct({
|
|
37
|
+
// result: Schema.String,
|
|
38
|
+
result: Schema.Any,
|
|
39
|
+
}),
|
|
40
|
+
handler: async ({ data: { query, mockSearch }, context }) => {
|
|
41
|
+
const ai = context.getService(AiService);
|
|
42
|
+
const credentials = context.getService(CredentialsService);
|
|
43
|
+
const { db } = context.getService(DatabaseService);
|
|
44
|
+
// const queues = context.getService(QueuesService);
|
|
45
|
+
const tracing = context.getService(TracingService);
|
|
46
|
+
|
|
47
|
+
tracing.write(create(AgentStatusReport, { message: 'Researching...' }));
|
|
48
|
+
|
|
49
|
+
const exaCredential = await credentials.getCredential({ service: 'exa.ai' });
|
|
50
|
+
const searchTool = mockSearch ? createMockExaTool() : createExaTool({ apiKey: exaCredential.apiKey! });
|
|
51
|
+
|
|
52
|
+
const printer = new ConsolePrinter();
|
|
53
|
+
const session = new AISession({ operationModel: 'configured' });
|
|
54
|
+
session.message.on((message) => printer.printMessage(message));
|
|
55
|
+
session.userMessage.on((message) => printer.printMessage(message));
|
|
56
|
+
session.block.on((block) => printer.printContentBlock(block));
|
|
57
|
+
session.statusReport.on((status) => {
|
|
58
|
+
log.info('[agent] status', { status });
|
|
59
|
+
tracing.write(status);
|
|
60
|
+
});
|
|
61
|
+
session.streamEvent.on((event) => log('stream', { event }));
|
|
62
|
+
|
|
63
|
+
const graphWriteTool = createGraphWriterTool({ db, schemaTypes: DataTypes });
|
|
64
|
+
log.info('graphWriteTool', { schema: graphWriteTool.parameters });
|
|
65
|
+
|
|
66
|
+
// TODO(dmaretskyi): Consider adding this pattern as the "Graph" output mode for the session.
|
|
67
|
+
const result = await session.run({
|
|
68
|
+
client: ai.client,
|
|
69
|
+
systemPrompt: PROMPT,
|
|
70
|
+
artifacts: [],
|
|
71
|
+
tools: [searchTool, graphWriteTool],
|
|
72
|
+
history: [],
|
|
73
|
+
prompt: query,
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
result: result as any,
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// queues.contextQueue!.append(data);
|
|
81
|
+
|
|
82
|
+
// return {
|
|
83
|
+
// result: `
|
|
84
|
+
// The research results are placed in the following objects:
|
|
85
|
+
// ${data.map((object, id) => `[obj_${id}][dxn:echo:@:${object.id}]`).join('\n')}
|
|
86
|
+
// `,
|
|
87
|
+
// };
|
|
88
|
+
},
|
|
89
|
+
});
|
package/src/session/index.ts
CHANGED
|
@@ -5,15 +5,15 @@
|
|
|
5
5
|
import { Schema } from 'effect';
|
|
6
6
|
import { describe, test } from 'vitest';
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { AIServiceEdgeClient, ConsolePrinter, createTool, ToolResult } from '@dxos/ai';
|
|
9
|
+
import { AI_SERVICE_ENDPOINT } from '@dxos/ai/testing';
|
|
10
|
+
import { ArtifactId, defineArtifact } from '@dxos/artifact';
|
|
10
11
|
import { Type } from '@dxos/echo';
|
|
11
12
|
import { create, ObjectId } from '@dxos/echo-schema';
|
|
12
13
|
import { DXN } from '@dxos/keys';
|
|
13
14
|
import { log } from '@dxos/log';
|
|
14
15
|
|
|
15
16
|
import { AISession } from './session';
|
|
16
|
-
import { AI_SERVICE_ENDPOINT, ConsolePrinter } from '../testing';
|
|
17
17
|
|
|
18
18
|
// Define a calendar event artifact schema.
|
|
19
19
|
const CalendarEventSchema = Schema.Struct({
|
|
@@ -22,7 +22,7 @@ const CalendarEventSchema = Schema.Struct({
|
|
|
22
22
|
endTime: Schema.String,
|
|
23
23
|
description: Schema.String,
|
|
24
24
|
}).pipe(
|
|
25
|
-
Type.
|
|
25
|
+
Type.Obj({
|
|
26
26
|
typename: 'example.com/type/CalendarEvent',
|
|
27
27
|
version: '0.1.0',
|
|
28
28
|
}),
|
|
@@ -48,7 +48,7 @@ describe.skip('AISession with Ollama', () => {
|
|
|
48
48
|
instructions: 'Use this to create and query calendar events.',
|
|
49
49
|
schema: CalendarEventSchema,
|
|
50
50
|
tools: [
|
|
51
|
-
|
|
51
|
+
createTool('calendar', {
|
|
52
52
|
name: 'query',
|
|
53
53
|
description: 'Query the calendar for events',
|
|
54
54
|
schema: Schema.Struct({}),
|
|
@@ -65,7 +65,7 @@ describe.skip('AISession with Ollama', () => {
|
|
|
65
65
|
instructions: 'Use this to create and manage tables. Each table has a unique id.',
|
|
66
66
|
schema: Schema.Struct({}),
|
|
67
67
|
tools: [
|
|
68
|
-
|
|
68
|
+
createTool('table', {
|
|
69
69
|
name: 'create',
|
|
70
70
|
description: 'Create a table',
|
|
71
71
|
schema: Schema.Struct({
|
|
@@ -89,7 +89,7 @@ describe.skip('AISession with Ollama', () => {
|
|
|
89
89
|
'Use this to create and manage maps. Maps source data from tables. Table id is required to create a map.',
|
|
90
90
|
schema: Schema.Struct({}),
|
|
91
91
|
tools: [
|
|
92
|
-
|
|
92
|
+
createTool('map', {
|
|
93
93
|
name: 'create',
|
|
94
94
|
description: 'Create a map',
|
|
95
95
|
schema: Schema.Struct({
|
package/src/session/session.ts
CHANGED
|
@@ -5,23 +5,29 @@
|
|
|
5
5
|
import { Option, Schema } from 'effect';
|
|
6
6
|
|
|
7
7
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
AgentStatusReport,
|
|
9
|
+
isToolUse,
|
|
10
|
+
runTools,
|
|
11
|
+
type AgentStatus,
|
|
10
12
|
structuredOutputParser,
|
|
11
|
-
|
|
12
|
-
type
|
|
13
|
+
type AIServiceClient,
|
|
14
|
+
type GenerationStream,
|
|
15
|
+
type GenerateRequest,
|
|
16
|
+
Message,
|
|
13
17
|
type MessageContentBlock,
|
|
14
|
-
|
|
15
|
-
|
|
18
|
+
MixedStreamParser,
|
|
19
|
+
ToolResult,
|
|
20
|
+
createTool,
|
|
21
|
+
type ExecutableTool,
|
|
22
|
+
} from '@dxos/ai';
|
|
23
|
+
import { type ArtifactDefinition } from '@dxos/artifact';
|
|
16
24
|
import { Event, synchronized } from '@dxos/async';
|
|
17
25
|
import { ObjectVersion } from '@dxos/echo-db';
|
|
18
26
|
import { create, type ObjectId } from '@dxos/echo-schema';
|
|
19
27
|
import { invariant } from '@dxos/invariant';
|
|
20
28
|
import { log } from '@dxos/log';
|
|
21
29
|
|
|
22
|
-
import { isToolUse, runTools } from './tools';
|
|
23
30
|
import { VersionPin } from './version-pin';
|
|
24
|
-
import { MixedStreamParser, type AIServiceClient, type GenerateRequest, type GenerationStream } from '../ai-service';
|
|
25
31
|
|
|
26
32
|
/**
|
|
27
33
|
* Contains message history, tools, current context.
|
|
@@ -58,7 +64,7 @@ export type SessionRunOptions = {
|
|
|
58
64
|
/**
|
|
59
65
|
* Non-artifact specific tools.
|
|
60
66
|
*/
|
|
61
|
-
tools:
|
|
67
|
+
tools: ExecutableTool[];
|
|
62
68
|
|
|
63
69
|
history: Message[];
|
|
64
70
|
|
|
@@ -129,16 +135,28 @@ export class AISession {
|
|
|
129
135
|
*/
|
|
130
136
|
public readonly userMessage = new Event<Message>();
|
|
131
137
|
|
|
138
|
+
/**
|
|
139
|
+
* Agent self-reporting its status.
|
|
140
|
+
*/
|
|
141
|
+
public readonly statusReport = new Event<AgentStatus>();
|
|
142
|
+
|
|
143
|
+
public readonly toolStatusReport = new Event<{ message: Message; status: AgentStatus }>();
|
|
144
|
+
|
|
132
145
|
constructor(private readonly _options: AiSessionOptions) {
|
|
133
146
|
// Message complete.
|
|
134
147
|
this._parser.message.on((message) => {
|
|
135
148
|
this._pending.push(message);
|
|
136
149
|
});
|
|
150
|
+
this._parser.block.on((block) => {
|
|
151
|
+
if (block.type === 'text' && block.disposition === 'status') {
|
|
152
|
+
this.statusReport.emit(create(AgentStatusReport, { message: block.text }));
|
|
153
|
+
}
|
|
154
|
+
});
|
|
137
155
|
}
|
|
138
156
|
|
|
139
157
|
@synchronized
|
|
140
158
|
async run(options: SessionRunOptions): Promise<Message[]> {
|
|
141
|
-
const systemTools:
|
|
159
|
+
const systemTools: ExecutableTool[] = [];
|
|
142
160
|
switch (this._options.operationModel) {
|
|
143
161
|
case 'planning':
|
|
144
162
|
systemTools.push(this._createQueryArtifactsTool(options.artifacts), this._createPlanningTool(options));
|
|
@@ -164,13 +182,14 @@ export class AISession {
|
|
|
164
182
|
this._pending = [await this._formatUserPrompt(options.artifactDiffResolver, options.prompt, options.history)];
|
|
165
183
|
this.userMessage.emit(this._pending.at(-1)!);
|
|
166
184
|
this._stream = undefined;
|
|
185
|
+
|
|
167
186
|
let error: Error | undefined;
|
|
168
187
|
|
|
169
188
|
const requiredArtifactIds = new Set<string>(options.requiredArtifactIds ?? []);
|
|
170
189
|
try {
|
|
171
190
|
let more = false;
|
|
172
191
|
do {
|
|
173
|
-
const tools = [
|
|
192
|
+
const tools: ExecutableTool[] = [
|
|
174
193
|
...systemTools,
|
|
175
194
|
...options.tools,
|
|
176
195
|
...options.artifacts
|
|
@@ -215,6 +234,7 @@ export class AISession {
|
|
|
215
234
|
message: this._pending.at(-1)!,
|
|
216
235
|
tools,
|
|
217
236
|
extensions: options.extensions ?? {},
|
|
237
|
+
reportStatus: (status) => this._onToolStatusReport(message, status),
|
|
218
238
|
});
|
|
219
239
|
|
|
220
240
|
log('tool response', { response });
|
|
@@ -246,7 +266,10 @@ export class AISession {
|
|
|
246
266
|
return this._pending;
|
|
247
267
|
}
|
|
248
268
|
|
|
249
|
-
async runStructured<S extends Schema.Schema.AnyNoContext>(
|
|
269
|
+
async runStructured<S extends Schema.Schema.AnyNoContext>(
|
|
270
|
+
schema: S,
|
|
271
|
+
options: SessionRunOptions,
|
|
272
|
+
): Promise<Schema.Schema.Type<S>> {
|
|
250
273
|
const parser = structuredOutputParser(schema);
|
|
251
274
|
const result = await this.run({
|
|
252
275
|
...options,
|
|
@@ -293,8 +316,8 @@ export class AISession {
|
|
|
293
316
|
});
|
|
294
317
|
}
|
|
295
318
|
|
|
296
|
-
private _createQueryArtifactsTool(artifacts: ArtifactDefinition[]) {
|
|
297
|
-
return
|
|
319
|
+
private _createQueryArtifactsTool(artifacts: ArtifactDefinition[]): ExecutableTool {
|
|
320
|
+
return createTool('system', {
|
|
298
321
|
name: 'query_artifact_definitions',
|
|
299
322
|
description: 'Query the available artifact definitions',
|
|
300
323
|
schema: Schema.Struct({}),
|
|
@@ -313,8 +336,8 @@ export class AISession {
|
|
|
313
336
|
private _createRequireTool(
|
|
314
337
|
artifacts: ArtifactDefinition[],
|
|
315
338
|
onRequire: (artifactDefinitionIds: readonly string[]) => void,
|
|
316
|
-
) {
|
|
317
|
-
return
|
|
339
|
+
): ExecutableTool {
|
|
340
|
+
return createTool('system', {
|
|
318
341
|
name: 'require_artifact_definitions',
|
|
319
342
|
description:
|
|
320
343
|
'Require the use of specific artifact definitions. This will allow the model to interact with artifact definitions and use their tools.',
|
|
@@ -341,8 +364,8 @@ export class AISession {
|
|
|
341
364
|
});
|
|
342
365
|
}
|
|
343
366
|
|
|
344
|
-
private _createPlanningTool(options: SessionRunOptions) {
|
|
345
|
-
return
|
|
367
|
+
private _createPlanningTool(options: SessionRunOptions): ExecutableTool {
|
|
368
|
+
return createTool('system', {
|
|
346
369
|
name: 'create_plan',
|
|
347
370
|
description:
|
|
348
371
|
'Create a plan. Make sure that each step is independent and can be executed solely on the data returned by the previous step. The steps only share the data that is specified in the plan.',
|
|
@@ -425,7 +448,11 @@ export class AISession {
|
|
|
425
448
|
});
|
|
426
449
|
}
|
|
427
450
|
|
|
428
|
-
|
|
451
|
+
private _onToolStatusReport(message: Message, status: AgentStatus): void {
|
|
452
|
+
this.toolStatusReport.emit({ message, status });
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
abort(): void {
|
|
429
456
|
this._stream?.abort();
|
|
430
457
|
}
|
|
431
458
|
}
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
import { Schema } from 'effect';
|
|
6
6
|
|
|
7
|
-
import type
|
|
8
|
-
import type
|
|
7
|
+
import { type MessageContentBlock } from '@dxos/ai';
|
|
8
|
+
import { type ObjectVersion } from '@dxos/echo-db';
|
|
9
9
|
import { getVersion } from '@dxos/echo-db';
|
|
10
10
|
import { ObjectId, type BaseEchoObject } from '@dxos/echo-schema';
|
|
11
11
|
|
|
@@ -21,7 +21,6 @@ const VersionPinSchema = Schema.Struct({
|
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* Used to pin a specific version of an object during the course of a conversation.
|
|
24
|
-
*
|
|
25
24
|
* This allows us to detect when the object changes during the course of the conversation.
|
|
26
25
|
*/
|
|
27
26
|
export interface VersionPin extends Schema.Schema.Type<typeof VersionPinSchema> {}
|