mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
* fix: prevent delete button click when card is not swiped open * refactor: improve CreateRepoInput type safety * security: require AUTH_SECRET and use secure random generation * fix: SSH key path validation, async passphrase stripping, and port handling * fix: use correct console methods for logger levels * Add error handling to DB update functions and improve migration logging * Add error handling for session lookup in auth middleware * Add structured git error handling with user-friendly messages - Parse git errors with specific error codes (AUTH_FAILED, REPO_NOT_FOUND, PUSH_REJECTED, MERGE_CONFLICT, etc.) and appropriate HTTP status codes - Return structured error responses with summary and detail from backend - Add GitErrorBanner component for better error display in UI - Add optional onError callback to useGit hook for external error handling * Make IPC server initialization/disposal async and fix SSH host key handler * add try-catch error handling in frontend lib utilities * remove unresolved promise handlers in speech synthesizer callbacks * Extract error types to shared package * Import GitErrorCode from shared package * Refactor API layer to use shared FetchError and fetchWrapper * Update prompt parser and source control components * Extract MCP server list to separate component with improved badge menu UX * merge useSettingsDialogUrl into useSettingsDialog and extract getRepoDisplayName utility * add separate loading state for passkey sign in * refactor hooks: use fetchWrapper, improve error handling, add proper types * replace browser confirm() with DeleteDialog component in settings * fix: add missing variables parameter in React Query onError callbacks * Refactor message parts to use separate Zustand store * Update QuestionPrompt styling for light/dark mode
105 lines
2.6 KiB
TypeScript
105 lines
2.6 KiB
TypeScript
import type { ContentPart, FileAttachmentInfo, ImageAttachment } from '@/api/types'
|
|
|
|
export const MENTION_PATTERN = /@([A-Za-z0-9_\-./]+)/g
|
|
export const MENTION_TRIGGER_PATTERN = /(^|\s)@([A-Za-z0-9_\-./]*)$/
|
|
|
|
export interface MentionTrigger {
|
|
start: number
|
|
end: number
|
|
query: string
|
|
}
|
|
|
|
export interface AgentInfo {
|
|
name: string
|
|
description?: string
|
|
}
|
|
|
|
export function detectMentionTrigger(
|
|
text: string,
|
|
cursorPosition: number
|
|
): MentionTrigger | null {
|
|
const textBeforeCursor = text.slice(0, cursorPosition)
|
|
const match = textBeforeCursor.match(MENTION_TRIGGER_PATTERN)
|
|
|
|
if (!match || match.index === undefined) return null
|
|
|
|
const atIndex = match.index + match[1].length
|
|
return {
|
|
start: atIndex,
|
|
end: cursorPosition,
|
|
query: match[2]
|
|
}
|
|
}
|
|
|
|
export function filterAgentsByQuery(agents: AgentInfo[], query: string): AgentInfo[] {
|
|
const lowerQuery = query.toLowerCase()
|
|
return agents.filter(agent =>
|
|
agent.name.toLowerCase().includes(lowerQuery)
|
|
)
|
|
}
|
|
|
|
export function parsePromptToParts(
|
|
rawInput: string,
|
|
fileMap: Map<string, FileAttachmentInfo>,
|
|
imageAttachments?: ImageAttachment[]
|
|
): ContentPart[] {
|
|
const parts: ContentPart[] = []
|
|
let lastIndex = 0
|
|
|
|
for (const match of rawInput.matchAll(MENTION_PATTERN)) {
|
|
const matchIndex = match.index!
|
|
|
|
if (matchIndex > lastIndex) {
|
|
const textContent = rawInput.slice(lastIndex, matchIndex)
|
|
if (textContent.trim()) {
|
|
parts.push({ type: 'text', content: textContent })
|
|
}
|
|
}
|
|
|
|
const mentionText = match[1]
|
|
const file = fileMap.get(mentionText.toLowerCase())
|
|
|
|
if (file) {
|
|
parts.push({
|
|
type: 'file',
|
|
path: file.path,
|
|
name: file.name
|
|
})
|
|
} else {
|
|
parts.push({ type: 'text', content: match[0] })
|
|
}
|
|
|
|
lastIndex = matchIndex + match[0].length
|
|
}
|
|
|
|
if (lastIndex < rawInput.length) {
|
|
const textContent = rawInput.slice(lastIndex)
|
|
if (textContent.trim()) {
|
|
parts.push({ type: 'text', content: textContent })
|
|
}
|
|
}
|
|
|
|
if (imageAttachments && imageAttachments.length > 0) {
|
|
for (const attachment of imageAttachments) {
|
|
parts.push({
|
|
type: 'image',
|
|
id: attachment.id,
|
|
filename: attachment.filename,
|
|
mime: attachment.mime,
|
|
dataUrl: attachment.dataUrl
|
|
})
|
|
}
|
|
}
|
|
|
|
return parts.length > 0 ? parts : [{ type: 'text', content: '' }]
|
|
}
|
|
|
|
export function getFilename(path: string): string {
|
|
return path.split('/').pop() || path
|
|
}
|
|
|
|
export function getDirectory(path: string): string {
|
|
const parts = path.split('/')
|
|
return parts.slice(0, -1).join('/') || '.'
|
|
}
|