dsh-agent-team-presets 0.1.4 → 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 +21 -4
- package/README.zh.md +21 -4
- package/lib/client.js +42 -42
- package/lib/index.js +231 -67
- package/lib/types/index.js +12 -6
- package/lib/types/member-identity.d.ts +56 -11
- package/lib/types/member-identity.js +239 -76
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
English | [中文](<README.zh.md>)
|
|
8
8
|
|
|
9
|
-
> **Community plugin v0.1.
|
|
9
|
+
> **Community plugin v0.1.5** · [Release](https://github.com/bloodarea/dsh-agent-team-presets/releases/tag/v0.1.5)
|
|
10
10
|
>
|
|
11
11
|
> Requires a compatible DeepSeek Harness deployment with Agent Teams enabled. This version uses rc.2 APIs; see [Requirements](#requirements). Prebuilt artifacts are included, so installation does not require a source build.
|
|
12
12
|
|
|
@@ -67,7 +67,7 @@ DeepSeek Harness already ships Agent Teams with multi-agent collaboration. In th
|
|
|
67
67
|
<a id="screenshots"></a>
|
|
68
68
|
## Screenshots
|
|
69
69
|
|
|
70
|
-
The screenshots illustrate the composer control and settings workflow. Example Team and provider names are illustrative; available models and tools depend on your deployment. Some screenshots show an earlier UI revision, so controls and helper text may differ from v0.1.
|
|
70
|
+
The screenshots illustrate the composer control and settings workflow. Example Team and provider names are illustrative; available models and tools depend on your deployment. Some screenshots show an earlier UI revision, so controls and helper text may differ from v0.1.5. The permission rules below describe the current version.
|
|
71
71
|
|
|
72
72
|
**Choose a Team in the composer**
|
|
73
73
|
|
|
@@ -114,11 +114,28 @@ The screenshots illustrate the composer control and settings workflow. Example T
|
|
|
114
114
|
- **A Web or Desktop profile with Settings and the required client services.** Install into the profile you actually use, typically `web` for the Web GUI or `desktop` for Desktop.
|
|
115
115
|
- **Durable storage and a continuable subagent backend for member execution.** Member creation is refused if the storage domain or the selected execution backend is unavailable. The default backend names are `spawn` and `fork`; custom deployments must configure compatible backends.
|
|
116
116
|
|
|
117
|
-
The plugin version (`0.1.
|
|
117
|
+
The plugin version (`0.1.5`) and the Harness version (`0.2.0-rc.2`, for example) are separate version lines.
|
|
118
118
|
|
|
119
119
|
<a id="use-this-package"></a>
|
|
120
120
|
## Install and upgrade
|
|
121
121
|
|
|
122
|
+
### One-click install in the GUI (Add plugin)
|
|
123
|
+
|
|
124
|
+
No command line required: open **Global panels → Plugins → Add plugin**, paste the line below into **Package name or address**, and click **Install**.
|
|
125
|
+
|
|
126
|
+
```text
|
|
127
|
+
dsh-agent-team-presets@0.1.5
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
<!-- release-version: keep in sync with package.json version -->
|
|
131
|
+
|
|
132
|
+
- **Registry** selects which npm source the download comes from. **Default registry** means whatever pnpm's own configuration names: on a machine whose `~/.npmrc` already points at `registry.npmmirror.com`, that *is* the mainland mirror, so the dialog lists no separate **Mainland China mirror** entry. Pick **Official npm registry** to bypass a mirror, or **Custom address** for a third source — an internal registry, or another mirror such as `https://mirrors.cloud.tencent.com/npm/` or `https://repo.huaweicloud.com/repository/npm/`.
|
|
133
|
+
- `@0.1.5` names the version; drop it and enter `dsh-agent-team-presets` to take whatever npm currently publishes.
|
|
134
|
+
- The field takes the same specs as `dsh plugin add`: a package name, `name@version`, `github:owner/repo`, a tarball URL, or an absolute path. The check before installing queries the package, so a version that does not exist or a package without `dsh.bundle` is refused before anything is written.
|
|
135
|
+
- This package declares its own `dsh.bundle`, so the plugin manager registers it as a profile bundle layer; do not add a loader entry by hand.
|
|
136
|
+
- Once the package is installed the field cannot install it again: the manager matches on package name and reports that it is already installed. To change installation source (for example from `github:…#v0.1.4` to the npm form), uninstall it in the plugin list first, then paste the spec above.
|
|
137
|
+
- The plugin manager only installs and enables; reload or restart as it instructs afterwards. Use the npm form when you want later releases to be offered; a pinned-ref source install is compared only with that ref and never advertises a newer one (see below).
|
|
138
|
+
|
|
122
139
|
### Install from GitHub
|
|
123
140
|
|
|
124
141
|
For an installation that can receive repository-version update notifications:
|
|
@@ -320,7 +337,7 @@ In Harness `0.2.0-rc.2`, the Team roster and `list_agents.model` read creation-t
|
|
|
320
337
|
- Team definitions and Session selections live in profile settings, not a structured selection history in the Session event log. Rendered prompts may contain the Team name, but they do not make the selection portable: a fork or a move to another deployment needs an explicit Team selection and matching settings.
|
|
321
338
|
- Already-created members retain their creation-time persona, description, route, and tool policy, including when resumed with `send_message`. Saved preset changes apply to future instances; send an existing member a message to adjust its immediate task.
|
|
322
339
|
- Legacy captain route fields are removed during settings reconciliation because captains use the conversation's model. Back up configuration before migrating older profiles.
|
|
323
|
-
- The bundled schema runtime
|
|
340
|
+
- The bundled schema runtime fixes missing-`zod` startup imports from earlier package builds. It does not repair unrelated Harness installation, encoding, lock, or third-party plugin failures.
|
|
324
341
|
|
|
325
342
|
<a id="understand-the-implementation"></a>
|
|
326
343
|
## How it works
|
package/README.zh.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
[English](<README.md>) | 中文
|
|
8
8
|
|
|
9
|
-
> **社区插件 v0.1.
|
|
9
|
+
> **社区插件 v0.1.5** · [发布版本](https://github.com/bloodarea/dsh-agent-team-presets/releases/tag/v0.1.5)
|
|
10
10
|
>
|
|
11
11
|
> 需要启用 Agent Teams 的兼容 DeepSeek Harness 部署。本版本使用 rc.2 API,详见[环境要求](#requirements)。仓库已包含预构建产物,安装时无需从源码构建。
|
|
12
12
|
|
|
@@ -67,7 +67,7 @@ DeepSeek Harness 原生 Agent Teams 已经具备多智能体协作能力。在
|
|
|
67
67
|
<a id="screenshots"></a>
|
|
68
68
|
## 界面预览
|
|
69
69
|
|
|
70
|
-
以下截图展示会话输入区的团队控件和设置流程。团队与提供商名称仅作示例,实际模型和工具取决于你的部署。部分截图来自较早的界面版本,控件和辅助文案可能与 v0.1.
|
|
70
|
+
以下截图展示会话输入区的团队控件和设置流程。团队与提供商名称仅作示例,实际模型和工具取决于你的部署。部分截图来自较早的界面版本,控件和辅助文案可能与 v0.1.5 不同;当前权限行为以下文说明为准。
|
|
71
71
|
|
|
72
72
|
**在会话输入区选择团队**
|
|
73
73
|
|
|
@@ -114,11 +114,28 @@ DeepSeek Harness 原生 Agent Teams 已经具备多智能体协作能力。在
|
|
|
114
114
|
- **具备 Settings 与所需客户端服务的 Web 或 Desktop profile。** 安装到实际使用的 profile:Web GUI 通常为 `web`,Desktop 通常为 `desktop`。
|
|
115
115
|
- **成员执行所需的持久存储与支持恢复执行的子智能体后端。** 缺少 storage domain 或所选执行后端时,插件会拒绝创建成员。默认后端名为 `spawn` 和 `fork`,自定义部署须提供兼容后端。
|
|
116
116
|
|
|
117
|
-
插件版本(如 `0.1.
|
|
117
|
+
插件版本(如 `0.1.5`)和 Harness 版本(如 `0.2.0-rc.2`)是不同的版本线。
|
|
118
118
|
|
|
119
119
|
<a id="use-this-package"></a>
|
|
120
120
|
## 安装与升级
|
|
121
121
|
|
|
122
|
+
### 在 GUI 中一键安装(添加插件)
|
|
123
|
+
|
|
124
|
+
不必使用命令行:打开 **全局面板 → 插件 → 添加插件**,把下面这一行粘贴到「包名或地址」,点 **安装**。
|
|
125
|
+
|
|
126
|
+
```text
|
|
127
|
+
dsh-agent-team-presets@0.1.5
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
<!-- release-version: 与 package.json 的 version 同步 -->
|
|
131
|
+
|
|
132
|
+
- **安装源**决定从哪个 npm 源下载。「默认安装源」指 pnpm 自身配置所指的源:若本机 `~/.npmrc` 已经指向 `registry.npmmirror.com`,默认源就是国内镜像,列表里不会再出现单独的「中国大陆镜像源」项。要绕开镜像选「npm 官方源」;要换第三个源(内网私有源,或腾讯云 `https://mirrors.cloud.tencent.com/npm/`、华为云 `https://repo.huaweicloud.com/repository/npm/` 这类镜像)选「自定义地址」。
|
|
133
|
+
- `@0.1.5` 指定版本;想装 npm 上当前的最新版,去掉它只填 `dsh-agent-team-presets`。
|
|
134
|
+
- 输入框与 `dsh plugin add` 接受同一套规格:`包名`、`包名@版本`、`github:作者/仓库`、压缩包地址或绝对路径。安装前会对包做一次查询,版本不存在、或包没有声明 `dsh.bundle`,都会在安装前被拒。
|
|
135
|
+
- 本包声明了自己的 `dsh.bundle`,安装后由插件管理器登记为 profile 的 bundle 层,不要再手写 loader 条目。
|
|
136
|
+
- 已安装本包时无法再用输入框安装:插件管理器按包名判定,会提示「该插件已安装」。要更换安装来源(例如把 `github:…#v0.1.4` 换成 npm 形式),先在插件列表里卸载,再执行上面的粘贴安装。
|
|
137
|
+
- 插件管理器本身只负责安装与启用,装完后按它的提示重新加载或重启。需要后续版本提示时用 npm 形式;固定 ref 的源码安装只与同一 ref 比较,不会提示新版本(原因见下文)。
|
|
138
|
+
|
|
122
139
|
### 从 GitHub 安装
|
|
123
140
|
|
|
124
141
|
需要接收仓库新版本更新提示时,使用不固定 ref 的安装方式:
|
|
@@ -320,7 +337,7 @@ Configuration for "agent-team-presets" is overridden by a home patch or command-
|
|
|
320
337
|
- 团队定义和会话选择存储在 profile 设置中,而不是会话事件日志中的结构化选择历史。渲染后的提示词可能包含团队名称,但不能据此迁移选择;fork 或迁移到其他部署时,仍须明确选择团队并具备相应设置。
|
|
321
338
|
- 已创建成员保留创建时的 persona、描述、路由和工具策略,通过 `send_message` 恢复时也不变。预设更新用于未来实例;可向已有成员发消息调整当前任务。
|
|
322
339
|
- 设置协调会移除旧版队长路由字段,因为队长使用会话模型。迁移旧 profile 前应备份配置。
|
|
323
|
-
-
|
|
340
|
+
- 将 schema 运行时代码内联,修复早期构建缺少 `zod` 导致的启动导入失败;不修复无关的 Harness 安装、编码、锁或第三方插件故障。
|
|
324
341
|
|
|
325
342
|
<a id="understand-the-implementation"></a>
|
|
326
343
|
## 工作原理
|
package/lib/client.js
CHANGED
|
@@ -4524,11 +4524,11 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
4524
4524
|
document.head.appendChild(style);
|
|
4525
4525
|
}
|
|
4526
4526
|
var ComposerTeamSelect_module_css_default = {
|
|
4527
|
+
"accentDot": "Q4LFCW_accentDot",
|
|
4528
|
+
"failure": "Q4LFCW_failure",
|
|
4527
4529
|
"triggerIcon": "Q4LFCW_triggerIcon",
|
|
4528
|
-
"triggerLabel": "Q4LFCW_triggerLabel",
|
|
4529
4530
|
"trigger": "Q4LFCW_trigger",
|
|
4530
|
-
"
|
|
4531
|
-
"failure": "Q4LFCW_failure"
|
|
4531
|
+
"triggerLabel": "Q4LFCW_triggerLabel"
|
|
4532
4532
|
};
|
|
4533
4533
|
|
|
4534
4534
|
|
|
@@ -6409,57 +6409,57 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
6409
6409
|
document.head.appendChild(style);
|
|
6410
6410
|
}
|
|
6411
6411
|
var TeamPresetsSection_module_css_default = {
|
|
6412
|
-
"
|
|
6413
|
-
"actionRow": "_628ArG_actionRow",
|
|
6414
|
-
"conflictName": "_628ArG_conflictName",
|
|
6415
|
-
"sectionTitle": "_628ArG_sectionTitle",
|
|
6412
|
+
"section": "_628ArG_section",
|
|
6416
6413
|
"choiceRow": "_628ArG_choiceRow",
|
|
6417
|
-
"card": "_628ArG_card",
|
|
6418
|
-
"cardTitle": "_628ArG_cardTitle",
|
|
6419
|
-
"rowMeta": "_628ArG_rowMeta",
|
|
6420
|
-
"field": "_628ArG_field",
|
|
6421
|
-
"fieldLabel": "_628ArG_fieldLabel",
|
|
6422
|
-
"hint": "_628ArG_hint",
|
|
6423
|
-
"swatchNone": "_628ArG_swatchNone",
|
|
6424
|
-
"swatch": "_628ArG_swatch",
|
|
6425
6414
|
"toolGroup": "_628ArG_toolGroup",
|
|
6415
|
+
"plainRows": "_628ArG_plainRows",
|
|
6426
6416
|
"input": "_628ArG_input",
|
|
6417
|
+
"field": "_628ArG_field",
|
|
6418
|
+
"footerActions": "_628ArG_footerActions",
|
|
6419
|
+
"toolGroupCount": "_628ArG_toolGroupCount",
|
|
6427
6420
|
"select": "_628ArG_select",
|
|
6428
|
-
"
|
|
6429
|
-
"conflict": "_628ArG_conflict",
|
|
6430
|
-
"dot": "_628ArG_dot",
|
|
6431
|
-
"rowActions": "_628ArG_rowActions",
|
|
6432
|
-
"plainRows": "_628ArG_plainRows",
|
|
6421
|
+
"cardTitle": "_628ArG_cardTitle",
|
|
6433
6422
|
"rowMain": "_628ArG_rowMain",
|
|
6434
|
-
"
|
|
6435
|
-
"
|
|
6423
|
+
"title": "_628ArG_title",
|
|
6424
|
+
"conflictName": "_628ArG_conflictName",
|
|
6436
6425
|
"intro": "_628ArG_intro",
|
|
6437
|
-
"
|
|
6438
|
-
"
|
|
6439
|
-
"
|
|
6440
|
-
"
|
|
6441
|
-
"pageHead": "_628ArG_pageHead",
|
|
6426
|
+
"rowMeta": "_628ArG_rowMeta",
|
|
6427
|
+
"chevron": "_628ArG_chevron",
|
|
6428
|
+
"actionRow": "_628ArG_actionRow",
|
|
6429
|
+
"warn": "_628ArG_warn",
|
|
6442
6430
|
"footer": "_628ArG_footer",
|
|
6443
|
-
"
|
|
6444
|
-
"
|
|
6445
|
-
"
|
|
6446
|
-
"
|
|
6431
|
+
"card": "_628ArG_card",
|
|
6432
|
+
"toolGroupToggle": "_628ArG_toolGroupToggle",
|
|
6433
|
+
"sectionTitle": "_628ArG_sectionTitle",
|
|
6434
|
+
"prompt": "_628ArG_prompt",
|
|
6447
6435
|
"crumb": "_628ArG_crumb",
|
|
6436
|
+
"fieldLabel": "_628ArG_fieldLabel",
|
|
6437
|
+
"swatches": "_628ArG_swatches",
|
|
6448
6438
|
"rows": "_628ArG_rows",
|
|
6449
|
-
"
|
|
6450
|
-
"
|
|
6439
|
+
"conflictLead": "_628ArG_conflictLead",
|
|
6440
|
+
"entryRow": "_628ArG_entryRow",
|
|
6451
6441
|
"footerNotes": "_628ArG_footerNotes",
|
|
6452
|
-
"
|
|
6453
|
-
"
|
|
6442
|
+
"conflict": "_628ArG_conflict",
|
|
6443
|
+
"swatch": "_628ArG_swatch",
|
|
6444
|
+
"hint": "_628ArG_hint",
|
|
6445
|
+
"choice": "_628ArG_choice",
|
|
6446
|
+
"rowActions": "_628ArG_rowActions",
|
|
6454
6447
|
"fileInput": "_628ArG_fileInput",
|
|
6455
|
-
"
|
|
6456
|
-
"
|
|
6457
|
-
"
|
|
6458
|
-
"
|
|
6448
|
+
"toolGroupHead": "_628ArG_toolGroupHead",
|
|
6449
|
+
"pageHead": "_628ArG_pageHead",
|
|
6450
|
+
"footerNote": "_628ArG_footerNote",
|
|
6451
|
+
"toolCheckbox": "_628ArG_toolCheckbox",
|
|
6452
|
+
"empty": "_628ArG_empty",
|
|
6453
|
+
"cardHead": "_628ArG_cardHead",
|
|
6454
|
+
"dot": "_628ArG_dot",
|
|
6455
|
+
"rowText": "_628ArG_rowText",
|
|
6456
|
+
"rowName": "_628ArG_rowName",
|
|
6459
6457
|
"toolGrid": "_628ArG_toolGrid",
|
|
6460
|
-
"
|
|
6461
|
-
"
|
|
6462
|
-
"
|
|
6458
|
+
"conflictMember": "_628ArG_conflictMember",
|
|
6459
|
+
"selectLabel": "_628ArG_selectLabel",
|
|
6460
|
+
"swatchNone": "_628ArG_swatchNone",
|
|
6461
|
+
"entry": "_628ArG_entry",
|
|
6462
|
+
"page": "_628ArG_page"
|
|
6463
6463
|
};
|
|
6464
6464
|
|
|
6465
6465
|
|
package/lib/index.js
CHANGED
|
@@ -386,12 +386,22 @@ async function routeRefusal(ctx, route) {
|
|
|
386
386
|
* whole provider contract to the deployment's own provider, so fresh/fork
|
|
387
387
|
* history semantics, cancellation, and concurrency isolation are unchanged.
|
|
388
388
|
*
|
|
389
|
+
* Aliases therefore have to exist exactly while their upstream provider does,
|
|
390
|
+
* whatever order the two plugins activate in. The registry built here is
|
|
391
|
+
* self-maintaining: it scans once when it subscribes, follows
|
|
392
|
+
* `subagent/provider-added` and `subagent/provider-removed` afterwards, and
|
|
393
|
+
* re-validates every alias whenever its upstream may have changed. Nothing
|
|
394
|
+
* about the mount order of this plugin and the provider plugins is assumed, and
|
|
395
|
+
* no alias failure is remembered past the moment it stops being true.
|
|
396
|
+
*
|
|
389
397
|
* @module dsh-agent-team-presets/member-identity
|
|
390
398
|
*/
|
|
391
399
|
/** Alias a fresh member is created through; persisted by the Host as its provider. */
|
|
392
400
|
const MEMBER_FRESH_PROVIDER = "preset-member-fresh-v1";
|
|
393
401
|
/** Alias a forked member is created through; persisted by the Host as its provider. */
|
|
394
402
|
const MEMBER_FORK_PROVIDER = "preset-member-fork-v1";
|
|
403
|
+
/** The two spawn contexts, in the fixed order their aliases are maintained. */
|
|
404
|
+
const CONTEXTS = ["fresh", "fork"];
|
|
395
405
|
/** Every alias this plugin registers. The set is fixed and versioned. */
|
|
396
406
|
const ALIASES = new Set([MEMBER_FRESH_PROVIDER, MEMBER_FORK_PROVIDER]);
|
|
397
407
|
/**
|
|
@@ -422,7 +432,12 @@ function memberProviderMarker(agent) {
|
|
|
422
432
|
}
|
|
423
433
|
/**
|
|
424
434
|
* Resolve the alias one spawn context must be created through.
|
|
425
|
-
*
|
|
435
|
+
*
|
|
436
|
+
* Called at member-creation time, so the answer is read from the aliases that
|
|
437
|
+
* exist NOW rather than from the state one startup scan happened to observe: a
|
|
438
|
+
* provider that registered after this plugin activated is usable, and one that
|
|
439
|
+
* has since been removed is refused.
|
|
440
|
+
* @param registry - the aliases this activation maintains.
|
|
426
441
|
* @param context - the configured spawn context of the member about to be created.
|
|
427
442
|
* @returns the alias to spawn through, or the refusal for that context.
|
|
428
443
|
*/
|
|
@@ -453,83 +468,232 @@ function aliasProvider(alias, upstream) {
|
|
|
453
468
|
};
|
|
454
469
|
}
|
|
455
470
|
/**
|
|
456
|
-
* Register the member aliases, delegating to the configured providers
|
|
471
|
+
* Register the member aliases, delegating to the configured providers, and keep
|
|
472
|
+
* them in step with the provider registry for as long as this activation lives.
|
|
457
473
|
*
|
|
458
474
|
* The two spawn contexts are independent: a deployment that composes only a
|
|
459
475
|
* fresh provider still serves fresh members, while a forked member is refused
|
|
460
476
|
* with the reason its own backend is unusable. A configured name that is itself
|
|
461
477
|
* an alias is always refused — the wrapper must never become its own backend —
|
|
462
|
-
* and so is a name
|
|
463
|
-
*
|
|
464
|
-
*
|
|
465
|
-
*
|
|
466
|
-
*
|
|
478
|
+
* and so is a name whose provider cannot create continuable children, or whose
|
|
479
|
+
* alias registration fails. A configured name the deployment does not (or does
|
|
480
|
+
* not yet) register is refused only while it stays absent: the aliases are
|
|
481
|
+
* re-validated on every provider registry event, so a provider that activates
|
|
482
|
+
* later is picked up without restarting this plugin, and one that is replaced
|
|
483
|
+
* has its wrapper rebound to the new object.
|
|
484
|
+
*
|
|
485
|
+
* Registration failure is reported per context rather than skipped: a member
|
|
486
|
+
* created through the deployment's own provider would carry no marker and could
|
|
487
|
+
* not be told apart from a native teammate after a restart.
|
|
467
488
|
* @param ctx - the plugin context carrying the subagent service.
|
|
468
489
|
* @param configured - the deployment's fresh/fork provider names from the plugin config.
|
|
469
|
-
* @
|
|
490
|
+
* @param onAvailability - optional observer of each context's availability change.
|
|
491
|
+
* @returns the maintained aliases, whose `dispose` releases every registration.
|
|
470
492
|
*/
|
|
471
|
-
function registerMemberProviders(ctx, configured) {
|
|
472
|
-
const
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
493
|
+
function registerMemberProviders(ctx, configured, onAvailability = () => {}) {
|
|
494
|
+
const states = {
|
|
495
|
+
fresh: {
|
|
496
|
+
alias: MEMBER_FRESH_PROVIDER,
|
|
497
|
+
upstreamName: configured.fresh,
|
|
498
|
+
upstream: void 0,
|
|
499
|
+
release: void 0,
|
|
500
|
+
failure: void 0,
|
|
501
|
+
reported: false
|
|
502
|
+
},
|
|
503
|
+
fork: {
|
|
504
|
+
alias: MEMBER_FORK_PROVIDER,
|
|
505
|
+
upstreamName: configured.fork,
|
|
506
|
+
upstream: void 0,
|
|
507
|
+
release: void 0,
|
|
508
|
+
failure: void 0,
|
|
509
|
+
reported: false
|
|
510
|
+
}
|
|
482
511
|
};
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
}
|
|
510
|
-
try {
|
|
511
|
-
sponsored.push(subagents.registerProvider(aliasProvider(alias, upstream)));
|
|
512
|
-
} catch (error) {
|
|
513
|
-
errors[context] = `the ${context} member execution alias "${alias}" could not be registered: ${String(error)}`;
|
|
514
|
-
}
|
|
512
|
+
let disposed = false;
|
|
513
|
+
let reconciling = false;
|
|
514
|
+
/**
|
|
515
|
+
* Look up an upstream provider without letting a broken registry take the
|
|
516
|
+
* plugin down: the Settings page and the preset tools belong to such a
|
|
517
|
+
* deployment; only member creation has no channel.
|
|
518
|
+
* @param name - the configured upstream provider name.
|
|
519
|
+
* @returns the provider, or the refusal kind and reason instead.
|
|
520
|
+
*/
|
|
521
|
+
const lookup = (name) => {
|
|
522
|
+
const subagents = ctx.get("subagents");
|
|
523
|
+
if (subagents === void 0) return {
|
|
524
|
+
state: "missing",
|
|
525
|
+
reason: "this deployment composes no subagent service, so a Team member cannot be created through this plugin's identity alias."
|
|
526
|
+
};
|
|
527
|
+
try {
|
|
528
|
+
const provider = subagents.getProvider(name);
|
|
529
|
+
return provider === void 0 ? {
|
|
530
|
+
state: "missing",
|
|
531
|
+
reason: `this deployment registers no subagent provider named "${name}".`
|
|
532
|
+
} : { provider };
|
|
533
|
+
} catch (error) {
|
|
534
|
+
return {
|
|
535
|
+
state: "registration",
|
|
536
|
+
reason: `the subagent providers could not be read: ${String(error)}`
|
|
537
|
+
};
|
|
515
538
|
}
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
539
|
+
};
|
|
540
|
+
/**
|
|
541
|
+
* Release one context's live alias, if it has one.
|
|
542
|
+
*
|
|
543
|
+
* The upstream is cleared BEFORE the registration is released, so the
|
|
544
|
+
* `subagent/provider-removed` this release emits cannot be mistaken for the
|
|
545
|
+
* deployment withdrawing the provider, and cannot re-enter this sweep.
|
|
546
|
+
* @param state - the context whose alias is released.
|
|
547
|
+
*/
|
|
548
|
+
const detach = (state) => {
|
|
549
|
+
const release = state.release;
|
|
550
|
+
state.release = void 0;
|
|
551
|
+
state.upstream = void 0;
|
|
552
|
+
if (release !== void 0) release();
|
|
553
|
+
};
|
|
554
|
+
/**
|
|
555
|
+
* Report one context's availability, once per actual change.
|
|
556
|
+
* @param state - the context whose registration was updated.
|
|
557
|
+
* @param context - the spawn context, for the availability report.
|
|
558
|
+
*/
|
|
559
|
+
const report = (state, context) => {
|
|
560
|
+
const failure = state.failure;
|
|
561
|
+
if (failure === void 0) {
|
|
562
|
+
state.reported = false;
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
if (state.reported) return;
|
|
566
|
+
state.reported = true;
|
|
567
|
+
onAvailability(context, failure.state, failure.reason);
|
|
568
|
+
};
|
|
569
|
+
/**
|
|
570
|
+
* Record why one context is unusable, releasing the alias it may still hold.
|
|
571
|
+
*
|
|
572
|
+
* A refusal with a different *kind* than the one already standing is a new
|
|
573
|
+
* fact — a provider that was merely absent and now actively cannot back a
|
|
574
|
+
* member, for instance — so it is reported even though the context was
|
|
575
|
+
* already unusable.
|
|
576
|
+
* @param state - the context to refuse.
|
|
577
|
+
* @param reason - the refusal a member creation must report.
|
|
578
|
+
* @param failureState - the category of the refusal.
|
|
579
|
+
* @param context - the spawn context, for the availability report.
|
|
580
|
+
*/
|
|
581
|
+
const fail = (state, reason, failureState, context) => {
|
|
582
|
+
detach(state);
|
|
583
|
+
const previous = state.failure;
|
|
584
|
+
if (previous?.state !== failureState || previous.reason !== reason) state.reported = false;
|
|
585
|
+
state.failure = {
|
|
586
|
+
state: failureState,
|
|
587
|
+
reason
|
|
524
588
|
};
|
|
525
|
-
|
|
589
|
+
report(state, context);
|
|
590
|
+
};
|
|
591
|
+
/**
|
|
592
|
+
* Validate one context and register, rebind, or release its alias to match.
|
|
593
|
+
*
|
|
594
|
+
* Registration happens only on a real change — no live alias, or a live alias
|
|
595
|
+
* still delegating to the same upstream object — so the events this function
|
|
596
|
+
* causes can never make it re-register what it just registered.
|
|
597
|
+
* @param context - the spawn context to reconcile.
|
|
598
|
+
*/
|
|
599
|
+
const reconcile = (context) => {
|
|
600
|
+
const state = states[context];
|
|
601
|
+
if (state.upstreamName.trim() === "") {
|
|
602
|
+
fail(state, `the ${context} subagent provider is not configured, so a ${context} member cannot be created without losing the identity that proves it is preset-managed.`, "unconfigured", context);
|
|
603
|
+
return;
|
|
604
|
+
}
|
|
605
|
+
if (isPresetMemberProvider(state.upstreamName)) {
|
|
606
|
+
fail(state, `the ${context} subagent provider "${state.upstreamName}" is this plugin's own member alias; point the plugin at the deployment provider it should delegate to.`, "alias", context);
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
609
|
+
const found = lookup(state.upstreamName);
|
|
610
|
+
if ("state" in found) {
|
|
611
|
+
fail(state, found.state === "missing" ? found.reason + ` A ${context} member cannot be created through this plugin's identity alias.` : found.reason, found.state, context);
|
|
612
|
+
return;
|
|
613
|
+
}
|
|
614
|
+
const { provider } = found;
|
|
615
|
+
if (provider.prepareContinuable === void 0) {
|
|
616
|
+
fail(state, `subagent provider "${state.upstreamName}" cannot create continuable children, so it cannot back a ${context} Team member.`, "unsupported", context);
|
|
617
|
+
return;
|
|
618
|
+
}
|
|
619
|
+
if (state.upstream === provider) {
|
|
620
|
+
state.failure = void 0;
|
|
621
|
+
report(state, context);
|
|
622
|
+
return;
|
|
623
|
+
}
|
|
624
|
+
detach(state);
|
|
625
|
+
try {
|
|
626
|
+
const release = ctx.get("subagents")?.registerProvider(aliasProvider(state.alias, provider));
|
|
627
|
+
if (release === void 0) {
|
|
628
|
+
fail(state, `the ${context} member execution alias "${state.alias}" could not be registered: the subagent service was released while it was being registered.`, "registration", context);
|
|
629
|
+
return;
|
|
630
|
+
}
|
|
631
|
+
state.upstream = provider;
|
|
632
|
+
state.release = release;
|
|
633
|
+
} catch (error) {
|
|
634
|
+
fail(state, `the ${context} member execution alias "${state.alias}" could not be registered: ${String(error)}`, "registration", context);
|
|
635
|
+
return;
|
|
636
|
+
}
|
|
637
|
+
state.failure = void 0;
|
|
638
|
+
report(state, context);
|
|
639
|
+
};
|
|
640
|
+
/**
|
|
641
|
+
* Re-validate both contexts. Never runs inside another sweep: the events a
|
|
642
|
+
* registration or release emits re-enter here, and the outer sweep already
|
|
643
|
+
* covers them.
|
|
644
|
+
*/
|
|
645
|
+
const sweep = () => {
|
|
646
|
+
if (disposed || reconciling) return;
|
|
647
|
+
reconciling = true;
|
|
648
|
+
try {
|
|
649
|
+
for (const context of CONTEXTS) reconcile(context);
|
|
650
|
+
} finally {
|
|
651
|
+
reconciling = false;
|
|
652
|
+
}
|
|
653
|
+
};
|
|
654
|
+
/**
|
|
655
|
+
* Follow the provider registry for as long as this activation lives.
|
|
656
|
+
*
|
|
657
|
+
* Only providers this plugin does not own are interesting: its own aliases
|
|
658
|
+
* arrive here too, and following them would be a self-loop. The listeners are
|
|
659
|
+
* registered before the initial scan so a registration that lands in between
|
|
660
|
+
* is not missed.
|
|
661
|
+
* @param name - the provider name the event names, for `provider-added` and `provider-removed` alike.
|
|
662
|
+
*/
|
|
663
|
+
const follow = (name) => {
|
|
664
|
+
if (disposed || isPresetMemberProvider(name)) return;
|
|
665
|
+
sweep();
|
|
666
|
+
};
|
|
667
|
+
const disposers = [];
|
|
668
|
+
disposers.push(ctx.on("subagent/provider-added", (provider) => {
|
|
669
|
+
follow(provider.name);
|
|
670
|
+
}));
|
|
671
|
+
disposers.push(ctx.on("subagent/provider-removed", (name) => {
|
|
672
|
+
follow(name);
|
|
673
|
+
}));
|
|
674
|
+
sweep();
|
|
526
675
|
return {
|
|
527
|
-
fresh
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
676
|
+
get fresh() {
|
|
677
|
+
return states.fresh.alias;
|
|
678
|
+
},
|
|
679
|
+
get fork() {
|
|
680
|
+
return states.fork.alias;
|
|
681
|
+
},
|
|
682
|
+
get freshError() {
|
|
683
|
+
return states.fresh.failure?.reason;
|
|
684
|
+
},
|
|
685
|
+
get forkError() {
|
|
686
|
+
return states.fork.failure?.reason;
|
|
687
|
+
},
|
|
531
688
|
dispose: () => {
|
|
532
|
-
|
|
689
|
+
if (disposed) return;
|
|
690
|
+
disposed = true;
|
|
691
|
+
for (const off of disposers.splice(0).reverse()) off();
|
|
692
|
+
for (const context of CONTEXTS) {
|
|
693
|
+
const state = states[context];
|
|
694
|
+
detach(state);
|
|
695
|
+
state.failure = void 0;
|
|
696
|
+
}
|
|
533
697
|
}
|
|
534
698
|
};
|
|
535
699
|
}
|
|
@@ -7320,12 +7484,12 @@ function apply(ctx, config) {
|
|
|
7320
7484
|
const providers = registerMemberProviders(ctx, {
|
|
7321
7485
|
fresh: config.freshProvider,
|
|
7322
7486
|
fork: config.forkProvider
|
|
7487
|
+
}, (context, state, reason) => {
|
|
7488
|
+
if (state === "registration" || state === "unsupported" || state === "alias" || state === "unconfigured") ctx.logger.warn(`${LOG}: ${context} Team members are unavailable: %s`, reason);
|
|
7323
7489
|
});
|
|
7324
7490
|
ctx.effect(() => () => {
|
|
7325
7491
|
providers.dispose();
|
|
7326
7492
|
}, "agent-team-presets: member execution aliases");
|
|
7327
|
-
if (providers.freshError !== void 0) ctx.logger.warn(`${LOG}: fresh Team members are unavailable: %s`, providers.freshError);
|
|
7328
|
-
if (providers.forkError !== void 0) ctx.logger.warn(`${LOG}: forked Team members are unavailable: %s`, providers.forkError);
|
|
7329
7493
|
const quarantine = (agent, reason) => {
|
|
7330
7494
|
const previous = quarantines.get(agent);
|
|
7331
7495
|
if (previous !== void 0) {
|
package/lib/types/index.js
CHANGED
|
@@ -62,13 +62,19 @@ export function apply(ctx, config) {
|
|
|
62
62
|
const members = new MemberRuntime(ctx);
|
|
63
63
|
// Every member is summoned through this plugin's own execution alias, so the
|
|
64
64
|
// Host itself persists the fact that the child is preset-managed. The aliases
|
|
65
|
-
// delegate the whole provider contract to the deployment's providers
|
|
66
|
-
|
|
65
|
+
// delegate the whole provider contract to the deployment's providers, and
|
|
66
|
+
// this registry keeps them in step with a provider registry that may still be
|
|
67
|
+
// filling up: a provider that activates after this plugin is picked up, and a
|
|
68
|
+
// replaced or withdrawn one is rebound or refused, without restarting.
|
|
69
|
+
const providers = registerMemberProviders(ctx, { fresh: config.freshProvider, fork: config.forkProvider }, (context, state, reason) => {
|
|
70
|
+
// `missing` is the expected state while a provider plugin is still
|
|
71
|
+
// loading, so it is not an incident here. It is still the refusal a member
|
|
72
|
+
// creation reports if it is asked for one in that window.
|
|
73
|
+
if (state === 'registration' || state === 'unsupported' || state === 'alias' || state === 'unconfigured') {
|
|
74
|
+
ctx.logger.warn(`${LOG}: ${context} Team members are unavailable: %s`, reason);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
67
77
|
ctx.effect(() => () => { providers.dispose(); }, 'agent-team-presets: member execution aliases');
|
|
68
|
-
if (providers.freshError !== undefined)
|
|
69
|
-
ctx.logger.warn(`${LOG}: fresh Team members are unavailable: %s`, providers.freshError);
|
|
70
|
-
if (providers.forkError !== undefined)
|
|
71
|
-
ctx.logger.warn(`${LOG}: forked Team members are unavailable: %s`, providers.forkError);
|
|
72
78
|
const quarantine = (agent, reason) => {
|
|
73
79
|
const previous = quarantines.get(agent);
|
|
74
80
|
if (previous !== undefined) {
|
|
@@ -17,6 +17,14 @@
|
|
|
17
17
|
* whole provider contract to the deployment's own provider, so fresh/fork
|
|
18
18
|
* history semantics, cancellation, and concurrency isolation are unchanged.
|
|
19
19
|
*
|
|
20
|
+
* Aliases therefore have to exist exactly while their upstream provider does,
|
|
21
|
+
* whatever order the two plugins activate in. The registry built here is
|
|
22
|
+
* self-maintaining: it scans once when it subscribes, follows
|
|
23
|
+
* `subagent/provider-added` and `subagent/provider-removed` afterwards, and
|
|
24
|
+
* re-validates every alias whenever its upstream may have changed. Nothing
|
|
25
|
+
* about the mount order of this plugin and the provider plugins is assumed, and
|
|
26
|
+
* no alias failure is remembered past the moment it stops being true.
|
|
27
|
+
*
|
|
20
28
|
* @module dsh-agent-team-presets/member-identity
|
|
21
29
|
*/
|
|
22
30
|
import type { Context } from '@deepseek-ai/cordis';
|
|
@@ -53,7 +61,8 @@ export interface MemberProviderAliases {
|
|
|
53
61
|
*
|
|
54
62
|
* Reported instead of falling back to the deployment's own provider: a member
|
|
55
63
|
* created without the alias would carry no marker, and would then be
|
|
56
|
-
* indistinguishable from a native teammate after a restart.
|
|
64
|
+
* indistinguishable from a native teammate after a restart. The value is read
|
|
65
|
+
* on every access, so it clears as soon as the alias becomes registrable.
|
|
57
66
|
*/
|
|
58
67
|
readonly freshError?: string | undefined;
|
|
59
68
|
/** Why a FORKED member cannot be created, when the fork alias is unusable. */
|
|
@@ -61,12 +70,17 @@ export interface MemberProviderAliases {
|
|
|
61
70
|
}
|
|
62
71
|
/** The provider aliases one activation registered, with their release. */
|
|
63
72
|
export interface MemberProviderRegistry extends MemberProviderAliases {
|
|
64
|
-
/** Release every alias this activation registered. */
|
|
73
|
+
/** Release every alias this activation registered, and stop following the registry. */
|
|
65
74
|
dispose(): void;
|
|
66
75
|
}
|
|
67
76
|
/**
|
|
68
77
|
* Resolve the alias one spawn context must be created through.
|
|
69
|
-
*
|
|
78
|
+
*
|
|
79
|
+
* Called at member-creation time, so the answer is read from the aliases that
|
|
80
|
+
* exist NOW rather than from the state one startup scan happened to observe: a
|
|
81
|
+
* provider that registered after this plugin activated is usable, and one that
|
|
82
|
+
* has since been removed is refused.
|
|
83
|
+
* @param registry - the aliases this activation maintains.
|
|
70
84
|
* @param context - the configured spawn context of the member about to be created.
|
|
71
85
|
* @returns the alias to spawn through, or the refusal for that context.
|
|
72
86
|
*/
|
|
@@ -75,23 +89,54 @@ export declare function memberProviderFor(registry: MemberProviderAliases, conte
|
|
|
75
89
|
} | {
|
|
76
90
|
readonly error: string;
|
|
77
91
|
};
|
|
92
|
+
/** Why one spawn context is currently unusable, or that it is usable. */
|
|
93
|
+
export type MemberProviderUnavailable =
|
|
94
|
+
/** The configured upstream name is empty. */
|
|
95
|
+
'unconfigured'
|
|
96
|
+
/** The configured upstream name is this plugin's own alias. */
|
|
97
|
+
| 'alias'
|
|
98
|
+
/** The deployment registers no provider under the configured name (yet). */
|
|
99
|
+
| 'missing'
|
|
100
|
+
/** The configured provider cannot create continuable children. */
|
|
101
|
+
| 'unsupported'
|
|
102
|
+
/** The alias could not be registered, or the provider lookup threw. */
|
|
103
|
+
| 'registration';
|
|
104
|
+
/**
|
|
105
|
+
* Report one spawn context becoming usable or unusable.
|
|
106
|
+
*
|
|
107
|
+
* Called only when a context's availability actually changes, so a caller can
|
|
108
|
+
* log a refusal once instead of once per registry event. `missing` is the
|
|
109
|
+
* expected state while a provider plugin is still loading, which is why it is
|
|
110
|
+
* reported separately from the states that mean the configuration is wrong.
|
|
111
|
+
* @param context - the spawn context that changed.
|
|
112
|
+
* @param state - the new state, or undefined once the alias is usable.
|
|
113
|
+
* @param reason - human-readable refusal for the new state.
|
|
114
|
+
*/
|
|
115
|
+
export type MemberProviderAvailability = (context: 'fresh' | 'fork', state: MemberProviderUnavailable | undefined, reason: string) => void;
|
|
78
116
|
/**
|
|
79
|
-
* Register the member aliases, delegating to the configured providers
|
|
117
|
+
* Register the member aliases, delegating to the configured providers, and keep
|
|
118
|
+
* them in step with the provider registry for as long as this activation lives.
|
|
80
119
|
*
|
|
81
120
|
* The two spawn contexts are independent: a deployment that composes only a
|
|
82
121
|
* fresh provider still serves fresh members, while a forked member is refused
|
|
83
122
|
* with the reason its own backend is unusable. A configured name that is itself
|
|
84
123
|
* an alias is always refused — the wrapper must never become its own backend —
|
|
85
|
-
* and so is a name
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
124
|
+
* and so is a name whose provider cannot create continuable children, or whose
|
|
125
|
+
* alias registration fails. A configured name the deployment does not (or does
|
|
126
|
+
* not yet) register is refused only while it stays absent: the aliases are
|
|
127
|
+
* re-validated on every provider registry event, so a provider that activates
|
|
128
|
+
* later is picked up without restarting this plugin, and one that is replaced
|
|
129
|
+
* has its wrapper rebound to the new object.
|
|
130
|
+
*
|
|
131
|
+
* Registration failure is reported per context rather than skipped: a member
|
|
132
|
+
* created through the deployment's own provider would carry no marker and could
|
|
133
|
+
* not be told apart from a native teammate after a restart.
|
|
90
134
|
* @param ctx - the plugin context carrying the subagent service.
|
|
91
135
|
* @param configured - the deployment's fresh/fork provider names from the plugin config.
|
|
92
|
-
* @
|
|
136
|
+
* @param onAvailability - optional observer of each context's availability change.
|
|
137
|
+
* @returns the maintained aliases, whose `dispose` releases every registration.
|
|
93
138
|
*/
|
|
94
139
|
export declare function registerMemberProviders(ctx: Context, configured: {
|
|
95
140
|
readonly fresh: string;
|
|
96
141
|
readonly fork: string;
|
|
97
|
-
}): MemberProviderRegistry;
|
|
142
|
+
}, onAvailability?: MemberProviderAvailability): MemberProviderRegistry;
|
|
@@ -17,12 +17,22 @@
|
|
|
17
17
|
* whole provider contract to the deployment's own provider, so fresh/fork
|
|
18
18
|
* history semantics, cancellation, and concurrency isolation are unchanged.
|
|
19
19
|
*
|
|
20
|
+
* Aliases therefore have to exist exactly while their upstream provider does,
|
|
21
|
+
* whatever order the two plugins activate in. The registry built here is
|
|
22
|
+
* self-maintaining: it scans once when it subscribes, follows
|
|
23
|
+
* `subagent/provider-added` and `subagent/provider-removed` afterwards, and
|
|
24
|
+
* re-validates every alias whenever its upstream may have changed. Nothing
|
|
25
|
+
* about the mount order of this plugin and the provider plugins is assumed, and
|
|
26
|
+
* no alias failure is remembered past the moment it stops being true.
|
|
27
|
+
*
|
|
20
28
|
* @module dsh-agent-team-presets/member-identity
|
|
21
29
|
*/
|
|
22
30
|
/** Alias a fresh member is created through; persisted by the Host as its provider. */
|
|
23
31
|
export const MEMBER_FRESH_PROVIDER = 'preset-member-fresh-v1';
|
|
24
32
|
/** Alias a forked member is created through; persisted by the Host as its provider. */
|
|
25
33
|
export const MEMBER_FORK_PROVIDER = 'preset-member-fork-v1';
|
|
34
|
+
/** The two spawn contexts, in the fixed order their aliases are maintained. */
|
|
35
|
+
const CONTEXTS = ['fresh', 'fork'];
|
|
26
36
|
/** Every alias this plugin registers. The set is fixed and versioned. */
|
|
27
37
|
const ALIASES = new Set([MEMBER_FRESH_PROVIDER, MEMBER_FORK_PROVIDER]);
|
|
28
38
|
/**
|
|
@@ -56,7 +66,12 @@ export function memberProviderMarker(agent) {
|
|
|
56
66
|
}
|
|
57
67
|
/**
|
|
58
68
|
* Resolve the alias one spawn context must be created through.
|
|
59
|
-
*
|
|
69
|
+
*
|
|
70
|
+
* Called at member-creation time, so the answer is read from the aliases that
|
|
71
|
+
* exist NOW rather than from the state one startup scan happened to observe: a
|
|
72
|
+
* provider that registered after this plugin activated is usable, and one that
|
|
73
|
+
* has since been removed is refused.
|
|
74
|
+
* @param registry - the aliases this activation maintains.
|
|
60
75
|
* @param context - the configured spawn context of the member about to be created.
|
|
61
76
|
* @returns the alias to spawn through, or the refusal for that context.
|
|
62
77
|
*/
|
|
@@ -90,91 +105,239 @@ function aliasProvider(alias, upstream) {
|
|
|
90
105
|
};
|
|
91
106
|
}
|
|
92
107
|
/**
|
|
93
|
-
* Register the member aliases, delegating to the configured providers
|
|
108
|
+
* Register the member aliases, delegating to the configured providers, and keep
|
|
109
|
+
* them in step with the provider registry for as long as this activation lives.
|
|
94
110
|
*
|
|
95
111
|
* The two spawn contexts are independent: a deployment that composes only a
|
|
96
112
|
* fresh provider still serves fresh members, while a forked member is refused
|
|
97
113
|
* with the reason its own backend is unusable. A configured name that is itself
|
|
98
114
|
* an alias is always refused — the wrapper must never become its own backend —
|
|
99
|
-
* and so is a name
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
115
|
+
* and so is a name whose provider cannot create continuable children, or whose
|
|
116
|
+
* alias registration fails. A configured name the deployment does not (or does
|
|
117
|
+
* not yet) register is refused only while it stays absent: the aliases are
|
|
118
|
+
* re-validated on every provider registry event, so a provider that activates
|
|
119
|
+
* later is picked up without restarting this plugin, and one that is replaced
|
|
120
|
+
* has its wrapper rebound to the new object.
|
|
121
|
+
*
|
|
122
|
+
* Registration failure is reported per context rather than skipped: a member
|
|
123
|
+
* created through the deployment's own provider would carry no marker and could
|
|
124
|
+
* not be told apart from a native teammate after a restart.
|
|
104
125
|
* @param ctx - the plugin context carrying the subagent service.
|
|
105
126
|
* @param configured - the deployment's fresh/fork provider names from the plugin config.
|
|
106
|
-
* @
|
|
127
|
+
* @param onAvailability - optional observer of each context's availability change.
|
|
128
|
+
* @returns the maintained aliases, whose `dispose` releases every registration.
|
|
107
129
|
*/
|
|
108
|
-
export function registerMemberProviders(ctx, configured) {
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
130
|
+
export function registerMemberProviders(ctx, configured, onAvailability = () => { }) {
|
|
131
|
+
const states = {
|
|
132
|
+
fresh: { alias: MEMBER_FRESH_PROVIDER, upstreamName: configured.fresh, upstream: undefined, release: undefined, failure: undefined, reported: false },
|
|
133
|
+
fork: { alias: MEMBER_FORK_PROVIDER, upstreamName: configured.fork, upstream: undefined, release: undefined, failure: undefined, reported: false },
|
|
134
|
+
};
|
|
135
|
+
let disposed = false;
|
|
136
|
+
// Reentrancy guard. Registering or releasing an alias is itself a provider
|
|
137
|
+
// registry event, so every public path that reaches the registry can be
|
|
138
|
+
// entered again from inside it; the outermost call owns the whole sweep.
|
|
139
|
+
let reconciling = false;
|
|
140
|
+
/**
|
|
141
|
+
* Look up an upstream provider without letting a broken registry take the
|
|
142
|
+
* plugin down: the Settings page and the preset tools belong to such a
|
|
143
|
+
* deployment; only member creation has no channel.
|
|
144
|
+
* @param name - the configured upstream provider name.
|
|
145
|
+
* @returns the provider, or the refusal kind and reason instead.
|
|
146
|
+
*/
|
|
147
|
+
const lookup = (name) => {
|
|
148
|
+
const subagents = ctx.get('subagents');
|
|
149
|
+
if (subagents === undefined) {
|
|
150
|
+
return {
|
|
151
|
+
state: 'missing',
|
|
152
|
+
reason: 'this deployment composes no subagent service, so a Team member cannot be created through '
|
|
153
|
+
+ 'this plugin\'s identity alias.',
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
try {
|
|
157
|
+
const provider = subagents.getProvider(name);
|
|
158
|
+
return provider === undefined
|
|
159
|
+
? { state: 'missing', reason: `this deployment registers no subagent provider named "${name}".` }
|
|
160
|
+
: { provider };
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
return { state: 'registration', reason: `the subagent providers could not be read: ${String(error)}` };
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* Release one context's live alias, if it has one.
|
|
168
|
+
*
|
|
169
|
+
* The upstream is cleared BEFORE the registration is released, so the
|
|
170
|
+
* `subagent/provider-removed` this release emits cannot be mistaken for the
|
|
171
|
+
* deployment withdrawing the provider, and cannot re-enter this sweep.
|
|
172
|
+
* @param state - the context whose alias is released.
|
|
173
|
+
*/
|
|
174
|
+
const detach = (state) => {
|
|
175
|
+
const release = state.release;
|
|
176
|
+
state.release = undefined;
|
|
177
|
+
state.upstream = undefined;
|
|
178
|
+
if (release !== undefined)
|
|
179
|
+
release();
|
|
180
|
+
};
|
|
181
|
+
/**
|
|
182
|
+
* Report one context's availability, once per actual change.
|
|
183
|
+
* @param state - the context whose registration was updated.
|
|
184
|
+
* @param context - the spawn context, for the availability report.
|
|
185
|
+
*/
|
|
186
|
+
const report = (state, context) => {
|
|
187
|
+
const failure = state.failure;
|
|
188
|
+
if (failure === undefined) {
|
|
189
|
+
// A usable alias is never reported as a recovery: the transient state a
|
|
190
|
+
// provider plugin passes through while loading is not an incident.
|
|
191
|
+
state.reported = false;
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
if (state.reported)
|
|
195
|
+
return;
|
|
196
|
+
state.reported = true;
|
|
197
|
+
onAvailability(context, failure.state, failure.reason);
|
|
198
|
+
};
|
|
199
|
+
/**
|
|
200
|
+
* Record why one context is unusable, releasing the alias it may still hold.
|
|
201
|
+
*
|
|
202
|
+
* A refusal with a different *kind* than the one already standing is a new
|
|
203
|
+
* fact — a provider that was merely absent and now actively cannot back a
|
|
204
|
+
* member, for instance — so it is reported even though the context was
|
|
205
|
+
* already unusable.
|
|
206
|
+
* @param state - the context to refuse.
|
|
207
|
+
* @param reason - the refusal a member creation must report.
|
|
208
|
+
* @param failureState - the category of the refusal.
|
|
209
|
+
* @param context - the spawn context, for the availability report.
|
|
210
|
+
*/
|
|
211
|
+
const fail = (state, reason, failureState, context) => {
|
|
212
|
+
detach(state);
|
|
213
|
+
const previous = state.failure;
|
|
214
|
+
// A repeat of the same refusal is not news; a refusal that changed kind or
|
|
215
|
+
// wording is.
|
|
216
|
+
if (previous?.state !== failureState || previous.reason !== reason)
|
|
217
|
+
state.reported = false;
|
|
218
|
+
state.failure = { state: failureState, reason };
|
|
219
|
+
report(state, context);
|
|
220
|
+
};
|
|
221
|
+
/**
|
|
222
|
+
* Validate one context and register, rebind, or release its alias to match.
|
|
223
|
+
*
|
|
224
|
+
* Registration happens only on a real change — no live alias, or a live alias
|
|
225
|
+
* still delegating to the same upstream object — so the events this function
|
|
226
|
+
* causes can never make it re-register what it just registered.
|
|
227
|
+
* @param context - the spawn context to reconcile.
|
|
228
|
+
*/
|
|
229
|
+
const reconcile = (context) => {
|
|
230
|
+
const state = states[context];
|
|
231
|
+
if (state.upstreamName.trim() === '') {
|
|
232
|
+
fail(state, `the ${context} subagent provider is not configured, so a ${context} member cannot be created `
|
|
233
|
+
+ 'without losing the identity that proves it is preset-managed.', 'unconfigured', context);
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
if (isPresetMemberProvider(state.upstreamName)) {
|
|
237
|
+
fail(state, `the ${context} subagent provider "${state.upstreamName}" is this plugin's own member alias; point `
|
|
238
|
+
+ 'the plugin at the deployment provider it should delegate to.', 'alias', context);
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
const found = lookup(state.upstreamName);
|
|
242
|
+
if ('state' in found) {
|
|
243
|
+
fail(state, found.state === 'missing'
|
|
244
|
+
? found.reason + ` A ${context} member cannot be created through this plugin's identity alias.`
|
|
245
|
+
: found.reason, found.state, context);
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
const { provider } = found;
|
|
249
|
+
if (provider.prepareContinuable === undefined) {
|
|
250
|
+
fail(state, `subagent provider "${state.upstreamName}" cannot create continuable children, so it cannot back `
|
|
251
|
+
+ `a ${context} Team member.`, 'unsupported', context);
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
// The upstream is live and usable, so the previous refusal no longer
|
|
255
|
+
// describes it. It is cleared only once the alias is actually registered,
|
|
256
|
+
// so a registration failure never leaves this context usable-looking.
|
|
257
|
+
if (state.upstream === provider) {
|
|
258
|
+
state.failure = undefined;
|
|
259
|
+
report(state, context);
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
// A replaced provider object must never stay behind a wrapper: release the
|
|
263
|
+
// old alias first, then bind the new object.
|
|
264
|
+
detach(state);
|
|
265
|
+
try {
|
|
266
|
+
const release = ctx.get('subagents')?.registerProvider(aliasProvider(state.alias, provider));
|
|
267
|
+
if (release === undefined) {
|
|
268
|
+
fail(state, `the ${context} member execution alias "${state.alias}" could not be registered: the subagent `
|
|
269
|
+
+ 'service was released while it was being registered.', 'registration', context);
|
|
270
|
+
return;
|
|
157
271
|
}
|
|
272
|
+
state.upstream = provider;
|
|
273
|
+
state.release = release;
|
|
158
274
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
275
|
+
catch (error) {
|
|
276
|
+
fail(state, `the ${context} member execution alias "${state.alias}" could not be registered: ${String(error)}`, 'registration', context);
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
state.failure = undefined;
|
|
280
|
+
report(state, context);
|
|
281
|
+
};
|
|
282
|
+
/**
|
|
283
|
+
* Re-validate both contexts. Never runs inside another sweep: the events a
|
|
284
|
+
* registration or release emits re-enter here, and the outer sweep already
|
|
285
|
+
* covers them.
|
|
286
|
+
*/
|
|
287
|
+
const sweep = () => {
|
|
288
|
+
if (disposed || reconciling)
|
|
289
|
+
return;
|
|
290
|
+
reconciling = true;
|
|
291
|
+
try {
|
|
292
|
+
// `fresh` first: a forked member must never be the reason a fresh member
|
|
293
|
+
// is unavailable, and neither context's failure is allowed to abort the
|
|
294
|
+
// other's registration.
|
|
295
|
+
for (const context of CONTEXTS)
|
|
296
|
+
reconcile(context);
|
|
297
|
+
}
|
|
298
|
+
finally {
|
|
299
|
+
reconciling = false;
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
/**
|
|
303
|
+
* Follow the provider registry for as long as this activation lives.
|
|
304
|
+
*
|
|
305
|
+
* Only providers this plugin does not own are interesting: its own aliases
|
|
306
|
+
* arrive here too, and following them would be a self-loop. The listeners are
|
|
307
|
+
* registered before the initial scan so a registration that lands in between
|
|
308
|
+
* is not missed.
|
|
309
|
+
* @param name - the provider name the event names, for `provider-added` and `provider-removed` alike.
|
|
310
|
+
*/
|
|
311
|
+
const follow = (name) => {
|
|
312
|
+
if (disposed || isPresetMemberProvider(name))
|
|
313
|
+
return;
|
|
314
|
+
sweep();
|
|
315
|
+
};
|
|
316
|
+
const disposers = [];
|
|
317
|
+
disposers.push(ctx.on('subagent/provider-added', (provider) => { follow(provider.name); }));
|
|
318
|
+
disposers.push(ctx.on('subagent/provider-removed', (name) => { follow(name); }));
|
|
319
|
+
// One initial scan covers a deployment whose providers were already
|
|
320
|
+
// registered when this activation mounted.
|
|
321
|
+
sweep();
|
|
172
322
|
return {
|
|
173
|
-
fresh
|
|
174
|
-
fork
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
dispose: () => {
|
|
178
|
-
|
|
323
|
+
get fresh() { return states.fresh.alias; },
|
|
324
|
+
get fork() { return states.fork.alias; },
|
|
325
|
+
get freshError() { return states.fresh.failure?.reason; },
|
|
326
|
+
get forkError() { return states.fork.failure?.reason; },
|
|
327
|
+
dispose: () => {
|
|
328
|
+
if (disposed)
|
|
329
|
+
return;
|
|
330
|
+
disposed = true;
|
|
331
|
+
// Stop following first: releasing the aliases emits provider-removed, and
|
|
332
|
+
// an unloaded activation must never resurrect an alias. The listeners are
|
|
333
|
+
// taken back off in reverse registration order.
|
|
334
|
+
for (const off of disposers.splice(0).reverse())
|
|
335
|
+
void off();
|
|
336
|
+
for (const context of CONTEXTS) {
|
|
337
|
+
const state = states[context];
|
|
338
|
+
detach(state);
|
|
339
|
+
state.failure = undefined;
|
|
340
|
+
}
|
|
341
|
+
},
|
|
179
342
|
};
|
|
180
343
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-agent-team-presets",
|
|
3
3
|
"description": "Reusable Agent Team presets for DeepSeek Harness: a captain plus members with their own prompt, model, reasoning effort, and tools.",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.5",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agent-presets",
|
|
7
7
|
"agent-teams",
|
|
@@ -68,6 +68,9 @@
|
|
|
68
68
|
"bundle": "node tools/build.mjs"
|
|
69
69
|
},
|
|
70
70
|
"license": "MIT",
|
|
71
|
+
"engines": {
|
|
72
|
+
"dsh": ">=0.2.0-rc.2 <0.3.0"
|
|
73
|
+
},
|
|
71
74
|
"peerDependencies": {
|
|
72
75
|
"@deepseek-ai/cordis": ">=4.0.4 <5.0.0",
|
|
73
76
|
"@deepseek-ai/dsh-agent": ">=0.2.0-rc.1 <0.3.0",
|