@dxos/assistant 0.7.5-main.b19bfc8 → 0.7.5-main.e94eead
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 +13 -27
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +20 -20
- package/dist/lib/browser/testing/index.mjs.map +2 -2
- package/dist/lib/node/index.cjs +13 -27
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +20 -20
- package/dist/lib/node/testing/index.cjs.map +2 -2
- package/dist/lib/node-esm/index.mjs +13 -27
- 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 +20 -20
- package/dist/lib/node-esm/testing/index.mjs.map +2 -2
- package/dist/types/src/ai-service/client.d.ts +7 -14
- package/dist/types/src/ai-service/client.d.ts.map +1 -1
- package/dist/types/src/ai-service/stream.d.ts.map +1 -1
- package/dist/types/src/ai-service/testing/index.d.ts +3 -0
- package/dist/types/src/ai-service/testing/index.d.ts.map +1 -0
- package/dist/types/src/ai-service/testing/mock.d.ts +7 -0
- package/dist/types/src/ai-service/testing/mock.d.ts.map +1 -0
- package/dist/types/src/ai-service/{testing.d.ts → testing/test-stream.d.ts} +1 -1
- package/dist/types/src/ai-service/testing/test-stream.d.ts.map +1 -0
- package/dist/types/src/ai-service/types.d.ts +91 -11
- package/dist/types/src/ai-service/types.d.ts.map +1 -1
- package/dist/types/src/conversation/conversation.d.ts.map +1 -1
- package/package.json +13 -13
- package/src/ai-service/client.test.ts +4 -4
- package/src/ai-service/client.ts +8 -29
- package/src/ai-service/stream.ts +1 -1
- package/src/ai-service/testing/index.ts +6 -0
- package/src/ai-service/testing/mock.ts +17 -0
- package/src/ai-service/{testing.ts → testing/test-stream.ts} +1 -1
- package/src/ai-service/types.ts +7 -7
- package/src/conversation/conversation.test.ts +1 -1
- package/src/conversation/conversation.ts +1 -1
- package/src/testing/artifacts.test.ts +7 -7
- package/src/testing/query-promts.ts +20 -20
- package/dist/types/src/ai-service/testing.d.ts.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/assistant",
|
|
3
|
-
"version": "0.7.5-main.
|
|
3
|
+
"version": "0.7.5-main.e94eead",
|
|
4
4
|
"description": "Natural language interface to DXOS",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -41,18 +41,18 @@
|
|
|
41
41
|
"parjs": "^1.3.9",
|
|
42
42
|
"parsimmon": "^1.18.1",
|
|
43
43
|
"ulidx": "^2.3.0",
|
|
44
|
-
"@dxos/artifact": "0.7.5-main.
|
|
45
|
-
"@dxos/
|
|
46
|
-
"@dxos/
|
|
47
|
-
"@dxos/debug": "0.7.5-main.
|
|
48
|
-
"@dxos/echo-
|
|
49
|
-
"@dxos/echo-
|
|
50
|
-
"@dxos/invariant": "0.7.5-main.
|
|
51
|
-
"@dxos/
|
|
52
|
-
"@dxos/
|
|
53
|
-
"@dxos/
|
|
54
|
-
"@dxos/
|
|
55
|
-
"@dxos/
|
|
44
|
+
"@dxos/artifact": "0.7.5-main.e94eead",
|
|
45
|
+
"@dxos/async": "0.7.5-main.e94eead",
|
|
46
|
+
"@dxos/context": "0.7.5-main.e94eead",
|
|
47
|
+
"@dxos/debug": "0.7.5-main.e94eead",
|
|
48
|
+
"@dxos/echo-schema": "0.7.5-main.e94eead",
|
|
49
|
+
"@dxos/echo-db": "0.7.5-main.e94eead",
|
|
50
|
+
"@dxos/invariant": "0.7.5-main.e94eead",
|
|
51
|
+
"@dxos/keys": "0.7.5-main.e94eead",
|
|
52
|
+
"@dxos/live-object": "0.7.5-main.e94eead",
|
|
53
|
+
"@dxos/log": "0.7.5-main.e94eead",
|
|
54
|
+
"@dxos/util": "0.7.5-main.e94eead",
|
|
55
|
+
"@dxos/node-std": "0.7.5-main.e94eead"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@types/parsimmon": "^1.10.9",
|
|
@@ -37,7 +37,7 @@ describe.skip('AI Service Client', () => {
|
|
|
37
37
|
},
|
|
38
38
|
]);
|
|
39
39
|
|
|
40
|
-
const stream = await client.
|
|
40
|
+
const stream = await client.exec({
|
|
41
41
|
model: DEFAULT_LLM_MODEL,
|
|
42
42
|
spaceId,
|
|
43
43
|
threadId,
|
|
@@ -82,7 +82,7 @@ describe.skip('AI Service Client', () => {
|
|
|
82
82
|
]);
|
|
83
83
|
|
|
84
84
|
{
|
|
85
|
-
const stream1 = await client.
|
|
85
|
+
const stream1 = await client.exec({
|
|
86
86
|
model: DEFAULT_LLM_MODEL,
|
|
87
87
|
spaceId,
|
|
88
88
|
threadId,
|
|
@@ -116,7 +116,7 @@ describe.skip('AI Service Client', () => {
|
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
{
|
|
119
|
-
const stream2 = await client.
|
|
119
|
+
const stream2 = await client.exec({
|
|
120
120
|
model: DEFAULT_LLM_MODEL,
|
|
121
121
|
spaceId,
|
|
122
122
|
threadId,
|
|
@@ -154,7 +154,7 @@ describe.skip('AI Service Client', () => {
|
|
|
154
154
|
},
|
|
155
155
|
]);
|
|
156
156
|
|
|
157
|
-
const stream = await client.
|
|
157
|
+
const stream = await client.exec({
|
|
158
158
|
model: DEFAULT_LLM_MODEL,
|
|
159
159
|
spaceId,
|
|
160
160
|
threadId,
|
package/src/ai-service/client.ts
CHANGED
|
@@ -4,22 +4,19 @@
|
|
|
4
4
|
|
|
5
5
|
import { Schema as S } from '@effect/schema';
|
|
6
6
|
|
|
7
|
-
import { Message
|
|
7
|
+
import { Message } from '@dxos/artifact';
|
|
8
8
|
import { invariant } from '@dxos/invariant';
|
|
9
|
-
import { type SpaceId } from '@dxos/keys';
|
|
10
9
|
import { log } from '@dxos/log';
|
|
11
10
|
|
|
12
11
|
import { createGenerationStream, type GenerationStream } from './stream';
|
|
13
12
|
import { type GenerateRequest } from './types';
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
export interface AIService {
|
|
15
|
+
exec(request: GenerateRequest): Promise<GenerationStream>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface AIServiceClient extends AIService {
|
|
20
19
|
appendMessages(messages: Message[]): Promise<void>;
|
|
21
|
-
updateMessage(spaceId: SpaceId, threadId: string, messageId: string, message: Message): Promise<void>;
|
|
22
|
-
generate(request: GenerateRequest): Promise<GenerationStream>;
|
|
23
20
|
}
|
|
24
21
|
|
|
25
22
|
export type AIServiceClientParams = {
|
|
@@ -38,19 +35,6 @@ export class AIServiceClientImpl implements AIServiceClient {
|
|
|
38
35
|
this._endpoint = endpoint;
|
|
39
36
|
}
|
|
40
37
|
|
|
41
|
-
async getSpace(spaceId: SpaceId): Promise<Space> {
|
|
42
|
-
throw new Error('Not implemented');
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
async getThread(spaceId: SpaceId, threadId: string): Promise<Thread> {
|
|
46
|
-
throw new Error('Not implemented');
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
async getMessages(spaceId: SpaceId, threadId: string): Promise<Message[]> {
|
|
50
|
-
const res = await fetch(`${this._endpoint}/space/${spaceId}/thread/${threadId}/message`);
|
|
51
|
-
return S.decodePromise(S.Array(Message).pipe(S.mutable))((await res.json()).data.results);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
38
|
async appendMessages(messages: Message[]): Promise<void> {
|
|
55
39
|
const url = `${this._endpoint}/message`;
|
|
56
40
|
const res = await fetch(url, {
|
|
@@ -66,15 +50,10 @@ export class AIServiceClientImpl implements AIServiceClient {
|
|
|
66
50
|
}
|
|
67
51
|
}
|
|
68
52
|
|
|
69
|
-
// TODO(dmaretskyi): Accept partial message schema.
|
|
70
|
-
async updateMessage(spaceId: SpaceId, threadId: string, messageId: string, message: Message): Promise<void> {
|
|
71
|
-
throw new Error('Not implemented');
|
|
72
|
-
}
|
|
73
|
-
|
|
74
53
|
/**
|
|
75
|
-
*
|
|
54
|
+
* Process request and open message stream.
|
|
76
55
|
*/
|
|
77
|
-
async
|
|
56
|
+
async exec(request: GenerateRequest): Promise<GenerationStream> {
|
|
78
57
|
// TODO(dmaretskyi): Errors if tools are not provided.
|
|
79
58
|
request = {
|
|
80
59
|
tools: request.tools ?? [],
|
package/src/ai-service/stream.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { iterSSEMessages } from './util';
|
|
|
11
11
|
/**
|
|
12
12
|
* Creates a stream from an SSE response.
|
|
13
13
|
*/
|
|
14
|
-
export const createGenerationStream = (response: Response, controller = new AbortController()) => {
|
|
14
|
+
export const createGenerationStream = (response: Response, controller = new AbortController()): GenerationStream => {
|
|
15
15
|
const iterator = async function* () {
|
|
16
16
|
for await (const sse of iterSSEMessages(response, controller)) {
|
|
17
17
|
if (sse.event === 'completion') {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type GenerationStream, type AIService, type GenerateRequest, createGenerationStream } from '@dxos/assistant';
|
|
6
|
+
|
|
7
|
+
import { createTestSSEStream } from './test-stream';
|
|
8
|
+
|
|
9
|
+
export class MockAIService implements AIService {
|
|
10
|
+
constructor(private readonly _responses: string[]) {}
|
|
11
|
+
|
|
12
|
+
// TODO(burdon): Match response to request.
|
|
13
|
+
// TODO(burdon): See MockGpt (from conductor).
|
|
14
|
+
async exec(request: GenerateRequest): Promise<GenerationStream> {
|
|
15
|
+
return createGenerationStream(new Response(createTestSSEStream(this._responses)));
|
|
16
|
+
}
|
|
17
|
+
}
|
package/src/ai-service/types.ts
CHANGED
|
@@ -34,25 +34,25 @@ export const GenerateRequest = S.Struct({
|
|
|
34
34
|
model: S.optional(LLMModel),
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
|
-
*
|
|
37
|
+
* Tools available for the LLM.
|
|
38
38
|
*/
|
|
39
|
-
|
|
39
|
+
tools: S.optional(S.Array(Tool).pipe(S.mutable)),
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
|
-
*
|
|
42
|
+
* System instructions to the LLM.
|
|
43
43
|
*/
|
|
44
|
-
|
|
45
|
-
// prompt: Message,
|
|
44
|
+
systemPrompt: S.optional(S.String),
|
|
46
45
|
|
|
47
46
|
/**
|
|
48
47
|
* History of messages to include in the context window.
|
|
49
48
|
*/
|
|
49
|
+
// TODO(burdon): Rename messages.
|
|
50
50
|
history: S.optional(S.Array(Message)),
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
|
-
*
|
|
53
|
+
* Current request.
|
|
54
54
|
*/
|
|
55
|
-
|
|
55
|
+
prompt: S.optional(Message),
|
|
56
56
|
});
|
|
57
57
|
|
|
58
58
|
export type GenerateRequest = S.Schema.Type<typeof GenerateRequest>;
|
|
@@ -37,7 +37,7 @@ describe.skip('Conversation tests', () => {
|
|
|
37
37
|
});
|
|
38
38
|
|
|
39
39
|
test('tool call', async ({ expect }) => {
|
|
40
|
-
const custodian = defineTool({
|
|
40
|
+
const custodian = defineTool('testing', {
|
|
41
41
|
name: 'custodian',
|
|
42
42
|
description: 'Custodian can tell you the password if you say the magic word',
|
|
43
43
|
schema: S.Struct({
|
|
@@ -43,7 +43,7 @@ export const runLLM = async (params: CreateLLMConversationParams) => {
|
|
|
43
43
|
const generate = async () => {
|
|
44
44
|
log('llm generate', { tools: params.tools });
|
|
45
45
|
const beginTs = Date.now();
|
|
46
|
-
const stream = await params.client.
|
|
46
|
+
const stream = await params.client.exec({
|
|
47
47
|
model: params.model,
|
|
48
48
|
spaceId: params.spaceId,
|
|
49
49
|
threadId: params.threadId,
|
|
@@ -41,16 +41,16 @@ const list: ArtifactDef = {
|
|
|
41
41
|
description: 'Ordered set of text items.',
|
|
42
42
|
schema: ListSchema,
|
|
43
43
|
actions: [
|
|
44
|
-
defineTool({
|
|
45
|
-
name: '
|
|
44
|
+
defineTool('list', {
|
|
45
|
+
name: 'query',
|
|
46
46
|
description: 'Query all lists',
|
|
47
47
|
schema: S.Struct({}),
|
|
48
48
|
execute: async ({}, context) => {
|
|
49
49
|
return ToolResult.Success(LISTS[id]);
|
|
50
50
|
},
|
|
51
51
|
}),
|
|
52
|
-
defineTool({
|
|
53
|
-
name: '
|
|
52
|
+
defineTool('list', {
|
|
53
|
+
name: 'inspect',
|
|
54
54
|
description: 'Get contents of the list',
|
|
55
55
|
schema: S.Struct({
|
|
56
56
|
id: ObjectId.annotations({ description: 'The list to inspect' }),
|
|
@@ -59,8 +59,8 @@ const list: ArtifactDef = {
|
|
|
59
59
|
return ToolResult.Success(LISTS[id]);
|
|
60
60
|
},
|
|
61
61
|
}),
|
|
62
|
-
defineTool({
|
|
63
|
-
name: '
|
|
62
|
+
defineTool('list', {
|
|
63
|
+
name: 'create',
|
|
64
64
|
description: 'Add one or more items to an existing list',
|
|
65
65
|
schema: S.Struct({
|
|
66
66
|
id: ObjectId.annotations({ description: 'The list to add items to' }),
|
|
@@ -78,7 +78,7 @@ const LISTS: Record<ObjectId, ListSchema> = {};
|
|
|
78
78
|
|
|
79
79
|
const artifacts = [list];
|
|
80
80
|
|
|
81
|
-
const getArtifactDefinitions = defineTool({
|
|
81
|
+
const getArtifactDefinitions = defineTool('system', {
|
|
82
82
|
name: 'getArtifactDefinitions',
|
|
83
83
|
description: 'Queries the definitions and metadata of artifacts defined in the system',
|
|
84
84
|
schema: S.Any,
|
|
@@ -12,34 +12,34 @@ import { executeQuery, formatJsonSchemaForLLM, type DataSource } from '../cypher
|
|
|
12
12
|
import { trim } from '../util';
|
|
13
13
|
|
|
14
14
|
export const createCypherTool = (dataSource: DataSource, schemaTypes: S.Schema.Any[] = []) =>
|
|
15
|
-
defineTool({
|
|
16
|
-
name: '
|
|
15
|
+
defineTool('dxos.org/echo', {
|
|
16
|
+
name: 'query',
|
|
17
17
|
description:
|
|
18
18
|
'Query the ECHO graph database in cypher query language. Returns data from the database.' +
|
|
19
19
|
(schemaTypes.length > 0 ? `\n\n${createSystemPrompt(schemaTypes)}` : ''),
|
|
20
20
|
schema: S.Struct({
|
|
21
21
|
query: S.String.annotations({
|
|
22
22
|
description: `
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
A valid cypher query string to execute.
|
|
24
|
+
Query must have one MATCH clause.
|
|
25
|
+
Match clause can have multiple patterns but they must all be connected via a relationship chain.
|
|
26
|
+
Query might have zero or one WHERE clauses.
|
|
27
|
+
Query must have one RETURN clause.
|
|
28
|
+
RETURN clause can have multiple expressions separated by commas.
|
|
29
|
+
DISTINCT keyword is not allowed.
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
<example>
|
|
32
|
+
MATCH (n:Person) RETURN n.name
|
|
33
|
+
</example>
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
35
|
+
<example>
|
|
36
|
+
MATCH (s:Studio)-[:PRODUCED]->(m:Movie)-[:PRODUCED_IN]->(c:City {name: "Las Vegas"}) RETURN s
|
|
37
|
+
</example>
|
|
38
|
+
|
|
39
|
+
<example>
|
|
40
|
+
MATCH (a:Actor)-[:STARRED_IN]->(m:Movie)<-[:PRODUCED]-(s:Studio {name: "Cinema Pictures"}) WHERE m.name = "Once upon a time" RETURN m.name, a.name
|
|
41
|
+
</example>
|
|
42
|
+
`,
|
|
43
43
|
}),
|
|
44
44
|
}),
|
|
45
45
|
execute: async ({ query }) => {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../../../../src/ai-service/testing.ts"],"names":[],"mappings":"AAQA;;GAEG;AACH,eAAO,MAAM,mBAAmB,SACxB,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,gBACH;IAAE,OAAO,CAAC,EAAE,MAAM,GAAG,WAAW,CAAA;CAAE,KACvD,cA8EF,CAAC"}
|