* refactor: 将 convertMessagesToLangfuse 参数类型从 unknown 收窄为联合类型 将 readonly unknown[] 改为 readonly LangfuseInputMessage[], 其中 LangfuseInputMessage = UserMessage | AssistantMessage | ChatCompletionMessageParam, 让调用方获得编译期类型检查。 * fix: 修复 Config 面板第二次进入时左右键无反应的问题 将左右键枚举值切换从依赖 DOM 焦点的 onKeyDown 改为 useKeybindings 系统, 确保按键在任何焦点状态下都能正确响应。同时修复 isSearchMode 初始值和布局问题。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * fix: 修复 PowerShellTool.isSearchOrReadCommand 在 input 为 undefined 时崩溃的问题 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * feat: 添加 RSS 内存指示器并解绑 auto 权限模式与 TRANSCRIPT_CLASSIFIER - 在 REPL 底栏添加 RSS 内存使用显示,512MB 以下 dimColor,512MB-1GB warning 色,1GB 以上 error 色 - auto 权限模式不再依赖 TRANSCRIPT_CLASSIFIER feature flag,classifier 不可用时 fallback 到 prompting - Config 面板 defaultPermissionMode 使用类型安全的 permissionModeFromString,显示改用 shortTitle - bypassPermissions title 缩短为 Bypass 与 shortTitle 一致 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * fix: 同步 permissionModeTitle 测试断言与 bypassPermissions 的新 title 值 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
138 lines
3.3 KiB
TypeScript
138 lines
3.3 KiB
TypeScript
import { feature } from 'bun:bundle'
|
|
import z from 'zod/v4'
|
|
import { PAUSE_ICON } from '../../constants/figures.js'
|
|
// Types extracted to src/types/permissions.ts to break import cycles
|
|
import {
|
|
EXTERNAL_PERMISSION_MODES,
|
|
type ExternalPermissionMode,
|
|
PERMISSION_MODES,
|
|
type PermissionMode,
|
|
} from '../../types/permissions.js'
|
|
import { lazySchema } from '../lazySchema.js'
|
|
|
|
// Re-export for backwards compatibility
|
|
export {
|
|
EXTERNAL_PERMISSION_MODES,
|
|
PERMISSION_MODES,
|
|
type ExternalPermissionMode,
|
|
type PermissionMode,
|
|
}
|
|
|
|
export const permissionModeSchema = lazySchema(() => z.enum(PERMISSION_MODES))
|
|
export const externalPermissionModeSchema = lazySchema(() =>
|
|
z.enum(EXTERNAL_PERMISSION_MODES),
|
|
)
|
|
|
|
type ModeColorKey =
|
|
| 'text'
|
|
| 'planMode'
|
|
| 'permission'
|
|
| 'autoAccept'
|
|
| 'error'
|
|
| 'warning'
|
|
|
|
type PermissionModeConfig = {
|
|
title: string
|
|
shortTitle: string
|
|
symbol: string
|
|
color: ModeColorKey
|
|
external: ExternalPermissionMode
|
|
}
|
|
|
|
const PERMISSION_MODE_CONFIG: Partial<
|
|
Record<PermissionMode, PermissionModeConfig>
|
|
> = {
|
|
default: {
|
|
title: 'Default',
|
|
shortTitle: 'Default',
|
|
symbol: '',
|
|
color: 'text',
|
|
external: 'default',
|
|
},
|
|
plan: {
|
|
title: 'Plan Mode',
|
|
shortTitle: 'Plan',
|
|
symbol: PAUSE_ICON,
|
|
color: 'planMode',
|
|
external: 'plan',
|
|
},
|
|
acceptEdits: {
|
|
title: 'Accept edits',
|
|
shortTitle: 'Accept',
|
|
symbol: '⏵⏵',
|
|
color: 'autoAccept',
|
|
external: 'acceptEdits',
|
|
},
|
|
bypassPermissions: {
|
|
title: 'Bypass',
|
|
shortTitle: 'Bypass',
|
|
symbol: '⏵⏵',
|
|
color: 'error',
|
|
external: 'bypassPermissions',
|
|
},
|
|
dontAsk: {
|
|
title: "Don't Ask",
|
|
shortTitle: 'DontAsk',
|
|
symbol: '⏵⏵',
|
|
color: 'error',
|
|
external: 'dontAsk',
|
|
},
|
|
auto: {
|
|
title: 'Auto',
|
|
shortTitle: 'Auto',
|
|
symbol: '⏵⏵',
|
|
color: 'warning' as ModeColorKey,
|
|
external: 'default' as ExternalPermissionMode,
|
|
},
|
|
}
|
|
|
|
/**
|
|
* Type guard to check if a PermissionMode is an ExternalPermissionMode.
|
|
* auto is ant-only and excluded from external modes.
|
|
*/
|
|
export function isExternalPermissionMode(
|
|
mode: PermissionMode,
|
|
): mode is ExternalPermissionMode {
|
|
// External users can't have auto, so always true for them
|
|
if (process.env.USER_TYPE !== 'ant') {
|
|
return true
|
|
}
|
|
return mode !== 'auto' && mode !== 'bubble'
|
|
}
|
|
|
|
function getModeConfig(mode: PermissionMode): PermissionModeConfig {
|
|
return PERMISSION_MODE_CONFIG[mode] ?? PERMISSION_MODE_CONFIG.default!
|
|
}
|
|
|
|
export function toExternalPermissionMode(
|
|
mode: PermissionMode,
|
|
): ExternalPermissionMode {
|
|
return getModeConfig(mode).external
|
|
}
|
|
|
|
export function permissionModeFromString(str: string): PermissionMode {
|
|
return (PERMISSION_MODES as readonly string[]).includes(str)
|
|
? (str as PermissionMode)
|
|
: 'default'
|
|
}
|
|
|
|
export function permissionModeTitle(mode: PermissionMode): string {
|
|
return getModeConfig(mode).title
|
|
}
|
|
|
|
export function isDefaultMode(mode: PermissionMode | undefined): boolean {
|
|
return mode === 'default' || mode === undefined
|
|
}
|
|
|
|
export function permissionModeShortTitle(mode: PermissionMode): string {
|
|
return getModeConfig(mode).shortTitle
|
|
}
|
|
|
|
export function permissionModeSymbol(mode: PermissionMode): string {
|
|
return getModeConfig(mode).symbol
|
|
}
|
|
|
|
export function getModeColor(mode: PermissionMode): ModeColorKey {
|
|
return getModeConfig(mode).color
|
|
}
|