@dxos/assistant-toolkit 0.16.0 → 0.17.0
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/chunk-AgentOperation.mjs +5 -1
- package/dist/lib/chunk-AgentOperation.mjs.map +1 -1
- package/dist/lib/chunk-AgentOperationHandlerSet.mjs +1 -1
- package/dist/lib/chunk-AgentSkill.mjs +1 -1
- package/dist/lib/chunk-AlarmSkill.mjs +1 -1
- package/dist/lib/chunk-BrowserSkill.mjs +4 -6
- package/dist/lib/chunk-BrowserSkill.mjs.map +1 -1
- package/dist/lib/chunk-ChatContextSkill.mjs +1 -1
- package/dist/lib/chunk-DelegationSkill.mjs +2 -2
- package/dist/lib/chunk-DelegationSkill.mjs.map +1 -1
- package/dist/lib/chunk-DelegationStrategy.mjs +16 -30
- package/dist/lib/chunk-DelegationStrategy.mjs.map +1 -1
- package/dist/lib/chunk-PlanningSkill.mjs +12 -10
- package/dist/lib/chunk-PlanningSkill.mjs.map +1 -1
- package/dist/lib/chunk-SkillManagerSkill.mjs +62 -7
- package/dist/lib/chunk-SkillManagerSkill.mjs.map +1 -1
- package/dist/lib/chunk-SlashCommand.mjs +2 -2
- package/dist/lib/chunk-SlashCommand.mjs.map +1 -1
- package/dist/lib/chunk-add-mcp-connection.mjs +58 -0
- package/dist/lib/chunk-add-mcp-connection.mjs.map +1 -0
- package/dist/lib/chunk-ask-question.mjs.map +1 -1
- package/dist/lib/chunk-catalog.mjs +86 -0
- package/dist/lib/chunk-catalog.mjs.map +1 -0
- package/dist/lib/chunk-context-add.mjs +1 -1
- package/dist/lib/chunk-context-remove.mjs +1 -1
- package/dist/lib/chunk-delegate-task.mjs +2 -2
- package/dist/lib/chunk-delegate-task.mjs.map +1 -1
- package/dist/lib/chunk-delegate-tasks.mjs +2 -8
- package/dist/lib/chunk-delegate-tasks.mjs.map +1 -1
- package/dist/lib/chunk-enable-skills.mjs +1 -1
- package/dist/lib/chunk-get-context.mjs +1 -1
- package/dist/lib/chunk-get-current-date.mjs +1 -1
- package/dist/lib/chunk-mcp-connections.mjs +26 -0
- package/dist/lib/chunk-mcp-connections.mjs.map +1 -0
- package/dist/lib/chunk-operations.mjs +2 -2
- package/dist/lib/chunk-operations.mjs.map +1 -1
- package/dist/lib/chunk-operations2.mjs +144 -9
- package/dist/lib/chunk-operations2.mjs.map +1 -1
- package/dist/lib/chunk-operations3.mjs +6 -5
- package/dist/lib/chunk-operations3.mjs.map +1 -1
- package/dist/lib/chunk-operations4.mjs +30 -55
- package/dist/lib/chunk-operations4.mjs.map +1 -1
- package/dist/lib/chunk-operations5.mjs +28 -27
- package/dist/lib/chunk-operations5.mjs.map +1 -1
- package/dist/lib/chunk-operations6.mjs +64 -29
- package/dist/lib/chunk-operations6.mjs.map +1 -1
- package/dist/lib/chunk-operations7.mjs +4 -79
- package/dist/lib/chunk-operations7.mjs.map +1 -1
- package/dist/lib/chunk-plan-reminder.mjs +7 -12
- package/dist/lib/chunk-plan-reminder.mjs.map +1 -1
- package/dist/lib/chunk-query-mcp-connections.mjs +16 -0
- package/dist/lib/chunk-query-mcp-connections.mjs.map +1 -0
- package/dist/lib/chunk-query-operations.mjs +23 -0
- package/dist/lib/chunk-query-operations.mjs.map +1 -0
- package/dist/lib/chunk-query-skills.mjs +23 -3
- package/dist/lib/chunk-query-skills.mjs.map +1 -1
- package/dist/lib/chunk-query-types.mjs +24 -0
- package/dist/lib/chunk-query-types.mjs.map +1 -0
- package/dist/lib/chunk-relay.mjs +1 -1
- package/dist/lib/chunk-run-instructions.mjs +14 -10
- package/dist/lib/chunk-run-instructions.mjs.map +1 -1
- package/dist/lib/chunk-set-alarm.mjs +1 -1
- package/dist/lib/chunk-set-mcp-connection.mjs +18 -0
- package/dist/lib/chunk-set-mcp-connection.mjs.map +1 -0
- package/dist/lib/chunk-sync-automation.mjs +1 -1
- package/dist/lib/chunk-update-tasks.mjs +20 -3
- package/dist/lib/chunk-update-tasks.mjs.map +1 -1
- package/dist/lib/index.mjs +1 -3
- package/dist/lib/ns/AgentOperationHandlerSet.mjs +1 -1
- package/dist/lib/ns/AgentSkill.mjs +1 -1
- package/dist/lib/ns/AlarmSkill.mjs +1 -1
- package/dist/lib/ns/ChatContextSkill.mjs +1 -1
- package/dist/lib/ns/PlanningSkill.mjs +2 -2
- package/dist/lib/ns/SkillManagerSkill.mjs +3 -3
- package/dist/lib/testing.mjs +7 -10
- package/dist/lib/testing.mjs.map +1 -1
- package/dist/types/src/commands.d.ts +10 -0
- package/dist/types/src/commands.d.ts.map +1 -1
- package/dist/types/src/operations/run-instructions.d.ts.map +1 -1
- package/dist/types/src/skills/browser/BrowserSkill.d.ts.map +1 -1
- package/dist/types/src/skills/delegation/operations/delegate-task.d.ts +1 -1
- package/dist/types/src/skills/delegation/operations/delegate-tasks.d.ts +0 -6
- package/dist/types/src/skills/delegation/operations/delegate-tasks.d.ts.map +1 -1
- package/dist/types/src/skills/index.d.ts +0 -1
- package/dist/types/src/skills/index.d.ts.map +1 -1
- package/dist/types/src/skills/planning/PlanningSkill.d.ts +3 -0
- package/dist/types/src/skills/planning/PlanningSkill.d.ts.map +1 -1
- package/dist/types/src/skills/planning/operations/definitions.d.ts +3 -1
- package/dist/types/src/skills/planning/operations/definitions.d.ts.map +1 -1
- package/dist/types/src/skills/planning/operations/plan-reminder.d.ts +6 -5
- package/dist/types/src/skills/planning/operations/plan-reminder.d.ts.map +1 -1
- package/dist/types/src/skills/planning/operations/update-tasks.d.ts +1 -1
- package/dist/types/src/skills/planning/operations/update-tasks.d.ts.map +1 -1
- package/dist/types/src/skills/skill-manager/SkillManagerSkill.d.ts +7 -0
- package/dist/types/src/skills/skill-manager/SkillManagerSkill.d.ts.map +1 -1
- package/dist/types/src/skills/skill-manager/lookup.test.d.ts +2 -0
- package/dist/types/src/skills/skill-manager/lookup.test.d.ts.map +1 -0
- package/dist/types/src/skills/skill-manager/operations/add-mcp-connection.d.ts +19 -0
- package/dist/types/src/skills/skill-manager/operations/add-mcp-connection.d.ts.map +1 -0
- package/dist/types/src/skills/skill-manager/operations/catalog.d.ts +36 -0
- package/dist/types/src/skills/skill-manager/operations/catalog.d.ts.map +1 -0
- package/dist/types/src/skills/skill-manager/operations/definitions.d.ts +116 -1
- package/dist/types/src/skills/skill-manager/operations/definitions.d.ts.map +1 -1
- package/dist/types/src/skills/skill-manager/operations/index.d.ts.map +1 -1
- package/dist/types/src/skills/skill-manager/operations/mcp-connections.d.ts +15 -0
- package/dist/types/src/skills/skill-manager/operations/mcp-connections.d.ts.map +1 -0
- package/dist/types/src/skills/skill-manager/operations/query-mcp-connections.d.ts +11 -0
- package/dist/types/src/skills/skill-manager/operations/query-mcp-connections.d.ts.map +1 -0
- package/dist/types/src/skills/skill-manager/operations/query-operations.d.ts +17 -0
- package/dist/types/src/skills/skill-manager/operations/query-operations.d.ts.map +1 -0
- package/dist/types/src/skills/skill-manager/operations/query-skills.d.ts +20 -2
- package/dist/types/src/skills/skill-manager/operations/query-skills.d.ts.map +1 -1
- package/dist/types/src/skills/skill-manager/operations/query-types.d.ts +13 -0
- package/dist/types/src/skills/skill-manager/operations/query-types.d.ts.map +1 -0
- package/dist/types/src/skills/skill-manager/operations/set-mcp-connection.d.ts +14 -0
- package/dist/types/src/skills/skill-manager/operations/set-mcp-connection.d.ts.map +1 -0
- package/dist/types/src/supervisor/delegation-strategy.d.ts +2 -7
- package/dist/types/src/supervisor/delegation-strategy.d.ts.map +1 -1
- package/dist/types/src/testing/operations.d.ts.map +1 -1
- package/dist/types/src/types/AgentOperation.d.ts +2 -1
- package/dist/types/src/types/AgentOperation.d.ts.map +1 -1
- package/dist/types/src/types/index.d.ts +0 -1
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +32 -40
- package/src/commands.test.ts +4 -0
- package/src/commands.ts +12 -2
- package/src/operations/run-instructions.test.ts +12 -6
- package/src/operations/run-instructions.ts +12 -2
- package/src/skills/browser/BrowserSkill.ts +3 -8
- package/src/skills/chat-context/operations/context-add.test.ts +6 -4
- package/src/skills/chat-context/operations/context-remove.test.ts +6 -4
- package/src/skills/delegation/DelegationSkill.ts +2 -2
- package/src/skills/delegation/operations/definitions.ts +2 -2
- package/src/skills/delegation/operations/delegate-task.test.ts +1 -2
- package/src/skills/delegation/operations/delegate-task.ts +2 -2
- package/src/skills/delegation/operations/delegate-tasks.ts +2 -8
- package/src/skills/index.ts +0 -1
- package/src/skills/planning/PlanningSkill.ts +8 -12
- package/src/skills/planning/operations/definitions.ts +5 -4
- package/src/skills/planning/operations/plan-reminder.test.ts +9 -15
- package/src/skills/planning/operations/plan-reminder.ts +7 -13
- package/src/skills/planning/operations/update-tasks.md +7 -5
- package/src/skills/planning/operations/update-tasks.model.test.ts +2 -2
- package/src/skills/planning/operations/update-tasks.test.ts +110 -10
- package/src/skills/planning/operations/update-tasks.ts +22 -10
- package/src/skills/planning/skill.test.ts +9 -7
- package/src/skills/skill-manager/SkillManagerSkill.ts +71 -5
- package/src/skills/skill-manager/lookup.test.ts +308 -0
- package/src/skills/skill-manager/operations/add-mcp-connection.ts +83 -0
- package/src/skills/skill-manager/operations/catalog.ts +140 -0
- package/src/skills/skill-manager/operations/definitions.ts +168 -6
- package/src/skills/skill-manager/operations/index.ts +14 -1
- package/src/skills/skill-manager/operations/mcp-connections.ts +29 -0
- package/src/skills/skill-manager/operations/query-mcp-connections.ts +22 -0
- package/src/skills/skill-manager/operations/query-operations.ts +50 -0
- package/src/skills/skill-manager/operations/query-skills.ts +43 -3
- package/src/skills/skill-manager/operations/query-types.ts +32 -0
- package/src/skills/skill-manager/operations/set-mcp-connection.ts +28 -0
- package/src/skills/skill-manager/skill.test.ts +172 -9
- package/src/supervisor/delegation-strategy.test.ts +55 -4
- package/src/supervisor/delegation-strategy.ts +13 -28
- package/src/testing/operations.ts +2 -6
- package/src/types/AgentOperation.ts +6 -1
- package/src/types/index.ts +0 -1
- package/dist/lib/Memory.mjs +0 -1
- package/dist/lib/chunk-Memory.mjs +0 -19
- package/dist/lib/chunk-Memory.mjs.map +0 -1
- package/dist/lib/chunk-MemorySkill.mjs +0 -39
- package/dist/lib/chunk-MemorySkill.mjs.map +0 -1
- package/dist/lib/chunk-delete.mjs +0 -14
- package/dist/lib/chunk-delete.mjs.map +0 -1
- package/dist/lib/chunk-operations8.mjs +0 -9
- package/dist/lib/chunk-operations8.mjs.map +0 -1
- package/dist/lib/chunk-query.mjs +0 -18
- package/dist/lib/chunk-query.mjs.map +0 -1
- package/dist/lib/chunk-save.mjs +0 -17
- package/dist/lib/chunk-save.mjs.map +0 -1
- package/dist/lib/ns/MemorySkill.mjs +0 -3
- package/dist/types/src/skills/memory/MemorySkill.d.ts +0 -6
- package/dist/types/src/skills/memory/MemorySkill.d.ts.map +0 -1
- package/dist/types/src/skills/memory/index.d.ts +0 -2
- package/dist/types/src/skills/memory/index.d.ts.map +0 -1
- package/dist/types/src/skills/memory/operations/definitions.d.ts +0 -15
- package/dist/types/src/skills/memory/operations/definitions.d.ts.map +0 -1
- package/dist/types/src/skills/memory/operations/delete.d.ts +0 -7
- package/dist/types/src/skills/memory/operations/delete.d.ts.map +0 -1
- package/dist/types/src/skills/memory/operations/delete.test.d.ts +0 -2
- package/dist/types/src/skills/memory/operations/delete.test.d.ts.map +0 -1
- package/dist/types/src/skills/memory/operations/index.d.ts +0 -4
- package/dist/types/src/skills/memory/operations/index.d.ts.map +0 -1
- package/dist/types/src/skills/memory/operations/query.d.ts +0 -8
- package/dist/types/src/skills/memory/operations/query.d.ts.map +0 -1
- package/dist/types/src/skills/memory/operations/query.test.d.ts +0 -2
- package/dist/types/src/skills/memory/operations/query.test.d.ts.map +0 -1
- package/dist/types/src/skills/memory/operations/save.d.ts +0 -8
- package/dist/types/src/skills/memory/operations/save.d.ts.map +0 -1
- package/dist/types/src/skills/memory/operations/save.test.d.ts +0 -2
- package/dist/types/src/skills/memory/operations/save.test.d.ts.map +0 -1
- package/dist/types/src/skills/memory/skill.test.d.ts +0 -2
- package/dist/types/src/skills/memory/skill.test.d.ts.map +0 -1
- package/dist/types/src/types/Memory.d.ts +0 -12
- package/dist/types/src/types/Memory.d.ts.map +0 -1
- package/src/skills/memory/MemorySkill.ts +0 -39
- package/src/skills/memory/index.ts +0 -5
- package/src/skills/memory/operations/definitions.ts +0 -72
- package/src/skills/memory/operations/delete.test.ts +0 -37
- package/src/skills/memory/operations/delete.ts +0 -20
- package/src/skills/memory/operations/index.ts +0 -16
- package/src/skills/memory/operations/query.test.ts +0 -76
- package/src/skills/memory/operations/query.ts +0 -32
- package/src/skills/memory/operations/save.test.ts +0 -43
- package/src/skills/memory/operations/save.ts +0 -20
- package/src/skills/memory/skill.test.ts +0 -147
- package/src/types/Memory.ts +0 -22
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2026 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { describe, expect, it } from '@effect/vitest';
|
|
6
|
+
import * as Context from 'effect/Context';
|
|
7
|
+
import * as Effect from 'effect/Effect';
|
|
8
|
+
import * as Layer from 'effect/Layer';
|
|
9
|
+
import * as Schema from 'effect/Schema';
|
|
10
|
+
|
|
11
|
+
import { AssistantTestLayer } from '@dxos/agent-runtime/testing';
|
|
12
|
+
import { AiContext, Harness } from '@dxos/assistant';
|
|
13
|
+
import * as Operation from '@dxos/compute/Operation';
|
|
14
|
+
import * as OperationHandlerSet from '@dxos/compute/OperationHandlerSet';
|
|
15
|
+
import * as Skill from '@dxos/compute/Skill';
|
|
16
|
+
import * as Template from '@dxos/compute/Template';
|
|
17
|
+
import { Database, Feed, Obj, Ref, Type } from '@dxos/echo';
|
|
18
|
+
import * as EffectEx from '@dxos/effect/EffectEx';
|
|
19
|
+
import { TestHelpers } from '@dxos/effect/testing';
|
|
20
|
+
import { DXN, EntityId, type URI } from '@dxos/keys';
|
|
21
|
+
|
|
22
|
+
import { EnableSkills, QueryOperations, QuerySkills, QueryTypes } from './operations/definitions.ts';
|
|
23
|
+
import { SkillManagerHandlers } from './operations/index.ts';
|
|
24
|
+
import * as SkillManagerSkill from './SkillManagerSkill.ts';
|
|
25
|
+
|
|
26
|
+
EntityId.dangerouslyDisableRandomness();
|
|
27
|
+
|
|
28
|
+
class Ticket extends Type.makeObject<Ticket>(DXN.make('com.example.type.ticket', '0.1.0'))(
|
|
29
|
+
Schema.Struct({ title: Schema.String, priority: Schema.optional(Schema.Number) }),
|
|
30
|
+
) {}
|
|
31
|
+
|
|
32
|
+
/** A field with five tagged variants, which a list of every type names by its tags alone. */
|
|
33
|
+
class Note extends Type.makeObject<Note>(DXN.make('com.example.type.note', '0.1.0'))(
|
|
34
|
+
Schema.Struct({
|
|
35
|
+
block: Schema.Union(['a', 'b', 'c', 'd', 'e'].map((tag) => Schema.TaggedStruct(tag, { text: Schema.String }))),
|
|
36
|
+
}),
|
|
37
|
+
) {}
|
|
38
|
+
|
|
39
|
+
const Score = Operation.make({
|
|
40
|
+
meta: {
|
|
41
|
+
key: DXN.make('com.example.operation.score'),
|
|
42
|
+
name: 'Score',
|
|
43
|
+
description: 'Scores a title for urgency. Returns its length.',
|
|
44
|
+
},
|
|
45
|
+
input: Schema.Struct({ title: Schema.String, ticket: Schema.optional(Ref.Ref(Ticket)) }),
|
|
46
|
+
output: Schema.Number,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const AddNote = Operation.make({
|
|
50
|
+
meta: {
|
|
51
|
+
key: DXN.make('com.example.operation.addNote'),
|
|
52
|
+
name: 'Add note',
|
|
53
|
+
description: 'Adds a note to the notebook.',
|
|
54
|
+
},
|
|
55
|
+
input: Schema.Struct({ text: Schema.String }),
|
|
56
|
+
output: Schema.String,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const Archive = Operation.make({
|
|
60
|
+
meta: { key: DXN.make('com.example.operation.archive'), name: 'Archive', description: 'Archives everything.' },
|
|
61
|
+
input: Schema.Struct({}),
|
|
62
|
+
output: Schema.Void,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const handlers = OperationHandlerSet.make(
|
|
66
|
+
Score.pipe(Operation.withHandler(({ title }) => Effect.succeed(title.length))),
|
|
67
|
+
AddNote.pipe(Operation.withHandler(() => Effect.succeed('noted'))),
|
|
68
|
+
Archive.pipe(Operation.withHandler(() => Effect.void)),
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
/** Enabled in the conversation below. */
|
|
72
|
+
const ScoreSkill = Skill.make({
|
|
73
|
+
key: 'com.example.skill.score',
|
|
74
|
+
name: 'Scoring',
|
|
75
|
+
description: 'Scores titles.',
|
|
76
|
+
instructions: Template.make({ source: 'Score titles before ranking them.' }),
|
|
77
|
+
tools: Skill.toolDefinitions({ operations: [Score] }),
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
/** Not enabled, but an agent may enable it. */
|
|
81
|
+
const NotesSkill = Skill.make({
|
|
82
|
+
key: 'com.example.skill.notes',
|
|
83
|
+
name: 'Notes',
|
|
84
|
+
description: 'Keeps a notebook.',
|
|
85
|
+
instructions: Template.make({ source: 'Write notes in lower case.' }),
|
|
86
|
+
tools: Skill.toolDefinitions({ operations: [AddNote] }),
|
|
87
|
+
agentCanEnable: true,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
/** Neither enabled nor enableable. */
|
|
91
|
+
const HiddenSkill = Skill.make({
|
|
92
|
+
key: 'com.example.skill.hidden',
|
|
93
|
+
name: 'Hidden',
|
|
94
|
+
instructions: Template.make({ source: 'Never shown.' }),
|
|
95
|
+
tools: Skill.toolDefinitions({ operations: [Archive] }),
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
/** A skill whose template cannot render: an operation input that names no operation is a defect. */
|
|
99
|
+
const BrokenSkill = Skill.make({
|
|
100
|
+
key: 'com.example.skill.broken',
|
|
101
|
+
name: 'Broken',
|
|
102
|
+
instructions: Template.make({ source: '{{value}}', inputs: [{ name: 'value', kind: 'operation' }] }),
|
|
103
|
+
agentCanEnable: true,
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const TestLayer = AssistantTestLayer({
|
|
107
|
+
operationHandlers: [SkillManagerHandlers, handlers],
|
|
108
|
+
types: [Ticket, Note, Feed.Feed, Skill.Skill],
|
|
109
|
+
skills: [ScoreSkill, NotesSkill, HiddenSkill, BrokenSkill],
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
class TestConversation extends Context.Service<TestConversation, { conversation: URI.URI }>()(
|
|
113
|
+
'@dxos/assistant-toolkit/LookupTestConversation',
|
|
114
|
+
) {}
|
|
115
|
+
|
|
116
|
+
/** A conversation with Scoring enabled, as `enable-skills` would leave it. */
|
|
117
|
+
const ConversationLayer = Layer.unwrap(
|
|
118
|
+
Effect.gen(function* () {
|
|
119
|
+
const feed = yield* Database.add(Feed.make());
|
|
120
|
+
const runtime = yield* Effect.context<Database.Service>();
|
|
121
|
+
const binder = yield* EffectEx.acquireReleaseResource(() => new AiContext.Binder({ feed, runtime }));
|
|
122
|
+
const scoring = yield* Skill.upsert('com.example.skill.score');
|
|
123
|
+
yield* Effect.promise(() => binder.bind({ skills: [Ref.make(scoring)] }));
|
|
124
|
+
return Layer.mergeAll(
|
|
125
|
+
Layer.succeed(TestConversation, { conversation: Obj.getURI(feed) }),
|
|
126
|
+
Layer.succeed(Harness.HarnessService, Harness.fromBinder({ feed, runtime, binder })),
|
|
127
|
+
);
|
|
128
|
+
}),
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
const provideTestLayers = Effect.provide(ConversationLayer.pipe(Layer.provideMerge(TestLayer)));
|
|
132
|
+
|
|
133
|
+
/** Keys as the registry may spell them, with or without `dxn:`. */
|
|
134
|
+
const bare = (key: string) => key.replace(/^dxn:/, '');
|
|
135
|
+
|
|
136
|
+
describe('Skill Manager lookups', () => {
|
|
137
|
+
it.effect(
|
|
138
|
+
'query-skills lists every skill, saying which are enabled here and which an agent may enable',
|
|
139
|
+
Effect.fnUntraced(
|
|
140
|
+
function* (_) {
|
|
141
|
+
const { conversation } = yield* TestConversation;
|
|
142
|
+
const rows = yield* Operation.invoke(QuerySkills, {}, { conversation });
|
|
143
|
+
expect(rows.map(({ key, enabled, agentCanEnable }) => ({ key, enabled, agentCanEnable }))).toEqual([
|
|
144
|
+
{ key: 'com.example.skill.broken', enabled: false, agentCanEnable: true },
|
|
145
|
+
{ key: 'com.example.skill.hidden', enabled: false, agentCanEnable: false },
|
|
146
|
+
{ key: 'com.example.skill.notes', enabled: false, agentCanEnable: true },
|
|
147
|
+
{ key: 'com.example.skill.score', enabled: true, agentCanEnable: false },
|
|
148
|
+
]);
|
|
149
|
+
expect(rows.every((row) => row.instructions === undefined && row.operations === undefined)).toBe(true);
|
|
150
|
+
},
|
|
151
|
+
provideTestLayers,
|
|
152
|
+
TestHelpers.provideTestContext,
|
|
153
|
+
),
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
it.effect(
|
|
157
|
+
"query-skills by key gives the skill's instructions and operations",
|
|
158
|
+
Effect.fnUntraced(
|
|
159
|
+
function* (_) {
|
|
160
|
+
const { conversation } = yield* TestConversation;
|
|
161
|
+
const [notes] = yield* Operation.invoke(QuerySkills, { keys: ['com.example.skill.notes'] }, { conversation });
|
|
162
|
+
expect(notes.instructions).toEqual('Write notes in lower case.');
|
|
163
|
+
expect(notes.operations).toEqual([
|
|
164
|
+
expect.objectContaining({
|
|
165
|
+
tool: Operation.toolName(AddNote),
|
|
166
|
+
name: 'Add note',
|
|
167
|
+
description: 'Adds a note to the notebook.',
|
|
168
|
+
skill: 'com.example.skill.notes',
|
|
169
|
+
enabled: false,
|
|
170
|
+
}),
|
|
171
|
+
]);
|
|
172
|
+
expect(bare(notes.operations?.[0].key ?? '')).toEqual('com.example.operation.addNote');
|
|
173
|
+
},
|
|
174
|
+
provideTestLayers,
|
|
175
|
+
TestHelpers.provideTestContext,
|
|
176
|
+
),
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
it.effect(
|
|
180
|
+
'query-operations searches the skills the agent can use, never a hidden one',
|
|
181
|
+
Effect.fnUntraced(
|
|
182
|
+
function* (_) {
|
|
183
|
+
const { conversation } = yield* TestConversation;
|
|
184
|
+
const query = (input: { query?: string; skill?: string }) =>
|
|
185
|
+
Operation.invoke(QueryOperations, input, { conversation }).pipe(
|
|
186
|
+
Effect.map((rows) => rows.map(({ key, skill, enabled }) => ({ key: bare(key), skill, enabled }))),
|
|
187
|
+
);
|
|
188
|
+
expect(yield* query({ query: 'urgency' })).toEqual([
|
|
189
|
+
{ key: 'com.example.operation.score', skill: 'com.example.skill.score', enabled: true },
|
|
190
|
+
]);
|
|
191
|
+
expect(yield* query({ query: 'notebook' })).toEqual([
|
|
192
|
+
{ key: 'com.example.operation.addNote', skill: 'com.example.skill.notes', enabled: false },
|
|
193
|
+
]);
|
|
194
|
+
expect(yield* query({ query: 'archive' })).toEqual([]);
|
|
195
|
+
expect(yield* query({ skill: 'com.example.skill.notes' })).toEqual(yield* query({ query: 'notebook' }));
|
|
196
|
+
|
|
197
|
+
// A list cuts a description to its first sentence; a lookup by key gives it whole.
|
|
198
|
+
const [listed] = yield* Operation.invoke(QueryOperations, { query: 'urgency' }, { conversation });
|
|
199
|
+
expect(listed.description).toEqual('Scores a title for urgency.');
|
|
200
|
+
expect(listed.input).toBeUndefined();
|
|
201
|
+
},
|
|
202
|
+
provideTestLayers,
|
|
203
|
+
TestHelpers.provideTestContext,
|
|
204
|
+
),
|
|
205
|
+
);
|
|
206
|
+
|
|
207
|
+
it.effect(
|
|
208
|
+
"query-operations by key gives the operation's input, refs as Ref<typename>",
|
|
209
|
+
Effect.fnUntraced(
|
|
210
|
+
function* (_) {
|
|
211
|
+
const { conversation } = yield* TestConversation;
|
|
212
|
+
const [score] = yield* Operation.invoke(
|
|
213
|
+
QueryOperations,
|
|
214
|
+
{ keys: ['com.example.operation.score'] },
|
|
215
|
+
{ conversation },
|
|
216
|
+
);
|
|
217
|
+
expect(score.description).toEqual('Scores a title for urgency. Returns its length.');
|
|
218
|
+
expect(score.input).toEqual('{ title: string, ticket?: Ref<com.example.type.ticket> }');
|
|
219
|
+
},
|
|
220
|
+
provideTestLayers,
|
|
221
|
+
TestHelpers.provideTestContext,
|
|
222
|
+
),
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
it.effect(
|
|
226
|
+
'query-types searches the registered types and gives their fields on lookup',
|
|
227
|
+
Effect.fnUntraced(
|
|
228
|
+
function* (_) {
|
|
229
|
+
const { conversation } = yield* TestConversation;
|
|
230
|
+
expect(yield* Operation.invoke(QueryTypes, { query: 'ticket' }, { conversation })).toEqual([
|
|
231
|
+
{
|
|
232
|
+
typename: 'com.example.type.ticket',
|
|
233
|
+
dxn: String(DXN.make('com.example.type.ticket', '0.1.0')),
|
|
234
|
+
kind: 'object',
|
|
235
|
+
},
|
|
236
|
+
]);
|
|
237
|
+
const [ticket] = yield* Operation.invoke(
|
|
238
|
+
QueryTypes,
|
|
239
|
+
{ typenames: ['com.example.type.ticket'] },
|
|
240
|
+
{ conversation },
|
|
241
|
+
);
|
|
242
|
+
expect(ticket.fields).toEqual('title: string, priority?: number');
|
|
243
|
+
},
|
|
244
|
+
provideTestLayers,
|
|
245
|
+
TestHelpers.provideTestContext,
|
|
246
|
+
),
|
|
247
|
+
);
|
|
248
|
+
|
|
249
|
+
it.effect(
|
|
250
|
+
'the tool-calling instructions list every skill and its flags; the code-mode ones list none and give no MCP',
|
|
251
|
+
Effect.fnUntraced(
|
|
252
|
+
function* (_) {
|
|
253
|
+
const { conversation } = yield* TestConversation;
|
|
254
|
+
const render = (skill: Skill.Skill) =>
|
|
255
|
+
Template.processTemplate(skill.instructions).pipe(
|
|
256
|
+
Effect.provide(Operation.withInvocationOptions({ conversation })),
|
|
257
|
+
);
|
|
258
|
+
const listing = yield* render(SkillManagerSkill.make());
|
|
259
|
+
expect(listing).toContain('- com.example.skill.score "Scoring" -- Scores titles. [enabled]');
|
|
260
|
+
expect(listing).toContain('- com.example.skill.notes "Notes" -- Keeps a notebook. [agent-can-enable]');
|
|
261
|
+
|
|
262
|
+
const codeMode = yield* render(SkillManagerSkill.makeForCodeMode());
|
|
263
|
+
expect(codeMode).toContain('The skills enabled in this conversation are stated in this prompt');
|
|
264
|
+
expect(codeMode).not.toContain('com.example.skill');
|
|
265
|
+
// The lookups only: an MCP connection is a bound Skill Manager's to give, not every conversation's.
|
|
266
|
+
expect(SkillManagerSkill.makeForCodeMode().tools).toEqual(
|
|
267
|
+
Skill.toolDefinitions({ operations: [QuerySkills, EnableSkills, QueryOperations, QueryTypes] }),
|
|
268
|
+
);
|
|
269
|
+
},
|
|
270
|
+
provideTestLayers,
|
|
271
|
+
TestHelpers.provideTestContext,
|
|
272
|
+
),
|
|
273
|
+
);
|
|
274
|
+
|
|
275
|
+
it.effect(
|
|
276
|
+
'query-skills by key still returns the other skills when one template cannot render',
|
|
277
|
+
Effect.fnUntraced(
|
|
278
|
+
function* (_) {
|
|
279
|
+
const { conversation } = yield* TestConversation;
|
|
280
|
+
const rows = yield* Operation.invoke(
|
|
281
|
+
QuerySkills,
|
|
282
|
+
{ keys: ['com.example.skill.broken', 'com.example.skill.notes'] },
|
|
283
|
+
{ conversation },
|
|
284
|
+
);
|
|
285
|
+
expect(rows.map(({ key, instructions }) => ({ key, instructions }))).toEqual([
|
|
286
|
+
{ key: 'com.example.skill.broken', instructions: undefined },
|
|
287
|
+
{ key: 'com.example.skill.notes', instructions: 'Write notes in lower case.' },
|
|
288
|
+
]);
|
|
289
|
+
},
|
|
290
|
+
provideTestLayers,
|
|
291
|
+
TestHelpers.provideTestContext,
|
|
292
|
+
),
|
|
293
|
+
);
|
|
294
|
+
|
|
295
|
+
it.effect(
|
|
296
|
+
'query-types by typename spells out every variant of a union, which a list names by its tags',
|
|
297
|
+
Effect.fnUntraced(
|
|
298
|
+
function* (_) {
|
|
299
|
+
const { conversation } = yield* TestConversation;
|
|
300
|
+
const [note] = yield* Operation.invoke(QueryTypes, { typenames: ['com.example.type.note'] }, { conversation });
|
|
301
|
+
expect(note.fields).toContain('{ _tag: "e", text: string }');
|
|
302
|
+
expect(note.fields).not.toContain('…');
|
|
303
|
+
},
|
|
304
|
+
provideTestLayers,
|
|
305
|
+
TestHelpers.provideTestContext,
|
|
306
|
+
),
|
|
307
|
+
);
|
|
308
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2026 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
6
|
+
import * as Option from 'effect/Option';
|
|
7
|
+
|
|
8
|
+
import { AiContext, Harness } from '@dxos/assistant';
|
|
9
|
+
import * as Operation from '@dxos/compute/Operation';
|
|
10
|
+
import { Database, Filter, Obj, Ref } from '@dxos/echo';
|
|
11
|
+
import { AccessToken, Connection } from '@dxos/link';
|
|
12
|
+
import { McpToolkit } from '@dxos/mcp-client';
|
|
13
|
+
|
|
14
|
+
import { AddMcpConnection } from './definitions.ts';
|
|
15
|
+
import { describe } from './mcp-connections.ts';
|
|
16
|
+
|
|
17
|
+
/** Matches the Custom MCP Server connector, so the connection lists and behaves as one the user added. */
|
|
18
|
+
const MCP_CONNECTOR_ID = 'mcp';
|
|
19
|
+
|
|
20
|
+
export default AddMcpConnection.pipe(
|
|
21
|
+
Operation.withHandler(
|
|
22
|
+
Effect.fnUntraced(function* ({ url, name, protocol = 'http', key }) {
|
|
23
|
+
const endpoint: Connection.McpEndpoint = { url: url.trim(), protocol };
|
|
24
|
+
if (!URL.canParse(endpoint.url)) {
|
|
25
|
+
return yield* Effect.die(new Error(`Not a URL: ${url}`));
|
|
26
|
+
}
|
|
27
|
+
const source = new URL(endpoint.url).host;
|
|
28
|
+
// A second connection to a server the space has would offer each of its tools twice, under two
|
|
29
|
+
// names; the existing one is updated instead.
|
|
30
|
+
const existing = (yield* Database.query(Filter.type(Connection.Connection)).run).find(
|
|
31
|
+
(connection) => connection.connectorId === MCP_CONNECTOR_ID && connection.mcp?.url === endpoint.url,
|
|
32
|
+
);
|
|
33
|
+
const stored = existing?.accessToken
|
|
34
|
+
? yield* Database.load(existing.accessToken).pipe(Effect.option)
|
|
35
|
+
: Option.none();
|
|
36
|
+
const newKey = key?.trim() || undefined;
|
|
37
|
+
const apiKey = newKey ?? Option.getOrUndefined(Option.map(stored, ({ token }) => token));
|
|
38
|
+
|
|
39
|
+
// Only a refusal of credentials stops the add: a server that is down, or blocks this network,
|
|
40
|
+
// may still answer the agent's turns.
|
|
41
|
+
const probe = yield* McpToolkit.probe({ ...endpoint, apiKey }).pipe(Effect.result);
|
|
42
|
+
if (probe._tag === 'Failure' && probe.failure.unauthorized) {
|
|
43
|
+
return yield* Effect.die(
|
|
44
|
+
new Error(
|
|
45
|
+
apiKey
|
|
46
|
+
? 'The MCP server rejected this API key.'
|
|
47
|
+
: 'The MCP server needs sign-in. Ask the user to connect it with Connect, then Custom MCP Server.',
|
|
48
|
+
),
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const connection =
|
|
53
|
+
existing ??
|
|
54
|
+
(yield* Database.add(
|
|
55
|
+
Obj.make(Connection.Connection, { name: name ?? source, connectorId: MCP_CONNECTOR_ID, mcp: endpoint }),
|
|
56
|
+
));
|
|
57
|
+
// The reply describes the endpoint that answered, so a re-add keeps that one.
|
|
58
|
+
if (existing && existing.mcp?.protocol !== endpoint.protocol) {
|
|
59
|
+
Obj.update(existing, (existing) => {
|
|
60
|
+
existing.mcp = endpoint;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
if (newKey) {
|
|
64
|
+
const accessToken = yield* Database.add(Obj.make(AccessToken.AccessToken, { source, token: newKey }));
|
|
65
|
+
Obj.update(connection, (connection) => {
|
|
66
|
+
connection.accessToken = Ref.make(accessToken);
|
|
67
|
+
});
|
|
68
|
+
Obj.setParent(accessToken, connection);
|
|
69
|
+
// The key it replaces stays readable by every member until it is removed.
|
|
70
|
+
if (Option.isSome(stored)) {
|
|
71
|
+
yield* Database.remove(stored.value);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const binder = yield* Harness.binder.pipe(Effect.orDie);
|
|
76
|
+
yield* Effect.promise(() => binder.setConnection(AiContext.connectionRef(connection), true));
|
|
77
|
+
return {
|
|
78
|
+
...describe(connection, binder.getConnections()),
|
|
79
|
+
...(probe._tag === 'Success' ? { tools: probe.success.tools } : { problem: probe.failure.message }),
|
|
80
|
+
};
|
|
81
|
+
}),
|
|
82
|
+
),
|
|
83
|
+
);
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2026 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
6
|
+
|
|
7
|
+
import { Harness } from '@dxos/assistant';
|
|
8
|
+
import { describeInput } from '@dxos/assistant/Describe';
|
|
9
|
+
import * as Operation from '@dxos/compute/Operation';
|
|
10
|
+
import type * as Skill from '@dxos/compute/Skill';
|
|
11
|
+
import { Obj } from '@dxos/echo';
|
|
12
|
+
|
|
13
|
+
import type { ListedOperation, ListedSkill } from './definitions.ts';
|
|
14
|
+
|
|
15
|
+
/** The skills enabled in this conversation, or none where it has no binder. */
|
|
16
|
+
export const enabledSkills: Effect.Effect<Skill.Skill[], never, Harness.HarnessService> = Harness.binder.pipe(
|
|
17
|
+
Effect.tap((binder) => Effect.promise(() => binder.sync())),
|
|
18
|
+
Effect.map((binder) => binder.getSkills()),
|
|
19
|
+
Effect.orElseSucceed((): Skill.Skill[] => []),
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
/** A skill's key, or for a space-authored skill with none its URI. */
|
|
23
|
+
export const skillKey = (skill: Skill.Skill): string => Obj.getMeta(skill).key ?? String(Obj.getURI(skill));
|
|
24
|
+
|
|
25
|
+
/** Keys compare with or without the `dxn:` prefix, which records and definitions spell differently. */
|
|
26
|
+
export const sameKey = (left: string, right: string): boolean => bare(left) === bare(right);
|
|
27
|
+
const bare = (key: string): string => key.replace(/^dxn:/, '');
|
|
28
|
+
|
|
29
|
+
/** Whether `skill` is one of `enabled`. */
|
|
30
|
+
export const isEnabled = (enabled: readonly Skill.Skill[], skill: Skill.Skill): boolean =>
|
|
31
|
+
enabled.some((other) => sameKey(skillKey(other), skillKey(skill)));
|
|
32
|
+
|
|
33
|
+
/** The registry's skills and any enabled one it does not hold (a space-authored skill), by name. */
|
|
34
|
+
export const knownSkills = (registered: readonly Skill.Skill[], enabled: readonly Skill.Skill[]): Skill.Skill[] =>
|
|
35
|
+
[...registered, ...enabled.filter((skill) => !isEnabled(registered, skill))].sort((left, right) =>
|
|
36
|
+
left.name.localeCompare(right.name),
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
export const listedSkill = (skill: Skill.Skill, enabled: boolean): ListedSkill => ({
|
|
40
|
+
key: skillKey(skill),
|
|
41
|
+
name: skill.name,
|
|
42
|
+
...(skill.description === undefined ? {} : { description: String(skill.description) }),
|
|
43
|
+
enabled,
|
|
44
|
+
agentCanEnable: skill.agentCanEnable === true,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
/** A listed operation, with the record it describes. */
|
|
48
|
+
export type OperationCandidate = { readonly listed: ListedOperation; readonly record: Operation.PersistentOperation };
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The operations of `skills`, each once, read from the registry's records (which every host's tools resolve through).
|
|
52
|
+
* Enabled skills' come first, so an operation two skills share counts as enabled when either is.
|
|
53
|
+
*/
|
|
54
|
+
export const operationCandidates = (
|
|
55
|
+
skills: readonly Skill.Skill[],
|
|
56
|
+
enabled: readonly Skill.Skill[],
|
|
57
|
+
records: readonly Operation.PersistentOperation[],
|
|
58
|
+
): OperationCandidate[] => {
|
|
59
|
+
const byTool = new Map(
|
|
60
|
+
records.flatMap((record) => {
|
|
61
|
+
const key = Operation.getKey(record);
|
|
62
|
+
const tool = key === undefined ? undefined : Operation.tryToolNameFromKey(key);
|
|
63
|
+
return key === undefined || tool === undefined ? [] : [[tool, { key, record }] as const];
|
|
64
|
+
}),
|
|
65
|
+
);
|
|
66
|
+
const ordered = [...skills].sort(
|
|
67
|
+
(left, right) => Number(isEnabled(enabled, right)) - Number(isEnabled(enabled, left)),
|
|
68
|
+
);
|
|
69
|
+
const candidates = new Map<string, OperationCandidate>();
|
|
70
|
+
for (const skill of ordered) {
|
|
71
|
+
for (const tool of skill.tools) {
|
|
72
|
+
const found = byTool.get(String(tool));
|
|
73
|
+
if (found !== undefined && !candidates.has(bare(found.key))) {
|
|
74
|
+
candidates.set(bare(found.key), {
|
|
75
|
+
listed: {
|
|
76
|
+
key: found.key,
|
|
77
|
+
tool: String(tool),
|
|
78
|
+
name: found.record.name,
|
|
79
|
+
...(found.record.description === undefined ? {} : { description: found.record.description }),
|
|
80
|
+
skill: skillKey(skill),
|
|
81
|
+
enabled: isEnabled(enabled, skill),
|
|
82
|
+
},
|
|
83
|
+
record: found.record,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return [...candidates.values()];
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* The listed operation with its input, labelled as code passes it (refs as `Ref<typename>`). Left out where the record's
|
|
93
|
+
* schema cannot be rebuilt, which costs only that operation's input.
|
|
94
|
+
*/
|
|
95
|
+
export const withInput = ({ listed, record }: OperationCandidate): Effect.Effect<ListedOperation> =>
|
|
96
|
+
Effect.try(() => describeInput(Operation.deserialize(record).input)).pipe(
|
|
97
|
+
Effect.map((input) => ({ ...listed, input })),
|
|
98
|
+
Effect.orElseSucceed(() => listed),
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
/** Lower-case words, splitting dotted keys, kebab-case and camelCase; words under three letters say nothing. */
|
|
102
|
+
const words = (text: string): string[] =>
|
|
103
|
+
text
|
|
104
|
+
.replace(/([a-z])([A-Z])/g, '$1 $2')
|
|
105
|
+
.toLowerCase()
|
|
106
|
+
.split(/[^a-z0-9]+/)
|
|
107
|
+
.filter((word) => word.length >= 3);
|
|
108
|
+
|
|
109
|
+
/** The items any of the query's words match, most matched first; every item, in order, without a query. */
|
|
110
|
+
export const ranked = <T>(
|
|
111
|
+
items: readonly T[],
|
|
112
|
+
query: string | undefined,
|
|
113
|
+
text: (item: T) => readonly (string | undefined)[],
|
|
114
|
+
): T[] => {
|
|
115
|
+
const terms = words(query ?? '');
|
|
116
|
+
if (terms.length === 0) {
|
|
117
|
+
return [...items];
|
|
118
|
+
}
|
|
119
|
+
return items
|
|
120
|
+
.map((item) => {
|
|
121
|
+
const itemWords = words(
|
|
122
|
+
text(item)
|
|
123
|
+
.filter((part) => part !== undefined)
|
|
124
|
+
.join(' '),
|
|
125
|
+
);
|
|
126
|
+
return { item, score: terms.filter((term) => itemWords.some((word) => word.startsWith(term))).length };
|
|
127
|
+
})
|
|
128
|
+
.filter(({ score }) => score > 0)
|
|
129
|
+
.sort((left, right) => right.score - left.score)
|
|
130
|
+
.map(({ item }) => item);
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
/** An operation as a list shows it: its description cut to the first sentence, which a lookup by key gives in full. */
|
|
134
|
+
export const brief = (listed: ListedOperation): ListedOperation =>
|
|
135
|
+
listed.description === undefined
|
|
136
|
+
? listed
|
|
137
|
+
: {
|
|
138
|
+
...listed,
|
|
139
|
+
description: (/^.*?[.!?](?=\s|$)/s.exec(listed.description)?.[0] ?? listed.description).slice(0, 200),
|
|
140
|
+
};
|