@dxos/assistant 0.8.4-main.c4373fc → 0.8.4-main.c85a9c8dae

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 (123) hide show
  1. package/README.md +1 -0
  2. package/dist/lib/neutral/chunk-BE6SRJ4N.mjs +193 -0
  3. package/dist/lib/neutral/chunk-BE6SRJ4N.mjs.map +7 -0
  4. package/dist/lib/neutral/extraction/index.mjs +223 -0
  5. package/dist/lib/neutral/extraction/index.mjs.map +7 -0
  6. package/dist/lib/neutral/index.mjs +1328 -0
  7. package/dist/lib/neutral/index.mjs.map +7 -0
  8. package/dist/lib/neutral/meta.json +1 -0
  9. package/dist/lib/neutral/testing/index.mjs +38 -0
  10. package/dist/lib/neutral/testing/index.mjs.map +7 -0
  11. package/dist/types/src/conversation/context.d.ts +109 -60
  12. package/dist/types/src/conversation/context.d.ts.map +1 -1
  13. package/dist/types/src/conversation/context.test.d.ts +2 -0
  14. package/dist/types/src/conversation/context.test.d.ts.map +1 -0
  15. package/dist/types/src/conversation/conversation.d.ts +41 -16
  16. package/dist/types/src/conversation/conversation.d.ts.map +1 -1
  17. package/dist/types/src/conversation/conversation.test.d.ts +2 -0
  18. package/dist/types/src/conversation/conversation.test.d.ts.map +1 -0
  19. package/dist/types/src/diff.d.ts +3 -1
  20. package/dist/types/src/diff.d.ts.map +1 -1
  21. package/dist/types/src/errors.d.ts +22 -30
  22. package/dist/types/src/errors.d.ts.map +1 -1
  23. package/dist/types/src/execution-graph.d.ts +5 -2
  24. package/dist/types/src/execution-graph.d.ts.map +1 -1
  25. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts.map +1 -1
  26. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts +282 -268
  27. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts.map +1 -1
  28. package/dist/types/src/extraction/extraction.d.ts +348 -303
  29. package/dist/types/src/extraction/extraction.d.ts.map +1 -1
  30. package/dist/types/src/extraction/quotes.d.ts +2 -2
  31. package/dist/types/src/extraction/quotes.d.ts.map +1 -1
  32. package/dist/types/src/functions/services.d.ts +6 -6
  33. package/dist/types/src/functions/services.d.ts.map +1 -1
  34. package/dist/types/src/functions.test.d.ts +2 -0
  35. package/dist/types/src/functions.test.d.ts.map +1 -0
  36. package/dist/types/src/session/artifact-diff.d.ts +1 -1
  37. package/dist/types/src/session/artifact-diff.d.ts.map +1 -1
  38. package/dist/types/src/session/format.d.ts +4 -176
  39. package/dist/types/src/session/format.d.ts.map +1 -1
  40. package/dist/types/src/session/index.d.ts +1 -0
  41. package/dist/types/src/session/index.d.ts.map +1 -1
  42. package/dist/types/src/session/observer.d.ts +6 -5
  43. package/dist/types/src/session/observer.d.ts.map +1 -1
  44. package/dist/types/src/session/session.d.ts +25 -15
  45. package/dist/types/src/session/session.d.ts.map +1 -1
  46. package/dist/types/src/session/toolkit.d.ts +9 -6
  47. package/dist/types/src/session/toolkit.d.ts.map +1 -1
  48. package/dist/types/src/session/version-pin.d.ts +3 -3
  49. package/dist/types/src/session/version-pin.d.ts.map +1 -1
  50. package/dist/types/src/testing/index.d.ts +2 -0
  51. package/dist/types/src/testing/index.d.ts.map +1 -0
  52. package/dist/types/src/testing/layer.d.ts +22 -0
  53. package/dist/types/src/testing/layer.d.ts.map +1 -0
  54. package/dist/types/src/types/artifact.d.ts +28 -0
  55. package/dist/types/src/types/artifact.d.ts.map +1 -0
  56. package/dist/types/src/types/index.d.ts +2 -0
  57. package/dist/types/src/types/index.d.ts.map +1 -0
  58. package/dist/types/tsconfig.tsbuildinfo +1 -1
  59. package/package.json +41 -31
  60. package/src/conversation/context.test.ts +46 -0
  61. package/src/conversation/context.ts +223 -49
  62. package/src/conversation/conversation.test.ts +65 -0
  63. package/src/conversation/conversation.ts +179 -53
  64. package/src/diff.test.ts +37 -6
  65. package/src/diff.ts +18 -4
  66. package/src/errors.ts +2 -2
  67. package/src/execution-graph.test.ts +46 -44
  68. package/src/execution-graph.ts +25 -16
  69. package/src/extraction/extraction-llm-function/extraction-llm-function.test.ts +2 -2
  70. package/src/extraction/extraction-llm-function/extraction-llm-function.ts +44 -54
  71. package/src/extraction/extraction-ner-function/extraction-ner-function.test.ts +15 -14
  72. package/src/extraction/extraction-ner-function/extraction-ner-function.ts +36 -44
  73. package/src/extraction/extraction-ner-function/named-entity-recognition.test.ts +10 -5
  74. package/src/extraction/extraction.ts +9 -8
  75. package/src/extraction/quotes.ts +4 -5
  76. package/src/functions/services.ts +88 -37
  77. package/src/functions.conversations.json +1 -0
  78. package/src/functions.test.ts +74 -0
  79. package/src/session/artifact-diff.ts +1 -1
  80. package/src/session/format.test.ts +103 -39
  81. package/src/session/format.ts +17 -16
  82. package/src/session/index.ts +1 -0
  83. package/src/session/observer.ts +6 -3
  84. package/src/session/session.conversations.json +1 -1
  85. package/src/session/session.test.ts +60 -18
  86. package/src/session/session.ts +99 -60
  87. package/src/session/toolkit.ts +21 -25
  88. package/src/session/version-pin.ts +6 -6
  89. package/src/templates/{format.tpl → instructions/format.tpl} +1 -4
  90. package/src/templates/system.ts +2 -2
  91. package/src/testing/index.ts +5 -0
  92. package/src/testing/layer.ts +85 -0
  93. package/src/{types.ts → types/artifact.ts} +43 -6
  94. package/src/types/index.ts +5 -0
  95. package/dist/lib/browser/chunk-CWGVG235.mjs +0 -380
  96. package/dist/lib/browser/chunk-CWGVG235.mjs.map +0 -7
  97. package/dist/lib/browser/chunk-UB26N5UF.mjs +0 -89
  98. package/dist/lib/browser/chunk-UB26N5UF.mjs.map +0 -7
  99. package/dist/lib/browser/extraction/index.mjs +0 -272
  100. package/dist/lib/browser/extraction/index.mjs.map +0 -7
  101. package/dist/lib/browser/index.mjs +0 -869
  102. package/dist/lib/browser/index.mjs.map +0 -7
  103. package/dist/lib/browser/meta.json +0 -1
  104. package/dist/lib/browser/named-entity-recognition-QPYHML66.mjs +0 -13
  105. package/dist/lib/browser/named-entity-recognition-QPYHML66.mjs.map +0 -7
  106. package/dist/lib/node-esm/chunk-BCFXTNSK.mjs +0 -91
  107. package/dist/lib/node-esm/chunk-BCFXTNSK.mjs.map +0 -7
  108. package/dist/lib/node-esm/chunk-OV5PMQPB.mjs +0 -382
  109. package/dist/lib/node-esm/chunk-OV5PMQPB.mjs.map +0 -7
  110. package/dist/lib/node-esm/extraction/index.mjs +0 -273
  111. package/dist/lib/node-esm/extraction/index.mjs.map +0 -7
  112. package/dist/lib/node-esm/index.mjs +0 -870
  113. package/dist/lib/node-esm/index.mjs.map +0 -7
  114. package/dist/lib/node-esm/meta.json +0 -1
  115. package/dist/lib/node-esm/named-entity-recognition-2HDF46YX.mjs +0 -14
  116. package/dist/lib/node-esm/named-entity-recognition-2HDF46YX.mjs.map +0 -7
  117. package/dist/types/src/summarization/summarization.test.d.ts +0 -2
  118. package/dist/types/src/summarization/summarization.test.d.ts.map +0 -1
  119. package/dist/types/src/types.d.ts +0 -16
  120. package/dist/types/src/types.d.ts.map +0 -1
  121. package/src/summarization/summarization.test.ts +0 -202
  122. /package/src/extraction/extraction-llm-function/{instructions.tpl → transcription-instructions.tpl} +0 -0
  123. /package/src/templates/{system.tpl → instructions/system.tpl} +0 -0
@@ -2,59 +2,123 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { beforeAll, describe, it } from '@effect/vitest';
5
+ import { describe, expect, it } from '@effect/vitest';
6
6
  import * as Effect from 'effect/Effect';
7
+ import * as Schema from 'effect/Schema';
7
8
 
8
9
  import { Blueprint, Template } from '@dxos/blueprints';
9
- import { Obj } from '@dxos/echo';
10
- import { type EchoDatabase } from '@dxos/echo-db';
11
- import { EchoTestBuilder } from '@dxos/echo-db/testing';
12
- import { DataType } from '@dxos/schema';
10
+ import { Database, Obj, Query } from '@dxos/echo';
11
+ import { TestHelpers } from '@dxos/effect/testing';
12
+ import { defineFunction } from '@dxos/functions';
13
+ import { Text } from '@dxos/schema';
14
+ import { Organization } from '@dxos/types';
13
15
  import { trim } from '@dxos/util';
14
16
 
15
17
  import { createSystemPrompt } from '../templates/system';
18
+ import { AssistantTestLayer } from '../testing';
16
19
 
17
20
  import { formatSystemPrompt } from './format';
18
21
 
19
- describe('format', () => {
20
- let db: EchoDatabase;
21
- beforeAll(async () => {
22
- const builder = await new EchoTestBuilder().open();
23
- ({ db } = await builder.createDatabase({
24
- types: [DataType.Text, DataType.Organization, Blueprint.Blueprint],
25
- }));
26
- });
22
+ const organizationListFunction = defineFunction({
23
+ key: 'dxos.org/function/organization-list',
24
+ name: 'Organization List',
25
+ description: 'List organizations',
26
+ inputSchema: Schema.Struct({}),
27
+ outputSchema: Schema.Array(Schema.String),
28
+ handler: Effect.fnUntraced(function* () {
29
+ const organizations = yield* Database.runQuery(Query.type(Organization.Organization));
30
+ return organizations.map((organization) => organization.name);
31
+ }),
32
+ });
33
+
34
+ const TestLayer = AssistantTestLayer({
35
+ types: [Text.Text, Organization.Organization, Blueprint.Blueprint],
36
+ functions: [organizationListFunction],
37
+ });
27
38
 
39
+ describe('format', () => {
28
40
  it.effect(
29
41
  'should format',
30
- Effect.fn(function* () {
31
- const object = db.add(
32
- Obj.make(DataType.Organization, {
33
- name: 'Test',
34
- website: 'https://www.test.com',
35
- }),
36
- );
37
-
38
- const blueprint = db.add(
39
- Blueprint.make({
40
- key: 'example.com/blueprint/test',
41
- name: 'Test',
42
- instructions: Template.make({
43
- source: trim`
44
- Test
45
- This is the test blueprint.
46
- `,
42
+ Effect.fnUntraced(
43
+ function* (_) {
44
+ const { db } = yield* Database.Service;
45
+ const object = db.add(
46
+ Obj.make(Organization.Organization, {
47
+ name: 'Test',
48
+ website: 'https://www.test.com',
49
+ }),
50
+ );
51
+
52
+ const blueprint = db.add(
53
+ Blueprint.make({
54
+ key: 'example.com/blueprint/test',
55
+ name: 'Test',
56
+ instructions: Template.make({
57
+ source: trim`
58
+ Test
59
+ This is the test blueprint.
60
+ `,
61
+ }),
62
+ }),
63
+ );
64
+
65
+ const output = yield* formatSystemPrompt({
66
+ system: createSystemPrompt({}),
67
+ blueprints: [blueprint],
68
+ objects: [object],
69
+ });
70
+
71
+ console.log(output);
72
+ },
73
+ Effect.provide(TestLayer),
74
+ TestHelpers.provideTestContext,
75
+ ),
76
+ );
77
+
78
+ it.effect(
79
+ 'should format with function input',
80
+ Effect.fnUntraced(
81
+ function* (_) {
82
+ const { db } = yield* Database.Service;
83
+ const object = db.add(
84
+ Obj.make(Organization.Organization, {
85
+ name: 'Test Org',
86
+ website: 'https://www.test.com',
87
+ }),
88
+ );
89
+
90
+ const blueprint = db.add(
91
+ Blueprint.make({
92
+ key: 'example.com/blueprint/test',
93
+ name: 'Test',
94
+ instructions: Template.make({
95
+ source: trim`
96
+ Organization List:
97
+ {{#each organizations}}
98
+ - {{this}}
99
+ {{/each}}
100
+ `,
101
+ inputs: [
102
+ {
103
+ name: 'organizations',
104
+ kind: 'function',
105
+ function: organizationListFunction.key,
106
+ },
107
+ ],
108
+ }),
47
109
  }),
48
- }),
49
- );
110
+ );
50
111
 
51
- const output = yield* formatSystemPrompt({
52
- system: createSystemPrompt({}),
53
- blueprints: [blueprint, blueprint],
54
- objects: [object, object],
55
- });
112
+ const output = yield* formatSystemPrompt({
113
+ system: createSystemPrompt({}),
114
+ blueprints: [blueprint],
115
+ objects: [object],
116
+ });
56
117
 
57
- console.log(output);
58
- }),
118
+ expect(output).to.include('Test Org');
119
+ },
120
+ Effect.provide(TestLayer),
121
+ TestHelpers.provideTestContext,
122
+ ),
59
123
  );
60
124
  });
@@ -2,24 +2,22 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import * as Array from 'effect/Array';
6
5
  import * as Effect from 'effect/Effect';
7
6
  import * as Function from 'effect/Function';
8
7
  import * as Option from 'effect/Option';
9
8
 
10
9
  import { Template } from '@dxos/blueprints';
11
10
  import { Obj } from '@dxos/echo';
12
- import { type ObjectId } from '@dxos/echo/internal';
13
11
  import { ObjectVersion } from '@dxos/echo-db';
14
- import { DatabaseService } from '@dxos/functions';
12
+ import { type ObjectId } from '@dxos/keys';
15
13
  import { log } from '@dxos/log';
16
- import { type ContentBlock, DataType } from '@dxos/schema';
14
+ import { type ContentBlock, Message } from '@dxos/types';
17
15
  import { trim } from '@dxos/util';
18
16
 
19
17
  import { AiAssistantError } from '../errors';
20
18
 
21
19
  import { ArtifactDiffResolver } from './artifact-diff';
22
- import { type AiSessionRunParams } from './session';
20
+ import { type AiSessionRunError, type AiSessionRunProps } from './session';
23
21
 
24
22
  /**
25
23
  * Formats the system prompt.
@@ -29,20 +27,20 @@ export const formatSystemPrompt = ({
29
27
  system,
30
28
  blueprints = [],
31
29
  objects = [],
32
- }: Pick<AiSessionRunParams<any>, 'system' | 'blueprints' | 'objects'>) =>
30
+ }: Pick<AiSessionRunProps<any>, 'system' | 'blueprints' | 'objects'>) =>
33
31
  Effect.gen(function* () {
34
32
  const blueprintDefs = yield* Function.pipe(
35
33
  blueprints,
36
34
  Effect.forEach((blueprint) => Effect.succeed(blueprint.instructions)),
37
- Effect.flatMap(Effect.forEach((template) => DatabaseService.loadOption(template.source))),
38
- Effect.map(Array.filter(Option.isSome)),
39
- Effect.map(
40
- Array.map(
41
- (template) => trim`
35
+ Effect.flatMap(
36
+ Effect.forEach((template) =>
37
+ Effect.gen(function* () {
38
+ return trim`
42
39
  <blueprint>
43
- ${Template.process(template.value.content)}
40
+ ${yield* Template.processTemplate(template)}
44
41
  </blueprint>
45
- `,
42
+ `;
43
+ }),
46
44
  ),
47
45
  ),
48
46
  Effect.map((blueprints) =>
@@ -74,7 +72,10 @@ export const formatSystemPrompt = ({
74
72
  */
75
73
  // TODO(burdon): Move to AiPreprocessor.
76
74
  // TODO(burdon): Convert util below to `Effect.fn` (to preserve stack info)
77
- export const formatUserPrompt = ({ prompt, history = [] }: Pick<AiSessionRunParams<any>, 'prompt' | 'history'>) =>
75
+ export const formatUserPrompt = ({
76
+ prompt,
77
+ history = [],
78
+ }: Pick<AiSessionRunProps<any>, 'prompt' | 'history'>): Effect.Effect<Message.Message, AiSessionRunError> =>
78
79
  Effect.gen(function* () {
79
80
  const blocks: ContentBlock.Any[] = [];
80
81
 
@@ -105,14 +106,14 @@ export const formatUserPrompt = ({ prompt, history = [] }: Pick<AiSessionRunPara
105
106
  }
106
107
  }
107
108
 
108
- return Obj.make(DataType.Message, {
109
+ return Obj.make(Message.Message, {
109
110
  created: new Date().toISOString(),
110
111
  sender: { role: 'user' },
111
112
  blocks: [...blocks, { _tag: 'text', text: prompt }],
112
113
  });
113
114
  });
114
115
 
115
- const gatherObjectVersions = (messages: DataType.Message[]): Map<ObjectId, ObjectVersion> => {
116
+ const gatherObjectVersions = (messages: Message.Message[]): Map<ObjectId, ObjectVersion> => {
116
117
  const artifactIds = new Map<ObjectId, ObjectVersion>();
117
118
  for (const message of messages) {
118
119
  for (const block of message.blocks) {
@@ -7,3 +7,4 @@ export * from './observer';
7
7
  export * from './session';
8
8
  export * from './toolkit';
9
9
  export * from './version-pin';
10
+ export * from './format';
@@ -2,21 +2,24 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
+ import type * as Tool from '@effect/ai/Tool';
5
6
  import * as Effect from 'effect/Effect';
6
7
  import * as Function from 'effect/Function';
7
8
 
8
9
  import { type AiParser, type ConsolePrinter } from '@dxos/ai';
9
- import { type DataType } from '@dxos/schema';
10
+ import { type Message } from '@dxos/types';
10
11
 
11
12
  /**
12
13
  * Live observer of the generation process.
13
14
  */
14
- export interface GenerationObserver extends AiParser.ParseResponseCallbacks {
15
+ export interface GenerationObserver<
16
+ Tools extends Record<string, Tool.Any> = any,
17
+ > extends AiParser.ParseResponseCallbacks<Tools> {
15
18
  /**
16
19
  * Complete messages fired during the session, both from the model and from the user.
17
20
  * This message will contain all message blocks emitted through the `onBlock` callback.
18
21
  */
19
- onMessage: (message: DataType.Message) => Effect.Effect<void>;
22
+ onMessage: (message: Message.Message) => Effect.Effect<void>;
20
23
  }
21
24
 
22
25
  export const GenerationObserver = Object.freeze({