@dxos/assistant 0.8.3 → 0.8.4-main.2e9d522
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 +760 -1087
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +760 -1087
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/context/binder.d.ts +34 -0
- package/dist/types/src/context/binder.d.ts.map +1 -0
- package/dist/types/src/context/binding.d.ts +56 -0
- package/dist/types/src/context/binding.d.ts.map +1 -0
- package/dist/types/src/context/index.d.ts +3 -0
- package/dist/types/src/context/index.d.ts.map +1 -0
- package/dist/types/src/conversation/conversation.d.ts +38 -0
- package/dist/types/src/conversation/conversation.d.ts.map +1 -0
- package/dist/types/src/conversation/index.d.ts +2 -0
- package/dist/types/src/conversation/index.d.ts.map +1 -0
- package/dist/types/src/errors.d.ts +38 -0
- package/dist/types/src/errors.d.ts.map +1 -0
- 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 +135 -41
- package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts.map +1 -1
- package/dist/types/src/extraction/extraction-ner-function/named-entity-recognition.d.ts +1 -1
- package/dist/types/src/extraction/extraction-ner-function/named-entity-recognition.d.ts.map +1 -1
- package/dist/types/src/extraction/extraction.d.ts +100 -42
- package/dist/types/src/extraction/extraction.d.ts.map +1 -1
- package/dist/types/src/functions/index.d.ts +2 -0
- package/dist/types/src/functions/index.d.ts.map +1 -0
- package/dist/types/src/functions/services.d.ts +6 -0
- package/dist/types/src/functions/services.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +4 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/research/exa.d.ts +10 -5
- package/dist/types/src/research/exa.d.ts.map +1 -1
- package/dist/types/src/research/graph.d.ts +18 -8
- package/dist/types/src/research/graph.d.ts.map +1 -1
- package/dist/types/src/research/research.d.ts +1 -1
- package/dist/types/src/research/research.d.ts.map +1 -1
- package/dist/types/src/session/session.d.ts +183 -184
- package/dist/types/src/session/session.d.ts.map +1 -1
- package/dist/types/src/session/version-pin.d.ts +2 -2
- package/dist/types/src/session/version-pin.d.ts.map +1 -1
- package/dist/types/src/templates/index.d.ts +2 -0
- package/dist/types/src/templates/index.d.ts.map +1 -0
- package/dist/types/src/templates/prompt.d.ts +30 -0
- package/dist/types/src/templates/prompt.d.ts.map +1 -0
- package/dist/types/src/types.d.ts +10 -0
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +29 -30
- package/src/context/binder.ts +103 -0
- package/src/context/binding.ts +32 -0
- package/src/context/index.ts +6 -0
- package/src/conversation/conversation.ts +96 -0
- package/src/conversation/index.ts +5 -0
- package/src/errors.ts +10 -0
- package/src/extraction/extraction-llm-function/extraction-llm-function.test.ts +6 -18
- package/src/extraction/extraction-llm-function/extraction-llm-function.ts +19 -14
- package/src/extraction/extraction-ner-function/extraction-ner-function.ts +6 -3
- package/src/extraction/extraction-ner-function/named-entity-recognition.test.ts +2 -2
- package/src/extraction/extraction-ner-function/named-entity-recognition.ts +1 -1
- package/src/functions/index.ts +5 -0
- package/src/functions/services.ts +139 -0
- package/src/index.ts +4 -1
- package/src/research/exa.ts +56 -59
- package/src/research/graph.test.ts +50 -1
- package/src/research/graph.ts +85 -53
- package/src/research/instructions-research.tpl +1 -0
- package/src/research/research.test.ts +27 -27
- package/src/research/research.ts +50 -52
- package/src/session/__snapshots__/session.test.ts.snap +32 -0
- package/src/session/session.test.ts +99 -18
- package/src/session/session.ts +230 -443
- package/src/session/version-pin.test.ts +2 -21
- package/src/session/version-pin.ts +5 -5
- package/src/summarization/summarization.test.ts +75 -88
- package/src/templates/assistant.tpl +111 -0
- package/src/templates/index.ts +5 -0
- package/src/templates/prompt.ts +45 -0
- package/src/types.ts +40 -1
- package/dist/lib/node/index.cjs +0 -2178
- package/dist/lib/node/index.cjs.map +0 -7
- package/dist/lib/node/meta.json +0 -1
- package/dist/types/src/blueprint/ai.test.d.ts +0 -2
- package/dist/types/src/blueprint/ai.test.d.ts.map +0 -1
- package/dist/types/src/blueprint/blueprint.d.ts +0 -55
- package/dist/types/src/blueprint/blueprint.d.ts.map +0 -1
- package/dist/types/src/blueprint/blueprint.test.d.ts +0 -2
- package/dist/types/src/blueprint/blueprint.test.d.ts.map +0 -1
- package/dist/types/src/blueprint/index.d.ts +0 -4
- package/dist/types/src/blueprint/index.d.ts.map +0 -1
- package/dist/types/src/blueprint/logger.d.ts +0 -25
- package/dist/types/src/blueprint/logger.d.ts.map +0 -1
- package/dist/types/src/blueprint/machine.d.ts +0 -143
- package/dist/types/src/blueprint/machine.d.ts.map +0 -1
- package/dist/types/src/blueprint/test-data.d.ts +0 -3
- package/dist/types/src/blueprint/test-data.d.ts.map +0 -1
- package/src/blueprint/ai.test.ts +0 -156
- package/src/blueprint/blueprint.test.ts +0 -151
- package/src/blueprint/blueprint.ts +0 -75
- package/src/blueprint/index.ts +0 -7
- package/src/blueprint/logger.ts +0 -155
- package/src/blueprint/machine.ts +0 -251
- package/src/blueprint/test-data.ts +0 -55
|
@@ -2,18 +2,16 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import { describe,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import { ObjectId } from '@dxos/echo-schema';
|
|
13
|
-
import { DXN } from '@dxos/keys';
|
|
5
|
+
import { AiTool, AiToolkit } from '@effect/ai';
|
|
6
|
+
import { describe, it } from '@effect/vitest';
|
|
7
|
+
import { Effect, Layer, Schema } from 'effect';
|
|
8
|
+
|
|
9
|
+
import { AiService, ToolExecutionService, ToolResolverService } from '@dxos/ai';
|
|
10
|
+
import { AiServiceTestingPreset } from '@dxos/ai/testing';
|
|
11
|
+
import { Obj, Type } from '@dxos/echo';
|
|
14
12
|
import { log } from '@dxos/log';
|
|
15
13
|
|
|
16
|
-
import {
|
|
14
|
+
import { AiSession } from './session';
|
|
17
15
|
|
|
18
16
|
// Define a calendar event artifact schema.
|
|
19
17
|
const CalendarEventSchema = Schema.Struct({
|
|
@@ -30,14 +28,94 @@ const CalendarEventSchema = Schema.Struct({
|
|
|
30
28
|
|
|
31
29
|
type CalendarEvent = Schema.Schema.Type<typeof CalendarEventSchema>;
|
|
32
30
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
31
|
+
class TestToolkit extends AiToolkit.make(
|
|
32
|
+
AiTool.make('Calculator', {
|
|
33
|
+
description: 'Basic calculator tool',
|
|
34
|
+
parameters: {
|
|
35
|
+
input: Schema.String.annotations({
|
|
36
|
+
description: 'The calculation to perform.',
|
|
37
|
+
}),
|
|
38
|
+
},
|
|
39
|
+
success: Schema.Struct({
|
|
40
|
+
result: Schema.Number,
|
|
41
|
+
}),
|
|
42
|
+
failure: Schema.Never,
|
|
43
|
+
}),
|
|
44
|
+
) {}
|
|
45
|
+
|
|
46
|
+
// Tool handlers.
|
|
47
|
+
const toolkitLayer = TestToolkit.toLayer({
|
|
48
|
+
Calculator: ({ input }) =>
|
|
49
|
+
Effect.gen(function* () {
|
|
50
|
+
const result = (() => {
|
|
51
|
+
// Restrict to basic arithmetic operations for safety.
|
|
52
|
+
const sanitizedInput = input.replace(/[^0-9+\-*/().\s]/g, '');
|
|
53
|
+
log.info('calculate', { sanitizedInput });
|
|
54
|
+
|
|
55
|
+
// eslint-disable-next-line no-new-func, @typescript-eslint/no-implied-eval
|
|
56
|
+
return Function(`"use strict"; return (${sanitizedInput})`)();
|
|
57
|
+
})();
|
|
58
|
+
|
|
59
|
+
return { result };
|
|
60
|
+
}),
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe.runIf(process.env.DX_RUN_SLOW_TESTS)('AiSession', () => {
|
|
64
|
+
it.effect(
|
|
65
|
+
'no tools',
|
|
66
|
+
Effect.fn(
|
|
67
|
+
function* ({ expect }) {
|
|
68
|
+
const session = new AiSession({ operationModel: 'configured' });
|
|
69
|
+
|
|
70
|
+
const response = yield* session.run({
|
|
71
|
+
prompt: 'Hello world!',
|
|
72
|
+
history: [],
|
|
73
|
+
});
|
|
74
|
+
log.info('response', { response });
|
|
75
|
+
},
|
|
76
|
+
Effect.provide(
|
|
77
|
+
AiService.model('@anthropic/claude-3-5-sonnet-20241022').pipe(
|
|
78
|
+
Layer.provideMerge(ToolResolverService.layerEmpty),
|
|
79
|
+
Layer.provideMerge(ToolExecutionService.layerEmpty),
|
|
80
|
+
Layer.provideMerge(AiServiceTestingPreset('direct')),
|
|
81
|
+
),
|
|
82
|
+
),
|
|
83
|
+
),
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
it.effect.only(
|
|
87
|
+
'calculator',
|
|
88
|
+
Effect.fn(
|
|
89
|
+
function* ({ expect }) {
|
|
90
|
+
const session = new AiSession({ operationModel: 'configured' });
|
|
91
|
+
|
|
92
|
+
const response = yield* session.run({
|
|
93
|
+
prompt: 'What is 10 + 20?',
|
|
94
|
+
history: [],
|
|
95
|
+
toolkit: TestToolkit,
|
|
96
|
+
});
|
|
97
|
+
log.info('response', { response });
|
|
98
|
+
},
|
|
99
|
+
Effect.provide(
|
|
100
|
+
Layer.mergeAll(
|
|
101
|
+
toolkitLayer,
|
|
102
|
+
ToolResolverService.layerEmpty,
|
|
103
|
+
ToolExecutionService.layerEmpty,
|
|
104
|
+
AiService.model('@anthropic/claude-3-5-sonnet-20241022').pipe(
|
|
105
|
+
Layer.provideMerge(AiServiceTestingPreset('direct')),
|
|
106
|
+
),
|
|
107
|
+
),
|
|
108
|
+
),
|
|
109
|
+
),
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
// TODO(dmaretskyi): Revive test.
|
|
113
|
+
/*
|
|
114
|
+
it.skip('create calendar itinerary', { timeout: 60_000 }, async () => {
|
|
115
|
+
|
|
38
116
|
// overrides: { model: 'llama3.1:8b' },
|
|
39
|
-
|
|
40
|
-
const session = new
|
|
117
|
+
|
|
118
|
+
const session = new AiSession({ operationModel: 'configured' });
|
|
41
119
|
|
|
42
120
|
const objects = new Set<string>();
|
|
43
121
|
|
|
@@ -145,6 +223,7 @@ describe.skip('AISession with Ollama', () => {
|
|
|
145
223
|
model: '@anthropic/claude-3-5-haiku-20241022',
|
|
146
224
|
},
|
|
147
225
|
prompt: 'create a table and map for a travel itinerary based on events in my calendar',
|
|
226
|
+
toolResolver: new ToolRegistry([]),
|
|
148
227
|
});
|
|
149
228
|
|
|
150
229
|
log('result', {
|
|
@@ -152,10 +231,12 @@ describe.skip('AISession with Ollama', () => {
|
|
|
152
231
|
finalMessage: response.at(-1),
|
|
153
232
|
});
|
|
154
233
|
});
|
|
234
|
+
*/
|
|
155
235
|
});
|
|
156
236
|
|
|
157
237
|
// Travel to rome, florence, livorno, siena, madrid for conferences
|
|
158
|
-
|
|
238
|
+
// eslint-disable-next-line no-unused-vars
|
|
239
|
+
const _CALENDAR_EVENTS: CalendarEvent[] = [
|
|
159
240
|
Obj.make(CalendarEventSchema, {
|
|
160
241
|
title: 'Exploring Ancient Ruins in Rome',
|
|
161
242
|
startTime: '2024-01-01T10:00:00Z',
|