@dxos/assistant 0.8.4-main.a4bbb77 → 0.8.4-main.ae835ea
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-ILL2CN3G.mjs → chunk-4VIJTKPM.mjs} +128 -148
- package/dist/lib/browser/chunk-4VIJTKPM.mjs.map +7 -0
- package/dist/lib/browser/extraction/index.mjs +7 -7
- package/dist/lib/browser/extraction/index.mjs.map +2 -2
- package/dist/lib/browser/index.mjs +157 -118
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/{chunk-GVKA7VL3.mjs → chunk-AUUC7II4.mjs} +128 -148
- package/dist/lib/node-esm/chunk-AUUC7II4.mjs.map +7 -0
- package/dist/lib/node-esm/extraction/index.mjs +7 -7
- package/dist/lib/node-esm/extraction/index.mjs.map +2 -2
- package/dist/lib/node-esm/index.mjs +157 -118
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/conversation/context.d.ts +14 -7
- package/dist/types/src/conversation/context.d.ts.map +1 -1
- package/dist/types/src/conversation/conversation.d.ts +7 -7
- package/dist/types/src/conversation/conversation.d.ts.map +1 -1
- package/dist/types/src/diff.d.ts.map +1 -1
- package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts +13 -9
- package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts.map +1 -1
- package/dist/types/src/extraction/extraction.d.ts +14 -8
- package/dist/types/src/extraction/extraction.d.ts.map +1 -1
- package/dist/types/src/extraction/quotes.d.ts +1 -1
- package/dist/types/src/extraction/quotes.d.ts.map +1 -1
- package/dist/types/src/functions/services.d.ts +3 -2
- package/dist/types/src/functions/services.d.ts.map +1 -1
- package/dist/types/src/session/artifact-diff.d.ts +2 -2
- package/dist/types/src/session/artifact-diff.d.ts.map +1 -1
- package/dist/types/src/session/error-handling.d.ts +2 -2
- package/dist/types/src/session/error-handling.d.ts.map +1 -1
- package/dist/types/src/session/format.d.ts +7 -5
- package/dist/types/src/session/format.d.ts.map +1 -1
- package/dist/types/src/session/observer.d.ts +1 -1
- package/dist/types/src/session/observer.d.ts.map +1 -1
- package/dist/types/src/session/session.d.ts +6 -2
- package/dist/types/src/session/session.d.ts.map +1 -1
- package/dist/types/src/session/toolkit.d.ts +3 -2
- package/dist/types/src/session/toolkit.d.ts.map +1 -1
- package/dist/types/src/session/version-pin.d.ts +2 -2
- package/dist/types/src/session/version-pin.d.ts.map +1 -1
- package/dist/types/src/{types.d.ts → types/artifact.d.ts} +3 -3
- package/dist/types/src/types/artifact.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +2 -0
- package/dist/types/src/types/index.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +21 -27
- package/src/conversation/context.ts +49 -17
- package/src/conversation/conversation.ts +18 -9
- package/src/diff.ts +5 -0
- package/src/execution-graph.test.ts +1 -1
- package/src/extraction/extraction-llm-function/extraction-llm-function.ts +1 -1
- package/src/extraction/extraction-ner-function/extraction-ner-function.ts +1 -1
- package/src/extraction/extraction.ts +2 -2
- package/src/extraction/quotes.ts +2 -2
- package/src/functions/services.ts +9 -4
- package/src/session/artifact-diff.ts +2 -2
- package/src/session/error-handling.ts +4 -3
- package/src/session/format.test.ts +1 -1
- package/src/session/format.ts +8 -5
- package/src/session/observer.ts +2 -1
- package/src/session/session.test.ts +7 -4
- package/src/session/session.ts +9 -2
- package/src/session/toolkit.ts +4 -2
- package/src/session/version-pin.ts +2 -2
- package/src/summarization/summarization.test.ts +4 -3
- package/src/{types.ts → types/artifact.ts} +2 -2
- package/src/types/index.ts +5 -0
- package/dist/lib/browser/chunk-ILL2CN3G.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-GVKA7VL3.mjs.map +0 -7
- package/dist/types/src/types.d.ts.map +0 -1
|
@@ -6,28 +6,20 @@ import {
|
|
|
6
6
|
GenerationObserver,
|
|
7
7
|
VersionPin,
|
|
8
8
|
createToolkit
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-4VIJTKPM.mjs";
|
|
10
10
|
|
|
11
11
|
// src/conversation/context.ts
|
|
12
12
|
import { computed } from "@preact/signals-core";
|
|
13
|
-
import
|
|
14
|
-
import
|
|
13
|
+
import * as Array2 from "effect/Array";
|
|
14
|
+
import * as Context from "effect/Context";
|
|
15
|
+
import * as Function from "effect/Function";
|
|
16
|
+
import * as Schema from "effect/Schema";
|
|
15
17
|
import { Blueprint } from "@dxos/blueprints";
|
|
16
|
-
import {
|
|
18
|
+
import { Resource } from "@dxos/context";
|
|
19
|
+
import { DXN, Filter, Obj, Query, Type } from "@dxos/echo";
|
|
20
|
+
import { invariant } from "@dxos/invariant";
|
|
17
21
|
import { ComplexSet } from "@dxos/util";
|
|
18
|
-
|
|
19
|
-
if (key in obj) {
|
|
20
|
-
Object.defineProperty(obj, key, {
|
|
21
|
-
value,
|
|
22
|
-
enumerable: true,
|
|
23
|
-
configurable: true,
|
|
24
|
-
writable: true
|
|
25
|
-
});
|
|
26
|
-
} else {
|
|
27
|
-
obj[key] = value;
|
|
28
|
-
}
|
|
29
|
-
return obj;
|
|
30
|
-
}
|
|
22
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/core/assistant/src/conversation/context.ts";
|
|
31
23
|
var ContextBinding = Schema.Struct({
|
|
32
24
|
blueprints: Schema.Struct({
|
|
33
25
|
added: Schema.Array(Type.Ref(Blueprint.Blueprint)),
|
|
@@ -43,32 +35,96 @@ var ContextBinding = Schema.Struct({
|
|
|
43
35
|
version: "0.1.0"
|
|
44
36
|
}));
|
|
45
37
|
var Bindings = class {
|
|
38
|
+
blueprints = new ComplexSet((ref) => ref.dxn.toString());
|
|
39
|
+
// TODO(burdon): Some DXNs have the Space prefix so only compare the object ID.
|
|
40
|
+
objects = new ComplexSet((ref) => ref.dxn.asEchoDXN()?.echoId);
|
|
46
41
|
toJSON() {
|
|
47
42
|
return {
|
|
48
43
|
blueprints: Array2.fromIterable(this.blueprints).map((ref) => ref.dxn.toString()),
|
|
49
44
|
objects: Array2.fromIterable(this.objects).map((ref) => ref.dxn.toString())
|
|
50
45
|
};
|
|
51
46
|
}
|
|
52
|
-
constructor() {
|
|
53
|
-
_define_property(this, "blueprints", new ComplexSet((ref) => ref.dxn.toString()));
|
|
54
|
-
_define_property(this, "objects", new ComplexSet((ref) => ref.dxn.asEchoDXN()?.echoId));
|
|
55
|
-
}
|
|
56
47
|
};
|
|
57
|
-
var AiContextBinder = class {
|
|
48
|
+
var AiContextBinder = class extends Resource {
|
|
49
|
+
_queue;
|
|
50
|
+
/**
|
|
51
|
+
* Reactive query of all bindings.
|
|
52
|
+
*/
|
|
53
|
+
// TODO(burdon): Cache value?
|
|
54
|
+
_bindings;
|
|
55
|
+
_blueprints;
|
|
56
|
+
_objects;
|
|
57
|
+
constructor(_queue) {
|
|
58
|
+
super(), this._queue = _queue;
|
|
59
|
+
}
|
|
60
|
+
get bindings() {
|
|
61
|
+
invariant(this._bindings, "AiContextBinder not open", {
|
|
62
|
+
F: __dxlog_file,
|
|
63
|
+
L: 78,
|
|
64
|
+
S: this,
|
|
65
|
+
A: [
|
|
66
|
+
"this._bindings",
|
|
67
|
+
"'AiContextBinder not open'"
|
|
68
|
+
]
|
|
69
|
+
});
|
|
70
|
+
return this._bindings;
|
|
71
|
+
}
|
|
72
|
+
get blueprints() {
|
|
73
|
+
invariant(this._blueprints, "AiContextBinder not open", {
|
|
74
|
+
F: __dxlog_file,
|
|
75
|
+
L: 83,
|
|
76
|
+
S: this,
|
|
77
|
+
A: [
|
|
78
|
+
"this._blueprints",
|
|
79
|
+
"'AiContextBinder not open'"
|
|
80
|
+
]
|
|
81
|
+
});
|
|
82
|
+
return this._blueprints;
|
|
83
|
+
}
|
|
84
|
+
get objects() {
|
|
85
|
+
invariant(this._objects, "AiContextBinder not open", {
|
|
86
|
+
F: __dxlog_file,
|
|
87
|
+
L: 88,
|
|
88
|
+
S: this,
|
|
89
|
+
A: [
|
|
90
|
+
"this._objects",
|
|
91
|
+
"'AiContextBinder not open'"
|
|
92
|
+
]
|
|
93
|
+
});
|
|
94
|
+
return this._objects;
|
|
95
|
+
}
|
|
96
|
+
// TODO(wittjosiah): Use parent context?
|
|
97
|
+
async _open() {
|
|
98
|
+
const query = this._queue.query(Query.select(Filter.everything()));
|
|
99
|
+
this._ctx.onDispose(query.subscribe(() => {
|
|
100
|
+
}));
|
|
101
|
+
this._bindings = computed(() => this._reduce(query.objects));
|
|
102
|
+
this._blueprints = computed(() => [
|
|
103
|
+
...this.bindings.value.blueprints
|
|
104
|
+
]);
|
|
105
|
+
this._objects = computed(() => [
|
|
106
|
+
...this.bindings.value.objects
|
|
107
|
+
]);
|
|
108
|
+
}
|
|
109
|
+
async _close() {
|
|
110
|
+
this._bindings = void 0;
|
|
111
|
+
this._blueprints = void 0;
|
|
112
|
+
this._objects = void 0;
|
|
113
|
+
}
|
|
58
114
|
/**
|
|
59
115
|
* Asynchronous query of all bindings.
|
|
60
116
|
*/
|
|
61
117
|
async query() {
|
|
62
|
-
const
|
|
63
|
-
return this._reduce(
|
|
118
|
+
const { objects } = await this._queue.query(Query.select(Filter.everything())).run();
|
|
119
|
+
return this._reduce(objects);
|
|
64
120
|
}
|
|
65
121
|
// TODO(burdon): Pass in Blueprint obj (from registry?) and create reference.
|
|
66
122
|
async bind(props) {
|
|
67
|
-
if (!props.blueprints?.length && !props.objects?.length) {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
123
|
const blueprints = props.blueprints?.filter((ref) => !this.blueprints.peek().find((b) => b.dxn.toString() === ref.dxn.toString())) ?? [];
|
|
71
124
|
const objects = props.objects?.filter((ref) => !this.objects.peek().find((o) => o.dxn.toString() === ref.dxn.toString())) ?? [];
|
|
125
|
+
if (!blueprints.length && !objects.length) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
72
128
|
await this._queue.append([
|
|
73
129
|
Obj.make(ContextBinding, {
|
|
74
130
|
blueprints: {
|
|
@@ -100,7 +156,7 @@ var AiContextBinder = class {
|
|
|
100
156
|
]);
|
|
101
157
|
}
|
|
102
158
|
_reduce(items) {
|
|
103
|
-
return pipe(items, Array2.filter(Obj.instanceOf(ContextBinding)), Array2.reduce(new Bindings(), (context, item) => {
|
|
159
|
+
return Function.pipe(items, Array2.filter(Obj.instanceOf(ContextBinding)), Array2.reduce(new Bindings(), (context, item) => {
|
|
104
160
|
item.blueprints.removed.forEach((ref) => context.blueprints.delete(ref));
|
|
105
161
|
item.blueprints.added.forEach((ref) => context.blueprints.add(ref));
|
|
106
162
|
item.objects.removed.forEach((ref) => {
|
|
@@ -114,45 +170,44 @@ var AiContextBinder = class {
|
|
|
114
170
|
return context;
|
|
115
171
|
}));
|
|
116
172
|
}
|
|
117
|
-
constructor(_queue) {
|
|
118
|
-
_define_property(this, "_queue", void 0);
|
|
119
|
-
_define_property(this, "bindings", void 0);
|
|
120
|
-
_define_property(this, "blueprints", void 0);
|
|
121
|
-
_define_property(this, "objects", void 0);
|
|
122
|
-
this._queue = _queue;
|
|
123
|
-
this.bindings = computed(() => this._reduce(this._queue.objects));
|
|
124
|
-
this.blueprints = computed(() => [
|
|
125
|
-
...this.bindings.value.blueprints
|
|
126
|
-
]);
|
|
127
|
-
this.objects = computed(() => [
|
|
128
|
-
...this.bindings.value.objects
|
|
129
|
-
]);
|
|
130
|
-
}
|
|
131
173
|
};
|
|
132
174
|
var AiContextService = class extends Context.Tag("@dxos/assistant/AiContextService")() {
|
|
133
175
|
};
|
|
134
176
|
|
|
135
177
|
// src/conversation/conversation.ts
|
|
136
|
-
import
|
|
178
|
+
import * as Array4 from "effect/Array";
|
|
179
|
+
import * as Effect from "effect/Effect";
|
|
180
|
+
import * as Option from "effect/Option";
|
|
181
|
+
import { Resource as Resource2 } from "@dxos/context";
|
|
137
182
|
import { Obj as Obj2 } from "@dxos/echo";
|
|
138
183
|
import { DatabaseService } from "@dxos/functions";
|
|
139
184
|
import { log } from "@dxos/log";
|
|
140
185
|
import { DataType } from "@dxos/schema";
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
186
|
+
var __dxlog_file2 = "/__w/dxos/dxos/packages/core/assistant/src/conversation/conversation.ts";
|
|
187
|
+
var AiConversation = class extends Resource2 {
|
|
188
|
+
/**
|
|
189
|
+
* Message and binding queue.
|
|
190
|
+
*/
|
|
191
|
+
_queue;
|
|
192
|
+
/**
|
|
193
|
+
* Blueprints bound to the conversation.
|
|
194
|
+
*/
|
|
195
|
+
_context;
|
|
196
|
+
/**
|
|
197
|
+
* Toolkit from the current session request.
|
|
198
|
+
*/
|
|
199
|
+
_toolkit;
|
|
200
|
+
constructor(queue) {
|
|
201
|
+
super();
|
|
202
|
+
this._queue = queue;
|
|
203
|
+
this._context = new AiContextBinder(this._queue);
|
|
204
|
+
}
|
|
205
|
+
async _open() {
|
|
206
|
+
await this._context.open();
|
|
207
|
+
}
|
|
208
|
+
async _close() {
|
|
209
|
+
await this._context.close();
|
|
151
210
|
}
|
|
152
|
-
return obj;
|
|
153
|
-
}
|
|
154
|
-
var __dxlog_file = "/__w/dxos/dxos/packages/core/assistant/src/conversation/conversation.ts";
|
|
155
|
-
var AiConversation = class {
|
|
156
211
|
get context() {
|
|
157
212
|
return this._context;
|
|
158
213
|
}
|
|
@@ -171,8 +226,8 @@ var AiConversation = class {
|
|
|
171
226
|
const session = new AiSession();
|
|
172
227
|
const history = yield* Effect.promise(() => this.getHistory());
|
|
173
228
|
const context = yield* Effect.promise(() => this.context.query());
|
|
174
|
-
const blueprints = yield* Effect.forEach(context.blueprints.values(), DatabaseService.loadOption).pipe(Effect.map(
|
|
175
|
-
const objects = yield* Effect.forEach(context.objects.values(), DatabaseService.loadOption).pipe(Effect.map(
|
|
229
|
+
const blueprints = yield* Effect.forEach(context.blueprints.values(), DatabaseService.loadOption).pipe(Effect.map(Array4.filter(Option.isSome)), Effect.map(Array4.map((option) => option.value)));
|
|
230
|
+
const objects = yield* Effect.forEach(context.objects.values(), DatabaseService.loadOption).pipe(Effect.map(Array4.filter(Option.isSome)), Effect.map(Array4.map((option) => option.value)));
|
|
176
231
|
const toolkit = yield* createToolkit({
|
|
177
232
|
blueprints
|
|
178
233
|
});
|
|
@@ -184,8 +239,8 @@ var AiConversation = class {
|
|
|
184
239
|
objects: objects.length,
|
|
185
240
|
tools: this._toolkit?.tools.length ?? 0
|
|
186
241
|
}, {
|
|
187
|
-
F:
|
|
188
|
-
L:
|
|
242
|
+
F: __dxlog_file2,
|
|
243
|
+
L: 107,
|
|
189
244
|
S: this,
|
|
190
245
|
C: (f, a) => f(...a)
|
|
191
246
|
});
|
|
@@ -202,8 +257,8 @@ var AiConversation = class {
|
|
|
202
257
|
messages: messages.length,
|
|
203
258
|
duration: Date.now() - start
|
|
204
259
|
}, {
|
|
205
|
-
F:
|
|
206
|
-
L:
|
|
260
|
+
F: __dxlog_file2,
|
|
261
|
+
L: 121,
|
|
207
262
|
S: this,
|
|
208
263
|
C: (f, a) => f(...a)
|
|
209
264
|
});
|
|
@@ -211,13 +266,6 @@ var AiConversation = class {
|
|
|
211
266
|
return messages;
|
|
212
267
|
}).pipe(Effect.withSpan("AiConversation.request"));
|
|
213
268
|
}
|
|
214
|
-
constructor(options) {
|
|
215
|
-
_define_property2(this, "_queue", void 0);
|
|
216
|
-
_define_property2(this, "_context", void 0);
|
|
217
|
-
_define_property2(this, "_toolkit", void 0);
|
|
218
|
-
this._queue = options.queue;
|
|
219
|
-
this._context = new AiContextBinder(this._queue);
|
|
220
|
-
}
|
|
221
269
|
};
|
|
222
270
|
|
|
223
271
|
// src/diff.ts
|
|
@@ -225,7 +273,7 @@ import { next as A } from "@automerge/automerge";
|
|
|
225
273
|
import { DocAccessor, toCursorRange } from "@dxos/echo-db";
|
|
226
274
|
import { log as log2 } from "@dxos/log";
|
|
227
275
|
import { isNonNullable } from "@dxos/util";
|
|
228
|
-
var
|
|
276
|
+
var __dxlog_file3 = "/__w/dxos/dxos/packages/core/assistant/src/diff.ts";
|
|
229
277
|
var reduceDiffs = (diffs) => {
|
|
230
278
|
return diffs.reduce((acc, diff) => {
|
|
231
279
|
const current = acc[acc.length - 1];
|
|
@@ -278,8 +326,8 @@ var applyDiffs = (accessor, diffs) => {
|
|
|
278
326
|
A.splice(doc, accessor.path, idx, diff.match.length, diff.replace);
|
|
279
327
|
} else {
|
|
280
328
|
log2.warn("diff not found", diff, {
|
|
281
|
-
F:
|
|
282
|
-
L:
|
|
329
|
+
F: __dxlog_file3,
|
|
330
|
+
L: 78,
|
|
283
331
|
S: void 0,
|
|
284
332
|
C: (f, a) => f(...a)
|
|
285
333
|
});
|
|
@@ -296,20 +344,15 @@ import { MESSAGE_PROPERTY_TOOL_CALL_ID } from "@dxos/functions";
|
|
|
296
344
|
import { LogLevel } from "@dxos/log";
|
|
297
345
|
import { ContentBlock, DataType as DataType2 } from "@dxos/schema";
|
|
298
346
|
import { isNonNullable as isNonNullable2 } from "@dxos/util";
|
|
299
|
-
function _define_property3(obj, key, value) {
|
|
300
|
-
if (key in obj) {
|
|
301
|
-
Object.defineProperty(obj, key, {
|
|
302
|
-
value,
|
|
303
|
-
enumerable: true,
|
|
304
|
-
configurable: true,
|
|
305
|
-
writable: true
|
|
306
|
-
});
|
|
307
|
-
} else {
|
|
308
|
-
obj[key] = value;
|
|
309
|
-
}
|
|
310
|
-
return obj;
|
|
311
|
-
}
|
|
312
347
|
var ExecutionGraph = class {
|
|
348
|
+
// TODO(dmaretskyi): Evolve the internal state to support chats, functions, circuit workflows, etc.
|
|
349
|
+
_commits = [];
|
|
350
|
+
_branchNames = /* @__PURE__ */ new Set();
|
|
351
|
+
_lastBlockId;
|
|
352
|
+
// Tool call tracking.
|
|
353
|
+
_toolCallCommitIds = /* @__PURE__ */ new Map();
|
|
354
|
+
_lastCommitByBranch = /* @__PURE__ */ new Map();
|
|
355
|
+
_pendingToolResults = /* @__PURE__ */ new Map();
|
|
313
356
|
/**
|
|
314
357
|
* Adds events to the graph.
|
|
315
358
|
*/
|
|
@@ -491,14 +534,6 @@ var ExecutionGraph = class {
|
|
|
491
534
|
const toolResultMatch = commitId.match(/_toolResult_(.+)$/);
|
|
492
535
|
return toolCallMatch?.[1] || toolResultMatch?.[1];
|
|
493
536
|
}
|
|
494
|
-
constructor() {
|
|
495
|
-
_define_property3(this, "_commits", []);
|
|
496
|
-
_define_property3(this, "_branchNames", /* @__PURE__ */ new Set());
|
|
497
|
-
_define_property3(this, "_lastBlockId", void 0);
|
|
498
|
-
_define_property3(this, "_toolCallCommitIds", /* @__PURE__ */ new Map());
|
|
499
|
-
_define_property3(this, "_lastCommitByBranch", /* @__PURE__ */ new Map());
|
|
500
|
-
_define_property3(this, "_pendingToolResults", /* @__PURE__ */ new Map());
|
|
501
|
-
}
|
|
502
537
|
};
|
|
503
538
|
var messageToCommits = (message, lastBlockId, toolCallIds, lastCommitByBranch) => {
|
|
504
539
|
let previousBlockId = lastBlockId;
|
|
@@ -663,14 +698,18 @@ var stringifyObject = (obj) => {
|
|
|
663
698
|
};
|
|
664
699
|
|
|
665
700
|
// src/functions/services.ts
|
|
666
|
-
import
|
|
667
|
-
import
|
|
701
|
+
import * as Tool from "@effect/ai/Tool";
|
|
702
|
+
import * as Context2 from "effect/Context";
|
|
703
|
+
import * as Effect2 from "effect/Effect";
|
|
704
|
+
import * as Layer from "effect/Layer";
|
|
705
|
+
import * as Record from "effect/Record";
|
|
706
|
+
import * as Schema2 from "effect/Schema";
|
|
668
707
|
import { AiToolNotFoundError, ToolExecutionService, ToolResolverService } from "@dxos/ai";
|
|
669
708
|
import { todo } from "@dxos/debug";
|
|
670
|
-
import { Query } from "@dxos/echo";
|
|
671
|
-
import { DatabaseService as DatabaseService2, FunctionDefinition, FunctionInvocationService
|
|
672
|
-
import { invariant } from "@dxos/invariant";
|
|
673
|
-
var
|
|
709
|
+
import { Query as Query2 } from "@dxos/echo";
|
|
710
|
+
import { DatabaseService as DatabaseService2, Function as Function2, FunctionDefinition, FunctionInvocationService } from "@dxos/functions";
|
|
711
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
712
|
+
var __dxlog_file4 = "/__w/dxos/dxos/packages/core/assistant/src/functions/services.ts";
|
|
674
713
|
var makeToolResolverFromFunctions = (functions, toolkit) => {
|
|
675
714
|
return Layer.effect(ToolResolverService, Effect2.gen(function* () {
|
|
676
715
|
const dbService = yield* DatabaseService2;
|
|
@@ -680,10 +719,10 @@ var makeToolResolverFromFunctions = (functions, toolkit) => {
|
|
|
680
719
|
if (tool) {
|
|
681
720
|
return tool;
|
|
682
721
|
}
|
|
683
|
-
const { objects: [dbFunction] } = yield* DatabaseService2.runQuery(
|
|
722
|
+
const { objects: [dbFunction] } = yield* DatabaseService2.runQuery(Query2.type(Function2.Function, {
|
|
684
723
|
key: id
|
|
685
724
|
}));
|
|
686
|
-
const functionDef = dbFunction ? FunctionDefinition.deserialize(dbFunction) : functions.find((
|
|
725
|
+
const functionDef = dbFunction ? FunctionDefinition.deserialize(dbFunction) : functions.find((fn2) => fn2.key === id);
|
|
687
726
|
if (!functionDef) {
|
|
688
727
|
return yield* Effect2.fail(new AiToolNotFoundError(id));
|
|
689
728
|
}
|
|
@@ -695,9 +734,9 @@ var makeToolResolverFromFunctions = (functions, toolkit) => {
|
|
|
695
734
|
var makeToolExecutionServiceFromFunctions = (toolkit, handlersLayer) => {
|
|
696
735
|
return Layer.effect(ToolExecutionService, Effect2.gen(function* () {
|
|
697
736
|
const toolkitHandler = yield* toolkit.pipe(Effect2.provide(handlersLayer));
|
|
698
|
-
|
|
699
|
-
F:
|
|
700
|
-
L:
|
|
737
|
+
invariant2(isHandlerLike(toolkitHandler), void 0, {
|
|
738
|
+
F: __dxlog_file4,
|
|
739
|
+
L: 73,
|
|
701
740
|
S: this,
|
|
702
741
|
A: [
|
|
703
742
|
"isHandlerLike(toolkitHandler)",
|
|
@@ -727,26 +766,26 @@ var makeToolExecutionServiceFromFunctions = (toolkit, handlersLayer) => {
|
|
|
727
766
|
var FunctionToolAnnotation = class extends Context2.Tag("@dxos/assistant/FunctionToolAnnotation")() {
|
|
728
767
|
};
|
|
729
768
|
var toolCache = /* @__PURE__ */ new WeakMap();
|
|
730
|
-
var projectFunctionToTool = (
|
|
731
|
-
if (toolCache.has(
|
|
732
|
-
return toolCache.get(
|
|
769
|
+
var projectFunctionToTool = (fn2) => {
|
|
770
|
+
if (toolCache.has(fn2)) {
|
|
771
|
+
return toolCache.get(fn2);
|
|
733
772
|
}
|
|
734
|
-
const tool = Tool.make(makeToolName(
|
|
735
|
-
description:
|
|
736
|
-
parameters: createStructFieldsFromSchema(
|
|
773
|
+
const tool = Tool.make(makeToolName(fn2.name), {
|
|
774
|
+
description: fn2.description,
|
|
775
|
+
parameters: createStructFieldsFromSchema(fn2.inputSchema),
|
|
737
776
|
// TODO(dmaretskyi): Include output schema.
|
|
738
777
|
failure: Schema2.Any
|
|
739
778
|
}).annotate(FunctionToolAnnotation, {
|
|
740
|
-
definition:
|
|
779
|
+
definition: fn2
|
|
741
780
|
});
|
|
742
|
-
toolCache.set(
|
|
781
|
+
toolCache.set(fn2, tool);
|
|
743
782
|
return tool;
|
|
744
783
|
};
|
|
745
784
|
var makeToolName = (name) => {
|
|
746
785
|
const toolName = name.replace(/[^a-zA-Z0-9]/g, "_");
|
|
747
|
-
|
|
748
|
-
F:
|
|
749
|
-
L:
|
|
786
|
+
invariant2(toolName.match(/^[a-zA-Z_][a-zA-Z0-9-_]*$/), void 0, {
|
|
787
|
+
F: __dxlog_file4,
|
|
788
|
+
L: 140,
|
|
750
789
|
S: void 0,
|
|
751
790
|
A: [
|
|
752
791
|
"toolName.match(/^[a-zA-Z_][a-zA-Z0-9-_]*$/)",
|
|
@@ -797,8 +836,8 @@ var templates = {
|
|
|
797
836
|
})
|
|
798
837
|
};
|
|
799
838
|
|
|
800
|
-
// src/types.ts
|
|
801
|
-
import
|
|
839
|
+
// src/types/artifact.ts
|
|
840
|
+
import * as Schema3 from "effect/Schema";
|
|
802
841
|
import { DXN as DXN2, LOCAL_SPACE_TAG } from "@dxos/keys";
|
|
803
842
|
import { trim } from "@dxos/util";
|
|
804
843
|
var createArtifactElement = (id) => `<artifact id=${id} />`;
|