@dxos/assistant 0.8.4-main.f9ba587 → 0.8.4-main.fd6878d

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 (145) hide show
  1. package/dist/lib/browser/chunk-6WRGDEMH.mjs +89 -0
  2. package/dist/lib/browser/chunk-6WRGDEMH.mjs.map +7 -0
  3. package/dist/lib/browser/chunk-NZGGCEF3.mjs +341 -0
  4. package/dist/lib/browser/chunk-NZGGCEF3.mjs.map +7 -0
  5. package/dist/lib/browser/extraction/index.mjs +269 -0
  6. package/dist/lib/browser/extraction/index.mjs.map +7 -0
  7. package/dist/lib/browser/index.mjs +240 -1905
  8. package/dist/lib/browser/index.mjs.map +4 -4
  9. package/dist/lib/browser/meta.json +1 -1
  10. package/dist/lib/browser/named-entity-recognition-O46UTCLR.mjs +13 -0
  11. package/dist/lib/browser/named-entity-recognition-O46UTCLR.mjs.map +7 -0
  12. package/dist/lib/node-esm/chunk-3UU5V4FS.mjs +91 -0
  13. package/dist/lib/node-esm/chunk-3UU5V4FS.mjs.map +7 -0
  14. package/dist/lib/node-esm/chunk-XOOPGSGW.mjs +343 -0
  15. package/dist/lib/node-esm/chunk-XOOPGSGW.mjs.map +7 -0
  16. package/dist/lib/node-esm/extraction/index.mjs +270 -0
  17. package/dist/lib/node-esm/extraction/index.mjs.map +7 -0
  18. package/dist/lib/node-esm/index.mjs +240 -1906
  19. package/dist/lib/node-esm/index.mjs.map +4 -4
  20. package/dist/lib/node-esm/meta.json +1 -1
  21. package/dist/lib/node-esm/named-entity-recognition-W4VMRCH6.mjs +14 -0
  22. package/dist/lib/node-esm/named-entity-recognition-W4VMRCH6.mjs.map +7 -0
  23. package/dist/types/src/conversation/context.d.ts +90 -0
  24. package/dist/types/src/conversation/context.d.ts.map +1 -0
  25. package/dist/types/src/conversation/conversation.d.ts +31 -25
  26. package/dist/types/src/conversation/conversation.d.ts.map +1 -1
  27. package/dist/types/src/conversation/index.d.ts +1 -0
  28. package/dist/types/src/conversation/index.d.ts.map +1 -1
  29. package/dist/types/src/errors.d.ts +39 -0
  30. package/dist/types/src/errors.d.ts.map +1 -0
  31. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts.map +1 -1
  32. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts +143 -45
  33. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts.map +1 -1
  34. package/dist/types/src/extraction/extraction-ner-function/named-entity-recognition.d.ts +1 -1
  35. package/dist/types/src/extraction/extraction-ner-function/named-entity-recognition.d.ts.map +1 -1
  36. package/dist/types/src/extraction/extraction.d.ts +106 -44
  37. package/dist/types/src/extraction/extraction.d.ts.map +1 -1
  38. package/dist/types/src/functions/index.d.ts +2 -0
  39. package/dist/types/src/functions/index.d.ts.map +1 -0
  40. package/dist/types/src/functions/services.d.ts +7 -0
  41. package/dist/types/src/functions/services.d.ts.map +1 -0
  42. package/dist/types/src/index.d.ts +3 -5
  43. package/dist/types/src/index.d.ts.map +1 -1
  44. package/dist/types/src/session/artifact-diff.d.ts +27 -0
  45. package/dist/types/src/session/artifact-diff.d.ts.map +1 -0
  46. package/dist/types/src/session/format.d.ts +168 -0
  47. package/dist/types/src/session/format.d.ts.map +1 -0
  48. package/dist/types/src/session/format.test.d.ts +2 -0
  49. package/dist/types/src/session/format.test.d.ts.map +1 -0
  50. package/dist/types/src/session/index.d.ts +1 -0
  51. package/dist/types/src/session/index.d.ts.map +1 -1
  52. package/dist/types/src/session/session.d.ts +123 -239
  53. package/dist/types/src/session/session.d.ts.map +1 -1
  54. package/dist/types/src/session/version-pin.d.ts +4 -4
  55. package/dist/types/src/session/version-pin.d.ts.map +1 -1
  56. package/dist/types/src/templates/index.d.ts +2 -0
  57. package/dist/types/src/templates/index.d.ts.map +1 -0
  58. package/dist/types/src/templates/system.d.ts +22 -0
  59. package/dist/types/src/templates/system.d.ts.map +1 -0
  60. package/dist/types/src/types.d.ts +13 -0
  61. package/dist/types/src/types.d.ts.map +1 -1
  62. package/dist/types/tsconfig.tsbuildinfo +1 -1
  63. package/package.json +46 -22
  64. package/src/{context/binder.ts → conversation/context.ts} +51 -19
  65. package/src/conversation/conversation.ts +90 -68
  66. package/src/conversation/index.ts +1 -0
  67. package/src/errors.ts +10 -0
  68. package/src/extraction/extraction-llm-function/extraction-llm-function.test.ts +7 -18
  69. package/src/extraction/extraction-llm-function/extraction-llm-function.ts +22 -17
  70. package/src/extraction/extraction-ner-function/extraction-ner-function.test.ts +4 -3
  71. package/src/extraction/extraction-ner-function/extraction-ner-function.ts +7 -4
  72. package/src/extraction/extraction-ner-function/named-entity-recognition.test.ts +2 -2
  73. package/src/extraction/extraction-ner-function/named-entity-recognition.ts +1 -1
  74. package/src/extraction/quotes.test.ts +1 -1
  75. package/src/extraction/quotes.ts +1 -1
  76. package/src/functions/index.ts +5 -0
  77. package/src/functions/services.ts +114 -0
  78. package/src/index.ts +3 -5
  79. package/src/session/__snapshots__/session.test.ts.snap +32 -0
  80. package/src/session/artifact-diff.ts +37 -0
  81. package/src/session/format.test.ts +60 -0
  82. package/src/session/format.ts +139 -0
  83. package/src/session/index.ts +1 -0
  84. package/src/session/session.test.ts +87 -57
  85. package/src/session/session.ts +220 -523
  86. package/src/session/version-pin.test.ts +2 -21
  87. package/src/session/version-pin.ts +9 -9
  88. package/src/summarization/summarization.test.ts +82 -106
  89. package/src/templates/format.tpl +55 -0
  90. package/src/templates/index.ts +5 -0
  91. package/src/templates/system.tpl +47 -0
  92. package/src/templates/system.ts +32 -0
  93. package/src/types.ts +45 -1
  94. package/src/typings.d.ts +5 -0
  95. package/dist/types/bin/chat.d.ts +0 -2
  96. package/dist/types/bin/chat.d.ts.map +0 -1
  97. package/dist/types/src/blueprint/blueprint.d.ts +0 -41
  98. package/dist/types/src/blueprint/blueprint.d.ts.map +0 -1
  99. package/dist/types/src/blueprint/index.d.ts +0 -3
  100. package/dist/types/src/blueprint/index.d.ts.map +0 -1
  101. package/dist/types/src/blueprint/registry.d.ts +0 -7
  102. package/dist/types/src/blueprint/registry.d.ts.map +0 -1
  103. package/dist/types/src/context/binder.d.ts +0 -34
  104. package/dist/types/src/context/binder.d.ts.map +0 -1
  105. package/dist/types/src/context/binding.d.ts +0 -38
  106. package/dist/types/src/context/binding.d.ts.map +0 -1
  107. package/dist/types/src/context/index.d.ts +0 -3
  108. package/dist/types/src/context/index.d.ts.map +0 -1
  109. package/dist/types/src/research/exa.d.ts +0 -7
  110. package/dist/types/src/research/exa.d.ts.map +0 -1
  111. package/dist/types/src/research/graph.d.ts +0 -41
  112. package/dist/types/src/research/graph.d.ts.map +0 -1
  113. package/dist/types/src/research/graph.test.d.ts +0 -2
  114. package/dist/types/src/research/graph.test.d.ts.map +0 -1
  115. package/dist/types/src/research/index.d.ts +0 -4
  116. package/dist/types/src/research/index.d.ts.map +0 -1
  117. package/dist/types/src/research/research.d.ts +0 -10
  118. package/dist/types/src/research/research.d.ts.map +0 -1
  119. package/dist/types/src/research/research.test.d.ts +0 -2
  120. package/dist/types/src/research/research.test.d.ts.map +0 -1
  121. package/dist/types/src/testing/exa-search-1748337321991.d.ts +0 -38
  122. package/dist/types/src/testing/exa-search-1748337321991.d.ts.map +0 -1
  123. package/dist/types/src/testing/exa-search-1748337331526.d.ts +0 -37
  124. package/dist/types/src/testing/exa-search-1748337331526.d.ts.map +0 -1
  125. package/dist/types/src/testing/exa-search-1748337344119.d.ts +0 -58
  126. package/dist/types/src/testing/exa-search-1748337344119.d.ts.map +0 -1
  127. package/dist/types/src/testing/index.d.ts +0 -3
  128. package/dist/types/src/testing/index.d.ts.map +0 -1
  129. package/src/blueprint/blueprint.ts +0 -75
  130. package/src/blueprint/index.ts +0 -6
  131. package/src/blueprint/registry.ts +0 -15
  132. package/src/context/binding.ts +0 -31
  133. package/src/context/index.ts +0 -6
  134. package/src/research/exa.ts +0 -100
  135. package/src/research/graph.test.ts +0 -15
  136. package/src/research/graph.ts +0 -337
  137. package/src/research/index.ts +0 -7
  138. package/src/research/instructions-research.tpl +0 -97
  139. package/src/research/research.test.ts +0 -190
  140. package/src/research/research.ts +0 -90
  141. package/src/testing/exa-search-1748337321991.ts +0 -131
  142. package/src/testing/exa-search-1748337331526.ts +0 -144
  143. package/src/testing/exa-search-1748337344119.ts +0 -133
  144. package/src/testing/index.ts +0 -11
  145. package/src/typedefs.d.ts +0 -8
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/session/artifact-diff.ts", "../../../src/errors.ts", "../../../src/session/session.ts", "../../../src/session/format.ts", "../../../src/session/version-pin.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { Context } from 'effect';\n\nimport { type ObjectVersion } from '@dxos/echo-db';\nimport { type ObjectId } from '@dxos/echo-schema';\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(burdon): Move.\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: (artifacts: { id: ObjectId; lastVersion: ObjectVersion }[]) => 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 { BaseError } from '@dxos/errors';\n\n/**\n * Generic error for AI agent execution.\n */\nexport class AiAssistantError extends BaseError.extend('AI_ASSISTANT_ERROR') {}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { type AiError, AiLanguageModel, type AiResponse, type AiTool, AiToolkit } from '@effect/ai';\nimport { Chunk, type Context, Effect, Function, Option, Queue, type Schema, Stream } from 'effect';\n\nimport {\n type AiInputPreprocessingError,\n AiParser,\n AiPreprocessor,\n type AiToolNotFoundError,\n type ConsolePrinter,\n ToolExecutionService,\n ToolResolverService,\n callTools,\n getToolCalls,\n} from '@dxos/ai';\nimport { type Blueprint } from '@dxos/blueprints';\nimport { todo } from '@dxos/debug';\nimport { Obj } from '@dxos/echo';\nimport { log } from '@dxos/log';\nimport { type ContentBlock, DataType } from '@dxos/schema';\nimport { isNotFalsy } from '@dxos/util';\n\nimport { type AiAssistantError } from '../errors';\n\nimport { formatSystemPrompt, formatUserPrompt } from './format';\n\nexport type AiSessionOptions = {};\n\n/**\n * Live observer of the generation process.\n */\nexport interface GenerationObserver {\n /**\n * Unparsed content block parts from the model.\n */\n onPart: (part: AiResponse.Part) => Effect.Effect<void>;\n\n /**\n * Parsed content blocks from the model.\n * NOTE: Use block.pending to determine if the block was completed.\n * For each block this will be called 0..n times with a pending block and then once with the final state of the block.\n *\n * Example:\n * 1. { pending: true, text: \"Hello\"}\n * 2. { pending: true, text: \"Hello, I am a\"}\n * 3. { pending: false, text: \"Hello, I am a helpful assistant!\"}\n */\n onBlock: (block: ContentBlock.Any) => Effect.Effect<void>;\n\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 onPart = Function.constant(Effect.void),\n onBlock = Function.constant(Effect.void),\n onMessage = Function.constant(Effect.void),\n }: Partial<GenerationObserver> = {}): GenerationObserver => ({\n onPart,\n onBlock,\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\nexport type SessionRunParams<Tools extends AiTool.Any> = {\n prompt: string;\n system?: string;\n history?: DataType.Message[];\n objects?: Obj.Any[]; // TODO(burdon): Meta only (typename and id -- write to binder).\n blueprints?: Blueprint.Blueprint[];\n toolkit?: AiToolkit.AiToolkit<Tools>;\n observer?: GenerationObserver;\n};\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 /** Complete messages fired during the session, both from the model and from the user. */\n public readonly messageQueue = Effect.runSync(Queue.unbounded<DataType.Message>());\n\n // TODO(dmaretskyi): Remove the queues and convert everything to observer.\n\n /**\n * Blocks streaming from the model during the session.\n * @deprecated Use `observer.onBlock` instead.\n */\n public readonly blockQueue = Effect.runSync(Queue.unbounded<Option.Option<ContentBlock.Any>>());\n\n /** Unparsed events from the underlying generation stream. */\n public readonly eventQueue = Effect.runSync(Queue.unbounded<AiResponse.Part>());\n\n /** Prevents concurrent execution of session. */\n private readonly _semaphore = Effect.runSync(Effect.makeSemaphore(1));\n\n /** Pending messages (incl. the current user request). */\n private _pending: DataType.Message[] = [];\n\n /** Prior history from queue. */\n private _history: DataType.Message[] = [];\n\n constructor(private readonly _options: AiSessionOptions = {}) {}\n\n /**\n * Runs the AI model loop interacting with tools and artifacts.\n * @returns The messages generated by the session, including the user's prompt.\n */\n // TODO(dmaretskyi): Toolkit context doesn't get added to the effect type.\n run = <Tools extends AiTool.Any>(\n params: SessionRunParams<Tools>,\n ): Effect.Effect<\n DataType.Message[],\n AiAssistantError | AiInputPreprocessingError | AiToolNotFoundError | AiError.AiError,\n AiLanguageModel.AiLanguageModel | ToolResolverService | ToolExecutionService | AiTool.ToHandler<Tools>\n > =>\n Effect.gen(this, function* () {\n const observer = params.observer ?? GenerationObserver.noop();\n\n // Create toolkit.\n const toolkit: AiToolkit.ToHandler<Tools> = yield* createToolkit(params);\n\n // Generate system prompt.\n // TODO(budon): Dynamically resolve template variables.\n const system = yield* formatSystemPrompt(params);\n console.log(system);\n\n // Generate user prompt.\n const promptMessages = yield* formatUserPrompt(params);\n yield* this.messageQueue.offer(promptMessages);\n yield* observer.onMessage(promptMessages);\n\n this._history = [...(params.history ?? [])];\n this._pending = [promptMessages];\n\n // Potential tool-use loop.\n do {\n log.info('request', {\n prompt: promptMessages,\n system: { snippet: [system.slice(0, 32), '...', system.slice(-32)].join(''), length: system.length },\n pending: this._pending.length,\n history: this._history.length,\n objects: params.objects?.length ?? 0,\n blueprints: params.blueprints?.length ?? 0,\n toolkit: Object.values(toolkit.tools).map((tool: AiTool.Any) => tool.name),\n });\n\n // Generate the prompt and make request.\n const prompt = yield* AiPreprocessor.preprocessAiInput([...this._history, ...this._pending]);\n const blocks = yield* AiLanguageModel.streamText({\n prompt,\n system,\n toolkit,\n // TODO(burdon): Despite this flag, the model still calls tools.\n // Flag is only used in generateText (not streamText); patch and submit bug.\n // https://github.com/Effect-TS/effect/blob/main/packages/ai/ai/src/AiLanguageModel.ts#L401\n disableToolCallResolution: true,\n }).pipe(\n AiParser.parseResponse({\n onBlock: (block) =>\n Effect.all([this.blockQueue.offer(Option.some(block)), observer.onBlock(block)], { discard: true }),\n onPart: (part) => Effect.all([this.eventQueue.offer(part), observer.onPart(part)], { discard: true }),\n }),\n Stream.runCollect,\n Effect.map(Chunk.toArray),\n );\n\n // Signal to stream consumers that message blocks are complete.\n // Allows for coordination between the block and message queues\n // to prevent the streaming blocks from being rendered twice when the message is produced.\n // TODO(wittjosiah): The block queue should probably be drained at this point in the case that there is no consumer.\n yield* this.blockQueue.offer(Option.none());\n\n // Create response message.\n const response = Obj.make(DataType.Message, {\n created: new Date().toISOString(),\n sender: { role: 'assistant' },\n blocks,\n });\n this._pending.push(response);\n yield* this.messageQueue.offer(response);\n yield* observer.onMessage(response);\n\n // Parse response for tool calls.\n const toolCalls = getToolCalls(response);\n if (toolCalls.length === 0) {\n break;\n }\n\n // TODO(burdon): Report errors to user; with proposed actions.\n const toolResults = yield* callTools(toolkit, toolCalls);\n const toolResultsMessage = Obj.make(DataType.Message, {\n created: new Date().toISOString(),\n sender: { role: 'user' },\n blocks: toolResults,\n });\n\n this._pending.push(toolResultsMessage);\n yield* this.messageQueue.offer(toolResultsMessage);\n yield* observer.onMessage(toolResultsMessage);\n } while (true);\n\n // Signals to stream consumers that the session has completed and no more messages are coming.\n yield* Queue.shutdown(this.messageQueue);\n yield* Queue.shutdown(this.blockQueue);\n yield* Queue.shutdown(this.eventQueue);\n\n log('done', { pending: this._pending.length });\n return this._pending;\n }).pipe(this._semaphore.withPermits(1), Effect.withSpan('AiSession.run'));\n\n // TODO(burdon): Implement.\n async runStructured<S extends Schema.Schema.AnyNoContext>(\n _schema: S,\n _options: SessionRunParams<AiTool.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\n/**\n * Build a combined toolkit from the blueprint tools and the provided toolkit.\n */\nconst createToolkit = <Tools extends AiTool.Any>({\n toolkit,\n blueprints = [],\n}: Pick<SessionRunParams<Tools>, 'toolkit' | 'blueprints'>) =>\n Effect.gen(function* () {\n const blueprintToolkit = yield* ToolResolverService.resolveToolkit(blueprints.flatMap(({ tools }) => tools));\n const blueprintToolkitHandler: Context.Context<AiTool.ToHandler<AiTool.Any>> = yield* blueprintToolkit.toContext(\n ToolExecutionService.handlersFor(blueprintToolkit),\n );\n\n return yield* AiToolkit.merge(...[toolkit, blueprintToolkit].filter(isNotFalsy)).pipe(\n Effect.provide(blueprintToolkitHandler),\n ) as Effect.Effect<AiToolkit.ToHandler<any>, never, AiTool.ToHandler<Tools>>;\n });\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { Array, Effect, Option, pipe } from 'effect';\n\nimport { Template } from '@dxos/blueprints';\nimport { Obj } from '@dxos/echo';\nimport { ObjectVersion } from '@dxos/echo-db';\nimport { type ObjectId } from '@dxos/echo-schema';\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 SessionRunParams } 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<SessionRunParams<any>, 'system' | 'blueprints' | 'objects'>) =>\n Effect.gen(function* () {\n // TOOD(burdon): Should process templates.\n const blueprintDefs = yield* pipe(\n blueprints,\n Effect.forEach((blueprint) => Effect.succeed(blueprint.instructions)),\n Effect.flatMap(Effect.forEach((template) => DatabaseService.load(template.source))),\n Effect.map(\n Array.map(\n (template) => trim`\n <blueprint>\n ${Template.process(template.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* 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* 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<SessionRunParams<any>, 'prompt' | 'history'>) =>\n Effect.gen(function* () {\n const prelude: 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('Artifact diff resolution error'),\n });\n\n log.info('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 prelude.push({ _tag: 'anchor', objectId: id, version });\n }\n\n if (artifactDiff.size > 0) {\n prelude.push(createArtifactUpdateBlock(artifactDiff));\n }\n }\n\n return Obj.make(DataType.Message, {\n created: new Date().toISOString(),\n sender: { role: 'user' },\n blocks: [...prelude, { _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 { Schema } from 'effect';\n\nimport { type ObjectVersion } from '@dxos/echo-db';\nimport { getVersion } from '@dxos/echo-db';\nimport { type AnyEchoObject, ObjectId } from '@dxos/echo-schema';\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,SAASA,eAAe;AAejB,IAAMC,uBAAN,cAAmCC,QAAQC,IAAI,sCAAA,EAAA,EAAA;AAGjD;;;AClBL,SAASC,iBAAiB;AAKnB,IAAMC,mBAAN,cAA+BC,UAAUC,OAAO,oBAAA,EAAA;AAAuB;;;ACL9E,SAAuBC,iBAA+CC,iBAAiB;AACvF,SAASC,OAAqBC,UAAAA,SAAQC,UAAUC,UAAAA,SAAQC,OAAoBC,cAAc;AAE1F,SAEEC,UACAC,gBAGAC,sBACAC,qBACAC,WACAC,oBACK;AAEP,SAASC,YAAY;AACrB,SAASC,OAAAA,YAAW;AACpB,S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UAAUL,GAAAA;IACvB;EACF;AACF;",
6
+ "names": ["Context", "ArtifactDiffResolver", "Context", "Tag", "BaseError", "AiAssistantError", "BaseError", "extend", "AiLanguageModel", "AiToolkit", "Chunk", "Effect", "Function", "Option", "Queue", "Stream", "AiParser", "AiPreprocessor", "ToolExecutionService", "ToolResolverService", "callTools", "getToolCalls", "todo", "Obj", "log", "DataType", "isNotFalsy", "Array", "Effect", "Option", "pipe", "Template", "Obj", "ObjectVersion", "DatabaseService", "log", "DataType", "trim", "formatSystemPrompt", "system", "blueprints", "objects", "Effect", "gen", "blueprintDefs", "pipe", "forEach", "blueprint", "succeed", "instructions", "flatMap", "template", "DatabaseService", "load", "source", "map", "Array", "trim", "Template", "process", "content", "length", "join", "undefined", "objectDefs", "object", "Obj", "getDXN", "getTypename", "filter", "def", "parts", "formatUserPrompt", "prompt", "history", "prelude", "artifactDiffResolver", "serviceOption", "ArtifactDiffResolver", "Option", "isSome", "versions", "gatherObjectVersions", "artifactDiff", "tryPromise", "try", "value", "resolve", "entries", "id", "version", "lastVersion", "catch", "AiAssistantError", "wrap", "log", "info", "ObjectVersion", "equals", "get", "delete", "push", "_tag", "objectId", "size", "createArtifactUpdateBlock", "make", "DataType", "Message", "created", "Date", "toISOString", "sender", "role", "blocks", "text", "messages", "artifactIds", "Map", "message", "block", "set", "disposition", "diff", "GenerationObserver", "Object", "freeze", "make", "onPart", "Function", "constant", "Effect", "void", "onBlock", "onMessage", "noop", "fromPrinter", "printer", "block", "sync", "pending", "printContentBlock", "message", "sender", "role", "printMessage", "AiSession", "messageQueue", "blockQueue", "eventQueue", "_semaphore", "_pending", "_history", "_options", "runSync", "Queue", "unbounded", "makeSemaphore", "run", "params", "gen", "observer", "toolkit", "createToolkit", "system", "formatSystemPrompt", "console", "log", "promptMessages", "formatUserPrompt", "offer", "history", "info", "prompt", "snippet", "slice", "join", "length", "objects", "blueprints", "values", "tools", "map", "tool", "name", "AiPreprocessor", "preprocessAiInput", "blocks", "AiLanguageModel", "streamText", "disableToolCallResolution", "pipe", "AiParser", "parseResponse", "all", "Option", "some", "discard", "part", "Stream", "runCollect", "Chunk", "toArray", "none", "response", "Obj", "DataType", "Message", "created", "Date", "toISOString", "push", "toolCalls", "getToolCalls", "toolResults", "callTools", "toolResultsMessage", "shutdown", "withPermits", "withSpan", "runStructured", "_schema", "todo", "blueprintToolkit", "ToolResolverService", "resolveToolkit", "flatMap", "blueprintToolkitHandler", "toContext", "ToolExecutionService", "handlersFor", "AiToolkit", "merge", "filter", "isNotFalsy", "provide", "Schema", "getVersion", "ObjectId", "ObjectVersionSchema", "Schema", "Unknown", "VersionPinSchema", "Struct", "objectId", "ObjectId", "version", "VersionPin", "DISPOSITION", "fromObject", "object", "make", "id", "getVersion", "createBlock", "pin", "_tag", "disposition", "data", "JSON", "stringify"]
7
+ }
@@ -0,0 +1,270 @@
1
+ import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
+ import {
3
+ AiSession
4
+ } from "../chunk-XOOPGSGW.mjs";
5
+ import {
6
+ combineNerTokens,
7
+ createTokenGroups,
8
+ extractFullEntities,
9
+ getNer
10
+ } from "../chunk-3UU5V4FS.mjs";
11
+
12
+ // src/extraction/extraction.ts
13
+ import { Schema } from "effect";
14
+ import { asyncTimeout } from "@dxos/async";
15
+ import { Expando } from "@dxos/echo-schema";
16
+ import { log } from "@dxos/log";
17
+ import { DataType } from "@dxos/schema";
18
+ var __dxlog_file = "/__w/dxos/dxos/packages/core/assistant/src/extraction/extraction.ts";
19
+ var ExtractionInput = Schema.Struct({
20
+ message: DataType.Message,
21
+ objects: Schema.optional(Schema.Array(Expando)),
22
+ options: Schema.optional(Schema.Struct({
23
+ timeout: Schema.optional(Schema.Number),
24
+ fallbackToRaw: Schema.optional(Schema.Boolean)
25
+ }))
26
+ });
27
+ var ExtractionOutput = Schema.Struct({
28
+ message: DataType.Message,
29
+ timeElapsed: Schema.Number
30
+ });
31
+ var processTranscriptMessage = async (params) => {
32
+ try {
33
+ if (params.options?.timeout && params.options.timeout > 0) {
34
+ return await asyncTimeout(params.executor.invoke(params.function, params.input), params.options.timeout);
35
+ } else {
36
+ return await params.executor.invoke(params.function, params.input);
37
+ }
38
+ } catch (error) {
39
+ if (params.options?.fallbackToRaw) {
40
+ log.warn("failed to process message, falling back to raw text", {
41
+ error
42
+ }, {
43
+ F: __dxlog_file,
44
+ L: 66,
45
+ S: void 0,
46
+ C: (f, a) => f(...a)
47
+ });
48
+ return {
49
+ message: params.input.message,
50
+ timeElapsed: 0
51
+ };
52
+ } else {
53
+ throw error;
54
+ }
55
+ }
56
+ };
57
+
58
+ // src/extraction/extraction-llm-function/extraction-llm-function.ts
59
+ import { AiService, ToolRegistry } from "@dxos/ai";
60
+ import { Obj } from "@dxos/echo";
61
+ import { create } from "@dxos/echo-schema";
62
+ import { defineFunction } from "@dxos/functions";
63
+ import { DataType as DataType2 } from "@dxos/schema";
64
+
65
+ // src/extraction/quotes.ts
66
+ import { Schema as Schema2 } from "effect";
67
+ import { Filter, Query } from "@dxos/echo";
68
+ import { ObjectId } from "@dxos/echo-schema";
69
+ import { DXN } from "@dxos/keys";
70
+ import { log as log2 } from "@dxos/log";
71
+ var __dxlog_file2 = "/__w/dxos/dxos/packages/core/assistant/src/extraction/quotes.ts";
72
+ var ReferencedQuotes = Schema2.Struct({
73
+ references: Schema2.Array(Schema2.Struct({
74
+ id: Schema2.String,
75
+ quote: Schema2.String
76
+ })).pipe(Schema2.mutable).annotations({
77
+ // TODO(burdon): Does this description make sense?
78
+ description: `
79
+ The references to the context objects that are mentioned in the transcript.
80
+ Quote should match the original transcript text exactly, while id is the id of the context object.
81
+ `
82
+ })
83
+ });
84
+ var findQuotes = async (quotes, db) => {
85
+ const references = await Promise.all(quotes.map(async (quote) => {
86
+ const { objects } = await db.query(Query.select(Filter.text(quote, {
87
+ type: "vector"
88
+ }))).run();
89
+ log2.info("found quotes in vector index", {
90
+ objects,
91
+ quote
92
+ }, {
93
+ F: __dxlog_file2,
94
+ L: 35,
95
+ S: void 0,
96
+ C: (f, a) => f(...a)
97
+ });
98
+ return objects.length > 0 ? [
99
+ {
100
+ id: objects[0].id.toString(),
101
+ quote
102
+ }
103
+ ] : [];
104
+ }));
105
+ return {
106
+ references: references.flat()
107
+ };
108
+ };
109
+ var insertReferences = (text, quotes) => {
110
+ for (const quote of quotes.references) {
111
+ if (!ObjectId.isValid(quote.id)) {
112
+ continue;
113
+ }
114
+ const regex = new RegExp(quote.quote.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "gi");
115
+ text = text.replace(regex, `[${quote.quote}][${DXN.fromLocalObjectId(quote.id).toString()}]`);
116
+ }
117
+ return text;
118
+ };
119
+
120
+ // raw-loader:./instructions.tpl?raw
121
+ var instructions_default = '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.';
122
+
123
+ // src/extraction/extraction-llm-function/extraction-llm-function.ts
124
+ var extractionAnthropicFn = defineFunction({
125
+ description: "Extract entities from the transcript message and add them to the message.",
126
+ inputSchema: ExtractionInput,
127
+ outputSchema: ExtractionOutput,
128
+ handler: async ({ data: { message, objects }, context }) => {
129
+ const startTime = performance.now();
130
+ const ai = context.getService(AiService.AiService);
131
+ const session = new AiSession({
132
+ operationModel: "configured"
133
+ });
134
+ const result = await session.runStructured(ReferencedQuotes, {
135
+ generationOptions: {
136
+ model: "@anthropic/claude-3-5-haiku-20241022"
137
+ },
138
+ client: ai.client,
139
+ systemPrompt: instructions_default,
140
+ history: [
141
+ Obj.make(DataType2.Message, {
142
+ created: (/* @__PURE__ */ new Date()).toISOString(),
143
+ sender: {
144
+ role: "user"
145
+ },
146
+ blocks: [
147
+ {
148
+ _tag: "text",
149
+ text: `<context>${JSON.stringify(objects)}</context>`
150
+ },
151
+ {
152
+ _tag: "text",
153
+ text: `<transcript>${JSON.stringify(message.blocks)}</transcript>`
154
+ }
155
+ ]
156
+ })
157
+ ],
158
+ artifacts: [],
159
+ prompt: "",
160
+ tools: [],
161
+ toolResolver: new ToolRegistry([])
162
+ });
163
+ return {
164
+ message: create(DataType2.Message, {
165
+ ...message,
166
+ blocks: message.blocks.map((block, i) => block._tag !== "transcript" ? block : {
167
+ ...block,
168
+ text: insertReferences(block.text, result)
169
+ })
170
+ }),
171
+ timeElapsed: performance.now() - startTime
172
+ };
173
+ }
174
+ });
175
+
176
+ // src/extraction/extraction-ner-function/extraction-ner-function.ts
177
+ import { asyncTimeout as asyncTimeout2 } from "@dxos/async";
178
+ import { create as create2 } from "@dxos/echo-schema";
179
+ import { DatabaseService, defineFunction as defineFunction2 } from "@dxos/functions";
180
+ import { invariant } from "@dxos/invariant";
181
+ import { log as log3 } from "@dxos/log";
182
+ import { DataType as DataType3 } from "@dxos/schema";
183
+ var __dxlog_file3 = "/__w/dxos/dxos/packages/core/assistant/src/extraction/extraction-ner-function/extraction-ner-function.ts";
184
+ var extractionNerFn = defineFunction2({
185
+ description: "Extracts named entities from a text",
186
+ inputSchema: ExtractionInput,
187
+ outputSchema: ExtractionOutput,
188
+ handler: async ({ data: { message, options }, context }) => {
189
+ log3.info("input", {
190
+ message,
191
+ options
192
+ }, {
193
+ F: __dxlog_file3,
194
+ L: 24,
195
+ S: void 0,
196
+ C: (f, a) => f(...a)
197
+ });
198
+ const startTime = performance.now();
199
+ const { db } = context.getService(DatabaseService);
200
+ const { extractFullEntities: extractFullEntities2 } = await import("../named-entity-recognition-W4VMRCH6.mjs");
201
+ const entitiesPromise = Promise.all(message.blocks.map(async (block) => {
202
+ invariant(block._tag === "transcript" || block._tag === "text", "Block must have text", {
203
+ F: __dxlog_file3,
204
+ L: 31,
205
+ S: void 0,
206
+ A: [
207
+ "block._tag === 'transcript' || block._tag === 'text'",
208
+ "'Block must have text'"
209
+ ]
210
+ });
211
+ return extractFullEntities2(block.text);
212
+ })).then((entities2) => entities2.flat());
213
+ const entities = options?.timeout ? await asyncTimeout2(entitiesPromise, options.timeout) : await entitiesPromise;
214
+ log3.info("entities", {
215
+ entities
216
+ }, {
217
+ F: __dxlog_file3,
218
+ L: 36,
219
+ S: void 0,
220
+ C: (f, a) => f(...a)
221
+ });
222
+ const quoteReferences = await findQuotes(entities.map((entity) => entity.word), db);
223
+ const blocksWithReferences = message.blocks.map((block, i) => {
224
+ invariant(block._tag === "transcript" || block._tag === "text", "Block must have text", {
225
+ F: __dxlog_file3,
226
+ L: 42,
227
+ S: void 0,
228
+ A: [
229
+ "block._tag === 'transcript' || block._tag === 'text'",
230
+ "'Block must have text'"
231
+ ]
232
+ });
233
+ return {
234
+ ...block,
235
+ text: insertReferences(block._tag, quoteReferences)
236
+ };
237
+ });
238
+ const messageWithReferences = create2(DataType3.Message, {
239
+ ...message,
240
+ blocks: blocksWithReferences
241
+ });
242
+ log3.info("output", {
243
+ messageWithReferences
244
+ }, {
245
+ F: __dxlog_file3,
246
+ L: 50,
247
+ S: void 0,
248
+ C: (f, a) => f(...a)
249
+ });
250
+ return {
251
+ message: messageWithReferences,
252
+ timeElapsed: performance.now() - startTime
253
+ };
254
+ }
255
+ });
256
+ export {
257
+ ExtractionInput,
258
+ ExtractionOutput,
259
+ ReferencedQuotes,
260
+ combineNerTokens,
261
+ createTokenGroups,
262
+ extractFullEntities,
263
+ extractionAnthropicFn,
264
+ extractionNerFn,
265
+ findQuotes,
266
+ getNer,
267
+ insertReferences,
268
+ processTranscriptMessage
269
+ };
270
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/extraction/extraction.ts", "../../../../src/extraction/extraction-llm-function/extraction-llm-function.ts", "../../../../src/extraction/quotes.ts", "raw-loader:./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, ToolRegistry } 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 extractionAnthropicFn: FunctionDefinition<ExtractionInput, ExtractionOutput> = defineFunction({\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 toolResolver: new ToolRegistry([]),\n } as any); // TODO(burdon): Rewrite test.\n\n return {\n message: create(DataType.Message, {\n ...message,\n blocks: message.blocks.map((block, i) =>\n block._tag !== 'transcript'\n ? block\n : {\n ...block,\n text: insertReferences(block.text, result),\n },\n ),\n }),\n timeElapsed: performance.now() - startTime,\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// TODO(mykola): Make it use vector index to query objects and not pass objects as input.\nexport const extractionNerFn = defineFunction({\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', 'Block must have 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 log.info('entities', { entities });\n const quoteReferences = await findQuotes(\n entities.map((entity) => entity.word),\n db,\n );\n const blocksWithReferences = message.blocks.map((block, i) => {\n invariant(block._tag === 'transcript' || block._tag === 'text', 'Block must have text');\n return { ...block, text: insertReferences(block._tag, quoteReferences) };\n });\n const messageWithReferences = create(DataType.Message, {\n ...message,\n blocks: blocksWithReferences,\n });\n\n log.info('output', { messageWithReferences });\n\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,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;AACjCZ,UAAIuB,KAAK,uDAAuD;QAAED;MAAM,GAAA;;;;;;AACxE,aAAO;QACLlB,SAASa,OAAOI,MAAMjB;QACtBW,aAAa;MACf;IACF,OAAO;AACL,YAAMO;IACR;EACF;AACF;;;ACnEA,SAASE,WAAWC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O,wBAAwBC,QAAOC,UAASC,SAAS;MACrD,GAAGpC;MACHe,QAAQe;IACV,CAAA;AAEA3B,IAAAA,KAAIC,KAAK,UAAU;MAAE6B;IAAsB,GAAA;;;;;;AAE3C,WAAO;MACLjC,SAASiC;MACTI,aAAa/B,YAAYC,IAAG,IAAKF;IACnC;EACF;AACF,CAAA;",
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", "ToolRegistry", "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", "extractionAnthropicFn", "defineFunction", "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", "toolResolver", "ToolRegistry", "create", "map", "block", "i", "insertReferences", "timeElapsed", "asyncTimeout", "create", "DatabaseService", "defineFunction", "invariant", "log", "DataType", "extractionNerFn", "defineFunction", "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", "i", "insertReferences", "messageWithReferences", "create", "DataType", "Message", "timeElapsed"]
7
+ }