@dxos/assistant 0.8.4-main.84f28bd → 0.8.4-main.b97322e
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 +623 -811
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +623 -811
- 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 +4 -4
- package/dist/types/src/context/binder.d.ts.map +1 -1
- package/dist/types/src/context/binding.d.ts +24 -6
- package/dist/types/src/context/binding.d.ts.map +1 -1
- package/dist/types/src/conversation/conversation.d.ts +12 -18
- package/dist/types/src/conversation/conversation.d.ts.map +1 -1
- 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 +127 -33
- 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 +2 -2
- 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 +170 -193
- 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 -21
- package/src/context/binder.ts +6 -4
- package/src/context/binding.ts +4 -3
- package/src/conversation/conversation.ts +54 -61
- 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 +18 -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 +2 -2
- 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 -53
- package/src/session/__snapshots__/session.test.ts.snap +32 -0
- package/src/session/session.test.ts +90 -55
- package/src/session/session.ts +215 -461
- 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/types/src/blueprint/blueprint.d.ts +0 -41
- package/dist/types/src/blueprint/blueprint.d.ts.map +0 -1
- package/dist/types/src/blueprint/index.d.ts +0 -3
- package/dist/types/src/blueprint/index.d.ts.map +0 -1
- package/dist/types/src/blueprint/registry.d.ts +0 -7
- package/dist/types/src/blueprint/registry.d.ts.map +0 -1
- package/src/blueprint/blueprint.ts +0 -75
- package/src/blueprint/index.ts +0 -6
- package/src/blueprint/registry.ts +0 -15
|
@@ -2,18 +2,16 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import { describe,
|
|
5
|
+
import { AiTool, AiToolkit } from '@effect/ai';
|
|
6
|
+
import { describe, it } from '@effect/vitest';
|
|
7
|
+
import { Effect, Layer, Schema } from 'effect';
|
|
7
8
|
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { Type, Obj } from '@dxos/echo';
|
|
12
|
-
import { ObjectId } from '@dxos/echo-schema';
|
|
13
|
-
import { DXN } from '@dxos/keys';
|
|
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,59 +28,94 @@ const CalendarEventSchema = Schema.Struct({
|
|
|
30
28
|
|
|
31
29
|
type CalendarEvent = Schema.Schema.Type<typeof CalendarEventSchema>;
|
|
32
30
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
+
) {}
|
|
41
45
|
|
|
42
|
-
|
|
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 });
|
|
46
54
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
55
|
+
// eslint-disable-next-line no-new-func, @typescript-eslint/no-implied-eval
|
|
56
|
+
return Function(`"use strict"; return (${sanitizedInput})`)();
|
|
57
|
+
})();
|
|
50
58
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
schema: Schema.Struct({
|
|
55
|
-
operand1: Schema.Number,
|
|
56
|
-
operand2: Schema.Number,
|
|
57
|
-
}),
|
|
58
|
-
execute: async ({ operand1, operand2 }) => {
|
|
59
|
-
return ToolResult.Success(operand1 + operand2);
|
|
60
|
-
},
|
|
61
|
-
});
|
|
59
|
+
return { result };
|
|
60
|
+
}),
|
|
61
|
+
});
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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 });
|
|
72
75
|
},
|
|
73
|
-
|
|
74
|
-
|
|
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
|
+
);
|
|
76
85
|
|
|
77
|
-
|
|
78
|
-
|
|
86
|
+
it.effect.only(
|
|
87
|
+
'calculator',
|
|
88
|
+
Effect.fn(
|
|
89
|
+
function* ({ expect }) {
|
|
90
|
+
const session = new AiSession({ operationModel: 'configured' });
|
|
79
91
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
+
|
|
83
116
|
// overrides: { model: 'llama3.1:8b' },
|
|
84
|
-
|
|
85
|
-
const session = new
|
|
117
|
+
|
|
118
|
+
const session = new AiSession({ operationModel: 'configured' });
|
|
86
119
|
|
|
87
120
|
const objects = new Set<string>();
|
|
88
121
|
|
|
@@ -198,10 +231,12 @@ describe.runIf(process.env.DX_RUN_SLOW_TESTS === '1')('AISession with Ollama', (
|
|
|
198
231
|
finalMessage: response.at(-1),
|
|
199
232
|
});
|
|
200
233
|
});
|
|
234
|
+
*/
|
|
201
235
|
});
|
|
202
236
|
|
|
203
237
|
// Travel to rome, florence, livorno, siena, madrid for conferences
|
|
204
|
-
|
|
238
|
+
// eslint-disable-next-line no-unused-vars
|
|
239
|
+
const _CALENDAR_EVENTS: CalendarEvent[] = [
|
|
205
240
|
Obj.make(CalendarEventSchema, {
|
|
206
241
|
title: 'Exploring Ancient Ruins in Rome',
|
|
207
242
|
startTime: '2024-01-01T10:00:00Z',
|