@dxos/assistant 0.7.4 → 0.7.5-labs.071a3e2

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 (115) hide show
  1. package/dist/lib/browser/chunk-AXUUNA7O.mjs +565 -0
  2. package/dist/lib/browser/chunk-AXUUNA7O.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +1212 -47
  4. package/dist/lib/browser/index.mjs.map +4 -4
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/testing/index.mjs +15 -9
  7. package/dist/lib/browser/testing/index.mjs.map +4 -4
  8. package/dist/lib/node/chunk-QPHGQINW.cjs +577 -0
  9. package/dist/lib/node/chunk-QPHGQINW.cjs.map +7 -0
  10. package/dist/lib/node/index.cjs +1212 -54
  11. package/dist/lib/node/index.cjs.map +4 -4
  12. package/dist/lib/node/meta.json +1 -1
  13. package/dist/lib/node/testing/index.cjs +21 -14
  14. package/dist/lib/node/testing/index.cjs.map +4 -4
  15. package/dist/lib/node-esm/chunk-GOVFOBIB.mjs +567 -0
  16. package/dist/lib/node-esm/chunk-GOVFOBIB.mjs.map +7 -0
  17. package/dist/lib/node-esm/index.mjs +1212 -47
  18. package/dist/lib/node-esm/index.mjs.map +4 -4
  19. package/dist/lib/node-esm/meta.json +1 -1
  20. package/dist/lib/node-esm/testing/index.mjs +15 -9
  21. package/dist/lib/node-esm/testing/index.mjs.map +4 -4
  22. package/dist/types/src/ai-service/client.d.ts +16 -32
  23. package/dist/types/src/ai-service/client.d.ts.map +1 -1
  24. package/dist/types/src/ai-service/index.d.ts +4 -1
  25. package/dist/types/src/ai-service/index.d.ts.map +1 -1
  26. package/dist/types/src/ai-service/parser.d.ts +136 -0
  27. package/dist/types/src/ai-service/parser.d.ts.map +1 -0
  28. package/dist/types/src/ai-service/stream.d.ts +39 -0
  29. package/dist/types/src/ai-service/stream.d.ts.map +1 -0
  30. package/dist/types/src/ai-service/stream.test.d.ts +2 -0
  31. package/dist/types/src/ai-service/stream.test.d.ts.map +1 -0
  32. package/dist/types/src/ai-service/testing.d.ts +7 -0
  33. package/dist/types/src/ai-service/testing.d.ts.map +1 -0
  34. package/dist/types/src/ai-service/transform.d.ts +27 -0
  35. package/dist/types/src/ai-service/transform.d.ts.map +1 -0
  36. package/dist/types/src/ai-service/types.d.ts +150 -0
  37. package/dist/types/src/ai-service/types.d.ts.map +1 -0
  38. package/dist/types/src/ai-service/util/index.d.ts +2 -0
  39. package/dist/types/src/ai-service/util/index.d.ts.map +1 -0
  40. package/dist/types/src/ai-service/{sse.d.ts → util/sse.d.ts} +5 -0
  41. package/dist/types/src/ai-service/util/sse.d.ts.map +1 -0
  42. package/dist/types/src/conversation/conversation.d.ts +61 -6
  43. package/dist/types/src/conversation/conversation.d.ts.map +1 -1
  44. package/dist/types/src/conversation/index.d.ts +0 -1
  45. package/dist/types/src/conversation/index.d.ts.map +1 -1
  46. package/dist/types/src/conversation/types.d.ts +44 -13
  47. package/dist/types/src/conversation/types.d.ts.map +1 -1
  48. package/dist/types/src/cypher/combinators.d.ts.map +1 -1
  49. package/dist/types/src/cypher/parjs.d.ts +1 -1
  50. package/dist/types/src/cypher/parjs.d.ts.map +1 -1
  51. package/dist/types/src/cypher/schema.d.ts.map +1 -1
  52. package/dist/types/src/testing/artifacts.test.d.ts +1 -0
  53. package/dist/types/src/testing/artifacts.test.d.ts.map +1 -0
  54. package/dist/types/src/testing/data.d.ts +2 -0
  55. package/dist/types/src/testing/data.d.ts.map +1 -0
  56. package/dist/types/src/testing/defs.d.ts +5 -0
  57. package/dist/types/src/testing/defs.d.ts.map +1 -0
  58. package/dist/types/src/testing/index.d.ts +1 -0
  59. package/dist/types/src/testing/index.d.ts.map +1 -1
  60. package/dist/types/src/testing/logger.d.ts +1 -1
  61. package/dist/types/src/testing/logger.d.ts.map +1 -1
  62. package/dist/types/src/testing/query-promts.d.ts +1 -1
  63. package/dist/types/src/testing/query-promts.d.ts.map +1 -1
  64. package/dist/types/src/testing/test-data.d.ts +1 -1
  65. package/dist/types/src/testing/test-data.d.ts.map +1 -1
  66. package/dist/types/src/testing/test-schema.d.ts +4 -4
  67. package/dist/types/tsconfig.tsbuildinfo +1 -1
  68. package/package.json +22 -18
  69. package/src/ai-service/client.test.ts +69 -54
  70. package/src/ai-service/client.ts +29 -184
  71. package/src/ai-service/index.ts +4 -1
  72. package/src/ai-service/parser.ts +338 -0
  73. package/src/ai-service/stream.test.ts +101 -0
  74. package/src/ai-service/stream.ts +116 -0
  75. package/src/ai-service/testing.ts +93 -0
  76. package/src/ai-service/transform.ts +121 -0
  77. package/src/ai-service/types.ts +107 -0
  78. package/src/ai-service/util/index.ts +5 -0
  79. package/src/ai-service/{sse.ts → util/sse.ts} +5 -0
  80. package/src/bin/chat.ts +10 -11
  81. package/src/conversation/conversation.test.ts +16 -17
  82. package/src/conversation/conversation.ts +126 -20
  83. package/src/conversation/index.ts +0 -1
  84. package/src/conversation/types.ts +55 -16
  85. package/src/cypher/combinators.test.ts +4 -4
  86. package/src/cypher/combinators.ts +0 -1
  87. package/src/cypher/execution-plan.test.ts +5 -3
  88. package/src/cypher/parjs-shims.d.ts +4 -0
  89. package/src/cypher/parjs.ts +2 -2
  90. package/src/cypher/query-executor.test.ts +1 -1
  91. package/src/cypher/schema.ts +6 -2
  92. package/src/index.ts +1 -1
  93. package/src/testing/artifacts.test.ts +182 -0
  94. package/src/testing/data.ts +13 -0
  95. package/src/testing/defs.ts +8 -0
  96. package/src/testing/index.ts +1 -0
  97. package/src/testing/logger.ts +3 -2
  98. package/src/testing/query-promts.ts +3 -3
  99. package/src/testing/query.test.ts +11 -10
  100. package/src/testing/test-data.ts +8 -2
  101. package/vendor/parjs-browser.mjs +4 -0
  102. package/vendor/parjs-default.mjs +8 -0
  103. package/dist/lib/browser/chunk-AKP45LQH.mjs +0 -1394
  104. package/dist/lib/browser/chunk-AKP45LQH.mjs.map +0 -7
  105. package/dist/lib/node/chunk-G6CGWEMO.cjs +0 -1418
  106. package/dist/lib/node/chunk-G6CGWEMO.cjs.map +0 -7
  107. package/dist/lib/node-esm/chunk-WUPUPEFB.mjs +0 -1396
  108. package/dist/lib/node-esm/chunk-WUPUPEFB.mjs.map +0 -7
  109. package/dist/types/src/ai-service/schema.d.ts +0 -296
  110. package/dist/types/src/ai-service/schema.d.ts.map +0 -1
  111. package/dist/types/src/ai-service/sse.d.ts.map +0 -1
  112. package/dist/types/src/sanity.test.d.ts +0 -2
  113. package/dist/types/src/sanity.test.d.ts.map +0 -1
  114. package/src/ai-service/schema.ts +0 -260
  115. package/src/sanity.test.ts +0 -9
@@ -1,72 +1,1237 @@
1
1
  import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
2
  import {
3
- AIServiceClientImpl,
4
3
  EchoDataSource,
5
- GenerateRequest,
6
- GenerationStream,
7
- ImageSource,
8
- LLMModel,
9
- LLMTool,
10
- LLMToolDefinition,
11
- LLMToolResult,
12
- Message,
13
- MessageContentBlock,
14
- MessageFromDb,
15
- MessageImageContentBlock,
16
- MessageRole,
17
- MessageTextContentBlock,
18
- MessageToolResultContentBlock,
19
- MessageToolUseContentBlock,
20
- ObjectId,
21
- ObjectIdBrand,
22
- Space,
23
- SpaceIdSchema,
24
- Thread,
25
- ToolTypes,
26
- createUserMessage,
27
- defineTool,
28
4
  executeQuery,
29
5
  executeQueryPlan,
30
6
  formatInferredRelationshipLabel,
31
7
  formatJsonSchemaForLLM,
32
8
  formatNodeLabel,
33
9
  isReference,
34
- parseCypherQuery,
35
- runLLM
36
- } from "./chunk-WUPUPEFB.mjs";
10
+ parseCypherQuery
11
+ } from "./chunk-GOVFOBIB.mjs";
12
+
13
+ // packages/experimental/assistant/src/ai-service/client.ts
14
+ import { Schema as S } from "@effect/schema";
15
+ import { Message } from "@dxos/artifact";
16
+ import { invariant } from "@dxos/invariant";
17
+
18
+ // packages/experimental/assistant/src/ai-service/stream.ts
19
+ import { Trigger } from "@dxos/async";
20
+ import { log } from "@dxos/log";
21
+
22
+ // packages/experimental/assistant/src/ai-service/util/sse.ts
23
+ async function* iterSSEMessages(response, controller) {
24
+ if (!response.body) {
25
+ controller.abort();
26
+ throw new Error("Attempted to iterate over a response with no body");
27
+ }
28
+ const sseDecoder = new SSEDecoder();
29
+ const lineDecoder = new LineDecoder();
30
+ const iter = readableStreamAsyncIterable(response.body);
31
+ for await (const sseChunk of iterSSEChunks(iter)) {
32
+ for (const line of lineDecoder.decode(sseChunk)) {
33
+ const sse = sseDecoder.decode(line);
34
+ if (sse) {
35
+ yield sse;
36
+ }
37
+ }
38
+ }
39
+ for (const line of lineDecoder.flush()) {
40
+ const sse = sseDecoder.decode(line);
41
+ if (sse) {
42
+ yield sse;
43
+ }
44
+ }
45
+ }
46
+ async function* iterSSEChunks(iterator) {
47
+ let data = new Uint8Array();
48
+ for await (const chunk of iterator) {
49
+ if (chunk == null) {
50
+ continue;
51
+ }
52
+ const binaryChunk = chunk instanceof ArrayBuffer ? new Uint8Array(chunk) : typeof chunk === "string" ? new TextEncoder().encode(chunk) : chunk;
53
+ const newData = new Uint8Array(data.length + binaryChunk.length);
54
+ newData.set(data);
55
+ newData.set(binaryChunk, data.length);
56
+ data = newData;
57
+ let patternIndex;
58
+ while ((patternIndex = findDoubleNewlineIndex(data)) !== -1) {
59
+ yield data.slice(0, patternIndex);
60
+ data = data.slice(patternIndex);
61
+ }
62
+ }
63
+ if (data.length > 0) {
64
+ yield data;
65
+ }
66
+ }
67
+ var findDoubleNewlineIndex = (buffer) => {
68
+ const newline = 10;
69
+ const carriage = 13;
70
+ for (let i = 0; i < buffer.length - 2; i++) {
71
+ if (buffer[i] === newline && buffer[i + 1] === newline) {
72
+ return i + 2;
73
+ }
74
+ if (buffer[i] === carriage && buffer[i + 1] === carriage) {
75
+ return i + 2;
76
+ }
77
+ if (buffer[i] === carriage && buffer[i + 1] === newline && i + 3 < buffer.length && buffer[i + 2] === carriage && buffer[i + 3] === newline) {
78
+ return i + 4;
79
+ }
80
+ }
81
+ return -1;
82
+ };
83
+ var SSEDecoder = class {
84
+ constructor() {
85
+ this.event = null;
86
+ this.data = [];
87
+ this.chunks = [];
88
+ }
89
+ decode(line) {
90
+ if (line.endsWith("\r")) {
91
+ line = line.substring(0, line.length - 1);
92
+ }
93
+ if (!line) {
94
+ if (!this.event && !this.data.length) {
95
+ return null;
96
+ }
97
+ const sse = {
98
+ event: this.event,
99
+ data: this.data.join("\n"),
100
+ raw: this.chunks
101
+ };
102
+ this.event = null;
103
+ this.data = [];
104
+ this.chunks = [];
105
+ return sse;
106
+ }
107
+ this.chunks.push(line);
108
+ if (line.startsWith(":")) {
109
+ return null;
110
+ }
111
+ let [fieldname, _, value] = partition(line, ":");
112
+ if (value.startsWith(" ")) {
113
+ value = value.substring(1);
114
+ }
115
+ if (fieldname === "event") {
116
+ this.event = value;
117
+ } else if (fieldname === "data") {
118
+ this.data.push(value);
119
+ }
120
+ return null;
121
+ }
122
+ };
123
+ var partition = (str, delimiter) => {
124
+ const index = str.indexOf(delimiter);
125
+ if (index !== -1) {
126
+ return [
127
+ str.substring(0, index),
128
+ delimiter,
129
+ str.substring(index + delimiter.length)
130
+ ];
131
+ }
132
+ return [
133
+ str,
134
+ "",
135
+ ""
136
+ ];
137
+ };
138
+ function readableStreamAsyncIterable(stream) {
139
+ if (stream[Symbol.asyncIterator]) {
140
+ return stream;
141
+ }
142
+ const reader = stream.getReader();
143
+ return {
144
+ next: async () => {
145
+ try {
146
+ const result = await reader.read();
147
+ if (result?.done) {
148
+ reader.releaseLock();
149
+ }
150
+ return result;
151
+ } catch (e) {
152
+ reader.releaseLock();
153
+ throw e;
154
+ }
155
+ },
156
+ return: async () => {
157
+ const cancelPromise = reader.cancel();
158
+ reader.releaseLock();
159
+ await cancelPromise;
160
+ return {
161
+ done: true,
162
+ value: void 0
163
+ };
164
+ },
165
+ [Symbol.asyncIterator]() {
166
+ return this;
167
+ }
168
+ };
169
+ }
170
+ var LineDecoder = class _LineDecoder {
171
+ static {
172
+ // prettier-ignore
173
+ this.NEWLINE_CHARS = /* @__PURE__ */ new Set([
174
+ "\n",
175
+ "\r"
176
+ ]);
177
+ }
178
+ static {
179
+ this.NEWLINE_REGEXP = /\r\n|[\n\r]/g;
180
+ }
181
+ constructor() {
182
+ this.buffer = [];
183
+ this.trailingCR = false;
184
+ }
185
+ decode(chunk) {
186
+ let text = this.decodeText(chunk);
187
+ if (this.trailingCR) {
188
+ text = "\r" + text;
189
+ this.trailingCR = false;
190
+ }
191
+ if (text.endsWith("\r")) {
192
+ this.trailingCR = true;
193
+ text = text.slice(0, -1);
194
+ }
195
+ if (!text) {
196
+ return [];
197
+ }
198
+ const trailingNewline = _LineDecoder.NEWLINE_CHARS.has(text[text.length - 1] || "");
199
+ let lines = text.split(_LineDecoder.NEWLINE_REGEXP);
200
+ if (trailingNewline) {
201
+ lines.pop();
202
+ }
203
+ if (lines.length === 1 && !trailingNewline) {
204
+ this.buffer.push(lines[0]);
205
+ return [];
206
+ }
207
+ if (this.buffer.length > 0) {
208
+ lines = [
209
+ this.buffer.join("") + lines[0],
210
+ ...lines.slice(1)
211
+ ];
212
+ this.buffer = [];
213
+ }
214
+ if (!trailingNewline) {
215
+ this.buffer = [
216
+ lines.pop() || ""
217
+ ];
218
+ }
219
+ return lines;
220
+ }
221
+ decodeText(bytes) {
222
+ if (bytes == null) {
223
+ return "";
224
+ }
225
+ if (typeof bytes === "string") {
226
+ return bytes;
227
+ }
228
+ if (typeof Buffer !== "undefined") {
229
+ if (bytes instanceof Buffer) {
230
+ return bytes.toString();
231
+ }
232
+ if (bytes instanceof Uint8Array) {
233
+ return Buffer.from(bytes).toString();
234
+ }
235
+ throw new Error(`Unexpected: received non-Uint8Array (${bytes.constructor.name}) stream chunk in an environment with a global "Buffer" defined, which this library assumes to be Node. Please report this error.`);
236
+ }
237
+ if (typeof TextDecoder !== "undefined") {
238
+ if (bytes instanceof Uint8Array || bytes instanceof ArrayBuffer) {
239
+ this.textDecoder ??= new TextDecoder("utf8");
240
+ return this.textDecoder.decode(bytes);
241
+ }
242
+ throw new Error(`Unexpected: received non-Uint8Array/ArrayBuffer (${bytes.constructor.name}) in a web platform. Please report this error.`);
243
+ }
244
+ throw new Error("Unexpected: neither Buffer nor TextDecoder are available as globals. Please report this error.");
245
+ }
246
+ flush() {
247
+ if (!this.buffer.length && !this.trailingCR) {
248
+ return [];
249
+ }
250
+ const lines = [
251
+ this.buffer.join("")
252
+ ];
253
+ this.buffer = [];
254
+ this.trailingCR = false;
255
+ return lines;
256
+ }
257
+ };
258
+
259
+ // packages/experimental/assistant/src/ai-service/stream.ts
260
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/experimental/assistant/src/ai-service/stream.ts";
261
+ var createGenerationStream = (response, controller = new AbortController()) => {
262
+ const iterator = async function* () {
263
+ for await (const sse of iterSSEMessages(response, controller)) {
264
+ if (sse.event === "completion") {
265
+ try {
266
+ yield JSON.parse(sse.data);
267
+ } catch (err) {
268
+ log.error("could not parse message into JSON:", {
269
+ data: sse.data,
270
+ raw: sse.raw
271
+ }, {
272
+ F: __dxlog_file,
273
+ L: 21,
274
+ S: this,
275
+ C: (f, a) => f(...a)
276
+ });
277
+ throw err;
278
+ }
279
+ }
280
+ if (sse.event === "message_start" || sse.event === "message_delta" || sse.event === "message_stop" || sse.event === "content_block_start" || sse.event === "content_block_delta" || sse.event === "content_block_stop") {
281
+ try {
282
+ yield JSON.parse(sse.data);
283
+ } catch (err) {
284
+ log.error("could not parse message into JSON:", {
285
+ data: sse.data,
286
+ raw: sse.raw
287
+ }, {
288
+ F: __dxlog_file,
289
+ L: 37,
290
+ S: this,
291
+ C: (f, a) => f(...a)
292
+ });
293
+ throw err;
294
+ }
295
+ }
296
+ if (sse.event === "ping") {
297
+ continue;
298
+ }
299
+ if (sse.event === "error") {
300
+ throw new Error(`Message generation error: ${sse.data}`);
301
+ }
302
+ }
303
+ };
304
+ return new GenerationStream(controller, iterator);
305
+ };
306
+ var GenerationStream = class {
307
+ constructor(_controller, _getIterator) {
308
+ this._controller = _controller;
309
+ this._getIterator = _getIterator;
310
+ this._done = new Trigger();
311
+ this._iterator = void 0;
312
+ }
313
+ /**
314
+ * Returns an iterator over the stream.
315
+ */
316
+ [Symbol.asyncIterator]() {
317
+ return this._createIterator();
318
+ }
319
+ /**
320
+ * Aborts the stream.
321
+ */
322
+ abort() {
323
+ this._controller.abort();
324
+ }
325
+ /**
326
+ * Returns the complete message list generated by the AI service.
327
+ */
328
+ async complete() {
329
+ await this._done.wait();
330
+ }
331
+ /**
332
+ * Creates an iterator over the stream.
333
+ */
334
+ _createIterator() {
335
+ const self = this;
336
+ return this._iterator ??= (() => {
337
+ const generator = async function* () {
338
+ try {
339
+ for await (const event of self._getIterator()) {
340
+ yield event;
341
+ }
342
+ this._done.wake();
343
+ } catch (err) {
344
+ this._done.throw(err);
345
+ }
346
+ };
347
+ return generator.call(this);
348
+ })();
349
+ }
350
+ };
351
+
352
+ // packages/experimental/assistant/src/ai-service/client.ts
353
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/experimental/assistant/src/ai-service/client.ts";
354
+ var AIServiceClientImpl = class {
355
+ constructor({ endpoint }) {
356
+ invariant(endpoint, "endpoint is required", {
357
+ F: __dxlog_file2,
358
+ L: 36,
359
+ S: this,
360
+ A: [
361
+ "endpoint",
362
+ "'endpoint is required'"
363
+ ]
364
+ });
365
+ this._endpoint = endpoint;
366
+ }
367
+ async getSpace(spaceId) {
368
+ throw new Error("Not implemented");
369
+ }
370
+ async getThread(spaceId, threadId) {
371
+ throw new Error("Not implemented");
372
+ }
373
+ async getMessages(spaceId, threadId) {
374
+ const res = await fetch(`${this._endpoint}/space/${spaceId}/thread/${threadId}/message`);
375
+ return S.decodePromise(S.Array(Message).pipe(S.mutable))((await res.json()).data.results);
376
+ }
377
+ async appendMessages(messages) {
378
+ const url = `${this._endpoint}/message`;
379
+ const res = await fetch(url, {
380
+ method: "POST",
381
+ headers: {
382
+ "Content-Type": "application/json"
383
+ },
384
+ body: JSON.stringify({
385
+ messages: await S.encodePromise(S.Array(Message))(messages)
386
+ })
387
+ });
388
+ if (!res.ok) {
389
+ throw new Error(`${await res.text()} [${url}]`);
390
+ }
391
+ }
392
+ // TODO(dmaretskyi): Accept partial message schema.
393
+ async updateMessage(spaceId, threadId, messageId, message) {
394
+ throw new Error("Not implemented");
395
+ }
396
+ /**
397
+ * Open message stream.
398
+ */
399
+ async generate(request) {
400
+ const controller = new AbortController();
401
+ const response = await fetch(`${this._endpoint}/generate`, {
402
+ signal: controller.signal,
403
+ method: "POST",
404
+ headers: {
405
+ "Content-Type": "application/json"
406
+ },
407
+ body: JSON.stringify(request)
408
+ });
409
+ invariant(response.body instanceof ReadableStream, void 0, {
410
+ F: __dxlog_file2,
411
+ L: 85,
412
+ S: this,
413
+ A: [
414
+ "response.body instanceof ReadableStream",
415
+ ""
416
+ ]
417
+ });
418
+ return createGenerationStream(response, controller);
419
+ }
420
+ };
421
+
422
+ // packages/experimental/assistant/src/ai-service/parser.ts
423
+ import { Message as Message2 } from "@dxos/artifact";
424
+ import { Event } from "@dxos/async";
425
+ import { createStatic } from "@dxos/echo-schema";
426
+ import { invariant as invariant2 } from "@dxos/invariant";
427
+ import { log as log2 } from "@dxos/log";
428
+ import { isNotFalsy, safeParseJson } from "@dxos/util";
429
+
430
+ // packages/experimental/assistant/src/ai-service/transform.ts
431
+ import * as P from "parsimmon";
432
+ var textChunk = P.regexp(/[^<]+/).map((content) => ({
433
+ type: "text",
434
+ content
435
+ }));
436
+ var attribute = P.seq(P.regexp(/[a-zA-Z_][a-zA-Z0-9_-]*/), P.string("=").trim(P.optWhitespace), P.alt(P.regexp(/"[^"]*"/).map((s) => s.slice(1, -1)), P.regexp(/'[^']*'/).map((s) => s.slice(1, -1)))).map(([name, _, value]) => [
437
+ name,
438
+ value
439
+ ]);
440
+ var tagName = P.regexp(/[a-zA-Z_][a-zA-Z0-9_-]*/);
441
+ var selfClosingTag = P.seqMap(
442
+ //
443
+ P.string("<"),
444
+ tagName,
445
+ P.optWhitespace.then(attribute).many(),
446
+ P.optWhitespace.then(P.string("/>")),
447
+ P.optWhitespace,
448
+ (_, tag, attributes, __) => ({
449
+ type: "tag",
450
+ tag,
451
+ attributes: Object.fromEntries(attributes),
452
+ content: [],
453
+ selfClosing: true
454
+ })
455
+ );
456
+ var openTag = P.seqMap(
457
+ //
458
+ P.string("<"),
459
+ tagName,
460
+ P.optWhitespace.then(attribute).many(),
461
+ P.string(">"),
462
+ P.regexp(/[^<]*/),
463
+ (_, tag, attributes, __, content) => ({
464
+ type: "tag",
465
+ tag,
466
+ attributes: Object.fromEntries(attributes),
467
+ content: content.length ? [
468
+ {
469
+ type: "text",
470
+ content
471
+ }
472
+ ] : []
473
+ })
474
+ );
475
+ var closeTag = P.seqMap(
476
+ //
477
+ P.string("</"),
478
+ tagName,
479
+ P.string(">"),
480
+ P.optWhitespace,
481
+ (_, tag) => ({
482
+ type: "tag",
483
+ tag,
484
+ content: [],
485
+ closing: true
486
+ })
487
+ );
488
+ var mixedChunk = P.alt(selfClosingTag, openTag, closeTag, textChunk);
489
+ var StreamTransform = class {
490
+ constructor() {
491
+ this._buffer = "";
492
+ }
493
+ transform(chunk) {
494
+ this._buffer += chunk;
495
+ const results = [];
496
+ const parser = mixedChunk.many().skip(P.optWhitespace);
497
+ const result = parser.parse(this._buffer);
498
+ if (result.status) {
499
+ for (const chunk2 of result.value) {
500
+ results.push(chunk2);
501
+ }
502
+ this._buffer = "";
503
+ }
504
+ return results;
505
+ }
506
+ // TODO(burdon): Process remaining buffer?
507
+ flush() {
508
+ const remaining = this._buffer;
509
+ this._buffer = "";
510
+ return remaining.length > 0 ? [
511
+ {
512
+ type: "text",
513
+ content: remaining
514
+ }
515
+ ] : [];
516
+ }
517
+ };
518
+
519
+ // packages/experimental/assistant/src/ai-service/parser.ts
520
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/experimental/assistant/src/ai-service/parser.ts";
521
+ var MixedStreamParser = class {
522
+ constructor() {
523
+ /**
524
+ * New message.
525
+ */
526
+ this.message = new Event();
527
+ /**
528
+ * Complete block added to Message.
529
+ */
530
+ this.block = new Event();
531
+ /**
532
+ * Update partial block (while streaming).
533
+ */
534
+ this.update = new Event();
535
+ }
536
+ _emitBlock(contentBlock, streamBlock) {
537
+ const messageBlock = streamBlock ? mergeMessageBlock(contentBlock, streamBlock) : contentBlock;
538
+ if (messageBlock) {
539
+ if (messageBlock.type === "text" && messageBlock.text.length === 0) {
540
+ return;
541
+ }
542
+ invariant2(this._message, void 0, {
543
+ F: __dxlog_file3,
544
+ L: 46,
545
+ S: this,
546
+ A: [
547
+ "this._message",
548
+ ""
549
+ ]
550
+ });
551
+ this._message.content.push(messageBlock);
552
+ this.block.emit(messageBlock);
553
+ }
554
+ }
555
+ _emitUpdate(contentBlock, streamBlock) {
556
+ const messageBlock = mergeMessageBlock(contentBlock, streamBlock);
557
+ if (messageBlock) {
558
+ messageBlock.pending = true;
559
+ this.update.emit(messageBlock);
560
+ }
561
+ }
562
+ /**
563
+ * Parse stream until end.
564
+ */
565
+ async parse(stream) {
566
+ const transformer = new StreamTransform();
567
+ let contentBlock;
568
+ let streamBlock;
569
+ const stack = [];
570
+ for await (const event of stream) {
571
+ switch (event.type) {
572
+ //
573
+ // Messages.
574
+ //
575
+ case "message_start": {
576
+ if (this._message) {
577
+ log2.warn("unexpected message_start", void 0, {
578
+ F: __dxlog_file3,
579
+ L: 86,
580
+ S: this,
581
+ C: (f, a) => f(...a)
582
+ });
583
+ }
584
+ this._message = createStatic(Message2, {
585
+ role: "assistant",
586
+ content: []
587
+ });
588
+ this.message.emit(this._message);
589
+ break;
590
+ }
591
+ case "message_delta": {
592
+ if (!this._message) {
593
+ log2.warn("unexpected message_delta", void 0, {
594
+ F: __dxlog_file3,
595
+ L: 96,
596
+ S: this,
597
+ C: (f, a) => f(...a)
598
+ });
599
+ }
600
+ break;
601
+ }
602
+ case "message_stop": {
603
+ if (!this._message) {
604
+ log2.warn("unexpected message_stop", void 0, {
605
+ F: __dxlog_file3,
606
+ L: 104,
607
+ S: this,
608
+ C: (f, a) => f(...a)
609
+ });
610
+ } else {
611
+ this._message = void 0;
612
+ }
613
+ break;
614
+ }
615
+ //
616
+ // Content blocks.
617
+ //
618
+ case "content_block_start": {
619
+ if (contentBlock) {
620
+ log2.warn("unexpected content_block_start", {
621
+ content: contentBlock
622
+ }, {
623
+ F: __dxlog_file3,
624
+ L: 117,
625
+ S: this,
626
+ C: (f, a) => f(...a)
627
+ });
628
+ }
629
+ contentBlock = event.content;
630
+ break;
631
+ }
632
+ case "content_block_delta": {
633
+ if (!contentBlock) {
634
+ log2.warn("unexpected content_block_delta", void 0, {
635
+ F: __dxlog_file3,
636
+ L: 127,
637
+ S: this,
638
+ C: (f, a) => f(...a)
639
+ });
640
+ break;
641
+ }
642
+ switch (event.delta.type) {
643
+ //
644
+ // Text
645
+ //
646
+ case "text_delta": {
647
+ const chunks = transformer.transform(event.delta.text);
648
+ for (const chunk of chunks) {
649
+ switch (streamBlock?.type) {
650
+ //
651
+ // XML Fragment.
652
+ //
653
+ case "tag": {
654
+ if (chunk.type === "tag") {
655
+ if (chunk.selfClosing) {
656
+ streamBlock.content.push(chunk);
657
+ } else if (chunk.closing) {
658
+ if (stack.length > 0) {
659
+ const top = stack.pop();
660
+ invariant2(top && top.type === "tag", void 0, {
661
+ F: __dxlog_file3,
662
+ L: 151,
663
+ S: this,
664
+ A: [
665
+ "top && top.type === 'tag'",
666
+ ""
667
+ ]
668
+ });
669
+ top.content.push(streamBlock);
670
+ streamBlock = top;
671
+ } else {
672
+ this._emitBlock(contentBlock, streamBlock);
673
+ streamBlock = void 0;
674
+ }
675
+ } else {
676
+ stack.push(streamBlock);
677
+ streamBlock = chunk;
678
+ }
679
+ } else {
680
+ if (streamBlock.content.length === 0) {
681
+ streamBlock.content.push(chunk);
682
+ } else {
683
+ const last = streamBlock.content.at(-1);
684
+ invariant2(last, void 0, {
685
+ F: __dxlog_file3,
686
+ L: 168,
687
+ S: this,
688
+ A: [
689
+ "last",
690
+ ""
691
+ ]
692
+ });
693
+ if (last.type === "text") {
694
+ last.content += chunk.content;
695
+ } else {
696
+ streamBlock.content.push(chunk);
697
+ }
698
+ }
699
+ }
700
+ break;
701
+ }
702
+ //
703
+ // Text Fragment.
704
+ //
705
+ case "text": {
706
+ if (chunk.type === "tag") {
707
+ this._emitBlock(contentBlock, streamBlock);
708
+ if (chunk.selfClosing) {
709
+ this._emitBlock(contentBlock, chunk);
710
+ streamBlock = void 0;
711
+ } else {
712
+ streamBlock = chunk;
713
+ }
714
+ } else {
715
+ streamBlock.content += chunk.content;
716
+ }
717
+ break;
718
+ }
719
+ //
720
+ // No current chunk.
721
+ //
722
+ default: {
723
+ if (chunk.type === "tag" && chunk.selfClosing) {
724
+ this._emitBlock(contentBlock, chunk);
725
+ } else {
726
+ streamBlock = chunk;
727
+ }
728
+ }
729
+ }
730
+ }
731
+ break;
732
+ }
733
+ //
734
+ // JSON
735
+ //
736
+ case "input_json_delta": {
737
+ if (!contentBlock) {
738
+ log2.warn("unexpected input_json_delta", {
739
+ contentBlock
740
+ }, {
741
+ F: __dxlog_file3,
742
+ L: 218,
743
+ S: this,
744
+ C: (f, a) => f(...a)
745
+ });
746
+ break;
747
+ }
748
+ if (streamBlock?.type === "json") {
749
+ streamBlock.content += event.delta.partial_json;
750
+ } else {
751
+ streamBlock = {
752
+ type: "json",
753
+ content: event.delta.partial_json
754
+ };
755
+ }
756
+ break;
757
+ }
758
+ }
759
+ break;
760
+ }
761
+ case "content_block_stop": {
762
+ if (!contentBlock) {
763
+ log2.warn("unexpected content_block_stop", void 0, {
764
+ F: __dxlog_file3,
765
+ L: 235,
766
+ S: this,
767
+ C: (f, a) => f(...a)
768
+ });
769
+ break;
770
+ }
771
+ this._emitBlock(contentBlock, streamBlock);
772
+ contentBlock = void 0;
773
+ streamBlock = void 0;
774
+ break;
775
+ }
776
+ }
777
+ if (contentBlock && streamBlock) {
778
+ this._emitUpdate(contentBlock, streamBlock);
779
+ }
780
+ }
781
+ }
782
+ };
783
+ var mergeMessageBlock = (contentBlock, streamBlock) => {
784
+ log2("mergeMessageBlock", {
785
+ contentBlock,
786
+ streamBlock
787
+ }, {
788
+ F: __dxlog_file3,
789
+ L: 260,
790
+ S: void 0,
791
+ C: (f, a) => f(...a)
792
+ });
793
+ switch (streamBlock.type) {
794
+ //
795
+ // Text
796
+ //
797
+ case "text": {
798
+ return {
799
+ ...contentBlock,
800
+ type: "text",
801
+ text: streamBlock.content
802
+ };
803
+ }
804
+ //
805
+ // XML
806
+ //
807
+ case "tag": {
808
+ switch (streamBlock.tag) {
809
+ case "cot": {
810
+ const content = streamBlock.content.map((block) => {
811
+ switch (block.type) {
812
+ case "text":
813
+ return block.content;
814
+ default:
815
+ return null;
816
+ }
817
+ }).filter(isNotFalsy).join("\n");
818
+ return {
819
+ ...contentBlock,
820
+ type: "text",
821
+ disposition: "cot",
822
+ text: content
823
+ };
824
+ }
825
+ case "artifact": {
826
+ const { attributes } = streamBlock;
827
+ return {
828
+ type: "json",
829
+ disposition: "artifact",
830
+ json: JSON.stringify(attributes)
831
+ };
832
+ }
833
+ case "suggest": {
834
+ if (streamBlock.content.length === 1 && streamBlock.content[0].type === "text") {
835
+ return {
836
+ type: "json",
837
+ disposition: "suggest",
838
+ json: JSON.stringify({
839
+ text: streamBlock.content[0].content
840
+ })
841
+ };
842
+ }
843
+ break;
844
+ }
845
+ case "select": {
846
+ return {
847
+ type: "json",
848
+ disposition: "select",
849
+ json: JSON.stringify({
850
+ options: streamBlock.content.flatMap((content) => content.type === "tag" && content.content.length === 1 && content.content[0].type === "text" ? [
851
+ content.content[0].content
852
+ ] : [])
853
+ })
854
+ };
855
+ }
856
+ }
857
+ break;
858
+ }
859
+ //
860
+ // JSON
861
+ //
862
+ case "json": {
863
+ switch (contentBlock.type) {
864
+ case "tool_use": {
865
+ return {
866
+ ...contentBlock,
867
+ input: safeParseJson(streamBlock.content) ?? {}
868
+ };
869
+ }
870
+ }
871
+ return {
872
+ ...contentBlock,
873
+ type: "json",
874
+ disposition: "artifact",
875
+ json: streamBlock.content
876
+ };
877
+ }
878
+ }
879
+ };
880
+
881
+ // packages/experimental/assistant/src/ai-service/types.ts
882
+ import { Schema as S2 } from "@effect/schema";
883
+ import { Tool, Message as Message3, SpaceIdSchema } from "@dxos/artifact";
884
+ import { ObjectId } from "@dxos/echo-schema";
885
+ var createArtifactElement = (id) => `<artifact id=${id} />`;
886
+ var LLMModel = S2.Literal("@anthropic/claude-3-5-haiku-20241022", "@anthropic/claude-3-5-sonnet-20241022", "@cf/deepseek-ai/deepseek-r1-distill-qwen-32b", "@hf/nousresearch/hermes-2-pro-mistral-7b", "@ollama/llama-3-2-3b", "@ollama/llama-3-1-nemotron-70b-instruct", "@ollama/llama-3-1-nemotron-mini-4b-instruct");
887
+ var ToolTypes = Object.freeze({
888
+ // TODO(dmaretskyi): Not implemented yet.
889
+ // DatabaseQuery: 'database_query',
890
+ TextToImage: "text_to_image"
891
+ });
892
+ var GenerateRequest = S2.Struct({
893
+ spaceId: S2.optional(SpaceIdSchema),
894
+ threadId: S2.optional(ObjectId),
895
+ // TODO(burdon): Make optional with default.
896
+ model: LLMModel,
897
+ /**
898
+ * Current request.
899
+ */
900
+ // TODO(burdon): Remove from history.
901
+ // prompt: Message,
902
+ /**
903
+ * System instructions to the LLM.
904
+ */
905
+ systemPrompt: S2.optional(S2.String),
906
+ /**
907
+ * History of messages to include in the context window.
908
+ */
909
+ history: S2.optional(S2.Array(Message3)),
910
+ /**
911
+ * Tools available for the LLM.
912
+ */
913
+ tools: S2.optional(S2.Array(Tool).pipe(S2.mutable))
914
+ });
915
+
916
+ // packages/experimental/assistant/src/conversation/conversation.ts
917
+ import { ToolResult, Message as Message4 } from "@dxos/artifact";
918
+ import { createStatic as createStatic2, ObjectId as ObjectId2 } from "@dxos/echo-schema";
919
+ import { invariant as invariant3 } from "@dxos/invariant";
920
+ import { log as log3 } from "@dxos/log";
921
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/experimental/assistant/src/conversation/conversation.ts";
922
+ var runLLM = async (params) => {
923
+ let conversationResult = null;
924
+ const history = params.history ?? [];
925
+ const generate = async () => {
926
+ log3("llm generate", {
927
+ tools: params.tools
928
+ }, {
929
+ F: __dxlog_file4,
930
+ L: 44,
931
+ S: void 0,
932
+ C: (f, a) => f(...a)
933
+ });
934
+ const beginTs = Date.now();
935
+ const stream = await params.client.generate({
936
+ model: params.model,
937
+ spaceId: params.spaceId,
938
+ threadId: params.threadId,
939
+ history,
940
+ systemPrompt: params.system,
941
+ tools: params.tools
942
+ });
943
+ for await (const event of stream) {
944
+ params.logger?.(event);
945
+ }
946
+ await stream.complete();
947
+ const messages = [];
948
+ const message = messages.at(-1);
949
+ invariant3(message, void 0, {
950
+ F: __dxlog_file4,
951
+ L: 63,
952
+ S: void 0,
953
+ A: [
954
+ "message",
955
+ ""
956
+ ]
957
+ });
958
+ log3("llm result", {
959
+ time: Date.now() - beginTs,
960
+ message
961
+ }, {
962
+ F: __dxlog_file4,
963
+ L: 65,
964
+ S: void 0,
965
+ C: (f, a) => f(...a)
966
+ });
967
+ invariant3(message, void 0, {
968
+ F: __dxlog_file4,
969
+ L: 66,
970
+ S: void 0,
971
+ A: [
972
+ "message",
973
+ ""
974
+ ]
975
+ });
976
+ params.logger?.({
977
+ type: "message",
978
+ message
979
+ });
980
+ history.push(...messages.map((message2) => ({
981
+ ...message2,
982
+ content: message2.content.filter((block) => block.type !== "image")
983
+ })));
984
+ const isToolUse2 = message.content.at(-1)?.type === "tool_use";
985
+ if (isToolUse2) {
986
+ const toolCalls = message.content.filter((block) => block.type === "tool_use");
987
+ invariant3(toolCalls.length === 1, void 0, {
988
+ F: __dxlog_file4,
989
+ L: 77,
990
+ S: void 0,
991
+ A: [
992
+ "toolCalls.length === 1",
993
+ ""
994
+ ]
995
+ });
996
+ const toolCall = toolCalls[0];
997
+ const tool = params.tools.find((tool2) => tool2.name === toolCall.name);
998
+ if (!tool) {
999
+ throw new Error(`Tool not found: ${toolCall.name}`);
1000
+ }
1001
+ invariant3(tool.execute, void 0, {
1002
+ F: __dxlog_file4,
1003
+ L: 84,
1004
+ S: void 0,
1005
+ A: [
1006
+ "tool.execute",
1007
+ ""
1008
+ ]
1009
+ });
1010
+ const toolResult = await tool.execute(toolCall.input);
1011
+ switch (toolResult.kind) {
1012
+ case "error": {
1013
+ log3.warn("tool error", {
1014
+ message: toolResult.message
1015
+ }, {
1016
+ F: __dxlog_file4,
1017
+ L: 88,
1018
+ S: void 0,
1019
+ C: (f, a) => f(...a)
1020
+ });
1021
+ const resultMessage = {
1022
+ id: ObjectId2.random(),
1023
+ spaceId: params.spaceId,
1024
+ threadId: params.threadId,
1025
+ role: "user",
1026
+ content: [
1027
+ {
1028
+ type: "tool_result",
1029
+ toolUseId: toolCall.id,
1030
+ content: toolResult.message,
1031
+ isError: true
1032
+ }
1033
+ ]
1034
+ };
1035
+ params.logger?.({
1036
+ type: "message",
1037
+ message: resultMessage
1038
+ });
1039
+ history.push(resultMessage);
1040
+ return true;
1041
+ }
1042
+ case "success": {
1043
+ log3("tool success", {
1044
+ result: toolResult.result
1045
+ }, {
1046
+ F: __dxlog_file4,
1047
+ L: 110,
1048
+ S: void 0,
1049
+ C: (f, a) => f(...a)
1050
+ });
1051
+ const resultMessage = {
1052
+ id: ObjectId2.random(),
1053
+ spaceId: params.spaceId,
1054
+ threadId: params.threadId,
1055
+ role: "user",
1056
+ content: [
1057
+ {
1058
+ type: "tool_result",
1059
+ toolUseId: toolCall.id,
1060
+ content: JSON.stringify(toolResult.result)
1061
+ }
1062
+ ]
1063
+ };
1064
+ params.logger?.({
1065
+ type: "message",
1066
+ message: resultMessage
1067
+ });
1068
+ history.push(resultMessage);
1069
+ return true;
1070
+ }
1071
+ case "break": {
1072
+ log3("tool break", {
1073
+ result: toolResult.result
1074
+ }, {
1075
+ F: __dxlog_file4,
1076
+ L: 131,
1077
+ S: void 0,
1078
+ C: (f, a) => f(...a)
1079
+ });
1080
+ conversationResult = toolResult.result;
1081
+ return false;
1082
+ }
1083
+ }
1084
+ }
1085
+ return false;
1086
+ };
1087
+ while (await generate()) {
1088
+ }
1089
+ return {
1090
+ result: conversationResult,
1091
+ history
1092
+ };
1093
+ };
1094
+ var isToolUse = (message) => {
1095
+ const block = message.content.at(-1);
1096
+ invariant3(block, void 0, {
1097
+ F: __dxlog_file4,
1098
+ L: 152,
1099
+ S: void 0,
1100
+ A: [
1101
+ "block",
1102
+ ""
1103
+ ]
1104
+ });
1105
+ return block.type === "tool_use";
1106
+ };
1107
+ var runTools = async ({ message, tools, extensions }) => {
1108
+ const toolCalls = message.content.filter((block) => block.type === "tool_use");
1109
+ invariant3(toolCalls.length === 1, void 0, {
1110
+ F: __dxlog_file4,
1111
+ L: 174,
1112
+ S: void 0,
1113
+ A: [
1114
+ "toolCalls.length === 1",
1115
+ ""
1116
+ ]
1117
+ });
1118
+ const toolCall = toolCalls[0];
1119
+ const tool = tools.find((tool2) => tool2.name === toolCall.name);
1120
+ if (!tool) {
1121
+ throw new Error(`Tool not found: ${toolCall.name}`);
1122
+ }
1123
+ let toolResult;
1124
+ try {
1125
+ invariant3(tool.execute, void 0, {
1126
+ F: __dxlog_file4,
1127
+ L: 183,
1128
+ S: void 0,
1129
+ A: [
1130
+ "tool.execute",
1131
+ ""
1132
+ ]
1133
+ });
1134
+ toolResult = await tool.execute(toolCall.input, {
1135
+ extensions
1136
+ });
1137
+ } catch (error) {
1138
+ log3("tool error", {
1139
+ error
1140
+ }, {
1141
+ F: __dxlog_file4,
1142
+ L: 186,
1143
+ S: void 0,
1144
+ C: (f, a) => f(...a)
1145
+ });
1146
+ toolResult = ToolResult.Error(error.message);
1147
+ }
1148
+ switch (toolResult.kind) {
1149
+ case "error": {
1150
+ log3("tool error", {
1151
+ message: toolResult.message
1152
+ }, {
1153
+ F: __dxlog_file4,
1154
+ L: 192,
1155
+ S: void 0,
1156
+ C: (f, a) => f(...a)
1157
+ });
1158
+ const resultMessage = createStatic2(Message4, {
1159
+ role: "user",
1160
+ content: [
1161
+ {
1162
+ type: "tool_result",
1163
+ toolUseId: toolCall.id,
1164
+ content: toolResult.message,
1165
+ isError: true
1166
+ }
1167
+ ]
1168
+ });
1169
+ return {
1170
+ type: "continue",
1171
+ message: resultMessage
1172
+ };
1173
+ }
1174
+ case "success": {
1175
+ log3("tool success", {
1176
+ result: toolResult.result
1177
+ }, {
1178
+ F: __dxlog_file4,
1179
+ L: 213,
1180
+ S: void 0,
1181
+ C: (f, a) => f(...a)
1182
+ });
1183
+ const resultMessage = createStatic2(Message4, {
1184
+ role: "user",
1185
+ content: [
1186
+ {
1187
+ type: "tool_result",
1188
+ toolUseId: toolCall.id,
1189
+ content: typeof toolResult.result === "string" ? toolResult.result : JSON.stringify(toolResult.result) ?? ""
1190
+ }
1191
+ ]
1192
+ });
1193
+ return {
1194
+ type: "continue",
1195
+ message: resultMessage
1196
+ };
1197
+ }
1198
+ case "break": {
1199
+ log3("tool break", {
1200
+ result: toolResult.result
1201
+ }, {
1202
+ F: __dxlog_file4,
1203
+ L: 233,
1204
+ S: void 0,
1205
+ C: (f, a) => f(...a)
1206
+ });
1207
+ return {
1208
+ type: "break",
1209
+ result: toolResult.result
1210
+ };
1211
+ }
1212
+ }
1213
+ };
37
1214
  export {
38
1215
  AIServiceClientImpl,
39
1216
  EchoDataSource,
40
1217
  GenerateRequest,
41
1218
  GenerationStream,
42
- ImageSource,
43
1219
  LLMModel,
44
- LLMTool,
45
- LLMToolDefinition,
46
- LLMToolResult,
47
- Message,
48
- MessageContentBlock,
49
- MessageFromDb,
50
- MessageImageContentBlock,
51
- MessageRole,
52
- MessageTextContentBlock,
53
- MessageToolResultContentBlock,
54
- MessageToolUseContentBlock,
55
- ObjectId,
56
- ObjectIdBrand,
57
- Space,
58
- SpaceIdSchema,
59
- Thread,
1220
+ MixedStreamParser,
1221
+ StreamTransform,
60
1222
  ToolTypes,
61
- createUserMessage,
62
- defineTool,
1223
+ createArtifactElement,
1224
+ createGenerationStream,
63
1225
  executeQuery,
64
1226
  executeQueryPlan,
65
1227
  formatInferredRelationshipLabel,
66
1228
  formatJsonSchemaForLLM,
67
1229
  formatNodeLabel,
68
1230
  isReference,
1231
+ isToolUse,
1232
+ mergeMessageBlock,
69
1233
  parseCypherQuery,
70
- runLLM
1234
+ runLLM,
1235
+ runTools
71
1236
  };
72
1237
  //# sourceMappingURL=index.mjs.map