@dxos/assistant 0.8.4-main.ae835ea → 0.8.4-main.bc674ce
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-4VIJTKPM.mjs → chunk-7CDDG6LL.mjs} +252 -28
- package/dist/lib/browser/chunk-7CDDG6LL.mjs.map +7 -0
- package/dist/lib/browser/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/browser/extraction/index.mjs +119 -166
- package/dist/lib/browser/extraction/index.mjs.map +4 -4
- package/dist/lib/browser/index.mjs +239 -289
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +32 -0
- package/dist/lib/browser/testing/index.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-AUUC7II4.mjs → chunk-CC7ER6Q3.mjs} +251 -28
- package/dist/lib/node-esm/chunk-CC7ER6Q3.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
- package/dist/lib/node-esm/extraction/index.mjs +119 -166
- package/dist/lib/node-esm/extraction/index.mjs.map +4 -4
- package/dist/lib/node-esm/index.mjs +239 -289
- 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 +33 -0
- package/dist/lib/node-esm/testing/index.mjs.map +7 -0
- package/dist/types/src/conversation/context.d.ts +88 -62
- package/dist/types/src/conversation/context.d.ts.map +1 -1
- package/dist/types/src/conversation/context.test.d.ts +2 -0
- package/dist/types/src/conversation/context.test.d.ts.map +1 -0
- package/dist/types/src/conversation/conversation.d.ts +16 -16
- package/dist/types/src/conversation/conversation.d.ts.map +1 -1
- package/dist/types/src/conversation/conversation.test.d.ts +2 -0
- package/dist/types/src/conversation/conversation.test.d.ts.map +1 -0
- package/dist/types/src/errors.d.ts +22 -30
- package/dist/types/src/errors.d.ts.map +1 -1
- package/dist/types/src/execution-graph.d.ts +5 -2
- package/dist/types/src/execution-graph.d.ts.map +1 -1
- package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts.map +1 -1
- package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts +254 -252
- package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts.map +1 -1
- package/dist/types/src/extraction/extraction.d.ts +344 -309
- package/dist/types/src/extraction/extraction.d.ts.map +1 -1
- package/dist/types/src/extraction/quotes.d.ts +2 -2
- package/dist/types/src/extraction/quotes.d.ts.map +1 -1
- package/dist/types/src/functions/services.d.ts +4 -3
- package/dist/types/src/functions/services.d.ts.map +1 -1
- package/dist/types/src/functions.test.d.ts +2 -0
- package/dist/types/src/functions.test.d.ts.map +1 -0
- package/dist/types/src/session/GenericToolkit.d.ts +85 -0
- package/dist/types/src/session/GenericToolkit.d.ts.map +1 -0
- package/dist/types/src/session/artifact-diff.d.ts +1 -1
- package/dist/types/src/session/artifact-diff.d.ts.map +1 -1
- package/dist/types/src/session/format.d.ts +4 -178
- package/dist/types/src/session/format.d.ts.map +1 -1
- package/dist/types/src/session/index.d.ts +1 -0
- package/dist/types/src/session/index.d.ts.map +1 -1
- package/dist/types/src/session/observer.d.ts +6 -5
- package/dist/types/src/session/observer.d.ts.map +1 -1
- package/dist/types/src/session/session.d.ts +16 -11
- package/dist/types/src/session/session.d.ts.map +1 -1
- package/dist/types/src/session/toolkit.d.ts +5 -6
- package/dist/types/src/session/toolkit.d.ts.map +1 -1
- package/dist/types/src/session/version-pin.d.ts +3 -3
- package/dist/types/src/session/version-pin.d.ts.map +1 -1
- package/dist/types/src/testing/index.d.ts +2 -0
- package/dist/types/src/testing/index.d.ts.map +1 -0
- package/dist/types/src/testing/layer.d.ts +21 -0
- package/dist/types/src/testing/layer.d.ts.map +1 -0
- package/dist/types/src/types/artifact.d.ts +14 -2
- package/dist/types/src/types/artifact.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +38 -27
- package/src/conversation/context.test.ts +46 -0
- package/src/conversation/context.ts +183 -66
- package/src/conversation/conversation.test.ts +65 -0
- package/src/conversation/conversation.ts +51 -54
- package/src/diff.test.ts +3 -3
- package/src/errors.ts +2 -2
- package/src/execution-graph.test.ts +45 -43
- package/src/execution-graph.ts +23 -14
- package/src/extraction/extraction-llm-function/extraction-llm-function.test.ts +2 -2
- package/src/extraction/extraction-llm-function/extraction-llm-function.ts +44 -54
- package/src/extraction/extraction-ner-function/extraction-ner-function.test.ts +14 -13
- package/src/extraction/extraction-ner-function/extraction-ner-function.ts +36 -44
- package/src/extraction/extraction-ner-function/named-entity-recognition.test.ts +10 -5
- package/src/extraction/extraction.ts +9 -8
- package/src/extraction/quotes.ts +4 -5
- package/src/functions/services.ts +41 -19
- package/src/functions.conversations.json +1 -0
- package/src/functions.test.ts +74 -0
- package/src/session/GenericToolkit.ts +131 -0
- package/src/session/artifact-diff.ts +1 -1
- package/src/session/format.test.ts +103 -39
- package/src/session/format.ts +17 -16
- package/src/session/index.ts +2 -0
- package/src/session/observer.ts +5 -3
- package/src/session/session.conversations.json +1 -1
- package/src/session/session.test.ts +7 -13
- package/src/session/session.ts +40 -19
- package/src/session/toolkit.ts +13 -22
- package/src/session/version-pin.ts +6 -6
- package/src/templates/{format.tpl → instructions/format.tpl} +1 -0
- package/src/templates/system.ts +2 -2
- package/src/testing/index.ts +5 -0
- package/src/testing/layer.ts +78 -0
- package/src/types/artifact.ts +33 -3
- package/dist/lib/browser/chunk-4VIJTKPM.mjs.map +0 -7
- package/dist/lib/browser/chunk-UB26N5UF.mjs +0 -89
- package/dist/lib/browser/chunk-UB26N5UF.mjs.map +0 -7
- package/dist/lib/browser/named-entity-recognition-QPYHML66.mjs +0 -13
- package/dist/lib/node-esm/chunk-AUUC7II4.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-BCFXTNSK.mjs +0 -91
- package/dist/lib/node-esm/chunk-BCFXTNSK.mjs.map +0 -7
- package/dist/lib/node-esm/named-entity-recognition-2HDF46YX.mjs +0 -14
- package/dist/types/src/summarization/summarization.test.d.ts +0 -2
- package/dist/types/src/summarization/summarization.test.d.ts.map +0 -1
- package/src/summarization/summarization.test.ts +0 -202
- /package/dist/lib/browser/{named-entity-recognition-QPYHML66.mjs.map → chunk-J5LGTIGS.mjs.map} +0 -0
- /package/dist/lib/node-esm/{named-entity-recognition-2HDF46YX.mjs.map → chunk-HSLMI22Q.mjs.map} +0 -0
- /package/src/extraction/extraction-llm-function/{instructions.tpl → transcription-instructions.tpl} +0 -0
- /package/src/templates/{system.tpl → instructions/system.tpl} +0 -0
|
@@ -3,34 +3,40 @@ import {
|
|
|
3
3
|
AiModelError,
|
|
4
4
|
AiSession,
|
|
5
5
|
ArtifactDiffResolver,
|
|
6
|
+
ArtifactId,
|
|
6
7
|
GenerationObserver,
|
|
8
|
+
GenericToolkit_exports,
|
|
9
|
+
RefFromLLM,
|
|
7
10
|
VersionPin,
|
|
8
|
-
|
|
9
|
-
|
|
11
|
+
createArtifactElement,
|
|
12
|
+
createToolkit,
|
|
13
|
+
makeToolExecutionServiceFromFunctions,
|
|
14
|
+
makeToolResolverFromFunctions
|
|
15
|
+
} from "./chunk-7CDDG6LL.mjs";
|
|
16
|
+
import "./chunk-J5LGTIGS.mjs";
|
|
10
17
|
|
|
11
18
|
// src/conversation/context.ts
|
|
12
|
-
import {
|
|
13
|
-
import * as
|
|
19
|
+
import { Atom, Registry } from "@effect-atom/atom-react";
|
|
20
|
+
import * as EArray from "effect/Array";
|
|
14
21
|
import * as Context from "effect/Context";
|
|
15
22
|
import * as Function from "effect/Function";
|
|
16
23
|
import * as Schema from "effect/Schema";
|
|
17
24
|
import { Blueprint } from "@dxos/blueprints";
|
|
18
25
|
import { Resource } from "@dxos/context";
|
|
19
|
-
import { DXN,
|
|
20
|
-
import {
|
|
21
|
-
import { ComplexSet } from "@dxos/util";
|
|
26
|
+
import { DXN, Obj, Query, Type } from "@dxos/echo";
|
|
27
|
+
import { log } from "@dxos/log";
|
|
28
|
+
import { ComplexSet, isTruthy } from "@dxos/util";
|
|
22
29
|
var __dxlog_file = "/__w/dxos/dxos/packages/core/assistant/src/conversation/context.ts";
|
|
23
30
|
var ContextBinding = Schema.Struct({
|
|
24
31
|
blueprints: Schema.Struct({
|
|
25
32
|
added: Schema.Array(Type.Ref(Blueprint.Blueprint)),
|
|
26
33
|
removed: Schema.Array(Type.Ref(Blueprint.Blueprint))
|
|
27
34
|
}),
|
|
28
|
-
// TODO(burdon): Type.Expando => Type.Obj (or Obj.Any?)
|
|
29
35
|
objects: Schema.Struct({
|
|
30
|
-
added: Schema.Array(Type.Ref(Type.
|
|
31
|
-
removed: Schema.Array(Type.Ref(Type.
|
|
36
|
+
added: Schema.Array(Type.Ref(Type.Obj)),
|
|
37
|
+
removed: Schema.Array(Type.Ref(Type.Obj))
|
|
32
38
|
})
|
|
33
|
-
}).pipe(Type.
|
|
39
|
+
}).pipe(Type.object({
|
|
34
40
|
typename: "dxos.org/type/ContextBinding",
|
|
35
41
|
version: "0.1.0"
|
|
36
42
|
}));
|
|
@@ -40,238 +46,322 @@ var Bindings = class {
|
|
|
40
46
|
objects = new ComplexSet((ref) => ref.dxn.asEchoDXN()?.echoId);
|
|
41
47
|
toJSON() {
|
|
42
48
|
return {
|
|
43
|
-
blueprints:
|
|
44
|
-
objects:
|
|
49
|
+
blueprints: EArray.fromIterable(this.blueprints).map((ref) => ref.dxn.toString()),
|
|
50
|
+
objects: EArray.fromIterable(this.objects).map((ref) => ref.dxn.toString())
|
|
45
51
|
};
|
|
46
52
|
}
|
|
47
53
|
};
|
|
48
54
|
var AiContextBinder = class extends Resource {
|
|
55
|
+
_blueprints = Atom.make([]).pipe(Atom.keepAlive);
|
|
56
|
+
_objects = Atom.make([]).pipe(Atom.keepAlive);
|
|
57
|
+
_registry;
|
|
49
58
|
_queue;
|
|
59
|
+
constructor(options) {
|
|
60
|
+
super();
|
|
61
|
+
this._queue = options.queue;
|
|
62
|
+
this._registry = options.registry ?? Registry.make();
|
|
63
|
+
}
|
|
50
64
|
/**
|
|
51
|
-
*
|
|
65
|
+
* Returns the blueprints atom for subscription.
|
|
52
66
|
*/
|
|
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
67
|
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
68
|
return this._blueprints;
|
|
83
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Returns the objects atom for subscription.
|
|
72
|
+
*/
|
|
84
73
|
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
74
|
return this._objects;
|
|
95
75
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
-
]);
|
|
76
|
+
/**
|
|
77
|
+
* Gets the current blueprints value.
|
|
78
|
+
*/
|
|
79
|
+
getBlueprints() {
|
|
80
|
+
return this._registry.get(this._blueprints);
|
|
108
81
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
82
|
+
/**
|
|
83
|
+
* Gets the current objects value.
|
|
84
|
+
*/
|
|
85
|
+
getObjects() {
|
|
86
|
+
return this._registry.get(this._objects);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Subscribe to changes in blueprints.
|
|
90
|
+
*/
|
|
91
|
+
subscribeBlueprints(cb) {
|
|
92
|
+
return this._registry.subscribe(this._blueprints, () => cb(this._registry.get(this._blueprints)));
|
|
113
93
|
}
|
|
114
94
|
/**
|
|
115
|
-
*
|
|
95
|
+
* Subscribe to changes in objects.
|
|
116
96
|
*/
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
97
|
+
subscribeObjects(cb) {
|
|
98
|
+
return this._registry.subscribe(this._objects, () => cb(this._registry.get(this._objects)));
|
|
99
|
+
}
|
|
100
|
+
async _open() {
|
|
101
|
+
const query = this._queue.query(Query.type(ContextBinding));
|
|
102
|
+
const initialResults = await query.run();
|
|
103
|
+
await this._updateBindings(initialResults);
|
|
104
|
+
this._ctx.onDispose(query.subscribe(async () => {
|
|
105
|
+
await this._updateBindings(query.results);
|
|
106
|
+
}));
|
|
107
|
+
}
|
|
108
|
+
async _updateBindings(items) {
|
|
109
|
+
if (items.length === 0) {
|
|
126
110
|
return;
|
|
127
111
|
}
|
|
112
|
+
const bindings = this._reduce(items);
|
|
113
|
+
const currentBlueprints = this._registry.get(this._blueprints);
|
|
114
|
+
const currentObjects = this._registry.get(this._objects);
|
|
115
|
+
const newBlueprints = await this._resolve(bindings.blueprints, currentBlueprints);
|
|
116
|
+
const newObjects = await this._resolve(bindings.objects, currentObjects);
|
|
117
|
+
this._registry.set(this._blueprints, newBlueprints);
|
|
118
|
+
this._registry.set(this._objects, newObjects);
|
|
119
|
+
log("updated bindings", {
|
|
120
|
+
blueprints: newBlueprints.length,
|
|
121
|
+
objects: newObjects.length
|
|
122
|
+
}, {
|
|
123
|
+
F: __dxlog_file,
|
|
124
|
+
L: 156,
|
|
125
|
+
S: this,
|
|
126
|
+
C: (f, a) => f(...a)
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
async _close() {
|
|
130
|
+
this._registry.set(this._blueprints, []);
|
|
131
|
+
this._registry.set(this._objects, []);
|
|
132
|
+
}
|
|
133
|
+
async bind({ blueprints, objects }) {
|
|
134
|
+
const currentBlueprints = this._registry.get(this._blueprints);
|
|
135
|
+
const currentObjects = this._registry.get(this._objects);
|
|
136
|
+
const { added: addedBlueprints, next: nextBlueprints } = this._processBindings(blueprints, currentBlueprints);
|
|
137
|
+
const { added: addedObjects, next: nextObjects } = this._processBindings(objects, currentObjects);
|
|
138
|
+
if (!addedBlueprints.length && !addedObjects.length) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
this._registry.set(this._blueprints, nextBlueprints);
|
|
142
|
+
this._registry.set(this._objects, nextObjects);
|
|
143
|
+
log("bind", {
|
|
144
|
+
blueprints: addedBlueprints.length,
|
|
145
|
+
objects: addedObjects.length
|
|
146
|
+
}, {
|
|
147
|
+
F: __dxlog_file,
|
|
148
|
+
L: 182,
|
|
149
|
+
S: this,
|
|
150
|
+
C: (f, a) => f(...a)
|
|
151
|
+
});
|
|
128
152
|
await this._queue.append([
|
|
129
153
|
Obj.make(ContextBinding, {
|
|
130
154
|
blueprints: {
|
|
131
|
-
added:
|
|
155
|
+
added: addedBlueprints,
|
|
132
156
|
removed: []
|
|
133
157
|
},
|
|
134
158
|
objects: {
|
|
135
|
-
added:
|
|
159
|
+
added: addedObjects,
|
|
136
160
|
removed: []
|
|
137
161
|
}
|
|
138
162
|
})
|
|
139
163
|
]);
|
|
140
164
|
}
|
|
141
|
-
async unbind(
|
|
142
|
-
if (!
|
|
165
|
+
async unbind({ blueprints, objects }) {
|
|
166
|
+
if (!blueprints?.length && !objects?.length) {
|
|
143
167
|
return;
|
|
144
168
|
}
|
|
169
|
+
log("unbind", {
|
|
170
|
+
blueprints: blueprints?.length,
|
|
171
|
+
objects: objects?.length
|
|
172
|
+
}, {
|
|
173
|
+
F: __dxlog_file,
|
|
174
|
+
L: 202,
|
|
175
|
+
S: this,
|
|
176
|
+
C: (f, a) => f(...a)
|
|
177
|
+
});
|
|
145
178
|
await this._queue.append([
|
|
146
179
|
Obj.make(ContextBinding, {
|
|
147
180
|
blueprints: {
|
|
148
181
|
added: [],
|
|
149
|
-
removed:
|
|
182
|
+
removed: blueprints ?? []
|
|
150
183
|
},
|
|
151
184
|
objects: {
|
|
152
185
|
added: [],
|
|
153
|
-
removed:
|
|
186
|
+
removed: objects ?? []
|
|
154
187
|
}
|
|
155
188
|
})
|
|
156
189
|
]);
|
|
157
190
|
}
|
|
191
|
+
/**
|
|
192
|
+
* Process bindings to filter duplicates and determine next state.
|
|
193
|
+
*/
|
|
194
|
+
_processBindings(refs, current) {
|
|
195
|
+
const next = [
|
|
196
|
+
...current
|
|
197
|
+
];
|
|
198
|
+
const added = [];
|
|
199
|
+
if (!refs?.length) {
|
|
200
|
+
return {
|
|
201
|
+
added,
|
|
202
|
+
next
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
const seen = new Set(current.map((obj) => Obj.getDXN(obj).toString()));
|
|
206
|
+
for (const ref of refs) {
|
|
207
|
+
const dxn = ref.dxn.toString();
|
|
208
|
+
if (!seen.has(dxn)) {
|
|
209
|
+
seen.add(dxn);
|
|
210
|
+
added.push(ref);
|
|
211
|
+
if (ref.isAvailable) {
|
|
212
|
+
const target = ref.target;
|
|
213
|
+
if (target) {
|
|
214
|
+
next.push(target);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return {
|
|
220
|
+
added,
|
|
221
|
+
next
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Reduce results into sets of blueprints and objects.
|
|
226
|
+
*/
|
|
158
227
|
_reduce(items) {
|
|
159
|
-
return Function.pipe(items,
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
228
|
+
return Function.pipe(items, EArray.reduce(new Bindings(), (context, { blueprints, objects }) => {
|
|
229
|
+
blueprints.added.forEach((ref) => context.blueprints.add(ref));
|
|
230
|
+
blueprints.removed.forEach((ref) => context.blueprints.delete(ref));
|
|
231
|
+
objects.added.forEach((ref) => context.objects.add(ref));
|
|
232
|
+
objects.removed.forEach((ref) => {
|
|
163
233
|
for (const obj of context.objects) {
|
|
164
234
|
if (DXN.equalsEchoId(obj.dxn, ref.dxn)) {
|
|
165
235
|
context.objects.delete(obj);
|
|
166
236
|
}
|
|
167
237
|
}
|
|
168
238
|
});
|
|
169
|
-
item.objects.added.forEach((ref) => context.objects.add(ref));
|
|
170
239
|
return context;
|
|
171
240
|
}));
|
|
172
241
|
}
|
|
242
|
+
/**
|
|
243
|
+
* Resolve references to objects, loading them first if needed and falling back to existing objects.
|
|
244
|
+
*/
|
|
245
|
+
async _resolve(refs, current) {
|
|
246
|
+
const refArray = [
|
|
247
|
+
...refs
|
|
248
|
+
];
|
|
249
|
+
await Promise.all(refArray.map((ref) => ref.load()));
|
|
250
|
+
return refArray.map((ref) => {
|
|
251
|
+
let target;
|
|
252
|
+
if (ref.isAvailable) {
|
|
253
|
+
target = ref.target;
|
|
254
|
+
}
|
|
255
|
+
return target ?? current.find((obj) => Obj.getDXN(obj).toString() === ref.dxn.toString());
|
|
256
|
+
}).filter(isTruthy);
|
|
257
|
+
}
|
|
173
258
|
};
|
|
174
259
|
var AiContextService = class extends Context.Tag("@dxos/assistant/AiContextService")() {
|
|
175
260
|
};
|
|
176
261
|
|
|
177
262
|
// src/conversation/conversation.ts
|
|
178
|
-
import * as Array4 from "effect/Array";
|
|
179
263
|
import * as Effect from "effect/Effect";
|
|
180
|
-
import * as Option from "effect/Option";
|
|
181
264
|
import { Resource as Resource2 } from "@dxos/context";
|
|
182
265
|
import { Obj as Obj2 } from "@dxos/echo";
|
|
183
|
-
import {
|
|
184
|
-
import { log } from "@dxos/log";
|
|
185
|
-
import {
|
|
266
|
+
import { invariant } from "@dxos/invariant";
|
|
267
|
+
import { log as log2 } from "@dxos/log";
|
|
268
|
+
import { Message } from "@dxos/types";
|
|
186
269
|
var __dxlog_file2 = "/__w/dxos/dxos/packages/core/assistant/src/conversation/conversation.ts";
|
|
187
270
|
var AiConversation = class extends Resource2 {
|
|
188
271
|
/**
|
|
189
|
-
*
|
|
272
|
+
* Blueprints and objects bound to the conversation.
|
|
190
273
|
*/
|
|
274
|
+
_binder;
|
|
191
275
|
_queue;
|
|
192
|
-
/**
|
|
193
|
-
* Blueprints bound to the conversation.
|
|
194
|
-
*/
|
|
195
|
-
_context;
|
|
196
|
-
/**
|
|
197
|
-
* Toolkit from the current session request.
|
|
198
|
-
*/
|
|
199
276
|
_toolkit;
|
|
200
|
-
constructor(
|
|
277
|
+
constructor(options) {
|
|
201
278
|
super();
|
|
202
|
-
this._queue = queue;
|
|
203
|
-
this.
|
|
279
|
+
this._queue = options.queue;
|
|
280
|
+
this._toolkit = options.toolkit;
|
|
281
|
+
invariant(this._queue, void 0, {
|
|
282
|
+
F: __dxlog_file2,
|
|
283
|
+
L: 54,
|
|
284
|
+
S: this,
|
|
285
|
+
A: [
|
|
286
|
+
"this._queue",
|
|
287
|
+
""
|
|
288
|
+
]
|
|
289
|
+
});
|
|
290
|
+
this._binder = new AiContextBinder({
|
|
291
|
+
queue: this._queue,
|
|
292
|
+
registry: options.registry
|
|
293
|
+
});
|
|
204
294
|
}
|
|
205
295
|
async _open() {
|
|
206
|
-
await this.
|
|
296
|
+
await this._binder.open(this._ctx);
|
|
207
297
|
}
|
|
208
|
-
|
|
209
|
-
|
|
298
|
+
get queue() {
|
|
299
|
+
return this._queue;
|
|
210
300
|
}
|
|
211
301
|
get context() {
|
|
212
|
-
return this.
|
|
302
|
+
return this._binder;
|
|
213
303
|
}
|
|
214
304
|
get toolkit() {
|
|
215
305
|
return this._toolkit;
|
|
216
306
|
}
|
|
217
307
|
async getHistory() {
|
|
218
308
|
const queueItems = await this._queue.queryObjects();
|
|
219
|
-
return queueItems.filter(Obj2.instanceOf(
|
|
309
|
+
return queueItems.filter(Obj2.instanceOf(Message.Message));
|
|
220
310
|
}
|
|
221
311
|
/**
|
|
222
312
|
* Creates a new cancelable request effect.
|
|
223
313
|
*/
|
|
224
314
|
createRequest(params) {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
const history = yield* Effect.promise(() =>
|
|
228
|
-
const
|
|
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)));
|
|
315
|
+
const self = this;
|
|
316
|
+
return Effect.gen(function* () {
|
|
317
|
+
const history = yield* Effect.promise(() => self.getHistory());
|
|
318
|
+
const blueprints = self.context.getBlueprints();
|
|
231
319
|
const toolkit = yield* createToolkit({
|
|
320
|
+
toolkit: self._toolkit,
|
|
232
321
|
blueprints
|
|
233
322
|
});
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
log("run", {
|
|
323
|
+
const objects = self.context.getObjects();
|
|
324
|
+
log2("run", {
|
|
237
325
|
history: history.length,
|
|
238
326
|
blueprints: blueprints.length,
|
|
239
|
-
|
|
240
|
-
|
|
327
|
+
tools: Object.keys(toolkit.tools).length,
|
|
328
|
+
objects: objects.length
|
|
241
329
|
}, {
|
|
242
330
|
F: __dxlog_file2,
|
|
243
|
-
L:
|
|
331
|
+
L: 99,
|
|
244
332
|
S: this,
|
|
245
333
|
C: (f, a) => f(...a)
|
|
246
334
|
});
|
|
335
|
+
const session = new AiSession();
|
|
247
336
|
const messages = yield* session.run({
|
|
248
337
|
history,
|
|
249
338
|
blueprints,
|
|
250
|
-
objects,
|
|
251
339
|
toolkit,
|
|
340
|
+
objects,
|
|
252
341
|
...params
|
|
253
342
|
}).pipe(Effect.provideService(AiContextService, {
|
|
254
|
-
binder:
|
|
343
|
+
binder: self.context
|
|
255
344
|
}));
|
|
256
|
-
|
|
345
|
+
log2("result", {
|
|
257
346
|
messages: messages.length,
|
|
258
|
-
duration:
|
|
347
|
+
duration: session.duration,
|
|
348
|
+
toolCalls: session.toolCalls
|
|
259
349
|
}, {
|
|
260
350
|
F: __dxlog_file2,
|
|
261
|
-
L:
|
|
351
|
+
L: 114,
|
|
262
352
|
S: this,
|
|
263
353
|
C: (f, a) => f(...a)
|
|
264
354
|
});
|
|
265
|
-
yield* Effect.promise(() =>
|
|
355
|
+
yield* Effect.promise(() => self._queue.append(messages));
|
|
266
356
|
return messages;
|
|
267
|
-
})
|
|
357
|
+
});
|
|
268
358
|
}
|
|
269
359
|
};
|
|
270
360
|
|
|
271
361
|
// src/diff.ts
|
|
272
362
|
import { next as A } from "@automerge/automerge";
|
|
273
363
|
import { DocAccessor, toCursorRange } from "@dxos/echo-db";
|
|
274
|
-
import { log as
|
|
364
|
+
import { log as log3 } from "@dxos/log";
|
|
275
365
|
import { isNonNullable } from "@dxos/util";
|
|
276
366
|
var __dxlog_file3 = "/__w/dxos/dxos/packages/core/assistant/src/diff.ts";
|
|
277
367
|
var reduceDiffs = (diffs) => {
|
|
@@ -325,7 +415,7 @@ var applyDiffs = (accessor, diffs) => {
|
|
|
325
415
|
if (idx !== -1) {
|
|
326
416
|
A.splice(doc, accessor.path, idx, diff.match.length, diff.replace);
|
|
327
417
|
} else {
|
|
328
|
-
|
|
418
|
+
log3.warn("diff not found", diff, {
|
|
329
419
|
F: __dxlog_file3,
|
|
330
420
|
L: 78,
|
|
331
421
|
S: void 0,
|
|
@@ -342,9 +432,13 @@ import { AgentStatus } from "@dxos/ai";
|
|
|
342
432
|
import { Obj as Obj3 } from "@dxos/echo";
|
|
343
433
|
import { MESSAGE_PROPERTY_TOOL_CALL_ID } from "@dxos/functions";
|
|
344
434
|
import { LogLevel } from "@dxos/log";
|
|
345
|
-
import { ContentBlock,
|
|
435
|
+
import { ContentBlock, Message as Message2 } from "@dxos/types";
|
|
346
436
|
import { isNonNullable as isNonNullable2 } from "@dxos/util";
|
|
437
|
+
var SKIP_BLOCKS = [
|
|
438
|
+
"text"
|
|
439
|
+
];
|
|
347
440
|
var ExecutionGraph = class {
|
|
441
|
+
_skipBlocks;
|
|
348
442
|
// TODO(dmaretskyi): Evolve the internal state to support chats, functions, circuit workflows, etc.
|
|
349
443
|
_commits = [];
|
|
350
444
|
_branchNames = /* @__PURE__ */ new Set();
|
|
@@ -353,13 +447,16 @@ var ExecutionGraph = class {
|
|
|
353
447
|
_toolCallCommitIds = /* @__PURE__ */ new Map();
|
|
354
448
|
_lastCommitByBranch = /* @__PURE__ */ new Map();
|
|
355
449
|
_pendingToolResults = /* @__PURE__ */ new Map();
|
|
450
|
+
constructor(_skipBlocks = SKIP_BLOCKS) {
|
|
451
|
+
this._skipBlocks = _skipBlocks;
|
|
452
|
+
}
|
|
356
453
|
/**
|
|
357
454
|
* Adds events to the graph.
|
|
358
455
|
*/
|
|
359
456
|
addEvents(events) {
|
|
360
457
|
const sortedEvents = this.sortObjectsByCreated(events);
|
|
361
458
|
for (const event of sortedEvents) {
|
|
362
|
-
if (Obj3.instanceOf(
|
|
459
|
+
if (Obj3.instanceOf(Message2.Message, event)) {
|
|
363
460
|
this._processMessage(event);
|
|
364
461
|
} else if (Obj3.instanceOf(AgentStatus, event)) {
|
|
365
462
|
this._processAgentStatus(event);
|
|
@@ -370,7 +467,7 @@ var ExecutionGraph = class {
|
|
|
370
467
|
* Processes a message event and creates commits for its blocks.
|
|
371
468
|
*/
|
|
372
469
|
_processMessage(message) {
|
|
373
|
-
const messageCommits = messageToCommits(message, this._lastBlockId, this._toolCallCommitIds, this._lastCommitByBranch);
|
|
470
|
+
const messageCommits = messageToCommits(message, this._lastBlockId, this._toolCallCommitIds, this._lastCommitByBranch, this._skipBlocks);
|
|
374
471
|
this._commits.push(...messageCommits);
|
|
375
472
|
messageCommits.forEach((commit) => this._branchNames.add(commit.branch));
|
|
376
473
|
this._trackToolCalls(messageCommits);
|
|
@@ -535,11 +632,14 @@ var ExecutionGraph = class {
|
|
|
535
632
|
return toolCallMatch?.[1] || toolResultMatch?.[1];
|
|
536
633
|
}
|
|
537
634
|
};
|
|
538
|
-
var messageToCommits = (message, lastBlockId, toolCallIds, lastCommitByBranch) => {
|
|
635
|
+
var messageToCommits = (message, lastBlockId, toolCallIds, lastCommitByBranch, skipBlocks) => {
|
|
539
636
|
let previousBlockId = lastBlockId;
|
|
540
637
|
return message.blocks.map((block, idx) => {
|
|
541
638
|
const branch = getMessageBranch(message);
|
|
542
639
|
const parents = getBlockParents(block, previousBlockId, message, toolCallIds, lastCommitByBranch);
|
|
640
|
+
if (skipBlocks?.includes(block._tag)) {
|
|
641
|
+
return null;
|
|
642
|
+
}
|
|
543
643
|
const commit = createBlockCommit(block, message, branch, parents, idx);
|
|
544
644
|
if (commit) {
|
|
545
645
|
previousBlockId = commit.id;
|
|
@@ -697,128 +797,14 @@ var stringifyObject = (obj) => {
|
|
|
697
797
|
return Obj3.getLabel(obj) ?? Obj3.getTypename(obj) ?? obj.id;
|
|
698
798
|
};
|
|
699
799
|
|
|
700
|
-
// src/functions/services.ts
|
|
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";
|
|
707
|
-
import { AiToolNotFoundError, ToolExecutionService, ToolResolverService } from "@dxos/ai";
|
|
708
|
-
import { todo } from "@dxos/debug";
|
|
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";
|
|
713
|
-
var makeToolResolverFromFunctions = (functions, toolkit) => {
|
|
714
|
-
return Layer.effect(ToolResolverService, Effect2.gen(function* () {
|
|
715
|
-
const dbService = yield* DatabaseService2;
|
|
716
|
-
return {
|
|
717
|
-
resolve: (id) => Effect2.gen(function* () {
|
|
718
|
-
const tool = toolkit.tools[id];
|
|
719
|
-
if (tool) {
|
|
720
|
-
return tool;
|
|
721
|
-
}
|
|
722
|
-
const { objects: [dbFunction] } = yield* DatabaseService2.runQuery(Query2.type(Function2.Function, {
|
|
723
|
-
key: id
|
|
724
|
-
}));
|
|
725
|
-
const functionDef = dbFunction ? FunctionDefinition.deserialize(dbFunction) : functions.find((fn2) => fn2.key === id);
|
|
726
|
-
if (!functionDef) {
|
|
727
|
-
return yield* Effect2.fail(new AiToolNotFoundError(id));
|
|
728
|
-
}
|
|
729
|
-
return projectFunctionToTool(functionDef);
|
|
730
|
-
}).pipe(Effect2.provideService(DatabaseService2, dbService))
|
|
731
|
-
};
|
|
732
|
-
}));
|
|
733
|
-
};
|
|
734
|
-
var makeToolExecutionServiceFromFunctions = (toolkit, handlersLayer) => {
|
|
735
|
-
return Layer.effect(ToolExecutionService, Effect2.gen(function* () {
|
|
736
|
-
const toolkitHandler = yield* toolkit.pipe(Effect2.provide(handlersLayer));
|
|
737
|
-
invariant2(isHandlerLike(toolkitHandler), void 0, {
|
|
738
|
-
F: __dxlog_file4,
|
|
739
|
-
L: 73,
|
|
740
|
-
S: this,
|
|
741
|
-
A: [
|
|
742
|
-
"isHandlerLike(toolkitHandler)",
|
|
743
|
-
""
|
|
744
|
-
]
|
|
745
|
-
});
|
|
746
|
-
const functionInvocationService = yield* FunctionInvocationService;
|
|
747
|
-
return {
|
|
748
|
-
handlersFor: (toolkit2) => {
|
|
749
|
-
const makeHandler = (tool) => {
|
|
750
|
-
return Effect2.fn(`toolFunctionHandler ${tool.name}`)(function* (input) {
|
|
751
|
-
if (toolkitHandler.tools[tool.name]) {
|
|
752
|
-
if (Tool.isProviderDefined(tool)) {
|
|
753
|
-
throw new Error("Attempted to call a provider-defined tool");
|
|
754
|
-
}
|
|
755
|
-
return yield* toolkitHandler.handle(tool.name, input);
|
|
756
|
-
}
|
|
757
|
-
const { definition: functionDef } = Context2.get(FunctionToolAnnotation)(tool.annotations);
|
|
758
|
-
return yield* functionInvocationService.invokeFunction(functionDef, input).pipe(Effect2.catchAllDefect((defect) => Effect2.fail(defect)));
|
|
759
|
-
});
|
|
760
|
-
};
|
|
761
|
-
return toolkit2.of(Record.map(toolkit2.tools, (tool, _name) => Tool.isUserDefined(tool) ? makeHandler(tool) : null));
|
|
762
|
-
}
|
|
763
|
-
};
|
|
764
|
-
}));
|
|
765
|
-
};
|
|
766
|
-
var FunctionToolAnnotation = class extends Context2.Tag("@dxos/assistant/FunctionToolAnnotation")() {
|
|
767
|
-
};
|
|
768
|
-
var toolCache = /* @__PURE__ */ new WeakMap();
|
|
769
|
-
var projectFunctionToTool = (fn2) => {
|
|
770
|
-
if (toolCache.has(fn2)) {
|
|
771
|
-
return toolCache.get(fn2);
|
|
772
|
-
}
|
|
773
|
-
const tool = Tool.make(makeToolName(fn2.name), {
|
|
774
|
-
description: fn2.description,
|
|
775
|
-
parameters: createStructFieldsFromSchema(fn2.inputSchema),
|
|
776
|
-
// TODO(dmaretskyi): Include output schema.
|
|
777
|
-
failure: Schema2.Any
|
|
778
|
-
}).annotate(FunctionToolAnnotation, {
|
|
779
|
-
definition: fn2
|
|
780
|
-
});
|
|
781
|
-
toolCache.set(fn2, tool);
|
|
782
|
-
return tool;
|
|
783
|
-
};
|
|
784
|
-
var makeToolName = (name) => {
|
|
785
|
-
const toolName = name.replace(/[^a-zA-Z0-9]/g, "_");
|
|
786
|
-
invariant2(toolName.match(/^[a-zA-Z_][a-zA-Z0-9-_]*$/), void 0, {
|
|
787
|
-
F: __dxlog_file4,
|
|
788
|
-
L: 140,
|
|
789
|
-
S: void 0,
|
|
790
|
-
A: [
|
|
791
|
-
"toolName.match(/^[a-zA-Z_][a-zA-Z0-9-_]*$/)",
|
|
792
|
-
""
|
|
793
|
-
]
|
|
794
|
-
});
|
|
795
|
-
return toolName;
|
|
796
|
-
};
|
|
797
|
-
var createStructFieldsFromSchema = (schema) => {
|
|
798
|
-
switch (schema.ast._tag) {
|
|
799
|
-
case "TypeLiteral":
|
|
800
|
-
return Object.fromEntries(schema.ast.propertySignatures.map((prop) => [
|
|
801
|
-
prop.name,
|
|
802
|
-
Schema2.make(prop.type)
|
|
803
|
-
]));
|
|
804
|
-
case "VoidKeyword":
|
|
805
|
-
return {};
|
|
806
|
-
default:
|
|
807
|
-
return todo(`Unsupported schema AST: ${schema.ast._tag}`);
|
|
808
|
-
}
|
|
809
|
-
};
|
|
810
|
-
var isHandlerLike = (value) => {
|
|
811
|
-
return typeof value.tools === "object" && typeof value.handle === "function";
|
|
812
|
-
};
|
|
813
|
-
|
|
814
800
|
// src/templates/system.ts
|
|
815
801
|
import defaultsDeep from "lodash.defaultsdeep";
|
|
816
802
|
import { Template } from "@dxos/blueprints";
|
|
817
803
|
|
|
818
|
-
// raw-loader:/__w/dxos/dxos/packages/core/assistant/src/templates/format.tpl?raw
|
|
819
|
-
var format_default = "{{! System Core }}\n\n## Input Formats\n\n### Blueprints\n\nYou may be provided with Blueprint definitions that include specific instructions and tools for a given set of tasks.\nBlue print instructions will be enclosed in a <blueprint> tag.\n\n### Context objects\n\nYou may be provided with references to objects that are relevant to the current prompt.\nObjects will be in the form of a <object> tag with a <dxn> element that is the unique key of the object required by many tools.\nThe <typename> element is the type of the object.\n\n<object>\n <dxn>object-id</dxn>\n <typename>example.com/type/TypeName</typename>\n</object>\n\n## Response Formats\n\nIt is very important to respond in the correct format.\nYou response must be valid Markdown.\nIn some cases you should respond with well-formed XML tags along with the content.\nCode snippets should use 2-space indents.\n\n{{#if cot}}\nBefore responding, explain your reasoning and include your detailed chain-of-thought enclosed in a <cot> tag.\nThe <cot> tag should be the first thing in your response.\n{{/if}}\n\n## Block references\n\nYou can reply with a block reference for objects if you have the DXN. For example:\n\n<object>\n <dxn>dxn:queue:data:B6INSIBY3CBEF4M5VZRYBCMAHQMPYK5AJ:01K24XMVHSZHS97SG1VTVQDM5Z:01K24XPK464FSCKVQJAB2H662M</dxn>\n</object>\n<object>\n <dxn>dxn:echo:@:01K24XPK464FSCKVQJAB2H662M</dxn>\n</object>\n\n### Suggestions\n\nEach suggestion must in the form of a proposed action enclosed in a <suggestion> tag.\nExample: <suggestion>Show on a map</suggestion>\n\n### Multiple choice questions\n\nYou may ask multiple choice questions by wrapping consise options inside <option> tags inside a well formed <select> tag.\nExample: <select><option>Yes</option><option>No</option></select>\n\n## Toolkit\n\nIf the user asks for a list of tools, then just emit a single self-closing <toolkit/> tag instead of listing the tools.\n\n## Context\n\nThe current date and time is {{DATETIME}}.\n";
|
|
804
|
+
// raw-loader:/__w/dxos/dxos/packages/core/assistant/src/templates/instructions/format.tpl?raw
|
|
805
|
+
var format_default = "{{! System Core }}\n\n## Input Formats\n\n### Blueprints\n\nYou may be provided with Blueprint definitions that include specific instructions and tools for a given set of tasks.\nBlue print instructions will be enclosed in a <blueprint> tag.\n\n### Context objects\n\nYou may be provided with references to objects that are relevant to the current prompt.\nObjects will be in the form of a <object> tag with a <dxn> element that is the unique key of the object required by many tools.\nThe <typename> element is the type of the object.\n\n<object>\n <dxn>object-id</dxn>\n <typename>example.com/type/TypeName</typename>\n</object>\n\n## Response Formats\n\nIt is very important to respond in the correct format.\nYou response must be valid Markdown.\nIn some cases you should respond with well-formed XML tags along with the content.\nCode snippets should use 2-space indents.\n\n{{#if cot}}\nBefore responding, explain your reasoning and include your detailed chain-of-thought enclosed in a <cot> tag.\nThe <cot> tag should be the first thing in your response.\n{{/if}}\n\n## Block references\n\nYou can reply with a block reference for objects if you have the DXN. For example:\n\n<object>\n <dxn>dxn:queue:data:B6INSIBY3CBEF4M5VZRYBCMAHQMPYK5AJ:01K24XMVHSZHS97SG1VTVQDM5Z:01K24XPK464FSCKVQJAB2H662M</dxn>\n</object>\n<object>\n <dxn>dxn:echo:@:01K24XPK464FSCKVQJAB2H662M</dxn>\n</object>\n\n### Suggestions\n\nEach suggestion must in the form of a proposed action enclosed in a <suggestion> tag.\nExample: <suggestion>Show on a map</suggestion>\nDo not use bullets when listing suggestions.\n\n### Multiple choice questions\n\nYou may ask multiple choice questions by wrapping consise options inside <option> tags inside a well formed <select> tag.\nExample: <select><option>Yes</option><option>No</option></select>\n\n## Toolkit\n\nIf the user asks for a list of tools, then just emit a single self-closing <toolkit/> tag instead of listing the tools.\n\n## Context\n\nThe current date and time is {{DATETIME}}.\n";
|
|
820
806
|
|
|
821
|
-
// raw-loader:/__w/dxos/dxos/packages/core/assistant/src/templates/system.tpl?raw
|
|
807
|
+
// raw-loader:/__w/dxos/dxos/packages/core/assistant/src/templates/instructions/system.tpl?raw
|
|
822
808
|
var system_default = "{{! System Prompt }}\n\n- You are a helpful assistant called Kai. \n- Your name is Kai and you are powered by different language models.\n- You were created by DXOS and operate inside of Composer and on the DXOS EDGE network.\n- In your initial greeting state your name and make some suggestions based on the current context objects.\n- You are an advanced AI assistant capable of creating and managing artifacts from provided data and tools.\n- Your task is to process user commands and questions and decide how best to respond.\n- In general be concise and direct.\n- Follow all instructions carefully.\n\n## Planning\n\n- Analyze the structure and type of the content in the user's message.\n- Determine if you complete the task using the available blueprint definitions?\n- If you can't complete the task using the available blueprint definitions, query the list of available blueprint definitions using the appropriate tool.\n- Identify which blueprint definitions are relevant to the user's request.\n- Evaluate the potential benefits of creating an artifact vs. normal processing for each identified element.\n- Make a final decision on whether to create an artifact and explain your reasoning.\n- Are the required blueprint definitions already available?\n- If not, select which blueprint definition(s) will be the most relevant and require them using the require_artifact_definitions tool.\n- The require'd artifact tools will be available for use after require.\n- If creating an artifact, outline how you will structure it within the response.\n- Decide if the artifact needs to be shown to the user.\n- Call the show tool to show the artifact to the user.\n- Your reasoning must include: whether to use artifacts or not, to create one or query, whether to show the artifact to the user, and how to structure the response.\n\n## Blueprints and Artifacts\n\n- Determine if the interaction involves an artifact. Prefer artifacts for tables, lists, spreadsheets, kanbans, games, images, and other structured data.\n- Determine if the user is explicitly talking about creating a new artifact, or wants to use an existing artifact.\n- If it is ambiguous, query for existing artifacts first and then decide.\n- If you decide to create an artifact, call the associated tool to create the artifact.\n- Artifacts are stored in the database. Tools are used to create and query artifacts.\n- If you are unsure about creating an artifact ask the user for clarification.\n- Artifacts are mutable objects that can change over the course of the conversation.\n- Always re-query the artifact using the tool (like query or inspect) to get the latest state of the artifact before answering the user.\n- You must never generate the id of the artifact; only recall the ids that are already in the history.\n- Artifacts are created by requiring the specific artifact using the require_artifact tool and creating it by calling the associated tool.\n- You can add suggested actions at the end of your response.\n- Suggested actions should be very concise and start with a verb and be phrased as a command to an agent -- not a question to the user.\n- Suggested actions must be in the form of a user instruction that you can follow.\n- Suggested actions could include actions that create artifacts.\n- After creating an artifact use a tool to add it to the chat context.\n\n## Context\n\nToday is {{DATETIME}}.\n";
|
|
823
809
|
|
|
824
810
|
// src/templates/system.ts
|
|
@@ -835,44 +821,6 @@ var templates = {
|
|
|
835
821
|
source: system_default
|
|
836
822
|
})
|
|
837
823
|
};
|
|
838
|
-
|
|
839
|
-
// src/types/artifact.ts
|
|
840
|
-
import * as Schema3 from "effect/Schema";
|
|
841
|
-
import { DXN as DXN2, LOCAL_SPACE_TAG } from "@dxos/keys";
|
|
842
|
-
import { trim } from "@dxos/util";
|
|
843
|
-
var createArtifactElement = (id) => `<artifact id=${id} />`;
|
|
844
|
-
var ArtifactId = class extends Schema3.String.annotations({
|
|
845
|
-
description: trim`
|
|
846
|
-
The ID of the referenced object. Formats accepted:
|
|
847
|
-
- DXN (dxn:echo:@:XXXXX). DXNs can be prepended with an @ symbol for compatibility with in-text references.
|
|
848
|
-
- space ID, object ID tuple (spaceID:objectID)
|
|
849
|
-
- Only object ID that is assumed to be in the current space (XXXXX)
|
|
850
|
-
`,
|
|
851
|
-
examples: [
|
|
852
|
-
"dxn:echo:@:XXXXX",
|
|
853
|
-
"@dxn:echo:@:XXXXX",
|
|
854
|
-
"spaceID:objectID",
|
|
855
|
-
"XXXXX"
|
|
856
|
-
]
|
|
857
|
-
}) {
|
|
858
|
-
static toDXN(reference, owningSpaceId) {
|
|
859
|
-
if (reference.startsWith("@dxn:")) {
|
|
860
|
-
return DXN2.parse(reference.slice(1));
|
|
861
|
-
} else if (reference.startsWith("dxn:")) {
|
|
862
|
-
return DXN2.parse(reference);
|
|
863
|
-
} else if (/^[A-Z0-9]+:[A-Z0-9]+$/.test(reference)) {
|
|
864
|
-
const [spaceId, objectId] = reference.split(":");
|
|
865
|
-
return new DXN2(DXN2.kind.ECHO, [
|
|
866
|
-
spaceId === owningSpaceId ? LOCAL_SPACE_TAG : spaceId,
|
|
867
|
-
objectId
|
|
868
|
-
]);
|
|
869
|
-
} else if (/^[A-Z0-9]+$/.test(reference)) {
|
|
870
|
-
return DXN2.fromLocalObjectId(reference);
|
|
871
|
-
} else {
|
|
872
|
-
throw new Error(`Unable to parse object reference: ${reference}`);
|
|
873
|
-
}
|
|
874
|
-
}
|
|
875
|
-
};
|
|
876
824
|
export {
|
|
877
825
|
AiAssistantError,
|
|
878
826
|
AiContextBinder,
|
|
@@ -886,6 +834,8 @@ export {
|
|
|
886
834
|
ContextBinding,
|
|
887
835
|
ExecutionGraph,
|
|
888
836
|
GenerationObserver,
|
|
837
|
+
GenericToolkit_exports as GenericToolkit,
|
|
838
|
+
RefFromLLM,
|
|
889
839
|
VersionPin,
|
|
890
840
|
applyDiffs,
|
|
891
841
|
computeDiffsWithCursors,
|