@dxos/assistant 0.8.1-staging.5be625a → 0.8.1-staging.97aedb1
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/{chunk-BDMTBYIM.mjs → chunk-PND5VR6D.mjs} +42 -12
- package/dist/lib/browser/chunk-PND5VR6D.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +24 -24
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +6 -6
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node/{chunk-A44NGSCM.cjs → chunk-IBOBRBDF.cjs} +45 -15
- package/dist/lib/node/chunk-IBOBRBDF.cjs.map +7 -0
- package/dist/lib/node/index.cjs +56 -56
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +13 -13
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/lib/node-esm/{chunk-J6DMSFSZ.mjs → chunk-DCQJOLSR.mjs} +42 -12
- package/dist/lib/node-esm/chunk-DCQJOLSR.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +24 -24
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +6 -6
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/ai-service/parser.d.ts.map +1 -1
- package/dist/types/src/conversation/conversation.d.ts.map +1 -1
- package/dist/types/src/session/session.d.ts +2 -1
- package/dist/types/src/session/session.d.ts.map +1 -1
- package/package.json +13 -13
- package/src/ai-service/client.test.ts +4 -4
- package/src/ai-service/ollama-client.ts +1 -1
- package/src/ai-service/parser.ts +3 -2
- package/src/ai-service/stream.test.ts +28 -4
- package/src/bin/chat.ts +1 -1
- package/src/conversation/conversation.ts +17 -1
- package/src/cypher/query-executor.test.ts +3 -3
- package/src/cypher/schema.test.ts +1 -1
- package/src/session/session.test.ts +9 -8
- package/src/session/session.ts +26 -20
- package/src/testing/artifacts.test.ts +4 -4
- package/src/testing/object-extraction.test.ts +1 -1
- package/src/testing/query.test.ts +2 -2
- package/src/testing/test-schema.ts +5 -5
- package/dist/lib/browser/chunk-BDMTBYIM.mjs.map +0 -7
- package/dist/lib/node/chunk-A44NGSCM.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-J6DMSFSZ.mjs.map +0 -7
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { describe,
|
|
5
|
+
import { describe, test } from 'vitest';
|
|
6
6
|
|
|
7
7
|
import { type Message } from '@dxos/artifact';
|
|
8
8
|
import { log } from '@dxos/log';
|
|
@@ -55,7 +55,7 @@ const TEST_BLOCKS = [
|
|
|
55
55
|
];
|
|
56
56
|
|
|
57
57
|
describe('GenerationStream', () => {
|
|
58
|
-
|
|
58
|
+
test('should generate a stream of blocks', async ({ expect }) => {
|
|
59
59
|
const stream = createGenerationStream(new Response(createTestSSEStream(TEST_BLOCKS)));
|
|
60
60
|
const events: GenerationStreamEvent[] = [];
|
|
61
61
|
for await (const event of stream) {
|
|
@@ -66,7 +66,7 @@ describe('GenerationStream', () => {
|
|
|
66
66
|
});
|
|
67
67
|
|
|
68
68
|
for (const splitBy of ['word'] as const) {
|
|
69
|
-
|
|
69
|
+
test(`should emit xml blocks (splitBy: ${splitBy})`, async ({ expect }) => {
|
|
70
70
|
const stream = createGenerationStream(new Response(createTestSSEStream(TEST_BLOCKS, { splitBy })));
|
|
71
71
|
const parser = new MixedStreamParser();
|
|
72
72
|
|
|
@@ -78,7 +78,7 @@ describe('GenerationStream', () => {
|
|
|
78
78
|
await parser.parse(stream);
|
|
79
79
|
|
|
80
80
|
for (const block of message?.content ?? []) {
|
|
81
|
-
log
|
|
81
|
+
log('block', { block });
|
|
82
82
|
}
|
|
83
83
|
expect(message?.content.map((block) => block.type)).to.deep.eq([
|
|
84
84
|
//
|
|
@@ -98,4 +98,28 @@ describe('GenerationStream', () => {
|
|
|
98
98
|
]);
|
|
99
99
|
});
|
|
100
100
|
}
|
|
101
|
+
|
|
102
|
+
test.skip('invalid xml', async ({ expect }) => {
|
|
103
|
+
const BLOCKS = [
|
|
104
|
+
//
|
|
105
|
+
'<cot> thoughts <tool-list> more thoughts </cot> <tool-list/>',
|
|
106
|
+
];
|
|
107
|
+
|
|
108
|
+
const stream = createGenerationStream(new Response(createTestSSEStream(BLOCKS, { splitBy: 'word' })));
|
|
109
|
+
const parser = new MixedStreamParser();
|
|
110
|
+
|
|
111
|
+
const result = await parser.parse(stream);
|
|
112
|
+
expect(result[0].content).to.deep.eq([
|
|
113
|
+
{
|
|
114
|
+
type: 'text',
|
|
115
|
+
disposition: 'cot',
|
|
116
|
+
text: 'thoughts more thoughts',
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
type: 'json',
|
|
120
|
+
disposition: 'tool_list',
|
|
121
|
+
json: '{}',
|
|
122
|
+
},
|
|
123
|
+
]);
|
|
124
|
+
});
|
|
101
125
|
});
|
package/src/bin/chat.ts
CHANGED
|
@@ -69,7 +69,7 @@ while (true) {
|
|
|
69
69
|
onImage: (img) => {
|
|
70
70
|
const path = `/tmp/image-${img.id}.jpeg`;
|
|
71
71
|
writeFileSync(path, Buffer.from(img.source.data, 'base64'));
|
|
72
|
-
log
|
|
72
|
+
log('Saved image', { path });
|
|
73
73
|
// Print image in iTerm using ANSI escape sequence
|
|
74
74
|
const imageData = img.source.data;
|
|
75
75
|
process.stdout.write('\x1b]1337;File=inline=1:' + imageData + '\x07');
|
|
@@ -175,7 +175,23 @@ export const runTools = async ({ message, tools, extensions }: RunToolsOptions):
|
|
|
175
175
|
const toolCall = toolCalls[0];
|
|
176
176
|
const tool = tools.find((tool) => tool.name === toolCall.name);
|
|
177
177
|
if (!tool) {
|
|
178
|
-
|
|
178
|
+
const resultMessage = createStatic(Message, {
|
|
179
|
+
role: 'user',
|
|
180
|
+
content: [
|
|
181
|
+
{
|
|
182
|
+
type: 'tool_result',
|
|
183
|
+
toolUseId: toolCall.id,
|
|
184
|
+
content: `Tool not found: ${toolCall.name}`,
|
|
185
|
+
isError: true,
|
|
186
|
+
},
|
|
187
|
+
],
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
// TODO(burdon): Retry count?
|
|
191
|
+
return {
|
|
192
|
+
type: 'continue',
|
|
193
|
+
message: resultMessage,
|
|
194
|
+
};
|
|
179
195
|
}
|
|
180
196
|
|
|
181
197
|
let toolResult: ToolResult;
|
|
@@ -12,10 +12,10 @@ import { createTestData } from '../testing';
|
|
|
12
12
|
test.skip('run', async ({ expect }) => {
|
|
13
13
|
const dataSource = createTestData();
|
|
14
14
|
// for (const node of dataSource.nodes) {
|
|
15
|
-
// log
|
|
15
|
+
// log('node', { id: node.id, label: node.label, name: node.properties.name });
|
|
16
16
|
// }
|
|
17
17
|
// for (const relationship of dataSource.relationships) {
|
|
18
|
-
// log
|
|
18
|
+
// log('relationship', {
|
|
19
19
|
// source: relationship.source.id,
|
|
20
20
|
// target: relationship.target.id,
|
|
21
21
|
// label: relationship.label,
|
|
@@ -43,5 +43,5 @@ test.skip('run', async ({ expect }) => {
|
|
|
43
43
|
},
|
|
44
44
|
]);
|
|
45
45
|
|
|
46
|
-
log
|
|
46
|
+
log('result', { result });
|
|
47
47
|
});
|
|
@@ -12,6 +12,6 @@ import { Contact, Org, Project, Task } from '../testing';
|
|
|
12
12
|
test('Org-Project-Task-Contact schema', async ({ expect }) => {
|
|
13
13
|
const jsonSchema = [Org, Project, Task, Contact].map((schema) => toJsonSchema(schema));
|
|
14
14
|
const result = formatJsonSchemaForLLM(jsonSchema);
|
|
15
|
-
// log
|
|
15
|
+
// log('result', { result });
|
|
16
16
|
expect(result).toHaveLength(8);
|
|
17
17
|
});
|
|
@@ -22,17 +22,18 @@ import { log } from '@dxos/log';
|
|
|
22
22
|
import { AISession } from './session';
|
|
23
23
|
import { AI_SERVICE_ENDPOINT } from '../testing';
|
|
24
24
|
|
|
25
|
-
// Define a calendar event artifact schema
|
|
25
|
+
// Define a calendar event artifact schema.
|
|
26
26
|
const CalendarEventSchema = S.Struct({
|
|
27
27
|
title: S.String,
|
|
28
28
|
startTime: S.String,
|
|
29
29
|
endTime: S.String,
|
|
30
30
|
description: S.String,
|
|
31
|
-
}).pipe(EchoObject('example.com/type/CalendarEvent', '0.1.0'));
|
|
31
|
+
}).pipe(EchoObject({ typename: 'example.com/type/CalendarEvent', version: '0.1.0' }));
|
|
32
32
|
|
|
33
33
|
type CalendarEvent = S.Schema.Type<typeof CalendarEventSchema>;
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
// TODO(burdon): Flaky.
|
|
36
|
+
describe.skip('AISession with Ollama', () => {
|
|
36
37
|
test('create calendar itinerary', { timeout: 60_000 }, async () => {
|
|
37
38
|
const aiClient = new AIServiceEdgeClient({ endpoint: AI_SERVICE_ENDPOINT.REMOTE });
|
|
38
39
|
// const aiClient = new OllamaClient({
|
|
@@ -42,7 +43,7 @@ describe('AISession with Ollama', () => {
|
|
|
42
43
|
|
|
43
44
|
const objects = new Set<string>();
|
|
44
45
|
|
|
45
|
-
// Define calendar artifact
|
|
46
|
+
// Define calendar artifact.
|
|
46
47
|
const calendarArtifact = defineArtifact({
|
|
47
48
|
id: 'artifact:dxos.org/plugin/calendar',
|
|
48
49
|
name: 'Calendar',
|
|
@@ -73,7 +74,7 @@ describe('AISession with Ollama', () => {
|
|
|
73
74
|
data: S.Array(S.Any).annotations({ description: 'Array of data payloads to add as rows' }),
|
|
74
75
|
}),
|
|
75
76
|
execute: async ({ data }) => {
|
|
76
|
-
log
|
|
77
|
+
log('create table', { data });
|
|
77
78
|
const id = DXN.fromLocalObjectId(ObjectId.random()).toString();
|
|
78
79
|
objects.add(id);
|
|
79
80
|
// TODO(dmaretskyi): consider xml for refs instead of @dxn:echo:@:XXXXX
|
|
@@ -104,7 +105,7 @@ describe('AISession with Ollama', () => {
|
|
|
104
105
|
if (!objects.has(sourceId.toString())) {
|
|
105
106
|
return ToolResult.Error(`table id=${source} not found`);
|
|
106
107
|
}
|
|
107
|
-
log
|
|
108
|
+
log('create map', { sourceId });
|
|
108
109
|
const id = DXN.fromLocalObjectId(ObjectId.random()).toString();
|
|
109
110
|
objects.add(id);
|
|
110
111
|
// TODO(dmaretskyi): consider xml for refs instead of @dxn:echo:@:XXXXX
|
|
@@ -131,7 +132,7 @@ describe('AISession with Ollama', () => {
|
|
|
131
132
|
session.block.on(printContentBlock);
|
|
132
133
|
|
|
133
134
|
// session.update.on((update) => {
|
|
134
|
-
// log
|
|
135
|
+
// log('update', { update });
|
|
135
136
|
// });
|
|
136
137
|
|
|
137
138
|
// Test creating an itinerary
|
|
@@ -146,7 +147,7 @@ describe('AISession with Ollama', () => {
|
|
|
146
147
|
prompt: 'create a table and map for a travel itinerary based on events in my calendar',
|
|
147
148
|
});
|
|
148
149
|
|
|
149
|
-
log
|
|
150
|
+
log('result', {
|
|
150
151
|
objects,
|
|
151
152
|
finalMessage: response.at(-1),
|
|
152
153
|
});
|
package/src/session/session.ts
CHANGED
|
@@ -37,10 +37,12 @@ export type SessionRunOptions = {
|
|
|
37
37
|
|
|
38
38
|
prompt: string;
|
|
39
39
|
|
|
40
|
-
generationOptions?: Pick<GenerateRequest, 'model'
|
|
40
|
+
generationOptions?: Pick<GenerateRequest, 'model'>;
|
|
41
41
|
|
|
42
42
|
extensions?: ToolContextExtensions;
|
|
43
43
|
|
|
44
|
+
systemPrompt?: string;
|
|
45
|
+
|
|
44
46
|
/**
|
|
45
47
|
* Pre-require artifacts.
|
|
46
48
|
*/
|
|
@@ -104,12 +106,12 @@ export class AISession {
|
|
|
104
106
|
async run(options: SessionRunOptions): Promise<Message[]> {
|
|
105
107
|
const systemTools: Tool[] = [
|
|
106
108
|
defineTool('system', {
|
|
107
|
-
name: '
|
|
108
|
-
description: 'Query the available
|
|
109
|
+
name: 'query_artifact_definitions',
|
|
110
|
+
description: 'Query the available artifact definitions',
|
|
109
111
|
schema: S.Struct({}),
|
|
110
112
|
execute: async () => {
|
|
111
113
|
return ToolResult.Success({
|
|
112
|
-
|
|
114
|
+
artifactDefinitions: options.artifacts.map((artifact) => ({
|
|
113
115
|
id: artifact.id,
|
|
114
116
|
name: artifact.name,
|
|
115
117
|
description: artifact.description,
|
|
@@ -155,7 +157,7 @@ export class AISession {
|
|
|
155
157
|
|
|
156
158
|
const stepResults: any[] = [];
|
|
157
159
|
for (const step of steps) {
|
|
158
|
-
log
|
|
160
|
+
log('executing step', { action: step.action });
|
|
159
161
|
const session = new AISession({ operationModel: 'immediate' });
|
|
160
162
|
session.message.on((ev) => this.message.emit(ev));
|
|
161
163
|
session.block.on((ev) => this.block.emit(ev));
|
|
@@ -206,25 +208,27 @@ export class AISession {
|
|
|
206
208
|
case 'immediate':
|
|
207
209
|
systemTools.push(
|
|
208
210
|
defineTool('system', {
|
|
209
|
-
name: '
|
|
211
|
+
name: 'require_artifact_definitions',
|
|
210
212
|
description:
|
|
211
|
-
'Require the use of specific
|
|
213
|
+
'Require the use of specific artifact definitions. This will allow the model to interact with artifact definitions and use their tools.',
|
|
212
214
|
schema: S.Struct({
|
|
213
|
-
|
|
214
|
-
description: 'The ids of the
|
|
215
|
+
artifactDefinitionIds: S.Array(S.String).annotations({
|
|
216
|
+
description: 'The ids of the artifact definitions to require',
|
|
215
217
|
examples: [['artifact:dxos.org/example/Test']],
|
|
216
218
|
}),
|
|
217
219
|
}),
|
|
218
|
-
execute: async ({
|
|
219
|
-
const
|
|
220
|
+
execute: async ({ artifactDefinitionIds }) => {
|
|
221
|
+
const missingArtifactDefinitionIds = artifactDefinitionIds.filter(
|
|
220
222
|
(artifactId) => !options.artifacts.some((artifact) => artifact.id === artifactId),
|
|
221
223
|
);
|
|
222
|
-
if (
|
|
223
|
-
return ToolResult.Error(
|
|
224
|
+
if (missingArtifactDefinitionIds.length > 0) {
|
|
225
|
+
return ToolResult.Error(
|
|
226
|
+
`One or more artifact definition ids are invalid: ${missingArtifactDefinitionIds.join(', ')}`,
|
|
227
|
+
);
|
|
224
228
|
}
|
|
225
229
|
|
|
226
|
-
for (const
|
|
227
|
-
requiredArtifactIds.add(
|
|
230
|
+
for (const artifactDefinitionId of artifactDefinitionIds) {
|
|
231
|
+
requiredArtifactIds.add(artifactDefinitionId);
|
|
228
232
|
}
|
|
229
233
|
|
|
230
234
|
return ToolResult.Success({});
|
|
@@ -269,10 +273,12 @@ export class AISession {
|
|
|
269
273
|
// TODO(burdon): Rename messages or separate history/message.
|
|
270
274
|
history: [...this._history, ...this._pending],
|
|
271
275
|
tools,
|
|
272
|
-
systemPrompt:
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
+
systemPrompt:
|
|
277
|
+
options.systemPrompt ??
|
|
278
|
+
createBaseInstructions({
|
|
279
|
+
availableArtifacts: Array.from(requiredArtifactIds),
|
|
280
|
+
operationModel: this._options.operationModel,
|
|
281
|
+
}),
|
|
276
282
|
});
|
|
277
283
|
|
|
278
284
|
// Wait until complete.
|
|
@@ -360,7 +366,7 @@ const createBaseInstructions = ({
|
|
|
360
366
|
`
|
|
361
367
|
}
|
|
362
368
|
|
|
363
|
-
Artifacts already
|
|
369
|
+
${availableArtifacts.length > 0 ? `Artifacts already in context: ${availableArtifacts.join('\n')}` : ''}
|
|
364
370
|
`;
|
|
365
371
|
|
|
366
372
|
export class AIServiecOverloadedError extends S.TaggedError<AIServiecOverloadedError>()(
|
|
@@ -143,10 +143,10 @@ describe('Artifacts', () => {
|
|
|
143
143
|
tools: [custodian],
|
|
144
144
|
});
|
|
145
145
|
for await (const event of stream) {
|
|
146
|
-
log
|
|
146
|
+
log('event', event);
|
|
147
147
|
}
|
|
148
148
|
const [message] = await stream.complete();
|
|
149
|
-
log
|
|
149
|
+
log('full message', {
|
|
150
150
|
message,
|
|
151
151
|
});
|
|
152
152
|
await client.appendMessages([message]);
|
|
@@ -171,10 +171,10 @@ describe('Artifacts', () => {
|
|
|
171
171
|
tools: [custodian],
|
|
172
172
|
});
|
|
173
173
|
for await (const event of stream2) {
|
|
174
|
-
log
|
|
174
|
+
log('event', event);
|
|
175
175
|
}
|
|
176
176
|
const [message2] = await stream2.complete();
|
|
177
|
-
log
|
|
177
|
+
log('full message', {
|
|
178
178
|
message: message2,
|
|
179
179
|
});
|
|
180
180
|
});
|
|
@@ -50,7 +50,7 @@ test.skip('cypher query', async () => {
|
|
|
50
50
|
logger: createLogger({ stream: false }),
|
|
51
51
|
});
|
|
52
52
|
|
|
53
|
-
log
|
|
53
|
+
log('DONE', { result: result.result });
|
|
54
54
|
});
|
|
55
55
|
|
|
56
56
|
test.skip('query ECHO', async () => {
|
|
@@ -87,5 +87,5 @@ test.skip('query ECHO', async () => {
|
|
|
87
87
|
logger: createLogger({ stream: false }),
|
|
88
88
|
});
|
|
89
89
|
|
|
90
|
-
log
|
|
90
|
+
log('DONE', { result: result.result });
|
|
91
91
|
});
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { Schema as S } from 'effect';
|
|
6
6
|
|
|
7
|
-
import { EntityKind,
|
|
7
|
+
import { EntityKind, TypeAnnotationId, Ref } from '@dxos/echo-schema';
|
|
8
8
|
|
|
9
9
|
// TODO(burdon): Reconcile with sdk/schema/testing.
|
|
10
10
|
// TODO(burdon): Convert interface to type.
|
|
@@ -19,7 +19,7 @@ export const Contact = S.Struct({
|
|
|
19
19
|
})
|
|
20
20
|
.pipe(S.mutable)
|
|
21
21
|
.annotations({
|
|
22
|
-
[
|
|
22
|
+
[TypeAnnotationId]: {
|
|
23
23
|
kind: EntityKind.Object,
|
|
24
24
|
typename: 'example.com/type/Contact',
|
|
25
25
|
version: '0.1.0',
|
|
@@ -35,7 +35,7 @@ export const Project = S.Struct({
|
|
|
35
35
|
})
|
|
36
36
|
.pipe(S.mutable)
|
|
37
37
|
.annotations({
|
|
38
|
-
[
|
|
38
|
+
[TypeAnnotationId]: {
|
|
39
39
|
kind: EntityKind.Object,
|
|
40
40
|
typename: 'example.com/type/Project',
|
|
41
41
|
version: '0.1.0',
|
|
@@ -53,7 +53,7 @@ export const Task = S.Struct({
|
|
|
53
53
|
})
|
|
54
54
|
.pipe(S.mutable)
|
|
55
55
|
.annotations({
|
|
56
|
-
[
|
|
56
|
+
[TypeAnnotationId]: {
|
|
57
57
|
kind: EntityKind.Object,
|
|
58
58
|
typename: 'example.com/type/Task',
|
|
59
59
|
version: '0.1.0',
|
|
@@ -70,7 +70,7 @@ export const Org = S.Struct({
|
|
|
70
70
|
})
|
|
71
71
|
.pipe(S.mutable)
|
|
72
72
|
.annotations({
|
|
73
|
-
[
|
|
73
|
+
[TypeAnnotationId]: {
|
|
74
74
|
kind: EntityKind.Object,
|
|
75
75
|
typename: 'example.com/type/Org',
|
|
76
76
|
version: '0.1.0',
|