@starsharryzhu/complete-subagent 0.0.0-stage → 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/AGENTS.md +52 -0
- package/LICENSE +21 -0
- package/README.md +166 -2
- package/cordis.patch.yml +11 -0
- package/lib/client.js +439 -0
- package/lib/client.modules.txt +8 -0
- package/lib/host/access.d.ts +46 -0
- package/lib/host/access.js +54 -0
- package/lib/host/call-scope.d.ts +21 -0
- package/lib/host/call-scope.js +26 -0
- package/lib/host/delegate.d.ts +47 -0
- package/lib/host/delegate.js +129 -0
- package/lib/host/grants.d.ts +51 -0
- package/lib/host/grants.js +62 -0
- package/lib/host/legacy.d.ts +57 -0
- package/lib/host/legacy.js +85 -0
- package/lib/host/models.d.ts +59 -0
- package/lib/host/models.js +139 -0
- package/lib/host/paths.d.ts +51 -0
- package/lib/host/paths.js +100 -0
- package/lib/host/policy.d.ts +72 -0
- package/lib/host/policy.js +169 -0
- package/lib/host/prompt.d.ts +41 -0
- package/lib/host/prompt.js +100 -0
- package/lib/host/requests.d.ts +82 -0
- package/lib/host/requests.js +109 -0
- package/lib/host/scope.d.ts +33 -0
- package/lib/host/scope.js +46 -0
- package/lib/host/store.d.ts +89 -0
- package/lib/host/store.js +128 -0
- package/lib/host/tools.d.ts +58 -0
- package/lib/host/tools.js +298 -0
- package/lib/host/types.d.ts +176 -0
- package/lib/host/types.js +26 -0
- package/lib/index.d.ts +55 -0
- package/lib/index.js +245 -0
- package/lib/shared/settings.d.ts +69 -0
- package/lib/shared/settings.js +86 -0
- package/locale/AGENTS.md +22 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +87 -4
- package/src/AGENTS.md +26 -0
- package/src/client/AGENTS.md +28 -0
- package/src/client/css.d.ts +5 -0
- package/src/client/host.ts +82 -0
- package/src/client/index.ts +81 -0
- package/src/client/locales.ts +61 -0
- package/src/client/settings.tsx +222 -0
- package/src/client/styles.css +44 -0
- package/src/host/AGENTS.md +51 -0
- package/src/host/access.ts +82 -0
- package/src/host/call-scope.ts +31 -0
- package/src/host/delegate.ts +162 -0
- package/src/host/grants.ts +82 -0
- package/src/host/legacy.ts +86 -0
- package/src/host/models.ts +155 -0
- package/src/host/paths.ts +100 -0
- package/src/host/policy.ts +169 -0
- package/src/host/prompt.ts +113 -0
- package/src/host/requests.ts +149 -0
- package/src/host/scope.ts +54 -0
- package/src/host/store.ts +159 -0
- package/src/host/tools.ts +318 -0
- package/src/host/types.ts +183 -0
- package/src/index.ts +316 -0
- package/src/shared/AGENTS.md +20 -0
- package/src/shared/settings.ts +104 -0
package/lib/client.js
ADDED
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
/* @starsharryzhu/complete-subagent 0.1.0 — generated by build.js from src/; do not edit. */
|
|
2
|
+
window.__ModuleLoader__.load({
|
|
3
|
+
id: "@starsharryzhu/complete-subagent",
|
|
4
|
+
factory: (require) => {
|
|
5
|
+
"use strict";
|
|
6
|
+
const definitions = {
|
|
7
|
+
"client/host.js": function (module, exports, require) {
|
|
8
|
+
"use strict";
|
|
9
|
+
/**
|
|
10
|
+
* The slice of host slot props and services the browser half reads, as
|
|
11
|
+
* structural types. The browser half imports no harness package, not even for
|
|
12
|
+
* types; every field is optional because an older host or another composition
|
|
13
|
+
* may leave any of them out, and the page must degrade, not throw.
|
|
14
|
+
* @module complete-subagent/client/host
|
|
15
|
+
*/
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
},
|
|
18
|
+
"client/index.js": function (module, exports, require) {
|
|
19
|
+
"use strict";
|
|
20
|
+
/**
|
|
21
|
+
* complete-subagent browser half: the settings page on the Plugins screen, its
|
|
22
|
+
* copy, and one stylesheet. Each is an effect of this plugin's context and is
|
|
23
|
+
* skipped (logged) if its host seat is missing.
|
|
24
|
+
* @module complete-subagent/client
|
|
25
|
+
*/
|
|
26
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
27
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
28
|
+
};
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
exports.inject = exports.name = void 0;
|
|
31
|
+
exports.apply = apply;
|
|
32
|
+
const settings_ts_1 = require("../shared/settings.js");
|
|
33
|
+
const locales_ts_1 = require("./locales.js");
|
|
34
|
+
const settings_tsx_1 = require("./settings.js");
|
|
35
|
+
const styles_css_1 = __importDefault(require("./styles.css"));
|
|
36
|
+
exports.name = settings_ts_1.PACKAGE_NAME;
|
|
37
|
+
exports.inject = ['slots', 'locale'];
|
|
38
|
+
/**
|
|
39
|
+
* Register the browser contributions.
|
|
40
|
+
* @param ctx - the plugin's client context.
|
|
41
|
+
*/
|
|
42
|
+
function apply(ctx) {
|
|
43
|
+
const slots = ctx.get?.('slots');
|
|
44
|
+
const locale = ctx.get?.('locale');
|
|
45
|
+
if (slots === undefined) {
|
|
46
|
+
console.error(`${settings_ts_1.PLUGIN_ID}: the slots service is missing, so the settings page cannot render`);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
// The remote session namespace is its own service and must be injected before use.
|
|
50
|
+
let session;
|
|
51
|
+
const getSession = () => session;
|
|
52
|
+
guard('dictionaries', () => {
|
|
53
|
+
if (locale !== undefined)
|
|
54
|
+
ctx.effect?.(() => locale.register(settings_ts_1.PACKAGE_NAME, { zh: locales_ts_1.zh, en: locales_ts_1.en }), `${settings_ts_1.PLUGIN_ID}: dictionaries`);
|
|
55
|
+
});
|
|
56
|
+
guard('styles', () => {
|
|
57
|
+
ctx.effect?.(() => mountStyles(styles_css_1.default), `${settings_ts_1.PLUGIN_ID}: styles`);
|
|
58
|
+
});
|
|
59
|
+
guard('remote', () => {
|
|
60
|
+
ctx.inject?.(['remote', 'remote.session'], (scope) => {
|
|
61
|
+
const service = scope.get?.('remote')?.session;
|
|
62
|
+
session = service;
|
|
63
|
+
scope.effect?.(() => () => { if (session === service)
|
|
64
|
+
session = undefined; }, `${settings_ts_1.PLUGIN_ID}: remote session`);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
guard('settings', () => {
|
|
68
|
+
ctx.inject?.(['configForms'], (scope) => {
|
|
69
|
+
const forms = scope.get?.('configForms');
|
|
70
|
+
const scopedSlots = scope.get?.('slots') ?? slots;
|
|
71
|
+
if (forms === undefined)
|
|
72
|
+
return;
|
|
73
|
+
const Settings = (0, settings_tsx_1.createSettings)(forms.get(settings_ts_1.PLUGIN_ID), getSession);
|
|
74
|
+
scopedSlots.inject('plugins.bundle.config', () => scopedSlots.register({ name: 'plugins.bundle.config', key: settings_ts_1.PACKAGE_NAME, locale: settings_ts_1.PACKAGE_NAME }, Settings));
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/** Run one contribution, logging instead of throwing: a throw here fails the page's boot. */
|
|
79
|
+
function guard(label, run) {
|
|
80
|
+
try {
|
|
81
|
+
run();
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
console.error(`${settings_ts_1.PLUGIN_ID}: the ${label} could not be registered`, error);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Add the plugin's stylesheet, tagged with the plugin id.
|
|
89
|
+
* @param text - the stylesheet.
|
|
90
|
+
* @returns the cleanup that removes it.
|
|
91
|
+
*/
|
|
92
|
+
function mountStyles(text) {
|
|
93
|
+
if (typeof document === 'undefined')
|
|
94
|
+
return () => undefined;
|
|
95
|
+
const style = document.createElement('style');
|
|
96
|
+
style.setAttribute('data-plugin', settings_ts_1.PACKAGE_NAME);
|
|
97
|
+
style.setAttribute('data-plugin-css', `${settings_ts_1.PACKAGE_NAME}/styles.css`);
|
|
98
|
+
style.textContent = text;
|
|
99
|
+
document.head.appendChild(style);
|
|
100
|
+
return () => { style.remove(); };
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
"client/locales.js": function (module, exports, require) {
|
|
104
|
+
"use strict";
|
|
105
|
+
/**
|
|
106
|
+
* Settings page copy.
|
|
107
|
+
* @module complete-subagent/client/locales
|
|
108
|
+
*/
|
|
109
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
110
|
+
exports.en = exports.zh = void 0;
|
|
111
|
+
exports.fallbackT = fallbackT;
|
|
112
|
+
exports.zh = {
|
|
113
|
+
'settings.summary.none': '子代理只用父代理自己的模型',
|
|
114
|
+
'settings.summary.some': '可为子代理选择 {count} 个模型',
|
|
115
|
+
'settings.models': '可选的子代理模型',
|
|
116
|
+
'settings.models.hint': '父代理派生子代理时,只能从这里选模型。父代理自己的模型总能用:不在列表里时可选它支持的全部推理强度,在列表里就只能选勾选的强度。',
|
|
117
|
+
'settings.models.empty': '还没有添加模型,子代理只用父代理自己的模型,推理强度可以调。',
|
|
118
|
+
'settings.efforts': '允许的推理强度',
|
|
119
|
+
'settings.efforts.all': '不勾选就是全部',
|
|
120
|
+
'settings.efforts.none': '这个模型没有可选的推理强度',
|
|
121
|
+
'settings.unavailable': '当前不可用',
|
|
122
|
+
'settings.remove': '移除',
|
|
123
|
+
'settings.add': '添加',
|
|
124
|
+
'settings.add.placeholder': '选择要添加的模型',
|
|
125
|
+
'settings.timeout': '写入申请的等待时间(秒)',
|
|
126
|
+
'settings.timeout.hint': '子代理申请写入后,父代理超过这个时间没回复就按拒绝处理。最少 {min} 秒。',
|
|
127
|
+
'settings.save': '保存',
|
|
128
|
+
'settings.saved': '已保存,AI 的下一步起生效',
|
|
129
|
+
'settings.failed': '保存失败,请重试。',
|
|
130
|
+
'settings.readonly': '当前配置文件不可写。',
|
|
131
|
+
'settings.loading': '正在读取…',
|
|
132
|
+
'settings.catalogFailed': '读取模型列表失败,已保存的模型仍会保留。',
|
|
133
|
+
};
|
|
134
|
+
exports.en = {
|
|
135
|
+
'settings.summary.none': 'Children use their parent\'s model',
|
|
136
|
+
'settings.summary.some': '{count} models to choose for children',
|
|
137
|
+
'settings.models': 'Models for subagents',
|
|
138
|
+
'settings.models.hint': 'A parent can choose a child\'s model only from this list. Its own model is always available: with every effort it supports when it is not listed, with the checked efforts when it is.',
|
|
139
|
+
'settings.models.empty': 'No models yet: children use their parent\'s model, and the parent can still set the reasoning effort.',
|
|
140
|
+
'settings.efforts': 'Allowed reasoning efforts',
|
|
141
|
+
'settings.efforts.all': 'None checked means all',
|
|
142
|
+
'settings.efforts.none': 'This model has no selectable reasoning effort',
|
|
143
|
+
'settings.unavailable': 'Unavailable',
|
|
144
|
+
'settings.remove': 'Remove',
|
|
145
|
+
'settings.add': 'Add',
|
|
146
|
+
'settings.add.placeholder': 'Choose a model to add',
|
|
147
|
+
'settings.timeout': 'Write-access answer time (seconds)',
|
|
148
|
+
'settings.timeout.hint': 'A request the parent does not answer within this time counts as denied. At least {min} seconds.',
|
|
149
|
+
'settings.save': 'Save',
|
|
150
|
+
'settings.saved': 'Saved; it applies from the next step',
|
|
151
|
+
'settings.failed': 'Saving failed. Try again.',
|
|
152
|
+
'settings.readonly': 'The profile is read-only.',
|
|
153
|
+
'settings.loading': 'Loading…',
|
|
154
|
+
'settings.catalogFailed': 'The model list could not be loaded; saved models are kept.',
|
|
155
|
+
};
|
|
156
|
+
/**
|
|
157
|
+
* Translator used when the locale service is missing.
|
|
158
|
+
* @param key - message key.
|
|
159
|
+
* @param params - interpolation values.
|
|
160
|
+
* @returns the English text.
|
|
161
|
+
*/
|
|
162
|
+
function fallbackT(key, params) {
|
|
163
|
+
const text = exports.en[key] ?? key;
|
|
164
|
+
return params === undefined ? text : text.replace(/\{(\w+)\}/gu, (match, name) => (name in params ? String(params[name]) : match));
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
"client/settings.js": function (module, exports, require) {
|
|
168
|
+
"use strict";
|
|
169
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
170
|
+
exports.readValues = readValues;
|
|
171
|
+
exports.changes = changes;
|
|
172
|
+
exports.createSettings = createSettings;
|
|
173
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
174
|
+
/**
|
|
175
|
+
* The plugin's settings page on the Plugins screen.
|
|
176
|
+
*
|
|
177
|
+
* Edits the host half's live config (`models`, `requestTimeoutSeconds`)
|
|
178
|
+
* through the host's settings form for the `complete-subagent` profile entry.
|
|
179
|
+
* Models are added from the same catalog the model picker uses; each one's
|
|
180
|
+
* efforts are checkboxes over what the catalog advertises. A saved model the
|
|
181
|
+
* catalog no longer lists stays, marked unavailable, until it is removed.
|
|
182
|
+
* @module complete-subagent/client/settings
|
|
183
|
+
*/
|
|
184
|
+
const react_1 = require("react");
|
|
185
|
+
const settings_ts_1 = require("../shared/settings.js");
|
|
186
|
+
const locales_ts_1 = require("./locales.js");
|
|
187
|
+
/**
|
|
188
|
+
* Read form values with defaults.
|
|
189
|
+
* @param value - the form's accepted section.
|
|
190
|
+
* @returns complete values.
|
|
191
|
+
*/
|
|
192
|
+
function readValues(value) {
|
|
193
|
+
return { models: (0, settings_ts_1.readModels)(value?.models), requestTimeoutSeconds: (0, settings_ts_1.readTimeout)(value?.requestTimeoutSeconds) };
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* The edits that turn the stored values into the draft.
|
|
197
|
+
* @param stored - the saved values.
|
|
198
|
+
* @param draft - the edited values.
|
|
199
|
+
* @returns one `set` per changed field.
|
|
200
|
+
*/
|
|
201
|
+
function changes(stored, draft) {
|
|
202
|
+
const ops = [];
|
|
203
|
+
if (JSON.stringify(draft.models) !== JSON.stringify(stored.models)) {
|
|
204
|
+
ops.push({ op: 'set', path: ['models'], value: draft.models.map(entry => ({ ...entry, reasoningEfforts: [...entry.reasoningEfforts] })) });
|
|
205
|
+
}
|
|
206
|
+
if (draft.requestTimeoutSeconds !== stored.requestTimeoutSeconds) {
|
|
207
|
+
ops.push({ op: 'set', path: ['requestTimeoutSeconds'], value: draft.requestTimeoutSeconds });
|
|
208
|
+
}
|
|
209
|
+
return ops;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Build the settings component over the form and the catalog.
|
|
213
|
+
* @param form - the `complete-subagent` settings form.
|
|
214
|
+
* @param getSession - the live `ctx.remote.session`, for the model catalog.
|
|
215
|
+
* @returns the `plugins.bundle.config` entry.
|
|
216
|
+
*/
|
|
217
|
+
function createSettings(form, getSession) {
|
|
218
|
+
// The host form is a class instance: keep its methods bound.
|
|
219
|
+
const subscribe = (listener) => form.subscribe(listener);
|
|
220
|
+
const getSnapshot = () => form.getSnapshot();
|
|
221
|
+
return function CompleteSubagentSettings(props) {
|
|
222
|
+
const t = props.t ?? locales_ts_1.fallbackT;
|
|
223
|
+
const snapshot = (0, react_1.useSyncExternalStore)(subscribe, getSnapshot);
|
|
224
|
+
const stored = readValues(snapshot.value);
|
|
225
|
+
if (props.view === 'summary') {
|
|
226
|
+
return stored.models.length === 0 ? t('settings.summary.none') : t('settings.summary.some', { count: stored.models.length });
|
|
227
|
+
}
|
|
228
|
+
return (0, jsx_runtime_1.jsx)(SettingsPage, { form: form, stored: stored, ready: snapshot.status === 'ready', writable: snapshot.writable !== false, revision: snapshot.revision, getSession: getSession, t: t });
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
function SettingsPage(props) {
|
|
232
|
+
const { t, stored } = props;
|
|
233
|
+
const [draft, setDraft] = (0, react_1.useState)(stored);
|
|
234
|
+
const [status, setStatus] = (0, react_1.useState)('idle');
|
|
235
|
+
const [groups, setGroups] = (0, react_1.useState)();
|
|
236
|
+
const [catalogFailed, setCatalogFailed] = (0, react_1.useState)(false);
|
|
237
|
+
const [adding, setAdding] = (0, react_1.useState)('');
|
|
238
|
+
const storedKey = JSON.stringify(stored);
|
|
239
|
+
// Re-seed the draft only when the stored values change, not on every render.
|
|
240
|
+
(0, react_1.useEffect)(() => { setDraft(stored); }, [storedKey]);
|
|
241
|
+
(0, react_1.useEffect)(() => {
|
|
242
|
+
let live = true;
|
|
243
|
+
const catalog = props.getSession()?.modelCatalog();
|
|
244
|
+
if (catalog === undefined) {
|
|
245
|
+
setCatalogFailed(true);
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
catalog.then((response) => {
|
|
249
|
+
if (!live)
|
|
250
|
+
return;
|
|
251
|
+
if (response.ok && response.value)
|
|
252
|
+
setGroups(response.value.groups);
|
|
253
|
+
else
|
|
254
|
+
setCatalogFailed(true);
|
|
255
|
+
}, () => { if (live)
|
|
256
|
+
setCatalogFailed(true); });
|
|
257
|
+
return () => { live = false; };
|
|
258
|
+
}, [props.getSession]);
|
|
259
|
+
if (!props.ready)
|
|
260
|
+
return (0, jsx_runtime_1.jsx)("p", { className: "complete-subagent-note", children: t('settings.loading') });
|
|
261
|
+
const listed = (groups ?? []).flatMap(group => group.models.map(model => ({ group, model })));
|
|
262
|
+
const find = (entry) => listed.find(item => item.group.id === entry.provider && item.model.id === entry.model);
|
|
263
|
+
const chosen = new Set(draft.models.map(settings_ts_1.modelKey));
|
|
264
|
+
const addable = listed.filter(item => !chosen.has((0, settings_ts_1.modelKey)({ provider: item.group.id, model: item.model.id })));
|
|
265
|
+
const ops = changes(stored, draft);
|
|
266
|
+
const disabled = !props.writable || status === 'saving';
|
|
267
|
+
const update = (patch) => {
|
|
268
|
+
setDraft(value => ({ ...value, ...patch }));
|
|
269
|
+
setStatus('idle');
|
|
270
|
+
};
|
|
271
|
+
const setModels = (models) => update({ models });
|
|
272
|
+
const save = async () => {
|
|
273
|
+
setStatus('saving');
|
|
274
|
+
try {
|
|
275
|
+
setStatus(await props.form.mutate(ops, props.revision) ? 'saved' : 'failed');
|
|
276
|
+
}
|
|
277
|
+
catch {
|
|
278
|
+
setStatus('failed');
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
const add = () => {
|
|
282
|
+
const item = addable.find(candidate => (0, settings_ts_1.modelKey)({ provider: candidate.group.id, model: candidate.model.id }) === adding);
|
|
283
|
+
if (item === undefined)
|
|
284
|
+
return;
|
|
285
|
+
setModels([...draft.models, { provider: item.group.id, model: item.model.id, reasoningEfforts: [] }]);
|
|
286
|
+
setAdding('');
|
|
287
|
+
};
|
|
288
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "complete-subagent-settings", children: [(0, jsx_runtime_1.jsxs)("section", { className: "complete-subagent-section", children: [(0, jsx_runtime_1.jsx)("h3", { children: t('settings.models') }), (0, jsx_runtime_1.jsx)("p", { className: "complete-subagent-note", children: t('settings.models.hint') }), draft.models.length === 0 && (0, jsx_runtime_1.jsx)("p", { className: "complete-subagent-note", children: t('settings.models.empty') }), (0, jsx_runtime_1.jsx)("ul", { className: "complete-subagent-models", children: draft.models.map((entry, index) => {
|
|
289
|
+
const item = find(entry);
|
|
290
|
+
const advertised = item?.model.reasoning?.efforts ?? [];
|
|
291
|
+
const extra = entry.reasoningEfforts.filter(effort => !advertised.some(option => option.id === effort)).map(id => ({ id, name: id }));
|
|
292
|
+
const options = [...advertised, ...extra];
|
|
293
|
+
const toggle = (effort) => {
|
|
294
|
+
const next = entry.reasoningEfforts.includes(effort)
|
|
295
|
+
? entry.reasoningEfforts.filter(value => value !== effort)
|
|
296
|
+
: options.map(option => option.id).filter(id => id === effort || entry.reasoningEfforts.includes(id));
|
|
297
|
+
setModels(draft.models.map((value, at) => (at === index ? { ...value, reasoningEfforts: next } : value)));
|
|
298
|
+
};
|
|
299
|
+
return ((0, jsx_runtime_1.jsxs)("li", { className: "complete-subagent-model", children: [(0, jsx_runtime_1.jsxs)("div", { className: "complete-subagent-model-head", children: [(0, jsx_runtime_1.jsx)("span", { className: "complete-subagent-model-name", children: item?.model.name ?? entry.model }), (0, jsx_runtime_1.jsx)("code", { children: (0, settings_ts_1.modelKey)(entry) }), item === undefined && groups !== undefined && (0, jsx_runtime_1.jsx)("span", { className: "complete-subagent-tag", children: t('settings.unavailable') }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "complete-subagent-button", disabled: disabled, onClick: () => setModels(draft.models.filter((_, at) => at !== index)), children: t('settings.remove') })] }), options.length === 0
|
|
300
|
+
? (0, jsx_runtime_1.jsx)("p", { className: "complete-subagent-note", children: t('settings.efforts.none') })
|
|
301
|
+
: ((0, jsx_runtime_1.jsxs)("fieldset", { className: "complete-subagent-efforts", disabled: disabled, children: [(0, jsx_runtime_1.jsxs)("legend", { children: [t('settings.efforts'), (0, jsx_runtime_1.jsx)("span", { className: "complete-subagent-note", children: t('settings.efforts.all') })] }), options.map(option => ((0, jsx_runtime_1.jsxs)("label", { className: "complete-subagent-check", children: [(0, jsx_runtime_1.jsx)("input", { type: "checkbox", checked: entry.reasoningEfforts.includes(option.id), onChange: () => toggle(option.id) }), option.name ?? option.id] }, option.id)))] }))] }, (0, settings_ts_1.modelKey)(entry)));
|
|
302
|
+
}) }), (0, jsx_runtime_1.jsxs)("div", { className: "complete-subagent-add", children: [(0, jsx_runtime_1.jsxs)("select", { value: adding, disabled: disabled || addable.length === 0, onChange: event => setAdding(event.target.value), "aria-label": t('settings.add.placeholder'), children: [(0, jsx_runtime_1.jsx)("option", { value: "", children: t('settings.add.placeholder') }), (groups ?? []).map(group => {
|
|
303
|
+
const models = addable.filter(item => item.group === group);
|
|
304
|
+
if (models.length === 0)
|
|
305
|
+
return null;
|
|
306
|
+
return ((0, jsx_runtime_1.jsx)("optgroup", { label: group.name ?? group.id, children: models.map(item => ((0, jsx_runtime_1.jsx)("option", { value: (0, settings_ts_1.modelKey)({ provider: group.id, model: item.model.id }), children: item.model.name ?? item.model.id }, item.model.id))) }, group.id));
|
|
307
|
+
})] }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "complete-subagent-button", disabled: disabled || adding === '', onClick: add, children: t('settings.add') })] }), catalogFailed && (0, jsx_runtime_1.jsx)("p", { className: "complete-subagent-note", children: t('settings.catalogFailed') })] }), (0, jsx_runtime_1.jsxs)("section", { className: "complete-subagent-section", children: [(0, jsx_runtime_1.jsxs)("label", { className: "complete-subagent-field", children: [(0, jsx_runtime_1.jsx)("span", { children: t('settings.timeout') }), (0, jsx_runtime_1.jsx)("input", { type: "number", min: settings_ts_1.MIN_TIMEOUT_SECONDS, step: 1, value: draft.requestTimeoutSeconds, disabled: disabled, onChange: event => update({ requestTimeoutSeconds: Math.max(settings_ts_1.MIN_TIMEOUT_SECONDS, Math.round(Number(event.target.value) || settings_ts_1.MIN_TIMEOUT_SECONDS)) }) })] }), (0, jsx_runtime_1.jsx)("p", { className: "complete-subagent-note", children: t('settings.timeout.hint', { min: settings_ts_1.MIN_TIMEOUT_SECONDS }) })] }), !props.writable && (0, jsx_runtime_1.jsx)("p", { className: "complete-subagent-note", children: t('settings.readonly') }), (0, jsx_runtime_1.jsxs)("div", { className: "complete-subagent-actions", children: [(0, jsx_runtime_1.jsx)("button", { type: "button", className: "complete-subagent-button", "data-primary": true, disabled: disabled || ops.length === 0, onClick: () => void save(), children: t('settings.save') }), status === 'saved' && (0, jsx_runtime_1.jsx)("span", { className: "complete-subagent-note", children: t('settings.saved') }), status === 'failed' && (0, jsx_runtime_1.jsx)("span", { className: "complete-subagent-error", children: t('settings.failed') })] })] }));
|
|
308
|
+
}
|
|
309
|
+
},
|
|
310
|
+
"client/styles.css": function (module, exports, require) {
|
|
311
|
+
"use strict";
|
|
312
|
+
module.exports = "/* complete-subagent settings page. Colors come from the host's design tokens. */\n.complete-subagent-settings { display: flex; flex-direction: column; gap: 16px; font-size: 13px; }\n.complete-subagent-section { display: flex; flex-direction: column; gap: 8px; }\n.complete-subagent-section h3 { margin: 0; font-size: 14px; font-weight: 600; }\n.complete-subagent-note { margin: 0; color: var(--dsw-alias-label-secondary); font-size: 12px; font-weight: 400; }\n.complete-subagent-error { color: var(--dsw-alias-state-error-primary); font-size: 12px; }\n\n.complete-subagent-models { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; }\n.complete-subagent-model {\n display: flex; flex-direction: column; gap: 8px; padding: 10px 12px;\n border: 1px solid var(--dsw-alias-border-l2); border-radius: 10px; background: var(--dsw-alias-bg-layer-2);\n}\n.complete-subagent-model-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }\n.complete-subagent-model-name { font-weight: 500; }\n.complete-subagent-model-head code { color: var(--dsw-alias-label-secondary); font-size: 12px; overflow-wrap: anywhere; }\n.complete-subagent-model-head .complete-subagent-button { margin-left: auto; }\n.complete-subagent-tag {\n padding: 0 6px; border-radius: 6px; font-size: 11px; line-height: 18px;\n color: var(--dsw-alias-state-error-primary); border: 1px solid currentColor;\n}\n\n.complete-subagent-efforts { margin: 0; padding: 0; border: 0; display: flex; gap: 6px 14px; flex-wrap: wrap; }\n.complete-subagent-efforts legend { padding: 0; margin-bottom: 4px; font-weight: 500; display: flex; gap: 8px; align-items: baseline; }\n.complete-subagent-check { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; }\n\n.complete-subagent-add { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }\n.complete-subagent-field { display: flex; flex-direction: column; gap: 4px; max-width: 360px; }\n.complete-subagent-field span { font-weight: 500; }\n.complete-subagent-add select, .complete-subagent-field input {\n padding: 5px 8px; border: 1px solid var(--dsw-alias-border-l2); border-radius: 8px;\n background: var(--dsw-alias-bg-layer-2); color: inherit; font: inherit; max-width: 100%;\n}\n\n.complete-subagent-button {\n display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border: 0; border-radius: 7px;\n background: transparent; color: inherit; font: inherit; cursor: pointer;\n}\n.complete-subagent-button:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover); }\n.complete-subagent-button[data-primary] { border: 1px solid var(--dsw-alias-border-l4); }\n.complete-subagent-button:disabled { opacity: 0.5; cursor: default; }\n.complete-subagent-button:focus-visible {\n outline: 2px solid var(--dsw-alias-state-business-primary, var(--dsw-alias-label-primary)); outline-offset: -2px;\n}\n.complete-subagent-actions { display: flex; align-items: center; gap: 10px; }\n";
|
|
313
|
+
},
|
|
314
|
+
"shared/settings.js": function (module, exports, require) {
|
|
315
|
+
"use strict";
|
|
316
|
+
/**
|
|
317
|
+
* The settings both halves read: which models a parent may choose for a child,
|
|
318
|
+
* which reasoning efforts each allows, and how long a parent has to answer.
|
|
319
|
+
* The host half declares them as live config fields; the browser half edits
|
|
320
|
+
* them on the Plugins page. Only the host half reads `presets`, `childPreset`,
|
|
321
|
+
* and `ownModel`, which a bundle that mounts this plugin sets in its patch.
|
|
322
|
+
* @module complete-subagent/shared/settings
|
|
323
|
+
*/
|
|
324
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
325
|
+
exports.MIN_TIMEOUT_SECONDS = exports.DEFAULT_TIMEOUT_SECONDS = exports.PLUGIN_ID = exports.PACKAGE_NAME = void 0;
|
|
326
|
+
exports.modelKey = modelKey;
|
|
327
|
+
exports.readModels = readModels;
|
|
328
|
+
exports.readPresets = readPresets;
|
|
329
|
+
exports.readChildPreset = readChildPreset;
|
|
330
|
+
exports.readOwnModel = readOwnModel;
|
|
331
|
+
exports.readTimeout = readTimeout;
|
|
332
|
+
/** The npm package name: the browser bundle's registration id and the Plugins page key. */
|
|
333
|
+
exports.PACKAGE_NAME = '@starsharryzhu/complete-subagent';
|
|
334
|
+
/** Bundle row id, settings form id, and plugin name; it keeps the original spelling. */
|
|
335
|
+
exports.PLUGIN_ID = 'complete-subagent';
|
|
336
|
+
/** Seconds a parent has to answer a write-access request, unless the settings say otherwise. */
|
|
337
|
+
exports.DEFAULT_TIMEOUT_SECONDS = 600;
|
|
338
|
+
/** The shortest answer time the settings accept. */
|
|
339
|
+
exports.MIN_TIMEOUT_SECONDS = 10;
|
|
340
|
+
/**
|
|
341
|
+
* The id a parent passes as `model`.
|
|
342
|
+
* @param route - provider and model.
|
|
343
|
+
* @returns `provider/model`.
|
|
344
|
+
*/
|
|
345
|
+
function modelKey(route) {
|
|
346
|
+
return `${route.provider}/${route.model}`;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Read a stored model list, dropping malformed entries, repeated models, and
|
|
350
|
+
* repeated efforts.
|
|
351
|
+
* @param value - the stored `models` field.
|
|
352
|
+
* @returns the usable entries in their stored order.
|
|
353
|
+
*/
|
|
354
|
+
function readModels(value) {
|
|
355
|
+
if (!Array.isArray(value))
|
|
356
|
+
return [];
|
|
357
|
+
const seen = new Set();
|
|
358
|
+
const models = [];
|
|
359
|
+
for (const item of value) {
|
|
360
|
+
if (typeof item !== 'object' || item === null)
|
|
361
|
+
continue;
|
|
362
|
+
const { provider, model, reasoningEfforts } = item;
|
|
363
|
+
if (typeof provider !== 'string' || provider === '' || typeof model !== 'string' || model === '')
|
|
364
|
+
continue;
|
|
365
|
+
const key = modelKey({ provider, model });
|
|
366
|
+
if (seen.has(key))
|
|
367
|
+
continue;
|
|
368
|
+
seen.add(key);
|
|
369
|
+
const efforts = Array.isArray(reasoningEfforts)
|
|
370
|
+
? [...new Set(reasoningEfforts.filter((effort) => typeof effort === 'string' && effort !== ''))]
|
|
371
|
+
: [];
|
|
372
|
+
models.push({ provider, model, reasoningEfforts: efforts });
|
|
373
|
+
}
|
|
374
|
+
return models;
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Read a stored preset list, dropping anything but non-empty strings and repeats.
|
|
378
|
+
* @param value - the stored `presets` field.
|
|
379
|
+
* @returns the preset ids in their stored order; empty means every preset.
|
|
380
|
+
*/
|
|
381
|
+
function readPresets(value) {
|
|
382
|
+
if (!Array.isArray(value))
|
|
383
|
+
return [];
|
|
384
|
+
return [...new Set(value.filter((preset) => typeof preset === 'string' && preset !== ''))];
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Read a stored child preset.
|
|
388
|
+
* @param value - the stored `childPreset` field.
|
|
389
|
+
* @returns the preset id, or undefined when none is set.
|
|
390
|
+
*/
|
|
391
|
+
function readChildPreset(value) {
|
|
392
|
+
return typeof value === 'string' && value.trim() !== '' ? value.trim() : undefined;
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Read the stored `ownModel` flag.
|
|
396
|
+
* @param value - the stored field.
|
|
397
|
+
* @returns false only when the field says so.
|
|
398
|
+
*/
|
|
399
|
+
function readOwnModel(value) {
|
|
400
|
+
return value !== false;
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Read a stored answer time.
|
|
404
|
+
* @param value - the stored `requestTimeoutSeconds` field.
|
|
405
|
+
* @returns whole seconds, at least {@link MIN_TIMEOUT_SECONDS}.
|
|
406
|
+
*/
|
|
407
|
+
function readTimeout(value) {
|
|
408
|
+
return typeof value === 'number' && Number.isInteger(value) && value >= exports.MIN_TIMEOUT_SECONDS ? value : exports.DEFAULT_TIMEOUT_SECONDS;
|
|
409
|
+
}
|
|
410
|
+
},
|
|
411
|
+
};
|
|
412
|
+
const externals = new Set(["react","react/jsx-runtime","react-dom","@deepseek-ai/dsh-client-ui-primitives"]);
|
|
413
|
+
const cache = Object.create(null);
|
|
414
|
+
const resolve = (from, request) => {
|
|
415
|
+
const parts = from.split("/");
|
|
416
|
+
parts.pop();
|
|
417
|
+
for (const part of request.split("/")) {
|
|
418
|
+
if (part === "." || part === "") continue;
|
|
419
|
+
if (part === "..") parts.pop();
|
|
420
|
+
else parts.push(part);
|
|
421
|
+
}
|
|
422
|
+
return parts.join("/");
|
|
423
|
+
};
|
|
424
|
+
const load = (id) => {
|
|
425
|
+
const cached = cache[id];
|
|
426
|
+
if (cached !== undefined) return cached.exports;
|
|
427
|
+
if (!Object.hasOwn(definitions, id)) throw new Error("@starsharryzhu/complete-subagent: missing bundled module " + id);
|
|
428
|
+
const module = { exports: {} };
|
|
429
|
+
cache[id] = module;
|
|
430
|
+
definitions[id].call(module.exports, module, module.exports, (request) => {
|
|
431
|
+
if (externals.has(request)) return require(request);
|
|
432
|
+
if (request.startsWith(".")) return load(resolve(id, request));
|
|
433
|
+
throw new Error("@starsharryzhu/complete-subagent: " + id + " requested " + request + ", which this bundle does not provide");
|
|
434
|
+
});
|
|
435
|
+
return module.exports;
|
|
436
|
+
};
|
|
437
|
+
return load("client/index.js");
|
|
438
|
+
},
|
|
439
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a new child may modify, decided from the delegation call's `cwd` and
|
|
3
|
+
* `writable_paths` before the child exists.
|
|
4
|
+
*
|
|
5
|
+
* A `cwd` the parent may modify becomes the child's sub-workspace and is created
|
|
6
|
+
* if missing; no `cwd`, or one outside the parent's writable area, gives the
|
|
7
|
+
* child none. `writable_paths` become grants, checked against the parent's own
|
|
8
|
+
* reach, so nothing outside it can be handed down.
|
|
9
|
+
* @module complete-subagent/host/access
|
|
10
|
+
*/
|
|
11
|
+
import type { Fence } from './policy.ts';
|
|
12
|
+
import type { BindingStore, Grant } from './store.ts';
|
|
13
|
+
import type { AgentLike, SandboxPolicy, SessionLike, WorkingDirectoryLike } from './types.ts';
|
|
14
|
+
/** What {@link decideAccess} reads. */
|
|
15
|
+
export interface AccessDeps {
|
|
16
|
+
readonly store: BindingStore;
|
|
17
|
+
readonly fence: Fence;
|
|
18
|
+
readonly workingDirectory: WorkingDirectoryLike;
|
|
19
|
+
/** The session's enforced (already narrowed) sandbox policy. */
|
|
20
|
+
readonly resolvePolicy: (session: SessionLike) => SandboxPolicy;
|
|
21
|
+
}
|
|
22
|
+
/** One delegation call's access arguments, unvalidated. */
|
|
23
|
+
export interface AccessRequest {
|
|
24
|
+
readonly parent: AgentLike;
|
|
25
|
+
readonly cwd: unknown;
|
|
26
|
+
readonly writablePaths: unknown;
|
|
27
|
+
readonly signal?: AbortSignal;
|
|
28
|
+
}
|
|
29
|
+
/** The decided access of a child that is about to start. */
|
|
30
|
+
export interface ChildAccess {
|
|
31
|
+
/** Directory to start the child in; undefined inherits the parent's. */
|
|
32
|
+
readonly cwd?: string;
|
|
33
|
+
/** Canonical sub-workspace, or null for none. */
|
|
34
|
+
readonly workspace: string | null;
|
|
35
|
+
/** Grants from `writable_paths`. */
|
|
36
|
+
readonly grants: readonly Grant[];
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Decide a new child's sub-workspace and grants, creating the sub-workspace and
|
|
40
|
+
* any granted directory that does not exist yet.
|
|
41
|
+
* @param deps - store, fence, and host services.
|
|
42
|
+
* @param request - the call's parent and arguments.
|
|
43
|
+
* @returns the child's access and start directory.
|
|
44
|
+
* @throws with a model-facing reason when the call must not run.
|
|
45
|
+
*/
|
|
46
|
+
export declare function decideAccess(deps: AccessDeps, request: AccessRequest): Promise<ChildAccess>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a new child may modify, decided from the delegation call's `cwd` and
|
|
3
|
+
* `writable_paths` before the child exists.
|
|
4
|
+
*
|
|
5
|
+
* A `cwd` the parent may modify becomes the child's sub-workspace and is created
|
|
6
|
+
* if missing; no `cwd`, or one outside the parent's writable area, gives the
|
|
7
|
+
* child none. `writable_paths` become grants, checked against the parent's own
|
|
8
|
+
* reach, so nothing outside it can be handed down.
|
|
9
|
+
* @module complete-subagent/host/access
|
|
10
|
+
*/
|
|
11
|
+
import { mkdirSync } from 'node:fs';
|
|
12
|
+
import { issueGrants, requestedPaths } from "./grants.js";
|
|
13
|
+
import { canonical, resolveFrom } from "./paths.js";
|
|
14
|
+
/**
|
|
15
|
+
* Decide a new child's sub-workspace and grants, creating the sub-workspace and
|
|
16
|
+
* any granted directory that does not exist yet.
|
|
17
|
+
* @param deps - store, fence, and host services.
|
|
18
|
+
* @param request - the call's parent and arguments.
|
|
19
|
+
* @returns the child's access and start directory.
|
|
20
|
+
* @throws with a model-facing reason when the call must not run.
|
|
21
|
+
*/
|
|
22
|
+
export async function decideAccess(deps, request) {
|
|
23
|
+
const { parent } = request;
|
|
24
|
+
const writable = request.writablePaths ?? [];
|
|
25
|
+
if (!Array.isArray(writable) || writable.some(path => typeof path !== 'string' || path.trim() === '')) {
|
|
26
|
+
throw new Error('writable_paths must be a list of paths');
|
|
27
|
+
}
|
|
28
|
+
if (request.cwd !== undefined && typeof request.cwd !== 'string')
|
|
29
|
+
throw new Error('cwd must be a path');
|
|
30
|
+
const base = await deps.workingDirectory.ensure(parent, request.signal);
|
|
31
|
+
const policy = deps.resolvePolicy(parent.session);
|
|
32
|
+
const grants = issueGrants({
|
|
33
|
+
fence: deps.fence,
|
|
34
|
+
store: deps.store,
|
|
35
|
+
grantor: parent,
|
|
36
|
+
policy,
|
|
37
|
+
targets: requestedPaths(base, writable),
|
|
38
|
+
requestId: 'spawn',
|
|
39
|
+
});
|
|
40
|
+
if (request.cwd === undefined || request.cwd.trim() === '')
|
|
41
|
+
return { workspace: null, grants };
|
|
42
|
+
const target = canonical(resolveFrom(base, request.cwd));
|
|
43
|
+
if (!deps.fence.canModify(policy, parent.session, target, 'dir'))
|
|
44
|
+
return { cwd: target, workspace: null, grants };
|
|
45
|
+
try {
|
|
46
|
+
mkdirSync(target, { recursive: true });
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
// Not a directory (or not creatable): the host reports it when the child starts.
|
|
50
|
+
return { cwd: target, workspace: null, grants };
|
|
51
|
+
}
|
|
52
|
+
const workspace = canonical(target);
|
|
53
|
+
return { cwd: workspace, workspace, grants };
|
|
54
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The tool call whose body is running, for code that the body reaches only
|
|
3
|
+
* indirectly. The sandbox policy is resolved deep inside a tool body with just a
|
|
4
|
+
* session, so a single-file grant can only be honored if the fence can see which
|
|
5
|
+
* call, and which target, asked. A `tools/execute` waterfall listener enters this
|
|
6
|
+
* scope around each body; async work started by the body inherits it.
|
|
7
|
+
* @module complete-subagent/host/call-scope
|
|
8
|
+
*/
|
|
9
|
+
import type { ToolCallLike } from './types.ts';
|
|
10
|
+
/**
|
|
11
|
+
* The call whose body is running in this async context.
|
|
12
|
+
* @returns the call, or undefined outside a tool body.
|
|
13
|
+
*/
|
|
14
|
+
export declare function currentCall(): ToolCallLike | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Run a tool body inside the scope of its call.
|
|
17
|
+
* @param call - the dispatching call.
|
|
18
|
+
* @param run - the body (the waterfall's `next`).
|
|
19
|
+
* @returns whatever the body returns.
|
|
20
|
+
*/
|
|
21
|
+
export declare function withinCall<T>(call: ToolCallLike, run: () => T): T;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The tool call whose body is running, for code that the body reaches only
|
|
3
|
+
* indirectly. The sandbox policy is resolved deep inside a tool body with just a
|
|
4
|
+
* session, so a single-file grant can only be honored if the fence can see which
|
|
5
|
+
* call, and which target, asked. A `tools/execute` waterfall listener enters this
|
|
6
|
+
* scope around each body; async work started by the body inherits it.
|
|
7
|
+
* @module complete-subagent/host/call-scope
|
|
8
|
+
*/
|
|
9
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
10
|
+
const storage = new AsyncLocalStorage();
|
|
11
|
+
/**
|
|
12
|
+
* The call whose body is running in this async context.
|
|
13
|
+
* @returns the call, or undefined outside a tool body.
|
|
14
|
+
*/
|
|
15
|
+
export function currentCall() {
|
|
16
|
+
return storage.getStore();
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Run a tool body inside the scope of its call.
|
|
20
|
+
* @param call - the dispatching call.
|
|
21
|
+
* @param run - the body (the waterfall's `next`).
|
|
22
|
+
* @returns whatever the body returns.
|
|
23
|
+
*/
|
|
24
|
+
export function withinCall(call, run) {
|
|
25
|
+
return storage.run(call, run);
|
|
26
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The delegation tools: `delegate` starts a fresh child on the host's `spawn`
|
|
3
|
+
* backend, `delegate_fork` one that inherits this conversation on `fork`.
|
|
4
|
+
*
|
|
5
|
+
* Children run on the host's own subagent runtime, so `send_message`,
|
|
6
|
+
* `list_agents`, `interrupt_agent`, the child conversations in the UI, result
|
|
7
|
+
* notices, and cold resume all work as they do for the official tools. The
|
|
8
|
+
* call decides the child's access and route first, stores the binding under a
|
|
9
|
+
* reserved child id, and only then starts the child, so the fence applies from
|
|
10
|
+
* the child's first step and no binding has to be matched afterwards.
|
|
11
|
+
* @module complete-subagent/host/delegate
|
|
12
|
+
*/
|
|
13
|
+
import type { ToolDefinition } from '@deepseek-ai/dsh-tools';
|
|
14
|
+
import type { ChildModel } from '../shared/settings.ts';
|
|
15
|
+
import type { AccessDeps } from './access.ts';
|
|
16
|
+
import type { AgentLike, DelegateTool, LlmLike, SubagentsLike } from './types.ts';
|
|
17
|
+
/** What the delegation tools read. */
|
|
18
|
+
export interface DelegateDeps extends AccessDeps {
|
|
19
|
+
readonly subagents: SubagentsLike;
|
|
20
|
+
/** The LLM runtime, read at call time because it is optional. */
|
|
21
|
+
readonly llm: () => LlmLike | undefined;
|
|
22
|
+
/** Reserves child ids; replaceable in tests. */
|
|
23
|
+
readonly newId?: () => string;
|
|
24
|
+
/** Agent preset a `delegate` child runs; undefined keeps the parent's. */
|
|
25
|
+
readonly childPreset?: string;
|
|
26
|
+
/** False keeps a `delegate` child off the parent's own model when models are listed. */
|
|
27
|
+
readonly ownModel?: boolean;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Build one delegation tool for the current settings. The model list is fixed
|
|
31
|
+
* into the schema, so the entry rebuilds the tools when the settings change.
|
|
32
|
+
* @param tool - which tool.
|
|
33
|
+
* @param models - the settings' model list.
|
|
34
|
+
* @param deps - shared state and services.
|
|
35
|
+
* @returns a registry-ready definition.
|
|
36
|
+
*/
|
|
37
|
+
export declare function createDelegateTool(tool: DelegateTool, models: readonly ChildModel[], deps: DelegateDeps): ToolDefinition;
|
|
38
|
+
/**
|
|
39
|
+
* Whether an agent may delegate on a backend now: the backend is registered
|
|
40
|
+
* and the agent is below the user's depth limit. A limit that cannot be read
|
|
41
|
+
* leaves the tool visible; the runtime then rejects the start.
|
|
42
|
+
* @param subagents - the subagent runtime.
|
|
43
|
+
* @param tool - which tool.
|
|
44
|
+
* @param agent - the would-be parent.
|
|
45
|
+
* @returns true when the tool should be offered.
|
|
46
|
+
*/
|
|
47
|
+
export declare function canStart(subagents: SubagentsLike, tool: DelegateTool, agent: AgentLike): boolean;
|