@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.
- package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/neutral/chunk-J5LGTIGS.mjs.map +7 -0
- package/dist/lib/{browser → neutral}/index.mjs +1410 -480
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/lib/neutral/testing/index.mjs +44 -0
- package/dist/lib/neutral/testing/index.mjs.map +7 -0
- package/dist/types/src/blueprints/design/design-blueprint.d.ts +17 -3
- package/dist/types/src/blueprints/design/design-blueprint.d.ts.map +1 -1
- package/dist/types/src/blueprints/design/index.d.ts +1 -1
- package/dist/types/src/blueprints/design/index.d.ts.map +1 -1
- package/dist/types/src/blueprints/discord/discord-blueprint.d.ts +13 -13
- package/dist/types/src/blueprints/discord/discord-blueprint.d.ts.map +1 -1
- package/dist/types/src/blueprints/discord/index.d.ts +1 -1
- package/dist/types/src/blueprints/discord/index.d.ts.map +1 -1
- package/dist/types/src/blueprints/index.d.ts +1 -0
- package/dist/types/src/blueprints/index.d.ts.map +1 -1
- package/dist/types/src/blueprints/linear/index.d.ts +1 -1
- package/dist/types/src/blueprints/linear/index.d.ts.map +1 -1
- package/dist/types/src/blueprints/linear/linear-blueprint.d.ts +13 -13
- package/dist/types/src/blueprints/linear/linear-blueprint.d.ts.map +1 -1
- package/dist/types/src/blueprints/markdown/index.d.ts +3 -0
- package/dist/types/src/blueprints/markdown/index.d.ts.map +1 -0
- package/dist/types/src/blueprints/markdown/markdown-blueprint.d.ts +18 -0
- package/dist/types/src/blueprints/markdown/markdown-blueprint.d.ts.map +1 -0
- package/dist/types/src/blueprints/planning/index.d.ts +1 -1
- package/dist/types/src/blueprints/planning/index.d.ts.map +1 -1
- package/dist/types/src/blueprints/planning/planning-blueprint.d.ts +17 -3
- package/dist/types/src/blueprints/planning/planning-blueprint.d.ts.map +1 -1
- package/dist/types/src/blueprints/research/index.d.ts +1 -1
- package/dist/types/src/blueprints/research/index.d.ts.map +1 -1
- package/dist/types/src/blueprints/research/research-blueprint.d.ts +17 -3
- package/dist/types/src/blueprints/research/research-blueprint.d.ts.map +1 -1
- package/dist/types/src/blueprints/testing.d.ts +2 -4
- package/dist/types/src/blueprints/testing.d.ts.map +1 -1
- package/dist/types/src/blueprints/websearch/index.d.ts +1 -1
- package/dist/types/src/blueprints/websearch/index.d.ts.map +1 -1
- package/dist/types/src/blueprints/websearch/websearch-blueprint.d.ts +17 -3
- package/dist/types/src/blueprints/websearch/websearch-blueprint.d.ts.map +1 -1
- package/dist/types/src/chat/Chat.d.ts +31 -0
- package/dist/types/src/chat/Chat.d.ts.map +1 -0
- package/dist/types/src/chat/index.d.ts +2 -0
- package/dist/types/src/chat/index.d.ts.map +1 -0
- package/dist/types/src/crud/graph.d.ts +14 -11
- package/dist/types/src/crud/graph.d.ts.map +1 -1
- package/dist/types/src/functions/agent/prompt.d.ts +71 -4
- package/dist/types/src/functions/agent/prompt.d.ts.map +1 -1
- package/dist/types/src/functions/document/create.d.ts +6 -0
- package/dist/types/src/functions/document/create.d.ts.map +1 -0
- package/dist/types/src/functions/document/index.d.ts +20 -3
- package/dist/types/src/functions/document/index.d.ts.map +1 -1
- package/dist/types/src/functions/document/read.d.ts +8 -1
- package/dist/types/src/functions/document/read.d.ts.map +1 -1
- package/dist/types/src/functions/document/update.d.ts +8 -1
- package/dist/types/src/functions/document/update.d.ts.map +1 -1
- package/dist/types/src/functions/entity-extraction/entity-extraction.d.ts +125 -124
- package/dist/types/src/functions/entity-extraction/entity-extraction.d.ts.map +1 -1
- package/dist/types/src/functions/entity-extraction/index.d.ts +125 -124
- package/dist/types/src/functions/entity-extraction/index.d.ts.map +1 -1
- 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.map +1 -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.map +1 -0
- package/dist/types/src/functions/github/fetch-prs.d.ts.map +1 -1
- package/dist/types/src/functions/linear/index.d.ts +1 -1
- package/dist/types/src/functions/linear/sync-issues.d.ts +1 -1
- package/dist/types/src/functions/linear/sync-issues.d.ts.map +1 -1
- package/dist/types/src/functions/research/document-create.d.ts +1 -1
- package/dist/types/src/functions/research/document-create.d.ts.map +1 -1
- package/dist/types/src/functions/research/index.d.ts +2 -2
- package/dist/types/src/functions/research/research-graph.d.ts +9 -8
- package/dist/types/src/functions/research/research-graph.d.ts.map +1 -1
- package/dist/types/src/functions/research/research.d.ts +1 -1
- package/dist/types/src/functions/research/research.d.ts.map +1 -1
- package/dist/types/src/functions/research/types.d.ts +1 -1
- package/dist/types/src/functions/research/types.d.ts.map +1 -1
- package/dist/types/src/functions/tasks/index.d.ts +16 -2
- package/dist/types/src/functions/tasks/index.d.ts.map +1 -1
- package/dist/types/src/functions/tasks/read.d.ts +8 -1
- package/dist/types/src/functions/tasks/read.d.ts.map +1 -1
- package/dist/types/src/functions/tasks/update.d.ts +8 -1
- package/dist/types/src/functions/tasks/update.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +4 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/initiative/Initiative.d.ts +41 -0
- package/dist/types/src/initiative/Initiative.d.ts.map +1 -0
- package/dist/types/src/initiative/blueprint.d.ts +153 -0
- package/dist/types/src/initiative/blueprint.d.ts.map +1 -0
- package/dist/types/src/initiative/functions/addArtifact.d.ts +6 -0
- package/dist/types/src/initiative/functions/addArtifact.d.ts.map +1 -0
- package/dist/types/src/initiative/functions/agent.d.ts +62 -0
- package/dist/types/src/initiative/functions/agent.d.ts.map +1 -0
- package/dist/types/src/initiative/functions/getContext.d.ts +13 -0
- package/dist/types/src/initiative/functions/getContext.d.ts.map +1 -0
- package/dist/types/src/initiative/functions/index.d.ts +5 -0
- package/dist/types/src/initiative/functions/index.d.ts.map +1 -0
- package/dist/types/src/initiative/functions/qualifier.d.ts +60 -0
- package/dist/types/src/initiative/functions/qualifier.d.ts.map +1 -0
- package/dist/types/src/initiative/index.d.ts +6 -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/initiative/plan.d.ts +77 -0
- package/dist/types/src/initiative/plan.d.ts.map +1 -0
- package/dist/types/src/initiative/util.d.ts +29 -0
- package/dist/types/src/initiative/util.d.ts.map +1 -0
- package/dist/types/src/planning/blueprint.d.ts +18 -0
- package/dist/types/src/planning/blueprint.d.ts.map +1 -0
- package/dist/types/src/planning/functions/index.d.ts +2 -0
- package/dist/types/src/planning/functions/index.d.ts.map +1 -0
- package/dist/types/src/planning/functions/update-tasks.d.ts +9 -0
- package/dist/types/src/planning/functions/update-tasks.d.ts.map +1 -0
- package/dist/types/src/planning/index.d.ts +3 -0
- package/dist/types/src/planning/index.d.ts.map +1 -0
- package/dist/types/src/sync/sync.d.ts +3 -3
- package/dist/types/src/sync/sync.d.ts.map +1 -1
- package/dist/types/src/testing/index.d.ts +1 -1
- package/dist/types/src/testing/index.d.ts.map +1 -1
- 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 +31 -5
- package/dist/types/src/toolkits/AssistantToolkit.d.ts.map +1 -1
- package/dist/types/src/toolkits/SystemToolkit.d.ts +42 -10
- package/dist/types/src/toolkits/SystemToolkit.d.ts.map +1 -1
- package/dist/types/src/toolkits/WebToolkit.d.ts +38 -0
- package/dist/types/src/toolkits/WebToolkit.d.ts.map +1 -0
- package/dist/types/src/toolkits/index.d.ts +1 -0
- package/dist/types/src/toolkits/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +45 -40
- package/src/blueprints/design/design-blueprint.test.ts +14 -17
- package/src/blueprints/design/design-blueprint.ts +2 -4
- package/src/blueprints/design/index.ts +1 -1
- package/src/blueprints/discord/discord-blueprint.ts +2 -4
- package/src/blueprints/discord/index.ts +1 -1
- package/src/blueprints/index.ts +1 -0
- package/src/blueprints/linear/index.ts +1 -1
- package/src/blueprints/linear/linear-blueprint.ts +2 -4
- package/src/blueprints/markdown/index.ts +7 -0
- package/src/blueprints/markdown/markdown-blueprint.ts +24 -0
- package/src/blueprints/planning/index.ts +1 -1
- package/src/blueprints/planning/planning-blueprint.test.ts +12 -16
- package/src/blueprints/planning/planning-blueprint.ts +2 -4
- package/src/blueprints/research/index.ts +1 -1
- package/src/blueprints/research/research-blueprint.ts +2 -4
- package/src/blueprints/testing.ts +2 -6
- package/src/blueprints/websearch/index.ts +2 -1
- package/src/blueprints/websearch/websearch-blueprint.ts +2 -4
- package/src/chat/Chat.ts +45 -0
- package/src/chat/index.ts +5 -0
- package/src/crud/graph.test.ts +6 -29
- package/src/crud/graph.ts +32 -40
- package/src/experimental/feed.test.ts +4 -9
- package/src/functions/agent/prompt.ts +15 -13
- package/src/functions/discord/fetch-messages.test.ts +4 -8
- package/src/functions/discord/fetch-messages.ts +1 -1
- package/src/functions/document/create.ts +29 -0
- package/src/functions/document/index.ts +2 -1
- package/src/functions/document/read.ts +11 -8
- package/src/functions/document/update.ts +9 -7
- package/src/functions/entity-extraction/entity-extraction.conversations.json +1 -1
- package/src/functions/entity-extraction/entity-extraction.test.ts +11 -29
- package/src/functions/entity-extraction/entity-extraction.ts +41 -24
- package/src/functions/exa/mock.ts +1 -1
- package/src/functions/github/fetch-prs.ts +3 -2
- package/src/functions/linear/linear.test.ts +18 -43
- package/src/functions/linear/sync-issues.ts +9 -7
- package/src/functions/research/document-create.ts +9 -11
- package/src/functions/research/research-graph.ts +13 -11
- package/src/functions/research/research.conversations.json +1 -1
- package/src/functions/research/research.test.ts +29 -64
- package/src/functions/research/research.ts +15 -23
- package/src/functions/research/types.ts +3 -3
- package/src/functions/tasks/read.ts +6 -6
- package/src/functions/tasks/update.ts +6 -6
- package/src/index.ts +4 -2
- package/src/initiative/Initiative.ts +61 -0
- package/src/initiative/blueprint.ts +60 -0
- package/src/initiative/functions/addArtifact.ts +41 -0
- package/src/initiative/functions/agent.ts +77 -0
- package/src/initiative/functions/getContext.ts +62 -0
- package/src/initiative/functions/index.ts +8 -0
- package/src/initiative/functions/qualifier.ts +98 -0
- package/src/initiative/index.ts +9 -0
- package/src/initiative/initiative.test.ts +584 -0
- package/src/initiative/plan.ts +107 -0
- package/src/initiative/util.ts +137 -0
- package/src/planning/blueprint.ts +14 -0
- package/src/planning/functions/index.ts +5 -0
- package/src/planning/functions/update-tasks.ts +168 -0
- package/src/planning/index.ts +6 -0
- package/src/sync/sync.ts +38 -30
- package/src/testing/index.ts +1 -1
- package/src/{plugins.tsx → testing/plugins.tsx} +14 -13
- package/src/toolkits/AssistantToolkit.conversations.json +1 -1
- package/src/toolkits/AssistantToolkit.test.ts +27 -43
- package/src/toolkits/AssistantToolkit.ts +31 -8
- package/src/toolkits/SystemToolkit.ts +100 -32
- package/src/toolkits/WebToolkit.ts +34 -0
- package/src/toolkits/index.ts +1 -0
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/node-esm/index.mjs +0 -2779
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/types/src/plugins.d.ts +0 -19
- package/dist/types/src/plugins.d.ts.map +0 -1
- package/dist/types/src/testing/data/exa-search-1748337321991.d.ts.map +0 -1
- package/dist/types/src/testing/data/exa-search-1748337331526.d.ts.map +0 -1
- package/dist/types/src/testing/data/exa-search-1748337344119.d.ts.map +0 -1
- package/dist/types/src/testing/data/index.d.ts.map +0 -1
- /package/dist/types/src/{testing → functions/exa}/data/exa-search-1748337321991.d.ts +0 -0
- /package/dist/types/src/{testing → functions/exa}/data/exa-search-1748337331526.d.ts +0 -0
- /package/dist/types/src/{testing → functions/exa}/data/exa-search-1748337344119.d.ts +0 -0
- /package/dist/types/src/{testing → functions/exa}/data/index.d.ts +0 -0
- /package/src/{testing → functions/exa}/data/exa-search-1748337321991.ts +0 -0
- /package/src/{testing → functions/exa}/data/exa-search-1748337331526.ts +0 -0
- /package/src/{testing → functions/exa}/data/exa-search-1748337344119.ts +0 -0
- /package/src/{testing → functions/exa}/data/index.ts +0 -0
|
@@ -6,36 +6,23 @@ import { inspect } from 'node:util';
|
|
|
6
6
|
|
|
7
7
|
import { describe, it } from '@effect/vitest';
|
|
8
8
|
import * as Effect from 'effect/Effect';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
AiConversation,
|
|
15
|
-
type ContextBinding,
|
|
16
|
-
GenerationObserver,
|
|
17
|
-
makeToolExecutionServiceFromFunctions,
|
|
18
|
-
makeToolResolverFromFunctions,
|
|
19
|
-
} from '@dxos/assistant';
|
|
9
|
+
|
|
10
|
+
import { ConsolePrinter } from '@dxos/ai';
|
|
11
|
+
import { MemoizedAiService } from '@dxos/ai/testing';
|
|
12
|
+
import { AiConversation, type ContextBinding, GenerationObserver } from '@dxos/assistant';
|
|
13
|
+
import { AssistantTestLayer } from '@dxos/assistant/testing';
|
|
20
14
|
import { Blueprint } from '@dxos/blueprints';
|
|
21
|
-
import { Filter, Obj, Query, Ref } from '@dxos/echo';
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
|
|
25
|
-
DatabaseService,
|
|
26
|
-
FunctionInvocationService,
|
|
27
|
-
QueueService,
|
|
28
|
-
TracingService,
|
|
29
|
-
} from '@dxos/functions';
|
|
30
|
-
import { FunctionInvocationServiceLayerTest, TestDatabaseLayer } from '@dxos/functions-runtime/testing';
|
|
15
|
+
import { Database, Filter, Obj, Query, Ref } from '@dxos/echo';
|
|
16
|
+
import { acquireReleaseResource } from '@dxos/effect';
|
|
17
|
+
import { TestHelpers } from '@dxos/effect/testing';
|
|
18
|
+
import { FunctionInvocationService, QueueService } from '@dxos/functions';
|
|
31
19
|
import { invariant } from '@dxos/invariant';
|
|
32
20
|
import { ObjectId } from '@dxos/keys';
|
|
33
|
-
import { MarkdownBlueprint
|
|
21
|
+
import { MarkdownBlueprint } from '@dxos/plugin-markdown/blueprints';
|
|
34
22
|
import { Markdown } from '@dxos/plugin-markdown/types';
|
|
35
23
|
import { HasSubject, type Message, Organization } from '@dxos/types';
|
|
36
24
|
|
|
37
25
|
import { ResearchBlueprint } from '../../blueprints';
|
|
38
|
-
import { testToolkit } from '../../blueprints/testing';
|
|
39
26
|
|
|
40
27
|
import { default as createDocument } from './document-create';
|
|
41
28
|
import { default as research } from './research';
|
|
@@ -44,45 +31,23 @@ import { ResearchDataTypes } from './types';
|
|
|
44
31
|
|
|
45
32
|
ObjectId.dangerouslyDisableRandomness();
|
|
46
33
|
|
|
47
|
-
const TestLayer =
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
testToolkit,
|
|
52
|
-
),
|
|
53
|
-
makeToolExecutionServiceFromFunctions(testToolkit, testToolkit.toLayer({}) as any),
|
|
54
|
-
).pipe(
|
|
55
|
-
Layer.provideMerge(
|
|
56
|
-
FunctionInvocationServiceLayerTest({
|
|
57
|
-
functions: [research, createDocument, MarkdownFunction.create, MarkdownFunction.open, MarkdownFunction.update],
|
|
58
|
-
}),
|
|
59
|
-
),
|
|
60
|
-
Layer.provideMerge(
|
|
61
|
-
Layer.mergeAll(
|
|
62
|
-
TestAiService(),
|
|
63
|
-
TestDatabaseLayer({
|
|
64
|
-
spaceKey: 'fixed',
|
|
65
|
-
indexing: { vector: true },
|
|
66
|
-
types: [...ResearchDataTypes, ResearchGraph, Blueprint.Blueprint, Markdown.Document, HasSubject.HasSubject],
|
|
67
|
-
}),
|
|
68
|
-
CredentialsService.configuredLayer([]),
|
|
69
|
-
TracingService.layerNoop,
|
|
70
|
-
),
|
|
71
|
-
),
|
|
72
|
-
);
|
|
34
|
+
const TestLayer = AssistantTestLayer({
|
|
35
|
+
functions: [research, createDocument, ...MarkdownBlueprint.functions],
|
|
36
|
+
types: [...ResearchDataTypes, ResearchGraph, Blueprint.Blueprint, Markdown.Document, HasSubject.HasSubject],
|
|
37
|
+
});
|
|
73
38
|
|
|
74
39
|
describe('Research', () => {
|
|
75
40
|
it.effect(
|
|
76
41
|
'call a function to generate a research report',
|
|
77
42
|
Effect.fnUntraced(
|
|
78
43
|
function* (_) {
|
|
79
|
-
yield*
|
|
44
|
+
yield* Database.add(
|
|
80
45
|
Obj.make(Organization.Organization, {
|
|
81
46
|
name: 'BlueYard',
|
|
82
47
|
website: 'https://blueyard.com',
|
|
83
48
|
}),
|
|
84
49
|
);
|
|
85
|
-
yield*
|
|
50
|
+
yield* Database.flush({ indexes: true });
|
|
86
51
|
const result = yield* FunctionInvocationService.invokeFunction(research, {
|
|
87
52
|
query: 'Founders and portfolio of BlueYard.',
|
|
88
53
|
});
|
|
@@ -90,10 +55,10 @@ describe('Research', () => {
|
|
|
90
55
|
console.log(inspect(result, { depth: null, colors: true }));
|
|
91
56
|
console.log(JSON.stringify(result, null, 2));
|
|
92
57
|
|
|
93
|
-
yield*
|
|
58
|
+
yield* Database.flush({ indexes: true });
|
|
94
59
|
const researchGraph = yield* queryResearchGraph();
|
|
95
60
|
if (researchGraph) {
|
|
96
|
-
const data = yield*
|
|
61
|
+
const data = yield* Database.load(researchGraph.queue).pipe(
|
|
97
62
|
Effect.flatMap((queue) => Effect.promise(() => queue.queryObjects())),
|
|
98
63
|
);
|
|
99
64
|
console.log(inspect(data, { depth: null, colors: true }));
|
|
@@ -109,7 +74,7 @@ describe('Research', () => {
|
|
|
109
74
|
'create and update research report',
|
|
110
75
|
Effect.fnUntraced(
|
|
111
76
|
function* (_) {
|
|
112
|
-
const organization = yield*
|
|
77
|
+
const organization = yield* Database.add(
|
|
113
78
|
Obj.make(Organization.Organization, {
|
|
114
79
|
name: 'BlueYard',
|
|
115
80
|
website: 'https://blueyard.com',
|
|
@@ -117,11 +82,11 @@ describe('Research', () => {
|
|
|
117
82
|
);
|
|
118
83
|
|
|
119
84
|
const queue = yield* QueueService.createQueue<Message.Message | ContextBinding>();
|
|
120
|
-
const conversation = yield* acquireReleaseResource(() => new AiConversation(queue));
|
|
85
|
+
const conversation = yield* acquireReleaseResource(() => new AiConversation({ queue }));
|
|
121
86
|
|
|
122
|
-
yield*
|
|
123
|
-
const researchBlueprint = yield*
|
|
124
|
-
const markdownBlueprint = yield*
|
|
87
|
+
yield* Database.flush({ indexes: true });
|
|
88
|
+
const researchBlueprint = yield* Database.add(Obj.clone(ResearchBlueprint));
|
|
89
|
+
const markdownBlueprint = yield* Database.add(Obj.clone(MarkdownBlueprint.make()));
|
|
125
90
|
yield* Effect.promise(() =>
|
|
126
91
|
conversation.context.bind({
|
|
127
92
|
blueprints: [Ref.make(researchBlueprint), Ref.make(markdownBlueprint)],
|
|
@@ -136,8 +101,8 @@ describe('Research', () => {
|
|
|
136
101
|
prompt: `Create a research summary about ${organization.name}.`,
|
|
137
102
|
});
|
|
138
103
|
{
|
|
139
|
-
const
|
|
140
|
-
Query.select(Filter.
|
|
104
|
+
const docs = yield* Database.runQuery(
|
|
105
|
+
Query.select(Filter.id(organization.id)).targetOf(HasSubject.HasSubject).source(),
|
|
141
106
|
);
|
|
142
107
|
if (docs.length !== 1) {
|
|
143
108
|
throw new Error(`Expected 1 research document; got ${docs.length}: ${docs.map((_) => _.name)}`);
|
|
@@ -147,7 +112,7 @@ describe('Research', () => {
|
|
|
147
112
|
invariant(Obj.instanceOf(Markdown.Document, doc));
|
|
148
113
|
console.log({
|
|
149
114
|
name: doc.name,
|
|
150
|
-
content: yield*
|
|
115
|
+
content: yield* Database.load(doc.content).pipe(Effect.map((_) => _.content)),
|
|
151
116
|
});
|
|
152
117
|
}
|
|
153
118
|
|
|
@@ -156,8 +121,8 @@ describe('Research', () => {
|
|
|
156
121
|
prompt: 'Add a section about their portfolio.',
|
|
157
122
|
});
|
|
158
123
|
{
|
|
159
|
-
const
|
|
160
|
-
Query.select(Filter.
|
|
124
|
+
const docs = yield* Database.runQuery(
|
|
125
|
+
Query.select(Filter.id(organization.id)).targetOf(HasSubject.HasSubject).source(),
|
|
161
126
|
);
|
|
162
127
|
if (docs.length !== 1) {
|
|
163
128
|
throw new Error(`Expected 1 research document; got ${docs.length}: ${docs.map((_) => _.name)}`);
|
|
@@ -167,7 +132,7 @@ describe('Research', () => {
|
|
|
167
132
|
invariant(Obj.instanceOf(Markdown.Document, doc));
|
|
168
133
|
console.log({
|
|
169
134
|
name: doc.name,
|
|
170
|
-
content: yield*
|
|
135
|
+
content: yield* Database.load(doc.content).pipe(Effect.map((_) => _.content)),
|
|
171
136
|
});
|
|
172
137
|
}
|
|
173
138
|
},
|
|
@@ -13,16 +13,11 @@ import * as Schema from 'effect/Schema';
|
|
|
13
13
|
import * as String from 'effect/String';
|
|
14
14
|
|
|
15
15
|
import { AiService, ConsolePrinter } from '@dxos/ai';
|
|
16
|
-
import {
|
|
17
|
-
AiSession,
|
|
18
|
-
GenerationObserver,
|
|
19
|
-
createToolkit,
|
|
20
|
-
makeToolExecutionServiceFromFunctions,
|
|
21
|
-
makeToolResolverFromFunctions,
|
|
22
|
-
} from '@dxos/assistant';
|
|
16
|
+
import { AiSession, GenerationObserver, GenericToolkit, ToolExecutionServices, createToolkit } from '@dxos/assistant';
|
|
23
17
|
import { Template } from '@dxos/blueprints';
|
|
24
|
-
import { type DXN, Obj } from '@dxos/echo';
|
|
25
|
-
import {
|
|
18
|
+
import { type DXN, Entity, Obj } from '@dxos/echo';
|
|
19
|
+
import { Database } from '@dxos/echo';
|
|
20
|
+
import { TracingService, defineFunction } from '@dxos/functions';
|
|
26
21
|
import { FunctionInvocationServiceLayerTestMocked } from '@dxos/functions-runtime/testing';
|
|
27
22
|
import { type Message, Person } from '@dxos/types';
|
|
28
23
|
import { trim } from '@dxos/util';
|
|
@@ -84,7 +79,7 @@ export default defineFunction({
|
|
|
84
79
|
handler: Effect.fnUntraced(
|
|
85
80
|
function* ({ data: { query, instructions, mockSearch = false, entityExtraction = false } }) {
|
|
86
81
|
if (mockSearch) {
|
|
87
|
-
const mockPerson = yield*
|
|
82
|
+
const mockPerson = yield* Database.add(
|
|
88
83
|
Obj.make(Person.Person, {
|
|
89
84
|
preferredName: 'John Doe',
|
|
90
85
|
emails: [{ value: 'john.doe@example.com' }],
|
|
@@ -101,7 +96,7 @@ export default defineFunction({
|
|
|
101
96
|
};
|
|
102
97
|
}
|
|
103
98
|
|
|
104
|
-
yield*
|
|
99
|
+
yield* Database.flush({ indexes: true });
|
|
105
100
|
yield* TracingService.emitStatus({ message: 'Starting research...' });
|
|
106
101
|
|
|
107
102
|
const NativeWebSearch = Toolkit.make(AnthropicTool.WebSearch_20250305({}));
|
|
@@ -122,9 +117,7 @@ export default defineFunction({
|
|
|
122
117
|
) as any;
|
|
123
118
|
}
|
|
124
119
|
|
|
125
|
-
const finishedToolkit = yield* createToolkit({
|
|
126
|
-
toolkit: toolkit as any,
|
|
127
|
-
}).pipe(Effect.provide(handlers));
|
|
120
|
+
const finishedToolkit = yield* createToolkit({ toolkit }).pipe(Effect.provide(handlers));
|
|
128
121
|
|
|
129
122
|
const session = new AiSession();
|
|
130
123
|
const result = yield* session.run({
|
|
@@ -137,8 +130,8 @@ export default defineFunction({
|
|
|
137
130
|
observer: GenerationObserver.fromPrinter(new ConsolePrinter({ tag: 'research' })),
|
|
138
131
|
});
|
|
139
132
|
|
|
140
|
-
const objects = yield* Effect.forEach(objectDXNs, (dxn) =>
|
|
141
|
-
Effect.map(Array.map((obj) =>
|
|
133
|
+
const objects = yield* Effect.forEach(objectDXNs, (dxn) => Database.resolve(dxn)).pipe(
|
|
134
|
+
Effect.map(Array.map((obj) => Entity.toJSON(obj))),
|
|
142
135
|
);
|
|
143
136
|
|
|
144
137
|
return {
|
|
@@ -147,15 +140,14 @@ export default defineFunction({
|
|
|
147
140
|
};
|
|
148
141
|
},
|
|
149
142
|
Effect.provide(
|
|
150
|
-
Layer.mergeAll(
|
|
151
|
-
AiService.model('@anthropic/claude-sonnet-4-0'),
|
|
152
|
-
// TODO(dmaretskyi): Extract.
|
|
153
|
-
makeToolResolverFromFunctions([exaFunction, exaMockFunction], Toolkit.make()),
|
|
154
|
-
makeToolExecutionServiceFromFunctions(Toolkit.make() as any, Layer.empty as any),
|
|
155
|
-
).pipe(
|
|
143
|
+
Layer.mergeAll(AiService.model('@anthropic/claude-sonnet-4-0'), ToolExecutionServices).pipe(
|
|
156
144
|
Layer.provide(
|
|
157
145
|
// TODO(dmaretskyi): This should be provided by environment.
|
|
158
|
-
|
|
146
|
+
|
|
147
|
+
Layer.mergeAll(
|
|
148
|
+
GenericToolkit.providerEmpty,
|
|
149
|
+
FunctionInvocationServiceLayerTestMocked({ functions: [exaFunction, exaMockFunction] }),
|
|
150
|
+
),
|
|
159
151
|
),
|
|
160
152
|
),
|
|
161
153
|
),
|
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
|
|
5
5
|
import { type Type } from '@dxos/echo';
|
|
6
6
|
import { Text } from '@dxos/schema';
|
|
7
|
-
import { Event, HasConnection, HasRelationship, LegacyOrganization, LegacyPerson,
|
|
7
|
+
import { Event, HasConnection, HasRelationship, LegacyOrganization, LegacyPerson, Pipeline, Task } from '@dxos/types';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Data types for research.
|
|
11
11
|
*/
|
|
12
|
-
export const ResearchDataTypes:
|
|
12
|
+
export const ResearchDataTypes: Type.Entity.Any[] = [
|
|
13
13
|
// Objects
|
|
14
14
|
Event.Event,
|
|
15
15
|
LegacyOrganization,
|
|
@@ -20,7 +20,7 @@ export const ResearchDataTypes: (Type.Obj.Any | Type.Relation.Any)[] = [
|
|
|
20
20
|
// TODO(wittjosiah): Until views (e.g., Table) support relations this needs to be expressed via organization ref.
|
|
21
21
|
// Employer.Employer,
|
|
22
22
|
LegacyPerson,
|
|
23
|
-
|
|
23
|
+
Pipeline.Pipeline,
|
|
24
24
|
HasRelationship.HasRelationship,
|
|
25
25
|
HasConnection.HasConnection,
|
|
26
26
|
];
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
import * as Effect from 'effect/Effect';
|
|
6
6
|
import * as Schema from 'effect/Schema';
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { Database, Type } from '@dxos/echo';
|
|
9
|
+
import { defineFunction } from '@dxos/functions';
|
|
10
10
|
import { Markdown } from '@dxos/plugin-markdown/types';
|
|
11
11
|
|
|
12
12
|
export default defineFunction({
|
|
@@ -14,18 +14,18 @@ export default defineFunction({
|
|
|
14
14
|
name: 'Read',
|
|
15
15
|
description: 'Read markdown tasks.',
|
|
16
16
|
inputSchema: Schema.Struct({
|
|
17
|
-
|
|
17
|
+
doc: Type.Ref(Markdown.Document).annotations({
|
|
18
18
|
description: 'The ID of the document to read.',
|
|
19
19
|
}),
|
|
20
20
|
}),
|
|
21
21
|
outputSchema: Schema.Struct({
|
|
22
22
|
content: Schema.String,
|
|
23
23
|
}),
|
|
24
|
-
handler: Effect.fn(function* ({ data: {
|
|
25
|
-
const
|
|
24
|
+
handler: Effect.fn(function* ({ data: { doc } }) {
|
|
25
|
+
const document = yield* Database.load(doc);
|
|
26
26
|
|
|
27
27
|
// Return content with line numbers prefixed.
|
|
28
|
-
const { content } = yield*
|
|
28
|
+
const { content } = yield* Database.load(document.content);
|
|
29
29
|
const lines = content.split('\n');
|
|
30
30
|
const len = String(lines.length).length;
|
|
31
31
|
const numbered = lines.map((line, i) => `${String(i + 1).padStart(len, ' ')}. ${line}`).join('\n');
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
import * as Effect from 'effect/Effect';
|
|
6
6
|
import * as Schema from 'effect/Schema';
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { Database, Type } from '@dxos/echo';
|
|
9
|
+
import { defineFunction } from '@dxos/functions';
|
|
10
10
|
import { Markdown } from '@dxos/plugin-markdown/types';
|
|
11
11
|
|
|
12
12
|
import { MarkdownTasks, type TaskOperation } from './task-list';
|
|
@@ -16,7 +16,7 @@ export default defineFunction({
|
|
|
16
16
|
name: 'Update markdown',
|
|
17
17
|
description: 'Creates and updates tasks in markdown documents.',
|
|
18
18
|
inputSchema: Schema.Struct({
|
|
19
|
-
|
|
19
|
+
doc: Type.Ref(Markdown.Document).annotations({
|
|
20
20
|
description: 'The ID of the document to update.',
|
|
21
21
|
}),
|
|
22
22
|
operations: Schema.optional(
|
|
@@ -33,11 +33,11 @@ export default defineFunction({
|
|
|
33
33
|
description: 'Content with line numbers for agent reference.',
|
|
34
34
|
}),
|
|
35
35
|
}),
|
|
36
|
-
handler: Effect.fn(function* ({ data: {
|
|
37
|
-
const
|
|
36
|
+
handler: Effect.fn(function* ({ data: { doc, operations = [] } }) {
|
|
37
|
+
const document = yield* Database.load(doc);
|
|
38
38
|
|
|
39
39
|
// Create task manager and apply operations if provided.
|
|
40
|
-
const { content } = yield*
|
|
40
|
+
const { content } = yield* Database.load(document.content);
|
|
41
41
|
const taskManager = new MarkdownTasks(content);
|
|
42
42
|
if (operations.length > 0) {
|
|
43
43
|
taskManager.applyOperations(operations as TaskOperation[]);
|
package/src/index.ts
CHANGED
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
export * from './blueprints';
|
|
6
|
+
export * from './chat';
|
|
7
|
+
export * from './crud';
|
|
6
8
|
export * from './functions';
|
|
7
|
-
export * from './
|
|
9
|
+
export * as Initiative from './initiative';
|
|
8
10
|
export * from './sync';
|
|
9
|
-
export * from './crud';
|
|
10
11
|
export * from './toolkits';
|
|
12
|
+
export * as Planning from './planning';
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2026 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
|
+
import { QueueAnnotation, Text } from '@dxos/schema';
|
|
10
|
+
|
|
11
|
+
import * as Chat from '../chat/Chat';
|
|
12
|
+
|
|
13
|
+
import { Plan } from './plan';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Initiative schema definition.
|
|
17
|
+
*/
|
|
18
|
+
export const Initiative = Schema.Struct({
|
|
19
|
+
name: Schema.String,
|
|
20
|
+
|
|
21
|
+
spec: Type.Ref(Text.Text),
|
|
22
|
+
plan: Type.Ref(Plan),
|
|
23
|
+
|
|
24
|
+
artifacts: Schema.Array(
|
|
25
|
+
Schema.Struct({
|
|
26
|
+
// TODO(dmaretskyi): Consider gettings names from the artifact itself using Obj.getLabel.
|
|
27
|
+
name: Schema.String,
|
|
28
|
+
data: Type.Ref(Type.Obj),
|
|
29
|
+
}),
|
|
30
|
+
),
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Incoming queue that the agent processes.
|
|
34
|
+
*/
|
|
35
|
+
// NOTE: Named `queue` to conform to subscribable schema (see QueueAnnotation).
|
|
36
|
+
queue: Schema.optional(Type.Ref(Queue)),
|
|
37
|
+
|
|
38
|
+
// TODO(dmaretskyi): Multiple chats.
|
|
39
|
+
chat: Schema.optional(Type.Ref(Chat.Chat)),
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Objects to subscribe to.
|
|
43
|
+
* References to objects with a a canonical queue property.
|
|
44
|
+
* Schema must have the QueueAnnotation.
|
|
45
|
+
*/
|
|
46
|
+
// TODO(dmaretskyi): Turn into an array of objects when form-data
|
|
47
|
+
subscriptions: Schema.Array(Type.Ref(Type.Obj)),
|
|
48
|
+
|
|
49
|
+
useQualifyingAgent: Schema.optional(Schema.Boolean),
|
|
50
|
+
|
|
51
|
+
newChatOnEveryEvent: Schema.optional(Schema.Boolean),
|
|
52
|
+
|
|
53
|
+
// TODO(dmaretskyi): input queue?
|
|
54
|
+
}).pipe(
|
|
55
|
+
Type.object({
|
|
56
|
+
typename: 'dxos.org/type/Initiative',
|
|
57
|
+
version: '0.1.0',
|
|
58
|
+
}),
|
|
59
|
+
QueueAnnotation.set(true),
|
|
60
|
+
);
|
|
61
|
+
export interface Initiative extends Schema.Schema.Type<typeof Initiative> {}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2026 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Blueprint, Template } from '@dxos/blueprints';
|
|
6
|
+
import { trim } from '@dxos/util';
|
|
7
|
+
|
|
8
|
+
import { addArtifact, agent, getContext, qualifier } from './functions';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Get all initiative functions. This is a function to avoid circular dependency issues.
|
|
12
|
+
*/
|
|
13
|
+
export const getFunctions = () => [getContext, addArtifact, agent, qualifier];
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Creates the Initiative blueprint. This is a function to avoid circular dependency issues.
|
|
17
|
+
*/
|
|
18
|
+
export const makeBlueprint = () =>
|
|
19
|
+
Blueprint.make({
|
|
20
|
+
key: 'dxos.org/blueprint/initiative',
|
|
21
|
+
name: 'Initiative blueprint',
|
|
22
|
+
instructions: Template.make({
|
|
23
|
+
source: trim`
|
|
24
|
+
You work on an initiative. Each initiative has a spec - the goal of the initiative.
|
|
25
|
+
The initiative plan shows the current progress of the initiative.
|
|
26
|
+
Initiative has an number of associated artifacts you can read/write.
|
|
27
|
+
Spec and plan are also artifacts.
|
|
28
|
+
You can edit them if necessary.
|
|
29
|
+
|
|
30
|
+
IMPORTANT: When create a new artifact, always add it to the initiative using the add-artifact function.
|
|
31
|
+
|
|
32
|
+
{{#with initiative}}
|
|
33
|
+
<initiative id="{{id}}" name="{{name}}">
|
|
34
|
+
<spec>
|
|
35
|
+
{{spec}}
|
|
36
|
+
</spec>
|
|
37
|
+
<plan>
|
|
38
|
+
{{plan}}
|
|
39
|
+
</plan>
|
|
40
|
+
|
|
41
|
+
<artifacts>
|
|
42
|
+
{{#each artifacts}}
|
|
43
|
+
<artifact type="{{type}}" dxn="{{dxn}}">
|
|
44
|
+
{{name}}
|
|
45
|
+
</artifact>
|
|
46
|
+
{{/each}}
|
|
47
|
+
</artifacts>
|
|
48
|
+
</initiative>
|
|
49
|
+
{{/with}}
|
|
50
|
+
`,
|
|
51
|
+
inputs: [
|
|
52
|
+
{
|
|
53
|
+
name: 'initiative',
|
|
54
|
+
kind: 'function',
|
|
55
|
+
function: 'dxos.org/function/initiative/get-context',
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
}),
|
|
59
|
+
tools: Blueprint.toolDefinitions({ functions: [addArtifact] }),
|
|
60
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
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, Type } from '@dxos/echo';
|
|
10
|
+
import { defineFunction } from '@dxos/functions';
|
|
11
|
+
|
|
12
|
+
import { getFromChatContext } from '../util';
|
|
13
|
+
|
|
14
|
+
export default defineFunction({
|
|
15
|
+
key: 'dxos.org/function/initiative/add-artifact',
|
|
16
|
+
name: 'Add artifact',
|
|
17
|
+
description: 'Adds a new artifact.',
|
|
18
|
+
inputSchema: Schema.Struct({
|
|
19
|
+
name: Schema.String.annotations({
|
|
20
|
+
description: 'The name of the artifact to add.',
|
|
21
|
+
}),
|
|
22
|
+
artifact: Type.Ref(Type.Obj).annotations({
|
|
23
|
+
description: 'The artifact to add. Do NOT guess or try to generate the ID.',
|
|
24
|
+
}),
|
|
25
|
+
}),
|
|
26
|
+
services: [AiContextService],
|
|
27
|
+
handler: Effect.fnUntraced(function* ({ data }) {
|
|
28
|
+
if (!(yield* Database.load(data.artifact))) {
|
|
29
|
+
throw new Error('Artifact not found.');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const initiative = yield* getFromChatContext;
|
|
33
|
+
|
|
34
|
+
Obj.change(initiative, (initiative) => {
|
|
35
|
+
initiative.artifacts.push({
|
|
36
|
+
name: data.name,
|
|
37
|
+
data: data.artifact,
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
}, AiContextService.fixFunctionHandlerType),
|
|
41
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
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 { AiService } from '@dxos/ai';
|
|
9
|
+
import { AiContextService, AiConversation, type ContextBinding } from '@dxos/assistant';
|
|
10
|
+
import { Database, Obj, Type } from '@dxos/echo';
|
|
11
|
+
import { type Queue } from '@dxos/echo-db';
|
|
12
|
+
import { acquireReleaseResource } from '@dxos/effect';
|
|
13
|
+
import { TriggerEvent, defineFunction } from '@dxos/functions';
|
|
14
|
+
import { invariant } from '@dxos/invariant';
|
|
15
|
+
import { type Message } from '@dxos/types';
|
|
16
|
+
|
|
17
|
+
import * as Initiative from '../Initiative';
|
|
18
|
+
import { resetChatHistory } from '../util';
|
|
19
|
+
|
|
20
|
+
export default defineFunction({
|
|
21
|
+
key: 'dxos.org/function/initiative/agent',
|
|
22
|
+
name: 'Initiative Agent',
|
|
23
|
+
description: 'Agentic worker that drives the initiative autonomously.',
|
|
24
|
+
inputSchema: Schema.Struct({
|
|
25
|
+
initiative: Schema.suspend(() => Type.Ref(Initiative.Initiative)),
|
|
26
|
+
prompt: Schema.optional(Schema.String),
|
|
27
|
+
event: Schema.optional(TriggerEvent.TriggerEvent),
|
|
28
|
+
}),
|
|
29
|
+
outputSchema: Schema.Void,
|
|
30
|
+
services: [AiContextService],
|
|
31
|
+
handler: Effect.fnUntraced(
|
|
32
|
+
function* ({ data }) {
|
|
33
|
+
const initiative = yield* Database.load(data.initiative);
|
|
34
|
+
invariant(Obj.instanceOf(Initiative.Initiative, initiative));
|
|
35
|
+
invariant(initiative.chat, 'Initiative has no chat.');
|
|
36
|
+
|
|
37
|
+
if (initiative.newChatOnEveryEvent) {
|
|
38
|
+
yield* resetChatHistory(initiative);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const chatQueue = yield* initiative.chat.pipe(
|
|
42
|
+
Database.load,
|
|
43
|
+
Effect.flatMap((chat) => Database.load(chat.queue)),
|
|
44
|
+
);
|
|
45
|
+
invariant(chatQueue, 'Initiative chat queue not found.');
|
|
46
|
+
const conversation = yield* acquireReleaseResource(
|
|
47
|
+
() => new AiConversation({ queue: chatQueue as Queue<Message.Message | ContextBinding> }),
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
const iniativesInContext = conversation.context.getObjects().filter(Obj.instanceOf(Initiative.Initiative));
|
|
51
|
+
if (iniativesInContext.length !== 1) {
|
|
52
|
+
throw new Error('There should be exactly one initiative in context. Got: ' + iniativesInContext.length);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (!data.prompt && !data.event) {
|
|
56
|
+
throw new Error('Either prompt or event must be provided.');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
let input = '';
|
|
60
|
+
if (data.prompt) {
|
|
61
|
+
input += `${data.prompt}\n\n`;
|
|
62
|
+
}
|
|
63
|
+
if (data.event) {
|
|
64
|
+
input += `<event>\n${JSON.stringify(data.event, null, 2)}\n</event>\n\n`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
yield* conversation
|
|
68
|
+
.createRequest({
|
|
69
|
+
prompt: input,
|
|
70
|
+
})
|
|
71
|
+
.pipe(Effect.retry({ times: 2 }));
|
|
72
|
+
},
|
|
73
|
+
Effect.scoped,
|
|
74
|
+
Effect.provide(AiService.model('@anthropic/claude-sonnet-4-5')),
|
|
75
|
+
AiContextService.fixFunctionHandlerType,
|
|
76
|
+
) as any,
|
|
77
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
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
|
+
|
|
12
|
+
import { formatPlan } from '../plan';
|
|
13
|
+
import { getFromChatContext } from '../util';
|
|
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
|
+
id: Schema.String,
|
|
22
|
+
name: Schema.String,
|
|
23
|
+
spec: Schema.String,
|
|
24
|
+
plan: Schema.String,
|
|
25
|
+
artifacts: Schema.Array(
|
|
26
|
+
Schema.Struct({
|
|
27
|
+
name: Schema.String,
|
|
28
|
+
type: Schema.optional(Schema.String),
|
|
29
|
+
dxn: Schema.optional(Schema.String),
|
|
30
|
+
}),
|
|
31
|
+
),
|
|
32
|
+
}),
|
|
33
|
+
services: [AiContextService],
|
|
34
|
+
handler: Effect.fnUntraced(function* ({ data: _data }) {
|
|
35
|
+
const initiative = yield* getFromChatContext;
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
id: initiative.id,
|
|
39
|
+
name: initiative.name,
|
|
40
|
+
spec: yield* initiative.spec.pipe(Database.load).pipe(
|
|
41
|
+
Effect.map((_) => _.content),
|
|
42
|
+
Effect.catchTag('ObjectNotFoundError', () => Effect.succeed('No spec found.')),
|
|
43
|
+
),
|
|
44
|
+
plan: yield* initiative.plan?.pipe(Database.load).pipe(
|
|
45
|
+
Effect.map(formatPlan),
|
|
46
|
+
Effect.catchTag('ObjectNotFoundError', () => Effect.succeed('No plan found.')),
|
|
47
|
+
) ?? Effect.succeed('No plan found.'),
|
|
48
|
+
artifacts: yield* Effect.forEach(initiative.artifacts, (artifact) =>
|
|
49
|
+
Effect.gen(function* () {
|
|
50
|
+
return {
|
|
51
|
+
name: artifact.name,
|
|
52
|
+
type: yield* Database.load(artifact.data).pipe(
|
|
53
|
+
Effect.map(Obj.getTypename),
|
|
54
|
+
Effect.catchTag('ObjectNotFoundError', () => Effect.succeed('Artifact not found.')),
|
|
55
|
+
),
|
|
56
|
+
dxn: artifact.data.dxn.toString(),
|
|
57
|
+
};
|
|
58
|
+
}),
|
|
59
|
+
),
|
|
60
|
+
};
|
|
61
|
+
}, AiContextService.fixFunctionHandlerType),
|
|
62
|
+
});
|