mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-16 20:11:08 +00:00
* chore: 移除死代码并修复架构分层违规 - 删除未使用的 ACP 模块 (infrastructure/ai/acp/) - 删除未使用的 AI 组件 (ExecutionPlan, PermissionDialog) - 将 syncPayload.ts 从 domain 移至 application 层,修复分层违规 - 移除未使用的导出 (useSecurityState, useProviderStatus, GitHubAuthState, getAgentCommandLabel, ImageAttachment, HotkeyActions) - 收窄 Electron bridge module.exports,移除未使用的导出函数 - 将仅内部使用的函数/类型取消导出 (isSupportedLocale, SyncDashboard) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * chore: 二次审查清理 — 移除更多死代码和架构违规 - 移除未使用的 ConversationEmptyState 组件和类型 - 移除未使用的 PromptInputSelect 系列组件 (5 个导出) - 移除 global.d.ts 中残留的 SMBConfig 类型和 cloudSyncSmb* 方法声明 - 移除 useAutoSync.ts 中未使用的 toast 导入 (同时修复 application→components 反向依赖) - 清理因删除而产生的多余 import Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * chore: 消除直接 localStorage 访问,提取 safeSend 共享工具 localStorage 集中化: - 新增 storageKeys 常量: SIDE_PANEL_WIDTH, PF_RECONNECT_CANCEL, DEBUG_HOTKEYS, DEBUG_UPDATE_DEMO - TerminalLayer/SettingsApplicationTab/App.tsx/useUpdateCheck 改用 localStorageAdapter - CloudSyncManager 内部方法改用 localStorageAdapter - portForwardingService 改用 localStorageAdapter + 集中 key safeSend 去重: - 新增 electron/bridges/ipcUtils.cjs 共享模块 - sshBridge/sftpBridge/portForwardingBridge/sshAuthHelper/aiBridge 统一引用 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * chore: 终审清理 — 移除未使用的 require 和废弃类型别名 - 移除 sftpBridge.cjs 中未使用的 require("node:net") - 移除 aiBridge.cjs 中未使用的 require("node:path") - 移除 types.ts 中已废弃的 ChatMessageImage 类型别名 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: 修复 ESLint 错误 — 组件不再直接导入 infrastructure - 新增 useStoredNumber hook,TerminalLayer 通过 hook 访问侧边栏宽度 - SettingsApplicationTab 的 isUpdateDemoMode 改为从 useUpdateCheck hook 传入 - 移除 useCloudSync.ts 中未使用的 CloudSyncManager 导入和 GitHubAuthState 接口 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * chore: 提取 notification port,消除 application 层对 components 的依赖 将 toast 通知抽象为 application/notification.ts 端口, UI 层通过 setNotify 注入实现,useAutoSync 改用 notify 接口。 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
248 lines
7.7 KiB
TypeScript
248 lines
7.7 KiB
TypeScript
/**
|
|
* PromptInput - Adapted from Vercel AI Elements prompt-input for netcatty.
|
|
*
|
|
* Simplified: no file attachments, screenshots, drag-drop, command palette,
|
|
* hover cards, referenced sources, or tabs. Core input + footer + submit.
|
|
*/
|
|
|
|
import { ArrowUp, Square, X } from 'lucide-react';
|
|
import type {
|
|
ComponentProps,
|
|
FormEvent,
|
|
HTMLAttributes,
|
|
KeyboardEvent,
|
|
ReactNode,
|
|
} from 'react';
|
|
import { forwardRef, useCallback, useRef } from 'react';
|
|
import { cn } from '../../lib/utils';
|
|
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '../ui/tooltip';
|
|
import {
|
|
InputGroup,
|
|
InputGroupAddon,
|
|
InputGroupButton,
|
|
InputGroupTextarea,
|
|
} from '../ui/input-group';
|
|
import { Spinner } from '../ui/spinner';
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// PromptInput (form wrapper)
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export interface PromptInputProps extends HTMLAttributes<HTMLFormElement> {
|
|
onSubmit: (text: string, event: FormEvent<HTMLFormElement>) => void | Promise<void>;
|
|
}
|
|
|
|
export const PromptInput = forwardRef<HTMLFormElement, PromptInputProps>(
|
|
({ className, onSubmit, children, ...props }, ref) => {
|
|
const handleSubmit = useCallback(
|
|
(e: FormEvent<HTMLFormElement>) => {
|
|
e.preventDefault();
|
|
const form = e.currentTarget;
|
|
const textarea = form.querySelector('textarea');
|
|
const text = textarea?.value?.trim() ?? '';
|
|
if (!text) return;
|
|
onSubmit(text, e);
|
|
},
|
|
[onSubmit],
|
|
);
|
|
|
|
return (
|
|
<form ref={ref} onSubmit={handleSubmit} className={className} {...props}>
|
|
<InputGroup>{children}</InputGroup>
|
|
</form>
|
|
);
|
|
},
|
|
);
|
|
PromptInput.displayName = 'PromptInput';
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// PromptInputTextarea
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export interface PromptInputTextareaProps extends ComponentProps<'textarea'> {
|
|
/** Called when Enter is pressed (without Shift) to trigger form submit */
|
|
onSubmitRequest?: () => void;
|
|
}
|
|
|
|
export const PromptInputTextarea = forwardRef<HTMLTextAreaElement, PromptInputTextareaProps>(
|
|
({ className, onSubmitRequest, onKeyDown, ...props }, ref) => {
|
|
const internalRef = useRef<HTMLTextAreaElement | null>(null);
|
|
|
|
const setRef = useCallback(
|
|
(node: HTMLTextAreaElement | null) => {
|
|
internalRef.current = node;
|
|
if (typeof ref === 'function') ref(node);
|
|
else if (ref) ref.current = node;
|
|
},
|
|
[ref],
|
|
);
|
|
|
|
const handleKeyDown = useCallback(
|
|
(e: KeyboardEvent<HTMLTextAreaElement>) => {
|
|
onKeyDown?.(e);
|
|
if (e.defaultPrevented) return;
|
|
|
|
// CJK composition guard
|
|
if (e.nativeEvent.isComposing) return;
|
|
|
|
if (e.key === 'Enter' && !e.shiftKey) {
|
|
e.preventDefault();
|
|
onSubmitRequest?.();
|
|
// Trigger form submit
|
|
const form = internalRef.current?.closest('form');
|
|
if (form) {
|
|
form.requestSubmit();
|
|
}
|
|
}
|
|
},
|
|
[onKeyDown, onSubmitRequest],
|
|
);
|
|
|
|
return (
|
|
<InputGroupTextarea
|
|
ref={setRef}
|
|
className={className}
|
|
onKeyDown={handleKeyDown}
|
|
{...props}
|
|
/>
|
|
);
|
|
},
|
|
);
|
|
PromptInputTextarea.displayName = 'PromptInputTextarea';
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// PromptInputFooter
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export type PromptInputFooterProps = HTMLAttributes<HTMLDivElement>;
|
|
|
|
export const PromptInputFooter = forwardRef<HTMLDivElement, PromptInputFooterProps>(
|
|
({ className, ...props }, ref) => (
|
|
<InputGroupAddon
|
|
ref={ref}
|
|
align="block-end"
|
|
className={cn('gap-1', className)}
|
|
{...props}
|
|
/>
|
|
),
|
|
);
|
|
PromptInputFooter.displayName = 'PromptInputFooter';
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// PromptInputTools (left side of footer)
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export type PromptInputToolsProps = HTMLAttributes<HTMLDivElement>;
|
|
|
|
export const PromptInputTools = forwardRef<HTMLDivElement, PromptInputToolsProps>(
|
|
({ className, ...props }, ref) => (
|
|
<div
|
|
ref={ref}
|
|
className={cn('flex items-center gap-0.5', className)}
|
|
{...props}
|
|
/>
|
|
),
|
|
);
|
|
PromptInputTools.displayName = 'PromptInputTools';
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// PromptInputButton (toolbar button with optional tooltip)
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export interface PromptInputButtonProps extends ComponentProps<typeof InputGroupButton> {
|
|
tooltip?: ReactNode;
|
|
tooltipSide?: 'top' | 'bottom' | 'left' | 'right';
|
|
}
|
|
|
|
export const PromptInputButton = forwardRef<HTMLButtonElement, PromptInputButtonProps>(
|
|
({ tooltip, tooltipSide = 'top', ...props }, ref) => {
|
|
const button = <InputGroupButton ref={ref} {...props} />;
|
|
|
|
if (!tooltip) return button;
|
|
|
|
return (
|
|
<TooltipProvider>
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>{button}</TooltipTrigger>
|
|
<TooltipContent side={tooltipSide}>{tooltip}</TooltipContent>
|
|
</Tooltip>
|
|
</TooltipProvider>
|
|
);
|
|
},
|
|
);
|
|
PromptInputButton.displayName = 'PromptInputButton';
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// PromptInputSubmit
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export type PromptInputStatus = 'idle' | 'submitted' | 'streaming' | 'error';
|
|
|
|
export interface PromptInputSubmitProps extends ComponentProps<typeof InputGroupButton> {
|
|
status?: PromptInputStatus;
|
|
onStop?: () => void;
|
|
}
|
|
|
|
export const PromptInputSubmit = forwardRef<HTMLButtonElement, PromptInputSubmitProps>(
|
|
({ status = 'idle', onStop, className, disabled, ...props }, ref) => {
|
|
const isRunning = status === 'submitted' || status === 'streaming';
|
|
|
|
const handleClick = useCallback(() => {
|
|
if (isRunning && onStop) {
|
|
onStop();
|
|
}
|
|
}, [isRunning, onStop]);
|
|
|
|
const icon =
|
|
status === 'submitted' ? (
|
|
<Spinner size={14} />
|
|
) : status === 'streaming' ? (
|
|
<Square size={14} />
|
|
) : status === 'error' ? (
|
|
<X size={14} />
|
|
) : (
|
|
<ArrowUp size={14} />
|
|
);
|
|
|
|
const tooltipLabel =
|
|
status === 'submitted'
|
|
? 'Waiting...'
|
|
: status === 'streaming'
|
|
? 'Stop'
|
|
: status === 'error'
|
|
? 'Error'
|
|
: 'Send';
|
|
|
|
return (
|
|
<TooltipProvider>
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<InputGroupButton
|
|
ref={ref}
|
|
type={isRunning ? 'button' : 'submit'}
|
|
onClick={isRunning ? handleClick : undefined}
|
|
variant="ghost"
|
|
disabled={disabled && !isRunning}
|
|
className={cn(
|
|
'h-8 w-8 rounded-full border p-0 shadow-sm disabled:opacity-100',
|
|
isRunning
|
|
? 'border-destructive/60 bg-destructive/85 text-destructive-foreground hover:bg-destructive'
|
|
: disabled
|
|
? 'border-border/80 bg-muted/52 text-foreground/72 hover:bg-muted/52'
|
|
: 'border-foreground/20 bg-foreground text-background hover:bg-foreground/90',
|
|
className,
|
|
)}
|
|
{...props}
|
|
>
|
|
{icon}
|
|
</InputGroupButton>
|
|
</TooltipTrigger>
|
|
<TooltipContent side="top">{tooltipLabel}</TooltipContent>
|
|
</Tooltip>
|
|
</TooltipProvider>
|
|
);
|
|
},
|
|
);
|
|
PromptInputSubmit.displayName = 'PromptInputSubmit';
|
|
|