@dxos/assistant 0.8.2-main.12df754 → 0.8.2-main.2f9c567

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 (65) hide show
  1. package/dist/lib/browser/{chunk-DEIGOD4U.mjs → chunk-OLO6SVOL.mjs} +21 -21
  2. package/dist/lib/browser/chunk-OLO6SVOL.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +272 -152
  4. package/dist/lib/browser/index.mjs.map +4 -4
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/testing/index.mjs +82 -86
  7. package/dist/lib/browser/testing/index.mjs.map +3 -3
  8. package/dist/lib/node/{chunk-7VH7NMIM.cjs → chunk-CI5Q7FBG.cjs} +6 -6
  9. package/dist/lib/node/chunk-CI5Q7FBG.cjs.map +7 -0
  10. package/dist/lib/node/index.cjs +300 -183
  11. package/dist/lib/node/index.cjs.map +4 -4
  12. package/dist/lib/node/meta.json +1 -1
  13. package/dist/lib/node/testing/index.cjs +72 -77
  14. package/dist/lib/node/testing/index.cjs.map +3 -3
  15. package/dist/lib/node-esm/{chunk-7JI4MDGL.mjs → chunk-Y3SYOFFJ.mjs} +21 -21
  16. package/dist/lib/node-esm/chunk-Y3SYOFFJ.mjs.map +7 -0
  17. package/dist/lib/node-esm/index.mjs +272 -152
  18. package/dist/lib/node-esm/index.mjs.map +4 -4
  19. package/dist/lib/node-esm/meta.json +1 -1
  20. package/dist/lib/node-esm/testing/index.mjs +82 -86
  21. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  22. package/dist/types/src/ai-service/types.d.ts +133 -133
  23. package/dist/types/src/ai-service/types.d.ts.map +1 -1
  24. package/dist/types/src/conversation/types.d.ts +9 -9
  25. package/dist/types/src/conversation/types.d.ts.map +1 -1
  26. package/dist/types/src/cypher/echo-data-source.d.ts.map +1 -1
  27. package/dist/types/src/session/index.d.ts +1 -0
  28. package/dist/types/src/session/index.d.ts.map +1 -1
  29. package/dist/types/src/session/session.d.ts +32 -7
  30. package/dist/types/src/session/session.d.ts.map +1 -1
  31. package/dist/types/src/session/version-pin.d.ts +17 -0
  32. package/dist/types/src/session/version-pin.d.ts.map +1 -0
  33. package/dist/types/src/session/version-pin.test.d.ts +2 -0
  34. package/dist/types/src/session/version-pin.test.d.ts.map +1 -0
  35. package/dist/types/src/testing/query-promts.d.ts +3 -3
  36. package/dist/types/src/testing/query-promts.d.ts.map +1 -1
  37. package/dist/types/src/testing/test-data.d.ts +4 -4
  38. package/dist/types/src/testing/test-data.d.ts.map +1 -1
  39. package/dist/types/src/testing/test-schema.d.ts +25 -23
  40. package/dist/types/src/testing/test-schema.d.ts.map +1 -1
  41. package/package.json +15 -14
  42. package/src/ai-service/client.test.ts +5 -5
  43. package/src/ai-service/ollama-client.ts +7 -7
  44. package/src/ai-service/types.ts +14 -14
  45. package/src/bin/chat.ts +2 -2
  46. package/src/conversation/conversation.test.ts +3 -3
  47. package/src/conversation/types.ts +10 -10
  48. package/src/cypher/combinators.test.ts +4 -4
  49. package/src/cypher/echo-data-source.ts +7 -5
  50. package/src/cypher/execution-plan.test.ts +1 -1
  51. package/src/cypher/query-executor.test.ts +1 -1
  52. package/src/cypher/schema.test.ts +3 -3
  53. package/src/session/index.ts +1 -0
  54. package/src/session/session.test.ts +24 -17
  55. package/src/session/session.ts +285 -149
  56. package/src/session/version-pin.test.ts +26 -0
  57. package/src/session/version-pin.ts +43 -0
  58. package/src/testing/artifacts.test.ts +22 -22
  59. package/src/testing/query-promts.ts +5 -5
  60. package/src/testing/query.test.ts +3 -3
  61. package/src/testing/test-data.ts +62 -55
  62. package/src/testing/test-schema.ts +28 -29
  63. package/dist/lib/browser/chunk-DEIGOD4U.mjs.map +0 -7
  64. package/dist/lib/node/chunk-7VH7NMIM.cjs.map +0 -7
  65. package/dist/lib/node-esm/chunk-7JI4MDGL.mjs.map +0 -7
@@ -2,7 +2,7 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import { Schema as S } from 'effect';
5
+ import { Schema } from 'effect';
6
6
 
7
7
  import { defineTool, ToolResult } from '@dxos/artifact';
8
8
  import { toJsonSchema } from '@dxos/echo-schema';
@@ -11,14 +11,14 @@ import { log } from '@dxos/log';
11
11
  import { executeQuery, formatJsonSchemaForLLM, type DataSource } from '../cypher';
12
12
  import { trim } from '../util';
13
13
 
14
- export const createCypherTool = (dataSource: DataSource, schemaTypes: S.Schema.Any[] = []) =>
14
+ export const createCypherTool = (dataSource: DataSource, schemaTypes: Schema.Schema.Any[] = []) =>
15
15
  defineTool('dxos.org/echo', {
16
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
- schema: S.Struct({
21
- query: S.String.annotations({
20
+ schema: Schema.Struct({
21
+ query: Schema.String.annotations({
22
22
  description: `
23
23
  A valid cypher query string to execute.
24
24
  Query must have one MATCH clause.
@@ -55,7 +55,7 @@ export const createCypherTool = (dataSource: DataSource, schemaTypes: S.Schema.A
55
55
  },
56
56
  });
57
57
 
58
- export const createSystemPrompt = (schemaTypes: S.Schema.Any[]) => trim`
58
+ export const createSystemPrompt = (schemaTypes: Schema.Schema.Any[]) => trim`
59
59
  You have access to ECHO graph database. You can query the database to get data to satisfy user prompts.
60
60
 
61
61
  Database schema is defined in pseud-cypher syntax. The schema is:
@@ -14,7 +14,7 @@ import { AI_SERVICE_ENDPOINT } from './defs';
14
14
  import { createLogger } from './logger';
15
15
  import { createCypherTool, createSystemPrompt } from './query-promts';
16
16
  import { createTestData, seedTestData } from './test-data';
17
- import { Contact, Org, Project, Task } from './test-schema';
17
+ import { Contact, Organization, Project, Task } from './test-schema';
18
18
  import { AIServiceEdgeClient, DEFAULT_EDGE_MODEL } from '../ai-service';
19
19
  import { runLLM } from '../conversation';
20
20
  import { EchoDataSource } from '../cypher';
@@ -25,7 +25,7 @@ const client = new AIServiceEdgeClient({
25
25
 
26
26
  test.skip('cypher query', async () => {
27
27
  const dataSource = createTestData();
28
- const schemaTypes = [Org, Project, Task, Contact];
28
+ const schemaTypes = [Organization, Project, Task, Contact];
29
29
 
30
30
  const cypherTool = createCypherTool(dataSource);
31
31
 
@@ -56,7 +56,7 @@ test.skip('query ECHO', async () => {
56
56
  await using builder = await new EchoTestBuilder().open();
57
57
  const { db, graph } = await builder.createDatabase();
58
58
 
59
- const schemaTypes = [Org, Project, Task, Contact];
59
+ const schemaTypes = [Organization, Project, Task, Contact];
60
60
  graph.schemaRegistry.addSchema(schemaTypes);
61
61
 
62
62
  seedTestData(db);
@@ -2,13 +2,20 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import { type Schema as S } from 'effect';
5
+ import { type Schema } from 'effect';
6
6
 
7
7
  import { raise } from '@dxos/debug';
8
8
  import type { EchoDatabase } from '@dxos/echo-db';
9
- import { JSON_SCHEMA_ECHO_REF_ID, ObjectId, toJsonSchema, type JsonSchemaType, type Ref } from '@dxos/echo-schema';
9
+ import {
10
+ JSON_SCHEMA_ECHO_REF_ID,
11
+ ObjectId,
12
+ toJsonSchema,
13
+ type JsonSchemaType,
14
+ type Ref,
15
+ Ref as RefImpl,
16
+ } from '@dxos/echo-schema';
10
17
  import { invariant } from '@dxos/invariant';
11
- import { live, makeRef } from '@dxos/live-object';
18
+ import { live } from '@dxos/live-object';
12
19
 
13
20
  import {
14
21
  type DataSource,
@@ -17,7 +24,7 @@ import {
17
24
  formatInferredRelationshipLabel,
18
25
  formatNodeLabel,
19
26
  } from '../cypher';
20
- import { Contact, Org, Project, Task } from '../testing';
27
+ import { Contact, Organization, Project, Task } from '../testing';
21
28
 
22
29
  export const seedTestData = (db: EchoDatabase) => {
23
30
  const contactRich = db.add(
@@ -60,79 +67,79 @@ export const seedTestData = (db: EchoDatabase) => {
60
67
  const _taskComposer1 = db.add(
61
68
  live(Task, {
62
69
  name: 'Optimize startup performance',
63
- project: makeRef(projectComposer),
64
- assignee: makeRef(contactJosiah),
70
+ project: RefImpl.make(projectComposer),
71
+ assignee: RefImpl.make(contactJosiah),
65
72
  }),
66
73
  );
67
74
  const _taskComposer2 = db.add(
68
75
  live(Task, {
69
76
  name: 'Create form builder',
70
- project: makeRef(projectComposer),
71
- assignee: makeRef(contactRich),
77
+ project: RefImpl.make(projectComposer),
78
+ assignee: RefImpl.make(contactRich),
72
79
  }),
73
80
  );
74
81
  const _taskComposer3 = db.add(
75
82
  live(Task, {
76
83
  name: 'Add support for custom themes',
77
- project: makeRef(projectComposer),
78
- assignee: makeRef(contactJosiah),
84
+ project: RefImpl.make(projectComposer),
85
+ assignee: RefImpl.make(contactJosiah),
79
86
  }),
80
87
  );
81
88
  const _taskComposer5 = db.add(
82
89
  live(Task, {
83
90
  name: 'Implement community plugin',
84
- project: makeRef(projectComposer),
85
- assignee: makeRef(contactFred),
91
+ project: RefImpl.make(projectComposer),
92
+ assignee: RefImpl.make(contactFred),
86
93
  }),
87
94
  );
88
95
  const _taskComposer4 = db.add(
89
96
  live(Task, {
90
97
  name: 'Implement dark mode',
91
- project: makeRef(projectComposer),
92
- assignee: makeRef(contactRich),
98
+ project: RefImpl.make(projectComposer),
99
+ assignee: RefImpl.make(contactRich),
93
100
  }),
94
101
  );
95
102
  const _taskEcho1 = db.add(
96
103
  live(Task, {
97
104
  name: 'Implement cypher query engine',
98
- project: makeRef(projectEcho),
99
- assignee: makeRef(contactDima),
105
+ project: RefImpl.make(projectEcho),
106
+ assignee: RefImpl.make(contactDima),
100
107
  }),
101
108
  );
102
109
  const _taskEcho2 = db.add(
103
110
  live(Task, {
104
111
  name: 'Add schema editor',
105
- project: makeRef(projectEcho),
106
- assignee: makeRef(contactRich),
112
+ project: RefImpl.make(projectEcho),
113
+ assignee: RefImpl.make(contactRich),
107
114
  }),
108
115
  );
109
116
  const _taskDoodles1 = db.add(
110
117
  live(Task, {
111
118
  name: 'Add support for custom themes',
112
- project: makeRef(projectDoodles),
113
- assignee: makeRef(contactFred),
119
+ project: RefImpl.make(projectDoodles),
120
+ assignee: RefImpl.make(contactFred),
114
121
  }),
115
122
  );
116
123
  const _taskDoodles2 = db.add(
117
124
  live(Task, {
118
125
  name: 'Implement dark mode',
119
- project: makeRef(projectDoodles),
120
- assignee: makeRef(contactJosiah),
126
+ project: RefImpl.make(projectDoodles),
127
+ assignee: RefImpl.make(contactJosiah),
121
128
  }),
122
129
  );
123
130
 
124
131
  const _orgDxos = db.add(
125
- live(Org, {
132
+ live(Organization, {
126
133
  name: 'DXOS',
127
- employees: [makeRef(contactRich), makeRef(contactJosiah), makeRef(contactDima)],
128
- projects: [makeRef(projectEcho)],
134
+ employees: [RefImpl.make(contactRich), RefImpl.make(contactJosiah), RefImpl.make(contactDima)],
135
+ projects: [RefImpl.make(projectEcho)],
129
136
  }),
130
137
  );
131
138
  const _orgBraneframe = db.add(
132
- live(Org, {
139
+ live(Organization, {
133
140
  name: 'Braneframe',
134
- employees: [makeRef(contactJosiah), makeRef(contactRich)],
135
- projects: [makeRef(projectComposer)],
141
+ employees: [RefImpl.make(contactJosiah), RefImpl.make(contactRich)],
142
+ projects: [RefImpl.make(projectComposer)],
136
143
  }),
137
144
  );
138
145
  };
@@ -174,69 +181,69 @@ export const createTestData = (): MockDataSource => {
174
181
  const _taskComposer1 = dataSource.add(Task, {
175
182
  id: ObjectId.random(),
176
183
  name: 'Optimize startup performance',
177
- project: makeRef(projectComposer),
178
- assignee: makeRef(contactJosiah),
184
+ project: RefImpl.make(projectComposer),
185
+ assignee: RefImpl.make(contactJosiah),
179
186
  });
180
187
  const _taskComposer2 = dataSource.add(Task, {
181
188
  id: ObjectId.random(),
182
189
  name: 'Create form builder',
183
- project: makeRef(projectComposer),
184
- assignee: makeRef(contactRich),
190
+ project: RefImpl.make(projectComposer),
191
+ assignee: RefImpl.make(contactRich),
185
192
  });
186
193
  const _taskComposer3 = dataSource.add(Task, {
187
194
  id: ObjectId.random(),
188
195
  name: 'Add support for custom themes',
189
- project: makeRef(projectComposer),
190
- assignee: makeRef(contactJosiah),
196
+ project: RefImpl.make(projectComposer),
197
+ assignee: RefImpl.make(contactJosiah),
191
198
  });
192
199
  const _taskComposer5 = dataSource.add(Task, {
193
200
  id: ObjectId.random(),
194
201
  name: 'Implement community plugin',
195
- project: makeRef(projectComposer),
196
- assignee: makeRef(contactFred),
202
+ project: RefImpl.make(projectComposer),
203
+ assignee: RefImpl.make(contactFred),
197
204
  });
198
205
  const _taskComposer4 = dataSource.add(Task, {
199
206
  id: ObjectId.random(),
200
207
  name: 'Implement dark mode',
201
- project: makeRef(projectComposer),
202
- assignee: makeRef(contactRich),
208
+ project: RefImpl.make(projectComposer),
209
+ assignee: RefImpl.make(contactRich),
203
210
  });
204
211
  const _taskEcho1 = dataSource.add(Task, {
205
212
  id: ObjectId.random(),
206
213
  name: 'Implement cypher query engine',
207
- project: makeRef(projectEcho),
208
- assignee: makeRef(contactDima),
214
+ project: RefImpl.make(projectEcho),
215
+ assignee: RefImpl.make(contactDima),
209
216
  });
210
217
  const _taskEcho2 = dataSource.add(Task, {
211
218
  id: ObjectId.random(),
212
219
  name: 'Add schema editor',
213
- project: makeRef(projectEcho),
214
- assignee: makeRef(contactRich),
220
+ project: RefImpl.make(projectEcho),
221
+ assignee: RefImpl.make(contactRich),
215
222
  });
216
223
  const _taskDoodles1 = dataSource.add(Task, {
217
224
  id: ObjectId.random(),
218
225
  name: 'Add support for custom themes',
219
- project: makeRef(projectDoodles),
220
- assignee: makeRef(contactFred),
226
+ project: RefImpl.make(projectDoodles),
227
+ assignee: RefImpl.make(contactFred),
221
228
  });
222
229
  const _taskDoodles2 = dataSource.add(Task, {
223
230
  id: ObjectId.random(),
224
231
  name: 'Implement dark mode',
225
- project: makeRef(projectDoodles),
226
- assignee: makeRef(contactJosiah),
232
+ project: RefImpl.make(projectDoodles),
233
+ assignee: RefImpl.make(contactJosiah),
227
234
  });
228
235
 
229
- const _orgDxos = dataSource.add(Org, {
236
+ const _orgDxos = dataSource.add(Organization, {
230
237
  id: ObjectId.random(),
231
238
  name: 'DXOS',
232
- employees: [makeRef(contactRich), makeRef(contactJosiah), makeRef(contactDima)],
233
- projects: [makeRef(projectEcho)],
239
+ employees: [RefImpl.make(contactRich), RefImpl.make(contactJosiah), RefImpl.make(contactDima)],
240
+ projects: [RefImpl.make(projectEcho)],
234
241
  });
235
- const _orgBraneframe = dataSource.add(Org, {
242
+ const _orgBraneframe = dataSource.add(Organization, {
236
243
  id: ObjectId.random(),
237
244
  name: 'Braneframe',
238
- employees: [makeRef(contactJosiah), makeRef(contactRich)],
239
- projects: [makeRef(projectComposer)],
245
+ employees: [RefImpl.make(contactJosiah), RefImpl.make(contactRich)],
246
+ projects: [RefImpl.make(projectComposer)],
240
247
  });
241
248
  dataSource.computeGraph();
242
249
 
@@ -247,7 +254,7 @@ export class MockDataSource implements DataSource {
247
254
  objects: Record<
248
255
  string,
249
256
  {
250
- schema: S.Schema.All;
257
+ schema: Schema.Schema.All;
251
258
  typeDxn: string;
252
259
  id: string;
253
260
  data: unknown;
@@ -258,7 +265,7 @@ export class MockDataSource implements DataSource {
258
265
  string,
259
266
  {
260
267
  json: JsonSchemaType;
261
- instance: S.Schema.All;
268
+ instance: Schema.Schema.All;
262
269
  }
263
270
  > = {};
264
271
 
@@ -273,7 +280,7 @@ export class MockDataSource implements DataSource {
273
280
  return this.relationships.filter((relationship) => !label || relationship.label === label);
274
281
  }
275
282
 
276
- add<S extends S.Schema.All>(schema: S, data: S.Schema.Type<S>) {
283
+ add<S extends Schema.Schema.All>(schema: S, data: Schema.Schema.Type<S>) {
277
284
  invariant(typeof data.id === 'string', 'Data must have an id');
278
285
  const jsonSchema = toJsonSchema(schema);
279
286
  if (!this.schema[jsonSchema.$id!]) {
@@ -2,22 +2,19 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import { Schema as S } from 'effect';
5
+ import { Schema } from 'effect';
6
6
 
7
- import { EntityKind, TypeAnnotationId, Ref } from '@dxos/echo-schema';
7
+ import { EntityKind, TypeAnnotationId, Ref, ObjectId } from '@dxos/echo-schema';
8
8
 
9
- // TODO(burdon): Reconcile with sdk/schema/testing.
10
- // TODO(burdon): Convert interface to type.
9
+ // TODO(burdon): Remove (use @dxos/schema DataType).
11
10
 
12
- // TODO(dmaretskyi): Extract.
13
- export const ObjectId = S.String.annotations({ description: 'The unique object identifier.' });
14
-
15
- export const Contact = S.Struct({
11
+ /** @deprecated */
12
+ export const Contact = Schema.Struct({
16
13
  id: ObjectId,
17
- name: S.String.annotations({ description: 'The name of the person.' }),
18
- email: S.optional(S.String).annotations({ description: 'Email address.' }),
14
+ name: Schema.String.annotations({ description: 'The name of the person.' }),
15
+ email: Schema.optional(Schema.String).annotations({ description: 'Email address.' }),
19
16
  })
20
- .pipe(S.mutable)
17
+ .pipe(Schema.mutable)
21
18
  .annotations({
22
19
  [TypeAnnotationId]: {
23
20
  kind: EntityKind.Object,
@@ -26,14 +23,15 @@ export const Contact = S.Struct({
26
23
  },
27
24
  description: 'Contact information.',
28
25
  });
29
- export interface Contact extends S.Schema.Type<typeof Contact> {}
26
+ export interface Contact extends Schema.Schema.Type<typeof Contact> {}
30
27
 
31
- export const Project = S.Struct({
28
+ /** @deprecated */
29
+ export const Project = Schema.Struct({
32
30
  id: ObjectId,
33
- name: S.String.annotations({ description: 'The name of the project.' }),
34
- description: S.optional(S.String).annotations({ description: 'The description of the project.' }),
31
+ name: Schema.String.annotations({ description: 'The name of the project.' }),
32
+ description: Schema.optional(Schema.String).annotations({ description: 'The description of the project.' }),
35
33
  })
36
- .pipe(S.mutable)
34
+ .pipe(Schema.mutable)
37
35
  .annotations({
38
36
  [TypeAnnotationId]: {
39
37
  kind: EntityKind.Object,
@@ -42,16 +40,16 @@ export const Project = S.Struct({
42
40
  },
43
41
  description: 'Contact information.',
44
42
  });
45
- export interface Project extends S.Schema.Type<typeof Project> {}
43
+ export interface Project extends Schema.Schema.Type<typeof Project> {}
46
44
 
47
- export const Task = S.Struct({
45
+ export const Task = Schema.Struct({
48
46
  id: ObjectId,
49
- name: S.String.annotations({ description: 'The name of the task.' }),
50
- description: S.optional(S.String).annotations({ description: 'The description of the task.' }),
47
+ name: Schema.String.annotations({ description: 'The name of the task.' }),
48
+ description: Schema.optional(Schema.String).annotations({ description: 'The description of the task.' }),
51
49
  project: Ref(Project),
52
50
  assignee: Ref(Contact),
53
51
  })
54
- .pipe(S.mutable)
52
+ .pipe(Schema.mutable)
55
53
  .annotations({
56
54
  [TypeAnnotationId]: {
57
55
  kind: EntityKind.Object,
@@ -60,21 +58,22 @@ export const Task = S.Struct({
60
58
  },
61
59
  description: 'Contact information.',
62
60
  });
63
- export interface Task extends S.Schema.Type<typeof Task> {}
61
+ export interface Task extends Schema.Schema.Type<typeof Task> {}
64
62
 
65
- export const Org = S.Struct({
63
+ /** @deprecated */
64
+ export const Organization = Schema.Struct({
66
65
  id: ObjectId,
67
- name: S.String.annotations({ description: 'The name of the organization.' }),
68
- projects: S.Array(Ref(Project)),
69
- employees: S.Array(Ref(Contact)),
66
+ name: Schema.String.annotations({ description: 'The name of the organization.' }),
67
+ projects: Schema.Array(Ref(Project)),
68
+ employees: Schema.Array(Ref(Contact)),
70
69
  })
71
- .pipe(S.mutable)
70
+ .pipe(Schema.mutable)
72
71
  .annotations({
73
72
  [TypeAnnotationId]: {
74
73
  kind: EntityKind.Object,
75
- typename: 'example.com/type/Org',
74
+ typename: 'example.com/type/Organization',
76
75
  version: '0.1.0',
77
76
  },
78
77
  description: 'Contact information.',
79
78
  });
80
- export interface Org extends S.Schema.Type<typeof Org> {}
79
+ export interface Organization extends Schema.Schema.Type<typeof Organization> {}