@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
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
2
|
|
|
3
3
|
// src/session/artifact-diff.ts
|
|
4
|
-
import
|
|
4
|
+
import * as Context from "effect/Context";
|
|
5
5
|
var ArtifactDiffResolver = class extends Context.Tag("@dxos/assistant/ArtifactDiffResolver")() {
|
|
6
6
|
};
|
|
7
7
|
|
|
8
8
|
// src/session/observer.ts
|
|
9
|
-
import
|
|
9
|
+
import * as Effect from "effect/Effect";
|
|
10
|
+
import * as Function from "effect/Function";
|
|
10
11
|
var GenerationObserver = Object.freeze({
|
|
11
12
|
make: ({ onBegin = Function.constant(Effect.void), onPart = Function.constant(Effect.void), onBlock = Function.constant(Effect.void), onEnd = Function.constant(Effect.void), onMessage = Function.constant(Effect.void) } = {}) => ({
|
|
12
13
|
onBegin,
|
|
@@ -43,8 +44,10 @@ var AiAssistantError = class extends BaseError.extend("AI_ASSISTANT_ERROR", "AI
|
|
|
43
44
|
};
|
|
44
45
|
|
|
45
46
|
// src/session/session.ts
|
|
46
|
-
import
|
|
47
|
-
import
|
|
47
|
+
import * as LanguageModel from "@effect/ai/LanguageModel";
|
|
48
|
+
import * as Chunk from "effect/Chunk";
|
|
49
|
+
import * as Effect3 from "effect/Effect";
|
|
50
|
+
import * as Stream from "effect/Stream";
|
|
48
51
|
import { AiParser, AiPreprocessor, callTool, getToolCalls } from "@dxos/ai";
|
|
49
52
|
import { todo } from "@dxos/debug";
|
|
50
53
|
import { Obj as Obj2 } from "@dxos/echo";
|
|
@@ -53,7 +56,10 @@ import { log as log2 } from "@dxos/log";
|
|
|
53
56
|
import { DataType as DataType2 } from "@dxos/schema";
|
|
54
57
|
|
|
55
58
|
// src/session/format.ts
|
|
56
|
-
import
|
|
59
|
+
import * as Array from "effect/Array";
|
|
60
|
+
import * as Effect2 from "effect/Effect";
|
|
61
|
+
import * as Function2 from "effect/Function";
|
|
62
|
+
import * as Option from "effect/Option";
|
|
57
63
|
import { Template } from "@dxos/blueprints";
|
|
58
64
|
import { Obj } from "@dxos/echo";
|
|
59
65
|
import { ObjectVersion } from "@dxos/echo-db";
|
|
@@ -63,7 +69,7 @@ import { DataType } from "@dxos/schema";
|
|
|
63
69
|
import { trim } from "@dxos/util";
|
|
64
70
|
var __dxlog_file = "/__w/dxos/dxos/packages/core/assistant/src/session/format.ts";
|
|
65
71
|
var formatSystemPrompt = ({ system, blueprints = [], objects = [] }) => Effect2.gen(function* () {
|
|
66
|
-
const blueprintDefs = yield* pipe(blueprints, Effect2.forEach((blueprint) => Effect2.succeed(blueprint.instructions)), Effect2.flatMap(Effect2.forEach((template) => DatabaseService.loadOption(template.source))), Effect2.map(Array.filter(Option.isSome)), Effect2.map(Array.map((template) => trim`
|
|
72
|
+
const blueprintDefs = yield* Function2.pipe(blueprints, Effect2.forEach((blueprint) => Effect2.succeed(blueprint.instructions)), Effect2.flatMap(Effect2.forEach((template) => DatabaseService.loadOption(template.source))), Effect2.map(Array.filter(Option.isSome)), Effect2.map(Array.map((template) => trim`
|
|
67
73
|
<blueprint>
|
|
68
74
|
${Template.process(template.value.content)}
|
|
69
75
|
</blueprint>
|
|
@@ -71,7 +77,7 @@ var formatSystemPrompt = ({ system, blueprints = [], objects = [] }) => Effect2.
|
|
|
71
77
|
"## Blueprints Definitions",
|
|
72
78
|
...blueprints2
|
|
73
79
|
].join("\n\n") : void 0));
|
|
74
|
-
const objectDefs = yield* pipe(objects, Effect2.forEach((object) => Effect2.succeed(trim`
|
|
80
|
+
const objectDefs = yield* Function2.pipe(objects, Effect2.forEach((object) => Effect2.succeed(trim`
|
|
75
81
|
<object>
|
|
76
82
|
<dxn>${Obj.getDXN(object)}</dxn>
|
|
77
83
|
<typename>${Obj.getTypename(object)}</typename>
|
|
@@ -80,7 +86,7 @@ var formatSystemPrompt = ({ system, blueprints = [], objects = [] }) => Effect2.
|
|
|
80
86
|
"## Context Objects",
|
|
81
87
|
...objects2
|
|
82
88
|
].join("\n\n") : void 0));
|
|
83
|
-
return yield* pipe(Effect2.succeed([
|
|
89
|
+
return yield* Function2.pipe(Effect2.succeed([
|
|
84
90
|
system,
|
|
85
91
|
blueprintDefs,
|
|
86
92
|
objectDefs
|
|
@@ -107,7 +113,7 @@ var formatUserPrompt = ({ prompt, history = [] }) => Effect2.gen(function* () {
|
|
|
107
113
|
versions
|
|
108
114
|
}, {
|
|
109
115
|
F: __dxlog_file,
|
|
110
|
-
L:
|
|
116
|
+
L: 93,
|
|
111
117
|
S: this,
|
|
112
118
|
C: (f, a) => f(...a)
|
|
113
119
|
});
|
|
@@ -169,134 +175,121 @@ ${diff}` : ""}</changed-artifact>`).join("\n")}
|
|
|
169
175
|
};
|
|
170
176
|
|
|
171
177
|
// src/session/session.ts
|
|
172
|
-
function _define_property(obj, key, value) {
|
|
173
|
-
if (key in obj) {
|
|
174
|
-
Object.defineProperty(obj, key, {
|
|
175
|
-
value,
|
|
176
|
-
enumerable: true,
|
|
177
|
-
configurable: true,
|
|
178
|
-
writable: true
|
|
179
|
-
});
|
|
180
|
-
} else {
|
|
181
|
-
obj[key] = value;
|
|
182
|
-
}
|
|
183
|
-
return obj;
|
|
184
|
-
}
|
|
185
178
|
var __dxlog_file2 = "/__w/dxos/dxos/packages/core/assistant/src/session/session.ts";
|
|
186
179
|
var AiSession = class {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
180
|
+
_options;
|
|
181
|
+
/** Prevents concurrent execution of session. */
|
|
182
|
+
_semaphore = Effect3.runSync(Effect3.makeSemaphore(1));
|
|
183
|
+
/** Message history from queue. */
|
|
184
|
+
// TODO(burdon): Evolve into supporting a git-like graph of messages.
|
|
185
|
+
_history = [];
|
|
186
|
+
/** Pending messages for this session (incl. the current prompt). */
|
|
187
|
+
_pending = [];
|
|
194
188
|
constructor(_options = {}) {
|
|
195
|
-
_define_property(this, "_options", void 0);
|
|
196
|
-
_define_property(this, "_semaphore", void 0);
|
|
197
|
-
_define_property(this, "_history", void 0);
|
|
198
|
-
_define_property(this, "_pending", void 0);
|
|
199
|
-
_define_property(this, "run", void 0);
|
|
200
189
|
this._options = _options;
|
|
201
|
-
|
|
202
|
-
|
|
190
|
+
}
|
|
191
|
+
run = ({ prompt, system: systemTemplate, history = [], objects = [], blueprints = [], toolkit, observer = GenerationObserver.noop() }) => Effect3.gen(this, function* () {
|
|
192
|
+
this._history = [
|
|
193
|
+
...history
|
|
194
|
+
];
|
|
203
195
|
this._pending = [];
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
length: system.length
|
|
231
|
-
},
|
|
232
|
-
pending: this._pending.length,
|
|
233
|
-
history: this._history.length,
|
|
234
|
-
objects: objects?.length ?? 0
|
|
235
|
-
}, {
|
|
236
|
-
F: __dxlog_file2,
|
|
237
|
-
L: 103,
|
|
238
|
-
S: this,
|
|
239
|
-
C: (f, a) => f(...a)
|
|
240
|
-
});
|
|
241
|
-
const prompt2 = yield* AiPreprocessor.preprocessPrompt([
|
|
242
|
-
...this._history,
|
|
243
|
-
...this._pending
|
|
244
|
-
], {
|
|
245
|
-
system
|
|
246
|
-
});
|
|
247
|
-
const blocks = yield* LanguageModel.streamText({
|
|
248
|
-
prompt: prompt2,
|
|
249
|
-
toolkit,
|
|
250
|
-
disableToolCallResolution: true
|
|
251
|
-
}).pipe(
|
|
252
|
-
// TOOD(dmaretskyi): Error mapping.
|
|
253
|
-
AiParser.parseResponse({
|
|
254
|
-
onBegin: () => observer.onBegin(),
|
|
255
|
-
onBlock: (block) => observer.onBlock(block),
|
|
256
|
-
onPart: (part) => observer.onPart(part),
|
|
257
|
-
onEnd: (summary) => observer.onEnd(summary)
|
|
258
|
-
}),
|
|
259
|
-
Stream.runCollect,
|
|
260
|
-
Effect3.map(Chunk.toArray)
|
|
261
|
-
);
|
|
262
|
-
const response = yield* submitMessage(Obj2.make(DataType2.Message, {
|
|
263
|
-
created: (/* @__PURE__ */ new Date()).toISOString(),
|
|
264
|
-
sender: {
|
|
265
|
-
role: "assistant"
|
|
266
|
-
},
|
|
267
|
-
blocks
|
|
268
|
-
}));
|
|
269
|
-
const toolCalls = getToolCalls(response);
|
|
270
|
-
if (toolCalls.length === 0) {
|
|
271
|
-
break;
|
|
272
|
-
} else if (!toolkit) {
|
|
273
|
-
throw new Error("No toolkit provided");
|
|
274
|
-
}
|
|
275
|
-
const toolResults = yield* Effect3.forEach(toolCalls, (toolCall) => {
|
|
276
|
-
return callTool(toolkit, toolCall).pipe(Effect3.provide(TracingService.layerSubframe((context) => ({
|
|
277
|
-
...context,
|
|
278
|
-
parentMessage: response.id,
|
|
279
|
-
toolCallId: toolCall.toolCallId
|
|
280
|
-
}))));
|
|
281
|
-
});
|
|
282
|
-
yield* submitMessage(Obj2.make(DataType2.Message, {
|
|
283
|
-
created: (/* @__PURE__ */ new Date()).toISOString(),
|
|
284
|
-
sender: {
|
|
285
|
-
role: "tool"
|
|
286
|
-
},
|
|
287
|
-
blocks: toolResults
|
|
288
|
-
}));
|
|
289
|
-
} while (true);
|
|
290
|
-
log2("done", {
|
|
291
|
-
pending: this._pending.length
|
|
196
|
+
const pending = this._pending;
|
|
197
|
+
const submitMessage = Effect3.fnUntraced(function* (message) {
|
|
198
|
+
pending.push(message);
|
|
199
|
+
yield* observer.onMessage(message);
|
|
200
|
+
yield* TracingService.emitConverationMessage(message);
|
|
201
|
+
return message;
|
|
202
|
+
});
|
|
203
|
+
const promptMessage = yield* submitMessage(yield* formatUserPrompt({
|
|
204
|
+
prompt,
|
|
205
|
+
history
|
|
206
|
+
}));
|
|
207
|
+
const system = yield* formatSystemPrompt({
|
|
208
|
+
system: systemTemplate,
|
|
209
|
+
blueprints,
|
|
210
|
+
objects
|
|
211
|
+
});
|
|
212
|
+
do {
|
|
213
|
+
log2("request", {
|
|
214
|
+
prompt: promptMessage,
|
|
215
|
+
system: {
|
|
216
|
+
snippet: createSnippet(system),
|
|
217
|
+
length: system.length
|
|
218
|
+
},
|
|
219
|
+
pending: this._pending.length,
|
|
220
|
+
history: this._history.length,
|
|
221
|
+
objects: objects?.length ?? 0
|
|
292
222
|
}, {
|
|
293
223
|
F: __dxlog_file2,
|
|
294
|
-
L:
|
|
224
|
+
L: 110,
|
|
295
225
|
S: this,
|
|
296
226
|
C: (f, a) => f(...a)
|
|
297
227
|
});
|
|
298
|
-
|
|
299
|
-
|
|
228
|
+
const prompt2 = yield* AiPreprocessor.preprocessPrompt([
|
|
229
|
+
...this._history,
|
|
230
|
+
...this._pending
|
|
231
|
+
], {
|
|
232
|
+
system
|
|
233
|
+
});
|
|
234
|
+
const blocks = yield* LanguageModel.streamText({
|
|
235
|
+
prompt: prompt2,
|
|
236
|
+
toolkit,
|
|
237
|
+
disableToolCallResolution: true
|
|
238
|
+
}).pipe(
|
|
239
|
+
// TOOD(dmaretskyi): Error mapping.
|
|
240
|
+
AiParser.parseResponse({
|
|
241
|
+
onBegin: () => observer.onBegin(),
|
|
242
|
+
onBlock: (block) => observer.onBlock(block),
|
|
243
|
+
onPart: (part) => observer.onPart(part),
|
|
244
|
+
onEnd: (summary) => observer.onEnd(summary)
|
|
245
|
+
}),
|
|
246
|
+
Stream.runCollect,
|
|
247
|
+
Effect3.map(Chunk.toArray)
|
|
248
|
+
);
|
|
249
|
+
const response = yield* submitMessage(Obj2.make(DataType2.Message, {
|
|
250
|
+
created: (/* @__PURE__ */ new Date()).toISOString(),
|
|
251
|
+
sender: {
|
|
252
|
+
role: "assistant"
|
|
253
|
+
},
|
|
254
|
+
blocks
|
|
255
|
+
}));
|
|
256
|
+
const toolCalls = getToolCalls(response);
|
|
257
|
+
if (toolCalls.length === 0) {
|
|
258
|
+
break;
|
|
259
|
+
} else if (!toolkit) {
|
|
260
|
+
throw new Error("No toolkit provided");
|
|
261
|
+
}
|
|
262
|
+
const toolResults = yield* Effect3.forEach(toolCalls, (toolCall) => {
|
|
263
|
+
return callTool(toolkit, toolCall).pipe(Effect3.provide(TracingService.layerSubframe((context) => ({
|
|
264
|
+
...context,
|
|
265
|
+
parentMessage: response.id,
|
|
266
|
+
toolCallId: toolCall.toolCallId
|
|
267
|
+
}))));
|
|
268
|
+
});
|
|
269
|
+
yield* submitMessage(Obj2.make(DataType2.Message, {
|
|
270
|
+
created: (/* @__PURE__ */ new Date()).toISOString(),
|
|
271
|
+
sender: {
|
|
272
|
+
role: "tool"
|
|
273
|
+
},
|
|
274
|
+
blocks: toolResults
|
|
275
|
+
}));
|
|
276
|
+
} while (true);
|
|
277
|
+
log2("done", {
|
|
278
|
+
pending: this._pending.length
|
|
279
|
+
}, {
|
|
280
|
+
F: __dxlog_file2,
|
|
281
|
+
L: 181,
|
|
282
|
+
S: this,
|
|
283
|
+
C: (f, a) => f(...a)
|
|
284
|
+
});
|
|
285
|
+
return this._pending;
|
|
286
|
+
}).pipe(this._semaphore.withPermits(1), Effect3.withSpan("AiSession.run"));
|
|
287
|
+
/**
|
|
288
|
+
* @deprecated
|
|
289
|
+
*/
|
|
290
|
+
// TODO(burdon): Implement or remove.
|
|
291
|
+
async runStructured(_schema, _options) {
|
|
292
|
+
return todo();
|
|
300
293
|
}
|
|
301
294
|
};
|
|
302
295
|
var createSnippet = (text, len = 32) => text.length <= len * 2 ? text : [
|
|
@@ -306,8 +299,8 @@ var createSnippet = (text, len = 32) => text.length <= len * 2 ? text : [
|
|
|
306
299
|
].join("");
|
|
307
300
|
|
|
308
301
|
// src/session/toolkit.ts
|
|
309
|
-
import
|
|
310
|
-
import
|
|
302
|
+
import * as Toolkit from "@effect/ai/Toolkit";
|
|
303
|
+
import * as Effect4 from "effect/Effect";
|
|
311
304
|
import { ToolExecutionService, ToolResolverService } from "@dxos/ai";
|
|
312
305
|
import { isTruthy } from "@dxos/util";
|
|
313
306
|
var createToolkit = ({ toolkit: toolkitParam, toolIds = [], blueprints = [] }) => Effect4.gen(function* () {
|
|
@@ -324,23 +317,9 @@ var createToolkit = ({ toolkit: toolkitParam, toolIds = [], blueprints = [] }) =
|
|
|
324
317
|
});
|
|
325
318
|
|
|
326
319
|
// src/session/version-pin.ts
|
|
327
|
-
import
|
|
320
|
+
import * as Schema from "effect/Schema";
|
|
321
|
+
import { ObjectId } from "@dxos/echo/internal";
|
|
328
322
|
import { getVersion } from "@dxos/echo-db";
|
|
329
|
-
import { ObjectId } from "@dxos/echo-schema";
|
|
330
|
-
function _define_property2(obj, key, value) {
|
|
331
|
-
if (key in obj) {
|
|
332
|
-
Object.defineProperty(obj, key, {
|
|
333
|
-
value,
|
|
334
|
-
enumerable: true,
|
|
335
|
-
configurable: true,
|
|
336
|
-
writable: true
|
|
337
|
-
});
|
|
338
|
-
} else {
|
|
339
|
-
obj[key] = value;
|
|
340
|
-
}
|
|
341
|
-
return obj;
|
|
342
|
-
}
|
|
343
|
-
var _class;
|
|
344
323
|
var ObjectVersionSchema = Schema.Unknown;
|
|
345
324
|
var VersionPinSchema = Schema.Struct({
|
|
346
325
|
// TODO(dmaretskyi): Use Ref when those support encoding.
|
|
@@ -348,7 +327,8 @@ var VersionPinSchema = Schema.Struct({
|
|
|
348
327
|
// TODO(dmaretskyi): Could be opaque.
|
|
349
328
|
version: ObjectVersionSchema
|
|
350
329
|
});
|
|
351
|
-
var VersionPin =
|
|
330
|
+
var VersionPin = class extends VersionPinSchema {
|
|
331
|
+
static DISPOSITION = "version-pin";
|
|
352
332
|
static fromObject(object) {
|
|
353
333
|
return VersionPin.make({
|
|
354
334
|
objectId: object.id,
|
|
@@ -362,7 +342,7 @@ var VersionPin = (_class = class extends VersionPinSchema {
|
|
|
362
342
|
data: JSON.stringify(pin)
|
|
363
343
|
};
|
|
364
344
|
}
|
|
365
|
-
}
|
|
345
|
+
};
|
|
366
346
|
|
|
367
347
|
export {
|
|
368
348
|
ArtifactDiffResolver,
|
|
@@ -373,4 +353,4 @@ export {
|
|
|
373
353
|
createToolkit,
|
|
374
354
|
VersionPin
|
|
375
355
|
};
|
|
376
|
-
//# sourceMappingURL=chunk-
|
|
356
|
+
//# sourceMappingURL=chunk-AUUC7II4.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/session/artifact-diff.ts", "../../../src/session/observer.ts", "../../../src/errors.ts", "../../../src/session/session.ts", "../../../src/session/format.ts", "../../../src/session/toolkit.ts", "../../../src/session/version-pin.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Context from 'effect/Context';\n\nimport { type ObjectId } from '@dxos/echo/internal';\nimport { type ObjectVersion } from '@dxos/echo-db';\n\n/**\n * Resolves artifact ids to their versions.\n * Used to give the model a sense of the changes to the artifacts made by users during the conversation.\n * The artifacts versions are pinned in the history, and whenever the artifact changes in-between assistant's steps,\n * a diff is inserted into the conversation.\n *\n * Can be optionally provided to the session run call.\n */\n// TODO(dmaretskyi): Convert to Context.Reference\nexport class ArtifactDiffResolver extends Context.Tag('@dxos/assistant/ArtifactDiffResolver')<\n ArtifactDiffResolver,\n ArtifactDiffResolver.Service\n>() {}\n\nexport namespace ArtifactDiffResolver {\n export type Service = {\n resolve: (\n artifacts: {\n id: ObjectId;\n lastVersion: ObjectVersion;\n }[],\n ) => Promise<\n Map<\n ObjectId,\n {\n version: ObjectVersion;\n diff?: string;\n }\n >\n >;\n };\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Effect from 'effect/Effect';\nimport * as Function from 'effect/Function';\n\nimport { type AiParser, type ConsolePrinter } from '@dxos/ai';\nimport { type DataType } from '@dxos/schema';\n\n/**\n * Live observer of the generation process.\n */\nexport interface GenerationObserver extends AiParser.ParseResponseCallbacks {\n /**\n * Complete messages fired during the session, both from the model and from the user.\n * This message will contain all message blocks emitted through the `onBlock` callback.\n */\n onMessage: (message: DataType.Message) => Effect.Effect<void>;\n}\n\nexport const GenerationObserver = Object.freeze({\n make: ({\n onBegin = Function.constant(Effect.void),\n onPart = Function.constant(Effect.void),\n onBlock = Function.constant(Effect.void),\n onEnd = Function.constant(Effect.void),\n onMessage = Function.constant(Effect.void),\n }: Partial<GenerationObserver> = {}): GenerationObserver => ({\n onBegin,\n onPart,\n onBlock,\n onEnd,\n onMessage,\n }),\n\n noop: () => GenerationObserver.make(),\n\n /**\n * Debug printer to be used in unit-tests and browser devtools.\n */\n fromPrinter: (printer: ConsolePrinter) =>\n GenerationObserver.make({\n onBlock: (block) =>\n Effect.sync(() => {\n if (block.pending) {\n return; // Only prints full blocks (better for unit-tests and browser devtools).\n }\n printer.printContentBlock(block);\n }),\n onMessage: (message) =>\n Effect.sync(() => {\n if (message.sender.role === 'assistant') {\n return; // Skip assistant messages since they are printed in the `onBlock` callback.\n }\n printer.printMessage(message);\n }),\n }),\n});\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { BaseError } from '@dxos/errors';\n\n/**\n * Generic error from AI model.\n */\nexport class AiModelError extends BaseError.extend('AI_MODEL_ERROR', 'AI model error') {}\n\n/**\n * Generic error for AI agent execution.\n */\nexport class AiAssistantError extends BaseError.extend('AI_ASSISTANT_ERROR', 'AI assistant error') {}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport type * as AiError from '@effect/ai/AiError';\nimport * as LanguageModel from '@effect/ai/LanguageModel';\nimport type * as Tool from '@effect/ai/Tool';\nimport type * as Toolkit from '@effect/ai/Toolkit';\nimport * as Chunk from 'effect/Chunk';\nimport * as Effect from 'effect/Effect';\nimport type * as Schema from 'effect/Schema';\nimport * as Stream from 'effect/Stream';\n\nimport {\n AiParser,\n AiPreprocessor,\n type AiToolNotFoundError,\n type PromptPreprocessingError,\n type ToolExecutionService,\n type ToolResolverService,\n callTool,\n getToolCalls,\n} from '@dxos/ai';\nimport { type Blueprint } from '@dxos/blueprints';\nimport { todo } from '@dxos/debug';\nimport { Obj } from '@dxos/echo';\nimport { TracingService } from '@dxos/functions';\nimport { log } from '@dxos/log';\nimport { DataType } from '@dxos/schema';\n\nimport { type AiAssistantError } from '../errors';\n\nimport { formatSystemPrompt, formatUserPrompt } from './format';\nimport { GenerationObserver } from './observer';\n\nexport type AiSessionRunError = AiError.AiError | PromptPreprocessingError | AiToolNotFoundError | AiAssistantError;\n\nexport type AiSessionRunRequirements =\n | LanguageModel.LanguageModel\n | ToolExecutionService\n | ToolResolverService\n | TracingService;\n\nexport type AiSessionRunParams<Tools extends Record<string, Tool.Any>> = {\n prompt: string;\n // TODO(wittjosiah): Rename to systemPrompt.\n system?: string;\n history?: DataType.Message[];\n objects?: Obj.Any[];\n blueprints?: Blueprint.Blueprint[];\n toolkit?: Toolkit.WithHandler<Tools>;\n observer?: GenerationObserver;\n};\n\nexport type AiSessionOptions = {};\n\n/**\n * Contains message history, tools, current context.\n * Current context means the state of the app, time of day, and other contextual information.\n * It makes requests to the model, its a state machine.\n * It keeps track of the current goal.\n * It manages the context window.\n * Tracks the success criteria of reaching the goal, exposing metrics (stretch).\n * Could be run locally in the app or remotely.\n * Could be personal or shared.\n */\nexport class AiSession {\n /** Prevents concurrent execution of session. */\n private readonly _semaphore = Effect.runSync(Effect.makeSemaphore(1));\n\n /** Message history from queue. */\n // TODO(burdon): Evolve into supporting a git-like graph of messages.\n private _history: DataType.Message[] = [];\n\n /** Pending messages for this session (incl. the current prompt). */\n private _pending: DataType.Message[] = [];\n\n constructor(private readonly _options: AiSessionOptions = {}) {}\n\n run = <Tools extends Record<string, Tool.Any>>({\n prompt,\n system: systemTemplate,\n history = [],\n objects = [],\n blueprints = [],\n toolkit,\n observer = GenerationObserver.noop(),\n }: AiSessionRunParams<Tools>): Effect.Effect<DataType.Message[], AiSessionRunError, AiSessionRunRequirements> =>\n Effect.gen(this, function* () {\n this._history = [...history];\n this._pending = [];\n const pending = this._pending;\n\n const submitMessage = Effect.fnUntraced(function* (message: DataType.Message) {\n pending.push(message);\n yield* observer.onMessage(message);\n yield* TracingService.emitConverationMessage(message);\n return message;\n });\n\n // Submit the prompt.\n // TODO(burdon): Remove if cancelled?\n const promptMessage = yield* submitMessage(yield* formatUserPrompt({ prompt, history }));\n\n // Generate system and prompt messages.\n const system = yield* formatSystemPrompt({ system: systemTemplate, blueprints, objects });\n\n // Tool call loop.\n do {\n log('request', {\n prompt: promptMessage,\n system: { snippet: createSnippet(system), length: system.length },\n pending: this._pending.length,\n history: this._history.length,\n objects: objects?.length ?? 0,\n });\n\n const prompt = yield* AiPreprocessor.preprocessPrompt([...this._history, ...this._pending], { system });\n\n // Execute the stream request.\n // logDump('prompt', Prompt.Prompt.pipe(Schema.encodeSync)(prompt));\n const blocks = yield* LanguageModel.streamText({\n prompt,\n toolkit,\n disableToolCallResolution: true,\n }).pipe(\n // TOOD(dmaretskyi): Error mapping.\n AiParser.parseResponse({\n onBegin: () => observer.onBegin(),\n onBlock: (block) => observer.onBlock(block),\n onPart: (part) => observer.onPart(part),\n onEnd: (summary) => observer.onEnd(summary),\n }),\n Stream.runCollect,\n Effect.map(Chunk.toArray),\n );\n\n // Create the response message.\n const response = yield* submitMessage(\n Obj.make(DataType.Message, {\n created: new Date().toISOString(),\n sender: { role: 'assistant' },\n blocks,\n }),\n );\n\n // Parse the response for tool calls.\n const toolCalls = getToolCalls(response);\n if (toolCalls.length === 0) {\n break;\n } else if (!toolkit) {\n throw new Error('No toolkit provided'); // TODO(burdon): Throw user error?\n }\n\n // Execute the tool calls.\n // TODO(burdon): Retry errors? Write result when each completes individually?\n const toolResults = yield* Effect.forEach(toolCalls, (toolCall) => {\n return callTool(toolkit, toolCall).pipe(\n Effect.provide(\n TracingService.layerSubframe((context) => ({\n ...context,\n parentMessage: response.id,\n toolCallId: toolCall.toolCallId,\n })),\n ),\n );\n });\n\n // Add to queue and continue loop.\n // TODO(wittjosiah): Sometimes tool error results are added to the queue before the tool agent statuses.\n // This results in a broken execution graph.\n yield* submitMessage(\n Obj.make(DataType.Message, {\n created: new Date().toISOString(),\n sender: { role: 'tool' },\n blocks: toolResults,\n }),\n );\n } while (true);\n\n log('done', { pending: this._pending.length });\n return this._pending;\n }).pipe(this._semaphore.withPermits(1), Effect.withSpan('AiSession.run'));\n\n /**\n * @deprecated\n */\n // TODO(burdon): Implement or remove.\n async runStructured<S extends Schema.Schema.AnyNoContext>(\n _schema: S,\n _options: AiSessionRunParams<any>,\n ): Promise<Schema.Schema.Type<S>> {\n return todo();\n // const parser = structuredOutputParser(schema);\n // const result = await this.run({\n // ...options,\n // executableTools: [...(options.executableTools ?? []), parser.tool],\n // });\n // return parser.getResult(result);\n }\n}\n\nconst createSnippet = (text: string, len = 32) =>\n text.length <= len * 2 ? text : [text.slice(0, len), '...', text.slice(-len)].join('');\n\n// TODO(dmaretskyi): Extract as a general util.\nconst logDump = (message: string, data: unknown) => {\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n const { writeFileSync } = require('node:fs');\n const path = `/tmp/log-data-${Date.now()}.json`;\n writeFileSync(path, JSON.stringify(data, null, 2));\n log.info(message, { path });\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Array from 'effect/Array';\nimport * as Effect from 'effect/Effect';\nimport * as Function from 'effect/Function';\nimport * as Option from 'effect/Option';\n\nimport { Template } from '@dxos/blueprints';\nimport { Obj } from '@dxos/echo';\nimport { type ObjectId } from '@dxos/echo/internal';\nimport { ObjectVersion } from '@dxos/echo-db';\nimport { DatabaseService } from '@dxos/functions';\nimport { log } from '@dxos/log';\nimport { type ContentBlock, DataType } from '@dxos/schema';\nimport { trim } from '@dxos/util';\n\nimport { AiAssistantError } from '../errors';\n\nimport { ArtifactDiffResolver } from './artifact-diff';\nimport { type AiSessionRunParams } from './session';\n\n/**\n * Formats the system prompt.\n */\n// TODO(burdon): Move to AiPreprocessor.\nexport const formatSystemPrompt = ({\n system,\n blueprints = [],\n objects = [],\n}: Pick<AiSessionRunParams<any>, 'system' | 'blueprints' | 'objects'>) =>\n Effect.gen(function* () {\n const blueprintDefs = yield* Function.pipe(\n blueprints,\n Effect.forEach((blueprint) => Effect.succeed(blueprint.instructions)),\n Effect.flatMap(Effect.forEach((template) => DatabaseService.loadOption(template.source))),\n Effect.map(Array.filter(Option.isSome)),\n Effect.map(\n Array.map(\n (template) => trim`\n <blueprint>\n ${Template.process(template.value.content)}\n </blueprint>\n `,\n ),\n ),\n Effect.map((blueprints) =>\n blueprints.length > 0 ? ['## Blueprints Definitions', ...blueprints].join('\\n\\n') : undefined,\n ),\n );\n\n const objectDefs = yield* Function.pipe(\n objects,\n Effect.forEach((object) =>\n Effect.succeed(trim`\n <object>\n <dxn>${Obj.getDXN(object)}</dxn>\n <typename>${Obj.getTypename(object)}</typename>\n </object>\n `),\n ),\n Effect.map((objects) => (objects.length > 0 ? ['## Context Objects', ...objects].join('\\n\\n') : undefined)),\n );\n\n return yield* Function.pipe(\n Effect.succeed([system, blueprintDefs, objectDefs].filter((def): def is string => def !== undefined)),\n Effect.map((parts) => parts.join('\\n\\n')),\n );\n });\n\n/**\n * Formats the user prompt.\n */\n// TODO(burdon): Move to AiPreprocessor.\n// TODO(burdon): Convert util below to `Effect.fn` (to preserve stack info)\nexport const formatUserPrompt = ({ prompt, history = [] }: Pick<AiSessionRunParams<any>, 'prompt' | 'history'>) =>\n Effect.gen(function* () {\n const blocks: ContentBlock.Any[] = [];\n\n // TODO(dmaretskyi): Evaluate other approaches as `serviceOption` isn't represented in the type system.\n const artifactDiffResolver = yield* Effect.serviceOption(ArtifactDiffResolver);\n if (Option.isSome(artifactDiffResolver)) {\n const versions = gatherObjectVersions(history);\n const artifactDiff = yield* Effect.tryPromise({\n try: () =>\n artifactDiffResolver.value.resolve(\n [...versions.entries()].map(([id, version]) => ({ id, lastVersion: version })),\n ),\n catch: AiAssistantError.wrap({ message: 'Artifact diff resolution error' }),\n });\n\n log('version', { artifactDiff, versions });\n for (const [id, { version }] of [...artifactDiff.entries()]) {\n if (ObjectVersion.equals(version, versions.get(id)!)) {\n artifactDiff.delete(id);\n continue;\n }\n\n blocks.push({ _tag: 'anchor', objectId: id, version });\n }\n\n if (artifactDiff.size > 0) {\n blocks.push(createArtifactUpdateBlock(artifactDiff));\n }\n }\n\n return Obj.make(DataType.Message, {\n created: new Date().toISOString(),\n sender: { role: 'user' },\n blocks: [...blocks, { _tag: 'text', text: prompt }],\n });\n });\n\nconst gatherObjectVersions = (messages: DataType.Message[]): Map<ObjectId, ObjectVersion> => {\n const artifactIds = new Map<ObjectId, ObjectVersion>();\n for (const message of messages) {\n for (const block of message.blocks) {\n if (block._tag === 'anchor') {\n artifactIds.set(block.objectId, block.version as ObjectVersion);\n }\n }\n }\n\n return artifactIds;\n};\n\nconst createArtifactUpdateBlock = (\n artifactDiff: Map<ObjectId, { version: ObjectVersion; diff?: string }>,\n): ContentBlock.Any => {\n return {\n _tag: 'text',\n // TODO(dmaretskyi): Does this need to be a special content-block?\n disposition: 'artifact-update',\n text: trim`\n The following artifacts have been updated since the last message:\n ${[...artifactDiff.entries()]\n .map(([id, { diff }]) => `<changed-artifact id=\"${id}\">${diff ? `\\n${diff}` : ''}</changed-artifact>`)\n .join('\\n')}\n `,\n };\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport type * as Tool from '@effect/ai/Tool';\nimport * as Toolkit from '@effect/ai/Toolkit';\nimport type * as Context from 'effect/Context';\nimport * as Effect from 'effect/Effect';\n\nimport { type AiToolNotFoundError, ToolExecutionService, type ToolId, ToolResolverService } from '@dxos/ai';\nimport { type Blueprint } from '@dxos/blueprints';\nimport { isTruthy } from '@dxos/util';\n\nexport type ToolkitParams<Tools extends Record<string, Tool.Any>> = {\n toolkit?: Toolkit.Toolkit<Tools>;\n toolIds?: ToolId[];\n blueprints?: Blueprint.Blueprint[];\n};\n\n/**\n * Build a combined toolkit from the blueprint tools and the provided toolkit.\n */\nexport const createToolkit = <Tools extends Record<string, Tool.Any> = {}>({\n toolkit: toolkitParam,\n toolIds = [],\n blueprints = [],\n}: ToolkitParams<Tools>): Effect.Effect<\n Toolkit.WithHandler<any>,\n AiToolNotFoundError,\n ToolResolverService | ToolExecutionService | Tool.HandlersFor<Tools>\n> =>\n Effect.gen(function* () {\n const blueprintToolkit = yield* ToolResolverService.resolveToolkit([\n ...blueprints.flatMap(({ tools }) => tools),\n ...toolIds,\n ]);\n\n const blueprintToolkitHandler: Context.Context<Tool.HandlersFor<any>> = yield* blueprintToolkit.toContext(\n ToolExecutionService.handlersFor(blueprintToolkit),\n );\n\n const toolkit = Toolkit.merge(...[toolkitParam, blueprintToolkit].filter(isTruthy));\n return yield* toolkit.pipe(Effect.provide(blueprintToolkitHandler)) as any as Effect.Effect<\n Toolkit.WithHandler<any>,\n never,\n Tool.HandlersFor<Tools>\n >;\n });\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { type AnyEchoObject, ObjectId } from '@dxos/echo/internal';\nimport { type ObjectVersion } from '@dxos/echo-db';\nimport { getVersion } from '@dxos/echo-db';\nimport { type ContentBlock } from '@dxos/schema';\n\n// TODO(dmaretskyi): Extract.\nconst ObjectVersionSchema = Schema.Unknown as Schema.Schema<ObjectVersion>;\n\nconst VersionPinSchema = Schema.Struct({\n // TODO(dmaretskyi): Use Ref when those support encoding.\n objectId: ObjectId,\n // TODO(dmaretskyi): Could be opaque.\n version: ObjectVersionSchema,\n});\n\n/**\n * Used to pin a specific version of an object during the course of a conversation.\n * This allows us to detect when the object changes during the course of the conversation.\n */\nexport interface VersionPin extends Schema.Schema.Type<typeof VersionPinSchema> {}\n\nexport const VersionPin: typeof VersionPinSchema & {\n DISPOSITION: 'version-pin';\n fromObject: (object: AnyEchoObject) => VersionPin;\n createBlock: (pin: VersionPin) => ContentBlock.Any;\n} = class extends VersionPinSchema {\n static readonly DISPOSITION = 'version-pin';\n static fromObject(object: AnyEchoObject): VersionPin {\n return VersionPin.make({\n objectId: object.id,\n version: getVersion(object),\n });\n }\n\n static createBlock(pin: VersionPin): ContentBlock.Any {\n return {\n _tag: 'json',\n disposition: VersionPin.DISPOSITION,\n data: JSON.stringify(pin),\n };\n }\n};\n"],
|
|
5
|
+
"mappings": ";;;AAIA,YAAYA,aAAa;AAclB,IAAMC,uBAAN,cAA2CC,YAAI,sCAAA,EAAA,EAAA;AAGjD;;;ACjBL,YAAYC,YAAY;AACxB,YAAYC,cAAc;AAgBnB,IAAMC,qBAAqBC,OAAOC,OAAO;EAC9CC,MAAM,CAAC,EACLC,UAAmBC,kBAAgBC,WAAI,GACvCC,SAAkBF,kBAAgBC,WAAI,GACtCE,UAAmBH,kBAAgBC,WAAI,GACvCG,QAAiBJ,kBAAgBC,WAAI,GACrCI,YAAqBL,kBAAgBC,WAAI,EAAC,IACX,CAAC,OAA2B;IAC3DF;IACAG;IACAC;IACAC;IACAC;EACF;EAEAC,MAAM,MAAMX,mBAAmBG,KAAI;;;;EAKnCS,aAAa,CAACC,YACZb,mBAAmBG,KAAK;IACtBK,SAAS,CAACM,UACDC,YAAK,MAAA;AACV,UAAID,MAAME,SAAS;AACjB;MACF;AACAH,cAAQI,kBAAkBH,KAAAA;IAC5B,CAAA;IACFJ,WAAW,CAACQ,YACHH,YAAK,MAAA;AACV,UAAIG,QAAQC,OAAOC,SAAS,aAAa;AACvC;MACF;AACAP,cAAQQ,aAAaH,OAAAA;IACvB,CAAA;EACJ,CAAA;AACJ,CAAA;;;ACtDA,SAASI,iBAAiB;AAKnB,IAAMC,eAAN,cAA2BC,UAAUC,OAAO,kBAAkB,gBAAA,EAAA;AAAmB;AAKjF,IAAMC,mBAAN,cAA+BF,UAAUC,OAAO,sBAAsB,oBAAA,EAAA;AAAuB;;;ACTpG,YAAYE,mBAAmB;AAG/B,YAAYC,WAAW;AACvB,YAAYC,aAAY;AAExB,YAAYC,YAAY;AAExB,SACEC,UACAC,gBAKAC,UACAC,oBACK;AAEP,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AAMC,sBAA6BC;AAEnC,IAAMC,mBAA0BC,cAAO;;EAErCC,UAAUC;;EAEVC,SAASN;AACX,CAAA;AAQO,IAAMO,aAIT,cAAcL,iBAAAA;EAChB,OAAgBM,cAAc;EAC9B,OAAOC,WAAWC,QAAmC;AACnD,WAAOH,WAAWI,KAAK;MACrBP,UAAUM,OAAOE;MACjBN,SAASO,WAAWH,MAAAA;IACtB,CAAA;EACF;EAEA,OAAOI,YAAYC,KAAmC;AACpD,WAAO;MACLC,MAAM;MACNC,aAAaV,WAAWC;MACxBU,MAAMC,KAAKC,UAAUL,GAAAA;IACvB;EACF;AACF;",
|
|
6
|
+
"names": ["Context", "ArtifactDiffResolver", "Tag", "Effect", "Function", "GenerationObserver", "Object", "freeze", "make", "onBegin", "constant", "void", "onPart", "onBlock", "onEnd", "onMessage", "noop", "fromPrinter", "printer", "block", "sync", "pending", "printContentBlock", "message", "sender", "role", "printMessage", "BaseError", "AiModelError", "BaseError", "extend", "AiAssistantError", "LanguageModel", "Chunk", "Effect", "Stream", "AiParser", "AiPreprocessor", "callTool", "getToolCalls", "todo", "Obj", "TracingService", "log", "DataType", "Array", "Effect", "Function", "Option", "Template", "Obj", "ObjectVersion", "DatabaseService", "log", "DataType", "trim", "formatSystemPrompt", "system", "blueprints", "objects", "gen", "blueprintDefs", "pipe", "forEach", "blueprint", "succeed", "instructions", "flatMap", "template", "DatabaseService", "loadOption", "source", "map", "filter", "isSome", "trim", "Template", "process", "value", "content", "length", "join", "undefined", "objectDefs", "object", "Obj", "getDXN", "getTypename", "def", "parts", "formatUserPrompt", "prompt", "history", "blocks", "artifactDiffResolver", "serviceOption", "ArtifactDiffResolver", "versions", "gatherObjectVersions", "artifactDiff", "tryPromise", "try", "resolve", "entries", "id", "version", "lastVersion", "catch", "AiAssistantError", "wrap", "message", "log", "ObjectVersion", "equals", "get", "delete", "push", "_tag", "objectId", "size", "createArtifactUpdateBlock", "make", "DataType", "Message", "created", "Date", "toISOString", "sender", "role", "text", "messages", "artifactIds", "Map", "block", "set", "disposition", "diff", "AiSession", "_semaphore", "runSync", "makeSemaphore", "_history", "_pending", "_options", "run", "prompt", "system", "systemTemplate", "history", "objects", "blueprints", "toolkit", "observer", "GenerationObserver", "noop", "gen", "pending", "submitMessage", "fnUntraced", "message", "push", "onMessage", "TracingService", "emitConverationMessage", "promptMessage", "formatUserPrompt", "formatSystemPrompt", "log", "snippet", "createSnippet", "length", "AiPreprocessor", "preprocessPrompt", "blocks", "streamText", "disableToolCallResolution", "pipe", "AiParser", "parseResponse", "onBegin", "onBlock", "block", "onPart", "part", "onEnd", "summary", "runCollect", "map", "toArray", "response", "Obj", "make", "DataType", "Message", "created", "Date", "toISOString", "sender", "role", "toolCalls", "getToolCalls", "Error", "toolResults", "forEach", "toolCall", "callTool", "provide", "layerSubframe", "context", "parentMessage", "id", "toolCallId", "withPermits", "withSpan", "runStructured", "_schema", "todo", "text", "len", "slice", "join", "Toolkit", "Effect", "ToolExecutionService", "ToolResolverService", "isTruthy", "createToolkit", "toolkit", "toolkitParam", "toolIds", "blueprints", "gen", "blueprintToolkit", "ToolResolverService", "resolveToolkit", "flatMap", "tools", "blueprintToolkitHandler", "toContext", "ToolExecutionService", "handlersFor", "merge", "filter", "isTruthy", "pipe", "provide", "Schema", "ObjectId", "getVersion", "ObjectVersionSchema", "Unknown", "VersionPinSchema", "Struct", "objectId", "ObjectId", "version", "VersionPin", "DISPOSITION", "fromObject", "object", "make", "id", "getVersion", "createBlock", "pin", "_tag", "disposition", "data", "JSON", "stringify"]
|
|
7
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
AiSession
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-AUUC7II4.mjs";
|
|
5
5
|
import {
|
|
6
6
|
combineNerTokens,
|
|
7
7
|
createTokenGroups,
|
|
@@ -10,9 +10,9 @@ import {
|
|
|
10
10
|
} from "../chunk-BCFXTNSK.mjs";
|
|
11
11
|
|
|
12
12
|
// src/extraction/extraction.ts
|
|
13
|
-
import
|
|
13
|
+
import * as Schema from "effect/Schema";
|
|
14
14
|
import { asyncTimeout } from "@dxos/async";
|
|
15
|
-
import { Expando } from "@dxos/echo
|
|
15
|
+
import { Expando } from "@dxos/echo/internal";
|
|
16
16
|
import { log } from "@dxos/log";
|
|
17
17
|
import { DataType } from "@dxos/schema";
|
|
18
18
|
var __dxlog_file = "/__w/dxos/dxos/packages/core/assistant/src/extraction/extraction.ts";
|
|
@@ -58,14 +58,14 @@ var processTranscriptMessage = async (params) => {
|
|
|
58
58
|
// src/extraction/extraction-llm-function/extraction-llm-function.ts
|
|
59
59
|
import { AiService } from "@dxos/ai";
|
|
60
60
|
import { Obj } from "@dxos/echo";
|
|
61
|
-
import { create } from "@dxos/echo
|
|
61
|
+
import { create } from "@dxos/echo/internal";
|
|
62
62
|
import { defineFunction } from "@dxos/functions";
|
|
63
63
|
import { DataType as DataType2 } from "@dxos/schema";
|
|
64
64
|
|
|
65
65
|
// src/extraction/quotes.ts
|
|
66
|
-
import
|
|
66
|
+
import * as Schema2 from "effect/Schema";
|
|
67
67
|
import { Filter, Query } from "@dxos/echo";
|
|
68
|
-
import { ObjectId } from "@dxos/echo
|
|
68
|
+
import { ObjectId } from "@dxos/echo/internal";
|
|
69
69
|
import { DXN } from "@dxos/keys";
|
|
70
70
|
import { log as log2 } from "@dxos/log";
|
|
71
71
|
var __dxlog_file2 = "/__w/dxos/dxos/packages/core/assistant/src/extraction/quotes.ts";
|
|
@@ -176,7 +176,7 @@ var extractionAnthropicFunction = defineFunction({
|
|
|
176
176
|
|
|
177
177
|
// src/extraction/extraction-ner-function/extraction-ner-function.ts
|
|
178
178
|
import { asyncTimeout as asyncTimeout2 } from "@dxos/async";
|
|
179
|
-
import { create as create2 } from "@dxos/echo
|
|
179
|
+
import { create as create2 } from "@dxos/echo/internal";
|
|
180
180
|
import { DatabaseService, defineFunction as defineFunction2 } from "@dxos/functions";
|
|
181
181
|
import { invariant } from "@dxos/invariant";
|
|
182
182
|
import { log as log3 } from "@dxos/log";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/extraction/extraction.ts", "../../../../src/extraction/extraction-llm-function/extraction-llm-function.ts", "../../../../src/extraction/quotes.ts", "raw-loader:/__w/dxos/dxos/packages/core/assistant/src/extraction/extraction-llm-function/instructions.tpl?raw", "../../../../src/extraction/extraction-ner-function/extraction-ner-function.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { Schema } from 'effect';\n\nimport { asyncTimeout } from '@dxos/async';\nimport { Expando } from '@dxos/echo-schema';\nimport { type FunctionDefinition, type FunctionExecutor } from '@dxos/functions';\nimport { log } from '@dxos/log';\nimport { DataType } from '@dxos/schema';\n\nexport const ExtractionInput = Schema.Struct({\n message: DataType.Message,\n objects: Schema.optional(Schema.Array(Expando)),\n options: Schema.optional(\n Schema.Struct({\n timeout: Schema.optional(Schema.Number),\n fallbackToRaw: Schema.optional(Schema.Boolean),\n }),\n ),\n});\nexport interface ExtractionInput extends Schema.Schema.Type<typeof ExtractionInput> {}\n\nexport const ExtractionOutput = Schema.Struct({\n message: DataType.Message,\n timeElapsed: Schema.Number,\n});\nexport interface ExtractionOutput extends Schema.Schema.Type<typeof ExtractionOutput> {}\n\nexport type ProcessTranscriptMessageParams = {\n input: ExtractionInput;\n function: FunctionDefinition<ExtractionInput, ExtractionOutput>;\n executor: FunctionExecutor;\n\n options?: {\n /**\n * Timeout for the entity extraction.\n */\n timeout?: number;\n\n /**\n * Fallback to raw text if the entity extraction fails.\n * Otherwise the function will throw an error.\n * @default false\n */\n fallbackToRaw?: boolean;\n };\n};\n\nexport type ExtractionFunction = FunctionDefinition<ExtractionInput, ExtractionOutput>;\n\n/**\n * Extract entities from the transcript message and add them to the message.\n */\n// TODO(dmaretskyi): Move context to a vector search index.\nexport const processTranscriptMessage = async (params: ProcessTranscriptMessageParams): Promise<ExtractionOutput> => {\n try {\n if (params.options?.timeout && params.options.timeout > 0) {\n return await asyncTimeout(params.executor.invoke(params.function, params.input), params.options.timeout);\n } else {\n return await params.executor.invoke(params.function, params.input);\n }\n } catch (error) {\n if (params.options?.fallbackToRaw) {\n log.warn('failed to process message, falling back to raw text', { error });\n return {\n message: params.input.message,\n timeElapsed: 0,\n };\n } else {\n throw error;\n }\n }\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\n// ISSUE(burdon): defineFunction\n// @ts-nocheck\n\nimport { AiService } from '@dxos/ai';\nimport { Obj } from '@dxos/echo';\nimport { create } from '@dxos/echo-schema';\nimport { type FunctionDefinition, defineFunction } from '@dxos/functions';\nimport { type ContentBlock, DataType } from '@dxos/schema';\n\nimport { AiSession } from '../../session';\nimport { ExtractionInput, ExtractionOutput } from '../extraction';\nimport { ReferencedQuotes, insertReferences } from '../quotes';\n\nimport PROMPT from './instructions.tpl?raw';\n\nexport const extractionAnthropicFunction: FunctionDefinition<ExtractionInput, ExtractionOutput> = defineFunction({\n key: 'dxos.org/function/extraction/extract-entities',\n name: 'Extract Entities',\n description: 'Extract entities from the transcript message and add them to the message.',\n inputSchema: ExtractionInput,\n outputSchema: ExtractionOutput,\n handler: async ({ data: { message, objects }, context }) => {\n const startTime = performance.now();\n const ai = context.getService(AiService.AiService);\n const session = new AiSession({ operationModel: 'configured' });\n const result = await session.runStructured(ReferencedQuotes, {\n generationOptions: {\n model: '@anthropic/claude-3-5-haiku-20241022',\n },\n client: ai.client,\n systemPrompt: PROMPT,\n history: [\n Obj.make(DataType.Message, {\n created: new Date().toISOString(),\n sender: { role: 'user' },\n blocks: [\n {\n _tag: 'text',\n text: `<context>${JSON.stringify(objects)}</context>`,\n } satisfies ContentBlock.Text,\n {\n _tag: 'text',\n text: `<transcript>${JSON.stringify(message.blocks)}</transcript>`,\n } satisfies ContentBlock.Text,\n ],\n }),\n ],\n artifacts: [],\n prompt: '',\n tools: [],\n } as any); // TODO(burdon): Rewrite test.\n\n return {\n timeElapsed: performance.now() - startTime,\n message: create(DataType.Message, {\n ...message,\n blocks: message.blocks.map((block) =>\n block._tag !== 'transcript'\n ? block\n : {\n ...block,\n text: insertReferences(block.text, result),\n },\n ),\n }),\n };\n },\n});\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { Schema } from 'effect';\n\nimport { Filter, Query } from '@dxos/echo';\nimport { type EchoDatabase } from '@dxos/echo-db';\nimport { ObjectId } from '@dxos/echo-schema';\nimport { DXN } from '@dxos/keys';\nimport { log } from '@dxos/log';\n\nexport const ReferencedQuotes = Schema.Struct({\n references: Schema.Array(\n Schema.Struct({\n id: Schema.String,\n quote: Schema.String, // TODO(burdon): Quote?\n }),\n )\n .pipe(Schema.mutable)\n .annotations({\n // TODO(burdon): Does this description make sense?\n description: `\n The references to the context objects that are mentioned in the transcript. \n Quote should match the original transcript text exactly, while id is the id of the context object.\n `,\n }),\n});\nexport type ReferencedQuotes = Schema.Schema.Type<typeof ReferencedQuotes>;\n\nexport const findQuotes = async (quotes: string[], db: EchoDatabase): Promise<ReferencedQuotes> => {\n const references = await Promise.all(\n quotes.map(async (quote) => {\n const { objects } = await db.query(Query.select(Filter.text(quote, { type: 'vector' }))).run();\n log.info('found quotes in vector index', { objects, quote });\n return objects.length > 0 ? [{ id: objects[0].id.toString(), quote }] : [];\n }),\n );\n return { references: references.flat() };\n};\n\n/**\n * Finds and replaces all quotes with DXNs references.\n */\n// TODO(dmaretskyi): Lookup and verifiy ids from provided context.\nexport const insertReferences = (text: string, quotes: ReferencedQuotes) => {\n for (const quote of quotes.references) {\n if (!ObjectId.isValid(quote.id)) {\n continue;\n }\n\n // Use a case-insensitive regular expression to replace the quote.\n const regex = new RegExp(quote.quote.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&'), 'gi');\n text = text.replace(regex, `[${quote.quote}](${DXN.fromLocalObjectId(quote.id).toString()})`);\n }\n\n return text;\n};\n", "You are an AI assistant specialized in processing and enhancing transcripts with contextual information.\nYour task is to analyze a given transcript and extract references to the context objects.\n\nThe context and transcript are provided in the user message in `context` and `transcript` XML tags.\n\nHere are your instructions:\n\n1. Read the transcript and context information provided above.\n\n2. Process each segment of the transcript separately.\n\n3. For each segment:\n a. Analyze the content and identify relevant information from the context.\n b. Extract a number of references to the context objects that are mentioned in the segment.\n c. Output the references in the format `{ \"quote\": \"earnings report\", \"id\": \"01JT0JP9AX0XKGZX4MV4B69VT6\" }`.\n d. If there are no references, just output an empty array.\n\n4. Maintain the exact order and structure of the original transcript segments.\n\nOutput Format:\nYou have been provided with a tool that specifies output format\n\nRemember:\n- Only quote the text that is in the transcript.\n- Analyze each segment carefully before processing it.\n- Only reference objects that appear in the context and exactly by their id, If the object is not in the context, do not insert a reference. \n\nNow, process the transcript and context provided below according to these instructions.", "//\n// Copyright 2025 DXOS.org\n//\n\n// ISSUE(burdon): defineFunction\n// @ts-nocheck\n\nimport { asyncTimeout } from '@dxos/async';\nimport { create } from '@dxos/echo-schema';\nimport { DatabaseService, defineFunction } from '@dxos/functions';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\nimport { DataType } from '@dxos/schema';\n\nimport { ExtractionInput, ExtractionOutput } from '../extraction';\nimport { findQuotes, insertReferences } from '../quotes';\n\n/**\n * Named Entity Recognition model\n */\n// TODO(mykola): Make it use vector index to query objects and not pass objects as input.\nexport const extractionNerFunction = defineFunction({\n key: 'dxos.org/function/extraction/extract-entities',\n name: 'Extract Entities',\n description: 'Extracts named entities from a text',\n inputSchema: ExtractionInput,\n outputSchema: ExtractionOutput,\n handler: async ({ data: { message, options }, context }) => {\n log.info('input', { message, options });\n const startTime = performance.now();\n const { db } = context.getService(DatabaseService);\n const { extractFullEntities } = await import('./named-entity-recognition');\n\n const entitiesPromise = Promise.all(\n message.blocks.map(async (block) => {\n invariant(block._tag === 'transcript' || block._tag === 'text');\n return extractFullEntities(block.text);\n }),\n ).then((entities) => entities.flat());\n const entities = options?.timeout ? await asyncTimeout(entitiesPromise, options.timeout) : await entitiesPromise;\n\n log.info('entities', { entities });\n const quoteReferences = await findQuotes(\n entities.map((entity) => entity.word),\n db,\n );\n\n const blocksWithReferences = message.blocks.map((block) => {\n invariant(block._tag === 'transcript' || block._tag === 'text');\n return { ...block, text: insertReferences(block._tag, quoteReferences) };\n });\n\n const messageWithReferences = create(DataType.Message, {\n ...message,\n blocks: blocksWithReferences,\n });\n\n log.info('output', { messageWithReferences });\n return {\n message: messageWithReferences,\n timeElapsed: performance.now() - startTime,\n };\n },\n});\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;AAIA,
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { asyncTimeout } from '@dxos/async';\nimport { Expando } from '@dxos/echo/internal';\nimport { type FunctionDefinition, type FunctionExecutor } from '@dxos/functions';\nimport { log } from '@dxos/log';\nimport { DataType } from '@dxos/schema';\n\nexport const ExtractionInput = Schema.Struct({\n message: DataType.Message,\n objects: Schema.optional(Schema.Array(Expando)),\n options: Schema.optional(\n Schema.Struct({\n timeout: Schema.optional(Schema.Number),\n fallbackToRaw: Schema.optional(Schema.Boolean),\n }),\n ),\n});\nexport interface ExtractionInput extends Schema.Schema.Type<typeof ExtractionInput> {}\n\nexport const ExtractionOutput = Schema.Struct({\n message: DataType.Message,\n timeElapsed: Schema.Number,\n});\nexport interface ExtractionOutput extends Schema.Schema.Type<typeof ExtractionOutput> {}\n\nexport type ProcessTranscriptMessageParams = {\n input: ExtractionInput;\n function: FunctionDefinition<ExtractionInput, ExtractionOutput>;\n executor: FunctionExecutor;\n\n options?: {\n /**\n * Timeout for the entity extraction.\n */\n timeout?: number;\n\n /**\n * Fallback to raw text if the entity extraction fails.\n * Otherwise the function will throw an error.\n * @default false\n */\n fallbackToRaw?: boolean;\n };\n};\n\nexport type ExtractionFunction = FunctionDefinition<ExtractionInput, ExtractionOutput>;\n\n/**\n * Extract entities from the transcript message and add them to the message.\n */\n// TODO(dmaretskyi): Move context to a vector search index.\nexport const processTranscriptMessage = async (params: ProcessTranscriptMessageParams): Promise<ExtractionOutput> => {\n try {\n if (params.options?.timeout && params.options.timeout > 0) {\n return await asyncTimeout(params.executor.invoke(params.function, params.input), params.options.timeout);\n } else {\n return await params.executor.invoke(params.function, params.input);\n }\n } catch (error) {\n if (params.options?.fallbackToRaw) {\n log.warn('failed to process message, falling back to raw text', { error });\n return {\n message: params.input.message,\n timeElapsed: 0,\n };\n } else {\n throw error;\n }\n }\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\n// ISSUE(burdon): defineFunction\n// @ts-nocheck\n\nimport { AiService } from '@dxos/ai';\nimport { Obj } from '@dxos/echo';\nimport { create } from '@dxos/echo/internal';\nimport { type FunctionDefinition, defineFunction } from '@dxos/functions';\nimport { type ContentBlock, DataType } from '@dxos/schema';\n\nimport { AiSession } from '../../session';\nimport { ExtractionInput, ExtractionOutput } from '../extraction';\nimport { ReferencedQuotes, insertReferences } from '../quotes';\n\nimport PROMPT from './instructions.tpl?raw';\n\nexport const extractionAnthropicFunction: FunctionDefinition<ExtractionInput, ExtractionOutput> = defineFunction({\n key: 'dxos.org/function/extraction/extract-entities',\n name: 'Extract Entities',\n description: 'Extract entities from the transcript message and add them to the message.',\n inputSchema: ExtractionInput,\n outputSchema: ExtractionOutput,\n handler: async ({ data: { message, objects }, context }) => {\n const startTime = performance.now();\n const ai = context.getService(AiService.AiService);\n const session = new AiSession({ operationModel: 'configured' });\n const result = await session.runStructured(ReferencedQuotes, {\n generationOptions: {\n model: '@anthropic/claude-3-5-haiku-20241022',\n },\n client: ai.client,\n systemPrompt: PROMPT,\n history: [\n Obj.make(DataType.Message, {\n created: new Date().toISOString(),\n sender: { role: 'user' },\n blocks: [\n {\n _tag: 'text',\n text: `<context>${JSON.stringify(objects)}</context>`,\n } satisfies ContentBlock.Text,\n {\n _tag: 'text',\n text: `<transcript>${JSON.stringify(message.blocks)}</transcript>`,\n } satisfies ContentBlock.Text,\n ],\n }),\n ],\n artifacts: [],\n prompt: '',\n tools: [],\n } as any); // TODO(burdon): Rewrite test.\n\n return {\n timeElapsed: performance.now() - startTime,\n message: create(DataType.Message, {\n ...message,\n blocks: message.blocks.map((block) =>\n block._tag !== 'transcript'\n ? block\n : {\n ...block,\n text: insertReferences(block.text, result),\n },\n ),\n }),\n };\n },\n});\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { Filter, Query } from '@dxos/echo';\nimport { ObjectId } from '@dxos/echo/internal';\nimport { type EchoDatabase } from '@dxos/echo-db';\nimport { DXN } from '@dxos/keys';\nimport { log } from '@dxos/log';\n\nexport const ReferencedQuotes = Schema.Struct({\n references: Schema.Array(\n Schema.Struct({\n id: Schema.String,\n quote: Schema.String, // TODO(burdon): Quote?\n }),\n )\n .pipe(Schema.mutable)\n .annotations({\n // TODO(burdon): Does this description make sense?\n description: `\n The references to the context objects that are mentioned in the transcript. \n Quote should match the original transcript text exactly, while id is the id of the context object.\n `,\n }),\n});\nexport type ReferencedQuotes = Schema.Schema.Type<typeof ReferencedQuotes>;\n\nexport const findQuotes = async (quotes: string[], db: EchoDatabase): Promise<ReferencedQuotes> => {\n const references = await Promise.all(\n quotes.map(async (quote) => {\n const { objects } = await db.query(Query.select(Filter.text(quote, { type: 'vector' }))).run();\n log.info('found quotes in vector index', { objects, quote });\n return objects.length > 0 ? [{ id: objects[0].id.toString(), quote }] : [];\n }),\n );\n return { references: references.flat() };\n};\n\n/**\n * Finds and replaces all quotes with DXNs references.\n */\n// TODO(dmaretskyi): Lookup and verifiy ids from provided context.\nexport const insertReferences = (text: string, quotes: ReferencedQuotes) => {\n for (const quote of quotes.references) {\n if (!ObjectId.isValid(quote.id)) {\n continue;\n }\n\n // Use a case-insensitive regular expression to replace the quote.\n const regex = new RegExp(quote.quote.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&'), 'gi');\n text = text.replace(regex, `[${quote.quote}](${DXN.fromLocalObjectId(quote.id).toString()})`);\n }\n\n return text;\n};\n", "You are an AI assistant specialized in processing and enhancing transcripts with contextual information.\nYour task is to analyze a given transcript and extract references to the context objects.\n\nThe context and transcript are provided in the user message in `context` and `transcript` XML tags.\n\nHere are your instructions:\n\n1. Read the transcript and context information provided above.\n\n2. Process each segment of the transcript separately.\n\n3. For each segment:\n a. Analyze the content and identify relevant information from the context.\n b. Extract a number of references to the context objects that are mentioned in the segment.\n c. Output the references in the format `{ \"quote\": \"earnings report\", \"id\": \"01JT0JP9AX0XKGZX4MV4B69VT6\" }`.\n d. If there are no references, just output an empty array.\n\n4. Maintain the exact order and structure of the original transcript segments.\n\nOutput Format:\nYou have been provided with a tool that specifies output format\n\nRemember:\n- Only quote the text that is in the transcript.\n- Analyze each segment carefully before processing it.\n- Only reference objects that appear in the context and exactly by their id, If the object is not in the context, do not insert a reference. \n\nNow, process the transcript and context provided below according to these instructions.", "//\n// Copyright 2025 DXOS.org\n//\n\n// ISSUE(burdon): defineFunction\n// @ts-nocheck\n\nimport { asyncTimeout } from '@dxos/async';\nimport { create } from '@dxos/echo/internal';\nimport { DatabaseService, defineFunction } from '@dxos/functions';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\nimport { DataType } from '@dxos/schema';\n\nimport { ExtractionInput, ExtractionOutput } from '../extraction';\nimport { findQuotes, insertReferences } from '../quotes';\n\n/**\n * Named Entity Recognition model\n */\n// TODO(mykola): Make it use vector index to query objects and not pass objects as input.\nexport const extractionNerFunction = defineFunction({\n key: 'dxos.org/function/extraction/extract-entities',\n name: 'Extract Entities',\n description: 'Extracts named entities from a text',\n inputSchema: ExtractionInput,\n outputSchema: ExtractionOutput,\n handler: async ({ data: { message, options }, context }) => {\n log.info('input', { message, options });\n const startTime = performance.now();\n const { db } = context.getService(DatabaseService);\n const { extractFullEntities } = await import('./named-entity-recognition');\n\n const entitiesPromise = Promise.all(\n message.blocks.map(async (block) => {\n invariant(block._tag === 'transcript' || block._tag === 'text');\n return extractFullEntities(block.text);\n }),\n ).then((entities) => entities.flat());\n const entities = options?.timeout ? await asyncTimeout(entitiesPromise, options.timeout) : await entitiesPromise;\n\n log.info('entities', { entities });\n const quoteReferences = await findQuotes(\n entities.map((entity) => entity.word),\n db,\n );\n\n const blocksWithReferences = message.blocks.map((block) => {\n invariant(block._tag === 'transcript' || block._tag === 'text');\n return { ...block, text: insertReferences(block._tag, quoteReferences) };\n });\n\n const messageWithReferences = create(DataType.Message, {\n ...message,\n blocks: blocksWithReferences,\n });\n\n log.info('output', { messageWithReferences });\n return {\n message: messageWithReferences,\n timeElapsed: performance.now() - startTime,\n };\n },\n});\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;AAIA,YAAYA,YAAY;AAExB,SAASC,oBAAoB;AAC7B,SAASC,eAAe;AAExB,SAASC,WAAW;AACpB,SAASC,gBAAgB;;AAElB,IAAMC,kBAAyBC,cAAO;EAC3CC,SAASH,SAASI;EAClBC,SAAgBC,gBAAgBC,aAAMT,OAAAA,CAAAA;EACtCU,SAAgBF,gBACPJ,cAAO;IACZO,SAAgBH,gBAAgBI,aAAM;IACtCC,eAAsBL,gBAAgBM,cAAO;EAC/C,CAAA,CAAA;AAEJ,CAAA;AAGO,IAAMC,mBAA0BX,cAAO;EAC5CC,SAASH,SAASI;EAClBU,aAAoBJ;AACtB,CAAA;AA6BO,IAAMK,2BAA2B,OAAOC,WAAAA;AAC7C,MAAI;AACF,QAAIA,OAAOR,SAASC,WAAWO,OAAOR,QAAQC,UAAU,GAAG;AACzD,aAAO,MAAMZ,aAAamB,OAAOC,SAASC,OAAOF,OAAOG,UAAUH,OAAOI,KAAK,GAAGJ,OAAOR,QAAQC,OAAO;IACzG,OAAO;AACL,aAAO,MAAMO,OAAOC,SAASC,OAAOF,OAAOG,UAAUH,OAAOI,KAAK;IACnE;EACF,SAASC,OAAO;AACd,QAAIL,OAAOR,SAASG,eAAe;AACjC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;;;AACxD,aAAO;QAAE,GAAGF;QAAOG,MAAMW,iBAAiBd,MAAME,MAAMO,eAAAA;MAAiB;IACzE,CAAA;AAEA,UAAMM,wBAAwBC,QAAOC,UAASC,SAAS;MACrD,GAAGnC;MACHe,QAAQe;IACV,CAAA;AAEA3B,IAAAA,KAAIC,KAAK,UAAU;MAAE4B;IAAsB,GAAA;;;;;;AAC3C,WAAO;MACLhC,SAASgC;MACTI,aAAa9B,YAAYC,IAAG,IAAKF;IACnC;EACF;AACF,CAAA;",
|
|
6
6
|
"names": ["Schema", "asyncTimeout", "Expando", "log", "DataType", "ExtractionInput", "Struct", "message", "Message", "objects", "optional", "Array", "options", "timeout", "Number", "fallbackToRaw", "Boolean", "ExtractionOutput", "timeElapsed", "processTranscriptMessage", "params", "executor", "invoke", "function", "input", "error", "warn", "AiService", "Obj", "create", "defineFunction", "DataType", "Schema", "Filter", "Query", "ObjectId", "DXN", "log", "ReferencedQuotes", "Struct", "references", "Array", "id", "String", "quote", "pipe", "mutable", "annotations", "description", "findQuotes", "quotes", "db", "Promise", "all", "map", "objects", "query", "select", "text", "type", "run", "info", "length", "toString", "flat", "insertReferences", "isValid", "regex", "RegExp", "replace", "fromLocalObjectId", "extractionAnthropicFunction", "defineFunction", "key", "name", "description", "inputSchema", "ExtractionInput", "outputSchema", "ExtractionOutput", "handler", "data", "message", "objects", "context", "startTime", "performance", "now", "ai", "getService", "AiService", "session", "AiSession", "operationModel", "result", "runStructured", "ReferencedQuotes", "generationOptions", "model", "client", "systemPrompt", "PROMPT", "history", "Obj", "make", "DataType", "Message", "created", "Date", "toISOString", "sender", "role", "blocks", "_tag", "text", "JSON", "stringify", "artifacts", "prompt", "tools", "timeElapsed", "create", "map", "block", "insertReferences", "asyncTimeout", "create", "DatabaseService", "defineFunction", "invariant", "log", "DataType", "extractionNerFunction", "defineFunction", "key", "name", "description", "inputSchema", "ExtractionInput", "outputSchema", "ExtractionOutput", "handler", "data", "message", "options", "context", "log", "info", "startTime", "performance", "now", "db", "getService", "DatabaseService", "extractFullEntities", "entitiesPromise", "Promise", "all", "blocks", "map", "block", "invariant", "_tag", "text", "then", "entities", "flat", "timeout", "asyncTimeout", "quoteReferences", "findQuotes", "entity", "word", "blocksWithReferences", "insertReferences", "messageWithReferences", "create", "DataType", "Message", "timeElapsed"]
|
|
7
7
|
}
|