@dxos/assistant-toolkit 0.8.4-main.21d9917

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 (249) hide show
  1. package/LICENSE +8 -0
  2. package/README.md +3 -0
  3. package/dist/lib/browser/chunk-J5LGTIGS.mjs +10 -0
  4. package/dist/lib/browser/chunk-J5LGTIGS.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +2880 -0
  6. package/dist/lib/browser/index.mjs.map +7 -0
  7. package/dist/lib/browser/meta.json +1 -0
  8. package/dist/lib/browser/testing/index.mjs +43 -0
  9. package/dist/lib/browser/testing/index.mjs.map +7 -0
  10. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
  11. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +7 -0
  12. package/dist/lib/node-esm/index.mjs +2881 -0
  13. package/dist/lib/node-esm/index.mjs.map +7 -0
  14. package/dist/lib/node-esm/meta.json +1 -0
  15. package/dist/lib/node-esm/testing/index.mjs +44 -0
  16. package/dist/lib/node-esm/testing/index.mjs.map +7 -0
  17. package/dist/types/src/blueprints/design/design-blueprint.d.ts +18 -0
  18. package/dist/types/src/blueprints/design/design-blueprint.d.ts.map +1 -0
  19. package/dist/types/src/blueprints/design/design-blueprint.test.d.ts +2 -0
  20. package/dist/types/src/blueprints/design/design-blueprint.test.d.ts.map +1 -0
  21. package/dist/types/src/blueprints/design/index.d.ts +3 -0
  22. package/dist/types/src/blueprints/design/index.d.ts.map +1 -0
  23. package/dist/types/src/blueprints/discord/discord-blueprint.d.ts +18 -0
  24. package/dist/types/src/blueprints/discord/discord-blueprint.d.ts.map +1 -0
  25. package/dist/types/src/blueprints/discord/index.d.ts +3 -0
  26. package/dist/types/src/blueprints/discord/index.d.ts.map +1 -0
  27. package/dist/types/src/blueprints/index.d.ts +7 -0
  28. package/dist/types/src/blueprints/index.d.ts.map +1 -0
  29. package/dist/types/src/blueprints/linear/index.d.ts +3 -0
  30. package/dist/types/src/blueprints/linear/index.d.ts.map +1 -0
  31. package/dist/types/src/blueprints/linear/linear-blueprint.d.ts +18 -0
  32. package/dist/types/src/blueprints/linear/linear-blueprint.d.ts.map +1 -0
  33. package/dist/types/src/blueprints/planning/index.d.ts +3 -0
  34. package/dist/types/src/blueprints/planning/index.d.ts.map +1 -0
  35. package/dist/types/src/blueprints/planning/planning-blueprint.d.ts +18 -0
  36. package/dist/types/src/blueprints/planning/planning-blueprint.d.ts.map +1 -0
  37. package/dist/types/src/blueprints/planning/planning-blueprint.test.d.ts +2 -0
  38. package/dist/types/src/blueprints/planning/planning-blueprint.test.d.ts.map +1 -0
  39. package/dist/types/src/blueprints/research/index.d.ts +3 -0
  40. package/dist/types/src/blueprints/research/index.d.ts.map +1 -0
  41. package/dist/types/src/blueprints/research/research-blueprint.d.ts +18 -0
  42. package/dist/types/src/blueprints/research/research-blueprint.d.ts.map +1 -0
  43. package/dist/types/src/blueprints/research/research-blueprint.test.d.ts +2 -0
  44. package/dist/types/src/blueprints/research/research-blueprint.test.d.ts.map +1 -0
  45. package/dist/types/src/blueprints/testing.d.ts +12 -0
  46. package/dist/types/src/blueprints/testing.d.ts.map +1 -0
  47. package/dist/types/src/blueprints/websearch/index.d.ts +4 -0
  48. package/dist/types/src/blueprints/websearch/index.d.ts.map +1 -0
  49. package/dist/types/src/blueprints/websearch/websearch-blueprint.d.ts +18 -0
  50. package/dist/types/src/blueprints/websearch/websearch-blueprint.d.ts.map +1 -0
  51. package/dist/types/src/blueprints/websearch/websearch-toolkit.d.ts +27 -0
  52. package/dist/types/src/blueprints/websearch/websearch-toolkit.d.ts.map +1 -0
  53. package/dist/types/src/crud/graph.d.ts +67 -0
  54. package/dist/types/src/crud/graph.d.ts.map +1 -0
  55. package/dist/types/src/crud/graph.test.d.ts +2 -0
  56. package/dist/types/src/crud/graph.test.d.ts.map +1 -0
  57. package/dist/types/src/crud/index.d.ts +2 -0
  58. package/dist/types/src/crud/index.d.ts.map +1 -0
  59. package/dist/types/src/experimental/feed.test.d.ts +2 -0
  60. package/dist/types/src/experimental/feed.test.d.ts.map +1 -0
  61. package/dist/types/src/functions/agent/index.d.ts +5 -0
  62. package/dist/types/src/functions/agent/index.d.ts.map +1 -0
  63. package/dist/types/src/functions/agent/prompt.d.ts +76 -0
  64. package/dist/types/src/functions/agent/prompt.d.ts.map +1 -0
  65. package/dist/types/src/functions/discord/fetch-messages.d.ts +11 -0
  66. package/dist/types/src/functions/discord/fetch-messages.d.ts.map +1 -0
  67. package/dist/types/src/functions/discord/fetch-messages.test.d.ts +2 -0
  68. package/dist/types/src/functions/discord/fetch-messages.test.d.ts.map +1 -0
  69. package/dist/types/src/functions/discord/index.d.ts +12 -0
  70. package/dist/types/src/functions/discord/index.d.ts.map +1 -0
  71. package/dist/types/src/functions/document/index.d.ts +13 -0
  72. package/dist/types/src/functions/document/index.d.ts.map +1 -0
  73. package/dist/types/src/functions/document/read.d.ts +7 -0
  74. package/dist/types/src/functions/document/read.d.ts.map +1 -0
  75. package/dist/types/src/functions/document/update.d.ts +6 -0
  76. package/dist/types/src/functions/document/update.d.ts.map +1 -0
  77. package/dist/types/src/functions/entity-extraction/entity-extraction.d.ts +174 -0
  78. package/dist/types/src/functions/entity-extraction/entity-extraction.d.ts.map +1 -0
  79. package/dist/types/src/functions/entity-extraction/entity-extraction.test.d.ts +2 -0
  80. package/dist/types/src/functions/entity-extraction/entity-extraction.test.d.ts.map +1 -0
  81. package/dist/types/src/functions/entity-extraction/index.d.ts +175 -0
  82. package/dist/types/src/functions/entity-extraction/index.d.ts.map +1 -0
  83. package/dist/types/src/functions/exa/data/exa-search-1748337321991.d.ts +38 -0
  84. package/dist/types/src/functions/exa/data/exa-search-1748337321991.d.ts.map +1 -0
  85. package/dist/types/src/functions/exa/data/exa-search-1748337331526.d.ts +37 -0
  86. package/dist/types/src/functions/exa/data/exa-search-1748337331526.d.ts.map +1 -0
  87. package/dist/types/src/functions/exa/data/exa-search-1748337344119.d.ts +58 -0
  88. package/dist/types/src/functions/exa/data/exa-search-1748337344119.d.ts.map +1 -0
  89. package/dist/types/src/functions/exa/data/index.d.ts +3 -0
  90. package/dist/types/src/functions/exa/data/index.d.ts.map +1 -0
  91. package/dist/types/src/functions/exa/exa.d.ts +5 -0
  92. package/dist/types/src/functions/exa/exa.d.ts.map +1 -0
  93. package/dist/types/src/functions/exa/index.d.ts +3 -0
  94. package/dist/types/src/functions/exa/index.d.ts.map +1 -0
  95. package/dist/types/src/functions/exa/mock.d.ts +5 -0
  96. package/dist/types/src/functions/exa/mock.d.ts.map +1 -0
  97. package/dist/types/src/functions/github/fetch-prs.d.ts +6 -0
  98. package/dist/types/src/functions/github/fetch-prs.d.ts.map +1 -0
  99. package/dist/types/src/functions/index.d.ts +8 -0
  100. package/dist/types/src/functions/index.d.ts.map +1 -0
  101. package/dist/types/src/functions/linear/index.d.ts +9 -0
  102. package/dist/types/src/functions/linear/index.d.ts.map +1 -0
  103. package/dist/types/src/functions/linear/linear.test.d.ts +2 -0
  104. package/dist/types/src/functions/linear/linear.test.d.ts.map +1 -0
  105. package/dist/types/src/functions/linear/sync-issues.d.ts +12 -0
  106. package/dist/types/src/functions/linear/sync-issues.d.ts.map +1 -0
  107. package/dist/types/src/functions/research/document-create.d.ts +9 -0
  108. package/dist/types/src/functions/research/document-create.d.ts.map +1 -0
  109. package/dist/types/src/functions/research/index.d.ts +21 -0
  110. package/dist/types/src/functions/research/index.d.ts.map +1 -0
  111. package/dist/types/src/functions/research/research-graph.d.ts +19 -0
  112. package/dist/types/src/functions/research/research-graph.d.ts.map +1 -0
  113. package/dist/types/src/functions/research/research.d.ts +14 -0
  114. package/dist/types/src/functions/research/research.d.ts.map +1 -0
  115. package/dist/types/src/functions/research/research.test.d.ts +2 -0
  116. package/dist/types/src/functions/research/research.test.d.ts.map +1 -0
  117. package/dist/types/src/functions/research/types.d.ts +6 -0
  118. package/dist/types/src/functions/research/types.d.ts.map +1 -0
  119. package/dist/types/src/functions/tasks/index.d.ts +15 -0
  120. package/dist/types/src/functions/tasks/index.d.ts.map +1 -0
  121. package/dist/types/src/functions/tasks/read.d.ts +7 -0
  122. package/dist/types/src/functions/tasks/read.d.ts.map +1 -0
  123. package/dist/types/src/functions/tasks/task-list.d.ts +74 -0
  124. package/dist/types/src/functions/tasks/task-list.d.ts.map +1 -0
  125. package/dist/types/src/functions/tasks/task-list.test.d.ts +2 -0
  126. package/dist/types/src/functions/tasks/task-list.test.d.ts.map +1 -0
  127. package/dist/types/src/functions/tasks/update.d.ts +9 -0
  128. package/dist/types/src/functions/tasks/update.d.ts.map +1 -0
  129. package/dist/types/src/index.d.ts +6 -0
  130. package/dist/types/src/index.d.ts.map +1 -0
  131. package/dist/types/src/initiative/Initiative.d.ts +84 -0
  132. package/dist/types/src/initiative/Initiative.d.ts.map +1 -0
  133. package/dist/types/src/initiative/InitiativeSchema.d.ts +19 -0
  134. package/dist/types/src/initiative/InitiativeSchema.d.ts.map +1 -0
  135. package/dist/types/src/initiative/functions/agent.d.ts +37 -0
  136. package/dist/types/src/initiative/functions/agent.d.ts.map +1 -0
  137. package/dist/types/src/initiative/functions/getContext.d.ts +17 -0
  138. package/dist/types/src/initiative/functions/getContext.d.ts.map +1 -0
  139. package/dist/types/src/initiative/functions/index.d.ts +4 -0
  140. package/dist/types/src/initiative/functions/index.d.ts.map +1 -0
  141. package/dist/types/src/initiative/functions/update.d.ts +7 -0
  142. package/dist/types/src/initiative/functions/update.d.ts.map +1 -0
  143. package/dist/types/src/initiative/index.d.ts +1 -0
  144. package/dist/types/src/initiative/index.d.ts.map +1 -0
  145. package/dist/types/src/initiative/initiative.test.d.ts +2 -0
  146. package/dist/types/src/initiative/initiative.test.d.ts.map +1 -0
  147. package/dist/types/src/sync/index.d.ts +2 -0
  148. package/dist/types/src/sync/index.d.ts.map +1 -0
  149. package/dist/types/src/sync/sync.d.ts +15 -0
  150. package/dist/types/src/sync/sync.d.ts.map +1 -0
  151. package/dist/types/src/testing/index.d.ts +2 -0
  152. package/dist/types/src/testing/index.d.ts.map +1 -0
  153. package/dist/types/src/testing/plugins.d.ts +19 -0
  154. package/dist/types/src/testing/plugins.d.ts.map +1 -0
  155. package/dist/types/src/toolkits/AssistantToolkit.d.ts +43 -0
  156. package/dist/types/src/toolkits/AssistantToolkit.d.ts.map +1 -0
  157. package/dist/types/src/toolkits/AssistantToolkit.test.d.ts +2 -0
  158. package/dist/types/src/toolkits/AssistantToolkit.test.d.ts.map +1 -0
  159. package/dist/types/src/toolkits/SystemToolkit.d.ts +99 -0
  160. package/dist/types/src/toolkits/SystemToolkit.d.ts.map +1 -0
  161. package/dist/types/src/toolkits/index.d.ts +3 -0
  162. package/dist/types/src/toolkits/index.d.ts.map +1 -0
  163. package/dist/types/src/util/graphql.d.ts +22 -0
  164. package/dist/types/src/util/graphql.d.ts.map +1 -0
  165. package/dist/types/src/util/index.d.ts +2 -0
  166. package/dist/types/src/util/index.d.ts.map +1 -0
  167. package/dist/types/tsconfig.tsbuildinfo +1 -0
  168. package/package.json +83 -0
  169. package/src/blueprints/design/design-blueprint.test.ts +105 -0
  170. package/src/blueprints/design/design-blueprint.ts +31 -0
  171. package/src/blueprints/design/index.ts +7 -0
  172. package/src/blueprints/discord/discord-blueprint.ts +32 -0
  173. package/src/blueprints/discord/index.ts +7 -0
  174. package/src/blueprints/index.ts +10 -0
  175. package/src/blueprints/linear/index.ts +7 -0
  176. package/src/blueprints/linear/linear-blueprint.ts +33 -0
  177. package/src/blueprints/planning/index.ts +7 -0
  178. package/src/blueprints/planning/planning-blueprint.test.ts +126 -0
  179. package/src/blueprints/planning/planning-blueprint.ts +96 -0
  180. package/src/blueprints/research/index.ts +7 -0
  181. package/src/blueprints/research/research-blueprint.test.ts +7 -0
  182. package/src/blueprints/research/research-blueprint.ts +51 -0
  183. package/src/blueprints/testing.ts +34 -0
  184. package/src/blueprints/websearch/index.ts +9 -0
  185. package/src/blueprints/websearch/websearch-blueprint.ts +18 -0
  186. package/src/blueprints/websearch/websearch-toolkit.ts +8 -0
  187. package/src/crud/graph.test.ts +46 -0
  188. package/src/crud/graph.ts +380 -0
  189. package/src/crud/index.ts +5 -0
  190. package/src/experimental/feed.test.ts +111 -0
  191. package/src/functions/agent/index.ts +11 -0
  192. package/src/functions/agent/prompt.ts +118 -0
  193. package/src/functions/discord/fetch-messages.test.ts +58 -0
  194. package/src/functions/discord/fetch-messages.ts +252 -0
  195. package/src/functions/discord/index.ts +9 -0
  196. package/src/functions/document/index.ts +12 -0
  197. package/src/functions/document/read.ts +30 -0
  198. package/src/functions/document/update.ts +33 -0
  199. package/src/functions/entity-extraction/entity-extraction.conversations.json +6597 -0
  200. package/src/functions/entity-extraction/entity-extraction.test.ts +93 -0
  201. package/src/functions/entity-extraction/entity-extraction.ts +183 -0
  202. package/src/functions/entity-extraction/index.ts +9 -0
  203. package/src/functions/exa/data/exa-search-1748337321991.ts +131 -0
  204. package/src/functions/exa/data/exa-search-1748337331526.ts +144 -0
  205. package/src/functions/exa/data/exa-search-1748337344119.ts +133 -0
  206. package/src/functions/exa/data/index.ts +11 -0
  207. package/src/functions/exa/exa.ts +37 -0
  208. package/src/functions/exa/index.ts +6 -0
  209. package/src/functions/exa/mock.ts +71 -0
  210. package/src/functions/github/fetch-prs.ts +31 -0
  211. package/src/functions/index.ts +11 -0
  212. package/src/functions/linear/index.ts +9 -0
  213. package/src/functions/linear/linear.test.ts +84 -0
  214. package/src/functions/linear/sync-issues.ts +191 -0
  215. package/src/functions/research/document-create.ts +76 -0
  216. package/src/functions/research/index.ts +14 -0
  217. package/src/functions/research/research-graph.ts +49 -0
  218. package/src/functions/research/research-instructions.tpl +106 -0
  219. package/src/functions/research/research.conversations.json +1 -0
  220. package/src/functions/research/research.test.ts +171 -0
  221. package/src/functions/research/research.ts +189 -0
  222. package/src/functions/research/types.ts +26 -0
  223. package/src/functions/tasks/index.ts +11 -0
  224. package/src/functions/tasks/read.ts +35 -0
  225. package/src/functions/tasks/task-list.test.ts +99 -0
  226. package/src/functions/tasks/task-list.ts +165 -0
  227. package/src/functions/tasks/update.ts +53 -0
  228. package/src/index.ts +9 -0
  229. package/src/initiative/Initiative.ts +99 -0
  230. package/src/initiative/InitiativeSchema.ts +37 -0
  231. package/src/initiative/functions/agent.ts +57 -0
  232. package/src/initiative/functions/getContext.ts +74 -0
  233. package/src/initiative/functions/index.ts +7 -0
  234. package/src/initiative/functions/update.ts +63 -0
  235. package/src/initiative/index.ts +3 -0
  236. package/src/initiative/initiative.conversations.json +1 -0
  237. package/src/initiative/initiative.test.ts +485 -0
  238. package/src/sync/index.ts +5 -0
  239. package/src/sync/sync.ts +95 -0
  240. package/src/testing/index.ts +5 -0
  241. package/src/testing/plugins.tsx +68 -0
  242. package/src/toolkits/AssistantToolkit.conversations.json +1 -0
  243. package/src/toolkits/AssistantToolkit.test.ts +94 -0
  244. package/src/toolkits/AssistantToolkit.ts +70 -0
  245. package/src/toolkits/SystemToolkit.ts +299 -0
  246. package/src/toolkits/index.ts +6 -0
  247. package/src/typedefs.d.ts +8 -0
  248. package/src/util/graphql.ts +31 -0
  249. package/src/util/index.ts +5 -0
@@ -0,0 +1,53 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import * as Effect from 'effect/Effect';
6
+ import * as Schema from 'effect/Schema';
7
+
8
+ import { ArtifactId } from '@dxos/assistant';
9
+ import { Database } from '@dxos/echo';
10
+ import { defineFunction } from '@dxos/functions';
11
+ import { Markdown } from '@dxos/plugin-markdown/types';
12
+
13
+ import { MarkdownTasks, type TaskOperation } from './task-list';
14
+
15
+ export default defineFunction({
16
+ key: 'dxos.org/function/markdown/update-tasks',
17
+ name: 'Update markdown',
18
+ description: 'Creates and updates tasks in markdown documents.',
19
+ inputSchema: Schema.Struct({
20
+ id: ArtifactId.annotations({
21
+ description: 'The ID of the document to update.',
22
+ }),
23
+ operations: Schema.optional(
24
+ Schema.Array(
25
+ Schema.Any.annotations({
26
+ description: 'Task operations to apply.',
27
+ }),
28
+ ),
29
+ ),
30
+ }),
31
+ outputSchema: Schema.Struct({
32
+ content: Schema.String,
33
+ numberedContent: Schema.String.annotations({
34
+ description: 'Content with line numbers for agent reference.',
35
+ }),
36
+ }),
37
+ handler: Effect.fn(function* ({ data: { id, operations = [] } }) {
38
+ const doc = yield* Database.Service.resolve(ArtifactId.toDXN(id), Markdown.Document);
39
+
40
+ // Create task manager and apply operations if provided.
41
+ const { content } = yield* Database.Service.load(doc.content);
42
+ const taskManager = new MarkdownTasks(content);
43
+ if (operations.length > 0) {
44
+ taskManager.applyOperations(operations as TaskOperation[]);
45
+ // TODO: Update the document content when database operations are fixed.
46
+ }
47
+
48
+ return {
49
+ content: taskManager.getRawContent(),
50
+ numberedContent: taskManager.getNumberedContent(),
51
+ };
52
+ }),
53
+ });
package/src/index.ts ADDED
@@ -0,0 +1,9 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ export * from './blueprints';
6
+ export * from './functions';
7
+ export * from './sync';
8
+ export * from './crud';
9
+ export * from './toolkits';
@@ -0,0 +1,99 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ import * as Effect from 'effect/Effect';
6
+
7
+ import { AiContextBinder, type ContextBinding } from '@dxos/assistant';
8
+ import { Blueprint, Template } from '@dxos/blueprints';
9
+ import { Database, Obj, Ref } from '@dxos/echo';
10
+ import { QueueService } from '@dxos/functions';
11
+ import { Text } from '@dxos/schema';
12
+ import type { Message } from '@dxos/types';
13
+ import { trim } from '@dxos/util';
14
+
15
+ import { agent, getContext, update } from './functions';
16
+ import { Initiative, PLAN_ARTIFACT_NAME, SPEC_ARTIFACT_NAME } from './InitiativeSchema';
17
+
18
+ export { Initiative, PLAN_ARTIFACT_NAME, SPEC_ARTIFACT_NAME } from './InitiativeSchema';
19
+ export type { Initiative as InitiativeType } from './InitiativeSchema';
20
+
21
+ export const make = (
22
+ props: Omit<Obj.MakeProps<typeof Initiative>, 'artifacts' | 'chat'> &
23
+ Partial<Pick<Obj.MakeProps<typeof Initiative>, 'artifacts'>> & {
24
+ spec: string;
25
+ plan?: string;
26
+ blueprints?: Ref.Ref<Blueprint.Blueprint>[];
27
+ contextObjects?: Ref.Ref<Obj.Any>[];
28
+ },
29
+ ): Effect.Effect<Initiative, never, QueueService | Database.Service> =>
30
+ Effect.gen(function* () {
31
+ const initiative = Obj.make(Initiative, {
32
+ ...props,
33
+ artifacts: [
34
+ {
35
+ name: SPEC_ARTIFACT_NAME,
36
+ data: Ref.make(Text.make(props.spec)),
37
+ },
38
+ {
39
+ name: PLAN_ARTIFACT_NAME,
40
+ data: Ref.make(Text.make(props.plan ?? '')),
41
+ },
42
+ ...(props.artifacts ?? []),
43
+ ],
44
+ });
45
+ yield* Database.Service.add(initiative);
46
+ const queue = yield* QueueService.createQueue<Message.Message | ContextBinding>();
47
+ const contextBinder = new AiContextBinder({ queue });
48
+ const initiativeBlueprint = yield* Database.Service.add(Obj.clone(InitiativeBlueprint, { deep: true }));
49
+ yield* Effect.promise(() =>
50
+ contextBinder.bind({
51
+ blueprints: [Ref.make(initiativeBlueprint), ...(props.blueprints ?? [])],
52
+ objects: [Ref.make(initiative), ...(props.contextObjects ?? [])],
53
+ }),
54
+ );
55
+ Obj.change(initiative, (initiative) => {
56
+ initiative.chat = Ref.fromDXN(queue.dxn);
57
+ });
58
+
59
+ return initiative;
60
+ });
61
+
62
+ export const functions = [getContext, update, agent];
63
+
64
+ export const InitiativeBlueprint = Blueprint.make({
65
+ key: 'dxos.org/blueprint/initiative',
66
+ name: 'Initiative blueprint',
67
+ instructions: Template.make({
68
+ source: trim`
69
+ You work on an initiative. Each initiative has a spec - the goal of the initiative.
70
+ The initiative plan shows the current progress of the initiative.
71
+ Initiative has an number of associated artifacts you can read/write.
72
+ Spec and plan are also artifacts.
73
+ You can edit them if necessary.
74
+
75
+ {{#with initiative}}
76
+ Initiative spec:
77
+ {{spec.dxn}}
78
+ {{spec.content}}
79
+
80
+ Initiative plan:
81
+ {{plan.dxn}}
82
+ {{plan.content}}
83
+
84
+ All artifacts:
85
+ {{#each artifacts}}
86
+ {{name}}: {{type}} {{dxn}}
87
+ {{/each}}
88
+ {{/with}}
89
+ `,
90
+ inputs: [
91
+ {
92
+ name: 'initiative',
93
+ kind: 'function',
94
+ function: 'dxos.org/function/initiative/get-context',
95
+ },
96
+ ],
97
+ }),
98
+ tools: Blueprint.toolDefinitions({ functions: [update] }),
99
+ });
@@ -0,0 +1,37 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import * as Schema from 'effect/Schema';
6
+
7
+ import { Type } from '@dxos/echo';
8
+ import { Queue } from '@dxos/echo-db';
9
+
10
+ /**
11
+ * Initiative schema definition.
12
+ */
13
+ export const Initiative = Schema.Struct({
14
+ name: Schema.String,
15
+ artifacts: Schema.Array(
16
+ Schema.Struct({
17
+ name: Schema.String,
18
+ data: Type.Ref(Type.Obj),
19
+ }),
20
+ ),
21
+
22
+ // TODO(dmaretskyi): Consider using chat type.
23
+ // TODO(dmaretskyi): Multiple chats.
24
+ chat: Schema.optional(Type.Ref(Queue)),
25
+
26
+ // TODO(dmaretskyi): Triggers & input queue.
27
+ }).pipe(
28
+ Type.object({
29
+ typename: 'dxos.org/type/Initiative',
30
+ version: '0.1.0',
31
+ }),
32
+ );
33
+ export interface Initiative extends Schema.Schema.Type<typeof Initiative> {}
34
+
35
+ export const SPEC_ARTIFACT_NAME = 'Spec';
36
+
37
+ export const PLAN_ARTIFACT_NAME = 'Plan';
@@ -0,0 +1,57 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ import * as Effect from 'effect/Effect';
6
+ import * as Schema from 'effect/Schema';
7
+
8
+ import { AiContextService, AiConversation } from '@dxos/assistant';
9
+ import { Database, Obj, Type } from '@dxos/echo';
10
+ import { acquireReleaseResource } from '@dxos/effect';
11
+ import { TriggerEvent, defineFunction } from '@dxos/functions';
12
+ import { invariant } from '@dxos/invariant';
13
+
14
+ import * as Initiative from '../InitiativeSchema';
15
+
16
+ export default defineFunction({
17
+ key: 'dxos.org/function/initiative/agent',
18
+ name: 'Initiative Agent',
19
+ description: 'Agentic worker that drives the initiative autonomously.',
20
+ inputSchema: Schema.Struct({
21
+ initiative: Schema.suspend(() => Type.Ref(Initiative.Initiative)),
22
+ prompt: Schema.optional(Schema.String),
23
+ event: Schema.optional(TriggerEvent.TriggerEvent),
24
+ }),
25
+ outputSchema: Schema.Void,
26
+ services: [AiContextService],
27
+ handler: Effect.fnUntraced(function* ({ data }) {
28
+ const initiative = yield* Database.Service.load(data.initiative);
29
+ invariant(Obj.instanceOf(Initiative.Initiative, initiative));
30
+ invariant(initiative.chat, 'Initiative has no chat.');
31
+ const chatQueue = yield* Database.Service.load(initiative.chat!);
32
+ invariant(chatQueue, 'Initiative chat queue not found.');
33
+ const conversation = yield* acquireReleaseResource(() => new AiConversation({ queue: chatQueue as any }));
34
+
35
+ const iniativesInContext = conversation.context.getObjects().filter(Obj.instanceOf(Initiative.Initiative));
36
+ if (iniativesInContext.length !== 1) {
37
+ throw new Error('There should be exactly one initiative in context. Got: ' + iniativesInContext.length);
38
+ }
39
+
40
+ if (!data.prompt && !data.event) {
41
+ throw new Error('Either prompt or event must be provided.');
42
+ }
43
+
44
+ let input = '';
45
+ if (data.prompt) {
46
+ input += `${data.prompt}\n\n`;
47
+ }
48
+ if (data.event) {
49
+ input += `<event>\n${JSON.stringify(data.event, null, 2)}\n</event>\n\n`;
50
+ }
51
+
52
+ yield* conversation.createRequest({
53
+ prompt: input,
54
+ // observer: GenerationObserver.fromPrinter(new ConsolePrinter()),
55
+ });
56
+ }, Effect.scoped) as any, // TODO(dmaretskyi): Services don't align -- need to refactor how functions are defined.
57
+ });
@@ -0,0 +1,74 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ import * as Effect from 'effect/Effect';
6
+ import * as Schema from 'effect/Schema';
7
+
8
+ import { AiContextService } from '@dxos/assistant';
9
+ import { Database, Obj } from '@dxos/echo';
10
+ import { defineFunction } from '@dxos/functions';
11
+ import { Text } from '@dxos/schema';
12
+
13
+ import * as Initiative from '../InitiativeSchema';
14
+
15
+ export default defineFunction({
16
+ key: 'dxos.org/function/initiative/get-context',
17
+ name: 'Get Initiative Context',
18
+ description: 'Get the context of an initiative.',
19
+ inputSchema: Schema.Struct({}),
20
+ outputSchema: Schema.Struct({
21
+ spec: Schema.Struct({
22
+ dxn: Schema.String,
23
+ content: Schema.String,
24
+ }),
25
+ plan: Schema.Struct({
26
+ dxn: Schema.String,
27
+ content: Schema.String,
28
+ }),
29
+ artifacts: Schema.Array(
30
+ Schema.Struct({
31
+ name: Schema.String,
32
+ type: Schema.String,
33
+ dxn: Schema.String,
34
+ }),
35
+ ),
36
+ }),
37
+ services: [AiContextService],
38
+ handler: Effect.fnUntraced(function* ({ data }) {
39
+ const { binder } = yield* AiContextService;
40
+
41
+ const initiative = binder
42
+ .getObjects()
43
+ .filter((_) => Obj.instanceOf(Initiative.Initiative, _))
44
+ .at(0);
45
+ if (!initiative) {
46
+ throw new Error('No initiative in context.');
47
+ }
48
+
49
+ const spec = initiative.artifacts.find((artifact) => artifact.name === Initiative.SPEC_ARTIFACT_NAME);
50
+ const plan = initiative.artifacts.find((artifact) => artifact.name === Initiative.PLAN_ARTIFACT_NAME);
51
+ const specObj = !spec ? undefined : yield* Database.Service.resolve(spec.data, Text.Text);
52
+ const planObj = !plan ? undefined : yield* Database.Service.resolve(plan.data, Text.Text);
53
+
54
+ return {
55
+ spec: {
56
+ dxn: spec?.data.dxn.toString(),
57
+ content: specObj?.content ?? 'No spec found.',
58
+ },
59
+ plan: {
60
+ dxn: plan?.data.dxn.toString(),
61
+ content: planObj?.content ?? 'No plan found.',
62
+ },
63
+ artifacts: yield* Effect.forEach(initiative.artifacts, (artifact) =>
64
+ Effect.gen(function* () {
65
+ return {
66
+ name: artifact.name,
67
+ type: Obj.getTypename(yield* Database.Service.load(artifact.data)),
68
+ dxn: artifact.data.dxn.toString(),
69
+ };
70
+ }),
71
+ ),
72
+ };
73
+ }) as any, // TODO(dmaretskyi): Services don't align -- need to refactor how functions are defined.
74
+ });
@@ -0,0 +1,7 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ export { default as getContext } from './getContext';
6
+ export { default as update } from './update';
7
+ export { default as agent } from './agent';
@@ -0,0 +1,63 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import * as Effect from 'effect/Effect';
6
+ import * as Schema from 'effect/Schema';
7
+
8
+ import { AiContextService } from '@dxos/assistant';
9
+ import { Database, Obj, Ref } from '@dxos/echo';
10
+ import { defineFunction } from '@dxos/functions';
11
+ import { Text } from '@dxos/schema';
12
+
13
+ import * as Initiative from '../InitiativeSchema';
14
+
15
+ export default defineFunction({
16
+ key: 'dxos.org/function/initiative/update',
17
+ name: 'Create or update artifact',
18
+ description: 'Updates the text artifact to have new content.',
19
+ inputSchema: Schema.Struct({
20
+ name: Schema.String.annotations({
21
+ description: 'The name of the artifact to update.',
22
+ }),
23
+ content: Schema.String.annotations({
24
+ description: 'The new content of the artifact.',
25
+ }),
26
+ create: Schema.optional(Schema.Boolean).annotations({
27
+ description: 'Whether to create the artifact if it does not exist.',
28
+ }),
29
+ }),
30
+ outputSchema: Schema.Void,
31
+ services: [AiContextService],
32
+ handler: Effect.fnUntraced(function* ({ data }) {
33
+ const { binder } = yield* AiContextService;
34
+
35
+ const initiative = binder
36
+ .getObjects()
37
+ .filter((_) => Obj.instanceOf(Initiative.Initiative, _))
38
+ .at(0);
39
+ if (!initiative) {
40
+ throw new Error('No initiative in context.');
41
+ }
42
+
43
+ const artifact = initiative.artifacts.find((artifact) => artifact.name === data.name);
44
+ if (!artifact) {
45
+ if (data.create) {
46
+ Obj.change(initiative, (initiative) => {
47
+ initiative.artifacts.push({
48
+ name: data.name,
49
+ data: Ref.make(Text.make(data.content)),
50
+ });
51
+ });
52
+ return;
53
+ } else {
54
+ throw new Error(`Artifact ${data.name} not found.`);
55
+ }
56
+ }
57
+
58
+ const artifactObj = yield* Database.Service.resolve(artifact.data, Text.Text);
59
+ Obj.change(artifactObj, (artifactObj) => {
60
+ artifactObj.content = data.content;
61
+ });
62
+ }) as any, // TODO(dmaretskyi): Services don't align -- need to refactor how functions are defined.
63
+ });
@@ -0,0 +1,3 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //