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

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 (107) hide show
  1. package/dist/lib/neutral/extraction/index.mjs +29 -50
  2. package/dist/lib/neutral/extraction/index.mjs.map +4 -4
  3. package/dist/lib/neutral/index.mjs +765 -362
  4. package/dist/lib/neutral/index.mjs.map +4 -4
  5. package/dist/lib/neutral/meta.json +1 -1
  6. package/dist/types/src/conversation/context.d.ts +28 -22
  7. package/dist/types/src/conversation/context.d.ts.map +1 -1
  8. package/dist/types/src/conversation/index.d.ts +1 -1
  9. package/dist/types/src/conversation/index.d.ts.map +1 -1
  10. package/dist/types/src/conversation/session.d.ts +78 -0
  11. package/dist/types/src/conversation/session.d.ts.map +1 -0
  12. package/dist/types/src/diff.d.ts.map +1 -1
  13. package/dist/types/src/errors.d.ts +12 -12
  14. package/dist/types/src/errors.d.ts.map +1 -1
  15. package/dist/types/src/execution-graph.d.ts.map +1 -1
  16. package/dist/types/src/extraction/extraction-ner-function/index.d.ts +0 -1
  17. package/dist/types/src/extraction/extraction-ner-function/index.d.ts.map +1 -1
  18. package/dist/types/src/extraction/extraction-ner-function/named-entity-recognition.d.ts.map +1 -1
  19. package/dist/types/src/extraction/extraction.d.ts +867 -153
  20. package/dist/types/src/extraction/extraction.d.ts.map +1 -1
  21. package/dist/types/src/extraction/index.d.ts +0 -1
  22. package/dist/types/src/extraction/index.d.ts.map +1 -1
  23. package/dist/types/src/extraction/quotes.d.ts.map +1 -1
  24. package/dist/types/src/functions/services.d.ts +14 -16
  25. package/dist/types/src/functions/services.d.ts.map +1 -1
  26. package/dist/types/src/index.d.ts +1 -0
  27. package/dist/types/src/index.d.ts.map +1 -1
  28. package/dist/types/src/session/artifact-diff.d.ts.map +1 -1
  29. package/dist/types/src/session/error-handling.d.ts.map +1 -1
  30. package/dist/types/src/session/format.d.ts +6 -3
  31. package/dist/types/src/session/format.d.ts.map +1 -1
  32. package/dist/types/src/session/index.d.ts +1 -1
  33. package/dist/types/src/session/request.d.ts +104 -0
  34. package/dist/types/src/session/request.d.ts.map +1 -0
  35. package/dist/types/src/session/toolkit.d.ts +5 -7
  36. package/dist/types/src/session/toolkit.d.ts.map +1 -1
  37. package/dist/types/src/templates/system.d.ts +1 -2
  38. package/dist/types/src/templates/system.d.ts.map +1 -1
  39. package/dist/types/src/tracing.d.ts +233 -0
  40. package/dist/types/src/tracing.d.ts.map +1 -0
  41. package/dist/types/src/types/artifact.d.ts.map +1 -1
  42. package/dist/types/tsconfig.tsbuildinfo +1 -1
  43. package/package.json +24 -40
  44. package/src/conversation/context.test.ts +19 -13
  45. package/src/conversation/context.ts +128 -55
  46. package/src/conversation/index.ts +1 -1
  47. package/src/conversation/session.ts +334 -0
  48. package/src/diff.test.ts +3 -3
  49. package/src/execution-graph.test.ts +1 -1
  50. package/src/execution-graph.ts +16 -6
  51. package/src/extraction/extraction-ner-function/index.ts +0 -1
  52. package/src/extraction/extraction.ts +36 -8
  53. package/src/extraction/index.ts +0 -1
  54. package/src/functions/services.ts +57 -52
  55. package/src/index.ts +1 -0
  56. package/src/session/format.ts +14 -10
  57. package/src/session/index.ts +1 -1
  58. package/src/session/request.ts +342 -0
  59. package/src/session/toolkit.ts +18 -15
  60. package/src/templates/instructions/system.tpl +50 -2
  61. package/src/templates/system.ts +7 -6
  62. package/src/tracing.ts +57 -0
  63. package/dist/lib/neutral/chunk-BE6SRJ4N.mjs +0 -193
  64. package/dist/lib/neutral/chunk-BE6SRJ4N.mjs.map +0 -7
  65. package/dist/lib/neutral/testing/index.mjs +0 -38
  66. package/dist/lib/neutral/testing/index.mjs.map +0 -7
  67. package/dist/types/src/conversation/conversation.d.ts +0 -66
  68. package/dist/types/src/conversation/conversation.d.ts.map +0 -1
  69. package/dist/types/src/conversation/conversation.test.d.ts +0 -2
  70. package/dist/types/src/conversation/conversation.test.d.ts.map +0 -1
  71. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts +0 -4
  72. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts.map +0 -1
  73. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.test.d.ts +0 -2
  74. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.test.d.ts.map +0 -1
  75. package/dist/types/src/extraction/extraction-llm-function/index.d.ts +0 -2
  76. package/dist/types/src/extraction/extraction-llm-function/index.d.ts.map +0 -1
  77. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts +0 -355
  78. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts.map +0 -1
  79. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.test.d.ts +0 -2
  80. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.test.d.ts.map +0 -1
  81. package/dist/types/src/functions.test.d.ts +0 -2
  82. package/dist/types/src/functions.test.d.ts.map +0 -1
  83. package/dist/types/src/session/format.test.d.ts +0 -2
  84. package/dist/types/src/session/format.test.d.ts.map +0 -1
  85. package/dist/types/src/session/session.d.ts +0 -61
  86. package/dist/types/src/session/session.d.ts.map +0 -1
  87. package/dist/types/src/session/session.test.d.ts +0 -2
  88. package/dist/types/src/session/session.test.d.ts.map +0 -1
  89. package/dist/types/src/testing/index.d.ts +0 -2
  90. package/dist/types/src/testing/index.d.ts.map +0 -1
  91. package/dist/types/src/testing/layer.d.ts +0 -22
  92. package/dist/types/src/testing/layer.d.ts.map +0 -1
  93. package/src/conversation/conversation.test.ts +0 -65
  94. package/src/conversation/conversation.ts +0 -247
  95. package/src/extraction/extraction-llm-function/extraction-llm-function.test.ts +0 -84
  96. package/src/extraction/extraction-llm-function/extraction-llm-function.ts +0 -62
  97. package/src/extraction/extraction-llm-function/index.ts +0 -5
  98. package/src/extraction/extraction-ner-function/extraction-ner-function.test.ts +0 -116
  99. package/src/extraction/extraction-ner-function/extraction-ner-function.ts +0 -56
  100. package/src/functions.conversations.json +0 -1
  101. package/src/functions.test.ts +0 -74
  102. package/src/session/format.test.ts +0 -124
  103. package/src/session/session.conversations.json +0 -1
  104. package/src/session/session.test.ts +0 -191
  105. package/src/session/session.ts +0 -251
  106. package/src/testing/index.ts +0 -5
  107. package/src/testing/layer.ts +0 -85
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/assistant",
3
- "version": "0.8.4-main.c85a9c8dae",
3
+ "version": "0.8.4-main.cb12b3f963",
4
4
  "description": "Natural language interface to DXOS",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -22,30 +22,15 @@
22
22
  "source": "./src/extraction/index.ts",
23
23
  "types": "./dist/types/src/extraction/index.d.ts",
24
24
  "default": "./dist/lib/neutral/extraction/index.mjs"
25
- },
26
- "./testing": {
27
- "source": "./src/testing/index.ts",
28
- "types": "./dist/types/src/testing/index.d.ts",
29
- "default": "./dist/lib/neutral/testing/index.mjs"
30
25
  }
31
26
  },
32
27
  "types": "dist/types/src/index.d.ts",
33
- "typesVersions": {
34
- "*": {
35
- "types": [
36
- "dist/types/src/types/index.d.ts"
37
- ],
38
- "extraction": [
39
- "dist/types/src/extraction/index.d.ts"
40
- ]
41
- }
42
- },
43
28
  "files": [
44
29
  "dist",
45
30
  "src"
46
31
  ],
47
32
  "dependencies": {
48
- "@automerge/automerge": "3.2.3",
33
+ "@automerge/automerge": "3.2.6",
49
34
  "@effect-atom/atom": "^0.5.1",
50
35
  "@effect-atom/atom-react": "^0.5.0",
51
36
  "@effect/ai": "0.33.2",
@@ -53,34 +38,33 @@
53
38
  "@effect/platform": "0.94.4",
54
39
  "@xenova/transformers": "^2.17.2",
55
40
  "lodash.defaultsdeep": "^4.6.1",
56
- "@dxos/ai": "0.8.4-main.c85a9c8dae",
57
- "@dxos/context": "0.8.4-main.c85a9c8dae",
58
- "@dxos/debug": "0.8.4-main.c85a9c8dae",
59
- "@dxos/echo-db": "0.8.4-main.c85a9c8dae",
60
- "@dxos/echo": "0.8.4-main.c85a9c8dae",
61
- "@dxos/async": "0.8.4-main.c85a9c8dae",
62
- "@dxos/echo-protocol": "0.8.4-main.c85a9c8dae",
63
- "@dxos/effect": "0.8.4-main.c85a9c8dae",
64
- "@dxos/errors": "0.8.4-main.c85a9c8dae",
65
- "@dxos/functions": "0.8.4-main.c85a9c8dae",
66
- "@dxos/blueprints": "0.8.4-main.c85a9c8dae",
67
- "@dxos/functions-runtime": "0.8.4-main.c85a9c8dae",
68
- "@dxos/invariant": "0.8.4-main.c85a9c8dae",
69
- "@dxos/keys": "0.8.4-main.c85a9c8dae",
70
- "@dxos/log": "0.8.4-main.c85a9c8dae",
71
- "@dxos/mcp-client": "0.8.4-main.c85a9c8dae",
72
- "@dxos/schema": "0.8.4-main.c85a9c8dae",
73
- "@dxos/node-std": "0.8.4-main.c85a9c8dae",
74
- "@dxos/graph": "0.8.4-main.c85a9c8dae",
75
- "@dxos/types": "0.8.4-main.c85a9c8dae",
76
- "@dxos/util": "0.8.4-main.c85a9c8dae"
41
+ "@dxos/ai": "0.8.4-main.cb12b3f963",
42
+ "@dxos/async": "0.8.4-main.cb12b3f963",
43
+ "@dxos/context": "0.8.4-main.cb12b3f963",
44
+ "@dxos/debug": "0.8.4-main.cb12b3f963",
45
+ "@dxos/echo": "0.8.4-main.cb12b3f963",
46
+ "@dxos/echo-protocol": "0.8.4-main.cb12b3f963",
47
+ "@dxos/echo-db": "0.8.4-main.cb12b3f963",
48
+ "@dxos/compute": "0.8.4-main.cb12b3f963",
49
+ "@dxos/effect": "0.8.4-main.cb12b3f963",
50
+ "@dxos/errors": "0.8.4-main.cb12b3f963",
51
+ "@dxos/functions": "0.8.4-main.cb12b3f963",
52
+ "@dxos/invariant": "0.8.4-main.cb12b3f963",
53
+ "@dxos/graph": "0.8.4-main.cb12b3f963",
54
+ "@dxos/keys": "0.8.4-main.cb12b3f963",
55
+ "@dxos/log": "0.8.4-main.cb12b3f963",
56
+ "@dxos/mcp-client": "0.8.4-main.cb12b3f963",
57
+ "@dxos/types": "0.8.4-main.cb12b3f963",
58
+ "@dxos/node-std": "0.8.4-main.cb12b3f963",
59
+ "@dxos/util": "0.8.4-main.cb12b3f963",
60
+ "@dxos/schema": "0.8.4-main.cb12b3f963"
77
61
  },
78
62
  "devDependencies": {
79
63
  "@types/lodash.defaultsdeep": "^4.6.6",
80
- "effect": "3.19.16"
64
+ "effect": "3.20.0"
81
65
  },
82
66
  "peerDependencies": {
83
- "effect": "3.19.16"
67
+ "effect": "3.20.0"
84
68
  },
85
69
  "publishConfig": {
86
70
  "access": "public"
@@ -2,35 +2,41 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
+ import * as Context from 'effect/Context';
6
+ import * as Effect from 'effect/Effect';
7
+ import * as Layer from 'effect/Layer';
8
+ import * as Runtime from 'effect/Runtime';
5
9
  import * as Schema from 'effect/Schema';
6
10
  import { describe, it } from 'vitest';
7
11
 
8
- import { Obj, Ref, Type } from '@dxos/echo';
9
- import { type Queue } from '@dxos/echo-db';
12
+ import { Feed, Obj, Ref, Type } from '@dxos/echo';
10
13
 
11
14
  import { AiContextBinder } from './context';
12
15
 
13
- // TODO(burdon): Create mock queue?
14
- const createMockQueue = (): Queue =>
15
- ({
16
+ const createMockFeedRuntime = (): Runtime.Runtime<Feed.FeedService> => {
17
+ const mockFeedService: Context.Tag.Service<Feed.FeedService> = {
18
+ append: async () => {},
19
+ remove: async () => {},
16
20
  query: () =>
17
21
  ({
18
- subscribe: () => ({ unsubscribe: () => {} }),
22
+ subscribe: () => () => {},
19
23
  results: [],
24
+ run: async () => [],
20
25
  }) as any,
21
- append: async () => {
22
- return [] as any;
23
- },
24
- }) as any;
26
+ };
27
+ const layer = Layer.succeed(Feed.FeedService, mockFeedService);
28
+ return Effect.runSync(Effect.runtime<Feed.FeedService>().pipe(Effect.provide(layer)));
29
+ };
25
30
 
26
31
  describe('AiContextBinder', () => {
27
32
  it('should handle bind with Ref', async () => {
28
- const queue = createMockQueue();
29
- const binder = new AiContextBinder({ queue });
33
+ const feed = Feed.make();
34
+ const runtime = createMockFeedRuntime();
35
+ const binder = new AiContextBinder({ feed, runtime });
30
36
 
31
37
  const TestSchema = Schema.Struct({}).pipe(
32
38
  Type.object({
33
- typename: 'dxos.org/type/Example',
39
+ typename: 'org.dxos.type.example',
34
40
  version: '0.1.0',
35
41
  }),
36
42
  );
@@ -7,15 +7,15 @@ import * as EArray from 'effect/Array';
7
7
  import * as Context from 'effect/Context';
8
8
  import * as Effect from 'effect/Effect';
9
9
  import * as Function from 'effect/Function';
10
+ import * as Runtime from 'effect/Runtime';
10
11
  import * as Schema from 'effect/Schema';
11
12
 
12
- import { Blueprint } from '@dxos/blueprints';
13
+ import { Blueprint } from '@dxos/compute';
13
14
  import { Resource } from '@dxos/context';
14
- import { DXN, Obj, Query, Ref, Type } from '@dxos/echo';
15
- import { type Queue } from '@dxos/echo-db';
15
+ import { DXN, Feed, Obj, type QueryResult, Query, Ref, Type } from '@dxos/echo';
16
16
  import { assertArgument } from '@dxos/invariant';
17
17
  import { log } from '@dxos/log';
18
- import { ComplexSet, isTruthy } from '@dxos/util';
18
+ import { ComplexSet, isNonNullable } from '@dxos/util';
19
19
 
20
20
  /**
21
21
  * Thread message that binds or unbinds contextual objects to a conversation.
@@ -33,7 +33,7 @@ export const ContextBinding = Schema.Struct({
33
33
  }),
34
34
  }).pipe(
35
35
  Type.object({
36
- typename: 'dxos.org/type/ContextBinding',
36
+ typename: 'org.dxos.type.contextBinding',
37
37
  version: '0.1.0',
38
38
  }),
39
39
  );
@@ -60,7 +60,8 @@ export class Bindings {
60
60
  }
61
61
 
62
62
  export type AiContextBinderOptions = {
63
- queue: Queue;
63
+ feed: Feed.Feed;
64
+ runtime: Runtime.Runtime<Feed.FeedService>;
64
65
  registry?: Registry.Registry;
65
66
  };
66
67
 
@@ -72,12 +73,16 @@ export class AiContextBinder extends Resource {
72
73
  private readonly _blueprints = Atom.make<Blueprint.Blueprint[]>([]).pipe(Atom.keepAlive);
73
74
  private readonly _objects = Atom.make<Obj.Unknown[]>([]).pipe(Atom.keepAlive);
74
75
  private readonly _registry: Registry.Registry;
75
- private readonly _queue: Queue;
76
+ private readonly _feed: Feed.Feed;
77
+ private readonly _runtime: Runtime.Runtime<Feed.FeedService>;
78
+ #bindingsQuery: QueryResult.QueryResult<ContextBinding> | undefined;
76
79
 
77
80
  constructor(options: AiContextBinderOptions) {
78
81
  super();
79
- assertArgument(options.queue, 'options.queue', 'Queue is required');
80
- this._queue = options.queue;
82
+ assertArgument(options.feed, 'options.feed', 'Feed is required');
83
+ assertArgument(options.runtime, 'options.runtime', 'Feed runtime is required');
84
+ this._feed = options.feed;
85
+ this._runtime = options.runtime;
81
86
  this._registry = options.registry ?? Registry.make();
82
87
  }
83
88
 
@@ -124,20 +129,35 @@ export class AiContextBinder extends Resource {
124
129
  }
125
130
 
126
131
  protected override async _open(): Promise<void> {
127
- const query = this._queue.query(Query.type(ContextBinding));
132
+ this.#bindingsQuery = await Runtime.runPromise(this._runtime)(Feed.query(this._feed, Query.type(ContextBinding)));
128
133
 
129
134
  // Process initial state before returning.
130
- const initialResults = await query.run();
135
+ const initialResults = await this.#bindingsQuery.run();
131
136
  await this._updateBindings(initialResults);
132
137
 
133
138
  // Subscribe to future changes.
134
139
  this._ctx.onDispose(
135
- query.subscribe(async () => {
136
- await this._updateBindings(query.results);
140
+ this.#bindingsQuery.subscribe(async () => {
141
+ await this._updateBindings(this.#bindingsQuery!.results);
137
142
  }),
138
143
  );
139
144
  }
140
145
 
146
+ /**
147
+ * Re-reads bindings from the feed to pick up changes made by other processes.
148
+ */
149
+ async sync(): Promise<void> {
150
+ if (this.#bindingsQuery) {
151
+ const results = await this.#bindingsQuery.run();
152
+ log('sync', { bindingItems: results.length });
153
+ await this._updateBindings(results);
154
+ log('sync complete', {
155
+ blueprints: this._registry.get(this._blueprints).length,
156
+ blueprintKeys: this._registry.get(this._blueprints).map((bp) => (bp as any).key),
157
+ });
158
+ }
159
+ }
160
+
141
161
  private async _updateBindings(items: ContextBinding[]): Promise<void> {
142
162
  // Skip update if no items - preserve existing state set by bind().
143
163
  if (items.length === 0) {
@@ -146,19 +166,43 @@ export class AiContextBinder extends Resource {
146
166
 
147
167
  const bindings = this._reduce(items);
148
168
 
169
+ log('_updateBindings', {
170
+ items: items.length,
171
+ blueprintRefs: [...bindings.blueprints].map((ref) => ({ dxn: ref.dxn.toString(), available: ref.isAvailable })),
172
+ });
173
+
149
174
  // Resolve references (loading them first if needed).
150
175
  const currentBlueprints = this._registry.get(this._blueprints);
151
176
  const currentObjects = this._registry.get(this._objects);
152
- const newBlueprints = await this._resolve(bindings.blueprints, currentBlueprints);
153
- const newObjects = await this._resolve(bindings.objects, currentObjects);
177
+ const resolvedBlueprints = await this._resolve(bindings.blueprints, currentBlueprints);
178
+ const resolvedObjects = await this._resolve(bindings.objects, currentObjects);
154
179
 
155
- // Atomic updates - subscribers notified automatically.
156
- this._registry.set(this._blueprints, newBlueprints);
157
- this._registry.set(this._objects, newObjects);
180
+ log('_updateBindings resolved', {
181
+ resolvedBlueprints: resolvedBlueprints.length,
182
+ resolvedBlueprintKeys: resolvedBlueprints.map((bp) => (bp as any).key),
183
+ });
184
+
185
+ // Filter current state to only items still in the reduced binding set,
186
+ // then merge in newly resolved items. This ensures unbind events are respected.
187
+ const reducedBlueprintDxns = new ComplexSet<DXN>(
188
+ DXN.hash,
189
+ [...bindings.blueprints].map((ref) => ref.dxn),
190
+ );
191
+ const reducedObjectDxns = new ComplexSet<DXN>(
192
+ DXN.hash,
193
+ [...bindings.objects].map((ref) => ref.dxn),
194
+ );
195
+ const filteredBlueprints = currentBlueprints.filter((obj) => reducedBlueprintDxns.has(Obj.getDXN(obj)));
196
+ const filteredObjects = currentObjects.filter((obj) => reducedObjectDxns.has(Obj.getDXN(obj)));
197
+ const mergedBlueprints = this._mergeInto(filteredBlueprints, resolvedBlueprints);
198
+ const mergedObjects = this._mergeInto(filteredObjects, resolvedObjects);
199
+
200
+ this._registry.set(this._blueprints, mergedBlueprints);
201
+ this._registry.set(this._objects, mergedObjects);
158
202
 
159
203
  log('updated bindings', {
160
- blueprints: newBlueprints.length,
161
- objects: newObjects.length,
204
+ blueprints: mergedBlueprints.length,
205
+ objects: mergedObjects.length,
162
206
  });
163
207
  }
164
208
 
@@ -183,18 +227,20 @@ export class AiContextBinder extends Resource {
183
227
  this._registry.set(this._objects, nextObjects);
184
228
 
185
229
  log('bind', { blueprints: addedBlueprints.length, objects: addedObjects.length });
186
- await this._queue.append([
187
- Obj.make(ContextBinding, {
188
- blueprints: {
189
- added: addedBlueprints,
190
- removed: [],
191
- },
192
- objects: {
193
- added: addedObjects,
194
- removed: [],
195
- },
196
- }),
197
- ]);
230
+ await Runtime.runPromise(this._runtime)(
231
+ Feed.append(this._feed, [
232
+ Obj.make(ContextBinding, {
233
+ blueprints: {
234
+ added: addedBlueprints,
235
+ removed: [],
236
+ },
237
+ objects: {
238
+ added: addedObjects,
239
+ removed: [],
240
+ },
241
+ }),
242
+ ]),
243
+ );
198
244
  }
199
245
 
200
246
  async unbind({ blueprints, objects }: BindingProps): Promise<void> {
@@ -202,19 +248,39 @@ export class AiContextBinder extends Resource {
202
248
  return;
203
249
  }
204
250
 
251
+ // Immediately update atom state so removals are reflected before the queue round-trips.
252
+ const removedBlueprintDxns = (blueprints ?? []).map((ref) => ref.dxn);
253
+ const removedObjectDxns = (objects ?? []).map((ref) => ref.dxn);
254
+ if (removedBlueprintDxns.length > 0) {
255
+ const current = this._registry.get(this._blueprints);
256
+ this._registry.set(
257
+ this._blueprints,
258
+ current.filter((obj) => !removedBlueprintDxns.some((dxn) => DXN.equalsEchoId(Obj.getDXN(obj), dxn))),
259
+ );
260
+ }
261
+ if (removedObjectDxns.length > 0) {
262
+ const current = this._registry.get(this._objects);
263
+ this._registry.set(
264
+ this._objects,
265
+ current.filter((obj) => !removedObjectDxns.some((dxn) => DXN.equalsEchoId(Obj.getDXN(obj), dxn))),
266
+ );
267
+ }
268
+
205
269
  log('unbind', { blueprints: blueprints?.length, objects: objects?.length });
206
- await this._queue.append([
207
- Obj.make(ContextBinding, {
208
- blueprints: {
209
- added: [],
210
- removed: blueprints ?? [],
211
- },
212
- objects: {
213
- added: [],
214
- removed: objects ?? [],
215
- },
216
- }),
217
- ]);
270
+ await Runtime.runPromise(this._runtime)(
271
+ Feed.append(this._feed, [
272
+ Obj.make(ContextBinding, {
273
+ blueprints: {
274
+ added: [],
275
+ removed: blueprints ?? [],
276
+ },
277
+ objects: {
278
+ added: [],
279
+ removed: objects ?? [],
280
+ },
281
+ }),
282
+ ]),
283
+ );
218
284
  }
219
285
 
220
286
  /**
@@ -274,10 +340,26 @@ export class AiContextBinder extends Resource {
274
340
  );
275
341
  }
276
342
 
343
+ /**
344
+ * Merge resolved items into the current set, adding only items not already present (by DXN).
345
+ */
346
+ private _mergeInto<T extends Obj.Unknown>(current: T[], resolved: T[]): T[] {
347
+ const seen = new Set(current.map((obj) => Obj.getDXN(obj).toString()));
348
+ const merged = [...current];
349
+ for (const obj of resolved) {
350
+ const dxn = Obj.getDXN(obj).toString();
351
+ if (!seen.has(dxn)) {
352
+ seen.add(dxn);
353
+ merged.push(obj);
354
+ }
355
+ }
356
+ return merged;
357
+ }
358
+
277
359
  /**
278
360
  * Resolve references to objects, loading them first if needed and falling back to existing objects.
279
361
  */
280
- private async _resolve<T>(refs: Iterable<Ref.Ref<T>>, current: T[]): Promise<T[]> {
362
+ private async _resolve<T extends Obj.Unknown>(refs: Iterable<Ref.Ref<T>>, current: T[]): Promise<T[]> {
281
363
  const refArray = [...refs];
282
364
 
283
365
  // Load all refs that need loading.
@@ -294,7 +376,7 @@ export class AiContextBinder extends Resource {
294
376
  // Fallback to existing object.
295
377
  return target ?? current.find((obj) => Obj.getDXN(obj as any).toString() === ref.dxn.toString());
296
378
  })
297
- .filter(isTruthy);
379
+ .filter(isNonNullable);
298
380
  }
299
381
  }
300
382
 
@@ -318,13 +400,4 @@ export class AiContextService extends Context.Tag('@dxos/assistant/AiContextServ
318
400
  return binder.getObjects().filter(Obj.instanceOf(type));
319
401
  });
320
402
  };
321
-
322
- /**
323
- * Glorified type cast until we figure out function service typing.
324
- * For context, the AiContextService is provided to functions called from tool calls, but it's not implemented in types yet.
325
- * @deprecated
326
- */
327
- static fixFunctionHandlerType = <A, E, R>(
328
- eff: Effect.Effect<A, E, R>,
329
- ): Effect.Effect<A, E, Exclude<R, AiContextService>> => eff as any;
330
403
  }
@@ -3,4 +3,4 @@
3
3
  //
4
4
 
5
5
  export * from './context';
6
- export * from './conversation';
6
+ export * from './session';