@dxos/assistant 0.8.1 → 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 (84) hide show
  1. package/dist/lib/browser/{chunk-PND5VR6D.mjs → chunk-OLO6SVOL.mjs} +91 -84
  2. package/dist/lib/browser/chunk-OLO6SVOL.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +276 -154
  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 +98 -102
  7. package/dist/lib/browser/testing/index.mjs.map +3 -3
  8. package/dist/lib/node/{chunk-IBOBRBDF.cjs → chunk-CI5Q7FBG.cjs} +106 -98
  9. package/dist/lib/node/chunk-CI5Q7FBG.cjs.map +7 -0
  10. package/dist/lib/node/index.cjs +302 -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 +88 -93
  14. package/dist/lib/node/testing/index.cjs.map +3 -3
  15. package/dist/lib/node-esm/{chunk-DCQJOLSR.mjs → chunk-Y3SYOFFJ.mjs} +91 -84
  16. package/dist/lib/node-esm/chunk-Y3SYOFFJ.mjs.map +7 -0
  17. package/dist/lib/node-esm/index.mjs +276 -154
  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 +98 -102
  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 +144 -101
  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 +11 -12
  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/index.d.ts +1 -0
  42. package/dist/types/src/session/index.d.ts.map +1 -1
  43. package/dist/types/src/session/session.d.ts +32 -13
  44. package/dist/types/src/session/session.d.ts.map +1 -1
  45. package/dist/types/src/session/version-pin.d.ts +17 -0
  46. package/dist/types/src/session/version-pin.d.ts.map +1 -0
  47. package/dist/types/src/session/version-pin.test.d.ts +2 -0
  48. package/dist/types/src/session/version-pin.test.d.ts.map +1 -0
  49. package/dist/types/src/testing/query-promts.d.ts +3 -3
  50. package/dist/types/src/testing/query-promts.d.ts.map +1 -1
  51. package/dist/types/src/testing/test-data.d.ts +4 -4
  52. package/dist/types/src/testing/test-data.d.ts.map +1 -1
  53. package/dist/types/src/testing/test-schema.d.ts +25 -23
  54. package/dist/types/src/testing/test-schema.d.ts.map +1 -1
  55. package/package.json +15 -14
  56. package/src/ai-service/client.test.ts +55 -73
  57. package/src/ai-service/edge-client.ts +13 -20
  58. package/src/ai-service/ollama-client.ts +16 -9
  59. package/src/ai-service/parser.ts +13 -2
  60. package/src/ai-service/service.ts +19 -3
  61. package/src/ai-service/testing/mock.ts +9 -1
  62. package/src/ai-service/types.ts +24 -15
  63. package/src/bin/chat.ts +3 -3
  64. package/src/conversation/conversation.test.ts +3 -3
  65. package/src/conversation/conversation.ts +5 -11
  66. package/src/conversation/types.ts +11 -14
  67. package/src/cypher/combinators.test.ts +4 -4
  68. package/src/cypher/echo-data-source.ts +7 -6
  69. package/src/cypher/execution-plan.test.ts +1 -1
  70. package/src/cypher/query-executor.test.ts +1 -1
  71. package/src/cypher/schema.test.ts +3 -3
  72. package/src/session/index.ts +1 -0
  73. package/src/session/session.test.ts +29 -22
  74. package/src/session/session.ts +286 -150
  75. package/src/session/version-pin.test.ts +26 -0
  76. package/src/session/version-pin.ts +43 -0
  77. package/src/testing/artifacts.test.ts +22 -22
  78. package/src/testing/query-promts.ts +5 -5
  79. package/src/testing/query.test.ts +17 -19
  80. package/src/testing/test-data.ts +78 -71
  81. package/src/testing/test-schema.ts +28 -29
  82. package/dist/lib/browser/chunk-PND5VR6D.mjs.map +0 -7
  83. package/dist/lib/node/chunk-IBOBRBDF.cjs.map +0 -7
  84. package/dist/lib/node-esm/chunk-DCQJOLSR.mjs.map +0 -7
@@ -2,18 +2,18 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { Schema as S } from 'effect';
5
+ import { Schema } 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
 
12
12
  export const createArtifactElement = (id: ObjectId) => `<artifact id=${id} />`;
13
13
 
14
- export const LLMModel = S.Literal(...DEFAULT_EDGE_MODELS, ...DEFAULT_OLLAMA_MODELS);
14
+ export const LLMModel = Schema.Literal(...DEFAULT_EDGE_MODELS, ...DEFAULT_OLLAMA_MODELS);
15
15
 
16
- export type LLMModel = S.Schema.Type<typeof LLMModel>;
16
+ export type LLMModel = Schema.Schema.Type<typeof LLMModel>;
17
17
 
18
18
  export const ToolTypes = Object.freeze({
19
19
  // TODO(dmaretskyi): Not implemented yet.
@@ -24,38 +24,47 @@ export const ToolTypes = Object.freeze({
24
24
  /**
25
25
  * Client GPT request.
26
26
  */
27
- export const GenerateRequest = S.Struct({
28
- spaceId: S.optional(SpaceIdSchema),
29
- threadId: S.optional(ObjectId),
30
-
27
+ export const GenerateRequest = Schema.Struct({
31
28
  /**
32
29
  * Preferred model or system default.
33
30
  */
34
- model: S.optional(LLMModel),
31
+ model: Schema.optional(LLMModel),
35
32
 
36
33
  /**
37
34
  * Tools available for the LLM.
38
35
  */
39
- tools: S.optional(S.Array(Tool).pipe(S.mutable)),
36
+ tools: Schema.optional(Schema.Array(Tool).pipe(Schema.mutable)),
40
37
 
41
38
  /**
42
39
  * System instructions to the LLM.
43
40
  */
44
- systemPrompt: S.optional(S.String),
41
+ systemPrompt: Schema.optional(Schema.String),
45
42
 
46
43
  /**
47
44
  * History of messages to include in the context window.
48
45
  */
49
46
  // TODO(burdon): Rename messages.
50
- history: S.optional(S.Array(Message)),
47
+ history: Schema.optional(Schema.Array(Message)),
51
48
 
52
49
  /**
53
50
  * Current request.
54
51
  */
55
- prompt: S.optional(Message),
52
+ prompt: Schema.optional(Message),
56
53
  });
54
+ export type GenerateRequest = Schema.Schema.Type<typeof GenerateRequest>;
55
+
56
+ /**
57
+ * Non-streaming response.
58
+ */
59
+ export const GenerateResponse = Schema.Struct({
60
+ messages: Schema.Array(Message),
57
61
 
58
- export type GenerateRequest = S.Schema.Type<typeof GenerateRequest>;
62
+ /**
63
+ * Number of tokens used in the response.
64
+ */
65
+ tokenCount: Schema.optional(Schema.Number),
66
+ });
67
+ export type GenerateResponse = Schema.Schema.Type<typeof GenerateResponse>;
59
68
 
60
69
  /**
61
70
  * Server-Sent Events (SSE) stream from the AI service.
package/src/bin/chat.ts CHANGED
@@ -19,7 +19,7 @@ import {
19
19
  createSystemPrompt,
20
20
  createTestData,
21
21
  Contact,
22
- Org,
22
+ Organization,
23
23
  Project,
24
24
  Task,
25
25
  } from '../testing';
@@ -33,7 +33,7 @@ const dataSource = createTestData();
33
33
 
34
34
  const cypherTool = createCypherTool(dataSource);
35
35
 
36
- const schemaTypes = [Org, Project, Task, Contact];
36
+ const schemaTypes = [Organization, Project, Task, Contact];
37
37
 
38
38
  const spaceId = SpaceId.random();
39
39
  const threadId = ObjectId.random();
@@ -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) => {
@@ -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
  import { describe, test } from 'vitest';
7
7
 
8
8
  import { createUserMessage, defineTool, ToolResult } from '@dxos/artifact';
@@ -40,8 +40,8 @@ describe.skip('Conversation tests', () => {
40
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
- schema: S.Struct({
44
- magicWord: S.String.annotations({ description: 'The magic word. Should be exactly "pretty please"' }),
43
+ schema: Schema.Struct({
44
+ magicWord: Schema.String.annotations({ description: 'The magic word. Should be exactly "pretty please"' }),
45
45
  }),
46
46
  execute: async ({ magicWord }) => {
47
47
  if (magicWord === 'pretty please') {
@@ -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
  {
@@ -2,17 +2,14 @@
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 { 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
  });
@@ -20,11 +17,11 @@ export const createUserMessage = (spaceId: SpaceId, threadId: ObjectId, text: st
20
17
  /**
21
18
  * @deprecated Use {@link LLMTool} instead.
22
19
  */
23
- export const ToolDefinition = S.Struct({
24
- name: S.String,
25
- description: S.String,
20
+ export const ToolDefinition = Schema.Struct({
21
+ name: Schema.String,
22
+ description: Schema.String,
26
23
  parameters: JsonSchemaType,
27
- execute: S.Any,
24
+ execute: Schema.Any,
28
25
  });
29
26
 
30
27
  /**
@@ -86,14 +83,14 @@ export const ToolResult = Object.freeze({
86
83
  Break: (result: unknown): ToolResult => ({ kind: 'break', result }),
87
84
  });
88
85
 
89
- export type DefineToolParams<Params extends S.Schema.AnyNoContext> = {
86
+ export type DefineToolParams<Params extends Schema.Schema.AnyNoContext> = {
90
87
  name: string;
91
88
  description: string;
92
89
  schema: Params;
93
- execute: (params: S.Schema.Type<Params>, context: ToolExecutionContext) => Promise<ToolResult>;
90
+ execute: (params: Schema.Schema.Type<Params>, context: ToolExecutionContext) => Promise<ToolResult>;
94
91
  };
95
92
 
96
- export const defineTool = <Params extends S.Schema.AnyNoContext>({
93
+ export const defineTool = <Params extends Schema.Schema.AnyNoContext>({
97
94
  name,
98
95
  description,
99
96
  schema,
@@ -104,7 +101,7 @@ export const defineTool = <Params extends S.Schema.AnyNoContext>({
104
101
  description,
105
102
  parameters: toFunctionParameterSchema(schema),
106
103
  execute: (params, context) => {
107
- const sanitized = S.decodeSync(schema)(params);
104
+ const sanitized = Schema.decodeSync(schema)(params);
108
105
  return execute(sanitized, context);
109
106
  },
110
107
  };
@@ -113,7 +110,7 @@ export const defineTool = <Params extends S.Schema.AnyNoContext>({
113
110
  /**
114
111
  * Adapts schems to be able to pass to AI providers.
115
112
  */
116
- const toFunctionParameterSchema = (schema: S.Schema.All) => {
113
+ const toFunctionParameterSchema = (schema: Schema.Schema.All) => {
117
114
  const jsonSchema = toJsonSchema(schema);
118
115
  log('tool schema', { jsonSchema });
119
116
  delete jsonSchema.anyOf;
@@ -77,7 +77,7 @@ describe('Cypher Combinators', () => {
77
77
  test('match clause', ({ expect }) => {
78
78
  testParser(matchClause, 'MATCH (n:Person)');
79
79
  testParser(matchClause, 'MATCH (n:Person)-[r:KNOWS]->(m:Person)');
80
- testParser(matchClause, 'MATCH (o:Org)-[:HAS_EMPLOYEE]->(e:Employee)');
80
+ testParser(matchClause, 'MATCH (o:Organization)-[:HAS_EMPLOYEE]->(e:Employee)');
81
81
  });
82
82
 
83
83
  test('where clause', ({ expect }) => {
@@ -116,15 +116,15 @@ describe('Cypher Combinators', () => {
116
116
  );
117
117
  testParser(
118
118
  cypherQuery,
119
- 'MATCH (o:Org)-[:HAS_EMPLOYEE]->(e:Employee)-[:WORKS_ON]->(p:Project) WHERE o.name = "DXOS" AND p.name = "Composer" RETURN e.name, e.id, p.name, p.id',
119
+ 'MATCH (o:Organization)-[:HAS_EMPLOYEE]->(e:Employee)-[:WORKS_ON]->(p:Project) WHERE o.name = "DXOS" AND p.name = "Composer" RETURN e.name, e.id, p.name, p.id',
120
120
  );
121
121
  testParser(
122
122
  cypherQuery,
123
- 'MATCH (n:Org {name: "DXOS"})-[:HAS_EMPLOYEE]->(m:Employee)<-[:WORKS_ON]-(p:Project {name: "Composer"}) RETURN m.name AS employee',
123
+ 'MATCH (n:Organization {name: "DXOS"})-[:HAS_EMPLOYEE]->(m:Employee)<-[:WORKS_ON]-(p:Project {name: "Composer"}) RETURN m.name AS employee',
124
124
  );
125
125
  testParser(
126
126
  cypherQuery,
127
- "MATCH (org:Org {name: 'DXOS'})-[:ORG_EMPLOYEES]->(c:Contact)<-[:TASK_ASSIGNEE]-(t:Task)-[:TASK_PROJECT]->(p:Project {name: 'Composer'}) RETURN c.name",
127
+ "MATCH (org:Organization {name: 'DXOS'})-[:ORG_EMPLOYEES]->(c:Contact)<-[:TASK_ASSIGNEE]-(t:Task)-[:TASK_PROJECT]->(p:Project {name: 'Composer'}) RETURN c.name",
128
128
  );
129
129
  });
130
130
  });
@@ -2,10 +2,11 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
+ import { type Schema } from 'effect';
6
+
5
7
  import { raise } from '@dxos/debug';
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';
8
+ import { type EchoDatabase, Filter, type AnyLiveObject } from '@dxos/echo-db';
9
+ import { getSchema, getSchemaTypename, StoredSchema, toJsonSchema } from '@dxos/echo-schema';
9
10
  import { log } from '@dxos/log';
10
11
 
11
12
  import type { DataSource, Node, Relationship } from './query-executor';
@@ -63,7 +64,7 @@ export class EchoDataSource implements DataSource {
63
64
  ).flat();
64
65
  }
65
66
 
66
- private async _getAllSchema(): Promise<S.Schema.AnyNoContext[]> {
67
+ private async _getAllSchema(): Promise<Schema.Schema.AnyNoContext[]> {
67
68
  return [
68
69
  ...(await this._db.schemaRegistry.query().run()),
69
70
  // TODO(dmaretskyi): Remove once we can serialize recursive schema.
@@ -71,7 +72,7 @@ export class EchoDataSource implements DataSource {
71
72
  ].filter((schema) => getSchemaTypename(schema) !== StoredSchema.typename);
72
73
  }
73
74
 
74
- private _objectToNode(object: ReactiveEchoObject<any>): Node {
75
+ private _objectToNode(object: AnyLiveObject<any>): Node {
75
76
  const { id, ...properties } = object;
76
77
  return {
77
78
  id,
@@ -81,7 +82,7 @@ export class EchoDataSource implements DataSource {
81
82
  };
82
83
  }
83
84
 
84
- private async _projectRefRelationship(object: ReactiveEchoObject<any>, prop: string): Promise<Relationship[]> {
85
+ private async _projectRefRelationship(object: AnyLiveObject<any>, prop: string): Promise<Relationship[]> {
85
86
  if (!object[prop]) {
86
87
  return [];
87
88
  }
@@ -21,7 +21,7 @@ describe('Execution Plan', () => {
21
21
  test('complex query', ({ expect }) => {
22
22
  const plan = createExecutionPlan(
23
23
  parseCypherQuery(
24
- "MATCH (org:Org {name: 'DXOS'})-[:ORG_EMPLOYEES]->(c:Contact)<-[:TASK_ASSIGNEE]-(:Task)-[:TASK_PROJECT]->(p:Project {name: 'Composer'}) RETURN c.name",
24
+ "MATCH (org:Organization {name: 'DXOS'})-[:ORG_EMPLOYEES]->(c:Contact)<-[:TASK_ASSIGNEE]-(:Task)-[:TASK_PROJECT]->(p:Project {name: 'Composer'}) RETURN c.name",
25
25
  ),
26
26
  );
27
27
  log('', { plan });
@@ -25,7 +25,7 @@ test.skip('run', async ({ expect }) => {
25
25
  const result = await executeQuery(
26
26
  dataSource,
27
27
  `
28
- MATCH (org:Org {name: 'DXOS'})-[:ORG_EMPLOYEES]->(c:Contact)<-[:TASK_ASSIGNEE]-(t:Task)-[:TASK_PROJECT]->(p:Project {name: 'Composer'})
28
+ MATCH (org:Organization {name: 'DXOS'})-[:ORG_EMPLOYEES]->(c:Contact)<-[:TASK_ASSIGNEE]-(t:Task)-[:TASK_PROJECT]->(p:Project {name: 'Composer'})
29
29
  RETURN c.name, t.name
30
30
  `,
31
31
  );
@@ -7,10 +7,10 @@ import { test } from 'vitest';
7
7
  import { toJsonSchema } from '@dxos/echo-schema';
8
8
 
9
9
  import { formatJsonSchemaForLLM } from './schema';
10
- import { Contact, Org, Project, Task } from '../testing';
10
+ import { Contact, Organization, Project, Task } from '../testing';
11
11
 
12
- test('Org-Project-Task-Contact schema', async ({ expect }) => {
13
- const jsonSchema = [Org, Project, Task, Contact].map((schema) => toJsonSchema(schema));
12
+ test('Organization-Project-Task-Contact schema', async ({ expect }) => {
13
+ const jsonSchema = [Organization, Project, Task, Contact].map((schema) => toJsonSchema(schema));
14
14
  const result = formatJsonSchemaForLLM(jsonSchema);
15
15
  // log('result', { result });
16
16
  expect(result).toHaveLength(8);
@@ -3,3 +3,4 @@
3
3
  //
4
4
 
5
5
  export * from './session';
6
+ export * from './version-pin';
@@ -2,7 +2,7 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { Schema as S } from 'effect';
5
+ import { Schema } from 'effect';
6
6
  import { inspect } from 'node:util';
7
7
  import { describe, test } from 'vitest';
8
8
 
@@ -15,7 +15,8 @@ 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 { Type } from '@dxos/echo';
19
+ import { create, ObjectId } from '@dxos/echo-schema';
19
20
  import { DXN } from '@dxos/keys';
20
21
  import { log } from '@dxos/log';
21
22
 
@@ -23,14 +24,19 @@ import { AISession } from './session';
23
24
  import { AI_SERVICE_ENDPOINT } from '../testing';
24
25
 
25
26
  // Define a calendar event artifact schema.
26
- const CalendarEventSchema = S.Struct({
27
- title: S.String,
28
- startTime: S.String,
29
- endTime: S.String,
30
- description: S.String,
31
- }).pipe(EchoObject({ typename: 'example.com/type/CalendarEvent', version: '0.1.0' }));
27
+ const CalendarEventSchema = Schema.Struct({
28
+ title: Schema.String,
29
+ startTime: Schema.String,
30
+ endTime: Schema.String,
31
+ description: Schema.String,
32
+ }).pipe(
33
+ Type.def({
34
+ typename: 'example.com/type/CalendarEvent',
35
+ version: '0.1.0',
36
+ }),
37
+ );
32
38
 
33
- type CalendarEvent = S.Schema.Type<typeof CalendarEventSchema>;
39
+ type CalendarEvent = Schema.Schema.Type<typeof CalendarEventSchema>;
34
40
 
35
41
  // TODO(burdon): Flaky.
36
42
  describe.skip('AISession with Ollama', () => {
@@ -39,7 +45,7 @@ describe.skip('AISession with Ollama', () => {
39
45
  // const aiClient = new OllamaClient({
40
46
  // overrides: { model: 'llama3.1:8b' },
41
47
  // });
42
- const session = new AISession({ operationModel: 'immediate' });
48
+ const session = new AISession({ operationModel: 'configured' });
43
49
 
44
50
  const objects = new Set<string>();
45
51
 
@@ -53,7 +59,7 @@ describe.skip('AISession with Ollama', () => {
53
59
  defineTool('calendar', {
54
60
  name: 'query',
55
61
  description: 'Query the calendar for events',
56
- schema: S.Struct({}),
62
+ schema: Schema.Struct({}),
57
63
  execute: async () => {
58
64
  return ToolResult.Success(CALENDAR_EVENTS);
59
65
  },
@@ -65,13 +71,13 @@ describe.skip('AISession with Ollama', () => {
65
71
  id: 'artifact:dxos.org/plugin/table',
66
72
  name: 'Table',
67
73
  instructions: 'Use this to create and manage tables. Each table has a unique id.',
68
- schema: S.Struct({}),
74
+ schema: Schema.Struct({}),
69
75
  tools: [
70
76
  defineTool('table', {
71
77
  name: 'create',
72
78
  description: 'Create a table',
73
- schema: S.Struct({
74
- data: S.Array(S.Any).annotations({ description: 'Array of data payloads to add as rows' }),
79
+ schema: Schema.Struct({
80
+ data: Schema.Array(Schema.Any).annotations({ description: 'Array of data payloads to add as rows' }),
75
81
  }),
76
82
  execute: async ({ data }) => {
77
83
  log('create table', { data });
@@ -89,12 +95,12 @@ describe.skip('AISession with Ollama', () => {
89
95
  name: 'Map',
90
96
  instructions:
91
97
  'Use this to create and manage maps. Maps source data from tables. Table id is required to create a map.',
92
- schema: S.Struct({}),
98
+ schema: Schema.Struct({}),
93
99
  tools: [
94
100
  defineTool('map', {
95
101
  name: 'create',
96
102
  description: 'Create a map',
97
- schema: S.Struct({
103
+ schema: Schema.Struct({
98
104
  source: ArtifactId.annotations({
99
105
  description: 'The table that will be used as the source of the map',
100
106
  }),
@@ -119,7 +125,7 @@ describe.skip('AISession with Ollama', () => {
119
125
  id: 'artifact:dxos.org/plugin/script',
120
126
  name: 'Script',
121
127
  instructions: 'Use this to create and manage scripts',
122
- schema: S.Struct({}),
128
+ schema: Schema.Struct({}),
123
129
  tools: [],
124
130
  });
125
131
 
@@ -140,6 +146,7 @@ describe.skip('AISession with Ollama', () => {
140
146
  client: aiClient,
141
147
  tools: [],
142
148
  artifacts: [calendarArtifact, tableArtifact, mapArtifact, scriptArtifact],
149
+ requiredArtifactIds: [calendarArtifact.id, tableArtifact.id, mapArtifact.id, scriptArtifact.id],
143
150
  history: [],
144
151
  generationOptions: {
145
152
  model: '@anthropic/claude-3-5-haiku-20241022',
@@ -156,31 +163,31 @@ describe.skip('AISession with Ollama', () => {
156
163
 
157
164
  // Travel to rome, florence, livorno, siena, madrid for conferences
158
165
  const CALENDAR_EVENTS: CalendarEvent[] = [
159
- createStatic(CalendarEventSchema, {
166
+ create(CalendarEventSchema, {
160
167
  title: 'Exploring Ancient Ruins in Rome',
161
168
  startTime: '2024-01-01T10:00:00Z',
162
169
  endTime: '2024-01-01T11:00:00Z',
163
170
  description: 'Tech conference at the historic Colosseum with networking opportunities',
164
171
  }),
165
- createStatic(CalendarEventSchema, {
172
+ create(CalendarEventSchema, {
166
173
  title: 'Renaissance Tech Summit in Florence',
167
174
  startTime: '2024-01-01T11:00:00Z',
168
175
  endTime: '2024-01-01T12:00:00Z',
169
176
  description: 'Discussing AI innovations surrounded by Renaissance art',
170
177
  }),
171
- createStatic(CalendarEventSchema, {
178
+ create(CalendarEventSchema, {
172
179
  title: 'Travel to Livorno',
173
180
  startTime: '2024-01-01T12:00:00Z',
174
181
  endTime: '2024-01-01T13:00:00Z',
175
182
  description: 'Travel to Livorno',
176
183
  }),
177
- createStatic(CalendarEventSchema, {
184
+ create(CalendarEventSchema, {
178
185
  title: 'Travel to Siena',
179
186
  startTime: '2024-01-01T13:00:00Z',
180
187
  endTime: '2024-01-01T14:00:00Z',
181
188
  description: 'Travel to Siena',
182
189
  }),
183
- createStatic(CalendarEventSchema, {
190
+ create(CalendarEventSchema, {
184
191
  title: 'Travel to Madrid',
185
192
  startTime: '2024-01-01T14:00:00Z',
186
193
  endTime: '2024-01-01T15:00:00Z',