import { Editor, Range } from '@tiptap/core'; import { AgentContextMentionProvider } from './context-mention-provider.js'; import { MentionPaletteGroup, MentionPaletteState } from '@tutti-os/ui-rich-text/at-panel'; type RuntimeDiagnosticsDetailValue = string | number | boolean | null; type AgentFileMentionKind = "file" | "directory" | "unknown"; type AgentMentionFileNavigationAction = "agent-generated-folder" | "agent-generated-folder-back" | "workspace-folder" | "workspace-folder-back"; type AgentMentionScope = "my_sessions" | "collab_sessions"; type AgentMentionReferenceSource = "app" | "task"; interface AgentMentionFileItem { kind: "file"; path: string; href: string; name: string; entryKind: AgentFileMentionKind; directoryPath: string; /** Present only for a regular file attached from the local composer. */ attachmentId?: string; attachmentStatus?: AgentComposerFileMentionStatus; attachmentErrorCode?: string; score?: number; thumbnailUrl?: string | null; mentionNavigation?: AgentMentionFileNavigationAction; childCount?: number; /** Ephemeral picker-only relative path and owning-workspace presentation. */ contextLabel?: string; } type AgentComposerFileMentionStatus = "uploading" | "ready" | "error"; interface AgentMentionSessionItem { kind: "session"; href: string; workspaceId: string; targetId: string; agentTargetId?: string; name: string; title: string; scope: AgentMentionScope; initiatorUserId?: string; initiatorName: string; initiatorAvatarUrl?: string; agentName: string; /** Structured owner segment from the matching provenance Agent option. */ agentOwnerLabel?: string; /** Structured Agent segment from the matching provenance Agent option. */ agentLabel?: string; agentIconUrl?: string; status?: string; inputPreview?: string; summaryPreview?: string; updatedAtUnixMs?: number; } interface AgentMentionWorkspaceIssueItem { kind: "workspace-issue"; href: string; workspaceId: string; targetId: string; topicId?: string; name: string; title: string; creatorName?: string; iconUrl?: string; status?: string; contentPreview?: string; updatedAtUnixMs?: number; } interface AgentMentionWorkspaceAppItem { kind: "workspace-app"; href: string; workspaceId: string; targetId: string; appId: string; name: string; description?: string; iconUrl?: string; /** 应用是否能够提供产物文件(reference),决定 @ 面板行末尾是否展示「查看产物」入口。 */ referencesListSupported?: boolean; } interface AgentMentionAgentTargetItem { kind: "agent-target"; href: string; workspaceId: string; targetId: string; name: string; description?: string; agentProviderId?: string; iconUrl?: string; availabilityStatus?: string; } interface AgentMentionWorkspaceReferenceItem { kind: "workspace-reference"; href: string; workspaceId: string; /** URI path id:source=app 时为 appId,source=task 时为 topicId。 */ targetId: string; source: AgentMentionReferenceSource; /** 子级 id:app 子分组 / issueId。缺省表示整个 app / topic。 */ groupId?: string; name: string; iconUrl?: string; /** 展示用文件数(来自 picker 节点 childCount);序列化不再展开文件。 */ fileCount: number; } interface AgentMentionWorkspaceAppFactoryItem { kind: "workspace-app-factory"; href: string; workspaceId: string; targetId: string; jobId: string; name: string; action?: string; contextPath?: string; } interface AgentMentionCustomItem { kind: "custom"; /** 注册表里的 kind(= mention:// providerId)。 */ customKind: string; href: string; workspaceId: string; targetId: string; /** Canonical Markdown label, kept separate from the host's chip presentation. */ sourceLabel: string; /** chip 第一行。 */ name: string; /** chip 第二行(通用双行卡)。 */ summary?: string; } type AgentContextMentionItem = AgentMentionFileItem | AgentMentionAgentTargetItem | AgentMentionSessionItem | AgentMentionWorkspaceAppItem | AgentMentionWorkspaceReferenceItem | AgentMentionWorkspaceAppFactoryItem | AgentMentionWorkspaceIssueItem | AgentMentionCustomItem; interface AgentMentionSuggestionState { editor: Editor; range: Range; query: string; text: string; command: (item: AgentContextMentionItem) => void; clientRect?: (() => DOMRect | null) | null; } type AgentFileMentionSuggestionState = AgentMentionSuggestionState; type AgentMentionProviderDiagnosticStatus = "success" | "timeout" | "error" | "missing"; interface AgentMentionProviderQueryDiagnostic { durationMs: number; errorKind?: string; providerId: string; resultCount: number; status: AgentMentionProviderDiagnosticStatus; } interface AgentMentionSearchDiagnosticLog { debounceMs: number; durationMs: number; errorKind?: string; event: "agent_gui.mention_search"; filter: AgentMentionFilterId; groupCount: number; itemCount: number; mode: "browse" | "results"; providerResults: AgentMentionProviderQueryDiagnostic[]; providerTimeoutMs: number; queryLength: number; requestId: number; status: "ready" | "error"; workspaceId: string; } type AgentMentionFilterId = "session" | "file" | "issue" | "agent" | "app"; type AgentMentionStaticGroupId = "apps" | "agents" | "files" | "opened_files" | "agent_generated_files" | "my_sessions" | "collab_sessions" | "issues"; type AgentMentionIssueTopicGroupId = `issue-topic:${string}`; type AgentMentionProvenanceGroupId = `agent:${string}`; type AgentMentionMemberGroupId = `member:${string}`; type AgentMentionGroupId = AgentMentionStaticGroupId | AgentMentionIssueTopicGroupId | AgentMentionProvenanceGroupId | AgentMentionMemberGroupId; type AgentMentionRawGroupId = Exclude | "sessions"; type AgentMentionRawGroups = Record; type AgentMentionTotalCounts = Partial>; interface AgentMentionIssueTopicGroup { id: `issue-topic:${string}`; providerGroupId: string; label: string; items: AgentContextMentionItem[]; totalCount: number; nextPageToken: string | null; loadMoreStatus: "idle" | "loading" | "error"; loadMoreError: string | null; } interface AgentMentionBrowseCategory { id: AgentMentionFilterId; label: string; } type AgentMentionGroup = MentionPaletteGroup; type AgentMentionSearchState = MentionPaletteState; interface AgentMentionSearchControllerOptions { contextMentionProviders?: readonly AgentContextMentionProvider[]; debounceMs?: number; fileLimit?: number; issueLimit?: number; browseCacheTtlMs?: number; providerTimeoutMs?: number; diagnosticInfoLogger?: (payload: AgentMentionSearchDiagnosticLog) => void; diagnosticNow?: () => number; diagnosticSlowThresholdMs?: number; } type AgentMentionSearchListener = (state: AgentMentionSearchState) => void; interface AgentMentionLifecycleDiagnosticLog { event: "browse.open" | "browse.preload" | "browse.cache" | "browse.fetch.start" | "browse.fetch.dedupe" | "browse.fetch.success" | "browse.fetch.error" | "browse.apply.skipped"; details: Record; } export type { AgentContextMentionItem as A, RuntimeDiagnosticsDetailValue as R, AgentFileMentionSuggestionState as a, AgentMentionBrowseCategory as b, AgentMentionFilterId as c, AgentMentionGroup as d, AgentMentionGroupId as e, AgentMentionIssueTopicGroup as f, AgentMentionLifecycleDiagnosticLog as g, AgentMentionProviderQueryDiagnostic as h, AgentMentionRawGroups as i, AgentMentionSearchControllerOptions as j, AgentMentionSearchDiagnosticLog as k, AgentMentionSearchListener as l, AgentMentionSearchState as m, AgentMentionTotalCounts as n };