@dxos/assistant-toolkit 0.8.4-main.2c6827d → 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 (219) 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 +1410 -480
  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 -13
  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 -13
  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 +14 -11
  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 +125 -124
  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 +125 -124
  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 +9 -8
  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/research/types.d.ts +1 -1
  76. package/dist/types/src/functions/research/types.d.ts.map +1 -1
  77. package/dist/types/src/functions/tasks/index.d.ts +16 -2
  78. package/dist/types/src/functions/tasks/index.d.ts.map +1 -1
  79. package/dist/types/src/functions/tasks/read.d.ts +8 -1
  80. package/dist/types/src/functions/tasks/read.d.ts.map +1 -1
  81. package/dist/types/src/functions/tasks/update.d.ts +8 -1
  82. package/dist/types/src/functions/tasks/update.d.ts.map +1 -1
  83. package/dist/types/src/index.d.ts +4 -2
  84. package/dist/types/src/index.d.ts.map +1 -1
  85. package/dist/types/src/initiative/Initiative.d.ts +41 -0
  86. package/dist/types/src/initiative/Initiative.d.ts.map +1 -0
  87. package/dist/types/src/initiative/blueprint.d.ts +153 -0
  88. package/dist/types/src/initiative/blueprint.d.ts.map +1 -0
  89. package/dist/types/src/initiative/functions/addArtifact.d.ts +6 -0
  90. package/dist/types/src/initiative/functions/addArtifact.d.ts.map +1 -0
  91. package/dist/types/src/initiative/functions/agent.d.ts +62 -0
  92. package/dist/types/src/initiative/functions/agent.d.ts.map +1 -0
  93. package/dist/types/src/initiative/functions/getContext.d.ts +13 -0
  94. package/dist/types/src/initiative/functions/getContext.d.ts.map +1 -0
  95. package/dist/types/src/initiative/functions/index.d.ts +5 -0
  96. package/dist/types/src/initiative/functions/index.d.ts.map +1 -0
  97. package/dist/types/src/initiative/functions/qualifier.d.ts +60 -0
  98. package/dist/types/src/initiative/functions/qualifier.d.ts.map +1 -0
  99. package/dist/types/src/initiative/index.d.ts +6 -0
  100. package/dist/types/src/initiative/index.d.ts.map +1 -0
  101. package/dist/types/src/initiative/initiative.test.d.ts +2 -0
  102. package/dist/types/src/initiative/initiative.test.d.ts.map +1 -0
  103. package/dist/types/src/initiative/plan.d.ts +77 -0
  104. package/dist/types/src/initiative/plan.d.ts.map +1 -0
  105. package/dist/types/src/initiative/util.d.ts +29 -0
  106. package/dist/types/src/initiative/util.d.ts.map +1 -0
  107. package/dist/types/src/planning/blueprint.d.ts +18 -0
  108. package/dist/types/src/planning/blueprint.d.ts.map +1 -0
  109. package/dist/types/src/planning/functions/index.d.ts +2 -0
  110. package/dist/types/src/planning/functions/index.d.ts.map +1 -0
  111. package/dist/types/src/planning/functions/update-tasks.d.ts +9 -0
  112. package/dist/types/src/planning/functions/update-tasks.d.ts.map +1 -0
  113. package/dist/types/src/planning/index.d.ts +3 -0
  114. package/dist/types/src/planning/index.d.ts.map +1 -0
  115. package/dist/types/src/sync/sync.d.ts +3 -3
  116. package/dist/types/src/sync/sync.d.ts.map +1 -1
  117. package/dist/types/src/testing/index.d.ts +1 -1
  118. package/dist/types/src/testing/index.d.ts.map +1 -1
  119. package/dist/types/src/testing/plugins.d.ts +19 -0
  120. package/dist/types/src/testing/plugins.d.ts.map +1 -0
  121. package/dist/types/src/toolkits/AssistantToolkit.d.ts +31 -5
  122. package/dist/types/src/toolkits/AssistantToolkit.d.ts.map +1 -1
  123. package/dist/types/src/toolkits/SystemToolkit.d.ts +42 -10
  124. package/dist/types/src/toolkits/SystemToolkit.d.ts.map +1 -1
  125. package/dist/types/src/toolkits/WebToolkit.d.ts +38 -0
  126. package/dist/types/src/toolkits/WebToolkit.d.ts.map +1 -0
  127. package/dist/types/src/toolkits/index.d.ts +1 -0
  128. package/dist/types/src/toolkits/index.d.ts.map +1 -1
  129. package/dist/types/tsconfig.tsbuildinfo +1 -1
  130. package/package.json +45 -40
  131. package/src/blueprints/design/design-blueprint.test.ts +14 -17
  132. package/src/blueprints/design/design-blueprint.ts +2 -4
  133. package/src/blueprints/design/index.ts +1 -1
  134. package/src/blueprints/discord/discord-blueprint.ts +2 -4
  135. package/src/blueprints/discord/index.ts +1 -1
  136. package/src/blueprints/index.ts +1 -0
  137. package/src/blueprints/linear/index.ts +1 -1
  138. package/src/blueprints/linear/linear-blueprint.ts +2 -4
  139. package/src/blueprints/markdown/index.ts +7 -0
  140. package/src/blueprints/markdown/markdown-blueprint.ts +24 -0
  141. package/src/blueprints/planning/index.ts +1 -1
  142. package/src/blueprints/planning/planning-blueprint.test.ts +12 -16
  143. package/src/blueprints/planning/planning-blueprint.ts +2 -4
  144. package/src/blueprints/research/index.ts +1 -1
  145. package/src/blueprints/research/research-blueprint.ts +2 -4
  146. package/src/blueprints/testing.ts +2 -6
  147. package/src/blueprints/websearch/index.ts +2 -1
  148. package/src/blueprints/websearch/websearch-blueprint.ts +2 -4
  149. package/src/chat/Chat.ts +45 -0
  150. package/src/chat/index.ts +5 -0
  151. package/src/crud/graph.test.ts +6 -29
  152. package/src/crud/graph.ts +32 -40
  153. package/src/experimental/feed.test.ts +4 -9
  154. package/src/functions/agent/prompt.ts +15 -13
  155. package/src/functions/discord/fetch-messages.test.ts +4 -8
  156. package/src/functions/discord/fetch-messages.ts +1 -1
  157. package/src/functions/document/create.ts +29 -0
  158. package/src/functions/document/index.ts +2 -1
  159. package/src/functions/document/read.ts +11 -8
  160. package/src/functions/document/update.ts +9 -7
  161. package/src/functions/entity-extraction/entity-extraction.conversations.json +1 -1
  162. package/src/functions/entity-extraction/entity-extraction.test.ts +11 -29
  163. package/src/functions/entity-extraction/entity-extraction.ts +41 -24
  164. package/src/functions/exa/mock.ts +1 -1
  165. package/src/functions/github/fetch-prs.ts +3 -2
  166. package/src/functions/linear/linear.test.ts +18 -43
  167. package/src/functions/linear/sync-issues.ts +9 -7
  168. package/src/functions/research/document-create.ts +9 -11
  169. package/src/functions/research/research-graph.ts +13 -11
  170. package/src/functions/research/research.conversations.json +1 -1
  171. package/src/functions/research/research.test.ts +29 -64
  172. package/src/functions/research/research.ts +15 -23
  173. package/src/functions/research/types.ts +3 -3
  174. package/src/functions/tasks/read.ts +6 -6
  175. package/src/functions/tasks/update.ts +6 -6
  176. package/src/index.ts +4 -2
  177. package/src/initiative/Initiative.ts +61 -0
  178. package/src/initiative/blueprint.ts +60 -0
  179. package/src/initiative/functions/addArtifact.ts +41 -0
  180. package/src/initiative/functions/agent.ts +77 -0
  181. package/src/initiative/functions/getContext.ts +62 -0
  182. package/src/initiative/functions/index.ts +8 -0
  183. package/src/initiative/functions/qualifier.ts +98 -0
  184. package/src/initiative/index.ts +9 -0
  185. package/src/initiative/initiative.test.ts +584 -0
  186. package/src/initiative/plan.ts +107 -0
  187. package/src/initiative/util.ts +137 -0
  188. package/src/planning/blueprint.ts +14 -0
  189. package/src/planning/functions/index.ts +5 -0
  190. package/src/planning/functions/update-tasks.ts +168 -0
  191. package/src/planning/index.ts +6 -0
  192. package/src/sync/sync.ts +38 -30
  193. package/src/testing/index.ts +1 -1
  194. package/src/{plugins.tsx → testing/plugins.tsx} +14 -13
  195. package/src/toolkits/AssistantToolkit.conversations.json +1 -1
  196. package/src/toolkits/AssistantToolkit.test.ts +27 -43
  197. package/src/toolkits/AssistantToolkit.ts +31 -8
  198. package/src/toolkits/SystemToolkit.ts +100 -32
  199. package/src/toolkits/WebToolkit.ts +34 -0
  200. package/src/toolkits/index.ts +1 -0
  201. package/dist/lib/browser/index.mjs.map +0 -7
  202. package/dist/lib/browser/meta.json +0 -1
  203. package/dist/lib/node-esm/index.mjs +0 -2779
  204. package/dist/lib/node-esm/index.mjs.map +0 -7
  205. package/dist/lib/node-esm/meta.json +0 -1
  206. package/dist/types/src/plugins.d.ts +0 -19
  207. package/dist/types/src/plugins.d.ts.map +0 -1
  208. package/dist/types/src/testing/data/exa-search-1748337321991.d.ts.map +0 -1
  209. package/dist/types/src/testing/data/exa-search-1748337331526.d.ts.map +0 -1
  210. package/dist/types/src/testing/data/exa-search-1748337344119.d.ts.map +0 -1
  211. package/dist/types/src/testing/data/index.d.ts.map +0 -1
  212. /package/dist/types/src/{testing → functions/exa}/data/exa-search-1748337321991.d.ts +0 -0
  213. /package/dist/types/src/{testing → functions/exa}/data/exa-search-1748337331526.d.ts +0 -0
  214. /package/dist/types/src/{testing → functions/exa}/data/exa-search-1748337344119.d.ts +0 -0
  215. /package/dist/types/src/{testing → functions/exa}/data/index.d.ts +0 -0
  216. /package/src/{testing → functions/exa}/data/exa-search-1748337321991.ts +0 -0
  217. /package/src/{testing → functions/exa}/data/exa-search-1748337331526.ts +0 -0
  218. /package/src/{testing → functions/exa}/data/exa-search-1748337344119.ts +0 -0
  219. /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
 
@@ -22,7 +20,8 @@ import { AiService, ConsolePrinter, ModelName } from "@dxos/ai";
22
20
  import { AiSession, GenerationObserver, createToolkit } from "@dxos/assistant";
23
21
  import { Prompt, Template } from "@dxos/blueprints";
24
22
  import { Obj, Ref, Type } from "@dxos/echo";
25
- import { DatabaseService, TracingService, defineFunction } from "@dxos/functions";
23
+ import { Database } from "@dxos/echo";
24
+ import { TracingService, defineFunction } from "@dxos/functions";
26
25
  import { log } from "@dxos/log";
27
26
  var __dxlog_file = "/__w/dxos/dxos/packages/core/assistant-toolkit/src/functions/agent/prompt.ts";
28
27
  var DEFAULT_MODEL = "@anthropic/claude-opus-4-0";
@@ -51,19 +50,19 @@ var prompt_default = defineFunction({
51
50
  input: data.input
52
51
  }, {
53
52
  F: __dxlog_file,
54
- L: 40,
53
+ L: 41,
55
54
  S: this,
56
55
  C: (f, a) => f(...a)
57
56
  });
58
57
  const input = yield* Match.value(data.input).pipe(Match.when((value2) => Ref.isRef(value2), Effect.fnUntraced(function* (ref) {
59
- const object = yield* DatabaseService.load(ref);
58
+ const object = yield* Database.load(ref);
60
59
  return Obj.toJSON(object);
61
60
  })), Match.orElse(() => Effect.succeed(data.input)));
62
- yield* DatabaseService.flush({
61
+ yield* Database.flush({
63
62
  indexes: true
64
63
  });
65
- const prompt = yield* DatabaseService.load(data.prompt);
66
- const systemPrompt = data.systemPrompt ? yield* DatabaseService.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;
67
66
  yield* TracingService.emitStatus({
68
67
  message: `Running ${prompt.id}`
69
68
  });
@@ -72,18 +71,18 @@ var prompt_default = defineFunction({
72
71
  input
73
72
  }, {
74
73
  F: __dxlog_file,
75
- L: 70,
74
+ L: 71,
76
75
  S: this,
77
76
  C: (f, a) => f(...a)
78
77
  });
79
- const blueprints = yield* Function.pipe(prompt.blueprints, Array2.appendAll(systemPrompt?.blueprints ?? []), Effect.forEach(DatabaseService.loadOption), Effect.map(Array2.filter(Option.isSome)), Effect.map(Array2.map((option) => option.value)));
80
- const objects = yield* Function.pipe(prompt.context, Array2.appendAll(systemPrompt?.context ?? []), Effect.forEach(DatabaseService.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)));
81
79
  const toolkit = yield* createToolkit({
82
80
  blueprints
83
81
  });
84
- const promptInstructions = yield* DatabaseService.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);
85
84
  const promptText = Template.process(promptInstructions.content, input);
86
- const systemInstructions = systemPrompt ? yield* DatabaseService.load(systemPrompt.instructions.source) : void 0;
85
+ const systemInstructions = systemPrompt ? yield* Database.load(systemPrompt.instructions.source) : void 0;
87
86
  const systemText = systemInstructions ? Template.process(systemInstructions.content, {}) : void 0;
88
87
  const session = new AiSession();
89
88
  const result = yield* session.run({
@@ -211,7 +210,15 @@ var fetch_messages_default = defineFunction2({
211
210
  throw new Error("no channels found");
212
211
  }
213
212
  for (const channel of channels) {
214
- 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
+ });
215
222
  }
216
223
  yield* TracingService2.emitStatus({
217
224
  message: `Will fetch from channels: ${channels.length}`
@@ -308,27 +315,56 @@ ${thread.messages.map((message) => ` ${message.sender.name}: ${message.blocks.f
308
315
  })(Discord || (Discord = {}));
309
316
  var Discord;
310
317
 
311
- // src/functions/document/read.ts
318
+ // src/functions/document/create.ts
312
319
  import * as Effect3 from "effect/Effect";
313
320
  import * as Schema3 from "effect/Schema";
314
- import { ArtifactId } from "@dxos/assistant";
315
- import { DatabaseService as DatabaseService2, defineFunction as defineFunction3 } from "@dxos/functions";
321
+ import { Database as Database2, Ref as Ref2 } from "@dxos/echo";
322
+ import { defineFunction as defineFunction3 } from "@dxos/functions";
316
323
  import { Markdown } from "@dxos/plugin-markdown/types";
317
- var read_default = defineFunction3({
324
+ var create_default = defineFunction3({
325
+ key: "dxos.org/function/markdown/create",
326
+ name: "Create markdown document",
327
+ description: "Creates a new markdown document.",
328
+ inputSchema: Schema3.Struct({
329
+ name: Schema3.String.annotations({
330
+ description: "Name of the document."
331
+ }),
332
+ content: Schema3.String.annotations({
333
+ description: "Content of the document."
334
+ })
335
+ }),
336
+ outputSchema: Schema3.Void,
337
+ handler: Effect3.fn(function* ({ data: { name, content } }) {
338
+ const doc = yield* Database2.add(Markdown.make({
339
+ name,
340
+ content
341
+ }));
342
+ return {
343
+ document: Ref2.make(doc)
344
+ };
345
+ })
346
+ });
347
+
348
+ // src/functions/document/read.ts
349
+ import * as Effect4 from "effect/Effect";
350
+ import * as Schema4 from "effect/Schema";
351
+ import { Database as Database3, Type as Type2 } from "@dxos/echo";
352
+ import { defineFunction as defineFunction4 } from "@dxos/functions";
353
+ import { Markdown as Markdown2 } from "@dxos/plugin-markdown/types";
354
+ var read_default = defineFunction4({
318
355
  key: "dxos.org/function/markdown/read",
319
356
  name: "Read markdown document",
320
- description: "Read markdown document.",
321
- inputSchema: Schema3.Struct({
322
- id: ArtifactId.annotations({
323
- description: "The ID of the document to read."
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."
324
361
  })
325
362
  }),
326
- outputSchema: Schema3.Struct({
327
- content: Schema3.String
363
+ outputSchema: Schema4.Struct({
364
+ content: Schema4.String
328
365
  }),
329
- handler: Effect3.fn(function* ({ data: { id } }) {
330
- const doc = yield* DatabaseService2.resolve(ArtifactId.toDXN(id), Markdown.Document);
331
- const { content } = yield* DatabaseService2.load(doc.content);
366
+ handler: Effect4.fn(function* ({ data: { document } }) {
367
+ const { content } = yield* document.pipe(Database3.load, Effect4.flatMap((doc) => doc.content.pipe(Database3.load)));
332
368
  return {
333
369
  content
334
370
  };
@@ -336,28 +372,30 @@ var read_default = defineFunction3({
336
372
  });
337
373
 
338
374
  // src/functions/document/update.ts
339
- import * as Effect4 from "effect/Effect";
340
- import * as Schema4 from "effect/Schema";
341
- import { ArtifactId as ArtifactId2 } from "@dxos/assistant";
342
- import { DatabaseService as DatabaseService3, defineFunction as defineFunction4 } from "@dxos/functions";
343
- import { Markdown as Markdown2 } from "@dxos/plugin-markdown/types";
344
- var update_default = defineFunction4({
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({
345
381
  key: "dxos.org/function/markdown/update",
346
382
  name: "Update markdown",
347
383
  description: "Updates the entire contents of the markdown document.",
348
- inputSchema: Schema4.Struct({
349
- id: ArtifactId2.annotations({
384
+ inputSchema: Schema5.Struct({
385
+ doc: Type3.Ref(Markdown3.Document).annotations({
350
386
  description: "The ID of the document to write."
351
387
  }),
352
- content: Schema4.String.annotations({
388
+ content: Schema5.String.annotations({
353
389
  description: "New content to write to the document."
354
390
  })
355
391
  }),
356
- outputSchema: Schema4.Void,
357
- handler: Effect4.fn(function* ({ data: { id, content } }) {
358
- const doc = yield* DatabaseService3.resolve(ArtifactId2.toDXN(id), Markdown2.Document);
359
- const text = yield* DatabaseService3.load(doc.content);
360
- 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
+ });
361
399
  })
362
400
  });
363
401
 
@@ -365,19 +403,20 @@ var update_default = defineFunction4({
365
403
  (function(Document2) {
366
404
  Document2.read = read_default;
367
405
  Document2.update = update_default;
406
+ Document2.create = create_default;
368
407
  })(Document || (Document = {}));
369
408
  var Document;
370
409
 
371
410
  // src/functions/entity-extraction/entity-extraction.ts
372
- import * as Toolkit3 from "@effect/ai/Toolkit";
373
- import * as Effect11 from "effect/Effect";
411
+ import * as Effect12 from "effect/Effect";
374
412
  import * as Layer4 from "effect/Layer";
375
413
  import * as Predicate from "effect/Predicate";
376
- import * as Schema11 from "effect/Schema";
414
+ import * as Schema12 from "effect/Schema";
377
415
  import { AiService as AiService3 } from "@dxos/ai";
378
- import { AiSession as AiSession3, makeToolExecutionServiceFromFunctions as makeToolExecutionServiceFromFunctions2, makeToolResolverFromFunctions as makeToolResolverFromFunctions2 } from "@dxos/assistant";
379
- import { Filter as Filter2, Obj as Obj7, Ref as Ref3 } from "@dxos/echo";
380
- import { DatabaseService as DatabaseService8, 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";
381
420
  import { FunctionInvocationServiceLayerTest } from "@dxos/functions-runtime/testing";
382
421
  import { log as log5 } from "@dxos/log";
383
422
  import { LegacyOrganization as LegacyOrganization2, Message as Message2, Organization, Person as Person2 } from "@dxos/types";
@@ -387,37 +426,35 @@ import { trim as trim4 } from "@dxos/util";
387
426
  import * as Tool from "@effect/ai/Tool";
388
427
  import * as Toolkit from "@effect/ai/Toolkit";
389
428
  import * as Context from "effect/Context";
390
- import * as Effect5 from "effect/Effect";
429
+ import * as Effect6 from "effect/Effect";
391
430
  import * as Function3 from "effect/Function";
392
431
  import * as Option3 from "effect/Option";
393
- import * as Schema5 from "effect/Schema";
432
+ import * as Schema6 from "effect/Schema";
394
433
  import * as SchemaAST from "effect/SchemaAST";
395
- import { Obj as Obj3 } from "@dxos/echo";
396
- import { Filter, Query } from "@dxos/echo";
397
- import { EntityKind, ObjectId, ReferenceAnnotationId, RelationSourceDXNId, RelationSourceId, RelationTargetDXNId, RelationTargetId, create, getEntityKind, getSchemaDXN, getSchemaTypename, getTypeAnnotation, getTypeIdentifierAnnotation } from "@dxos/echo/internal";
434
+ import { Entity, Filter, Obj as Obj4, Query, Type as Type4 } from "@dxos/echo";
435
+ import { Database as Database5 } from "@dxos/echo";
436
+ import { ReferenceAnnotationId, RelationSourceDXNId, RelationSourceId, RelationTargetDXNId, RelationTargetId, createObject, getTypeAnnotation, getTypeIdentifierAnnotation } from "@dxos/echo/internal";
398
437
  import { isEncodedReference } from "@dxos/echo-protocol";
399
438
  import { mapAst } from "@dxos/effect";
400
- import { ContextQueueService, DatabaseService as DatabaseService4 } from "@dxos/functions";
401
- import { DXN } from "@dxos/keys";
439
+ import { ContextQueueService } from "@dxos/functions";
440
+ import { DXN, ObjectId } from "@dxos/keys";
402
441
  import { log as log3 } from "@dxos/log";
403
442
  import { deepMapValues, isNonNullable, trim } from "@dxos/util";
404
443
  var __dxlog_file3 = "/__w/dxos/dxos/packages/core/assistant-toolkit/src/crud/graph.ts";
405
- var Subgraph = Schema5.Struct({
444
+ var Subgraph = Schema6.Struct({
406
445
  /** Objects and relations. */
407
- objects: Schema5.Array(Schema5.Any)
446
+ objects: Schema6.Array(Schema6.Any)
408
447
  });
409
448
  var findRelatedSchema = async (db, anchor) => {
410
- const allSchemas = [
411
- ...db.graph.schemaRegistry.schemas
412
- ];
449
+ const allSchemas = await db.graph.schemaRegistry.query().run();
413
450
  return allSchemas.filter((schema) => {
414
- if (getTypeAnnotation(schema)?.kind !== EntityKind.Relation) {
451
+ if (getTypeAnnotation(schema)?.kind !== Entity.Kind.Relation) {
415
452
  return false;
416
453
  }
417
454
  return isSchemaAddressableByDxn(anchor, DXN.parse(getTypeAnnotation(schema).sourceSchema)) || isSchemaAddressableByDxn(anchor, DXN.parse(getTypeAnnotation(schema).targetSchema));
418
455
  }).map((schema) => ({
419
- schema,
420
- kind: "relation"
456
+ kind: "relation",
457
+ schema
421
458
  }));
422
459
  };
423
460
  var isSchemaAddressableByDxn = (schema, dxn) => {
@@ -426,34 +463,34 @@ var isSchemaAddressableByDxn = (schema, dxn) => {
426
463
  }
427
464
  const t = dxn.asTypeDXN();
428
465
  if (t) {
429
- return t.type === getSchemaTypename(schema);
466
+ return t.type === Type4.getTypename(schema);
430
467
  }
431
468
  return false;
432
469
  };
433
470
  var LocalSearchToolkit = Toolkit.make(Tool.make("search_local_search", {
434
471
  description: "Search the local database for information using a vector index",
435
472
  parameters: {
436
- query: Schema5.String.annotations({
473
+ query: Schema6.String.annotations({
437
474
  description: "The query to search for. Could be a question or a topic or a set of keywords."
438
475
  })
439
476
  },
440
- success: Schema5.Unknown,
441
- failure: Schema5.Never,
477
+ success: Schema6.Unknown,
478
+ failure: Schema6.Never,
442
479
  dependencies: [
443
- DatabaseService4
480
+ Database5.Service
444
481
  ]
445
482
  }));
446
483
  var LocalSearchHandler = LocalSearchToolkit.toLayer({
447
- search_local_search: Effect5.fn(function* ({ query }) {
448
- const { objects } = yield* DatabaseService4.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, {
449
486
  type: "vector"
450
487
  })));
451
488
  const results = [
452
489
  ...objects
453
490
  ];
454
- const option = yield* Effect5.serviceOption(ContextQueueService);
491
+ const option = yield* Effect6.serviceOption(ContextQueueService);
455
492
  if (Option3.isSome(option)) {
456
- const queueObjects = yield* Effect5.promise(() => option.value.queue.queryObjects());
493
+ const queueObjects = yield* Effect6.promise(() => option.value.queue.queryObjects());
457
494
  results.push(...queueObjects);
458
495
  }
459
496
  return trim`
@@ -469,10 +506,10 @@ var makeGraphWriterToolkit = ({ schema }) => {
469
506
  return Toolkit.make(Tool.make("graph_writer", {
470
507
  description: "Write to the local graph database",
471
508
  parameters: createExtractionSchema(schema).fields,
472
- success: Schema5.Unknown,
473
- failure: Schema5.Never,
509
+ success: Schema6.Unknown,
510
+ failure: Schema6.Never,
474
511
  dependencies: [
475
- DatabaseService4,
512
+ Database5.Service,
476
513
  ContextQueueService
477
514
  ]
478
515
  }).annotateContext(Context.make(GraphWriterSchema, {
@@ -482,29 +519,29 @@ var makeGraphWriterToolkit = ({ schema }) => {
482
519
  var makeGraphWriterHandler = (toolkit, { onAppend } = {}) => {
483
520
  const { schema } = Context.get(toolkit.tools.graph_writer.annotations, GraphWriterSchema);
484
521
  return toolkit.toLayer({
485
- graph_writer: Effect5.fn(function* (input) {
486
- const { db } = yield* DatabaseService4;
522
+ graph_writer: Effect6.fn(function* (input) {
523
+ const { db } = yield* Database5.Service;
487
524
  const { queue } = yield* ContextQueueService;
488
- const data = yield* Effect5.promise(() => sanitizeObjects(schema, input, db, queue));
489
- yield* Effect5.promise(() => queue.append(data));
490
- 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));
491
528
  onAppend?.(dxns);
492
529
  return dxns;
493
530
  })
494
531
  });
495
532
  };
496
533
  var createExtractionSchema = (types) => {
497
- return Schema5.Struct({
534
+ return Schema6.Struct({
498
535
  ...Object.fromEntries(types.map(preprocessSchema).map((schema, index) => [
499
536
  `objects_${getSanitizedSchemaName(types[index])}`,
500
- Schema5.optional(Schema5.Array(schema)).annotations({
501
- description: `The objects of type: ${getSchemaDXN(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(() => ""))}`
502
539
  })
503
540
  ]))
504
541
  });
505
542
  };
506
543
  var getSanitizedSchemaName = (schema) => {
507
- return getSchemaDXN(schema).asTypeDXN().type.replaceAll(/[^a-zA-Z0-9]+/g, "_");
544
+ return Type4.getDXN(schema).asTypeDXN().type.replaceAll(/[^a-zA-Z0-9]+/g, "_");
508
545
  };
509
546
  var sanitizeObjects = async (types, data, db, queue) => {
510
547
  const entries = types.map((type) => data[`objects_${getSanitizedSchemaName(type)}`]?.map((object) => ({
@@ -549,14 +586,14 @@ var sanitizeObjects = async (types, data, db, queue) => {
549
586
  }
550
587
  return recurse(value2);
551
588
  });
552
- if (getEntityKind(entry.schema) === "relation") {
589
+ if (Entity.getKind(entry.schema) === "relation") {
553
590
  const sourceDxn = resolveId(data2.source);
554
591
  if (!sourceDxn) {
555
592
  log3.warn("source not found", {
556
593
  source: data2.source
557
594
  }, {
558
595
  F: __dxlog_file3,
559
- L: 281,
596
+ L: 273,
560
597
  S: void 0,
561
598
  C: (f, a) => f(...a)
562
599
  });
@@ -567,7 +604,7 @@ var sanitizeObjects = async (types, data, db, queue) => {
567
604
  target: data2.target
568
605
  }, {
569
606
  F: __dxlog_file3,
570
- L: 285,
607
+ L: 277,
571
608
  S: void 0,
572
609
  C: (f, a) => f(...a)
573
610
  });
@@ -582,7 +619,7 @@ var sanitizeObjects = async (types, data, db, queue) => {
582
619
  schema: entry.schema
583
620
  };
584
621
  }).filter((object) => !existingIds.has(object.data.id));
585
- const { objects: dbObjects } = await db.query(Query.select(Filter.ids(...existingIds))).run();
622
+ const dbObjects = await db.query(Query.select(Filter.id(...existingIds))).run();
586
623
  const queueObjects = await queue?.getObjectsById([
587
624
  ...existingIds
588
625
  ]) ?? [];
@@ -596,7 +633,7 @@ var sanitizeObjects = async (types, data, db, queue) => {
596
633
  existingIds
597
634
  }, {
598
635
  F: __dxlog_file3,
599
- L: 306,
636
+ L: 298,
600
637
  S: void 0,
601
638
  C: (f, a) => f(...a)
602
639
  });
@@ -627,7 +664,7 @@ var sanitizeObjects = async (types, data, db, queue) => {
627
664
  }
628
665
  }
629
666
  if (!skip) {
630
- const obj = create(schema, data2);
667
+ const obj = createObject(schema, data2);
631
668
  enitties.set(obj.id, obj);
632
669
  return [
633
670
  obj
@@ -636,13 +673,13 @@ var sanitizeObjects = async (types, data, db, queue) => {
636
673
  return [];
637
674
  });
638
675
  };
639
- var SoftRef = Schema5.Struct({
640
- "/": Schema5.String
676
+ var SoftRef = Schema6.Struct({
677
+ "/": Schema6.String
641
678
  }).annotations({
642
679
  description: "Reference to another object."
643
680
  });
644
681
  var preprocessSchema = (schema) => {
645
- const isRelationSchema = getEntityKind(schema) === "relation";
682
+ const isRelationSchema = Entity.getKind(schema) === "relation";
646
683
  const go = (ast, visited = /* @__PURE__ */ new Set()) => {
647
684
  if (visited.has(ast)) {
648
685
  return ast;
@@ -653,84 +690,83 @@ var preprocessSchema = (schema) => {
653
690
  }
654
691
  return mapAst(ast, (child) => go(child, visited));
655
692
  };
656
- return Schema5.make(mapAst(schema.ast, (ast) => go(ast))).pipe(Schema5.omit("id"), Schema5.extend(Schema5.Struct({
657
- 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({
658
695
  description: "The id of this object. Come up with a unique id based on your judgement."
659
696
  })
660
- })), isRelationSchema ? Schema5.extend(Schema5.Struct({
661
- source: Schema5.String.annotations({
697
+ })), isRelationSchema ? Schema6.extend(Schema6.Struct({
698
+ source: Schema6.String.annotations({
662
699
  description: "The id of the source object for this relation."
663
700
  }),
664
- target: Schema5.String.annotations({
701
+ target: Schema6.String.annotations({
665
702
  description: "The id of the target object for this relation."
666
703
  })
667
704
  })) : Function3.identity);
668
705
  };
669
706
 
670
707
  // src/functions/research/document-create.ts
671
- import * as Effect6 from "effect/Effect";
672
- import * as Schema6 from "effect/Schema";
673
- import { ArtifactId as ArtifactId3 } from "@dxos/assistant";
674
- import { Obj as Obj4, Relation } from "@dxos/echo";
675
- import { DatabaseService as DatabaseService5, 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";
676
712
  import { log as log4 } from "@dxos/log";
677
- import { Markdown as Markdown3 } from "@dxos/plugin-markdown/types";
713
+ import { Markdown as Markdown4 } from "@dxos/plugin-markdown/types";
678
714
  import { HasSubject } from "@dxos/types";
679
715
  import { trim as trim2 } from "@dxos/util";
680
716
  var __dxlog_file4 = "/__w/dxos/dxos/packages/core/assistant-toolkit/src/functions/research/document-create.ts";
681
- var document_create_default = defineFunction5({
717
+ var document_create_default = defineFunction6({
682
718
  key: "dxos.org/function/research/document-create",
683
719
  name: "Create research document",
684
720
  description: "Creates a note summarizing the research.",
685
- inputSchema: Schema6.Struct({
686
- subject: ArtifactId3.annotations({
721
+ inputSchema: Schema7.Struct({
722
+ subject: Type5.Ref(Type5.Obj).annotations({
687
723
  description: trim2`
688
724
  ID of the object (organization, contact, etc.) for which the research was performed.
689
725
  `
690
726
  }),
691
- name: Schema6.String.annotations({
727
+ name: Schema7.String.annotations({
692
728
  description: "Name of the document."
693
729
  }),
694
- content: Schema6.String.annotations({
730
+ content: Schema7.String.annotations({
695
731
  description: trim2`
696
732
  Content of the note.
697
733
  Supports (and are prefered) references to research objects using @ syntax and <object> tags (refer to research blueprint instructions).
698
734
  `
699
735
  })
700
736
  }),
701
- outputSchema: Schema6.Struct({
702
- document: ArtifactId3.annotations({
737
+ outputSchema: Schema7.Struct({
738
+ document: Schema7.String.annotations({
703
739
  description: "DXN of the created document."
704
740
  })
705
741
  }),
706
- handler: Effect6.fnUntraced(function* ({ data: { subject, name, content } }) {
742
+ handler: Effect7.fnUntraced(function* ({ data: { subject, name, content } }) {
707
743
  log4.info("Creating research document", {
708
744
  subject,
709
745
  name,
710
746
  content
711
747
  }, {
712
748
  F: __dxlog_file4,
713
- L: 42,
749
+ L: 41,
714
750
  S: this,
715
751
  C: (f, a) => f(...a)
716
752
  });
717
- yield* DatabaseService5.flush({
753
+ yield* Database6.flush({
718
754
  indexes: true
719
755
  });
720
756
  yield* TracingService3.emitStatus({
721
757
  message: "Creating research document..."
722
758
  });
723
- const target = yield* DatabaseService5.resolve(ArtifactId3.toDXN(subject));
724
- const object = yield* DatabaseService5.add(Markdown3.make({
759
+ const target = yield* Database6.load(subject);
760
+ const object = yield* Database6.add(Markdown4.make({
725
761
  name,
726
762
  content
727
763
  }));
728
- yield* DatabaseService5.add(Relation.make(HasSubject.HasSubject, {
764
+ yield* Database6.add(Relation.make(HasSubject.HasSubject, {
729
765
  [Relation.Source]: object,
730
766
  [Relation.Target]: target,
731
767
  completedAt: (/* @__PURE__ */ new Date()).toISOString()
732
768
  }));
733
- yield* DatabaseService5.flush({
769
+ yield* Database6.flush({
734
770
  indexes: true
735
771
  });
736
772
  log4.info("Created research document", {
@@ -738,12 +774,12 @@ var document_create_default = defineFunction5({
738
774
  object
739
775
  }, {
740
776
  F: __dxlog_file4,
741
- L: 69,
777
+ L: 67,
742
778
  S: this,
743
779
  C: (f, a) => f(...a)
744
780
  });
745
781
  return {
746
- document: Obj4.getDXN(object).toString()
782
+ document: Obj5.getDXN(object).toString()
747
783
  };
748
784
  })
749
785
  });
@@ -752,42 +788,43 @@ var document_create_default = defineFunction5({
752
788
  import * as Toolkit2 from "@effect/ai/Toolkit";
753
789
  import * as AnthropicTool from "@effect/ai-anthropic/AnthropicTool";
754
790
  import * as Array6 from "effect/Array";
755
- import * as Effect10 from "effect/Effect";
791
+ import * as Effect11 from "effect/Effect";
756
792
  import * as Function4 from "effect/Function";
757
793
  import * as Layer3 from "effect/Layer";
758
794
  import * as Option4 from "effect/Option";
759
- import * as Schema10 from "effect/Schema";
760
- import * as String10 from "effect/String";
795
+ import * as Schema11 from "effect/Schema";
796
+ import * as String11 from "effect/String";
761
797
  import { AiService as AiService2, ConsolePrinter as ConsolePrinter2 } from "@dxos/ai";
762
- 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";
763
799
  import { Template as Template2 } from "@dxos/blueprints";
764
- import { Obj as Obj6 } from "@dxos/echo";
765
- import { DatabaseService as DatabaseService7, 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";
766
803
  import { FunctionInvocationServiceLayerTestMocked } from "@dxos/functions-runtime/testing";
767
804
  import { Person } from "@dxos/types";
768
805
  import { trim as trim3 } from "@dxos/util";
769
806
 
770
807
  // src/functions/exa/exa.ts
771
- import * as Effect7 from "effect/Effect";
772
- import * as Schema7 from "effect/Schema";
808
+ import * as Effect8 from "effect/Effect";
809
+ import * as Schema8 from "effect/Schema";
773
810
  import Exa from "exa-js";
774
- import { CredentialsService as CredentialsService2, defineFunction as defineFunction6 } from "@dxos/functions";
775
- var exa_default = defineFunction6({
811
+ import { CredentialsService as CredentialsService2, defineFunction as defineFunction7 } from "@dxos/functions";
812
+ var exa_default = defineFunction7({
776
813
  key: "dxos.org/function/exa",
777
814
  name: "Exa",
778
815
  description: "Search the web for information",
779
- inputSchema: Schema7.Struct({
780
- query: Schema7.String.annotations({
816
+ inputSchema: Schema8.Struct({
817
+ query: Schema8.String.annotations({
781
818
  description: "The query to search for."
782
819
  })
783
820
  }),
784
- outputSchema: Schema7.Unknown,
785
- handler: Effect7.fnUntraced(function* ({ data: { query } }) {
821
+ outputSchema: Schema8.Unknown,
822
+ handler: Effect8.fnUntraced(function* ({ data: { query } }) {
786
823
  const credential = yield* CredentialsService2.getCredential({
787
824
  service: "exa.ai"
788
825
  });
789
826
  const exa = new Exa(credential.apiKey);
790
- const context = yield* Effect7.promise(async () => exa.searchAndContents(query, {
827
+ const context = yield* Effect8.promise(async () => exa.searchAndContents(query, {
791
828
  type: "auto",
792
829
  text: {
793
830
  maxCharacters: 3e3
@@ -799,11 +836,11 @@ var exa_default = defineFunction6({
799
836
  });
800
837
 
801
838
  // src/functions/exa/mock.ts
802
- import * as Effect8 from "effect/Effect";
803
- import * as Schema8 from "effect/Schema";
804
- 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";
805
842
 
806
- // src/testing/data/exa-search-1748337321991.ts
843
+ // src/functions/exa/data/exa-search-1748337321991.ts
807
844
  var exa_search_1748337321991_default = {
808
845
  requestId: "324936368a74f4db978982172bc18a6c",
809
846
  autopromptString: "AI personal knowledge management tools projects 2024",
@@ -959,7 +996,7 @@ var exa_search_1748337321991_default = {
959
996
  }
960
997
  };
961
998
 
962
- // src/testing/data/exa-search-1748337331526.ts
999
+ // src/functions/exa/data/exa-search-1748337331526.ts
963
1000
  var exa_search_1748337331526_default = {
964
1001
  requestId: "0dc12e344fa649884456960ca1a54954",
965
1002
  autopromptString: "PKM software artificial intelligence integration open source projects",
@@ -1182,7 +1219,7 @@ npm run tauri dev
1182
1219
  }
1183
1220
  };
1184
1221
 
1185
- // src/testing/data/exa-search-1748337344119.ts
1222
+ // src/functions/exa/data/exa-search-1748337344119.ts
1186
1223
  var exa_search_1748337344119_default = {
1187
1224
  requestId: "32df0c541f9883180b35e04caece4374",
1188
1225
  autopromptString: "open source AI knowledge management projects features comparison 2024",
@@ -1305,7 +1342,7 @@ var exa_search_1748337344119_default = {
1305
1342
  }
1306
1343
  };
1307
1344
 
1308
- // src/testing/data/index.ts
1345
+ // src/functions/exa/data/index.ts
1309
1346
  var SEARCH_RESULTS = [
1310
1347
  exa_search_1748337321991_default,
1311
1348
  exa_search_1748337331526_default,
@@ -1313,17 +1350,17 @@ var SEARCH_RESULTS = [
1313
1350
  ];
1314
1351
 
1315
1352
  // src/functions/exa/mock.ts
1316
- var mock_default = defineFunction7({
1353
+ var mock_default = defineFunction8({
1317
1354
  key: "dxos.org/function/exa-mock",
1318
1355
  name: "Exa mock",
1319
1356
  description: "Search the web for information",
1320
- inputSchema: Schema8.Struct({
1321
- query: Schema8.String.annotations({
1357
+ inputSchema: Schema9.Struct({
1358
+ query: Schema9.String.annotations({
1322
1359
  description: "The query to search for."
1323
1360
  })
1324
1361
  }),
1325
- outputSchema: Schema8.Unknown,
1326
- handler: Effect8.fnUntraced(function* ({ data: { query } }) {
1362
+ outputSchema: Schema9.Unknown,
1363
+ handler: Effect9.fnUntraced(function* ({ data: { query } }) {
1327
1364
  const result = SEARCH_RESULTS.reduce((closest, current) => {
1328
1365
  if (!current.autopromptString) {
1329
1366
  return closest;
@@ -1359,31 +1396,33 @@ var levenshteinDistance = (str1, str2) => {
1359
1396
  };
1360
1397
 
1361
1398
  // src/functions/research/research-graph.ts
1362
- import * as Effect9 from "effect/Effect";
1399
+ import * as Effect10 from "effect/Effect";
1363
1400
  import * as Layer2 from "effect/Layer";
1364
- import * as Schema9 from "effect/Schema";
1365
- import { Obj as Obj5, Query as Query2, Ref as Ref2, Type as Type2 } 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";
1404
+ import { SystemTypeAnnotation } from "@dxos/echo/internal";
1366
1405
  import { Queue } from "@dxos/echo-db";
1367
- import { ContextQueueService as ContextQueueService2, DatabaseService as DatabaseService6, QueueService } from "@dxos/functions";
1368
- var ResearchGraph = Schema9.Struct({
1369
- queue: Type2.Ref(Queue)
1370
- }).pipe(Type2.Obj({
1406
+ import { ContextQueueService as ContextQueueService2, QueueService } from "@dxos/functions";
1407
+ var ResearchGraph = Schema10.Struct({
1408
+ queue: Type6.Ref(Queue)
1409
+ }).pipe(Type6.object({
1371
1410
  typename: "dxos.org/type/ResearchGraph",
1372
1411
  version: "0.1.0"
1373
- }));
1374
- var queryResearchGraph = Effect9.fn("queryResearchGraph")(function* () {
1375
- const { objects } = yield* DatabaseService6.runQuery(Query2.type(ResearchGraph));
1412
+ }), SystemTypeAnnotation.set(true));
1413
+ var queryResearchGraph = Effect10.fn("queryResearchGraph")(function* () {
1414
+ const objects = yield* Database7.runQuery(Query2.type(ResearchGraph));
1376
1415
  return objects.at(0);
1377
1416
  });
1378
- var createResearchGraph = Effect9.fn("createResearchGraph")(function* () {
1417
+ var createResearchGraph = Effect10.fn("createResearchGraph")(function* () {
1379
1418
  const queue = yield* QueueService.createQueue();
1380
- return yield* DatabaseService6.add(Obj5.make(ResearchGraph, {
1381
- queue: Ref2.fromDXN(queue.dxn)
1419
+ return yield* Database7.add(Obj6.make(ResearchGraph, {
1420
+ queue: Ref3.fromDXN(queue.dxn)
1382
1421
  }));
1383
1422
  });
1384
- var contextQueueLayerFromResearchGraph = Layer2.unwrapEffect(Effect9.gen(function* () {
1423
+ var contextQueueLayerFromResearchGraph = Layer2.unwrapEffect(Effect10.gen(function* () {
1385
1424
  const researchGraph = (yield* queryResearchGraph()) ?? (yield* createResearchGraph());
1386
- const researchQueue = yield* DatabaseService6.load(researchGraph.queue);
1425
+ const researchQueue = yield* Database7.load(researchGraph.queue);
1387
1426
  return ContextQueueService2.layer(researchQueue);
1388
1427
  }));
1389
1428
 
@@ -1392,7 +1431,7 @@ var research_instructions_default = "You are the Research Agent.\n\nThe Research
1392
1431
 
1393
1432
  // src/functions/research/types.ts
1394
1433
  import { Text } from "@dxos/schema";
1395
- import { Event, HasConnection, HasRelationship, LegacyOrganization, LegacyPerson, Project, Task } from "@dxos/types";
1434
+ import { Event, HasConnection, HasRelationship, LegacyOrganization, LegacyPerson, Pipeline, Task } from "@dxos/types";
1396
1435
  var ResearchDataTypes = [
1397
1436
  // Objects
1398
1437
  Event.Event,
@@ -1403,13 +1442,13 @@ var ResearchDataTypes = [
1403
1442
  // TODO(wittjosiah): Until views (e.g., Table) support relations this needs to be expressed via organization ref.
1404
1443
  // Employer.Employer,
1405
1444
  LegacyPerson,
1406
- Project.Project,
1445
+ Pipeline.Pipeline,
1407
1446
  HasRelationship.HasRelationship,
1408
1447
  HasConnection.HasConnection
1409
1448
  ];
1410
1449
 
1411
1450
  // src/functions/research/research.ts
1412
- var research_default = defineFunction8({
1451
+ var research_default = defineFunction9({
1413
1452
  key: "dxos.org/function/research",
1414
1453
  name: "Research",
1415
1454
  description: trim3`
@@ -1417,24 +1456,24 @@ var research_default = defineFunction8({
1417
1456
  Inserts structured data into the research graph.
1418
1457
  Creates a research summary and returns the objects created.
1419
1458
  `,
1420
- inputSchema: Schema10.Struct({
1421
- query: Schema10.String.annotations({
1459
+ inputSchema: Schema11.Struct({
1460
+ query: Schema11.String.annotations({
1422
1461
  description: trim3`
1423
1462
  The search query.
1424
1463
  If doing research on an object then load it first and pass it as JSON.
1425
1464
  `
1426
1465
  }),
1427
- instructions: Schema10.optional(Schema10.String).annotations({
1466
+ instructions: Schema11.optional(Schema11.String).annotations({
1428
1467
  description: trim3`
1429
1468
  The instructions for the research agent.
1430
1469
  `
1431
1470
  }),
1432
1471
  // TOOD(burdon): Move to context.
1433
- mockSearch: Schema10.optional(Schema10.Boolean).annotations({
1472
+ mockSearch: Schema11.optional(Schema11.Boolean).annotations({
1434
1473
  description: "Whether to use the mock search tool.",
1435
1474
  default: false
1436
1475
  }),
1437
- entityExtraction: Schema10.optional(Schema10.Boolean).annotations({
1476
+ entityExtraction: Schema11.optional(Schema11.Boolean).annotations({
1438
1477
  description: trim3`
1439
1478
  Whether to extract structured entities from the research.
1440
1479
  Experimental feature only enable if user explicitly requests it.
@@ -1442,17 +1481,17 @@ var research_default = defineFunction8({
1442
1481
  default: false
1443
1482
  })
1444
1483
  }),
1445
- outputSchema: Schema10.Struct({
1446
- document: Schema10.optional(Schema10.String).annotations({
1484
+ outputSchema: Schema11.Struct({
1485
+ document: Schema11.optional(Schema11.String).annotations({
1447
1486
  description: "The generated research document."
1448
1487
  }),
1449
- objects: Schema10.Array(Schema10.Unknown).annotations({
1488
+ objects: Schema11.Array(Schema11.Unknown).annotations({
1450
1489
  description: "Structured objects created during the research process."
1451
1490
  })
1452
1491
  }),
1453
- 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 } }) {
1454
1493
  if (mockSearch) {
1455
- const mockPerson = yield* DatabaseService7.add(Obj6.make(Person.Person, {
1494
+ const mockPerson = yield* Database8.add(Obj7.make(Person.Person, {
1456
1495
  preferredName: "John Doe",
1457
1496
  emails: [
1458
1497
  {
@@ -1468,14 +1507,14 @@ var research_default = defineFunction8({
1468
1507
  return {
1469
1508
  document: trim3`
1470
1509
  The research ran in test-mode and was mocked. Proceed as usual.
1471
- We reference John Doe to test reference: ${Obj6.getDXN(mockPerson)}
1510
+ We reference John Doe to test reference: ${Obj7.getDXN(mockPerson)}
1472
1511
  `,
1473
1512
  objects: [
1474
- Obj6.toJSON(mockPerson)
1513
+ Obj7.toJSON(mockPerson)
1475
1514
  ]
1476
1515
  };
1477
1516
  }
1478
- yield* DatabaseService7.flush({
1517
+ yield* Database8.flush({
1479
1518
  indexes: true
1480
1519
  });
1481
1520
  yield* TracingService4.emitStatus({
@@ -1497,34 +1536,26 @@ var research_default = defineFunction8({
1497
1536
  }
1498
1537
  const finishedToolkit = yield* createToolkit2({
1499
1538
  toolkit
1500
- }).pipe(Effect10.provide(handlers));
1539
+ }).pipe(Effect11.provide(handlers));
1501
1540
  const session = new AiSession2();
1502
1541
  const result = yield* session.run({
1503
1542
  prompt: query,
1504
1543
  system: join(Template2.process(research_instructions_default, {
1505
1544
  entityExtraction
1506
- }), instructions6 && `<instructions>${instructions6}</instructions>`),
1545
+ }), instructions7 && `<instructions>${instructions7}</instructions>`),
1507
1546
  toolkit: finishedToolkit,
1508
1547
  observer: GenerationObserver2.fromPrinter(new ConsolePrinter2({
1509
1548
  tag: "research"
1510
1549
  }))
1511
1550
  });
1512
- const objects = yield* Effect10.forEach(objectDXNs, (dxn) => DatabaseService7.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))));
1513
1552
  return {
1514
1553
  document: extractLastTextBlock(result),
1515
1554
  objects
1516
1555
  };
1517
- }, Effect10.provide(Layer3.mergeAll(
1518
- AiService2.model("@anthropic/claude-sonnet-4-0"),
1519
- // TODO(dmaretskyi): Extract.
1520
- makeToolResolverFromFunctions([
1521
- exa_default,
1522
- mock_default
1523
- ], Toolkit2.make()),
1524
- makeToolExecutionServiceFromFunctions(Toolkit2.make(), Layer3.empty)
1525
- ).pipe(Layer3.provide(
1556
+ }, Effect11.provide(Layer3.mergeAll(AiService2.model("@anthropic/claude-sonnet-4-0"), ToolExecutionServices).pipe(Layer3.provide(
1526
1557
  // TODO(dmaretskyi): This should be provided by environment.
1527
- Layer3.mergeAll(FunctionInvocationServiceLayerTestMocked({
1558
+ Layer3.mergeAll(GenericToolkit.providerEmpty, FunctionInvocationServiceLayerTestMocked({
1528
1559
  functions: [
1529
1560
  exa_default,
1530
1561
  mock_default
@@ -1534,7 +1565,7 @@ var research_default = defineFunction8({
1534
1565
  });
1535
1566
  var join = (...strings) => strings.filter(Boolean).join("\n\n");
1536
1567
  var extractLastTextBlock = (result) => {
1537
- 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(() => ""));
1538
1569
  };
1539
1570
 
1540
1571
  // src/functions/research/index.ts
@@ -1546,26 +1577,26 @@ var Research;
1546
1577
 
1547
1578
  // src/functions/entity-extraction/entity-extraction.ts
1548
1579
  var __dxlog_file5 = "/__w/dxos/dxos/packages/core/assistant-toolkit/src/functions/entity-extraction/entity-extraction.ts";
1549
- var entity_extraction_default = defineFunction9({
1580
+ var entity_extraction_default = defineFunction10({
1550
1581
  key: "dxos.org/functions/entity-extraction",
1551
1582
  name: "Entity Extraction",
1552
1583
  description: "Extracts entities from emails and transcripts.",
1553
- inputSchema: Schema11.Struct({
1584
+ inputSchema: Schema12.Struct({
1554
1585
  source: Message2.Message.annotations({
1555
1586
  description: "Email or transcript to extract entities from."
1556
1587
  }),
1557
1588
  // TODO(dmaretskyi): Consider making this an array of blueprints instead.
1558
- instructions: Schema11.optional(Schema11.String).annotations({
1589
+ instructions: Schema12.optional(Schema12.String).annotations({
1559
1590
  description: "Instructions extraction process."
1560
1591
  })
1561
1592
  }),
1562
- outputSchema: Schema11.Struct({
1563
- entities: Schema11.optional(Schema11.Array(Obj7.Any).annotations({
1593
+ outputSchema: Schema12.Struct({
1594
+ entities: Schema12.optional(Schema12.Array(Type7.Obj).annotations({
1564
1595
  description: "Extracted entities."
1565
1596
  }))
1566
1597
  }),
1567
- handler: Effect11.fnUntraced(function* ({ data: { source: message, instructions: instructions6 } }) {
1568
- const tags = Obj7.getMeta(message)?.tags;
1598
+ handler: Effect12.fnUntraced(function* ({ data: { source: message, instructions: instructions7 } }) {
1599
+ const tags = Obj8.getMeta(message)?.tags;
1569
1600
  const contact = yield* extractContact(message.sender, tags);
1570
1601
  let organization = null;
1571
1602
  if (contact && !contact.organization) {
@@ -1578,12 +1609,12 @@ var entity_extraction_default = defineFunction9({
1578
1609
  const GraphWriterHandler = makeGraphWriterHandler(GraphWriterToolkit, {
1579
1610
  onAppend: (dxns) => created.push(...dxns)
1580
1611
  });
1581
- 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))));
1582
1613
  yield* new AiSession3().run({
1583
1614
  system: trim4`
1584
1615
  Extract the sender's organization from the email. If you are not sure, do nothing.
1585
1616
  The extracted organization URL must match the sender's email domain.
1586
- ${instructions6 ? "<user_intructions>" + instructions6 + "</user_intructions>" : ""},
1617
+ ${instructions7 ? "<user_intructions>" + instructions7 + "</user_intructions>" : ""},
1587
1618
  `,
1588
1619
  prompt: JSON.stringify({
1589
1620
  source: message,
@@ -1594,10 +1625,15 @@ var entity_extraction_default = defineFunction9({
1594
1625
  if (created.length > 1) {
1595
1626
  throw new Error("Multiple organizations created");
1596
1627
  } else if (created.length === 1) {
1597
- organization = yield* DatabaseService8.resolve(created[0], Organization.Organization);
1598
- Obj7.getMeta(organization).tags ??= [];
1599
- Obj7.getMeta(organization).tags.push(...tags ?? []);
1600
- 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
+ });
1601
1637
  }
1602
1638
  }
1603
1639
  return {
@@ -1606,12 +1642,12 @@ var entity_extraction_default = defineFunction9({
1606
1642
  organization
1607
1643
  ].filter(Predicate.isNotNullable)
1608
1644
  };
1609
- }, 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(
1610
1646
  // TODO(dmaretskyi): This should be provided by environment.
1611
- Layer4.mergeAll(FunctionInvocationServiceLayerTest())
1647
+ Layer4.mergeAll(GenericToolkit2.providerEmpty, FunctionInvocationServiceLayerTest())
1612
1648
  ))))
1613
1649
  });
1614
- var extractContact = Effect11.fn("extractContact")(function* (actor, tags) {
1650
+ var extractContact = Effect12.fn("extractContact")(function* (actor, tags) {
1615
1651
  const name = actor.name;
1616
1652
  const email = actor.email;
1617
1653
  if (!email) {
@@ -1619,13 +1655,13 @@ var extractContact = Effect11.fn("extractContact")(function* (actor, tags) {
1619
1655
  actor
1620
1656
  }, {
1621
1657
  F: __dxlog_file5,
1622
- L: 100,
1658
+ L: 110,
1623
1659
  S: this,
1624
1660
  C: (f, a) => f(...a)
1625
1661
  });
1626
1662
  return void 0;
1627
1663
  }
1628
- const { objects: existingContacts } = yield* DatabaseService8.runQuery(Filter2.type(Person2.Person));
1664
+ const existingContacts = yield* Database9.runQuery(Filter2.type(Person2.Person));
1629
1665
  const existingContact = existingContacts.find((contact) => contact.emails?.some((contactEmail) => contactEmail.value === email));
1630
1666
  if (existingContact) {
1631
1667
  log5.info("Contact already exists", {
@@ -1633,25 +1669,31 @@ var extractContact = Effect11.fn("extractContact")(function* (actor, tags) {
1633
1669
  existingContact
1634
1670
  }, {
1635
1671
  F: __dxlog_file5,
1636
- L: 113,
1672
+ L: 123,
1637
1673
  S: this,
1638
1674
  C: (f, a) => f(...a)
1639
1675
  });
1640
1676
  return existingContact;
1641
1677
  }
1642
- const newContact = Obj7.make(Person2.Person, {
1643
- [Obj7.Meta]: {
1644
- tags
1645
- },
1678
+ const newContact = Obj8.make(Person2.Person, {
1679
+ ...tags ? {
1680
+ [Obj8.Meta]: {
1681
+ tags: [
1682
+ ...tags
1683
+ ]
1684
+ }
1685
+ } : {},
1646
1686
  emails: [
1647
1687
  {
1648
1688
  value: email
1649
1689
  }
1650
1690
  ]
1651
1691
  });
1652
- yield* DatabaseService8.add(newContact);
1692
+ yield* Database9.add(newContact);
1653
1693
  if (name) {
1654
- newContact.fullName = name;
1694
+ Obj8.change(newContact, (c) => {
1695
+ c.fullName = name;
1696
+ });
1655
1697
  }
1656
1698
  const emailDomain = email.split("@")[1]?.toLowerCase();
1657
1699
  if (!emailDomain) {
@@ -1659,7 +1701,7 @@ var extractContact = Effect11.fn("extractContact")(function* (actor, tags) {
1659
1701
  email
1660
1702
  }, {
1661
1703
  F: __dxlog_file5,
1662
- L: 129,
1704
+ L: 141,
1663
1705
  S: this,
1664
1706
  C: (f, a) => f(...a)
1665
1707
  });
@@ -1669,11 +1711,11 @@ var extractContact = Effect11.fn("extractContact")(function* (actor, tags) {
1669
1711
  emailDomain
1670
1712
  }, {
1671
1713
  F: __dxlog_file5,
1672
- L: 133,
1714
+ L: 145,
1673
1715
  S: this,
1674
1716
  C: (f, a) => f(...a)
1675
1717
  });
1676
- const { objects: existingOrganisations } = yield* DatabaseService8.runQuery(Filter2.type(Organization.Organization));
1718
+ const existingOrganisations = yield* Database9.runQuery(Filter2.type(Organization.Organization));
1677
1719
  const matchingOrg = existingOrganisations.find((org) => {
1678
1720
  if (org.website) {
1679
1721
  try {
@@ -1686,7 +1728,7 @@ var extractContact = Effect11.fn("extractContact")(function* (actor, tags) {
1686
1728
  error: e
1687
1729
  }, {
1688
1730
  F: __dxlog_file5,
1689
- L: 151,
1731
+ L: 163,
1690
1732
  S: this,
1691
1733
  C: (f, a) => f(...a)
1692
1734
  });
@@ -1700,11 +1742,13 @@ var extractContact = Effect11.fn("extractContact")(function* (actor, tags) {
1700
1742
  organization: matchingOrg
1701
1743
  }, {
1702
1744
  F: __dxlog_file5,
1703
- L: 159,
1745
+ L: 174,
1704
1746
  S: this,
1705
1747
  C: (f, a) => f(...a)
1706
1748
  });
1707
- newContact.organization = Ref3.make(matchingOrg);
1749
+ Obj8.change(newContact, (c) => {
1750
+ c.organization = Ref4.make(matchingOrg);
1751
+ });
1708
1752
  }
1709
1753
  return newContact;
1710
1754
  });
@@ -1719,57 +1763,58 @@ var EntityExtraction;
1719
1763
  import * as FetchHttpClient2 from "@effect/platform/FetchHttpClient";
1720
1764
  import * as HttpClient from "@effect/platform/HttpClient";
1721
1765
  import * as Array9 from "effect/Array";
1722
- import * as Effect13 from "effect/Effect";
1766
+ import * as Effect14 from "effect/Effect";
1723
1767
  import * as Function5 from "effect/Function";
1724
- import * as Schema12 from "effect/Schema";
1725
- import { Filter as Filter4, Obj as Obj9, Query as Query4, Ref as Ref5 } from "@dxos/echo";
1726
- import { DatabaseService as DatabaseService10, 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";
1727
1772
  import { log as log7 } from "@dxos/log";
1728
- 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";
1729
1774
 
1730
1775
  // src/sync/sync.ts
1731
- import * as Effect12 from "effect/Effect";
1732
- import { Filter as Filter3, Obj as Obj8, Query as Query3, Ref as Ref4 } from "@dxos/echo";
1733
- import { DatabaseService as DatabaseService9 } from "@dxos/functions";
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";
1734
1779
  import { failedInvariant } from "@dxos/invariant";
1735
1780
  import { log as log6 } from "@dxos/log";
1736
1781
  var __dxlog_file6 = "/__w/dxos/dxos/packages/core/assistant-toolkit/src/sync/sync.ts";
1737
- var syncObjects = Effect12.fn("syncObjects")(function* (objs, { foreignKeyId }) {
1738
- 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) {
1739
1784
  for (const key of Object.keys(obj)) {
1740
1785
  if (typeof key !== "string" || key === "id") continue;
1741
- if (!Ref4.isRef(obj[key])) continue;
1786
+ if (!Ref5.isRef(obj[key])) continue;
1742
1787
  const ref = obj[key];
1743
1788
  if (!ref.target) continue;
1744
- if (Obj8.getDXN(ref.target).isLocalObjectId()) {
1789
+ if (Obj9.getDXN(ref.target).isLocalObjectId()) {
1745
1790
  const [target] = yield* syncObjects([
1746
1791
  ref.target
1747
1792
  ], {
1748
1793
  foreignKeyId
1749
1794
  });
1750
- obj[key] = Ref4.make(target);
1795
+ obj[key] = Ref5.make(target);
1751
1796
  }
1752
1797
  }
1753
- const schema = Obj8.getSchema(obj) ?? failedInvariant("No schema.");
1754
- const foreignId = Obj8.getKeys(obj, foreignKeyId)[0]?.id ?? failedInvariant("No foreign key.");
1755
- const { objects: [existing] } = yield* DatabaseService9.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, [
1756
1801
  {
1757
1802
  source: foreignKeyId,
1758
1803
  id: foreignId
1759
1804
  }
1760
1805
  ])));
1761
1806
  log6("sync object", {
1762
- type: Obj8.getTypename(obj),
1807
+ type: Obj9.getTypename(obj),
1763
1808
  foreignId,
1764
- existing: existing ? Obj8.getDXN(existing) : void 0
1809
+ existing: existing ? Obj9.getDXN(existing) : void 0
1765
1810
  }, {
1766
1811
  F: __dxlog_file6,
1767
- L: 47,
1812
+ L: 48,
1768
1813
  S: this,
1769
1814
  C: (f, a) => f(...a)
1770
1815
  });
1771
1816
  if (!existing) {
1772
- yield* DatabaseService9.add(obj);
1817
+ yield* Database10.add(obj);
1773
1818
  return obj;
1774
1819
  } else {
1775
1820
  copyObjectData(existing, obj);
@@ -1780,23 +1825,25 @@ var syncObjects = Effect12.fn("syncObjects")(function* (objs, { foreignKeyId })
1780
1825
  });
1781
1826
  });
1782
1827
  var copyObjectData = (existing, newObj) => {
1783
- for (const key of Object.keys(newObj)) {
1784
- if (typeof key !== "string" || key === "id") continue;
1785
- if (typeof newObj[key] !== "string" && typeof newObj[key] !== "number" && typeof newObj[key] !== "boolean" && !Ref4.isRef(newObj[key])) continue;
1786
- existing[key] = newObj[key];
1787
- }
1788
- for (const key of Object.keys(existing)) {
1789
- if (typeof key !== "string" || key === "id") continue;
1790
- if (!(key in newObj)) {
1791
- 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];
1792
1833
  }
1793
- }
1794
- for (const foreignKey of Obj8.getMeta(newObj).keys) {
1795
- Obj8.deleteKeys(existing, foreignKey.source);
1796
- Obj8.getMeta(existing).keys.push({
1797
- ...foreignKey
1798
- });
1799
- }
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
+ });
1800
1847
  };
1801
1848
 
1802
1849
  // src/util/graphql.ts
@@ -1826,7 +1873,7 @@ query Issues($teamId: String!, $after: DateTimeOrDuration!) {
1826
1873
  updatedAt
1827
1874
  description
1828
1875
  assignee { id, name }
1829
- state {
1876
+ state {
1830
1877
  name
1831
1878
  }
1832
1879
  project {
@@ -1847,25 +1894,26 @@ query Issues($teamId: String!, $after: DateTimeOrDuration!) {
1847
1894
  var LINEAR_ID_KEY = "linear.app/id";
1848
1895
  var LINEAR_TEAM_ID_KEY = "linear.app/teamId";
1849
1896
  var LINEAR_UPDATED_AT_KEY = "linear.app/updatedAt";
1850
- var sync_issues_default = defineFunction10({
1897
+ var sync_issues_default = defineFunction11({
1851
1898
  key: "dxos.org/function/linear/sync-issues",
1852
1899
  name: "Linear",
1853
1900
  description: "Sync issues from Linear.",
1854
- inputSchema: Schema12.Struct({
1855
- team: Schema12.String.annotations({
1901
+ inputSchema: Schema13.Struct({
1902
+ team: Schema13.String.annotations({
1856
1903
  description: "Linear team id."
1857
1904
  })
1858
1905
  }),
1859
- handler: Effect13.fnUntraced(function* ({ data }) {
1860
- const client = yield* HttpClient.HttpClient.pipe(Effect13.map(withAuthorization({
1906
+ handler: Effect14.fnUntraced(function* ({ data }) {
1907
+ const credential = yield* CredentialsService3.getCredential({
1861
1908
  service: "linear.app"
1862
- })));
1909
+ });
1910
+ const client = yield* HttpClient.HttpClient.pipe(Effect14.map(withAuthorization(credential.apiKey)));
1863
1911
  const after = yield* getLatestUpdateTimestamp(data.team, Task2.Task);
1864
1912
  log7.info("will fetch", {
1865
1913
  after
1866
1914
  }, {
1867
1915
  F: __dxlog_file7,
1868
- L: 91,
1916
+ L: 93,
1869
1917
  S: this,
1870
1918
  C: (f, a) => f(...a)
1871
1919
  });
@@ -1883,7 +1931,7 @@ var sync_issues_default = defineFunction10({
1883
1931
  count: tasks.length
1884
1932
  }, {
1885
1933
  F: __dxlog_file7,
1886
- L: 104,
1934
+ L: 106,
1887
1935
  S: this,
1888
1936
  C: (f, a) => f(...a)
1889
1937
  });
@@ -1893,19 +1941,19 @@ var sync_issues_default = defineFunction10({
1893
1941
  }),
1894
1942
  syncComplete: tasks.length < 150
1895
1943
  };
1896
- }, Effect13.provide(FetchHttpClient2.layer))
1944
+ }, Effect14.provide(FetchHttpClient2.layer))
1897
1945
  });
1898
- var getLatestUpdateTimestamp = Effect13.fnUntraced(function* (teamId, dataType) {
1899
- const { objects: existingTasks } = yield* DatabaseService10.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, [
1900
1948
  {
1901
1949
  source: LINEAR_TEAM_ID_KEY,
1902
1950
  id: teamId
1903
1951
  }
1904
1952
  ])));
1905
- 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));
1906
1954
  });
1907
- var mapLinearPerson = (person, { teamId }) => Obj9.make(Person3.Person, {
1908
- [Obj9.Meta]: {
1955
+ var mapLinearPerson = (person, { teamId }) => Obj10.make(Person3.Person, {
1956
+ [Obj10.Meta]: {
1909
1957
  keys: [
1910
1958
  {
1911
1959
  id: person.id,
@@ -1919,8 +1967,8 @@ var mapLinearPerson = (person, { teamId }) => Obj9.make(Person3.Person, {
1919
1967
  },
1920
1968
  nickname: person.name
1921
1969
  });
1922
- var mapLinearIssue = (issue, { teamId }) => Obj9.make(Task2.Task, {
1923
- [Obj9.Meta]: {
1970
+ var mapLinearIssue = (issue, { teamId }) => Obj10.make(Task2.Task, {
1971
+ [Obj10.Meta]: {
1924
1972
  keys: [
1925
1973
  {
1926
1974
  id: issue.id,
@@ -1938,13 +1986,13 @@ var mapLinearIssue = (issue, { teamId }) => Obj9.make(Task2.Task, {
1938
1986
  },
1939
1987
  title: issue.title ?? void 0,
1940
1988
  description: issue.description ?? void 0,
1941
- assigned: !issue.assignee ? void 0 : Ref5.make(mapLinearPerson(issue.assignee, {
1989
+ assigned: !issue.assignee ? void 0 : Ref6.make(mapLinearPerson(issue.assignee, {
1942
1990
  teamId
1943
1991
  })),
1944
1992
  // TODO(dmaretskyi): Sync those (+ linear team as org?).
1945
1993
  // state: issue.state.name,
1946
- project: !issue.project ? void 0 : Ref5.make(Project2.make({
1947
- [Obj9.Meta]: {
1994
+ project: !issue.project ? void 0 : Ref6.make(Pipeline2.make({
1995
+ [Obj10.Meta]: {
1948
1996
  keys: [
1949
1997
  {
1950
1998
  id: issue.project.id,
@@ -1967,26 +2015,26 @@ var mapLinearIssue = (issue, { teamId }) => Obj9.make(Task2.Task, {
1967
2015
  var Linear;
1968
2016
 
1969
2017
  // src/functions/tasks/read.ts
1970
- import * as Effect14 from "effect/Effect";
1971
- import * as Schema13 from "effect/Schema";
1972
- import { ArtifactId as ArtifactId4 } from "@dxos/assistant";
1973
- import { DatabaseService as DatabaseService11, defineFunction as defineFunction11 } from "@dxos/functions";
1974
- import { Markdown as Markdown4 } from "@dxos/plugin-markdown/types";
1975
- 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({
1976
2024
  key: "dxos.org/function/markdown/read-tasks",
1977
2025
  name: "Read",
1978
2026
  description: "Read markdown tasks.",
1979
- inputSchema: Schema13.Struct({
1980
- id: ArtifactId4.annotations({
2027
+ inputSchema: Schema14.Struct({
2028
+ doc: Type8.Ref(Markdown5.Document).annotations({
1981
2029
  description: "The ID of the document to read."
1982
2030
  })
1983
2031
  }),
1984
- outputSchema: Schema13.Struct({
1985
- content: Schema13.String
2032
+ outputSchema: Schema14.Struct({
2033
+ content: Schema14.String
1986
2034
  }),
1987
- handler: Effect14.fn(function* ({ data: { id } }) {
1988
- const doc = yield* DatabaseService11.resolve(ArtifactId4.toDXN(id), Markdown4.Document);
1989
- const { content } = yield* DatabaseService11.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);
1990
2038
  const lines = content.split("\n");
1991
2039
  const len = String(lines.length).length;
1992
2040
  const numbered = lines.map((line, i) => `${String(i + 1).padStart(len, " ")}. ${line}`).join("\n");
@@ -1997,11 +2045,11 @@ var read_default2 = defineFunction11({
1997
2045
  });
1998
2046
 
1999
2047
  // src/functions/tasks/update.ts
2000
- import * as Effect15 from "effect/Effect";
2001
- import * as Schema14 from "effect/Schema";
2002
- import { ArtifactId as ArtifactId5 } from "@dxos/assistant";
2003
- import { DatabaseService as DatabaseService12, defineFunction as defineFunction12 } from "@dxos/functions";
2004
- 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";
2005
2053
 
2006
2054
  // src/functions/tasks/task-list.ts
2007
2055
  var MarkdownTasks = class {
@@ -2132,27 +2180,27 @@ var MarkdownTasks = class {
2132
2180
  };
2133
2181
 
2134
2182
  // src/functions/tasks/update.ts
2135
- var update_default2 = defineFunction12({
2183
+ var update_default2 = defineFunction13({
2136
2184
  key: "dxos.org/function/markdown/update-tasks",
2137
2185
  name: "Update markdown",
2138
2186
  description: "Creates and updates tasks in markdown documents.",
2139
- inputSchema: Schema14.Struct({
2140
- id: ArtifactId5.annotations({
2187
+ inputSchema: Schema15.Struct({
2188
+ doc: Type9.Ref(Markdown6.Document).annotations({
2141
2189
  description: "The ID of the document to update."
2142
2190
  }),
2143
- operations: Schema14.optional(Schema14.Array(Schema14.Any.annotations({
2191
+ operations: Schema15.optional(Schema15.Array(Schema15.Any.annotations({
2144
2192
  description: "Task operations to apply."
2145
2193
  })))
2146
2194
  }),
2147
- outputSchema: Schema14.Struct({
2148
- content: Schema14.String,
2149
- numberedContent: Schema14.String.annotations({
2195
+ outputSchema: Schema15.Struct({
2196
+ content: Schema15.String,
2197
+ numberedContent: Schema15.String.annotations({
2150
2198
  description: "Content with line numbers for agent reference."
2151
2199
  })
2152
2200
  }),
2153
- handler: Effect15.fn(function* ({ data: { id, operations = [] } }) {
2154
- const doc = yield* DatabaseService12.resolve(ArtifactId5.toDXN(id), Markdown5.Document);
2155
- const { content } = yield* DatabaseService12.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);
2156
2204
  const taskManager = new MarkdownTasks(content);
2157
2205
  if (operations.length > 0) {
2158
2206
  taskManager.applyOperations(operations);
@@ -2181,27 +2229,26 @@ var instructions = trim5`
2181
2229
  When replying to the user, be terse with your comments about design doc handling.
2182
2230
  Do not announce when you read or write the design spec document.
2183
2231
  `;
2184
- var blueprint = Obj10.make(Blueprint.Blueprint, {
2232
+ var blueprint = Blueprint.make({
2185
2233
  key: "dxos.org/blueprint/design",
2186
2234
  name: "Design Spec",
2187
2235
  description: "Preserve the conversation in the design spec.",
2188
2236
  instructions: {
2189
- source: Ref6.make(Text2.make(instructions))
2237
+ source: Ref7.make(Text2.make(instructions))
2190
2238
  },
2191
2239
  tools: [
2192
2240
  Document.read,
2193
2241
  Document.update
2194
- ].map((fn9) => ToolId.make(fn9.key))
2242
+ ].map((fn11) => ToolId.make(fn11.key))
2195
2243
  });
2196
- var design_blueprint_default = blueprint;
2197
2244
 
2198
2245
  // src/blueprints/design/index.ts
2199
- var design_default = design_blueprint_default;
2246
+ var design_default = blueprint;
2200
2247
 
2201
2248
  // src/blueprints/discord/discord-blueprint.ts
2202
2249
  import { ToolId as ToolId2 } from "@dxos/ai";
2203
2250
  import { Blueprint as Blueprint2 } from "@dxos/blueprints";
2204
- import { Obj as Obj11, Ref as Ref7 } from "@dxos/echo";
2251
+ import { Ref as Ref8 } from "@dxos/echo";
2205
2252
  import { Text as Text3 } from "@dxos/schema";
2206
2253
  import { trim as trim6 } from "@dxos/util";
2207
2254
  var instructions2 = trim6`
@@ -2211,26 +2258,25 @@ var instructions2 = trim6`
2211
2258
 
2212
2259
  DXOS serverId: 837138313172353095
2213
2260
  `;
2214
- var blueprint2 = Obj11.make(Blueprint2.Blueprint, {
2261
+ var blueprint2 = Blueprint2.make({
2215
2262
  key: "dxos.org/blueprint/discord",
2216
2263
  name: "Discord",
2217
2264
  description: "Discord integration.",
2218
2265
  instructions: {
2219
- source: Ref7.make(Text3.make(instructions2))
2266
+ source: Ref8.make(Text3.make(instructions2))
2220
2267
  },
2221
2268
  tools: [
2222
2269
  ToolId2.make(Discord.fetch.key)
2223
2270
  ]
2224
2271
  });
2225
- var discord_blueprint_default = blueprint2;
2226
2272
 
2227
2273
  // src/blueprints/discord/index.ts
2228
- var discord_default = discord_blueprint_default;
2274
+ var discord_default = blueprint2;
2229
2275
 
2230
2276
  // src/blueprints/linear/linear-blueprint.ts
2231
2277
  import { ToolId as ToolId3 } from "@dxos/ai";
2232
2278
  import { Blueprint as Blueprint3 } from "@dxos/blueprints";
2233
- import { Obj as Obj12, Ref as Ref8 } from "@dxos/echo";
2279
+ import { Ref as Ref9 } from "@dxos/echo";
2234
2280
  import { Text as Text4 } from "@dxos/schema";
2235
2281
  import { trim as trim7 } from "@dxos/util";
2236
2282
  var instructions3 = trim7`
@@ -2241,26 +2287,25 @@ var instructions3 = trim7`
2241
2287
 
2242
2288
  DXOS teamId: 1127c63a-6f77-4725-9229-50f6cd47321c
2243
2289
  `;
2244
- var blueprint3 = Obj12.make(Blueprint3.Blueprint, {
2290
+ var blueprint3 = Blueprint3.make({
2245
2291
  key: "dxos.org/blueprint/linear",
2246
2292
  name: "Linear",
2247
2293
  description: "Syncs Linear workspaces.",
2248
2294
  instructions: {
2249
- source: Ref8.make(Text4.make(instructions3))
2295
+ source: Ref9.make(Text4.make(instructions3))
2250
2296
  },
2251
2297
  tools: [
2252
2298
  Linear.sync
2253
2299
  ].map((tool) => ToolId3.make(tool.key))
2254
2300
  });
2255
- var linear_blueprint_default = blueprint3;
2256
2301
 
2257
2302
  // src/blueprints/linear/index.ts
2258
- var linear_default = linear_blueprint_default;
2303
+ var linear_default = blueprint3;
2259
2304
 
2260
2305
  // src/blueprints/planning/planning-blueprint.ts
2261
2306
  import { ToolId as ToolId4 } from "@dxos/ai";
2262
2307
  import { Blueprint as Blueprint4 } from "@dxos/blueprints";
2263
- import { Obj as Obj13, Ref as Ref9 } from "@dxos/echo";
2308
+ import { Ref as Ref10 } from "@dxos/echo";
2264
2309
  import { Text as Text5 } from "@dxos/schema";
2265
2310
  import { trim as trim8 } from "@dxos/util";
2266
2311
  var instructions4 = trim8`
@@ -2334,27 +2379,26 @@ var instructions4 = trim8`
2334
2379
  - When creating subtasks, consider the parent task's completion status
2335
2380
  - Be precise with task descriptions and hierarchy levels
2336
2381
  `;
2337
- var blueprint4 = Obj13.make(Blueprint4.Blueprint, {
2382
+ var blueprint4 = Blueprint4.make({
2338
2383
  key: "dxos.org/blueprint/planning",
2339
2384
  name: "Planning",
2340
2385
  description: "Plans and tracks complex tasks with artifact management.",
2341
2386
  instructions: {
2342
- source: Ref9.make(Text5.make(instructions4))
2387
+ source: Ref10.make(Text5.make(instructions4))
2343
2388
  },
2344
2389
  tools: [
2345
2390
  Tasks.read,
2346
2391
  Tasks.update
2347
- ].map((fn9) => ToolId4.make(fn9.key))
2392
+ ].map((fn11) => ToolId4.make(fn11.key))
2348
2393
  });
2349
- var planning_blueprint_default = blueprint4;
2350
2394
 
2351
2395
  // src/blueprints/planning/index.ts
2352
- var planning_default = planning_blueprint_default;
2396
+ var planning_default = blueprint4;
2353
2397
 
2354
2398
  // src/blueprints/research/research-blueprint.ts
2355
2399
  import { ToolId as ToolId5 } from "@dxos/ai";
2356
2400
  import { Blueprint as Blueprint5 } from "@dxos/blueprints";
2357
- import { Obj as Obj14, Ref as Ref10 } from "@dxos/echo";
2401
+ import { Ref as Ref11 } from "@dxos/echo";
2358
2402
  import { Text as Text6 } from "@dxos/schema";
2359
2403
  import { trim as trim9 } from "@dxos/util";
2360
2404
  var instructions5 = trim9`
@@ -2383,85 +2427,650 @@ var instructions5 = trim9`
2383
2427
  Reply normally with the text mode of the result of your research.
2384
2428
  </unstructured_mode>
2385
2429
  `;
2386
- var blueprint5 = Obj14.make(Blueprint5.Blueprint, {
2430
+ var blueprint5 = Blueprint5.make({
2387
2431
  key: "dxos.org/blueprint/research",
2388
2432
  name: "Research",
2389
2433
  description: "Researches the web and creates structured data.",
2390
2434
  instructions: {
2391
- source: Ref10.make(Text6.make(instructions5))
2435
+ source: Ref11.make(Text6.make(instructions5))
2392
2436
  },
2393
2437
  tools: [
2394
2438
  Research.create,
2395
2439
  Research.research
2396
- ].map((fn9) => ToolId5.make(fn9.key))
2440
+ ].map((fn11) => ToolId5.make(fn11.key))
2397
2441
  });
2398
- var research_blueprint_default = blueprint5;
2399
2442
 
2400
2443
  // src/blueprints/research/index.ts
2401
- var research_default2 = research_blueprint_default;
2444
+ var research_default2 = blueprint5;
2402
2445
 
2403
2446
  // src/blueprints/websearch/websearch-blueprint.ts
2404
2447
  import { ToolId as ToolId6 } from "@dxos/ai";
2405
2448
  import { Blueprint as Blueprint6 } from "@dxos/blueprints";
2406
- import { Obj as Obj15, Ref as Ref11 } from "@dxos/echo";
2449
+ import { Ref as Ref12 } from "@dxos/echo";
2407
2450
  import { Text as Text7 } from "@dxos/schema";
2408
- var blueprint6 = Obj15.make(Blueprint6.Blueprint, {
2451
+ var blueprint6 = Blueprint6.make({
2409
2452
  key: "dxos.org/blueprint/web-search",
2410
2453
  name: "Web Search",
2411
2454
  description: "Search the web.",
2412
2455
  instructions: {
2413
- source: Ref11.make(Text7.make())
2456
+ source: Ref12.make(Text7.make())
2414
2457
  },
2415
2458
  tools: [
2416
2459
  ToolId6.make("AnthropicWebSearch")
2417
2460
  ]
2418
2461
  });
2419
- var websearch_blueprint_default = blueprint6;
2420
2462
 
2421
2463
  // src/blueprints/websearch/websearch-toolkit.ts
2422
- import * as Toolkit4 from "@effect/ai/Toolkit";
2464
+ import * as Toolkit3 from "@effect/ai/Toolkit";
2423
2465
  import * as AnthropicTool2 from "@effect/ai-anthropic/AnthropicTool";
2424
- var WebSearchToolkit = Toolkit4.make(AnthropicTool2.WebSearch_20250305({}));
2466
+ var WebSearchToolkit = Toolkit3.make(AnthropicTool2.WebSearch_20250305({}));
2425
2467
 
2426
2468
  // src/blueprints/websearch/index.ts
2427
- var websearch_default = websearch_blueprint_default;
2469
+ var websearch_default = blueprint6;
2428
2470
 
2429
- // src/plugins.tsx
2430
- import * as Schema15 from "effect/Schema";
2431
- import React from "react";
2432
- import { Capabilities, contributes, createSurface } from "@dxos/app-framework";
2433
- import { Type as Type3 } from "@dxos/echo";
2434
- import { JsonFilter } from "@dxos/react-ui-syntax-highlighter";
2435
- var MapSchema = Schema15.Struct({
2436
- coordinates: Type3.Format.GeoPoint
2437
- }).pipe(Type3.Obj({
2438
- 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",
2439
2586
  version: "0.1.0"
2440
2587
  }));
2441
- var isImage = (data) => false;
2442
- var capabilities = [
2443
- contributes(Capabilities.ReactSurface, createSurface({
2444
- id: "plugin-image",
2445
- role: "card--extrinsic",
2446
- filter: (data) => isImage(data.value),
2447
- component: ({ data }) => /* @__PURE__ */ React.createElement("img", {
2448
- className: "grow object-cover",
2449
- src: `data:image/jpeg;base64,${data.value.source.data}`,
2450
- alt: data.value.prompt ?? `Generated image [id=${data.value.id}]`
2451
- })
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)
2452
2634
  })),
2453
- //
2454
- // Default
2455
- //
2456
- contributes(Capabilities.ReactSurface, createSurface({
2457
- id: "plugin-default",
2458
- role: "card--extrinsic",
2459
- position: "fallback",
2460
- component: ({ role, data }) => /* @__PURE__ */ React.createElement(JsonFilter, {
2461
- 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."
2462
2815
  })
2463
- }))
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
2464
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
+ });
2465
3074
 
2466
3075
  // src/toolkits/AssistantToolkit.ts
2467
3076
  var AssistantToolkit_exports = {};
@@ -2471,37 +3080,62 @@ __export(AssistantToolkit_exports, {
2471
3080
  tools: () => tools
2472
3081
  });
2473
3082
  import * as Tool2 from "@effect/ai/Tool";
2474
- import * as Toolkit5 from "@effect/ai/Toolkit";
2475
- import * as Effect16 from "effect/Effect";
3083
+ import * as Toolkit4 from "@effect/ai/Toolkit";
3084
+ import * as Effect22 from "effect/Effect";
2476
3085
  import * as Record from "effect/Record";
2477
- import * as Schema16 from "effect/Schema";
2478
- import { AiContextService, ArtifactId as ArtifactId6 } from "@dxos/assistant";
2479
- import { Ref as Ref12 } from "@dxos/echo";
2480
- import { DatabaseService as DatabaseService13 } from "@dxos/functions";
2481
- import { trim as trim10 } from "@dxos/util";
2482
- var AssistantToolkit = Toolkit5.make(Tool2.make("add-to-context", {
2483
- 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`
2484
3092
  Adds the object to the chat context.
2485
3093
  `,
2486
3094
  parameters: {
2487
- id: ArtifactId6.annotations({
2488
- 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."
2489
3112
  })
2490
3113
  },
2491
- success: Schema16.Void,
2492
- failure: Schema16.Never,
3114
+ success: Schema23.Void,
3115
+ failure: Schema23.Never,
2493
3116
  dependencies: [
2494
- AiContextService,
2495
- DatabaseService13
3117
+ AiContextService5,
3118
+ Database19.Service
2496
3119
  ]
2497
3120
  }));
2498
3121
  var tools = Record.keys(AssistantToolkit.tools);
2499
3122
  var layer3 = () => AssistantToolkit.toLayer({
2500
- "add-to-context": Effect16.fnUntraced(function* ({ id }) {
2501
- const { binder } = yield* AiContextService;
2502
- const { db } = yield* DatabaseService13;
2503
- const ref = Ref12.fromDXN(ArtifactId6.toDXN(id, db.spaceId));
2504
- 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({
2505
3139
  blueprints: [],
2506
3140
  objects: [
2507
3141
  ref
@@ -2518,173 +3152,225 @@ __export(SystemToolkit_exports, {
2518
3152
  tools: () => tools2
2519
3153
  });
2520
3154
  import * as Tool3 from "@effect/ai/Tool";
2521
- import * as Toolkit6 from "@effect/ai/Toolkit";
2522
- import * as Effect17 from "effect/Effect";
3155
+ import * as Toolkit5 from "@effect/ai/Toolkit";
3156
+ import * as Effect23 from "effect/Effect";
2523
3157
  import * as Record2 from "effect/Record";
2524
- import * as Schema17 from "effect/Schema";
2525
- import { ArtifactId as ArtifactId7 } from "@dxos/assistant";
2526
- import { DXN as DXN2, Obj as Obj16, Relation as Relation2, Tag as Tag2, Type as Type4 } from "@dxos/echo";
2527
- import { DatabaseService as DatabaseService14 } from "@dxos/functions";
2528
- import { trim as trim11 } from "@dxos/util";
2529
- 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(
2530
3165
  //
2531
3166
  // Schema
2532
3167
  //
2533
3168
  Tool3.make("schema-list", {
2534
- description: trim11`
3169
+ description: trim14`
2535
3170
  Lists schemas definitions.
2536
3171
  `,
2537
3172
  parameters: {
2538
3173
  // TODO(wittjosiah): Remove this once parameter-less tools are fixed.
2539
- limit: Schema17.Number
3174
+ limit: Schema24.Number
2540
3175
  },
2541
3176
  // TODO(dmaretskyi): Effect returns ({ result, encodedResult })
2542
- success: Schema17.Any,
2543
- failure: Schema17.Never,
3177
+ success: Schema24.Any,
3178
+ failure: Schema24.Never,
2544
3179
  dependencies: [
2545
- DatabaseService14
3180
+ Database20.Service
2546
3181
  ]
2547
3182
  }),
2548
3183
  Tool3.make("schema-add", {
2549
- description: trim11`
3184
+ description: trim14`
2550
3185
  Adds a schema to the space.
2551
3186
  The name will be used when displayed to the user.
2552
3187
  The typename must be in the format of "example.com/type/Type".
2553
3188
  `,
2554
3189
  parameters: {
2555
- name: Schema17.String,
2556
- typename: Schema17.String,
2557
- jsonSchema: Schema17.Any
3190
+ name: Schema24.String,
3191
+ typename: Schema24.String,
3192
+ jsonSchema: Schema24.Any
2558
3193
  },
2559
- success: Schema17.Any,
2560
- failure: Schema17.Never,
3194
+ success: Schema24.Any,
3195
+ failure: Schema24.Never,
2561
3196
  dependencies: [
2562
- DatabaseService14
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
3210
+ },
3211
+ success: Schema24.Any,
3212
+ failure: Schema24.Never,
3213
+ dependencies: [
3214
+ Database20.Service
2563
3215
  ]
2564
3216
  }),
2565
3217
  //
2566
3218
  // Objects
2567
3219
  //
2568
3220
  Tool3.make("object-create", {
2569
- description: trim11`
3221
+ description: trim14`
2570
3222
  Creates a new object and adds it to the current space.
2571
3223
  Get the schema from the schema-list tool and ensure that the data matches the corresponding schema.
2572
3224
  `,
2573
3225
  parameters: {
2574
- typename: Schema17.String,
2575
- data: Schema17.Any
3226
+ typename: Schema24.String,
3227
+ data: Schema24.Any
3228
+ },
3229
+ success: Schema24.Any,
3230
+ failure: Schema24.Never,
3231
+ dependencies: [
3232
+ Database20.Service
3233
+ ]
3234
+ }),
3235
+ Tool3.make("object-delete", {
3236
+ description: trim14`
3237
+ Deletes the object.
3238
+ `,
3239
+ parameters: {
3240
+ id: ArtifactId2.annotations({
3241
+ description: "The ID of the object."
3242
+ })
2576
3243
  },
2577
- success: Schema17.Any,
2578
- failure: Schema17.Never,
3244
+ success: Schema24.Any,
3245
+ failure: Schema24.Never,
2579
3246
  dependencies: [
2580
- DatabaseService14
3247
+ Database20.Service
2581
3248
  ]
2582
3249
  }),
2583
- Tool3.make("object-remove", {
2584
- description: trim11`
2585
- Removes an object or relation from the database.
3250
+ Tool3.make("object-update", {
3251
+ description: trim14`
3252
+ Updates the object properties.
2586
3253
  `,
2587
3254
  parameters: {
2588
- id: ArtifactId7.annotations({
3255
+ id: ArtifactId2.annotations({
2589
3256
  description: "The ID of the object."
3257
+ }),
3258
+ properties: Schema24.Record({
3259
+ key: Schema24.String,
3260
+ value: Schema24.Any
2590
3261
  })
2591
3262
  },
2592
- success: Schema17.Any,
2593
- failure: Schema17.Never,
3263
+ success: Schema24.Any,
3264
+ failure: Schema24.Never,
2594
3265
  dependencies: [
2595
- DatabaseService14
3266
+ Database20.Service
2596
3267
  ]
2597
3268
  }),
2598
3269
  //
2599
3270
  // Relations
2600
3271
  //
2601
3272
  Tool3.make("relation-create", {
2602
- description: trim11`
3273
+ description: trim14`
2603
3274
  Creates a new relation and adds it to the current space.
2604
3275
  Get the schema from the schema-list tool and ensure that the data matches the corresponding schema.
2605
3276
  `,
2606
3277
  parameters: {
2607
- typename: Schema17.String,
2608
- source: ArtifactId7.annotations({
3278
+ typename: Schema24.String,
3279
+ source: ArtifactId2.annotations({
2609
3280
  description: "The ID of the source object."
2610
3281
  }),
2611
- target: ArtifactId7.annotations({
3282
+ target: ArtifactId2.annotations({
2612
3283
  description: "The ID of the target object."
2613
3284
  }),
2614
- data: Schema17.Any.annotations({
3285
+ data: Schema24.Any.annotations({
2615
3286
  description: "The data to be stored in the relation."
2616
3287
  })
2617
3288
  },
2618
- success: Schema17.Any,
2619
- 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,
2620
3306
  dependencies: [
2621
- DatabaseService14
3307
+ Database20.Service
2622
3308
  ]
2623
3309
  }),
2624
3310
  //
2625
3311
  // Tags
2626
3312
  //
2627
3313
  Tool3.make("tag-add", {
2628
- description: trim11`
3314
+ description: trim14`
2629
3315
  Adds a tag to an object.
2630
3316
  Tags are objects of type ${Tag2.Tag.typename}.
2631
3317
  `,
2632
3318
  parameters: {
2633
- tagId: ArtifactId7.annotations({
3319
+ tagId: ArtifactId2.annotations({
2634
3320
  description: "The ID of the tag."
2635
3321
  }),
2636
- objectId: ArtifactId7.annotations({
3322
+ objectId: ArtifactId2.annotations({
2637
3323
  description: "The ID of the object."
2638
3324
  })
2639
3325
  },
2640
- success: Schema17.Any,
2641
- failure: Schema17.Never,
3326
+ success: Schema24.Any,
3327
+ failure: Schema24.Never,
2642
3328
  dependencies: [
2643
- DatabaseService14
3329
+ Database20.Service
2644
3330
  ]
2645
3331
  }),
2646
3332
  Tool3.make("tag-remove", {
2647
- description: trim11`
3333
+ description: trim14`
2648
3334
  Removes a tag from an object.
2649
3335
  Tags are objects of type ${Tag2.Tag.typename}.
2650
3336
  `,
2651
3337
  parameters: {
2652
- tagId: ArtifactId7.annotations({
3338
+ tagId: ArtifactId2.annotations({
2653
3339
  description: "The ID of the tag."
2654
3340
  }),
2655
- objectId: ArtifactId7.annotations({
3341
+ objectId: ArtifactId2.annotations({
2656
3342
  description: "The ID of the object."
2657
3343
  })
2658
3344
  },
2659
- success: Schema17.Any,
2660
- failure: Schema17.Never,
3345
+ success: Schema24.Any,
3346
+ failure: Schema24.Never,
2661
3347
  dependencies: [
2662
- DatabaseService14
3348
+ Database20.Service
2663
3349
  ]
2664
3350
  })
2665
3351
  );
2666
3352
  var tools2 = Record2.keys(SystemToolkit.tools);
2667
3353
  var layer4 = () => SystemToolkit.toLayer({
2668
- "schema-list": Effect17.fnUntraced(function* () {
2669
- const { db } = yield* DatabaseService14;
2670
- 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({
2671
3357
  location: [
2672
3358
  "database",
2673
3359
  "runtime"
2674
3360
  ]
2675
3361
  }).run());
2676
3362
  return schema.map((schema2) => {
2677
- const meta = Type4.getMeta(schema2);
3363
+ const meta = Type16.getMeta(schema2);
2678
3364
  return {
2679
- typename: Type4.getTypename(schema2),
2680
- jsonSchema: Type4.toJsonSchema(schema2),
3365
+ typename: Type16.getTypename(schema2),
3366
+ jsonSchema: Type16.toJsonSchema(schema2),
2681
3367
  kind: meta?.sourceSchema ? "relation" : "record"
2682
3368
  };
2683
3369
  });
2684
3370
  }),
2685
- "schema-add": Effect17.fnUntraced(function* ({ name, typename, jsonSchema }) {
2686
- const { db } = yield* DatabaseService14;
2687
- 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([
2688
3374
  {
2689
3375
  typename,
2690
3376
  version: "0.1.0",
@@ -2693,66 +3379,310 @@ var layer4 = () => SystemToolkit.toLayer({
2693
3379
  }
2694
3380
  ]));
2695
3381
  }),
2696
- "object-create": Effect17.fnUntraced(function* ({ typename, data }) {
2697
- const { db } = yield* DatabaseService14;
2698
- 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({
2699
3389
  typename,
2700
3390
  location: [
2701
3391
  "database",
2702
3392
  "runtime"
2703
3393
  ]
2704
3394
  }).first());
2705
- 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));
2706
3405
  return object;
2707
3406
  }),
2708
- "object-remove": Effect17.fnUntraced(function* ({ id }) {
2709
- const { db } = yield* DatabaseService14;
2710
- const object = yield* DatabaseService14.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));
2711
3410
  db.remove(object);
2712
3411
  return object;
2713
3412
  }),
2714
- "relation-create": Effect17.fnUntraced(function* ({ typename, source, target, data }) {
2715
- const { db } = yield* DatabaseService14;
2716
- 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({
2717
3425
  typename,
2718
3426
  location: [
2719
3427
  "database",
2720
3428
  "runtime"
2721
3429
  ]
2722
3430
  }).first());
2723
- const sourceObj = yield* DatabaseService14.resolve(DXN2.parse(source));
2724
- const targetObj = yield* DatabaseService14.resolve(DXN2.parse(target));
2725
- const relation = db.add(Relation2.make(schema, {
2726
- [Relation2.Source]: sourceObj,
2727
- [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,
2728
3445
  ...data
2729
3446
  }));
2730
3447
  return relation;
2731
3448
  }),
2732
- "tag-add": Effect17.fnUntraced(function* ({ tagId, objectId }) {
2733
- const object = yield* DatabaseService14.resolve(DXN2.parse(objectId));
2734
- 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()));
2735
3458
  return object;
2736
3459
  }),
2737
- "tag-remove": Effect17.fnUntraced(function* ({ tagId, objectId }) {
2738
- const object = yield* DatabaseService14.resolve(DXN2.parse(objectId));
2739
- 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()));
2740
3463
  return object;
2741
3464
  })
2742
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
+ });
2743
3670
  export {
2744
3671
  Agent,
2745
3672
  AssistantToolkit_exports as AssistantToolkit,
3673
+ Chat_exports as Chat,
2746
3674
  design_default as DesignBlueprint,
2747
3675
  Discord,
2748
3676
  discord_default as DiscordBlueprint,
2749
3677
  Document,
2750
3678
  EntityExtraction,
3679
+ initiative_exports as Initiative,
2751
3680
  Linear,
2752
3681
  linear_default as LinearBlueprint,
2753
3682
  LocalSearchHandler,
2754
3683
  LocalSearchToolkit,
2755
- MapSchema,
3684
+ markdown_default as MarkdownBlueprint,
3685
+ planning_exports as Planning,
2756
3686
  planning_default as PlanningBlueprint,
2757
3687
  Research,
2758
3688
  research_default2 as ResearchBlueprint,
@@ -2763,7 +3693,7 @@ export {
2763
3693
  Tasks,
2764
3694
  websearch_default as WebSearchBlueprint,
2765
3695
  WebSearchToolkit,
2766
- capabilities,
3696
+ WebToolkit_exports as WebToolkit,
2767
3697
  contextQueueLayerFromResearchGraph,
2768
3698
  createExtractionSchema,
2769
3699
  createResearchGraph,