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