@dxos/assistant 0.8.4-main.dedc0f3 → 0.8.4-main.ead640a

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 (89) hide show
  1. package/dist/lib/browser/{chunk-5GJYG2ML.mjs → chunk-CWGVG235.mjs} +65 -81
  2. package/dist/lib/browser/chunk-CWGVG235.mjs.map +7 -0
  3. package/dist/lib/browser/extraction/index.mjs +18 -14
  4. package/dist/lib/browser/extraction/index.mjs.map +4 -4
  5. package/dist/lib/browser/index.mjs +552 -88
  6. package/dist/lib/browser/index.mjs.map +4 -4
  7. package/dist/lib/browser/meta.json +1 -1
  8. package/dist/lib/node-esm/{chunk-FLFCEB4P.mjs → chunk-OV5PMQPB.mjs} +65 -81
  9. package/dist/lib/node-esm/chunk-OV5PMQPB.mjs.map +7 -0
  10. package/dist/lib/node-esm/extraction/index.mjs +18 -14
  11. package/dist/lib/node-esm/extraction/index.mjs.map +4 -4
  12. package/dist/lib/node-esm/index.mjs +552 -88
  13. package/dist/lib/node-esm/index.mjs.map +4 -4
  14. package/dist/lib/node-esm/meta.json +1 -1
  15. package/dist/types/src/conversation/context.d.ts +14 -7
  16. package/dist/types/src/conversation/context.d.ts.map +1 -1
  17. package/dist/types/src/conversation/conversation.d.ts +9 -10
  18. package/dist/types/src/conversation/conversation.d.ts.map +1 -1
  19. package/dist/types/src/errors.d.ts +38 -38
  20. package/dist/types/src/errors.d.ts.map +1 -1
  21. package/dist/types/src/execution-graph.d.ts +82 -0
  22. package/dist/types/src/execution-graph.d.ts.map +1 -0
  23. package/dist/types/src/execution-graph.test.d.ts +2 -0
  24. package/dist/types/src/execution-graph.test.d.ts.map +1 -0
  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 +61 -57
  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 +10 -6
  29. package/dist/types/src/extraction/extraction.d.ts.map +1 -1
  30. package/dist/types/src/extraction/quotes.d.ts +1 -1
  31. package/dist/types/src/extraction/quotes.d.ts.map +1 -1
  32. package/dist/types/src/functions/services.d.ts +17 -5
  33. package/dist/types/src/functions/services.d.ts.map +1 -1
  34. package/dist/types/src/index.d.ts +2 -1
  35. package/dist/types/src/index.d.ts.map +1 -1
  36. package/dist/types/src/session/artifact-diff.d.ts +2 -2
  37. package/dist/types/src/session/artifact-diff.d.ts.map +1 -1
  38. package/dist/types/src/session/error-handling.d.ts +2 -2
  39. package/dist/types/src/session/error-handling.d.ts.map +1 -1
  40. package/dist/types/src/session/format.d.ts +34 -32
  41. package/dist/types/src/session/format.d.ts.map +1 -1
  42. package/dist/types/src/session/observer.d.ts +1 -1
  43. package/dist/types/src/session/observer.d.ts.map +1 -1
  44. package/dist/types/src/session/session.d.ts +13 -9
  45. package/dist/types/src/session/session.d.ts.map +1 -1
  46. package/dist/types/src/session/toolkit.d.ts +7 -6
  47. package/dist/types/src/session/toolkit.d.ts.map +1 -1
  48. package/dist/types/src/session/version-pin.d.ts +2 -2
  49. package/dist/types/src/session/version-pin.d.ts.map +1 -1
  50. package/dist/types/src/{types.d.ts → types/artifact.d.ts} +3 -3
  51. package/dist/types/src/types/artifact.d.ts.map +1 -0
  52. package/dist/types/src/types/index.d.ts +2 -0
  53. package/dist/types/src/types/index.d.ts.map +1 -0
  54. package/dist/types/tsconfig.tsbuildinfo +1 -1
  55. package/package.json +26 -31
  56. package/src/conversation/context.ts +49 -17
  57. package/src/conversation/conversation.ts +23 -18
  58. package/src/errors.ts +4 -4
  59. package/src/execution-graph.test.ts +738 -0
  60. package/src/execution-graph.ts +500 -0
  61. package/src/extraction/extraction-llm-function/extraction-llm-function.ts +3 -1
  62. package/src/extraction/extraction-ner-function/extraction-ner-function.ts +3 -1
  63. package/src/extraction/extraction-ner-function/named-entity-recognition.test.ts +2 -1
  64. package/src/extraction/extraction.ts +2 -2
  65. package/src/extraction/quotes.test.ts +2 -2
  66. package/src/extraction/quotes.ts +3 -3
  67. package/src/functions/services.ts +85 -46
  68. package/src/index.ts +2 -1
  69. package/src/session/artifact-diff.ts +2 -2
  70. package/src/session/error-handling.ts +11 -6
  71. package/src/session/format.test.ts +1 -1
  72. package/src/session/format.ts +9 -6
  73. package/src/session/observer.ts +2 -1
  74. package/src/session/session.conversations.json +1 -0
  75. package/src/session/session.test.ts +50 -209
  76. package/src/session/session.ts +31 -20
  77. package/src/session/toolkit.ts +19 -13
  78. package/src/session/version-pin.ts +2 -2
  79. package/src/summarization/summarization.test.ts +8 -3
  80. package/src/templates/system.tpl +10 -12
  81. package/src/{types.ts → types/artifact.ts} +2 -2
  82. package/src/types/index.ts +5 -0
  83. package/dist/lib/browser/chunk-5GJYG2ML.mjs.map +0 -7
  84. package/dist/lib/node-esm/chunk-FLFCEB4P.mjs.map +0 -7
  85. package/dist/types/src/session/version-pin.test.d.ts +0 -2
  86. package/dist/types/src/session/version-pin.test.d.ts.map +0 -1
  87. package/dist/types/src/types.d.ts.map +0 -1
  88. package/src/session/__snapshots__/session.test.ts.snap +0 -32
  89. package/src/session/version-pin.test.ts +0 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/assistant",
3
- "version": "0.8.4-main.dedc0f3",
3
+ "version": "0.8.4-main.ead640a",
4
4
  "description": "Natural language interface to DXOS",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -38,41 +38,36 @@
38
38
  "src"
39
39
  ],
40
40
  "dependencies": {
41
- "@automerge/automerge": "3.1.1",
42
- "@effect/ai": "0.25.2",
43
- "@effect/ai-anthropic": "^0.16.1",
44
- "@effect/platform": "^0.90.2",
45
- "@effect/platform-node": "^0.95.0",
46
- "@preact/signals-core": "^1.9.0",
41
+ "@automerge/automerge": "3.1.2",
42
+ "@effect/ai": "0.29.1",
43
+ "@effect/experimental": "0.56.0",
44
+ "@effect/platform": "^0.92.1",
45
+ "@preact/signals-core": "^1.12.1",
47
46
  "@xenova/transformers": "^2.17.2",
48
- "chalk": "^4.1.0",
49
- "handlebars": "4.7.8",
50
47
  "lodash.defaultsdeep": "^4.6.1",
51
- "@dxos/ai": "0.8.4-main.dedc0f3",
52
- "@dxos/blueprints": "0.8.4-main.dedc0f3",
53
- "@dxos/context": "0.8.4-main.dedc0f3",
54
- "@dxos/async": "0.8.4-main.dedc0f3",
55
- "@dxos/debug": "0.8.4-main.dedc0f3",
56
- "@dxos/echo-db": "0.8.4-main.dedc0f3",
57
- "@dxos/echo-protocol": "0.8.4-main.dedc0f3",
58
- "@dxos/echo-schema": "0.8.4-main.dedc0f3",
59
- "@dxos/errors": "0.8.4-main.dedc0f3",
60
- "@dxos/functions": "0.8.4-main.dedc0f3",
61
- "@dxos/effect": "0.8.4-main.dedc0f3",
62
- "@dxos/graph": "0.8.4-main.dedc0f3",
63
- "@dxos/keys": "0.8.4-main.dedc0f3",
64
- "@dxos/echo": "0.8.4-main.dedc0f3",
65
- "@dxos/log": "0.8.4-main.dedc0f3",
66
- "@dxos/node-std": "0.8.4-main.dedc0f3",
67
- "@dxos/schema": "0.8.4-main.dedc0f3",
68
- "@dxos/invariant": "0.8.4-main.dedc0f3",
69
- "@dxos/util": "0.8.4-main.dedc0f3",
70
- "@dxos/live-object": "0.8.4-main.dedc0f3"
48
+ "@dxos/ai": "0.8.4-main.ead640a",
49
+ "@dxos/async": "0.8.4-main.ead640a",
50
+ "@dxos/blueprints": "0.8.4-main.ead640a",
51
+ "@dxos/debug": "0.8.4-main.ead640a",
52
+ "@dxos/echo": "0.8.4-main.ead640a",
53
+ "@dxos/echo-db": "0.8.4-main.ead640a",
54
+ "@dxos/echo-protocol": "0.8.4-main.ead640a",
55
+ "@dxos/effect": "0.8.4-main.ead640a",
56
+ "@dxos/errors": "0.8.4-main.ead640a",
57
+ "@dxos/graph": "0.8.4-main.ead640a",
58
+ "@dxos/functions": "0.8.4-main.ead640a",
59
+ "@dxos/invariant": "0.8.4-main.ead640a",
60
+ "@dxos/keys": "0.8.4-main.ead640a",
61
+ "@dxos/live-object": "0.8.4-main.ead640a",
62
+ "@dxos/log": "0.8.4-main.ead640a",
63
+ "@dxos/node-std": "0.8.4-main.ead640a",
64
+ "@dxos/context": "0.8.4-main.ead640a",
65
+ "@dxos/schema": "0.8.4-main.ead640a",
66
+ "@dxos/util": "0.8.4-main.ead640a"
71
67
  },
72
68
  "devDependencies": {
73
69
  "@types/lodash.defaultsdeep": "^4.6.6",
74
- "effect": "3.17.7",
75
- "inquirer": "^12.0.0"
70
+ "effect": "3.18.3"
76
71
  },
77
72
  "peerDependencies": {
78
73
  "effect": "^3.13.3"
@@ -3,12 +3,16 @@
3
3
  //
4
4
 
5
5
  import { type ReadonlySignal, computed } from '@preact/signals-core';
6
- import { Context, Schema } from 'effect';
7
- import { Array, pipe } from 'effect';
6
+ import * as Array from 'effect/Array';
7
+ import * as Context from 'effect/Context';
8
+ import * as Function from 'effect/Function';
9
+ import * as Schema from 'effect/Schema';
8
10
 
9
11
  import { Blueprint } from '@dxos/blueprints';
10
- import { DXN, Obj, type Ref, type Relation, Type } from '@dxos/echo';
12
+ import { Resource } from '@dxos/context';
13
+ import { DXN, Filter, Obj, Query, type Ref, type Relation, Type } from '@dxos/echo';
11
14
  import { type Queue } from '@dxos/echo-db';
15
+ import { invariant } from '@dxos/invariant';
12
16
  import { ComplexSet } from '@dxos/util';
13
17
 
14
18
  /**
@@ -57,41 +61,69 @@ export class Bindings {
57
61
  * Manages bindings of blueprints and objects to a conversation.
58
62
  */
59
63
  // TODO(burdon): Context should manage ephemeral state of bindings until prompt is issued?
60
- export class AiContextBinder {
64
+ export class AiContextBinder extends Resource {
61
65
  /**
62
66
  * Reactive query of all bindings.
63
67
  */
64
68
  // TODO(burdon): Cache value?
65
- readonly bindings: ReadonlySignal<Bindings> = computed(() => this._reduce(this._queue.objects));
69
+ private _bindings?: ReadonlySignal<Bindings>;
70
+ private _blueprints?: ReadonlySignal<Ref.Ref<Blueprint.Blueprint>[]>;
71
+ private _objects?: ReadonlySignal<Ref.Ref<Type.Expando>[]>;
66
72
 
67
- readonly blueprints: ReadonlySignal<Ref.Ref<Blueprint.Blueprint>[]> = computed(() => [
68
- ...this.bindings.value.blueprints,
69
- ]);
73
+ constructor(private readonly _queue: Queue) {
74
+ super();
75
+ }
76
+
77
+ get bindings() {
78
+ invariant(this._bindings, 'AiContextBinder not open');
79
+ return this._bindings;
80
+ }
81
+
82
+ get blueprints() {
83
+ invariant(this._blueprints, 'AiContextBinder not open');
84
+ return this._blueprints;
85
+ }
86
+
87
+ get objects() {
88
+ invariant(this._objects, 'AiContextBinder not open');
89
+ return this._objects;
90
+ }
70
91
 
71
- readonly objects: ReadonlySignal<Ref.Ref<Type.Expando>[]> = computed(() => [...this.bindings.value.objects]);
92
+ // TODO(wittjosiah): Use parent context?
93
+ protected override async _open(): Promise<void> {
94
+ const query = this._queue.query(Query.select(Filter.everything()));
95
+ this._ctx.onDispose(query.subscribe(() => {}));
96
+ this._bindings = computed(() => this._reduce(query.objects));
97
+ this._blueprints = computed(() => [...this.bindings.value.blueprints]);
98
+ this._objects = computed(() => [...this.bindings.value.objects]);
99
+ }
72
100
 
73
- constructor(private readonly _queue: Queue) {}
101
+ protected override async _close(): Promise<void> {
102
+ this._bindings = undefined;
103
+ this._blueprints = undefined;
104
+ this._objects = undefined;
105
+ }
74
106
 
75
107
  /**
76
108
  * Asynchronous query of all bindings.
77
109
  */
78
110
  async query(): Promise<Bindings> {
79
- const queueItems = await this._queue.queryObjects();
80
- return this._reduce(queueItems);
111
+ const { objects } = await this._queue.query(Query.select(Filter.everything())).run();
112
+ return this._reduce(objects);
81
113
  }
82
114
 
83
115
  // TODO(burdon): Pass in Blueprint obj (from registry?) and create reference.
84
116
  async bind(props: BindingProps): Promise<void> {
85
- if (!props.blueprints?.length && !props.objects?.length) {
86
- return;
87
- }
88
-
89
117
  const blueprints =
90
118
  props.blueprints?.filter((ref) => !this.blueprints.peek().find((b) => b.dxn.toString() === ref.dxn.toString())) ??
91
119
  [];
92
120
  const objects =
93
121
  props.objects?.filter((ref) => !this.objects.peek().find((o) => o.dxn.toString() === ref.dxn.toString())) ?? [];
94
122
 
123
+ if (!blueprints.length && !objects.length) {
124
+ return;
125
+ }
126
+
95
127
  await this._queue.append([
96
128
  Obj.make(ContextBinding, {
97
129
  blueprints: {
@@ -126,7 +158,7 @@ export class AiContextBinder {
126
158
  }
127
159
 
128
160
  private _reduce(items: (Obj.Any | Relation.Any)[]): Bindings {
129
- return pipe(
161
+ return Function.pipe(
130
162
  items,
131
163
  Array.filter(Obj.instanceOf(ContextBinding)),
132
164
  Array.reduce(new Bindings(), (context, item) => {
@@ -2,9 +2,12 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { type AiTool, type AiToolkit } from '@effect/ai';
6
- import { Array, Effect, Option } from 'effect';
5
+ import type * as Toolkit from '@effect/ai/Toolkit';
6
+ import * as Array from 'effect/Array';
7
+ import * as Effect from 'effect/Effect';
8
+ import * as Option from 'effect/Option';
7
9
 
10
+ import { Resource } from '@dxos/context';
8
11
  import { Obj } from '@dxos/echo';
9
12
  import { type Queue } from '@dxos/echo-db';
10
13
  import { DatabaseService } from '@dxos/functions';
@@ -21,25 +24,17 @@ import {
21
24
 
22
25
  import { AiContextBinder, AiContextService, type ContextBinding } from './context';
23
26
 
24
- export type AiConversationRunRequirements<Tools extends AiTool.Any> =
25
- | AiSessionRunRequirements
26
- | AiTool.ToHandler<Tools>;
27
-
28
27
  export interface AiConversationRunParams {
29
28
  prompt: string;
30
29
  system?: string;
31
30
  observer?: GenerationObserver;
32
31
  }
33
32
 
34
- export type AiConversationOptions = {
35
- queue: Queue<DataType.Message | ContextBinding>;
36
- };
37
-
38
33
  /**
39
34
  * Durable conversation state (initiated by users and agents) backed by a Queue.
40
35
  * Executes tools based on AI responses and supports cancellation of in-progress requests.
41
36
  */
42
- export class AiConversation {
37
+ export class AiConversation extends Resource {
43
38
  /**
44
39
  * Message and binding queue.
45
40
  */
@@ -53,13 +48,23 @@ export class AiConversation {
53
48
  /**
54
49
  * Toolkit from the current session request.
55
50
  */
56
- private _toolkit: AiToolkit.ToHandler<AiTool.Any> | undefined;
51
+ private _toolkit: Toolkit.WithHandler<any> | undefined;
57
52
 
58
- public constructor(options: AiConversationOptions) {
59
- this._queue = options.queue;
53
+ public constructor(queue: Queue<DataType.Message | ContextBinding>) {
54
+ super();
55
+ this._queue = queue;
60
56
  this._context = new AiContextBinder(this._queue);
61
57
  }
62
58
 
59
+ protected override async _open(): Promise<void> {
60
+ // TODO(wittjosiah): Pass in parent context?
61
+ await this._context.open();
62
+ }
63
+
64
+ protected override async _close(): Promise<void> {
65
+ await this._context.close();
66
+ }
67
+
63
68
  public get context() {
64
69
  return this._context;
65
70
  }
@@ -76,9 +81,9 @@ export class AiConversation {
76
81
  /**
77
82
  * Creates a new cancelable request effect.
78
83
  */
79
- createRequest<Tools extends AiTool.Any>(
84
+ createRequest(
80
85
  params: AiConversationRunParams,
81
- ): Effect.Effect<DataType.Message[], AiSessionRunError, AiConversationRunRequirements<Tools>> {
86
+ ): Effect.Effect<DataType.Message[], AiSessionRunError, AiSessionRunRequirements> {
82
87
  return Effect.gen(this, function* () {
83
88
  const session = new AiSession();
84
89
  const history = yield* Effect.promise(() => this.getHistory());
@@ -95,7 +100,7 @@ export class AiConversation {
95
100
  );
96
101
 
97
102
  // Create toolkit.
98
- const toolkit = yield* createToolkit<Tools>({ blueprints });
103
+ const toolkit = yield* createToolkit({ blueprints });
99
104
  this._toolkit = toolkit;
100
105
 
101
106
  const start = Date.now();
@@ -107,7 +112,7 @@ export class AiConversation {
107
112
  });
108
113
 
109
114
  // Process request.
110
- const messages = yield* session.run<Tools>({ history, blueprints, objects, toolkit, ...params }).pipe(
115
+ const messages = yield* session.run({ history, blueprints, objects, toolkit, ...params }).pipe(
111
116
  Effect.provideService(AiContextService, {
112
117
  binder: this.context,
113
118
  }),
package/src/errors.ts CHANGED
@@ -5,11 +5,11 @@
5
5
  import { BaseError } from '@dxos/errors';
6
6
 
7
7
  /**
8
- * Generic error for AI agent execution.
8
+ * Generic error from AI model.
9
9
  */
10
- export class AiAssistantError extends BaseError.extend('AI_ASSISTANT_ERROR') {}
10
+ export class AiModelError extends BaseError.extend('AI_MODEL_ERROR', 'AI model error') {}
11
11
 
12
12
  /**
13
- * Parsed error from the anthropic API.
13
+ * Generic error for AI agent execution.
14
14
  */
15
- export class AnthropicError extends BaseError.extend('ANTHROPIC_ERROR') {}
15
+ export class AiAssistantError extends BaseError.extend('AI_ASSISTANT_ERROR', 'AI assistant error') {}