fix(ui-conversation): preserve composer bar props for existing plugins

This commit is contained in:
EricMoin committed 2026-11-20 16:41:36 +08:00
1 parent 7cb77eade7
commit c50abb6f2f
13 files changed
+149 -89

No files matched your search

@@ -1,16 +0,0 @@
# Bilingual-pair consistency record for guide.md (docs/i18n/README.md): per heading
# section, a hash of its English and Chinese blocks outside code blocks and generated regions.
# After editing either side, bring the other along and re-record with:
# pnpm run verify-translation-pairing --write docs/upgrade-guide/v0.2.2-rc.5/composer-bar-placeholder-slot/guide.md
/:
en: 173c515498e7b371
zh: 033eee00d419ce1b
/composer-bar-props-require-a-placeholder-renderer:
en: 4d6c99579d07b5ce
zh: e922b7d8c73cbf6f
/composer-bar-props-require-a-placeholder-renderer/change:
en: fa611f5d3749d20b
zh: 1d32a73e54bb8c42
/composer-bar-props-require-a-placeholder-renderer/migration:
en: 6f543e4b2bc60c76
zh: eae15e765a8a248b
@@ -1,18 +0,0 @@
---
kind: upgrade-guide
description: "Code that constructs ComposerBarProps must now supply renderSlotChain for the built-in composer placeholder."
---
# Composer bar props require a placeholder renderer
English | [中文](guide.zh.md)
## Change
`ComposerBarProps` from `@deepseek-ai/dsh-client-ui-conversation/client` now requires `renderSlotChain` for `conversation.input.placeholder`. Code that constructs these props without that member fails type checking. Whole-bar replacements that use `ComposerBarProps` need a props type derived from their own registration.
## Migration
1. For fixtures that construct `ComposerBarProps`, provide `renderSlotChain: (_key, _owner, options) => options?.fallback` to render the built-in placeholder in tests without slot contributions.
2. For a replacement registered in `conversation.composer.bar`, start with `PropsRuntime<'conversation.composer.bar'>` from `@deepseek-ai/dsh-client-ui-slots`. Add `PropsRenderSlots` for the child keys in the replacement's own registration and keep the injected and locale props it uses. See [Slots](../../../subsystems/slots.md).
3. Run your TypeScript check to confirm the updated props and registration agree.
@@ -1,18 +0,0 @@
---
kind: upgrade-guide
description: "构造 ComposerBarProps 的代码现在必须提供内置输入栏占位提示的 renderSlotChain。"
---
# 输入栏 props 需要提供占位提示的渲染函数
[English](guide.md) | 中文
## 变更
`@deepseek-ai/dsh-client-ui-conversation/client` 导出的 `ComposerBarProps` 现在要求提供 `conversation.input.placeholder` 的 `renderSlotChain`。构造这组 props 时缺少该属性会导致类型检查失败。使用 `ComposerBarProps` 替换整个输入栏的组件,需要按自己的注册声明定义 props 类型。
## 迁移
1. 若测试夹具构造 `ComposerBarProps`,提供 `renderSlotChain: (_key, _owner, options) => options?.fallback`,让没有插槽贡献的测试显示内置占位提示。
2. 若在 `conversation.composer.bar` 注册替换输入栏,以 `@deepseek-ai/dsh-client-ui-slots` 的 `PropsRuntime<'conversation.composer.bar'>` 为基础类型。按该注册声明的子插槽键加入 `PropsRenderSlots`,并保留组件使用的注入和本地化 props。参见[插槽](../../../subsystems/slots.zh.md)。
3. 运行 TypeScript 类型检查,确认更新后的 props 与注册声明匹配。
@@ -21,8 +21,8 @@
en: 4a094cd97426ad18
zh: 5faadddb7e2b0a43
/deepseek-ai-dsh-client-ui-conversation/shell-and-standard-props:
en: a5caa37045ac6c9a
zh: a97522f13f4d0f25
en: 793a61adeee867e0
zh: 732017ffb439a73b
/deepseek-ai-dsh-client-ui-conversation/shell-and-standard-props/control-geometry:
en: 876be274c65b56d9
zh: c3adbf5a16e0e38e
@@ -132,6 +132,8 @@ The main Conversation body can keep room free at its inline end for something th
The built-in composer exposes `conversation.input.placeholder` for an empty, editable Session input. A chain entry matches the owner's `sessionId` and renders localized text or non-interactive inline JSX such as `<kbd>/</kbd>`. The visible hint supplies the textbox's accessible name. When every selector returns `null`, the composer shows its usual home, Plan, or default hint. Workspace selection, blocked input, unavailable Sessions, and queue steering use the composer's own prompts.
For plugins that replace `conversation.composer.bar`, `ComposerBarProps` defaults to a fixed set of child slots, so adding a slot to the built-in composer preserves existing plugin types. A replacement can use `ComposerBarProps<keyof typeof children>` to derive its render keys from the `children` table it passes to `slots.register`.
The resident composer survives no-Session and Session transitions. Whitespace hides its placeholder; a whitespace-only draft without attachments cannot be sent. The no-Session state keeps the same composer surface mounted but inert while the Workspace picker connects a blank Session. The surface is a shell-owned Lexical editor: reference chips are atomic decorator nodes carrying the owner's serialization identity (submission expands them through the owner codec), the claimed slash command is an atomic leading chip that carries its claim, folder text references carry the folder glyph as an icon prefix, and the draft's text and semantic references are persisted by the per-Session Conversation store. QueueDock reads `next-turn` from the Session `inbox` projection, including cold recovered messages, and excludes only requestIds still owned by local transcript submissions. Other queued rows retain their normal display and actions. Queue operations address exact queue occurrences through the scoped `ctx.conversation` service; queue previews use the [UserText Factory](#sent-user-text) (wire session forms fold to their label) and show local or durable images and files in original attachment order. Images use thumbnails; files use compact name-and-size cards. An edit exposes the literal sent text in the ui-primitives `InlineEditor`, so line breaks survive re-editing. Durable thumbnails resolve through the session image URL cache. Busy Enter behavior is stored in the Host-backed `ui-conversation` settings namespace. The composer keymap arbitrates the trigger menu's keys through the slash pipeline — Tab settles the highlighted completion (or drills a drillable one), Escape and Shift+Tab leave the menu without settling — and leaves every other key to the editor. On Apple platforms, Home and End move the caret to the start or end of the current visual line instead of scrolling the conversation, and Shift extends the selection; End immediately before a quote takes the same path as Cmd+Right to the end of that line. An overlay that takes the keyboard hands it back through `SessionInput.focus()`, which rides Lexical's own focus so the caret returns where the draft left it rather than at the start.
In narrow browser settings, the busy-state Enter preference uses a smaller label gutter. Windows and macOS desktop windows retain the standard spacing.
@@ -132,6 +132,8 @@ Session 首次绑定或缓存的 Session 成为 current 时,shell 会在渲染
内置输入栏通过 `conversation.input.placeholder` 为可编辑会话的空输入框提供占位提示。插件通过 chain 的选择器匹配拥有者传入的 `sessionId`。匹配的组件可渲染本地化文字或不参与交互的行内 JSX,例如 `<kbd>/</kbd>`。提示可见时,其文字用作输入框的无障碍名称。所有选择器均返回 `null` 时,输入栏按当前状态显示首页、Plan 或默认提示。选择工作区、输入受阻、会话不可用或可将排队消息送入当前轮次时,输入栏显示相应的内置提示。
替换 `conversation.composer.bar` 的插件可以直接使用 `ComposerBarProps`。它默认使用一组固定的子插槽,内置输入栏新增插槽时,现有插件的类型仍然兼容。替换组件也可以使用 `ComposerBarProps<keyof typeof children>`,从传给 `slots.register` 的 `children` 声明中推导自己可以渲染的键。
常驻 composer 在无 Session 与有 Session 之间保持挂载。输入空白字符会隐藏占位提示;没有附件的纯空白草稿无法发送。无 Session 时,同一个编辑器表面保持 inert,Workspace picker 连接 blank Session。该表面是 shell 所有的 Lexical 编辑器:引用 chip 是携带 owner 序列化身份的原子 decorator 节点(提交时经 owner codec 展开),已认领的 slash command 是携带认领的行首原子 chip,文件夹文本引用以图标前缀携带文件夹图形,草稿文字和引用语义字段由逐 Session Conversation store 持久化。QueueDock 从 Session 的 `inbox` 投影读取 `next-turn`,包含从冷状态恢复的消息,仅排除仍由本地 transcript 提交承接的 requestId。其他排队行保留正常展示和操作。Queue 操作通过 scoped `ctx.conversation` service 寻址准确的 queue occurrence;queue 预览使用 [UserText Factory](#sent-user-text)(wire 会话形式折叠为其标签),并按原始附件顺序展示本地或持久化的图片和文件。图片使用缩略图,文件使用紧凑的名称与大小卡片。编辑态在 ui-primitives 的 `InlineEditor` 中展示字面发送文本,因此重新编辑不会丢失换行。持久化缩略图通过会话图片 URL 缓存解析。繁忙时 Enter 行为保存在 Host-backed `ui-conversation` settings namespace。 composer 键盘映射经斜杠流水线裁决触发菜单的按键——Tab 确认高亮补全项(可下钻项则下钻),Escape 与 Shift+Tab 离开菜单且不选定——其余按键交给编辑器自身。 在 Apple 平台上,Home 与 End 把光标移到当前视觉行的行首或行末,而不是滚动对话,按住 Shift 时扩展选区;光标紧贴在 quote 左侧时,End 与 Cmd+Right 走同一路径移到该行末尾。 接管键盘的浮层通过 `SessionInput.focus()` 把键盘还回来,该路径走 Lexical 自己的 focus,因此光标回到草稿原来的位置而不是开头。
窄屏浏览器设置中,繁忙时 Enter 偏好的标签与控件间距缩小;Windows 和 macOS 桌面窗口保留标准间距。
@@ -21,6 +21,7 @@ import { UserText, PlainUserText, SessionReference } from './user-text/UserText.
import { sessionReferenceRule } from './user-text/session-reference-rule.ts'
import { collapseWhitespaceRule, trimWhitespaceRule } from './user-text/whitespace-rules.ts'
import type { ViewTab } from './contract/views.ts'
import { inputBarChildren } from './contract/slots.ts'
import type {
ComposerBarInjected, ConversationInjected, ConversationSessionHeaderInjected, ConversationShellInjected,
ConversationSessionInjected, DraftFileUploads, UserTextInjected,
@@ -464,18 +465,7 @@ export function apply(ctx: Context, config: SyncedConfig<ConversationConfig>): v
const registerComposerBar = () => slots.register({
name: 'conversation.composer.bar',
locale: NS,
children: {
'conversation.input.attachments': { kind: 'single', scope: 'session-maybe' },
'conversation.input.placeholder': { kind: 'chain', scope: 'session', inline: true },
'conversation.input.overlay': { kind: 'list', scope: 'session' },
'conversation.input.permission': { kind: 'single', scope: 'session' },
'conversation.input.left': { kind: 'list', scope: 'session' },
'conversation.input.plan': { kind: 'single', scope: 'session' },
'conversation.input.right': { kind: 'list', scope: 'session' },
'conversation.input.model': { kind: 'single', scope: 'session' },
'conversation.input.activity': { kind: 'single', scope: 'session' },
'conversation.composer.dock': { kind: 'list', scope: 'session' },
},
children: inputBarChildren,
inject: (sessionId: SessionId | undefined): ComposerBarInjected => {
if (sessionId === undefined) {
return {
@@ -9,7 +9,7 @@ import type {
MaybeSnapshotSelectorHook, ObservableSnapshot, SnapshotSelectorHook,
} from '@deepseek-ai/dsh-client-store'
import type {
FactoryComponentPropsOf, FactoryLocalComponentPropsOf,
ChildrenDecl, FactoryComponentPropsOf, FactoryLocalComponentPropsOf,
InjectFace, PropsLocale, PropsRenderFactories, PropsRenderSlots, PropsRuntime, PropsStore,
} from '@deepseek-ai/dsh-client-ui-slots'
import type { SessionPendingInteraction } from '@deepseek-ai/dsh-client-ui-session/client'
@@ -667,16 +667,29 @@ export interface InputActivityOwnerProps extends InputControlOwnerProps {
onActiveChange: (active: boolean) => void
}
/** Props supplied to the built-in resident composer bar. */
export type ComposerBarProps =
/** Adding a key here changes the default render keys for plugins using ComposerBarProps. */
const baseComposerChildren = {
'conversation.input.attachments': { kind: 'single', scope: 'session-maybe' },
'conversation.input.overlay': { kind: 'list', scope: 'session' },
'conversation.input.permission': { kind: 'single', scope: 'session' },
'conversation.input.left': { kind: 'list', scope: 'session' },
'conversation.input.plan': { kind: 'single', scope: 'session' },
'conversation.input.right': { kind: 'list', scope: 'session' },
'conversation.input.model': { kind: 'single', scope: 'session' },
'conversation.input.activity': { kind: 'single', scope: 'session' },
'conversation.composer.dock': { kind: 'list', scope: 'session' },
} as const satisfies ChildrenDecl
/** Child slots owned by the built-in input bar. */
export const inputBarChildren = {
...baseComposerChildren,
'conversation.input.placeholder': { kind: 'chain', scope: 'session', inline: true },
} as const satisfies ChildrenDecl
/** Composer bar props for a registration's child keys. The default preserves the original child slots. */
export type ComposerBarProps<K extends keyof ChildrenDecl = keyof typeof baseComposerChildren> =
PropsRuntime<'conversation.composer.bar'>
& PropsRenderSlots<
| 'conversation.input.attachments' | 'conversation.input.placeholder' | 'conversation.input.overlay'
| 'conversation.input.permission'
| 'conversation.input.left' | 'conversation.input.plan'
| 'conversation.input.right' | 'conversation.input.model' | 'conversation.input.activity'
| 'conversation.composer.dock'
>
& PropsRenderSlots<K>
& InjectFace<ComposerBarInjected>
& PropsLocale<'conversation'>
@@ -28,7 +28,7 @@ import type {} from '@deepseek-ai/dsh-goal/client'
// wire types: apiproxy's sessions contract declares it, and client-runtime's
// api-remotes import already places it in every client program.
import type { Translate } from '@deepseek-ai/dsh-client-ui-slots'
import type { ComposerBarProps } from '../contract/slots.ts'
import type { ComposerBarProps, inputBarChildren } from '../contract/slots.ts'
import { DraftEditor } from '../input/editor/DraftEditor.tsx'
import {
focusDraftEditor, installDraftFilePicker, installDraftKeyboardDismissal, installDraftKeymap, installDraftWheel,
@@ -41,7 +41,7 @@ import { ContextMeter } from './ContextMeter.tsx'
import { observeControlRow } from './control-row-layout.ts'
import css from './InputBar.module.css'
export type InputBarProps = ComposerBarProps
export type InputBarProps = ComposerBarProps<keyof typeof inputBarChildren>
export const InputBar = memo(function InputBar({
useSession, useInput, inputActions, keyboard, addFiles, removeAttachment, resolveDraftAttachments,
@@ -0,0 +1,46 @@
import { expect, expectTypeOf, it, vi } from 'vitest'
import type { ComposerBarInjected, ComposerBarProps } from '@deepseek-ai/dsh-client-ui-conversation/client'
import { SlotCore, type ChildrenDecl, type PropsRenderSlots } from '@deepseek-ai/dsh-client-ui-slots'
it('accepts props supplied by existing composer bar registrations', () => {
const slots = new SlotCore()
slots.register({
name: 'root',
children: { 'conversation.composer.bar': { kind: 'single', scope: 'session-maybe' } },
}, (_props: PropsRenderSlots<'conversation.composer.bar'>) => null)
const children = {
'conversation.composer.dock': { kind: 'list', scope: 'session' },
'conversation.input.activity': { kind: 'single', scope: 'session' },
'conversation.input.attachments': { kind: 'single', scope: 'session-maybe' },
'conversation.input.left': { kind: 'list', scope: 'session' },
'conversation.input.model': { kind: 'single', scope: 'session' },
'conversation.input.overlay': { kind: 'list', scope: 'session' },
'conversation.input.permission': { kind: 'single', scope: 'session' },
'conversation.input.plan': { kind: 'single', scope: 'session' },
'conversation.input.right': { kind: 'list', scope: 'session' },
} satisfies ChildrenDecl
const ExistingBar = ({ renderSlot }: ComposerBarProps) => renderSlot('conversation.input.left', {})
slots.register({
name: 'conversation.composer.bar',
locale: 'conversation',
children,
inject: vi.fn<() => ComposerBarInjected>(),
}, ExistingBar)
expect(slots.entries('conversation.composer.bar')[0]?.component).toBe(ExistingBar)
expectTypeOf<Parameters<ComposerBarProps['renderSlot']>[0]>().toEqualTypeOf<keyof typeof children>()
expectTypeOf<ComposerBarProps>().not.toHaveProperty('renderSlotChain')
})
it('dispatches only the children declared by a custom composer bar', () => {
const children = {
'conversation.input.placeholder': { kind: 'chain', scope: 'session', inline: true },
'conversation.input.left': { kind: 'list', scope: 'session' },
} satisfies ChildrenDecl
type Props = ComposerBarProps<keyof typeof children>
expectTypeOf<Parameters<Props['renderSlot']>[0]>().toEqualTypeOf<'conversation.input.left'>()
expectTypeOf<Parameters<Props['renderSlotChain']>[0]>().toEqualTypeOf<'conversation.input.placeholder'>()
})
+25
View File
@@ -7,8 +7,11 @@
* make a stale or undocumented contract fail loudly instead of shipping.
*/
import { resolve } from 'node:path'
import ts from 'typescript'
import { describe, expect, it } from 'vitest'
import { collectSlotEntries, oversizedSlotReports, resolveSlotEntries, validateSlotContracts } from './gen-client-catalog.ts'
import { slotRegistrations } from './slot-walk.ts'
import type { SlotDeclaration, SlotRegistration, TypeDeclaration } from './slot-walk.ts'
/** A declaration with every field the catalog needs, overridable per case. */
@@ -46,6 +49,24 @@ const OWNER_TYPES = new Map<string, TypeDeclaration>([
])
describe('client slot contract validation', () => {
it('resolves shorthand child tables in the scope of each registration', () => {
const source = `
const children = { 'outer.action': {} }
slots.register({ name: 'outer', children }, Outer)
function registerInner() {
const children = { 'inner.action': {} }
slots.register({ name: 'inner', children }, Inner)
}
function registerDynamic(children) {
slots.register({ name: 'dynamic', children }, Dynamic)
}`
const registrations = slotRegistrations({
rel: 'fixture.ts', package: 'demo',
sf: ts.createSourceFile(resolve('fixture.ts'), source, ts.ScriptTarget.Latest, true),
})
expect(registrations.map(({ children }) => children)).toEqual([['outer.action'], ['inner.action'], []])
})
it('accepts a documented slot whose owner props resolve', () => {
expect(validateSlotContracts(
[declaration({ ownerType: 'DemoOwnerProps' })],
@@ -255,6 +276,10 @@ describe('the real workspace surface', () => {
expect(root?.occupants.join(' ')).toContain('AppFrame')
expect(entries.find(entry => entry.key === 'conversation.session')?.declaredBy)
.toContain("factory 'conversation.content' (client-ui-conversation)")
for (const key of ['conversation.input.attachments', 'conversation.input.placeholder']) {
expect(entries.find(entry => entry.key === key)?.declaredBy)
.toContain("an entry in 'conversation.composer.bar' (client-ui-conversation)")
}
const tool = entries.find(entry => entry.key === 'tool.call.toolview')!
const owner = tool.ownerProps.join('\n')
for (const field of ['callId', 'toolName', 'useDisclosure', 'cwd', 'home', 'openFile', 'loadImage', 'inspect']) {
+1 -1
View File
@@ -5,7 +5,7 @@
* which keys exist, what each register call must pass, what the component
* receives, who already occupies the seat, and when the seat exists at all —
* is decided at compile time by the shipped web bundle. This generator reads
* those facts lexically (no type-checker program) and emits them as a data
* those facts from source and emits them as a data
* module inside `tool-cordis`, so the host-side toolset teaches the browser
* surface without importing a single client runtime module.
*
+44 -10
View File
@@ -1,10 +1,8 @@
/**
* AST helpers for the client slot surface: the `SlotMap` declaration merges
* that type every slot, and the `slots.register` / `slots.registerFactory`
* call sites that say who occupies or declares one. Both readings are lexical:
* the client catalog generator consumes them, and the same scan doubles as its
* own exhaustiveness backstop because it reads every source file rather than a
* reachable-export closure.
* call sites that say who occupies or declares one. The scanner resolves named
* child tables through local bindings and relative imports.
*/
import { globSync, readFileSync } from 'node:fs'
@@ -195,6 +193,8 @@ export function slotDeclarations(file: ScannedFile): SlotDeclaration[] {
*/
export function slotRegistrations(file: ScannedFile): SlotRegistration[] {
const out: SlotRegistration[] = []
let checker: ts.TypeChecker | undefined
const bindings = () => checker ??= localBindings(file.sf)
const visit = (node: ts.Node): void => {
if (ts.isCallExpression(node)
&& ts.isPropertyAccessExpression(node.expression)
@@ -214,7 +214,7 @@ export function slotRegistrations(file: ScannedFile): SlotRegistration[] {
...node.expression.name.text === 'registerFactory' ? { factory: true } : {},
...id === undefined ? {} : { id },
...entryKey === undefined ? {} : { entryKey },
children: childKeys(options),
children: childKeys(options, bindings),
source: `${file.rel}:${String(lineOf(file.sf, node))}`,
})
}
@@ -413,18 +413,52 @@ function stringProperty(options: ts.ObjectLiteralExpression, name: string): stri
return undefined
}
/** Bind the scanned AST and its relative imports without loading installed packages or build outputs. */
function localBindings(source: ts.SourceFile): ts.TypeChecker {
const options: ts.CompilerOptions = { noLib: true, types: [], module: ts.ModuleKind.Preserve }
const host = ts.createCompilerHost(options, true)
const read = host.getSourceFile.bind(host)
host.getSourceFile = (name, ...args) => name === source.fileName ? source : read(name, ...args)
host.resolveModuleNameLiterals = (imports, from) => imports.map(({ text }) => text.startsWith('.')
? ts.resolveModuleName(text, from, options, host)
: { resolvedModule: undefined })
return ts.createProgram([source.fileName], options, host).getTypeChecker()
}
/** The SlotMap keys a registration's `children` table declares. */
function childKeys(options: ts.ObjectLiteralExpression): string[] {
function childKeys(options: ts.ObjectLiteralExpression, bindings: () => ts.TypeChecker): string[] {
for (const property of options.properties) {
if (!ts.isPropertyAssignment(property)) continue
if (!ts.isPropertyAssignment(property) && !ts.isShorthandPropertyAssignment(property)) continue
if (memberName(property.name) !== 'children') continue
if (!ts.isObjectLiteralExpression(property.initializer)) return []
return property.initializer.properties
.flatMap(child => (child.name === undefined ? [] : [memberName(child.name)]))
const table = ts.isPropertyAssignment(property) ? property.initializer : property.name
return [...new Set(tableKeys(table, bindings, new Set()))]
}
return []
}
/** Read literal keys, including those contributed by const tables and their spreads. */
function tableKeys(expr: ts.Expression, bindings: () => ts.TypeChecker, seen: Set<ts.Declaration>): string[] {
if (ts.isAsExpression(expr) || ts.isSatisfiesExpression(expr) || ts.isParenthesizedExpression(expr)) {
return tableKeys(expr.expression, bindings, seen)
}
if (ts.isObjectLiteralExpression(expr)) {
return expr.properties.flatMap(child => ts.isSpreadAssignment(child)
? tableKeys(child.expression, bindings, seen)
: [memberName(child.name)])
}
if (!ts.isIdentifier(expr)) return []
const checker = bindings()
const symbol = ts.isShorthandPropertyAssignment(expr.parent)
? checker.getShorthandAssignmentValueSymbol(expr.parent)
: checker.getSymbolAtLocation(expr)
if (symbol === undefined) return []
const variable = (symbol.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol).valueDeclaration
if (variable === undefined || !ts.isVariableDeclaration(variable) || variable.initializer === undefined
|| !(variable.parent.flags & ts.NodeFlags.Const) || seen.has(variable)) return []
seen.add(variable)
return tableKeys(variable.initializer, bindings, seen)
}
/** The component argument as written; a non-identifier expression is collapsed. */
function componentText(argument: ts.Expression | undefined, sf: ts.SourceFile): string {
if (argument === undefined) return '(none)'