@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.
- package/LICENSE +8 -0
- package/README.md +3 -0
- package/dist/lib/browser/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/browser/chunk-J5LGTIGS.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +2880 -0
- package/dist/lib/browser/index.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -0
- package/dist/lib/browser/testing/index.mjs +43 -0
- package/dist/lib/browser/testing/index.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +2881 -0
- package/dist/lib/node-esm/index.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -0
- package/dist/lib/node-esm/testing/index.mjs +44 -0
- package/dist/lib/node-esm/testing/index.mjs.map +7 -0
- package/dist/types/src/blueprints/design/design-blueprint.d.ts +18 -0
- package/dist/types/src/blueprints/design/design-blueprint.d.ts.map +1 -0
- package/dist/types/src/blueprints/design/design-blueprint.test.d.ts +2 -0
- package/dist/types/src/blueprints/design/design-blueprint.test.d.ts.map +1 -0
- package/dist/types/src/blueprints/design/index.d.ts +3 -0
- package/dist/types/src/blueprints/design/index.d.ts.map +1 -0
- package/dist/types/src/blueprints/discord/discord-blueprint.d.ts +18 -0
- package/dist/types/src/blueprints/discord/discord-blueprint.d.ts.map +1 -0
- package/dist/types/src/blueprints/discord/index.d.ts +3 -0
- package/dist/types/src/blueprints/discord/index.d.ts.map +1 -0
- package/dist/types/src/blueprints/index.d.ts +7 -0
- package/dist/types/src/blueprints/index.d.ts.map +1 -0
- package/dist/types/src/blueprints/linear/index.d.ts +3 -0
- package/dist/types/src/blueprints/linear/index.d.ts.map +1 -0
- package/dist/types/src/blueprints/linear/linear-blueprint.d.ts +18 -0
- package/dist/types/src/blueprints/linear/linear-blueprint.d.ts.map +1 -0
- package/dist/types/src/blueprints/planning/index.d.ts +3 -0
- package/dist/types/src/blueprints/planning/index.d.ts.map +1 -0
- package/dist/types/src/blueprints/planning/planning-blueprint.d.ts +18 -0
- package/dist/types/src/blueprints/planning/planning-blueprint.d.ts.map +1 -0
- package/dist/types/src/blueprints/planning/planning-blueprint.test.d.ts +2 -0
- package/dist/types/src/blueprints/planning/planning-blueprint.test.d.ts.map +1 -0
- package/dist/types/src/blueprints/research/index.d.ts +3 -0
- package/dist/types/src/blueprints/research/index.d.ts.map +1 -0
- package/dist/types/src/blueprints/research/research-blueprint.d.ts +18 -0
- package/dist/types/src/blueprints/research/research-blueprint.d.ts.map +1 -0
- package/dist/types/src/blueprints/research/research-blueprint.test.d.ts +2 -0
- package/dist/types/src/blueprints/research/research-blueprint.test.d.ts.map +1 -0
- package/dist/types/src/blueprints/testing.d.ts +12 -0
- package/dist/types/src/blueprints/testing.d.ts.map +1 -0
- package/dist/types/src/blueprints/websearch/index.d.ts +4 -0
- package/dist/types/src/blueprints/websearch/index.d.ts.map +1 -0
- package/dist/types/src/blueprints/websearch/websearch-blueprint.d.ts +18 -0
- package/dist/types/src/blueprints/websearch/websearch-blueprint.d.ts.map +1 -0
- package/dist/types/src/blueprints/websearch/websearch-toolkit.d.ts +27 -0
- package/dist/types/src/blueprints/websearch/websearch-toolkit.d.ts.map +1 -0
- package/dist/types/src/crud/graph.d.ts +67 -0
- package/dist/types/src/crud/graph.d.ts.map +1 -0
- package/dist/types/src/crud/graph.test.d.ts +2 -0
- package/dist/types/src/crud/graph.test.d.ts.map +1 -0
- package/dist/types/src/crud/index.d.ts +2 -0
- package/dist/types/src/crud/index.d.ts.map +1 -0
- package/dist/types/src/experimental/feed.test.d.ts +2 -0
- package/dist/types/src/experimental/feed.test.d.ts.map +1 -0
- package/dist/types/src/functions/agent/index.d.ts +5 -0
- package/dist/types/src/functions/agent/index.d.ts.map +1 -0
- package/dist/types/src/functions/agent/prompt.d.ts +76 -0
- package/dist/types/src/functions/agent/prompt.d.ts.map +1 -0
- package/dist/types/src/functions/discord/fetch-messages.d.ts +11 -0
- package/dist/types/src/functions/discord/fetch-messages.d.ts.map +1 -0
- package/dist/types/src/functions/discord/fetch-messages.test.d.ts +2 -0
- package/dist/types/src/functions/discord/fetch-messages.test.d.ts.map +1 -0
- package/dist/types/src/functions/discord/index.d.ts +12 -0
- package/dist/types/src/functions/discord/index.d.ts.map +1 -0
- package/dist/types/src/functions/document/index.d.ts +13 -0
- package/dist/types/src/functions/document/index.d.ts.map +1 -0
- package/dist/types/src/functions/document/read.d.ts +7 -0
- package/dist/types/src/functions/document/read.d.ts.map +1 -0
- package/dist/types/src/functions/document/update.d.ts +6 -0
- package/dist/types/src/functions/document/update.d.ts.map +1 -0
- package/dist/types/src/functions/entity-extraction/entity-extraction.d.ts +174 -0
- package/dist/types/src/functions/entity-extraction/entity-extraction.d.ts.map +1 -0
- package/dist/types/src/functions/entity-extraction/entity-extraction.test.d.ts +2 -0
- package/dist/types/src/functions/entity-extraction/entity-extraction.test.d.ts.map +1 -0
- package/dist/types/src/functions/entity-extraction/index.d.ts +175 -0
- package/dist/types/src/functions/entity-extraction/index.d.ts.map +1 -0
- package/dist/types/src/functions/exa/data/exa-search-1748337321991.d.ts +38 -0
- package/dist/types/src/functions/exa/data/exa-search-1748337321991.d.ts.map +1 -0
- package/dist/types/src/functions/exa/data/exa-search-1748337331526.d.ts +37 -0
- package/dist/types/src/functions/exa/data/exa-search-1748337331526.d.ts.map +1 -0
- package/dist/types/src/functions/exa/data/exa-search-1748337344119.d.ts +58 -0
- package/dist/types/src/functions/exa/data/exa-search-1748337344119.d.ts.map +1 -0
- package/dist/types/src/functions/exa/data/index.d.ts +3 -0
- package/dist/types/src/functions/exa/data/index.d.ts.map +1 -0
- package/dist/types/src/functions/exa/exa.d.ts +5 -0
- package/dist/types/src/functions/exa/exa.d.ts.map +1 -0
- package/dist/types/src/functions/exa/index.d.ts +3 -0
- package/dist/types/src/functions/exa/index.d.ts.map +1 -0
- package/dist/types/src/functions/exa/mock.d.ts +5 -0
- package/dist/types/src/functions/exa/mock.d.ts.map +1 -0
- package/dist/types/src/functions/github/fetch-prs.d.ts +6 -0
- package/dist/types/src/functions/github/fetch-prs.d.ts.map +1 -0
- package/dist/types/src/functions/index.d.ts +8 -0
- package/dist/types/src/functions/index.d.ts.map +1 -0
- package/dist/types/src/functions/linear/index.d.ts +9 -0
- package/dist/types/src/functions/linear/index.d.ts.map +1 -0
- package/dist/types/src/functions/linear/linear.test.d.ts +2 -0
- package/dist/types/src/functions/linear/linear.test.d.ts.map +1 -0
- package/dist/types/src/functions/linear/sync-issues.d.ts +12 -0
- package/dist/types/src/functions/linear/sync-issues.d.ts.map +1 -0
- package/dist/types/src/functions/research/document-create.d.ts +9 -0
- package/dist/types/src/functions/research/document-create.d.ts.map +1 -0
- package/dist/types/src/functions/research/index.d.ts +21 -0
- package/dist/types/src/functions/research/index.d.ts.map +1 -0
- package/dist/types/src/functions/research/research-graph.d.ts +19 -0
- package/dist/types/src/functions/research/research-graph.d.ts.map +1 -0
- package/dist/types/src/functions/research/research.d.ts +14 -0
- package/dist/types/src/functions/research/research.d.ts.map +1 -0
- package/dist/types/src/functions/research/research.test.d.ts +2 -0
- package/dist/types/src/functions/research/research.test.d.ts.map +1 -0
- package/dist/types/src/functions/research/types.d.ts +6 -0
- package/dist/types/src/functions/research/types.d.ts.map +1 -0
- package/dist/types/src/functions/tasks/index.d.ts +15 -0
- package/dist/types/src/functions/tasks/index.d.ts.map +1 -0
- package/dist/types/src/functions/tasks/read.d.ts +7 -0
- package/dist/types/src/functions/tasks/read.d.ts.map +1 -0
- package/dist/types/src/functions/tasks/task-list.d.ts +74 -0
- package/dist/types/src/functions/tasks/task-list.d.ts.map +1 -0
- package/dist/types/src/functions/tasks/task-list.test.d.ts +2 -0
- package/dist/types/src/functions/tasks/task-list.test.d.ts.map +1 -0
- package/dist/types/src/functions/tasks/update.d.ts +9 -0
- package/dist/types/src/functions/tasks/update.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +6 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/dist/types/src/initiative/Initiative.d.ts +84 -0
- package/dist/types/src/initiative/Initiative.d.ts.map +1 -0
- package/dist/types/src/initiative/InitiativeSchema.d.ts +19 -0
- package/dist/types/src/initiative/InitiativeSchema.d.ts.map +1 -0
- package/dist/types/src/initiative/functions/agent.d.ts +37 -0
- package/dist/types/src/initiative/functions/agent.d.ts.map +1 -0
- package/dist/types/src/initiative/functions/getContext.d.ts +17 -0
- package/dist/types/src/initiative/functions/getContext.d.ts.map +1 -0
- package/dist/types/src/initiative/functions/index.d.ts +4 -0
- package/dist/types/src/initiative/functions/index.d.ts.map +1 -0
- package/dist/types/src/initiative/functions/update.d.ts +7 -0
- package/dist/types/src/initiative/functions/update.d.ts.map +1 -0
- package/dist/types/src/initiative/index.d.ts +1 -0
- package/dist/types/src/initiative/index.d.ts.map +1 -0
- package/dist/types/src/initiative/initiative.test.d.ts +2 -0
- package/dist/types/src/initiative/initiative.test.d.ts.map +1 -0
- package/dist/types/src/sync/index.d.ts +2 -0
- package/dist/types/src/sync/index.d.ts.map +1 -0
- package/dist/types/src/sync/sync.d.ts +15 -0
- package/dist/types/src/sync/sync.d.ts.map +1 -0
- package/dist/types/src/testing/index.d.ts +2 -0
- package/dist/types/src/testing/index.d.ts.map +1 -0
- package/dist/types/src/testing/plugins.d.ts +19 -0
- package/dist/types/src/testing/plugins.d.ts.map +1 -0
- package/dist/types/src/toolkits/AssistantToolkit.d.ts +43 -0
- package/dist/types/src/toolkits/AssistantToolkit.d.ts.map +1 -0
- package/dist/types/src/toolkits/AssistantToolkit.test.d.ts +2 -0
- package/dist/types/src/toolkits/AssistantToolkit.test.d.ts.map +1 -0
- package/dist/types/src/toolkits/SystemToolkit.d.ts +99 -0
- package/dist/types/src/toolkits/SystemToolkit.d.ts.map +1 -0
- package/dist/types/src/toolkits/index.d.ts +3 -0
- package/dist/types/src/toolkits/index.d.ts.map +1 -0
- package/dist/types/src/util/graphql.d.ts +22 -0
- package/dist/types/src/util/graphql.d.ts.map +1 -0
- package/dist/types/src/util/index.d.ts +2 -0
- package/dist/types/src/util/index.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +83 -0
- package/src/blueprints/design/design-blueprint.test.ts +105 -0
- package/src/blueprints/design/design-blueprint.ts +31 -0
- package/src/blueprints/design/index.ts +7 -0
- package/src/blueprints/discord/discord-blueprint.ts +32 -0
- package/src/blueprints/discord/index.ts +7 -0
- package/src/blueprints/index.ts +10 -0
- package/src/blueprints/linear/index.ts +7 -0
- package/src/blueprints/linear/linear-blueprint.ts +33 -0
- package/src/blueprints/planning/index.ts +7 -0
- package/src/blueprints/planning/planning-blueprint.test.ts +126 -0
- package/src/blueprints/planning/planning-blueprint.ts +96 -0
- package/src/blueprints/research/index.ts +7 -0
- package/src/blueprints/research/research-blueprint.test.ts +7 -0
- package/src/blueprints/research/research-blueprint.ts +51 -0
- package/src/blueprints/testing.ts +34 -0
- package/src/blueprints/websearch/index.ts +9 -0
- package/src/blueprints/websearch/websearch-blueprint.ts +18 -0
- package/src/blueprints/websearch/websearch-toolkit.ts +8 -0
- package/src/crud/graph.test.ts +46 -0
- package/src/crud/graph.ts +380 -0
- package/src/crud/index.ts +5 -0
- package/src/experimental/feed.test.ts +111 -0
- package/src/functions/agent/index.ts +11 -0
- package/src/functions/agent/prompt.ts +118 -0
- package/src/functions/discord/fetch-messages.test.ts +58 -0
- package/src/functions/discord/fetch-messages.ts +252 -0
- package/src/functions/discord/index.ts +9 -0
- package/src/functions/document/index.ts +12 -0
- package/src/functions/document/read.ts +30 -0
- package/src/functions/document/update.ts +33 -0
- package/src/functions/entity-extraction/entity-extraction.conversations.json +6597 -0
- package/src/functions/entity-extraction/entity-extraction.test.ts +93 -0
- package/src/functions/entity-extraction/entity-extraction.ts +183 -0
- package/src/functions/entity-extraction/index.ts +9 -0
- package/src/functions/exa/data/exa-search-1748337321991.ts +131 -0
- package/src/functions/exa/data/exa-search-1748337331526.ts +144 -0
- package/src/functions/exa/data/exa-search-1748337344119.ts +133 -0
- package/src/functions/exa/data/index.ts +11 -0
- package/src/functions/exa/exa.ts +37 -0
- package/src/functions/exa/index.ts +6 -0
- package/src/functions/exa/mock.ts +71 -0
- package/src/functions/github/fetch-prs.ts +31 -0
- package/src/functions/index.ts +11 -0
- package/src/functions/linear/index.ts +9 -0
- package/src/functions/linear/linear.test.ts +84 -0
- package/src/functions/linear/sync-issues.ts +191 -0
- package/src/functions/research/document-create.ts +76 -0
- package/src/functions/research/index.ts +14 -0
- package/src/functions/research/research-graph.ts +49 -0
- package/src/functions/research/research-instructions.tpl +106 -0
- package/src/functions/research/research.conversations.json +1 -0
- package/src/functions/research/research.test.ts +171 -0
- package/src/functions/research/research.ts +189 -0
- package/src/functions/research/types.ts +26 -0
- package/src/functions/tasks/index.ts +11 -0
- package/src/functions/tasks/read.ts +35 -0
- package/src/functions/tasks/task-list.test.ts +99 -0
- package/src/functions/tasks/task-list.ts +165 -0
- package/src/functions/tasks/update.ts +53 -0
- package/src/index.ts +9 -0
- package/src/initiative/Initiative.ts +99 -0
- package/src/initiative/InitiativeSchema.ts +37 -0
- package/src/initiative/functions/agent.ts +57 -0
- package/src/initiative/functions/getContext.ts +74 -0
- package/src/initiative/functions/index.ts +7 -0
- package/src/initiative/functions/update.ts +63 -0
- package/src/initiative/index.ts +3 -0
- package/src/initiative/initiative.conversations.json +1 -0
- package/src/initiative/initiative.test.ts +485 -0
- package/src/sync/index.ts +5 -0
- package/src/sync/sync.ts +95 -0
- package/src/testing/index.ts +5 -0
- package/src/testing/plugins.tsx +68 -0
- package/src/toolkits/AssistantToolkit.conversations.json +1 -0
- package/src/toolkits/AssistantToolkit.test.ts +94 -0
- package/src/toolkits/AssistantToolkit.ts +70 -0
- package/src/toolkits/SystemToolkit.ts +299 -0
- package/src/toolkits/index.ts +6 -0
- package/src/typedefs.d.ts +8 -0
- package/src/util/graphql.ts +31 -0
- 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,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,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
|
+
});
|