wip
fix: docs
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import type { InjectFace, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots'
|
||||
import type { InjectFace, PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots'
|
||||
// Type-only: pulls the ui-conversation SlotMap merge (the input.plan seat and
|
||||
// its {locked} owner share).
|
||||
import type {} from '@deepseek-ai/dsh-client-ui-conversation/client'
|
||||
import type { PlanChipInjected } from './index.ts'
|
||||
import css from './PlanModeControl.module.css'
|
||||
|
||||
/** Full plan-seat component props: runtime share (standard kit + locked owner prop) & injected share. */
|
||||
/** Full plan-seat component props: runtime share (standard kit + locked owner prop) & injected share & the locale seat. */
|
||||
export type PlanChipProps =
|
||||
PropsRuntime<'conversation.input.plan'> & InjectFace<PlanChipInjected>
|
||||
PropsRuntime<'conversation.input.plan'> & InjectFace<PlanChipInjected> & PropsLocale<'plan'>
|
||||
|
||||
/**
|
||||
* Plan-mode toggle over the host-computed `plan` projection. The chip renders
|
||||
@@ -17,7 +17,7 @@ export type PlanChipProps =
|
||||
* client optimism, so an arriving frame corrects it). Clicking executes
|
||||
* /plan or /plan off toward the opposite target.
|
||||
*/
|
||||
export function PlanChip({ useProjection, locked, setPlanMode }: PlanChipProps) {
|
||||
export function PlanChip({ useProjection, locked, setPlanMode, t }: PlanChipProps) {
|
||||
const plan = useProjection('plan')
|
||||
const [busy, setBusy] = useState(false)
|
||||
const [error, setError] = useState<{ text: string; detail: string } | null>(null)
|
||||
@@ -37,8 +37,9 @@ export function PlanChip({ useProjection, locked, setPlanMode }: PlanChipProps)
|
||||
|
||||
const toggle = (): void => {
|
||||
// No busy/locked guard: both disable the button, so no click arrives.
|
||||
// Failure copy stays English (error-surface policy: not localized).
|
||||
const on = !target
|
||||
const failText = on ? '进入 plan mode 失败' : '退出 plan mode 失败'
|
||||
const failText = on ? 'failed to enter plan mode' : 'failed to exit plan mode'
|
||||
setBusy(true)
|
||||
setError(null)
|
||||
void setPlanMode(on).then((failure) => {
|
||||
@@ -58,13 +59,12 @@ export function PlanChip({ useProjection, locked, setPlanMode }: PlanChipProps)
|
||||
type="button"
|
||||
className={css.chip}
|
||||
aria-pressed={target}
|
||||
aria-label={target ? 'Plan mode on, press to turn off' : 'Plan mode off, press to turn on'}
|
||||
title={target
|
||||
? 'Plan mode on — click to turn off (/plan off)'
|
||||
: 'Plan mode off — click to turn on (/plan)'}
|
||||
aria-label={target ? t('chip.on.aria') : t('chip.off.aria')}
|
||||
title={target ? t('chip.on.title') : t('chip.off.title')}
|
||||
disabled={locked || busy}
|
||||
onClick={toggle}
|
||||
>
|
||||
{/* Design literal, not copy: the chip wordmark stays 'Plan on/off' in every locale. */}
|
||||
Plan { target ? 'on' : 'off' }
|
||||
</button>
|
||||
{error !== null && <span className={css.error} role="status" title={error.detail}>{error.text}</span>}
|
||||
|
||||
@@ -11,9 +11,24 @@ import type { ConnectionHandle } from '@deepseek-ai/dsh-client-connection/client
|
||||
import type { ClientContext, SessionId } from '@deepseek-ai/dsh-client-runtime/client'
|
||||
// Type-only: pulls the ui-conversation SlotMap merge (the input.plan seat).
|
||||
import type {} from '@deepseek-ai/dsh-client-ui-conversation/client'
|
||||
// Type-only: pulls the locale plugin's Context merge (ctx.locale).
|
||||
import type {} from '@deepseek-ai/dsh-client-locale/client'
|
||||
// Type-only: pulls the `plan` SessionProjectionMap merge for useProjection.
|
||||
import type {} from '@deepseek-ai/dsh-plan-mode/client'
|
||||
import { PlanChip } from './PlanModeControl.tsx'
|
||||
import { en, zh, type PlanKey } from './locales.ts'
|
||||
|
||||
export type { PlanKey } from './locales.ts'
|
||||
|
||||
declare module '@deepseek-ai/dsh-client-ui-slots' {
|
||||
interface LocaleNamespaceMap {
|
||||
/** The composer plan chip's copy. */
|
||||
plan: PlanKey
|
||||
}
|
||||
}
|
||||
|
||||
/** Dictionary namespace owned by this plugin. */
|
||||
const NS = 'plan'
|
||||
|
||||
/** Injected business face of the composer plan seat. */
|
||||
export interface PlanChipInjected {
|
||||
@@ -26,25 +41,30 @@ export interface PlanChipInjected {
|
||||
}
|
||||
|
||||
/**
|
||||
* Required services: the seat's slot registry, the transport, and the
|
||||
* conversation service whose presence guarantees the seat is declared.
|
||||
* Required services: the seat's slot registry, the transport, the copy's
|
||||
* locale registry, and the conversation service whose presence guarantees
|
||||
* the seat is declared.
|
||||
*/
|
||||
export const inject = ['slots', 'connection', 'conversation']
|
||||
export const inject = ['slots', 'connection', 'conversation', 'locale']
|
||||
|
||||
/**
|
||||
* Client plugin body: register the plan chip over the command channel.
|
||||
* @param ctx - client root context.
|
||||
*/
|
||||
export function apply(ctx: ClientContext): void {
|
||||
ctx.effect(() => ctx.locale.register(NS, { zh, en }), 'ui-plan: dictionaries')
|
||||
|
||||
ctx.effect(() => ctx.slots.register({
|
||||
name: 'conversation.input.plan',
|
||||
locale: NS,
|
||||
inject: (sessionId: SessionId): PlanChipInjected => ({
|
||||
// Failure strings stay English (error-surface policy: not localized).
|
||||
setPlanMode: async (on) => {
|
||||
const line = on ? '/plan' : '/plan off'
|
||||
const connection = ctx.get('connection') as ConnectionHandle
|
||||
const { result } = await connection.api.commands.execute({ sessionId, line })
|
||||
if (!result.ok) return `${result.error.message}(${result.error.code})`
|
||||
if (!result.value.matched) return `未知命令:${line}`
|
||||
if (!result.ok) return `${result.error.message} (${result.error.code})`
|
||||
if (!result.value.matched) return `unknown command: ${line}`
|
||||
return null
|
||||
},
|
||||
}),
|
||||
|
||||
20
packages/client/ui-plan/src/client/locales.ts
Normal file
20
packages/client/ui-plan/src/client/locales.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
/** `plan` namespace dictionaries (the composer plan chip's copy). */
|
||||
|
||||
/** Simplified Chinese dictionary (the key-set source of truth). */
|
||||
export const zh = {
|
||||
'chip.on.aria': 'plan mode 已开启,按下关闭',
|
||||
'chip.on.title': 'plan mode 已开启 — 点击关闭(/plan off)',
|
||||
'chip.off.aria': 'plan mode 已关闭,按下开启',
|
||||
'chip.off.title': 'plan mode 已关闭 — 点击开启(/plan)',
|
||||
} satisfies Record<string, string>
|
||||
|
||||
/** The plan namespace key union. */
|
||||
export type PlanKey = keyof typeof zh
|
||||
|
||||
/** English dictionary, checked complete against the zh key set. */
|
||||
export const en = {
|
||||
'chip.on.aria': 'Plan mode on, press to turn off',
|
||||
'chip.on.title': 'Plan mode on — click to turn off (/plan off)',
|
||||
'chip.off.aria': 'Plan mode off, press to turn on',
|
||||
'chip.off.title': 'Plan mode off — click to turn on (/plan)',
|
||||
} satisfies Record<PlanKey, string>
|
||||
Reference in New Issue
Block a user