@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.
Files changed (71) hide show
  1. package/dist/lib/browser/{chunk-ILL2CN3G.mjs → chunk-4VIJTKPM.mjs} +128 -148
  2. package/dist/lib/browser/chunk-4VIJTKPM.mjs.map +7 -0
  3. package/dist/lib/browser/extraction/index.mjs +7 -7
  4. package/dist/lib/browser/extraction/index.mjs.map +2 -2
  5. package/dist/lib/browser/index.mjs +157 -118
  6. package/dist/lib/browser/index.mjs.map +4 -4
  7. package/dist/lib/browser/meta.json +1 -1
  8. package/dist/lib/node-esm/{chunk-GVKA7VL3.mjs → chunk-AUUC7II4.mjs} +128 -148
  9. package/dist/lib/node-esm/chunk-AUUC7II4.mjs.map +7 -0
  10. package/dist/lib/node-esm/extraction/index.mjs +7 -7
  11. package/dist/lib/node-esm/extraction/index.mjs.map +2 -2
  12. package/dist/lib/node-esm/index.mjs +157 -118
  13. package/dist/lib/node-esm/index.mjs.map +4 -4
  14. package/dist/lib/node-esm/meta.json +1 -1
  15. package/dist/types/src/conversation/context.d.ts +14 -7
  16. package/dist/types/src/conversation/context.d.ts.map +1 -1
  17. package/dist/types/src/conversation/conversation.d.ts +7 -7
  18. package/dist/types/src/conversation/conversation.d.ts.map +1 -1
  19. package/dist/types/src/diff.d.ts.map +1 -1
  20. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts +13 -9
  21. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts.map +1 -1
  22. package/dist/types/src/extraction/extraction.d.ts +14 -8
  23. package/dist/types/src/extraction/extraction.d.ts.map +1 -1
  24. package/dist/types/src/extraction/quotes.d.ts +1 -1
  25. package/dist/types/src/extraction/quotes.d.ts.map +1 -1
  26. package/dist/types/src/functions/services.d.ts +3 -2
  27. package/dist/types/src/functions/services.d.ts.map +1 -1
  28. package/dist/types/src/session/artifact-diff.d.ts +2 -2
  29. package/dist/types/src/session/artifact-diff.d.ts.map +1 -1
  30. package/dist/types/src/session/error-handling.d.ts +2 -2
  31. package/dist/types/src/session/error-handling.d.ts.map +1 -1
  32. package/dist/types/src/session/format.d.ts +7 -5
  33. package/dist/types/src/session/format.d.ts.map +1 -1
  34. package/dist/types/src/session/observer.d.ts +1 -1
  35. package/dist/types/src/session/observer.d.ts.map +1 -1
  36. package/dist/types/src/session/session.d.ts +6 -2
  37. package/dist/types/src/session/session.d.ts.map +1 -1
  38. package/dist/types/src/session/toolkit.d.ts +3 -2
  39. package/dist/types/src/session/toolkit.d.ts.map +1 -1
  40. package/dist/types/src/session/version-pin.d.ts +2 -2
  41. package/dist/types/src/session/version-pin.d.ts.map +1 -1
  42. package/dist/types/src/{types.d.ts → types/artifact.d.ts} +3 -3
  43. package/dist/types/src/types/artifact.d.ts.map +1 -0
  44. package/dist/types/src/types/index.d.ts +2 -0
  45. package/dist/types/src/types/index.d.ts.map +1 -0
  46. package/dist/types/tsconfig.tsbuildinfo +1 -1
  47. package/package.json +21 -27
  48. package/src/conversation/context.ts +49 -17
  49. package/src/conversation/conversation.ts +18 -9
  50. package/src/diff.ts +5 -0
  51. package/src/execution-graph.test.ts +1 -1
  52. package/src/extraction/extraction-llm-function/extraction-llm-function.ts +1 -1
  53. package/src/extraction/extraction-ner-function/extraction-ner-function.ts +1 -1
  54. package/src/extraction/extraction.ts +2 -2
  55. package/src/extraction/quotes.ts +2 -2
  56. package/src/functions/services.ts +9 -4
  57. package/src/session/artifact-diff.ts +2 -2
  58. package/src/session/error-handling.ts +4 -3
  59. package/src/session/format.test.ts +1 -1
  60. package/src/session/format.ts +8 -5
  61. package/src/session/observer.ts +2 -1
  62. package/src/session/session.test.ts +7 -4
  63. package/src/session/session.ts +9 -2
  64. package/src/session/toolkit.ts +4 -2
  65. package/src/session/version-pin.ts +2 -2
  66. package/src/summarization/summarization.test.ts +4 -3
  67. package/src/{types.ts → types/artifact.ts} +2 -2
  68. package/src/types/index.ts +5 -0
  69. package/dist/lib/browser/chunk-ILL2CN3G.mjs.map +0 -7
  70. package/dist/lib/node-esm/chunk-GVKA7VL3.mjs.map +0 -7
  71. package/dist/types/src/types.d.ts.map +0 -1
@@ -1,10 +1,11 @@
1
1
  // src/session/artifact-diff.ts
2
- import { Context } from "effect";
2
+ import * as Context from "effect/Context";
3
3
  var ArtifactDiffResolver = class extends Context.Tag("@dxos/assistant/ArtifactDiffResolver")() {
4
4
  };
5
5
 
6
6
  // src/session/observer.ts
7
- import { Effect, Function } from "effect";
7
+ import * as Effect from "effect/Effect";
8
+ import * as Function from "effect/Function";
8
9
  var GenerationObserver = Object.freeze({
9
10
  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) } = {}) => ({
10
11
  onBegin,
@@ -41,8 +42,10 @@ var AiAssistantError = class extends BaseError.extend("AI_ASSISTANT_ERROR", "AI
41
42
  };
42
43
 
43
44
  // src/session/session.ts
44
- import { LanguageModel } from "@effect/ai";
45
- import { Chunk, Effect as Effect3, Stream } from "effect";
45
+ import * as LanguageModel from "@effect/ai/LanguageModel";
46
+ import * as Chunk from "effect/Chunk";
47
+ import * as Effect3 from "effect/Effect";
48
+ import * as Stream from "effect/Stream";
46
49
  import { AiParser, AiPreprocessor, callTool, getToolCalls } from "@dxos/ai";
47
50
  import { todo } from "@dxos/debug";
48
51
  import { Obj as Obj2 } from "@dxos/echo";
@@ -51,7 +54,10 @@ import { log as log2 } from "@dxos/log";
51
54
  import { DataType as DataType2 } from "@dxos/schema";
52
55
 
53
56
  // src/session/format.ts
54
- import { Array, Effect as Effect2, Option, pipe } from "effect";
57
+ import * as Array from "effect/Array";
58
+ import * as Effect2 from "effect/Effect";
59
+ import * as Function2 from "effect/Function";
60
+ import * as Option from "effect/Option";
55
61
  import { Template } from "@dxos/blueprints";
56
62
  import { Obj } from "@dxos/echo";
57
63
  import { ObjectVersion } from "@dxos/echo-db";
@@ -61,7 +67,7 @@ import { DataType } from "@dxos/schema";
61
67
  import { trim } from "@dxos/util";
62
68
  var __dxlog_file = "/__w/dxos/dxos/packages/core/assistant/src/session/format.ts";
63
69
  var formatSystemPrompt = ({ system, blueprints = [], objects = [] }) => Effect2.gen(function* () {
64
- 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`
70
+ 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`
65
71
  <blueprint>
66
72
  ${Template.process(template.value.content)}
67
73
  </blueprint>
@@ -69,7 +75,7 @@ var formatSystemPrompt = ({ system, blueprints = [], objects = [] }) => Effect2.
69
75
  "## Blueprints Definitions",
70
76
  ...blueprints2
71
77
  ].join("\n\n") : void 0));
72
- const objectDefs = yield* pipe(objects, Effect2.forEach((object) => Effect2.succeed(trim`
78
+ const objectDefs = yield* Function2.pipe(objects, Effect2.forEach((object) => Effect2.succeed(trim`
73
79
  <object>
74
80
  <dxn>${Obj.getDXN(object)}</dxn>
75
81
  <typename>${Obj.getTypename(object)}</typename>
@@ -78,7 +84,7 @@ var formatSystemPrompt = ({ system, blueprints = [], objects = [] }) => Effect2.
78
84
  "## Context Objects",
79
85
  ...objects2
80
86
  ].join("\n\n") : void 0));
81
- return yield* pipe(Effect2.succeed([
87
+ return yield* Function2.pipe(Effect2.succeed([
82
88
  system,
83
89
  blueprintDefs,
84
90
  objectDefs
@@ -105,7 +111,7 @@ var formatUserPrompt = ({ prompt, history = [] }) => Effect2.gen(function* () {
105
111
  versions
106
112
  }, {
107
113
  F: __dxlog_file,
108
- L: 90,
114
+ L: 93,
109
115
  S: this,
110
116
  C: (f, a) => f(...a)
111
117
  });
@@ -167,134 +173,121 @@ ${diff}` : ""}</changed-artifact>`).join("\n")}
167
173
  };
168
174
 
169
175
  // src/session/session.ts
170
- function _define_property(obj, key, value) {
171
- if (key in obj) {
172
- Object.defineProperty(obj, key, {
173
- value,
174
- enumerable: true,
175
- configurable: true,
176
- writable: true
177
- });
178
- } else {
179
- obj[key] = value;
180
- }
181
- return obj;
182
- }
183
176
  var __dxlog_file2 = "/__w/dxos/dxos/packages/core/assistant/src/session/session.ts";
184
177
  var AiSession = class {
185
- /**
186
- * @deprecated
187
- */
188
- // TODO(burdon): Implement or remove.
189
- async runStructured(_schema, _options) {
190
- return todo();
191
- }
178
+ _options;
179
+ /** Prevents concurrent execution of session. */
180
+ _semaphore = Effect3.runSync(Effect3.makeSemaphore(1));
181
+ /** Message history from queue. */
182
+ // TODO(burdon): Evolve into supporting a git-like graph of messages.
183
+ _history = [];
184
+ /** Pending messages for this session (incl. the current prompt). */
185
+ _pending = [];
192
186
  constructor(_options = {}) {
193
- _define_property(this, "_options", void 0);
194
- _define_property(this, "_semaphore", void 0);
195
- _define_property(this, "_history", void 0);
196
- _define_property(this, "_pending", void 0);
197
- _define_property(this, "run", void 0);
198
187
  this._options = _options;
199
- this._semaphore = Effect3.runSync(Effect3.makeSemaphore(1));
200
- this._history = [];
188
+ }
189
+ run = ({ prompt, system: systemTemplate, history = [], objects = [], blueprints = [], toolkit, observer = GenerationObserver.noop() }) => Effect3.gen(this, function* () {
190
+ this._history = [
191
+ ...history
192
+ ];
201
193
  this._pending = [];
202
- this.run = ({ prompt, system: systemTemplate, history = [], objects = [], blueprints = [], toolkit, observer = GenerationObserver.noop() }) => Effect3.gen(this, function* () {
203
- this._history = [
204
- ...history
205
- ];
206
- this._pending = [];
207
- const pending = this._pending;
208
- const submitMessage = Effect3.fnUntraced(function* (message) {
209
- pending.push(message);
210
- yield* observer.onMessage(message);
211
- yield* TracingService.emitConverationMessage(message);
212
- return message;
213
- });
214
- const promptMessage = yield* submitMessage(yield* formatUserPrompt({
215
- prompt,
216
- history
217
- }));
218
- const system = yield* formatSystemPrompt({
219
- system: systemTemplate,
220
- blueprints,
221
- objects
222
- });
223
- do {
224
- log2("request", {
225
- prompt: promptMessage,
226
- system: {
227
- snippet: createSnippet(system),
228
- length: system.length
229
- },
230
- pending: this._pending.length,
231
- history: this._history.length,
232
- objects: objects?.length ?? 0
233
- }, {
234
- F: __dxlog_file2,
235
- L: 103,
236
- S: this,
237
- C: (f, a) => f(...a)
238
- });
239
- const prompt2 = yield* AiPreprocessor.preprocessPrompt([
240
- ...this._history,
241
- ...this._pending
242
- ], {
243
- system
244
- });
245
- const blocks = yield* LanguageModel.streamText({
246
- prompt: prompt2,
247
- toolkit,
248
- disableToolCallResolution: true
249
- }).pipe(
250
- // TOOD(dmaretskyi): Error mapping.
251
- AiParser.parseResponse({
252
- onBegin: () => observer.onBegin(),
253
- onBlock: (block) => observer.onBlock(block),
254
- onPart: (part) => observer.onPart(part),
255
- onEnd: (summary) => observer.onEnd(summary)
256
- }),
257
- Stream.runCollect,
258
- Effect3.map(Chunk.toArray)
259
- );
260
- const response = yield* submitMessage(Obj2.make(DataType2.Message, {
261
- created: (/* @__PURE__ */ new Date()).toISOString(),
262
- sender: {
263
- role: "assistant"
264
- },
265
- blocks
266
- }));
267
- const toolCalls = getToolCalls(response);
268
- if (toolCalls.length === 0) {
269
- break;
270
- } else if (!toolkit) {
271
- throw new Error("No toolkit provided");
272
- }
273
- const toolResults = yield* Effect3.forEach(toolCalls, (toolCall) => {
274
- return callTool(toolkit, toolCall).pipe(Effect3.provide(TracingService.layerSubframe((context) => ({
275
- ...context,
276
- parentMessage: response.id,
277
- toolCallId: toolCall.toolCallId
278
- }))));
279
- });
280
- yield* submitMessage(Obj2.make(DataType2.Message, {
281
- created: (/* @__PURE__ */ new Date()).toISOString(),
282
- sender: {
283
- role: "tool"
284
- },
285
- blocks: toolResults
286
- }));
287
- } while (true);
288
- log2("done", {
289
- pending: this._pending.length
194
+ const pending = this._pending;
195
+ const submitMessage = Effect3.fnUntraced(function* (message) {
196
+ pending.push(message);
197
+ yield* observer.onMessage(message);
198
+ yield* TracingService.emitConverationMessage(message);
199
+ return message;
200
+ });
201
+ const promptMessage = yield* submitMessage(yield* formatUserPrompt({
202
+ prompt,
203
+ history
204
+ }));
205
+ const system = yield* formatSystemPrompt({
206
+ system: systemTemplate,
207
+ blueprints,
208
+ objects
209
+ });
210
+ do {
211
+ log2("request", {
212
+ prompt: promptMessage,
213
+ system: {
214
+ snippet: createSnippet(system),
215
+ length: system.length
216
+ },
217
+ pending: this._pending.length,
218
+ history: this._history.length,
219
+ objects: objects?.length ?? 0
290
220
  }, {
291
221
  F: __dxlog_file2,
292
- L: 174,
222
+ L: 110,
293
223
  S: this,
294
224
  C: (f, a) => f(...a)
295
225
  });
296
- return this._pending;
297
- }).pipe(this._semaphore.withPermits(1), Effect3.withSpan("AiSession.run"));
226
+ const prompt2 = yield* AiPreprocessor.preprocessPrompt([
227
+ ...this._history,
228
+ ...this._pending
229
+ ], {
230
+ system
231
+ });
232
+ const blocks = yield* LanguageModel.streamText({
233
+ prompt: prompt2,
234
+ toolkit,
235
+ disableToolCallResolution: true
236
+ }).pipe(
237
+ // TOOD(dmaretskyi): Error mapping.
238
+ AiParser.parseResponse({
239
+ onBegin: () => observer.onBegin(),
240
+ onBlock: (block) => observer.onBlock(block),
241
+ onPart: (part) => observer.onPart(part),
242
+ onEnd: (summary) => observer.onEnd(summary)
243
+ }),
244
+ Stream.runCollect,
245
+ Effect3.map(Chunk.toArray)
246
+ );
247
+ const response = yield* submitMessage(Obj2.make(DataType2.Message, {
248
+ created: (/* @__PURE__ */ new Date()).toISOString(),
249
+ sender: {
250
+ role: "assistant"
251
+ },
252
+ blocks
253
+ }));
254
+ const toolCalls = getToolCalls(response);
255
+ if (toolCalls.length === 0) {
256
+ break;
257
+ } else if (!toolkit) {
258
+ throw new Error("No toolkit provided");
259
+ }
260
+ const toolResults = yield* Effect3.forEach(toolCalls, (toolCall) => {
261
+ return callTool(toolkit, toolCall).pipe(Effect3.provide(TracingService.layerSubframe((context) => ({
262
+ ...context,
263
+ parentMessage: response.id,
264
+ toolCallId: toolCall.toolCallId
265
+ }))));
266
+ });
267
+ yield* submitMessage(Obj2.make(DataType2.Message, {
268
+ created: (/* @__PURE__ */ new Date()).toISOString(),
269
+ sender: {
270
+ role: "tool"
271
+ },
272
+ blocks: toolResults
273
+ }));
274
+ } while (true);
275
+ log2("done", {
276
+ pending: this._pending.length
277
+ }, {
278
+ F: __dxlog_file2,
279
+ L: 181,
280
+ S: this,
281
+ C: (f, a) => f(...a)
282
+ });
283
+ return this._pending;
284
+ }).pipe(this._semaphore.withPermits(1), Effect3.withSpan("AiSession.run"));
285
+ /**
286
+ * @deprecated
287
+ */
288
+ // TODO(burdon): Implement or remove.
289
+ async runStructured(_schema, _options) {
290
+ return todo();
298
291
  }
299
292
  };
300
293
  var createSnippet = (text, len = 32) => text.length <= len * 2 ? text : [
@@ -304,8 +297,8 @@ var createSnippet = (text, len = 32) => text.length <= len * 2 ? text : [
304
297
  ].join("");
305
298
 
306
299
  // src/session/toolkit.ts
307
- import { Toolkit } from "@effect/ai";
308
- import { Effect as Effect4 } from "effect";
300
+ import * as Toolkit from "@effect/ai/Toolkit";
301
+ import * as Effect4 from "effect/Effect";
309
302
  import { ToolExecutionService, ToolResolverService } from "@dxos/ai";
310
303
  import { isTruthy } from "@dxos/util";
311
304
  var createToolkit = ({ toolkit: toolkitParam, toolIds = [], blueprints = [] }) => Effect4.gen(function* () {
@@ -322,23 +315,9 @@ var createToolkit = ({ toolkit: toolkitParam, toolIds = [], blueprints = [] }) =
322
315
  });
323
316
 
324
317
  // src/session/version-pin.ts
325
- import { Schema } from "effect";
318
+ import * as Schema from "effect/Schema";
319
+ import { ObjectId } from "@dxos/echo/internal";
326
320
  import { getVersion } from "@dxos/echo-db";
327
- import { ObjectId } from "@dxos/echo-schema";
328
- function _define_property2(obj, key, value) {
329
- if (key in obj) {
330
- Object.defineProperty(obj, key, {
331
- value,
332
- enumerable: true,
333
- configurable: true,
334
- writable: true
335
- });
336
- } else {
337
- obj[key] = value;
338
- }
339
- return obj;
340
- }
341
- var _class;
342
321
  var ObjectVersionSchema = Schema.Unknown;
343
322
  var VersionPinSchema = Schema.Struct({
344
323
  // TODO(dmaretskyi): Use Ref when those support encoding.
@@ -346,7 +325,8 @@ var VersionPinSchema = Schema.Struct({
346
325
  // TODO(dmaretskyi): Could be opaque.
347
326
  version: ObjectVersionSchema
348
327
  });
349
- var VersionPin = (_class = class extends VersionPinSchema {
328
+ var VersionPin = class extends VersionPinSchema {
329
+ static DISPOSITION = "version-pin";
350
330
  static fromObject(object) {
351
331
  return VersionPin.make({
352
332
  objectId: object.id,
@@ -360,7 +340,7 @@ var VersionPin = (_class = class extends VersionPinSchema {
360
340
  data: JSON.stringify(pin)
361
341
  };
362
342
  }
363
- }, _define_property2(_class, "DISPOSITION", "version-pin"), _class);
343
+ };
364
344
 
365
345
  export {
366
346
  ArtifactDiffResolver,
@@ -371,4 +351,4 @@ export {
371
351
  createToolkit,
372
352
  VersionPin
373
353
  };
374
- //# sourceMappingURL=chunk-ILL2CN3G.mjs.map
354
+ //# sourceMappingURL=chunk-4VIJTKPM.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,MA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AgB;AAWlB,IAAMC,gBAAgB,CAA8C,EACzEC,SAASC,cACTC,UAAU,CAAA,GACVC,aAAa,CAAA,EAAE,MAMRC,YAAI,aAAA;AACT,QAAMC,mBAAmB,OAAOC,oBAAoBC,eAAe;OAC9DJ,WAAWK,QAAQ,CAAC,EAAEC,MAAK,MAAOA,KAAAA;OAClCP;GACJ;AAED,QAAMQ,0BAAkE,OAAOL,iBAAiBM,UAC9FC,qBAAqBC,YAAYR,gBAAAA,CAAAA;AAGnC,QAAML,UAAkBc,cAAK,GAAI;IAACb;IAAcI;IAAkBU,OAAOC,QAAAA,CAAAA;AACzE,SAAO,OAAOhB,QAAQiB,KAAYC,gBAAQR,uBAAAA,CAAAA;AAK5C,CAAA;;;AC3CF,YAAYS,YAAY;AAExB,SAA6BC,gBAAgB;AAE7C,SAASC,kBAAkB;AAI3B,IAAMC,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,6 +1,6 @@
1
1
  import {
2
2
  AiSession
3
- } from "../chunk-ILL2CN3G.mjs";
3
+ } from "../chunk-4VIJTKPM.mjs";
4
4
  import {
5
5
  combineNerTokens,
6
6
  createTokenGroups,
@@ -9,9 +9,9 @@ import {
9
9
  } from "../chunk-UB26N5UF.mjs";
10
10
 
11
11
  // src/extraction/extraction.ts
12
- import { Schema } from "effect";
12
+ import * as Schema from "effect/Schema";
13
13
  import { asyncTimeout } from "@dxos/async";
14
- import { Expando } from "@dxos/echo-schema";
14
+ import { Expando } from "@dxos/echo/internal";
15
15
  import { log } from "@dxos/log";
16
16
  import { DataType } from "@dxos/schema";
17
17
  var __dxlog_file = "/__w/dxos/dxos/packages/core/assistant/src/extraction/extraction.ts";
@@ -57,14 +57,14 @@ var processTranscriptMessage = async (params) => {
57
57
  // src/extraction/extraction-llm-function/extraction-llm-function.ts
58
58
  import { AiService } from "@dxos/ai";
59
59
  import { Obj } from "@dxos/echo";
60
- import { create } from "@dxos/echo-schema";
60
+ import { create } from "@dxos/echo/internal";
61
61
  import { defineFunction } from "@dxos/functions";
62
62
  import { DataType as DataType2 } from "@dxos/schema";
63
63
 
64
64
  // src/extraction/quotes.ts
65
- import { Schema as Schema2 } from "effect";
65
+ import * as Schema2 from "effect/Schema";
66
66
  import { Filter, Query } from "@dxos/echo";
67
- import { ObjectId } from "@dxos/echo-schema";
67
+ import { ObjectId } from "@dxos/echo/internal";
68
68
  import { DXN } from "@dxos/keys";
69
69
  import { log as log2 } from "@dxos/log";
70
70
  var __dxlog_file2 = "/__w/dxos/dxos/packages/core/assistant/src/extraction/quotes.ts";
@@ -175,7 +175,7 @@ var extractionAnthropicFunction = defineFunction({
175
175
 
176
176
  // src/extraction/extraction-ner-function/extraction-ner-function.ts
177
177
  import { asyncTimeout as asyncTimeout2 } from "@dxos/async";
178
- import { create as create2 } from "@dxos/echo-schema";
178
+ import { create as create2 } from "@dxos/echo/internal";
179
179
  import { DatabaseService, defineFunction as defineFunction2 } from "@dxos/functions";
180
180
  import { invariant } from "@dxos/invariant";
181
181
  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,SAASA,cAAc;AAEvB,SAASC,oBAAoB;AAC7B,SAASC,eAAe;AAExB,SAASC,WAAW;AACpB,SAASC,gBAAgB;;AAElB,IAAMC,kBAAkBL,OAAOM,OAAO;EAC3CC,SAASH,SAASI;EAClBC,SAAST,OAAOU,SAASV,OAAOW,MAAMT,OAAAA,CAAAA;EACtCU,SAASZ,OAAOU,SACdV,OAAOM,OAAO;IACZO,SAASb,OAAOU,SAASV,OAAOc,MAAM;IACtCC,eAAef,OAAOU,SAASV,OAAOgB,OAAO;EAC/C,CAAA,CAAA;AAEJ,CAAA;AAGO,IAAMC,mBAAmBjB,OAAOM,OAAO;EAC5CC,SAASH,SAASI;EAClBU,aAAalB,OAAOc;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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AChC,UAAMI,kBAAkB,MAAMC,WAC5BL,SAASN,IAAI,CAACY,WAAWA,OAAOC,IAAI,GACpCrB,EAAAA;AAGF,UAAMsB,uBAAuB9B,QAAQe,OAAOC,IAAI,CAACC,UAAAA;AAC/CC,gBAAUD,MAAME,SAAS,gBAAgBF,MAAME,SAAS,QAAA,QAAA;;;;;;;;;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;",
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,OA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B,QAAQe,OAAOC,IAAI,CAACC,UAAAA;AAC/CC,gBAAUD,MAAME,SAAS,gBAAgBF,MAAME,SAAS,QAAA,QAAA;;;;;;;;;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
  }