@dxos/assistant 0.8.1-staging.9eaf14f → 0.8.2-main.12df754

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 (61) hide show
  1. package/dist/lib/browser/{chunk-PND5VR6D.mjs → chunk-DEIGOD4U.mjs} +91 -84
  2. package/dist/lib/browser/chunk-DEIGOD4U.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +6 -4
  4. package/dist/lib/browser/index.mjs.map +3 -3
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/testing/index.mjs +20 -20
  7. package/dist/lib/browser/testing/index.mjs.map +3 -3
  8. package/dist/lib/node/{chunk-IBOBRBDF.cjs → chunk-7VH7NMIM.cjs} +106 -98
  9. package/dist/lib/node/chunk-7VH7NMIM.cjs.map +7 -0
  10. package/dist/lib/node/index.cjs +37 -35
  11. package/dist/lib/node/index.cjs.map +3 -3
  12. package/dist/lib/node/meta.json +1 -1
  13. package/dist/lib/node/testing/index.cjs +27 -27
  14. package/dist/lib/node/testing/index.cjs.map +3 -3
  15. package/dist/lib/node-esm/{chunk-DCQJOLSR.mjs → chunk-7JI4MDGL.mjs} +91 -84
  16. package/dist/lib/node-esm/chunk-7JI4MDGL.mjs.map +7 -0
  17. package/dist/lib/node-esm/index.mjs +6 -4
  18. package/dist/lib/node-esm/index.mjs.map +3 -3
  19. package/dist/lib/node-esm/meta.json +1 -1
  20. package/dist/lib/node-esm/testing/index.mjs +20 -20
  21. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  22. package/dist/types/src/ai-service/edge-client.d.ts +4 -5
  23. package/dist/types/src/ai-service/edge-client.d.ts.map +1 -1
  24. package/dist/types/src/ai-service/message-collector.d.ts +0 -6
  25. package/dist/types/src/ai-service/message-collector.d.ts.map +1 -1
  26. package/dist/types/src/ai-service/ollama-client.d.ts +6 -2
  27. package/dist/types/src/ai-service/ollama-client.d.ts.map +1 -1
  28. package/dist/types/src/ai-service/parser.d.ts +0 -3
  29. package/dist/types/src/ai-service/parser.d.ts.map +1 -1
  30. package/dist/types/src/ai-service/service.d.ts +18 -2
  31. package/dist/types/src/ai-service/service.d.ts.map +1 -1
  32. package/dist/types/src/ai-service/testing/mock.d.ts +6 -2
  33. package/dist/types/src/ai-service/testing/mock.d.ts.map +1 -1
  34. package/dist/types/src/ai-service/types.d.ts +52 -9
  35. package/dist/types/src/ai-service/types.d.ts.map +1 -1
  36. package/dist/types/src/conversation/conversation.d.ts +0 -3
  37. package/dist/types/src/conversation/conversation.d.ts.map +1 -1
  38. package/dist/types/src/conversation/types.d.ts +2 -3
  39. package/dist/types/src/conversation/types.d.ts.map +1 -1
  40. package/dist/types/src/cypher/echo-data-source.d.ts.map +1 -1
  41. package/dist/types/src/session/session.d.ts +0 -6
  42. package/dist/types/src/session/session.d.ts.map +1 -1
  43. package/package.json +13 -13
  44. package/src/ai-service/client.test.ts +50 -68
  45. package/src/ai-service/edge-client.ts +13 -20
  46. package/src/ai-service/ollama-client.ts +9 -2
  47. package/src/ai-service/parser.ts +13 -2
  48. package/src/ai-service/service.ts +19 -3
  49. package/src/ai-service/testing/mock.ts +9 -1
  50. package/src/ai-service/types.ts +15 -6
  51. package/src/bin/chat.ts +1 -1
  52. package/src/conversation/conversation.ts +5 -11
  53. package/src/conversation/types.ts +1 -4
  54. package/src/cypher/echo-data-source.ts +1 -2
  55. package/src/session/session.test.ts +6 -6
  56. package/src/session/session.ts +3 -3
  57. package/src/testing/query.test.ts +14 -16
  58. package/src/testing/test-data.ts +19 -19
  59. package/dist/lib/browser/chunk-PND5VR6D.mjs.map +0 -7
  60. package/dist/lib/node/chunk-IBOBRBDF.cjs.map +0 -7
  61. package/dist/lib/node-esm/chunk-DCQJOLSR.mjs.map +0 -7
@@ -4,8 +4,8 @@
4
4
 
5
5
  import { Schema as S } from 'effect';
6
6
 
7
- import { Tool, Message, type MessageContentBlock, SpaceIdSchema } from '@dxos/artifact';
8
- import { ObjectId } from '@dxos/echo-schema';
7
+ import { Tool, Message, type MessageContentBlock } from '@dxos/artifact';
8
+ import { type ObjectId } from '@dxos/echo-schema';
9
9
 
10
10
  import { DEFAULT_EDGE_MODELS, DEFAULT_OLLAMA_MODELS } from './defs';
11
11
 
@@ -25,9 +25,6 @@ export const ToolTypes = Object.freeze({
25
25
  * Client GPT request.
26
26
  */
27
27
  export const GenerateRequest = S.Struct({
28
- spaceId: S.optional(SpaceIdSchema),
29
- threadId: S.optional(ObjectId),
30
-
31
28
  /**
32
29
  * Preferred model or system default.
33
30
  */
@@ -54,9 +51,21 @@ export const GenerateRequest = S.Struct({
54
51
  */
55
52
  prompt: S.optional(Message),
56
53
  });
57
-
58
54
  export type GenerateRequest = S.Schema.Type<typeof GenerateRequest>;
59
55
 
56
+ /**
57
+ * Non-streaming response.
58
+ */
59
+ export const GenerateResponse = S.Struct({
60
+ messages: S.Array(Message),
61
+
62
+ /**
63
+ * Number of tokens used in the response.
64
+ */
65
+ tokenCount: S.optional(S.Number),
66
+ });
67
+ export type GenerateResponse = S.Schema.Type<typeof GenerateResponse>;
68
+
60
69
  /**
61
70
  * Server-Sent Events (SSE) stream from the AI service.
62
71
  * https://docs.anthropic.com/en/api/streaming
package/src/bin/chat.ts CHANGED
@@ -46,7 +46,6 @@ while (true) {
46
46
  message: 'Enter a message:',
47
47
  },
48
48
  ]);
49
- await client.appendMessages([createUserMessage(spaceId, threadId, prompt.message)]);
50
49
 
51
50
  await runLLM({
52
51
  model: DEFAULT_EDGE_MODEL,
@@ -61,6 +60,7 @@ while (true) {
61
60
  },
62
61
  ],
63
62
  client,
63
+ history: [createUserMessage(spaceId, threadId, prompt.message)],
64
64
  logger: createLogger({
65
65
  stream: true,
66
66
  filter: (e) => {
@@ -3,7 +3,7 @@
3
3
  //
4
4
 
5
5
  import { type Tool, ToolResult, Message } from '@dxos/artifact';
6
- import { createStatic, ObjectId } from '@dxos/echo-schema';
6
+ import { create, ObjectId } from '@dxos/echo-schema';
7
7
  import { invariant } from '@dxos/invariant';
8
8
  import { type SpaceId } from '@dxos/keys';
9
9
  import { log } from '@dxos/log';
@@ -43,10 +43,8 @@ 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.exec({
46
+ const stream = await params.client.execStream({
47
47
  model: params.model,
48
- spaceId: params.spaceId,
49
- threadId: params.threadId,
50
48
  history,
51
49
  systemPrompt: params.system,
52
50
  tools: params.tools as any,
@@ -88,8 +86,6 @@ export const runLLM = async (params: CreateLLMConversationParams) => {
88
86
  log.warn('tool error', { message: toolResult.message });
89
87
  const resultMessage: Message = {
90
88
  id: ObjectId.random(),
91
- spaceId: params.spaceId,
92
- threadId: params.threadId,
93
89
  role: 'user',
94
90
  content: [
95
91
  {
@@ -110,8 +106,6 @@ export const runLLM = async (params: CreateLLMConversationParams) => {
110
106
  log('tool success', { result: toolResult.result });
111
107
  const resultMessage: Message = {
112
108
  id: ObjectId.random(),
113
- spaceId: params.spaceId,
114
- threadId: params.threadId,
115
109
  role: 'user',
116
110
  content: [
117
111
  {
@@ -175,7 +169,7 @@ export const runTools = async ({ message, tools, extensions }: RunToolsOptions):
175
169
  const toolCall = toolCalls[0];
176
170
  const tool = tools.find((tool) => tool.name === toolCall.name);
177
171
  if (!tool) {
178
- const resultMessage = createStatic(Message, {
172
+ const resultMessage = create(Message, {
179
173
  role: 'user',
180
174
  content: [
181
175
  {
@@ -206,7 +200,7 @@ export const runTools = async ({ message, tools, extensions }: RunToolsOptions):
206
200
  switch (toolResult.kind) {
207
201
  case 'error': {
208
202
  log('tool error', { message: toolResult.message });
209
- const resultMessage = createStatic(Message, {
203
+ const resultMessage = create(Message, {
210
204
  role: 'user',
211
205
  content: [
212
206
  {
@@ -227,7 +221,7 @@ export const runTools = async ({ message, tools, extensions }: RunToolsOptions):
227
221
 
228
222
  case 'success': {
229
223
  log('tool success', { result: toolResult.result });
230
- const resultMessage = createStatic(Message, {
224
+ const resultMessage = create(Message, {
231
225
  role: 'user',
232
226
  content: [
233
227
  {
@@ -6,13 +6,10 @@ import { Schema as S } from 'effect';
6
6
 
7
7
  import { type Message, type MessageContentBlock } from '@dxos/artifact';
8
8
  import { toJsonSchema, JsonSchemaType, ObjectId } from '@dxos/echo-schema';
9
- import type { SpaceId } from '@dxos/keys';
10
9
  import { log } from '@dxos/log';
11
10
 
12
- export const createUserMessage = (spaceId: SpaceId, threadId: ObjectId, text: string): Message => ({
11
+ export const createUserMessage = (text: string): Message => ({
13
12
  id: ObjectId.random(),
14
- spaceId,
15
- threadId,
16
13
  role: 'user',
17
14
  content: [{ type: 'text', text }],
18
15
  });
@@ -4,8 +4,7 @@
4
4
 
5
5
  import { raise } from '@dxos/debug';
6
6
  import { type EchoDatabase, Filter, type ReactiveEchoObject } from '@dxos/echo-db';
7
- import { type S, getSchemaTypename, StoredSchema, toJsonSchema } from '@dxos/echo-schema';
8
- import { getSchema } from '@dxos/live-object';
7
+ import { getSchema, getSchemaTypename, type S, StoredSchema, toJsonSchema } from '@dxos/echo-schema';
9
8
  import { log } from '@dxos/log';
10
9
 
11
10
  import type { DataSource, Node, Relationship } from './query-executor';
@@ -15,7 +15,7 @@ import {
15
15
  type MessageContentBlock,
16
16
  } from '@dxos/artifact';
17
17
  import { AIServiceEdgeClient } from '@dxos/assistant';
18
- import { createStatic, EchoObject, ObjectId } from '@dxos/echo-schema';
18
+ import { create, EchoObject, ObjectId } from '@dxos/echo-schema';
19
19
  import { DXN } from '@dxos/keys';
20
20
  import { log } from '@dxos/log';
21
21
 
@@ -156,31 +156,31 @@ describe.skip('AISession with Ollama', () => {
156
156
 
157
157
  // Travel to rome, florence, livorno, siena, madrid for conferences
158
158
  const CALENDAR_EVENTS: CalendarEvent[] = [
159
- createStatic(CalendarEventSchema, {
159
+ create(CalendarEventSchema, {
160
160
  title: 'Exploring Ancient Ruins in Rome',
161
161
  startTime: '2024-01-01T10:00:00Z',
162
162
  endTime: '2024-01-01T11:00:00Z',
163
163
  description: 'Tech conference at the historic Colosseum with networking opportunities',
164
164
  }),
165
- createStatic(CalendarEventSchema, {
165
+ create(CalendarEventSchema, {
166
166
  title: 'Renaissance Tech Summit in Florence',
167
167
  startTime: '2024-01-01T11:00:00Z',
168
168
  endTime: '2024-01-01T12:00:00Z',
169
169
  description: 'Discussing AI innovations surrounded by Renaissance art',
170
170
  }),
171
- createStatic(CalendarEventSchema, {
171
+ create(CalendarEventSchema, {
172
172
  title: 'Travel to Livorno',
173
173
  startTime: '2024-01-01T12:00:00Z',
174
174
  endTime: '2024-01-01T13:00:00Z',
175
175
  description: 'Travel to Livorno',
176
176
  }),
177
- createStatic(CalendarEventSchema, {
177
+ create(CalendarEventSchema, {
178
178
  title: 'Travel to Siena',
179
179
  startTime: '2024-01-01T13:00:00Z',
180
180
  endTime: '2024-01-01T14:00:00Z',
181
181
  description: 'Travel to Siena',
182
182
  }),
183
- createStatic(CalendarEventSchema, {
183
+ create(CalendarEventSchema, {
184
184
  title: 'Travel to Madrid',
185
185
  startTime: '2024-01-01T14:00:00Z',
186
186
  endTime: '2024-01-01T15:00:00Z',
@@ -6,7 +6,7 @@ import { Schema as S } from 'effect';
6
6
 
7
7
  import { defineTool, Message, ToolResult, type ArtifactDefinition, type Tool } from '@dxos/artifact';
8
8
  import { Event, synchronized } from '@dxos/async';
9
- import { createStatic } from '@dxos/echo-schema';
9
+ import { create } from '@dxos/echo-schema';
10
10
  import { invariant } from '@dxos/invariant';
11
11
  import { log } from '@dxos/log';
12
12
 
@@ -240,7 +240,7 @@ export class AISession {
240
240
 
241
241
  this._history = [...options.history];
242
242
  this._pending = [
243
- createStatic(Message, {
243
+ create(Message, {
244
244
  role: 'user',
245
245
  content: [{ type: 'text', text: options.prompt }],
246
246
  }),
@@ -268,7 +268,7 @@ export class AISession {
268
268
  });
269
269
 
270
270
  // Open request stream.
271
- this._stream = await options.client.exec({
271
+ this._stream = await options.client.execStream({
272
272
  ...(options.generationOptions ?? {}),
273
273
  // TODO(burdon): Rename messages or separate history/message.
274
274
  history: [...this._history, ...this._pending],
@@ -32,20 +32,19 @@ test.skip('cypher query', async () => {
32
32
  const spaceId = SpaceId.random();
33
33
  const threadId = ObjectId.random();
34
34
 
35
- await client.appendMessages([
36
- createUserMessage(
37
- spaceId,
38
- threadId,
39
- 'Query the database and give me all employees from DXOS organization that work on Composer and what their tasks are.',
40
- ),
41
- ]);
42
-
43
35
  const result = await runLLM({
44
36
  model: DEFAULT_EDGE_MODEL,
45
37
  tools: [cypherTool],
46
38
  spaceId,
47
39
  threadId,
48
40
  system: createSystemPrompt(schemaTypes),
41
+ history: [
42
+ createUserMessage(
43
+ spaceId,
44
+ threadId,
45
+ 'Query the database and give me all employees from DXOS organization that work on Composer and what their tasks are.',
46
+ ),
47
+ ],
49
48
  client,
50
49
  logger: createLogger({ stream: false }),
51
50
  });
@@ -69,14 +68,6 @@ test.skip('query ECHO', async () => {
69
68
  const spaceId = SpaceId.random();
70
69
  const threadId = ObjectId.random();
71
70
 
72
- await client.appendMessages([
73
- createUserMessage(
74
- spaceId,
75
- threadId,
76
- 'Query the database and give me all employees from DXOS organization that work on Composer and what their tasks are.',
77
- ),
78
- ]);
79
-
80
71
  const result = await runLLM({
81
72
  model: DEFAULT_EDGE_MODEL,
82
73
  tools: [cypherTool],
@@ -84,6 +75,13 @@ test.skip('query ECHO', async () => {
84
75
  threadId,
85
76
  system: createSystemPrompt(schemaTypes),
86
77
  client,
78
+ history: [
79
+ createUserMessage(
80
+ spaceId,
81
+ threadId,
82
+ 'Query the database and give me all employees from DXOS organization that work on Composer and what their tasks are.',
83
+ ),
84
+ ],
87
85
  logger: createLogger({ stream: false }),
88
86
  });
89
87
 
@@ -8,7 +8,7 @@ import { raise } from '@dxos/debug';
8
8
  import type { EchoDatabase } from '@dxos/echo-db';
9
9
  import { JSON_SCHEMA_ECHO_REF_ID, ObjectId, toJsonSchema, type JsonSchemaType, type Ref } from '@dxos/echo-schema';
10
10
  import { invariant } from '@dxos/invariant';
11
- import { create, makeRef } from '@dxos/live-object';
11
+ import { live, makeRef } from '@dxos/live-object';
12
12
 
13
13
  import {
14
14
  type DataSource,
@@ -21,100 +21,100 @@ import { Contact, Org, Project, Task } from '../testing';
21
21
 
22
22
  export const seedTestData = (db: EchoDatabase) => {
23
23
  const contactRich = db.add(
24
- create(Contact, {
24
+ live(Contact, {
25
25
  name: 'Rich',
26
26
  }),
27
27
  );
28
28
  const contactJosiah = db.add(
29
- create(Contact, {
29
+ live(Contact, {
30
30
  name: 'Josiah',
31
31
  }),
32
32
  );
33
33
  const contactDima = db.add(
34
- create(Contact, {
34
+ live(Contact, {
35
35
  name: 'Dima',
36
36
  }),
37
37
  );
38
38
  const contactFred = db.add(
39
- create(Contact, {
39
+ live(Contact, {
40
40
  name: 'Fred',
41
41
  }),
42
42
  );
43
43
 
44
44
  const projectComposer = db.add(
45
- create(Project, {
45
+ live(Project, {
46
46
  name: 'Composer',
47
47
  }),
48
48
  );
49
49
  const projectEcho = db.add(
50
- create(Project, {
50
+ live(Project, {
51
51
  name: 'ECHO',
52
52
  }),
53
53
  );
54
54
  const projectDoodles = db.add(
55
- create(Project, {
55
+ live(Project, {
56
56
  name: 'Doodles',
57
57
  }),
58
58
  );
59
59
 
60
60
  const _taskComposer1 = db.add(
61
- create(Task, {
61
+ live(Task, {
62
62
  name: 'Optimize startup performance',
63
63
  project: makeRef(projectComposer),
64
64
  assignee: makeRef(contactJosiah),
65
65
  }),
66
66
  );
67
67
  const _taskComposer2 = db.add(
68
- create(Task, {
68
+ live(Task, {
69
69
  name: 'Create form builder',
70
70
  project: makeRef(projectComposer),
71
71
  assignee: makeRef(contactRich),
72
72
  }),
73
73
  );
74
74
  const _taskComposer3 = db.add(
75
- create(Task, {
75
+ live(Task, {
76
76
  name: 'Add support for custom themes',
77
77
  project: makeRef(projectComposer),
78
78
  assignee: makeRef(contactJosiah),
79
79
  }),
80
80
  );
81
81
  const _taskComposer5 = db.add(
82
- create(Task, {
82
+ live(Task, {
83
83
  name: 'Implement community plugin',
84
84
  project: makeRef(projectComposer),
85
85
  assignee: makeRef(contactFred),
86
86
  }),
87
87
  );
88
88
  const _taskComposer4 = db.add(
89
- create(Task, {
89
+ live(Task, {
90
90
  name: 'Implement dark mode',
91
91
  project: makeRef(projectComposer),
92
92
  assignee: makeRef(contactRich),
93
93
  }),
94
94
  );
95
95
  const _taskEcho1 = db.add(
96
- create(Task, {
96
+ live(Task, {
97
97
  name: 'Implement cypher query engine',
98
98
  project: makeRef(projectEcho),
99
99
  assignee: makeRef(contactDima),
100
100
  }),
101
101
  );
102
102
  const _taskEcho2 = db.add(
103
- create(Task, {
103
+ live(Task, {
104
104
  name: 'Add schema editor',
105
105
  project: makeRef(projectEcho),
106
106
  assignee: makeRef(contactRich),
107
107
  }),
108
108
  );
109
109
  const _taskDoodles1 = db.add(
110
- create(Task, {
110
+ live(Task, {
111
111
  name: 'Add support for custom themes',
112
112
  project: makeRef(projectDoodles),
113
113
  assignee: makeRef(contactFred),
114
114
  }),
115
115
  );
116
116
  const _taskDoodles2 = db.add(
117
- create(Task, {
117
+ live(Task, {
118
118
  name: 'Implement dark mode',
119
119
  project: makeRef(projectDoodles),
120
120
  assignee: makeRef(contactJosiah),
@@ -122,14 +122,14 @@ export const seedTestData = (db: EchoDatabase) => {
122
122
  );
123
123
 
124
124
  const _orgDxos = db.add(
125
- create(Org, {
125
+ live(Org, {
126
126
  name: 'DXOS',
127
127
  employees: [makeRef(contactRich), makeRef(contactJosiah), makeRef(contactDima)],
128
128
  projects: [makeRef(projectEcho)],
129
129
  }),
130
130
  );
131
131
  const _orgBraneframe = db.add(
132
- create(Org, {
132
+ live(Org, {
133
133
  name: 'Braneframe',
134
134
  employees: [makeRef(contactJosiah), makeRef(contactRich)],
135
135
  projects: [makeRef(projectComposer)],