@dxos/assistant 0.8.2-main.2f9c567 → 0.8.2-main.36232bc
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/{chunk-OLO6SVOL.mjs → chunk-DEIGOD4U.mjs} +21 -21
- package/dist/lib/browser/chunk-DEIGOD4U.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +14 -14
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +80 -76
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node/{chunk-CI5Q7FBG.cjs → chunk-7VH7NMIM.cjs} +6 -6
- package/dist/lib/node/chunk-7VH7NMIM.cjs.map +7 -0
- package/dist/lib/node/index.cjs +34 -34
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +69 -64
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/lib/node-esm/{chunk-Y3SYOFFJ.mjs → chunk-7JI4MDGL.mjs} +21 -21
- package/dist/lib/node-esm/chunk-7JI4MDGL.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +14 -14
- 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 +80 -76
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/ai-service/types.d.ts +133 -133
- package/dist/types/src/ai-service/types.d.ts.map +1 -1
- package/dist/types/src/conversation/types.d.ts +9 -9
- package/dist/types/src/conversation/types.d.ts.map +1 -1
- package/dist/types/src/cypher/echo-data-source.d.ts.map +1 -1
- package/dist/types/src/session/session.d.ts +3 -3
- package/dist/types/src/session/session.d.ts.map +1 -1
- package/dist/types/src/testing/query-promts.d.ts +3 -3
- package/dist/types/src/testing/query-promts.d.ts.map +1 -1
- package/dist/types/src/testing/test-data.d.ts +4 -4
- package/dist/types/src/testing/test-data.d.ts.map +1 -1
- package/dist/types/src/testing/test-schema.d.ts +23 -25
- package/dist/types/src/testing/test-schema.d.ts.map +1 -1
- package/package.json +14 -15
- package/src/ai-service/client.test.ts +5 -5
- package/src/ai-service/ollama-client.ts +7 -7
- package/src/ai-service/types.ts +14 -14
- package/src/conversation/conversation.test.ts +3 -3
- package/src/conversation/types.ts +10 -10
- package/src/cypher/echo-data-source.ts +5 -7
- package/src/session/session.test.ts +16 -22
- package/src/session/session.ts +15 -15
- package/src/testing/artifacts.test.ts +22 -22
- package/src/testing/query-promts.ts +5 -5
- package/src/testing/test-data.ts +50 -57
- package/src/testing/test-schema.ts +28 -27
- package/dist/lib/browser/chunk-OLO6SVOL.mjs.map +0 -7
- package/dist/lib/node/chunk-CI5Q7FBG.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-Y3SYOFFJ.mjs.map +0 -7
package/src/session/session.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Option, Schema } from 'effect';
|
|
5
|
+
import { Option, Schema as S } from 'effect';
|
|
6
6
|
|
|
7
7
|
import {
|
|
8
8
|
defineTool,
|
|
@@ -230,7 +230,7 @@ export class AISession {
|
|
|
230
230
|
} catch (err) {
|
|
231
231
|
log.catch(err);
|
|
232
232
|
if (err instanceof Error && err.message.includes('Overloaded')) {
|
|
233
|
-
error = new AIServiecOverloadedError('AI service overloaded', { cause: err }
|
|
233
|
+
error = new AIServiecOverloadedError('AI service overloaded', { cause: err });
|
|
234
234
|
} else {
|
|
235
235
|
error = new Error('AI service error', { cause: err });
|
|
236
236
|
}
|
|
@@ -287,7 +287,7 @@ export class AISession {
|
|
|
287
287
|
return defineTool('system', {
|
|
288
288
|
name: 'query_artifact_definitions',
|
|
289
289
|
description: 'Query the available artifact definitions',
|
|
290
|
-
schema:
|
|
290
|
+
schema: S.Struct({}),
|
|
291
291
|
execute: async () => {
|
|
292
292
|
return ToolResult.Success({
|
|
293
293
|
artifactDefinitions: artifacts.map((artifact) => ({
|
|
@@ -308,8 +308,8 @@ export class AISession {
|
|
|
308
308
|
name: 'require_artifact_definitions',
|
|
309
309
|
description:
|
|
310
310
|
'Require the use of specific artifact definitions. This will allow the model to interact with artifact definitions and use their tools.',
|
|
311
|
-
schema:
|
|
312
|
-
artifactDefinitionIds:
|
|
311
|
+
schema: S.Struct({
|
|
312
|
+
artifactDefinitionIds: S.Array(S.String).annotations({
|
|
313
313
|
description: 'The ids of the artifact definitions to require',
|
|
314
314
|
examples: [['artifact:dxos.org/example/Test']],
|
|
315
315
|
}),
|
|
@@ -336,20 +336,20 @@ export class AISession {
|
|
|
336
336
|
name: 'create_plan',
|
|
337
337
|
description:
|
|
338
338
|
'Create a plan. Make sure that each step is independent and can be executed solely on the data returned by the previous step. The steps only share the data that is specified in the plan.',
|
|
339
|
-
schema:
|
|
340
|
-
goal:
|
|
341
|
-
steps:
|
|
342
|
-
|
|
343
|
-
action:
|
|
339
|
+
schema: S.Struct({
|
|
340
|
+
goal: S.String.annotations({ description: 'The goal that the plan will achieve.' }),
|
|
341
|
+
steps: S.Array(
|
|
342
|
+
S.Struct({
|
|
343
|
+
action: S.String.annotations({
|
|
344
344
|
description: 'Complete, detailed action to perform.',
|
|
345
345
|
}),
|
|
346
|
-
input:
|
|
346
|
+
input: S.String.annotations({
|
|
347
347
|
description: 'The required input data for this step. First step must not require any data.',
|
|
348
348
|
}),
|
|
349
|
-
output:
|
|
349
|
+
output: S.String.annotations({
|
|
350
350
|
description: 'The output data from this step. This is passed to the next step as input.',
|
|
351
351
|
}),
|
|
352
|
-
requiredArtifactIds:
|
|
352
|
+
requiredArtifactIds: S.Array(S.String).annotations({
|
|
353
353
|
description: 'The ids of the artifacts required to perform this step.',
|
|
354
354
|
examples: [['artifact:dxos.org/example/Test']],
|
|
355
355
|
}),
|
|
@@ -473,7 +473,7 @@ const createBaseInstructions = ({
|
|
|
473
473
|
${availableArtifacts.length > 0 ? `Artifacts already in context: ${availableArtifacts.join('\n')}` : ''}
|
|
474
474
|
`;
|
|
475
475
|
|
|
476
|
-
export class AIServiecOverloadedError extends
|
|
476
|
+
export class AIServiecOverloadedError extends S.TaggedError<AIServiecOverloadedError>()(
|
|
477
477
|
'AIServiecOverloadedError',
|
|
478
478
|
{},
|
|
479
479
|
) {}
|
|
@@ -483,7 +483,7 @@ const gatherObjectVersions = (messages: Message[]): Map<ObjectId, ObjectVersion>
|
|
|
483
483
|
for (const message of messages) {
|
|
484
484
|
for (const block of message.content) {
|
|
485
485
|
if (block.type === 'json' && block.disposition === VersionPin.DISPOSITION) {
|
|
486
|
-
const pin = VersionPin.pipe(
|
|
486
|
+
const pin = VersionPin.pipe(S.decodeOption)(JSON.parse(block.json)).pipe(Option.getOrUndefined);
|
|
487
487
|
if (!pin) {
|
|
488
488
|
continue;
|
|
489
489
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
/*
|
|
6
|
-
import { Schema } from '@effect/schema';
|
|
6
|
+
import { Schema as S } from '@effect/schema';
|
|
7
7
|
import { describe, test } from 'vitest';
|
|
8
8
|
|
|
9
9
|
import { ObjectId, toJsonSchema } from '@dxos/echo-schema';
|
|
@@ -15,26 +15,26 @@ import { AIServiceEdgeClient, Tool } from '../ai-service';
|
|
|
15
15
|
import { defineTool, ToolResult } from '../conversation';
|
|
16
16
|
|
|
17
17
|
// TODO(dmaretskyi): Effect schema.
|
|
18
|
-
const ArtifactDef =
|
|
19
|
-
typename:
|
|
20
|
-
description:
|
|
21
|
-
schema:
|
|
22
|
-
actions:
|
|
23
|
-
}).pipe(
|
|
18
|
+
const ArtifactDef = S.Struct({
|
|
19
|
+
typename: S.String,
|
|
20
|
+
description: S.String,
|
|
21
|
+
schema: S.Any,
|
|
22
|
+
actions: S.Array(Tool),
|
|
23
|
+
}).pipe(S.mutable);
|
|
24
24
|
|
|
25
|
-
type ArtifactDef =
|
|
25
|
+
type ArtifactDef = S.Schema.Type<typeof ArtifactDef>;
|
|
26
26
|
|
|
27
|
-
const ListItem =
|
|
28
|
-
name:
|
|
27
|
+
const ListItem = S.Struct({
|
|
28
|
+
name: S.String,
|
|
29
29
|
});
|
|
30
30
|
|
|
31
|
-
const ListSchema =
|
|
31
|
+
const ListSchema = S.Struct({
|
|
32
32
|
id: ObjectId,
|
|
33
|
-
title:
|
|
34
|
-
items:
|
|
35
|
-
}).pipe(
|
|
33
|
+
title: S.String,
|
|
34
|
+
items: S.Array(ListItem).pipe(S.mutable),
|
|
35
|
+
}).pipe(S.mutable);
|
|
36
36
|
|
|
37
|
-
type ListSchema =
|
|
37
|
+
type ListSchema = S.Schema.Type<typeof ListSchema>;
|
|
38
38
|
|
|
39
39
|
const list: ArtifactDef = {
|
|
40
40
|
typename: 'example.com/type/List',
|
|
@@ -44,7 +44,7 @@ const list: ArtifactDef = {
|
|
|
44
44
|
defineTool('list', {
|
|
45
45
|
name: 'query',
|
|
46
46
|
description: 'Query all lists',
|
|
47
|
-
schema:
|
|
47
|
+
schema: S.Struct({}),
|
|
48
48
|
execute: async ({}, context) => {
|
|
49
49
|
return ToolResult.Success(LISTS[id]);
|
|
50
50
|
},
|
|
@@ -52,7 +52,7 @@ const list: ArtifactDef = {
|
|
|
52
52
|
defineTool('list', {
|
|
53
53
|
name: 'inspect',
|
|
54
54
|
description: 'Get contents of the list',
|
|
55
|
-
schema:
|
|
55
|
+
schema: S.Struct({
|
|
56
56
|
id: ObjectId.annotations({ description: 'The list to inspect' }),
|
|
57
57
|
}),
|
|
58
58
|
execute: async ({ id }, context) => {
|
|
@@ -62,9 +62,9 @@ const list: ArtifactDef = {
|
|
|
62
62
|
defineTool('list', {
|
|
63
63
|
name: 'create',
|
|
64
64
|
description: 'Add one or more items to an existing list',
|
|
65
|
-
schema:
|
|
65
|
+
schema: S.Struct({
|
|
66
66
|
id: ObjectId.annotations({ description: 'The list to add items to' }),
|
|
67
|
-
items:
|
|
67
|
+
items: S.Array(ListItem).annotations({ description: 'The items to add to the list' }),
|
|
68
68
|
}),
|
|
69
69
|
execute: async ({ id, items }, context) => {
|
|
70
70
|
LISTS[id].items.push(...items);
|
|
@@ -81,7 +81,7 @@ const artifacts = [list];
|
|
|
81
81
|
const getArtifactDefinitions = defineTool('system', {
|
|
82
82
|
name: 'getArtifactDefinitions',
|
|
83
83
|
description: 'Queries the definitions and metadata of artifacts defined in the system',
|
|
84
|
-
schema:
|
|
84
|
+
schema: S.Any,
|
|
85
85
|
execute: async (_, context) => {
|
|
86
86
|
return ToolResult.Success(
|
|
87
87
|
artifacts.map((artifact) => ({
|
|
@@ -116,8 +116,8 @@ describe('Artifacts', () => {
|
|
|
116
116
|
name: 'custodian',
|
|
117
117
|
description: 'Custodian can tell you the password if you say the magic word',
|
|
118
118
|
parameters: toJsonSchema(
|
|
119
|
-
|
|
120
|
-
magicWord:
|
|
119
|
+
S.Struct({
|
|
120
|
+
magicWord: S.String.annotations({ description: 'The magic word. Should be exactly "pretty please"' }),
|
|
121
121
|
}),
|
|
122
122
|
),
|
|
123
123
|
};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Schema } from 'effect';
|
|
5
|
+
import { Schema as S } 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:
|
|
14
|
+
export const createCypherTool = (dataSource: DataSource, schemaTypes: S.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:
|
|
21
|
-
query:
|
|
20
|
+
schema: S.Struct({
|
|
21
|
+
query: S.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: Schema.Sch
|
|
|
55
55
|
},
|
|
56
56
|
});
|
|
57
57
|
|
|
58
|
-
export const createSystemPrompt = (schemaTypes:
|
|
58
|
+
export const createSystemPrompt = (schemaTypes: S.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:
|
package/src/testing/test-data.ts
CHANGED
|
@@ -2,20 +2,13 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type Schema } from 'effect';
|
|
5
|
+
import { type Schema as S } from 'effect';
|
|
6
6
|
|
|
7
7
|
import { raise } from '@dxos/debug';
|
|
8
8
|
import type { EchoDatabase } from '@dxos/echo-db';
|
|
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';
|
|
9
|
+
import { JSON_SCHEMA_ECHO_REF_ID, ObjectId, toJsonSchema, type JsonSchemaType, type Ref } from '@dxos/echo-schema';
|
|
17
10
|
import { invariant } from '@dxos/invariant';
|
|
18
|
-
import { live } from '@dxos/live-object';
|
|
11
|
+
import { live, makeRef } from '@dxos/live-object';
|
|
19
12
|
|
|
20
13
|
import {
|
|
21
14
|
type DataSource,
|
|
@@ -67,79 +60,79 @@ export const seedTestData = (db: EchoDatabase) => {
|
|
|
67
60
|
const _taskComposer1 = db.add(
|
|
68
61
|
live(Task, {
|
|
69
62
|
name: 'Optimize startup performance',
|
|
70
|
-
project:
|
|
71
|
-
assignee:
|
|
63
|
+
project: makeRef(projectComposer),
|
|
64
|
+
assignee: makeRef(contactJosiah),
|
|
72
65
|
}),
|
|
73
66
|
);
|
|
74
67
|
const _taskComposer2 = db.add(
|
|
75
68
|
live(Task, {
|
|
76
69
|
name: 'Create form builder',
|
|
77
|
-
project:
|
|
78
|
-
assignee:
|
|
70
|
+
project: makeRef(projectComposer),
|
|
71
|
+
assignee: makeRef(contactRich),
|
|
79
72
|
}),
|
|
80
73
|
);
|
|
81
74
|
const _taskComposer3 = db.add(
|
|
82
75
|
live(Task, {
|
|
83
76
|
name: 'Add support for custom themes',
|
|
84
|
-
project:
|
|
85
|
-
assignee:
|
|
77
|
+
project: makeRef(projectComposer),
|
|
78
|
+
assignee: makeRef(contactJosiah),
|
|
86
79
|
}),
|
|
87
80
|
);
|
|
88
81
|
const _taskComposer5 = db.add(
|
|
89
82
|
live(Task, {
|
|
90
83
|
name: 'Implement community plugin',
|
|
91
|
-
project:
|
|
92
|
-
assignee:
|
|
84
|
+
project: makeRef(projectComposer),
|
|
85
|
+
assignee: makeRef(contactFred),
|
|
93
86
|
}),
|
|
94
87
|
);
|
|
95
88
|
const _taskComposer4 = db.add(
|
|
96
89
|
live(Task, {
|
|
97
90
|
name: 'Implement dark mode',
|
|
98
|
-
project:
|
|
99
|
-
assignee:
|
|
91
|
+
project: makeRef(projectComposer),
|
|
92
|
+
assignee: makeRef(contactRich),
|
|
100
93
|
}),
|
|
101
94
|
);
|
|
102
95
|
const _taskEcho1 = db.add(
|
|
103
96
|
live(Task, {
|
|
104
97
|
name: 'Implement cypher query engine',
|
|
105
|
-
project:
|
|
106
|
-
assignee:
|
|
98
|
+
project: makeRef(projectEcho),
|
|
99
|
+
assignee: makeRef(contactDima),
|
|
107
100
|
}),
|
|
108
101
|
);
|
|
109
102
|
const _taskEcho2 = db.add(
|
|
110
103
|
live(Task, {
|
|
111
104
|
name: 'Add schema editor',
|
|
112
|
-
project:
|
|
113
|
-
assignee:
|
|
105
|
+
project: makeRef(projectEcho),
|
|
106
|
+
assignee: makeRef(contactRich),
|
|
114
107
|
}),
|
|
115
108
|
);
|
|
116
109
|
const _taskDoodles1 = db.add(
|
|
117
110
|
live(Task, {
|
|
118
111
|
name: 'Add support for custom themes',
|
|
119
|
-
project:
|
|
120
|
-
assignee:
|
|
112
|
+
project: makeRef(projectDoodles),
|
|
113
|
+
assignee: makeRef(contactFred),
|
|
121
114
|
}),
|
|
122
115
|
);
|
|
123
116
|
const _taskDoodles2 = db.add(
|
|
124
117
|
live(Task, {
|
|
125
118
|
name: 'Implement dark mode',
|
|
126
|
-
project:
|
|
127
|
-
assignee:
|
|
119
|
+
project: makeRef(projectDoodles),
|
|
120
|
+
assignee: makeRef(contactJosiah),
|
|
128
121
|
}),
|
|
129
122
|
);
|
|
130
123
|
|
|
131
124
|
const _orgDxos = db.add(
|
|
132
125
|
live(Organization, {
|
|
133
126
|
name: 'DXOS',
|
|
134
|
-
employees: [
|
|
135
|
-
projects: [
|
|
127
|
+
employees: [makeRef(contactRich), makeRef(contactJosiah), makeRef(contactDima)],
|
|
128
|
+
projects: [makeRef(projectEcho)],
|
|
136
129
|
}),
|
|
137
130
|
);
|
|
138
131
|
const _orgBraneframe = db.add(
|
|
139
132
|
live(Organization, {
|
|
140
133
|
name: 'Braneframe',
|
|
141
|
-
employees: [
|
|
142
|
-
projects: [
|
|
134
|
+
employees: [makeRef(contactJosiah), makeRef(contactRich)],
|
|
135
|
+
projects: [makeRef(projectComposer)],
|
|
143
136
|
}),
|
|
144
137
|
);
|
|
145
138
|
};
|
|
@@ -181,69 +174,69 @@ export const createTestData = (): MockDataSource => {
|
|
|
181
174
|
const _taskComposer1 = dataSource.add(Task, {
|
|
182
175
|
id: ObjectId.random(),
|
|
183
176
|
name: 'Optimize startup performance',
|
|
184
|
-
project:
|
|
185
|
-
assignee:
|
|
177
|
+
project: makeRef(projectComposer),
|
|
178
|
+
assignee: makeRef(contactJosiah),
|
|
186
179
|
});
|
|
187
180
|
const _taskComposer2 = dataSource.add(Task, {
|
|
188
181
|
id: ObjectId.random(),
|
|
189
182
|
name: 'Create form builder',
|
|
190
|
-
project:
|
|
191
|
-
assignee:
|
|
183
|
+
project: makeRef(projectComposer),
|
|
184
|
+
assignee: makeRef(contactRich),
|
|
192
185
|
});
|
|
193
186
|
const _taskComposer3 = dataSource.add(Task, {
|
|
194
187
|
id: ObjectId.random(),
|
|
195
188
|
name: 'Add support for custom themes',
|
|
196
|
-
project:
|
|
197
|
-
assignee:
|
|
189
|
+
project: makeRef(projectComposer),
|
|
190
|
+
assignee: makeRef(contactJosiah),
|
|
198
191
|
});
|
|
199
192
|
const _taskComposer5 = dataSource.add(Task, {
|
|
200
193
|
id: ObjectId.random(),
|
|
201
194
|
name: 'Implement community plugin',
|
|
202
|
-
project:
|
|
203
|
-
assignee:
|
|
195
|
+
project: makeRef(projectComposer),
|
|
196
|
+
assignee: makeRef(contactFred),
|
|
204
197
|
});
|
|
205
198
|
const _taskComposer4 = dataSource.add(Task, {
|
|
206
199
|
id: ObjectId.random(),
|
|
207
200
|
name: 'Implement dark mode',
|
|
208
|
-
project:
|
|
209
|
-
assignee:
|
|
201
|
+
project: makeRef(projectComposer),
|
|
202
|
+
assignee: makeRef(contactRich),
|
|
210
203
|
});
|
|
211
204
|
const _taskEcho1 = dataSource.add(Task, {
|
|
212
205
|
id: ObjectId.random(),
|
|
213
206
|
name: 'Implement cypher query engine',
|
|
214
|
-
project:
|
|
215
|
-
assignee:
|
|
207
|
+
project: makeRef(projectEcho),
|
|
208
|
+
assignee: makeRef(contactDima),
|
|
216
209
|
});
|
|
217
210
|
const _taskEcho2 = dataSource.add(Task, {
|
|
218
211
|
id: ObjectId.random(),
|
|
219
212
|
name: 'Add schema editor',
|
|
220
|
-
project:
|
|
221
|
-
assignee:
|
|
213
|
+
project: makeRef(projectEcho),
|
|
214
|
+
assignee: makeRef(contactRich),
|
|
222
215
|
});
|
|
223
216
|
const _taskDoodles1 = dataSource.add(Task, {
|
|
224
217
|
id: ObjectId.random(),
|
|
225
218
|
name: 'Add support for custom themes',
|
|
226
|
-
project:
|
|
227
|
-
assignee:
|
|
219
|
+
project: makeRef(projectDoodles),
|
|
220
|
+
assignee: makeRef(contactFred),
|
|
228
221
|
});
|
|
229
222
|
const _taskDoodles2 = dataSource.add(Task, {
|
|
230
223
|
id: ObjectId.random(),
|
|
231
224
|
name: 'Implement dark mode',
|
|
232
|
-
project:
|
|
233
|
-
assignee:
|
|
225
|
+
project: makeRef(projectDoodles),
|
|
226
|
+
assignee: makeRef(contactJosiah),
|
|
234
227
|
});
|
|
235
228
|
|
|
236
229
|
const _orgDxos = dataSource.add(Organization, {
|
|
237
230
|
id: ObjectId.random(),
|
|
238
231
|
name: 'DXOS',
|
|
239
|
-
employees: [
|
|
240
|
-
projects: [
|
|
232
|
+
employees: [makeRef(contactRich), makeRef(contactJosiah), makeRef(contactDima)],
|
|
233
|
+
projects: [makeRef(projectEcho)],
|
|
241
234
|
});
|
|
242
235
|
const _orgBraneframe = dataSource.add(Organization, {
|
|
243
236
|
id: ObjectId.random(),
|
|
244
237
|
name: 'Braneframe',
|
|
245
|
-
employees: [
|
|
246
|
-
projects: [
|
|
238
|
+
employees: [makeRef(contactJosiah), makeRef(contactRich)],
|
|
239
|
+
projects: [makeRef(projectComposer)],
|
|
247
240
|
});
|
|
248
241
|
dataSource.computeGraph();
|
|
249
242
|
|
|
@@ -254,7 +247,7 @@ export class MockDataSource implements DataSource {
|
|
|
254
247
|
objects: Record<
|
|
255
248
|
string,
|
|
256
249
|
{
|
|
257
|
-
schema:
|
|
250
|
+
schema: S.Schema.All;
|
|
258
251
|
typeDxn: string;
|
|
259
252
|
id: string;
|
|
260
253
|
data: unknown;
|
|
@@ -265,7 +258,7 @@ export class MockDataSource implements DataSource {
|
|
|
265
258
|
string,
|
|
266
259
|
{
|
|
267
260
|
json: JsonSchemaType;
|
|
268
|
-
instance:
|
|
261
|
+
instance: S.Schema.All;
|
|
269
262
|
}
|
|
270
263
|
> = {};
|
|
271
264
|
|
|
@@ -280,7 +273,7 @@ export class MockDataSource implements DataSource {
|
|
|
280
273
|
return this.relationships.filter((relationship) => !label || relationship.label === label);
|
|
281
274
|
}
|
|
282
275
|
|
|
283
|
-
add<S extends
|
|
276
|
+
add<S extends S.Schema.All>(schema: S, data: S.Schema.Type<S>) {
|
|
284
277
|
invariant(typeof data.id === 'string', 'Data must have an id');
|
|
285
278
|
const jsonSchema = toJsonSchema(schema);
|
|
286
279
|
if (!this.schema[jsonSchema.$id!]) {
|
|
@@ -2,19 +2,22 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Schema } from 'effect';
|
|
5
|
+
import { Schema as S } from 'effect';
|
|
6
6
|
|
|
7
|
-
import { EntityKind, TypeAnnotationId, Ref
|
|
7
|
+
import { EntityKind, TypeAnnotationId, Ref } from '@dxos/echo-schema';
|
|
8
8
|
|
|
9
|
-
// TODO(burdon):
|
|
9
|
+
// TODO(burdon): Reconcile with sdk/schema/testing.
|
|
10
|
+
// TODO(burdon): Convert interface to type.
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
export const
|
|
12
|
+
// TODO(dmaretskyi): Extract.
|
|
13
|
+
export const ObjectId = S.String.annotations({ description: 'The unique object identifier.' });
|
|
14
|
+
|
|
15
|
+
export const Contact = S.Struct({
|
|
13
16
|
id: ObjectId,
|
|
14
|
-
name:
|
|
15
|
-
email:
|
|
17
|
+
name: S.String.annotations({ description: 'The name of the person.' }),
|
|
18
|
+
email: S.optional(S.String).annotations({ description: 'Email address.' }),
|
|
16
19
|
})
|
|
17
|
-
.pipe(
|
|
20
|
+
.pipe(S.mutable)
|
|
18
21
|
.annotations({
|
|
19
22
|
[TypeAnnotationId]: {
|
|
20
23
|
kind: EntityKind.Object,
|
|
@@ -23,15 +26,14 @@ export const Contact = Schema.Struct({
|
|
|
23
26
|
},
|
|
24
27
|
description: 'Contact information.',
|
|
25
28
|
});
|
|
26
|
-
export interface Contact extends
|
|
29
|
+
export interface Contact extends S.Schema.Type<typeof Contact> {}
|
|
27
30
|
|
|
28
|
-
|
|
29
|
-
export const Project = Schema.Struct({
|
|
31
|
+
export const Project = S.Struct({
|
|
30
32
|
id: ObjectId,
|
|
31
|
-
name:
|
|
32
|
-
description:
|
|
33
|
+
name: S.String.annotations({ description: 'The name of the project.' }),
|
|
34
|
+
description: S.optional(S.String).annotations({ description: 'The description of the project.' }),
|
|
33
35
|
})
|
|
34
|
-
.pipe(
|
|
36
|
+
.pipe(S.mutable)
|
|
35
37
|
.annotations({
|
|
36
38
|
[TypeAnnotationId]: {
|
|
37
39
|
kind: EntityKind.Object,
|
|
@@ -40,16 +42,16 @@ export const Project = Schema.Struct({
|
|
|
40
42
|
},
|
|
41
43
|
description: 'Contact information.',
|
|
42
44
|
});
|
|
43
|
-
export interface Project extends
|
|
45
|
+
export interface Project extends S.Schema.Type<typeof Project> {}
|
|
44
46
|
|
|
45
|
-
export const Task =
|
|
47
|
+
export const Task = S.Struct({
|
|
46
48
|
id: ObjectId,
|
|
47
|
-
name:
|
|
48
|
-
description:
|
|
49
|
+
name: S.String.annotations({ description: 'The name of the task.' }),
|
|
50
|
+
description: S.optional(S.String).annotations({ description: 'The description of the task.' }),
|
|
49
51
|
project: Ref(Project),
|
|
50
52
|
assignee: Ref(Contact),
|
|
51
53
|
})
|
|
52
|
-
.pipe(
|
|
54
|
+
.pipe(S.mutable)
|
|
53
55
|
.annotations({
|
|
54
56
|
[TypeAnnotationId]: {
|
|
55
57
|
kind: EntityKind.Object,
|
|
@@ -58,16 +60,15 @@ export const Task = Schema.Struct({
|
|
|
58
60
|
},
|
|
59
61
|
description: 'Contact information.',
|
|
60
62
|
});
|
|
61
|
-
export interface Task extends
|
|
63
|
+
export interface Task extends S.Schema.Type<typeof Task> {}
|
|
62
64
|
|
|
63
|
-
|
|
64
|
-
export const Organization = Schema.Struct({
|
|
65
|
+
export const Organization = S.Struct({
|
|
65
66
|
id: ObjectId,
|
|
66
|
-
name:
|
|
67
|
-
projects:
|
|
68
|
-
employees:
|
|
67
|
+
name: S.String.annotations({ description: 'The name of the organization.' }),
|
|
68
|
+
projects: S.Array(Ref(Project)),
|
|
69
|
+
employees: S.Array(Ref(Contact)),
|
|
69
70
|
})
|
|
70
|
-
.pipe(
|
|
71
|
+
.pipe(S.mutable)
|
|
71
72
|
.annotations({
|
|
72
73
|
[TypeAnnotationId]: {
|
|
73
74
|
kind: EntityKind.Object,
|
|
@@ -76,4 +77,4 @@ export const Organization = Schema.Struct({
|
|
|
76
77
|
},
|
|
77
78
|
description: 'Contact information.',
|
|
78
79
|
});
|
|
79
|
-
export interface Organization extends
|
|
80
|
+
export interface Organization extends S.Schema.Type<typeof Organization> {}
|