@dxos/assistant 0.8.4-main.84f28bd → 0.8.4-main.ae835ea

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. package/dist/lib/browser/chunk-4VIJTKPM.mjs +354 -0
  2. package/dist/lib/browser/chunk-4VIJTKPM.mjs.map +7 -0
  3. package/dist/lib/browser/chunk-UB26N5UF.mjs +89 -0
  4. package/dist/lib/browser/chunk-UB26N5UF.mjs.map +7 -0
  5. package/dist/lib/browser/extraction/index.mjs +272 -0
  6. package/dist/lib/browser/extraction/index.mjs.map +7 -0
  7. package/dist/lib/browser/index.mjs +754 -1873
  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-QPYHML66.mjs +13 -0
  11. package/dist/lib/browser/named-entity-recognition-QPYHML66.mjs.map +7 -0
  12. package/dist/lib/node-esm/chunk-AUUC7II4.mjs +356 -0
  13. package/dist/lib/node-esm/chunk-AUUC7II4.mjs.map +7 -0
  14. package/dist/lib/node-esm/chunk-BCFXTNSK.mjs +91 -0
  15. package/dist/lib/node-esm/chunk-BCFXTNSK.mjs.map +7 -0
  16. package/dist/lib/node-esm/extraction/index.mjs +273 -0
  17. package/dist/lib/node-esm/extraction/index.mjs.map +7 -0
  18. package/dist/lib/node-esm/index.mjs +754 -1874
  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-2HDF46YX.mjs +14 -0
  22. package/dist/lib/node-esm/named-entity-recognition-2HDF46YX.mjs.map +7 -0
  23. package/dist/types/src/conversation/context.d.ts +103 -0
  24. package/dist/types/src/conversation/context.d.ts.map +1 -0
  25. package/dist/types/src/conversation/conversation.d.ts +29 -32
  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/diff.d.ts +15 -0
  30. package/dist/types/src/diff.d.ts.map +1 -0
  31. package/dist/types/src/diff.test.d.ts +2 -0
  32. package/dist/types/src/diff.test.d.ts.map +1 -0
  33. package/dist/types/src/errors.d.ts +75 -0
  34. package/dist/types/src/errors.d.ts.map +1 -0
  35. package/dist/types/src/execution-graph.d.ts +82 -0
  36. package/dist/types/src/execution-graph.d.ts.map +1 -0
  37. package/dist/types/src/execution-graph.test.d.ts +2 -0
  38. package/dist/types/src/execution-graph.test.d.ts.map +1 -0
  39. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts +1 -1
  40. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts.map +1 -1
  41. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts +210 -73
  42. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts.map +1 -1
  43. package/dist/types/src/extraction/extraction-ner-function/named-entity-recognition.d.ts +1 -1
  44. package/dist/types/src/extraction/extraction-ner-function/named-entity-recognition.d.ts.map +1 -1
  45. package/dist/types/src/extraction/extraction.d.ts +264 -166
  46. package/dist/types/src/extraction/extraction.d.ts.map +1 -1
  47. package/dist/types/src/extraction/quotes.d.ts +1 -1
  48. package/dist/types/src/extraction/quotes.d.ts.map +1 -1
  49. package/dist/types/src/functions/index.d.ts +2 -0
  50. package/dist/types/src/functions/index.d.ts.map +1 -0
  51. package/dist/types/src/functions/services.d.ts +19 -0
  52. package/dist/types/src/functions/services.d.ts.map +1 -0
  53. package/dist/types/src/index.d.ts +5 -5
  54. package/dist/types/src/index.d.ts.map +1 -1
  55. package/dist/types/src/session/artifact-diff.d.ts +27 -0
  56. package/dist/types/src/session/artifact-diff.d.ts.map +1 -0
  57. package/dist/types/src/session/error-handling.d.ts +4 -0
  58. package/dist/types/src/session/error-handling.d.ts.map +1 -0
  59. package/dist/types/src/session/format.d.ts +186 -0
  60. package/dist/types/src/session/format.d.ts.map +1 -0
  61. package/dist/types/src/session/format.test.d.ts +2 -0
  62. package/dist/types/src/session/format.test.d.ts.map +1 -0
  63. package/dist/types/src/session/index.d.ts +3 -0
  64. package/dist/types/src/session/index.d.ts.map +1 -1
  65. package/dist/types/src/session/observer.d.ts +22 -0
  66. package/dist/types/src/session/observer.d.ts.map +1 -0
  67. package/dist/types/src/session/session.d.ts +36 -268
  68. package/dist/types/src/session/session.d.ts.map +1 -1
  69. package/dist/types/src/session/toolkit.d.ts +15 -0
  70. package/dist/types/src/session/toolkit.d.ts.map +1 -0
  71. package/dist/types/src/session/version-pin.d.ts +5 -5
  72. package/dist/types/src/session/version-pin.d.ts.map +1 -1
  73. package/dist/types/src/templates/index.d.ts +2 -0
  74. package/dist/types/src/templates/index.d.ts.map +1 -0
  75. package/dist/types/src/templates/system.d.ts +18 -0
  76. package/dist/types/src/templates/system.d.ts.map +1 -0
  77. package/dist/types/src/types/artifact.d.ts +16 -0
  78. package/dist/types/src/types/artifact.d.ts.map +1 -0
  79. package/dist/types/src/types/index.d.ts +2 -0
  80. package/dist/types/src/types/index.d.ts.map +1 -0
  81. package/dist/types/tsconfig.tsbuildinfo +1 -1
  82. package/package.json +46 -26
  83. package/src/conversation/context.ts +186 -0
  84. package/src/conversation/conversation.ts +101 -76
  85. package/src/conversation/index.ts +1 -0
  86. package/src/diff.test.ts +43 -0
  87. package/src/diff.ts +84 -0
  88. package/src/errors.ts +15 -0
  89. package/src/execution-graph.test.ts +738 -0
  90. package/src/execution-graph.ts +500 -0
  91. package/src/extraction/extraction-llm-function/extraction-llm-function.test.ts +13 -24
  92. package/src/extraction/extraction-llm-function/extraction-llm-function.ts +28 -22
  93. package/src/extraction/extraction-ner-function/extraction-ner-function.test.ts +9 -9
  94. package/src/extraction/extraction-ner-function/extraction-ner-function.ts +18 -8
  95. package/src/extraction/extraction-ner-function/named-entity-recognition.test.ts +4 -3
  96. package/src/extraction/extraction-ner-function/named-entity-recognition.ts +3 -1
  97. package/src/extraction/extraction.ts +2 -2
  98. package/src/extraction/quotes.test.ts +3 -3
  99. package/src/extraction/quotes.ts +4 -4
  100. package/src/functions/index.ts +5 -0
  101. package/src/functions/services.ts +158 -0
  102. package/src/index.ts +5 -5
  103. package/src/session/artifact-diff.ts +41 -0
  104. package/src/session/error-handling.ts +41 -0
  105. package/src/session/format.test.ts +60 -0
  106. package/src/session/format.ts +142 -0
  107. package/src/session/index.ts +3 -0
  108. package/src/session/observer.ts +59 -0
  109. package/src/session/session.conversations.json +1 -0
  110. package/src/session/session.test.ts +88 -214
  111. package/src/session/session.ts +170 -539
  112. package/src/session/toolkit.ts +48 -0
  113. package/src/session/version-pin.ts +10 -10
  114. package/src/summarization/summarization.test.ts +87 -106
  115. package/src/templates/format.tpl +60 -0
  116. package/src/templates/index.ts +5 -0
  117. package/src/templates/system.tpl +48 -0
  118. package/src/templates/system.ts +41 -0
  119. package/src/types/artifact.ts +52 -0
  120. package/src/types/index.ts +5 -0
  121. package/src/typings.d.ts +5 -0
  122. package/dist/types/bin/chat.d.ts +0 -2
  123. package/dist/types/bin/chat.d.ts.map +0 -1
  124. package/dist/types/src/blueprint/blueprint.d.ts +0 -41
  125. package/dist/types/src/blueprint/blueprint.d.ts.map +0 -1
  126. package/dist/types/src/blueprint/index.d.ts +0 -3
  127. package/dist/types/src/blueprint/index.d.ts.map +0 -1
  128. package/dist/types/src/blueprint/registry.d.ts +0 -7
  129. package/dist/types/src/blueprint/registry.d.ts.map +0 -1
  130. package/dist/types/src/context/binder.d.ts +0 -34
  131. package/dist/types/src/context/binder.d.ts.map +0 -1
  132. package/dist/types/src/context/binding.d.ts +0 -38
  133. package/dist/types/src/context/binding.d.ts.map +0 -1
  134. package/dist/types/src/context/index.d.ts +0 -3
  135. package/dist/types/src/context/index.d.ts.map +0 -1
  136. package/dist/types/src/research/exa.d.ts +0 -7
  137. package/dist/types/src/research/exa.d.ts.map +0 -1
  138. package/dist/types/src/research/graph.d.ts +0 -41
  139. package/dist/types/src/research/graph.d.ts.map +0 -1
  140. package/dist/types/src/research/graph.test.d.ts +0 -2
  141. package/dist/types/src/research/graph.test.d.ts.map +0 -1
  142. package/dist/types/src/research/index.d.ts +0 -4
  143. package/dist/types/src/research/index.d.ts.map +0 -1
  144. package/dist/types/src/research/research.d.ts +0 -10
  145. package/dist/types/src/research/research.d.ts.map +0 -1
  146. package/dist/types/src/research/research.test.d.ts +0 -2
  147. package/dist/types/src/research/research.test.d.ts.map +0 -1
  148. package/dist/types/src/session/version-pin.test.d.ts +0 -2
  149. package/dist/types/src/session/version-pin.test.d.ts.map +0 -1
  150. package/dist/types/src/testing/exa-search-1748337321991.d.ts +0 -38
  151. package/dist/types/src/testing/exa-search-1748337321991.d.ts.map +0 -1
  152. package/dist/types/src/testing/exa-search-1748337331526.d.ts +0 -37
  153. package/dist/types/src/testing/exa-search-1748337331526.d.ts.map +0 -1
  154. package/dist/types/src/testing/exa-search-1748337344119.d.ts +0 -58
  155. package/dist/types/src/testing/exa-search-1748337344119.d.ts.map +0 -1
  156. package/dist/types/src/testing/index.d.ts +0 -3
  157. package/dist/types/src/testing/index.d.ts.map +0 -1
  158. package/dist/types/src/types.d.ts +0 -3
  159. package/dist/types/src/types.d.ts.map +0 -1
  160. package/src/blueprint/blueprint.ts +0 -75
  161. package/src/blueprint/index.ts +0 -6
  162. package/src/blueprint/registry.ts +0 -15
  163. package/src/context/binder.ts +0 -101
  164. package/src/context/binding.ts +0 -31
  165. package/src/context/index.ts +0 -6
  166. package/src/research/exa.ts +0 -100
  167. package/src/research/graph.test.ts +0 -15
  168. package/src/research/graph.ts +0 -337
  169. package/src/research/index.ts +0 -7
  170. package/src/research/instructions-research.tpl +0 -97
  171. package/src/research/research.test.ts +0 -190
  172. package/src/research/research.ts +0 -90
  173. package/src/session/version-pin.test.ts +0 -26
  174. package/src/testing/exa-search-1748337321991.ts +0 -131
  175. package/src/testing/exa-search-1748337331526.ts +0 -144
  176. package/src/testing/exa-search-1748337344119.ts +0 -133
  177. package/src/testing/index.ts +0 -11
  178. package/src/typedefs.d.ts +0 -8
  179. package/src/types.ts +0 -8
@@ -0,0 +1,48 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import type * as Tool from '@effect/ai/Tool';
6
+ import * as Toolkit from '@effect/ai/Toolkit';
7
+ import type * as Context from 'effect/Context';
8
+ import * as Effect from 'effect/Effect';
9
+
10
+ import { type AiToolNotFoundError, ToolExecutionService, type ToolId, ToolResolverService } from '@dxos/ai';
11
+ import { type Blueprint } from '@dxos/blueprints';
12
+ import { isTruthy } from '@dxos/util';
13
+
14
+ export type ToolkitParams<Tools extends Record<string, Tool.Any>> = {
15
+ toolkit?: Toolkit.Toolkit<Tools>;
16
+ toolIds?: ToolId[];
17
+ blueprints?: Blueprint.Blueprint[];
18
+ };
19
+
20
+ /**
21
+ * Build a combined toolkit from the blueprint tools and the provided toolkit.
22
+ */
23
+ export const createToolkit = <Tools extends Record<string, Tool.Any> = {}>({
24
+ toolkit: toolkitParam,
25
+ toolIds = [],
26
+ blueprints = [],
27
+ }: ToolkitParams<Tools>): Effect.Effect<
28
+ Toolkit.WithHandler<any>,
29
+ AiToolNotFoundError,
30
+ ToolResolverService | ToolExecutionService | Tool.HandlersFor<Tools>
31
+ > =>
32
+ Effect.gen(function* () {
33
+ const blueprintToolkit = yield* ToolResolverService.resolveToolkit([
34
+ ...blueprints.flatMap(({ tools }) => tools),
35
+ ...toolIds,
36
+ ]);
37
+
38
+ const blueprintToolkitHandler: Context.Context<Tool.HandlersFor<any>> = yield* blueprintToolkit.toContext(
39
+ ToolExecutionService.handlersFor(blueprintToolkit),
40
+ );
41
+
42
+ const toolkit = Toolkit.merge(...[toolkitParam, blueprintToolkit].filter(isTruthy));
43
+ return yield* toolkit.pipe(Effect.provide(blueprintToolkitHandler)) as any as Effect.Effect<
44
+ Toolkit.WithHandler<any>,
45
+ never,
46
+ Tool.HandlersFor<Tools>
47
+ >;
48
+ });
@@ -2,12 +2,12 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { Schema } from 'effect';
5
+ import * as Schema from 'effect/Schema';
6
6
 
7
- import { type MessageContentBlock } from '@dxos/ai';
7
+ import { type AnyEchoObject, ObjectId } from '@dxos/echo/internal';
8
8
  import { type ObjectVersion } from '@dxos/echo-db';
9
9
  import { getVersion } from '@dxos/echo-db';
10
- import { ObjectId, type BaseEchoObject } from '@dxos/echo-schema';
10
+ import { type ContentBlock } from '@dxos/schema';
11
11
 
12
12
  // TODO(dmaretskyi): Extract.
13
13
  const ObjectVersionSchema = Schema.Unknown as Schema.Schema<ObjectVersion>;
@@ -15,7 +15,7 @@ const ObjectVersionSchema = Schema.Unknown as Schema.Schema<ObjectVersion>;
15
15
  const VersionPinSchema = Schema.Struct({
16
16
  // TODO(dmaretskyi): Use Ref when those support encoding.
17
17
  objectId: ObjectId,
18
- // TODO(dmaretskyi): Could be opaque
18
+ // TODO(dmaretskyi): Could be opaque.
19
19
  version: ObjectVersionSchema,
20
20
  });
21
21
 
@@ -27,22 +27,22 @@ export interface VersionPin extends Schema.Schema.Type<typeof VersionPinSchema>
27
27
 
28
28
  export const VersionPin: typeof VersionPinSchema & {
29
29
  DISPOSITION: 'version-pin';
30
- fromObject: (object: BaseEchoObject) => VersionPin;
31
- createBlock: (pin: VersionPin) => MessageContentBlock;
30
+ fromObject: (object: AnyEchoObject) => VersionPin;
31
+ createBlock: (pin: VersionPin) => ContentBlock.Any;
32
32
  } = class extends VersionPinSchema {
33
33
  static readonly DISPOSITION = 'version-pin';
34
- static fromObject(object: BaseEchoObject): VersionPin {
34
+ static fromObject(object: AnyEchoObject): VersionPin {
35
35
  return VersionPin.make({
36
36
  objectId: object.id,
37
37
  version: getVersion(object),
38
38
  });
39
39
  }
40
40
 
41
- static createBlock(pin: VersionPin): MessageContentBlock {
41
+ static createBlock(pin: VersionPin): ContentBlock.Any {
42
42
  return {
43
- type: 'json',
43
+ _tag: 'json',
44
44
  disposition: VersionPin.DISPOSITION,
45
- json: JSON.stringify(pin),
45
+ data: JSON.stringify(pin),
46
46
  };
47
47
  }
48
48
  };
@@ -2,27 +2,25 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { pipe, Schema } from 'effect';
5
+ // ISSUE(burdon): defineFunction
6
+ // @ts-nocheck
7
+
8
+ import * as Function from 'effect/Function';
9
+ import * as Schema from 'effect/Schema';
6
10
  import { beforeAll, describe, test } from 'vitest';
7
11
 
8
- import {
9
- EdgeAiServiceClient,
10
- Message,
11
- MixedStreamParser,
12
- OllamaAiServiceClient,
13
- type TextContentBlock,
14
- } from '@dxos/ai';
15
- import { AI_SERVICE_ENDPOINT } from '@dxos/ai/testing';
12
+ import { AiService, MixedStreamParser } from '@dxos/ai';
16
13
  import { Obj } from '@dxos/echo';
17
- import type { EchoDatabase } from '@dxos/echo-db';
14
+ import { type EchoDatabase } from '@dxos/echo-db';
18
15
  import { EchoTestBuilder } from '@dxos/echo-db/testing';
19
- import { AiService, defineFunction, FunctionExecutor, ServiceContainer } from '@dxos/functions';
20
- import { DataType } from '@dxos/schema';
16
+ import { FunctionExecutor, ServiceContainer, defineFunction } from '@dxos/functions';
17
+ import { type ContentBlock, DataType } from '@dxos/schema';
21
18
  import { createTestData } from '@dxos/schema/testing';
22
-
23
- const REMOTE_AI = true;
19
+ import { trim } from '@dxos/util';
24
20
 
25
21
  const summarizationFn = defineFunction({
22
+ key: 'dxos.org/function/summarization/summarize',
23
+ name: 'Summarize transcript',
26
24
  description: 'Summarize a document',
27
25
  inputSchema: Schema.Struct({
28
26
  document: Schema.optional(DataType.Text),
@@ -30,49 +28,50 @@ const summarizationFn = defineFunction({
30
28
  }),
31
29
  outputSchema: DataType.Text,
32
30
  handler: async ({ data: { document, transcript }, context }) => {
33
- const ai = context.getService(AiService);
31
+ const ai = context.getService(AiService.AiService);
34
32
  const result = await new MixedStreamParser().parse(
35
33
  await ai.client.execStream({
36
34
  model: '@anthropic/claude-3-5-haiku-20241022',
37
- systemPrompt: `
38
- You are a Transcript Summarizer.
39
- Transcript Summarizer update an existing summary within <summary> tags with a new transcript that is placed in <transcript> tags.
40
- Transcript Summarizer updates only the relevant parts of the summary.
41
- If there's no summary, create a new one.
42
- Transcript Summarizer outputs only the summary texts and nothing else.
43
- Transcript Summarizer keeps the original summary structure.
44
- Transcript Summarizer keeps the unrelated parts of the summary untouched.
45
- The Transcript Summarizer errs on the side of being too verbose.
46
- The Transcript Summarizer outputs the entire update summary.
47
- Transcript Summarizer outputs the entire update summary.
48
- The summary is formatted as hierarchical markdown bullet points with no headings.
49
- The hierarchical structure is deeply nested.
50
- The summarizer formats the bullets with "-" symbol as prefix and two spaces indentation.
51
- The Transcript Summarizer knows that the content of transcript will be updated solely by its output.
52
- The Transcript Summarizer outputs only the summary text.
53
- `,
35
+ // TODO(burdon): Factor out and test prompts.
36
+ systemPrompt: trim`
37
+ Your job is to summarize a meeting transcript.
38
+ Transcript Summarizer updates an existing summary within <summary> tags with a new transcript that is placed in <transcript> tags.
39
+ Transcript Summarizer updates only the relevant parts of the summary.
40
+ If there's no summary, create a new one.
41
+ Transcript Summarizer outputs only the summary texts and nothing else.
42
+ Transcript Summarizer keeps the original summary structure.
43
+ Transcript Summarizer keeps the unrelated parts of the summary untouched.
44
+ The Transcript Summarizer errs on the side of being too verbose.
45
+ The Transcript Summarizer outputs the entire update summary.
46
+ The summary is formatted as hierarchical markdown bullet points with no headings.
47
+ The hierarchical structure is deeply nested.
48
+ The Transcript Summarizer formats the bullets with "-" symbol as prefix and two spaces indentation.
49
+ The Transcript Summarizer knows that the content of transcript will be updated solely by its output.
50
+ The Transcript Summarizer outputs only the summary text.
51
+ `,
54
52
  history: [
55
- Obj.make(Message, {
56
- role: 'user',
57
- content: [
53
+ Obj.make(DataType.Message, {
54
+ created: new Date().toISOString(),
55
+ sender: { role: 'user' },
56
+ blocks: [
58
57
  {
59
- type: 'text',
60
- text: `
61
- <transcript>
62
- ${JSON.stringify(transcript, null, 2)}
63
- </transcript>
64
- `,
58
+ _tag: 'text',
59
+ text: trim`
60
+ <transcript>
61
+ ${JSON.stringify(transcript, null, 2)}
62
+ </transcript>
63
+ `,
65
64
  },
66
65
  ...(document != null && document.content.length > 0
67
66
  ? [
68
67
  {
69
- type: 'text',
70
- text: `
71
- <summary>
72
- ${document.content}
73
- </summary>
74
- `,
75
- } satisfies TextContentBlock,
68
+ _tag: 'text',
69
+ text: trim`
70
+ <summary>
71
+ ${document.content}
72
+ </summary>
73
+ `,
74
+ } satisfies ContentBlock.Text,
76
75
  ]
77
76
  : []),
78
77
  ],
@@ -80,13 +79,14 @@ const summarizationFn = defineFunction({
80
79
  ],
81
80
  }),
82
81
  );
83
- return Obj.make(DataType.Text, {
84
- content: pipe(result[0]?.content[0], (c) => (c?.type === 'text' ? c.text : '')),
85
- });
82
+
83
+ return DataType.makeText(Function.pipe(result[0]?.blocks[0], (c) => (c?._tag === 'text' ? c.text : '')));
86
84
  },
87
85
  });
88
86
 
89
87
  const refinementFn = defineFunction({
88
+ key: 'dxos.org/function/summarization/refine',
89
+ name: 'Refine transcript summary',
90
90
  description: 'Refine a summary',
91
91
  inputSchema: Schema.Struct({
92
92
  summaries: Schema.Array(DataType.Text),
@@ -95,49 +95,49 @@ const refinementFn = defineFunction({
95
95
  summary: DataType.Text,
96
96
  }),
97
97
  handler: async ({ data: { summaries }, context }) => {
98
- const ai = context.getService(AiService);
98
+ const ai = context.getService(AiService.AiService);
99
99
  const result = await new MixedStreamParser().parse(
100
100
  await ai.client.execStream({
101
101
  model: '@anthropic/claude-3-5-haiku-20241022',
102
- systemPrompt: `
103
- You are a Transcript Summary Refiner.
104
- Transcript Summary Refiner works on a history of evolving summaries that were generated based on the transcript.
105
- The summaries are presented starting from the oldest to the newest.
106
- Each iteration of the summary contains a new part of the transcript.
107
- The Transcript Summary Refiner refines the summary based on the history of summaries.
108
- The Transcript Summary Refiner identifies any potential data lost between the iterations and adds its back to the output.
109
- The Transcript Summary Refiner updates the summary to be more structured.
110
- The Transcript Summary Refiner errs on the side of being too verbose.
111
- The Transcript Summary Refiner errs on keeping the original summary structure.
112
- Transcript Summary Refiner outputs the entire update summary.
113
- The summary is formatted as hierarchical markdown bullet points with no headings.
114
- The hierarchical structure is deeply nested.
115
- The Transcript Summary Refiner formats the bullets with "-" symbol as prefix and two spaces indentation.
116
- The Transcript Summary Refiner knows that the content of transcript will be updated solely by its output.
117
- The Transcript Summary Refiner outputs only the summary text.
118
- `,
102
+ // TODO(burdon): Factor out and test prompts.
103
+ systemPrompt: trim`
104
+ You are a Transcript Summary Refiner.
105
+ Transcript Summary Refiner works on a history of evolving summaries that were generated based on the transcript.
106
+ The summaries are presented starting from the oldest to the newest.
107
+ Each iteration of the summary contains a new part of the transcript.
108
+ The Transcript Summary Refiner refines the summary based on the history of summaries.
109
+ The Transcript Summary Refiner identifies any potential data lost between the iterations and adds its back to the output.
110
+ The Transcript Summary Refiner updates the summary to be more structured.
111
+ The Transcript Summary Refiner errs on the side of being too verbose.
112
+ The Transcript Summary Refiner errs on keeping the original summary structure.
113
+ The Transcript Summary Refiner outputs the entire update summary.
114
+ The Transcript Summary is formatted as hierarchical markdown bullet points with no headings.
115
+ The hierarchical structure is deeply nested.
116
+ The Transcript Summary Refiner formats the bullets with "-" symbol as prefix and two spaces indentation.
117
+ The Transcript Summary Refiner knows that the content of transcript will be updated solely by its output.
118
+ The Transcript Summary Refiner outputs only the summary text.
119
+ `,
119
120
  history: [
120
- Obj.make(Message, {
121
- role: 'user',
122
- content: summaries.map(
121
+ Obj.make(DataType.Message, {
122
+ created: new Date().toISOString(),
123
+ sender: { role: 'user' },
124
+ blocks: summaries.map(
123
125
  (summary) =>
124
126
  ({
125
- type: 'text',
126
- text: `
127
- <summary>
128
- ${summary.content}
129
- </summary>
130
- `,
131
- }) satisfies TextContentBlock,
127
+ _tag: 'text',
128
+ text: trim`
129
+ <summary>
130
+ ${summary.content}
131
+ </summary>
132
+ `,
133
+ }) satisfies ContentBlock.Text,
132
134
  ),
133
135
  }),
134
136
  ],
135
137
  }),
136
138
  );
137
139
  return {
138
- summary: Obj.make(DataType.Text, {
139
- content: pipe(result[0]?.content[0], (c) => (c?.type === 'text' ? c.text : '')),
140
- }),
140
+ summary: DataType.makeText(Function.pipe(result[0]?.blocks[0], (c) => (c?._tag === 'text' ? c.text : ''))),
141
141
  };
142
142
  },
143
143
  });
@@ -147,6 +147,7 @@ describe.skip('Summarization', () => {
147
147
  let db: EchoDatabase;
148
148
  let executor: FunctionExecutor;
149
149
 
150
+ // TODO(burdon): Rewrite test.
150
151
  beforeAll(async () => {
151
152
  // TODO(dmaretskyi): Helper to scaffold this from a config.
152
153
  builder = await new EchoTestBuilder().open();
@@ -154,21 +155,7 @@ describe.skip('Summarization', () => {
154
155
  db = db1;
155
156
  executor = new FunctionExecutor(
156
157
  new ServiceContainer().setServices({
157
- ai: {
158
- client: REMOTE_AI
159
- ? new EdgeAiServiceClient({
160
- endpoint: AI_SERVICE_ENDPOINT.REMOTE,
161
- defaultGenerationOptions: {
162
- // model: '@anthropic/claude-sonnet-4-20250514',
163
- model: '@anthropic/claude-3-5-sonnet-20241022',
164
- },
165
- })
166
- : new OllamaAiServiceClient({
167
- overrides: {
168
- model: 'llama3.1:8b',
169
- },
170
- }),
171
- },
158
+ ai: todo(),
172
159
  database: {
173
160
  db,
174
161
  },
@@ -179,9 +166,7 @@ describe.skip('Summarization', () => {
179
166
  test('keeps transcript outline', { timeout: 1000_000 }, async () => {
180
167
  const { transcriptMessages } = createTestData();
181
168
 
182
- const summary = Obj.make(DataType.Text, {
183
- content: '',
184
- });
169
+ const summary = DataType.makeText();
185
170
 
186
171
  const summaries = [];
187
172
 
@@ -192,12 +177,10 @@ describe.skip('Summarization', () => {
192
177
  transcript: blocks,
193
178
  });
194
179
  summary.content = result.content;
195
- summaries.push(Obj.make(DataType.Text, { content: result.content }));
180
+ summaries.push(DataType.makeText(result.content));
196
181
 
197
182
  console.log(blocks.at(-1));
198
183
  console.log();
199
- console.log('--------------------------------');
200
- console.log();
201
184
  console.log(summary.content);
202
185
  console.log();
203
186
 
@@ -207,12 +190,10 @@ describe.skip('Summarization', () => {
207
190
  summaries: history,
208
191
  });
209
192
  summary.content = result.summary.content;
210
- summaries.push(Obj.make(DataType.Text, { content: result.summary.content }));
193
+ summaries.push(DataType.makeText(result.summary.content));
211
194
 
212
195
  console.log('REFINED');
213
196
  console.log();
214
- console.log('--------------------------------');
215
- console.log();
216
197
  console.log(summary.content);
217
198
  console.log();
218
199
  }
@@ -0,0 +1,60 @@
1
+ {{! System Core }}
2
+
3
+ ## Input Formats
4
+
5
+ ### Blueprints
6
+
7
+ You may be provided with Blueprint definitions that include specific instructions and tools for a given set of tasks.
8
+ Blue print instructions will be enclosed in a <blueprint> tag.
9
+
10
+ ### Context objects
11
+
12
+ You may be provided with references to objects that are relevant to the current prompt.
13
+ Objects will be in the form of a <object> tag with a <dxn> element that is the unique key of the object required by many tools.
14
+ The <typename> element is the type of the object.
15
+
16
+ <object>
17
+ <dxn>object-id</dxn>
18
+ <typename>example.com/type/TypeName</typename>
19
+ </object>
20
+
21
+ ## Response Formats
22
+
23
+ It is very important to respond in the correct format.
24
+ You response must be valid Markdown.
25
+ In some cases you should respond with well-formed XML tags along with the content.
26
+ Code snippets should use 2-space indents.
27
+
28
+ {{#if cot}}
29
+ Before responding, explain your reasoning and include your detailed chain-of-thought enclosed in a <cot> tag.
30
+ The <cot> tag should be the first thing in your response.
31
+ {{/if}}
32
+
33
+ ## Block references
34
+
35
+ You can reply with a block reference for objects if you have the DXN. For example:
36
+
37
+ <object>
38
+ <dxn>dxn:queue:data:B6INSIBY3CBEF4M5VZRYBCMAHQMPYK5AJ:01K24XMVHSZHS97SG1VTVQDM5Z:01K24XPK464FSCKVQJAB2H662M</dxn>
39
+ </object>
40
+ <object>
41
+ <dxn>dxn:echo:@:01K24XPK464FSCKVQJAB2H662M</dxn>
42
+ </object>
43
+
44
+ ### Suggestions
45
+
46
+ Each suggestion must in the form of a proposed action enclosed in a <suggestion> tag.
47
+ Example: <suggestion>Show on a map</suggestion>
48
+
49
+ ### Multiple choice questions
50
+
51
+ You may ask multiple choice questions by wrapping consise options inside <option> tags inside a well formed <select> tag.
52
+ Example: <select><option>Yes</option><option>No</option></select>
53
+
54
+ ## Toolkit
55
+
56
+ If the user asks for a list of tools, then just emit a single self-closing <toolkit/> tag instead of listing the tools.
57
+
58
+ ## Context
59
+
60
+ The current date and time is {{DATETIME}}.
@@ -0,0 +1,5 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ export * from './system';
@@ -0,0 +1,48 @@
1
+ {{! System Prompt }}
2
+
3
+ - You are a helpful assistant called Kai.
4
+ - Your name is Kai and you are powered by different language models.
5
+ - You were created by DXOS and operate inside of Composer and on the DXOS EDGE network.
6
+ - In your initial greeting state your name and make some suggestions based on the current context objects.
7
+ - You are an advanced AI assistant capable of creating and managing artifacts from provided data and tools.
8
+ - Your task is to process user commands and questions and decide how best to respond.
9
+ - In general be concise and direct.
10
+ - Follow all instructions carefully.
11
+
12
+ ## Planning
13
+
14
+ - Analyze the structure and type of the content in the user's message.
15
+ - Determine if you complete the task using the available blueprint definitions?
16
+ - If you can't complete the task using the available blueprint definitions, query the list of available blueprint definitions using the appropriate tool.
17
+ - Identify which blueprint definitions are relevant to the user's request.
18
+ - Evaluate the potential benefits of creating an artifact vs. normal processing for each identified element.
19
+ - Make a final decision on whether to create an artifact and explain your reasoning.
20
+ - Are the required blueprint definitions already available?
21
+ - If not, select which blueprint definition(s) will be the most relevant and require them using the require_artifact_definitions tool.
22
+ - The require'd artifact tools will be available for use after require.
23
+ - If creating an artifact, outline how you will structure it within the response.
24
+ - Decide if the artifact needs to be shown to the user.
25
+ - Call the show tool to show the artifact to the user.
26
+ - Your reasoning must include: whether to use artifacts or not, to create one or query, whether to show the artifact to the user, and how to structure the response.
27
+
28
+ ## Blueprints and Artifacts
29
+
30
+ - Determine if the interaction involves an artifact. Prefer artifacts for tables, lists, spreadsheets, kanbans, games, images, and other structured data.
31
+ - Determine if the user is explicitly talking about creating a new artifact, or wants to use an existing artifact.
32
+ - If it is ambiguous, query for existing artifacts first and then decide.
33
+ - If you decide to create an artifact, call the associated tool to create the artifact.
34
+ - Artifacts are stored in the database. Tools are used to create and query artifacts.
35
+ - If you are unsure about creating an artifact ask the user for clarification.
36
+ - Artifacts are mutable objects that can change over the course of the conversation.
37
+ - Always re-query the artifact using the tool (like query or inspect) to get the latest state of the artifact before answering the user.
38
+ - You must never generate the id of the artifact; only recall the ids that are already in the history.
39
+ - Artifacts are created by requiring the specific artifact using the require_artifact tool and creating it by calling the associated tool.
40
+ - You can add suggested actions at the end of your response.
41
+ - Suggested actions should be very concise and start with a verb and be phrased as a command to an agent -- not a question to the user.
42
+ - Suggested actions must be in the form of a user instruction that you can follow.
43
+ - Suggested actions could include actions that create artifacts.
44
+ - After creating an artifact use a tool to add it to the chat context.
45
+
46
+ ## Context
47
+
48
+ Today is {{DATETIME}}.
@@ -0,0 +1,41 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import defaultsDeep from 'lodash.defaultsdeep';
6
+
7
+ import { type ModelCapabilities } from '@dxos/ai';
8
+ import { Template } from '@dxos/blueprints';
9
+
10
+ import FORMAT from './format.tpl?raw';
11
+ import SYSTEM from './system.tpl?raw';
12
+
13
+ /**
14
+ * System template variables.
15
+ */
16
+ export type SystemPromptOptions = ModelCapabilities & {
17
+ DATETIME: string;
18
+ };
19
+
20
+ /**
21
+ * Base system prompt.
22
+ * NOTE: This contains protocol instructions that can not be dynamically edited.
23
+ */
24
+ export const createSystemPrompt = (options: Partial<SystemPromptOptions> = {}) =>
25
+ Template.process<SystemPromptOptions>(
26
+ FORMAT,
27
+ defaultsDeep(options, {
28
+ DATETIME: new Date().toISOString(),
29
+ }),
30
+ );
31
+
32
+ export const templates = {
33
+ /** Editable system prompt.*/
34
+ system: Template.make({
35
+ /**
36
+ * NOTE: We are forbidden from accessing randomness at model level in cloudflare, so we have to have pre-generated ids.
37
+ */
38
+ id: '01K2J2FZWH39F55CS7B26GP1Q3',
39
+ source: SYSTEM,
40
+ }),
41
+ };
@@ -0,0 +1,52 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import * as Schema from 'effect/Schema';
6
+
7
+ import { type ObjectId } from '@dxos/echo/internal';
8
+ import { DXN, LOCAL_SPACE_TAG, type SpaceId } from '@dxos/keys';
9
+ import { trim } from '@dxos/util';
10
+
11
+ /**
12
+ * @deprecated
13
+ */
14
+ export const createArtifactElement = (id: ObjectId) => `<artifact id=${id} />`;
15
+
16
+ /**
17
+ * A model-friendly way to reference an object.
18
+ * Supports vairous formats that will be normalized to a DXN.
19
+ */
20
+ // TODO(burdon): Rename ObjectReference?
21
+ export const ArtifactId: Schema.Schema<string> & {
22
+ toDXN: (reference: ArtifactId, owningSpaceId?: SpaceId) => DXN;
23
+ } = class extends Schema.String.annotations({
24
+ description: trim`
25
+ The ID of the referenced object. Formats accepted:
26
+ - DXN (dxn:echo:@:XXXXX). DXNs can be prepended with an @ symbol for compatibility with in-text references.
27
+ - space ID, object ID tuple (spaceID:objectID)
28
+ - Only object ID that is assumed to be in the current space (XXXXX)
29
+ `,
30
+ examples: ['dxn:echo:@:XXXXX', '@dxn:echo:@:XXXXX', 'spaceID:objectID', 'XXXXX'],
31
+ }) {
32
+ static toDXN(reference: ArtifactId, owningSpaceId?: SpaceId): DXN {
33
+ // Allow @dxn: prefix for compatibility with in-text references.
34
+ if (reference.startsWith('@dxn:')) {
35
+ return DXN.parse(reference.slice(1));
36
+ } else if (reference.startsWith('dxn:')) {
37
+ return DXN.parse(reference);
38
+ } else if (/^[A-Z0-9]+:[A-Z0-9]+$/.test(reference)) {
39
+ const [spaceId, objectId] = reference.split(':');
40
+ // This is a workaround because the current Filter API doesn't work with fully qualified Echo DXNs.
41
+ // We check if the space ID is the same as the owning space and then use LOCAL_SPACE_TAG for local references.
42
+ // TODO(dmaretskyi): Fix this in the Echo and Filter API to properly handle fully qualified DXNs.
43
+ return new DXN(DXN.kind.ECHO, [spaceId === owningSpaceId ? LOCAL_SPACE_TAG : spaceId, objectId]);
44
+ } else if (/^[A-Z0-9]+$/.test(reference)) {
45
+ return DXN.fromLocalObjectId(reference);
46
+ } else {
47
+ throw new Error(`Unable to parse object reference: ${reference}`);
48
+ }
49
+ }
50
+ };
51
+
52
+ export type ArtifactId = Schema.Schema.Type<typeof ArtifactId>;
@@ -0,0 +1,5 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ export * from './artifact';
package/src/typings.d.ts CHANGED
@@ -2,6 +2,11 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
+ declare module '*?raw' {
6
+ const content: string;
7
+ export default content;
8
+ }
9
+
5
10
  declare module '*.tpl?raw' {
6
11
  const content: string;
7
12
  export default content;
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=chat.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../../bin/chat.ts"],"names":[],"mappings":""}