@dxos/assistant-toolkit 0.8.4-main.2c6827d → 0.8.4-main.3c1ae3b
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/index.mjs +123 -112
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +123 -112
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/blueprints/discord/discord-blueprint.d.ts +4 -3
- package/dist/types/src/blueprints/discord/discord-blueprint.d.ts.map +1 -1
- package/dist/types/src/blueprints/linear/linear-blueprint.d.ts +4 -3
- package/dist/types/src/blueprints/linear/linear-blueprint.d.ts.map +1 -1
- package/dist/types/src/crud/graph.d.ts +5 -4
- package/dist/types/src/crud/graph.d.ts.map +1 -1
- package/dist/types/src/functions/agent/prompt.d.ts.map +1 -1
- package/dist/types/src/functions/document/read.d.ts.map +1 -1
- package/dist/types/src/functions/document/update.d.ts.map +1 -1
- package/dist/types/src/functions/entity-extraction/entity-extraction.d.ts +12 -13
- package/dist/types/src/functions/entity-extraction/entity-extraction.d.ts.map +1 -1
- package/dist/types/src/functions/entity-extraction/index.d.ts +12 -13
- package/dist/types/src/functions/entity-extraction/index.d.ts.map +1 -1
- package/dist/types/src/functions/linear/sync-issues.d.ts.map +1 -1
- package/dist/types/src/functions/research/document-create.d.ts.map +1 -1
- package/dist/types/src/functions/research/research-graph.d.ts +7 -6
- package/dist/types/src/functions/research/research-graph.d.ts.map +1 -1
- package/dist/types/src/functions/research/research.d.ts.map +1 -1
- package/dist/types/src/functions/research/types.d.ts +1 -1
- package/dist/types/src/functions/research/types.d.ts.map +1 -1
- package/dist/types/src/functions/tasks/read.d.ts.map +1 -1
- package/dist/types/src/functions/tasks/update.d.ts.map +1 -1
- package/dist/types/src/plugins.d.ts.map +1 -1
- package/dist/types/src/sync/sync.d.ts +2 -2
- package/dist/types/src/sync/sync.d.ts.map +1 -1
- package/dist/types/src/toolkits/AssistantToolkit.d.ts +2 -2
- package/dist/types/src/toolkits/AssistantToolkit.d.ts.map +1 -1
- package/dist/types/src/toolkits/SystemToolkit.d.ts +8 -8
- package/dist/types/src/toolkits/SystemToolkit.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +23 -23
- package/src/blueprints/design/design-blueprint.test.ts +8 -6
- package/src/blueprints/planning/planning-blueprint.test.ts +6 -4
- package/src/crud/graph.test.ts +4 -3
- package/src/crud/graph.ts +19 -24
- package/src/experimental/feed.test.ts +1 -1
- package/src/functions/agent/prompt.ts +13 -10
- package/src/functions/discord/fetch-messages.test.ts +1 -1
- package/src/functions/document/read.ts +4 -3
- package/src/functions/document/update.ts +4 -3
- package/src/functions/entity-extraction/entity-extraction.test.ts +7 -6
- package/src/functions/entity-extraction/entity-extraction.ts +20 -10
- package/src/functions/linear/linear.test.ts +11 -10
- package/src/functions/linear/sync-issues.ts +5 -4
- package/src/functions/research/document-create.ts +7 -6
- package/src/functions/research/research-graph.ts +12 -10
- package/src/functions/research/research.test.ts +20 -24
- package/src/functions/research/research.ts +5 -4
- package/src/functions/research/types.ts +1 -1
- package/src/functions/tasks/read.ts +4 -3
- package/src/functions/tasks/update.ts +4 -3
- package/src/plugins.tsx +3 -3
- package/src/sync/sync.ts +4 -6
- package/src/toolkits/AssistantToolkit.test.ts +8 -6
- package/src/toolkits/AssistantToolkit.ts +3 -3
- package/src/toolkits/SystemToolkit.ts +18 -18
|
@@ -10,7 +10,8 @@ import * as Function from 'effect/Function';
|
|
|
10
10
|
import * as Schema from 'effect/Schema';
|
|
11
11
|
|
|
12
12
|
import { Filter, Obj, Query, Ref, type Type } from '@dxos/echo';
|
|
13
|
-
import {
|
|
13
|
+
import { Database } from '@dxos/echo';
|
|
14
|
+
import { defineFunction, withAuthorization } from '@dxos/functions';
|
|
14
15
|
import { log } from '@dxos/log';
|
|
15
16
|
import { Person, Project, Task } from '@dxos/types';
|
|
16
17
|
|
|
@@ -35,7 +36,7 @@ query Issues($teamId: String!, $after: DateTimeOrDuration!) {
|
|
|
35
36
|
updatedAt
|
|
36
37
|
description
|
|
37
38
|
assignee { id, name }
|
|
38
|
-
state {
|
|
39
|
+
state {
|
|
39
40
|
name
|
|
40
41
|
}
|
|
41
42
|
project {
|
|
@@ -114,8 +115,8 @@ export default defineFunction({
|
|
|
114
115
|
const getLatestUpdateTimestamp: (
|
|
115
116
|
teamId: string,
|
|
116
117
|
dataType: Type.Obj.Any,
|
|
117
|
-
) => Effect.Effect<string, never,
|
|
118
|
-
const
|
|
118
|
+
) => Effect.Effect<string, never, Database.Service> = Effect.fnUntraced(function* (teamId, dataType) {
|
|
119
|
+
const existingTasks = yield* Database.Service.runQuery(
|
|
119
120
|
Query.type(dataType).select(Filter.foreignKeys(dataType, [{ source: LINEAR_TEAM_ID_KEY, id: teamId }])),
|
|
120
121
|
);
|
|
121
122
|
return Function.pipe(
|
|
@@ -7,7 +7,8 @@ import * as Schema from 'effect/Schema';
|
|
|
7
7
|
|
|
8
8
|
import { ArtifactId } from '@dxos/assistant';
|
|
9
9
|
import { Obj, Relation } from '@dxos/echo';
|
|
10
|
-
import {
|
|
10
|
+
import { Database } from '@dxos/echo';
|
|
11
|
+
import { TracingService, defineFunction } from '@dxos/functions';
|
|
11
12
|
import { log } from '@dxos/log';
|
|
12
13
|
import { Markdown } from '@dxos/plugin-markdown/types';
|
|
13
14
|
import { HasSubject } from '@dxos/types';
|
|
@@ -42,14 +43,14 @@ export default defineFunction({
|
|
|
42
43
|
log.info('Creating research document', { subject, name, content });
|
|
43
44
|
|
|
44
45
|
// TODO(burdon): Auto flush before and after calling function?
|
|
45
|
-
yield*
|
|
46
|
+
yield* Database.Service.flush({ indexes: true });
|
|
46
47
|
yield* TracingService.emitStatus({ message: 'Creating research document...' });
|
|
47
48
|
|
|
48
49
|
// TODO(burdon): Type check.
|
|
49
|
-
const target = (yield*
|
|
50
|
+
const target = (yield* Database.Service.resolve(ArtifactId.toDXN(subject))) as Obj.Any;
|
|
50
51
|
|
|
51
52
|
// Create document.
|
|
52
|
-
const object = yield*
|
|
53
|
+
const object = yield* Database.Service.add(
|
|
53
54
|
Markdown.make({
|
|
54
55
|
name,
|
|
55
56
|
content,
|
|
@@ -57,7 +58,7 @@ export default defineFunction({
|
|
|
57
58
|
);
|
|
58
59
|
|
|
59
60
|
// Create relation.
|
|
60
|
-
yield*
|
|
61
|
+
yield* Database.Service.add(
|
|
61
62
|
Relation.make(HasSubject.HasSubject, {
|
|
62
63
|
[Relation.Source]: object,
|
|
63
64
|
[Relation.Target]: target,
|
|
@@ -65,7 +66,7 @@ export default defineFunction({
|
|
|
65
66
|
}),
|
|
66
67
|
);
|
|
67
68
|
|
|
68
|
-
yield*
|
|
69
|
+
yield* Database.Service.flush({ indexes: true });
|
|
69
70
|
log.info('Created research document', { subject, object });
|
|
70
71
|
|
|
71
72
|
return {
|
|
@@ -7,8 +7,10 @@ import * as Layer from 'effect/Layer';
|
|
|
7
7
|
import * as Schema from 'effect/Schema';
|
|
8
8
|
|
|
9
9
|
import { Obj, Query, Ref, Type } from '@dxos/echo';
|
|
10
|
+
import { Database } from '@dxos/echo';
|
|
11
|
+
import { SystemTypeAnnotation } from '@dxos/echo/internal';
|
|
10
12
|
import { Queue } from '@dxos/echo-db';
|
|
11
|
-
import { ContextQueueService,
|
|
13
|
+
import { ContextQueueService, QueueService } from '@dxos/functions';
|
|
12
14
|
|
|
13
15
|
/**
|
|
14
16
|
* Container for a set of ephemeral research results.
|
|
@@ -20,28 +22,28 @@ export const ResearchGraph = Schema.Struct({
|
|
|
20
22
|
typename: 'dxos.org/type/ResearchGraph',
|
|
21
23
|
version: '0.1.0',
|
|
22
24
|
}),
|
|
25
|
+
SystemTypeAnnotation.set(true),
|
|
23
26
|
);
|
|
24
27
|
|
|
25
28
|
export interface ResearchGraph extends Schema.Schema.Type<typeof ResearchGraph> {}
|
|
26
29
|
|
|
27
|
-
export const queryResearchGraph: () => Effect.Effect<ResearchGraph | undefined, never,
|
|
30
|
+
export const queryResearchGraph: () => Effect.Effect<ResearchGraph | undefined, never, Database.Service> = Effect.fn(
|
|
28
31
|
'queryResearchGraph',
|
|
29
32
|
)(function* () {
|
|
30
|
-
const
|
|
33
|
+
const objects = yield* Database.Service.runQuery(Query.type(ResearchGraph));
|
|
31
34
|
return objects.at(0);
|
|
32
35
|
});
|
|
33
36
|
|
|
34
|
-
export const createResearchGraph: () => Effect.Effect<ResearchGraph, never,
|
|
35
|
-
'createResearchGraph'
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
});
|
|
37
|
+
export const createResearchGraph: () => Effect.Effect<ResearchGraph, never, Database.Service | QueueService> =
|
|
38
|
+
Effect.fn('createResearchGraph')(function* () {
|
|
39
|
+
const queue = yield* QueueService.createQueue();
|
|
40
|
+
return yield* Database.Service.add(Obj.make(ResearchGraph, { queue: Ref.fromDXN(queue.dxn) }));
|
|
41
|
+
});
|
|
40
42
|
|
|
41
43
|
export const contextQueueLayerFromResearchGraph = Layer.unwrapEffect(
|
|
42
44
|
Effect.gen(function* () {
|
|
43
45
|
const researchGraph = (yield* queryResearchGraph()) ?? (yield* createResearchGraph());
|
|
44
|
-
const researchQueue = yield*
|
|
46
|
+
const researchQueue = yield* Database.Service.load(researchGraph.queue);
|
|
45
47
|
return ContextQueueService.layer(researchQueue);
|
|
46
48
|
}),
|
|
47
49
|
);
|
|
@@ -8,8 +8,8 @@ import { describe, it } from '@effect/vitest';
|
|
|
8
8
|
import * as Effect from 'effect/Effect';
|
|
9
9
|
import * as Layer from 'effect/Layer';
|
|
10
10
|
|
|
11
|
-
import { AiService, ConsolePrinter
|
|
12
|
-
import { TestAiService } from '@dxos/ai/testing';
|
|
11
|
+
import { AiService, ConsolePrinter } from '@dxos/ai';
|
|
12
|
+
import { MemoizedAiService, TestAiService } from '@dxos/ai/testing';
|
|
13
13
|
import {
|
|
14
14
|
AiConversation,
|
|
15
15
|
type ContextBinding,
|
|
@@ -19,14 +19,10 @@ import {
|
|
|
19
19
|
} from '@dxos/assistant';
|
|
20
20
|
import { Blueprint } from '@dxos/blueprints';
|
|
21
21
|
import { Filter, Obj, Query, Ref } from '@dxos/echo';
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
FunctionInvocationService,
|
|
27
|
-
QueueService,
|
|
28
|
-
TracingService,
|
|
29
|
-
} from '@dxos/functions';
|
|
22
|
+
import { Database } from '@dxos/echo';
|
|
23
|
+
import { acquireReleaseResource } from '@dxos/effect';
|
|
24
|
+
import { TestHelpers } from '@dxos/effect/testing';
|
|
25
|
+
import { CredentialsService, FunctionInvocationService, QueueService, TracingService } from '@dxos/functions';
|
|
30
26
|
import { FunctionInvocationServiceLayerTest, TestDatabaseLayer } from '@dxos/functions-runtime/testing';
|
|
31
27
|
import { invariant } from '@dxos/invariant';
|
|
32
28
|
import { ObjectId } from '@dxos/keys';
|
|
@@ -76,13 +72,13 @@ describe('Research', () => {
|
|
|
76
72
|
'call a function to generate a research report',
|
|
77
73
|
Effect.fnUntraced(
|
|
78
74
|
function* (_) {
|
|
79
|
-
yield*
|
|
75
|
+
yield* Database.Service.add(
|
|
80
76
|
Obj.make(Organization.Organization, {
|
|
81
77
|
name: 'BlueYard',
|
|
82
78
|
website: 'https://blueyard.com',
|
|
83
79
|
}),
|
|
84
80
|
);
|
|
85
|
-
yield*
|
|
81
|
+
yield* Database.Service.flush({ indexes: true });
|
|
86
82
|
const result = yield* FunctionInvocationService.invokeFunction(research, {
|
|
87
83
|
query: 'Founders and portfolio of BlueYard.',
|
|
88
84
|
});
|
|
@@ -90,10 +86,10 @@ describe('Research', () => {
|
|
|
90
86
|
console.log(inspect(result, { depth: null, colors: true }));
|
|
91
87
|
console.log(JSON.stringify(result, null, 2));
|
|
92
88
|
|
|
93
|
-
yield*
|
|
89
|
+
yield* Database.Service.flush({ indexes: true });
|
|
94
90
|
const researchGraph = yield* queryResearchGraph();
|
|
95
91
|
if (researchGraph) {
|
|
96
|
-
const data = yield*
|
|
92
|
+
const data = yield* Database.Service.load(researchGraph.queue).pipe(
|
|
97
93
|
Effect.flatMap((queue) => Effect.promise(() => queue.queryObjects())),
|
|
98
94
|
);
|
|
99
95
|
console.log(inspect(data, { depth: null, colors: true }));
|
|
@@ -109,7 +105,7 @@ describe('Research', () => {
|
|
|
109
105
|
'create and update research report',
|
|
110
106
|
Effect.fnUntraced(
|
|
111
107
|
function* (_) {
|
|
112
|
-
const organization = yield*
|
|
108
|
+
const organization = yield* Database.Service.add(
|
|
113
109
|
Obj.make(Organization.Organization, {
|
|
114
110
|
name: 'BlueYard',
|
|
115
111
|
website: 'https://blueyard.com',
|
|
@@ -119,9 +115,9 @@ describe('Research', () => {
|
|
|
119
115
|
const queue = yield* QueueService.createQueue<Message.Message | ContextBinding>();
|
|
120
116
|
const conversation = yield* acquireReleaseResource(() => new AiConversation(queue));
|
|
121
117
|
|
|
122
|
-
yield*
|
|
123
|
-
const researchBlueprint = yield*
|
|
124
|
-
const markdownBlueprint = yield*
|
|
118
|
+
yield* Database.Service.flush({ indexes: true });
|
|
119
|
+
const researchBlueprint = yield* Database.Service.add(Obj.clone(ResearchBlueprint));
|
|
120
|
+
const markdownBlueprint = yield* Database.Service.add(Obj.clone(MarkdownBlueprint));
|
|
125
121
|
yield* Effect.promise(() =>
|
|
126
122
|
conversation.context.bind({
|
|
127
123
|
blueprints: [Ref.make(researchBlueprint), Ref.make(markdownBlueprint)],
|
|
@@ -136,8 +132,8 @@ describe('Research', () => {
|
|
|
136
132
|
prompt: `Create a research summary about ${organization.name}.`,
|
|
137
133
|
});
|
|
138
134
|
{
|
|
139
|
-
const
|
|
140
|
-
Query.select(Filter.
|
|
135
|
+
const docs = yield* Database.Service.runQuery(
|
|
136
|
+
Query.select(Filter.id(organization.id)).targetOf(HasSubject.HasSubject).source(),
|
|
141
137
|
);
|
|
142
138
|
if (docs.length !== 1) {
|
|
143
139
|
throw new Error(`Expected 1 research document; got ${docs.length}: ${docs.map((_) => _.name)}`);
|
|
@@ -147,7 +143,7 @@ describe('Research', () => {
|
|
|
147
143
|
invariant(Obj.instanceOf(Markdown.Document, doc));
|
|
148
144
|
console.log({
|
|
149
145
|
name: doc.name,
|
|
150
|
-
content: yield*
|
|
146
|
+
content: yield* Database.Service.load(doc.content).pipe(Effect.map((_) => _.content)),
|
|
151
147
|
});
|
|
152
148
|
}
|
|
153
149
|
|
|
@@ -156,8 +152,8 @@ describe('Research', () => {
|
|
|
156
152
|
prompt: 'Add a section about their portfolio.',
|
|
157
153
|
});
|
|
158
154
|
{
|
|
159
|
-
const
|
|
160
|
-
Query.select(Filter.
|
|
155
|
+
const docs = yield* Database.Service.runQuery(
|
|
156
|
+
Query.select(Filter.id(organization.id)).targetOf(HasSubject.HasSubject).source(),
|
|
161
157
|
);
|
|
162
158
|
if (docs.length !== 1) {
|
|
163
159
|
throw new Error(`Expected 1 research document; got ${docs.length}: ${docs.map((_) => _.name)}`);
|
|
@@ -167,7 +163,7 @@ describe('Research', () => {
|
|
|
167
163
|
invariant(Obj.instanceOf(Markdown.Document, doc));
|
|
168
164
|
console.log({
|
|
169
165
|
name: doc.name,
|
|
170
|
-
content: yield*
|
|
166
|
+
content: yield* Database.Service.load(doc.content).pipe(Effect.map((_) => _.content)),
|
|
171
167
|
});
|
|
172
168
|
}
|
|
173
169
|
},
|
|
@@ -22,7 +22,8 @@ import {
|
|
|
22
22
|
} from '@dxos/assistant';
|
|
23
23
|
import { Template } from '@dxos/blueprints';
|
|
24
24
|
import { type DXN, Obj } from '@dxos/echo';
|
|
25
|
-
import {
|
|
25
|
+
import { Database } from '@dxos/echo';
|
|
26
|
+
import { TracingService, defineFunction } from '@dxos/functions';
|
|
26
27
|
import { FunctionInvocationServiceLayerTestMocked } from '@dxos/functions-runtime/testing';
|
|
27
28
|
import { type Message, Person } from '@dxos/types';
|
|
28
29
|
import { trim } from '@dxos/util';
|
|
@@ -84,7 +85,7 @@ export default defineFunction({
|
|
|
84
85
|
handler: Effect.fnUntraced(
|
|
85
86
|
function* ({ data: { query, instructions, mockSearch = false, entityExtraction = false } }) {
|
|
86
87
|
if (mockSearch) {
|
|
87
|
-
const mockPerson = yield*
|
|
88
|
+
const mockPerson = yield* Database.Service.add(
|
|
88
89
|
Obj.make(Person.Person, {
|
|
89
90
|
preferredName: 'John Doe',
|
|
90
91
|
emails: [{ value: 'john.doe@example.com' }],
|
|
@@ -101,7 +102,7 @@ export default defineFunction({
|
|
|
101
102
|
};
|
|
102
103
|
}
|
|
103
104
|
|
|
104
|
-
yield*
|
|
105
|
+
yield* Database.Service.flush({ indexes: true });
|
|
105
106
|
yield* TracingService.emitStatus({ message: 'Starting research...' });
|
|
106
107
|
|
|
107
108
|
const NativeWebSearch = Toolkit.make(AnthropicTool.WebSearch_20250305({}));
|
|
@@ -137,7 +138,7 @@ export default defineFunction({
|
|
|
137
138
|
observer: GenerationObserver.fromPrinter(new ConsolePrinter({ tag: 'research' })),
|
|
138
139
|
});
|
|
139
140
|
|
|
140
|
-
const objects = yield* Effect.forEach(objectDXNs, (dxn) =>
|
|
141
|
+
const objects = yield* Effect.forEach(objectDXNs, (dxn) => Database.Service.resolve(dxn)).pipe(
|
|
141
142
|
Effect.map(Array.map((obj) => Obj.toJSON(obj))),
|
|
142
143
|
);
|
|
143
144
|
|
|
@@ -9,7 +9,7 @@ import { Event, HasConnection, HasRelationship, LegacyOrganization, LegacyPerson
|
|
|
9
9
|
/**
|
|
10
10
|
* Data types for research.
|
|
11
11
|
*/
|
|
12
|
-
export const ResearchDataTypes:
|
|
12
|
+
export const ResearchDataTypes: Type.Entity.Any[] = [
|
|
13
13
|
// Objects
|
|
14
14
|
Event.Event,
|
|
15
15
|
LegacyOrganization,
|
|
@@ -6,7 +6,8 @@ import * as Effect from 'effect/Effect';
|
|
|
6
6
|
import * as Schema from 'effect/Schema';
|
|
7
7
|
|
|
8
8
|
import { ArtifactId } from '@dxos/assistant';
|
|
9
|
-
import {
|
|
9
|
+
import { Database } from '@dxos/echo';
|
|
10
|
+
import { defineFunction } from '@dxos/functions';
|
|
10
11
|
import { Markdown } from '@dxos/plugin-markdown/types';
|
|
11
12
|
|
|
12
13
|
export default defineFunction({
|
|
@@ -22,10 +23,10 @@ export default defineFunction({
|
|
|
22
23
|
content: Schema.String,
|
|
23
24
|
}),
|
|
24
25
|
handler: Effect.fn(function* ({ data: { id } }) {
|
|
25
|
-
const doc = yield*
|
|
26
|
+
const doc = yield* Database.Service.resolve(ArtifactId.toDXN(id), Markdown.Document);
|
|
26
27
|
|
|
27
28
|
// Return content with line numbers prefixed.
|
|
28
|
-
const { content } = yield*
|
|
29
|
+
const { content } = yield* Database.Service.load(doc.content);
|
|
29
30
|
const lines = content.split('\n');
|
|
30
31
|
const len = String(lines.length).length;
|
|
31
32
|
const numbered = lines.map((line, i) => `${String(i + 1).padStart(len, ' ')}. ${line}`).join('\n');
|
|
@@ -6,7 +6,8 @@ import * as Effect from 'effect/Effect';
|
|
|
6
6
|
import * as Schema from 'effect/Schema';
|
|
7
7
|
|
|
8
8
|
import { ArtifactId } from '@dxos/assistant';
|
|
9
|
-
import {
|
|
9
|
+
import { Database } from '@dxos/echo';
|
|
10
|
+
import { defineFunction } from '@dxos/functions';
|
|
10
11
|
import { Markdown } from '@dxos/plugin-markdown/types';
|
|
11
12
|
|
|
12
13
|
import { MarkdownTasks, type TaskOperation } from './task-list';
|
|
@@ -34,10 +35,10 @@ export default defineFunction({
|
|
|
34
35
|
}),
|
|
35
36
|
}),
|
|
36
37
|
handler: Effect.fn(function* ({ data: { id, operations = [] } }) {
|
|
37
|
-
const doc = yield*
|
|
38
|
+
const doc = yield* Database.Service.resolve(ArtifactId.toDXN(id), Markdown.Document);
|
|
38
39
|
|
|
39
40
|
// Create task manager and apply operations if provided.
|
|
40
|
-
const { content } = yield*
|
|
41
|
+
const { content } = yield* Database.Service.load(doc.content);
|
|
41
42
|
const taskManager = new MarkdownTasks(content);
|
|
42
43
|
if (operations.length > 0) {
|
|
43
44
|
taskManager.applyOperations(operations as TaskOperation[]);
|
package/src/plugins.tsx
CHANGED
|
@@ -6,11 +6,11 @@ import * as Schema from 'effect/Schema';
|
|
|
6
6
|
import React from 'react';
|
|
7
7
|
|
|
8
8
|
import { type AnyCapability, Capabilities, contributes, createSurface } from '@dxos/app-framework';
|
|
9
|
-
import { type Obj, Type } from '@dxos/echo';
|
|
9
|
+
import { Format, type Obj, Type } from '@dxos/echo';
|
|
10
10
|
import { JsonFilter } from '@dxos/react-ui-syntax-highlighter';
|
|
11
11
|
|
|
12
12
|
export const MapSchema = Schema.Struct({
|
|
13
|
-
coordinates:
|
|
13
|
+
coordinates: Format.GeoPoint,
|
|
14
14
|
}).pipe(
|
|
15
15
|
Type.Obj({
|
|
16
16
|
typename: 'example.com/type/Map',
|
|
@@ -62,7 +62,7 @@ export const capabilities: AnyCapability[] = [
|
|
|
62
62
|
id: 'plugin-default',
|
|
63
63
|
role: 'card--extrinsic',
|
|
64
64
|
position: 'fallback',
|
|
65
|
-
component: ({
|
|
65
|
+
component: ({ data }) => <JsonFilter data={data} />,
|
|
66
66
|
}),
|
|
67
67
|
),
|
|
68
68
|
];
|
package/src/sync/sync.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import * as Effect from 'effect/Effect';
|
|
6
6
|
|
|
7
7
|
import { Filter, Obj, Query, Ref } from '@dxos/echo';
|
|
8
|
-
import {
|
|
8
|
+
import { Database } from '@dxos/echo';
|
|
9
9
|
import { failedInvariant } from '@dxos/invariant';
|
|
10
10
|
import { log } from '@dxos/log';
|
|
11
11
|
|
|
@@ -20,7 +20,7 @@ import { log } from '@dxos/log';
|
|
|
20
20
|
export const syncObjects: (
|
|
21
21
|
objs: Obj.Any[],
|
|
22
22
|
opts: { foreignKeyId: string },
|
|
23
|
-
) => Effect.Effect<Obj.Any[], never,
|
|
23
|
+
) => Effect.Effect<Obj.Any[], never, Database.Service> = Effect.fn('syncObjects')(function* (objs, { foreignKeyId }) {
|
|
24
24
|
return yield* Effect.forEach(
|
|
25
25
|
objs,
|
|
26
26
|
Effect.fnUntraced(function* (obj) {
|
|
@@ -39,9 +39,7 @@ export const syncObjects: (
|
|
|
39
39
|
|
|
40
40
|
const schema = Obj.getSchema(obj) ?? failedInvariant('No schema.');
|
|
41
41
|
const foreignId = Obj.getKeys(obj, foreignKeyId)[0]?.id ?? failedInvariant('No foreign key.');
|
|
42
|
-
const
|
|
43
|
-
objects: [existing],
|
|
44
|
-
} = yield* DatabaseService.runQuery(
|
|
42
|
+
const [existing] = yield* Database.Service.runQuery(
|
|
45
43
|
Query.select(Filter.foreignKeys(schema, [{ source: foreignKeyId, id: foreignId }])),
|
|
46
44
|
);
|
|
47
45
|
log('sync object', {
|
|
@@ -50,7 +48,7 @@ export const syncObjects: (
|
|
|
50
48
|
existing: existing ? Obj.getDXN(existing) : undefined,
|
|
51
49
|
});
|
|
52
50
|
if (!existing) {
|
|
53
|
-
yield*
|
|
51
|
+
yield* Database.Service.add(obj);
|
|
54
52
|
return obj;
|
|
55
53
|
} else {
|
|
56
54
|
copyObjectData(existing, obj);
|
|
@@ -6,8 +6,8 @@ import { describe, expect, it } from '@effect/vitest';
|
|
|
6
6
|
import * as Effect from 'effect/Effect';
|
|
7
7
|
import * as Layer from 'effect/Layer';
|
|
8
8
|
|
|
9
|
-
import { AiService, ConsolePrinter
|
|
10
|
-
import { TestAiService } from '@dxos/ai/testing';
|
|
9
|
+
import { AiService, ConsolePrinter } from '@dxos/ai';
|
|
10
|
+
import { MemoizedAiService, TestAiService } from '@dxos/ai/testing';
|
|
11
11
|
import {
|
|
12
12
|
AiConversation,
|
|
13
13
|
type ContextBinding,
|
|
@@ -18,8 +18,10 @@ import {
|
|
|
18
18
|
import { Blueprint, Template } from '@dxos/blueprints';
|
|
19
19
|
import { Obj } from '@dxos/echo';
|
|
20
20
|
import { Ref } from '@dxos/echo';
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
21
|
+
import { Database } from '@dxos/echo';
|
|
22
|
+
import { acquireReleaseResource } from '@dxos/effect';
|
|
23
|
+
import { TestHelpers } from '@dxos/effect/testing';
|
|
24
|
+
import { CredentialsService, QueueService, TracingService } from '@dxos/functions';
|
|
23
25
|
import { FunctionInvocationServiceLayerTest, TestDatabaseLayer } from '@dxos/functions-runtime/testing';
|
|
24
26
|
import { ObjectId } from '@dxos/keys';
|
|
25
27
|
import { Message, Organization, Person } from '@dxos/types';
|
|
@@ -60,13 +62,13 @@ describe('AssistantToolkit', () => {
|
|
|
60
62
|
'can add to context',
|
|
61
63
|
Effect.fnUntraced(
|
|
62
64
|
function* (_) {
|
|
63
|
-
const { db } = yield*
|
|
65
|
+
const { db } = yield* Database.Service;
|
|
64
66
|
const queue = yield* QueueService.createQueue<Message.Message | ContextBinding>();
|
|
65
67
|
const conversation = yield* acquireReleaseResource(() => new AiConversation(queue));
|
|
66
68
|
const observer = GenerationObserver.fromPrinter(new ConsolePrinter());
|
|
67
69
|
yield* Effect.promise(() => conversation.context.bind({ blueprints: [Ref.make(db.add(blueprint))] }));
|
|
68
70
|
|
|
69
|
-
const organization = yield*
|
|
71
|
+
const organization = yield* Database.Service.add(
|
|
70
72
|
Obj.make(Organization.Organization, {
|
|
71
73
|
name: 'Cyberdyne Systems',
|
|
72
74
|
website: 'https://cyberdyne.com',
|
|
@@ -10,7 +10,7 @@ import * as Schema from 'effect/Schema';
|
|
|
10
10
|
|
|
11
11
|
import { AiContextService, ArtifactId } from '@dxos/assistant';
|
|
12
12
|
import { Ref } from '@dxos/echo';
|
|
13
|
-
import {
|
|
13
|
+
import { Database } from '@dxos/echo';
|
|
14
14
|
import { trim } from '@dxos/util';
|
|
15
15
|
|
|
16
16
|
export const AssistantToolkit = Toolkit.make(
|
|
@@ -25,7 +25,7 @@ export const AssistantToolkit = Toolkit.make(
|
|
|
25
25
|
},
|
|
26
26
|
success: Schema.Void,
|
|
27
27
|
failure: Schema.Never,
|
|
28
|
-
dependencies: [AiContextService,
|
|
28
|
+
dependencies: [AiContextService, Database.Service],
|
|
29
29
|
}),
|
|
30
30
|
);
|
|
31
31
|
|
|
@@ -35,7 +35,7 @@ export const layer = () =>
|
|
|
35
35
|
AssistantToolkit.toLayer({
|
|
36
36
|
'add-to-context': Effect.fnUntraced(function* ({ id }) {
|
|
37
37
|
const { binder } = yield* AiContextService;
|
|
38
|
-
const { db } = yield*
|
|
38
|
+
const { db } = yield* Database.Service;
|
|
39
39
|
const ref = Ref.fromDXN(ArtifactId.toDXN(id, db.spaceId));
|
|
40
40
|
yield* Effect.promise(() =>
|
|
41
41
|
binder.bind({
|
|
@@ -11,7 +11,7 @@ import * as Schema from 'effect/Schema';
|
|
|
11
11
|
|
|
12
12
|
import { ArtifactId } from '@dxos/assistant';
|
|
13
13
|
import { DXN, Obj, Relation, Tag, Type } from '@dxos/echo';
|
|
14
|
-
import {
|
|
14
|
+
import { Database } from '@dxos/echo';
|
|
15
15
|
import { trim } from '@dxos/util';
|
|
16
16
|
|
|
17
17
|
export const SystemToolkit = Toolkit.make(
|
|
@@ -30,7 +30,7 @@ export const SystemToolkit = Toolkit.make(
|
|
|
30
30
|
// TODO(dmaretskyi): Effect returns ({ result, encodedResult })
|
|
31
31
|
success: Schema.Any,
|
|
32
32
|
failure: Schema.Never,
|
|
33
|
-
dependencies: [
|
|
33
|
+
dependencies: [Database.Service],
|
|
34
34
|
}),
|
|
35
35
|
|
|
36
36
|
Tool.make('schema-add', {
|
|
@@ -46,7 +46,7 @@ export const SystemToolkit = Toolkit.make(
|
|
|
46
46
|
},
|
|
47
47
|
success: Schema.Any,
|
|
48
48
|
failure: Schema.Never,
|
|
49
|
-
dependencies: [
|
|
49
|
+
dependencies: [Database.Service],
|
|
50
50
|
}),
|
|
51
51
|
|
|
52
52
|
//
|
|
@@ -64,7 +64,7 @@ export const SystemToolkit = Toolkit.make(
|
|
|
64
64
|
},
|
|
65
65
|
success: Schema.Any,
|
|
66
66
|
failure: Schema.Never,
|
|
67
|
-
dependencies: [
|
|
67
|
+
dependencies: [Database.Service],
|
|
68
68
|
}),
|
|
69
69
|
|
|
70
70
|
Tool.make('object-remove', {
|
|
@@ -78,7 +78,7 @@ export const SystemToolkit = Toolkit.make(
|
|
|
78
78
|
},
|
|
79
79
|
success: Schema.Any,
|
|
80
80
|
failure: Schema.Never,
|
|
81
|
-
dependencies: [
|
|
81
|
+
dependencies: [Database.Service],
|
|
82
82
|
}),
|
|
83
83
|
|
|
84
84
|
//
|
|
@@ -104,7 +104,7 @@ export const SystemToolkit = Toolkit.make(
|
|
|
104
104
|
},
|
|
105
105
|
success: Schema.Any,
|
|
106
106
|
failure: Schema.Never,
|
|
107
|
-
dependencies: [
|
|
107
|
+
dependencies: [Database.Service],
|
|
108
108
|
}),
|
|
109
109
|
|
|
110
110
|
//
|
|
@@ -126,7 +126,7 @@ export const SystemToolkit = Toolkit.make(
|
|
|
126
126
|
},
|
|
127
127
|
success: Schema.Any,
|
|
128
128
|
failure: Schema.Never,
|
|
129
|
-
dependencies: [
|
|
129
|
+
dependencies: [Database.Service],
|
|
130
130
|
}),
|
|
131
131
|
|
|
132
132
|
Tool.make('tag-remove', {
|
|
@@ -144,7 +144,7 @@ export const SystemToolkit = Toolkit.make(
|
|
|
144
144
|
},
|
|
145
145
|
success: Schema.Any,
|
|
146
146
|
failure: Schema.Never,
|
|
147
|
-
dependencies: [
|
|
147
|
+
dependencies: [Database.Service],
|
|
148
148
|
}),
|
|
149
149
|
);
|
|
150
150
|
|
|
@@ -153,7 +153,7 @@ export const tools = Record.keys(SystemToolkit.tools);
|
|
|
153
153
|
export const layer = (): Layer.Layer<Tool.Handler<any>, never, never> =>
|
|
154
154
|
SystemToolkit.toLayer({
|
|
155
155
|
'schema-list': Effect.fnUntraced(function* () {
|
|
156
|
-
const { db } = yield*
|
|
156
|
+
const { db } = yield* Database.Service;
|
|
157
157
|
const schema = yield* Effect.promise(() => db.schemaRegistry.query({ location: ['database', 'runtime'] }).run());
|
|
158
158
|
|
|
159
159
|
return schema.map((schema) => {
|
|
@@ -167,7 +167,7 @@ export const layer = (): Layer.Layer<Tool.Handler<any>, never, never> =>
|
|
|
167
167
|
}),
|
|
168
168
|
|
|
169
169
|
'schema-add': Effect.fnUntraced(function* ({ name, typename, jsonSchema }) {
|
|
170
|
-
const { db } = yield*
|
|
170
|
+
const { db } = yield* Database.Service;
|
|
171
171
|
|
|
172
172
|
yield* Effect.promise(() =>
|
|
173
173
|
db.schemaRegistry.register([
|
|
@@ -182,7 +182,7 @@ export const layer = (): Layer.Layer<Tool.Handler<any>, never, never> =>
|
|
|
182
182
|
}),
|
|
183
183
|
|
|
184
184
|
'object-create': Effect.fnUntraced(function* ({ typename, data }) {
|
|
185
|
-
const { db } = yield*
|
|
185
|
+
const { db } = yield* Database.Service;
|
|
186
186
|
const schema = yield* Effect.promise(() =>
|
|
187
187
|
db.schemaRegistry.query({ typename, location: ['database', 'runtime'] }).first(),
|
|
188
188
|
);
|
|
@@ -193,20 +193,20 @@ export const layer = (): Layer.Layer<Tool.Handler<any>, never, never> =>
|
|
|
193
193
|
}),
|
|
194
194
|
|
|
195
195
|
'object-remove': Effect.fnUntraced(function* ({ id }) {
|
|
196
|
-
const { db } = yield*
|
|
197
|
-
const object = yield*
|
|
196
|
+
const { db } = yield* Database.Service;
|
|
197
|
+
const object = yield* Database.Service.resolve(DXN.parse(id));
|
|
198
198
|
db.remove(object);
|
|
199
199
|
return object;
|
|
200
200
|
}),
|
|
201
201
|
|
|
202
202
|
'relation-create': Effect.fnUntraced(function* ({ typename, source, target, data }) {
|
|
203
|
-
const { db } = yield*
|
|
203
|
+
const { db } = yield* Database.Service;
|
|
204
204
|
const schema = yield* Effect.promise(() =>
|
|
205
205
|
db.schemaRegistry.query({ typename, location: ['database', 'runtime'] }).first(),
|
|
206
206
|
);
|
|
207
207
|
|
|
208
|
-
const sourceObj = yield*
|
|
209
|
-
const targetObj = yield*
|
|
208
|
+
const sourceObj = yield* Database.Service.resolve(DXN.parse(source));
|
|
209
|
+
const targetObj = yield* Database.Service.resolve(DXN.parse(target));
|
|
210
210
|
const relation = db.add(
|
|
211
211
|
Relation.make(schema, {
|
|
212
212
|
[Relation.Source]: sourceObj,
|
|
@@ -218,13 +218,13 @@ export const layer = (): Layer.Layer<Tool.Handler<any>, never, never> =>
|
|
|
218
218
|
}),
|
|
219
219
|
|
|
220
220
|
'tag-add': Effect.fnUntraced(function* ({ tagId, objectId }) {
|
|
221
|
-
const object = yield*
|
|
221
|
+
const object = yield* Database.Service.resolve(DXN.parse(objectId));
|
|
222
222
|
Obj.addTag(object, DXN.parse(tagId).toString());
|
|
223
223
|
return object;
|
|
224
224
|
}),
|
|
225
225
|
|
|
226
226
|
'tag-remove': Effect.fnUntraced(function* ({ tagId, objectId }) {
|
|
227
|
-
const object = yield*
|
|
227
|
+
const object = yield* Database.Service.resolve(DXN.parse(objectId));
|
|
228
228
|
Obj.removeTag(object, DXN.parse(tagId).toString());
|
|
229
229
|
return object;
|
|
230
230
|
}),
|