@dxos/assistant-toolkit 0.8.4-main.72ec0f3 → 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 +388 -285
- 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 +388 -285
- 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 +10 -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 +10 -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 +100 -99
- package/dist/types/src/functions/entity-extraction/entity-extraction.d.ts.map +1 -1
- package/dist/types/src/functions/entity-extraction/index.d.ts +100 -99
- 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 +9 -8
- 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/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 +32 -40
- 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 +46 -28
- 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 +13 -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/research/types.ts +1 -1
- 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} +15 -15
- 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
package/src/crud/graph.ts
CHANGED
|
@@ -11,28 +11,23 @@ import * as Option from 'effect/Option';
|
|
|
11
11
|
import * as Schema from 'effect/Schema';
|
|
12
12
|
import * as SchemaAST from 'effect/SchemaAST';
|
|
13
13
|
|
|
14
|
-
import { Obj,
|
|
15
|
-
import {
|
|
14
|
+
import { Entity, Filter, Obj, Query, Type } from '@dxos/echo';
|
|
15
|
+
import { Database } from '@dxos/echo';
|
|
16
16
|
import {
|
|
17
|
-
EntityKind,
|
|
18
|
-
ObjectId,
|
|
19
17
|
ReferenceAnnotationId,
|
|
20
18
|
RelationSourceDXNId,
|
|
21
19
|
RelationSourceId,
|
|
22
20
|
RelationTargetDXNId,
|
|
23
21
|
RelationTargetId,
|
|
24
|
-
|
|
25
|
-
getEntityKind,
|
|
26
|
-
getSchemaDXN,
|
|
27
|
-
getSchemaTypename,
|
|
22
|
+
createObject,
|
|
28
23
|
getTypeAnnotation,
|
|
29
24
|
getTypeIdentifierAnnotation,
|
|
30
25
|
} from '@dxos/echo/internal';
|
|
31
|
-
import { type
|
|
26
|
+
import { type Queue } from '@dxos/echo-db';
|
|
32
27
|
import { isEncodedReference } from '@dxos/echo-protocol';
|
|
33
28
|
import { mapAst } from '@dxos/effect';
|
|
34
|
-
import { ContextQueueService
|
|
35
|
-
import { DXN } from '@dxos/keys';
|
|
29
|
+
import { ContextQueueService } from '@dxos/functions';
|
|
30
|
+
import { DXN, ObjectId } from '@dxos/keys';
|
|
36
31
|
import { log } from '@dxos/log';
|
|
37
32
|
import { deepMapValues, isNonNullable, trim } from '@dxos/util';
|
|
38
33
|
|
|
@@ -45,7 +40,7 @@ export const Subgraph = Schema.Struct({
|
|
|
45
40
|
export interface Subgraph extends Schema.Schema.Type<typeof Subgraph> {}
|
|
46
41
|
|
|
47
42
|
export type RelatedSchema = {
|
|
48
|
-
schema:
|
|
43
|
+
schema: Type.Entity.Any;
|
|
49
44
|
kind: 'reference' | 'relation';
|
|
50
45
|
};
|
|
51
46
|
|
|
@@ -56,17 +51,14 @@ export type RelatedSchema = {
|
|
|
56
51
|
* @param schema
|
|
57
52
|
* @returns
|
|
58
53
|
*/
|
|
59
|
-
export const findRelatedSchema = async (
|
|
60
|
-
db: EchoDatabase,
|
|
61
|
-
anchor: Schema.Schema.AnyNoContext,
|
|
62
|
-
): Promise<RelatedSchema[]> => {
|
|
54
|
+
export const findRelatedSchema = async (db: Database.Database, anchor: Type.Entity.Any): Promise<RelatedSchema[]> => {
|
|
63
55
|
// TODO(dmaretskyi): Query stored schemas.
|
|
64
|
-
const allSchemas =
|
|
56
|
+
const allSchemas = await db.graph.schemaRegistry.query().run();
|
|
65
57
|
|
|
66
58
|
// TODO(dmaretskyi): Also do references.
|
|
67
59
|
return allSchemas
|
|
68
60
|
.filter((schema) => {
|
|
69
|
-
if (getTypeAnnotation(schema)?.kind !==
|
|
61
|
+
if (getTypeAnnotation(schema)?.kind !== Entity.Kind.Relation) {
|
|
70
62
|
return false;
|
|
71
63
|
}
|
|
72
64
|
|
|
@@ -77,8 +69,8 @@ export const findRelatedSchema = async (
|
|
|
77
69
|
})
|
|
78
70
|
.map(
|
|
79
71
|
(schema): RelatedSchema => ({
|
|
80
|
-
schema,
|
|
81
72
|
kind: 'relation',
|
|
73
|
+
schema,
|
|
82
74
|
}),
|
|
83
75
|
);
|
|
84
76
|
};
|
|
@@ -87,14 +79,14 @@ export const findRelatedSchema = async (
|
|
|
87
79
|
* Non-strict DXN comparison.
|
|
88
80
|
* Returns true if the DXN could be resolved to the schema.
|
|
89
81
|
*/
|
|
90
|
-
const isSchemaAddressableByDxn = (schema:
|
|
82
|
+
const isSchemaAddressableByDxn = (schema: Type.Entity.Any, dxn: DXN): boolean => {
|
|
91
83
|
if (getTypeIdentifierAnnotation(schema) === dxn.toString()) {
|
|
92
84
|
return true;
|
|
93
85
|
}
|
|
94
86
|
|
|
95
87
|
const t = dxn.asTypeDXN();
|
|
96
88
|
if (t) {
|
|
97
|
-
return t.type ===
|
|
89
|
+
return t.type === Type.getTypename(schema);
|
|
98
90
|
}
|
|
99
91
|
|
|
100
92
|
return false;
|
|
@@ -114,13 +106,13 @@ export const LocalSearchToolkit = Toolkit.make(
|
|
|
114
106
|
},
|
|
115
107
|
success: Schema.Unknown,
|
|
116
108
|
failure: Schema.Never,
|
|
117
|
-
dependencies: [
|
|
109
|
+
dependencies: [Database.Service],
|
|
118
110
|
}),
|
|
119
111
|
);
|
|
120
112
|
|
|
121
113
|
export const LocalSearchHandler = LocalSearchToolkit.toLayer({
|
|
122
114
|
search_local_search: Effect.fn(function* ({ query }) {
|
|
123
|
-
const
|
|
115
|
+
const objects = yield* Database.Service.runQuery(Query.select(Filter.text(query, { type: 'vector' })));
|
|
124
116
|
const results = [...objects];
|
|
125
117
|
|
|
126
118
|
const option = yield* Effect.serviceOption(ContextQueueService);
|
|
@@ -144,21 +136,21 @@ export const LocalSearchHandler = LocalSearchToolkit.toLayer({
|
|
|
144
136
|
class GraphWriterSchema extends Context.Tag('@dxos/assistant/GraphWriterSchema')<
|
|
145
137
|
GraphWriterSchema,
|
|
146
138
|
{
|
|
147
|
-
schema:
|
|
139
|
+
schema: Type.Entity.Any[];
|
|
148
140
|
}
|
|
149
141
|
>() {}
|
|
150
142
|
|
|
151
143
|
/**
|
|
152
144
|
* Forms typed objects that can be written to the graph database.
|
|
153
145
|
*/
|
|
154
|
-
export const makeGraphWriterToolkit = ({ schema }: { schema:
|
|
146
|
+
export const makeGraphWriterToolkit = ({ schema }: { schema: Type.Entity.Any[] }) => {
|
|
155
147
|
return Toolkit.make(
|
|
156
148
|
Tool.make('graph_writer', {
|
|
157
149
|
description: 'Write to the local graph database',
|
|
158
150
|
parameters: createExtractionSchema(schema).fields,
|
|
159
151
|
success: Schema.Unknown,
|
|
160
152
|
failure: Schema.Never,
|
|
161
|
-
dependencies: [
|
|
153
|
+
dependencies: [Database.Service, ContextQueueService],
|
|
162
154
|
}).annotateContext(Context.make(GraphWriterSchema, { schema })),
|
|
163
155
|
);
|
|
164
156
|
};
|
|
@@ -178,10 +170,10 @@ export const makeGraphWriterHandler = (
|
|
|
178
170
|
|
|
179
171
|
return toolkit.toLayer({
|
|
180
172
|
graph_writer: Effect.fn(function* (input) {
|
|
181
|
-
const { db } = yield*
|
|
173
|
+
const { db } = yield* Database.Service;
|
|
182
174
|
const { queue } = yield* ContextQueueService;
|
|
183
175
|
const data = yield* Effect.promise(() => sanitizeObjects(schema, input as any, db, queue));
|
|
184
|
-
yield* Effect.promise(() => queue.append(data as Obj.
|
|
176
|
+
yield* Effect.promise(() => queue.append(data as Obj.Unknown[]));
|
|
185
177
|
|
|
186
178
|
const dxns = data.map((obj) => Obj.getDXN(obj));
|
|
187
179
|
onAppend?.(dxns);
|
|
@@ -193,31 +185,31 @@ export const makeGraphWriterHandler = (
|
|
|
193
185
|
/**
|
|
194
186
|
* Create a schema for structured data extraction.
|
|
195
187
|
*/
|
|
196
|
-
export const createExtractionSchema = (types:
|
|
188
|
+
export const createExtractionSchema = (types: Type.Entity.Any[]) => {
|
|
197
189
|
return Schema.Struct({
|
|
198
190
|
...Object.fromEntries(
|
|
199
191
|
types.map(preprocessSchema).map((schema, index) => [
|
|
200
192
|
`objects_${getSanitizedSchemaName(types[index])}`,
|
|
201
193
|
Schema.optional(Schema.Array(schema)).annotations({
|
|
202
|
-
description: `The objects of type: ${
|
|
194
|
+
description: `The objects of type: ${Type.getDXN(types[index])?.asTypeDXN()!.type}. ${SchemaAST.getDescriptionAnnotation(types[index].ast).pipe(Option.getOrElse(() => ''))}`,
|
|
203
195
|
}),
|
|
204
196
|
]),
|
|
205
197
|
),
|
|
206
198
|
});
|
|
207
199
|
};
|
|
208
200
|
|
|
209
|
-
export const getSanitizedSchemaName = (schema:
|
|
210
|
-
return
|
|
201
|
+
export const getSanitizedSchemaName = (schema: Type.Entity.Any) => {
|
|
202
|
+
return Type.getDXN(schema)!
|
|
211
203
|
.asTypeDXN()!
|
|
212
204
|
.type.replaceAll(/[^a-zA-Z0-9]+/g, '_');
|
|
213
205
|
};
|
|
214
206
|
|
|
215
207
|
export const sanitizeObjects = async (
|
|
216
|
-
types:
|
|
208
|
+
types: Type.Entity.Any[],
|
|
217
209
|
data: Record<string, readonly unknown[]>,
|
|
218
|
-
db:
|
|
210
|
+
db: Database.Database,
|
|
219
211
|
queue?: Queue,
|
|
220
|
-
): Promise<Obj.
|
|
212
|
+
): Promise<Obj.Unknown[]> => {
|
|
221
213
|
const entries = types
|
|
222
214
|
.map(
|
|
223
215
|
(type) =>
|
|
@@ -230,7 +222,7 @@ export const sanitizeObjects = async (
|
|
|
230
222
|
|
|
231
223
|
const idMap = new Map<string, string>();
|
|
232
224
|
const existingIds = new Set<ObjectId>();
|
|
233
|
-
const enitties = new Map<ObjectId,
|
|
225
|
+
const enitties = new Map<ObjectId, Entity.Unknown>();
|
|
234
226
|
|
|
235
227
|
const resolveId = (id: string): DXN | undefined => {
|
|
236
228
|
if (ObjectId.isValid(id)) {
|
|
@@ -275,7 +267,7 @@ export const sanitizeObjects = async (
|
|
|
275
267
|
return recurse(value);
|
|
276
268
|
});
|
|
277
269
|
|
|
278
|
-
if (
|
|
270
|
+
if (Entity.getKind(entry.schema) === 'relation') {
|
|
279
271
|
const sourceDxn = resolveId(data.source);
|
|
280
272
|
if (!sourceDxn) {
|
|
281
273
|
log.warn('source not found', { source: data.source });
|
|
@@ -298,7 +290,7 @@ export const sanitizeObjects = async (
|
|
|
298
290
|
.filter((object) => !existingIds.has(object.data.id)); // TODO(dmaretskyi): This dissallows updating existing objects.
|
|
299
291
|
|
|
300
292
|
// TODO(dmaretskyi): Use ref resolver.
|
|
301
|
-
const
|
|
293
|
+
const dbObjects = await db.query(Query.select(Filter.id(...existingIds))).run();
|
|
302
294
|
const queueObjects = (await queue?.getObjectsById([...existingIds])) ?? [];
|
|
303
295
|
const objects = [...dbObjects, ...queueObjects].filter(isNonNullable);
|
|
304
296
|
|
|
@@ -332,7 +324,7 @@ export const sanitizeObjects = async (
|
|
|
332
324
|
}
|
|
333
325
|
}
|
|
334
326
|
if (!skip) {
|
|
335
|
-
const obj =
|
|
327
|
+
const obj = createObject(schema, data);
|
|
336
328
|
enitties.set(obj.id, obj);
|
|
337
329
|
return [obj];
|
|
338
330
|
}
|
|
@@ -347,7 +339,7 @@ const SoftRef = Schema.Struct({
|
|
|
347
339
|
});
|
|
348
340
|
|
|
349
341
|
const preprocessSchema = (schema: Schema.Schema.AnyNoContext) => {
|
|
350
|
-
const isRelationSchema =
|
|
342
|
+
const isRelationSchema = Entity.getKind(schema) === 'relation';
|
|
351
343
|
|
|
352
344
|
const go = (ast: SchemaAST.AST, visited = new Set<SchemaAST.AST>()): SchemaAST.AST => {
|
|
353
345
|
if (visited.has(ast)) {
|
|
@@ -13,7 +13,7 @@ import * as Redacted from 'effect/Redacted';
|
|
|
13
13
|
import { AiService } from '@dxos/ai';
|
|
14
14
|
import { AiServiceTestingPreset, EXA_API_KEY } from '@dxos/ai/testing';
|
|
15
15
|
import { makeToolExecutionServiceFromFunctions, makeToolResolverFromFunctions } from '@dxos/assistant';
|
|
16
|
-
import { TestHelpers } from '@dxos/effect';
|
|
16
|
+
import { TestHelpers } from '@dxos/effect/testing';
|
|
17
17
|
import { CredentialsService, FunctionInvocationService } from '@dxos/functions';
|
|
18
18
|
import { TracingServiceExt } from '@dxos/functions-runtime';
|
|
19
19
|
import {
|
|
@@ -13,7 +13,8 @@ import { AiService, ConsolePrinter, ModelName } from '@dxos/ai';
|
|
|
13
13
|
import { AiSession, GenerationObserver, createToolkit } from '@dxos/assistant';
|
|
14
14
|
import { Prompt, Template } from '@dxos/blueprints';
|
|
15
15
|
import { Obj, Ref, Type } from '@dxos/echo';
|
|
16
|
-
import {
|
|
16
|
+
import { Database } from '@dxos/echo';
|
|
17
|
+
import { TracingService, defineFunction } from '@dxos/functions';
|
|
17
18
|
import { log } from '@dxos/log';
|
|
18
19
|
|
|
19
20
|
const DEFAULT_MODEL: ModelName = '@anthropic/claude-opus-4-0';
|
|
@@ -45,7 +46,7 @@ export default defineFunction({
|
|
|
45
46
|
// for (const key of Object.keys(data.input)) {
|
|
46
47
|
// const value = data.input[key];
|
|
47
48
|
// if (Ref.isRef(value)) {
|
|
48
|
-
// const object = yield*
|
|
49
|
+
// const object = yield* Database.Service.load(value);
|
|
49
50
|
// input[key] = Obj.toJSON(object);
|
|
50
51
|
// } else {
|
|
51
52
|
// input[key] = JSON.stringify(value);
|
|
@@ -55,16 +56,16 @@ export default defineFunction({
|
|
|
55
56
|
Match.when(
|
|
56
57
|
(value: any) => Ref.isRef(value),
|
|
57
58
|
Effect.fnUntraced(function* (ref) {
|
|
58
|
-
const object = yield*
|
|
59
|
-
return Obj.toJSON(object as Obj.
|
|
59
|
+
const object = yield* Database.Service.load(ref);
|
|
60
|
+
return Obj.toJSON(object as Obj.Unknown);
|
|
60
61
|
}),
|
|
61
62
|
),
|
|
62
63
|
Match.orElse(() => Effect.succeed(data.input)),
|
|
63
64
|
);
|
|
64
65
|
|
|
65
|
-
yield*
|
|
66
|
-
const prompt = yield*
|
|
67
|
-
const systemPrompt = data.systemPrompt ? yield*
|
|
66
|
+
yield* Database.Service.flush({ indexes: true });
|
|
67
|
+
const prompt = yield* Database.Service.load(data.prompt);
|
|
68
|
+
const systemPrompt = data.systemPrompt ? yield* Database.Service.load(data.systemPrompt) : undefined;
|
|
68
69
|
yield* TracingService.emitStatus({ message: `Running ${prompt.id}` });
|
|
69
70
|
|
|
70
71
|
log.info('starting agent', { prompt: prompt.id, input });
|
|
@@ -72,23 +73,26 @@ export default defineFunction({
|
|
|
72
73
|
const blueprints = yield* Function.pipe(
|
|
73
74
|
prompt.blueprints,
|
|
74
75
|
Array.appendAll(systemPrompt?.blueprints ?? []),
|
|
75
|
-
Effect.forEach(
|
|
76
|
+
Effect.forEach(Database.Service.loadOption),
|
|
76
77
|
Effect.map(Array.filter(Option.isSome)),
|
|
77
78
|
Effect.map(Array.map((option) => option.value)),
|
|
78
79
|
);
|
|
80
|
+
const toolkit = yield* createToolkit({ blueprints });
|
|
81
|
+
|
|
79
82
|
const objects = yield* Function.pipe(
|
|
80
83
|
prompt.context,
|
|
81
84
|
Array.appendAll(systemPrompt?.context ?? []),
|
|
82
|
-
Effect.forEach(
|
|
85
|
+
Effect.forEach(Database.Service.loadOption),
|
|
83
86
|
Effect.map(Array.filter(Option.isSome)),
|
|
84
87
|
Effect.map(Array.map((option) => option.value)),
|
|
85
88
|
);
|
|
86
|
-
const toolkit = yield* createToolkit({ blueprints });
|
|
87
89
|
|
|
88
|
-
const promptInstructions = yield*
|
|
90
|
+
const promptInstructions = yield* Database.Service.load(prompt.instructions.source);
|
|
89
91
|
const promptText = Template.process(promptInstructions.content, input);
|
|
90
92
|
|
|
91
|
-
const systemInstructions = systemPrompt
|
|
93
|
+
const systemInstructions = systemPrompt
|
|
94
|
+
? yield* Database.Service.load(systemPrompt.instructions.source)
|
|
95
|
+
: undefined;
|
|
92
96
|
const systemText = systemInstructions ? Template.process(systemInstructions.content, {}) : undefined;
|
|
93
97
|
|
|
94
98
|
const session = new AiSession();
|
|
@@ -97,7 +101,7 @@ export default defineFunction({
|
|
|
97
101
|
prompt: promptText,
|
|
98
102
|
system: systemText,
|
|
99
103
|
blueprints,
|
|
100
|
-
objects: objects as Obj.
|
|
104
|
+
objects: objects as Obj.Unknown[],
|
|
101
105
|
toolkit,
|
|
102
106
|
observer: GenerationObserver.fromPrinter(new ConsolePrinter({ tag: 'agent' })),
|
|
103
107
|
})
|
|
@@ -12,7 +12,7 @@ import * as Layer from 'effect/Layer';
|
|
|
12
12
|
import { AiService } from '@dxos/ai';
|
|
13
13
|
import { AiServiceTestingPreset } from '@dxos/ai/testing';
|
|
14
14
|
import { makeToolExecutionServiceFromFunctions, makeToolResolverFromFunctions } from '@dxos/assistant';
|
|
15
|
-
import { TestHelpers } from '@dxos/effect';
|
|
15
|
+
import { TestHelpers } from '@dxos/effect/testing';
|
|
16
16
|
import { CredentialsService, FunctionInvocationService, TracingService } from '@dxos/functions';
|
|
17
17
|
import { FunctionInvocationServiceLayerTestMocked, TestDatabaseLayer } from '@dxos/functions-runtime/testing';
|
|
18
18
|
|
|
@@ -133,7 +133,7 @@ export default defineFunction({
|
|
|
133
133
|
throw new Error('no channels found');
|
|
134
134
|
}
|
|
135
135
|
for (const channel of channels) {
|
|
136
|
-
|
|
136
|
+
log.info('channel', { id: channel.id, name: 'name' in channel ? channel.name : undefined });
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
yield* TracingService.emitStatus({ message: `Will fetch from channels: ${channels.length}` });
|
|
@@ -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,8 +23,8 @@ export default defineFunction({
|
|
|
22
23
|
content: Schema.String,
|
|
23
24
|
}),
|
|
24
25
|
handler: Effect.fn(function* ({ data: { id } }) {
|
|
25
|
-
const doc = yield*
|
|
26
|
-
const { content } = yield*
|
|
26
|
+
const doc = yield* Database.Service.resolve(ArtifactId.toDXN(id), Markdown.Document);
|
|
27
|
+
const { content } = yield* Database.Service.load(doc.content);
|
|
27
28
|
return { content };
|
|
28
29
|
}),
|
|
29
30
|
});
|
|
@@ -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, Obj } 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({
|
|
@@ -23,8 +24,10 @@ export default defineFunction({
|
|
|
23
24
|
}),
|
|
24
25
|
outputSchema: Schema.Void,
|
|
25
26
|
handler: Effect.fn(function* ({ data: { id, content } }) {
|
|
26
|
-
const doc = yield*
|
|
27
|
-
const text = yield*
|
|
28
|
-
text
|
|
27
|
+
const doc = yield* Database.Service.resolve(ArtifactId.toDXN(id), Markdown.Document);
|
|
28
|
+
const text = yield* Database.Service.load(doc.content);
|
|
29
|
+
Obj.change(text, (t) => {
|
|
30
|
+
t.content = content;
|
|
31
|
+
});
|
|
29
32
|
}),
|
|
30
33
|
});
|