@dxos/assistant 0.9.0 → 0.9.1-staging.ee54ba693a

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 (84) hide show
  1. package/dist/lib/neutral/extraction/index.mjs +108 -119
  2. package/dist/lib/neutral/extraction/index.mjs.map +4 -4
  3. package/dist/lib/neutral/index.mjs +395 -234
  4. package/dist/lib/neutral/index.mjs.map +4 -4
  5. package/dist/lib/neutral/meta.json +1 -1
  6. package/dist/types/src/extraction/extraction-llm-function/index.d.ts +2 -0
  7. package/dist/types/src/extraction/extraction-llm-function/index.d.ts.map +1 -0
  8. package/dist/types/src/extraction/extraction-llm-function/proper-noun-extraction.d.ts +26 -0
  9. package/dist/types/src/extraction/extraction-llm-function/proper-noun-extraction.d.ts.map +1 -0
  10. package/dist/types/src/extraction/index.d.ts +1 -1
  11. package/dist/types/src/extraction/index.d.ts.map +1 -1
  12. package/dist/types/src/extraction/quotes.d.ts +8 -1
  13. package/dist/types/src/extraction/quotes.d.ts.map +1 -1
  14. package/dist/types/src/index.d.ts +1 -1
  15. package/dist/types/src/index.d.ts.map +1 -1
  16. package/dist/types/src/request/AiRequest.d.ts +19 -208
  17. package/dist/types/src/request/AiRequest.d.ts.map +1 -1
  18. package/dist/types/src/request/format.d.ts +1 -1
  19. package/dist/types/src/request/format.d.ts.map +1 -1
  20. package/dist/types/src/session/AiContext.d.ts +27 -105
  21. package/dist/types/src/session/AiContext.d.ts.map +1 -1
  22. package/dist/types/src/session/AiSession.d.ts +11 -29
  23. package/dist/types/src/session/AiSession.d.ts.map +1 -1
  24. package/dist/types/src/session/Harness.d.ts +122 -0
  25. package/dist/types/src/session/Harness.d.ts.map +1 -0
  26. package/dist/types/src/session/SessionLink.d.ts +8 -11
  27. package/dist/types/src/session/SessionLink.d.ts.map +1 -1
  28. package/dist/types/src/session/SessionLoader.d.ts +2 -2
  29. package/dist/types/src/session/SessionLoader.d.ts.map +1 -1
  30. package/dist/types/src/session/SkillHooks.d.ts +28 -0
  31. package/dist/types/src/session/SkillHooks.d.ts.map +1 -0
  32. package/dist/types/src/session/harness-control.d.ts +177 -0
  33. package/dist/types/src/session/harness-control.d.ts.map +1 -0
  34. package/dist/types/src/session/index.d.ts +3 -0
  35. package/dist/types/src/session/index.d.ts.map +1 -1
  36. package/dist/types/src/session/toolkit.d.ts +4 -4
  37. package/dist/types/src/session/toolkit.d.ts.map +1 -1
  38. package/dist/types/src/templates/system.d.ts +4 -6
  39. package/dist/types/src/templates/system.d.ts.map +1 -1
  40. package/dist/types/src/tool-runtime/index.d.ts.map +1 -0
  41. package/dist/types/src/tool-runtime/services.d.ts.map +1 -0
  42. package/dist/types/src/util/artifact.d.ts.map +1 -1
  43. package/dist/types/src/util/diff.d.ts +9 -3
  44. package/dist/types/src/util/diff.d.ts.map +1 -1
  45. package/dist/types/src/util/tracing.d.ts +40 -0
  46. package/dist/types/src/util/tracing.d.ts.map +1 -1
  47. package/dist/types/tsconfig.tsbuildinfo +1 -1
  48. package/package.json +28 -25
  49. package/src/extraction/extraction-llm-function/index.ts +5 -0
  50. package/src/extraction/extraction-llm-function/proper-noun-extraction.ts +78 -0
  51. package/src/extraction/index.ts +1 -1
  52. package/src/extraction/quotes.test.ts +67 -2
  53. package/src/extraction/quotes.ts +47 -13
  54. package/src/index.ts +1 -1
  55. package/src/request/AiRequest.ts +45 -14
  56. package/src/request/format.ts +9 -11
  57. package/src/session/AiContext.test.ts +52 -32
  58. package/src/session/AiContext.ts +73 -95
  59. package/src/session/AiSession.test.ts +4 -4
  60. package/src/session/AiSession.ts +51 -83
  61. package/src/session/Harness.ts +241 -0
  62. package/src/session/SessionLink.ts +8 -8
  63. package/src/session/SessionLoader.ts +4 -4
  64. package/src/session/SkillHooks.ts +71 -0
  65. package/src/session/harness-control.ts +30 -0
  66. package/src/session/index.ts +3 -0
  67. package/src/session/toolkit.ts +8 -8
  68. package/src/templates/instructions/format.tpl +3 -3
  69. package/src/templates/instructions/system.tpl +10 -12
  70. package/src/templates/system.ts +6 -2
  71. package/src/util/artifact.ts +9 -2
  72. package/src/util/diff.test.ts +4 -4
  73. package/src/util/diff.ts +15 -8
  74. package/src/util/tracing.ts +1 -1
  75. package/dist/types/src/extraction/extraction.d.ts +0 -1677
  76. package/dist/types/src/extraction/extraction.d.ts.map +0 -1
  77. package/dist/types/src/functions/index.d.ts.map +0 -1
  78. package/dist/types/src/functions/services.d.ts.map +0 -1
  79. package/src/extraction/extraction-llm-function/transcription-instructions.tpl +0 -28
  80. package/src/extraction/extraction.ts +0 -105
  81. /package/dist/types/src/{functions → tool-runtime}/index.d.ts +0 -0
  82. /package/dist/types/src/{functions → tool-runtime}/services.d.ts +0 -0
  83. /package/src/{functions → tool-runtime}/index.ts +0 -0
  84. /package/src/{functions → tool-runtime}/services.ts +0 -0
@@ -7,12 +7,12 @@ import * as Effect from 'effect/Effect';
7
7
  import * as Layer from 'effect/Layer';
8
8
 
9
9
  import { type AiToolNotFoundError, OpaqueToolkit, ToolExecutionService, ToolResolverService } from '@dxos/ai';
10
- import { type Blueprint } from '@dxos/compute';
10
+ import { type Skill } from '@dxos/compute';
11
11
  import { isTruthy } from '@dxos/util';
12
12
 
13
13
  export type CreateToolkitProps = {
14
14
  toolkit?: OpaqueToolkit.Any;
15
- blueprints?: readonly Blueprint.Blueprint[];
15
+ skills?: readonly Skill.Skill[];
16
16
  /**
17
17
  * Self-contained with handlers toolkits.
18
18
  */
@@ -20,11 +20,11 @@ export type CreateToolkitProps = {
20
20
  };
21
21
 
22
22
  /**
23
- * Build a combined toolkit from the blueprint tools and the provided toolkit.
23
+ * Build a combined toolkit from the skill tools and the provided toolkit.
24
24
  */
25
25
  export const createToolkit = ({
26
26
  toolkit: toolkitProp,
27
- blueprints = [],
27
+ skills = [],
28
28
  opaqueToolkits = [],
29
29
  }: CreateToolkitProps): Effect.Effect<
30
30
  OpaqueToolkit.OpaqueToolkit,
@@ -32,14 +32,14 @@ export const createToolkit = ({
32
32
  ToolResolverService | ToolExecutionService
33
33
  > =>
34
34
  Effect.gen(function* () {
35
- const blueprintToolkit = yield* ToolResolverService.resolveToolkit(blueprints.flatMap(({ tools }) => tools));
36
- const blueprintToolHandler = yield* blueprintToolkit.toContext(ToolExecutionService.handlersFor(blueprintToolkit));
35
+ const skillToolkit = yield* ToolResolverService.resolveToolkit(skills.flatMap(({ tools }) => tools));
36
+ const skillToolHandler = yield* skillToolkit.toContext(ToolExecutionService.handlersFor(skillToolkit));
37
37
  const opaqueToolkit = OpaqueToolkit.merge(...opaqueToolkits);
38
38
 
39
- const toolkitDefs = [toolkitProp?.toolkit, blueprintToolkit, opaqueToolkit.toolkit].filter(isTruthy);
39
+ const toolkitDefs = [toolkitProp?.toolkit, skillToolkit, opaqueToolkit.toolkit].filter(isTruthy);
40
40
  const mergedToolkit = Toolkit.merge(...toolkitDefs);
41
41
  const combinedHandlerLayer = Layer.mergeAll(
42
- Layer.succeedContext(blueprintToolHandler),
42
+ Layer.succeedContext(skillToolHandler),
43
43
  toolkitProp?.layer ?? OpaqueToolkit.empty.layer,
44
44
  opaqueToolkit.layer,
45
45
  );
@@ -2,10 +2,10 @@
2
2
 
3
3
  ## Input Formats
4
4
 
5
- ### Blueprints
5
+ ### Skills
6
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.
7
+ You may be provided with Skill definitions that include specific instructions and tools for a given set of tasks.
8
+ Blue print instructions will be enclosed in a <skill> tag.
9
9
 
10
10
  ### Context objects
11
11
 
@@ -12,20 +12,20 @@
12
12
  ## Planning
13
13
 
14
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.
15
+ - Determine if you complete the task using the available skill definitions?
16
+ - If you can't complete the task using the available skill definitions, query the list of available skill definitions using the appropriate tool.
17
+ - Identify which skill definitions are relevant to the user's request.
18
18
  - Evaluate the potential benefits of creating an artifact vs. normal processing for each identified element.
19
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.
20
+ - Are the required skill definitions already available?
21
+ - If not, select which skill definition(s) will be the most relevant and require them using the require_artifact_definitions tool.
22
22
  - The require'd artifact tools will be available for use after require.
23
23
  - If creating an artifact, outline how you will structure it within the response.
24
24
  - Decide if the artifact needs to be shown to the user.
25
25
  - Call the show tool to show the artifact to the user.
26
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
27
 
28
- ## Blueprints and Artifacts
28
+ ## Skills and Artifacts
29
29
 
30
30
  - Determine if the interaction involves an artifact. Prefer artifacts for tables, lists, spreadsheets, kanbans, games, images, and other structured data.
31
31
  - Determine if the user is explicitly talking about creating a new artifact, or wants to use an existing artifact.
@@ -45,12 +45,10 @@
45
45
 
46
46
  ## Navigation
47
47
 
48
- - When the user asks to open, go to, navigate to, or show a specific document, page, or object, use the navigation tools instead of loading content inline.
49
- - First, call the Resolve navigation targets tool to find the navigation path for the requested item.
50
- - Without arguments, it returns available pages that can be navigated to.
51
- - With a DXN in the query, it resolves that specific object to a navigation path.
52
- - If you know the object's DXN (e.g. from a database query or context objects), pass it in the query to get the exact navigation path.
53
- - Then, call the Open tool with the resolved navigation path(s) in the subject array to navigate the user to that item.
48
+ - When the user asks to open, go to, navigate to, or show a specific document, page, or object, use the navigation tools instead of loading content inline. Navigation is always two steps: first resolve a navigation path with Resolve navigation targets, then open that path with Open.
49
+ - The Open tool accepts navigation **paths** only. Never pass an object DXN, URI, or id to Open — pass only a `path` returned by Resolve navigation targets. Passing anything else will fail to navigate.
50
+ - To open a specific object: call Resolve navigation targets with the object's URI in the `query.uri` field — use the value from the object's `<dxn>` tag in context (which may be an `echo:` EID or a `dxn:` DXN), then pass the returned target's `path` to Open.
51
+ - To navigate to a page (not a specific object): call Resolve navigation targets without arguments to list the available pages, then pass the chosen target's `path` to Open.
54
52
  - Do not respond with the document's content when the user asks to open it — open it in the main content area instead.
55
53
  - If multiple targets match, present the options to the user and let them choose which to open.
56
54
 
@@ -4,8 +4,12 @@
4
4
 
5
5
  import defaultsDeep from 'lodash.defaultsdeep';
6
6
 
7
- import { type ModelCapabilities } from '@dxos/ai';
7
+ import { Model } from '@dxos/ai';
8
8
  import { Template } from '@dxos/compute';
9
+ // Text is referenced in the inferred type of 'templates' (via Template.make → Template.Template.source → Ref.Ref(Text.Text));
10
+ // the import lets TypeScript name it in the emitted .d.ts.
11
+ // eslint-disable-next-line unused-imports/no-unused-imports
12
+ import { type Text } from '@dxos/schema';
9
13
 
10
14
  import FORMAT from './instructions/format.tpl?raw';
11
15
  import SYSTEM from './instructions/system.tpl?raw';
@@ -13,7 +17,7 @@ import SYSTEM from './instructions/system.tpl?raw';
13
17
  /**
14
18
  * System template variables.
15
19
  */
16
- export type SystemPromptOptions = ModelCapabilities & {
20
+ export type SystemPromptOptions = Model.Capabilities & {
17
21
  DATETIME: string;
18
22
  };
19
23
 
@@ -88,8 +88,15 @@ type ArtifactURI = Schema.Schema.Type<typeof ArtifactURI>;
88
88
  * Schema that decodes ECHO reference object from an LLM-friendly input.
89
89
  */
90
90
  export const RefFromLLM = Schema.transform(ArtifactURI, Ref.Ref(Obj.Unknown), {
91
- decode: (fromA, fromI) => EncodedReference.fromURI(ArtifactURI.toEchoURI(fromA)),
92
- encode: (toI, toA) => EncodedReference.toURI(toI),
91
+ decode: (fromA) => {
92
+ const eid = ArtifactURI.toEchoURI(fromA);
93
+ // Normalize to local form: strip any space authority so the ref resolves within the current
94
+ // space context. The AI commonly sends echo://SPACE/ENTITY format (mirroring what it sees in
95
+ // the database context), but cross-space resolution is not yet supported and the space ID
96
+ // encoded in the URI is always the current space anyway.
97
+ return EncodedReference.fromURI(EID.toLocal(eid));
98
+ },
99
+ encode: (toI) => EncodedReference.toURI(toI),
93
100
  strict: false,
94
101
  }).annotations({
95
102
  description: ArtifactURI.ast.annotations.description as string,
@@ -4,8 +4,8 @@
4
4
 
5
5
  import { afterEach, beforeEach, describe, expect, it } from 'vitest';
6
6
 
7
- import { createDocAccessor } from '@dxos/echo-client';
8
7
  import { EchoTestBuilder } from '@dxos/echo-client/testing';
8
+ import { Doc } from '@dxos/echo-doc';
9
9
  import { Text } from '@dxos/schema';
10
10
  import { trim } from '@dxos/util';
11
11
 
@@ -32,7 +32,7 @@ describe('diff', () => {
32
32
  `;
33
33
 
34
34
  const text = db.add(Text.make({ content: document }));
35
- const accessor = createDocAccessor(text, ['content']);
35
+ const accessor = Doc.createAccessor(text, ['content']);
36
36
  const result = applyDiffs(accessor, [
37
37
  `- There'z a typo in this sentence.`,
38
38
  `+ There is a typo in this sentence.`,
@@ -54,7 +54,7 @@ describe('diff', () => {
54
54
  const document = '# Shopping list';
55
55
 
56
56
  const text = db.add(Text.make({ content: document }));
57
- const accessor = createDocAccessor(text, ['content']);
57
+ const accessor = Doc.createAccessor(text, ['content']);
58
58
  const result = applyDiffs(accessor, ['- # Shopping list', '+ # Shopping list\n- Milk']);
59
59
 
60
60
  expect(result).toBe('# Shopping list\n- Milk');
@@ -66,7 +66,7 @@ describe('diff', () => {
66
66
  graph.registry.add([Text.Text]);
67
67
 
68
68
  const text = db.add(Text.make({ content: '' }));
69
- const accessor = createDocAccessor(text, ['content']);
69
+ const accessor = Doc.createAccessor(text, ['content']);
70
70
  const result = applyDiffs(accessor, ['+ # Shopping list']);
71
71
 
72
72
  expect(result).toBe('# Shopping list');
package/src/util/diff.ts CHANGED
@@ -2,9 +2,10 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { next as A, type Doc } from '@automerge/automerge';
5
+ import { next as A, type Doc as AutomergeDoc } from '@automerge/automerge';
6
6
 
7
- import { DocAccessor, toCursorRange } from '@dxos/echo-client';
7
+ import { toCursorRange } from '@dxos/echo-client';
8
+ import { Doc } from '@dxos/echo-doc';
8
9
  import { log } from '@dxos/log';
9
10
  import { isNonNullable } from '@dxos/util';
10
11
 
@@ -54,10 +55,13 @@ export const reduceDiffs = (diffs: readonly string[]): Diff[] => {
54
55
  }, []);
55
56
  };
56
57
 
57
- export const computeDiffsWithCursors = <T>(accessor: DocAccessor<T>, diffs: readonly string[]) => {
58
+ /**
59
+ * Resolves text diffs against the accessor's current value into cursor-anchored replacements.
60
+ */
61
+ export const computeDiffsWithCursors = <T>(accessor: Doc.Accessor<T>, diffs: readonly string[]) => {
58
62
  return reduceDiffs(diffs)
59
63
  .map((diff) => {
60
- const text = DocAccessor.getValue<string>(accessor);
64
+ const text = Doc.getValue<string>(accessor);
61
65
  const idx = text.indexOf(diff.match);
62
66
  if (idx !== -1) {
63
67
  return { cursor: toCursorRange(accessor, idx, idx + diff.match.length), text: diff.replace };
@@ -66,14 +70,17 @@ export const computeDiffsWithCursors = <T>(accessor: DocAccessor<T>, diffs: read
66
70
  .filter(isNonNullable);
67
71
  };
68
72
 
73
+ /**
74
+ * Applies text diffs to the accessor-backed document and returns the resulting string.
75
+ */
69
76
  export const applyDiffs = <T>(
70
- accessor: DocAccessor<T>,
77
+ accessor: Doc.Accessor<T>,
71
78
  diffs: readonly string[],
72
79
  { errorOnNotFound = false }: { errorOnNotFound?: boolean } = {},
73
80
  ): string => {
74
81
  for (const diff of reduceDiffs(diffs)) {
75
- accessor.handle.change((doc: Doc<T>) => {
76
- const text = DocAccessor.getValue<string>(accessor);
82
+ accessor.handle.change((doc: AutomergeDoc<T>) => {
83
+ const text = Doc.getValue<string>(accessor);
77
84
  const idx = text.indexOf(diff.match);
78
85
  if (idx !== -1) {
79
86
  // TODO(burdon): Replace smallest substring.
@@ -89,5 +96,5 @@ export const applyDiffs = <T>(
89
96
  });
90
97
  }
91
98
 
92
- return DocAccessor.getValue<string>(accessor);
99
+ return Doc.getValue<string>(accessor);
93
100
  };
@@ -6,7 +6,7 @@ import * as Schema from 'effect/Schema';
6
6
 
7
7
  import { Trace } from '@dxos/compute';
8
8
  import { Obj } from '@dxos/echo';
9
- import { ContentBlock, Actor } from '@dxos/types';
9
+ import { Actor, ContentBlock } from '@dxos/types';
10
10
 
11
11
  /**
12
12
  * Partial content block emitted.