@dxos/assistant 0.8.4-main.ead640a → 0.8.4-main.ef1bc66f44
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/neutral/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/neutral/chunk-ZPC54VRM.mjs +596 -0
- package/dist/lib/neutral/chunk-ZPC54VRM.mjs.map +7 -0
- package/dist/lib/neutral/extraction/index.mjs +225 -0
- package/dist/lib/neutral/extraction/index.mjs.map +7 -0
- package/dist/lib/{browser → neutral}/index.mjs +346 -350
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/lib/neutral/testing/index.mjs +38 -0
- package/dist/lib/neutral/testing/index.mjs.map +7 -0
- package/dist/types/src/conversation/context.d.ts +97 -62
- package/dist/types/src/conversation/context.d.ts.map +1 -1
- package/dist/types/src/conversation/context.test.d.ts +2 -0
- package/dist/types/src/conversation/context.test.d.ts.map +1 -0
- package/dist/types/src/conversation/conversation.d.ts +41 -16
- package/dist/types/src/conversation/conversation.d.ts.map +1 -1
- package/dist/types/src/conversation/conversation.test.d.ts +2 -0
- package/dist/types/src/conversation/conversation.test.d.ts.map +1 -0
- package/dist/types/src/diff.d.ts +3 -1
- package/dist/types/src/diff.d.ts.map +1 -1
- package/dist/types/src/errors.d.ts +22 -30
- package/dist/types/src/errors.d.ts.map +1 -1
- package/dist/types/src/execution-graph.d.ts +5 -2
- package/dist/types/src/execution-graph.d.ts.map +1 -1
- package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts.map +1 -1
- package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts +254 -248
- package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts.map +1 -1
- package/dist/types/src/extraction/extraction.d.ts +344 -303
- package/dist/types/src/extraction/extraction.d.ts.map +1 -1
- package/dist/types/src/extraction/quotes.d.ts +2 -2
- package/dist/types/src/extraction/quotes.d.ts.map +1 -1
- package/dist/types/src/functions/services.d.ts +6 -6
- package/dist/types/src/functions/services.d.ts.map +1 -1
- package/dist/types/src/functions.test.d.ts +2 -0
- package/dist/types/src/functions.test.d.ts.map +1 -0
- package/dist/types/src/session/GenericToolkit.d.ts +107 -0
- package/dist/types/src/session/GenericToolkit.d.ts.map +1 -0
- package/dist/types/src/session/artifact-diff.d.ts +1 -1
- package/dist/types/src/session/artifact-diff.d.ts.map +1 -1
- package/dist/types/src/session/format.d.ts +4 -176
- package/dist/types/src/session/format.d.ts.map +1 -1
- package/dist/types/src/session/index.d.ts +2 -0
- package/dist/types/src/session/index.d.ts.map +1 -1
- package/dist/types/src/session/observer.d.ts +6 -5
- package/dist/types/src/session/observer.d.ts.map +1 -1
- package/dist/types/src/session/session.d.ts +16 -11
- package/dist/types/src/session/session.d.ts.map +1 -1
- package/dist/types/src/session/toolkit.d.ts +5 -6
- package/dist/types/src/session/toolkit.d.ts.map +1 -1
- package/dist/types/src/session/version-pin.d.ts +3 -3
- package/dist/types/src/session/version-pin.d.ts.map +1 -1
- package/dist/types/src/testing/index.d.ts +2 -0
- package/dist/types/src/testing/index.d.ts.map +1 -0
- package/dist/types/src/testing/layer.d.ts +22 -0
- package/dist/types/src/testing/layer.d.ts.map +1 -0
- package/dist/types/src/types/artifact.d.ts +14 -2
- package/dist/types/src/types/artifact.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +40 -31
- package/src/conversation/context.test.ts +46 -0
- package/src/conversation/context.ts +211 -67
- package/src/conversation/conversation.test.ts +65 -0
- package/src/conversation/conversation.ts +128 -53
- package/src/diff.test.ts +37 -6
- package/src/diff.ts +18 -4
- package/src/errors.ts +2 -2
- package/src/execution-graph.test.ts +45 -43
- package/src/execution-graph.ts +23 -14
- package/src/extraction/extraction-llm-function/extraction-llm-function.test.ts +2 -2
- package/src/extraction/extraction-llm-function/extraction-llm-function.ts +44 -54
- package/src/extraction/extraction-ner-function/extraction-ner-function.test.ts +15 -14
- package/src/extraction/extraction-ner-function/extraction-ner-function.ts +36 -44
- package/src/extraction/extraction-ner-function/named-entity-recognition.test.ts +10 -5
- package/src/extraction/extraction.ts +9 -8
- package/src/extraction/quotes.ts +4 -5
- package/src/functions/services.ts +66 -37
- package/src/functions.conversations.json +1 -0
- package/src/functions.test.ts +74 -0
- package/src/session/GenericToolkit.ts +160 -0
- package/src/session/artifact-diff.ts +1 -1
- package/src/session/format.test.ts +103 -39
- package/src/session/format.ts +17 -16
- package/src/session/index.ts +3 -0
- package/src/session/observer.ts +5 -3
- package/src/session/session.conversations.json +1 -1
- package/src/session/session.test.ts +28 -15
- package/src/session/session.ts +44 -21
- package/src/session/toolkit.ts +13 -22
- package/src/session/version-pin.ts +6 -6
- package/src/templates/{format.tpl → instructions/format.tpl} +1 -4
- package/src/templates/system.ts +2 -2
- package/src/testing/index.ts +5 -0
- package/src/testing/layer.ts +84 -0
- package/src/types/artifact.ts +43 -6
- package/dist/lib/browser/chunk-CWGVG235.mjs +0 -380
- package/dist/lib/browser/chunk-CWGVG235.mjs.map +0 -7
- package/dist/lib/browser/chunk-UB26N5UF.mjs +0 -89
- package/dist/lib/browser/chunk-UB26N5UF.mjs.map +0 -7
- package/dist/lib/browser/extraction/index.mjs +0 -272
- package/dist/lib/browser/extraction/index.mjs.map +0 -7
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/named-entity-recognition-QPYHML66.mjs +0 -13
- package/dist/lib/node-esm/chunk-BCFXTNSK.mjs +0 -91
- package/dist/lib/node-esm/chunk-BCFXTNSK.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-OV5PMQPB.mjs +0 -382
- package/dist/lib/node-esm/chunk-OV5PMQPB.mjs.map +0 -7
- package/dist/lib/node-esm/extraction/index.mjs +0 -273
- package/dist/lib/node-esm/extraction/index.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -934
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/named-entity-recognition-2HDF46YX.mjs +0 -14
- package/dist/lib/node-esm/named-entity-recognition-2HDF46YX.mjs.map +0 -7
- package/dist/types/src/summarization/summarization.test.d.ts +0 -2
- package/dist/types/src/summarization/summarization.test.d.ts.map +0 -1
- package/src/summarization/summarization.test.ts +0 -202
- /package/dist/lib/{browser/named-entity-recognition-QPYHML66.mjs.map → neutral/chunk-J5LGTIGS.mjs.map} +0 -0
- /package/src/extraction/extraction-llm-function/{instructions.tpl → transcription-instructions.tpl} +0 -0
- /package/src/templates/{system.tpl → instructions/system.tpl} +0 -0
|
@@ -6,15 +6,17 @@ import { describe, expect, it } from '@effect/vitest';
|
|
|
6
6
|
|
|
7
7
|
import { AgentStatus } from '@dxos/ai';
|
|
8
8
|
import { Obj } from '@dxos/echo';
|
|
9
|
-
import { ObjectId } from '@dxos/
|
|
9
|
+
import { ObjectId } from '@dxos/keys';
|
|
10
10
|
import { log } from '@dxos/log';
|
|
11
|
-
import {
|
|
11
|
+
import { type ContentBlock, Message } from '@dxos/types';
|
|
12
12
|
|
|
13
13
|
import { ExecutionGraph } from './execution-graph';
|
|
14
14
|
|
|
15
|
-
// Helper function to create valid object IDs for testing
|
|
15
|
+
// Helper function to create valid object IDs for testing.
|
|
16
16
|
const createTestId = () => ObjectId.random();
|
|
17
17
|
|
|
18
|
+
const SKIP_BLOCKS: ContentBlock.Any['_tag'][] = [];
|
|
19
|
+
|
|
18
20
|
describe('ExecutionGraph', () => {
|
|
19
21
|
describe('basic functionality', () => {
|
|
20
22
|
it('should create an empty graph initially', () => {
|
|
@@ -26,9 +28,9 @@ describe('ExecutionGraph', () => {
|
|
|
26
28
|
});
|
|
27
29
|
|
|
28
30
|
it('should add a simple user message', () => {
|
|
29
|
-
const graph = new ExecutionGraph();
|
|
31
|
+
const graph = new ExecutionGraph(SKIP_BLOCKS);
|
|
30
32
|
const messageId = createTestId();
|
|
31
|
-
const message = Obj.make(
|
|
33
|
+
const message = Obj.make(Message.Message, {
|
|
32
34
|
id: messageId,
|
|
33
35
|
created: '2025-01-01T00:00:00Z',
|
|
34
36
|
sender: { role: 'user' },
|
|
@@ -56,12 +58,12 @@ describe('ExecutionGraph', () => {
|
|
|
56
58
|
});
|
|
57
59
|
|
|
58
60
|
it('should handle basic status & message processing', () => {
|
|
59
|
-
const graph = new ExecutionGraph();
|
|
61
|
+
const graph = new ExecutionGraph(SKIP_BLOCKS);
|
|
60
62
|
const status = Obj.make(AgentStatus, {
|
|
61
63
|
created: '2025-01-01T00:00:00Z',
|
|
62
64
|
message: 'Running Research',
|
|
63
65
|
});
|
|
64
|
-
const message = Obj.make(
|
|
66
|
+
const message = Obj.make(Message.Message, {
|
|
65
67
|
created: '2025-09-29T14:29:37.860Z',
|
|
66
68
|
sender: {
|
|
67
69
|
role: 'user',
|
|
@@ -90,9 +92,9 @@ describe('ExecutionGraph', () => {
|
|
|
90
92
|
});
|
|
91
93
|
|
|
92
94
|
it('should add an assistant message with text', () => {
|
|
93
|
-
const graph = new ExecutionGraph();
|
|
95
|
+
const graph = new ExecutionGraph(SKIP_BLOCKS);
|
|
94
96
|
const messageId = createTestId();
|
|
95
|
-
const message = Obj.make(
|
|
97
|
+
const message = Obj.make(Message.Message, {
|
|
96
98
|
id: messageId,
|
|
97
99
|
created: '2025-01-01T00:00:00Z',
|
|
98
100
|
sender: { role: 'assistant' },
|
|
@@ -120,9 +122,9 @@ describe('ExecutionGraph', () => {
|
|
|
120
122
|
|
|
121
123
|
describe('sequential chaining within messages', () => {
|
|
122
124
|
it('should chain blocks within a message', () => {
|
|
123
|
-
const graph = new ExecutionGraph();
|
|
125
|
+
const graph = new ExecutionGraph(SKIP_BLOCKS);
|
|
124
126
|
const messageId = createTestId();
|
|
125
|
-
const message = Obj.make(
|
|
127
|
+
const message = Obj.make(Message.Message, {
|
|
126
128
|
id: messageId,
|
|
127
129
|
created: '2025-01-01T00:00:00Z',
|
|
128
130
|
sender: { role: 'assistant' },
|
|
@@ -168,11 +170,11 @@ describe('ExecutionGraph', () => {
|
|
|
168
170
|
});
|
|
169
171
|
|
|
170
172
|
it('should chain across multiple messages', () => {
|
|
171
|
-
const graph = new ExecutionGraph();
|
|
173
|
+
const graph = new ExecutionGraph(SKIP_BLOCKS);
|
|
172
174
|
|
|
173
175
|
// First message
|
|
174
176
|
const message1Id = createTestId();
|
|
175
|
-
const message1 = Obj.make(
|
|
177
|
+
const message1 = Obj.make(Message.Message, {
|
|
176
178
|
id: message1Id,
|
|
177
179
|
created: '2025-01-01T00:00:00Z',
|
|
178
180
|
sender: { role: 'user' },
|
|
@@ -182,7 +184,7 @@ describe('ExecutionGraph', () => {
|
|
|
182
184
|
|
|
183
185
|
// Second message
|
|
184
186
|
const message2Id = createTestId();
|
|
185
|
-
const message2 = Obj.make(
|
|
187
|
+
const message2 = Obj.make(Message.Message, {
|
|
186
188
|
id: message2Id,
|
|
187
189
|
created: '2025-01-01T00:01:00Z',
|
|
188
190
|
sender: { role: 'assistant' },
|
|
@@ -211,7 +213,7 @@ describe('ExecutionGraph', () => {
|
|
|
211
213
|
|
|
212
214
|
describe('tool calls and results', () => {
|
|
213
215
|
it('should handle tool calls and results with proper parent relationships', () => {
|
|
214
|
-
const graph = new ExecutionGraph();
|
|
216
|
+
const graph = new ExecutionGraph(SKIP_BLOCKS);
|
|
215
217
|
|
|
216
218
|
const message1Id = createTestId();
|
|
217
219
|
const message2Id = createTestId();
|
|
@@ -219,7 +221,7 @@ describe('ExecutionGraph', () => {
|
|
|
219
221
|
const toolCallId = 'tool1';
|
|
220
222
|
|
|
221
223
|
// Assistant message with tool call
|
|
222
|
-
const toolCallMessage = Obj.make(
|
|
224
|
+
const toolCallMessage = Obj.make(Message.Message, {
|
|
223
225
|
id: message1Id,
|
|
224
226
|
created: '2025-01-01T00:00:00Z',
|
|
225
227
|
sender: { role: 'assistant' },
|
|
@@ -240,7 +242,7 @@ describe('ExecutionGraph', () => {
|
|
|
240
242
|
});
|
|
241
243
|
|
|
242
244
|
// User message with tool result
|
|
243
|
-
const toolResultMessage = Obj.make(
|
|
245
|
+
const toolResultMessage = Obj.make(Message.Message, {
|
|
244
246
|
id: message2Id,
|
|
245
247
|
created: '2025-01-01T00:01:00Z',
|
|
246
248
|
sender: { role: 'user' },
|
|
@@ -296,7 +298,7 @@ describe('ExecutionGraph', () => {
|
|
|
296
298
|
});
|
|
297
299
|
|
|
298
300
|
it('should handle tool errors with proper parent relationships', () => {
|
|
299
|
-
const graph = new ExecutionGraph();
|
|
301
|
+
const graph = new ExecutionGraph(SKIP_BLOCKS);
|
|
300
302
|
|
|
301
303
|
const message1Id = createTestId();
|
|
302
304
|
const message2Id = createTestId();
|
|
@@ -304,7 +306,7 @@ describe('ExecutionGraph', () => {
|
|
|
304
306
|
const toolCallId = 'tool1';
|
|
305
307
|
|
|
306
308
|
// Assistant message with tool call
|
|
307
|
-
const toolCallMessage = Obj.make(
|
|
309
|
+
const toolCallMessage = Obj.make(Message.Message, {
|
|
308
310
|
id: message1Id,
|
|
309
311
|
created: '2025-01-01T00:00:00Z',
|
|
310
312
|
sender: { role: 'assistant' },
|
|
@@ -321,7 +323,7 @@ describe('ExecutionGraph', () => {
|
|
|
321
323
|
});
|
|
322
324
|
|
|
323
325
|
// User message with tool error
|
|
324
|
-
const toolErrorMessage = Obj.make(
|
|
326
|
+
const toolErrorMessage = Obj.make(Message.Message, {
|
|
325
327
|
id: message2Id,
|
|
326
328
|
created: '2025-01-01T00:01:00Z',
|
|
327
329
|
sender: { role: 'user' },
|
|
@@ -373,7 +375,7 @@ describe('ExecutionGraph', () => {
|
|
|
373
375
|
|
|
374
376
|
describe('different processing orders', () => {
|
|
375
377
|
it('should handle AgentStatus processed after tool result', () => {
|
|
376
|
-
const graph = new ExecutionGraph();
|
|
378
|
+
const graph = new ExecutionGraph(SKIP_BLOCKS);
|
|
377
379
|
|
|
378
380
|
const message1Id = createTestId();
|
|
379
381
|
const message2Id = createTestId();
|
|
@@ -381,7 +383,7 @@ describe('ExecutionGraph', () => {
|
|
|
381
383
|
const toolCallId = 'tool1';
|
|
382
384
|
|
|
383
385
|
// Tool call message
|
|
384
|
-
const toolCallMessage = Obj.make(
|
|
386
|
+
const toolCallMessage = Obj.make(Message.Message, {
|
|
385
387
|
id: message1Id,
|
|
386
388
|
created: '2025-01-01T00:00:00Z',
|
|
387
389
|
sender: { role: 'assistant' },
|
|
@@ -398,7 +400,7 @@ describe('ExecutionGraph', () => {
|
|
|
398
400
|
});
|
|
399
401
|
|
|
400
402
|
// Tool result message
|
|
401
|
-
const toolResultMessage = Obj.make(
|
|
403
|
+
const toolResultMessage = Obj.make(Message.Message, {
|
|
402
404
|
id: message2Id,
|
|
403
405
|
created: '2025-01-01T00:01:00Z',
|
|
404
406
|
sender: { role: 'user' },
|
|
@@ -432,7 +434,7 @@ describe('ExecutionGraph', () => {
|
|
|
432
434
|
});
|
|
433
435
|
|
|
434
436
|
it('should handle AgentStatus processed before tool result', () => {
|
|
435
|
-
const graph = new ExecutionGraph();
|
|
437
|
+
const graph = new ExecutionGraph(SKIP_BLOCKS);
|
|
436
438
|
|
|
437
439
|
const message1Id = createTestId();
|
|
438
440
|
const message2Id = createTestId();
|
|
@@ -440,7 +442,7 @@ describe('ExecutionGraph', () => {
|
|
|
440
442
|
const toolCallId = 'tool1';
|
|
441
443
|
|
|
442
444
|
// Tool call message
|
|
443
|
-
const toolCallMessage = Obj.make(
|
|
445
|
+
const toolCallMessage = Obj.make(Message.Message, {
|
|
444
446
|
id: message1Id,
|
|
445
447
|
created: '2025-01-01T00:00:00Z',
|
|
446
448
|
sender: { role: 'assistant' },
|
|
@@ -466,7 +468,7 @@ describe('ExecutionGraph', () => {
|
|
|
466
468
|
});
|
|
467
469
|
|
|
468
470
|
// Tool result message
|
|
469
|
-
const toolResultMessage = Obj.make(
|
|
471
|
+
const toolResultMessage = Obj.make(Message.Message, {
|
|
470
472
|
id: message2Id,
|
|
471
473
|
created: '2025-01-01T00:01:00Z',
|
|
472
474
|
sender: { role: 'user' },
|
|
@@ -493,7 +495,7 @@ describe('ExecutionGraph', () => {
|
|
|
493
495
|
|
|
494
496
|
describe('complex scenarios', () => {
|
|
495
497
|
it('should handle multiple tool calls in sequence', () => {
|
|
496
|
-
const graph = new ExecutionGraph();
|
|
498
|
+
const graph = new ExecutionGraph(SKIP_BLOCKS);
|
|
497
499
|
|
|
498
500
|
const msg1Id = createTestId();
|
|
499
501
|
const msg2Id = createTestId();
|
|
@@ -505,7 +507,7 @@ describe('ExecutionGraph', () => {
|
|
|
505
507
|
|
|
506
508
|
const events = [
|
|
507
509
|
// User message
|
|
508
|
-
Obj.make(
|
|
510
|
+
Obj.make(Message.Message, {
|
|
509
511
|
id: msg1Id,
|
|
510
512
|
created: '2025-01-01T00:00:00Z',
|
|
511
513
|
sender: { role: 'user' },
|
|
@@ -514,7 +516,7 @@ describe('ExecutionGraph', () => {
|
|
|
514
516
|
}),
|
|
515
517
|
|
|
516
518
|
// Assistant with first tool call
|
|
517
|
-
Obj.make(
|
|
519
|
+
Obj.make(Message.Message, {
|
|
518
520
|
id: msg2Id,
|
|
519
521
|
created: '2025-01-01T00:01:00Z',
|
|
520
522
|
sender: { role: 'assistant' },
|
|
@@ -526,7 +528,7 @@ describe('ExecutionGraph', () => {
|
|
|
526
528
|
}),
|
|
527
529
|
|
|
528
530
|
// First tool result
|
|
529
|
-
Obj.make(
|
|
531
|
+
Obj.make(Message.Message, {
|
|
530
532
|
id: msg3Id,
|
|
531
533
|
created: '2025-01-01T00:02:00Z',
|
|
532
534
|
sender: { role: 'user' },
|
|
@@ -543,7 +545,7 @@ describe('ExecutionGraph', () => {
|
|
|
543
545
|
}),
|
|
544
546
|
|
|
545
547
|
// Assistant with second tool call
|
|
546
|
-
Obj.make(
|
|
548
|
+
Obj.make(Message.Message, {
|
|
547
549
|
id: msg4Id,
|
|
548
550
|
created: '2025-01-01T00:03:00Z',
|
|
549
551
|
sender: { role: 'assistant' },
|
|
@@ -555,7 +557,7 @@ describe('ExecutionGraph', () => {
|
|
|
555
557
|
}),
|
|
556
558
|
|
|
557
559
|
// Second tool result
|
|
558
|
-
Obj.make(
|
|
560
|
+
Obj.make(Message.Message, {
|
|
559
561
|
id: msg5Id,
|
|
560
562
|
created: '2025-01-01T00:04:00Z',
|
|
561
563
|
sender: { role: 'user' },
|
|
@@ -605,10 +607,10 @@ describe('ExecutionGraph', () => {
|
|
|
605
607
|
});
|
|
606
608
|
|
|
607
609
|
it('should handle mixed block types in a message', () => {
|
|
608
|
-
const graph = new ExecutionGraph();
|
|
610
|
+
const graph = new ExecutionGraph(SKIP_BLOCKS);
|
|
609
611
|
|
|
610
612
|
const messageId = createTestId();
|
|
611
|
-
const message = Obj.make(
|
|
613
|
+
const message = Obj.make(Message.Message, {
|
|
612
614
|
id: messageId,
|
|
613
615
|
created: '2025-01-01T00:00:00Z',
|
|
614
616
|
sender: { role: 'assistant' },
|
|
@@ -642,10 +644,10 @@ describe('ExecutionGraph', () => {
|
|
|
642
644
|
|
|
643
645
|
describe('edge cases', () => {
|
|
644
646
|
it('should handle empty text blocks', () => {
|
|
645
|
-
const graph = new ExecutionGraph();
|
|
647
|
+
const graph = new ExecutionGraph(SKIP_BLOCKS);
|
|
646
648
|
|
|
647
649
|
const messageId = createTestId();
|
|
648
|
-
const message = Obj.make(
|
|
650
|
+
const message = Obj.make(Message.Message, {
|
|
649
651
|
id: messageId,
|
|
650
652
|
created: '2025-01-01T00:00:00Z',
|
|
651
653
|
sender: { role: 'assistant' },
|
|
@@ -666,10 +668,10 @@ describe('ExecutionGraph', () => {
|
|
|
666
668
|
});
|
|
667
669
|
|
|
668
670
|
it('should handle messages with no blocks', () => {
|
|
669
|
-
const graph = new ExecutionGraph();
|
|
671
|
+
const graph = new ExecutionGraph(SKIP_BLOCKS);
|
|
670
672
|
|
|
671
673
|
const messageId = createTestId();
|
|
672
|
-
const message = Obj.make(
|
|
674
|
+
const message = Obj.make(Message.Message, {
|
|
673
675
|
id: messageId,
|
|
674
676
|
created: '2025-01-01T00:00:00Z',
|
|
675
677
|
sender: { role: 'assistant' },
|
|
@@ -684,7 +686,7 @@ describe('ExecutionGraph', () => {
|
|
|
684
686
|
});
|
|
685
687
|
|
|
686
688
|
it('should handle getGraph with lastRequest filter', () => {
|
|
687
|
-
const graph = new ExecutionGraph();
|
|
689
|
+
const graph = new ExecutionGraph(SKIP_BLOCKS);
|
|
688
690
|
|
|
689
691
|
const msg1Id = createTestId();
|
|
690
692
|
const msg2Id = createTestId();
|
|
@@ -692,28 +694,28 @@ describe('ExecutionGraph', () => {
|
|
|
692
694
|
const msg4Id = createTestId();
|
|
693
695
|
|
|
694
696
|
const events = [
|
|
695
|
-
Obj.make(
|
|
697
|
+
Obj.make(Message.Message, {
|
|
696
698
|
id: msg1Id,
|
|
697
699
|
created: '2025-01-01T00:00:00Z',
|
|
698
700
|
sender: { role: 'user' },
|
|
699
701
|
blocks: [{ _tag: 'text', text: 'First request' }],
|
|
700
702
|
properties: {},
|
|
701
703
|
}),
|
|
702
|
-
Obj.make(
|
|
704
|
+
Obj.make(Message.Message, {
|
|
703
705
|
id: msg2Id,
|
|
704
706
|
created: '2025-01-01T00:01:00Z',
|
|
705
707
|
sender: { role: 'assistant' },
|
|
706
708
|
blocks: [{ _tag: 'text', text: 'Response 1' }],
|
|
707
709
|
properties: {},
|
|
708
710
|
}),
|
|
709
|
-
Obj.make(
|
|
711
|
+
Obj.make(Message.Message, {
|
|
710
712
|
id: msg3Id,
|
|
711
713
|
created: '2025-01-01T00:02:00Z',
|
|
712
714
|
sender: { role: 'user' },
|
|
713
715
|
blocks: [{ _tag: 'text', text: 'Second request' }],
|
|
714
716
|
properties: {},
|
|
715
717
|
}),
|
|
716
|
-
Obj.make(
|
|
718
|
+
Obj.make(Message.Message, {
|
|
717
719
|
id: msg4Id,
|
|
718
720
|
created: '2025-01-01T00:03:00Z',
|
|
719
721
|
sender: { role: 'assistant' },
|
package/src/execution-graph.ts
CHANGED
|
@@ -3,13 +3,15 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { AgentStatus } from '@dxos/ai';
|
|
6
|
-
import { Obj, type Ref } from '@dxos/echo';
|
|
6
|
+
import { type Entity, Obj, type Ref } from '@dxos/echo';
|
|
7
7
|
import { MESSAGE_PROPERTY_TOOL_CALL_ID } from '@dxos/functions';
|
|
8
8
|
import { type ObjectId } from '@dxos/keys';
|
|
9
9
|
import { LogLevel } from '@dxos/log';
|
|
10
|
-
import { ContentBlock,
|
|
10
|
+
import { ContentBlock, Message } from '@dxos/types';
|
|
11
11
|
import { isNonNullable } from '@dxos/util';
|
|
12
12
|
|
|
13
|
+
const SKIP_BLOCKS: ContentBlock.Any['_tag'][] = ['text'];
|
|
14
|
+
|
|
13
15
|
/**
|
|
14
16
|
* Mercurial-style Commit.
|
|
15
17
|
*/
|
|
@@ -58,13 +60,15 @@ export class ExecutionGraph {
|
|
|
58
60
|
private _lastCommitByBranch = new Map<string, string>(); // branch -> last commitId
|
|
59
61
|
private _pendingToolResults = new Map<string, string>(); // toolCallId -> toolResultCommitId
|
|
60
62
|
|
|
63
|
+
constructor(private readonly _skipBlocks: ContentBlock.Any['_tag'][] = SKIP_BLOCKS) {}
|
|
64
|
+
|
|
61
65
|
/**
|
|
62
66
|
* Adds events to the graph.
|
|
63
67
|
*/
|
|
64
|
-
addEvents(events:
|
|
68
|
+
addEvents(events: Entity.Unknown[]) {
|
|
65
69
|
const sortedEvents = this.sortObjectsByCreated(events);
|
|
66
70
|
for (const event of sortedEvents) {
|
|
67
|
-
if (Obj.instanceOf(
|
|
71
|
+
if (Obj.instanceOf(Message.Message, event)) {
|
|
68
72
|
this._processMessage(event);
|
|
69
73
|
} else if (Obj.instanceOf(AgentStatus, event)) {
|
|
70
74
|
this._processAgentStatus(event);
|
|
@@ -75,12 +79,13 @@ export class ExecutionGraph {
|
|
|
75
79
|
/**
|
|
76
80
|
* Processes a message event and creates commits for its blocks.
|
|
77
81
|
*/
|
|
78
|
-
private _processMessage(message:
|
|
82
|
+
private _processMessage(message: Message.Message) {
|
|
79
83
|
const messageCommits = messageToCommits(
|
|
80
84
|
message,
|
|
81
85
|
this._lastBlockId,
|
|
82
86
|
this._toolCallCommitIds,
|
|
83
87
|
this._lastCommitByBranch,
|
|
88
|
+
this._skipBlocks,
|
|
84
89
|
);
|
|
85
90
|
this._commits.push(...messageCommits);
|
|
86
91
|
|
|
@@ -278,15 +283,16 @@ export class ExecutionGraph {
|
|
|
278
283
|
}
|
|
279
284
|
}
|
|
280
285
|
|
|
281
|
-
// TODO(burdon): Pass in AiToolProvider.
|
|
282
286
|
/**
|
|
283
287
|
* Creates commits for all blocks in a message.
|
|
284
288
|
*/
|
|
289
|
+
// TODO(burdon): Pass in AiToolProvider.
|
|
285
290
|
const messageToCommits = (
|
|
286
|
-
message:
|
|
291
|
+
message: Message.Message,
|
|
287
292
|
lastBlockId?: string,
|
|
288
293
|
toolCallIds?: Map<string, string>,
|
|
289
294
|
lastCommitByBranch?: Map<string, string>,
|
|
295
|
+
skipBlocks?: ContentBlock.Any['_tag'][],
|
|
290
296
|
): Commit[] => {
|
|
291
297
|
let previousBlockId: string | undefined = lastBlockId;
|
|
292
298
|
|
|
@@ -294,6 +300,9 @@ const messageToCommits = (
|
|
|
294
300
|
.map((block, idx) => {
|
|
295
301
|
const branch = getMessageBranch(message);
|
|
296
302
|
const parents = getBlockParents(block, previousBlockId, message, toolCallIds, lastCommitByBranch);
|
|
303
|
+
if (skipBlocks?.includes(block._tag)) {
|
|
304
|
+
return null;
|
|
305
|
+
}
|
|
297
306
|
|
|
298
307
|
const commit = createBlockCommit(block, message, branch, parents, idx);
|
|
299
308
|
if (commit) {
|
|
@@ -311,14 +320,14 @@ const messageToCommits = (
|
|
|
311
320
|
const getBlockParents = (
|
|
312
321
|
block: ContentBlock.Any,
|
|
313
322
|
previousBlockId: string | undefined,
|
|
314
|
-
message:
|
|
323
|
+
message: Message.Message,
|
|
315
324
|
toolCallIds?: Map<string, string>,
|
|
316
325
|
lastCommitByBranch?: Map<string, string>,
|
|
317
326
|
): string[] => {
|
|
318
327
|
const parents: string[] = [];
|
|
319
328
|
|
|
320
329
|
if (block._tag === 'toolResult') {
|
|
321
|
-
// Tool results have two parents: previous block and last block from tool call branch
|
|
330
|
+
// Tool results have two parents: previous block and last block from tool call branch.
|
|
322
331
|
if (previousBlockId) {
|
|
323
332
|
parents.push(previousBlockId);
|
|
324
333
|
}
|
|
@@ -355,7 +364,7 @@ const getBlockParents = (
|
|
|
355
364
|
*/
|
|
356
365
|
const createBlockCommit = (
|
|
357
366
|
block: ContentBlock.Any,
|
|
358
|
-
message:
|
|
367
|
+
message: Message.Message,
|
|
359
368
|
branch: string,
|
|
360
369
|
parents: string[],
|
|
361
370
|
idx: number,
|
|
@@ -472,14 +481,14 @@ const getBranchName = (options: { parentMessage?: ObjectId; toolCallId?: string
|
|
|
472
481
|
}
|
|
473
482
|
};
|
|
474
483
|
|
|
475
|
-
const getMessageBranch = (message:
|
|
484
|
+
const getMessageBranch = (message: Message.Message) => {
|
|
476
485
|
return getBranchName({
|
|
477
486
|
parentMessage: message.parentMessage,
|
|
478
487
|
toolCallId: message.properties?.[MESSAGE_PROPERTY_TOOL_CALL_ID],
|
|
479
488
|
});
|
|
480
489
|
};
|
|
481
490
|
|
|
482
|
-
const getParentId = (message:
|
|
491
|
+
const getParentId = (message: Message.Message) => {
|
|
483
492
|
if (message.parentMessage && message.properties?.[MESSAGE_PROPERTY_TOOL_CALL_ID]) {
|
|
484
493
|
return getToolCallId(message.parentMessage, message.properties[MESSAGE_PROPERTY_TOOL_CALL_ID]);
|
|
485
494
|
} else {
|
|
@@ -487,7 +496,7 @@ const getParentId = (message: DataType.Message) => {
|
|
|
487
496
|
}
|
|
488
497
|
};
|
|
489
498
|
|
|
490
|
-
const stringifyRef = (ref: Ref.
|
|
499
|
+
const stringifyRef = (ref: Ref.Unknown) => {
|
|
491
500
|
if (ref.target) {
|
|
492
501
|
return stringifyObject(ref.target);
|
|
493
502
|
}
|
|
@@ -495,6 +504,6 @@ const stringifyRef = (ref: Ref.Any) => {
|
|
|
495
504
|
return ref.dxn.asEchoDXN()?.echoId ?? ref.dxn.asQueueDXN()?.objectId ?? '';
|
|
496
505
|
};
|
|
497
506
|
|
|
498
|
-
const stringifyObject = (obj: Obj.
|
|
507
|
+
const stringifyObject = (obj: Obj.Unknown) => {
|
|
499
508
|
return Obj.getLabel(obj) ?? Obj.getTypename(obj) ?? obj.id;
|
|
500
509
|
};
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
import { beforeAll, describe, test } from 'vitest';
|
|
6
6
|
|
|
7
7
|
import { todo } from '@dxos/debug';
|
|
8
|
-
import { FunctionExecutor } from '@dxos/functions';
|
|
8
|
+
import { FunctionExecutor } from '@dxos/functions-runtime';
|
|
9
9
|
import { log } from '@dxos/log';
|
|
10
|
-
import { createTestData } from '@dxos/
|
|
10
|
+
import { createTestData } from '@dxos/types/testing';
|
|
11
11
|
import { range } from '@dxos/util';
|
|
12
12
|
|
|
13
13
|
import { processTranscriptMessage } from '../extraction';
|
|
@@ -2,20 +2,9 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
// ISSUE(burdon): defineFunction
|
|
6
|
-
// @ts-nocheck
|
|
7
|
-
|
|
8
|
-
import { AiService } from '@dxos/ai';
|
|
9
|
-
import { Obj } from '@dxos/echo';
|
|
10
|
-
import { create } from '@dxos/echo/internal';
|
|
11
5
|
import { type FunctionDefinition, defineFunction } from '@dxos/functions';
|
|
12
|
-
import { type ContentBlock, DataType } from '@dxos/schema';
|
|
13
6
|
|
|
14
|
-
import { AiSession } from '../../session';
|
|
15
7
|
import { ExtractionInput, ExtractionOutput } from '../extraction';
|
|
16
|
-
import { ReferencedQuotes, insertReferences } from '../quotes';
|
|
17
|
-
|
|
18
|
-
import PROMPT from './instructions.tpl?raw';
|
|
19
8
|
|
|
20
9
|
export const extractionAnthropicFunction: FunctionDefinition<ExtractionInput, ExtractionOutput> = defineFunction({
|
|
21
10
|
key: 'dxos.org/function/extraction/extract-entities',
|
|
@@ -24,49 +13,50 @@ export const extractionAnthropicFunction: FunctionDefinition<ExtractionInput, Ex
|
|
|
24
13
|
inputSchema: ExtractionInput,
|
|
25
14
|
outputSchema: ExtractionOutput,
|
|
26
15
|
handler: async ({ data: { message, objects }, context }) => {
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
16
|
+
throw new Error('not implemented');
|
|
17
|
+
// const startTime = performance.now();
|
|
18
|
+
// const ai = context.getService(AiService.AiService);
|
|
19
|
+
// const session = new AiSession({ operationModel: 'configured' });
|
|
20
|
+
// const result = await session.runStructured(ReferencedQuotes, {
|
|
21
|
+
// generationOptions: {
|
|
22
|
+
// model: '@anthropic/claude-3-5-haiku-20241022',
|
|
23
|
+
// },
|
|
24
|
+
// client: ai.client,
|
|
25
|
+
// systemPrompt: PROMPT,
|
|
26
|
+
// history: [
|
|
27
|
+
// Obj.make(DataType.Message.Message, {
|
|
28
|
+
// created: new Date().toISOString(),
|
|
29
|
+
// sender: { role: 'user' },
|
|
30
|
+
// blocks: [
|
|
31
|
+
// {
|
|
32
|
+
// _tag: 'text',
|
|
33
|
+
// text: `<context>${JSON.stringify(objects)}</context>`,
|
|
34
|
+
// } satisfies DataType.ContentBlock.Text,
|
|
35
|
+
// {
|
|
36
|
+
// _tag: 'text',
|
|
37
|
+
// text: `<transcript>${JSON.stringify(message.blocks)}</transcript>`,
|
|
38
|
+
// } satisfies DataType.ContentBlock.Text,
|
|
39
|
+
// ],
|
|
40
|
+
// }),
|
|
41
|
+
// ],
|
|
42
|
+
// artifacts: [],
|
|
43
|
+
// prompt: '',
|
|
44
|
+
// tools: [],
|
|
45
|
+
// } as any); // TODO(burdon): Rewrite test.
|
|
56
46
|
|
|
57
|
-
return {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
};
|
|
47
|
+
// return {
|
|
48
|
+
// timeElapsed: performance.now() - startTime,
|
|
49
|
+
// message: create(DataType.Message.Message, {
|
|
50
|
+
// ...message,
|
|
51
|
+
// blocks: message.blocks.map((block) =>
|
|
52
|
+
// block._tag !== 'transcript'
|
|
53
|
+
// ? block
|
|
54
|
+
// : {
|
|
55
|
+
// ...block,
|
|
56
|
+
// text: insertReferences(block.text, result),
|
|
57
|
+
// },
|
|
58
|
+
// ),
|
|
59
|
+
// }),
|
|
60
|
+
// };
|
|
71
61
|
},
|
|
72
62
|
});
|
|
@@ -4,12 +4,13 @@
|
|
|
4
4
|
|
|
5
5
|
import { beforeAll, describe, test } from 'vitest';
|
|
6
6
|
|
|
7
|
-
import { type
|
|
7
|
+
import { type Database } from '@dxos/echo';
|
|
8
8
|
import { EchoTestBuilder } from '@dxos/echo-db/testing';
|
|
9
|
-
import { FunctionExecutor, ServiceContainer } from '@dxos/functions';
|
|
9
|
+
import { FunctionExecutor, ServiceContainer } from '@dxos/functions-runtime';
|
|
10
10
|
import { log } from '@dxos/log';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
11
|
+
import { TestSchema } from '@dxos/schema/testing';
|
|
12
|
+
import { type Message, Organization, Person } from '@dxos/types';
|
|
13
|
+
import { createTestData } from '@dxos/types/testing';
|
|
13
14
|
import { range } from '@dxos/util';
|
|
14
15
|
|
|
15
16
|
import { processTranscriptMessage } from '../extraction';
|
|
@@ -18,25 +19,25 @@ import { extractionNerFunction } from './extraction-ner-function';
|
|
|
18
19
|
|
|
19
20
|
describe.skip('NER EntityExtraction', () => {
|
|
20
21
|
let builder: EchoTestBuilder;
|
|
21
|
-
let db:
|
|
22
|
+
let db: Database.Database;
|
|
22
23
|
let executor: FunctionExecutor;
|
|
23
24
|
let testData: {
|
|
24
|
-
transcriptJosiah:
|
|
25
|
-
transcriptWoflram:
|
|
26
|
-
transcriptMessages:
|
|
27
|
-
documents:
|
|
28
|
-
contacts: Record<string,
|
|
29
|
-
organizations: Record<string,
|
|
25
|
+
transcriptJosiah: Message.Message[];
|
|
26
|
+
transcriptWoflram: Message.Message[];
|
|
27
|
+
transcriptMessages: Message.Message[];
|
|
28
|
+
documents: TestSchema.DocumentType[];
|
|
29
|
+
contacts: Record<string, Person.Person>;
|
|
30
|
+
organizations: Record<string, Organization.Organization>;
|
|
30
31
|
};
|
|
31
32
|
|
|
32
|
-
const TYPES = [
|
|
33
|
+
const TYPES = [Organization.Organization, Person.Person, TestSchema.Person, TestSchema.DocumentType];
|
|
33
34
|
|
|
34
35
|
beforeAll(async () => {
|
|
35
36
|
// TODO(dmaretskyi): Helper to scaffold this from a config.
|
|
36
37
|
builder = await new EchoTestBuilder().open();
|
|
37
|
-
const { db: db1 } = await builder.createDatabase(
|
|
38
|
+
const { db: db1 } = await builder.createDatabase();
|
|
38
39
|
db = db1;
|
|
39
|
-
db.graph.schemaRegistry.
|
|
40
|
+
await db.graph.schemaRegistry.register(TYPES);
|
|
40
41
|
const data = createTestData();
|
|
41
42
|
testData = {
|
|
42
43
|
transcriptJosiah: data.transcriptJosiah,
|