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