@dxos/assistant-toolkit 0.8.4-main.1068cf700f

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 (280) hide show
  1. package/LICENSE +8 -0
  2. package/README.md +3 -0
  3. package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
  4. package/dist/lib/neutral/chunk-J5LGTIGS.mjs.map +7 -0
  5. package/dist/lib/neutral/index.mjs +3708 -0
  6. package/dist/lib/neutral/index.mjs.map +7 -0
  7. package/dist/lib/neutral/meta.json +1 -0
  8. package/dist/lib/neutral/testing/index.mjs +44 -0
  9. package/dist/lib/neutral/testing/index.mjs.map +7 -0
  10. package/dist/types/src/blueprints/design/design-blueprint.d.ts +18 -0
  11. package/dist/types/src/blueprints/design/design-blueprint.d.ts.map +1 -0
  12. package/dist/types/src/blueprints/design/design-blueprint.test.d.ts +2 -0
  13. package/dist/types/src/blueprints/design/design-blueprint.test.d.ts.map +1 -0
  14. package/dist/types/src/blueprints/design/index.d.ts +3 -0
  15. package/dist/types/src/blueprints/design/index.d.ts.map +1 -0
  16. package/dist/types/src/blueprints/discord/discord-blueprint.d.ts +18 -0
  17. package/dist/types/src/blueprints/discord/discord-blueprint.d.ts.map +1 -0
  18. package/dist/types/src/blueprints/discord/index.d.ts +3 -0
  19. package/dist/types/src/blueprints/discord/index.d.ts.map +1 -0
  20. package/dist/types/src/blueprints/index.d.ts +8 -0
  21. package/dist/types/src/blueprints/index.d.ts.map +1 -0
  22. package/dist/types/src/blueprints/linear/index.d.ts +3 -0
  23. package/dist/types/src/blueprints/linear/index.d.ts.map +1 -0
  24. package/dist/types/src/blueprints/linear/linear-blueprint.d.ts +18 -0
  25. package/dist/types/src/blueprints/linear/linear-blueprint.d.ts.map +1 -0
  26. package/dist/types/src/blueprints/markdown/index.d.ts +3 -0
  27. package/dist/types/src/blueprints/markdown/index.d.ts.map +1 -0
  28. package/dist/types/src/blueprints/markdown/markdown-blueprint.d.ts +18 -0
  29. package/dist/types/src/blueprints/markdown/markdown-blueprint.d.ts.map +1 -0
  30. package/dist/types/src/blueprints/planning/index.d.ts +3 -0
  31. package/dist/types/src/blueprints/planning/index.d.ts.map +1 -0
  32. package/dist/types/src/blueprints/planning/planning-blueprint.d.ts +18 -0
  33. package/dist/types/src/blueprints/planning/planning-blueprint.d.ts.map +1 -0
  34. package/dist/types/src/blueprints/planning/planning-blueprint.test.d.ts +2 -0
  35. package/dist/types/src/blueprints/planning/planning-blueprint.test.d.ts.map +1 -0
  36. package/dist/types/src/blueprints/research/index.d.ts +3 -0
  37. package/dist/types/src/blueprints/research/index.d.ts.map +1 -0
  38. package/dist/types/src/blueprints/research/research-blueprint.d.ts +18 -0
  39. package/dist/types/src/blueprints/research/research-blueprint.d.ts.map +1 -0
  40. package/dist/types/src/blueprints/research/research-blueprint.test.d.ts +2 -0
  41. package/dist/types/src/blueprints/research/research-blueprint.test.d.ts.map +1 -0
  42. package/dist/types/src/blueprints/testing.d.ts +10 -0
  43. package/dist/types/src/blueprints/testing.d.ts.map +1 -0
  44. package/dist/types/src/blueprints/websearch/index.d.ts +4 -0
  45. package/dist/types/src/blueprints/websearch/index.d.ts.map +1 -0
  46. package/dist/types/src/blueprints/websearch/websearch-blueprint.d.ts +18 -0
  47. package/dist/types/src/blueprints/websearch/websearch-blueprint.d.ts.map +1 -0
  48. package/dist/types/src/blueprints/websearch/websearch-toolkit.d.ts +27 -0
  49. package/dist/types/src/blueprints/websearch/websearch-toolkit.d.ts.map +1 -0
  50. package/dist/types/src/chat/Chat.d.ts +31 -0
  51. package/dist/types/src/chat/Chat.d.ts.map +1 -0
  52. package/dist/types/src/chat/index.d.ts +2 -0
  53. package/dist/types/src/chat/index.d.ts.map +1 -0
  54. package/dist/types/src/crud/graph.d.ts +67 -0
  55. package/dist/types/src/crud/graph.d.ts.map +1 -0
  56. package/dist/types/src/crud/graph.test.d.ts +2 -0
  57. package/dist/types/src/crud/graph.test.d.ts.map +1 -0
  58. package/dist/types/src/crud/index.d.ts +2 -0
  59. package/dist/types/src/crud/index.d.ts.map +1 -0
  60. package/dist/types/src/experimental/feed.test.d.ts +2 -0
  61. package/dist/types/src/experimental/feed.test.d.ts.map +1 -0
  62. package/dist/types/src/functions/agent/index.d.ts +5 -0
  63. package/dist/types/src/functions/agent/index.d.ts.map +1 -0
  64. package/dist/types/src/functions/agent/prompt.d.ts +76 -0
  65. package/dist/types/src/functions/agent/prompt.d.ts.map +1 -0
  66. package/dist/types/src/functions/discord/fetch-messages.d.ts +11 -0
  67. package/dist/types/src/functions/discord/fetch-messages.d.ts.map +1 -0
  68. package/dist/types/src/functions/discord/fetch-messages.test.d.ts +2 -0
  69. package/dist/types/src/functions/discord/fetch-messages.test.d.ts.map +1 -0
  70. package/dist/types/src/functions/discord/index.d.ts +12 -0
  71. package/dist/types/src/functions/discord/index.d.ts.map +1 -0
  72. package/dist/types/src/functions/document/create.d.ts +6 -0
  73. package/dist/types/src/functions/document/create.d.ts.map +1 -0
  74. package/dist/types/src/functions/document/index.d.ts +30 -0
  75. package/dist/types/src/functions/document/index.d.ts.map +1 -0
  76. package/dist/types/src/functions/document/read.d.ts +14 -0
  77. package/dist/types/src/functions/document/read.d.ts.map +1 -0
  78. package/dist/types/src/functions/document/update.d.ts +13 -0
  79. package/dist/types/src/functions/document/update.d.ts.map +1 -0
  80. package/dist/types/src/functions/entity-extraction/entity-extraction.d.ts +174 -0
  81. package/dist/types/src/functions/entity-extraction/entity-extraction.d.ts.map +1 -0
  82. package/dist/types/src/functions/entity-extraction/entity-extraction.test.d.ts +2 -0
  83. package/dist/types/src/functions/entity-extraction/entity-extraction.test.d.ts.map +1 -0
  84. package/dist/types/src/functions/entity-extraction/index.d.ts +175 -0
  85. package/dist/types/src/functions/entity-extraction/index.d.ts.map +1 -0
  86. package/dist/types/src/functions/exa/data/exa-search-1748337321991.d.ts +38 -0
  87. package/dist/types/src/functions/exa/data/exa-search-1748337321991.d.ts.map +1 -0
  88. package/dist/types/src/functions/exa/data/exa-search-1748337331526.d.ts +37 -0
  89. package/dist/types/src/functions/exa/data/exa-search-1748337331526.d.ts.map +1 -0
  90. package/dist/types/src/functions/exa/data/exa-search-1748337344119.d.ts +58 -0
  91. package/dist/types/src/functions/exa/data/exa-search-1748337344119.d.ts.map +1 -0
  92. package/dist/types/src/functions/exa/data/index.d.ts +3 -0
  93. package/dist/types/src/functions/exa/data/index.d.ts.map +1 -0
  94. package/dist/types/src/functions/exa/exa.d.ts +5 -0
  95. package/dist/types/src/functions/exa/exa.d.ts.map +1 -0
  96. package/dist/types/src/functions/exa/index.d.ts +3 -0
  97. package/dist/types/src/functions/exa/index.d.ts.map +1 -0
  98. package/dist/types/src/functions/exa/mock.d.ts +5 -0
  99. package/dist/types/src/functions/exa/mock.d.ts.map +1 -0
  100. package/dist/types/src/functions/github/fetch-prs.d.ts +6 -0
  101. package/dist/types/src/functions/github/fetch-prs.d.ts.map +1 -0
  102. package/dist/types/src/functions/index.d.ts +8 -0
  103. package/dist/types/src/functions/index.d.ts.map +1 -0
  104. package/dist/types/src/functions/linear/index.d.ts +9 -0
  105. package/dist/types/src/functions/linear/index.d.ts.map +1 -0
  106. package/dist/types/src/functions/linear/linear.test.d.ts +2 -0
  107. package/dist/types/src/functions/linear/linear.test.d.ts.map +1 -0
  108. package/dist/types/src/functions/linear/sync-issues.d.ts +12 -0
  109. package/dist/types/src/functions/linear/sync-issues.d.ts.map +1 -0
  110. package/dist/types/src/functions/research/document-create.d.ts +9 -0
  111. package/dist/types/src/functions/research/document-create.d.ts.map +1 -0
  112. package/dist/types/src/functions/research/index.d.ts +21 -0
  113. package/dist/types/src/functions/research/index.d.ts.map +1 -0
  114. package/dist/types/src/functions/research/research-graph.d.ts +19 -0
  115. package/dist/types/src/functions/research/research-graph.d.ts.map +1 -0
  116. package/dist/types/src/functions/research/research.d.ts +14 -0
  117. package/dist/types/src/functions/research/research.d.ts.map +1 -0
  118. package/dist/types/src/functions/research/research.test.d.ts +2 -0
  119. package/dist/types/src/functions/research/research.test.d.ts.map +1 -0
  120. package/dist/types/src/functions/research/types.d.ts +6 -0
  121. package/dist/types/src/functions/research/types.d.ts.map +1 -0
  122. package/dist/types/src/functions/tasks/index.d.ts +29 -0
  123. package/dist/types/src/functions/tasks/index.d.ts.map +1 -0
  124. package/dist/types/src/functions/tasks/read.d.ts +14 -0
  125. package/dist/types/src/functions/tasks/read.d.ts.map +1 -0
  126. package/dist/types/src/functions/tasks/task-list.d.ts +74 -0
  127. package/dist/types/src/functions/tasks/task-list.d.ts.map +1 -0
  128. package/dist/types/src/functions/tasks/task-list.test.d.ts +2 -0
  129. package/dist/types/src/functions/tasks/task-list.test.d.ts.map +1 -0
  130. package/dist/types/src/functions/tasks/update.d.ts +16 -0
  131. package/dist/types/src/functions/tasks/update.d.ts.map +1 -0
  132. package/dist/types/src/index.d.ts +9 -0
  133. package/dist/types/src/index.d.ts.map +1 -0
  134. package/dist/types/src/initiative/Initiative.d.ts +41 -0
  135. package/dist/types/src/initiative/Initiative.d.ts.map +1 -0
  136. package/dist/types/src/initiative/blueprint.d.ts +153 -0
  137. package/dist/types/src/initiative/blueprint.d.ts.map +1 -0
  138. package/dist/types/src/initiative/functions/addArtifact.d.ts +6 -0
  139. package/dist/types/src/initiative/functions/addArtifact.d.ts.map +1 -0
  140. package/dist/types/src/initiative/functions/agent.d.ts +62 -0
  141. package/dist/types/src/initiative/functions/agent.d.ts.map +1 -0
  142. package/dist/types/src/initiative/functions/getContext.d.ts +13 -0
  143. package/dist/types/src/initiative/functions/getContext.d.ts.map +1 -0
  144. package/dist/types/src/initiative/functions/index.d.ts +5 -0
  145. package/dist/types/src/initiative/functions/index.d.ts.map +1 -0
  146. package/dist/types/src/initiative/functions/qualifier.d.ts +60 -0
  147. package/dist/types/src/initiative/functions/qualifier.d.ts.map +1 -0
  148. package/dist/types/src/initiative/index.d.ts +6 -0
  149. package/dist/types/src/initiative/index.d.ts.map +1 -0
  150. package/dist/types/src/initiative/initiative.test.d.ts +2 -0
  151. package/dist/types/src/initiative/initiative.test.d.ts.map +1 -0
  152. package/dist/types/src/initiative/plan.d.ts +77 -0
  153. package/dist/types/src/initiative/plan.d.ts.map +1 -0
  154. package/dist/types/src/initiative/util.d.ts +29 -0
  155. package/dist/types/src/initiative/util.d.ts.map +1 -0
  156. package/dist/types/src/planning/blueprint.d.ts +18 -0
  157. package/dist/types/src/planning/blueprint.d.ts.map +1 -0
  158. package/dist/types/src/planning/functions/index.d.ts +2 -0
  159. package/dist/types/src/planning/functions/index.d.ts.map +1 -0
  160. package/dist/types/src/planning/functions/update-tasks.d.ts +9 -0
  161. package/dist/types/src/planning/functions/update-tasks.d.ts.map +1 -0
  162. package/dist/types/src/planning/index.d.ts +3 -0
  163. package/dist/types/src/planning/index.d.ts.map +1 -0
  164. package/dist/types/src/sync/index.d.ts +2 -0
  165. package/dist/types/src/sync/index.d.ts.map +1 -0
  166. package/dist/types/src/sync/sync.d.ts +15 -0
  167. package/dist/types/src/sync/sync.d.ts.map +1 -0
  168. package/dist/types/src/testing/index.d.ts +2 -0
  169. package/dist/types/src/testing/index.d.ts.map +1 -0
  170. package/dist/types/src/testing/plugins.d.ts +19 -0
  171. package/dist/types/src/testing/plugins.d.ts.map +1 -0
  172. package/dist/types/src/toolkits/AssistantToolkit.d.ts +43 -0
  173. package/dist/types/src/toolkits/AssistantToolkit.d.ts.map +1 -0
  174. package/dist/types/src/toolkits/AssistantToolkit.test.d.ts +2 -0
  175. package/dist/types/src/toolkits/AssistantToolkit.test.d.ts.map +1 -0
  176. package/dist/types/src/toolkits/SystemToolkit.d.ts +99 -0
  177. package/dist/types/src/toolkits/SystemToolkit.d.ts.map +1 -0
  178. package/dist/types/src/toolkits/WebToolkit.d.ts +38 -0
  179. package/dist/types/src/toolkits/WebToolkit.d.ts.map +1 -0
  180. package/dist/types/src/toolkits/index.d.ts +4 -0
  181. package/dist/types/src/toolkits/index.d.ts.map +1 -0
  182. package/dist/types/src/util/graphql.d.ts +22 -0
  183. package/dist/types/src/util/graphql.d.ts.map +1 -0
  184. package/dist/types/src/util/index.d.ts +2 -0
  185. package/dist/types/src/util/index.d.ts.map +1 -0
  186. package/dist/types/tsconfig.tsbuildinfo +1 -0
  187. package/package.json +74 -0
  188. package/src/blueprints/design/design-blueprint.test.ts +100 -0
  189. package/src/blueprints/design/design-blueprint.ts +31 -0
  190. package/src/blueprints/design/index.ts +7 -0
  191. package/src/blueprints/discord/discord-blueprint.ts +32 -0
  192. package/src/blueprints/discord/index.ts +7 -0
  193. package/src/blueprints/index.ts +11 -0
  194. package/src/blueprints/linear/index.ts +7 -0
  195. package/src/blueprints/linear/linear-blueprint.ts +33 -0
  196. package/src/blueprints/markdown/index.ts +7 -0
  197. package/src/blueprints/markdown/markdown-blueprint.ts +24 -0
  198. package/src/blueprints/planning/index.ts +7 -0
  199. package/src/blueprints/planning/planning-blueprint.test.ts +120 -0
  200. package/src/blueprints/planning/planning-blueprint.ts +96 -0
  201. package/src/blueprints/research/index.ts +7 -0
  202. package/src/blueprints/research/research-blueprint.test.ts +7 -0
  203. package/src/blueprints/research/research-blueprint.ts +51 -0
  204. package/src/blueprints/testing.ts +30 -0
  205. package/src/blueprints/websearch/index.ts +9 -0
  206. package/src/blueprints/websearch/websearch-blueprint.ts +18 -0
  207. package/src/blueprints/websearch/websearch-toolkit.ts +8 -0
  208. package/src/chat/Chat.ts +45 -0
  209. package/src/chat/index.ts +5 -0
  210. package/src/crud/graph.test.ts +46 -0
  211. package/src/crud/graph.ts +380 -0
  212. package/src/crud/index.ts +5 -0
  213. package/src/experimental/feed.test.ts +106 -0
  214. package/src/functions/agent/index.ts +11 -0
  215. package/src/functions/agent/prompt.ts +116 -0
  216. package/src/functions/discord/fetch-messages.test.ts +54 -0
  217. package/src/functions/discord/fetch-messages.ts +252 -0
  218. package/src/functions/discord/index.ts +9 -0
  219. package/src/functions/document/create.ts +29 -0
  220. package/src/functions/document/index.ts +13 -0
  221. package/src/functions/document/read.ts +32 -0
  222. package/src/functions/document/update.ts +32 -0
  223. package/src/functions/entity-extraction/entity-extraction.conversations.json +1 -0
  224. package/src/functions/entity-extraction/entity-extraction.test.ts +74 -0
  225. package/src/functions/entity-extraction/entity-extraction.ts +181 -0
  226. package/src/functions/entity-extraction/index.ts +9 -0
  227. package/src/functions/exa/data/exa-search-1748337321991.ts +131 -0
  228. package/src/functions/exa/data/exa-search-1748337331526.ts +144 -0
  229. package/src/functions/exa/data/exa-search-1748337344119.ts +133 -0
  230. package/src/functions/exa/data/index.ts +11 -0
  231. package/src/functions/exa/exa.ts +37 -0
  232. package/src/functions/exa/index.ts +6 -0
  233. package/src/functions/exa/mock.ts +71 -0
  234. package/src/functions/github/fetch-prs.ts +31 -0
  235. package/src/functions/index.ts +11 -0
  236. package/src/functions/linear/index.ts +9 -0
  237. package/src/functions/linear/linear.test.ts +58 -0
  238. package/src/functions/linear/sync-issues.ts +191 -0
  239. package/src/functions/research/document-create.ts +73 -0
  240. package/src/functions/research/index.ts +14 -0
  241. package/src/functions/research/research-graph.ts +49 -0
  242. package/src/functions/research/research-instructions.tpl +106 -0
  243. package/src/functions/research/research.conversations.json +1 -0
  244. package/src/functions/research/research.test.ts +144 -0
  245. package/src/functions/research/research.ts +182 -0
  246. package/src/functions/research/types.ts +26 -0
  247. package/src/functions/tasks/index.ts +11 -0
  248. package/src/functions/tasks/read.ts +34 -0
  249. package/src/functions/tasks/task-list.test.ts +99 -0
  250. package/src/functions/tasks/task-list.ts +165 -0
  251. package/src/functions/tasks/update.ts +52 -0
  252. package/src/index.ts +12 -0
  253. package/src/initiative/Initiative.ts +61 -0
  254. package/src/initiative/blueprint.ts +60 -0
  255. package/src/initiative/functions/addArtifact.ts +41 -0
  256. package/src/initiative/functions/agent.ts +77 -0
  257. package/src/initiative/functions/getContext.ts +54 -0
  258. package/src/initiative/functions/index.ts +8 -0
  259. package/src/initiative/functions/qualifier.ts +98 -0
  260. package/src/initiative/index.ts +9 -0
  261. package/src/initiative/initiative.test.ts +584 -0
  262. package/src/initiative/plan.ts +107 -0
  263. package/src/initiative/util.ts +137 -0
  264. package/src/planning/blueprint.ts +14 -0
  265. package/src/planning/functions/index.ts +5 -0
  266. package/src/planning/functions/update-tasks.ts +168 -0
  267. package/src/planning/index.ts +6 -0
  268. package/src/sync/index.ts +5 -0
  269. package/src/sync/sync.ts +95 -0
  270. package/src/testing/index.ts +5 -0
  271. package/src/testing/plugins.tsx +69 -0
  272. package/src/toolkits/AssistantToolkit.conversations.json +1 -0
  273. package/src/toolkits/AssistantToolkit.test.ts +72 -0
  274. package/src/toolkits/AssistantToolkit.ts +70 -0
  275. package/src/toolkits/SystemToolkit.ts +299 -0
  276. package/src/toolkits/WebToolkit.ts +34 -0
  277. package/src/toolkits/index.ts +7 -0
  278. package/src/typedefs.d.ts +8 -0
  279. package/src/util/graphql.ts +31 -0
  280. package/src/util/index.ts +5 -0
@@ -0,0 +1,70 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import * as Tool from '@effect/ai/Tool';
6
+ import * as Toolkit from '@effect/ai/Toolkit';
7
+ import * as Effect from 'effect/Effect';
8
+ import * as Record from 'effect/Record';
9
+ import * as Schema from 'effect/Schema';
10
+
11
+ import { AiContextService, ArtifactId } from '@dxos/assistant';
12
+ import { Database, type Ref } from '@dxos/echo';
13
+ import { trim } from '@dxos/util';
14
+
15
+ export const AssistantToolkit = Toolkit.make(
16
+ Tool.make('context-add', {
17
+ description: trim`
18
+ Adds the object to the chat context.
19
+ `,
20
+ parameters: {
21
+ id: ArtifactId.annotations({
22
+ description: 'The ID of the document to add.',
23
+ }),
24
+ },
25
+ success: Schema.Void,
26
+ failure: Schema.Never,
27
+ dependencies: [AiContextService, Database.Service],
28
+ }),
29
+ Tool.make('context-remove', {
30
+ description: trim`
31
+ Removes the object from the chat context.
32
+ `,
33
+ parameters: {
34
+ id: ArtifactId.annotations({
35
+ description: 'The ID of the document to remove.',
36
+ }),
37
+ },
38
+ success: Schema.Void,
39
+ failure: Schema.Never,
40
+ dependencies: [AiContextService, Database.Service],
41
+ }),
42
+ );
43
+
44
+ export const tools = Record.keys(AssistantToolkit.tools);
45
+
46
+ export const layer = () =>
47
+ AssistantToolkit.toLayer({
48
+ ['context-add' as const]: Effect.fnUntraced(function* ({ id }) {
49
+ const { binder } = yield* AiContextService;
50
+ const { db } = yield* Database.Service;
51
+ const ref = db.makeRef(ArtifactId.toDXN(id, db.spaceId)) as Ref.Ref<any>;
52
+ yield* Effect.promise(() =>
53
+ binder.bind({
54
+ blueprints: [],
55
+ objects: [ref],
56
+ }),
57
+ );
58
+ }),
59
+ ['context-remove' as const]: Effect.fnUntraced(function* ({ id }) {
60
+ const { binder } = yield* AiContextService;
61
+ const { db } = yield* Database.Service;
62
+ const ref = db.makeRef(ArtifactId.toDXN(id, db.spaceId)) as Ref.Ref<any>;
63
+ yield* Effect.promise(() =>
64
+ binder.unbind({
65
+ blueprints: [],
66
+ objects: [ref],
67
+ }),
68
+ );
69
+ }),
70
+ });
@@ -0,0 +1,299 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import * as Tool from '@effect/ai/Tool';
6
+ import * as Toolkit from '@effect/ai/Toolkit';
7
+ import * as Effect from 'effect/Effect';
8
+ import type * as Layer from 'effect/Layer';
9
+ import * as Record from 'effect/Record';
10
+ import * as Schema from 'effect/Schema';
11
+
12
+ import { ArtifactId } from '@dxos/assistant';
13
+ import { DXN, Database, Entity, Filter, Obj, Relation, Tag, Type } from '@dxos/echo';
14
+ import { invariant } from '@dxos/invariant';
15
+ import { trim } from '@dxos/util';
16
+
17
+ export const SystemToolkit = Toolkit.make(
18
+ //
19
+ // Schema
20
+ //
21
+
22
+ Tool.make('schema-list', {
23
+ description: trim`
24
+ Lists schemas definitions.
25
+ `,
26
+ parameters: {
27
+ // TODO(wittjosiah): Remove this once parameter-less tools are fixed.
28
+ limit: Schema.Number,
29
+ },
30
+ // TODO(dmaretskyi): Effect returns ({ result, encodedResult })
31
+ success: Schema.Any,
32
+ failure: Schema.Never,
33
+ dependencies: [Database.Service],
34
+ }),
35
+
36
+ Tool.make('schema-add', {
37
+ description: trim`
38
+ Adds a schema to the space.
39
+ The name will be used when displayed to the user.
40
+ The typename must be in the format of "example.com/type/Type".
41
+ `,
42
+ parameters: {
43
+ name: Schema.String,
44
+ typename: Schema.String,
45
+ jsonSchema: Schema.Any,
46
+ },
47
+ success: Schema.Any,
48
+ failure: Schema.Never,
49
+ dependencies: [Database.Service],
50
+ }),
51
+
52
+ //
53
+ // Query
54
+ //
55
+
56
+ Tool.make('query', {
57
+ description: trim`
58
+ Queries objects in the space.
59
+ Get the typename from the schema-list tool.
60
+ `,
61
+ parameters: {
62
+ typename: Schema.String,
63
+ },
64
+ success: Schema.Any,
65
+ failure: Schema.Never,
66
+ dependencies: [Database.Service],
67
+ }),
68
+
69
+ //
70
+ // Objects
71
+ //
72
+
73
+ Tool.make('object-create', {
74
+ description: trim`
75
+ Creates a new object and adds it to the current space.
76
+ Get the schema from the schema-list tool and ensure that the data matches the corresponding schema.
77
+ `,
78
+ parameters: {
79
+ typename: Schema.String,
80
+ data: Schema.Any,
81
+ },
82
+ success: Schema.Any,
83
+ failure: Schema.Never, // TODO(burdon): Error handing?
84
+ dependencies: [Database.Service],
85
+ }),
86
+
87
+ Tool.make('object-delete', {
88
+ description: trim`
89
+ Deletes the object.
90
+ `,
91
+ parameters: {
92
+ id: ArtifactId.annotations({
93
+ description: 'The ID of the object.',
94
+ }),
95
+ },
96
+ success: Schema.Any,
97
+ failure: Schema.Never,
98
+ dependencies: [Database.Service],
99
+ }),
100
+
101
+ Tool.make('object-update', {
102
+ description: trim`
103
+ Updates the object properties.
104
+ `,
105
+ parameters: {
106
+ id: ArtifactId.annotations({
107
+ description: 'The ID of the object.',
108
+ }),
109
+ properties: Schema.Record({ key: Schema.String, value: Schema.Any }),
110
+ },
111
+ success: Schema.Any,
112
+ failure: Schema.Never,
113
+ dependencies: [Database.Service],
114
+ }),
115
+
116
+ //
117
+ // Relations
118
+ //
119
+
120
+ Tool.make('relation-create', {
121
+ description: trim`
122
+ Creates a new relation and adds it to the current space.
123
+ Get the schema from the schema-list tool and ensure that the data matches the corresponding schema.
124
+ `,
125
+ parameters: {
126
+ typename: Schema.String,
127
+ source: ArtifactId.annotations({
128
+ description: 'The ID of the source object.',
129
+ }),
130
+ target: ArtifactId.annotations({
131
+ description: 'The ID of the target object.',
132
+ }),
133
+ data: Schema.Any.annotations({
134
+ description: 'The data to be stored in the relation.',
135
+ }),
136
+ },
137
+ success: Schema.Any,
138
+ failure: Schema.Never,
139
+ dependencies: [Database.Service],
140
+ }),
141
+
142
+ Tool.make('relation-delete', {
143
+ description: trim`
144
+ Deletes the relation.
145
+ `,
146
+ parameters: {
147
+ id: ArtifactId.annotations({
148
+ description: 'The ID of the relation.',
149
+ }),
150
+ },
151
+ success: Schema.Any,
152
+ failure: Schema.Never,
153
+ dependencies: [Database.Service],
154
+ }),
155
+
156
+ //
157
+ // Tags
158
+ //
159
+
160
+ Tool.make('tag-add', {
161
+ description: trim`
162
+ Adds a tag to an object.
163
+ Tags are objects of type ${Tag.Tag.typename}.
164
+ `,
165
+ parameters: {
166
+ tagId: ArtifactId.annotations({
167
+ description: 'The ID of the tag.',
168
+ }),
169
+ objectId: ArtifactId.annotations({
170
+ description: 'The ID of the object.',
171
+ }),
172
+ },
173
+ success: Schema.Any,
174
+ failure: Schema.Never,
175
+ dependencies: [Database.Service],
176
+ }),
177
+
178
+ Tool.make('tag-remove', {
179
+ description: trim`
180
+ Removes a tag from an object.
181
+ Tags are objects of type ${Tag.Tag.typename}.
182
+ `,
183
+ parameters: {
184
+ tagId: ArtifactId.annotations({
185
+ description: 'The ID of the tag.',
186
+ }),
187
+ objectId: ArtifactId.annotations({
188
+ description: 'The ID of the object.',
189
+ }),
190
+ },
191
+ success: Schema.Any,
192
+ failure: Schema.Never,
193
+ dependencies: [Database.Service],
194
+ }),
195
+ );
196
+
197
+ export const tools = Record.keys(SystemToolkit.tools);
198
+
199
+ export const layer = (): Layer.Layer<Tool.Handler<any>, never, never> =>
200
+ SystemToolkit.toLayer({
201
+ ['schema-list' as const]: Effect.fnUntraced(function* () {
202
+ const { db } = yield* Database.Service;
203
+ const schema = yield* Effect.promise(() => db.schemaRegistry.query({ location: ['database', 'runtime'] }).run());
204
+ return schema.map((schema) => {
205
+ const meta = Type.getMeta(schema);
206
+ return {
207
+ typename: Type.getTypename(schema),
208
+ jsonSchema: Type.toJsonSchema(schema),
209
+ kind: meta?.sourceSchema ? 'relation' : 'record',
210
+ };
211
+ });
212
+ }),
213
+
214
+ ['schema-add' as const]: Effect.fnUntraced(function* ({ name, typename, jsonSchema }) {
215
+ const { db } = yield* Database.Service;
216
+ yield* Effect.promise(() =>
217
+ db.schemaRegistry.register([
218
+ {
219
+ typename,
220
+ version: '0.1.0',
221
+ jsonSchema,
222
+ name,
223
+ },
224
+ ]),
225
+ );
226
+ }),
227
+
228
+ ['query' as const]: Effect.fnUntraced(function* ({ typename }) {
229
+ const objects = yield* Database.runQuery(Filter.typename(typename));
230
+ return objects;
231
+ }),
232
+
233
+ ['object-create' as const]: Effect.fnUntraced(function* ({ typename, data }) {
234
+ const { db } = yield* Database.Service;
235
+ const schema = yield* Effect.promise(() =>
236
+ db.schemaRegistry.query({ typename, location: ['database', 'runtime'] }).first(),
237
+ );
238
+ invariant(Type.isObjectSchema(schema), 'Schema is not an object schema');
239
+
240
+ // TODO(dmaretskyi): How to add object to a collection?
241
+ const object = db.add(Obj.make(schema, data));
242
+ return object;
243
+ }),
244
+
245
+ ['object-delete' as const]: Effect.fnUntraced(function* ({ id }) {
246
+ const { db } = yield* Database.Service;
247
+ const object = yield* Database.resolve(DXN.parse(id));
248
+ db.remove(object);
249
+ return object;
250
+ }),
251
+
252
+ ['object-update' as const]: Effect.fnUntraced(function* ({ id, properties }) {
253
+ const object = yield* Database.resolve(DXN.parse(id));
254
+ Entity.change(object as Entity.Any, (obj) => {
255
+ for (const [key, value] of Object.entries(properties)) {
256
+ obj[key] = value;
257
+ }
258
+ });
259
+ return object;
260
+ }),
261
+
262
+ ['relation-create' as const]: Effect.fnUntraced(function* ({ typename, source, target, data }) {
263
+ const { db } = yield* Database.Service;
264
+ const schema = yield* Effect.promise(() =>
265
+ db.schemaRegistry.query({ typename, location: ['database', 'runtime'] }).first(),
266
+ );
267
+ invariant(Type.isRelationSchema(schema), 'Schema is not a relation schema');
268
+
269
+ const sourceObj = yield* Database.resolve(DXN.parse(source));
270
+ const targetObj = yield* Database.resolve(DXN.parse(target));
271
+ const relation = db.add(
272
+ Relation.make(schema, {
273
+ [Relation.Source]: sourceObj,
274
+ [Relation.Target]: targetObj,
275
+ ...data,
276
+ }),
277
+ );
278
+ return relation;
279
+ }),
280
+
281
+ ['relation-delete' as const]: Effect.fnUntraced(function* ({ id }) {
282
+ const { db } = yield* Database.Service;
283
+ const relation = yield* Database.resolve(DXN.parse(id));
284
+ db.remove(relation);
285
+ return relation;
286
+ }),
287
+
288
+ ['tag-add' as const]: Effect.fnUntraced(function* ({ tagId, objectId }) {
289
+ const object = yield* Database.resolve(DXN.parse(objectId));
290
+ Entity.change(object, (obj) => Entity.addTag(obj, DXN.parse(tagId).toString()));
291
+ return object;
292
+ }),
293
+
294
+ ['tag-remove' as const]: Effect.fnUntraced(function* ({ tagId, objectId }) {
295
+ const object = yield* Database.resolve(DXN.parse(objectId));
296
+ Entity.change(object, (obj) => Entity.removeTag(obj, DXN.parse(tagId).toString()));
297
+ return object;
298
+ }),
299
+ });
@@ -0,0 +1,34 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import * as Tool from '@effect/ai/Tool';
6
+ import * as Toolkit from '@effect/ai/Toolkit';
7
+ import * as AnthropicTool from '@effect/ai-anthropic/AnthropicTool';
8
+ import * as Effect from 'effect/Effect';
9
+ import * as Schema from 'effect/Schema';
10
+
11
+ // TODO(dmaretskyi): Testing only.
12
+ export const WebToolkit = Toolkit.make(
13
+ AnthropicTool.WebSearch_20250305({})
14
+ .pipe
15
+ // TODO(dmaretskyi): Effect bug -- provider-defined tools don't support annotations.
16
+ // ToolFormatter.assign({
17
+ // debugFormatResult: (result) =>
18
+ // Array.isArray(result) ? result.map(Struct.pick('title', 'type', 'url', 'page_age')) : result,
19
+ // }),
20
+ (),
21
+ Tool.make('WebFetch', {
22
+ parameters: {
23
+ url: Schema.String,
24
+ },
25
+ success: Schema.String,
26
+ }),
27
+ );
28
+
29
+ export const layer = WebToolkit.toLayer({
30
+ WebFetch: Effect.fnUntraced(function* ({ url }) {
31
+ const response = yield* Effect.promise(() => fetch(url).then((response) => response.text()));
32
+ return response;
33
+ }),
34
+ });
@@ -0,0 +1,7 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ export * as AssistantToolkit from './AssistantToolkit';
6
+ export * as SystemToolkit from './SystemToolkit';
7
+ export * as WebToolkit from './WebToolkit';
@@ -0,0 +1,8 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ declare module '*?raw' {
6
+ const content: string;
7
+ export default content;
8
+ }
@@ -0,0 +1,31 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import * as HttpBody from '@effect/platform/HttpBody';
6
+
7
+ /**
8
+ * Template tag literal to get syntax highlighting for the query.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * const query = gql`
13
+ * query Team($teamId: String!) {
14
+ * team(id: $teamId) {
15
+ * id
16
+ * name
17
+ * }
18
+ * }
19
+ * `;
20
+ * ```
21
+ */
22
+ export const gql = (query: string) => query;
23
+
24
+ /**
25
+ * @returns JSON body for the graphql request.
26
+ */
27
+ export const graphqlRequestBody = (query: string, variables: Record<string, any> = {}) =>
28
+ HttpBody.json({
29
+ query,
30
+ variables,
31
+ });
@@ -0,0 +1,5 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ export * from './graphql';