@dxos/assistant 0.8.1 → 0.8.2-main.10c050d
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 +1830 -228
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +1825 -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 +1831 -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 +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/blueprint/machine.d.ts +113 -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 +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 +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 +25 -35
- 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 -3
- 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 +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,142 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Schema } from 'effect';
|
|
6
|
+
import { describe, test } from 'vitest';
|
|
7
|
+
|
|
8
|
+
import { AIServiceEdgeClient, 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 machine = new BlueprintMachine(blueprint);
|
|
43
|
+
setConsolePrinter(machine, true);
|
|
44
|
+
await machine.runToCompletion({ aiService });
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('email bot', { timeout: 60_000 }, async () => {
|
|
48
|
+
const replyTool = createTool('email', {
|
|
49
|
+
name: 'reply',
|
|
50
|
+
description: 'Reply to the email',
|
|
51
|
+
schema: Schema.Struct({
|
|
52
|
+
toEmail: ArtifactId,
|
|
53
|
+
subject: Schema.String.annotations({
|
|
54
|
+
description: 'The subject of the reply',
|
|
55
|
+
}),
|
|
56
|
+
body: Schema.String.annotations({
|
|
57
|
+
description: 'The body of the reply',
|
|
58
|
+
}),
|
|
59
|
+
}),
|
|
60
|
+
execute: async (params) => {
|
|
61
|
+
console.log('reply', params);
|
|
62
|
+
return ToolResult.Success('Sent!');
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const labelTool = createTool('email', {
|
|
67
|
+
name: 'label',
|
|
68
|
+
description: 'Apply a label to the email',
|
|
69
|
+
schema: Schema.Struct({
|
|
70
|
+
toEmail: ArtifactId,
|
|
71
|
+
label: Schema.String.annotations({
|
|
72
|
+
description: 'The label to apply to the email',
|
|
73
|
+
}),
|
|
74
|
+
}),
|
|
75
|
+
execute: async (params) => {
|
|
76
|
+
return ToolResult.Success('Labeled!');
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const blueprint = BlueprintBuilder.create()
|
|
81
|
+
.step(
|
|
82
|
+
'Determine if the email is introduction, question, or spam. Bail if email does not fit into one of these categories.',
|
|
83
|
+
)
|
|
84
|
+
.step('If the email is spam, label it as spam and do not respond.', {
|
|
85
|
+
tools: [labelTool],
|
|
86
|
+
})
|
|
87
|
+
.step(
|
|
88
|
+
'If the email is an introduction, respond with a short introduction of yourself and ask for more information.',
|
|
89
|
+
{
|
|
90
|
+
tools: [replyTool],
|
|
91
|
+
},
|
|
92
|
+
)
|
|
93
|
+
.step('If the email is a question, respond with a short answer and ask for more information.', {
|
|
94
|
+
tools: [replyTool],
|
|
95
|
+
})
|
|
96
|
+
.build();
|
|
97
|
+
|
|
98
|
+
const machine = new BlueprintMachine(blueprint);
|
|
99
|
+
setConsolePrinter(machine);
|
|
100
|
+
await machine.runToCompletion({ aiService, input: TEST_EMAILS[0] });
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test.only('research', { timeout: 120_000 }, async () => {
|
|
104
|
+
const builder = await new EchoTestBuilder().open();
|
|
105
|
+
const { db } = await builder.createDatabase({ indexing: { vector: true }, types: DataTypes });
|
|
106
|
+
|
|
107
|
+
const [org1] = [
|
|
108
|
+
db.add(
|
|
109
|
+
create(DataType.Organization, {
|
|
110
|
+
name: 'Exa',
|
|
111
|
+
website: 'https://exa.ai',
|
|
112
|
+
description: 'An AI-powered search engine company building search infrastructure for AI agents',
|
|
113
|
+
}),
|
|
114
|
+
),
|
|
115
|
+
db.add(
|
|
116
|
+
create(DataType.Organization, {
|
|
117
|
+
name: 'Cresta',
|
|
118
|
+
website: 'https://cresta.ai',
|
|
119
|
+
description: 'A company that builds AI agents',
|
|
120
|
+
}),
|
|
121
|
+
),
|
|
122
|
+
];
|
|
123
|
+
|
|
124
|
+
await db.flush({ indexes: true });
|
|
125
|
+
|
|
126
|
+
const blueprint = BlueprintBuilder.create()
|
|
127
|
+
.step('Research founders of the organization. Do deep research.', {
|
|
128
|
+
tools: [createExaTool({ apiKey: EXA_API_KEY })],
|
|
129
|
+
})
|
|
130
|
+
.step('Based on your research select matching entires that are already in the graph', {
|
|
131
|
+
tools: [createLocalSearchTool(db)],
|
|
132
|
+
})
|
|
133
|
+
.step('Add researched data to the graph', {
|
|
134
|
+
tools: [createLocalSearchTool(db), createGraphWriterTool({ db, schemaTypes: DataTypes })],
|
|
135
|
+
})
|
|
136
|
+
.build();
|
|
137
|
+
|
|
138
|
+
const machine = new BlueprintMachine(blueprint);
|
|
139
|
+
setConsolePrinter(machine, true);
|
|
140
|
+
await machine.runToCompletion({ aiService, input: org1 });
|
|
141
|
+
});
|
|
142
|
+
});
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Schema } from 'effect';
|
|
6
|
+
|
|
7
|
+
import { type ExecutableTool, Tool } from '@dxos/ai';
|
|
8
|
+
import { raise } from '@dxos/debug';
|
|
9
|
+
import { ObjectId } from '@dxos/keys';
|
|
10
|
+
|
|
11
|
+
export const BlueprintStep = Schema.Struct({
|
|
12
|
+
id: Schema.String,
|
|
13
|
+
instructions: Schema.String,
|
|
14
|
+
// TODO(burdon): ExecutableTool can't be serialized.
|
|
15
|
+
tools: Schema.Array(Tool).pipe(Schema.mutable),
|
|
16
|
+
});
|
|
17
|
+
export interface BlueprintStep extends Schema.Schema.Type<typeof BlueprintStep> {}
|
|
18
|
+
|
|
19
|
+
export const Blueprint = Schema.Struct({
|
|
20
|
+
steps: Schema.Array(BlueprintStep).pipe(Schema.mutable),
|
|
21
|
+
});
|
|
22
|
+
export interface Blueprint extends Schema.Schema.Type<typeof Blueprint> {}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Blueprint builder API.
|
|
26
|
+
*/
|
|
27
|
+
export namespace BlueprintBuilder {
|
|
28
|
+
export const create = () => new Builder();
|
|
29
|
+
|
|
30
|
+
class Builder {
|
|
31
|
+
private readonly _steps: BlueprintStep[] = [];
|
|
32
|
+
|
|
33
|
+
step(instructions: string, options?: { tools?: ExecutableTool[] }): Builder {
|
|
34
|
+
this._steps.push({
|
|
35
|
+
id: ObjectId.random(),
|
|
36
|
+
instructions,
|
|
37
|
+
tools: options?.tools ?? [],
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
build(): Blueprint {
|
|
44
|
+
return {
|
|
45
|
+
steps: this._steps,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Blueprint parser API.
|
|
53
|
+
*/
|
|
54
|
+
export namespace BlueprintParser {
|
|
55
|
+
export type Step = {
|
|
56
|
+
instructions: string;
|
|
57
|
+
// TODO(burdon): Tool DXN? Additional metadata?
|
|
58
|
+
tools?: string[];
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export type DSL = {
|
|
62
|
+
steps: Step[];
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export const create = (tools: ExecutableTool[] = []) => new Parser(tools);
|
|
66
|
+
|
|
67
|
+
class Parser {
|
|
68
|
+
constructor(private readonly _tools: ExecutableTool[]) {}
|
|
69
|
+
|
|
70
|
+
toJSON() {
|
|
71
|
+
return {
|
|
72
|
+
tools: this._tools.map((tool) => ({
|
|
73
|
+
name: tool.name,
|
|
74
|
+
namespace: tool.namespace,
|
|
75
|
+
type: tool.type,
|
|
76
|
+
})),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
parse({ steps }: DSL): Blueprint {
|
|
81
|
+
const builder = BlueprintBuilder.create();
|
|
82
|
+
|
|
83
|
+
for (const step of steps) {
|
|
84
|
+
builder.step(step.instructions, {
|
|
85
|
+
// TODO(burdon): Tool resolution is duplicated in the session and ollama-client.
|
|
86
|
+
tools: step.tools?.map(
|
|
87
|
+
(tool) => this._tools.find(({ id }) => id === tool) ?? raise(new Error(`Tool not found: ${tool}`)),
|
|
88
|
+
),
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return builder.build();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import chalk from 'chalk';
|
|
6
|
+
|
|
7
|
+
import { ConsolePrinter } from '@dxos/ai';
|
|
8
|
+
|
|
9
|
+
import { type Blueprint } from './blueprint';
|
|
10
|
+
import { type BlueprintMachine, type BlueprintMachineState } from './machine';
|
|
11
|
+
|
|
12
|
+
/* eslint-disable no-console */
|
|
13
|
+
|
|
14
|
+
// Force chalk colors on for tests
|
|
15
|
+
chalk.level = 2;
|
|
16
|
+
|
|
17
|
+
export const setConsolePrinter = (machine: BlueprintMachine, extraLogging = false) => {
|
|
18
|
+
const printer = new ConsolePrinter();
|
|
19
|
+
if (extraLogging) {
|
|
20
|
+
machine.stepStart.on((step) =>
|
|
21
|
+
console.log(
|
|
22
|
+
`\n${chalk.magenta(`${chalk.bold(`STEP ${machine.blueprint.steps.indexOf(step) + 1} of ${machine.blueprint.steps.length}:`)} ${step.instructions}`)}\n`,
|
|
23
|
+
),
|
|
24
|
+
);
|
|
25
|
+
machine.message.on((msg) => printer.printMessage(msg));
|
|
26
|
+
machine.block.on((block) => printer.printContentBlock(block));
|
|
27
|
+
}
|
|
28
|
+
machine.begin.on(() => printTrace(machine.blueprint, machine.state));
|
|
29
|
+
machine.stepComplete.on(() => printTrace(machine.blueprint, machine.state));
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const printTrace = (blueprint: Blueprint, state: BlueprintMachineState) => {
|
|
33
|
+
console.log('\n==============================================\n');
|
|
34
|
+
console.log(chalk.bold('\nThe Blueprint:'));
|
|
35
|
+
|
|
36
|
+
blueprint.steps.forEach((step, index) => {
|
|
37
|
+
const traceStep = state.trace.find((t) => t.stepId === step.id);
|
|
38
|
+
|
|
39
|
+
let color = chalk.gray; // Not executed
|
|
40
|
+
let bullet = '○';
|
|
41
|
+
if (traceStep) {
|
|
42
|
+
switch (traceStep.status) {
|
|
43
|
+
case 'done':
|
|
44
|
+
color = chalk.green;
|
|
45
|
+
bullet = '✓';
|
|
46
|
+
break;
|
|
47
|
+
case 'skipped':
|
|
48
|
+
color = chalk.blue;
|
|
49
|
+
bullet = '↓';
|
|
50
|
+
break;
|
|
51
|
+
case 'bailed':
|
|
52
|
+
color = chalk.red;
|
|
53
|
+
bullet = '✗';
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
console.log(color(`\n${bullet} ${step.instructions}`));
|
|
59
|
+
|
|
60
|
+
if (traceStep?.comment) {
|
|
61
|
+
console.log(chalk.white(` ↳ ${traceStep.comment}`));
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
console.log('\n');
|
|
65
|
+
console.log('\n==============================================\n');
|
|
66
|
+
};
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Match, Schema } from 'effect';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
createTool,
|
|
9
|
+
type ExecutableTool,
|
|
10
|
+
Message,
|
|
11
|
+
ToolResult,
|
|
12
|
+
type AIServiceClient,
|
|
13
|
+
type MessageContentBlock,
|
|
14
|
+
type ToolUseContentBlock,
|
|
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
|
+
|
|
21
|
+
import type { Blueprint, BlueprintStep } from './blueprint';
|
|
22
|
+
import { AISession } from '../session';
|
|
23
|
+
|
|
24
|
+
export type BlueprintMachineState = {
|
|
25
|
+
history: Message[];
|
|
26
|
+
trace: BlueprintTraceStep[];
|
|
27
|
+
state: 'working' | 'bail' | 'done';
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const INITIAL_STATE: BlueprintMachineState = {
|
|
31
|
+
state: 'working',
|
|
32
|
+
history: [],
|
|
33
|
+
trace: [],
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export type BlueprintTraceStep = {
|
|
37
|
+
status: 'done' | 'bailed' | 'skipped';
|
|
38
|
+
stepId: ObjectId;
|
|
39
|
+
comment: string;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
type ExecutionOptions = {
|
|
43
|
+
aiService: AIServiceClient;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Input to the blueprint.
|
|
47
|
+
*/
|
|
48
|
+
input?: unknown;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Blueprint state machine.
|
|
53
|
+
*/
|
|
54
|
+
export class BlueprintMachine {
|
|
55
|
+
public readonly begin = new Event<void>();
|
|
56
|
+
public readonly end = new Event<void>();
|
|
57
|
+
public readonly stepStart = new Event<BlueprintStep>();
|
|
58
|
+
public readonly stepComplete = new Event<BlueprintStep>();
|
|
59
|
+
public readonly message = new Event<Message>();
|
|
60
|
+
public readonly block = new Event<MessageContentBlock>();
|
|
61
|
+
|
|
62
|
+
state: BlueprintMachineState = structuredClone(INITIAL_STATE);
|
|
63
|
+
|
|
64
|
+
constructor(readonly blueprint: Blueprint) {}
|
|
65
|
+
|
|
66
|
+
async runToCompletion(options: ExecutionOptions): Promise<void> {
|
|
67
|
+
log.info('runToCompletion', options);
|
|
68
|
+
|
|
69
|
+
this.begin.emit();
|
|
70
|
+
let firstStep = true;
|
|
71
|
+
while (this.state.state !== 'done') {
|
|
72
|
+
const input = firstStep ? options.input : undefined;
|
|
73
|
+
|
|
74
|
+
firstStep = false;
|
|
75
|
+
this.state = await this._execStep(this.state, {
|
|
76
|
+
input,
|
|
77
|
+
aiService: options.aiService,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
this.stepComplete.emit(this.blueprint.steps.find((step) => step.id === this.state.trace.at(-1)?.stepId)!);
|
|
81
|
+
|
|
82
|
+
if (this.state.state === 'bail') {
|
|
83
|
+
throw new Error('Agent unable to follow the blueprint');
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
this.end.emit();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
private async _execStep(state: BlueprintMachineState, options: ExecutionOptions): Promise<BlueprintMachineState> {
|
|
91
|
+
const prevStep = this.blueprint.steps.findIndex((step) => step.id === this.state.trace.at(-1)?.stepId);
|
|
92
|
+
if (prevStep === this.blueprint.steps.length - 1) {
|
|
93
|
+
throw new Error('Done execution blueprint');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const nextStep = this.blueprint.steps[prevStep + 1];
|
|
97
|
+
const onLastStep = prevStep === this.blueprint.steps.length - 2;
|
|
98
|
+
this.stepStart.emit(nextStep);
|
|
99
|
+
|
|
100
|
+
const ReportSchema = Schema.Struct({
|
|
101
|
+
status: Schema.Literal('done', 'bailed', 'skipped').annotations({
|
|
102
|
+
description: 'The status of the task completion',
|
|
103
|
+
}),
|
|
104
|
+
comment: Schema.String.annotations({
|
|
105
|
+
description:
|
|
106
|
+
'A comment about the task completion. If you bailed, you must explain why in detail (min couple of sentences).',
|
|
107
|
+
}),
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
const report = createTool('system', {
|
|
111
|
+
name: 'report',
|
|
112
|
+
description: 'This tool reports that the agent has completed the task or is unable to do so',
|
|
113
|
+
schema: ReportSchema,
|
|
114
|
+
execute: async (input) => ToolResult.Break(input),
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
const session = new AISession({
|
|
118
|
+
operationModel: 'configured',
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
session.userMessage.pipeInto(this.message);
|
|
122
|
+
session.message.pipeInto(this.message);
|
|
123
|
+
session.block.pipeInto(this.block);
|
|
124
|
+
|
|
125
|
+
const inputMessages = options.input
|
|
126
|
+
? [
|
|
127
|
+
create(Message, {
|
|
128
|
+
role: 'user',
|
|
129
|
+
content: [taggedDataBlock('input', options.input)],
|
|
130
|
+
}),
|
|
131
|
+
]
|
|
132
|
+
: [];
|
|
133
|
+
inputMessages.forEach((message) => this.message.emit(message));
|
|
134
|
+
|
|
135
|
+
const messages = await session.run({
|
|
136
|
+
systemPrompt: `
|
|
137
|
+
You are a smart Rule-Following Agent.
|
|
138
|
+
Rule-Following Agent executes the command that the user sent in the last message.
|
|
139
|
+
After doing the work, the Rule-Following Agent calls report tool.
|
|
140
|
+
If the Rule-Following agent believes that no action is needed, it calls the report tool with "skipped" status.
|
|
141
|
+
If the Rule-Following Agent is unable to perform the task, it calls the report tool with "bail" status.
|
|
142
|
+
Rule-Following Agent explains the reason it is unable to perform the task before bailing.
|
|
143
|
+
The Rule-Following Agent can express creativity and imagination in the way it performs the task.
|
|
144
|
+
The Rule-Following Agent precisely follows the instructions.
|
|
145
|
+
`,
|
|
146
|
+
history: [...state.history, ...inputMessages],
|
|
147
|
+
tools: [...nextStep.tools, report] as ExecutableTool[], // TODO(burdon): REMOVE CAST!
|
|
148
|
+
artifacts: [],
|
|
149
|
+
client: options.aiService,
|
|
150
|
+
prompt: nextStep.instructions,
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
const { messages: trimmedHistory, call: lastBlock } = popLastToolCall(messages);
|
|
154
|
+
|
|
155
|
+
if (!lastBlock) {
|
|
156
|
+
// TODO(dmaretskyi): Handle this with grace
|
|
157
|
+
throw new Error('Agent did not call the report tool');
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const { status, comment } = ReportSchema.pipe(Schema.decodeUnknownSync)(lastBlock.input);
|
|
161
|
+
|
|
162
|
+
return {
|
|
163
|
+
history: [...state.history, ...inputMessages, ...trimmedHistory],
|
|
164
|
+
trace: [
|
|
165
|
+
...state.trace,
|
|
166
|
+
{
|
|
167
|
+
stepId: nextStep.id,
|
|
168
|
+
status,
|
|
169
|
+
comment,
|
|
170
|
+
},
|
|
171
|
+
],
|
|
172
|
+
state: Match.value(status).pipe(
|
|
173
|
+
Match.withReturnType<BlueprintMachineState['state']>(),
|
|
174
|
+
Match.when('done', () => (onLastStep ? 'done' : 'working')),
|
|
175
|
+
Match.when('skipped', () => (onLastStep ? 'done' : 'working')),
|
|
176
|
+
Match.when('bailed', () => 'bail'),
|
|
177
|
+
Match.exhaustive,
|
|
178
|
+
),
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const taggedDataBlock = (tag: string, data: unknown): MessageContentBlock => {
|
|
184
|
+
return {
|
|
185
|
+
type: 'text',
|
|
186
|
+
text: `<${tag}>\n${JSON.stringify(data, null, 2)}\n</${tag}>`,
|
|
187
|
+
} satisfies MessageContentBlock;
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
const popLastToolCall = (messages: Message[]): { messages: Message[]; call?: ToolUseContentBlock } => {
|
|
191
|
+
const lastBlock = messages.at(-1)?.content.at(-1);
|
|
192
|
+
if (lastBlock?.type !== 'tool_use') {
|
|
193
|
+
return { messages };
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const trimmedHistory = [
|
|
197
|
+
...messages.slice(0, -1),
|
|
198
|
+
{
|
|
199
|
+
...messages.at(-1)!,
|
|
200
|
+
content: [...messages.at(-1)!.content.slice(0, -1)],
|
|
201
|
+
} satisfies Message,
|
|
202
|
+
];
|
|
203
|
+
|
|
204
|
+
return {
|
|
205
|
+
messages: trimmedHistory,
|
|
206
|
+
call: lastBlock,
|
|
207
|
+
};
|
|
208
|
+
};
|
|
@@ -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
|
+
});
|