Merge pull request #4896 from deepseek-harness/fix/preset-ui-20260921

fix(ui-agent-preset): restore the read-only configuration viewer
This commit is contained in:
Turtle authored and GitHub committed 2026-09-23 15:50:34 +08:00
commit 3d6d46b8a6
33 files changed
+425 -73

No files matched your search

+24 -3
View File
@@ -1,4 +1,4 @@
/** The preset settings page only selects a preset; creating one starts a Creator-mode task. */
/** The preset settings page selects a preset and shows what it declares; creating one starts a Creator-mode task. */
import { fileURLToPath } from 'node:url'
import { join } from 'node:path'
import type { Browser, Page } from 'playwright'
@@ -27,13 +27,13 @@ describe('web e2e: preset roster guidance', () => {
}, 120_000)
afterAll(async () => { await browser?.close(); await scaffold?.close() })
it('shows the shipped roster with mode help and no editing actions', async () => {
it('shows the shipped roster with mode help and a read-only view, and no editing actions', async () => {
onTestFailed(() => saveFailureShot(page, 'preset-roster-section'))
await expect.poll(() => page.locator('[data-agent-preset-id]').count()).toBe(4)
const snapshot = await captureStableAria(page, '[role="dialog"]', scaffold.workspaceCwd)
await compareOrRefreshGolden(join(EXPECTED, 'section.expected.md'), snapshot, mode)
expect(snapshot).toContain('让 Agent 帮我创建预设模式')
expect(snapshot).not.toContain('查看配置')
expect(snapshot).toContain('查看配置: 标准模式')
expect(snapshot).not.toContain('复制预设')
expect(snapshot).not.toContain('编辑插件')
expect(snapshot).not.toContain('打开目录')
@@ -55,6 +55,27 @@ describe('web e2e: preset roster guidance', () => {
expect(await settings.getByRole('button', { name: '新任务默认: 标准模式', exact: true }).getAttribute('aria-pressed')).toBe('true')
})
it('views a shipped composition read-only', async () => {
onTestFailed(() => saveFailureShot(page, 'preset-roster-view'))
const settings = page.getByRole('dialog', { name: '设置' })
await settings.getByRole('button', { name: '查看配置: PTC 模式', exact: true }).click()
const viewer = page.getByRole('dialog', { name: '查看配置 · PTC 模式', exact: true })
await viewer.waitFor({ timeout: 10_000 })
// The real shipped declaration, not a golden: the viewer shows whatever
// the deployment ships, and this lane only asserts it is shown read-only
// in the Loader's own dialect.
const shown = await viewer.locator('pre').textContent()
expect(shown).toContain("- id: persona\n name: '@deepseek-ai/dsh-persona'\n")
expect(shown).toContain('- id: workflow-ptc\n')
expect(shown).toContain("disabled: !!js process.platform === 'win32'\n")
expect(shown).not.toContain('__jsExpr')
expect(await viewer.getByRole('textbox').count()).toBe(0)
// The header X and the footer button share the 关闭 name; the footer one is last.
await viewer.getByRole('button', { name: '关闭', exact: true }).last().click()
await viewer.waitFor({ state: 'detached', timeout: 10_000 })
expect(await settings.getByRole('button', { name: '新任务默认: 标准模式', exact: true }).getAttribute('aria-pressed')).toBe('true')
})
it('starts a Creator-mode task from the section entry', async () => {
onTestFailed(() => saveFailureShot(page, 'preset-roster-creator'))
// The entry stages the self-referential preset and lands a new task on it,
@@ -21,6 +21,7 @@
- text: 处理代码、文件和资料,适合大多数任务。Agent 会按需使用检索、编辑和终端等工具。
- 'button "模式说明: 标准模式"': 模式说明
- 'button "如何使用: 标准模式"': 如何使用
- 'button "查看配置: 标准模式"': 查看配置
- listitem:
- 'button "设为新任务默认: PTC 模式"':
- text: PTC 模式 内置
@@ -28,6 +29,7 @@
- text: 包含标准模式的所有能力,更适合批量调用工具,并对结果进行筛选、整理、去重、统计或汇总的任务。
- 'button "模式说明: PTC 模式"': 模式说明
- 'button "如何使用: PTC 模式"': 如何使用
- 'button "查看配置: PTC 模式"': 查看配置
- listitem:
- 'button "设为新任务默认: 极简模式"':
- text: 极简模式 内置
@@ -35,6 +37,7 @@
- text: Agent 仅使用终端工具完成任务,适合测试和对比其基础表现。
- 'button "模式说明: 极简模式"': 模式说明
- 'button "如何使用: 极简模式"': 如何使用
- 'button "查看配置: 极简模式"': 查看配置
- listitem:
- 'button "设为新任务默认: 创造模式"':
- text: 创造模式 内置
@@ -42,5 +45,6 @@
- text: 用对话定制 DSH:让 Agent 编写插件,添加新功能或界面;也能组合工具和提示词,创建自己的模式。
- 'button "模式说明: 创造模式"': 模式说明
- 'button "如何使用: 创造模式"': 如何使用
- 'button "查看配置: 创造模式"': 查看配置
- heading "自定义" [level=3]
- button "让 Agent 帮我创建预设模式"
+2 -2
View File
@@ -2,5 +2,5 @@
# side as of the last confirmed-consistent state. Both languages carry equal authority;
# after editing either side, bring the other along and re-record with:
# pnpm run verify-translation-pairing --write docs/event-producer-consumer.md
event-producer-consumer.md: 1d844013f1230d6dbe535c3942279683f03738ce
event-producer-consumer.zh.md: 73438c3f19ef6850674a27bf8f490fe4cf52b420
event-producer-consumer.md: 549c80e95ec9fdeb997bd11b392ad30ba9c78c6f
event-producer-consumer.zh.md: b079ddb558e51389c36e4dd77fdc03d3b52f48c3
+1 -1
View File
@@ -8,7 +8,7 @@ This matrix shows which packages dispatch each harness-owned event and which pac
| Event | Mode | Declared in | Dispatchers | Listeners |
| --- | --- | --- | --- | --- |
| `agent-loop/config-start-failed` | `emit` | [`packages/core/agent-loop/src/index.ts:238`](../packages/core/agent-loop/src/index.ts) | [`agent-loop`](../packages/core/agent-loop) (`events.dispatch`) | - |
| `agent-preset/selected` | `emit` | [`packages/preset/agent-preset-registry/src/types.ts:59`](../packages/preset/agent-preset-registry/src/types.ts) | [`agent-preset-registry`](../packages/preset/agent-preset-registry) (`emit`) | `remotes` |
| `agent-preset/selected` | `emit` | [`packages/preset/agent-preset-registry/src/types.ts:71`](../packages/preset/agent-preset-registry/src/types.ts) | [`agent-preset-registry`](../packages/preset/agent-preset-registry) (`emit`) | `remotes` |
| `agent/assistant-stream` | `emit` | [`packages/core/agent/src/runtime-types.ts:363`](../packages/core/agent/src/runtime-types.ts) | [`agent-loop`](../packages/core/agent-loop) (`emit`) | [`headless`](../packages/bundle/headless), `session-controller` |
| `agent/created` | `serial` | [`packages/core/agent/src/runtime-types.ts:261`](../packages/core/agent/src/runtime-types.ts) | [`agent`](../packages/core/agent) (`serial`) | `agent-team`, `browser-use-runtime`, [`file-reference-local`](../packages/context/file-reference-local), [`goal`](../packages/goal/goal), [`goal-round-driver`](../packages/goal/goal-round-driver), [`hooks-claude-code`](../packages/hooks/hooks-claude-code), [`hooks-codex`](../packages/hooks/hooks-codex), [`loader-smoke`](../packages/test-support/loader-smoke), [`schedule`](../packages/schedule/schedule), `session-controller`, `tool-agent-team`, [`tool-subagent`](../packages/subagent/tool-subagent) |
| `agent/disposed` | `emit` | [`packages/core/agent/src/runtime-types.ts:270`](../packages/core/agent/src/runtime-types.ts) | [`agent`](../packages/core/agent) (`events.dispatch`) | [`agent-loop`](../packages/core/agent-loop), [`file-reference-local`](../packages/context/file-reference-local), [`goal-round-driver`](../packages/goal/goal-round-driver), `session-controller`, [`subagent`](../packages/subagent/subagent), `tool-agent-team`, [`tool-subagent`](../packages/subagent/tool-subagent) |
+1 -1
View File
@@ -10,7 +10,7 @@
| Event | Mode | Declared in | Dispatchers | Listeners |
| --- | --- | --- | --- | --- |
| `agent-loop/config-start-failed` | `emit` | [`packages/core/agent-loop/src/index.ts:238`](../packages/core/agent-loop/src/index.ts) | [`agent-loop`](../packages/core/agent-loop) (`events.dispatch`) | - |
| `agent-preset/selected` | `emit` | [`packages/preset/agent-preset-registry/src/types.ts:59`](../packages/preset/agent-preset-registry/src/types.ts) | [`agent-preset-registry`](../packages/preset/agent-preset-registry) (`emit`) | `remotes` |
| `agent-preset/selected` | `emit` | [`packages/preset/agent-preset-registry/src/types.ts:71`](../packages/preset/agent-preset-registry/src/types.ts) | [`agent-preset-registry`](../packages/preset/agent-preset-registry) (`emit`) | `remotes` |
| `agent/assistant-stream` | `emit` | [`packages/core/agent/src/runtime-types.ts:363`](../packages/core/agent/src/runtime-types.ts) | [`agent-loop`](../packages/core/agent-loop) (`emit`) | [`headless`](../packages/bundle/headless), `session-controller` |
| `agent/created` | `serial` | [`packages/core/agent/src/runtime-types.ts:261`](../packages/core/agent/src/runtime-types.ts) | [`agent`](../packages/core/agent) (`serial`) | `agent-team`, `browser-use-runtime`, [`file-reference-local`](../packages/context/file-reference-local), [`goal`](../packages/goal/goal), [`goal-round-driver`](../packages/goal/goal-round-driver), [`hooks-claude-code`](../packages/hooks/hooks-claude-code), [`hooks-codex`](../packages/hooks/hooks-codex), [`loader-smoke`](../packages/test-support/loader-smoke), [`schedule`](../packages/schedule/schedule), `session-controller`, `tool-agent-team`, [`tool-subagent`](../packages/subagent/tool-subagent) |
| `agent/disposed` | `emit` | [`packages/core/agent/src/runtime-types.ts:270`](../packages/core/agent/src/runtime-types.ts) | [`agent`](../packages/core/agent) (`events.dispatch`) | [`agent-loop`](../packages/core/agent-loop), [`file-reference-local`](../packages/context/file-reference-local), [`goal-round-driver`](../packages/goal/goal-round-driver), `session-controller`, [`subagent`](../packages/subagent/subagent), `tool-agent-team`, [`tool-subagent`](../packages/subagent/tool-subagent) |
+2 -2
View File
@@ -2,5 +2,5 @@
# side as of the last confirmed-consistent state. Both languages carry equal authority;
# after editing either side, bring the other along and re-record with:
# pnpm run verify-translation-pairing --write docs/subsystems/core.md
core.md: aa9af309c03ebedae353139c4017d19f2607dd7d
core.zh.md: b18ff5bba1c0309e9b9dcdf1f3e97adb5895caf6
core.md: 64344148708b29fc186a2e33ef187025c4bc5300
core.zh.md: 0b85519b916490d6692a31f59ed89527ce72fa43
+6
View File
@@ -510,6 +510,12 @@ async list(): Promise<AgentPreset[]>
*/
async resolve(id?: string): Promise<AgentPreset>
/** Read one declaration's child plugin list as YAML, for viewing only.
* @param agentPreset Preset identity.
* @returns The declared composition beside its published metadata.
*/
@Remote('read') readDocument(agentPreset: string): Promise<AgentPresetDocument>
/** Bind an unpublished Agent to the current preset revision.
* @param ctx Agent context from its setup callback.
* @param id Requested preset, or the default.
+6
View File
@@ -520,6 +520,12 @@ async list(): Promise<AgentPreset[]>
*/
async resolve(id?: string): Promise<AgentPreset>
/** Read one declaration's child plugin list as YAML, for viewing only.
* @param agentPreset Preset identity.
* @returns The declared composition beside its published metadata.
*/
@Remote('read') readDocument(agentPreset: string): Promise<AgentPresetDocument>
/** Bind an unpublished Agent to the current preset revision.
* @param ctx Agent context from its setup callback.
* @param id Requested preset, or the default.
@@ -2,5 +2,5 @@
# side as of the last confirmed-consistent state. Both languages carry equal authority;
# after editing either side, bring the other along and re-record with:
# pnpm run verify-translation-pairing --write packages/client/ui-agent-preset/README.md
README.md: 176957e32695debf6a8aedd98368ec0d985d9182
README.zh.md: a9496780ce5ea48ae95420d11d9f182134518b93
README.md: f529c62f16873ce7b10fce70907f56630b133bdb
README.zh.md: 281a667980c66ca90c4180b5ae6bd176d34568f4
+5 -5
View File
@@ -1,5 +1,5 @@
---
description: "Choose Agent presets and the new-task default in Web, and read what each mode does. Authoring is guided to Creator mode."
description: "Choose Agent presets and the new-task default in Web, read what each mode does and what it declares. Authoring is guided to Creator mode."
kind: "package-reference"
---
@@ -9,7 +9,7 @@ English | [中文](README.zh.md)
## Summary
Choose Agent presets and the new-task default in Web, and read what each mode does. Authoring is guided to Creator mode.
Choose Agent presets and the new-task default in Web, read what each mode does and what it declares. Authoring is guided to Creator mode.
## Table of Contents
@@ -25,7 +25,7 @@ Choose Agent presets and the new-task default in Web, and read what each mode do
<a id="use-this-package"></a>
## Use this package
Settings shows the built-in and custom card groups with default highlighting and card-body selection; a group without presets is omitted, except the custom group, which keeps its Creator entry on screen. The page edits nothing: that entry starts a Creator-mode task that authors or overrides a preset as a bundle, offered while the `cordis` preset is on the roster and a conversation flow exists.
Settings shows the built-in and custom card groups with default highlighting and card-body selection; a group without presets is omitted, except the custom group, which keeps its Creator entry on screen. Every card offers “View configuration”, which opens the preset's declared plugin list as read-only YAML in the Loader's own dialect (`!!js` conditions included); a failed preset stays readable because its diagnostic points into that YAML. Escape closes only the viewer and returns focus to its card; leaving Settings clears the viewer, and a late read does not reopen it. The page edits nothing: the Creator entry starts a Creator-mode task that authors or overrides a preset as a bundle, offered while the `cordis` preset is on the roster and a conversation flow exists.
The “Choose a mode for new tasks” switch controls whether the saved user default is active. Hiding selection uses the deployment default; showing it restores the user preference. Choosing a healthy default also synchronizes the blank session on the current new-task surface. Creator starts a new task using the `cordis` preset. The new-session picker additionally requires Developer tools in General Settings.
@@ -37,7 +37,7 @@ Known shipped presets offer mode details and usage examples in a read-only dialo
<details>
<summary>Implementation internals — click to expand</summary>
`agentPresets/list` supplies the roster and the chooser policy; default and visibility changes write the `agent-presets` settings namespace. The picker, blank-session synchronization and read-only session label use recorded preset identities. Connection resets and settings updates refresh the roster.
`agentPresets/list` supplies the roster and the chooser policy, and `agentPresets/read` one declaration's YAML for the viewer; default and visibility changes write the `agent-presets` settings namespace. The picker, blank-session synchronization and read-only session label use recorded preset identities. Connection resets and settings updates refresh the roster.
</details>
@@ -61,7 +61,7 @@ Selection changes affect only later tasks; existing plugins and prompts remain u
<a id="known-limitations-and-deferred-work"></a>
- Web creates and edits no preset: a bundle installed through Creator mode declares a new preset or overrides a shipped one by row id, replacing its complete child list.
- Web creates and edits no preset: the configuration viewer is read-only, and a bundle installed through Creator mode declares a new preset or overrides a shipped one by row id, replacing its complete child list.
<a id="dev-note"></a>
### Dev Note
+5 -5
View File
@@ -1,5 +1,5 @@
---
description: "在 Web 中选择 Agent preset 和新任务默认值,并查看各模式的说明。创建与修改引导至创造模式。"
description: "在 Web 中选择 Agent preset 和新任务默认值,查看各模式的说明与声明的配置。创建与修改引导至创造模式。"
kind: "package-reference"
---
@@ -9,7 +9,7 @@ kind: "package-reference"
## 概述
在 Web 中选择 Agent preset 和新任务默认值,并查看各模式的说明。创建与修改引导至创造模式。
在 Web 中选择 Agent preset 和新任务默认值,查看各模式的说明与声明的配置。创建与修改引导至创造模式。
## 目录
@@ -25,7 +25,7 @@ kind: "package-reference"
<a id="use-this-package"></a>
## 使用此包
设置页显示内置与自定义卡片分组、默认项高亮和点击卡片选择;没有 preset 的分组不显示,但自定义分组会保留其创造入口。本页不编辑任何内容:该入口启动一个创造模式任务,以 bundle 形式创建或覆盖 preset;当 `cordis` preset 在列表中且存在会话流程时提供。
设置页显示内置与自定义卡片分组、默认项高亮和点击卡片选择;没有 preset 的分组不显示,但自定义分组会保留其创造入口。每张卡片都提供「查看配置」,以只读 YAML 打开该 preset 声明的插件列表,使用 Loader 自己的方言(含 `!!js` 条件);加载失败的 preset 同样可读,因为其诊断信息正指向这份 YAML。Escape 只关闭查看器并将焦点还给卡片;离开设置页会清空查看器,迟到的读取结果不会重新打开它。本页不编辑任何内容:创造入口启动一个创造模式任务,以 bundle 形式创建或覆盖 preset;当 `cordis` preset 在列表中且存在会话流程时提供。
「新任务可选择模式」开关控制保存的用户默认值是否生效。关闭时使用部署默认值,重新开启则恢复用户偏好。选择健康定义作为默认值也会同步当前新任务页面的空白会话。Creator 入口开启一个使用 `cordis` preset 的新任务。新会话选择器还要求通用设置开启开发者工具。
@@ -37,7 +37,7 @@ kind: "package-reference"
<details>
<summary>实现细节 — 点击展开</summary>
`agentPresets/list` 提供列表和选择器策略;默认值与可见性的修改写入 `agent-presets` settings 命名空间。选择器、空白会话同步和只读会话标签使用记录的 preset 标识。连接重置和设置更新会刷新列表。
`agentPresets/list` 提供列表和选择器策略,`agentPresets/read` 为查看器提供一条声明的 YAML;默认值与可见性的修改写入 `agent-presets` settings 命名空间。选择器、空白会话同步和只读会话标签使用记录的 preset 标识。连接重置和设置更新会刷新列表。
</details>
@@ -61,7 +61,7 @@ kind: "package-reference"
<a id="known-limitations-and-deferred-work"></a>
- Web 不创建也不编辑 preset:通过创造模式安装的 bundle 声明新 preset,或按行 id 覆盖内置 preset,覆盖会替换整个子插件列表。
- Web 不创建也不编辑 preset:配置查看器是只读的;通过创造模式安装的 bundle 声明新 preset,或按行 id 覆盖内置 preset,覆盖会替换整个子插件列表。
<a id="dev-note"></a>
### 开发备注
@@ -317,6 +317,77 @@
color: var(--dsw-alias-label-primary);
}
/* Icon-only actions: the label rides `data-tip` so the row stays quiet until
someone reaches for it. */
.iconButton {
position: relative;
appearance: none;
border: 0;
border-radius: 7px;
padding: 6px;
background: none;
color: var(--dsw-alias-label-tertiary);
cursor: pointer;
display: inline-flex;
align-items: center;
}
.iconButton:hover {
background: var(--dsw-alias-bg-layer-1);
color: var(--dsw-alias-label-primary);
}
.iconButton:focus-visible {
outline: 2px solid var(--dsw-alias-brand-primary);
outline-offset: -1px;
}
.iconButton::after {
content: attr(data-tip);
position: absolute;
bottom: calc(100% + 6px);
left: 50%;
transform: translateX(-50%);
padding: 3px 8px;
border-radius: 6px;
background: var(--dsw-alias-label-primary);
color: var(--dsw-alias-bg-layer-3);
font-size: 11px;
line-height: 17px;
white-space: nowrap;
opacity: 0;
pointer-events: none;
transition: opacity .12s;
}
.iconButton:hover::after,
.iconButton:focus-visible::after {
opacity: 1;
}
.dialog {
width: min(720px, 100%);
}
/* A declared composition can be long; the dialog scrolls it rather than grow. */
.viewerCode {
margin: 0;
padding: 12px;
max-height: min(60vh, 560px);
overflow: auto;
border: 0.5px solid var(--dsw-alias-border-l4);
border-radius: 10px;
background: var(--dsw-alias-bg-layer-2);
color: var(--dsw-alias-label-secondary);
font-family: var(--dsw-font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
font-size: 12.5px;
line-height: 1.5;
white-space: pre;
tab-size: 2;
--dsh-scrollbar-thumb: var(--dsw-alias-scrollbar-bg-l2);
--dsh-scrollbar-thumb-hover: var(--dsw-alias-scrollbar-hover-l2);
}
.error {
margin: 0;
font-size: 12px;
@@ -1,12 +1,14 @@
/** Preset selection settings: the roster, its default, mode help and the Creator-mode entry. */
/** Preset selection settings: the roster, its default, mode help, a read-only view of each composition, and the Creator-mode entry. */
import type { ReactNode } from 'react'
import { useEffect, useLayoutEffect, useRef, useState } from 'react'
import { Button, IconPlusOutlineRegular, Switch, Tag, Tooltip } from '@deepseek-ai/dsh-client-ui-primitives'
import {
Button, IconBrowseOutlineRegular, IconPlusOutlineRegular, Modal, Switch, Tag, Tooltip,
} from '@deepseek-ai/dsh-client-ui-primitives'
import type { ObservableSnapshot, SnapshotStore } from '@deepseek-ai/dsh-client-store'
import type { InjectFace, PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots'
import type { AgentPresetSectionState } from './section-store.ts'
import { isBuiltInPreset, presetDisplayText } from './locales.ts'
import { PresetGuideDialog, presetGuide, type PresetGuidePage } from './PresetGuideDialog.tsx'
import { PresetGuideDialog, presetGuide, trapPresetReaderTab, type PresetGuidePage } from './PresetGuideDialog.tsx'
import css from './AgentPresetSection.module.css'
/** Settings actions and their shared controller state. */
@@ -19,6 +21,10 @@ export interface AgentPresetSectionInjected {
/** Stage the `cordis` preset and start a Creator-mode task; absent without a conversation flow. */
startCreatorDraft?: () => void
load: () => Promise<void>
/** Open one preset's declared composition in the read-only viewer. */
view: (id: string) => Promise<void>
/** Close the read-only viewer. */
closeView: () => void
makeDefault: (id: string) => Promise<void>
setPickerVisible: (visible: boolean) => Promise<void>
}
@@ -51,12 +57,13 @@ function CardDescription({ text }: { text: string }): ReactNode {
)
}
/** Render the roster with its default, mode help, and the guidance to Creator mode.
/** Render the roster with its default, mode help, composition viewer, and the guidance to Creator mode.
* @param props Settings actions, snapshot hooks and localized text.
* @returns The preset settings section.
*/
export function AgentPresetSection({
useAgentPresetSection, load, makeDefault, setPickerVisible, startCreatorDraft, close: closeSettings, useDeveloperTools, t,
useAgentPresetSection, load, view, closeView, makeDefault, setPickerVisible, startCreatorDraft,
close: closeSettings, useDeveloperTools, t,
}: AgentPresetSectionProps) {
const state = useAgentPresetSection(value => value)
const developerTools = useDeveloperTools(enabled => enabled)
@@ -64,7 +71,15 @@ export function AgentPresetSection({
content: NonNullable<ReturnType<typeof presetGuide>>
page: PresetGuidePage
} | null>(null)
const viewTrigger = useRef<HTMLButtonElement | null>(null)
const closeViewOnUnmount = useRef(closeView)
useEffect(() => { void load() }, [load])
useLayoutEffect(() => { closeViewOnUnmount.current = closeView }, [closeView])
useEffect(() => () => { closeViewOnUnmount.current() }, [])
const closeViewer = () => { closeView(); viewTrigger.current?.focus() }
const viewed = state.view
const viewedRow = viewed === null ? undefined : state.rows.find(row => row.id === viewed.id)
const viewedTitle = viewed === null ? '' : viewedRow === undefined ? viewed.title : presetDisplayText(viewedRow, t).name
// Creator mode authors presets in conversation; it needs the flow to land a
// session in and the self-referential preset on the roster.
const creator = startCreatorDraft !== undefined && state.rows.some(row => row.id === 'cordis') ? startCreatorDraft : undefined
@@ -138,14 +153,21 @@ export function AgentPresetSection({
<CardDescription text={display.description ?? t('noDescription')} />
{row.broken === undefined ? null : <span className={css.cardBrokenReason} role="alert">{row.broken}</span>}
</button>
{help === undefined ? null : <div className={css.cardFoot}>
<div className={css.cardHelp}>
<div className={css.cardFoot}>
{help === undefined ? null : <div className={css.cardHelp}>
<Button variant="ghost" className={css.helpButton} aria-label={`${t('modeExplanation')}: ${display.name}`}
onClick={() => { setGuide({ content: help, page: 'explanation' }) }}>{t('modeExplanation')}</Button>
<Button variant="ghost" className={css.helpButton} aria-label={`${t('howToUse')}: ${display.name}`}
onClick={() => { setGuide({ content: help, page: 'usage' }) }}>{t('howToUse')}</Button>
</div>
</div>}
</div>}
{/* Reading the declaration is the one thing this page offers
beyond choosing: a broken preset's YAML is also where its
diagnostic points, so the viewer stays available for it. */}
<button type="button" className={css.iconButton} data-tip={t('view')} aria-label={`${t('view')}: ${display.name}`}
onClick={(event) => { viewTrigger.current = event.currentTarget; void view(row.id) }}>
<IconBrowseOutlineRegular />
</button>
</div>
</li>
})}
</ul>}
@@ -153,5 +175,17 @@ export function AgentPresetSection({
</section>
})}
{guide === null ? null : <PresetGuideDialog guide={guide.content} initialPage={guide.page} t={t} onClose={() => { setGuide(null) }} />}
<Modal open={viewed !== null} onClose={closeViewer} closeLabel={t('close')}
onKeyDownCapture={(event) => {
if (event.key === 'Escape') {
event.preventDefault()
event.stopPropagation()
closeViewer()
} else trapPresetReaderTab(event)
}}
title={viewed === null ? '' : `${t('view')} · ${viewedTitle}`} className={css.dialog as string}
footer={<Button variant="outline" autoFocus onClick={closeViewer}>{t('close')}</Button>}>
{viewed === null ? null : <pre className={css.viewerCode}>{viewed.content}</pre>}
</Modal>
</section>
}
@@ -33,6 +33,25 @@ export function presetGuide(id: string, trust: string): PresetGuide | undefined
return trust === 'system' ? guides.get(id) : undefined
}
/** Keep keyboard focus inside a preset reader while Tab moves through its controls.
* @param event Keyboard event from the active reader.
*/
export function trapPresetReaderTab(event: KeyboardEvent<HTMLDivElement>): void {
if (event.key !== 'Tab') return
const targets = Array.from(event.currentTarget.querySelectorAll<HTMLElement>(
'button:not([disabled]):not([tabindex="-1"]), [tabindex="0"]',
)).filter(element => !element.closest('[hidden]'))
const first = targets[0]
const last = targets[targets.length - 1]
if (event.shiftKey && document.activeElement === first) {
event.preventDefault()
last?.focus()
} else if (!event.shiftKey && document.activeElement === last) {
event.preventDefault()
first?.focus()
}
}
/** Curated usage dictionaries contain only level-three example sections. */
function GuideUsage({ text, t }: {
text: string
@@ -90,20 +109,7 @@ export function PresetGuideDialog({ guide, initialPage, t, onClose }: {
event.preventDefault()
event.stopPropagation()
onClose()
} else if (event.key === 'Tab') {
const targets = Array.from(event.currentTarget.querySelectorAll<HTMLElement>(
'button:not([disabled]):not([tabindex="-1"]), [tabindex="0"]',
)).filter(element => !element.closest('[hidden]'))
const first = targets[0]
const last = targets[targets.length - 1]
if (event.shiftKey && document.activeElement === first) {
event.preventDefault()
last?.focus()
} else if (!event.shiftKey && document.activeElement === last) {
event.preventDefault()
first?.focus()
}
}
} else trapPresetReaderTab(event)
}
return (
@@ -2,7 +2,8 @@
* Agent-preset surface plugin, browser half — three surfaces over one roster:
* a chip on the new-session screen for the session about to start, a
* read-only label in the session header, and a settings section that lists
* the roster (selection, the new-task default, and the way into Creator mode).
* the roster (selection, the new-task default, a read-only view of each
* declared composition, and the way into Creator mode).
*
* A running session keeps the composition it began with (the host refuses to
* adopt an existing session under a different preset). That is what splits
@@ -49,7 +50,7 @@ export type { AgentPresetLabelInjected, AgentPresetLabelProps } from './AgentPre
export type { AgentPresetSeatInjected, AgentPresetSeatProps } from './AgentPresetSeat.tsx'
export type { AgentPresetSectionInjected, AgentPresetSectionProps } from './AgentPresetSection.tsx'
export type { AgentPresetSeatState } from './seat-store.ts'
export type { AgentPresetSectionState } from './section-store.ts'
export type { AgentPresetSectionState, PresetView } from './section-store.ts'
export type { AgentPresetOption, AgentPresetSettingsState } from './settings-store.ts'
export { AGENT_PRESET_SETTINGS_NS, writeDefaultPreset } from './settings-store.ts'
@@ -199,6 +200,8 @@ export function apply(ctx: ClientContext): void {
const sectionInjected = (): AgentPresetSectionInjected => ({
hooks: { agentPresetSection: section.store, developerTools: ctx.configForms.developerTools.enabled },
load: () => section.load(),
view: (id: string) => section.view(id),
closeView: () => { section.closeView() },
...creatorDraft === undefined ? {} : { startCreatorDraft: creatorDraft },
makeDefault: (id: string) => section.makeDefault(id, captureBlankSessionSync()),
setPickerVisible: (showPicker: boolean) => section.setPickerVisible(showPicker, captureBlankSessionSync()),
@@ -12,6 +12,7 @@ export type AgentPresetSettingsKey =
| 'nav'
| 'sectionIntro'
| 'setDefault'
| 'view'
| 'presetStandardName'
| 'presetStandardDescription'
| 'presetPtcName'
@@ -44,6 +45,7 @@ export const en: Record<AgentPresetSettingsKey, string> = {
nav: 'Agent presets',
setDefault: 'Set as new task default',
view: 'View configuration',
presetStandardName: 'Standard mode',
presetStandardDescription:
@@ -89,6 +91,7 @@ export const zh: Record<AgentPresetSettingsKey, string> = {
nav: 'Agent 预设',
setDefault: '设为新任务默认',
view: '查看配置',
presetStandardName: '标准模式',
presetStandardDescription: '处理代码、文件和资料,适合大多数任务。Agent 会按需使用检索、编辑和终端等工具。',
@@ -1,10 +1,19 @@
/** Preset roster and selection policy for the settings section. */
/** Preset roster, selection policy and the read-only composition viewer for the settings section. */
import type { Context } from '@deepseek-ai/cordis'
import type {} from '@deepseek-ai/dsh-api-remotes/client'
import { createSnapshotStore, type SnapshotStore } from '@deepseek-ai/dsh-client-store'
import type { AgentPresetRow } from '@deepseek-ai/dsh-agent-preset-registry/types'
import { writeDefaultPreset, writeModeSelectionEnabled } from './settings-store.ts'
/** The read-only composition viewer over one preset. */
export interface PresetView {
/** The preset being read. */
id: string
/** Display name the preset published, or its id. */
title: string
/** The declared child plugin list as YAML. */
content: string
}
/** Settings page state. */
export interface AgentPresetSectionState {
status: 'idle' | 'loading' | 'ready' | 'error'
@@ -12,15 +21,18 @@ export interface AgentPresetSectionState {
showPicker: boolean
policySaving: boolean
rows: readonly AgentPresetRow[]
/** The open viewer, or null. */
view: PresetView | null
}
const INITIAL: AgentPresetSectionState = { status: 'idle', error: null, showPicker: true, policySaving: false, rows: [] }
const INITIAL: AgentPresetSectionState = { status: 'idle', error: null, showPicker: true, policySaving: false, rows: [], view: null }
const message = (error: unknown): string => error instanceof Error ? error.message : String(error)
/** Loads the roster and writes the default and chooser policy. */
/** Loads the roster, writes the default and chooser policy, and reads one composition at a time. */
export class AgentPresetSectionController {
/** Observable roster and selection state. */
/** Observable roster, selection and viewer state. */
readonly store: SnapshotStore<AgentPresetSectionState> = createSnapshotStore(INITIAL)
private loading: Promise<void> | undefined
private viewRequest = 0
constructor(private readonly ctx: Context) {}
private set(patch: Partial<AgentPresetSectionState>): void { this.store.set({ ...this.store.getSnapshot(), ...patch }) }
@@ -39,6 +51,24 @@ export class AgentPresetSectionController {
} catch (error) { this.set({ status: 'error', error: message(error) }) }
}
/** Open one preset's declared composition in the viewer.
* @param id Preset to read.
* @returns Once the read settles; a current failure lands in `error`, while a read superseded by close or another read is ignored.
*/
async view(id: string): Promise<void> {
const request = ++this.viewRequest
this.set({ error: null, view: null })
try {
const result = await this.ctx.remote.agentPresets.read(id)
if (request !== this.viewRequest) return
if (!result.ok) throw new Error(result.error.message)
const { name, content } = result.value
this.set({ view: { id, title: name ?? id, content } })
} catch (error) { if (request === this.viewRequest) this.set({ error: message(error) }) }
}
/** Close the viewer. */
closeView(): void { this.viewRequest++; this.set({ view: null }) }
/** Set the default and synchronize the current blank task when supplied.
* @param id Selected default.
* @param sync Blank-session synchronization callback.
@@ -131,9 +131,9 @@ async function bench(options: {
}
return Promise.resolve(ROSTER)
},
read: () => Promise.resolve({
read: (id: string) => Promise.resolve({
ok: true as const,
value: { agentPreset: 'standard', content: '', revision: 'rev' },
value: { agentPreset: id, content: `# ${id}\n[]\n` },
}),
save: (id: string) => {
calls.push(`save:${id}`)
@@ -350,6 +350,11 @@ describe('ui-agent-preset apply', () => {
await section.makeDefault('standard')
expect(section.hooks.agentPresetSection.getSnapshot().rows)
.toEqual([{ id: 'standard', isDefault: true }])
await section.view('standard')
expect(section.hooks.agentPresetSection.getSnapshot().view)
.toEqual({ id: 'standard', title: 'standard', content: '# standard\n[]\n' })
section.closeView()
expect(section.hooks.agentPresetSection.getSnapshot().view).toBeNull()
})
it('refreshes a showing surface when its namespace changes, and ignores others', async () => {
@@ -4,6 +4,7 @@ import { AgentPresetSectionController } from '../src/client/section-store.ts'
function fixture() {
const remote = { agentPresets: {
list: vi.fn(async () => ({ ok: true as const, value: { presets: [{ id: 'standard', isDefault: true }], modeSelectionEnabled: true } })),
read: vi.fn(async (id: string) => ({ ok: true as const, value: { agentPreset: id, name: 'Standard', content: '- name: fs\n' } })),
}, settings: { update: vi.fn(async () => ({ ok: true as const, value: {} })) } }
const controller = new AgentPresetSectionController({ remote } as never)
return { remote, controller, state: () => controller.store.getSnapshot() }
@@ -14,7 +15,7 @@ describe('the preset roster', () => {
const { controller, remote, state } = fixture()
await Promise.all([controller.load(), controller.load()])
expect(remote.agentPresets.list).toHaveBeenCalledOnce()
expect(state()).toMatchObject({ status: 'ready', rows: [{ id: 'standard', isDefault: true }], showPicker: true })
expect(state()).toMatchObject({ status: 'ready', rows: [{ id: 'standard', isDefault: true }], showPicker: true, view: null })
remote.agentPresets.list.mockRejectedValueOnce(new Error('offline'))
await controller.load()
expect(state()).toMatchObject({ status: 'error', error: 'offline' })
@@ -26,6 +27,43 @@ describe('the preset roster', () => {
expect(state().error).toBe('gone')
})
it('opens one declared composition for reading and keeps a failed read out of the viewer', async () => {
const { controller, remote, state } = fixture()
await controller.view('standard')
expect(remote.agentPresets.read).toHaveBeenCalledWith('standard')
expect(state().view).toEqual({ id: 'standard', title: 'Standard', content: '- name: fs\n' })
controller.closeView()
expect(state().view).toBeNull()
remote.agentPresets.read.mockResolvedValueOnce({ ok: true, value: { agentPreset: 'mine', content: '[]\n' } } as never)
await controller.view('mine')
expect(state().view).toEqual({ id: 'mine', title: 'mine', content: '[]\n' })
remote.agentPresets.read.mockResolvedValueOnce({ ok: false, error: { message: 'Unknown agent preset: gone' } } as never)
await controller.view('gone')
expect(state()).toMatchObject({ view: null, error: 'Unknown agent preset: gone' })
remote.agentPresets.read.mockRejectedValueOnce(new Error('offline'))
await controller.view('standard')
expect(state()).toMatchObject({ view: null, error: 'offline' })
})
it('ignores a read that settles after the viewer closes or a newer read opens', async () => {
const { controller, remote, state } = fixture()
const late = Promise.withResolvers<Awaited<ReturnType<typeof remote.agentPresets.read>>>()
remote.agentPresets.read.mockImplementationOnce(() => late.promise)
const first = controller.view('standard')
controller.closeView()
late.resolve({ ok: true, value: { agentPreset: 'standard', name: 'Standard', content: 'old' } })
await first
expect(state().view).toBeNull()
const failed = Promise.withResolvers<Awaited<ReturnType<typeof remote.agentPresets.read>>>()
remote.agentPresets.read.mockImplementationOnce(() => failed.promise)
const stale = controller.view('standard')
await controller.view('mine')
failed.reject(new Error('stale read'))
await stale
expect(state()).toMatchObject({ error: null, view: { id: 'mine', content: '- name: fs\n' } })
})
it('keeps default selection and blank-session synchronization on their existing settings path', async () => {
const { controller, remote, state } = fixture()
const sync = vi.fn(async () => undefined)
@@ -3,6 +3,7 @@ import { act, cleanup, fireEvent, render, screen, waitFor, within } from '@testi
import { afterEach, expect, it, vi } from 'vitest'
import { bindSnapshotSelector } from '@deepseek-ai/dsh-client-test-runtime'
import { createSnapshotStore } from '@deepseek-ai/dsh-client-store'
import { Modal } from '@deepseek-ai/dsh-client-ui-primitives'
import { AgentPresetSection, type AgentPresetSectionProps } from '../src/client/AgentPresetSection.tsx'
import type { AgentPresetSectionState } from '../src/client/section-store.ts'
import { en } from '../src/client/locales.ts'
@@ -11,10 +12,12 @@ const translations: ReadonlyMap<string, string> = new Map(Object.entries(en))
function unusedHook(): never {
throw new Error('This section does not read global slot sources')
}
function view(partial: Partial<AgentPresetSectionState> = {}, startCreatorDraft?: () => void, developerTools = true) {
function view(partial: Partial<AgentPresetSectionState> = {}, startCreatorDraft?: () => void, developerTools = true,
outerClose?: () => void) {
const store = createSnapshotStore<AgentPresetSectionState>({ status: 'ready', error: null,
showPicker: true, policySaving: false, rows: [{ id: 'standard', isDefault: true }, { id: 'mine', name: 'Mine', isDefault: false }], ...partial })
const actions = { load: vi.fn(async () => {}), makeDefault: vi.fn(async () => {}),
showPicker: true, policySaving: false, rows: [{ id: 'standard', isDefault: true }, { id: 'mine', name: 'Mine', isDefault: false }],
view: null, ...partial })
const actions = { load: vi.fn(async () => {}), view: vi.fn(async () => {}), closeView: vi.fn(), makeDefault: vi.fn(async () => {}),
setPickerVisible: vi.fn(async () => {}), close: vi.fn() }
const props: AgentPresetSectionProps = { ...actions,
...(startCreatorDraft === undefined ? {} : { startCreatorDraft }),
@@ -23,8 +26,9 @@ function view(partial: Partial<AgentPresetSectionState> = {}, startCreatorDraft?
useAgentPresetSection: bindSnapshotSelector(store),
useDeveloperTools: bindSnapshotSelector(createSnapshotStore(developerTools)),
t: key => translations.get(key) ?? key }
render(<AgentPresetSection {...props} />)
return actions
render(outerClose === undefined ? <AgentPresetSection {...props} />
: <Modal open onClose={outerClose} title="Settings" closeLabel="Close"><AgentPresetSection {...props} /></Modal>)
return { ...actions, store }
}
function rowFor(id: string): HTMLElement {
const row = document.querySelector<HTMLElement>(`[data-agent-preset-id="${id}"]`)
@@ -87,6 +91,52 @@ it('disables the Creator entry when mode selection is hidden', () => {
fireEvent.click(button)
expect(launch).not.toHaveBeenCalled()
})
it('reads a declared composition read-only from every card, broken ones included', () => {
const actions = view({ rows: [{ id: 'standard', isDefault: true }, { id: 'broken', isDefault: false, broken: 'Missing plugin' }] })
expect(screen.queryByRole('dialog')).toBeNull()
fireEvent.click(within(rowFor('standard')).getByRole('button', { name: `${en.view}: ${en.presetStandardName}` }))
expect(actions.view).toHaveBeenCalledWith('standard')
fireEvent.click(within(rowFor('broken')).getByRole('button', { name: `${en.view}: broken` }))
expect(actions.view).toHaveBeenLastCalledWith('broken')
expect(actions.makeDefault).not.toHaveBeenCalled()
})
it('shows the open composition under the preset display name, without copy, and closes it from the footer', () => {
const actions = view({ view: { id: 'standard', title: 'standard', content: '- id: tool-fs\n name: fs\n' } })
const dialog = screen.getByRole('dialog', { name: `${en.view} · ${en.presetStandardName}` })
expect(dialog.querySelector('pre')?.textContent).toBe('- id: tool-fs\n name: fs\n')
expect(within(dialog).queryByRole('textbox')).toBeNull()
expect(dialog.querySelectorAll('p')).toHaveLength(0)
fireEvent.click(within(dialog).getAllByRole('button', { name: en.close }).at(-1)!)
expect(actions.closeView).toHaveBeenCalledOnce()
cleanup()
view({ view: { id: 'gone', title: 'Gone', content: '[]\n' } })
expect(screen.getByRole('dialog', { name: `${en.view} · Gone` })).toBeTruthy()
})
it('keeps Escape inside the composition viewer when Settings is also open', () => {
const closeSettings = vi.fn()
const actions = view({}, undefined, true, closeSettings)
const trigger = within(rowFor('standard')).getByRole('button', { name: `${en.view}: ${en.presetStandardName}` })
trigger.focus()
fireEvent.click(trigger)
act(() => { actions.store.set({ ...actions.store.getSnapshot(), view: { id: 'standard', title: 'standard', content: '[]\n' } }) })
const dialog = screen.getByRole('dialog', { name: `${en.view} · ${en.presetStandardName}` })
const [header, footer] = within(dialog).getAllByRole('button', { name: en.close })
expect(document.activeElement).toBe(footer)
fireEvent.keyDown(footer!, { key: 'Tab' })
expect(document.activeElement).toBe(header)
fireEvent.keyDown(header!, { key: 'Tab', shiftKey: true })
expect(document.activeElement).toBe(footer)
fireEvent.keyDown(footer!, { key: 'Escape' })
expect(actions.closeView).toHaveBeenCalledOnce()
expect(closeSettings).not.toHaveBeenCalled()
expect(actions.close).not.toHaveBeenCalled()
expect(document.activeElement).toBe(trigger)
})
it('clears an open viewer when the settings section unmounts', () => {
const actions = view({ view: { id: 'standard', title: 'standard', content: '[]\n' } })
cleanup()
expect(actions.closeView).toHaveBeenCalledOnce()
})
it('shows roster errors while the policy switch stays usable', () => {
const actions = view({ error: 'Roster stale', rows: [{ id: 'broken', isDefault: false, broken: 'Missing plugin' }] })
expect(screen.getAllByRole('alert').map(node => node.textContent)).toEqual(['Roster stale', 'Missing plugin'])
@@ -2,5 +2,5 @@
# side as of the last confirmed-consistent state. Both languages carry equal authority;
# after editing either side, bring the other along and re-record with:
# pnpm run verify-translation-pairing --write packages/client/ui-primitives/README.md
README.md: 36ec3d016c1e39527fe71634157a8604e84aa3e7
README.zh.md: 46e692b74d25e816632663490ba065cf188989fb
README.md: 5b8a16739504d8da169e04f64b0feb684f47f8c3
README.zh.md: 291beb0cef60584ec86d349e8be8a11a1ae1694b
+1 -1
View File
@@ -49,7 +49,7 @@ Check this table before writing a control in a feature package. A plugin cannot
| `StateDot` | Solid green `done`, amber `warning`, red `error`, and neutral-grey `idle` marks in a 10px slot, plus a tertiary-grey 14px rotating `ongoing` loader whose animations pin to document time zero so every visible loader rotates in phase. `aria-hidden`, so the render site owns the name. `appearance="step"` shows a filled check for completion and a hollow pending circle. |
| `ConnectionIndicator` | Inline connection-recovery control across outage, retry, and recovered states. |
| `DisclosureRow` | 24px compact disclosure that lays title and content side by side. Memoized with shallow prop comparison; keep callbacks and React-node props stable when their content is unchanged. |
| `Modal` | Centered dialog over a page mask. |
| `Modal` | Centered dialog over a page mask. A nested dialog can intercept keys with `onKeyDownCapture` before document Escape handlers. |
| `RiskConfirmation` | Sensitive action gated behind an explicit checkbox. |
| `OnboardingSurface` | First-run stage that holds the application root inert. |
| `Tooltip` | Hover text anchored to a cloned child; optional `portal` rendering escapes clipping containers and ancestor stacking contexts that cap the bubble's z-index. |
+1 -1
View File
@@ -49,7 +49,7 @@ kind: "package-library"
| `StateDot` | 10px 槽内的绿色 `done`、琥珀色 `warning`、红色 `error`、中性灰色 `idle` 圆点,以及 tertiary 灰色 14px 旋转 `ongoing` loading,其动画固定到文档时间零点,所以所有可见 loading 同相旋转。它是 `aria-hidden` 的,名称由渲染点提供。 `appearance="step"` 以实心勾表示完成、空心圆表示等待。 |
| `ConnectionIndicator` | 行内连接恢复控件,覆盖断线、重试与已恢复三种状态。 |
| `DisclosureRow` | 24px 紧凑折叠行,标题与内容左右排列。使用浅层 prop 比较进行 memo;内容未变时,保持回调与 React 节点 prop 的引用稳定。 |
| `Modal` | 页面遮罩之上的居中对话框。 |
| `Modal` | 页面遮罩之上的居中对话框。嵌套对话框可通过 `onKeyDownCapture` 在文档级 Escape 处理器之前拦截按键。 |
| `RiskConfirmation` | 以显式复选框把关的敏感操作确认。 |
| `OnboardingSurface` | 首次运行的引导舞台,期间保持应用根节点 inert。 |
| `Tooltip` | 锚定在克隆子元素上的悬停文本;可通过 `portal` 渲染到外层,避免被容器裁剪,或受祖先层叠上下文限制其 z-index。 |
+5 -3
View File
@@ -1,5 +1,5 @@
import { useEffect } from 'react'
import type { ReactNode } from 'react'
import type { KeyboardEventHandler, ReactNode } from 'react'
import { createPortal } from 'react-dom'
import clsx from 'clsx'
import { IconCloseOutlineRegular } from './icons/index.tsx'
@@ -14,6 +14,7 @@ interface ModalBaseProps {
footer?: ReactNode
className?: string
contentClassName?: string
onKeyDownCapture?: KeyboardEventHandler<HTMLDivElement>
}
type ModalProps = ModalBaseProps & (
@@ -34,10 +35,11 @@ type ModalProps = ModalBaseProps & (
* @param props.contentClassName - optional class for a scrollable content region.
* @param props.headless - render children directly in the card (no default
* header/close/body chrome); mask, card, Escape, and aria-label remain.
* @param props.onKeyDownCapture - handle a nested dialog's keys before the document Escape listeners.
* @returns null when closed; otherwise the overlay tree.
*/
export function Modal({
open, onClose, title, closeLabel, description, children, footer, className, contentClassName, headless = false,
open, onClose, title, closeLabel, description, children, footer, className, contentClassName, onKeyDownCapture, headless = false,
}: ModalProps) {
useEffect(() => {
if (!open) return
@@ -51,7 +53,7 @@ export function Modal({
if (!open) return null
return createPortal((
<div className={css.root} role="presentation">
<div className={css.root} role="presentation" onKeyDownCapture={onKeyDownCapture}>
<div className={css.mask} aria-hidden="true" onClick={onClose} />
<div
className={clsx(css.dialog, className)}
@@ -159,6 +159,12 @@ export const SERVICE_API: readonly ServiceApiEntry[] = [
parameters: [{ name: 'id', description: 'Explicit preset or the current default.' }],
returns: 'Current metadata, including failure when activation failed.',
},
{
signature: '@Remote(\'read\') readDocument(agentPreset: string): Promise<AgentPresetDocument>',
description: 'Read one declaration\'s child plugin list as YAML, for viewing only.',
parameters: [{ name: 'agentPreset', description: 'Preset identity.' }],
returns: 'The declared composition beside its published metadata.',
},
{
signature: 'async mount(ctx: Context, id?: string): Promise<AgentPreset>',
description: 'Bind an unpublished Agent to the current preset revision.',
@@ -4275,6 +4281,10 @@ export const TYPE_API: readonly TypeApiEntry[] = [
name: 'AgentPresetCompositionRow',
declaration: 'export interface AgentPresetCompositionRow {\n readonly entryId: string | null;\n readonly moduleName: string;\n readonly enabled: CompositionRowEnablement;\n readonly condition?: string;\n readonly fiberState?: FiberState;\n}',
},
{
name: 'AgentPresetDocument',
declaration: 'export interface AgentPresetDocument {\n readonly agentPreset: string;\n readonly content: string;\n readonly name?: string;\n readonly description?: string;\n}',
},
{
name: 'AgentPresetRoster',
declaration: 'export interface AgentPresetRoster {\n readonly presets: readonly AgentPresetRow[];\n readonly modeSelectionEnabled: boolean;\n}',
@@ -2,5 +2,5 @@
# side as of the last confirmed-consistent state. Both languages carry equal authority;
# after editing either side, bring the other along and re-record with:
# pnpm run verify-translation-pairing --write packages/preset/agent-preset-registry/README.md
README.md: 7a1ee3e733fc54194515dbf093e53af0c9698e40
README.zh.md: 11206a3f9237cbca237220a81fd98ec5eea1083e
README.md: 44b01be1ceea5936668f091fb410137f3a139a88
README.zh.md: a0c75fa50ba781ffc394e04502c922684beda387
@@ -45,7 +45,7 @@ Choose an Agent’s tools, prompt sections and skills through declarative preset
The Web definitions come from the `dsh-web-app` bundle. Definitions are ordinary plugin rows; the registry neither scans directories nor accepts preset paths. The `selectedDefault` and `modeSelectionEnabled` volatile fields of the `agent-preset-registry` entry retain the user default and the chooser visibility; hiding the chooser uses the deployment `default`.
The registry writes no declarations. A new preset or an override of a shipped one is a bundle patch: an `insert` of a `@deepseek-ai/dsh-agent-preset` row, or a patch keyed by that row’s id, installed into the profile with `plugin_manager`; Creator mode authors such bundles in conversation.
The registry writes no declarations. The `read` Remote renders one declaration’s child list back as entry-list YAML (`!!js` conditions included) so a client can show what a preset composes; nothing accepts YAML back. A new preset or an override of a shipped one is a bundle patch: an `insert` of a `@deepseek-ai/dsh-agent-preset` row, or a patch keyed by that row’s id, installed into the profile with `plugin_manager`; Creator mode authors such bundles in conversation.
<a id="understand-the-implementation"></a>
## Understand the implementation
@@ -45,7 +45,7 @@ kind: "package-reference"
Web 内置定义来自 `dsh-web-app` bundle。定义使用普通插件行;注册表不扫描目录,也不接受 preset 路径。`agent-preset-registry` 条目的 volatile 字段 `selectedDefault` 与 `modeSelectionEnabled` 保留用户默认值和选择器可见性;隐藏选择器时使用部署 `default`。
注册表不写入任何声明。新建 preset 或覆盖内置 preset 都是 bundle 补丁:插入一行 `@deepseek-ai/dsh-agent-preset`,或按该行 id 写覆盖补丁,再用 `plugin_manager` 安装到 profile;创造模式在对话中编写这类 bundle。
注册表不写入任何声明。`read` Remote 把一条声明的子插件列表按 entry-list YAML 方言(含 `!!js` 条件)渲染回来,供客户端展示 preset 的组成;没有任何接口接受 YAML 写回。新建 preset 或覆盖内置 preset 都是 bundle 补丁:插入一行 `@deepseek-ai/dsh-agent-preset`,或按该行 id 写覆盖补丁,再用 `plugin_manager` 安装到 profile;创造模式在对话中编写这类 bundle。
<a id="understand-the-implementation"></a>
## 理解实现
@@ -53,6 +53,7 @@
],
"license": "MIT",
"peerDependencies": {
"@deepseek-ai/cordis-plugin-include": "workspace:~",
"@deepseek-ai/cordis-plugin-loader": "workspace:~",
"@deepseek-ai/dsh-agent": "workspace:*",
"@deepseek-ai/dsh-invariants": "workspace:*",
@@ -67,7 +68,8 @@
},
"dependencies": {
"@deepseek-ai/schemastery": "workspace:~",
"zod": "^4.4.3"
"zod": "^4.4.3",
"js-yaml": "^4.2.0"
},
"devDependencies": {
"@deepseek-ai/dsh-app-boot": "workspace:*",
@@ -91,6 +93,7 @@
"@deepseek-ai/dsh-sandbox": "workspace:*",
"@deepseek-ai/dsh-sandbox-policy": "workspace:*",
"@deepseek-ai/dsh-user-approval": "workspace:*",
"@deepseek-ai/dsh-agent-preset": "workspace:*"
"@deepseek-ai/dsh-agent-preset": "workspace:*",
"@types/js-yaml": "^4.0.9"
}
}
@@ -3,11 +3,13 @@ import { Context } from '@deepseek-ai/cordis'
import z from '@deepseek-ai/schemastery'
import { Remote, RemoteError, TypertRemoteService } from '@deepseek-ai/dsh-typert-protocol'
import { bindScopeParent, createScope, scopeOf, type Scope, type ScopeKey, type ScopeParentBinding } from '@deepseek-ai/dsh-scope'
import { entryListSchema } from '@deepseek-ai/cordis-plugin-include'
import { dump } from 'js-yaml'
import type { Agent } from '@deepseek-ai/dsh-agent'
// Type-only: the optional `settings` service this registry keeps off the generated pages.
import type {} from '@deepseek-ai/dsh-settings'
import type {} from '@deepseek-ai/dsh-tools'
import type { AgentPresetRoster } from './types.ts'
import type { AgentPresetDocument, AgentPresetRoster } from './types.ts'
import { entryListProblem, type PresetDefinition } from './definition.ts'
import type { AgentPreset, Config } from './preset.ts'
import { agentPresetProjectionDefinition } from './session.ts'
@@ -191,6 +193,25 @@ export class AgentPresetRegistry extends TypertRemoteService {
return { id: wanted, ...(broken === undefined ? {} : { broken }) }
}
/** Read one declaration's child plugin list as YAML, for viewing only.
* @param agentPreset Preset identity.
* @returns The declared composition beside its published metadata.
*/
@Remote('read')
readDocument(agentPreset: string): Promise<AgentPresetDocument> {
const record = this.definitions.get(agentPreset)
if (record === undefined) {
return Promise.reject(new RemoteError('agent-preset/not-found', `Unknown agent preset: ${agentPreset}`,
{ agentPreset, available: [...this.definitions.keys()] }))
}
const { id, name, description, plugins } = record.config
// The Loader's own dialect, so `!!js` conditions read as declared rather than as expression objects.
const content = dump(plugins, { schema: entryListSchema, noRefs: true, lineWidth: -1 })
return Promise.resolve({
agentPreset: id, content, ...(name === undefined ? {} : { name }), ...(description === undefined ? {} : { description }),
})
}
private async retain(id?: string): Promise<Generation> {
const wanted = id ?? this.defaultId
while (true) {
@@ -26,6 +26,18 @@ export interface AgentPresetRoster {
readonly modeSelectionEnabled: boolean
}
/** One preset's declared composition, rendered for reading. */
export interface AgentPresetDocument {
/** The preset the composition belongs to. */
readonly agentPreset: string
/** The declared child plugin list as entry-list YAML, `!!js` expressions included. */
readonly content: string
/** Display name the preset published. */
readonly name?: string
/** One sentence on what this preset is for. */
readonly description?: string
}
declare module '@deepseek-ai/dsh-typert-protocol' {
interface RemoteErrorDetailsMap {
/** No declaration supplies the requested identity. */
@@ -2,7 +2,7 @@ import { afterEach, describe, expect, it } from 'vitest'
import { createScope } from '@deepseek-ai/dsh-scope'
import { assembleContextFor } from '@deepseek-ai/dsh-agent'
import { entryListProblem, livePresetMounts } from '../src/index.ts'
import { currentKey, harness, declare, contribution, agentOn, liveRegistries } from './harness.ts'
import { currentKey, harness, declare, contribution, agentOn, liveRegistries, plugin } from './harness.ts'
import { omitsGeneratedPage } from '../../../settings/settings/tests/live-config.ts'
import Loader from '@deepseek-ai/cordis-plugin-loader'
import SessionProjectionRegistry from '@deepseek-ai/dsh-session-projection'
@@ -121,6 +121,27 @@ describe('declarative preset revisions', () => {
expect.objectContaining({ id: 'empty', rows: [expect.objectContaining({ moduleName: 'missing', enabled: false })] }),
]))
})
it('renders a declaration as entry-list YAML for reading, conditions included', async () => {
const ctx = await setup()
await declare(ctx, {
...contribution('standard'), name: 'Standard', description: 'General',
plugins: [
{ id: 'contribute', name: plugin('contribute'), config: { tool: 'standard' } },
{ id: 'windows-only', name: 'missing', disabled: { __jsExpr: "process.platform !== 'win32'" } },
],
})
const document = await ctx.agentPresets.readDocument('standard')
expect(document).toMatchObject({ agentPreset: 'standard', name: 'Standard', description: 'General' })
expect(document.content.startsWith('- id: contribute\n name: ')).toBe(true)
expect(document.content).toContain("\n config:\n tool: standard\n- id: windows-only\n name: missing\n disabled: !!js process.platform !== 'win32'\n")
expect(document.content).not.toContain('__jsExpr')
await declare(ctx, contribution('minimal'))
expect(await ctx.agentPresets.readDocument('minimal')).toEqual({
agentPreset: 'minimal', content: expect.any(String) as string,
})
await expect(ctx.agentPresets.readDocument('absent')).rejects.toThrow('Unknown agent preset: absent')
})
})
it('retains a retired revision for an in-flight cold read', async () => {
+6
View File
@@ -9616,6 +9616,9 @@ importers:
'@deepseek-ai/schemastery':
specifier: link:../../../vendor/schemastery
version: link:../../../vendor/schemastery
js-yaml:
specifier: ^4.2.0
version: 4.3.1
zod:
specifier: ^4.4.3
version: 4.4.3
@@ -9686,6 +9689,9 @@ importers:
'@deepseek-ai/dsh-user-approval':
specifier: workspace:*
version: link:../../interaction/user-approval
'@types/js-yaml':
specifier: ^4.0.9
version: 4.0.9
packages/preset/persona:
dependencies: