@khorsheed/dsh-local-agent-dsh 0.1.0-rc.6
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.en.md +150 -0
- package/README.i18n.yaml +6 -0
- package/README.md +151 -0
- package/cordis.patch.yml +24 -0
- package/lib/client.js +1115 -0
- package/lib/dsh-cli-provider-UhWvivte.js +1701 -0
- package/lib/dsh-cli-provider.js +3 -0
- package/lib/index.js +624 -0
- package/lib/invariant.js +33 -0
- package/lib/provision.js +602 -0
- package/lib/records.js +109 -0
- package/lib/session-log-DOsSz56-.js +88 -0
- package/lib/types/client/SettingsCard.d.ts +78 -0
- package/lib/types/client/SettingsCard.js +200 -0
- package/lib/types/client/icons.d.ts +18 -0
- package/lib/types/client/icons.js +2 -0
- package/lib/types/client/index.d.ts +45 -0
- package/lib/types/client/index.js +88 -0
- package/lib/types/client/locales.d.ts +76 -0
- package/lib/types/client/locales.js +67 -0
- package/lib/types/dsh-cli-provider.d.ts +213 -0
- package/lib/types/dsh-cli-provider.js +733 -0
- package/lib/types/index.d.ts +124 -0
- package/lib/types/index.js +347 -0
- package/lib/types/invariant.d.ts +16 -0
- package/lib/types/invariant.js +37 -0
- package/lib/types/live-driver.d.ts +180 -0
- package/lib/types/live-driver.js +887 -0
- package/lib/types/live-switch.d.ts +76 -0
- package/lib/types/live-switch.js +100 -0
- package/lib/types/model-broker.d.ts +86 -0
- package/lib/types/model-broker.js +149 -0
- package/lib/types/model-catalog.d.ts +27 -0
- package/lib/types/model-catalog.js +71 -0
- package/lib/types/provision.d.ts +382 -0
- package/lib/types/provision.js +656 -0
- package/lib/types/records.d.ts +41 -0
- package/lib/types/records.js +125 -0
- package/lib/types/session-log.d.ts +58 -0
- package/lib/types/session-log.js +83 -0
- package/lib/types/session-mirror.d.ts +155 -0
- package/lib/types/session-mirror.js +451 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +121 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import type { LocalAgentResolvedConfiguration } from '@khorsheed/dsh-local-agent/types';
|
|
2
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
3
|
+
import type { Session } from '@deepseek-ai/dsh-session';
|
|
4
|
+
import { type SubagentRun, type SubagentStartRequest } from '@deepseek-ai/dsh-subagent';
|
|
5
|
+
import type { LocalAgentDshConfig } from './index.ts';
|
|
6
|
+
import { type DshLiveMirrorGranularity } from './session-mirror.ts';
|
|
7
|
+
/** Default idle lifetime of an unused resident runtime before reclaim. */
|
|
8
|
+
export declare const DEFAULT_LIVE_IDLE_MS: number;
|
|
9
|
+
/** Default timeout for a wire request acknowledgement. */
|
|
10
|
+
export declare const DEFAULT_LIVE_REQUEST_TIMEOUT_MS = 30000;
|
|
11
|
+
/** Default timeout for the serve handshake (a cold sub-dsh boot can be slow). */
|
|
12
|
+
export declare const DEFAULT_LIVE_INITIALIZE_TIMEOUT_MS = 60000;
|
|
13
|
+
/** Bounded wait for an interrupted turn to converge while a run disposes. */
|
|
14
|
+
export declare const DEFAULT_LIVE_DISPOSE_CONVERGE_MS = 5000;
|
|
15
|
+
/** How long the channel stays broken before a round retries live. */
|
|
16
|
+
export declare const DEFAULT_LIVE_CHANNEL_RETRY_MS: number;
|
|
17
|
+
/**
|
|
18
|
+
* The serve channel could not come up (spawn failure or handshake
|
|
19
|
+
* timeout/mismatch). The provider catches exactly this and falls back to the
|
|
20
|
+
* exec one-shot; any other error is a real round failure.
|
|
21
|
+
*/
|
|
22
|
+
export declare class LiveChannelUnavailableError extends Error {
|
|
23
|
+
constructor(message: string);
|
|
24
|
+
}
|
|
25
|
+
/** Internal timeouts; tests inject small values. */
|
|
26
|
+
export interface DshLiveDriverTimeouts {
|
|
27
|
+
readonly initializeMs: number;
|
|
28
|
+
readonly requestMs: number;
|
|
29
|
+
readonly convergeMs: number;
|
|
30
|
+
/** How long a broken channel stays on the exec fallback before a retry. */
|
|
31
|
+
readonly channelRetryMs: number;
|
|
32
|
+
}
|
|
33
|
+
/** Fully resolved inputs for one live round (the live counterpart of DshCliRunSpec). */
|
|
34
|
+
export interface DshLiveRoundSpec {
|
|
35
|
+
/** Parent Session workspace; also the runtime process cwd. */
|
|
36
|
+
readonly cwd: string;
|
|
37
|
+
/** The `dsh` harness's scoped home, injected as the runtime's `$DSH_HOME`. */
|
|
38
|
+
readonly homeDir: string;
|
|
39
|
+
/** dsh subagent session recording this delegation (always live on this path). */
|
|
40
|
+
readonly childSession: Session;
|
|
41
|
+
/** The sub-dsh session id — the caller-supplied uuid, == the child session id. */
|
|
42
|
+
readonly sessionId: string;
|
|
43
|
+
/** The delegating session (member-channel registration). */
|
|
44
|
+
readonly parentSessionId: string;
|
|
45
|
+
/** Resume round: continue the session, appending under this turn number. */
|
|
46
|
+
readonly resume?: {
|
|
47
|
+
readonly turn: number;
|
|
48
|
+
} | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* The member's START model — the delegation's own requested model, or the
|
|
51
|
+
* composer's session-level override, as resolved by the provider. When it
|
|
52
|
+
* names one, a resident runtime bound to a DIFFERENT model is retired
|
|
53
|
+
* before the spawn so the round respawns onto it (the sub-dsh session
|
|
54
|
+
* resumes from disk — only the process is replaced). Absent means the
|
|
55
|
+
* spawn resolver decides (override → settings).
|
|
56
|
+
*/
|
|
57
|
+
readonly startModel?: string | undefined;
|
|
58
|
+
readonly configuration?: LocalAgentResolvedConfiguration;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The live driver owns every resident runtime of this provider generation.
|
|
62
|
+
* The LiveDriverSwitch builds a generation when the settings resolve live on,
|
|
63
|
+
* retires one with {@link DshLiveDriver.drain} (never interrupts), and
|
|
64
|
+
* disposes with the enabled toggle (disposeAll).
|
|
65
|
+
*/
|
|
66
|
+
export declare class DshLiveDriver {
|
|
67
|
+
private readonly ctx;
|
|
68
|
+
private readonly config;
|
|
69
|
+
private readonly timeouts;
|
|
70
|
+
private readonly runtimes;
|
|
71
|
+
/** In-flight spawns by member: concurrent rounds share one, disposeAll waits them out. */
|
|
72
|
+
private readonly ensuring;
|
|
73
|
+
private readonly idleTimers;
|
|
74
|
+
/** Per-member round serialization (the resume lock covers resume-vs-resume only). */
|
|
75
|
+
private readonly roundChains;
|
|
76
|
+
/** When the channel last failed its spawn/handshake probe (breaker with cooldown). */
|
|
77
|
+
private channelBrokenAt;
|
|
78
|
+
private disposed;
|
|
79
|
+
/**
|
|
80
|
+
* Set by drain() (a settings-driven generation handoff): new rounds are
|
|
81
|
+
* refused so the provider falls back to exec, while in-flight rounds finish
|
|
82
|
+
* on their runtime undisturbed. Unlike `disposed`, the driver still serves
|
|
83
|
+
* what it already accepted.
|
|
84
|
+
*/
|
|
85
|
+
private draining;
|
|
86
|
+
/** Aborts in-flight spawns when the driver is disposed mid-handshake. */
|
|
87
|
+
private readonly disposeController;
|
|
88
|
+
constructor(ctx: Context, config: LocalAgentDshConfig & {
|
|
89
|
+
/**
|
|
90
|
+
* Resolver for the member's configured model, read at each RUNTIME
|
|
91
|
+
* SPAWN (the serve process is where a live round's model binds, through
|
|
92
|
+
* its `--model` flag). Receives the member's child session id so the
|
|
93
|
+
* session-level override can outrank the settings value; absent, or
|
|
94
|
+
* resolving to nothing, the spawn carries no `--model` and the sub-dsh
|
|
95
|
+
* inherits the host instance's default selection.
|
|
96
|
+
*/
|
|
97
|
+
modelFor?: (childSessionId: string) => string | undefined;
|
|
98
|
+
}, timeouts?: DshLiveDriverTimeouts);
|
|
99
|
+
/**
|
|
100
|
+
* Whether the channel is in its post-failure cooldown. A spawn/handshake
|
|
101
|
+
* failure trips the breaker (rounds fall back to exec), but only for
|
|
102
|
+
* `channelRetryMs` — a transient boot fault must not disable live driving
|
|
103
|
+
* until the next plugin reload.
|
|
104
|
+
*/
|
|
105
|
+
get disabled(): boolean;
|
|
106
|
+
/** Count of resident runtimes currently registered (zombie accounting in tests). */
|
|
107
|
+
get liveCount(): number;
|
|
108
|
+
private clearIdleTimer;
|
|
109
|
+
/** Arm the idle reaper; every round settlement re-arms it. */
|
|
110
|
+
private armIdleTimer;
|
|
111
|
+
/** Reclaim one runtime: deregister, wire shutdown, terminate ladder, member release. */
|
|
112
|
+
private reclaim;
|
|
113
|
+
/** Reclaim every runtime (plugin unload); no process survives the profile. */
|
|
114
|
+
disposeAll(): Promise<void>;
|
|
115
|
+
/**
|
|
116
|
+
* True while the member's runtime exists or is being spawned. The settings
|
|
117
|
+
* controller gates a new generation on this: a fresh driver must not serve
|
|
118
|
+
* a member whose retiring generation still hosts the (same) sub-dsh session.
|
|
119
|
+
*/
|
|
120
|
+
hasRuntime(key: string): boolean;
|
|
121
|
+
/** @deprecated Compatibility no-op: live output is always incremental. */
|
|
122
|
+
setLiveMirrorGranularity(_granularity: DshLiveMirrorGranularity): void;
|
|
123
|
+
/**
|
|
124
|
+
* Drain for a settings-driven generation handoff: refuse new rounds (the
|
|
125
|
+
* provider's catch falls back to exec), let every in-flight round finish on
|
|
126
|
+
* its runtime, then reclaim. Resolves when no runtime or spawn remains.
|
|
127
|
+
* Unlike disposeAll, in-flight work is never interrupted.
|
|
128
|
+
*/
|
|
129
|
+
drain(): Promise<void>;
|
|
130
|
+
/**
|
|
131
|
+
* The model the member's live runtime bound at spawn: the identifier, or
|
|
132
|
+
* undefined when the runtime spawned with no `--model`. Null when the
|
|
133
|
+
* member has no live runtime in this generation — the broker's switch check
|
|
134
|
+
* distinguishes "no runtime to retire" from "runtime bound to no model".
|
|
135
|
+
*/
|
|
136
|
+
boundModelOf(key: string): string | undefined | null;
|
|
137
|
+
/**
|
|
138
|
+
* Retire the member's resident runtime so the NEXT round respawns (the
|
|
139
|
+
* sub-dsh session itself carries over via the on-disk resume). The
|
|
140
|
+
* composer's model switch calls this after storing the new override; the
|
|
141
|
+
* caller guarantees no round is in flight for the member.
|
|
142
|
+
*/
|
|
143
|
+
retireRuntime(key: string): Promise<void>;
|
|
144
|
+
/**
|
|
145
|
+
* The member's live runtime, spawning it (once per member at a time) when
|
|
146
|
+
* absent or dead. `signal` abandons the spawn on cancellation.
|
|
147
|
+
*/
|
|
148
|
+
private ensureRuntime;
|
|
149
|
+
/**
|
|
150
|
+
* Spawn the member's resident runtime and prove the wire with a handshake.
|
|
151
|
+
* Spawn/handshake failure trips the channel breaker (exec fallback) and
|
|
152
|
+
* throws {@link LiveChannelUnavailableError}; a later crash is NOT a broken
|
|
153
|
+
* channel — the next round re-spawns and resumes the on-disk session. A
|
|
154
|
+
* cancellation mid-spawn reclaims the half-started runtime and throws the
|
|
155
|
+
* abort instead, without touching the breaker.
|
|
156
|
+
*/
|
|
157
|
+
private spawnRuntime;
|
|
158
|
+
private markChannelBroken;
|
|
159
|
+
/**
|
|
160
|
+
* Drive one delegation round on the member's resident runtime. Rounds of
|
|
161
|
+
* one member are strictly serialized: the facade's resume lock covers
|
|
162
|
+
* resume-vs-resume only, and a resume racing an in-flight fresh round would
|
|
163
|
+
* otherwise overwrite the runtime's single notification sink and strand
|
|
164
|
+
* the earlier round forever.
|
|
165
|
+
*/
|
|
166
|
+
/** Prepare the owned headless agent and validate its adapter without a model turn. */
|
|
167
|
+
prepare(spec: DshLiveRoundSpec, signal: AbortSignal): Promise<void>;
|
|
168
|
+
startRound(request: SubagentStartRequest, spec: DshLiveRoundSpec): Promise<SubagentRun>;
|
|
169
|
+
/**
|
|
170
|
+
* The serialized round body. Mirrors the exec run's settlement contract
|
|
171
|
+
* exactly (settleRunResult + turn/end bookkeeping) so the facade, the
|
|
172
|
+
* tool, and the projections cannot tell the difference — except `cancel`
|
|
173
|
+
* is a runtime interrupt and the process survives. Cancellation is honored
|
|
174
|
+
* in EVERY window: a slow spawn/handshake or a slow accept races the abort
|
|
175
|
+
* signal and settles aborted instead of running the turn to completion
|
|
176
|
+
* unwatched.
|
|
177
|
+
*/
|
|
178
|
+
private startRoundLocked;
|
|
179
|
+
}
|
|
180
|
+
//# sourceMappingURL=live-driver.d.ts.map
|