@dxos/assistant-toolkit 0.8.4-main.3c1ae3b → 0.8.4-main.3eb6e50203

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 (217) hide show
  1. package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
  2. package/dist/lib/neutral/chunk-J5LGTIGS.mjs.map +7 -0
  3. package/dist/lib/{browser → neutral}/index.mjs +1393 -474
  4. package/dist/lib/neutral/index.mjs.map +7 -0
  5. package/dist/lib/neutral/meta.json +1 -0
  6. package/dist/lib/neutral/testing/index.mjs +44 -0
  7. package/dist/lib/neutral/testing/index.mjs.map +7 -0
  8. package/dist/types/src/blueprints/design/design-blueprint.d.ts +17 -3
  9. package/dist/types/src/blueprints/design/design-blueprint.d.ts.map +1 -1
  10. package/dist/types/src/blueprints/design/index.d.ts +1 -1
  11. package/dist/types/src/blueprints/design/index.d.ts.map +1 -1
  12. package/dist/types/src/blueprints/discord/discord-blueprint.d.ts +13 -14
  13. package/dist/types/src/blueprints/discord/discord-blueprint.d.ts.map +1 -1
  14. package/dist/types/src/blueprints/discord/index.d.ts +1 -1
  15. package/dist/types/src/blueprints/discord/index.d.ts.map +1 -1
  16. package/dist/types/src/blueprints/index.d.ts +1 -0
  17. package/dist/types/src/blueprints/index.d.ts.map +1 -1
  18. package/dist/types/src/blueprints/linear/index.d.ts +1 -1
  19. package/dist/types/src/blueprints/linear/index.d.ts.map +1 -1
  20. package/dist/types/src/blueprints/linear/linear-blueprint.d.ts +13 -14
  21. package/dist/types/src/blueprints/linear/linear-blueprint.d.ts.map +1 -1
  22. package/dist/types/src/blueprints/markdown/index.d.ts +3 -0
  23. package/dist/types/src/blueprints/markdown/index.d.ts.map +1 -0
  24. package/dist/types/src/blueprints/markdown/markdown-blueprint.d.ts +18 -0
  25. package/dist/types/src/blueprints/markdown/markdown-blueprint.d.ts.map +1 -0
  26. package/dist/types/src/blueprints/planning/index.d.ts +1 -1
  27. package/dist/types/src/blueprints/planning/index.d.ts.map +1 -1
  28. package/dist/types/src/blueprints/planning/planning-blueprint.d.ts +17 -3
  29. package/dist/types/src/blueprints/planning/planning-blueprint.d.ts.map +1 -1
  30. package/dist/types/src/blueprints/research/index.d.ts +1 -1
  31. package/dist/types/src/blueprints/research/index.d.ts.map +1 -1
  32. package/dist/types/src/blueprints/research/research-blueprint.d.ts +17 -3
  33. package/dist/types/src/blueprints/research/research-blueprint.d.ts.map +1 -1
  34. package/dist/types/src/blueprints/testing.d.ts +2 -4
  35. package/dist/types/src/blueprints/testing.d.ts.map +1 -1
  36. package/dist/types/src/blueprints/websearch/index.d.ts +1 -1
  37. package/dist/types/src/blueprints/websearch/index.d.ts.map +1 -1
  38. package/dist/types/src/blueprints/websearch/websearch-blueprint.d.ts +17 -3
  39. package/dist/types/src/blueprints/websearch/websearch-blueprint.d.ts.map +1 -1
  40. package/dist/types/src/chat/Chat.d.ts +31 -0
  41. package/dist/types/src/chat/Chat.d.ts.map +1 -0
  42. package/dist/types/src/chat/index.d.ts +2 -0
  43. package/dist/types/src/chat/index.d.ts.map +1 -0
  44. package/dist/types/src/crud/graph.d.ts +10 -8
  45. package/dist/types/src/crud/graph.d.ts.map +1 -1
  46. package/dist/types/src/functions/agent/prompt.d.ts +71 -4
  47. package/dist/types/src/functions/agent/prompt.d.ts.map +1 -1
  48. package/dist/types/src/functions/document/create.d.ts +6 -0
  49. package/dist/types/src/functions/document/create.d.ts.map +1 -0
  50. package/dist/types/src/functions/document/index.d.ts +20 -3
  51. package/dist/types/src/functions/document/index.d.ts.map +1 -1
  52. package/dist/types/src/functions/document/read.d.ts +8 -1
  53. package/dist/types/src/functions/document/read.d.ts.map +1 -1
  54. package/dist/types/src/functions/document/update.d.ts +8 -1
  55. package/dist/types/src/functions/document/update.d.ts.map +1 -1
  56. package/dist/types/src/functions/entity-extraction/entity-extraction.d.ts +120 -118
  57. package/dist/types/src/functions/entity-extraction/entity-extraction.d.ts.map +1 -1
  58. package/dist/types/src/functions/entity-extraction/index.d.ts +120 -118
  59. package/dist/types/src/functions/entity-extraction/index.d.ts.map +1 -1
  60. package/dist/types/src/functions/exa/data/exa-search-1748337321991.d.ts.map +1 -0
  61. package/dist/types/src/functions/exa/data/exa-search-1748337331526.d.ts.map +1 -0
  62. package/dist/types/src/functions/exa/data/exa-search-1748337344119.d.ts.map +1 -0
  63. package/dist/types/src/functions/exa/data/index.d.ts.map +1 -0
  64. package/dist/types/src/functions/github/fetch-prs.d.ts.map +1 -1
  65. package/dist/types/src/functions/linear/index.d.ts +1 -1
  66. package/dist/types/src/functions/linear/sync-issues.d.ts +1 -1
  67. package/dist/types/src/functions/linear/sync-issues.d.ts.map +1 -1
  68. package/dist/types/src/functions/research/document-create.d.ts +1 -1
  69. package/dist/types/src/functions/research/document-create.d.ts.map +1 -1
  70. package/dist/types/src/functions/research/index.d.ts +2 -2
  71. package/dist/types/src/functions/research/research-graph.d.ts +3 -3
  72. package/dist/types/src/functions/research/research-graph.d.ts.map +1 -1
  73. package/dist/types/src/functions/research/research.d.ts +1 -1
  74. package/dist/types/src/functions/research/research.d.ts.map +1 -1
  75. package/dist/types/src/functions/tasks/index.d.ts +16 -2
  76. package/dist/types/src/functions/tasks/index.d.ts.map +1 -1
  77. package/dist/types/src/functions/tasks/read.d.ts +8 -1
  78. package/dist/types/src/functions/tasks/read.d.ts.map +1 -1
  79. package/dist/types/src/functions/tasks/update.d.ts +8 -1
  80. package/dist/types/src/functions/tasks/update.d.ts.map +1 -1
  81. package/dist/types/src/index.d.ts +4 -2
  82. package/dist/types/src/index.d.ts.map +1 -1
  83. package/dist/types/src/initiative/Initiative.d.ts +41 -0
  84. package/dist/types/src/initiative/Initiative.d.ts.map +1 -0
  85. package/dist/types/src/initiative/blueprint.d.ts +153 -0
  86. package/dist/types/src/initiative/blueprint.d.ts.map +1 -0
  87. package/dist/types/src/initiative/functions/addArtifact.d.ts +6 -0
  88. package/dist/types/src/initiative/functions/addArtifact.d.ts.map +1 -0
  89. package/dist/types/src/initiative/functions/agent.d.ts +62 -0
  90. package/dist/types/src/initiative/functions/agent.d.ts.map +1 -0
  91. package/dist/types/src/initiative/functions/getContext.d.ts +13 -0
  92. package/dist/types/src/initiative/functions/getContext.d.ts.map +1 -0
  93. package/dist/types/src/initiative/functions/index.d.ts +5 -0
  94. package/dist/types/src/initiative/functions/index.d.ts.map +1 -0
  95. package/dist/types/src/initiative/functions/qualifier.d.ts +60 -0
  96. package/dist/types/src/initiative/functions/qualifier.d.ts.map +1 -0
  97. package/dist/types/src/initiative/index.d.ts +6 -0
  98. package/dist/types/src/initiative/index.d.ts.map +1 -0
  99. package/dist/types/src/initiative/initiative.test.d.ts +2 -0
  100. package/dist/types/src/initiative/initiative.test.d.ts.map +1 -0
  101. package/dist/types/src/initiative/plan.d.ts +77 -0
  102. package/dist/types/src/initiative/plan.d.ts.map +1 -0
  103. package/dist/types/src/initiative/util.d.ts +29 -0
  104. package/dist/types/src/initiative/util.d.ts.map +1 -0
  105. package/dist/types/src/planning/blueprint.d.ts +18 -0
  106. package/dist/types/src/planning/blueprint.d.ts.map +1 -0
  107. package/dist/types/src/planning/functions/index.d.ts +2 -0
  108. package/dist/types/src/planning/functions/index.d.ts.map +1 -0
  109. package/dist/types/src/planning/functions/update-tasks.d.ts +9 -0
  110. package/dist/types/src/planning/functions/update-tasks.d.ts.map +1 -0
  111. package/dist/types/src/planning/index.d.ts +3 -0
  112. package/dist/types/src/planning/index.d.ts.map +1 -0
  113. package/dist/types/src/sync/sync.d.ts +2 -2
  114. package/dist/types/src/sync/sync.d.ts.map +1 -1
  115. package/dist/types/src/testing/index.d.ts +1 -1
  116. package/dist/types/src/testing/index.d.ts.map +1 -1
  117. package/dist/types/src/testing/plugins.d.ts +19 -0
  118. package/dist/types/src/testing/plugins.d.ts.map +1 -0
  119. package/dist/types/src/toolkits/AssistantToolkit.d.ts +29 -3
  120. package/dist/types/src/toolkits/AssistantToolkit.d.ts.map +1 -1
  121. package/dist/types/src/toolkits/SystemToolkit.d.ts +34 -2
  122. package/dist/types/src/toolkits/SystemToolkit.d.ts.map +1 -1
  123. package/dist/types/src/toolkits/WebToolkit.d.ts +38 -0
  124. package/dist/types/src/toolkits/WebToolkit.d.ts.map +1 -0
  125. package/dist/types/src/toolkits/index.d.ts +1 -0
  126. package/dist/types/src/toolkits/index.d.ts.map +1 -1
  127. package/dist/types/tsconfig.tsbuildinfo +1 -1
  128. package/package.json +45 -40
  129. package/src/blueprints/design/design-blueprint.test.ts +8 -13
  130. package/src/blueprints/design/design-blueprint.ts +2 -4
  131. package/src/blueprints/design/index.ts +1 -1
  132. package/src/blueprints/discord/discord-blueprint.ts +2 -4
  133. package/src/blueprints/discord/index.ts +1 -1
  134. package/src/blueprints/index.ts +1 -0
  135. package/src/blueprints/linear/index.ts +1 -1
  136. package/src/blueprints/linear/linear-blueprint.ts +2 -4
  137. package/src/blueprints/markdown/index.ts +7 -0
  138. package/src/blueprints/markdown/markdown-blueprint.ts +24 -0
  139. package/src/blueprints/planning/index.ts +1 -1
  140. package/src/blueprints/planning/planning-blueprint.test.ts +8 -14
  141. package/src/blueprints/planning/planning-blueprint.ts +2 -4
  142. package/src/blueprints/research/index.ts +1 -1
  143. package/src/blueprints/research/research-blueprint.ts +2 -4
  144. package/src/blueprints/testing.ts +2 -6
  145. package/src/blueprints/websearch/index.ts +2 -1
  146. package/src/blueprints/websearch/websearch-blueprint.ts +2 -4
  147. package/src/chat/Chat.ts +45 -0
  148. package/src/chat/index.ts +5 -0
  149. package/src/crud/graph.test.ts +5 -29
  150. package/src/crud/graph.ts +14 -17
  151. package/src/experimental/feed.test.ts +3 -8
  152. package/src/functions/agent/prompt.ts +13 -14
  153. package/src/functions/discord/fetch-messages.test.ts +3 -7
  154. package/src/functions/discord/fetch-messages.ts +1 -1
  155. package/src/functions/document/create.ts +29 -0
  156. package/src/functions/document/index.ts +2 -1
  157. package/src/functions/document/read.ts +10 -8
  158. package/src/functions/document/update.ts +8 -7
  159. package/src/functions/entity-extraction/entity-extraction.conversations.json +1 -1
  160. package/src/functions/entity-extraction/entity-extraction.test.ts +9 -28
  161. package/src/functions/entity-extraction/entity-extraction.ts +25 -18
  162. package/src/functions/exa/mock.ts +1 -1
  163. package/src/functions/github/fetch-prs.ts +3 -2
  164. package/src/functions/linear/linear.test.ts +16 -42
  165. package/src/functions/linear/sync-issues.ts +6 -5
  166. package/src/functions/research/document-create.ts +8 -11
  167. package/src/functions/research/research-graph.ts +4 -4
  168. package/src/functions/research/research.conversations.json +1 -1
  169. package/src/functions/research/research.test.ts +25 -56
  170. package/src/functions/research/research.ts +13 -22
  171. package/src/functions/research/types.ts +2 -2
  172. package/src/functions/tasks/read.ts +5 -6
  173. package/src/functions/tasks/update.ts +5 -6
  174. package/src/index.ts +4 -2
  175. package/src/initiative/Initiative.ts +61 -0
  176. package/src/initiative/blueprint.ts +60 -0
  177. package/src/initiative/functions/addArtifact.ts +41 -0
  178. package/src/initiative/functions/agent.ts +77 -0
  179. package/src/initiative/functions/getContext.ts +62 -0
  180. package/src/initiative/functions/index.ts +8 -0
  181. package/src/initiative/functions/qualifier.ts +98 -0
  182. package/src/initiative/index.ts +9 -0
  183. package/src/initiative/initiative.test.ts +584 -0
  184. package/src/initiative/plan.ts +107 -0
  185. package/src/initiative/util.ts +137 -0
  186. package/src/planning/blueprint.ts +14 -0
  187. package/src/planning/functions/index.ts +5 -0
  188. package/src/planning/functions/update-tasks.ts +168 -0
  189. package/src/planning/index.ts +6 -0
  190. package/src/sync/sync.ts +37 -27
  191. package/src/testing/index.ts +1 -1
  192. package/src/{plugins.tsx → testing/plugins.tsx} +11 -10
  193. package/src/toolkits/AssistantToolkit.conversations.json +1 -1
  194. package/src/toolkits/AssistantToolkit.test.ts +26 -44
  195. package/src/toolkits/AssistantToolkit.ts +29 -6
  196. package/src/toolkits/SystemToolkit.ts +88 -20
  197. package/src/toolkits/WebToolkit.ts +34 -0
  198. package/src/toolkits/index.ts +1 -0
  199. package/dist/lib/browser/index.mjs.map +0 -7
  200. package/dist/lib/browser/meta.json +0 -1
  201. package/dist/lib/node-esm/index.mjs +0 -2790
  202. package/dist/lib/node-esm/index.mjs.map +0 -7
  203. package/dist/lib/node-esm/meta.json +0 -1
  204. package/dist/types/src/plugins.d.ts +0 -19
  205. package/dist/types/src/plugins.d.ts.map +0 -1
  206. package/dist/types/src/testing/data/exa-search-1748337321991.d.ts.map +0 -1
  207. package/dist/types/src/testing/data/exa-search-1748337331526.d.ts.map +0 -1
  208. package/dist/types/src/testing/data/exa-search-1748337344119.d.ts.map +0 -1
  209. package/dist/types/src/testing/data/index.d.ts.map +0 -1
  210. /package/dist/types/src/{testing → functions/exa}/data/exa-search-1748337321991.d.ts +0 -0
  211. /package/dist/types/src/{testing → functions/exa}/data/exa-search-1748337331526.d.ts +0 -0
  212. /package/dist/types/src/{testing → functions/exa}/data/exa-search-1748337344119.d.ts +0 -0
  213. /package/dist/types/src/{testing → functions/exa}/data/index.d.ts +0 -0
  214. /package/src/{testing → functions/exa}/data/exa-search-1748337321991.ts +0 -0
  215. /package/src/{testing → functions/exa}/data/exa-search-1748337331526.ts +0 -0
  216. /package/src/{testing → functions/exa}/data/exa-search-1748337344119.ts +0 -0
  217. /package/src/{testing → functions/exa}/data/index.ts +0 -0
@@ -1,13 +1,11 @@
1
- var __defProp = Object.defineProperty;
2
- var __export = (target, all) => {
3
- for (var name in all)
4
- __defProp(target, name, { get: all[name], enumerable: true });
5
- };
1
+ import {
2
+ __export
3
+ } from "./chunk-J5LGTIGS.mjs";
6
4
 
7
5
  // src/blueprints/design/design-blueprint.ts
8
6
  import { ToolId } from "@dxos/ai";
9
7
  import { Blueprint } from "@dxos/blueprints";
10
- import { Obj as Obj10, Ref as Ref6 } from "@dxos/echo";
8
+ import { Ref as Ref7 } from "@dxos/echo";
11
9
  import { Text as Text2 } from "@dxos/schema";
12
10
  import { trim as trim5 } from "@dxos/util";
13
11
 
@@ -57,14 +55,14 @@ var prompt_default = defineFunction({
57
55
  C: (f, a) => f(...a)
58
56
  });
59
57
  const input = yield* Match.value(data.input).pipe(Match.when((value2) => Ref.isRef(value2), Effect.fnUntraced(function* (ref) {
60
- const object = yield* Database.Service.load(ref);
58
+ const object = yield* Database.load(ref);
61
59
  return Obj.toJSON(object);
62
60
  })), Match.orElse(() => Effect.succeed(data.input)));
63
- yield* Database.Service.flush({
61
+ yield* Database.flush({
64
62
  indexes: true
65
63
  });
66
- const prompt = yield* Database.Service.load(data.prompt);
67
- const systemPrompt = data.systemPrompt ? yield* Database.Service.load(data.systemPrompt) : void 0;
64
+ const prompt = yield* Database.load(data.prompt);
65
+ const systemPrompt = data.systemPrompt ? yield* Database.load(data.systemPrompt) : void 0;
68
66
  yield* TracingService.emitStatus({
69
67
  message: `Running ${prompt.id}`
70
68
  });
@@ -77,14 +75,14 @@ var prompt_default = defineFunction({
77
75
  S: this,
78
76
  C: (f, a) => f(...a)
79
77
  });
80
- const blueprints = yield* Function.pipe(prompt.blueprints, Array2.appendAll(systemPrompt?.blueprints ?? []), Effect.forEach(Database.Service.loadOption), Effect.map(Array2.filter(Option.isSome)), Effect.map(Array2.map((option) => option.value)));
81
- const objects = yield* Function.pipe(prompt.context, Array2.appendAll(systemPrompt?.context ?? []), Effect.forEach(Database.Service.loadOption), Effect.map(Array2.filter(Option.isSome)), Effect.map(Array2.map((option) => option.value)));
78
+ const blueprints = yield* Function.pipe(prompt.blueprints, Array2.appendAll(systemPrompt?.blueprints ?? []), Effect.forEach(Database.loadOption), Effect.map(Array2.filter(Option.isSome)), Effect.map(Array2.map((option) => option.value)));
82
79
  const toolkit = yield* createToolkit({
83
80
  blueprints
84
81
  });
85
- const promptInstructions = yield* Database.Service.load(prompt.instructions.source);
82
+ const objects = yield* Function.pipe(prompt.context, Array2.appendAll(systemPrompt?.context ?? []), Effect.forEach(Database.loadOption), Effect.map(Array2.filter(Option.isSome)), Effect.map(Array2.map((option) => option.value)));
83
+ const promptInstructions = yield* Database.load(prompt.instructions.source);
86
84
  const promptText = Template.process(promptInstructions.content, input);
87
- const systemInstructions = systemPrompt ? yield* Database.Service.load(systemPrompt.instructions.source) : void 0;
85
+ const systemInstructions = systemPrompt ? yield* Database.load(systemPrompt.instructions.source) : void 0;
88
86
  const systemText = systemInstructions ? Template.process(systemInstructions.content, {}) : void 0;
89
87
  const session = new AiSession();
90
88
  const result = yield* session.run({
@@ -212,7 +210,15 @@ var fetch_messages_default = defineFunction2({
212
210
  throw new Error("no channels found");
213
211
  }
214
212
  for (const channel of channels) {
215
- console.log(channel.id, "name" in channel ? channel.name : void 0);
213
+ log2.info("channel", {
214
+ id: channel.id,
215
+ name: "name" in channel ? channel.name : void 0
216
+ }, {
217
+ F: __dxlog_file2,
218
+ L: 136,
219
+ S: this,
220
+ C: (f, a) => f(...a)
221
+ });
216
222
  }
217
223
  yield* TracingService2.emitStatus({
218
224
  message: `Will fetch from channels: ${channels.length}`
@@ -309,58 +315,87 @@ ${thread.messages.map((message) => ` ${message.sender.name}: ${message.blocks.f
309
315
  })(Discord || (Discord = {}));
310
316
  var Discord;
311
317
 
312
- // src/functions/document/read.ts
318
+ // src/functions/document/create.ts
313
319
  import * as Effect3 from "effect/Effect";
314
320
  import * as Schema3 from "effect/Schema";
315
- import { ArtifactId } from "@dxos/assistant";
316
- import { Database as Database2 } from "@dxos/echo";
321
+ import { Database as Database2, Ref as Ref2 } from "@dxos/echo";
317
322
  import { defineFunction as defineFunction3 } from "@dxos/functions";
318
323
  import { Markdown } from "@dxos/plugin-markdown/types";
319
- var read_default = defineFunction3({
320
- key: "dxos.org/function/markdown/read",
321
- name: "Read markdown document",
322
- description: "Read markdown document.",
324
+ var create_default = defineFunction3({
325
+ key: "dxos.org/function/markdown/create",
326
+ name: "Create markdown document",
327
+ description: "Creates a new markdown document.",
323
328
  inputSchema: Schema3.Struct({
324
- id: ArtifactId.annotations({
325
- description: "The ID of the document to read."
329
+ name: Schema3.String.annotations({
330
+ description: "Name of the document."
331
+ }),
332
+ content: Schema3.String.annotations({
333
+ description: "Content of the document."
326
334
  })
327
335
  }),
328
- outputSchema: Schema3.Struct({
329
- content: Schema3.String
330
- }),
331
- handler: Effect3.fn(function* ({ data: { id } }) {
332
- const doc = yield* Database2.Service.resolve(ArtifactId.toDXN(id), Markdown.Document);
333
- const { content } = yield* Database2.Service.load(doc.content);
334
- return {
336
+ outputSchema: Schema3.Void,
337
+ handler: Effect3.fn(function* ({ data: { name, content } }) {
338
+ const doc = yield* Database2.add(Markdown.make({
339
+ name,
335
340
  content
341
+ }));
342
+ return {
343
+ document: Ref2.make(doc)
336
344
  };
337
345
  })
338
346
  });
339
347
 
340
- // src/functions/document/update.ts
348
+ // src/functions/document/read.ts
341
349
  import * as Effect4 from "effect/Effect";
342
350
  import * as Schema4 from "effect/Schema";
343
- import { ArtifactId as ArtifactId2 } from "@dxos/assistant";
344
- import { Database as Database3 } from "@dxos/echo";
351
+ import { Database as Database3, Type as Type2 } from "@dxos/echo";
345
352
  import { defineFunction as defineFunction4 } from "@dxos/functions";
346
353
  import { Markdown as Markdown2 } from "@dxos/plugin-markdown/types";
347
- var update_default = defineFunction4({
354
+ var read_default = defineFunction4({
355
+ key: "dxos.org/function/markdown/read",
356
+ name: "Read markdown document",
357
+ description: "Read markdown document. Note that result is a snapshot in time, and might have changed since the document was last read.",
358
+ inputSchema: Schema4.Struct({
359
+ document: Type2.Ref(Markdown2.Document).annotations({
360
+ description: "The document to read."
361
+ })
362
+ }),
363
+ outputSchema: Schema4.Struct({
364
+ content: Schema4.String
365
+ }),
366
+ handler: Effect4.fn(function* ({ data: { document } }) {
367
+ const { content } = yield* document.pipe(Database3.load, Effect4.flatMap((doc) => doc.content.pipe(Database3.load)));
368
+ return {
369
+ content
370
+ };
371
+ })
372
+ });
373
+
374
+ // src/functions/document/update.ts
375
+ import * as Effect5 from "effect/Effect";
376
+ import * as Schema5 from "effect/Schema";
377
+ import { Database as Database4, Obj as Obj3, Type as Type3 } from "@dxos/echo";
378
+ import { defineFunction as defineFunction5 } from "@dxos/functions";
379
+ import { Markdown as Markdown3 } from "@dxos/plugin-markdown/types";
380
+ var update_default = defineFunction5({
348
381
  key: "dxos.org/function/markdown/update",
349
382
  name: "Update markdown",
350
383
  description: "Updates the entire contents of the markdown document.",
351
- inputSchema: Schema4.Struct({
352
- id: ArtifactId2.annotations({
384
+ inputSchema: Schema5.Struct({
385
+ doc: Type3.Ref(Markdown3.Document).annotations({
353
386
  description: "The ID of the document to write."
354
387
  }),
355
- content: Schema4.String.annotations({
388
+ content: Schema5.String.annotations({
356
389
  description: "New content to write to the document."
357
390
  })
358
391
  }),
359
- outputSchema: Schema4.Void,
360
- handler: Effect4.fn(function* ({ data: { id, content } }) {
361
- const doc = yield* Database3.Service.resolve(ArtifactId2.toDXN(id), Markdown2.Document);
362
- const text = yield* Database3.Service.load(doc.content);
363
- text.content = content;
392
+ outputSchema: Schema5.Void,
393
+ handler: Effect5.fn(function* ({ data: { doc, content } }) {
394
+ const document = yield* Database4.load(doc);
395
+ const text = yield* Database4.load(document.content);
396
+ Obj3.change(text, (t) => {
397
+ t.content = content;
398
+ });
364
399
  })
365
400
  });
366
401
 
@@ -368,20 +403,20 @@ var update_default = defineFunction4({
368
403
  (function(Document2) {
369
404
  Document2.read = read_default;
370
405
  Document2.update = update_default;
406
+ Document2.create = create_default;
371
407
  })(Document || (Document = {}));
372
408
  var Document;
373
409
 
374
410
  // src/functions/entity-extraction/entity-extraction.ts
375
- import * as Toolkit3 from "@effect/ai/Toolkit";
376
- import * as Effect11 from "effect/Effect";
411
+ import * as Effect12 from "effect/Effect";
377
412
  import * as Layer4 from "effect/Layer";
378
413
  import * as Predicate from "effect/Predicate";
379
- import * as Schema11 from "effect/Schema";
414
+ import * as Schema12 from "effect/Schema";
380
415
  import { AiService as AiService3 } from "@dxos/ai";
381
- import { AiSession as AiSession3, makeToolExecutionServiceFromFunctions as makeToolExecutionServiceFromFunctions2, makeToolResolverFromFunctions as makeToolResolverFromFunctions2 } from "@dxos/assistant";
382
- import { Filter as Filter2, Obj as Obj7, Ref as Ref3 } from "@dxos/echo";
383
- import { Database as Database8 } from "@dxos/echo";
384
- import { defineFunction as defineFunction9 } from "@dxos/functions";
416
+ import { AiSession as AiSession3, GenericToolkit as GenericToolkit2, ToolExecutionServices as ToolExecutionServices2 } from "@dxos/assistant";
417
+ import { Filter as Filter2, Obj as Obj8, Ref as Ref4, Type as Type7 } from "@dxos/echo";
418
+ import { Database as Database9 } from "@dxos/echo";
419
+ import { defineFunction as defineFunction10 } from "@dxos/functions";
385
420
  import { FunctionInvocationServiceLayerTest } from "@dxos/functions-runtime/testing";
386
421
  import { log as log5 } from "@dxos/log";
387
422
  import { LegacyOrganization as LegacyOrganization2, Message as Message2, Organization, Person as Person2 } from "@dxos/types";
@@ -391,13 +426,13 @@ import { trim as trim4 } from "@dxos/util";
391
426
  import * as Tool from "@effect/ai/Tool";
392
427
  import * as Toolkit from "@effect/ai/Toolkit";
393
428
  import * as Context from "effect/Context";
394
- import * as Effect5 from "effect/Effect";
429
+ import * as Effect6 from "effect/Effect";
395
430
  import * as Function3 from "effect/Function";
396
431
  import * as Option3 from "effect/Option";
397
- import * as Schema5 from "effect/Schema";
432
+ import * as Schema6 from "effect/Schema";
398
433
  import * as SchemaAST from "effect/SchemaAST";
399
- import { Entity, Filter, Obj as Obj3, Query, Type as Type2 } from "@dxos/echo";
400
- import { Database as Database4 } from "@dxos/echo";
434
+ import { Entity, Filter, Obj as Obj4, Query, Type as Type4 } from "@dxos/echo";
435
+ import { Database as Database5 } from "@dxos/echo";
401
436
  import { ReferenceAnnotationId, RelationSourceDXNId, RelationSourceId, RelationTargetDXNId, RelationTargetId, createObject, getTypeAnnotation, getTypeIdentifierAnnotation } from "@dxos/echo/internal";
402
437
  import { isEncodedReference } from "@dxos/echo-protocol";
403
438
  import { mapAst } from "@dxos/effect";
@@ -406,22 +441,20 @@ import { DXN, ObjectId } from "@dxos/keys";
406
441
  import { log as log3 } from "@dxos/log";
407
442
  import { deepMapValues, isNonNullable, trim } from "@dxos/util";
408
443
  var __dxlog_file3 = "/__w/dxos/dxos/packages/core/assistant-toolkit/src/crud/graph.ts";
409
- var Subgraph = Schema5.Struct({
444
+ var Subgraph = Schema6.Struct({
410
445
  /** Objects and relations. */
411
- objects: Schema5.Array(Schema5.Any)
446
+ objects: Schema6.Array(Schema6.Any)
412
447
  });
413
448
  var findRelatedSchema = async (db, anchor) => {
414
- const allSchemas = [
415
- ...db.graph.schemaRegistry.schemas
416
- ];
449
+ const allSchemas = await db.graph.schemaRegistry.query().run();
417
450
  return allSchemas.filter((schema) => {
418
451
  if (getTypeAnnotation(schema)?.kind !== Entity.Kind.Relation) {
419
452
  return false;
420
453
  }
421
454
  return isSchemaAddressableByDxn(anchor, DXN.parse(getTypeAnnotation(schema).sourceSchema)) || isSchemaAddressableByDxn(anchor, DXN.parse(getTypeAnnotation(schema).targetSchema));
422
455
  }).map((schema) => ({
423
- schema,
424
- kind: "relation"
456
+ kind: "relation",
457
+ schema
425
458
  }));
426
459
  };
427
460
  var isSchemaAddressableByDxn = (schema, dxn) => {
@@ -430,34 +463,34 @@ var isSchemaAddressableByDxn = (schema, dxn) => {
430
463
  }
431
464
  const t = dxn.asTypeDXN();
432
465
  if (t) {
433
- return t.type === Type2.getTypename(schema);
466
+ return t.type === Type4.getTypename(schema);
434
467
  }
435
468
  return false;
436
469
  };
437
470
  var LocalSearchToolkit = Toolkit.make(Tool.make("search_local_search", {
438
471
  description: "Search the local database for information using a vector index",
439
472
  parameters: {
440
- query: Schema5.String.annotations({
473
+ query: Schema6.String.annotations({
441
474
  description: "The query to search for. Could be a question or a topic or a set of keywords."
442
475
  })
443
476
  },
444
- success: Schema5.Unknown,
445
- failure: Schema5.Never,
477
+ success: Schema6.Unknown,
478
+ failure: Schema6.Never,
446
479
  dependencies: [
447
- Database4.Service
480
+ Database5.Service
448
481
  ]
449
482
  }));
450
483
  var LocalSearchHandler = LocalSearchToolkit.toLayer({
451
- search_local_search: Effect5.fn(function* ({ query }) {
452
- const objects = yield* Database4.Service.runQuery(Query.select(Filter.text(query, {
484
+ search_local_search: Effect6.fn(function* ({ query }) {
485
+ const objects = yield* Database5.runQuery(Query.select(Filter.text(query, {
453
486
  type: "vector"
454
487
  })));
455
488
  const results = [
456
489
  ...objects
457
490
  ];
458
- const option = yield* Effect5.serviceOption(ContextQueueService);
491
+ const option = yield* Effect6.serviceOption(ContextQueueService);
459
492
  if (Option3.isSome(option)) {
460
- const queueObjects = yield* Effect5.promise(() => option.value.queue.queryObjects());
493
+ const queueObjects = yield* Effect6.promise(() => option.value.queue.queryObjects());
461
494
  results.push(...queueObjects);
462
495
  }
463
496
  return trim`
@@ -473,10 +506,10 @@ var makeGraphWriterToolkit = ({ schema }) => {
473
506
  return Toolkit.make(Tool.make("graph_writer", {
474
507
  description: "Write to the local graph database",
475
508
  parameters: createExtractionSchema(schema).fields,
476
- success: Schema5.Unknown,
477
- failure: Schema5.Never,
509
+ success: Schema6.Unknown,
510
+ failure: Schema6.Never,
478
511
  dependencies: [
479
- Database4.Service,
512
+ Database5.Service,
480
513
  ContextQueueService
481
514
  ]
482
515
  }).annotateContext(Context.make(GraphWriterSchema, {
@@ -486,29 +519,29 @@ var makeGraphWriterToolkit = ({ schema }) => {
486
519
  var makeGraphWriterHandler = (toolkit, { onAppend } = {}) => {
487
520
  const { schema } = Context.get(toolkit.tools.graph_writer.annotations, GraphWriterSchema);
488
521
  return toolkit.toLayer({
489
- graph_writer: Effect5.fn(function* (input) {
490
- const { db } = yield* Database4.Service;
522
+ graph_writer: Effect6.fn(function* (input) {
523
+ const { db } = yield* Database5.Service;
491
524
  const { queue } = yield* ContextQueueService;
492
- const data = yield* Effect5.promise(() => sanitizeObjects(schema, input, db, queue));
493
- yield* Effect5.promise(() => queue.append(data));
494
- const dxns = data.map((obj) => Obj3.getDXN(obj));
525
+ const data = yield* Effect6.promise(() => sanitizeObjects(schema, input, db, queue));
526
+ yield* Effect6.promise(() => queue.append(data));
527
+ const dxns = data.map((obj) => Obj4.getDXN(obj));
495
528
  onAppend?.(dxns);
496
529
  return dxns;
497
530
  })
498
531
  });
499
532
  };
500
533
  var createExtractionSchema = (types) => {
501
- return Schema5.Struct({
534
+ return Schema6.Struct({
502
535
  ...Object.fromEntries(types.map(preprocessSchema).map((schema, index) => [
503
536
  `objects_${getSanitizedSchemaName(types[index])}`,
504
- Schema5.optional(Schema5.Array(schema)).annotations({
505
- description: `The objects of type: ${Type2.getDXN(types[index])?.asTypeDXN().type}. ${SchemaAST.getDescriptionAnnotation(types[index].ast).pipe(Option3.getOrElse(() => ""))}`
537
+ Schema6.optional(Schema6.Array(schema)).annotations({
538
+ description: `The objects of type: ${Type4.getDXN(types[index])?.asTypeDXN().type}. ${SchemaAST.getDescriptionAnnotation(types[index].ast).pipe(Option3.getOrElse(() => ""))}`
506
539
  })
507
540
  ]))
508
541
  });
509
542
  };
510
543
  var getSanitizedSchemaName = (schema) => {
511
- return Type2.getDXN(schema).asTypeDXN().type.replaceAll(/[^a-zA-Z0-9]+/g, "_");
544
+ return Type4.getDXN(schema).asTypeDXN().type.replaceAll(/[^a-zA-Z0-9]+/g, "_");
512
545
  };
513
546
  var sanitizeObjects = async (types, data, db, queue) => {
514
547
  const entries = types.map((type) => data[`objects_${getSanitizedSchemaName(type)}`]?.map((object) => ({
@@ -560,7 +593,7 @@ var sanitizeObjects = async (types, data, db, queue) => {
560
593
  source: data2.source
561
594
  }, {
562
595
  F: __dxlog_file3,
563
- L: 276,
596
+ L: 273,
564
597
  S: void 0,
565
598
  C: (f, a) => f(...a)
566
599
  });
@@ -571,7 +604,7 @@ var sanitizeObjects = async (types, data, db, queue) => {
571
604
  target: data2.target
572
605
  }, {
573
606
  F: __dxlog_file3,
574
- L: 280,
607
+ L: 277,
575
608
  S: void 0,
576
609
  C: (f, a) => f(...a)
577
610
  });
@@ -600,7 +633,7 @@ var sanitizeObjects = async (types, data, db, queue) => {
600
633
  existingIds
601
634
  }, {
602
635
  F: __dxlog_file3,
603
- L: 301,
636
+ L: 298,
604
637
  S: void 0,
605
638
  C: (f, a) => f(...a)
606
639
  });
@@ -640,8 +673,8 @@ var sanitizeObjects = async (types, data, db, queue) => {
640
673
  return [];
641
674
  });
642
675
  };
643
- var SoftRef = Schema5.Struct({
644
- "/": Schema5.String
676
+ var SoftRef = Schema6.Struct({
677
+ "/": Schema6.String
645
678
  }).annotations({
646
679
  description: "Reference to another object."
647
680
  });
@@ -657,85 +690,83 @@ var preprocessSchema = (schema) => {
657
690
  }
658
691
  return mapAst(ast, (child) => go(child, visited));
659
692
  };
660
- return Schema5.make(mapAst(schema.ast, (ast) => go(ast))).pipe(Schema5.omit("id"), Schema5.extend(Schema5.Struct({
661
- id: Schema5.String.annotations({
693
+ return Schema6.make(mapAst(schema.ast, (ast) => go(ast))).pipe(Schema6.omit("id"), Schema6.extend(Schema6.Struct({
694
+ id: Schema6.String.annotations({
662
695
  description: "The id of this object. Come up with a unique id based on your judgement."
663
696
  })
664
- })), isRelationSchema ? Schema5.extend(Schema5.Struct({
665
- source: Schema5.String.annotations({
697
+ })), isRelationSchema ? Schema6.extend(Schema6.Struct({
698
+ source: Schema6.String.annotations({
666
699
  description: "The id of the source object for this relation."
667
700
  }),
668
- target: Schema5.String.annotations({
701
+ target: Schema6.String.annotations({
669
702
  description: "The id of the target object for this relation."
670
703
  })
671
704
  })) : Function3.identity);
672
705
  };
673
706
 
674
707
  // src/functions/research/document-create.ts
675
- import * as Effect6 from "effect/Effect";
676
- import * as Schema6 from "effect/Schema";
677
- import { ArtifactId as ArtifactId3 } from "@dxos/assistant";
678
- import { Obj as Obj4, Relation } from "@dxos/echo";
679
- import { Database as Database5 } from "@dxos/echo";
680
- import { TracingService as TracingService3, defineFunction as defineFunction5 } from "@dxos/functions";
708
+ import * as Effect7 from "effect/Effect";
709
+ import * as Schema7 from "effect/Schema";
710
+ import { Database as Database6, Obj as Obj5, Relation, Type as Type5 } from "@dxos/echo";
711
+ import { TracingService as TracingService3, defineFunction as defineFunction6 } from "@dxos/functions";
681
712
  import { log as log4 } from "@dxos/log";
682
- import { Markdown as Markdown3 } from "@dxos/plugin-markdown/types";
713
+ import { Markdown as Markdown4 } from "@dxos/plugin-markdown/types";
683
714
  import { HasSubject } from "@dxos/types";
684
715
  import { trim as trim2 } from "@dxos/util";
685
716
  var __dxlog_file4 = "/__w/dxos/dxos/packages/core/assistant-toolkit/src/functions/research/document-create.ts";
686
- var document_create_default = defineFunction5({
717
+ var document_create_default = defineFunction6({
687
718
  key: "dxos.org/function/research/document-create",
688
719
  name: "Create research document",
689
720
  description: "Creates a note summarizing the research.",
690
- inputSchema: Schema6.Struct({
691
- subject: ArtifactId3.annotations({
721
+ inputSchema: Schema7.Struct({
722
+ subject: Type5.Ref(Type5.Obj).annotations({
692
723
  description: trim2`
693
724
  ID of the object (organization, contact, etc.) for which the research was performed.
694
725
  `
695
726
  }),
696
- name: Schema6.String.annotations({
727
+ name: Schema7.String.annotations({
697
728
  description: "Name of the document."
698
729
  }),
699
- content: Schema6.String.annotations({
730
+ content: Schema7.String.annotations({
700
731
  description: trim2`
701
732
  Content of the note.
702
733
  Supports (and are prefered) references to research objects using @ syntax and <object> tags (refer to research blueprint instructions).
703
734
  `
704
735
  })
705
736
  }),
706
- outputSchema: Schema6.Struct({
707
- document: ArtifactId3.annotations({
737
+ outputSchema: Schema7.Struct({
738
+ document: Schema7.String.annotations({
708
739
  description: "DXN of the created document."
709
740
  })
710
741
  }),
711
- handler: Effect6.fnUntraced(function* ({ data: { subject, name, content } }) {
742
+ handler: Effect7.fnUntraced(function* ({ data: { subject, name, content } }) {
712
743
  log4.info("Creating research document", {
713
744
  subject,
714
745
  name,
715
746
  content
716
747
  }, {
717
748
  F: __dxlog_file4,
718
- L: 43,
749
+ L: 41,
719
750
  S: this,
720
751
  C: (f, a) => f(...a)
721
752
  });
722
- yield* Database5.Service.flush({
753
+ yield* Database6.flush({
723
754
  indexes: true
724
755
  });
725
756
  yield* TracingService3.emitStatus({
726
757
  message: "Creating research document..."
727
758
  });
728
- const target = yield* Database5.Service.resolve(ArtifactId3.toDXN(subject));
729
- const object = yield* Database5.Service.add(Markdown3.make({
759
+ const target = yield* Database6.load(subject);
760
+ const object = yield* Database6.add(Markdown4.make({
730
761
  name,
731
762
  content
732
763
  }));
733
- yield* Database5.Service.add(Relation.make(HasSubject.HasSubject, {
764
+ yield* Database6.add(Relation.make(HasSubject.HasSubject, {
734
765
  [Relation.Source]: object,
735
766
  [Relation.Target]: target,
736
767
  completedAt: (/* @__PURE__ */ new Date()).toISOString()
737
768
  }));
738
- yield* Database5.Service.flush({
769
+ yield* Database6.flush({
739
770
  indexes: true
740
771
  });
741
772
  log4.info("Created research document", {
@@ -743,12 +774,12 @@ var document_create_default = defineFunction5({
743
774
  object
744
775
  }, {
745
776
  F: __dxlog_file4,
746
- L: 70,
777
+ L: 67,
747
778
  S: this,
748
779
  C: (f, a) => f(...a)
749
780
  });
750
781
  return {
751
- document: Obj4.getDXN(object).toString()
782
+ document: Obj5.getDXN(object).toString()
752
783
  };
753
784
  })
754
785
  });
@@ -757,43 +788,43 @@ var document_create_default = defineFunction5({
757
788
  import * as Toolkit2 from "@effect/ai/Toolkit";
758
789
  import * as AnthropicTool from "@effect/ai-anthropic/AnthropicTool";
759
790
  import * as Array6 from "effect/Array";
760
- import * as Effect10 from "effect/Effect";
791
+ import * as Effect11 from "effect/Effect";
761
792
  import * as Function4 from "effect/Function";
762
793
  import * as Layer3 from "effect/Layer";
763
794
  import * as Option4 from "effect/Option";
764
- import * as Schema10 from "effect/Schema";
765
- import * as String10 from "effect/String";
795
+ import * as Schema11 from "effect/Schema";
796
+ import * as String11 from "effect/String";
766
797
  import { AiService as AiService2, ConsolePrinter as ConsolePrinter2 } from "@dxos/ai";
767
- import { AiSession as AiSession2, GenerationObserver as GenerationObserver2, createToolkit as createToolkit2, makeToolExecutionServiceFromFunctions, makeToolResolverFromFunctions } from "@dxos/assistant";
798
+ import { AiSession as AiSession2, GenerationObserver as GenerationObserver2, GenericToolkit, ToolExecutionServices, createToolkit as createToolkit2 } from "@dxos/assistant";
768
799
  import { Template as Template2 } from "@dxos/blueprints";
769
- import { Obj as Obj6 } from "@dxos/echo";
770
- import { Database as Database7 } from "@dxos/echo";
771
- import { TracingService as TracingService4, defineFunction as defineFunction8 } from "@dxos/functions";
800
+ import { Entity as Entity2, Obj as Obj7 } from "@dxos/echo";
801
+ import { Database as Database8 } from "@dxos/echo";
802
+ import { TracingService as TracingService4, defineFunction as defineFunction9 } from "@dxos/functions";
772
803
  import { FunctionInvocationServiceLayerTestMocked } from "@dxos/functions-runtime/testing";
773
804
  import { Person } from "@dxos/types";
774
805
  import { trim as trim3 } from "@dxos/util";
775
806
 
776
807
  // src/functions/exa/exa.ts
777
- import * as Effect7 from "effect/Effect";
778
- import * as Schema7 from "effect/Schema";
808
+ import * as Effect8 from "effect/Effect";
809
+ import * as Schema8 from "effect/Schema";
779
810
  import Exa from "exa-js";
780
- import { CredentialsService as CredentialsService2, defineFunction as defineFunction6 } from "@dxos/functions";
781
- var exa_default = defineFunction6({
811
+ import { CredentialsService as CredentialsService2, defineFunction as defineFunction7 } from "@dxos/functions";
812
+ var exa_default = defineFunction7({
782
813
  key: "dxos.org/function/exa",
783
814
  name: "Exa",
784
815
  description: "Search the web for information",
785
- inputSchema: Schema7.Struct({
786
- query: Schema7.String.annotations({
816
+ inputSchema: Schema8.Struct({
817
+ query: Schema8.String.annotations({
787
818
  description: "The query to search for."
788
819
  })
789
820
  }),
790
- outputSchema: Schema7.Unknown,
791
- handler: Effect7.fnUntraced(function* ({ data: { query } }) {
821
+ outputSchema: Schema8.Unknown,
822
+ handler: Effect8.fnUntraced(function* ({ data: { query } }) {
792
823
  const credential = yield* CredentialsService2.getCredential({
793
824
  service: "exa.ai"
794
825
  });
795
826
  const exa = new Exa(credential.apiKey);
796
- const context = yield* Effect7.promise(async () => exa.searchAndContents(query, {
827
+ const context = yield* Effect8.promise(async () => exa.searchAndContents(query, {
797
828
  type: "auto",
798
829
  text: {
799
830
  maxCharacters: 3e3
@@ -805,11 +836,11 @@ var exa_default = defineFunction6({
805
836
  });
806
837
 
807
838
  // src/functions/exa/mock.ts
808
- import * as Effect8 from "effect/Effect";
809
- import * as Schema8 from "effect/Schema";
810
- import { defineFunction as defineFunction7 } from "@dxos/functions";
839
+ import * as Effect9 from "effect/Effect";
840
+ import * as Schema9 from "effect/Schema";
841
+ import { defineFunction as defineFunction8 } from "@dxos/functions";
811
842
 
812
- // src/testing/data/exa-search-1748337321991.ts
843
+ // src/functions/exa/data/exa-search-1748337321991.ts
813
844
  var exa_search_1748337321991_default = {
814
845
  requestId: "324936368a74f4db978982172bc18a6c",
815
846
  autopromptString: "AI personal knowledge management tools projects 2024",
@@ -965,7 +996,7 @@ var exa_search_1748337321991_default = {
965
996
  }
966
997
  };
967
998
 
968
- // src/testing/data/exa-search-1748337331526.ts
999
+ // src/functions/exa/data/exa-search-1748337331526.ts
969
1000
  var exa_search_1748337331526_default = {
970
1001
  requestId: "0dc12e344fa649884456960ca1a54954",
971
1002
  autopromptString: "PKM software artificial intelligence integration open source projects",
@@ -1188,7 +1219,7 @@ npm run tauri dev
1188
1219
  }
1189
1220
  };
1190
1221
 
1191
- // src/testing/data/exa-search-1748337344119.ts
1222
+ // src/functions/exa/data/exa-search-1748337344119.ts
1192
1223
  var exa_search_1748337344119_default = {
1193
1224
  requestId: "32df0c541f9883180b35e04caece4374",
1194
1225
  autopromptString: "open source AI knowledge management projects features comparison 2024",
@@ -1311,7 +1342,7 @@ var exa_search_1748337344119_default = {
1311
1342
  }
1312
1343
  };
1313
1344
 
1314
- // src/testing/data/index.ts
1345
+ // src/functions/exa/data/index.ts
1315
1346
  var SEARCH_RESULTS = [
1316
1347
  exa_search_1748337321991_default,
1317
1348
  exa_search_1748337331526_default,
@@ -1319,17 +1350,17 @@ var SEARCH_RESULTS = [
1319
1350
  ];
1320
1351
 
1321
1352
  // src/functions/exa/mock.ts
1322
- var mock_default = defineFunction7({
1353
+ var mock_default = defineFunction8({
1323
1354
  key: "dxos.org/function/exa-mock",
1324
1355
  name: "Exa mock",
1325
1356
  description: "Search the web for information",
1326
- inputSchema: Schema8.Struct({
1327
- query: Schema8.String.annotations({
1357
+ inputSchema: Schema9.Struct({
1358
+ query: Schema9.String.annotations({
1328
1359
  description: "The query to search for."
1329
1360
  })
1330
1361
  }),
1331
- outputSchema: Schema8.Unknown,
1332
- handler: Effect8.fnUntraced(function* ({ data: { query } }) {
1362
+ outputSchema: Schema9.Unknown,
1363
+ handler: Effect9.fnUntraced(function* ({ data: { query } }) {
1333
1364
  const result = SEARCH_RESULTS.reduce((closest, current) => {
1334
1365
  if (!current.autopromptString) {
1335
1366
  return closest;
@@ -1365,33 +1396,33 @@ var levenshteinDistance = (str1, str2) => {
1365
1396
  };
1366
1397
 
1367
1398
  // src/functions/research/research-graph.ts
1368
- import * as Effect9 from "effect/Effect";
1399
+ import * as Effect10 from "effect/Effect";
1369
1400
  import * as Layer2 from "effect/Layer";
1370
- import * as Schema9 from "effect/Schema";
1371
- import { Obj as Obj5, Query as Query2, Ref as Ref2, Type as Type3 } from "@dxos/echo";
1372
- import { Database as Database6 } from "@dxos/echo";
1401
+ import * as Schema10 from "effect/Schema";
1402
+ import { Obj as Obj6, Query as Query2, Ref as Ref3, Type as Type6 } from "@dxos/echo";
1403
+ import { Database as Database7 } from "@dxos/echo";
1373
1404
  import { SystemTypeAnnotation } from "@dxos/echo/internal";
1374
1405
  import { Queue } from "@dxos/echo-db";
1375
1406
  import { ContextQueueService as ContextQueueService2, QueueService } from "@dxos/functions";
1376
- var ResearchGraph = Schema9.Struct({
1377
- queue: Type3.Ref(Queue)
1378
- }).pipe(Type3.Obj({
1407
+ var ResearchGraph = Schema10.Struct({
1408
+ queue: Type6.Ref(Queue)
1409
+ }).pipe(Type6.object({
1379
1410
  typename: "dxos.org/type/ResearchGraph",
1380
1411
  version: "0.1.0"
1381
1412
  }), SystemTypeAnnotation.set(true));
1382
- var queryResearchGraph = Effect9.fn("queryResearchGraph")(function* () {
1383
- const objects = yield* Database6.Service.runQuery(Query2.type(ResearchGraph));
1413
+ var queryResearchGraph = Effect10.fn("queryResearchGraph")(function* () {
1414
+ const objects = yield* Database7.runQuery(Query2.type(ResearchGraph));
1384
1415
  return objects.at(0);
1385
1416
  });
1386
- var createResearchGraph = Effect9.fn("createResearchGraph")(function* () {
1417
+ var createResearchGraph = Effect10.fn("createResearchGraph")(function* () {
1387
1418
  const queue = yield* QueueService.createQueue();
1388
- return yield* Database6.Service.add(Obj5.make(ResearchGraph, {
1389
- queue: Ref2.fromDXN(queue.dxn)
1419
+ return yield* Database7.add(Obj6.make(ResearchGraph, {
1420
+ queue: Ref3.fromDXN(queue.dxn)
1390
1421
  }));
1391
1422
  });
1392
- var contextQueueLayerFromResearchGraph = Layer2.unwrapEffect(Effect9.gen(function* () {
1423
+ var contextQueueLayerFromResearchGraph = Layer2.unwrapEffect(Effect10.gen(function* () {
1393
1424
  const researchGraph = (yield* queryResearchGraph()) ?? (yield* createResearchGraph());
1394
- const researchQueue = yield* Database6.Service.load(researchGraph.queue);
1425
+ const researchQueue = yield* Database7.load(researchGraph.queue);
1395
1426
  return ContextQueueService2.layer(researchQueue);
1396
1427
  }));
1397
1428
 
@@ -1400,7 +1431,7 @@ var research_instructions_default = "You are the Research Agent.\n\nThe Research
1400
1431
 
1401
1432
  // src/functions/research/types.ts
1402
1433
  import { Text } from "@dxos/schema";
1403
- import { Event, HasConnection, HasRelationship, LegacyOrganization, LegacyPerson, Project, Task } from "@dxos/types";
1434
+ import { Event, HasConnection, HasRelationship, LegacyOrganization, LegacyPerson, Pipeline, Task } from "@dxos/types";
1404
1435
  var ResearchDataTypes = [
1405
1436
  // Objects
1406
1437
  Event.Event,
@@ -1411,13 +1442,13 @@ var ResearchDataTypes = [
1411
1442
  // TODO(wittjosiah): Until views (e.g., Table) support relations this needs to be expressed via organization ref.
1412
1443
  // Employer.Employer,
1413
1444
  LegacyPerson,
1414
- Project.Project,
1445
+ Pipeline.Pipeline,
1415
1446
  HasRelationship.HasRelationship,
1416
1447
  HasConnection.HasConnection
1417
1448
  ];
1418
1449
 
1419
1450
  // src/functions/research/research.ts
1420
- var research_default = defineFunction8({
1451
+ var research_default = defineFunction9({
1421
1452
  key: "dxos.org/function/research",
1422
1453
  name: "Research",
1423
1454
  description: trim3`
@@ -1425,24 +1456,24 @@ var research_default = defineFunction8({
1425
1456
  Inserts structured data into the research graph.
1426
1457
  Creates a research summary and returns the objects created.
1427
1458
  `,
1428
- inputSchema: Schema10.Struct({
1429
- query: Schema10.String.annotations({
1459
+ inputSchema: Schema11.Struct({
1460
+ query: Schema11.String.annotations({
1430
1461
  description: trim3`
1431
1462
  The search query.
1432
1463
  If doing research on an object then load it first and pass it as JSON.
1433
1464
  `
1434
1465
  }),
1435
- instructions: Schema10.optional(Schema10.String).annotations({
1466
+ instructions: Schema11.optional(Schema11.String).annotations({
1436
1467
  description: trim3`
1437
1468
  The instructions for the research agent.
1438
1469
  `
1439
1470
  }),
1440
1471
  // TOOD(burdon): Move to context.
1441
- mockSearch: Schema10.optional(Schema10.Boolean).annotations({
1472
+ mockSearch: Schema11.optional(Schema11.Boolean).annotations({
1442
1473
  description: "Whether to use the mock search tool.",
1443
1474
  default: false
1444
1475
  }),
1445
- entityExtraction: Schema10.optional(Schema10.Boolean).annotations({
1476
+ entityExtraction: Schema11.optional(Schema11.Boolean).annotations({
1446
1477
  description: trim3`
1447
1478
  Whether to extract structured entities from the research.
1448
1479
  Experimental feature only enable if user explicitly requests it.
@@ -1450,17 +1481,17 @@ var research_default = defineFunction8({
1450
1481
  default: false
1451
1482
  })
1452
1483
  }),
1453
- outputSchema: Schema10.Struct({
1454
- document: Schema10.optional(Schema10.String).annotations({
1484
+ outputSchema: Schema11.Struct({
1485
+ document: Schema11.optional(Schema11.String).annotations({
1455
1486
  description: "The generated research document."
1456
1487
  }),
1457
- objects: Schema10.Array(Schema10.Unknown).annotations({
1488
+ objects: Schema11.Array(Schema11.Unknown).annotations({
1458
1489
  description: "Structured objects created during the research process."
1459
1490
  })
1460
1491
  }),
1461
- handler: Effect10.fnUntraced(function* ({ data: { query, instructions: instructions6, mockSearch = false, entityExtraction = false } }) {
1492
+ handler: Effect11.fnUntraced(function* ({ data: { query, instructions: instructions7, mockSearch = false, entityExtraction = false } }) {
1462
1493
  if (mockSearch) {
1463
- const mockPerson = yield* Database7.Service.add(Obj6.make(Person.Person, {
1494
+ const mockPerson = yield* Database8.add(Obj7.make(Person.Person, {
1464
1495
  preferredName: "John Doe",
1465
1496
  emails: [
1466
1497
  {
@@ -1476,14 +1507,14 @@ var research_default = defineFunction8({
1476
1507
  return {
1477
1508
  document: trim3`
1478
1509
  The research ran in test-mode and was mocked. Proceed as usual.
1479
- We reference John Doe to test reference: ${Obj6.getDXN(mockPerson)}
1510
+ We reference John Doe to test reference: ${Obj7.getDXN(mockPerson)}
1480
1511
  `,
1481
1512
  objects: [
1482
- Obj6.toJSON(mockPerson)
1513
+ Obj7.toJSON(mockPerson)
1483
1514
  ]
1484
1515
  };
1485
1516
  }
1486
- yield* Database7.Service.flush({
1517
+ yield* Database8.flush({
1487
1518
  indexes: true
1488
1519
  });
1489
1520
  yield* TracingService4.emitStatus({
@@ -1505,34 +1536,26 @@ var research_default = defineFunction8({
1505
1536
  }
1506
1537
  const finishedToolkit = yield* createToolkit2({
1507
1538
  toolkit
1508
- }).pipe(Effect10.provide(handlers));
1539
+ }).pipe(Effect11.provide(handlers));
1509
1540
  const session = new AiSession2();
1510
1541
  const result = yield* session.run({
1511
1542
  prompt: query,
1512
1543
  system: join(Template2.process(research_instructions_default, {
1513
1544
  entityExtraction
1514
- }), instructions6 && `<instructions>${instructions6}</instructions>`),
1545
+ }), instructions7 && `<instructions>${instructions7}</instructions>`),
1515
1546
  toolkit: finishedToolkit,
1516
1547
  observer: GenerationObserver2.fromPrinter(new ConsolePrinter2({
1517
1548
  tag: "research"
1518
1549
  }))
1519
1550
  });
1520
- const objects = yield* Effect10.forEach(objectDXNs, (dxn) => Database7.Service.resolve(dxn)).pipe(Effect10.map(Array6.map((obj) => Obj6.toJSON(obj))));
1551
+ const objects = yield* Effect11.forEach(objectDXNs, (dxn) => Database8.resolve(dxn)).pipe(Effect11.map(Array6.map((obj) => Entity2.toJSON(obj))));
1521
1552
  return {
1522
1553
  document: extractLastTextBlock(result),
1523
1554
  objects
1524
1555
  };
1525
- }, Effect10.provide(Layer3.mergeAll(
1526
- AiService2.model("@anthropic/claude-sonnet-4-0"),
1527
- // TODO(dmaretskyi): Extract.
1528
- makeToolResolverFromFunctions([
1529
- exa_default,
1530
- mock_default
1531
- ], Toolkit2.make()),
1532
- makeToolExecutionServiceFromFunctions(Toolkit2.make(), Layer3.empty)
1533
- ).pipe(Layer3.provide(
1556
+ }, Effect11.provide(Layer3.mergeAll(AiService2.model("@anthropic/claude-sonnet-4-0"), ToolExecutionServices).pipe(Layer3.provide(
1534
1557
  // TODO(dmaretskyi): This should be provided by environment.
1535
- Layer3.mergeAll(FunctionInvocationServiceLayerTestMocked({
1558
+ Layer3.mergeAll(GenericToolkit.providerEmpty, FunctionInvocationServiceLayerTestMocked({
1536
1559
  functions: [
1537
1560
  exa_default,
1538
1561
  mock_default
@@ -1542,7 +1565,7 @@ var research_default = defineFunction8({
1542
1565
  });
1543
1566
  var join = (...strings) => strings.filter(Boolean).join("\n\n");
1544
1567
  var extractLastTextBlock = (result) => {
1545
- return Function4.pipe(result, Array6.last, Option4.map(Function4.flow((_) => _.blocks, Array6.reverse, Array6.dropWhile((_) => _._tag === "summary"), Array6.takeWhile((_) => _._tag === "text"), Array6.reverse, Array6.map((_) => _.text), Array6.reduce("", String10.concat))), Option4.getOrElse(() => ""));
1568
+ return Function4.pipe(result, Array6.last, Option4.map(Function4.flow((_) => _.blocks, Array6.reverse, Array6.dropWhile((_) => _._tag === "summary"), Array6.takeWhile((_) => _._tag === "text"), Array6.reverse, Array6.map((_) => _.text), Array6.reduce("", String11.concat))), Option4.getOrElse(() => ""));
1546
1569
  };
1547
1570
 
1548
1571
  // src/functions/research/index.ts
@@ -1554,26 +1577,26 @@ var Research;
1554
1577
 
1555
1578
  // src/functions/entity-extraction/entity-extraction.ts
1556
1579
  var __dxlog_file5 = "/__w/dxos/dxos/packages/core/assistant-toolkit/src/functions/entity-extraction/entity-extraction.ts";
1557
- var entity_extraction_default = defineFunction9({
1580
+ var entity_extraction_default = defineFunction10({
1558
1581
  key: "dxos.org/functions/entity-extraction",
1559
1582
  name: "Entity Extraction",
1560
1583
  description: "Extracts entities from emails and transcripts.",
1561
- inputSchema: Schema11.Struct({
1584
+ inputSchema: Schema12.Struct({
1562
1585
  source: Message2.Message.annotations({
1563
1586
  description: "Email or transcript to extract entities from."
1564
1587
  }),
1565
1588
  // TODO(dmaretskyi): Consider making this an array of blueprints instead.
1566
- instructions: Schema11.optional(Schema11.String).annotations({
1589
+ instructions: Schema12.optional(Schema12.String).annotations({
1567
1590
  description: "Instructions extraction process."
1568
1591
  })
1569
1592
  }),
1570
- outputSchema: Schema11.Struct({
1571
- entities: Schema11.optional(Schema11.Array(Obj7.Any).annotations({
1593
+ outputSchema: Schema12.Struct({
1594
+ entities: Schema12.optional(Schema12.Array(Type7.Obj).annotations({
1572
1595
  description: "Extracted entities."
1573
1596
  }))
1574
1597
  }),
1575
- handler: Effect11.fnUntraced(function* ({ data: { source: message, instructions: instructions6 } }) {
1576
- const tags = Obj7.getMeta(message)?.tags;
1598
+ handler: Effect12.fnUntraced(function* ({ data: { source: message, instructions: instructions7 } }) {
1599
+ const tags = Obj8.getMeta(message)?.tags;
1577
1600
  const contact = yield* extractContact(message.sender, tags);
1578
1601
  let organization = null;
1579
1602
  if (contact && !contact.organization) {
@@ -1586,12 +1609,12 @@ var entity_extraction_default = defineFunction9({
1586
1609
  const GraphWriterHandler = makeGraphWriterHandler(GraphWriterToolkit, {
1587
1610
  onAppend: (dxns) => created.push(...dxns)
1588
1611
  });
1589
- const toolkit = yield* GraphWriterToolkit.pipe(Effect11.provide(GraphWriterHandler.pipe(Layer4.provide(contextQueueLayerFromResearchGraph))));
1612
+ const toolkit = yield* GraphWriterToolkit.pipe(Effect12.provide(GraphWriterHandler.pipe(Layer4.provide(contextQueueLayerFromResearchGraph))));
1590
1613
  yield* new AiSession3().run({
1591
1614
  system: trim4`
1592
1615
  Extract the sender's organization from the email. If you are not sure, do nothing.
1593
1616
  The extracted organization URL must match the sender's email domain.
1594
- ${instructions6 ? "<user_intructions>" + instructions6 + "</user_intructions>" : ""},
1617
+ ${instructions7 ? "<user_intructions>" + instructions7 + "</user_intructions>" : ""},
1595
1618
  `,
1596
1619
  prompt: JSON.stringify({
1597
1620
  source: message,
@@ -1602,10 +1625,15 @@ var entity_extraction_default = defineFunction9({
1602
1625
  if (created.length > 1) {
1603
1626
  throw new Error("Multiple organizations created");
1604
1627
  } else if (created.length === 1) {
1605
- organization = yield* Database8.Service.resolve(created[0], Organization.Organization);
1606
- Obj7.getMeta(organization).tags ??= [];
1607
- Obj7.getMeta(organization).tags.push(...tags ?? []);
1608
- contact.organization = Ref3.make(organization);
1628
+ organization = yield* Database9.resolve(created[0], Organization.Organization);
1629
+ Obj8.change(organization, (org) => {
1630
+ const meta = Obj8.getMeta(org);
1631
+ meta.tags ??= [];
1632
+ meta.tags.push(...tags ?? []);
1633
+ });
1634
+ Obj8.change(contact, (c) => {
1635
+ c.organization = Ref4.make(organization);
1636
+ });
1609
1637
  }
1610
1638
  }
1611
1639
  return {
@@ -1614,12 +1642,12 @@ var entity_extraction_default = defineFunction9({
1614
1642
  organization
1615
1643
  ].filter(Predicate.isNotNullable)
1616
1644
  };
1617
- }, Effect11.provide(Layer4.mergeAll(AiService3.model("@anthropic/claude-sonnet-4-0"), makeToolResolverFromFunctions2([], Toolkit3.make()), makeToolExecutionServiceFromFunctions2(Toolkit3.make(), Layer4.empty)).pipe(Layer4.provide(
1645
+ }, Effect12.provide(Layer4.mergeAll(AiService3.model("@anthropic/claude-sonnet-4-0"), ToolExecutionServices2).pipe(Layer4.provide(
1618
1646
  // TODO(dmaretskyi): This should be provided by environment.
1619
- Layer4.mergeAll(FunctionInvocationServiceLayerTest())
1647
+ Layer4.mergeAll(GenericToolkit2.providerEmpty, FunctionInvocationServiceLayerTest())
1620
1648
  ))))
1621
1649
  });
1622
- var extractContact = Effect11.fn("extractContact")(function* (actor, tags) {
1650
+ var extractContact = Effect12.fn("extractContact")(function* (actor, tags) {
1623
1651
  const name = actor.name;
1624
1652
  const email = actor.email;
1625
1653
  if (!email) {
@@ -1627,13 +1655,13 @@ var extractContact = Effect11.fn("extractContact")(function* (actor, tags) {
1627
1655
  actor
1628
1656
  }, {
1629
1657
  F: __dxlog_file5,
1630
- L: 107,
1658
+ L: 110,
1631
1659
  S: this,
1632
1660
  C: (f, a) => f(...a)
1633
1661
  });
1634
1662
  return void 0;
1635
1663
  }
1636
- const existingContacts = yield* Database8.Service.runQuery(Filter2.type(Person2.Person));
1664
+ const existingContacts = yield* Database9.runQuery(Filter2.type(Person2.Person));
1637
1665
  const existingContact = existingContacts.find((contact) => contact.emails?.some((contactEmail) => contactEmail.value === email));
1638
1666
  if (existingContact) {
1639
1667
  log5.info("Contact already exists", {
@@ -1641,25 +1669,31 @@ var extractContact = Effect11.fn("extractContact")(function* (actor, tags) {
1641
1669
  existingContact
1642
1670
  }, {
1643
1671
  F: __dxlog_file5,
1644
- L: 120,
1672
+ L: 123,
1645
1673
  S: this,
1646
1674
  C: (f, a) => f(...a)
1647
1675
  });
1648
1676
  return existingContact;
1649
1677
  }
1650
- const newContact = Obj7.make(Person2.Person, {
1651
- [Obj7.Meta]: {
1652
- tags
1653
- },
1678
+ const newContact = Obj8.make(Person2.Person, {
1679
+ ...tags ? {
1680
+ [Obj8.Meta]: {
1681
+ tags: [
1682
+ ...tags
1683
+ ]
1684
+ }
1685
+ } : {},
1654
1686
  emails: [
1655
1687
  {
1656
1688
  value: email
1657
1689
  }
1658
1690
  ]
1659
1691
  });
1660
- yield* Database8.Service.add(newContact);
1692
+ yield* Database9.add(newContact);
1661
1693
  if (name) {
1662
- newContact.fullName = name;
1694
+ Obj8.change(newContact, (c) => {
1695
+ c.fullName = name;
1696
+ });
1663
1697
  }
1664
1698
  const emailDomain = email.split("@")[1]?.toLowerCase();
1665
1699
  if (!emailDomain) {
@@ -1667,7 +1701,7 @@ var extractContact = Effect11.fn("extractContact")(function* (actor, tags) {
1667
1701
  email
1668
1702
  }, {
1669
1703
  F: __dxlog_file5,
1670
- L: 136,
1704
+ L: 141,
1671
1705
  S: this,
1672
1706
  C: (f, a) => f(...a)
1673
1707
  });
@@ -1677,11 +1711,11 @@ var extractContact = Effect11.fn("extractContact")(function* (actor, tags) {
1677
1711
  emailDomain
1678
1712
  }, {
1679
1713
  F: __dxlog_file5,
1680
- L: 140,
1714
+ L: 145,
1681
1715
  S: this,
1682
1716
  C: (f, a) => f(...a)
1683
1717
  });
1684
- const existingOrganisations = yield* Database8.Service.runQuery(Filter2.type(Organization.Organization));
1718
+ const existingOrganisations = yield* Database9.runQuery(Filter2.type(Organization.Organization));
1685
1719
  const matchingOrg = existingOrganisations.find((org) => {
1686
1720
  if (org.website) {
1687
1721
  try {
@@ -1694,7 +1728,7 @@ var extractContact = Effect11.fn("extractContact")(function* (actor, tags) {
1694
1728
  error: e
1695
1729
  }, {
1696
1730
  F: __dxlog_file5,
1697
- L: 158,
1731
+ L: 163,
1698
1732
  S: this,
1699
1733
  C: (f, a) => f(...a)
1700
1734
  });
@@ -1708,11 +1742,13 @@ var extractContact = Effect11.fn("extractContact")(function* (actor, tags) {
1708
1742
  organization: matchingOrg
1709
1743
  }, {
1710
1744
  F: __dxlog_file5,
1711
- L: 169,
1745
+ L: 174,
1712
1746
  S: this,
1713
1747
  C: (f, a) => f(...a)
1714
1748
  });
1715
- newContact.organization = Ref3.make(matchingOrg);
1749
+ Obj8.change(newContact, (c) => {
1750
+ c.organization = Ref4.make(matchingOrg);
1751
+ });
1716
1752
  }
1717
1753
  return newContact;
1718
1754
  });
@@ -1727,58 +1763,58 @@ var EntityExtraction;
1727
1763
  import * as FetchHttpClient2 from "@effect/platform/FetchHttpClient";
1728
1764
  import * as HttpClient from "@effect/platform/HttpClient";
1729
1765
  import * as Array9 from "effect/Array";
1730
- import * as Effect13 from "effect/Effect";
1766
+ import * as Effect14 from "effect/Effect";
1731
1767
  import * as Function5 from "effect/Function";
1732
- import * as Schema12 from "effect/Schema";
1733
- import { Filter as Filter4, Obj as Obj9, Query as Query4, Ref as Ref5 } from "@dxos/echo";
1734
- import { Database as Database10 } from "@dxos/echo";
1735
- import { defineFunction as defineFunction10, withAuthorization } from "@dxos/functions";
1768
+ import * as Schema13 from "effect/Schema";
1769
+ import { Filter as Filter4, Obj as Obj10, Query as Query4, Ref as Ref6 } from "@dxos/echo";
1770
+ import { Database as Database11 } from "@dxos/echo";
1771
+ import { CredentialsService as CredentialsService3, defineFunction as defineFunction11, withAuthorization } from "@dxos/functions";
1736
1772
  import { log as log7 } from "@dxos/log";
1737
- import { Person as Person3, Project as Project2, Task as Task2 } from "@dxos/types";
1773
+ import { Person as Person3, Pipeline as Pipeline2, Task as Task2 } from "@dxos/types";
1738
1774
 
1739
1775
  // src/sync/sync.ts
1740
- import * as Effect12 from "effect/Effect";
1741
- import { Filter as Filter3, Obj as Obj8, Query as Query3, Ref as Ref4 } from "@dxos/echo";
1742
- import { Database as Database9 } from "@dxos/echo";
1776
+ import * as Effect13 from "effect/Effect";
1777
+ import { Filter as Filter3, Obj as Obj9, Query as Query3, Ref as Ref5 } from "@dxos/echo";
1778
+ import { Database as Database10 } from "@dxos/echo";
1743
1779
  import { failedInvariant } from "@dxos/invariant";
1744
1780
  import { log as log6 } from "@dxos/log";
1745
1781
  var __dxlog_file6 = "/__w/dxos/dxos/packages/core/assistant-toolkit/src/sync/sync.ts";
1746
- var syncObjects = Effect12.fn("syncObjects")(function* (objs, { foreignKeyId }) {
1747
- return yield* Effect12.forEach(objs, Effect12.fnUntraced(function* (obj) {
1782
+ var syncObjects = Effect13.fn("syncObjects")(function* (objs, { foreignKeyId }) {
1783
+ return yield* Effect13.forEach(objs, Effect13.fnUntraced(function* (obj) {
1748
1784
  for (const key of Object.keys(obj)) {
1749
1785
  if (typeof key !== "string" || key === "id") continue;
1750
- if (!Ref4.isRef(obj[key])) continue;
1786
+ if (!Ref5.isRef(obj[key])) continue;
1751
1787
  const ref = obj[key];
1752
1788
  if (!ref.target) continue;
1753
- if (Obj8.getDXN(ref.target).isLocalObjectId()) {
1789
+ if (Obj9.getDXN(ref.target).isLocalObjectId()) {
1754
1790
  const [target] = yield* syncObjects([
1755
1791
  ref.target
1756
1792
  ], {
1757
1793
  foreignKeyId
1758
1794
  });
1759
- obj[key] = Ref4.make(target);
1795
+ obj[key] = Ref5.make(target);
1760
1796
  }
1761
1797
  }
1762
- const schema = Obj8.getSchema(obj) ?? failedInvariant("No schema.");
1763
- const foreignId = Obj8.getKeys(obj, foreignKeyId)[0]?.id ?? failedInvariant("No foreign key.");
1764
- const [existing] = yield* Database9.Service.runQuery(Query3.select(Filter3.foreignKeys(schema, [
1798
+ const schema = Obj9.getSchema(obj) ?? failedInvariant("No schema.");
1799
+ const foreignId = Obj9.getKeys(obj, foreignKeyId)[0]?.id ?? failedInvariant("No foreign key.");
1800
+ const [existing] = yield* Database10.runQuery(Query3.select(Filter3.foreignKeys(schema, [
1765
1801
  {
1766
1802
  source: foreignKeyId,
1767
1803
  id: foreignId
1768
1804
  }
1769
1805
  ])));
1770
1806
  log6("sync object", {
1771
- type: Obj8.getTypename(obj),
1807
+ type: Obj9.getTypename(obj),
1772
1808
  foreignId,
1773
- existing: existing ? Obj8.getDXN(existing) : void 0
1809
+ existing: existing ? Obj9.getDXN(existing) : void 0
1774
1810
  }, {
1775
1811
  F: __dxlog_file6,
1776
- L: 45,
1812
+ L: 48,
1777
1813
  S: this,
1778
1814
  C: (f, a) => f(...a)
1779
1815
  });
1780
1816
  if (!existing) {
1781
- yield* Database9.Service.add(obj);
1817
+ yield* Database10.add(obj);
1782
1818
  return obj;
1783
1819
  } else {
1784
1820
  copyObjectData(existing, obj);
@@ -1789,23 +1825,25 @@ var syncObjects = Effect12.fn("syncObjects")(function* (objs, { foreignKeyId })
1789
1825
  });
1790
1826
  });
1791
1827
  var copyObjectData = (existing, newObj) => {
1792
- for (const key of Object.keys(newObj)) {
1793
- if (typeof key !== "string" || key === "id") continue;
1794
- if (typeof newObj[key] !== "string" && typeof newObj[key] !== "number" && typeof newObj[key] !== "boolean" && !Ref4.isRef(newObj[key])) continue;
1795
- existing[key] = newObj[key];
1796
- }
1797
- for (const key of Object.keys(existing)) {
1798
- if (typeof key !== "string" || key === "id") continue;
1799
- if (!(key in newObj)) {
1800
- delete existing[key];
1828
+ Obj9.change(existing, (obj) => {
1829
+ for (const key of Object.keys(newObj)) {
1830
+ if (typeof key !== "string" || key === "id") continue;
1831
+ if (typeof newObj[key] !== "string" && typeof newObj[key] !== "number" && typeof newObj[key] !== "boolean" && !Ref5.isRef(newObj[key])) continue;
1832
+ obj[key] = newObj[key];
1801
1833
  }
1802
- }
1803
- for (const foreignKey of Obj8.getMeta(newObj).keys) {
1804
- Obj8.deleteKeys(existing, foreignKey.source);
1805
- Obj8.getMeta(existing).keys.push({
1806
- ...foreignKey
1807
- });
1808
- }
1834
+ for (const key of Object.keys(obj)) {
1835
+ if (typeof key !== "string" || key === "id") continue;
1836
+ if (!(key in newObj)) {
1837
+ delete obj[key];
1838
+ }
1839
+ }
1840
+ for (const foreignKey of Obj9.getMeta(newObj).keys) {
1841
+ Obj9.deleteKeys(obj, foreignKey.source);
1842
+ Obj9.getMeta(obj).keys.push({
1843
+ ...foreignKey
1844
+ });
1845
+ }
1846
+ });
1809
1847
  };
1810
1848
 
1811
1849
  // src/util/graphql.ts
@@ -1856,25 +1894,26 @@ query Issues($teamId: String!, $after: DateTimeOrDuration!) {
1856
1894
  var LINEAR_ID_KEY = "linear.app/id";
1857
1895
  var LINEAR_TEAM_ID_KEY = "linear.app/teamId";
1858
1896
  var LINEAR_UPDATED_AT_KEY = "linear.app/updatedAt";
1859
- var sync_issues_default = defineFunction10({
1897
+ var sync_issues_default = defineFunction11({
1860
1898
  key: "dxos.org/function/linear/sync-issues",
1861
1899
  name: "Linear",
1862
1900
  description: "Sync issues from Linear.",
1863
- inputSchema: Schema12.Struct({
1864
- team: Schema12.String.annotations({
1901
+ inputSchema: Schema13.Struct({
1902
+ team: Schema13.String.annotations({
1865
1903
  description: "Linear team id."
1866
1904
  })
1867
1905
  }),
1868
- handler: Effect13.fnUntraced(function* ({ data }) {
1869
- const client = yield* HttpClient.HttpClient.pipe(Effect13.map(withAuthorization({
1906
+ handler: Effect14.fnUntraced(function* ({ data }) {
1907
+ const credential = yield* CredentialsService3.getCredential({
1870
1908
  service: "linear.app"
1871
- })));
1909
+ });
1910
+ const client = yield* HttpClient.HttpClient.pipe(Effect14.map(withAuthorization(credential.apiKey)));
1872
1911
  const after = yield* getLatestUpdateTimestamp(data.team, Task2.Task);
1873
1912
  log7.info("will fetch", {
1874
1913
  after
1875
1914
  }, {
1876
1915
  F: __dxlog_file7,
1877
- L: 92,
1916
+ L: 93,
1878
1917
  S: this,
1879
1918
  C: (f, a) => f(...a)
1880
1919
  });
@@ -1892,7 +1931,7 @@ var sync_issues_default = defineFunction10({
1892
1931
  count: tasks.length
1893
1932
  }, {
1894
1933
  F: __dxlog_file7,
1895
- L: 105,
1934
+ L: 106,
1896
1935
  S: this,
1897
1936
  C: (f, a) => f(...a)
1898
1937
  });
@@ -1902,19 +1941,19 @@ var sync_issues_default = defineFunction10({
1902
1941
  }),
1903
1942
  syncComplete: tasks.length < 150
1904
1943
  };
1905
- }, Effect13.provide(FetchHttpClient2.layer))
1944
+ }, Effect14.provide(FetchHttpClient2.layer))
1906
1945
  });
1907
- var getLatestUpdateTimestamp = Effect13.fnUntraced(function* (teamId, dataType) {
1908
- const existingTasks = yield* Database10.Service.runQuery(Query4.type(dataType).select(Filter4.foreignKeys(dataType, [
1946
+ var getLatestUpdateTimestamp = Effect14.fnUntraced(function* (teamId, dataType) {
1947
+ const existingTasks = yield* Database11.runQuery(Query4.type(dataType).select(Filter4.foreignKeys(dataType, [
1909
1948
  {
1910
1949
  source: LINEAR_TEAM_ID_KEY,
1911
1950
  id: teamId
1912
1951
  }
1913
1952
  ])));
1914
- return Function5.pipe(existingTasks, Array9.map((task) => Obj9.getKeys(task, LINEAR_UPDATED_AT_KEY).at(0)?.id), Array9.filter((x) => x !== void 0), Array9.reduce("2025-01-01T00:00:00.000Z", (acc, x) => x > acc ? x : acc));
1953
+ return Function5.pipe(existingTasks, Array9.map((task) => Obj10.getKeys(task, LINEAR_UPDATED_AT_KEY).at(0)?.id), Array9.filter((x) => x !== void 0), Array9.reduce("2025-01-01T00:00:00.000Z", (acc, x) => x > acc ? x : acc));
1915
1954
  });
1916
- var mapLinearPerson = (person, { teamId }) => Obj9.make(Person3.Person, {
1917
- [Obj9.Meta]: {
1955
+ var mapLinearPerson = (person, { teamId }) => Obj10.make(Person3.Person, {
1956
+ [Obj10.Meta]: {
1918
1957
  keys: [
1919
1958
  {
1920
1959
  id: person.id,
@@ -1928,8 +1967,8 @@ var mapLinearPerson = (person, { teamId }) => Obj9.make(Person3.Person, {
1928
1967
  },
1929
1968
  nickname: person.name
1930
1969
  });
1931
- var mapLinearIssue = (issue, { teamId }) => Obj9.make(Task2.Task, {
1932
- [Obj9.Meta]: {
1970
+ var mapLinearIssue = (issue, { teamId }) => Obj10.make(Task2.Task, {
1971
+ [Obj10.Meta]: {
1933
1972
  keys: [
1934
1973
  {
1935
1974
  id: issue.id,
@@ -1947,13 +1986,13 @@ var mapLinearIssue = (issue, { teamId }) => Obj9.make(Task2.Task, {
1947
1986
  },
1948
1987
  title: issue.title ?? void 0,
1949
1988
  description: issue.description ?? void 0,
1950
- assigned: !issue.assignee ? void 0 : Ref5.make(mapLinearPerson(issue.assignee, {
1989
+ assigned: !issue.assignee ? void 0 : Ref6.make(mapLinearPerson(issue.assignee, {
1951
1990
  teamId
1952
1991
  })),
1953
1992
  // TODO(dmaretskyi): Sync those (+ linear team as org?).
1954
1993
  // state: issue.state.name,
1955
- project: !issue.project ? void 0 : Ref5.make(Project2.make({
1956
- [Obj9.Meta]: {
1994
+ project: !issue.project ? void 0 : Ref6.make(Pipeline2.make({
1995
+ [Obj10.Meta]: {
1957
1996
  keys: [
1958
1997
  {
1959
1998
  id: issue.project.id,
@@ -1976,27 +2015,26 @@ var mapLinearIssue = (issue, { teamId }) => Obj9.make(Task2.Task, {
1976
2015
  var Linear;
1977
2016
 
1978
2017
  // src/functions/tasks/read.ts
1979
- import * as Effect14 from "effect/Effect";
1980
- import * as Schema13 from "effect/Schema";
1981
- import { ArtifactId as ArtifactId4 } from "@dxos/assistant";
1982
- import { Database as Database11 } from "@dxos/echo";
1983
- import { defineFunction as defineFunction11 } from "@dxos/functions";
1984
- import { Markdown as Markdown4 } from "@dxos/plugin-markdown/types";
1985
- var read_default2 = defineFunction11({
2018
+ import * as Effect15 from "effect/Effect";
2019
+ import * as Schema14 from "effect/Schema";
2020
+ import { Database as Database12, Type as Type8 } from "@dxos/echo";
2021
+ import { defineFunction as defineFunction12 } from "@dxos/functions";
2022
+ import { Markdown as Markdown5 } from "@dxos/plugin-markdown/types";
2023
+ var read_default2 = defineFunction12({
1986
2024
  key: "dxos.org/function/markdown/read-tasks",
1987
2025
  name: "Read",
1988
2026
  description: "Read markdown tasks.",
1989
- inputSchema: Schema13.Struct({
1990
- id: ArtifactId4.annotations({
2027
+ inputSchema: Schema14.Struct({
2028
+ doc: Type8.Ref(Markdown5.Document).annotations({
1991
2029
  description: "The ID of the document to read."
1992
2030
  })
1993
2031
  }),
1994
- outputSchema: Schema13.Struct({
1995
- content: Schema13.String
2032
+ outputSchema: Schema14.Struct({
2033
+ content: Schema14.String
1996
2034
  }),
1997
- handler: Effect14.fn(function* ({ data: { id } }) {
1998
- const doc = yield* Database11.Service.resolve(ArtifactId4.toDXN(id), Markdown4.Document);
1999
- const { content } = yield* Database11.Service.load(doc.content);
2035
+ handler: Effect15.fn(function* ({ data: { doc } }) {
2036
+ const document = yield* Database12.load(doc);
2037
+ const { content } = yield* Database12.load(document.content);
2000
2038
  const lines = content.split("\n");
2001
2039
  const len = String(lines.length).length;
2002
2040
  const numbered = lines.map((line, i) => `${String(i + 1).padStart(len, " ")}. ${line}`).join("\n");
@@ -2007,12 +2045,11 @@ var read_default2 = defineFunction11({
2007
2045
  });
2008
2046
 
2009
2047
  // src/functions/tasks/update.ts
2010
- import * as Effect15 from "effect/Effect";
2011
- import * as Schema14 from "effect/Schema";
2012
- import { ArtifactId as ArtifactId5 } from "@dxos/assistant";
2013
- import { Database as Database12 } from "@dxos/echo";
2014
- import { defineFunction as defineFunction12 } from "@dxos/functions";
2015
- import { Markdown as Markdown5 } from "@dxos/plugin-markdown/types";
2048
+ import * as Effect16 from "effect/Effect";
2049
+ import * as Schema15 from "effect/Schema";
2050
+ import { Database as Database13, Type as Type9 } from "@dxos/echo";
2051
+ import { defineFunction as defineFunction13 } from "@dxos/functions";
2052
+ import { Markdown as Markdown6 } from "@dxos/plugin-markdown/types";
2016
2053
 
2017
2054
  // src/functions/tasks/task-list.ts
2018
2055
  var MarkdownTasks = class {
@@ -2143,27 +2180,27 @@ var MarkdownTasks = class {
2143
2180
  };
2144
2181
 
2145
2182
  // src/functions/tasks/update.ts
2146
- var update_default2 = defineFunction12({
2183
+ var update_default2 = defineFunction13({
2147
2184
  key: "dxos.org/function/markdown/update-tasks",
2148
2185
  name: "Update markdown",
2149
2186
  description: "Creates and updates tasks in markdown documents.",
2150
- inputSchema: Schema14.Struct({
2151
- id: ArtifactId5.annotations({
2187
+ inputSchema: Schema15.Struct({
2188
+ doc: Type9.Ref(Markdown6.Document).annotations({
2152
2189
  description: "The ID of the document to update."
2153
2190
  }),
2154
- operations: Schema14.optional(Schema14.Array(Schema14.Any.annotations({
2191
+ operations: Schema15.optional(Schema15.Array(Schema15.Any.annotations({
2155
2192
  description: "Task operations to apply."
2156
2193
  })))
2157
2194
  }),
2158
- outputSchema: Schema14.Struct({
2159
- content: Schema14.String,
2160
- numberedContent: Schema14.String.annotations({
2195
+ outputSchema: Schema15.Struct({
2196
+ content: Schema15.String,
2197
+ numberedContent: Schema15.String.annotations({
2161
2198
  description: "Content with line numbers for agent reference."
2162
2199
  })
2163
2200
  }),
2164
- handler: Effect15.fn(function* ({ data: { id, operations = [] } }) {
2165
- const doc = yield* Database12.Service.resolve(ArtifactId5.toDXN(id), Markdown5.Document);
2166
- const { content } = yield* Database12.Service.load(doc.content);
2201
+ handler: Effect16.fn(function* ({ data: { doc, operations = [] } }) {
2202
+ const document = yield* Database13.load(doc);
2203
+ const { content } = yield* Database13.load(document.content);
2167
2204
  const taskManager = new MarkdownTasks(content);
2168
2205
  if (operations.length > 0) {
2169
2206
  taskManager.applyOperations(operations);
@@ -2192,27 +2229,26 @@ var instructions = trim5`
2192
2229
  When replying to the user, be terse with your comments about design doc handling.
2193
2230
  Do not announce when you read or write the design spec document.
2194
2231
  `;
2195
- var blueprint = Obj10.make(Blueprint.Blueprint, {
2232
+ var blueprint = Blueprint.make({
2196
2233
  key: "dxos.org/blueprint/design",
2197
2234
  name: "Design Spec",
2198
2235
  description: "Preserve the conversation in the design spec.",
2199
2236
  instructions: {
2200
- source: Ref6.make(Text2.make(instructions))
2237
+ source: Ref7.make(Text2.make(instructions))
2201
2238
  },
2202
2239
  tools: [
2203
2240
  Document.read,
2204
2241
  Document.update
2205
- ].map((fn9) => ToolId.make(fn9.key))
2242
+ ].map((fn11) => ToolId.make(fn11.key))
2206
2243
  });
2207
- var design_blueprint_default = blueprint;
2208
2244
 
2209
2245
  // src/blueprints/design/index.ts
2210
- var design_default = design_blueprint_default;
2246
+ var design_default = blueprint;
2211
2247
 
2212
2248
  // src/blueprints/discord/discord-blueprint.ts
2213
2249
  import { ToolId as ToolId2 } from "@dxos/ai";
2214
2250
  import { Blueprint as Blueprint2 } from "@dxos/blueprints";
2215
- import { Obj as Obj11, Ref as Ref7 } from "@dxos/echo";
2251
+ import { Ref as Ref8 } from "@dxos/echo";
2216
2252
  import { Text as Text3 } from "@dxos/schema";
2217
2253
  import { trim as trim6 } from "@dxos/util";
2218
2254
  var instructions2 = trim6`
@@ -2222,26 +2258,25 @@ var instructions2 = trim6`
2222
2258
 
2223
2259
  DXOS serverId: 837138313172353095
2224
2260
  `;
2225
- var blueprint2 = Obj11.make(Blueprint2.Blueprint, {
2261
+ var blueprint2 = Blueprint2.make({
2226
2262
  key: "dxos.org/blueprint/discord",
2227
2263
  name: "Discord",
2228
2264
  description: "Discord integration.",
2229
2265
  instructions: {
2230
- source: Ref7.make(Text3.make(instructions2))
2266
+ source: Ref8.make(Text3.make(instructions2))
2231
2267
  },
2232
2268
  tools: [
2233
2269
  ToolId2.make(Discord.fetch.key)
2234
2270
  ]
2235
2271
  });
2236
- var discord_blueprint_default = blueprint2;
2237
2272
 
2238
2273
  // src/blueprints/discord/index.ts
2239
- var discord_default = discord_blueprint_default;
2274
+ var discord_default = blueprint2;
2240
2275
 
2241
2276
  // src/blueprints/linear/linear-blueprint.ts
2242
2277
  import { ToolId as ToolId3 } from "@dxos/ai";
2243
2278
  import { Blueprint as Blueprint3 } from "@dxos/blueprints";
2244
- import { Obj as Obj12, Ref as Ref8 } from "@dxos/echo";
2279
+ import { Ref as Ref9 } from "@dxos/echo";
2245
2280
  import { Text as Text4 } from "@dxos/schema";
2246
2281
  import { trim as trim7 } from "@dxos/util";
2247
2282
  var instructions3 = trim7`
@@ -2252,26 +2287,25 @@ var instructions3 = trim7`
2252
2287
 
2253
2288
  DXOS teamId: 1127c63a-6f77-4725-9229-50f6cd47321c
2254
2289
  `;
2255
- var blueprint3 = Obj12.make(Blueprint3.Blueprint, {
2290
+ var blueprint3 = Blueprint3.make({
2256
2291
  key: "dxos.org/blueprint/linear",
2257
2292
  name: "Linear",
2258
2293
  description: "Syncs Linear workspaces.",
2259
2294
  instructions: {
2260
- source: Ref8.make(Text4.make(instructions3))
2295
+ source: Ref9.make(Text4.make(instructions3))
2261
2296
  },
2262
2297
  tools: [
2263
2298
  Linear.sync
2264
2299
  ].map((tool) => ToolId3.make(tool.key))
2265
2300
  });
2266
- var linear_blueprint_default = blueprint3;
2267
2301
 
2268
2302
  // src/blueprints/linear/index.ts
2269
- var linear_default = linear_blueprint_default;
2303
+ var linear_default = blueprint3;
2270
2304
 
2271
2305
  // src/blueprints/planning/planning-blueprint.ts
2272
2306
  import { ToolId as ToolId4 } from "@dxos/ai";
2273
2307
  import { Blueprint as Blueprint4 } from "@dxos/blueprints";
2274
- import { Obj as Obj13, Ref as Ref9 } from "@dxos/echo";
2308
+ import { Ref as Ref10 } from "@dxos/echo";
2275
2309
  import { Text as Text5 } from "@dxos/schema";
2276
2310
  import { trim as trim8 } from "@dxos/util";
2277
2311
  var instructions4 = trim8`
@@ -2345,27 +2379,26 @@ var instructions4 = trim8`
2345
2379
  - When creating subtasks, consider the parent task's completion status
2346
2380
  - Be precise with task descriptions and hierarchy levels
2347
2381
  `;
2348
- var blueprint4 = Obj13.make(Blueprint4.Blueprint, {
2382
+ var blueprint4 = Blueprint4.make({
2349
2383
  key: "dxos.org/blueprint/planning",
2350
2384
  name: "Planning",
2351
2385
  description: "Plans and tracks complex tasks with artifact management.",
2352
2386
  instructions: {
2353
- source: Ref9.make(Text5.make(instructions4))
2387
+ source: Ref10.make(Text5.make(instructions4))
2354
2388
  },
2355
2389
  tools: [
2356
2390
  Tasks.read,
2357
2391
  Tasks.update
2358
- ].map((fn9) => ToolId4.make(fn9.key))
2392
+ ].map((fn11) => ToolId4.make(fn11.key))
2359
2393
  });
2360
- var planning_blueprint_default = blueprint4;
2361
2394
 
2362
2395
  // src/blueprints/planning/index.ts
2363
- var planning_default = planning_blueprint_default;
2396
+ var planning_default = blueprint4;
2364
2397
 
2365
2398
  // src/blueprints/research/research-blueprint.ts
2366
2399
  import { ToolId as ToolId5 } from "@dxos/ai";
2367
2400
  import { Blueprint as Blueprint5 } from "@dxos/blueprints";
2368
- import { Obj as Obj14, Ref as Ref10 } from "@dxos/echo";
2401
+ import { Ref as Ref11 } from "@dxos/echo";
2369
2402
  import { Text as Text6 } from "@dxos/schema";
2370
2403
  import { trim as trim9 } from "@dxos/util";
2371
2404
  var instructions5 = trim9`
@@ -2394,85 +2427,650 @@ var instructions5 = trim9`
2394
2427
  Reply normally with the text mode of the result of your research.
2395
2428
  </unstructured_mode>
2396
2429
  `;
2397
- var blueprint5 = Obj14.make(Blueprint5.Blueprint, {
2430
+ var blueprint5 = Blueprint5.make({
2398
2431
  key: "dxos.org/blueprint/research",
2399
2432
  name: "Research",
2400
2433
  description: "Researches the web and creates structured data.",
2401
2434
  instructions: {
2402
- source: Ref10.make(Text6.make(instructions5))
2435
+ source: Ref11.make(Text6.make(instructions5))
2403
2436
  },
2404
2437
  tools: [
2405
2438
  Research.create,
2406
2439
  Research.research
2407
- ].map((fn9) => ToolId5.make(fn9.key))
2440
+ ].map((fn11) => ToolId5.make(fn11.key))
2408
2441
  });
2409
- var research_blueprint_default = blueprint5;
2410
2442
 
2411
2443
  // src/blueprints/research/index.ts
2412
- var research_default2 = research_blueprint_default;
2444
+ var research_default2 = blueprint5;
2413
2445
 
2414
2446
  // src/blueprints/websearch/websearch-blueprint.ts
2415
2447
  import { ToolId as ToolId6 } from "@dxos/ai";
2416
2448
  import { Blueprint as Blueprint6 } from "@dxos/blueprints";
2417
- import { Obj as Obj15, Ref as Ref11 } from "@dxos/echo";
2449
+ import { Ref as Ref12 } from "@dxos/echo";
2418
2450
  import { Text as Text7 } from "@dxos/schema";
2419
- var blueprint6 = Obj15.make(Blueprint6.Blueprint, {
2451
+ var blueprint6 = Blueprint6.make({
2420
2452
  key: "dxos.org/blueprint/web-search",
2421
2453
  name: "Web Search",
2422
2454
  description: "Search the web.",
2423
2455
  instructions: {
2424
- source: Ref11.make(Text7.make())
2456
+ source: Ref12.make(Text7.make())
2425
2457
  },
2426
2458
  tools: [
2427
2459
  ToolId6.make("AnthropicWebSearch")
2428
2460
  ]
2429
2461
  });
2430
- var websearch_blueprint_default = blueprint6;
2431
2462
 
2432
2463
  // src/blueprints/websearch/websearch-toolkit.ts
2433
- import * as Toolkit4 from "@effect/ai/Toolkit";
2464
+ import * as Toolkit3 from "@effect/ai/Toolkit";
2434
2465
  import * as AnthropicTool2 from "@effect/ai-anthropic/AnthropicTool";
2435
- var WebSearchToolkit = Toolkit4.make(AnthropicTool2.WebSearch_20250305({}));
2466
+ var WebSearchToolkit = Toolkit3.make(AnthropicTool2.WebSearch_20250305({}));
2436
2467
 
2437
2468
  // src/blueprints/websearch/index.ts
2438
- var websearch_default = websearch_blueprint_default;
2469
+ var websearch_default = blueprint6;
2439
2470
 
2440
- // src/plugins.tsx
2441
- import * as Schema15 from "effect/Schema";
2442
- import React from "react";
2443
- import { Capabilities, contributes, createSurface } from "@dxos/app-framework";
2444
- import { Format, Type as Type4 } from "@dxos/echo";
2445
- import { JsonFilter } from "@dxos/react-ui-syntax-highlighter";
2446
- var MapSchema = Schema15.Struct({
2447
- coordinates: Format.GeoPoint
2448
- }).pipe(Type4.Obj({
2449
- typename: "example.com/type/Map",
2471
+ // src/blueprints/markdown/markdown-blueprint.ts
2472
+ import { Blueprint as Blueprint7 } from "@dxos/blueprints";
2473
+ import { Ref as Ref13 } from "@dxos/echo";
2474
+ import { Text as Text8 } from "@dxos/schema";
2475
+ import { trim as trim10 } from "@dxos/util";
2476
+ var instructions6 = trim10`
2477
+ You read, write & create markdown documents.
2478
+ `;
2479
+ var blueprint7 = Blueprint7.make({
2480
+ key: "dxos.org/blueprint/markdown",
2481
+ name: "Markdown",
2482
+ description: "Work with markdown documents.",
2483
+ instructions: {
2484
+ source: Ref13.make(Text8.make(instructions6))
2485
+ },
2486
+ tools: Blueprint7.toolDefinitions({
2487
+ functions: [
2488
+ Document.read,
2489
+ Document.update,
2490
+ Document.create
2491
+ ]
2492
+ })
2493
+ });
2494
+
2495
+ // src/blueprints/markdown/index.ts
2496
+ var markdown_default = blueprint7;
2497
+
2498
+ // src/chat/Chat.ts
2499
+ var Chat_exports = {};
2500
+ __export(Chat_exports, {
2501
+ Chat: () => Chat,
2502
+ CompanionTo: () => CompanionTo,
2503
+ make: () => make7
2504
+ });
2505
+ import * as Schema16 from "effect/Schema";
2506
+ import { Obj as Obj11, Type as Type10 } from "@dxos/echo";
2507
+ import { FormInputAnnotation, LabelAnnotation } from "@dxos/echo/internal";
2508
+ import { Queue as Queue2 } from "@dxos/echo-db";
2509
+ var Chat = Schema16.Struct({
2510
+ name: Schema16.String.pipe(Schema16.optional),
2511
+ queue: Type10.Ref(Queue2).pipe(FormInputAnnotation.set(false)),
2512
+ // TODO(dmaretskyi): Eventually this and the message queue will be the same.
2513
+ traceQueue: Type10.Ref(Queue2).pipe(FormInputAnnotation.set(false), Schema16.optional)
2514
+ }).pipe(Type10.object({
2515
+ typename: "dxos.org/type/assistant/Chat",
2516
+ version: "0.2.0"
2517
+ }), LabelAnnotation.set([
2518
+ "name"
2519
+ ]));
2520
+ var make7 = (props) => Obj11.make(Chat, props);
2521
+ var CompanionTo = Schema16.Struct({
2522
+ id: Obj11.ID
2523
+ }).pipe(Type10.relation({
2524
+ typename: "dxos.org/relation/assistant/CompanionTo",
2525
+ version: "0.1.0",
2526
+ source: Chat,
2527
+ target: Type10.Obj
2528
+ }));
2529
+
2530
+ // src/initiative/index.ts
2531
+ var initiative_exports = {};
2532
+ __export(initiative_exports, {
2533
+ Initiative: () => Initiative,
2534
+ Plan: () => Plan,
2535
+ Task: () => Task3,
2536
+ TaskId: () => TaskId,
2537
+ addArtifact: () => addArtifact_default,
2538
+ addTasks: () => addTasks,
2539
+ agent: () => agent_default,
2540
+ formatPlan: () => formatPlan,
2541
+ generateTaskId: () => generateTaskId,
2542
+ getContext: () => getContext_default,
2543
+ getFromChatContext: () => getFromChatContext,
2544
+ getFunctions: () => getFunctions,
2545
+ makeBlueprint: () => makeBlueprint,
2546
+ makeInitialized: () => makeInitialized,
2547
+ makePlan: () => makePlan,
2548
+ qualifier: () => qualifier_default,
2549
+ resetChatHistory: () => resetChatHistory
2550
+ });
2551
+
2552
+ // src/initiative/Initiative.ts
2553
+ import * as Schema18 from "effect/Schema";
2554
+ import { Type as Type12 } from "@dxos/echo";
2555
+ import { Queue as Queue3 } from "@dxos/echo-db";
2556
+ import { QueueAnnotation, Text as Text9 } from "@dxos/schema";
2557
+
2558
+ // src/initiative/plan.ts
2559
+ import * as Schema17 from "effect/Schema";
2560
+ import { Obj as Obj12, Type as Type11 } from "@dxos/echo";
2561
+ var TaskId = Schema17.String.pipe(Schema17.brand("@dxos/assistant-toolkit/TaskId"));
2562
+ var Task3 = Schema17.Struct({
2563
+ /**
2564
+ * Short task ID unique within the plan.
2565
+ */
2566
+ id: TaskId,
2567
+ title: Schema17.String.annotations({
2568
+ description: "Task title and description."
2569
+ }),
2570
+ status: Schema17.Literal("todo", "in-progress", "done"),
2571
+ /**
2572
+ * Parent task ID.
2573
+ */
2574
+ parent: Schema17.optional(TaskId).annotations({
2575
+ description: "Parent task ID."
2576
+ }),
2577
+ /**
2578
+ * Chat object that this task is associated with.
2579
+ */
2580
+ chat: Schema17.optional(Type11.Ref(Chat))
2581
+ });
2582
+ var Plan = Schema17.Struct({
2583
+ tasks: Schema17.Array(Task3)
2584
+ }).pipe(Type11.object({
2585
+ typename: "dxos.org/type/Plan",
2450
2586
  version: "0.1.0"
2451
2587
  }));
2452
- var isImage = (data) => false;
2453
- var capabilities = [
2454
- contributes(Capabilities.ReactSurface, createSurface({
2455
- id: "plugin-image",
2456
- role: "card--extrinsic",
2457
- filter: (data) => isImage(data.value),
2458
- component: ({ data }) => /* @__PURE__ */ React.createElement("img", {
2459
- className: "grow object-cover",
2460
- src: `data:image/jpeg;base64,${data.value.source.data}`,
2461
- alt: data.value.prompt ?? `Generated image [id=${data.value.id}]`
2462
- })
2588
+ var generateTaskId = (plan) => {
2589
+ const existingIds = plan.tasks.map((task) => {
2590
+ const [num, letter] = task.id.split("-");
2591
+ return parseInt(num);
2592
+ }).filter((_) => !isNaN(_));
2593
+ let newId;
2594
+ if (existingIds.length === 0) {
2595
+ newId = 1;
2596
+ } else {
2597
+ newId = Math.max(...existingIds) + 1;
2598
+ }
2599
+ return TaskId.make(`${newId}-${crypto.randomUUID().slice(0, 2)}`);
2600
+ };
2601
+ var addTasks = (plan, tasks) => {
2602
+ for (const task of tasks) {
2603
+ const taskId = generateTaskId(plan);
2604
+ plan.tasks.push({
2605
+ id: taskId,
2606
+ ...task,
2607
+ status: task.status ?? "todo"
2608
+ });
2609
+ }
2610
+ return plan;
2611
+ };
2612
+ var makePlan = (props) => {
2613
+ const plan = Obj12.make(Plan, {
2614
+ tasks: []
2615
+ });
2616
+ Obj12.change(plan, (plan2) => {
2617
+ addTasks(plan2, props.tasks);
2618
+ });
2619
+ return plan;
2620
+ };
2621
+ var formatPlan = (plan) => {
2622
+ return plan.tasks.map((task) => `- **${task.status?.toLocaleUpperCase()}**: ${task.title ?? "No title"} <!-- id=${task.id} -->`).join("\n");
2623
+ };
2624
+
2625
+ // src/initiative/Initiative.ts
2626
+ var Initiative = Schema18.Struct({
2627
+ name: Schema18.String,
2628
+ spec: Type12.Ref(Text9.Text),
2629
+ plan: Type12.Ref(Plan),
2630
+ artifacts: Schema18.Array(Schema18.Struct({
2631
+ // TODO(dmaretskyi): Consider gettings names from the artifact itself using Obj.getLabel.
2632
+ name: Schema18.String,
2633
+ data: Type12.Ref(Type12.Obj)
2463
2634
  })),
2464
- //
2465
- // Default
2466
- //
2467
- contributes(Capabilities.ReactSurface, createSurface({
2468
- id: "plugin-default",
2469
- role: "card--extrinsic",
2470
- position: "fallback",
2471
- component: ({ data }) => /* @__PURE__ */ React.createElement(JsonFilter, {
2472
- data
2635
+ /**
2636
+ * Incoming queue that the agent processes.
2637
+ */
2638
+ // NOTE: Named `queue` to conform to subscribable schema (see QueueAnnotation).
2639
+ queue: Schema18.optional(Type12.Ref(Queue3)),
2640
+ // TODO(dmaretskyi): Multiple chats.
2641
+ chat: Schema18.optional(Type12.Ref(Chat)),
2642
+ /**
2643
+ * Objects to subscribe to.
2644
+ * References to objects with a a canonical queue property.
2645
+ * Schema must have the QueueAnnotation.
2646
+ */
2647
+ // TODO(dmaretskyi): Turn into an array of objects when form-data
2648
+ subscriptions: Schema18.Array(Type12.Ref(Type12.Obj)),
2649
+ useQualifyingAgent: Schema18.optional(Schema18.Boolean),
2650
+ newChatOnEveryEvent: Schema18.optional(Schema18.Boolean)
2651
+ }).pipe(Type12.object({
2652
+ typename: "dxos.org/type/Initiative",
2653
+ version: "0.1.0"
2654
+ }), QueueAnnotation.set(true));
2655
+
2656
+ // src/initiative/util.ts
2657
+ import * as Effect17 from "effect/Effect";
2658
+ import * as Function6 from "effect/Function";
2659
+ import { AiContextBinder, AiContextService } from "@dxos/assistant";
2660
+ import { Database as Database14, Obj as Obj13, Ref as Ref14, Relation as Relation2 } from "@dxos/echo";
2661
+ import { acquireReleaseResource } from "@dxos/effect";
2662
+ import { QueueService as QueueService2 } from "@dxos/functions";
2663
+ import { invariant } from "@dxos/invariant";
2664
+ import { Text as Text10 } from "@dxos/schema";
2665
+ var __dxlog_file8 = "/__w/dxos/dxos/packages/core/assistant-toolkit/src/initiative/util.ts";
2666
+ var makeInitialized = (props, blueprint8) => Effect17.gen(function* () {
2667
+ const initiative = Obj13.make(Initiative, {
2668
+ ...props,
2669
+ spec: Ref14.make(Text10.make(props.spec)),
2670
+ plan: Ref14.make(makePlan({
2671
+ tasks: []
2672
+ })),
2673
+ artifacts: props.artifacts ?? [],
2674
+ subscriptions: props.subscriptions ?? []
2675
+ });
2676
+ yield* Database14.add(initiative);
2677
+ const queue = yield* QueueService2.createQueue();
2678
+ const contextBinder = new AiContextBinder({
2679
+ queue
2680
+ });
2681
+ const initiativeBlueprint = yield* Database14.add(Obj13.clone(blueprint8, {
2682
+ deep: true
2683
+ }));
2684
+ yield* Effect17.promise(() => contextBinder.bind({
2685
+ blueprints: [
2686
+ Ref14.make(initiativeBlueprint),
2687
+ ...props.blueprints ?? []
2688
+ ],
2689
+ objects: [
2690
+ Ref14.make(initiative),
2691
+ ...props.contextObjects ?? []
2692
+ ]
2693
+ }));
2694
+ const chat = yield* Database14.add(make7({
2695
+ queue: Ref14.fromDXN(queue.dxn)
2696
+ }));
2697
+ yield* Database14.add(Relation2.make(CompanionTo, {
2698
+ [Relation2.Source]: chat,
2699
+ [Relation2.Target]: initiative
2700
+ }));
2701
+ const inputQueue = yield* QueueService2.createQueue();
2702
+ Obj13.change(initiative, (initiative2) => {
2703
+ initiative2.chat = Ref14.make(chat);
2704
+ initiative2.queue = Ref14.fromDXN(inputQueue.dxn);
2705
+ });
2706
+ return initiative;
2707
+ });
2708
+ var resetChatHistory = (initiative) => Effect17.gen(function* () {
2709
+ invariant(initiative.chat, "Initiative must have an existing chat to reset.", {
2710
+ F: __dxlog_file8,
2711
+ L: 91,
2712
+ S: this,
2713
+ A: [
2714
+ "initiative.chat",
2715
+ "'Initiative must have an existing chat to reset.'"
2716
+ ]
2717
+ });
2718
+ const existingQueue = yield* initiative.chat.pipe(Database14.load).pipe(Effect17.map((_) => _.queue), Effect17.flatMap(Database14.load));
2719
+ const existingContextBinder = yield* acquireReleaseResource(() => new AiContextBinder({
2720
+ queue: existingQueue
2721
+ }));
2722
+ const blueprints = existingContextBinder.getBlueprints().map((blueprint8) => Ref14.make(blueprint8));
2723
+ const objects = existingContextBinder.getObjects().map((object) => Ref14.make(object));
2724
+ const queue = yield* QueueService2.createQueue();
2725
+ const contextBinder = new AiContextBinder({
2726
+ queue
2727
+ });
2728
+ yield* Effect17.promise(() => contextBinder.bind({
2729
+ blueprints,
2730
+ objects
2731
+ }));
2732
+ const chat = yield* Database14.add(make7({
2733
+ queue: Ref14.fromDXN(queue.dxn)
2734
+ }));
2735
+ Obj13.change(initiative, (initiative2) => {
2736
+ initiative2.chat = Ref14.make(chat);
2737
+ });
2738
+ yield* Database14.add(Relation2.make(CompanionTo, {
2739
+ [Relation2.Source]: chat,
2740
+ [Relation2.Target]: initiative
2741
+ }));
2742
+ }).pipe(Effect17.scoped);
2743
+ var getFromChatContext = Effect17.gen(function* () {
2744
+ const initiatives = yield* Function6.pipe(AiContextService.findObjects(Initiative));
2745
+ if (initiatives.length !== 1) {
2746
+ throw new Error("There should be exactly one initiative in context. Got: " + initiatives.length);
2747
+ }
2748
+ const initiative = initiatives[0];
2749
+ return initiative;
2750
+ });
2751
+
2752
+ // src/initiative/blueprint.ts
2753
+ import { Blueprint as Blueprint8, Template as Template3 } from "@dxos/blueprints";
2754
+ import { trim as trim12 } from "@dxos/util";
2755
+
2756
+ // src/initiative/functions/getContext.ts
2757
+ import * as Effect18 from "effect/Effect";
2758
+ import * as Schema19 from "effect/Schema";
2759
+ import { AiContextService as AiContextService2 } from "@dxos/assistant";
2760
+ import { Database as Database15, Obj as Obj14 } from "@dxos/echo";
2761
+ import { defineFunction as defineFunction14 } from "@dxos/functions";
2762
+ var getContext_default = defineFunction14({
2763
+ key: "dxos.org/function/initiative/get-context",
2764
+ name: "Get Initiative Context",
2765
+ description: "Get the context of an initiative.",
2766
+ inputSchema: Schema19.Struct({}),
2767
+ outputSchema: Schema19.Struct({
2768
+ id: Schema19.String,
2769
+ name: Schema19.String,
2770
+ spec: Schema19.String,
2771
+ plan: Schema19.String,
2772
+ artifacts: Schema19.Array(Schema19.Struct({
2773
+ name: Schema19.String,
2774
+ type: Schema19.optional(Schema19.String),
2775
+ dxn: Schema19.optional(Schema19.String)
2776
+ }))
2777
+ }),
2778
+ services: [
2779
+ AiContextService2
2780
+ ],
2781
+ handler: Effect18.fnUntraced(function* ({ data: _data }) {
2782
+ const initiative = yield* getFromChatContext;
2783
+ return {
2784
+ id: initiative.id,
2785
+ name: initiative.name,
2786
+ spec: yield* initiative.spec.pipe(Database15.load).pipe(Effect18.map((_) => _.content), Effect18.catchTag("ObjectNotFoundError", () => Effect18.succeed("No spec found."))),
2787
+ plan: yield* initiative.plan?.pipe(Database15.load).pipe(Effect18.map(formatPlan), Effect18.catchTag("ObjectNotFoundError", () => Effect18.succeed("No plan found."))) ?? Effect18.succeed("No plan found."),
2788
+ artifacts: yield* Effect18.forEach(initiative.artifacts, (artifact) => Effect18.gen(function* () {
2789
+ return {
2790
+ name: artifact.name,
2791
+ type: yield* Database15.load(artifact.data).pipe(Effect18.map(Obj14.getTypename), Effect18.catchTag("ObjectNotFoundError", () => Effect18.succeed("Artifact not found."))),
2792
+ dxn: artifact.data.dxn.toString()
2793
+ };
2794
+ }))
2795
+ };
2796
+ }, AiContextService2.fixFunctionHandlerType)
2797
+ });
2798
+
2799
+ // src/initiative/functions/addArtifact.ts
2800
+ import * as Effect19 from "effect/Effect";
2801
+ import * as Schema20 from "effect/Schema";
2802
+ import { AiContextService as AiContextService3 } from "@dxos/assistant";
2803
+ import { Database as Database16, Obj as Obj15, Type as Type13 } from "@dxos/echo";
2804
+ import { defineFunction as defineFunction15 } from "@dxos/functions";
2805
+ var addArtifact_default = defineFunction15({
2806
+ key: "dxos.org/function/initiative/add-artifact",
2807
+ name: "Add artifact",
2808
+ description: "Adds a new artifact.",
2809
+ inputSchema: Schema20.Struct({
2810
+ name: Schema20.String.annotations({
2811
+ description: "The name of the artifact to add."
2812
+ }),
2813
+ artifact: Type13.Ref(Type13.Obj).annotations({
2814
+ description: "The artifact to add. Do NOT guess or try to generate the ID."
2473
2815
  })
2474
- }))
2816
+ }),
2817
+ services: [
2818
+ AiContextService3
2819
+ ],
2820
+ handler: Effect19.fnUntraced(function* ({ data }) {
2821
+ if (!(yield* Database16.load(data.artifact))) {
2822
+ throw new Error("Artifact not found.");
2823
+ }
2824
+ const initiative = yield* getFromChatContext;
2825
+ Obj15.change(initiative, (initiative2) => {
2826
+ initiative2.artifacts.push({
2827
+ name: data.name,
2828
+ data: data.artifact
2829
+ });
2830
+ });
2831
+ }, AiContextService3.fixFunctionHandlerType)
2832
+ });
2833
+
2834
+ // src/initiative/functions/agent.ts
2835
+ import * as Effect20 from "effect/Effect";
2836
+ import * as Schema21 from "effect/Schema";
2837
+ import { AiService as AiService4 } from "@dxos/ai";
2838
+ import { AiContextService as AiContextService4, AiConversation } from "@dxos/assistant";
2839
+ import { Database as Database17, Obj as Obj16, Type as Type14 } from "@dxos/echo";
2840
+ import { acquireReleaseResource as acquireReleaseResource2 } from "@dxos/effect";
2841
+ import { TriggerEvent, defineFunction as defineFunction16 } from "@dxos/functions";
2842
+ import { invariant as invariant2 } from "@dxos/invariant";
2843
+ var __dxlog_file9 = "/__w/dxos/dxos/packages/core/assistant-toolkit/src/initiative/functions/agent.ts";
2844
+ var agent_default = defineFunction16({
2845
+ key: "dxos.org/function/initiative/agent",
2846
+ name: "Initiative Agent",
2847
+ description: "Agentic worker that drives the initiative autonomously.",
2848
+ inputSchema: Schema21.Struct({
2849
+ initiative: Schema21.suspend(() => Type14.Ref(Initiative)),
2850
+ prompt: Schema21.optional(Schema21.String),
2851
+ event: Schema21.optional(TriggerEvent.TriggerEvent)
2852
+ }),
2853
+ outputSchema: Schema21.Void,
2854
+ services: [
2855
+ AiContextService4
2856
+ ],
2857
+ handler: Effect20.fnUntraced(function* ({ data }) {
2858
+ const initiative = yield* Database17.load(data.initiative);
2859
+ invariant2(Obj16.instanceOf(Initiative, initiative), void 0, {
2860
+ F: __dxlog_file9,
2861
+ L: 34,
2862
+ S: this,
2863
+ A: [
2864
+ "Obj.instanceOf(Initiative.Initiative, initiative)",
2865
+ ""
2866
+ ]
2867
+ });
2868
+ invariant2(initiative.chat, "Initiative has no chat.", {
2869
+ F: __dxlog_file9,
2870
+ L: 35,
2871
+ S: this,
2872
+ A: [
2873
+ "initiative.chat",
2874
+ "'Initiative has no chat.'"
2875
+ ]
2876
+ });
2877
+ if (initiative.newChatOnEveryEvent) {
2878
+ yield* resetChatHistory(initiative);
2879
+ }
2880
+ const chatQueue = yield* initiative.chat.pipe(Database17.load, Effect20.flatMap((chat) => Database17.load(chat.queue)));
2881
+ invariant2(chatQueue, "Initiative chat queue not found.", {
2882
+ F: __dxlog_file9,
2883
+ L: 45,
2884
+ S: this,
2885
+ A: [
2886
+ "chatQueue",
2887
+ "'Initiative chat queue not found.'"
2888
+ ]
2889
+ });
2890
+ const conversation = yield* acquireReleaseResource2(() => new AiConversation({
2891
+ queue: chatQueue
2892
+ }));
2893
+ const iniativesInContext = conversation.context.getObjects().filter(Obj16.instanceOf(Initiative));
2894
+ if (iniativesInContext.length !== 1) {
2895
+ throw new Error("There should be exactly one initiative in context. Got: " + iniativesInContext.length);
2896
+ }
2897
+ if (!data.prompt && !data.event) {
2898
+ throw new Error("Either prompt or event must be provided.");
2899
+ }
2900
+ let input = "";
2901
+ if (data.prompt) {
2902
+ input += `${data.prompt}
2903
+
2904
+ `;
2905
+ }
2906
+ if (data.event) {
2907
+ input += `<event>
2908
+ ${JSON.stringify(data.event, null, 2)}
2909
+ </event>
2910
+
2911
+ `;
2912
+ }
2913
+ yield* conversation.createRequest({
2914
+ prompt: input
2915
+ }).pipe(Effect20.retry({
2916
+ times: 2
2917
+ }));
2918
+ }, Effect20.scoped, Effect20.provide(AiService4.model("@anthropic/claude-sonnet-4-5")), AiContextService4.fixFunctionHandlerType)
2919
+ });
2920
+
2921
+ // src/initiative/functions/qualifier.ts
2922
+ import * as LanguageModel from "@effect/ai/LanguageModel";
2923
+ import * as Prompt2 from "@effect/ai/Prompt";
2924
+ import * as Effect21 from "effect/Effect";
2925
+ import * as Schema22 from "effect/Schema";
2926
+ import { AiService as AiService5 } from "@dxos/ai";
2927
+ import { Database as Database18, Obj as Obj17, Ref as Ref15, Type as Type15 } from "@dxos/echo";
2928
+ import { TriggerEvent as TriggerEvent2, defineFunction as defineFunction17 } from "@dxos/functions";
2929
+ import { invariant as invariant3 } from "@dxos/invariant";
2930
+ import { trim as trim11 } from "@dxos/util";
2931
+ var __dxlog_file10 = "/__w/dxos/dxos/packages/core/assistant-toolkit/src/initiative/functions/qualifier.ts";
2932
+ var qualifier_default = defineFunction17({
2933
+ key: "dxos.org/function/initiative/qualifier",
2934
+ name: "Initiative Qualifier",
2935
+ description: "Qualifier that determines if the event is relevant to the initiative. Puts the data into the input queue of the initiative.",
2936
+ inputSchema: Schema22.Struct({
2937
+ initiative: Schema22.suspend(() => Type15.Ref(Initiative)),
2938
+ event: TriggerEvent2.TriggerEvent
2939
+ }),
2940
+ outputSchema: Schema22.Void,
2941
+ services: [],
2942
+ handler: Effect21.fnUntraced(function* ({ data }) {
2943
+ const initiative = yield* Database18.load(data.initiative);
2944
+ invariant3(Obj17.instanceOf(Initiative, initiative), void 0, {
2945
+ F: __dxlog_file10,
2946
+ L: 33,
2947
+ S: this,
2948
+ A: [
2949
+ "Obj.instanceOf(Initiative.Initiative, initiative)",
2950
+ ""
2951
+ ]
2952
+ });
2953
+ invariant3(initiative.chat, "Initiative has no chat.", {
2954
+ F: __dxlog_file10,
2955
+ L: 34,
2956
+ S: this,
2957
+ A: [
2958
+ "initiative.chat",
2959
+ "'Initiative has no chat.'"
2960
+ ]
2961
+ });
2962
+ const { id, name, queue } = initiative;
2963
+ if (!queue) {
2964
+ throw new Error("Initiative has no queue.");
2965
+ }
2966
+ const plan = yield* Database18.load(initiative.plan);
2967
+ const spec = yield* Database18.load(initiative.spec);
2968
+ const { value: { isRelevant } } = yield* LanguageModel.generateObject({
2969
+ schema: Schema22.Struct({
2970
+ isRelevant: Schema22.Boolean
2971
+ }),
2972
+ prompt: Prompt2.fromMessages([
2973
+ Prompt2.systemMessage({
2974
+ content: trim11`
2975
+ You are a qualifying agent that determines if the event is relevant to the initiative.
2976
+ Respond with true if the event is relevant to the initiative, false otherwise.
2977
+ If you are not sure, return true.
2978
+ The qualified events will be forwarded to the larger agent that will process them.
2979
+ <initiative id="${id}" name="${name}">
2980
+ <spec>
2981
+ ${spec.content}
2982
+ </spec>
2983
+ <plan>
2984
+ ${formatPlan(plan)}
2985
+ </plan>
2986
+ </initiative>
2987
+ `
2988
+ }),
2989
+ Prompt2.userMessage({
2990
+ content: [
2991
+ Prompt2.makePart("text", {
2992
+ text: trim11`
2993
+ <event>
2994
+ ${JSON.stringify(data.event, null, 2)}
2995
+ </event>
2996
+ `
2997
+ })
2998
+ ]
2999
+ })
3000
+ ])
3001
+ });
3002
+ if (isRelevant) {
3003
+ const queueTarget = yield* Database18.load(queue);
3004
+ if ("queue" in data.event && data.event.item) {
3005
+ const obj = data.event.item;
3006
+ yield* Effect21.promise(() => queueTarget.append([
3007
+ obj
3008
+ ]));
3009
+ } else if ("subject" in data.event && Ref15.isRef(data.event.subject)) {
3010
+ const obj = yield* Database18.load(data.event.subject);
3011
+ yield* Effect21.promise(() => queueTarget.append([
3012
+ obj
3013
+ ]));
3014
+ } else {
3015
+ throw new Error("Invalid event.");
3016
+ }
3017
+ }
3018
+ }, Effect21.scoped, Effect21.provide(AiService5.model("@anthropic/claude-sonnet-4-5")))
3019
+ });
3020
+
3021
+ // src/initiative/blueprint.ts
3022
+ var getFunctions = () => [
3023
+ getContext_default,
3024
+ addArtifact_default,
3025
+ agent_default,
3026
+ qualifier_default
2475
3027
  ];
3028
+ var makeBlueprint = () => Blueprint8.make({
3029
+ key: "dxos.org/blueprint/initiative",
3030
+ name: "Initiative blueprint",
3031
+ instructions: Template3.make({
3032
+ source: trim12`
3033
+ You work on an initiative. Each initiative has a spec - the goal of the initiative.
3034
+ The initiative plan shows the current progress of the initiative.
3035
+ Initiative has an number of associated artifacts you can read/write.
3036
+ Spec and plan are also artifacts.
3037
+ You can edit them if necessary.
3038
+
3039
+ IMPORTANT: When create a new artifact, always add it to the initiative using the add-artifact function.
3040
+
3041
+ {{#with initiative}}
3042
+ <initiative id="{{id}}" name="{{name}}">
3043
+ <spec>
3044
+ {{spec}}
3045
+ </spec>
3046
+ <plan>
3047
+ {{plan}}
3048
+ </plan>
3049
+
3050
+ <artifacts>
3051
+ {{#each artifacts}}
3052
+ <artifact type="{{type}}" dxn="{{dxn}}">
3053
+ {{name}}
3054
+ </artifact>
3055
+ {{/each}}
3056
+ </artifacts>
3057
+ </initiative>
3058
+ {{/with}}
3059
+ `,
3060
+ inputs: [
3061
+ {
3062
+ name: "initiative",
3063
+ kind: "function",
3064
+ function: "dxos.org/function/initiative/get-context"
3065
+ }
3066
+ ]
3067
+ }),
3068
+ tools: Blueprint8.toolDefinitions({
3069
+ functions: [
3070
+ addArtifact_default
3071
+ ]
3072
+ })
3073
+ });
2476
3074
 
2477
3075
  // src/toolkits/AssistantToolkit.ts
2478
3076
  var AssistantToolkit_exports = {};
@@ -2482,37 +3080,62 @@ __export(AssistantToolkit_exports, {
2482
3080
  tools: () => tools
2483
3081
  });
2484
3082
  import * as Tool2 from "@effect/ai/Tool";
2485
- import * as Toolkit5 from "@effect/ai/Toolkit";
2486
- import * as Effect16 from "effect/Effect";
3083
+ import * as Toolkit4 from "@effect/ai/Toolkit";
3084
+ import * as Effect22 from "effect/Effect";
2487
3085
  import * as Record from "effect/Record";
2488
- import * as Schema16 from "effect/Schema";
2489
- import { AiContextService, ArtifactId as ArtifactId6 } from "@dxos/assistant";
2490
- import { Ref as Ref12 } from "@dxos/echo";
2491
- import { Database as Database13 } from "@dxos/echo";
2492
- import { trim as trim10 } from "@dxos/util";
2493
- var AssistantToolkit = Toolkit5.make(Tool2.make("add-to-context", {
2494
- description: trim10`
3086
+ import * as Schema23 from "effect/Schema";
3087
+ import { AiContextService as AiContextService5, ArtifactId } from "@dxos/assistant";
3088
+ import { Database as Database19 } from "@dxos/echo";
3089
+ import { trim as trim13 } from "@dxos/util";
3090
+ var AssistantToolkit = Toolkit4.make(Tool2.make("context-add", {
3091
+ description: trim13`
2495
3092
  Adds the object to the chat context.
2496
3093
  `,
2497
3094
  parameters: {
2498
- id: ArtifactId6.annotations({
2499
- description: "The ID of the document to read."
3095
+ id: ArtifactId.annotations({
3096
+ description: "The ID of the document to add."
3097
+ })
3098
+ },
3099
+ success: Schema23.Void,
3100
+ failure: Schema23.Never,
3101
+ dependencies: [
3102
+ AiContextService5,
3103
+ Database19.Service
3104
+ ]
3105
+ }), Tool2.make("context-remove", {
3106
+ description: trim13`
3107
+ Removes the object from the chat context.
3108
+ `,
3109
+ parameters: {
3110
+ id: ArtifactId.annotations({
3111
+ description: "The ID of the document to remove."
2500
3112
  })
2501
3113
  },
2502
- success: Schema16.Void,
2503
- failure: Schema16.Never,
3114
+ success: Schema23.Void,
3115
+ failure: Schema23.Never,
2504
3116
  dependencies: [
2505
- AiContextService,
2506
- Database13.Service
3117
+ AiContextService5,
3118
+ Database19.Service
2507
3119
  ]
2508
3120
  }));
2509
3121
  var tools = Record.keys(AssistantToolkit.tools);
2510
3122
  var layer3 = () => AssistantToolkit.toLayer({
2511
- "add-to-context": Effect16.fnUntraced(function* ({ id }) {
2512
- const { binder } = yield* AiContextService;
2513
- const { db } = yield* Database13.Service;
2514
- const ref = Ref12.fromDXN(ArtifactId6.toDXN(id, db.spaceId));
2515
- yield* Effect16.promise(() => binder.bind({
3123
+ ["context-add"]: Effect22.fnUntraced(function* ({ id }) {
3124
+ const { binder } = yield* AiContextService5;
3125
+ const { db } = yield* Database19.Service;
3126
+ const ref = db.makeRef(ArtifactId.toDXN(id, db.spaceId));
3127
+ yield* Effect22.promise(() => binder.bind({
3128
+ blueprints: [],
3129
+ objects: [
3130
+ ref
3131
+ ]
3132
+ }));
3133
+ }),
3134
+ ["context-remove"]: Effect22.fnUntraced(function* ({ id }) {
3135
+ const { binder } = yield* AiContextService5;
3136
+ const { db } = yield* Database19.Service;
3137
+ const ref = db.makeRef(ArtifactId.toDXN(id, db.spaceId));
3138
+ yield* Effect22.promise(() => binder.unbind({
2516
3139
  blueprints: [],
2517
3140
  objects: [
2518
3141
  ref
@@ -2529,173 +3152,225 @@ __export(SystemToolkit_exports, {
2529
3152
  tools: () => tools2
2530
3153
  });
2531
3154
  import * as Tool3 from "@effect/ai/Tool";
2532
- import * as Toolkit6 from "@effect/ai/Toolkit";
2533
- import * as Effect17 from "effect/Effect";
3155
+ import * as Toolkit5 from "@effect/ai/Toolkit";
3156
+ import * as Effect23 from "effect/Effect";
2534
3157
  import * as Record2 from "effect/Record";
2535
- import * as Schema17 from "effect/Schema";
2536
- import { ArtifactId as ArtifactId7 } from "@dxos/assistant";
2537
- import { DXN as DXN2, Obj as Obj16, Relation as Relation2, Tag as Tag2, Type as Type5 } from "@dxos/echo";
2538
- import { Database as Database14 } from "@dxos/echo";
2539
- import { trim as trim11 } from "@dxos/util";
2540
- var SystemToolkit = Toolkit6.make(
3158
+ import * as Schema24 from "effect/Schema";
3159
+ import { ArtifactId as ArtifactId2 } from "@dxos/assistant";
3160
+ import { DXN as DXN2, Database as Database20, Entity as Entity3, Filter as Filter5, Obj as Obj18, Relation as Relation3, Tag as Tag2, Type as Type16 } from "@dxos/echo";
3161
+ import { invariant as invariant4 } from "@dxos/invariant";
3162
+ import { trim as trim14 } from "@dxos/util";
3163
+ var __dxlog_file11 = "/__w/dxos/dxos/packages/core/assistant-toolkit/src/toolkits/SystemToolkit.ts";
3164
+ var SystemToolkit = Toolkit5.make(
2541
3165
  //
2542
3166
  // Schema
2543
3167
  //
2544
3168
  Tool3.make("schema-list", {
2545
- description: trim11`
3169
+ description: trim14`
2546
3170
  Lists schemas definitions.
2547
3171
  `,
2548
3172
  parameters: {
2549
3173
  // TODO(wittjosiah): Remove this once parameter-less tools are fixed.
2550
- limit: Schema17.Number
3174
+ limit: Schema24.Number
2551
3175
  },
2552
3176
  // TODO(dmaretskyi): Effect returns ({ result, encodedResult })
2553
- success: Schema17.Any,
2554
- failure: Schema17.Never,
3177
+ success: Schema24.Any,
3178
+ failure: Schema24.Never,
2555
3179
  dependencies: [
2556
- Database14.Service
3180
+ Database20.Service
2557
3181
  ]
2558
3182
  }),
2559
3183
  Tool3.make("schema-add", {
2560
- description: trim11`
3184
+ description: trim14`
2561
3185
  Adds a schema to the space.
2562
3186
  The name will be used when displayed to the user.
2563
3187
  The typename must be in the format of "example.com/type/Type".
2564
3188
  `,
2565
3189
  parameters: {
2566
- name: Schema17.String,
2567
- typename: Schema17.String,
2568
- jsonSchema: Schema17.Any
3190
+ name: Schema24.String,
3191
+ typename: Schema24.String,
3192
+ jsonSchema: Schema24.Any
3193
+ },
3194
+ success: Schema24.Any,
3195
+ failure: Schema24.Never,
3196
+ dependencies: [
3197
+ Database20.Service
3198
+ ]
3199
+ }),
3200
+ //
3201
+ // Query
3202
+ //
3203
+ Tool3.make("query", {
3204
+ description: trim14`
3205
+ Queries objects in the space.
3206
+ Get the typename from the schema-list tool.
3207
+ `,
3208
+ parameters: {
3209
+ typename: Schema24.String
2569
3210
  },
2570
- success: Schema17.Any,
2571
- failure: Schema17.Never,
3211
+ success: Schema24.Any,
3212
+ failure: Schema24.Never,
2572
3213
  dependencies: [
2573
- Database14.Service
3214
+ Database20.Service
2574
3215
  ]
2575
3216
  }),
2576
3217
  //
2577
3218
  // Objects
2578
3219
  //
2579
3220
  Tool3.make("object-create", {
2580
- description: trim11`
3221
+ description: trim14`
2581
3222
  Creates a new object and adds it to the current space.
2582
3223
  Get the schema from the schema-list tool and ensure that the data matches the corresponding schema.
2583
3224
  `,
2584
3225
  parameters: {
2585
- typename: Schema17.String,
2586
- data: Schema17.Any
3226
+ typename: Schema24.String,
3227
+ data: Schema24.Any
2587
3228
  },
2588
- success: Schema17.Any,
2589
- failure: Schema17.Never,
3229
+ success: Schema24.Any,
3230
+ failure: Schema24.Never,
2590
3231
  dependencies: [
2591
- Database14.Service
3232
+ Database20.Service
2592
3233
  ]
2593
3234
  }),
2594
- Tool3.make("object-remove", {
2595
- description: trim11`
2596
- Removes an object or relation from the database.
3235
+ Tool3.make("object-delete", {
3236
+ description: trim14`
3237
+ Deletes the object.
2597
3238
  `,
2598
3239
  parameters: {
2599
- id: ArtifactId7.annotations({
3240
+ id: ArtifactId2.annotations({
2600
3241
  description: "The ID of the object."
2601
3242
  })
2602
3243
  },
2603
- success: Schema17.Any,
2604
- failure: Schema17.Never,
3244
+ success: Schema24.Any,
3245
+ failure: Schema24.Never,
2605
3246
  dependencies: [
2606
- Database14.Service
3247
+ Database20.Service
3248
+ ]
3249
+ }),
3250
+ Tool3.make("object-update", {
3251
+ description: trim14`
3252
+ Updates the object properties.
3253
+ `,
3254
+ parameters: {
3255
+ id: ArtifactId2.annotations({
3256
+ description: "The ID of the object."
3257
+ }),
3258
+ properties: Schema24.Record({
3259
+ key: Schema24.String,
3260
+ value: Schema24.Any
3261
+ })
3262
+ },
3263
+ success: Schema24.Any,
3264
+ failure: Schema24.Never,
3265
+ dependencies: [
3266
+ Database20.Service
2607
3267
  ]
2608
3268
  }),
2609
3269
  //
2610
3270
  // Relations
2611
3271
  //
2612
3272
  Tool3.make("relation-create", {
2613
- description: trim11`
3273
+ description: trim14`
2614
3274
  Creates a new relation and adds it to the current space.
2615
3275
  Get the schema from the schema-list tool and ensure that the data matches the corresponding schema.
2616
3276
  `,
2617
3277
  parameters: {
2618
- typename: Schema17.String,
2619
- source: ArtifactId7.annotations({
3278
+ typename: Schema24.String,
3279
+ source: ArtifactId2.annotations({
2620
3280
  description: "The ID of the source object."
2621
3281
  }),
2622
- target: ArtifactId7.annotations({
3282
+ target: ArtifactId2.annotations({
2623
3283
  description: "The ID of the target object."
2624
3284
  }),
2625
- data: Schema17.Any.annotations({
3285
+ data: Schema24.Any.annotations({
2626
3286
  description: "The data to be stored in the relation."
2627
3287
  })
2628
3288
  },
2629
- success: Schema17.Any,
2630
- failure: Schema17.Never,
3289
+ success: Schema24.Any,
3290
+ failure: Schema24.Never,
3291
+ dependencies: [
3292
+ Database20.Service
3293
+ ]
3294
+ }),
3295
+ Tool3.make("relation-delete", {
3296
+ description: trim14`
3297
+ Deletes the relation.
3298
+ `,
3299
+ parameters: {
3300
+ id: ArtifactId2.annotations({
3301
+ description: "The ID of the relation."
3302
+ })
3303
+ },
3304
+ success: Schema24.Any,
3305
+ failure: Schema24.Never,
2631
3306
  dependencies: [
2632
- Database14.Service
3307
+ Database20.Service
2633
3308
  ]
2634
3309
  }),
2635
3310
  //
2636
3311
  // Tags
2637
3312
  //
2638
3313
  Tool3.make("tag-add", {
2639
- description: trim11`
3314
+ description: trim14`
2640
3315
  Adds a tag to an object.
2641
3316
  Tags are objects of type ${Tag2.Tag.typename}.
2642
3317
  `,
2643
3318
  parameters: {
2644
- tagId: ArtifactId7.annotations({
3319
+ tagId: ArtifactId2.annotations({
2645
3320
  description: "The ID of the tag."
2646
3321
  }),
2647
- objectId: ArtifactId7.annotations({
3322
+ objectId: ArtifactId2.annotations({
2648
3323
  description: "The ID of the object."
2649
3324
  })
2650
3325
  },
2651
- success: Schema17.Any,
2652
- failure: Schema17.Never,
3326
+ success: Schema24.Any,
3327
+ failure: Schema24.Never,
2653
3328
  dependencies: [
2654
- Database14.Service
3329
+ Database20.Service
2655
3330
  ]
2656
3331
  }),
2657
3332
  Tool3.make("tag-remove", {
2658
- description: trim11`
3333
+ description: trim14`
2659
3334
  Removes a tag from an object.
2660
3335
  Tags are objects of type ${Tag2.Tag.typename}.
2661
3336
  `,
2662
3337
  parameters: {
2663
- tagId: ArtifactId7.annotations({
3338
+ tagId: ArtifactId2.annotations({
2664
3339
  description: "The ID of the tag."
2665
3340
  }),
2666
- objectId: ArtifactId7.annotations({
3341
+ objectId: ArtifactId2.annotations({
2667
3342
  description: "The ID of the object."
2668
3343
  })
2669
3344
  },
2670
- success: Schema17.Any,
2671
- failure: Schema17.Never,
3345
+ success: Schema24.Any,
3346
+ failure: Schema24.Never,
2672
3347
  dependencies: [
2673
- Database14.Service
3348
+ Database20.Service
2674
3349
  ]
2675
3350
  })
2676
3351
  );
2677
3352
  var tools2 = Record2.keys(SystemToolkit.tools);
2678
3353
  var layer4 = () => SystemToolkit.toLayer({
2679
- "schema-list": Effect17.fnUntraced(function* () {
2680
- const { db } = yield* Database14.Service;
2681
- const schema = yield* Effect17.promise(() => db.schemaRegistry.query({
3354
+ ["schema-list"]: Effect23.fnUntraced(function* () {
3355
+ const { db } = yield* Database20.Service;
3356
+ const schema = yield* Effect23.promise(() => db.schemaRegistry.query({
2682
3357
  location: [
2683
3358
  "database",
2684
3359
  "runtime"
2685
3360
  ]
2686
3361
  }).run());
2687
3362
  return schema.map((schema2) => {
2688
- const meta = Type5.getMeta(schema2);
3363
+ const meta = Type16.getMeta(schema2);
2689
3364
  return {
2690
- typename: Type5.getTypename(schema2),
2691
- jsonSchema: Type5.toJsonSchema(schema2),
3365
+ typename: Type16.getTypename(schema2),
3366
+ jsonSchema: Type16.toJsonSchema(schema2),
2692
3367
  kind: meta?.sourceSchema ? "relation" : "record"
2693
3368
  };
2694
3369
  });
2695
3370
  }),
2696
- "schema-add": Effect17.fnUntraced(function* ({ name, typename, jsonSchema }) {
2697
- const { db } = yield* Database14.Service;
2698
- yield* Effect17.promise(() => db.schemaRegistry.register([
3371
+ ["schema-add"]: Effect23.fnUntraced(function* ({ name, typename, jsonSchema }) {
3372
+ const { db } = yield* Database20.Service;
3373
+ yield* Effect23.promise(() => db.schemaRegistry.register([
2699
3374
  {
2700
3375
  typename,
2701
3376
  version: "0.1.0",
@@ -2704,66 +3379,310 @@ var layer4 = () => SystemToolkit.toLayer({
2704
3379
  }
2705
3380
  ]));
2706
3381
  }),
2707
- "object-create": Effect17.fnUntraced(function* ({ typename, data }) {
2708
- const { db } = yield* Database14.Service;
2709
- const schema = yield* Effect17.promise(() => db.schemaRegistry.query({
3382
+ ["query"]: Effect23.fnUntraced(function* ({ typename }) {
3383
+ const objects = yield* Database20.runQuery(Filter5.typename(typename));
3384
+ return objects;
3385
+ }),
3386
+ ["object-create"]: Effect23.fnUntraced(function* ({ typename, data }) {
3387
+ const { db } = yield* Database20.Service;
3388
+ const schema = yield* Effect23.promise(() => db.schemaRegistry.query({
2710
3389
  typename,
2711
3390
  location: [
2712
3391
  "database",
2713
3392
  "runtime"
2714
3393
  ]
2715
3394
  }).first());
2716
- const object = db.add(Obj16.make(schema, data));
3395
+ invariant4(Type16.isObjectSchema(schema), "Schema is not an object schema", {
3396
+ F: __dxlog_file11,
3397
+ L: 238,
3398
+ S: this,
3399
+ A: [
3400
+ "Type.isObjectSchema(schema)",
3401
+ "'Schema is not an object schema'"
3402
+ ]
3403
+ });
3404
+ const object = db.add(Obj18.make(schema, data));
2717
3405
  return object;
2718
3406
  }),
2719
- "object-remove": Effect17.fnUntraced(function* ({ id }) {
2720
- const { db } = yield* Database14.Service;
2721
- const object = yield* Database14.Service.resolve(DXN2.parse(id));
3407
+ ["object-delete"]: Effect23.fnUntraced(function* ({ id }) {
3408
+ const { db } = yield* Database20.Service;
3409
+ const object = yield* Database20.resolve(DXN2.parse(id));
2722
3410
  db.remove(object);
2723
3411
  return object;
2724
3412
  }),
2725
- "relation-create": Effect17.fnUntraced(function* ({ typename, source, target, data }) {
2726
- const { db } = yield* Database14.Service;
2727
- const schema = yield* Effect17.promise(() => db.schemaRegistry.query({
3413
+ ["object-update"]: Effect23.fnUntraced(function* ({ id, properties }) {
3414
+ const object = yield* Database20.resolve(DXN2.parse(id));
3415
+ Entity3.change(object, (obj) => {
3416
+ for (const [key, value2] of Object.entries(properties)) {
3417
+ obj[key] = value2;
3418
+ }
3419
+ });
3420
+ return object;
3421
+ }),
3422
+ ["relation-create"]: Effect23.fnUntraced(function* ({ typename, source, target, data }) {
3423
+ const { db } = yield* Database20.Service;
3424
+ const schema = yield* Effect23.promise(() => db.schemaRegistry.query({
2728
3425
  typename,
2729
3426
  location: [
2730
3427
  "database",
2731
3428
  "runtime"
2732
3429
  ]
2733
3430
  }).first());
2734
- const sourceObj = yield* Database14.Service.resolve(DXN2.parse(source));
2735
- const targetObj = yield* Database14.Service.resolve(DXN2.parse(target));
2736
- const relation = db.add(Relation2.make(schema, {
2737
- [Relation2.Source]: sourceObj,
2738
- [Relation2.Target]: targetObj,
3431
+ invariant4(Type16.isRelationSchema(schema), "Schema is not a relation schema", {
3432
+ F: __dxlog_file11,
3433
+ L: 267,
3434
+ S: this,
3435
+ A: [
3436
+ "Type.isRelationSchema(schema)",
3437
+ "'Schema is not a relation schema'"
3438
+ ]
3439
+ });
3440
+ const sourceObj = yield* Database20.resolve(DXN2.parse(source));
3441
+ const targetObj = yield* Database20.resolve(DXN2.parse(target));
3442
+ const relation = db.add(Relation3.make(schema, {
3443
+ [Relation3.Source]: sourceObj,
3444
+ [Relation3.Target]: targetObj,
2739
3445
  ...data
2740
3446
  }));
2741
3447
  return relation;
2742
3448
  }),
2743
- "tag-add": Effect17.fnUntraced(function* ({ tagId, objectId }) {
2744
- const object = yield* Database14.Service.resolve(DXN2.parse(objectId));
2745
- Obj16.addTag(object, DXN2.parse(tagId).toString());
3449
+ ["relation-delete"]: Effect23.fnUntraced(function* ({ id }) {
3450
+ const { db } = yield* Database20.Service;
3451
+ const relation = yield* Database20.resolve(DXN2.parse(id));
3452
+ db.remove(relation);
3453
+ return relation;
3454
+ }),
3455
+ ["tag-add"]: Effect23.fnUntraced(function* ({ tagId, objectId }) {
3456
+ const object = yield* Database20.resolve(DXN2.parse(objectId));
3457
+ Entity3.change(object, (obj) => Entity3.addTag(obj, DXN2.parse(tagId).toString()));
2746
3458
  return object;
2747
3459
  }),
2748
- "tag-remove": Effect17.fnUntraced(function* ({ tagId, objectId }) {
2749
- const object = yield* Database14.Service.resolve(DXN2.parse(objectId));
2750
- Obj16.removeTag(object, DXN2.parse(tagId).toString());
3460
+ ["tag-remove"]: Effect23.fnUntraced(function* ({ tagId, objectId }) {
3461
+ const object = yield* Database20.resolve(DXN2.parse(objectId));
3462
+ Entity3.change(object, (obj) => Entity3.removeTag(obj, DXN2.parse(tagId).toString()));
2751
3463
  return object;
2752
3464
  })
2753
3465
  });
3466
+
3467
+ // src/toolkits/WebToolkit.ts
3468
+ var WebToolkit_exports = {};
3469
+ __export(WebToolkit_exports, {
3470
+ WebToolkit: () => WebToolkit,
3471
+ layer: () => layer5
3472
+ });
3473
+ import * as Tool4 from "@effect/ai/Tool";
3474
+ import * as Toolkit6 from "@effect/ai/Toolkit";
3475
+ import * as AnthropicTool3 from "@effect/ai-anthropic/AnthropicTool";
3476
+ import * as Effect24 from "effect/Effect";
3477
+ import * as Schema25 from "effect/Schema";
3478
+ var WebToolkit = Toolkit6.make(AnthropicTool3.WebSearch_20250305({}).pipe(), Tool4.make("WebFetch", {
3479
+ parameters: {
3480
+ url: Schema25.String
3481
+ },
3482
+ success: Schema25.String
3483
+ }));
3484
+ var layer5 = WebToolkit.toLayer({
3485
+ WebFetch: Effect24.fnUntraced(function* ({ url }) {
3486
+ const response = yield* Effect24.promise(() => fetch(url).then((response2) => response2.text()));
3487
+ return response;
3488
+ })
3489
+ });
3490
+
3491
+ // src/planning/index.ts
3492
+ var planning_exports = {};
3493
+ __export(planning_exports, {
3494
+ PlanningBlueprint: () => PlanningBlueprint,
3495
+ PlanningFunctions: () => functions_exports
3496
+ });
3497
+
3498
+ // src/planning/blueprint.ts
3499
+ import { Blueprint as Blueprint9 } from "@dxos/blueprints";
3500
+
3501
+ // src/planning/functions/index.ts
3502
+ var functions_exports = {};
3503
+ __export(functions_exports, {
3504
+ updateTasks: () => update_tasks_default
3505
+ });
3506
+
3507
+ // src/planning/functions/update-tasks.ts
3508
+ import * as Effect25 from "effect/Effect";
3509
+ import * as Schema26 from "effect/Schema";
3510
+ import { AiContextService as AiContextService6 } from "@dxos/assistant";
3511
+ import { Database as Database21, Obj as Obj19 } from "@dxos/echo";
3512
+ import { defineFunction as defineFunction18 } from "@dxos/functions";
3513
+ import { trim as trim15 } from "@dxos/util";
3514
+ var INSTRUCTIONS = trim15`
3515
+ TASK MANAGEMENT TOOL - USAGE GUIDELINES
3516
+
3517
+ This tool maintains an organized task list during work sessions to track progress, break down objectives, and ensure thoroughness. After creating initial tasks, update them silently without announcing changes to the user.
3518
+
3519
+ === CORE USAGE PRINCIPLES ===
3520
+
3521
+ Create and manage tasks for: multi-step objectives requiring 3+ distinct actions, complex projects needing careful sequencing, user requests for task organization, multiple deliverables provided together, new instructions (capture as tasks immediately with new IDs), completed work (mark done and add follow-ups), and active work (mark as 'in-progress', limit one at a time).
3522
+
3523
+ Skip task management for: single straightforward actions, simple requests achievable in 1-2 steps, informational queries, quick lookups or clarifications, and avoid creating verification tasks unless requested.
3524
+
3525
+ === TOOL SPECIFICATION ===
3526
+
3527
+ update-tasks requires an array of task objects. Each task object contains:
3528
+ - id (string, required): unique identifier like "task_1" or "research_sources"
3529
+ - title (string, optional): update to clarify or refine task description
3530
+ - status (string, optional): 'todo' | 'in-progress' | 'done'
3531
+
3532
+ Task status meanings: 'todo' means not yet started, 'in-progress' means currently being worked on, 'done' means completed successfully.
3533
+
3534
+ === OPERATIONAL GUIDELINES ===
3535
+
3536
+ Update tasks in real-time as work progresses. Mark tasks 'done' immediately upon completion. Maintain only ONE task with 'in-progress' status at a time. Complete current tasks before starting new ones. Use specific, actionable task titles. Break complex work into manageable logical pieces. Batch task updates with other actions when possible for efficiency.
3537
+
3538
+ === USAGE EXAMPLES ===
3539
+
3540
+ <example type="research_project">
3541
+ <user_message>I need to research sustainable packaging options and write a report comparing costs and environmental impact.</user_message>
3542
+ <assistant_action>
3543
+ Creates tasks:
3544
+ 1. {id: "research_materials", title: "Research sustainable packaging materials", status: "in-progress"}
3545
+ 2. {id: "compare_costs", title: "Compile cost comparison data", status: "todo"}
3546
+ 3. {id: "assess_impact", title: "Evaluate environmental impact metrics", status: "todo"}
3547
+ 4. {id: "draft_report", title: "Write comparative analysis report", status: "todo"}
3548
+
3549
+ Begins research work immediately in same response.
3550
+ </assistant_action>
3551
+ <reasoning>Multi-phase project requiring systematic tracking across research, analysis, and writing stages.</reasoning>
3552
+ </example>
3553
+
3554
+ <example type="event_planning">
3555
+ <user_message>Help me plan a team retreat - venue, agenda, catering, and send invitations.</user_message>
3556
+ <assistant_action>
3557
+ Creates tasks:
3558
+ 1. {id: "venue_options", title: "Research and recommend venues", status: "in-progress"}
3559
+ 2. {id: "draft_agenda", title: "Create retreat agenda", status: "todo"}
3560
+ 3. {id: "arrange_catering", title: "Coordinate catering options", status: "todo"}
3561
+ 4. {id: "send_invites", title: "Draft and send invitations", status: "todo"}
3562
+ </assistant_action>
3563
+ <reasoning>Multiple distinct deliverables with dependencies requiring organized tracking.</reasoning>
3564
+ </example>
3565
+
3566
+ <example type="document_analysis">
3567
+ <user_message>Review this 30-page contract for key terms, risks, and negotiation points.</user_message>
3568
+ <assistant_action>
3569
+ Creates tasks:
3570
+ 1. {id: "extract_key_terms", title: "Identify key contractual terms", status: "in-progress"}
3571
+ 2. {id: "flag_risks", title: "Flag potential risks and liabilities", status: "todo"}
3572
+ 3. {id: "negotiation_points", title: "Compile negotiation recommendations", status: "todo"}
3573
+ 4. {id: "summary_doc", title: "Prepare executive summary", status: "todo"}
3574
+ </assistant_action>
3575
+ <reasoning>Substantial analysis work requiring methodical breakdown and systematic review.</reasoning>
3576
+ </example>
3577
+
3578
+ <example type="multiple_deliverables">
3579
+ <user_message>I need: 1) competitor analysis for three companies, 2) SWOT analysis, 3) market positioning recommendations.</user_message>
3580
+ <assistant_action>
3581
+ Creates tasks:
3582
+ 1. {id: "competitor_research", title: "Research three competitor companies", status: "in-progress"}
3583
+ 2. {id: "swot_analysis", title: "Develop SWOT analysis", status: "todo"}
3584
+ 3. {id: "positioning_recs", title: "Create market positioning recommendations", status: "todo"}
3585
+ </assistant_action>
3586
+ <reasoning>User provided numbered list of distinct deliverables requiring separate effort.</reasoning>
3587
+ </example>
3588
+
3589
+ <example type="skip_simple_question">
3590
+ <user_message>What's the difference between renewable and sustainable energy?</user_message>
3591
+ <assistant_action>Provides explanation directly without creating tasks.</assistant_action>
3592
+ <reasoning>Informational request with no actionable work to complete or track.</reasoning>
3593
+ </example>
3594
+
3595
+ <example type="skip_quick_lookup">
3596
+ <user_message>Find the population of Tokyo.</user_message>
3597
+ <assistant_action>Searches and provides answer without task tracking.</assistant_action>
3598
+ <reasoning>Single straightforward lookup completable immediately.</reasoning>
3599
+ </example>
3600
+
3601
+ <example type="skip_trivial_task">
3602
+ <user_message>Summarize this 2-paragraph email.</user_message>
3603
+ <assistant_action>Provides summary directly without creating tasks.</assistant_action>
3604
+ <reasoning>Single simple action requiring no breakdown or progress tracking.</reasoning>
3605
+ </example>
3606
+
3607
+ <example type="skip_single_action">
3608
+ <user_message>Check if my flight is on time.</user_message>
3609
+ <assistant_action>Performs lookup and reports status without task management.</assistant_action>
3610
+ <reasoning>One-step action with immediate completion, no organizational benefit from tasks.</reasoning>
3611
+ </example>
3612
+
3613
+ === BEST PRACTICES ===
3614
+
3615
+ For task creation: use descriptive unique IDs reflecting the work, start first task as 'in-progress', batch initial creation with beginning work. For progress tracking: update status immediately upon completion, keep only one 'in-progress' task unless parallel work is natural, add follow-up tasks as they emerge. For task breakdown: aim for reasonably-scoped tasks, group related small actions into logical units, split tasks requiring different approaches.
3616
+
3617
+ When uncertain whether to use task management, err on the side of creating tasks. Proactive organization demonstrates thoroughness and ensures comprehensive work completion.
3618
+ `;
3619
+ var TaskProps = Schema26.Struct({
3620
+ id: TaskId,
3621
+ title: Schema26.String,
3622
+ status: Schema26.Literal("todo", "in-progress", "done")
3623
+ });
3624
+ var update_tasks_default = defineFunction18({
3625
+ key: "dxos.org/function/planning/update-tasks",
3626
+ name: "Update tasks",
3627
+ description: INSTRUCTIONS,
3628
+ inputSchema: Schema26.Struct({
3629
+ tasks: Schema26.Array(TaskProps)
3630
+ }),
3631
+ handler: Effect25.fn(function* ({ data: { tasks: newTasks } }) {
3632
+ const initiative = yield* getFromChatContext;
3633
+ const plan = yield* Database21.load(initiative.plan);
3634
+ Obj19.change(plan, (plan2) => {
3635
+ for (const task of newTasks) {
3636
+ const existingTask = plan2.tasks.find((t) => t.id === task.id);
3637
+ if (existingTask) {
3638
+ existingTask.title = task.title;
3639
+ existingTask.status = task.status;
3640
+ } else {
3641
+ plan2.tasks.push({
3642
+ id: task.id,
3643
+ title: task.title,
3644
+ status: task.status
3645
+ });
3646
+ }
3647
+ }
3648
+ });
3649
+ return `
3650
+ Tasks updated. Don't forget to mark tasks as done when you're done with them or update their status to 'in-progress' when you start working on them.
3651
+ Current plan:
3652
+ <plan>
3653
+ ${formatPlan(plan)}
3654
+ </plan>
3655
+ `;
3656
+ }, AiContextService6.fixFunctionHandlerType)
3657
+ });
3658
+
3659
+ // src/planning/blueprint.ts
3660
+ var PlanningBlueprint = Blueprint9.make({
3661
+ key: "dxos.org/blueprint/planning",
3662
+ name: "Planning",
3663
+ description: "Plans and tracks complex tasks with artifact management.",
3664
+ tools: Blueprint9.toolDefinitions({
3665
+ functions: [
3666
+ update_tasks_default
3667
+ ]
3668
+ })
3669
+ });
2754
3670
  export {
2755
3671
  Agent,
2756
3672
  AssistantToolkit_exports as AssistantToolkit,
3673
+ Chat_exports as Chat,
2757
3674
  design_default as DesignBlueprint,
2758
3675
  Discord,
2759
3676
  discord_default as DiscordBlueprint,
2760
3677
  Document,
2761
3678
  EntityExtraction,
3679
+ initiative_exports as Initiative,
2762
3680
  Linear,
2763
3681
  linear_default as LinearBlueprint,
2764
3682
  LocalSearchHandler,
2765
3683
  LocalSearchToolkit,
2766
- MapSchema,
3684
+ markdown_default as MarkdownBlueprint,
3685
+ planning_exports as Planning,
2767
3686
  planning_default as PlanningBlueprint,
2768
3687
  Research,
2769
3688
  research_default2 as ResearchBlueprint,
@@ -2774,7 +3693,7 @@ export {
2774
3693
  Tasks,
2775
3694
  websearch_default as WebSearchBlueprint,
2776
3695
  WebSearchToolkit,
2777
- capabilities,
3696
+ WebToolkit_exports as WebToolkit,
2778
3697
  contextQueueLayerFromResearchGraph,
2779
3698
  createExtractionSchema,
2780
3699
  createResearchGraph,