@michengai/dsh-automation 0.1.3 → 0.1.5
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/README.md +54 -31
- package/README.zh-CN.md +50 -27
- package/assets/branding/dsh-banner.png +0 -0
- package/assets/screenshots/chat-approval.png +0 -0
- package/assets/screenshots/chat-create.png +0 -0
- package/assets/screenshots/chat-created.png +0 -0
- package/assets/screenshots/settings-runs.png +0 -0
- package/assets/screenshots/settings-tasks.png +0 -0
- package/assets/screenshots/workspace-scheduled.png +0 -0
- package/lib/client.js +14 -2
- package/lib/client.js.map +2 -2
- package/lib/index.js +35 -1
- package/lib/types/client/schedule-rail-model.d.ts +2 -0
- package/lib/types/service.d.ts +2 -0
- package/package.json +2 -1
package/lib/index.js
CHANGED
|
@@ -22008,6 +22008,7 @@ var AutomationService = class _AutomationService {
|
|
|
22008
22008
|
service.definitions = domain2.table("definitions");
|
|
22009
22009
|
service.runs = domain2.table("runs");
|
|
22010
22010
|
await service.recoverInterruptedRuns();
|
|
22011
|
+
await service.reconcileMissingSessions();
|
|
22011
22012
|
await service.pruneAllHistory();
|
|
22012
22013
|
return service;
|
|
22013
22014
|
} catch (error51) {
|
|
@@ -22167,6 +22168,32 @@ var AutomationService = class _AutomationService {
|
|
|
22167
22168
|
}
|
|
22168
22169
|
});
|
|
22169
22170
|
}
|
|
22171
|
+
async reconcileMissingSessions() {
|
|
22172
|
+
const known = await this.knownSessionIds();
|
|
22173
|
+
if (known === void 0) return;
|
|
22174
|
+
await this.serialize(async () => {
|
|
22175
|
+
for (const [runId, run] of this.runs.entries()) {
|
|
22176
|
+
if (typeof run.sessionId !== "string" || run.sessionId === "") continue;
|
|
22177
|
+
if (known.has(run.sessionId)) continue;
|
|
22178
|
+
await this.runs.put(runId, { ...run, sessionId: null });
|
|
22179
|
+
}
|
|
22180
|
+
});
|
|
22181
|
+
}
|
|
22182
|
+
async knownSessionIds() {
|
|
22183
|
+
const live = this.ctx.sessions;
|
|
22184
|
+
const persistence = this.ctx.get?.("sessionPersistence");
|
|
22185
|
+
const canListLive = typeof live?.list === "function";
|
|
22186
|
+
const canListStored = typeof persistence?.list === "function";
|
|
22187
|
+
if (!canListLive && !canListStored) return void 0;
|
|
22188
|
+
const ids = /* @__PURE__ */ new Set();
|
|
22189
|
+
if (canListLive && live?.list !== void 0) {
|
|
22190
|
+
for (const session of live.list()) ids.add(String(session.id));
|
|
22191
|
+
}
|
|
22192
|
+
if (canListStored && persistence?.list !== void 0) {
|
|
22193
|
+
for (const header of await persistence.list()) ids.add(String(header.id));
|
|
22194
|
+
}
|
|
22195
|
+
return ids;
|
|
22196
|
+
}
|
|
22170
22197
|
async forgetAutomationSessions(automationId) {
|
|
22171
22198
|
const id = automationId.trim();
|
|
22172
22199
|
if (id === "") return;
|
|
@@ -22819,13 +22846,15 @@ async function apply(ctx, rawConfig) {
|
|
|
22819
22846
|
};
|
|
22820
22847
|
let stopPrompt = () => {
|
|
22821
22848
|
};
|
|
22849
|
+
let stopSessionGone = () => {
|
|
22850
|
+
};
|
|
22822
22851
|
let removeRpc = async () => {
|
|
22823
22852
|
};
|
|
22824
22853
|
const cleanup = async () => {
|
|
22825
22854
|
if (cleaned) return;
|
|
22826
22855
|
cleaned = true;
|
|
22827
22856
|
alive = false;
|
|
22828
|
-
for (const stop of [stopCreated, stopDisposed, stopApproval, stopPrompt]) {
|
|
22857
|
+
for (const stop of [stopCreated, stopDisposed, stopApproval, stopPrompt, stopSessionGone]) {
|
|
22829
22858
|
try {
|
|
22830
22859
|
stop();
|
|
22831
22860
|
} catch (error51) {
|
|
@@ -22861,6 +22890,11 @@ async function apply(ctx, rawConfig) {
|
|
|
22861
22890
|
stopDisposed = ctx.on("agent/disposed", ({ agent }) => {
|
|
22862
22891
|
agentTools.delete(agent);
|
|
22863
22892
|
});
|
|
22893
|
+
stopSessionGone = ctx.on("session/disposed", (session) => {
|
|
22894
|
+
const id = String(session?.id ?? "");
|
|
22895
|
+
if (id === "") return;
|
|
22896
|
+
void service.forgetSession(id);
|
|
22897
|
+
});
|
|
22864
22898
|
const systemPrompt = ctx.get("systemPrompt");
|
|
22865
22899
|
if (typeof systemPrompt?.section === "function") {
|
|
22866
22900
|
stopPrompt = systemPrompt.section({
|
|
@@ -44,6 +44,8 @@ export declare function groupScheduledSessions(automations: readonly {
|
|
|
44
44
|
readonly id: string;
|
|
45
45
|
readonly name: string;
|
|
46
46
|
}[], runs: readonly ScheduleRunLike[]): ScheduleRailGroup[];
|
|
47
|
+
/** 归档中的、以及宿主已经不认识的 Session,都不应再出现在定时页。 */
|
|
48
|
+
export declare function keepScheduledSessionLink(sessionId: string | undefined, archived: ReadonlySet<string>, presentIds?: ReadonlySet<string>): boolean;
|
|
47
49
|
export declare function collectScheduledSessionIds(runs: readonly {
|
|
48
50
|
readonly sessionId?: string | null;
|
|
49
51
|
}[] | undefined): Set<string>;
|
package/lib/types/service.d.ts
CHANGED
|
@@ -86,6 +86,8 @@ export declare class AutomationService {
|
|
|
86
86
|
runNow(scope: AutomationScope, id: string, signal?: AbortSignal): Promise<AutomationRun>;
|
|
87
87
|
markRead(scope: AutomationScope, runId: string, signal?: AbortSignal): Promise<AutomationRun>;
|
|
88
88
|
forgetSession(sessionId: string): Promise<void>;
|
|
89
|
+
reconcileMissingSessions(): Promise<void>;
|
|
90
|
+
private knownSessionIds;
|
|
89
91
|
forgetAutomationSessions(automationId: string): Promise<void>;
|
|
90
92
|
adoptSession(sessionId: string): Promise<void>;
|
|
91
93
|
addWorkspace(path: string): Promise<WorkspaceOption>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@michengai/dsh-automation",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "在独立 DSH Session 中按计划执行编码任务,支持 Web 设置页与 Agent 双入口管理。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"files": [
|
|
20
20
|
"lib",
|
|
21
|
+
"assets",
|
|
21
22
|
"docs",
|
|
22
23
|
"cordis.patch.yml",
|
|
23
24
|
"README.md",
|