@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
@@ -0,0 +1,13 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ export const DATA_MESSAGES = [
6
+ `
7
+ <cot>
8
+ ${Array.from({ length: 5 })
9
+ .map((_, i) => `${i + 1}. Step`)
10
+ .join('\n')}
11
+ </cot>
12
+ `,
13
+ ];
@@ -0,0 +1,8 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ export const AI_SERVICE_ENDPOINT = {
6
+ LOCAL: 'http://localhost:8788',
7
+ REMOTE: 'https://ai-service.dxos.workers.dev',
8
+ };
@@ -2,6 +2,7 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
+ export * from './defs';
5
6
  export * from './logger';
6
7
  export * from './query-promts';
7
8
  export * from './test-data';
@@ -2,7 +2,8 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import type { ImageSource, MessageContentBlock } from '../ai-service';
5
+ import type { ImageSource, MessageContentBlock } from '@dxos/artifact';
6
+
6
7
  import type { ConversationEvent } from '../conversation';
7
8
 
8
9
  export const createLogger = ({
@@ -34,7 +35,7 @@ export const createLogger = ({
34
35
  if (content.id && content.source) {
35
36
  images[content.id] = content.source;
36
37
  }
37
- process.stdout.write(`[Image id=${content.id} media_type=${content.source?.media_type}]`);
38
+ process.stdout.write(`[Image id=${content.id} mediaType=${content.source?.mediaType}]`);
38
39
  break;
39
40
  }
40
41
  }
@@ -4,10 +4,10 @@
4
4
 
5
5
  import { Schema as S } from '@effect/schema';
6
6
 
7
+ import { defineTool, ToolResult } from '@dxos/artifact';
7
8
  import { toJsonSchema } from '@dxos/echo-schema';
8
9
  import { log } from '@dxos/log';
9
10
 
10
- import { defineTool, LLMToolResult } from '../conversation';
11
11
  import { executeQuery, formatJsonSchemaForLLM, type DataSource } from '../cypher';
12
12
  import { trim } from '../util';
13
13
 
@@ -47,10 +47,10 @@ export const createCypherTool = (dataSource: DataSource, schemaTypes: S.Schema.A
47
47
  log('cypher query', { query });
48
48
  const results = await executeQuery(dataSource, query);
49
49
  log('query complete', { results });
50
- return LLMToolResult.Success(results);
50
+ return ToolResult.Success(results);
51
51
  } catch (e: any) {
52
52
  log.catch(e);
53
- return LLMToolResult.Error(e.message);
53
+ return ToolResult.Error(e.message);
54
54
  }
55
55
  },
56
56
  });
@@ -4,22 +4,23 @@
4
4
 
5
5
  import { test } from 'vitest';
6
6
 
7
+ import { createUserMessage } from '@dxos/artifact';
8
+ import { EchoTestBuilder } from '@dxos/echo-db/testing';
9
+ import { ObjectId } from '@dxos/echo-schema';
7
10
  import { SpaceId } from '@dxos/keys';
8
11
  import { log } from '@dxos/log';
9
- import { EchoTestBuilder } from '@dxos/echo-db/testing';
10
12
 
13
+ import { AI_SERVICE_ENDPOINT } from './defs';
11
14
  import { createLogger } from './logger';
12
15
  import { createCypherTool, createSystemPrompt } from './query-promts';
13
16
  import { createTestData, seedTestData } from './test-data';
14
17
  import { Contact, Org, Project, Task } from './test-schema';
15
- import { AIServiceClientImpl, ObjectId } from '../ai-service';
16
- import { runLLM, createUserMessage } from '../conversation';
17
- import { EchoDataSource } from '../cypher/echo-data-source';
18
-
19
- const ENDPOINT = 'http://localhost:8787';
18
+ import { AIServiceClientImpl } from '../ai-service';
19
+ import { runLLM } from '../conversation';
20
+ import { EchoDataSource } from '../cypher';
20
21
 
21
22
  const client = new AIServiceClientImpl({
22
- endpoint: ENDPOINT,
23
+ endpoint: AI_SERVICE_ENDPOINT.LOCAL,
23
24
  });
24
25
 
25
26
  test.skip('cypher query', async () => {
@@ -31,7 +32,7 @@ test.skip('cypher query', async () => {
31
32
  const spaceId = SpaceId.random();
32
33
  const threadId = ObjectId.random();
33
34
 
34
- await client.insertMessages([
35
+ await client.appendMessages([
35
36
  createUserMessage(
36
37
  spaceId,
37
38
  threadId,
@@ -52,7 +53,7 @@ test.skip('cypher query', async () => {
52
53
  log.info('DONE', { result: result.result });
53
54
  });
54
55
 
55
- test.only('query ECHO', async () => {
56
+ test.skip('query ECHO', async () => {
56
57
  await using builder = await new EchoTestBuilder().open();
57
58
  const { db, graph } = await builder.createDatabase();
58
59
 
@@ -68,7 +69,7 @@ test.only('query ECHO', async () => {
68
69
  const spaceId = SpaceId.random();
69
70
  const threadId = ObjectId.random();
70
71
 
71
- await client.insertMessages([
72
+ await client.appendMessages([
72
73
  createUserMessage(
73
74
  spaceId,
74
75
  threadId,
@@ -5,6 +5,7 @@
5
5
  import { type Schema as S } from '@effect/schema';
6
6
 
7
7
  import { raise } from '@dxos/debug';
8
+ import type { EchoDatabase } from '@dxos/echo-db';
8
9
  import { JSON_SCHEMA_ECHO_REF_ID, ObjectId, toJsonSchema, type JsonSchemaType, type Ref } from '@dxos/echo-schema';
9
10
  import { invariant } from '@dxos/invariant';
10
11
  import { create, makeRef } from '@dxos/live-object';
@@ -17,7 +18,6 @@ import {
17
18
  formatNodeLabel,
18
19
  } from '../cypher';
19
20
  import { Contact, Org, Project, Task } from '../testing';
20
- import type { EchoDatabase } from '@dxos/echo-db';
21
21
 
22
22
  export const seedTestData = (db: EchoDatabase) => {
23
23
  const contactRich = db.add(
@@ -336,7 +336,13 @@ export class MockDataSource implements DataSource {
336
336
  source,
337
337
  target,
338
338
  });
339
- } else if (propSchema.type === 'array' && propSchema.items?.$id === JSON_SCHEMA_ECHO_REF_ID) {
339
+ } else if (
340
+ propSchema.type === 'array' &&
341
+ propSchema.items &&
342
+ typeof propSchema.items === 'object' &&
343
+ '$id' in propSchema.items &&
344
+ propSchema.items.$id === JSON_SCHEMA_ECHO_REF_ID
345
+ ) {
340
346
  const label = formatInferredRelationshipLabel(typenameDxn, name);
341
347
 
342
348
  const source = this.nodes.find((node) => node.id === object.id);
@@ -0,0 +1,4 @@
1
+ import * as parjs from 'parjs';
2
+ import * as parjsCombinators from 'parjs/combinators';
3
+
4
+ export { parjsCombinators, parjs };
@@ -0,0 +1,8 @@
1
+ import { createRequire } from 'node:module';
2
+
3
+ // TODO(dmaretskyi): Must be like this or it breaks vitest.
4
+ const require = createRequire(import.meta.url);
5
+ const parjs = require('parjs');
6
+ const parjsCombinators = require('parjs/combinators');
7
+
8
+ export { parjsCombinators, parjs };