@hhuangpanda/dsh-automation 0.0.0-stage → 0.3.34
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 +22 -0
- package/README.md +133 -2
- package/README.zh.md +134 -0
- package/cordis.patch.yml +3 -0
- package/docs/images/automation-overview-en.png +0 -0
- package/docs/images/automation-overview-zh.png +0 -0
- package/docs/reference.md +55 -0
- package/docs/reference.zh.md +55 -0
- package/lib/agent-configuration.d.ts +27 -0
- package/lib/agent-configuration.js +217 -0
- package/lib/api.d.ts +5 -0
- package/lib/api.js +253 -0
- package/lib/client/AutomationPanel.d.ts +9 -0
- package/lib/client/EmptyState.d.ts +10 -0
- package/lib/client/ModelSelection.d.ts +17 -0
- package/lib/client/ScheduleSection.d.ts +32 -0
- package/lib/client/SchedulerHealth.d.ts +10 -0
- package/lib/client/SkillPicker.d.ts +15 -0
- package/lib/client/TaskDetail.d.ts +34 -0
- package/lib/client/TaskEditor.d.ts +38 -0
- package/lib/client/TaskRow.d.ts +12 -0
- package/lib/client/editor-layout.d.ts +20 -0
- package/lib/client/i18n.d.ts +15 -0
- package/lib/client/icons.d.ts +30 -0
- package/lib/client/index.d.ts +6 -0
- package/lib/client/locales.d.ts +260 -0
- package/lib/client/rrule-editor.d.ts +15 -0
- package/lib/client/session-selection.d.ts +4 -0
- package/lib/client/shared.d.ts +77 -0
- package/lib/client/store.d.ts +40 -0
- package/lib/client.js +3014 -0
- package/lib/controller.d.ts +36 -0
- package/lib/controller.js +154 -0
- package/lib/domain.d.ts +44 -0
- package/lib/domain.js +473 -0
- package/lib/errors.d.ts +14 -0
- package/lib/errors.js +16 -0
- package/lib/im-delivery.d.ts +30 -0
- package/lib/im-delivery.js +69 -0
- package/lib/index.d.ts +25 -0
- package/lib/index.js +92 -0
- package/lib/recurrence.d.ts +14 -0
- package/lib/recurrence.js +203 -0
- package/lib/runner.d.ts +27 -0
- package/lib/runner.js +295 -0
- package/lib/runtime-marker.d.ts +3 -0
- package/lib/runtime-marker.js +2 -0
- package/lib/scheduler.d.ts +58 -0
- package/lib/scheduler.js +287 -0
- package/lib/store.d.ts +14 -0
- package/lib/store.js +108 -0
- package/lib/tool-configuration.d.ts +8 -0
- package/lib/tool-configuration.js +220 -0
- package/lib/tool-support.d.ts +67 -0
- package/lib/tool-support.js +47 -0
- package/lib/tools.d.ts +6 -0
- package/lib/tools.js +140 -0
- package/lib/types.d.ts +465 -0
- package/lib/types.js +99 -0
- package/lib/validation.d.ts +34 -0
- package/lib/validation.js +99 -0
- package/package.json +163 -4
- package/screenshots.json +1 -0
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { defineTool } from '@deepseek-ai/dsh-tools';
|
|
2
|
+
import { SessionId } from '@deepseek-ai/dsh-session';
|
|
3
|
+
import { AutomationError } from './errors.js';
|
|
4
|
+
import { assertProviderModelPair } from './validation.js';
|
|
5
|
+
import { ACTION_SCHEMA, ERROR_SCHEMA, executeTool, render, workspaceDirectory } from './tool-support.js';
|
|
6
|
+
import '@deepseek-ai/dsh-agent-preset-registry';
|
|
7
|
+
import '@deepseek-ai/dsh-workspace';
|
|
8
|
+
function latestSessionModel(agent) {
|
|
9
|
+
const events = agent.session.snapshotEvents();
|
|
10
|
+
const event = [...events].reverse().find((entry) => entry.type === 'request/header');
|
|
11
|
+
if (event?.type !== 'request/header')
|
|
12
|
+
return undefined;
|
|
13
|
+
const config = event.data.header.config;
|
|
14
|
+
if (typeof config.provider !== 'string' || typeof config.model !== 'string')
|
|
15
|
+
return undefined;
|
|
16
|
+
return { provider: config.provider, model: config.model };
|
|
17
|
+
}
|
|
18
|
+
function createSchedule(args) {
|
|
19
|
+
const { once_at, rrule, time_zone, start_at } = args;
|
|
20
|
+
const hasRecurring = rrule !== undefined || time_zone !== undefined || start_at !== undefined;
|
|
21
|
+
if (once_at !== undefined && !hasRecurring) {
|
|
22
|
+
if (typeof once_at !== 'string')
|
|
23
|
+
throw new Error('once_at must be an RFC 3339 UTC string.');
|
|
24
|
+
return { kind: 'once', fireAt: once_at };
|
|
25
|
+
}
|
|
26
|
+
if (once_at === undefined && rrule !== undefined && time_zone !== undefined && start_at !== undefined) {
|
|
27
|
+
return { kind: 'recurring', rrule, timeZone: time_zone, startAt: start_at };
|
|
28
|
+
}
|
|
29
|
+
throw new Error('Supply either once_at, or all of rrule, time_zone, and start_at.');
|
|
30
|
+
}
|
|
31
|
+
function updateSchedule(args) {
|
|
32
|
+
if (args.once_at === undefined && args.rrule === undefined && args.time_zone === undefined && args.start_at === undefined) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
return createSchedule(args);
|
|
36
|
+
}
|
|
37
|
+
export function registerConfigurationTools(rootCtx, toolCtx, agent, controller, agentConfiguration) {
|
|
38
|
+
const disposers = [];
|
|
39
|
+
disposers.push(toolCtx.tools.register(defineTool({
|
|
40
|
+
name: 'automation_options',
|
|
41
|
+
description: 'List the Host agent presets, provider/models, user-invocable skills, and permission presets available for automation configuration. Call this before selecting configuration ids. With an id, options use that task workspace and saved preset; agent_preset previews skills for a candidate preset. An empty agent_preset means the Host default.',
|
|
42
|
+
parameters: {
|
|
43
|
+
id: { type: 'string', description: 'Existing automation id. Omit to use this Agent workspace.' },
|
|
44
|
+
agent_preset: { type: 'string', description: 'Candidate preset id for skill discovery; empty means Host default.' },
|
|
45
|
+
provider: { type: 'string', description: 'Candidate provider for exact-model reasoning options; supply with model. Omit both to use the saved task model.' },
|
|
46
|
+
model: { type: 'string', description: 'Candidate model for reasoning options; supply with provider. Empty pair means no model override.' },
|
|
47
|
+
},
|
|
48
|
+
output: {
|
|
49
|
+
schema: {
|
|
50
|
+
oneOf: [
|
|
51
|
+
{
|
|
52
|
+
type: 'object',
|
|
53
|
+
additionalProperties: false,
|
|
54
|
+
properties: {
|
|
55
|
+
ok: { type: 'boolean', required: true, const: true },
|
|
56
|
+
options: { type: 'object', required: true, additionalProperties: true },
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
ERROR_SCHEMA,
|
|
60
|
+
],
|
|
61
|
+
},
|
|
62
|
+
render,
|
|
63
|
+
},
|
|
64
|
+
execute(args, exec) {
|
|
65
|
+
return executeTool('automation_options', agent, exec.agent, async () => {
|
|
66
|
+
const candidate = args.agent_preset === undefined ? undefined : args.agent_preset || undefined;
|
|
67
|
+
assertProviderModelPair(args.provider, args.model);
|
|
68
|
+
const options = args.id === undefined
|
|
69
|
+
? await agentConfiguration.options(workspaceDirectory(agent), args.agent_preset === undefined ? rootCtx.agentPresets.composedPreset(agent.ctx) : candidate, args.provider, args.model)
|
|
70
|
+
: await controller.options(args.id, args.agent_preset === undefined ? undefined : candidate ?? null, args.provider, args.model);
|
|
71
|
+
return { ok: true, options: options };
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
presentCall: () => ({ card: 'generic', title: 'Automation options', kind: 'read' }),
|
|
75
|
+
})));
|
|
76
|
+
disposers.push(toolCtx.tools.register(defineTool({
|
|
77
|
+
name: 'automation_create',
|
|
78
|
+
description: 'Create one durable unattended automation. Call automation_options before selecting Host ids. Before calling, show one concise preview with name, schedule/time zone, workspace, Agent preset, provider/model, ordered selected skills, reasoning effort (default or exact supported id), exact Host permission label/id (including approval warning), notification policy, and failure-pause policy; wait for explicit user confirmation, then set creation_confirmed to true. Every run starts a fresh visible session. Presets with approval ask may wait until timeout because unattended runs never auto-approve. Supply either once_at, or rrule + time_zone + start_at.',
|
|
79
|
+
parameters: {
|
|
80
|
+
name: { type: 'string', required: true, description: 'Short task name.' },
|
|
81
|
+
prompt: { type: 'string', required: true, description: 'Self-contained prompt for every fresh run session.' },
|
|
82
|
+
once_at: { type: 'string', description: 'One-time canonical RFC 3339 UTC instant.' },
|
|
83
|
+
rrule: { type: 'string', description: 'Single RFC 5545 RRULE line without DTSTART.' },
|
|
84
|
+
time_zone: { type: 'string', description: 'IANA time zone for a recurring rule.' },
|
|
85
|
+
start_at: { type: 'string', description: 'Recurring local wall clock DTSTART as YYYY-MM-DDTHH:mm:ss.' },
|
|
86
|
+
notification_policy: { type: 'string', enum: ['failures', 'always', 'never'], description: 'Sidebar notification policy. Defaults to failures.' },
|
|
87
|
+
pause_after_failures: { type: 'boolean', description: 'Pause future scheduling after 3 consecutive failed or timed-out runs.' },
|
|
88
|
+
agent_preset: { type: 'string', description: 'Host Agent preset id. Omit to capture the creating Agent preset.' },
|
|
89
|
+
provider: { type: 'string', description: 'Provider override; must be supplied with model.' },
|
|
90
|
+
model: { type: 'string', description: 'Model override; must be supplied with provider.' },
|
|
91
|
+
reasoning_effort: { type: 'string', description: 'Exact supported reasoning effort id from automation_options for the chosen provider/model. Omit to keep default behavior; not captured from the creating session. Ignored for pinned sessions.' },
|
|
92
|
+
skills: { type: 'array', items: { type: 'string' }, description: 'Ordered user-invocable skill names to preload. Defaults to none.' },
|
|
93
|
+
permission_preset: { type: 'string', required: true, description: 'Confirmed Host permission preset id for every run.' },
|
|
94
|
+
execution_mode: { type: 'string', enum: ['fresh', 'pinned-session'], description: 'Execution destination; defaults to fresh.' },
|
|
95
|
+
target_session_id: { type: 'string', description: 'Persisted target session id for pinned-session mode.' },
|
|
96
|
+
session_target_confirmed: { type: 'boolean', description: 'Must be true after the target session preview is confirmed.' },
|
|
97
|
+
creation_confirmed: { type: 'boolean', required: true, description: 'Must be true only after the user explicitly confirms the complete creation preview.' },
|
|
98
|
+
},
|
|
99
|
+
output: { schema: ACTION_SCHEMA, render },
|
|
100
|
+
execute(args, exec) {
|
|
101
|
+
return executeTool('automation_create', agent, exec.agent, async () => {
|
|
102
|
+
if (args.creation_confirmed !== true)
|
|
103
|
+
throw new Error('Explicit user confirmation of the complete creation preview is required.');
|
|
104
|
+
const cwd = workspaceDirectory(agent);
|
|
105
|
+
const workspace = await rootCtx.workspaceRegistry.create(cwd);
|
|
106
|
+
assertProviderModelPair(args.provider, args.model);
|
|
107
|
+
const currentModel = latestSessionModel(agent);
|
|
108
|
+
const capturedProvider = args.provider ?? currentModel?.provider ?? agent.options.provider;
|
|
109
|
+
const capturedModel = args.model ?? currentModel?.model ?? agent.options.model;
|
|
110
|
+
let target = { mode: 'fresh' };
|
|
111
|
+
if (args.execution_mode === 'pinned-session') {
|
|
112
|
+
const targetSessionId = args.target_session_id;
|
|
113
|
+
if (targetSessionId === undefined)
|
|
114
|
+
throw new Error('target_session_id is required for pinned-session mode.');
|
|
115
|
+
if (args.session_target_confirmed !== true)
|
|
116
|
+
throw new Error('Explicit user confirmation is required for a pinned session target.');
|
|
117
|
+
const persistence = rootCtx.get('sessionPersistence');
|
|
118
|
+
if (persistence === undefined)
|
|
119
|
+
throw new AutomationError('target_session_unavailable', 'persisted session inspection is unavailable.');
|
|
120
|
+
const snapshot = await persistence.stat(SessionId(targetSessionId));
|
|
121
|
+
if (snapshot === undefined || snapshot.header.id !== SessionId(targetSessionId))
|
|
122
|
+
throw new AutomationError('target_session_not_found', 'pinned session could not be resolved.');
|
|
123
|
+
if (snapshot.header.cwd !== cwd)
|
|
124
|
+
throw new AutomationError('target_workspace_mismatch', 'pinned session cwd does not match.');
|
|
125
|
+
target = { mode: 'pinned-session', sessionId: targetSessionId, workspaceId: workspace.id, cwd: workspace.path, fallback: 'fail' };
|
|
126
|
+
}
|
|
127
|
+
const agentPreset = args.agent_preset ?? rootCtx.agentPresets.composedPreset(agent.ctx);
|
|
128
|
+
const task = await controller.create({
|
|
129
|
+
name: args.name,
|
|
130
|
+
prompt: args.prompt,
|
|
131
|
+
schedule: createSchedule(args),
|
|
132
|
+
execution: {
|
|
133
|
+
workspaceId: workspace.id,
|
|
134
|
+
cwd: workspace.path,
|
|
135
|
+
...(agentPreset === undefined ? {} : { agentPreset }),
|
|
136
|
+
...(capturedProvider === undefined || capturedModel === undefined ? {} : { provider: capturedProvider, model: capturedModel }),
|
|
137
|
+
...(args.reasoning_effort === undefined ? {} : { reasoningEffort: args.reasoning_effort }),
|
|
138
|
+
skills: args.skills ?? [],
|
|
139
|
+
target,
|
|
140
|
+
},
|
|
141
|
+
createdBySessionId: agent.id,
|
|
142
|
+
permissionPreset: args.permission_preset,
|
|
143
|
+
...(target.mode === 'pinned-session' ? { sessionTargetConfirmed: true } : {}),
|
|
144
|
+
...(args.notification_policy === undefined ? {} : { notificationPolicy: args.notification_policy }),
|
|
145
|
+
...(args.pause_after_failures === undefined ? {} : { pauseAfterConsecutiveFailures: args.pause_after_failures }),
|
|
146
|
+
});
|
|
147
|
+
return {
|
|
148
|
+
ok: true,
|
|
149
|
+
id: task.id,
|
|
150
|
+
status: task.status,
|
|
151
|
+
message: `Created ${task.name}; next run ${task.nextRunAt}; permission ${task.security.permissionPreset}; notifications ${task.notificationPolicy}.`,
|
|
152
|
+
};
|
|
153
|
+
});
|
|
154
|
+
},
|
|
155
|
+
presentCall: (args) => ({ card: 'generic', title: 'Create automation', kind: 'other', rawInput: args.name }),
|
|
156
|
+
})));
|
|
157
|
+
disposers.push(toolCtx.tools.register(defineTool({
|
|
158
|
+
name: 'automation_update',
|
|
159
|
+
description: 'Update an existing automation. Call automation_options before selecting Host ids. Omitted fields stay unchanged; null clears an Agent preset, provider/model, or reasoning effort override, and skills replaces the ordered selection. Provider/model must be set or cleared together. Before an actual permission change, show the exact Host preset and get explicit confirmation; set permission_confirmed only after they confirm.',
|
|
160
|
+
parameters: {
|
|
161
|
+
id: { type: 'string', required: true, description: 'Exact automation id.' },
|
|
162
|
+
name: { type: 'string', description: 'Replacement task name.' },
|
|
163
|
+
prompt: { type: 'string', description: 'Replacement self-contained prompt for future runs.' },
|
|
164
|
+
once_at: { type: 'string', description: 'Replacement one-time canonical RFC 3339 UTC instant.' },
|
|
165
|
+
rrule: { type: 'string', description: 'Replacement RFC 5545 RRULE line without DTSTART.' },
|
|
166
|
+
time_zone: { type: 'string', description: 'Replacement IANA time zone.' },
|
|
167
|
+
start_at: { type: 'string', description: 'Replacement local wall clock DTSTART as YYYY-MM-DDTHH:mm:ss.' },
|
|
168
|
+
notification_policy: { type: 'string', enum: ['failures', 'always', 'never'], description: 'Replacement sidebar notification policy.' },
|
|
169
|
+
pause_after_failures: { type: 'boolean', description: 'Whether to pause after 3 consecutive failed or timed-out runs.' },
|
|
170
|
+
agent_preset: { oneOf: [{ type: 'string' }, { type: 'null' }], description: 'Replacement Host Agent preset id, or null for Host default.' },
|
|
171
|
+
provider: { oneOf: [{ type: 'string' }, { type: 'null' }], description: 'Replacement provider, or null with model to use Host default.' },
|
|
172
|
+
model: { oneOf: [{ type: 'string' }, { type: 'null' }], description: 'Replacement model, or null with provider to use Host default.' },
|
|
173
|
+
reasoning_effort: { oneOf: [{ type: 'string' }, { type: 'null' }], description: 'Exact supported effort id for the saved or replacement provider/model; null clears the override. Omit to preserve it, including on model changes. Ignored for pinned sessions.' },
|
|
174
|
+
skills: { type: 'array', items: { type: 'string' }, description: 'Replacement ordered selected skills; [] clears.' },
|
|
175
|
+
permission_preset: { type: 'string', description: 'Replacement Host permission preset id for future runs.' },
|
|
176
|
+
permission_confirmed: { type: 'boolean', description: 'Required and true only after the user explicitly confirms a permission change.' },
|
|
177
|
+
},
|
|
178
|
+
output: { schema: ACTION_SCHEMA, render },
|
|
179
|
+
execute(args, exec) {
|
|
180
|
+
return executeTool('automation_update', agent, exec.agent, async () => {
|
|
181
|
+
const schedule = updateSchedule(args);
|
|
182
|
+
const current = controller.get(args.id);
|
|
183
|
+
if (['delivery', 'confirmDeliveryChange', 'deliveryChangeConfirmed'].some((key) => Object.hasOwn(args, key))) {
|
|
184
|
+
throw new Error('Message delivery changes are manual-only in Automation settings.');
|
|
185
|
+
}
|
|
186
|
+
if (['execution_mode', 'target_session_id', 'session_target_confirmed', 'execution', 'target', 'confirmSessionTargetChange'].some((key) => Object.hasOwn(args, key))) {
|
|
187
|
+
throw new Error('Session target changes are unsupported by automation_update; change the target manually in Automation settings.');
|
|
188
|
+
}
|
|
189
|
+
if (args.permission_preset !== undefined && args.permission_preset !== current.security.permissionPreset && args.permission_confirmed !== true) {
|
|
190
|
+
throw new Error('Explicit user confirmation is required to change permissions.');
|
|
191
|
+
}
|
|
192
|
+
if (args.name === undefined && args.prompt === undefined && schedule === undefined && args.notification_policy === undefined && args.pause_after_failures === undefined && args.permission_preset === undefined && args.agent_preset === undefined && args.provider === undefined && args.model === undefined && args.reasoning_effort === undefined && args.skills === undefined) {
|
|
193
|
+
throw new Error('Supply at least one field to update.');
|
|
194
|
+
}
|
|
195
|
+
const task = await controller.update(args.id, {
|
|
196
|
+
...(args.name === undefined ? {} : { name: args.name }),
|
|
197
|
+
...(args.prompt === undefined ? {} : { prompt: args.prompt }),
|
|
198
|
+
...(schedule === undefined ? {} : { schedule }),
|
|
199
|
+
...(args.notification_policy === undefined ? {} : { notificationPolicy: args.notification_policy }),
|
|
200
|
+
...(args.pause_after_failures === undefined ? {} : { pauseAfterConsecutiveFailures: args.pause_after_failures }),
|
|
201
|
+
...(args.permission_preset === undefined ? {} : { permissionPreset: args.permission_preset }),
|
|
202
|
+
...(args.permission_preset === undefined || args.permission_confirmed !== true ? {} : { permissionChangeConfirmed: true }),
|
|
203
|
+
...((args.agent_preset === undefined && args.provider === undefined && args.model === undefined && args.reasoning_effort === undefined && args.skills === undefined) ? {} : {
|
|
204
|
+
execution: {
|
|
205
|
+
...(args.agent_preset === undefined ? {} : { agentPreset: args.agent_preset }),
|
|
206
|
+
...(args.provider === undefined ? {} : { provider: args.provider }),
|
|
207
|
+
...(args.model === undefined ? {} : { model: args.model }),
|
|
208
|
+
...(args.reasoning_effort === undefined ? {} : { reasoningEffort: args.reasoning_effort }),
|
|
209
|
+
...(args.skills === undefined ? {} : { skills: args.skills }),
|
|
210
|
+
},
|
|
211
|
+
}),
|
|
212
|
+
});
|
|
213
|
+
return { ok: true, id: task.id, status: task.status, message: `Updated ${task.id}; next run ${task.nextRunAt}; permission ${task.security.permissionPreset}.` };
|
|
214
|
+
});
|
|
215
|
+
},
|
|
216
|
+
presentCall: (args) => ({ card: 'generic', title: 'Update automation', kind: 'other', rawInput: args.id }),
|
|
217
|
+
})));
|
|
218
|
+
return disposers;
|
|
219
|
+
}
|
|
220
|
+
//# sourceMappingURL=tool-configuration.js.map
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { Agent } from '@deepseek-ai/dsh-agent';
|
|
2
|
+
import type { JsonValue } from '@deepseek-ai/dsh-util-values';
|
|
3
|
+
export declare const ERROR_SCHEMA: {
|
|
4
|
+
readonly type: "object";
|
|
5
|
+
readonly additionalProperties: false;
|
|
6
|
+
readonly properties: {
|
|
7
|
+
readonly ok: {
|
|
8
|
+
readonly type: "boolean";
|
|
9
|
+
readonly required: true;
|
|
10
|
+
readonly const: false;
|
|
11
|
+
};
|
|
12
|
+
readonly error: {
|
|
13
|
+
readonly type: "string";
|
|
14
|
+
readonly required: true;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export declare const ACTION_SCHEMA: {
|
|
19
|
+
readonly oneOf: readonly [{
|
|
20
|
+
readonly type: "object";
|
|
21
|
+
readonly additionalProperties: false;
|
|
22
|
+
readonly properties: {
|
|
23
|
+
readonly ok: {
|
|
24
|
+
readonly type: "boolean";
|
|
25
|
+
readonly required: true;
|
|
26
|
+
readonly const: true;
|
|
27
|
+
};
|
|
28
|
+
readonly id: {
|
|
29
|
+
readonly type: "string";
|
|
30
|
+
readonly required: true;
|
|
31
|
+
};
|
|
32
|
+
readonly status: {
|
|
33
|
+
readonly type: "string";
|
|
34
|
+
readonly required: true;
|
|
35
|
+
};
|
|
36
|
+
readonly message: {
|
|
37
|
+
readonly type: "string";
|
|
38
|
+
readonly required: true;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
}, {
|
|
42
|
+
readonly type: "object";
|
|
43
|
+
readonly additionalProperties: false;
|
|
44
|
+
readonly properties: {
|
|
45
|
+
readonly ok: {
|
|
46
|
+
readonly type: "boolean";
|
|
47
|
+
readonly required: true;
|
|
48
|
+
readonly const: false;
|
|
49
|
+
};
|
|
50
|
+
readonly error: {
|
|
51
|
+
readonly type: "string";
|
|
52
|
+
readonly required: true;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
}];
|
|
56
|
+
};
|
|
57
|
+
export declare function render(_args: unknown, value: JsonValue): {
|
|
58
|
+
type: "text";
|
|
59
|
+
text: string;
|
|
60
|
+
}[];
|
|
61
|
+
export declare function workspaceDirectory(agent: Agent): string;
|
|
62
|
+
/** Guard borrowed live Agents too: their installed tools must stay unavailable during unattended runs. */
|
|
63
|
+
export declare function executeTool<T>(name: string, owner: Agent, caller: Agent | undefined, action: () => T | Promise<T>): Promise<T | {
|
|
64
|
+
ok: false;
|
|
65
|
+
error: string;
|
|
66
|
+
}>;
|
|
67
|
+
//# sourceMappingURL=tool-support.d.ts.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { unattendedAgents } from './runtime-marker.js';
|
|
2
|
+
export const ERROR_SCHEMA = {
|
|
3
|
+
type: 'object',
|
|
4
|
+
additionalProperties: false,
|
|
5
|
+
properties: {
|
|
6
|
+
ok: { type: 'boolean', required: true, const: false },
|
|
7
|
+
error: { type: 'string', required: true },
|
|
8
|
+
},
|
|
9
|
+
};
|
|
10
|
+
export const ACTION_SCHEMA = {
|
|
11
|
+
oneOf: [
|
|
12
|
+
{
|
|
13
|
+
type: 'object',
|
|
14
|
+
additionalProperties: false,
|
|
15
|
+
properties: {
|
|
16
|
+
ok: { type: 'boolean', required: true, const: true },
|
|
17
|
+
id: { type: 'string', required: true },
|
|
18
|
+
status: { type: 'string', required: true },
|
|
19
|
+
message: { type: 'string', required: true },
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
ERROR_SCHEMA,
|
|
23
|
+
],
|
|
24
|
+
};
|
|
25
|
+
export function render(_args, value) {
|
|
26
|
+
return [{ type: 'text', text: JSON.stringify(value) }];
|
|
27
|
+
}
|
|
28
|
+
export function workspaceDirectory(agent) {
|
|
29
|
+
const cwd = agent.session.header.cwd;
|
|
30
|
+
if (cwd === undefined)
|
|
31
|
+
throw new Error('The current session has no workspace directory.');
|
|
32
|
+
return cwd;
|
|
33
|
+
}
|
|
34
|
+
/** Guard borrowed live Agents too: their installed tools must stay unavailable during unattended runs. */
|
|
35
|
+
export async function executeTool(name, owner, caller, action) {
|
|
36
|
+
try {
|
|
37
|
+
if (unattendedAgents.has(owner))
|
|
38
|
+
throw new Error('Automation tools are unavailable during an unattended run.');
|
|
39
|
+
if (caller !== owner)
|
|
40
|
+
throw new Error(`${name} must run in its owning agent scope.`);
|
|
41
|
+
return await action();
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
return { ok: false, error: error instanceof Error ? error.message : String(error) };
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=tool-support.js.map
|
package/lib/tools.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
2
|
+
import type { Agent } from '@deepseek-ai/dsh-agent';
|
|
3
|
+
import type { AutomationController } from './controller.js';
|
|
4
|
+
import { AgentConfiguration } from './agent-configuration.js';
|
|
5
|
+
export declare function registerAutomationTools(rootCtx: Context, toolCtx: Context, agent: Agent, controller: AutomationController, agentConfiguration?: AgentConfiguration): () => void;
|
|
6
|
+
//# sourceMappingURL=tools.d.ts.map
|
package/lib/tools.js
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { defineTool } from '@deepseek-ai/dsh-tools';
|
|
2
|
+
import { AgentConfiguration } from './agent-configuration.js';
|
|
3
|
+
import { registerConfigurationTools } from './tool-configuration.js';
|
|
4
|
+
import { ACTION_SCHEMA, ERROR_SCHEMA, executeTool, render } from './tool-support.js';
|
|
5
|
+
const TASK_SUMMARY_SCHEMA = {
|
|
6
|
+
type: 'object',
|
|
7
|
+
additionalProperties: false,
|
|
8
|
+
properties: {
|
|
9
|
+
id: { type: 'string', required: true },
|
|
10
|
+
name: { type: 'string', required: true },
|
|
11
|
+
status: { type: 'string', required: true },
|
|
12
|
+
schedule: { type: 'string', required: true },
|
|
13
|
+
nextRunAt: { oneOf: [{ type: 'string' }, { type: 'null' }], required: true },
|
|
14
|
+
running: { type: 'boolean', required: true },
|
|
15
|
+
lastRunStatus: { oneOf: [{ type: 'string' }, { type: 'null' }], required: true },
|
|
16
|
+
notificationPolicy: { type: 'string', required: true },
|
|
17
|
+
permissionPreset: { type: 'string', required: true },
|
|
18
|
+
agentPreset: { type: 'string', required: true },
|
|
19
|
+
provider: { type: 'string', required: true },
|
|
20
|
+
model: { type: 'string', required: true },
|
|
21
|
+
skills: { type: 'array', required: true, items: { type: 'string' } },
|
|
22
|
+
consecutiveFailures: { type: 'number', required: true },
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
const LIST_SCHEMA = {
|
|
26
|
+
oneOf: [
|
|
27
|
+
{
|
|
28
|
+
type: 'object',
|
|
29
|
+
additionalProperties: false,
|
|
30
|
+
properties: {
|
|
31
|
+
ok: { type: 'boolean', required: true, const: true },
|
|
32
|
+
tasks: {
|
|
33
|
+
type: 'array',
|
|
34
|
+
required: true,
|
|
35
|
+
items: TASK_SUMMARY_SCHEMA,
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
ERROR_SCHEMA,
|
|
40
|
+
],
|
|
41
|
+
};
|
|
42
|
+
function summary(task) {
|
|
43
|
+
return {
|
|
44
|
+
id: task.id,
|
|
45
|
+
name: task.name,
|
|
46
|
+
status: task.status,
|
|
47
|
+
schedule: task.schedule.kind === 'once'
|
|
48
|
+
? `once at ${task.schedule.fireAt}`
|
|
49
|
+
: `${task.schedule.rrule} (${task.schedule.timeZone})`,
|
|
50
|
+
nextRunAt: task.nextRunAt,
|
|
51
|
+
running: task.running,
|
|
52
|
+
lastRunStatus: task.runs.at(-1)?.status ?? null,
|
|
53
|
+
notificationPolicy: task.notificationPolicy,
|
|
54
|
+
permissionPreset: task.security.permissionPreset,
|
|
55
|
+
agentPreset: task.execution.agentPreset ?? 'Host default',
|
|
56
|
+
provider: task.execution.provider ?? 'Host default',
|
|
57
|
+
model: task.execution.model ?? 'Host default',
|
|
58
|
+
skills: task.execution.skills,
|
|
59
|
+
consecutiveFailures: task.consecutiveFailures,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
export function registerAutomationTools(rootCtx, toolCtx, agent, controller, agentConfiguration = new AgentConfiguration(rootCtx)) {
|
|
63
|
+
const disposers = registerConfigurationTools(rootCtx, toolCtx, agent, controller, agentConfiguration);
|
|
64
|
+
disposers.push(toolCtx.tools.register(defineTool({
|
|
65
|
+
name: 'automation_list',
|
|
66
|
+
description: 'List durable automations and their current scheduling state.',
|
|
67
|
+
parameters: {},
|
|
68
|
+
output: { schema: LIST_SCHEMA, render },
|
|
69
|
+
execute(_args, exec) {
|
|
70
|
+
return executeTool('automation_list', agent, exec.agent, () => ({ ok: true, tasks: controller.list().map(summary) }));
|
|
71
|
+
},
|
|
72
|
+
presentCall: () => ({ card: 'generic', title: 'List automations', kind: 'read' }),
|
|
73
|
+
})));
|
|
74
|
+
disposers.push(toolCtx.tools.register(defineTool({
|
|
75
|
+
name: 'automation_run',
|
|
76
|
+
description: 'Queue one immediate manual run without changing the automation schedule.',
|
|
77
|
+
parameters: {
|
|
78
|
+
id: { type: 'string', required: true, description: 'Exact automation id.' },
|
|
79
|
+
},
|
|
80
|
+
output: { schema: ACTION_SCHEMA, render },
|
|
81
|
+
execute(args, exec) {
|
|
82
|
+
return executeTool('automation_run', agent, exec.agent, async () => {
|
|
83
|
+
const run = await controller.runNow(args.id);
|
|
84
|
+
return { ok: true, id: run.id, status: run.status, message: `Queued manual run ${run.id} for ${args.id}.` };
|
|
85
|
+
});
|
|
86
|
+
},
|
|
87
|
+
presentCall: (args) => ({ card: 'generic', title: 'Run automation', kind: 'other', rawInput: args.id }),
|
|
88
|
+
})));
|
|
89
|
+
for (const definition of [
|
|
90
|
+
{
|
|
91
|
+
name: 'automation_delete',
|
|
92
|
+
description: 'Delete one automation and cancel future scheduling. Existing run sessions remain.',
|
|
93
|
+
verb: 'Deleted',
|
|
94
|
+
execute: (id) => controller.delete(id),
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: 'automation_pause',
|
|
98
|
+
description: 'Pause one active automation. A run already started continues.',
|
|
99
|
+
verb: 'Paused',
|
|
100
|
+
execute: (id) => controller.pause(id),
|
|
101
|
+
},
|
|
102
|
+
]) {
|
|
103
|
+
disposers.push(toolCtx.tools.register(defineTool({
|
|
104
|
+
name: definition.name,
|
|
105
|
+
description: definition.description,
|
|
106
|
+
parameters: { id: { type: 'string', required: true, description: 'Exact automation id.' } },
|
|
107
|
+
output: { schema: ACTION_SCHEMA, render },
|
|
108
|
+
execute(args, exec) {
|
|
109
|
+
return executeTool(definition.name, agent, exec.agent, async () => {
|
|
110
|
+
const result = await definition.execute(args.id);
|
|
111
|
+
if (typeof result === 'boolean' && !result)
|
|
112
|
+
throw new Error(`Automation ${args.id} was not found.`);
|
|
113
|
+
return { ok: true, id: args.id, status: definition.name === 'automation_delete' ? 'deleted' : 'paused', message: `${definition.verb} ${args.id}.` };
|
|
114
|
+
});
|
|
115
|
+
},
|
|
116
|
+
presentCall: (args) => ({ card: 'generic', title: definition.verb, kind: 'other', rawInput: args.id }),
|
|
117
|
+
})));
|
|
118
|
+
}
|
|
119
|
+
disposers.push(toolCtx.tools.register(defineTool({
|
|
120
|
+
name: 'automation_resume',
|
|
121
|
+
description: 'Resume one paused automation. Set run_now to run once immediately while preserving the future recurring schedule.',
|
|
122
|
+
parameters: {
|
|
123
|
+
id: { type: 'string', required: true, description: 'Exact automation id.' },
|
|
124
|
+
run_now: { type: 'boolean', description: 'Also enqueue one immediate manual run.' },
|
|
125
|
+
},
|
|
126
|
+
output: { schema: ACTION_SCHEMA, render },
|
|
127
|
+
execute(args, exec) {
|
|
128
|
+
return executeTool('automation_resume', agent, exec.agent, async () => {
|
|
129
|
+
const task = await controller.resume(args.id, { runNow: args.run_now ?? false });
|
|
130
|
+
return { ok: true, id: task.id, status: task.status, message: `Resumed ${task.id}; next run ${task.nextRunAt}.` };
|
|
131
|
+
});
|
|
132
|
+
},
|
|
133
|
+
presentCall: (args) => ({ card: 'generic', title: 'Resume automation', kind: 'other', rawInput: args.id }),
|
|
134
|
+
})));
|
|
135
|
+
return () => {
|
|
136
|
+
for (const dispose of disposers.reverse())
|
|
137
|
+
dispose();
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=tools.js.map
|