mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-16 03:50:52 +00:00
Phase 2 of #4098: every remaining positional fallback in the workspace AI scope is replaced with id-based resolution. - Workspace gains anchorChatId: pinned by the AI side panel whenever a chat becomes active in the workspace scope, persisted through the session restore snapshot, and validated lazily by consumers. - resolveDisplayedPanelView: the auto-resume fallback now resolves the anchored chat first, then the most recently updated chat (updatedAt), else draft; sessions[0] is gone. - retargetWorkspaceActiveChatAfterMemberLoss: when the focused member did not survive, the retarget lands on the most-recently-active survivor by chat recency, not the first positional member. - plugin keybinding context: focused member, then the terminal member owning the anchored chat, then the most-recently-active member; a single-member workspace uses its only member. - New domain/aiSessionRecency helper shared by all survivor rankings. - /rebind and session_recover semantics (#4019) are unchanged.
158 lines
6.1 KiB
TypeScript
158 lines
6.1 KiB
TypeScript
import type {
|
|
AIDraft,
|
|
AIPanelView,
|
|
AIPermissionMode,
|
|
AIToolIntegrationMode,
|
|
AISession,
|
|
AISessionScope,
|
|
ChatMessage,
|
|
ExternalAgentConfig,
|
|
ProviderConfig,
|
|
WebSearchConfig,
|
|
} from '../infrastructure/ai/types';
|
|
import type { AIQuickMessage } from '../infrastructure/ai/quickMessages';
|
|
import type { ExecutorContext } from '../infrastructure/ai/cattyAgent/executor';
|
|
import type { Host, Snippet, VaultNote } from '../types';
|
|
|
|
// -------------------------------------------------------------------
|
|
// Props
|
|
// -------------------------------------------------------------------
|
|
|
|
export interface AIChatSidePanelProps {
|
|
// Session state (per-scope)
|
|
sessions: AISession[];
|
|
activeSessionIdMap: Record<string, string | null>;
|
|
draftsByScope: Partial<Record<string, AIDraft>>;
|
|
panelViewByScope: Partial<Record<string, AIPanelView>>;
|
|
setActiveSessionId: (scopeKey: string, id: string | null) => void;
|
|
ensureDraftForScope: (scopeKey: string, agentId: string) => void;
|
|
updateDraft: (
|
|
scopeKey: string,
|
|
fallbackAgentId: string,
|
|
updater: (draft: AIDraft) => AIDraft,
|
|
) => void;
|
|
showDraftView: (scopeKey: string) => void;
|
|
showSessionView: (scopeKey: string, sessionId: string) => void;
|
|
clearDraftForScope: (scopeKey: string) => void;
|
|
addDraftFiles: (scopeKey: string, fallbackAgentId: string, inputFiles: File[]) => Promise<void>;
|
|
removeDraftFile: (scopeKey: string, fallbackAgentId: string, fileId: string) => void;
|
|
createSession: (scope: AISessionScope, agentId?: string) => AISession;
|
|
/** Non-destructively branch before the last user turn; returns the branch id + restored composer content. */
|
|
undoLastTurnInSession?: (
|
|
sessionId: string,
|
|
viewingScope?: Pick<AISessionScope, 'type' | 'targetId'>,
|
|
) => Promise<{ sessionId: string; restored: { text: string; attachments: import('../infrastructure/ai/types').UploadedFile[]; selectedUserSkillSlugs: string[] } } | null>;
|
|
deleteSession: (sessionId: string, scopeKey?: string) => void;
|
|
updateSessionTitle: (sessionId: string, title: string) => void;
|
|
/** Issue #4015 R2: rebind a dangling chat to this panel's scope (panel action, never agent content). */
|
|
rebindSessionScope?: (sessionId: string, scope: { type: 'terminal' | 'workspace'; targetId: string; hostIds?: string[] }) => void;
|
|
/** Manual durability escape hatch: export the store to a JSON file (returns the path, '' when fixed-path). */
|
|
exportSessionsBackup?: () => Promise<string | null>;
|
|
/** Import sessions from a JSON export; merges by id. Returns the imported count. */
|
|
importSessionsBackup?: () => Promise<number>;
|
|
updateSessionExternalSessionId: (sessionId: string, externalSessionId: string | undefined) => void;
|
|
addMessageToSession: (sessionId: string, message: ChatMessage) => void;
|
|
updateLastMessage: (
|
|
sessionId: string,
|
|
updater: (msg: ChatMessage) => ChatMessage,
|
|
) => void;
|
|
updateMessageById: (
|
|
sessionId: string,
|
|
messageId: string,
|
|
updater: (msg: ChatMessage) => ChatMessage,
|
|
) => void;
|
|
persistContextCompaction: (
|
|
sessionId: string,
|
|
compaction: import('../infrastructure/ai/types').AISessionContextCompaction,
|
|
) => void;
|
|
forkSessionFromMessage?: (
|
|
sessionId: string,
|
|
messageId: string,
|
|
viewingScope?: Pick<AISessionScope, 'type' | 'targetId'>,
|
|
) => Promise<AISession | null>;
|
|
// Provider config
|
|
providers: ProviderConfig[];
|
|
activeProviderId: string;
|
|
activeModelId: string;
|
|
|
|
// Agent info
|
|
defaultAgentId: string;
|
|
toolIntegrationMode: AIToolIntegrationMode;
|
|
externalAgents: ExternalAgentConfig[];
|
|
setExternalAgents?: (value: ExternalAgentConfig[] | ((prev: ExternalAgentConfig[]) => ExternalAgentConfig[])) => void;
|
|
agentModelMap: Record<string, string>;
|
|
setAgentModel: (agentId: string, modelId: string) => void;
|
|
agentProviderMap: Record<string, string>;
|
|
setAgentProvider: (agentId: string, providerId: string) => void;
|
|
agentThinkingMap: Record<string, string>;
|
|
setAgentThinking: (agentId: string, thinkingLevel: string) => void;
|
|
updateProvider?: (id: string, updates: Partial<ProviderConfig>) => void;
|
|
|
|
// Safety
|
|
globalPermissionMode: AIPermissionMode;
|
|
setGlobalPermissionMode?: (mode: AIPermissionMode) => void;
|
|
commandBlocklist?: string[];
|
|
commandTimeout?: number;
|
|
responseIdleTimeout?: number;
|
|
maxIterations?: number;
|
|
|
|
// Web search
|
|
webSearchConfig?: WebSearchConfig | null;
|
|
|
|
// Quick messages (slash prompts)
|
|
quickMessages?: AIQuickMessage[];
|
|
|
|
// Context
|
|
scopeType: 'terminal' | 'workspace';
|
|
scopeTargetId?: string;
|
|
scopeHostIds?: string[];
|
|
scopeLabel?: string;
|
|
/** Workspace focused pane; preferred when inheriting AI chat after merge. */
|
|
focusedSessionId?: string;
|
|
/** Issue #4098 phase 2: pin the AI chat a workspace scope is anchored to. */
|
|
onSetWorkspaceAnchorChat?: (workspaceId: string, chatId: string | null) => void;
|
|
/** Live workspaces (with their anchor chat), used for scope titles and anchor resolution. */
|
|
workspaces?: Array<{ id: string; title: string; anchorChatId?: string }>;
|
|
/** All currently live terminal (and workspace) scope target ids. */
|
|
liveScopeTargetIds?: Set<string>;
|
|
|
|
// Terminal session context (from parent)
|
|
terminalSessions?: Array<{
|
|
sessionId: string;
|
|
hostId: string;
|
|
hostname: string;
|
|
label: string;
|
|
os?: string;
|
|
username?: string;
|
|
protocol?: string;
|
|
shellType?: string;
|
|
deviceType?: string;
|
|
connected: boolean;
|
|
}>;
|
|
resolveExecutorContext?: (scope: {
|
|
type: 'terminal' | 'workspace';
|
|
targetId?: string;
|
|
label?: string;
|
|
}) => ExecutorContext;
|
|
|
|
// Visibility
|
|
isVisible?: boolean;
|
|
|
|
// Vault artifact navigation (from AI chat tool results)
|
|
notes?: VaultNote[];
|
|
hosts?: Host[];
|
|
snippets?: Snippet[];
|
|
onOpenVaultNote?: (noteId: string) => void;
|
|
onOpenVaultHost?: (hostId: string) => void;
|
|
onOpenVaultSnippet?: (snippetId: string) => void;
|
|
onOpenVaultSection?: (section: 'notes' | 'hosts' | 'snippets') => void;
|
|
}
|
|
|
|
// -------------------------------------------------------------------
|
|
// Helpers
|
|
// -------------------------------------------------------------------
|
|
|
|
// -------------------------------------------------------------------
|
|
// Component
|
|
// -------------------------------------------------------------------
|