@michengai/dsh-automation 0.1.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/LICENSE +201 -0
- package/NOTICE +9 -0
- package/README.md +136 -0
- package/README.zh-CN.md +136 -0
- package/cordis.patch.yml +9 -0
- package/docs/00-/344/272/244/346/216/245/345/205/245/345/217/243/00-/351/230/205/350/257/273/345/257/274/350/210/252.md +11 -0
- package/docs/00-/344/272/244/346/216/245/345/205/245/345/217/243/01-/351/241/271/347/233/256/346/246/202/350/247/210.md +22 -0
- package/docs/00-/344/272/244/346/216/245/345/205/245/345/217/243/02-/345/275/223/345/211/215/347/212/266/346/200/201.md +9 -0
- package/docs/00-/344/272/244/346/216/245/345/205/245/345/217/243/03-/345/276/205/345/212/236/344/270/216/351/230/273/345/241/236.md +7 -0
- package/docs/00-/344/272/244/346/216/245/345/205/245/345/217/243/04-/350/277/255/344/273/243/350/267/257/347/272/277/345/233/276.md +5 -0
- package/docs/00-/344/272/244/346/216/245/345/205/245/345/217/243/05-/346/212/200/346/234/257/346/236/266/346/236/204/345/237/272/347/272/277.md +10 -0
- package/docs/00-/344/272/244/346/216/245/345/205/245/345/217/243/06-/346/226/207/346/241/243/347/274/226/345/206/231/350/247/204/350/214/203.md +8 -0
- package/docs/01-/345/275/223/345/211/215/345/267/245/344/275/234/I001-/344/273/273/345/212/241/350/207/252/345/212/250/345/214/226/346/217/222/344/273/266/00-/350/277/255/344/273/243/346/200/273/350/247/210.md +47 -0
- package/docs/03-/346/212/200/346/234/257/346/236/266/346/236/204/00-/351/242/206/345/237/237/347/264/242/345/274/225.md +5 -0
- package/docs/03-/346/212/200/346/234/257/346/236/266/346/236/204/01-/350/260/203/345/272/246/344/270/216/346/211/247/350/241/214/346/250/241/345/236/213.md +30 -0
- package/lib/client.js +2792 -0
- package/lib/client.js.map +7 -0
- package/lib/index.js +22869 -0
- package/lib/types/client/AutomationView.d.ts +2 -0
- package/lib/types/client/ScheduleRail.d.ts +34 -0
- package/lib/types/client/contracts.d.ts +57 -0
- package/lib/types/client/create-modal.d.ts +30 -0
- package/lib/types/client/helpers.d.ts +67 -0
- package/lib/types/client/icons.d.ts +28 -0
- package/lib/types/client/index.d.ts +4 -0
- package/lib/types/client/locales.d.ts +187 -0
- package/lib/types/client/menu.d.ts +53 -0
- package/lib/types/client/native-session-list.d.ts +14 -0
- package/lib/types/client/native-tabs.d.ts +23 -0
- package/lib/types/client/prefill.d.ts +6 -0
- package/lib/types/client/protocol.d.ts +153 -0
- package/lib/types/client/runtime.d.ts +29 -0
- package/lib/types/client/schedule-rail-model.d.ts +87 -0
- package/lib/types/client/styles.d.ts +1 -0
- package/lib/types/domain.d.ts +67 -0
- package/lib/types/executor.d.ts +30 -0
- package/lib/types/index.d.ts +20 -0
- package/lib/types/recurrence.d.ts +7 -0
- package/lib/types/rpc.d.ts +13 -0
- package/lib/types/run-title.d.ts +3 -0
- package/lib/types/service.d.ts +110 -0
- package/lib/types/tools.d.ts +12 -0
- package/lib/types/types.d.ts +146 -0
- package/package.json +99 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/** Web 客户端与 Host RPC 共享的 JSON 契约。 */
|
|
2
|
+
export type AutomationStatus = 'active' | 'paused';
|
|
3
|
+
export type AutomationRunStatus = 'queued' | 'running' | 'succeeded' | 'failed' | 'skipped' | 'cancelled' | 'interrupted';
|
|
4
|
+
export type AutomationPermission = 'read-only' | 'workspace-write' | 'full-access';
|
|
5
|
+
export type AutomationSchedule = {
|
|
6
|
+
readonly kind: 'once';
|
|
7
|
+
readonly at: string;
|
|
8
|
+
readonly timeZone?: string;
|
|
9
|
+
} | {
|
|
10
|
+
readonly kind: 'interval';
|
|
11
|
+
readonly everyMinutes: number;
|
|
12
|
+
readonly anchor?: string;
|
|
13
|
+
readonly timeZone?: string;
|
|
14
|
+
} | {
|
|
15
|
+
readonly kind: 'daily';
|
|
16
|
+
readonly time: string;
|
|
17
|
+
readonly timeZone?: string;
|
|
18
|
+
} | {
|
|
19
|
+
readonly kind: 'weekly';
|
|
20
|
+
readonly time: string;
|
|
21
|
+
readonly weekdays: readonly number[];
|
|
22
|
+
readonly timeZone?: string;
|
|
23
|
+
} | {
|
|
24
|
+
readonly kind: 'hourly';
|
|
25
|
+
readonly minute: number;
|
|
26
|
+
readonly timeZone?: string;
|
|
27
|
+
} | {
|
|
28
|
+
readonly kind: 'monthly';
|
|
29
|
+
readonly day: number;
|
|
30
|
+
readonly time: string;
|
|
31
|
+
readonly timeZone?: string;
|
|
32
|
+
} | {
|
|
33
|
+
readonly kind: 'custom';
|
|
34
|
+
readonly everyDays: number;
|
|
35
|
+
readonly time: string;
|
|
36
|
+
readonly timeZone?: string;
|
|
37
|
+
};
|
|
38
|
+
export interface WorkspaceOption {
|
|
39
|
+
readonly id: string;
|
|
40
|
+
readonly title: string;
|
|
41
|
+
readonly path: string;
|
|
42
|
+
}
|
|
43
|
+
export interface ModelOption {
|
|
44
|
+
readonly provider: string;
|
|
45
|
+
readonly model: string;
|
|
46
|
+
readonly label: string;
|
|
47
|
+
}
|
|
48
|
+
export interface AutomationViewModel {
|
|
49
|
+
readonly id: string;
|
|
50
|
+
readonly revision: number;
|
|
51
|
+
readonly name: string;
|
|
52
|
+
readonly prompt: string;
|
|
53
|
+
readonly status: AutomationStatus;
|
|
54
|
+
readonly schedule: AutomationSchedule;
|
|
55
|
+
readonly scheduleSummary: string;
|
|
56
|
+
readonly timeZone: string;
|
|
57
|
+
readonly permission: AutomationPermission;
|
|
58
|
+
readonly workspaceId?: string;
|
|
59
|
+
readonly cwd?: string;
|
|
60
|
+
readonly provider?: string | null;
|
|
61
|
+
readonly model?: string | null;
|
|
62
|
+
readonly reasoningEffort?: string | null | undefined;
|
|
63
|
+
readonly nextRunAt?: string;
|
|
64
|
+
readonly lastRunAt?: string;
|
|
65
|
+
readonly lastRunStatus?: AutomationRunStatus;
|
|
66
|
+
readonly createdAt: string;
|
|
67
|
+
readonly updatedAt: string;
|
|
68
|
+
}
|
|
69
|
+
export interface AutomationRunViewModel {
|
|
70
|
+
readonly id: string;
|
|
71
|
+
readonly automationId: string;
|
|
72
|
+
readonly automationName: string;
|
|
73
|
+
readonly status: AutomationRunStatus;
|
|
74
|
+
readonly trigger: 'schedule' | 'manual' | 'catch-up';
|
|
75
|
+
readonly scheduledFor: string;
|
|
76
|
+
readonly startedAt?: string;
|
|
77
|
+
readonly finishedAt?: string;
|
|
78
|
+
readonly sessionId?: string;
|
|
79
|
+
readonly summary?: string;
|
|
80
|
+
readonly error?: string;
|
|
81
|
+
readonly unread?: boolean;
|
|
82
|
+
}
|
|
83
|
+
export interface AutomationSnapshot {
|
|
84
|
+
readonly scope: {
|
|
85
|
+
readonly workspaceId?: string;
|
|
86
|
+
readonly workspaceName?: string;
|
|
87
|
+
readonly cwd: string;
|
|
88
|
+
};
|
|
89
|
+
readonly workspaces?: readonly WorkspaceOption[];
|
|
90
|
+
readonly models?: readonly ModelOption[];
|
|
91
|
+
readonly defaultModel?: ModelOption | null;
|
|
92
|
+
readonly skills?: readonly {
|
|
93
|
+
readonly id: string;
|
|
94
|
+
readonly name: string;
|
|
95
|
+
}[];
|
|
96
|
+
readonly automations: readonly AutomationViewModel[];
|
|
97
|
+
readonly runs: readonly AutomationRunViewModel[];
|
|
98
|
+
readonly serverNow: string;
|
|
99
|
+
}
|
|
100
|
+
export interface CreateAutomationInput {
|
|
101
|
+
readonly name: string;
|
|
102
|
+
readonly prompt: string;
|
|
103
|
+
readonly schedule: AutomationSchedule;
|
|
104
|
+
readonly timeZone: string;
|
|
105
|
+
readonly permission: AutomationPermission;
|
|
106
|
+
readonly workspaceId: string;
|
|
107
|
+
readonly cwd: string;
|
|
108
|
+
readonly provider?: string | null;
|
|
109
|
+
readonly model?: string | null;
|
|
110
|
+
readonly reasoningEffort?: string | null | undefined;
|
|
111
|
+
}
|
|
112
|
+
export interface SnapshotRequest {
|
|
113
|
+
readonly sessionId?: string;
|
|
114
|
+
}
|
|
115
|
+
export interface CreateRequest {
|
|
116
|
+
readonly sessionId?: string;
|
|
117
|
+
readonly input: CreateAutomationInput;
|
|
118
|
+
}
|
|
119
|
+
export interface MutateRequest {
|
|
120
|
+
readonly sessionId?: string;
|
|
121
|
+
readonly automationId: string;
|
|
122
|
+
readonly mutation: 'pause' | 'resume' | 'delete';
|
|
123
|
+
}
|
|
124
|
+
export interface UpdateRequest {
|
|
125
|
+
readonly sessionId?: string;
|
|
126
|
+
readonly automationId: string;
|
|
127
|
+
readonly input: CreateAutomationInput;
|
|
128
|
+
}
|
|
129
|
+
export interface RunNowRequest {
|
|
130
|
+
readonly sessionId?: string;
|
|
131
|
+
readonly automationId: string;
|
|
132
|
+
}
|
|
133
|
+
export interface MarkReadRequest {
|
|
134
|
+
readonly sessionId?: string;
|
|
135
|
+
readonly runId: string;
|
|
136
|
+
}
|
|
137
|
+
export interface AddWorkspaceRequest {
|
|
138
|
+
readonly sessionId?: string;
|
|
139
|
+
readonly path: string;
|
|
140
|
+
}
|
|
141
|
+
export interface RpcErrorValue {
|
|
142
|
+
readonly code: string;
|
|
143
|
+
readonly message: string;
|
|
144
|
+
readonly details?: unknown;
|
|
145
|
+
}
|
|
146
|
+
export type RpcResult<T> = {
|
|
147
|
+
readonly ok: true;
|
|
148
|
+
readonly value: T;
|
|
149
|
+
} | {
|
|
150
|
+
readonly ok: false;
|
|
151
|
+
readonly error: RpcErrorValue;
|
|
152
|
+
};
|
|
153
|
+
export declare function unwrapRpcResult<T>(value: unknown): T;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ClientRpc } from './contracts.js';
|
|
2
|
+
import type { AutomationSnapshot, CreateAutomationInput, MutateRequest } from './protocol.js';
|
|
3
|
+
export declare function isTransportError(error: unknown): boolean;
|
|
4
|
+
export interface AutomationClientState {
|
|
5
|
+
readonly phase: 'idle' | 'loading' | 'ready' | 'error';
|
|
6
|
+
readonly snapshot?: AutomationSnapshot;
|
|
7
|
+
readonly error?: string;
|
|
8
|
+
readonly refreshedAt?: number;
|
|
9
|
+
}
|
|
10
|
+
export interface AutomationStateSource {
|
|
11
|
+
getSnapshot(): AutomationClientState;
|
|
12
|
+
subscribe(listener: () => void): () => void;
|
|
13
|
+
}
|
|
14
|
+
export interface AutomationRuntime {
|
|
15
|
+
readonly source: AutomationStateSource;
|
|
16
|
+
refresh(): Promise<void>;
|
|
17
|
+
createAutomation(input: CreateAutomationInput): Promise<void>;
|
|
18
|
+
mutateAutomation(automationId: string, mutation: MutateRequest['mutation']): Promise<void>;
|
|
19
|
+
updateAutomation(automationId: string, input: CreateAutomationInput): Promise<void>;
|
|
20
|
+
runNow(automationId: string): Promise<void>;
|
|
21
|
+
markRunRead(runId: string): Promise<void>;
|
|
22
|
+
addWorkspace(path: string): Promise<{
|
|
23
|
+
id: string;
|
|
24
|
+
}>;
|
|
25
|
+
adoptSession(sessionId: string): Promise<void>;
|
|
26
|
+
forgetSession(sessionId: string): Promise<void>;
|
|
27
|
+
forgetAutomationSessions(automationId: string): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
export declare function createAutomationRuntime(rpc: ClientRpc): AutomationRuntime;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/** 侧栏定时树与原生任务列表的纯函数,供组件和单测共用。 */
|
|
2
|
+
export declare const AUTOMATION_SESSION_PREFIX = "dsh-automation-session-";
|
|
3
|
+
export declare const NATIVE_SIDEBAR_TAB_KEY = "dsh-automation.sidebar-tab";
|
|
4
|
+
export interface ScheduleRailSession {
|
|
5
|
+
readonly id: string;
|
|
6
|
+
readonly running: boolean;
|
|
7
|
+
readonly label: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ScheduleRailGroup {
|
|
10
|
+
readonly id: string;
|
|
11
|
+
readonly name: string;
|
|
12
|
+
readonly sessions: readonly ScheduleRailSession[];
|
|
13
|
+
}
|
|
14
|
+
export interface ScheduleRunLike {
|
|
15
|
+
readonly automationId: string;
|
|
16
|
+
readonly automationName?: string;
|
|
17
|
+
readonly sessionId?: string;
|
|
18
|
+
readonly status: string;
|
|
19
|
+
readonly startedAt?: string;
|
|
20
|
+
readonly scheduledFor: string;
|
|
21
|
+
}
|
|
22
|
+
export interface NativeSessionLike {
|
|
23
|
+
readonly id?: string;
|
|
24
|
+
readonly title?: string;
|
|
25
|
+
readonly blank?: boolean;
|
|
26
|
+
readonly origin?: string;
|
|
27
|
+
readonly updatedAt?: number | string;
|
|
28
|
+
readonly running?: boolean;
|
|
29
|
+
}
|
|
30
|
+
export interface NativeWorkspaceLike {
|
|
31
|
+
readonly id?: string;
|
|
32
|
+
readonly workspaceId?: string;
|
|
33
|
+
readonly title?: string;
|
|
34
|
+
readonly path?: string;
|
|
35
|
+
readonly sessionIds?: readonly string[];
|
|
36
|
+
}
|
|
37
|
+
export type NativeSidebarTab = 'tasks' | 'channels' | 'schedule';
|
|
38
|
+
export { formatRunStamp } from '../run-title.js';
|
|
39
|
+
/** 定时会话标题复刻任务树:优先用 Session 真实标题,没有再用执行时间兜底。 */
|
|
40
|
+
export declare function scheduledSessionTitle(liveTitle: string | undefined, fallbackLabel: string): string;
|
|
41
|
+
export declare function sessionUpdatedAtIso(value: number | string | undefined, fallback: string): string;
|
|
42
|
+
export declare function groupScheduledSessions(automations: readonly {
|
|
43
|
+
readonly id: string;
|
|
44
|
+
readonly name: string;
|
|
45
|
+
}[], runs: readonly ScheduleRunLike[]): ScheduleRailGroup[];
|
|
46
|
+
export declare function isNativeTaskSession(item: NativeSessionLike | undefined): boolean;
|
|
47
|
+
export declare function groupNativeTaskSessions(sessions: {
|
|
48
|
+
readonly ids?: readonly string[];
|
|
49
|
+
readonly byId?: Record<string, NativeSessionLike>;
|
|
50
|
+
}, workspaces: {
|
|
51
|
+
readonly items?: readonly NativeWorkspaceLike[];
|
|
52
|
+
readonly archivedSessionIds?: readonly string[];
|
|
53
|
+
} | undefined, ungroupedLabel: string): {
|
|
54
|
+
readonly id: string;
|
|
55
|
+
readonly label: string;
|
|
56
|
+
readonly sessions: readonly NativeSessionLike[];
|
|
57
|
+
}[];
|
|
58
|
+
export declare function readNativeSidebarTab(raw: string | null): NativeSidebarTab;
|
|
59
|
+
export declare function tabForSessionId(sessionId: string | null | undefined): NativeSidebarTab | undefined;
|
|
60
|
+
export declare function occupantLooksLikeCodexUi(value: unknown): boolean;
|
|
61
|
+
export declare function slotOccupantName(item: unknown): string;
|
|
62
|
+
export declare function hasCodexUiSidebar(entries: readonly unknown[] | undefined): boolean;
|
|
63
|
+
export interface SessionListState {
|
|
64
|
+
readonly ids?: readonly string[];
|
|
65
|
+
readonly byId?: Record<string, NativeSessionLike>;
|
|
66
|
+
readonly current?: string | null;
|
|
67
|
+
}
|
|
68
|
+
export declare function filterTaskSessionState<T extends SessionListState>(state: T | undefined): T;
|
|
69
|
+
export interface WorkspaceListState {
|
|
70
|
+
readonly items?: readonly NativeWorkspaceLike[];
|
|
71
|
+
readonly archivedSessionIds?: readonly string[];
|
|
72
|
+
}
|
|
73
|
+
export declare function openScheduledSession(id: string, openRuntime?: (sessionId: string) => void, openHost?: (sessionId: string) => void): void;
|
|
74
|
+
export declare function isHiddenSidebarSessionId(id: string): boolean;
|
|
75
|
+
export declare function filterWorkspaceListState<T extends WorkspaceListState>(state: T | undefined): T;
|
|
76
|
+
export type WrapperFlags = {
|
|
77
|
+
__dshAutomationWrapped?: unknown;
|
|
78
|
+
__dshAutomationOriginal?: unknown;
|
|
79
|
+
__imConnectWrapped?: unknown;
|
|
80
|
+
__imConnectOriginal?: unknown;
|
|
81
|
+
};
|
|
82
|
+
export declare function wrapperFlags(component: unknown): WrapperFlags;
|
|
83
|
+
export declare function isOwnAutomationWrapper(component: unknown): boolean;
|
|
84
|
+
export declare function isMarkedWorkspaceWrapper(component: unknown): boolean;
|
|
85
|
+
export declare function resolveOfficialTreeComponent(component: unknown): unknown;
|
|
86
|
+
export declare function isAutomationWorkspaceWrapper(item: unknown): boolean;
|
|
87
|
+
export declare function pickWrappableWorkspacesEntry(entries: readonly unknown[]): unknown;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function installStyles(): () => void;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { AutomationDefinition, AutomationRun, AutomationSchedule, CreateAutomationInput, DeleteAutomationPlan, UpdateAutomationInput } from './types.ts';
|
|
3
|
+
export declare const automationScheduleSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
4
|
+
kind: z.ZodLiteral<"once">;
|
|
5
|
+
at: z.ZodString;
|
|
6
|
+
timeZone: z.ZodString;
|
|
7
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
8
|
+
kind: z.ZodLiteral<"interval">;
|
|
9
|
+
everyMinutes: z.ZodNumber;
|
|
10
|
+
anchor: z.ZodString;
|
|
11
|
+
timeZone: z.ZodString;
|
|
12
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
13
|
+
kind: z.ZodLiteral<"daily">;
|
|
14
|
+
time: z.ZodString;
|
|
15
|
+
timeZone: z.ZodString;
|
|
16
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
17
|
+
kind: z.ZodLiteral<"weekly">;
|
|
18
|
+
weekdays: z.ZodArray<z.ZodEnum<{
|
|
19
|
+
MO: "MO";
|
|
20
|
+
TU: "TU";
|
|
21
|
+
WE: "WE";
|
|
22
|
+
TH: "TH";
|
|
23
|
+
FR: "FR";
|
|
24
|
+
SA: "SA";
|
|
25
|
+
SU: "SU";
|
|
26
|
+
}>>;
|
|
27
|
+
time: z.ZodString;
|
|
28
|
+
timeZone: z.ZodString;
|
|
29
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
30
|
+
kind: z.ZodLiteral<"hourly">;
|
|
31
|
+
minute: z.ZodNumber;
|
|
32
|
+
timeZone: z.ZodString;
|
|
33
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
34
|
+
kind: z.ZodLiteral<"monthly">;
|
|
35
|
+
day: z.ZodNumber;
|
|
36
|
+
time: z.ZodString;
|
|
37
|
+
timeZone: z.ZodString;
|
|
38
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
39
|
+
kind: z.ZodLiteral<"custom">;
|
|
40
|
+
everyDays: z.ZodNumber;
|
|
41
|
+
time: z.ZodString;
|
|
42
|
+
timeZone: z.ZodString;
|
|
43
|
+
}, z.core.$strip>], "kind">;
|
|
44
|
+
export declare const automationDefinitionSchema: z.ZodType<AutomationDefinition>;
|
|
45
|
+
export declare const automationRunSchema: z.ZodType<AutomationRun>;
|
|
46
|
+
export declare const automationDomainSpec: {
|
|
47
|
+
readonly name: "dsh_automation";
|
|
48
|
+
readonly version: 1;
|
|
49
|
+
readonly tables: {
|
|
50
|
+
readonly definitions: {
|
|
51
|
+
readonly valueSchema: z.ZodType<AutomationDefinition, unknown, z.core.$ZodTypeInternals<AutomationDefinition, unknown>>;
|
|
52
|
+
};
|
|
53
|
+
readonly runs: {
|
|
54
|
+
readonly valueSchema: z.ZodType<AutomationRun, unknown, z.core.$ZodTypeInternals<AutomationRun, unknown>>;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
export declare function createDefinition(input: CreateAutomationInput): AutomationDefinition;
|
|
59
|
+
export declare function updateDefinition(current: AutomationDefinition, input: UpdateAutomationInput): AutomationDefinition;
|
|
60
|
+
export declare function pauseDefinition(current: AutomationDefinition, now: string): AutomationDefinition;
|
|
61
|
+
export declare function resumeDefinition(current: AutomationDefinition, now: string): AutomationDefinition;
|
|
62
|
+
export declare function deleteDefinition(current: AutomationDefinition): DeleteAutomationPlan;
|
|
63
|
+
export declare function occurrenceKey(automationId: string, definitionRevision: number, scheduledFor: string): string;
|
|
64
|
+
export declare function runIdForOccurrence(key: string): string;
|
|
65
|
+
export declare function createScheduledRun(definition: AutomationDefinition, scheduledFor: string): AutomationRun;
|
|
66
|
+
export declare function createManualRun(definition: AutomationDefinition, scheduledFor: string, nonce?: string): AutomationRun;
|
|
67
|
+
export type { AutomationSchedule };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** 已认领 run 的独立 Agent 执行边界。 */
|
|
2
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
3
|
+
import type { AutomationDefinition, AutomationRun } from './types.ts';
|
|
4
|
+
interface SessionEventLike {
|
|
5
|
+
readonly seq: number;
|
|
6
|
+
readonly type: string;
|
|
7
|
+
readonly data: Record<string, any>;
|
|
8
|
+
}
|
|
9
|
+
export declare function unattendedToolGuardReason(name: string, args: unknown): string | undefined;
|
|
10
|
+
export interface RunCompletion {
|
|
11
|
+
readonly sessionId?: string;
|
|
12
|
+
readonly status: 'succeeded' | 'failed' | 'cancelled';
|
|
13
|
+
readonly summary?: string;
|
|
14
|
+
readonly error?: {
|
|
15
|
+
readonly code: string;
|
|
16
|
+
readonly message: string;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export interface ExecutorConfig {
|
|
20
|
+
readonly runTimeoutMs: number;
|
|
21
|
+
readonly sessionId: string;
|
|
22
|
+
readonly signal?: AbortSignal;
|
|
23
|
+
}
|
|
24
|
+
export declare function summarizeRun(events: readonly SessionEventLike[], firstSeq: number): {
|
|
25
|
+
readonly text: string;
|
|
26
|
+
readonly reason?: Record<string, any>;
|
|
27
|
+
};
|
|
28
|
+
export declare function executeAutomationRun(ctx: Context, definition: AutomationDefinition, run: AutomationRun, config: ExecutorConfig): Promise<RunCompletion>;
|
|
29
|
+
export declare function pinAutomationSessionTitle(ctx: Context, session: unknown, title: string): void;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** 独立自动化的 Cordis Host 插件入口。 */
|
|
2
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
3
|
+
export declare const name = "dsh-automation";
|
|
4
|
+
export declare const inject: string[];
|
|
5
|
+
export interface Config {
|
|
6
|
+
readonly maxConcurrentRuns?: number;
|
|
7
|
+
readonly runTimeoutMinutes?: number;
|
|
8
|
+
readonly misfireGraceMinutes?: number;
|
|
9
|
+
readonly historyLimit?: number;
|
|
10
|
+
}
|
|
11
|
+
export declare const Config: any;
|
|
12
|
+
export declare function needsHumanApproval(exec: {
|
|
13
|
+
readonly name: string;
|
|
14
|
+
readonly arguments?: unknown;
|
|
15
|
+
readonly signal: AbortSignal;
|
|
16
|
+
}, isMountedAgent: boolean): boolean;
|
|
17
|
+
export declare function humanApprovalReason(toolName: string): string;
|
|
18
|
+
export declare function apply(ctx: Context, rawConfig: Config): Promise<void>;
|
|
19
|
+
export type * from './types.ts';
|
|
20
|
+
export { automationDomainSpec } from './domain.ts';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AutomationSchedule } from './types.ts';
|
|
2
|
+
export declare function assertValidSchedule(schedule: AutomationSchedule): void;
|
|
3
|
+
export declare function normalizeSchedule(schedule: AutomationSchedule): AutomationSchedule;
|
|
4
|
+
export declare function scheduleToRRule(schedule: AutomationSchedule): string;
|
|
5
|
+
export declare function nextOccurrence(schedule: AutomationSchedule, afterExclusive: string): string | null;
|
|
6
|
+
export declare function latestDueOccurrence(schedule: AutomationSchedule, now: string): string | null;
|
|
7
|
+
export declare function occurrencesBetween(schedule: AutomationSchedule, afterExclusive: string, untilInclusive: string, limit?: number): string[];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** 仅 loopback 的 Web 客户端 RPC 适配器。 */
|
|
2
|
+
import type { AutomationService } from './service.ts';
|
|
3
|
+
interface RpcContext {
|
|
4
|
+
readonly connection: {
|
|
5
|
+
readonly rpc: {
|
|
6
|
+
handle(channel: string, handler: (endpoint: string, payload: unknown, signal: AbortSignal) => Promise<unknown>, options: {
|
|
7
|
+
readonly authority: 'loopback' | 'trusted-host';
|
|
8
|
+
}): () => Promise<void>;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export declare function registerAutomationRpc(ctx: RpcContext, service: AutomationService): () => Promise<void>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/** 持久化定义、occurrence 认领、时钟与执行调度。 */
|
|
2
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
3
|
+
import type { AutomationDefinition, AutomationRun, AutomationSchedule, PermissionPreset, UpdateAutomationInput } from './types.ts';
|
|
4
|
+
export declare const AUTOMATION_SESSION_PREFIX = "dsh-automation-session-";
|
|
5
|
+
export interface AutomationConfig {
|
|
6
|
+
readonly maxConcurrentRuns: number;
|
|
7
|
+
readonly runTimeoutMs: number;
|
|
8
|
+
readonly misfireGraceMs: number;
|
|
9
|
+
readonly historyLimit: number;
|
|
10
|
+
}
|
|
11
|
+
export interface WorkspaceOption {
|
|
12
|
+
readonly id: string;
|
|
13
|
+
readonly title: string;
|
|
14
|
+
readonly path: string;
|
|
15
|
+
}
|
|
16
|
+
export interface ModelOption {
|
|
17
|
+
readonly provider: string;
|
|
18
|
+
readonly model: string;
|
|
19
|
+
readonly label: string;
|
|
20
|
+
}
|
|
21
|
+
export interface CreateRequest {
|
|
22
|
+
readonly name: string;
|
|
23
|
+
readonly prompt: string;
|
|
24
|
+
readonly schedule: AutomationSchedule;
|
|
25
|
+
readonly permissionPreset?: PermissionPreset;
|
|
26
|
+
readonly workspaceId?: string;
|
|
27
|
+
readonly cwd?: string;
|
|
28
|
+
readonly provider?: string | null;
|
|
29
|
+
readonly model?: string | null;
|
|
30
|
+
readonly reasoningEffort?: string | null;
|
|
31
|
+
readonly agentPreset?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface AutomationScope {
|
|
34
|
+
readonly sessionId: string;
|
|
35
|
+
readonly creatorKind: 'agent' | 'web';
|
|
36
|
+
readonly hostWide?: boolean;
|
|
37
|
+
}
|
|
38
|
+
export interface AutomationSnapshot {
|
|
39
|
+
readonly generatedAt: string;
|
|
40
|
+
readonly workspace: WorkspaceOption | null;
|
|
41
|
+
readonly workspaces: readonly WorkspaceOption[];
|
|
42
|
+
readonly models: readonly ModelOption[];
|
|
43
|
+
readonly defaultModel: ModelOption | null;
|
|
44
|
+
readonly skills: readonly {
|
|
45
|
+
readonly id: string;
|
|
46
|
+
readonly name: string;
|
|
47
|
+
}[];
|
|
48
|
+
readonly definitions: readonly AutomationDefinitionView[];
|
|
49
|
+
readonly runs: readonly AutomationRun[];
|
|
50
|
+
}
|
|
51
|
+
export interface AutomationDefinitionView extends AutomationDefinition {
|
|
52
|
+
readonly nextRunAt: string | null;
|
|
53
|
+
readonly lastRun: AutomationRun | null;
|
|
54
|
+
}
|
|
55
|
+
interface SessionEventLike {
|
|
56
|
+
readonly type: string;
|
|
57
|
+
readonly data: unknown;
|
|
58
|
+
}
|
|
59
|
+
export declare class AutomationService {
|
|
60
|
+
private readonly ctx;
|
|
61
|
+
private readonly domain;
|
|
62
|
+
private readonly config;
|
|
63
|
+
private definitions;
|
|
64
|
+
private runs;
|
|
65
|
+
private timer;
|
|
66
|
+
private operationTail;
|
|
67
|
+
private pumpScheduled;
|
|
68
|
+
private requested;
|
|
69
|
+
private started;
|
|
70
|
+
private stopping;
|
|
71
|
+
private readonly active;
|
|
72
|
+
private constructor();
|
|
73
|
+
static open(ctx: Context, config: AutomationConfig): Promise<AutomationService>;
|
|
74
|
+
start(): void;
|
|
75
|
+
ownsSession(sessionId: string, events?: readonly SessionEventLike[]): boolean;
|
|
76
|
+
dispose(): Promise<void>;
|
|
77
|
+
snapshot(scope: AutomationScope, signal?: AbortSignal): Promise<AutomationSnapshot>;
|
|
78
|
+
create(scope: AutomationScope, request: CreateRequest, signal?: AbortSignal): Promise<AutomationDefinition>;
|
|
79
|
+
update(scope: AutomationScope, id: string, input: Omit<UpdateAutomationInput, 'now'> & {
|
|
80
|
+
readonly status?: 'active' | 'paused';
|
|
81
|
+
}, signal?: AbortSignal): Promise<AutomationDefinition>;
|
|
82
|
+
delete(scope: AutomationScope, id: string, signal?: AbortSignal): Promise<{
|
|
83
|
+
readonly id: string;
|
|
84
|
+
readonly deleted: boolean;
|
|
85
|
+
}>;
|
|
86
|
+
runNow(scope: AutomationScope, id: string, signal?: AbortSignal): Promise<AutomationRun>;
|
|
87
|
+
markRead(scope: AutomationScope, runId: string, signal?: AbortSignal): Promise<AutomationRun>;
|
|
88
|
+
forgetSession(sessionId: string): Promise<void>;
|
|
89
|
+
forgetAutomationSessions(automationId: string): Promise<void>;
|
|
90
|
+
adoptSession(sessionId: string): Promise<void>;
|
|
91
|
+
addWorkspace(path: string): Promise<WorkspaceOption>;
|
|
92
|
+
private collectOptions;
|
|
93
|
+
private resolveCreateTarget;
|
|
94
|
+
private resolveScope;
|
|
95
|
+
private ownedDefinition;
|
|
96
|
+
private requestPump;
|
|
97
|
+
private pumpOnce;
|
|
98
|
+
private claimLatestDue;
|
|
99
|
+
private startQueuedRuns;
|
|
100
|
+
private startRun;
|
|
101
|
+
private executeRun;
|
|
102
|
+
private armNextTimer;
|
|
103
|
+
private armRetryTimer;
|
|
104
|
+
private clearTimer;
|
|
105
|
+
private serialize;
|
|
106
|
+
private recoverInterruptedRuns;
|
|
107
|
+
private pruneWorkspaceHistory;
|
|
108
|
+
private pruneAllHistory;
|
|
109
|
+
}
|
|
110
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** 绑定到单个 root Agent 工作区的管理工具。 */
|
|
2
|
+
import type { AutomationService } from './service.ts';
|
|
3
|
+
interface ToolAgent {
|
|
4
|
+
readonly id: string;
|
|
5
|
+
readonly ctx: {
|
|
6
|
+
readonly tools: {
|
|
7
|
+
register(definition: unknown): () => void;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export declare function registerAutomationTools(service: AutomationService, agent: ToolAgent): () => void;
|
|
12
|
+
export {};
|