@dxos/assistant 0.8.2-staging.7ac8446 → 0.8.3-main.672df60
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 +1909 -228
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +1907 -229
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +1910 -228
- 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 +51 -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 +12 -0
- package/dist/types/src/blueprint/logger.d.ts.map +1 -0
- package/dist/types/src/blueprint/machine.d.ts +122 -0
- 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 -3
- 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 +40 -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 +2 -0
- package/dist/types/src/research/research.test.d.ts.map +1 -0
- package/dist/types/src/session/index.d.ts +1 -0
- package/dist/types/src/session/index.d.ts.map +1 -1
- package/dist/types/src/session/session.d.ts +80 -35
- package/dist/types/src/session/session.d.ts.map +1 -1
- package/dist/types/src/session/version-pin.d.ts +21 -0
- package/dist/types/src/session/version-pin.d.ts.map +1 -0
- package/dist/types/src/session/version-pin.test.d.ts +2 -0
- package/dist/types/src/session/version-pin.test.d.ts.map +1 -0
- 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 -6
- 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/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +26 -35
- package/src/blueprint/blueprint.test.ts +149 -0
- package/src/blueprint/blueprint.ts +71 -0
- package/src/blueprint/index.ts +7 -0
- package/src/blueprint/logger.ts +109 -0
- package/src/blueprint/machine.ts +214 -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 -3
- package/src/research/exa.ts +100 -0
- package/src/research/graph.test.ts +15 -0
- package/src/research/graph.ts +339 -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 +1 -0
- package/src/session/session.test.ts +39 -67
- package/src/session/session.ts +328 -155
- package/src/session/version-pin.test.ts +26 -0
- package/src/session/version-pin.ts +48 -0
- 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 -7
- package/src/typedefs.d.ts +8 -0
- package/src/types.ts +8 -0
- package/src/typings.d.ts +8 -0
- package/dist/lib/browser/chunk-PND5VR6D.mjs +0 -2315
- package/dist/lib/browser/chunk-PND5VR6D.mjs.map +0 -7
- package/dist/lib/browser/testing/index.mjs +0 -621
- package/dist/lib/browser/testing/index.mjs.map +0 -7
- package/dist/lib/node/chunk-IBOBRBDF.cjs +0 -2326
- package/dist/lib/node/chunk-IBOBRBDF.cjs.map +0 -7
- package/dist/lib/node/testing/index.cjs +0 -637
- package/dist/lib/node/testing/index.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-DCQJOLSR.mjs +0 -2317
- package/dist/lib/node-esm/chunk-DCQJOLSR.mjs.map +0 -7
- package/dist/lib/node-esm/testing/index.mjs +0 -622
- 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 -19
- 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 -88
- package/dist/types/src/ai-service/message-collector.d.ts.map +0 -1
- package/dist/types/src/ai-service/ollama-client.d.ts +0 -39
- package/dist/types/src/ai-service/ollama-client.d.ts.map +0 -1
- package/dist/types/src/ai-service/parser.d.ts +0 -138
- package/dist/types/src/ai-service/parser.d.ts.map +0 -1
- package/dist/types/src/ai-service/service.d.ts +0 -9
- 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 -7
- 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 -167
- 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/conversation/conversation.d.ts +0 -80
- package/dist/types/src/conversation/conversation.d.ts.map +0 -1
- package/dist/types/src/conversation/conversation.test.d.ts +0 -2
- package/dist/types/src/conversation/conversation.test.d.ts.map +0 -1
- package/dist/types/src/conversation/index.d.ts +0 -2
- package/dist/types/src/conversation/index.d.ts.map +0 -1
- package/dist/types/src/conversation/types.d.ts +0 -79
- package/dist/types/src/conversation/types.d.ts.map +0 -1
- package/dist/types/src/cypher/ast.d.ts +0 -56
- package/dist/types/src/cypher/ast.d.ts.map +0 -1
- package/dist/types/src/cypher/combinators.d.ts +0 -14
- package/dist/types/src/cypher/combinators.d.ts.map +0 -1
- package/dist/types/src/cypher/combinators.test.d.ts +0 -2
- package/dist/types/src/cypher/combinators.test.d.ts.map +0 -1
- package/dist/types/src/cypher/echo-data-source.d.ts +0 -16
- package/dist/types/src/cypher/echo-data-source.d.ts.map +0 -1
- package/dist/types/src/cypher/execution-plan.d.ts +0 -49
- package/dist/types/src/cypher/execution-plan.d.ts.map +0 -1
- package/dist/types/src/cypher/execution-plan.test.d.ts +0 -2
- package/dist/types/src/cypher/execution-plan.test.d.ts.map +0 -1
- package/dist/types/src/cypher/index.d.ts +0 -5
- package/dist/types/src/cypher/index.d.ts.map +0 -1
- package/dist/types/src/cypher/parjs.d.ts +0 -4
- package/dist/types/src/cypher/parjs.d.ts.map +0 -1
- package/dist/types/src/cypher/parser.d.ts +0 -6
- package/dist/types/src/cypher/parser.d.ts.map +0 -1
- package/dist/types/src/cypher/query-executor.d.ts +0 -26
- package/dist/types/src/cypher/query-executor.d.ts.map +0 -1
- package/dist/types/src/cypher/query-executor.test.d.ts +0 -2
- package/dist/types/src/cypher/query-executor.test.d.ts.map +0 -1
- package/dist/types/src/cypher/schema.d.ts +0 -12
- package/dist/types/src/cypher/schema.d.ts.map +0 -1
- package/dist/types/src/cypher/schema.test.d.ts +0 -2
- package/dist/types/src/cypher/schema.test.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/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 -50
- 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 -265
- package/src/ai-service/defs.ts +0 -39
- package/src/ai-service/edge-client.ts +0 -67
- 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 -499
- package/src/ai-service/parser.ts +0 -358
- package/src/ai-service/service.ts +0 -15
- 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 -22
- 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 -103
- 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/conversation/conversation.test.ts +0 -73
- package/src/conversation/conversation.ts +0 -257
- package/src/conversation/index.ts +0 -5
- package/src/conversation/types.ts +0 -129
- package/src/cypher/ast.ts +0 -75
- package/src/cypher/combinators.test.ts +0 -137
- package/src/cypher/combinators.ts +0 -148
- package/src/cypher/echo-data-source.ts +0 -105
- package/src/cypher/execution-plan.test.ts +0 -44
- package/src/cypher/execution-plan.ts +0 -208
- package/src/cypher/index.ts +0 -8
- package/src/cypher/parjs-shims.d.ts +0 -10
- package/src/cypher/parjs.ts +0 -10
- package/src/cypher/parser.ts +0 -19
- package/src/cypher/query-executor.test.ts +0 -47
- package/src/cypher/query-executor.ts +0 -145
- package/src/cypher/schema.test.ts +0 -17
- package/src/cypher/schema.ts +0 -86
- 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/query-promts.ts +0 -75
- package/src/testing/query.test.ts +0 -91
- package/src/testing/test-data.ts +0 -372
- package/src/testing/test-schema.ts +0 -80
- 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
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Schema } from 'effect';
|
|
6
|
+
import { describe, test } from 'vitest';
|
|
7
|
+
|
|
8
|
+
import { AIServiceEdgeClient, ToolRegistry, ToolResult, createTool } from '@dxos/ai';
|
|
9
|
+
import { AI_SERVICE_ENDPOINT, EXA_API_KEY } from '@dxos/ai/testing';
|
|
10
|
+
import { ArtifactId } from '@dxos/artifact';
|
|
11
|
+
import { EchoTestBuilder } from '@dxos/echo-db/testing';
|
|
12
|
+
import { create } from '@dxos/echo-schema';
|
|
13
|
+
import { DataType, DataTypes } from '@dxos/schema';
|
|
14
|
+
|
|
15
|
+
import { BlueprintBuilder } from './blueprint';
|
|
16
|
+
import { setConsolePrinter } from './logger';
|
|
17
|
+
import { BlueprintMachine } from './machine';
|
|
18
|
+
import { TEST_EMAILS } from './test-data';
|
|
19
|
+
import { createGraphWriterTool, createLocalSearchTool } from '../research';
|
|
20
|
+
import { createExaTool } from '../research/exa';
|
|
21
|
+
|
|
22
|
+
// TODO(burdon): Conslidate with existing artifact definition and create JSON DSL.
|
|
23
|
+
|
|
24
|
+
// TODO(burdon): Don't run on CI.
|
|
25
|
+
describe.skip('Blueprint', () => {
|
|
26
|
+
const aiService = new AIServiceEdgeClient({
|
|
27
|
+
endpoint: AI_SERVICE_ENDPOINT.REMOTE,
|
|
28
|
+
defaultGenerationOptions: {
|
|
29
|
+
// model: '@anthropic/claude-sonnet-4-20250514',
|
|
30
|
+
model: '@anthropic/claude-3-5-sonnet-20241022',
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('follows a simple blueprint', { timeout: 60_000 }, async () => {
|
|
35
|
+
const blueprint = BlueprintBuilder.create()
|
|
36
|
+
.step('Generate an idea for a new product. Do not use any external tools for this.')
|
|
37
|
+
.step('Write a short description of the product.')
|
|
38
|
+
.step('Run a market research to see if the product is viable. Do not use any external tools for this.')
|
|
39
|
+
.step('Write a pitch deck for the product')
|
|
40
|
+
.build();
|
|
41
|
+
|
|
42
|
+
const registry = new ToolRegistry([]);
|
|
43
|
+
const machine = new BlueprintMachine(registry, blueprint);
|
|
44
|
+
setConsolePrinter(machine, true);
|
|
45
|
+
await machine.runToCompletion({ aiService });
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test('email bot', { timeout: 60_000 }, async () => {
|
|
49
|
+
const replyTool = createTool('email', {
|
|
50
|
+
name: 'reply',
|
|
51
|
+
description: 'Reply to the email',
|
|
52
|
+
schema: Schema.Struct({
|
|
53
|
+
toEmail: ArtifactId,
|
|
54
|
+
subject: Schema.String.annotations({
|
|
55
|
+
description: 'The subject of the reply',
|
|
56
|
+
}),
|
|
57
|
+
body: Schema.String.annotations({
|
|
58
|
+
description: 'The body of the reply',
|
|
59
|
+
}),
|
|
60
|
+
}),
|
|
61
|
+
execute: async (params) => {
|
|
62
|
+
console.log('reply', params);
|
|
63
|
+
return ToolResult.Success('Sent!');
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const labelTool = createTool('email', {
|
|
68
|
+
name: 'label',
|
|
69
|
+
description: 'Apply a label to the email',
|
|
70
|
+
schema: Schema.Struct({
|
|
71
|
+
toEmail: ArtifactId,
|
|
72
|
+
label: Schema.String.annotations({
|
|
73
|
+
description: 'The label to apply to the email',
|
|
74
|
+
}),
|
|
75
|
+
}),
|
|
76
|
+
execute: async (params) => {
|
|
77
|
+
return ToolResult.Success('Labeled!');
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const blueprint = BlueprintBuilder.create()
|
|
82
|
+
.step(
|
|
83
|
+
'Determine if the email is introduction, question, or spam. Bail if email does not fit into one of these categories.',
|
|
84
|
+
)
|
|
85
|
+
.step('If the email is spam, label it as spam and do not respond.', {
|
|
86
|
+
tools: [labelTool.id],
|
|
87
|
+
})
|
|
88
|
+
.step(
|
|
89
|
+
'If the email is an introduction, respond with a short introduction of yourself and ask for more information.',
|
|
90
|
+
{
|
|
91
|
+
tools: [replyTool.id],
|
|
92
|
+
},
|
|
93
|
+
)
|
|
94
|
+
.step('If the email is a question, respond with a short answer and ask for more information.', {
|
|
95
|
+
tools: [replyTool.id],
|
|
96
|
+
})
|
|
97
|
+
.build();
|
|
98
|
+
|
|
99
|
+
const registry = new ToolRegistry([replyTool, labelTool]);
|
|
100
|
+
const machine = new BlueprintMachine(registry, blueprint);
|
|
101
|
+
setConsolePrinter(machine);
|
|
102
|
+
await machine.runToCompletion({ aiService, input: TEST_EMAILS[0] });
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test.only('research', { timeout: 120_000 }, async () => {
|
|
106
|
+
const builder = await new EchoTestBuilder().open();
|
|
107
|
+
const { db } = await builder.createDatabase({ indexing: { vector: true }, types: DataTypes });
|
|
108
|
+
|
|
109
|
+
const [org1] = [
|
|
110
|
+
db.add(
|
|
111
|
+
create(DataType.Organization, {
|
|
112
|
+
name: 'Exa',
|
|
113
|
+
website: 'https://exa.ai',
|
|
114
|
+
description: 'An AI-powered search engine company building search infrastructure for AI agents',
|
|
115
|
+
}),
|
|
116
|
+
),
|
|
117
|
+
db.add(
|
|
118
|
+
create(DataType.Organization, {
|
|
119
|
+
name: 'Cresta',
|
|
120
|
+
website: 'https://cresta.ai',
|
|
121
|
+
description: 'A company that builds AI agents',
|
|
122
|
+
}),
|
|
123
|
+
),
|
|
124
|
+
];
|
|
125
|
+
|
|
126
|
+
await db.flush({ indexes: true });
|
|
127
|
+
|
|
128
|
+
const webSearchTool = createExaTool({ apiKey: EXA_API_KEY });
|
|
129
|
+
const localSearchTool = createLocalSearchTool(db);
|
|
130
|
+
const graphWriterTool = createGraphWriterTool({ db, schemaTypes: DataTypes });
|
|
131
|
+
const registry = new ToolRegistry([webSearchTool, localSearchTool, graphWriterTool]);
|
|
132
|
+
|
|
133
|
+
const blueprint = BlueprintBuilder.create()
|
|
134
|
+
.step('Research founders of the organization. Do deep research.', {
|
|
135
|
+
tools: [webSearchTool.id],
|
|
136
|
+
})
|
|
137
|
+
.step('Based on your research select matching entires that are already in the graph', {
|
|
138
|
+
tools: [localSearchTool.id],
|
|
139
|
+
})
|
|
140
|
+
.step('Add researched data to the graph', {
|
|
141
|
+
tools: [localSearchTool.id, graphWriterTool.id],
|
|
142
|
+
})
|
|
143
|
+
.build();
|
|
144
|
+
|
|
145
|
+
const machine = new BlueprintMachine(registry, blueprint);
|
|
146
|
+
setConsolePrinter(machine, true);
|
|
147
|
+
await machine.runToCompletion({ aiService, input: org1 });
|
|
148
|
+
});
|
|
149
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Schema } from 'effect';
|
|
6
|
+
|
|
7
|
+
import { Obj, Type } from '@dxos/echo';
|
|
8
|
+
import { ObjectId } from '@dxos/keys';
|
|
9
|
+
|
|
10
|
+
export const BlueprintStepSchema = Schema.Struct({
|
|
11
|
+
id: ObjectId,
|
|
12
|
+
instructions: Schema.String,
|
|
13
|
+
tools: Schema.Array(Schema.String),
|
|
14
|
+
});
|
|
15
|
+
export type BlueprintStep = Schema.Schema.Type<typeof BlueprintStepSchema>;
|
|
16
|
+
|
|
17
|
+
export const BlueprintSchema = Schema.Struct({
|
|
18
|
+
steps: Schema.Array(BlueprintStepSchema.pipe(Schema.omit('id'))),
|
|
19
|
+
});
|
|
20
|
+
export type BlueprintDef = Schema.Schema.Type<typeof BlueprintSchema>;
|
|
21
|
+
|
|
22
|
+
export const Blueprint = Schema.Struct({
|
|
23
|
+
name: Schema.optional(Schema.String),
|
|
24
|
+
steps: Schema.Array(BlueprintStepSchema),
|
|
25
|
+
}).pipe(Type.Obj({ typename: 'dxos.org/type/Blueprint', version: '0.1.0' }));
|
|
26
|
+
export type Blueprint = Schema.Schema.Type<typeof Blueprint>;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Blueprint builder API.
|
|
30
|
+
*/
|
|
31
|
+
export namespace BlueprintBuilder {
|
|
32
|
+
export const create = () => new Builder();
|
|
33
|
+
|
|
34
|
+
class Builder {
|
|
35
|
+
private readonly _steps: BlueprintStep[] = [];
|
|
36
|
+
|
|
37
|
+
step(instructions: string, options?: { tools?: string[] }): Builder {
|
|
38
|
+
this._steps.push({
|
|
39
|
+
id: ObjectId.random(),
|
|
40
|
+
instructions,
|
|
41
|
+
tools: options?.tools ?? [],
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
build(): Blueprint {
|
|
48
|
+
return Obj.make(Blueprint, { steps: this._steps });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Blueprint parser API.
|
|
55
|
+
*/
|
|
56
|
+
export namespace BlueprintParser {
|
|
57
|
+
export const create = () => new Parser();
|
|
58
|
+
|
|
59
|
+
class Parser {
|
|
60
|
+
parse({ steps }: BlueprintDef): Blueprint {
|
|
61
|
+
const builder = BlueprintBuilder.create();
|
|
62
|
+
for (const step of steps) {
|
|
63
|
+
builder.step(step.instructions, {
|
|
64
|
+
tools: (step.tools ?? []) as string[],
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return builder.build();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type ReadonlySignal, signal } from '@preact/signals-core';
|
|
6
|
+
import chalk from 'chalk';
|
|
7
|
+
|
|
8
|
+
import { ConsolePrinter } from '@dxos/ai';
|
|
9
|
+
import { type CleanupFn, combine } from '@dxos/async';
|
|
10
|
+
|
|
11
|
+
import { type Blueprint } from './blueprint';
|
|
12
|
+
import { type BlueprintMachine, type BlueprintMachineState } from './machine';
|
|
13
|
+
|
|
14
|
+
/* eslint-disable no-console */
|
|
15
|
+
|
|
16
|
+
// Force chalk colors on for tests.
|
|
17
|
+
chalk.level = 2;
|
|
18
|
+
|
|
19
|
+
export class Logger {
|
|
20
|
+
private _messages = signal<string[]>([]);
|
|
21
|
+
|
|
22
|
+
get messages(): ReadonlySignal<string[]> {
|
|
23
|
+
return this._messages;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
clear() {
|
|
27
|
+
this._messages.value = [];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
log(message: string) {
|
|
31
|
+
this._messages.value = [...this._messages.value, message];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const setLogger = (machine: BlueprintMachine, logger: Logger): CleanupFn => {
|
|
36
|
+
return combine(
|
|
37
|
+
machine.begin.on(() => {
|
|
38
|
+
logger.log('Starting...');
|
|
39
|
+
}),
|
|
40
|
+
machine.stepStart.on((step) => {
|
|
41
|
+
const index = machine.blueprint.steps.indexOf(step);
|
|
42
|
+
logger.log(`Step ${index + 1} of ${machine.blueprint.steps.length}`);
|
|
43
|
+
logger.log(`Instructions: ${step.instructions}`);
|
|
44
|
+
}),
|
|
45
|
+
machine.stepComplete.on((step) => {
|
|
46
|
+
const trace = machine.state.trace.find((t) => t.stepId === step.id);
|
|
47
|
+
logger.log(`Complete: ${trace?.comment}`);
|
|
48
|
+
}),
|
|
49
|
+
machine.end.on(() => {
|
|
50
|
+
logger.log('OK');
|
|
51
|
+
}),
|
|
52
|
+
);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const setConsolePrinter = (machine: BlueprintMachine, verbose = false): CleanupFn => {
|
|
56
|
+
const printer = new ConsolePrinter();
|
|
57
|
+
return combine(
|
|
58
|
+
machine.begin.on(() => printTrace(machine.blueprint, machine.state)),
|
|
59
|
+
machine.stepStart.on((step) =>
|
|
60
|
+
console.log(
|
|
61
|
+
`\n${chalk.magenta(`${chalk.bold(`STEP ${machine.blueprint.steps.indexOf(step) + 1} of ${machine.blueprint.steps.length}:`)} ${step.instructions}`)}\n`,
|
|
62
|
+
),
|
|
63
|
+
),
|
|
64
|
+
machine.stepComplete.on(() => printTrace(machine.blueprint, machine.state)),
|
|
65
|
+
machine.end.on(() => console.log('DONE')),
|
|
66
|
+
verbose
|
|
67
|
+
? [
|
|
68
|
+
machine.message.on((msg) => printer.printMessage(msg)),
|
|
69
|
+
machine.block.on((block) => printer.printContentBlock(block)),
|
|
70
|
+
]
|
|
71
|
+
: [],
|
|
72
|
+
);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const BREAK_LINE = `\n${'_'.repeat(80)}\n`;
|
|
76
|
+
|
|
77
|
+
const printTrace = (blueprint: Blueprint, state: BlueprintMachineState) => {
|
|
78
|
+
console.group(chalk.bold('\nBlueprint'));
|
|
79
|
+
blueprint.steps.forEach((step) => {
|
|
80
|
+
const traceStep = state.trace.find((t) => t.stepId === step.id);
|
|
81
|
+
|
|
82
|
+
let color = chalk.gray; // Not executed.
|
|
83
|
+
let bullet = '○';
|
|
84
|
+
if (traceStep) {
|
|
85
|
+
switch (traceStep.status) {
|
|
86
|
+
case 'done':
|
|
87
|
+
color = chalk.green;
|
|
88
|
+
bullet = '✓';
|
|
89
|
+
break;
|
|
90
|
+
case 'skipped':
|
|
91
|
+
color = chalk.blue;
|
|
92
|
+
bullet = '↓';
|
|
93
|
+
break;
|
|
94
|
+
case 'bailed':
|
|
95
|
+
color = chalk.red;
|
|
96
|
+
bullet = '✗';
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
console.log(color(`\n${bullet} ${step.instructions}`));
|
|
102
|
+
if (traceStep?.comment) {
|
|
103
|
+
console.log(chalk.white(` ↳ ${traceStep.comment}`));
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
console.groupEnd();
|
|
108
|
+
console.log(BREAK_LINE);
|
|
109
|
+
};
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Match, Schema } from 'effect';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
createTool,
|
|
9
|
+
type AIServiceClient,
|
|
10
|
+
Message,
|
|
11
|
+
type MessageContentBlock,
|
|
12
|
+
ToolResult,
|
|
13
|
+
type ToolUseContentBlock,
|
|
14
|
+
type ToolRegistry,
|
|
15
|
+
} from '@dxos/ai';
|
|
16
|
+
import { Event } from '@dxos/async';
|
|
17
|
+
import { create } from '@dxos/echo-schema';
|
|
18
|
+
import { type ObjectId } from '@dxos/keys';
|
|
19
|
+
import { log } from '@dxos/log';
|
|
20
|
+
import { isNonNullable } from '@dxos/util';
|
|
21
|
+
|
|
22
|
+
import type { Blueprint, BlueprintStep } from './blueprint';
|
|
23
|
+
import { AISession } from '../session';
|
|
24
|
+
|
|
25
|
+
export type BlueprintTraceStep = {
|
|
26
|
+
status: 'done' | 'bailed' | 'skipped';
|
|
27
|
+
stepId: ObjectId;
|
|
28
|
+
comment: string;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type BlueprintMachineState = {
|
|
32
|
+
history: Message[];
|
|
33
|
+
trace: BlueprintTraceStep[];
|
|
34
|
+
state: 'working' | 'bail' | 'done';
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const INITIAL_STATE: BlueprintMachineState = {
|
|
38
|
+
state: 'working',
|
|
39
|
+
history: [],
|
|
40
|
+
trace: [],
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
type ExecutionOptions = {
|
|
44
|
+
aiService: AIServiceClient;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Input to the blueprint.
|
|
48
|
+
*/
|
|
49
|
+
input?: unknown;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Blueprint state machine.
|
|
54
|
+
*/
|
|
55
|
+
export class BlueprintMachine {
|
|
56
|
+
public readonly begin = new Event<void>();
|
|
57
|
+
public readonly end = new Event<void>();
|
|
58
|
+
public readonly stepStart = new Event<BlueprintStep>();
|
|
59
|
+
public readonly stepComplete = new Event<BlueprintStep>();
|
|
60
|
+
public readonly message = new Event<Message>();
|
|
61
|
+
public readonly block = new Event<MessageContentBlock>();
|
|
62
|
+
|
|
63
|
+
state: BlueprintMachineState = structuredClone(INITIAL_STATE);
|
|
64
|
+
|
|
65
|
+
constructor(
|
|
66
|
+
readonly registry: ToolRegistry,
|
|
67
|
+
readonly blueprint: Blueprint,
|
|
68
|
+
) {}
|
|
69
|
+
|
|
70
|
+
async runToCompletion(options: ExecutionOptions): Promise<void> {
|
|
71
|
+
log.info('runToCompletion', options);
|
|
72
|
+
|
|
73
|
+
this.begin.emit();
|
|
74
|
+
let firstStep = true;
|
|
75
|
+
while (this.state.state !== 'done') {
|
|
76
|
+
const input = firstStep ? options.input : undefined;
|
|
77
|
+
|
|
78
|
+
firstStep = false;
|
|
79
|
+
this.state = await this._execStep(this.state, {
|
|
80
|
+
input,
|
|
81
|
+
aiService: options.aiService,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
this.stepComplete.emit(this.blueprint.steps.find((step) => step.id === this.state.trace.at(-1)?.stepId)!);
|
|
85
|
+
|
|
86
|
+
if (this.state.state === 'bail') {
|
|
87
|
+
throw new Error('Agent unable to follow the blueprint');
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
this.end.emit();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
private async _execStep(state: BlueprintMachineState, options: ExecutionOptions): Promise<BlueprintMachineState> {
|
|
95
|
+
const prevStep = this.blueprint.steps.findIndex((step) => step.id === this.state.trace.at(-1)?.stepId);
|
|
96
|
+
if (prevStep === this.blueprint.steps.length - 1) {
|
|
97
|
+
throw new Error('Done execution blueprint');
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const nextStep = this.blueprint.steps[prevStep + 1];
|
|
101
|
+
const onLastStep = prevStep === this.blueprint.steps.length - 2;
|
|
102
|
+
this.stepStart.emit(nextStep);
|
|
103
|
+
|
|
104
|
+
const ReportSchema = Schema.Struct({
|
|
105
|
+
status: Schema.Literal('done', 'bailed', 'skipped').annotations({
|
|
106
|
+
description: 'The status of the task completion',
|
|
107
|
+
}),
|
|
108
|
+
comment: Schema.String.annotations({
|
|
109
|
+
description:
|
|
110
|
+
'A comment about the task completion. If you bailed, you must explain why in detail (min couple of sentences).',
|
|
111
|
+
}),
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
const report = createTool('system', {
|
|
115
|
+
name: 'report',
|
|
116
|
+
description: 'This tool reports that the agent has completed the task or is unable to do so',
|
|
117
|
+
schema: ReportSchema,
|
|
118
|
+
execute: async (input) => ToolResult.Break(input),
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
const session = new AISession({
|
|
122
|
+
operationModel: 'configured',
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
session.userMessage.pipeInto(this.message);
|
|
126
|
+
session.message.pipeInto(this.message);
|
|
127
|
+
session.block.pipeInto(this.block);
|
|
128
|
+
|
|
129
|
+
const inputMessages = options.input
|
|
130
|
+
? [
|
|
131
|
+
create(Message, {
|
|
132
|
+
role: 'user',
|
|
133
|
+
content: [taggedDataBlock('input', options.input)],
|
|
134
|
+
}),
|
|
135
|
+
]
|
|
136
|
+
: [];
|
|
137
|
+
inputMessages.forEach((message) => this.message.emit(message));
|
|
138
|
+
|
|
139
|
+
// TODO(wittjosiah): Warn if tool is not found.
|
|
140
|
+
const tools = nextStep.tools.map((tool) => this.registry.get(tool)).filter(isNonNullable);
|
|
141
|
+
const messages = await session.run({
|
|
142
|
+
systemPrompt: `
|
|
143
|
+
You are a smart Rule-Following Agent.
|
|
144
|
+
Rule-Following Agent executes the command that the user sent in the last message.
|
|
145
|
+
After doing the work, the Rule-Following Agent calls report tool.
|
|
146
|
+
If the Rule-Following agent believes that no action is needed, it calls the report tool with "skipped" status.
|
|
147
|
+
If the Rule-Following Agent is unable to perform the task, it calls the report tool with "bail" status.
|
|
148
|
+
Rule-Following Agent explains the reason it is unable to perform the task before bailing.
|
|
149
|
+
The Rule-Following Agent can express creativity and imagination in the way it performs the task.
|
|
150
|
+
The Rule-Following Agent precisely follows the instructions.
|
|
151
|
+
`,
|
|
152
|
+
history: [...state.history, ...inputMessages],
|
|
153
|
+
tools: [...tools, report],
|
|
154
|
+
artifacts: [],
|
|
155
|
+
client: options.aiService,
|
|
156
|
+
prompt: nextStep.instructions,
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
const { messages: trimmedHistory, call: lastBlock } = popLastToolCall(messages);
|
|
160
|
+
|
|
161
|
+
if (!lastBlock) {
|
|
162
|
+
// TODO(dmaretskyi): Handle this with grace
|
|
163
|
+
throw new Error('Agent did not call the report tool');
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const { status, comment } = ReportSchema.pipe(Schema.decodeUnknownSync)(lastBlock.input);
|
|
167
|
+
|
|
168
|
+
return {
|
|
169
|
+
history: [...state.history, ...inputMessages, ...trimmedHistory],
|
|
170
|
+
trace: [
|
|
171
|
+
...state.trace,
|
|
172
|
+
{
|
|
173
|
+
stepId: nextStep.id,
|
|
174
|
+
status,
|
|
175
|
+
comment,
|
|
176
|
+
},
|
|
177
|
+
],
|
|
178
|
+
state: Match.value(status).pipe(
|
|
179
|
+
Match.withReturnType<BlueprintMachineState['state']>(),
|
|
180
|
+
Match.when('done', () => (onLastStep ? 'done' : 'working')),
|
|
181
|
+
Match.when('skipped', () => (onLastStep ? 'done' : 'working')),
|
|
182
|
+
Match.when('bailed', () => 'bail'),
|
|
183
|
+
Match.exhaustive,
|
|
184
|
+
),
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const taggedDataBlock = (tag: string, data: unknown): MessageContentBlock => {
|
|
190
|
+
return {
|
|
191
|
+
type: 'text',
|
|
192
|
+
text: `<${tag}>\n${JSON.stringify(data, null, 2)}\n</${tag}>`,
|
|
193
|
+
} satisfies MessageContentBlock;
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
const popLastToolCall = (messages: Message[]): { messages: Message[]; call?: ToolUseContentBlock } => {
|
|
197
|
+
const lastBlock = messages.at(-1)?.content.at(-1);
|
|
198
|
+
if (lastBlock?.type !== 'tool_use') {
|
|
199
|
+
return { messages };
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const trimmedHistory = [
|
|
203
|
+
...messages.slice(0, -1),
|
|
204
|
+
{
|
|
205
|
+
...messages.at(-1)!,
|
|
206
|
+
content: [...messages.at(-1)!.content.slice(0, -1)],
|
|
207
|
+
} satisfies Message,
|
|
208
|
+
];
|
|
209
|
+
|
|
210
|
+
return {
|
|
211
|
+
messages: trimmedHistory,
|
|
212
|
+
call: lastBlock,
|
|
213
|
+
};
|
|
214
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { create } from '@dxos/echo-schema';
|
|
6
|
+
import { DataType } from '@dxos/schema';
|
|
7
|
+
|
|
8
|
+
// TODO(burdon): Convert to queue.
|
|
9
|
+
export const TEST_EMAILS: DataType.Message[] = [
|
|
10
|
+
create(DataType.Message, {
|
|
11
|
+
properties: {
|
|
12
|
+
subject: 'Introduction email',
|
|
13
|
+
},
|
|
14
|
+
sender: {
|
|
15
|
+
email: 'alice@example.com',
|
|
16
|
+
},
|
|
17
|
+
blocks: [
|
|
18
|
+
{
|
|
19
|
+
type: 'text',
|
|
20
|
+
text: "Hi there! I came across your work and would love to connect. I'm working on some interesting projects in the decentralized space and think there could be good collaboration opportunities.",
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
created: new Date().toISOString(),
|
|
24
|
+
}),
|
|
25
|
+
create(DataType.Message, {
|
|
26
|
+
properties: {
|
|
27
|
+
subject: 'Question about integration',
|
|
28
|
+
},
|
|
29
|
+
sender: {
|
|
30
|
+
email: 'bob@example.com',
|
|
31
|
+
},
|
|
32
|
+
blocks: [
|
|
33
|
+
{
|
|
34
|
+
type: 'text',
|
|
35
|
+
text: "Hello, I was wondering if your system supports integration with external APIs? We have some custom services we'd like to connect. Could you explain the process?",
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
created: new Date().toISOString(),
|
|
39
|
+
}),
|
|
40
|
+
create(DataType.Message, {
|
|
41
|
+
properties: {
|
|
42
|
+
subject: 'MAKE MONEY FAST!!!',
|
|
43
|
+
},
|
|
44
|
+
sender: {
|
|
45
|
+
email: 'spammer123@sketchy.com',
|
|
46
|
+
},
|
|
47
|
+
blocks: [
|
|
48
|
+
{
|
|
49
|
+
type: 'text',
|
|
50
|
+
text: 'CONGRATULATIONS!!! You have been selected to receive $10 MILLION dollars! Just send us your bank details and social security number to claim your prize NOW!!!',
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
created: new Date().toISOString(),
|
|
54
|
+
}),
|
|
55
|
+
];
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { describe, test, beforeAll } from 'vitest';
|
|
6
|
+
|
|
7
|
+
import { AIServiceEdgeClient } from '@dxos/ai';
|
|
8
|
+
import { AI_SERVICE_ENDPOINT } from '@dxos/ai/testing';
|
|
9
|
+
import { FunctionExecutor, ServiceContainer } from '@dxos/functions';
|
|
10
|
+
import { log } from '@dxos/log';
|
|
11
|
+
import { createTestData } from '@dxos/schema/testing';
|
|
12
|
+
import { range } from '@dxos/util';
|
|
13
|
+
|
|
14
|
+
import { extractionAnthropicFn } from './extraction-llm-function';
|
|
15
|
+
import { processTranscriptMessage } from '../extraction';
|
|
16
|
+
|
|
17
|
+
describe.skip('LLM EntityExtraction', () => {
|
|
18
|
+
let executor: FunctionExecutor;
|
|
19
|
+
|
|
20
|
+
beforeAll(async () => {
|
|
21
|
+
executor = new FunctionExecutor(
|
|
22
|
+
new ServiceContainer().setServices({
|
|
23
|
+
ai: {
|
|
24
|
+
client: new AIServiceEdgeClient({
|
|
25
|
+
endpoint: AI_SERVICE_ENDPOINT.REMOTE,
|
|
26
|
+
defaultGenerationOptions: {
|
|
27
|
+
// model: '@anthropic/claude-sonnet-4-20250514',
|
|
28
|
+
model: '@anthropic/claude-3-5-haiku-20241022',
|
|
29
|
+
},
|
|
30
|
+
}),
|
|
31
|
+
},
|
|
32
|
+
}),
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('should process a transcript block', async () => {
|
|
37
|
+
const { transcriptMessages, documents, contacts } = createTestData();
|
|
38
|
+
log.info('context', { documents, contacts });
|
|
39
|
+
|
|
40
|
+
for (const message of transcriptMessages.slice(0, 1)) {
|
|
41
|
+
log.info('input', message);
|
|
42
|
+
const { message: enhancedMessage } = await processTranscriptMessage({
|
|
43
|
+
input: {
|
|
44
|
+
message,
|
|
45
|
+
objects: [...documents, ...Object.values(contacts)],
|
|
46
|
+
},
|
|
47
|
+
function: extractionAnthropicFn,
|
|
48
|
+
executor,
|
|
49
|
+
});
|
|
50
|
+
log.info('output', enhancedMessage);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('computational irreducibility', async () => {
|
|
55
|
+
const { transcriptWoflram, documents, contacts } = createTestData();
|
|
56
|
+
|
|
57
|
+
log.info('context', { documents, contacts });
|
|
58
|
+
const message = transcriptWoflram[0];
|
|
59
|
+
log.info('input', message);
|
|
60
|
+
|
|
61
|
+
await Promise.all(
|
|
62
|
+
range(10).map(async () => {
|
|
63
|
+
const { message: enhancedMessage, timeElapsed } = await processTranscriptMessage({
|
|
64
|
+
input: {
|
|
65
|
+
message,
|
|
66
|
+
objects: [...documents, ...Object.values(contacts)],
|
|
67
|
+
},
|
|
68
|
+
function: extractionAnthropicFn,
|
|
69
|
+
executor,
|
|
70
|
+
});
|
|
71
|
+
log.info('output', { message: enhancedMessage.blocks[0], timeElapsed });
|
|
72
|
+
}),
|
|
73
|
+
);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test('org and document linking', async () => {
|
|
77
|
+
const { transcriptJosiah, documents, contacts, organizations } = createTestData();
|
|
78
|
+
|
|
79
|
+
log.info('context', { contacts, organizations, documents });
|
|
80
|
+
|
|
81
|
+
for (const message of transcriptJosiah) {
|
|
82
|
+
log.info('input', message);
|
|
83
|
+
|
|
84
|
+
const { message: enhancedMessage } = await processTranscriptMessage({
|
|
85
|
+
input: {
|
|
86
|
+
message,
|
|
87
|
+
objects: [...documents, ...Object.values(contacts), ...Object.values(organizations)],
|
|
88
|
+
},
|
|
89
|
+
function: extractionAnthropicFn,
|
|
90
|
+
executor,
|
|
91
|
+
});
|
|
92
|
+
log.info('output', enhancedMessage);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
});
|