@dxos/assistant-toolkit 0.8.4-main.7ace549 → 0.8.4-main.937b3ca
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-J5LGTIGS.mjs +10 -0
- package/dist/lib/browser/chunk-J5LGTIGS.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +366 -264
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +43 -0
- package/dist/lib/browser/testing/index.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +366 -264
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +44 -0
- package/dist/lib/node-esm/testing/index.mjs.map +7 -0
- package/dist/types/src/blueprints/design/design-blueprint.d.ts +17 -3
- package/dist/types/src/blueprints/design/design-blueprint.d.ts.map +1 -1
- package/dist/types/src/blueprints/design/index.d.ts +1 -1
- package/dist/types/src/blueprints/design/index.d.ts.map +1 -1
- package/dist/types/src/blueprints/discord/discord-blueprint.d.ts +9 -10
- package/dist/types/src/blueprints/discord/discord-blueprint.d.ts.map +1 -1
- package/dist/types/src/blueprints/discord/index.d.ts +1 -1
- package/dist/types/src/blueprints/discord/index.d.ts.map +1 -1
- package/dist/types/src/blueprints/linear/index.d.ts +1 -1
- package/dist/types/src/blueprints/linear/index.d.ts.map +1 -1
- package/dist/types/src/blueprints/linear/linear-blueprint.d.ts +9 -10
- package/dist/types/src/blueprints/linear/linear-blueprint.d.ts.map +1 -1
- package/dist/types/src/blueprints/planning/index.d.ts +1 -1
- package/dist/types/src/blueprints/planning/index.d.ts.map +1 -1
- package/dist/types/src/blueprints/planning/planning-blueprint.d.ts +17 -3
- package/dist/types/src/blueprints/planning/planning-blueprint.d.ts.map +1 -1
- package/dist/types/src/blueprints/research/index.d.ts +1 -1
- package/dist/types/src/blueprints/research/index.d.ts.map +1 -1
- package/dist/types/src/blueprints/research/research-blueprint.d.ts +17 -3
- package/dist/types/src/blueprints/research/research-blueprint.d.ts.map +1 -1
- package/dist/types/src/blueprints/testing.d.ts +2 -2
- package/dist/types/src/blueprints/testing.d.ts.map +1 -1
- package/dist/types/src/blueprints/websearch/index.d.ts +1 -1
- package/dist/types/src/blueprints/websearch/index.d.ts.map +1 -1
- package/dist/types/src/blueprints/websearch/websearch-blueprint.d.ts +17 -3
- package/dist/types/src/blueprints/websearch/websearch-blueprint.d.ts.map +1 -1
- package/dist/types/src/crud/graph.d.ts +14 -11
- package/dist/types/src/crud/graph.d.ts.map +1 -1
- package/dist/types/src/functions/agent/prompt.d.ts +71 -4
- 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 +93 -91
- package/dist/types/src/functions/entity-extraction/entity-extraction.d.ts.map +1 -1
- package/dist/types/src/functions/entity-extraction/index.d.ts +93 -91
- package/dist/types/src/functions/entity-extraction/index.d.ts.map +1 -1
- package/dist/types/src/functions/exa/data/exa-search-1748337321991.d.ts.map +1 -0
- package/dist/types/src/functions/exa/data/exa-search-1748337331526.d.ts.map +1 -0
- package/dist/types/src/functions/exa/data/exa-search-1748337344119.d.ts.map +1 -0
- package/dist/types/src/functions/exa/data/index.d.ts.map +1 -0
- package/dist/types/src/functions/github/fetch-prs.d.ts.map +1 -1
- package/dist/types/src/functions/linear/index.d.ts +1 -1
- package/dist/types/src/functions/linear/sync-issues.d.ts +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 +8 -7
- 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/tasks/read.d.ts.map +1 -1
- package/dist/types/src/functions/tasks/update.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +0 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/initiative/Initiative.d.ts +84 -0
- package/dist/types/src/initiative/Initiative.d.ts.map +1 -0
- package/dist/types/src/initiative/InitiativeSchema.d.ts +19 -0
- package/dist/types/src/initiative/InitiativeSchema.d.ts.map +1 -0
- package/dist/types/src/initiative/functions/agent.d.ts +37 -0
- package/dist/types/src/initiative/functions/agent.d.ts.map +1 -0
- package/dist/types/src/initiative/functions/getContext.d.ts +17 -0
- package/dist/types/src/initiative/functions/getContext.d.ts.map +1 -0
- package/dist/types/src/initiative/functions/index.d.ts +4 -0
- package/dist/types/src/initiative/functions/index.d.ts.map +1 -0
- package/dist/types/src/initiative/functions/update.d.ts +7 -0
- package/dist/types/src/initiative/functions/update.d.ts.map +1 -0
- package/dist/types/src/initiative/index.d.ts +1 -0
- package/dist/types/src/initiative/index.d.ts.map +1 -0
- package/dist/types/src/initiative/initiative.test.d.ts +2 -0
- package/dist/types/src/initiative/initiative.test.d.ts.map +1 -0
- package/dist/types/src/sync/sync.d.ts +3 -3
- package/dist/types/src/sync/sync.d.ts.map +1 -1
- package/dist/types/src/testing/index.d.ts +1 -1
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/testing/plugins.d.ts +19 -0
- package/dist/types/src/testing/plugins.d.ts.map +1 -0
- package/dist/types/src/toolkits/AssistantToolkit.d.ts +31 -5
- package/dist/types/src/toolkits/AssistantToolkit.d.ts.map +1 -1
- package/dist/types/src/toolkits/SystemToolkit.d.ts +42 -10
- package/dist/types/src/toolkits/SystemToolkit.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +49 -35
- package/src/blueprints/design/design-blueprint.test.ts +10 -8
- package/src/blueprints/design/design-blueprint.ts +2 -4
- package/src/blueprints/design/index.ts +1 -1
- package/src/blueprints/discord/discord-blueprint.ts +2 -4
- package/src/blueprints/discord/index.ts +1 -1
- package/src/blueprints/linear/index.ts +1 -1
- package/src/blueprints/linear/linear-blueprint.ts +2 -4
- package/src/blueprints/planning/index.ts +1 -1
- package/src/blueprints/planning/planning-blueprint.test.ts +8 -6
- package/src/blueprints/planning/planning-blueprint.ts +2 -4
- package/src/blueprints/research/index.ts +1 -1
- package/src/blueprints/research/research-blueprint.ts +2 -4
- package/src/blueprints/testing.ts +2 -2
- package/src/blueprints/websearch/index.ts +2 -1
- package/src/blueprints/websearch/websearch-blueprint.ts +2 -4
- package/src/crud/graph.test.ts +4 -27
- package/src/crud/graph.ts +21 -23
- package/src/experimental/feed.test.ts +1 -1
- package/src/functions/agent/prompt.ts +17 -13
- package/src/functions/discord/fetch-messages.test.ts +1 -1
- package/src/functions/discord/fetch-messages.ts +1 -1
- package/src/functions/document/read.ts +4 -3
- package/src/functions/document/update.ts +7 -4
- package/src/functions/entity-extraction/entity-extraction.conversations.json +6597 -1
- package/src/functions/entity-extraction/entity-extraction.test.ts +7 -6
- package/src/functions/entity-extraction/entity-extraction.ts +38 -19
- package/src/functions/exa/mock.ts +1 -1
- package/src/functions/github/fetch-prs.ts +3 -2
- package/src/functions/linear/linear.test.ts +11 -10
- package/src/functions/linear/sync-issues.ts +7 -5
- package/src/functions/research/document-create.ts +7 -6
- package/src/functions/research/research-graph.ts +11 -11
- package/src/functions/research/research.conversations.json +1 -1
- package/src/functions/research/research.test.ts +24 -32
- package/src/functions/research/research.ts +8 -9
- package/src/functions/tasks/read.ts +4 -3
- package/src/functions/tasks/update.ts +4 -3
- package/src/index.ts +0 -1
- package/src/initiative/Initiative.ts +99 -0
- package/src/initiative/InitiativeSchema.ts +37 -0
- package/src/initiative/functions/agent.ts +57 -0
- package/src/initiative/functions/getContext.ts +74 -0
- package/src/initiative/functions/index.ts +7 -0
- package/src/initiative/functions/update.ts +63 -0
- package/src/initiative/index.ts +3 -0
- package/src/initiative/initiative.conversations.json +1 -0
- package/src/initiative/initiative.test.ts +485 -0
- package/src/sync/sync.ts +38 -30
- package/src/testing/index.ts +1 -1
- package/src/{plugins.tsx → testing/plugins.tsx} +13 -13
- package/src/toolkits/AssistantToolkit.conversations.json +1 -1
- package/src/toolkits/AssistantToolkit.test.ts +17 -11
- package/src/toolkits/AssistantToolkit.ts +31 -8
- package/src/toolkits/SystemToolkit.ts +100 -32
- package/dist/types/src/plugins.d.ts +0 -19
- package/dist/types/src/plugins.d.ts.map +0 -1
- package/dist/types/src/testing/data/exa-search-1748337321991.d.ts.map +0 -1
- package/dist/types/src/testing/data/exa-search-1748337331526.d.ts.map +0 -1
- package/dist/types/src/testing/data/exa-search-1748337344119.d.ts.map +0 -1
- package/dist/types/src/testing/data/index.d.ts.map +0 -1
- /package/dist/types/src/{testing → functions/exa}/data/exa-search-1748337321991.d.ts +0 -0
- /package/dist/types/src/{testing → functions/exa}/data/exa-search-1748337331526.d.ts +0 -0
- /package/dist/types/src/{testing → functions/exa}/data/exa-search-1748337344119.d.ts +0 -0
- /package/dist/types/src/{testing → functions/exa}/data/index.d.ts +0 -0
- /package/src/{testing → functions/exa}/data/exa-search-1748337321991.ts +0 -0
- /package/src/{testing → functions/exa}/data/exa-search-1748337331526.ts +0 -0
- /package/src/{testing → functions/exa}/data/exa-search-1748337344119.ts +0 -0
- /package/src/{testing → functions/exa}/data/index.ts +0 -0
|
@@ -6,13 +6,14 @@ 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
|
|
10
|
-
import { TestAiService } from '@dxos/ai/testing';
|
|
9
|
+
import { AiService } from '@dxos/ai';
|
|
10
|
+
import { MemoizedAiService, TestAiService } from '@dxos/ai/testing';
|
|
11
11
|
import { makeToolExecutionServiceFromFunctions, makeToolResolverFromFunctions } from '@dxos/assistant';
|
|
12
12
|
import { Blueprint } from '@dxos/blueprints';
|
|
13
13
|
import { Obj } from '@dxos/echo';
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
14
|
+
import { Database } from '@dxos/echo';
|
|
15
|
+
import { TestHelpers } from '@dxos/effect/testing';
|
|
16
|
+
import { CredentialsService, FunctionInvocationService, TracingService } from '@dxos/functions';
|
|
16
17
|
import { FunctionInvocationServiceLayerTest, TestDatabaseLayer } from '@dxos/functions-runtime/testing';
|
|
17
18
|
import { ObjectId } from '@dxos/keys';
|
|
18
19
|
import { Message, Organization, Person } from '@dxos/types';
|
|
@@ -49,7 +50,7 @@ describe('Entity extraction', () => {
|
|
|
49
50
|
'call a function to generate a research report',
|
|
50
51
|
Effect.fnUntraced(
|
|
51
52
|
function* (_) {
|
|
52
|
-
const email = yield*
|
|
53
|
+
const email = yield* Database.Service.add(
|
|
53
54
|
Obj.make(Message.Message, {
|
|
54
55
|
[Obj.Meta]: {
|
|
55
56
|
tags: ['important'],
|
|
@@ -75,7 +76,7 @@ describe('Entity extraction', () => {
|
|
|
75
76
|
],
|
|
76
77
|
}),
|
|
77
78
|
);
|
|
78
|
-
yield*
|
|
79
|
+
yield* Database.Service.flush({ indexes: true });
|
|
79
80
|
const result = yield* FunctionInvocationService.invokeFunction(entityExtraction, {
|
|
80
81
|
source: email,
|
|
81
82
|
});
|
|
@@ -10,8 +10,9 @@ import * as Schema from 'effect/Schema';
|
|
|
10
10
|
|
|
11
11
|
import { AiService } from '@dxos/ai';
|
|
12
12
|
import { AiSession, makeToolExecutionServiceFromFunctions, makeToolResolverFromFunctions } from '@dxos/assistant';
|
|
13
|
-
import { Filter, Obj, Ref } from '@dxos/echo';
|
|
14
|
-
import {
|
|
13
|
+
import { Filter, Obj, Ref, Type } from '@dxos/echo';
|
|
14
|
+
import { Database } from '@dxos/echo';
|
|
15
|
+
import { defineFunction } from '@dxos/functions';
|
|
15
16
|
import { FunctionInvocationServiceLayerTest } from '@dxos/functions-runtime/testing';
|
|
16
17
|
import { type DXN } from '@dxos/keys';
|
|
17
18
|
import { log } from '@dxos/log';
|
|
@@ -26,14 +27,18 @@ export default defineFunction({
|
|
|
26
27
|
name: 'Entity Extraction',
|
|
27
28
|
description: 'Extracts entities from emails and transcripts.',
|
|
28
29
|
inputSchema: Schema.Struct({
|
|
29
|
-
source: Message.Message.annotations({
|
|
30
|
+
source: Message.Message.annotations({
|
|
31
|
+
description: 'Email or transcript to extract entities from.',
|
|
32
|
+
}),
|
|
30
33
|
|
|
31
34
|
// TODO(dmaretskyi): Consider making this an array of blueprints instead.
|
|
32
|
-
instructions: Schema.optional(Schema.String).annotations({
|
|
35
|
+
instructions: Schema.optional(Schema.String).annotations({
|
|
36
|
+
description: 'Instructions extraction process.',
|
|
37
|
+
}),
|
|
33
38
|
}),
|
|
34
39
|
outputSchema: Schema.Struct({
|
|
35
40
|
entities: Schema.optional(
|
|
36
|
-
Schema.Array(Obj
|
|
41
|
+
Schema.Array(Type.Obj).annotations({
|
|
37
42
|
description: 'Extracted entities.',
|
|
38
43
|
}),
|
|
39
44
|
),
|
|
@@ -46,7 +51,9 @@ export default defineFunction({
|
|
|
46
51
|
|
|
47
52
|
if (contact && !contact.organization) {
|
|
48
53
|
const created: DXN[] = [];
|
|
49
|
-
const GraphWriterToolkit = makeGraphWriterToolkit({
|
|
54
|
+
const GraphWriterToolkit = makeGraphWriterToolkit({
|
|
55
|
+
schema: [LegacyOrganization],
|
|
56
|
+
}).pipe();
|
|
50
57
|
const GraphWriterHandler = makeGraphWriterHandler(GraphWriterToolkit, {
|
|
51
58
|
onAppend: (dxns) => created.push(...dxns),
|
|
52
59
|
});
|
|
@@ -67,10 +74,15 @@ export default defineFunction({
|
|
|
67
74
|
if (created.length > 1) {
|
|
68
75
|
throw new Error('Multiple organizations created');
|
|
69
76
|
} else if (created.length === 1) {
|
|
70
|
-
organization = yield*
|
|
71
|
-
Obj.
|
|
72
|
-
|
|
73
|
-
|
|
77
|
+
organization = yield* Database.Service.resolve(created[0], Organization.Organization);
|
|
78
|
+
Obj.change(organization, (org) => {
|
|
79
|
+
const meta = Obj.getMeta(org);
|
|
80
|
+
meta.tags ??= [];
|
|
81
|
+
meta.tags.push(...(tags ?? []));
|
|
82
|
+
});
|
|
83
|
+
Obj.change(contact, (c) => {
|
|
84
|
+
c.organization = Ref.make(organization!);
|
|
85
|
+
});
|
|
74
86
|
}
|
|
75
87
|
}
|
|
76
88
|
|
|
@@ -93,7 +105,7 @@ export default defineFunction({
|
|
|
93
105
|
),
|
|
94
106
|
});
|
|
95
107
|
|
|
96
|
-
const extractContact = Effect.fn('extractContact')(function* (actor: Actor.Actor, tags?: string[]) {
|
|
108
|
+
const extractContact = Effect.fn('extractContact')(function* (actor: Actor.Actor, tags?: readonly string[]) {
|
|
97
109
|
const name = actor.name;
|
|
98
110
|
const email = actor.email;
|
|
99
111
|
if (!email) {
|
|
@@ -101,12 +113,12 @@ const extractContact = Effect.fn('extractContact')(function* (actor: Actor.Actor
|
|
|
101
113
|
return undefined;
|
|
102
114
|
}
|
|
103
115
|
|
|
104
|
-
const
|
|
116
|
+
const existingContacts = yield* Database.Service.runQuery(Filter.type(Person.Person));
|
|
105
117
|
|
|
106
118
|
// Check for existing contact
|
|
107
119
|
// TODO(dmaretskyi): Query filter DSL - https://linear.app/dxos/issue/DX-541/filtercontains-should-work-with-partial-objects
|
|
108
120
|
const existingContact = existingContacts.find((contact) =>
|
|
109
|
-
contact.emails?.some((contactEmail
|
|
121
|
+
contact.emails?.some((contactEmail) => contactEmail.value === email),
|
|
110
122
|
);
|
|
111
123
|
|
|
112
124
|
if (existingContact) {
|
|
@@ -115,13 +127,15 @@ const extractContact = Effect.fn('extractContact')(function* (actor: Actor.Actor
|
|
|
115
127
|
}
|
|
116
128
|
|
|
117
129
|
const newContact = Obj.make(Person.Person, {
|
|
118
|
-
[Obj.Meta]: { tags },
|
|
130
|
+
...(tags ? { [Obj.Meta]: { tags: [...tags] } } : {}),
|
|
119
131
|
emails: [{ value: email }],
|
|
120
132
|
});
|
|
121
|
-
yield*
|
|
133
|
+
yield* Database.Service.add(newContact);
|
|
122
134
|
|
|
123
135
|
if (name) {
|
|
124
|
-
newContact
|
|
136
|
+
Obj.change(newContact, (c) => {
|
|
137
|
+
c.fullName = name;
|
|
138
|
+
});
|
|
125
139
|
}
|
|
126
140
|
|
|
127
141
|
const emailDomain = email.split('@')[1]?.toLowerCase();
|
|
@@ -132,7 +146,7 @@ const extractContact = Effect.fn('extractContact')(function* (actor: Actor.Actor
|
|
|
132
146
|
|
|
133
147
|
log.info('extracted email domain', { emailDomain });
|
|
134
148
|
|
|
135
|
-
const
|
|
149
|
+
const existingOrganisations = yield* Database.Service.runQuery(Filter.type(Organization.Organization));
|
|
136
150
|
const matchingOrg = existingOrganisations.find((org) => {
|
|
137
151
|
if (org.website) {
|
|
138
152
|
try {
|
|
@@ -148,7 +162,10 @@ const extractContact = Effect.fn('extractContact')(function* (actor: Actor.Actor
|
|
|
148
162
|
emailDomain.endsWith(`.${websiteDomain}`)
|
|
149
163
|
);
|
|
150
164
|
} catch (e) {
|
|
151
|
-
log.warn('Error parsing website URL', {
|
|
165
|
+
log.warn('Error parsing website URL', {
|
|
166
|
+
website: org.website,
|
|
167
|
+
error: e,
|
|
168
|
+
});
|
|
152
169
|
return false;
|
|
153
170
|
}
|
|
154
171
|
}
|
|
@@ -157,7 +174,9 @@ const extractContact = Effect.fn('extractContact')(function* (actor: Actor.Actor
|
|
|
157
174
|
|
|
158
175
|
if (matchingOrg) {
|
|
159
176
|
log.info('found matching organization', { organization: matchingOrg });
|
|
160
|
-
newContact
|
|
177
|
+
Obj.change(newContact, (c) => {
|
|
178
|
+
c.organization = Ref.make(matchingOrg);
|
|
179
|
+
});
|
|
161
180
|
}
|
|
162
181
|
|
|
163
182
|
return newContact;
|
|
@@ -7,7 +7,7 @@ import * as Schema from 'effect/Schema';
|
|
|
7
7
|
|
|
8
8
|
import { defineFunction } from '@dxos/functions';
|
|
9
9
|
|
|
10
|
-
import { SEARCH_RESULTS } from '
|
|
10
|
+
import { SEARCH_RESULTS } from './data';
|
|
11
11
|
|
|
12
12
|
export default defineFunction({
|
|
13
13
|
key: 'dxos.org/function/exa-mock',
|
|
@@ -6,7 +6,7 @@ import * as HttpClient from '@effect/platform/HttpClient';
|
|
|
6
6
|
import * as Effect from 'effect/Effect';
|
|
7
7
|
import * as Schema from 'effect/Schema';
|
|
8
8
|
|
|
9
|
-
import { defineFunction, withAuthorization } from '@dxos/functions';
|
|
9
|
+
import { CredentialsService, defineFunction, withAuthorization } from '@dxos/functions';
|
|
10
10
|
|
|
11
11
|
export default defineFunction({
|
|
12
12
|
key: 'dxos.org/function/github/fetch-prs',
|
|
@@ -21,7 +21,8 @@ export default defineFunction({
|
|
|
21
21
|
}),
|
|
22
22
|
}),
|
|
23
23
|
handler: Effect.fnUntraced(function* ({ data }) {
|
|
24
|
-
const
|
|
24
|
+
const credential = yield* CredentialsService.getCredential({ service: 'github.com' });
|
|
25
|
+
const client = yield* HttpClient.HttpClient.pipe(Effect.map(withAuthorization(credential.apiKey!)));
|
|
25
26
|
|
|
26
27
|
const response = yield* client.get(`https://api.github.com/repos/${data.owner}/${data.repo}/pulls`);
|
|
27
28
|
const json: any = yield* response.json;
|
|
@@ -13,8 +13,9 @@ import { AiService } from '@dxos/ai';
|
|
|
13
13
|
import { AiServiceTestingPreset } from '@dxos/ai/testing';
|
|
14
14
|
import { makeToolExecutionServiceFromFunctions, makeToolResolverFromFunctions } from '@dxos/assistant';
|
|
15
15
|
import { Obj, Query } from '@dxos/echo';
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
16
|
+
import { Database } from '@dxos/echo';
|
|
17
|
+
import { TestHelpers } from '@dxos/effect/testing';
|
|
18
|
+
import { CredentialsService, FunctionInvocationService } from '@dxos/functions';
|
|
18
19
|
import { TracingServiceExt } from '@dxos/functions-runtime';
|
|
19
20
|
import {
|
|
20
21
|
FunctionInvocationServiceLayerTestMocked,
|
|
@@ -39,9 +40,9 @@ const TestLayer = Layer.mergeAll(
|
|
|
39
40
|
storagePath: testStoragePath({ name: 'feed-test-13' }),
|
|
40
41
|
}),
|
|
41
42
|
CredentialsService.layerConfig([{ service: 'linear.app', apiKey: Config.redacted('LINEAR_API_KEY') }]),
|
|
42
|
-
FunctionInvocationServiceLayerTestMocked({
|
|
43
|
-
|
|
44
|
-
),
|
|
43
|
+
FunctionInvocationServiceLayerTestMocked({
|
|
44
|
+
functions: [fetchLinearIssues],
|
|
45
|
+
}).pipe(Layer.provideMerge(TracingServiceExt.layerLogInfo())),
|
|
45
46
|
FetchHttpClient.layer,
|
|
46
47
|
),
|
|
47
48
|
),
|
|
@@ -52,29 +53,29 @@ describe('Linear', { timeout: 600_000 }, () => {
|
|
|
52
53
|
'sync',
|
|
53
54
|
Effect.fnUntraced(
|
|
54
55
|
function* (_) {
|
|
55
|
-
yield*
|
|
56
|
+
yield* Database.Service.flush({ indexes: true });
|
|
56
57
|
|
|
57
58
|
yield* FunctionInvocationService.invokeFunction(fetchLinearIssues, {
|
|
58
59
|
team: '1127c63a-6f77-4725-9229-50f6cd47321c',
|
|
59
60
|
});
|
|
60
61
|
|
|
61
|
-
const
|
|
62
|
+
const persons = yield* Database.Service.runQuery(Query.type(Person.Person));
|
|
62
63
|
console.log('people', {
|
|
63
64
|
count: persons.length,
|
|
64
65
|
people: persons.map((_) => `(${_.id}) ${Obj.getLabel(_)} [${Obj.getKeys(_, LINEAR_ID_KEY)[0]?.id}]`),
|
|
65
66
|
});
|
|
66
|
-
const
|
|
67
|
+
const projects = yield* Database.Service.runQuery(Query.type(Project.Project));
|
|
67
68
|
console.log('projects', {
|
|
68
69
|
count: projects.length,
|
|
69
70
|
projects: projects.map((_) => `(${_.id}) ${Obj.getLabel(_)} [${Obj.getKeys(_, LINEAR_ID_KEY)[0]?.id}]`),
|
|
70
71
|
});
|
|
71
|
-
const
|
|
72
|
+
const tasks = yield* Database.Service.runQuery(Query.type(Task.Task));
|
|
72
73
|
console.log('tasks', {
|
|
73
74
|
count: tasks.length,
|
|
74
75
|
tasks: tasks.map((_) => `(${_.id}) ${Obj.getLabel(_)} [${Obj.getKeys(_, LINEAR_ID_KEY)[0]?.id}]`),
|
|
75
76
|
});
|
|
76
77
|
|
|
77
|
-
yield*
|
|
78
|
+
yield* Database.Service.flush({ indexes: true });
|
|
78
79
|
},
|
|
79
80
|
Effect.provide(TestLayer),
|
|
80
81
|
TestHelpers.taggedTest('sync'),
|
|
@@ -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 { CredentialsService, 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 {
|
|
@@ -84,7 +85,8 @@ export default defineFunction({
|
|
|
84
85
|
}),
|
|
85
86
|
}),
|
|
86
87
|
handler: Effect.fnUntraced(function* ({ data }) {
|
|
87
|
-
const
|
|
88
|
+
const credential = yield* CredentialsService.getCredential({ service: 'linear.app' });
|
|
89
|
+
const client = yield* HttpClient.HttpClient.pipe(Effect.map(withAuthorization(credential.apiKey!)));
|
|
88
90
|
|
|
89
91
|
// Get the timestamp that was previosly synced.
|
|
90
92
|
const after = yield* getLatestUpdateTimestamp(data.team, Task.Task);
|
|
@@ -114,8 +116,8 @@ export default defineFunction({
|
|
|
114
116
|
const getLatestUpdateTimestamp: (
|
|
115
117
|
teamId: string,
|
|
116
118
|
dataType: Type.Obj.Any,
|
|
117
|
-
) => Effect.Effect<string, never,
|
|
118
|
-
const
|
|
119
|
+
) => Effect.Effect<string, never, Database.Service> = Effect.fnUntraced(function* (teamId, dataType) {
|
|
120
|
+
const existingTasks = yield* Database.Service.runQuery(
|
|
119
121
|
Query.type(dataType).select(Filter.foreignKeys(dataType, [{ source: LINEAR_TEAM_ID_KEY, id: teamId }])),
|
|
120
122
|
);
|
|
121
123
|
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.Unknown;
|
|
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,9 +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';
|
|
10
11
|
import { SystemTypeAnnotation } from '@dxos/echo/internal';
|
|
11
12
|
import { Queue } from '@dxos/echo-db';
|
|
12
|
-
import { ContextQueueService,
|
|
13
|
+
import { ContextQueueService, QueueService } from '@dxos/functions';
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Container for a set of ephemeral research results.
|
|
@@ -17,7 +18,7 @@ import { ContextQueueService, DatabaseService, QueueService } from '@dxos/functi
|
|
|
17
18
|
export const ResearchGraph = Schema.Struct({
|
|
18
19
|
queue: Type.Ref(Queue),
|
|
19
20
|
}).pipe(
|
|
20
|
-
Type.
|
|
21
|
+
Type.object({
|
|
21
22
|
typename: 'dxos.org/type/ResearchGraph',
|
|
22
23
|
version: '0.1.0',
|
|
23
24
|
}),
|
|
@@ -26,24 +27,23 @@ export const ResearchGraph = Schema.Struct({
|
|
|
26
27
|
|
|
27
28
|
export interface ResearchGraph extends Schema.Schema.Type<typeof ResearchGraph> {}
|
|
28
29
|
|
|
29
|
-
export const queryResearchGraph: () => Effect.Effect<ResearchGraph | undefined, never,
|
|
30
|
+
export const queryResearchGraph: () => Effect.Effect<ResearchGraph | undefined, never, Database.Service> = Effect.fn(
|
|
30
31
|
'queryResearchGraph',
|
|
31
32
|
)(function* () {
|
|
32
|
-
const
|
|
33
|
+
const objects = yield* Database.Service.runQuery(Query.type(ResearchGraph));
|
|
33
34
|
return objects.at(0);
|
|
34
35
|
});
|
|
35
36
|
|
|
36
|
-
export const createResearchGraph: () => Effect.Effect<ResearchGraph, never,
|
|
37
|
-
'createResearchGraph'
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
});
|
|
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
|
+
});
|
|
42
42
|
|
|
43
43
|
export const contextQueueLayerFromResearchGraph = Layer.unwrapEffect(
|
|
44
44
|
Effect.gen(function* () {
|
|
45
45
|
const researchGraph = (yield* queryResearchGraph()) ?? (yield* createResearchGraph());
|
|
46
|
-
const researchQueue = yield*
|
|
46
|
+
const researchQueue = yield* Database.Service.load(researchGraph.queue);
|
|
47
47
|
return ContextQueueService.layer(researchQueue);
|
|
48
48
|
}),
|
|
49
49
|
);
|