@thready-web/dsh-bot-plugin 0.1.0-beta.0 → 0.1.0-beta.10
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 +109 -1
- package/client.js +646 -621
- package/dist/approvals.js +160 -0
- package/dist/authorization.js +225 -0
- package/dist/cli.js +32 -12
- package/dist/context.js +59 -17
- package/dist/cron.js +1 -1
- package/dist/cua-access.js +79 -0
- package/dist/desk.js +314 -37
- package/dist/engine.js +178 -84
- package/dist/fs-safe.js +1 -1
- package/dist/host.js +1 -0
- package/dist/http-plugin.js +14 -4
- package/dist/http.js +383 -85
- package/dist/inbox.js +51 -40
- package/dist/index.js +190 -47
- package/dist/live-diff.js +3 -1
- package/dist/live-snapshot.js +2 -13
- package/dist/log/canonical.js +37 -0
- package/dist/log/plan.js +62 -0
- package/dist/log/routes.js +144 -0
- package/dist/log/snapshot-service.js +76 -0
- package/dist/log/source.js +173 -0
- package/dist/memory-catalog.js +798 -0
- package/dist/permissions.js +86 -0
- package/dist/provision.js +2 -0
- package/dist/questions.js +407 -0
- package/dist/runtime-registry.js +4 -4
- package/dist/session-files.js +2 -2
- package/dist/session-previews.js +5 -1
- package/dist/store.js +20 -5
- package/dist/tools.js +150 -32
- package/dist/triggers.js +83 -39
- package/dist/work-admit.js +222 -25
- package/dist/work-child.js +17 -9
- package/dist/work-http.js +33 -2
- package/dist/work-ledger.js +256 -16
- package/dist/work-mock-host.js +9 -6
- package/dist/work-mock.js +29 -19
- package/dist/work-tickets.js +423 -96
- package/dist/work-tools.js +43 -6
- package/dist/work-worker.js +1028 -207
- package/dist/workspace-files.js +319 -0
- package/dist/workspace-image.js +91 -0
- package/fixtures/mock-llm.mjs +17 -2
- package/package.json +15 -5
- package/public/assets/SourceEditor-BEQaScgR.js +669 -0
- package/public/assets/SourceEditor-CJwK846Z.css +1 -0
- package/public/assets/abap-CRCWOmpq.js +1 -0
- package/public/assets/apex-DnsZk_dE.js +1 -0
- package/public/assets/azcli-1IWB1ccx.js +1 -0
- package/public/assets/bat-DPkNLes8.js +1 -0
- package/public/assets/bicep-Corcdgou.js +2 -0
- package/public/assets/cameligo-CGrWLZr3.js +1 -0
- package/public/assets/clojure-D9WOWImG.js +1 -0
- package/public/assets/codicon-DCmgc-ay.ttf +0 -0
- package/public/assets/coffee-B7EJu28W.js +1 -0
- package/public/assets/cpp-SEyurbux.js +1 -0
- package/public/assets/csharp-BoL64M5l.js +1 -0
- package/public/assets/csp-C46ZqvIl.js +1 -0
- package/public/assets/css-DQU6DXDx.js +3 -0
- package/public/assets/css.worker-DYpkewsP.js +79 -0
- package/public/assets/cssMode-gpcjCFFS.js +4 -0
- package/public/assets/cypher-D84EuPTj.js +1 -0
- package/public/assets/dart-D8lhlL1r.js +1 -0
- package/public/assets/dockerfile-DLk6rpji.js +1 -0
- package/public/assets/ecl-BO6FnfXk.js +1 -0
- package/public/assets/editor.worker-B4pQIWZD.js +12 -0
- package/public/assets/elixir-BRjLKONM.js +1 -0
- package/public/assets/flow9-Cac8vKd7.js +1 -0
- package/public/assets/freemarker2-C1qemGIt.js +3 -0
- package/public/assets/fsharp-fd1GTHhf.js +1 -0
- package/public/assets/go-O9LJTZXk.js +1 -0
- package/public/assets/graphql-LQdxqEYJ.js +1 -0
- package/public/assets/handlebars-sZqIfAlP.js +1 -0
- package/public/assets/hcl-DxDQ3s82.js +1 -0
- package/public/assets/html-Bn1WXB8L.js +1 -0
- package/public/assets/html.worker-tnXziJOq.js +456 -0
- package/public/assets/htmlMode-CvQyXnaW.js +4 -0
- package/public/assets/index-DRNkUrer.css +1 -0
- package/public/assets/index-DhL5Kdlz.js +63 -0
- package/public/assets/ini-BvajGCUy.js +1 -0
- package/public/assets/java-SYsfObOQ.js +1 -0
- package/public/assets/javascript-Ox4Jg12j.js +1 -0
- package/public/assets/json.worker-aFakAbRR.js +44 -0
- package/public/assets/jsonMode-DMR7R2dQ.js +10 -0
- package/public/assets/julia-DQXNmw_w.js +1 -0
- package/public/assets/kotlin-qQ0MG-9I.js +1 -0
- package/public/assets/less-GGFNNJHn.js +2 -0
- package/public/assets/lexon-Canl7DCW.js +1 -0
- package/public/assets/liquid-B6HxtpBd.js +1 -0
- package/public/assets/lua-D28Ae8-K.js +1 -0
- package/public/assets/m3-DPitgjJI.js +1 -0
- package/public/assets/markdown-B811l8j2.js +1 -0
- package/public/assets/mdx--jDhmrXq.js +1 -0
- package/public/assets/mips-CdjsipkG.js +1 -0
- package/public/assets/msdax-CYqgjx_P.js +1 -0
- package/public/assets/mysql-BHd6q0vd.js +1 -0
- package/public/assets/objective-c-B1aVtJYH.js +1 -0
- package/public/assets/pascal-BhNW15KB.js +1 -0
- package/public/assets/pascaligo-5jv8CcQD.js +1 -0
- package/public/assets/perl-DlYyT36c.js +1 -0
- package/public/assets/pgsql-Dy0bjov7.js +1 -0
- package/public/assets/php-120yhfDK.js +1 -0
- package/public/assets/pla-CjnFlu4u.js +1 -0
- package/public/assets/postiats-CQpG440k.js +1 -0
- package/public/assets/powerquery-DdJtto1Z.js +1 -0
- package/public/assets/powershell-Bu_VLpJB.js +1 -0
- package/public/assets/protobuf-IBS6jZEB.js +2 -0
- package/public/assets/pug-kFxLfcjb.js +1 -0
- package/public/assets/python-YjG50skX.js +1 -0
- package/public/assets/qsharp-q7JyzKFN.js +1 -0
- package/public/assets/r-BIFz-_sK.js +1 -0
- package/public/assets/razor-CEcFE3UK.js +1 -0
- package/public/assets/redis-CHOsPHWR.js +1 -0
- package/public/assets/redshift-CBifECDb.js +1 -0
- package/public/assets/restructuredtext-CghPJEOS.js +1 -0
- package/public/assets/ruby-CYWGW-b1.js +1 -0
- package/public/assets/rust-DMDD0SHb.js +1 -0
- package/public/assets/sb-BYAiYHFx.js +1 -0
- package/public/assets/scala-Bqvq8jcR.js +1 -0
- package/public/assets/scheme-Dhb-2j9p.js +1 -0
- package/public/assets/scss-CTwUZ5N7.js +3 -0
- package/public/assets/shell-CsDZo4DB.js +1 -0
- package/public/assets/solidity-CME5AdoB.js +1 -0
- package/public/assets/sophia-RYC1BQQz.js +1 -0
- package/public/assets/sparql-KEyrF7De.js +1 -0
- package/public/assets/sql-BdTr02Mf.js +1 -0
- package/public/assets/st-C7iG7M4S.js +1 -0
- package/public/assets/swift-D7IUmUK8.js +1 -0
- package/public/assets/systemverilog-DgMryOEJ.js +1 -0
- package/public/assets/tcl-PloMZuKG.js +1 -0
- package/public/assets/ts.worker-Bij5J2kb.js +51316 -0
- package/public/assets/tsMode-g4kTQl09.js +11 -0
- package/public/assets/twig-BfRIq3la.js +1 -0
- package/public/assets/typescript-CnHeFmPW.js +1 -0
- package/public/assets/typespec-CzxlYoT_.js +1 -0
- package/public/assets/vb-BwAE3J76.js +1 -0
- package/public/assets/wgsl-B_1kOXbF.js +298 -0
- package/public/assets/xml-BFXMY9nb.js +1 -0
- package/public/assets/yaml-DNm87nSf.js +1 -0
- package/public/index.html +2 -2
- package/public/assets/index-Be82iGwe.css +0 -1
- package/public/assets/index-ByU9a3Lh.js +0 -61
package/dist/work-admit.js
CHANGED
|
@@ -1,19 +1,179 @@
|
|
|
1
1
|
/** Admission and host budgets. Neither function calls a model or reorders an inbox. */
|
|
2
|
+
/**
|
|
3
|
+
* Main-session caps. The main bot may still call host tools; these caps are a
|
|
4
|
+
* runaway guard. Worker parallelism is a separate slot/queue policy: `perBot`
|
|
5
|
+
* and `global` limit running workers, and `perBotQueue` / `globalQueue` cap
|
|
6
|
+
* tickets waiting for a slot. `needs_user` does not occupy a running slot.
|
|
7
|
+
* `main*` is the cap after a dispatch or a host tool and is never looser than
|
|
8
|
+
* `chat*`.
|
|
9
|
+
*/
|
|
10
|
+
/** Hard ceiling so a typo cannot raise a slot cap without bound. */
|
|
11
|
+
export const WORK_SLOT_MAX = 64;
|
|
12
|
+
/** Hard ceiling so a typo cannot raise a queue cap without bound. */
|
|
13
|
+
export const WORK_QUEUE_MAX = 256;
|
|
2
14
|
export const DEFAULT_WORK_BUDGET = Object.freeze({
|
|
3
|
-
mainMaxSteps:
|
|
4
|
-
mainWallMs:
|
|
5
|
-
chatMaxSteps:
|
|
6
|
-
chatWallMs:
|
|
15
|
+
mainMaxSteps: 80,
|
|
16
|
+
mainWallMs: 30 * 60 * 1000,
|
|
17
|
+
chatMaxSteps: 80,
|
|
18
|
+
chatWallMs: 30 * 60 * 1000,
|
|
7
19
|
holdMs: 15_000,
|
|
8
20
|
workerMaxSteps: 8,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
21
|
+
/** One budget slice. A grant adds another slice; there is no cumulative ceiling. */
|
|
22
|
+
workerWallMs: 30 * 60 * 1000,
|
|
23
|
+
/** One budget slice. A grant adds another slice; there is no cumulative ceiling. */
|
|
24
|
+
workerMaxTokens: 1_000_000,
|
|
25
|
+
perBot: 2,
|
|
26
|
+
global: 4,
|
|
27
|
+
perBotQueue: 8,
|
|
28
|
+
globalQueue: 16,
|
|
13
29
|
leaseMs: 60_000,
|
|
14
30
|
starveMs: 30_000,
|
|
15
31
|
mergeWindowMs: 1_000,
|
|
16
32
|
});
|
|
33
|
+
const BUDGET_KEYS = Object.keys(DEFAULT_WORK_BUDGET);
|
|
34
|
+
const INT_MAX = {
|
|
35
|
+
perBot: WORK_SLOT_MAX,
|
|
36
|
+
global: WORK_SLOT_MAX,
|
|
37
|
+
perBotQueue: WORK_QUEUE_MAX,
|
|
38
|
+
globalQueue: WORK_QUEUE_MAX,
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* A single bot cannot run more workers than the global cap, even if `perBot`
|
|
42
|
+
* is larger. The same applies to the queue caps. Existing running workers are
|
|
43
|
+
* not cancelled when a later process start uses a lower cap.
|
|
44
|
+
* @param {WorkBudget} budget
|
|
45
|
+
*/
|
|
46
|
+
export function effectiveWorkLimits(budget) {
|
|
47
|
+
return {
|
|
48
|
+
perBot: Math.min(budget.perBot, budget.global),
|
|
49
|
+
global: budget.global,
|
|
50
|
+
perBotQueue: Math.min(budget.perBotQueue, budget.globalQueue),
|
|
51
|
+
globalQueue: budget.globalQueue,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/** Environment variable the launcher uses to pass `--work-budget` to the plugin. */
|
|
55
|
+
export const WORK_BUDGET_ENV = 'DSH_BOT_WORK_BUDGET';
|
|
56
|
+
/**
|
|
57
|
+
* Milliseconds from a number or a `90s` / `30m` / `2h` / `1500ms` string.
|
|
58
|
+
* @param {unknown} value
|
|
59
|
+
*/
|
|
60
|
+
function durationMs(value) {
|
|
61
|
+
if (typeof value === 'number')
|
|
62
|
+
return value;
|
|
63
|
+
if (typeof value !== 'string')
|
|
64
|
+
return Number.NaN;
|
|
65
|
+
const match = /^\s*(\d+(?:\.\d+)?)\s*(ms|s|m|h)?\s*$/i.exec(value);
|
|
66
|
+
if (!match)
|
|
67
|
+
return Number.NaN;
|
|
68
|
+
const unit = (match[2] ?? 'ms').toLowerCase();
|
|
69
|
+
const scale = unit === 'h' ? 3_600_000 : unit === 'm' ? 60_000 : unit === 's' ? 1000 : 1;
|
|
70
|
+
return Number(match[1]) * scale;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Keep only known, positive, finite budget fields. Unknown keys and bad values
|
|
74
|
+
* are dropped (and listed in `ignored`) so a typo never zeroes a cap or raises
|
|
75
|
+
* it to Infinity. Slot and queue integers above WORK_SLOT_MAX / WORK_QUEUE_MAX
|
|
76
|
+
* are clamped (and listed in `clamped`). Non-integer slot/queue/step values
|
|
77
|
+
* are ignored.
|
|
78
|
+
* Shorthands: `steps` sets mainMaxSteps and chatMaxSteps; `wall` sets mainWallMs and chatWallMs.
|
|
79
|
+
* Fields ending in `Ms` accept duration strings such as `30m`.
|
|
80
|
+
* @param {unknown} input
|
|
81
|
+
*/
|
|
82
|
+
export function normalizeWorkBudget(input) {
|
|
83
|
+
const budget = {};
|
|
84
|
+
const ignored = [];
|
|
85
|
+
const clamped = [];
|
|
86
|
+
if (input == null || typeof input !== 'object' || Array.isArray(input))
|
|
87
|
+
return { budget, ignored, clamped };
|
|
88
|
+
const raw = { ...input };
|
|
89
|
+
const expanded = {};
|
|
90
|
+
if ('steps' in raw) {
|
|
91
|
+
expanded.mainMaxSteps = raw.steps;
|
|
92
|
+
expanded.chatMaxSteps = raw.steps;
|
|
93
|
+
delete raw.steps;
|
|
94
|
+
}
|
|
95
|
+
if ('wall' in raw) {
|
|
96
|
+
expanded.mainWallMs = raw.wall;
|
|
97
|
+
expanded.chatWallMs = raw.wall;
|
|
98
|
+
delete raw.wall;
|
|
99
|
+
}
|
|
100
|
+
Object.assign(expanded, raw);
|
|
101
|
+
for (const [key, value] of Object.entries(expanded)) {
|
|
102
|
+
if (!BUDGET_KEYS.includes(key)) {
|
|
103
|
+
ignored.push(key);
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
const duration = key.endsWith('Ms');
|
|
107
|
+
const number = duration ? durationMs(value) : Number(value);
|
|
108
|
+
if (!Number.isFinite(number) || number <= 0) {
|
|
109
|
+
ignored.push(key);
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
if (!duration && !Number.isInteger(number)) {
|
|
113
|
+
ignored.push(key);
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
const max = INT_MAX[key];
|
|
117
|
+
if (max != null && number > max) {
|
|
118
|
+
budget[key] = max;
|
|
119
|
+
clamped.push(key);
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
budget[key] = duration ? Math.floor(number) : number;
|
|
123
|
+
}
|
|
124
|
+
return { budget, ignored, clamped };
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Parse `--work-budget` / DSH_BOT_WORK_BUDGET: JSON (`{"steps":80,"wall":"30m"}`)
|
|
128
|
+
* or comma-separated `key=value` (`steps=80,wall=30m,mainMaxSteps=10`).
|
|
129
|
+
* @param {string | undefined} text
|
|
130
|
+
*/
|
|
131
|
+
export function parseWorkBudget(text) {
|
|
132
|
+
const source = typeof text === 'string' ? text.trim() : '';
|
|
133
|
+
if (source === '')
|
|
134
|
+
return { budget: {}, ignored: [], clamped: [] };
|
|
135
|
+
if (source.startsWith('{')) {
|
|
136
|
+
try {
|
|
137
|
+
return normalizeWorkBudget(JSON.parse(source));
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
return { budget: {}, ignored: [source], clamped: [] };
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
const object = {};
|
|
144
|
+
const ignored = [];
|
|
145
|
+
for (const part of source.split(',')) {
|
|
146
|
+
const piece = part.trim();
|
|
147
|
+
if (piece === '')
|
|
148
|
+
continue;
|
|
149
|
+
const eq = piece.indexOf('=');
|
|
150
|
+
if (eq <= 0) {
|
|
151
|
+
ignored.push(piece);
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
object[piece.slice(0, eq).trim()] = piece.slice(eq + 1).trim();
|
|
155
|
+
}
|
|
156
|
+
const normalized = normalizeWorkBudget(object);
|
|
157
|
+
return { budget: normalized.budget, ignored: [...ignored, ...normalized.ignored], clamped: normalized.clamped };
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Defaults, then the environment (launcher `--work-budget` / `DSH_BOT_WORK_BUDGET`),
|
|
161
|
+
* then plugin config `work`. Limits are applied when the work runtime is created
|
|
162
|
+
* (process start or plugin load). They are not hot-reloaded into an already
|
|
163
|
+
* running runtime. Lowering a cap never cancels a worker that is already running;
|
|
164
|
+
* later dispatch and promotion use the new caps.
|
|
165
|
+
* @param {unknown} config
|
|
166
|
+
* @param {string | undefined} envText
|
|
167
|
+
*/
|
|
168
|
+
export function resolveWorkBudget(config, envText) {
|
|
169
|
+
const fromEnv = parseWorkBudget(envText);
|
|
170
|
+
const fromConfig = normalizeWorkBudget(config);
|
|
171
|
+
return {
|
|
172
|
+
budget: { ...DEFAULT_WORK_BUDGET, ...fromEnv.budget, ...fromConfig.budget },
|
|
173
|
+
ignored: [...fromEnv.ignored, ...fromConfig.ignored],
|
|
174
|
+
clamped: [...fromEnv.clamped, ...fromConfig.clamped],
|
|
175
|
+
};
|
|
176
|
+
}
|
|
17
177
|
/**
|
|
18
178
|
* Pending next-turn ids whose source is not a ticket notice and not a delivery.
|
|
19
179
|
* @param {string[]} pendingIds
|
|
@@ -62,45 +222,78 @@ export function decideAdmission(input) {
|
|
|
62
222
|
* @returns {'steps' | 'wall' | 'tokens' | null}
|
|
63
223
|
*/
|
|
64
224
|
export function budgetTrip(input) {
|
|
65
|
-
|
|
225
|
+
const maxSteps = input.maxSteps;
|
|
226
|
+
const maxTokens = input.maxTokens;
|
|
227
|
+
if (maxSteps != null && Number.isFinite(maxSteps) && Number(input.steps) >= maxSteps)
|
|
66
228
|
return 'steps';
|
|
67
|
-
if (Number.isFinite(
|
|
229
|
+
if (maxTokens != null && Number.isFinite(maxTokens) && Number(input.tokens) >= maxTokens)
|
|
68
230
|
return 'tokens';
|
|
69
231
|
if (input.elapsedMs >= input.wallMs)
|
|
70
232
|
return 'wall';
|
|
71
233
|
return null;
|
|
72
234
|
}
|
|
73
235
|
/**
|
|
74
|
-
* Positive integer
|
|
236
|
+
* Positive integer at or above `min`. A non-finite value is omitted.
|
|
75
237
|
* @param {unknown} value
|
|
76
238
|
* @param {number} min
|
|
77
|
-
* @param {number} max
|
|
78
239
|
*/
|
|
79
|
-
function
|
|
240
|
+
function clampAtLeast(value, min) {
|
|
80
241
|
const number = Number(value);
|
|
81
242
|
if (!Number.isFinite(number))
|
|
82
243
|
return null;
|
|
83
|
-
return Math.max(min, Math.
|
|
244
|
+
return Math.max(min, Math.floor(number));
|
|
84
245
|
}
|
|
85
246
|
/**
|
|
86
247
|
* Ticket budget chosen when the main bot dispatches.
|
|
87
|
-
* An
|
|
88
|
-
*
|
|
89
|
-
* @param {string}
|
|
248
|
+
* An omitted field is one standard slice. An explicit estimate is kept, with a
|
|
249
|
+
* floor of 1000. Later grants add on top and are not capped by this slice.
|
|
250
|
+
* @param {string} _briefing
|
|
90
251
|
* @param {{ wallMs?: number, maxTokens?: number } | null | undefined} suggestion
|
|
91
252
|
* @param {typeof DEFAULT_WORK_BUDGET} defaults
|
|
92
253
|
*/
|
|
93
|
-
export function estimateWorkerBudget(
|
|
94
|
-
const chars = typeof briefing === 'string' ? briefing.length : 0;
|
|
95
|
-
const guessedWall = Math.min(defaults.workerWallMs, 180_000 + chars * 100);
|
|
96
|
-
const guessedTokens = Math.min(defaults.workerMaxTokens, 24_000 + chars * 8);
|
|
254
|
+
export function estimateWorkerBudget(_briefing, suggestion, defaults = DEFAULT_WORK_BUDGET) {
|
|
97
255
|
return {
|
|
98
|
-
wallMs:
|
|
99
|
-
maxTokens:
|
|
256
|
+
wallMs: clampAtLeast(suggestion?.wallMs, 1000) ?? defaults.workerWallMs,
|
|
257
|
+
maxTokens: clampAtLeast(suggestion?.maxTokens, 1000) ?? defaults.workerMaxTokens,
|
|
100
258
|
perBot: defaults.perBot,
|
|
101
259
|
global: defaults.global,
|
|
260
|
+
perBotQueue: defaults.perBotQueue,
|
|
261
|
+
globalQueue: defaults.globalQueue,
|
|
102
262
|
};
|
|
103
263
|
}
|
|
264
|
+
/** Main-session reasoning effort. `off` skips thinking so the reply starts sooner. */
|
|
265
|
+
export const MAIN_REASONING_EFFORT = 'off';
|
|
266
|
+
/**
|
|
267
|
+
* Record `off` on a bot main session before the next step is prepared.
|
|
268
|
+
* A matching selection is left alone. Ordinary sessions are left alone.
|
|
269
|
+
* Call this outside an open session append: `model.select` appends `model/selection`.
|
|
270
|
+
* @param {{ id?: string, model?: { current?: () => ModelSelection, select?: (selection: { provider: string, model: string, reasoningEffort: string }) => void } } | null | undefined} agent
|
|
271
|
+
* @param {(sessionId: string) => boolean} isBot
|
|
272
|
+
*/
|
|
273
|
+
export function pinMainReasoning(agent, isBot) {
|
|
274
|
+
if (!agent || typeof agent.id !== 'string' || agent.id === '' || !isBot(agent.id))
|
|
275
|
+
return false;
|
|
276
|
+
const current = agent.model?.current?.();
|
|
277
|
+
if (!current?.provider || !current.model || current.reasoningEffort === MAIN_REASONING_EFFORT)
|
|
278
|
+
return false;
|
|
279
|
+
agent.model?.select?.({
|
|
280
|
+
provider: current.provider,
|
|
281
|
+
model: current.model,
|
|
282
|
+
reasoningEffort: MAIN_REASONING_EFFORT,
|
|
283
|
+
});
|
|
284
|
+
return true;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Worker route copied from the main session. Thinking stays at the adapter
|
|
288
|
+
* default: the main session's `off` is for reply latency and is not copied.
|
|
289
|
+
* @param {ModelSelection} model
|
|
290
|
+
*/
|
|
291
|
+
export function workerModelSelection(model) {
|
|
292
|
+
if (!model || model.reasoningEffort !== MAIN_REASONING_EFFORT)
|
|
293
|
+
return model;
|
|
294
|
+
const { reasoningEffort: _effort, ...rest } = model;
|
|
295
|
+
return rest;
|
|
296
|
+
}
|
|
104
297
|
/**
|
|
105
298
|
* Child creation options. parentAgent and meta.parentSession are omitted on purpose:
|
|
106
299
|
* the parent link lives only on the ticket row.
|
|
@@ -116,12 +309,16 @@ export function childCreateOptions(sessionId, cwd, model, maxTokens) {
|
|
|
116
309
|
const options = { sessionId };
|
|
117
310
|
if (typeof cwd === 'string' && cwd !== '')
|
|
118
311
|
options.meta = { cwd };
|
|
119
|
-
if (model &&
|
|
312
|
+
if (model &&
|
|
313
|
+
typeof model.provider === 'string' &&
|
|
314
|
+
model.provider !== '' &&
|
|
315
|
+
typeof model.model === 'string' &&
|
|
316
|
+
model.model !== '') {
|
|
120
317
|
options.agentOptions = { provider: model.provider, model: model.model };
|
|
121
318
|
if (typeof model.reasoningEffort === 'string' && model.reasoningEffort !== '') {
|
|
122
319
|
options.agentOptions.reasoningEffort = model.reasoningEffort;
|
|
123
320
|
}
|
|
124
|
-
if (Number.isSafeInteger(maxTokens) && maxTokens > 0)
|
|
321
|
+
if (typeof maxTokens === 'number' && Number.isSafeInteger(maxTokens) && maxTokens > 0)
|
|
125
322
|
options.agentOptions.maxTokens = maxTokens;
|
|
126
323
|
}
|
|
127
324
|
return options;
|
package/dist/work-child.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* File tools for a worker. Plugin-created agents do not inherit the web preset,
|
|
3
3
|
* so their request header otherwise lists only host tools.
|
|
4
|
-
* This preset
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* This preset mounts official file tools and official command tools
|
|
5
|
+
* (`@deepseek-ai/dsh-tool-bash`, `@deepseek-ai/dsh-tool-jobs`). It does not
|
|
6
|
+
* change the host sandbox mode, add writable roots, or mount the web preset
|
|
7
|
+
* (no web_fetch, subagent, or other profile tools). The session cwd copied
|
|
8
|
+
* at create remains the workspace-write boundary; bash uses the already
|
|
9
|
+
* composed host bash-sandbox and approval policy.
|
|
7
10
|
*/
|
|
8
11
|
export const WORKER_FILE_PRESET = 'foundations-files';
|
|
9
12
|
/**
|
|
@@ -14,7 +17,9 @@ function presetsOf(ctx) {
|
|
|
14
17
|
if (typeof ctx.get === 'function')
|
|
15
18
|
return ctx.get('agentPresets') ?? null;
|
|
16
19
|
}
|
|
17
|
-
catch {
|
|
20
|
+
catch {
|
|
21
|
+
/* preset service is optional until a worker is created */
|
|
22
|
+
}
|
|
18
23
|
try {
|
|
19
24
|
return ctx.agentPresets ?? null;
|
|
20
25
|
}
|
|
@@ -31,7 +36,8 @@ export function ensureWorkerFilePreset(ctx) {
|
|
|
31
36
|
const presets = presetsOf(ctx);
|
|
32
37
|
if (!presets?.register || !presets?.mount)
|
|
33
38
|
return Promise.resolve(null);
|
|
34
|
-
return presets
|
|
39
|
+
return presets
|
|
40
|
+
.register({
|
|
35
41
|
id: WORKER_FILE_PRESET,
|
|
36
42
|
plugins: [
|
|
37
43
|
{
|
|
@@ -39,8 +45,12 @@ export function ensureWorkerFilePreset(ctx) {
|
|
|
39
45
|
name: '@deepseek-ai/dsh-tool-fs',
|
|
40
46
|
config: { applyPatch: false, readImage: false },
|
|
41
47
|
},
|
|
48
|
+
{ id: 'tool-bash', name: '@deepseek-ai/dsh-tool-bash' },
|
|
49
|
+
{ id: 'tool-jobs', name: '@deepseek-ai/dsh-tool-jobs' },
|
|
42
50
|
],
|
|
43
|
-
})
|
|
51
|
+
})
|
|
52
|
+
.then(() => WORKER_FILE_PRESET)
|
|
53
|
+
.catch((error) => {
|
|
44
54
|
const message = error instanceof Error ? error.message : String(error);
|
|
45
55
|
if (message.includes('Duplicate'))
|
|
46
56
|
return WORKER_FILE_PRESET;
|
|
@@ -59,9 +69,7 @@ export function workerFileSetup(ctx, presetId) {
|
|
|
59
69
|
const presets = presetsOf(ctx);
|
|
60
70
|
if (!presets?.mount)
|
|
61
71
|
return;
|
|
62
|
-
const recorded = agent?.session && typeof presets.presetForSession === 'function'
|
|
63
|
-
? presets.presetForSession(agent.session)
|
|
64
|
-
: null;
|
|
72
|
+
const recorded = agent?.session && typeof presets.presetForSession === 'function' ? presets.presetForSession(agent.session) : null;
|
|
65
73
|
const id = presetId || recorded || presets.defaultId;
|
|
66
74
|
if (!id)
|
|
67
75
|
return;
|
package/dist/work-http.js
CHANGED
|
@@ -141,12 +141,36 @@ export function openPageLive(req, res, source) {
|
|
|
141
141
|
const intervalMs = source.intervalMs ?? 1000;
|
|
142
142
|
/** @type {ReturnType<typeof setInterval> | null} */
|
|
143
143
|
let timer = null;
|
|
144
|
+
let interactionTimer = null;
|
|
145
|
+
let lastInteractions = '';
|
|
146
|
+
let interactionFailed = false;
|
|
147
|
+
const pumpInteractions = () => {
|
|
148
|
+
if (stopped || !source.interactions)
|
|
149
|
+
return;
|
|
150
|
+
try {
|
|
151
|
+
const text = JSON.stringify(source.interactions());
|
|
152
|
+
if (text === lastInteractions && !interactionFailed)
|
|
153
|
+
return;
|
|
154
|
+
interactionFailed = false;
|
|
155
|
+
lastInteractions = text;
|
|
156
|
+
res.write(`event: interactions\ndata: ${text}\n\n`);
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
// Downgrade the client to REST fallback without closing desk/work updates.
|
|
160
|
+
if (!interactionFailed) {
|
|
161
|
+
interactionFailed = true;
|
|
162
|
+
res.write('event: interaction-error\ndata: {}\n\n');
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
};
|
|
144
166
|
const stop = () => {
|
|
145
167
|
if (stopped)
|
|
146
168
|
return;
|
|
147
169
|
stopped = true;
|
|
148
170
|
if (timer)
|
|
149
171
|
clearInterval(timer);
|
|
172
|
+
if (interactionTimer)
|
|
173
|
+
clearInterval(interactionTimer);
|
|
150
174
|
if (!res.writableEnded)
|
|
151
175
|
res.end();
|
|
152
176
|
};
|
|
@@ -201,8 +225,15 @@ export function openPageLive(req, res, source) {
|
|
|
201
225
|
busy = false;
|
|
202
226
|
}
|
|
203
227
|
};
|
|
228
|
+
pumpInteractions();
|
|
229
|
+
if (source.interactions) {
|
|
230
|
+
interactionTimer = setInterval(pumpInteractions, intervalMs);
|
|
231
|
+
interactionTimer.unref?.();
|
|
232
|
+
}
|
|
204
233
|
void pump();
|
|
205
|
-
timer = setInterval(() => {
|
|
234
|
+
timer = setInterval(() => {
|
|
235
|
+
void pump();
|
|
236
|
+
}, intervalMs);
|
|
206
237
|
timer.unref?.();
|
|
207
238
|
req.on('close', stop);
|
|
208
239
|
res.on('error', stop);
|
|
@@ -216,7 +247,7 @@ export function openPageLive(req, res, source) {
|
|
|
216
247
|
* @param {string} path
|
|
217
248
|
* @param {URL} url
|
|
218
249
|
* @param {Record<string, unknown>} body
|
|
219
|
-
* @param {ReturnType<import('./work-worker.js').createWorkRuntime> | null} work
|
|
250
|
+
* @param {ReturnType<typeof import('./work-worker.js').createWorkRuntime> | null} work
|
|
220
251
|
*/
|
|
221
252
|
export async function handleWorkApi(method, path, url, body, work) {
|
|
222
253
|
if (!path.startsWith('/session-foundations/api/work'))
|