@dxos/assistant 0.8.4-main.bc674ce → 0.8.4-main.bcb3aa67d6

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 (121) hide show
  1. package/README.md +1 -0
  2. package/dist/lib/neutral/chunk-KVYJFFLF.mjs +1805 -0
  3. package/dist/lib/neutral/chunk-KVYJFFLF.mjs.map +7 -0
  4. package/dist/lib/{browser → neutral}/extraction/index.mjs +26 -32
  5. package/dist/lib/neutral/extraction/index.mjs.map +7 -0
  6. package/dist/lib/{browser → neutral}/index.mjs +72 -371
  7. package/dist/lib/neutral/index.mjs.map +7 -0
  8. package/dist/lib/neutral/meta.json +1 -0
  9. package/dist/lib/neutral/testing/index.mjs +112 -0
  10. package/dist/lib/neutral/testing/index.mjs.map +7 -0
  11. package/dist/types/src/conversation/context.d.ts +24 -5
  12. package/dist/types/src/conversation/context.d.ts.map +1 -1
  13. package/dist/types/src/conversation/conversation.d.ts +29 -4
  14. package/dist/types/src/conversation/conversation.d.ts.map +1 -1
  15. package/dist/types/src/diff.d.ts +3 -1
  16. package/dist/types/src/diff.d.ts.map +1 -1
  17. package/dist/types/src/extraction/extraction-ner-function/index.d.ts +0 -1
  18. package/dist/types/src/extraction/extraction-ner-function/index.d.ts.map +1 -1
  19. package/dist/types/src/extraction/extraction.d.ts +729 -17
  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/functions/services.d.ts +27 -8
  24. package/dist/types/src/functions/services.d.ts.map +1 -1
  25. package/dist/types/src/index.d.ts +2 -0
  26. package/dist/types/src/index.d.ts.map +1 -1
  27. package/dist/types/src/service/AgentService.d.ts +62 -0
  28. package/dist/types/src/service/AgentService.d.ts.map +1 -0
  29. package/dist/types/src/service/AgentService.test.d.ts +2 -0
  30. package/dist/types/src/service/AgentService.test.d.ts.map +1 -0
  31. package/dist/types/src/service/agent-process.d.ts +17 -0
  32. package/dist/types/src/service/agent-process.d.ts.map +1 -0
  33. package/dist/types/src/service/index.d.ts +3 -0
  34. package/dist/types/src/service/index.d.ts.map +1 -0
  35. package/dist/types/src/session/index.d.ts +1 -1
  36. package/dist/types/src/session/index.d.ts.map +1 -1
  37. package/dist/types/src/session/observer.d.ts.map +1 -1
  38. package/dist/types/src/session/session.d.ts +64 -8
  39. package/dist/types/src/session/session.d.ts.map +1 -1
  40. package/dist/types/src/session/toolkit.d.ts +6 -2
  41. package/dist/types/src/session/toolkit.d.ts.map +1 -1
  42. package/dist/types/src/templates/system.d.ts +0 -1
  43. package/dist/types/src/templates/system.d.ts.map +1 -1
  44. package/dist/types/src/testing/layer.d.ts +23 -9
  45. package/dist/types/src/testing/layer.d.ts.map +1 -1
  46. package/dist/types/src/tracing.d.ts +264 -0
  47. package/dist/types/src/tracing.d.ts.map +1 -0
  48. package/dist/types/src/types/artifact.d.ts +5 -5
  49. package/dist/types/src/types/artifact.d.ts.map +1 -1
  50. package/dist/types/tsconfig.tsbuildinfo +1 -1
  51. package/package.json +33 -33
  52. package/src/conversation/context.test.ts +1 -1
  53. package/src/conversation/context.ts +84 -18
  54. package/src/conversation/conversation.ts +173 -32
  55. package/src/diff.test.ts +36 -5
  56. package/src/diff.ts +13 -4
  57. package/src/execution-graph.test.ts +2 -2
  58. package/src/execution-graph.ts +2 -2
  59. package/src/extraction/extraction-ner-function/index.ts +0 -1
  60. package/src/extraction/extraction.ts +38 -10
  61. package/src/extraction/index.ts +0 -1
  62. package/src/functions/services.ts +199 -50
  63. package/src/functions.conversations.json +1 -1
  64. package/src/functions.test.ts +28 -20
  65. package/src/index.ts +2 -0
  66. package/src/service/AgentService.conversations.json +1 -0
  67. package/src/service/AgentService.test.ts +169 -0
  68. package/src/service/AgentService.ts +171 -0
  69. package/src/service/agent-process.ts +360 -0
  70. package/src/service/index.ts +6 -0
  71. package/src/session/format.test.ts +23 -14
  72. package/src/session/index.ts +1 -2
  73. package/src/session/observer.ts +3 -2
  74. package/src/session/session.conversations.json +1 -1
  75. package/src/session/session.test.ts +52 -4
  76. package/src/session/session.ts +231 -117
  77. package/src/session/toolkit.ts +12 -7
  78. package/src/templates/instructions/format.tpl +0 -4
  79. package/src/templates/instructions/system.tpl +11 -2
  80. package/src/templates/system.ts +6 -5
  81. package/src/testing/layer.ts +209 -24
  82. package/src/tracing.ts +112 -0
  83. package/src/types/artifact.ts +17 -10
  84. package/dist/lib/browser/chunk-7CDDG6LL.mjs +0 -578
  85. package/dist/lib/browser/chunk-7CDDG6LL.mjs.map +0 -7
  86. package/dist/lib/browser/extraction/index.mjs.map +0 -7
  87. package/dist/lib/browser/index.mjs.map +0 -7
  88. package/dist/lib/browser/meta.json +0 -1
  89. package/dist/lib/browser/testing/index.mjs +0 -32
  90. package/dist/lib/browser/testing/index.mjs.map +0 -7
  91. package/dist/lib/node-esm/chunk-CC7ER6Q3.mjs +0 -579
  92. package/dist/lib/node-esm/chunk-CC7ER6Q3.mjs.map +0 -7
  93. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +0 -11
  94. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +0 -7
  95. package/dist/lib/node-esm/extraction/index.mjs +0 -226
  96. package/dist/lib/node-esm/extraction/index.mjs.map +0 -7
  97. package/dist/lib/node-esm/index.mjs +0 -851
  98. package/dist/lib/node-esm/index.mjs.map +0 -7
  99. package/dist/lib/node-esm/meta.json +0 -1
  100. package/dist/lib/node-esm/testing/index.mjs +0 -33
  101. package/dist/lib/node-esm/testing/index.mjs.map +0 -7
  102. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts +0 -4
  103. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts.map +0 -1
  104. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.test.d.ts +0 -2
  105. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.test.d.ts.map +0 -1
  106. package/dist/types/src/extraction/extraction-llm-function/index.d.ts +0 -2
  107. package/dist/types/src/extraction/extraction-llm-function/index.d.ts.map +0 -1
  108. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts +0 -347
  109. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts.map +0 -1
  110. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.test.d.ts +0 -2
  111. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.test.d.ts.map +0 -1
  112. package/dist/types/src/session/GenericToolkit.d.ts +0 -85
  113. package/dist/types/src/session/GenericToolkit.d.ts.map +0 -1
  114. package/src/extraction/extraction-llm-function/extraction-llm-function.test.ts +0 -84
  115. package/src/extraction/extraction-llm-function/extraction-llm-function.ts +0 -62
  116. package/src/extraction/extraction-llm-function/index.ts +0 -5
  117. package/src/extraction/extraction-ner-function/extraction-ner-function.test.ts +0 -116
  118. package/src/extraction/extraction-ner-function/extraction-ner-function.ts +0 -56
  119. package/src/session/GenericToolkit.ts +0 -131
  120. /package/dist/lib/{browser → neutral}/chunk-J5LGTIGS.mjs +0 -0
  121. /package/dist/lib/{browser → neutral}/chunk-J5LGTIGS.mjs.map +0 -0
@@ -1,369 +1,49 @@
1
1
  import {
2
+ AGENT_PROCESS_KEY,
3
+ AgentInputReceived,
4
+ AgentRequestCompleted,
5
+ AgentService_exports,
6
+ AgentTurnCompleted,
7
+ AgentTurnStarted,
2
8
  AiAssistantError,
9
+ AiContextBinder,
10
+ AiContextService,
11
+ AiConversation,
12
+ AiConversationService,
3
13
  AiModelError,
4
14
  AiSession,
5
15
  ArtifactDiffResolver,
6
16
  ArtifactId,
17
+ Bindings,
18
+ CompleteBlock,
19
+ ContextBinding,
7
20
  GenerationObserver,
8
- GenericToolkit_exports,
21
+ PartialBlock,
9
22
  RefFromLLM,
23
+ ToolCallCompleted,
24
+ ToolCallStarted,
25
+ ToolExecutionServices,
10
26
  VersionPin,
11
27
  createArtifactElement,
12
28
  createToolkit,
29
+ formatSystemPrompt,
30
+ formatUserPrompt,
31
+ functionInvocationServiceFromOperations,
32
+ getOperationFromTool,
33
+ makeToolExecutionService,
13
34
  makeToolExecutionServiceFromFunctions,
14
- makeToolResolverFromFunctions
15
- } from "./chunk-7CDDG6LL.mjs";
35
+ makeToolExecutionServiceFromOperationInvoker,
36
+ makeToolResolverFromFunctions,
37
+ makeToolResolverFromOperations
38
+ } from "./chunk-KVYJFFLF.mjs";
16
39
  import "./chunk-J5LGTIGS.mjs";
17
40
 
18
- // src/conversation/context.ts
19
- import { Atom, Registry } from "@effect-atom/atom-react";
20
- import * as EArray from "effect/Array";
21
- import * as Context from "effect/Context";
22
- import * as Function from "effect/Function";
23
- import * as Schema from "effect/Schema";
24
- import { Blueprint } from "@dxos/blueprints";
25
- import { Resource } from "@dxos/context";
26
- import { DXN, Obj, Query, Type } from "@dxos/echo";
27
- import { log } from "@dxos/log";
28
- import { ComplexSet, isTruthy } from "@dxos/util";
29
- var __dxlog_file = "/__w/dxos/dxos/packages/core/assistant/src/conversation/context.ts";
30
- var ContextBinding = Schema.Struct({
31
- blueprints: Schema.Struct({
32
- added: Schema.Array(Type.Ref(Blueprint.Blueprint)),
33
- removed: Schema.Array(Type.Ref(Blueprint.Blueprint))
34
- }),
35
- objects: Schema.Struct({
36
- added: Schema.Array(Type.Ref(Type.Obj)),
37
- removed: Schema.Array(Type.Ref(Type.Obj))
38
- })
39
- }).pipe(Type.object({
40
- typename: "dxos.org/type/ContextBinding",
41
- version: "0.1.0"
42
- }));
43
- var Bindings = class {
44
- blueprints = new ComplexSet((ref) => ref.dxn.toString());
45
- // TODO(burdon): Some DXNs have the Space prefix so only compare the object ID.
46
- objects = new ComplexSet((ref) => ref.dxn.asEchoDXN()?.echoId);
47
- toJSON() {
48
- return {
49
- blueprints: EArray.fromIterable(this.blueprints).map((ref) => ref.dxn.toString()),
50
- objects: EArray.fromIterable(this.objects).map((ref) => ref.dxn.toString())
51
- };
52
- }
53
- };
54
- var AiContextBinder = class extends Resource {
55
- _blueprints = Atom.make([]).pipe(Atom.keepAlive);
56
- _objects = Atom.make([]).pipe(Atom.keepAlive);
57
- _registry;
58
- _queue;
59
- constructor(options) {
60
- super();
61
- this._queue = options.queue;
62
- this._registry = options.registry ?? Registry.make();
63
- }
64
- /**
65
- * Returns the blueprints atom for subscription.
66
- */
67
- get blueprints() {
68
- return this._blueprints;
69
- }
70
- /**
71
- * Returns the objects atom for subscription.
72
- */
73
- get objects() {
74
- return this._objects;
75
- }
76
- /**
77
- * Gets the current blueprints value.
78
- */
79
- getBlueprints() {
80
- return this._registry.get(this._blueprints);
81
- }
82
- /**
83
- * Gets the current objects value.
84
- */
85
- getObjects() {
86
- return this._registry.get(this._objects);
87
- }
88
- /**
89
- * Subscribe to changes in blueprints.
90
- */
91
- subscribeBlueprints(cb) {
92
- return this._registry.subscribe(this._blueprints, () => cb(this._registry.get(this._blueprints)));
93
- }
94
- /**
95
- * Subscribe to changes in objects.
96
- */
97
- subscribeObjects(cb) {
98
- return this._registry.subscribe(this._objects, () => cb(this._registry.get(this._objects)));
99
- }
100
- async _open() {
101
- const query = this._queue.query(Query.type(ContextBinding));
102
- const initialResults = await query.run();
103
- await this._updateBindings(initialResults);
104
- this._ctx.onDispose(query.subscribe(async () => {
105
- await this._updateBindings(query.results);
106
- }));
107
- }
108
- async _updateBindings(items) {
109
- if (items.length === 0) {
110
- return;
111
- }
112
- const bindings = this._reduce(items);
113
- const currentBlueprints = this._registry.get(this._blueprints);
114
- const currentObjects = this._registry.get(this._objects);
115
- const newBlueprints = await this._resolve(bindings.blueprints, currentBlueprints);
116
- const newObjects = await this._resolve(bindings.objects, currentObjects);
117
- this._registry.set(this._blueprints, newBlueprints);
118
- this._registry.set(this._objects, newObjects);
119
- log("updated bindings", {
120
- blueprints: newBlueprints.length,
121
- objects: newObjects.length
122
- }, {
123
- F: __dxlog_file,
124
- L: 156,
125
- S: this,
126
- C: (f, a) => f(...a)
127
- });
128
- }
129
- async _close() {
130
- this._registry.set(this._blueprints, []);
131
- this._registry.set(this._objects, []);
132
- }
133
- async bind({ blueprints, objects }) {
134
- const currentBlueprints = this._registry.get(this._blueprints);
135
- const currentObjects = this._registry.get(this._objects);
136
- const { added: addedBlueprints, next: nextBlueprints } = this._processBindings(blueprints, currentBlueprints);
137
- const { added: addedObjects, next: nextObjects } = this._processBindings(objects, currentObjects);
138
- if (!addedBlueprints.length && !addedObjects.length) {
139
- return;
140
- }
141
- this._registry.set(this._blueprints, nextBlueprints);
142
- this._registry.set(this._objects, nextObjects);
143
- log("bind", {
144
- blueprints: addedBlueprints.length,
145
- objects: addedObjects.length
146
- }, {
147
- F: __dxlog_file,
148
- L: 182,
149
- S: this,
150
- C: (f, a) => f(...a)
151
- });
152
- await this._queue.append([
153
- Obj.make(ContextBinding, {
154
- blueprints: {
155
- added: addedBlueprints,
156
- removed: []
157
- },
158
- objects: {
159
- added: addedObjects,
160
- removed: []
161
- }
162
- })
163
- ]);
164
- }
165
- async unbind({ blueprints, objects }) {
166
- if (!blueprints?.length && !objects?.length) {
167
- return;
168
- }
169
- log("unbind", {
170
- blueprints: blueprints?.length,
171
- objects: objects?.length
172
- }, {
173
- F: __dxlog_file,
174
- L: 202,
175
- S: this,
176
- C: (f, a) => f(...a)
177
- });
178
- await this._queue.append([
179
- Obj.make(ContextBinding, {
180
- blueprints: {
181
- added: [],
182
- removed: blueprints ?? []
183
- },
184
- objects: {
185
- added: [],
186
- removed: objects ?? []
187
- }
188
- })
189
- ]);
190
- }
191
- /**
192
- * Process bindings to filter duplicates and determine next state.
193
- */
194
- _processBindings(refs, current) {
195
- const next = [
196
- ...current
197
- ];
198
- const added = [];
199
- if (!refs?.length) {
200
- return {
201
- added,
202
- next
203
- };
204
- }
205
- const seen = new Set(current.map((obj) => Obj.getDXN(obj).toString()));
206
- for (const ref of refs) {
207
- const dxn = ref.dxn.toString();
208
- if (!seen.has(dxn)) {
209
- seen.add(dxn);
210
- added.push(ref);
211
- if (ref.isAvailable) {
212
- const target = ref.target;
213
- if (target) {
214
- next.push(target);
215
- }
216
- }
217
- }
218
- }
219
- return {
220
- added,
221
- next
222
- };
223
- }
224
- /**
225
- * Reduce results into sets of blueprints and objects.
226
- */
227
- _reduce(items) {
228
- return Function.pipe(items, EArray.reduce(new Bindings(), (context, { blueprints, objects }) => {
229
- blueprints.added.forEach((ref) => context.blueprints.add(ref));
230
- blueprints.removed.forEach((ref) => context.blueprints.delete(ref));
231
- objects.added.forEach((ref) => context.objects.add(ref));
232
- objects.removed.forEach((ref) => {
233
- for (const obj of context.objects) {
234
- if (DXN.equalsEchoId(obj.dxn, ref.dxn)) {
235
- context.objects.delete(obj);
236
- }
237
- }
238
- });
239
- return context;
240
- }));
241
- }
242
- /**
243
- * Resolve references to objects, loading them first if needed and falling back to existing objects.
244
- */
245
- async _resolve(refs, current) {
246
- const refArray = [
247
- ...refs
248
- ];
249
- await Promise.all(refArray.map((ref) => ref.load()));
250
- return refArray.map((ref) => {
251
- let target;
252
- if (ref.isAvailable) {
253
- target = ref.target;
254
- }
255
- return target ?? current.find((obj) => Obj.getDXN(obj).toString() === ref.dxn.toString());
256
- }).filter(isTruthy);
257
- }
258
- };
259
- var AiContextService = class extends Context.Tag("@dxos/assistant/AiContextService")() {
260
- };
261
-
262
- // src/conversation/conversation.ts
263
- import * as Effect from "effect/Effect";
264
- import { Resource as Resource2 } from "@dxos/context";
265
- import { Obj as Obj2 } from "@dxos/echo";
266
- import { invariant } from "@dxos/invariant";
267
- import { log as log2 } from "@dxos/log";
268
- import { Message } from "@dxos/types";
269
- var __dxlog_file2 = "/__w/dxos/dxos/packages/core/assistant/src/conversation/conversation.ts";
270
- var AiConversation = class extends Resource2 {
271
- /**
272
- * Blueprints and objects bound to the conversation.
273
- */
274
- _binder;
275
- _queue;
276
- _toolkit;
277
- constructor(options) {
278
- super();
279
- this._queue = options.queue;
280
- this._toolkit = options.toolkit;
281
- invariant(this._queue, void 0, {
282
- F: __dxlog_file2,
283
- L: 54,
284
- S: this,
285
- A: [
286
- "this._queue",
287
- ""
288
- ]
289
- });
290
- this._binder = new AiContextBinder({
291
- queue: this._queue,
292
- registry: options.registry
293
- });
294
- }
295
- async _open() {
296
- await this._binder.open(this._ctx);
297
- }
298
- get queue() {
299
- return this._queue;
300
- }
301
- get context() {
302
- return this._binder;
303
- }
304
- get toolkit() {
305
- return this._toolkit;
306
- }
307
- async getHistory() {
308
- const queueItems = await this._queue.queryObjects();
309
- return queueItems.filter(Obj2.instanceOf(Message.Message));
310
- }
311
- /**
312
- * Creates a new cancelable request effect.
313
- */
314
- createRequest(params) {
315
- const self = this;
316
- return Effect.gen(function* () {
317
- const history = yield* Effect.promise(() => self.getHistory());
318
- const blueprints = self.context.getBlueprints();
319
- const toolkit = yield* createToolkit({
320
- toolkit: self._toolkit,
321
- blueprints
322
- });
323
- const objects = self.context.getObjects();
324
- log2("run", {
325
- history: history.length,
326
- blueprints: blueprints.length,
327
- tools: Object.keys(toolkit.tools).length,
328
- objects: objects.length
329
- }, {
330
- F: __dxlog_file2,
331
- L: 99,
332
- S: this,
333
- C: (f, a) => f(...a)
334
- });
335
- const session = new AiSession();
336
- const messages = yield* session.run({
337
- history,
338
- blueprints,
339
- toolkit,
340
- objects,
341
- ...params
342
- }).pipe(Effect.provideService(AiContextService, {
343
- binder: self.context
344
- }));
345
- log2("result", {
346
- messages: messages.length,
347
- duration: session.duration,
348
- toolCalls: session.toolCalls
349
- }, {
350
- F: __dxlog_file2,
351
- L: 114,
352
- S: this,
353
- C: (f, a) => f(...a)
354
- });
355
- yield* Effect.promise(() => self._queue.append(messages));
356
- return messages;
357
- });
358
- }
359
- };
360
-
361
41
  // src/diff.ts
362
42
  import { next as A } from "@automerge/automerge";
363
43
  import { DocAccessor, toCursorRange } from "@dxos/echo-db";
364
- import { log as log3 } from "@dxos/log";
44
+ import { log } from "@dxos/log";
365
45
  import { isNonNullable } from "@dxos/util";
366
- var __dxlog_file3 = "/__w/dxos/dxos/packages/core/assistant/src/diff.ts";
46
+ var __dxlog_file = "/__w/dxos/dxos/packages/core/assistant/src/diff.ts";
367
47
  var reduceDiffs = (diffs) => {
368
48
  return diffs.reduce((acc, diff) => {
369
49
  const current = acc[acc.length - 1];
@@ -391,8 +71,10 @@ var reduceDiffs = (diffs) => {
391
71
  }
392
72
  return acc;
393
73
  }
74
+ default: {
75
+ throw new Error(`Invalid diff format: each line must start with "- " or "+ ", got: ${JSON.stringify(diff)}`);
76
+ }
394
77
  }
395
- return acc;
396
78
  }, []);
397
79
  };
398
80
  var computeDiffsWithCursors = (accessor, diffs) => {
@@ -407,7 +89,7 @@ var computeDiffsWithCursors = (accessor, diffs) => {
407
89
  }
408
90
  }).filter(isNonNullable);
409
91
  };
410
- var applyDiffs = (accessor, diffs) => {
92
+ var applyDiffs = (accessor, diffs, { errorOnNotFound = false } = {}) => {
411
93
  for (const diff of reduceDiffs(diffs)) {
412
94
  accessor.handle.change((doc) => {
413
95
  const text = DocAccessor.getValue(accessor);
@@ -415,12 +97,16 @@ var applyDiffs = (accessor, diffs) => {
415
97
  if (idx !== -1) {
416
98
  A.splice(doc, accessor.path, idx, diff.match.length, diff.replace);
417
99
  } else {
418
- log3.warn("diff not found", diff, {
419
- F: __dxlog_file3,
420
- L: 78,
421
- S: void 0,
422
- C: (f, a) => f(...a)
423
- });
100
+ if (errorOnNotFound) {
101
+ throw new Error(`Diff not found: ${diff.match}`);
102
+ } else {
103
+ log.warn("diff not found", diff, {
104
+ F: __dxlog_file,
105
+ L: 86,
106
+ S: void 0,
107
+ C: (f, a) => f(...a)
108
+ });
109
+ }
424
110
  }
425
111
  });
426
112
  }
@@ -429,10 +115,10 @@ var applyDiffs = (accessor, diffs) => {
429
115
 
430
116
  // src/execution-graph.ts
431
117
  import { AgentStatus } from "@dxos/ai";
432
- import { Obj as Obj3 } from "@dxos/echo";
118
+ import { Obj } from "@dxos/echo";
433
119
  import { MESSAGE_PROPERTY_TOOL_CALL_ID } from "@dxos/functions";
434
120
  import { LogLevel } from "@dxos/log";
435
- import { ContentBlock, Message as Message2 } from "@dxos/types";
121
+ import { ContentBlock, Message } from "@dxos/types";
436
122
  import { isNonNullable as isNonNullable2 } from "@dxos/util";
437
123
  var SKIP_BLOCKS = [
438
124
  "text"
@@ -456,9 +142,9 @@ var ExecutionGraph = class {
456
142
  addEvents(events) {
457
143
  const sortedEvents = this.sortObjectsByCreated(events);
458
144
  for (const event of sortedEvents) {
459
- if (Obj3.instanceOf(Message2.Message, event)) {
145
+ if (Obj.instanceOf(Message.Message, event)) {
460
146
  this._processMessage(event);
461
- } else if (Obj3.instanceOf(AgentStatus, event)) {
147
+ } else if (Obj.instanceOf(AgentStatus, event)) {
462
148
  this._processAgentStatus(event);
463
149
  }
464
150
  }
@@ -716,7 +402,7 @@ var createBlockCommit = (block, message, branch, parents, idx) => {
716
402
  level: block.error ? LogLevel.ERROR : LogLevel.INFO,
717
403
  message: block.error ? "Tool error: " + block.error : "Tool call succeeded"
718
404
  };
719
- case "summary":
405
+ case "stats":
720
406
  return {
721
407
  id: getGenericBlockId(message.id, idx),
722
408
  branch,
@@ -724,7 +410,7 @@ var createBlockCommit = (block, message, branch, parents, idx) => {
724
410
  timestamp,
725
411
  icon: "ph--rocket--regular",
726
412
  level: LogLevel.INFO,
727
- message: ContentBlock.createSummaryMessage(block)
413
+ message: ContentBlock.createStatsMessage(block)
728
414
  };
729
415
  case "status":
730
416
  return {
@@ -794,7 +480,7 @@ var stringifyRef = (ref) => {
794
480
  return ref.dxn.asEchoDXN()?.echoId ?? ref.dxn.asQueueDXN()?.objectId ?? "";
795
481
  };
796
482
  var stringifyObject = (obj) => {
797
- return Obj3.getLabel(obj) ?? Obj3.getTypename(obj) ?? obj.id;
483
+ return Obj.getLabel(obj) ?? Obj.getTypename(obj) ?? obj.id;
798
484
  };
799
485
 
800
486
  // src/templates/system.ts
@@ -802,48 +488,63 @@ import defaultsDeep from "lodash.defaultsdeep";
802
488
  import { Template } from "@dxos/blueprints";
803
489
 
804
490
  // raw-loader:/__w/dxos/dxos/packages/core/assistant/src/templates/instructions/format.tpl?raw
805
- var format_default = "{{! System Core }}\n\n## Input Formats\n\n### Blueprints\n\nYou may be provided with Blueprint definitions that include specific instructions and tools for a given set of tasks.\nBlue print instructions will be enclosed in a <blueprint> tag.\n\n### Context objects\n\nYou may be provided with references to objects that are relevant to the current prompt.\nObjects 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.\nThe <typename> element is the type of the object.\n\n<object>\n <dxn>object-id</dxn>\n <typename>example.com/type/TypeName</typename>\n</object>\n\n## Response Formats\n\nIt is very important to respond in the correct format.\nYou response must be valid Markdown.\nIn some cases you should respond with well-formed XML tags along with the content.\nCode snippets should use 2-space indents.\n\n{{#if cot}}\nBefore responding, explain your reasoning and include your detailed chain-of-thought enclosed in a <cot> tag.\nThe <cot> tag should be the first thing in your response.\n{{/if}}\n\n## Block references\n\nYou can reply with a block reference for objects if you have the DXN. For example:\n\n<object>\n <dxn>dxn:queue:data:B6INSIBY3CBEF4M5VZRYBCMAHQMPYK5AJ:01K24XMVHSZHS97SG1VTVQDM5Z:01K24XPK464FSCKVQJAB2H662M</dxn>\n</object>\n<object>\n <dxn>dxn:echo:@:01K24XPK464FSCKVQJAB2H662M</dxn>\n</object>\n\n### Suggestions\n\nEach suggestion must in the form of a proposed action enclosed in a <suggestion> tag.\nExample: <suggestion>Show on a map</suggestion>\nDo not use bullets when listing suggestions.\n\n### Multiple choice questions\n\nYou may ask multiple choice questions by wrapping consise options inside <option> tags inside a well formed <select> tag.\nExample: <select><option>Yes</option><option>No</option></select>\n\n## Toolkit\n\nIf the user asks for a list of tools, then just emit a single self-closing <toolkit/> tag instead of listing the tools.\n\n## Context\n\nThe current date and time is {{DATETIME}}.\n";
491
+ var format_default = "{{! System Core }}\n\n## Input Formats\n\n### Blueprints\n\nYou may be provided with Blueprint definitions that include specific instructions and tools for a given set of tasks.\nBlue print instructions will be enclosed in a <blueprint> tag.\n\n### Context objects\n\nYou may be provided with references to objects that are relevant to the current prompt.\nObjects 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.\nThe <typename> element is the type of the object.\n\n<object>\n <dxn>object-id</dxn>\n <typename>example.com/type/TypeName</typename>\n</object>\n\n## Response Formats\n\nIt is very important to respond in the correct format.\nYou response must be valid Markdown.\nIn some cases you should respond with well-formed XML tags along with the content.\nCode snippets should use 2-space indents.\n\n{{#if cot}}\nBefore responding, explain your reasoning and include your detailed chain-of-thought enclosed in a <cot> tag.\nThe <cot> tag should be the first thing in your response.\n{{/if}}\n\n## Block references\n\nYou can reply with a block reference for objects if you have the DXN. For example:\n\n<object>\n <dxn>dxn:queue:data:B6INSIBY3CBEF4M5VZRYBCMAHQMPYK5AJ:01K24XMVHSZHS97SG1VTVQDM5Z:01K24XPK464FSCKVQJAB2H662M</dxn>\n</object>\n<object>\n <dxn>dxn:echo:@:01K24XPK464FSCKVQJAB2H662M</dxn>\n</object>\n\n### Suggestions\n\nEach suggestion must in the form of a proposed action enclosed in a <suggestion> tag.\nExample: <suggestion>Show on a map</suggestion>\nDo not use bullets when listing suggestions.\n\n### Multiple choice questions\n\nYou may ask multiple choice questions by wrapping consise options inside <option> tags inside a well formed <select> tag.\nExample: <select><option>Yes</option><option>No</option></select>\n\n## Context\n\nThe current date and time is {{DATETIME}}.\n";
806
492
 
807
493
  // raw-loader:/__w/dxos/dxos/packages/core/assistant/src/templates/instructions/system.tpl?raw
808
- var system_default = "{{! System Prompt }}\n\n- You are a helpful assistant called Kai. \n- Your name is Kai and you are powered by different language models.\n- You were created by DXOS and operate inside of Composer and on the DXOS EDGE network.\n- In your initial greeting state your name and make some suggestions based on the current context objects.\n- You are an advanced AI assistant capable of creating and managing artifacts from provided data and tools.\n- Your task is to process user commands and questions and decide how best to respond.\n- In general be concise and direct.\n- Follow all instructions carefully.\n\n## Planning\n\n- Analyze the structure and type of the content in the user's message.\n- Determine if you complete the task using the available blueprint definitions?\n- If you can't complete the task using the available blueprint definitions, query the list of available blueprint definitions using the appropriate tool.\n- Identify which blueprint definitions are relevant to the user's request.\n- Evaluate the potential benefits of creating an artifact vs. normal processing for each identified element.\n- Make a final decision on whether to create an artifact and explain your reasoning.\n- Are the required blueprint definitions already available?\n- If not, select which blueprint definition(s) will be the most relevant and require them using the require_artifact_definitions tool.\n- The require'd artifact tools will be available for use after require.\n- If creating an artifact, outline how you will structure it within the response.\n- Decide if the artifact needs to be shown to the user.\n- Call the show tool to show the artifact to the user.\n- 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.\n\n## Blueprints and Artifacts\n\n- Determine if the interaction involves an artifact. Prefer artifacts for tables, lists, spreadsheets, kanbans, games, images, and other structured data.\n- Determine if the user is explicitly talking about creating a new artifact, or wants to use an existing artifact.\n- If it is ambiguous, query for existing artifacts first and then decide.\n- If you decide to create an artifact, call the associated tool to create the artifact.\n- Artifacts are stored in the database. Tools are used to create and query artifacts.\n- If you are unsure about creating an artifact ask the user for clarification.\n- Artifacts are mutable objects that can change over the course of the conversation.\n- Always re-query the artifact using the tool (like query or inspect) to get the latest state of the artifact before answering the user.\n- You must never generate the id of the artifact; only recall the ids that are already in the history.\n- Artifacts are created by requiring the specific artifact using the require_artifact tool and creating it by calling the associated tool.\n- You can add suggested actions at the end of your response.\n- 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.\n- Suggested actions must be in the form of a user instruction that you can follow.\n- Suggested actions could include actions that create artifacts.\n- After creating an artifact use a tool to add it to the chat context.\n\n## Context\n\nToday is {{DATETIME}}.\n";
494
+ var system_default = "{{! System Prompt }}\n\n- You are a helpful assistant called Kai. \n- Your name is Kai and you are powered by different language models.\n- You were created by DXOS and operate inside of Composer and on the DXOS EDGE network.\n- In your initial greeting state your name and make some suggestions based on the current context objects.\n- You are an advanced AI assistant capable of creating and managing artifacts from provided data and tools.\n- Your task is to process user commands and questions and decide how best to respond.\n- In general be concise and direct.\n- Follow all instructions carefully.\n\n## Planning\n\n- Analyze the structure and type of the content in the user's message.\n- Determine if you complete the task using the available blueprint definitions?\n- If you can't complete the task using the available blueprint definitions, query the list of available blueprint definitions using the appropriate tool.\n- Identify which blueprint definitions are relevant to the user's request.\n- Evaluate the potential benefits of creating an artifact vs. normal processing for each identified element.\n- Make a final decision on whether to create an artifact and explain your reasoning.\n- Are the required blueprint definitions already available?\n- If not, select which blueprint definition(s) will be the most relevant and require them using the require_artifact_definitions tool.\n- The require'd artifact tools will be available for use after require.\n- If creating an artifact, outline how you will structure it within the response.\n- Decide if the artifact needs to be shown to the user.\n- Call the show tool to show the artifact to the user.\n- 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.\n\n## Blueprints and Artifacts\n\n- Determine if the interaction involves an artifact. Prefer artifacts for tables, lists, spreadsheets, kanbans, games, images, and other structured data.\n- Determine if the user is explicitly talking about creating a new artifact, or wants to use an existing artifact.\n- If it is ambiguous, query for existing artifacts first and then decide.\n- If you decide to create an artifact, call the associated tool to create the artifact.\n- Artifacts are stored in the database. Tools are used to create and query artifacts.\n- If you are unsure about creating an artifact ask the user for clarification.\n- Artifacts are mutable objects that can change over the course of the conversation.\n- Always re-query the artifact using the tool (like query or inspect) to get the latest state of the artifact before answering the user.\n- You must never generate the id of the artifact; only recall the ids that are already in the history.\n- Artifacts are created by requiring the specific artifact using the require_artifact tool and creating it by calling the associated tool.\n- You can add suggested actions at the end of your response.\n- 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.\n- Suggested actions must be in the form of a user instruction that you can follow.\n- Suggested actions could include actions that create artifacts.\n- After creating an artifact use a tool to add it to the chat context.\n\n## Navigation\n\n- 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.\n- First, call the Resolve navigation targets tool to find the navigation path for the requested item.\n - Without arguments, it returns available pages that can be navigated to.\n - With a DXN in the query, it resolves that specific object to a navigation path.\n- 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.\n- Then, call the Open tool with the resolved navigation path(s) in the subject array to navigate the user to that item.\n- Do not respond with the document's content when the user asks to open it \u2014 open it in the main content area instead.\n- If multiple targets match, present the options to the user and let them choose which to open.\n\n## Context\n";
809
495
 
810
496
  // src/templates/system.ts
811
497
  var createSystemPrompt = (options = {}) => Template.process(format_default, defaultsDeep(options, {
812
498
  DATETIME: (/* @__PURE__ */ new Date()).toISOString()
813
499
  }));
500
+ var SYSTEM_ID = "01K2J2FZWH39F55CS7B26GP1Q3";
814
501
  var templates = {
815
- /** Editable system prompt.*/
816
502
  system: Template.make({
817
- /**
818
- * NOTE: We are forbidden from accessing randomness at model level in cloudflare, so we have to have pre-generated ids.
819
- */
820
- id: "01K2J2FZWH39F55CS7B26GP1Q3",
503
+ id: SYSTEM_ID,
821
504
  source: system_default
822
505
  })
823
506
  };
824
507
  export {
508
+ AGENT_PROCESS_KEY,
509
+ AgentInputReceived,
510
+ AgentRequestCompleted,
511
+ AgentService_exports as AgentService,
512
+ AgentTurnCompleted,
513
+ AgentTurnStarted,
825
514
  AiAssistantError,
826
515
  AiContextBinder,
827
516
  AiContextService,
828
517
  AiConversation,
518
+ AiConversationService,
829
519
  AiModelError,
830
520
  AiSession,
831
521
  ArtifactDiffResolver,
832
522
  ArtifactId,
833
523
  Bindings,
524
+ CompleteBlock,
834
525
  ContextBinding,
835
526
  ExecutionGraph,
836
527
  GenerationObserver,
837
- GenericToolkit_exports as GenericToolkit,
528
+ PartialBlock,
838
529
  RefFromLLM,
530
+ ToolCallCompleted,
531
+ ToolCallStarted,
532
+ ToolExecutionServices,
839
533
  VersionPin,
840
534
  applyDiffs,
841
535
  computeDiffsWithCursors,
842
536
  createArtifactElement,
843
537
  createSystemPrompt,
844
538
  createToolkit,
539
+ formatSystemPrompt,
540
+ formatUserPrompt,
541
+ functionInvocationServiceFromOperations,
542
+ getOperationFromTool,
543
+ makeToolExecutionService,
845
544
  makeToolExecutionServiceFromFunctions,
545
+ makeToolExecutionServiceFromOperationInvoker,
846
546
  makeToolResolverFromFunctions,
547
+ makeToolResolverFromOperations,
847
548
  reduceDiffs,
848
549
  templates
849
550
  };