@dxos/assistant 0.7.5-staging.b81e783 → 0.8.0

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.
Files changed (50) hide show
  1. package/dist/lib/browser/index.mjs +35 -28
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/browser/testing/index.mjs +20 -20
  5. package/dist/lib/browser/testing/index.mjs.map +2 -2
  6. package/dist/lib/node/index.cjs +35 -28
  7. package/dist/lib/node/index.cjs.map +4 -4
  8. package/dist/lib/node/meta.json +1 -1
  9. package/dist/lib/node/testing/index.cjs +20 -20
  10. package/dist/lib/node/testing/index.cjs.map +2 -2
  11. package/dist/lib/node-esm/index.mjs +35 -28
  12. package/dist/lib/node-esm/index.mjs.map +4 -4
  13. package/dist/lib/node-esm/meta.json +1 -1
  14. package/dist/lib/node-esm/testing/index.mjs +20 -20
  15. package/dist/lib/node-esm/testing/index.mjs.map +2 -2
  16. package/dist/types/src/ai-service/client.d.ts +7 -14
  17. package/dist/types/src/ai-service/client.d.ts.map +1 -1
  18. package/dist/types/src/ai-service/defs.d.ts +3 -0
  19. package/dist/types/src/ai-service/defs.d.ts.map +1 -0
  20. package/dist/types/src/ai-service/index.d.ts +1 -0
  21. package/dist/types/src/ai-service/index.d.ts.map +1 -1
  22. package/dist/types/src/ai-service/parser.d.ts +1 -1
  23. package/dist/types/src/ai-service/stream.d.ts.map +1 -1
  24. package/dist/types/src/ai-service/testing/index.d.ts +3 -0
  25. package/dist/types/src/ai-service/testing/index.d.ts.map +1 -0
  26. package/dist/types/src/ai-service/testing/mock.d.ts +7 -0
  27. package/dist/types/src/ai-service/testing/mock.d.ts.map +1 -0
  28. package/dist/types/src/ai-service/{testing.d.ts → testing/test-stream.d.ts} +1 -1
  29. package/dist/types/src/ai-service/testing/test-stream.d.ts.map +1 -0
  30. package/dist/types/src/ai-service/types.d.ts +97 -14
  31. package/dist/types/src/ai-service/types.d.ts.map +1 -1
  32. package/dist/types/src/conversation/conversation.d.ts.map +1 -1
  33. package/package.json +13 -13
  34. package/src/ai-service/client.test.ts +9 -8
  35. package/src/ai-service/client.ts +8 -29
  36. package/src/ai-service/defs.ts +24 -0
  37. package/src/ai-service/index.ts +1 -0
  38. package/src/ai-service/stream.ts +1 -1
  39. package/src/ai-service/testing/index.ts +6 -0
  40. package/src/ai-service/testing/mock.ts +17 -0
  41. package/src/ai-service/{testing.ts → testing/test-stream.ts} +1 -1
  42. package/src/ai-service/types.ts +12 -16
  43. package/src/bin/chat.ts +2 -2
  44. package/src/conversation/conversation.test.ts +4 -4
  45. package/src/conversation/conversation.ts +1 -1
  46. package/src/testing/artifacts.test.ts +9 -9
  47. package/src/testing/object-extraction.test.ts +1 -1
  48. package/src/testing/query-promts.ts +20 -20
  49. package/src/testing/query.test.ts +3 -3
  50. package/dist/types/src/ai-service/testing.d.ts.map +0 -1
@@ -0,0 +1,24 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ // TODO(burdon): Share with Edge.
6
+ // TODO(burdon): Move to service config retrieved by HTTP?
7
+
8
+ export const DEFAULT_LLM_MODEL = '@anthropic/claude-3-5-sonnet-20241022';
9
+
10
+ export const DEFAULT_LLM_MODELS = [
11
+ // AI Gateway.
12
+ // https://developers.cloudflare.com/ai-gateway
13
+ '@anthropic/claude-3-5-haiku-20241022',
14
+ '@anthropic/claude-3-5-sonnet-20241022',
15
+ '@anthropic/claude-3-7-sonnet-20250219',
16
+
17
+ // Workers AI.
18
+ // https://developers.cloudflare.com/workers-ai/models
19
+ '@cf/deepseek-ai/deepseek-r1-distill-qwen-32b',
20
+ '@hf/nousresearch/hermes-2-pro-mistral-7b',
21
+ '@ollama/llama-3-1-nemotron-70b-instruct',
22
+ '@ollama/llama-3-1-nemotron-mini-4b-instruct',
23
+ '@ollama/llama-3-2-3b',
24
+ ];
@@ -3,6 +3,7 @@
3
3
  //
4
4
 
5
5
  export * from './client';
6
+ export * from './defs';
6
7
  export * from './parser';
7
8
  export * from './stream';
8
9
  export * from './transform';
@@ -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,6 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ export * from './mock';
6
+ export * from './test-stream';
@@ -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
+ }
@@ -4,7 +4,7 @@
4
4
 
5
5
  import { ObjectId } from '@dxos/echo-schema';
6
6
 
7
- import { type GenerationStreamEvent } from './types';
7
+ import { type GenerationStreamEvent } from '../types';
8
8
 
9
9
  /**
10
10
  * Mock server-side events (SSE) stream.
@@ -7,17 +7,11 @@ import { Schema as S } from '@effect/schema';
7
7
  import { Tool, Message, type MessageContentBlock, SpaceIdSchema } from '@dxos/artifact';
8
8
  import { ObjectId } from '@dxos/echo-schema';
9
9
 
10
+ import { DEFAULT_LLM_MODELS } from './defs';
11
+
10
12
  export const createArtifactElement = (id: ObjectId) => `<artifact id=${id} />`;
11
13
 
12
- export const LLMModel = S.Literal(
13
- '@anthropic/claude-3-5-haiku-20241022',
14
- '@anthropic/claude-3-5-sonnet-20241022',
15
- '@cf/deepseek-ai/deepseek-r1-distill-qwen-32b',
16
- '@hf/nousresearch/hermes-2-pro-mistral-7b',
17
- '@ollama/llama-3-2-3b',
18
- '@ollama/llama-3-1-nemotron-70b-instruct',
19
- '@ollama/llama-3-1-nemotron-mini-4b-instruct',
20
- );
14
+ export const LLMModel = S.Literal(...DEFAULT_LLM_MODELS);
21
15
 
22
16
  export type LLMModel = S.Schema.Type<typeof LLMModel>;
23
17
 
@@ -34,14 +28,15 @@ export const GenerateRequest = S.Struct({
34
28
  spaceId: S.optional(SpaceIdSchema),
35
29
  threadId: S.optional(ObjectId),
36
30
 
37
- // TODO(burdon): Make optional with default.
38
- model: LLMModel,
31
+ /**
32
+ * Preferred model or system default.
33
+ */
34
+ model: S.optional(LLMModel),
39
35
 
40
36
  /**
41
- * Current request.
37
+ * Tools available for the LLM.
42
38
  */
43
- // TODO(burdon): Remove from history.
44
- // prompt: Message,
39
+ tools: S.optional(S.Array(Tool).pipe(S.mutable)),
45
40
 
46
41
  /**
47
42
  * System instructions to the LLM.
@@ -51,12 +46,13 @@ export const GenerateRequest = S.Struct({
51
46
  /**
52
47
  * History of messages to include in the context window.
53
48
  */
49
+ // TODO(burdon): Rename messages.
54
50
  history: S.optional(S.Array(Message)),
55
51
 
56
52
  /**
57
- * Tools available for the LLM.
53
+ * Current request.
58
54
  */
59
- tools: S.optional(S.Array(Tool).pipe(S.mutable)),
55
+ prompt: S.optional(Message),
60
56
  });
61
57
 
62
58
  export type GenerateRequest = S.Schema.Type<typeof GenerateRequest>;
package/src/bin/chat.ts CHANGED
@@ -10,7 +10,7 @@ import { ObjectId } from '@dxos/echo-schema';
10
10
  import { SpaceId } from '@dxos/keys';
11
11
  import { log } from '@dxos/log';
12
12
 
13
- import { AIServiceClientImpl, ToolTypes } from '../ai-service';
13
+ import { AIServiceClientImpl, ToolTypes, DEFAULT_LLM_MODEL } from '../ai-service';
14
14
  import { runLLM } from '../conversation';
15
15
  import {
16
16
  AI_SERVICE_ENDPOINT,
@@ -49,7 +49,7 @@ while (true) {
49
49
  await client.appendMessages([createUserMessage(spaceId, threadId, prompt.message)]);
50
50
 
51
51
  await runLLM({
52
- model: '@anthropic/claude-3-5-sonnet-20241022',
52
+ model: DEFAULT_LLM_MODEL,
53
53
  spaceId,
54
54
  threadId,
55
55
  system: createSystemPrompt(schemaTypes),
@@ -11,7 +11,7 @@ import { SpaceId } from '@dxos/keys';
11
11
  import { log } from '@dxos/log';
12
12
 
13
13
  import { runLLM, type ConversationEvent } from './conversation';
14
- import { AIServiceClientImpl } from '../ai-service';
14
+ import { AIServiceClientImpl, DEFAULT_LLM_MODEL } from '../ai-service';
15
15
  import { AI_SERVICE_ENDPOINT } from '../testing';
16
16
 
17
17
  // TODO(burdon): Local live LLM test.
@@ -25,7 +25,7 @@ describe.skip('Conversation tests', () => {
25
25
  const threadId = ObjectId.random();
26
26
 
27
27
  const result = await runLLM({
28
- model: '@anthropic/claude-3-5-sonnet-20241022',
28
+ model: DEFAULT_LLM_MODEL,
29
29
  history: [createUserMessage(spaceId, threadId, 'Hello, how are you?')],
30
30
  tools: [],
31
31
  client,
@@ -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({
@@ -56,7 +56,7 @@ describe.skip('Conversation tests', () => {
56
56
  const threadId = ObjectId.random();
57
57
 
58
58
  const result = await runLLM({
59
- model: '@anthropic/claude-3-5-sonnet-20241022',
59
+ model: DEFAULT_LLM_MODEL,
60
60
  history: [createUserMessage(spaceId, threadId, 'What is the password? Ask the custodian.')],
61
61
  tools: [custodian],
62
62
  client,
@@ -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.generate({
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: 'list.query',
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: 'list.inspect',
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: 'list.add',
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,
@@ -136,7 +136,7 @@ describe('Artifacts', () => {
136
136
  ]);
137
137
 
138
138
  const stream = await client.generate({
139
- model: '@anthropic/claude-3-5-haiku-20241022',
139
+ model: DEFAULT_LLM_MODEL,
140
140
  spaceId,
141
141
  threadId,
142
142
  systemPrompt: 'You are a helpful assistant.',
@@ -164,7 +164,7 @@ describe('Artifacts', () => {
164
164
  ]);
165
165
 
166
166
  const stream2 = await client.generate({
167
- model: '@anthropic/claude-3-5-haiku-20241022',
167
+ model: DEFAULT_LLM_MODEL,
168
168
  spaceId,
169
169
  threadId,
170
170
  systemPrompt: 'You are a helpful assistant.',
@@ -8,7 +8,7 @@
8
8
 
9
9
  // test('extract objects from the DXOS explainer', async () => {
10
10
  // const result = await runLLM({
11
- // model: '@anthropic/claude-3-5-haiku-20241022',
11
+ // model: DEFAULT_LLM_MODEL,
12
12
  // messages: [
13
13
  // createUserMessage(`
14
14
  // # README
@@ -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: 'graphQuery',
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
- 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.
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
- <example>
32
- MATCH (n:Person) RETURN n.name
33
- </example>
31
+ <example>
32
+ MATCH (n:Person) RETURN n.name
33
+ </example>
34
34
 
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
- `,
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 }) => {
@@ -15,7 +15,7 @@ import { createLogger } from './logger';
15
15
  import { createCypherTool, createSystemPrompt } from './query-promts';
16
16
  import { createTestData, seedTestData } from './test-data';
17
17
  import { Contact, Org, Project, Task } from './test-schema';
18
- import { AIServiceClientImpl } from '../ai-service';
18
+ import { AIServiceClientImpl, DEFAULT_LLM_MODEL } from '../ai-service';
19
19
  import { runLLM } from '../conversation';
20
20
  import { EchoDataSource } from '../cypher';
21
21
 
@@ -41,7 +41,7 @@ test.skip('cypher query', async () => {
41
41
  ]);
42
42
 
43
43
  const result = await runLLM({
44
- model: '@anthropic/claude-3-5-sonnet-20241022',
44
+ model: DEFAULT_LLM_MODEL,
45
45
  tools: [cypherTool],
46
46
  spaceId,
47
47
  threadId,
@@ -78,7 +78,7 @@ test.skip('query ECHO', async () => {
78
78
  ]);
79
79
 
80
80
  const result = await runLLM({
81
- model: '@anthropic/claude-3-5-sonnet-20241022',
81
+ model: DEFAULT_LLM_MODEL,
82
82
  tools: [cypherTool],
83
83
  spaceId,
84
84
  threadId,
@@ -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"}