| import { Provider } from "#/types/settings"; |
| import type { PluginSpec } from "#/api/conversation-service/agent-server-conversation-service.types"; |
|
|
| const STORAGE_KEY = "openhands-agent-server-conversation-metadata"; |
|
|
| export type WorkspaceMode = "local_repo" | "new_worktree"; |
|
|
| export interface ConversationMetadata { |
| selected_repository: string | null; |
| selected_branch: string | null; |
| git_provider: Provider | null; |
| |
| |
| |
| |
| |
| |
| |
| |
| selected_workspace?: string | null; |
| |
| |
| |
| |
| |
| |
| |
| |
| workspace_mode?: WorkspaceMode | null; |
| |
| |
| |
| |
| |
| |
| |
| active_profile?: string | null; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| stamped_at?: string | null; |
| |
| plugins?: PluginSpec[] | null; |
| |
| |
| |
| |
| |
| local_planning_conversation_id?: string | null; |
| } |
|
|
| export const toPluginCoordinates = (plugin: PluginSpec): PluginSpec => ({ |
| source: plugin.source, |
| ref: plugin.ref ?? null, |
| repo_path: plugin.repo_path ?? null, |
| }); |
|
|
| type StoredMetadata = Record<string, ConversationMetadata>; |
|
|
| const readAll = (): StoredMetadata => { |
| if (typeof window === "undefined") return {}; |
| try { |
| const raw = window.localStorage.getItem(STORAGE_KEY); |
| if (!raw) return {}; |
| const parsed = JSON.parse(raw) as unknown; |
| if (!parsed || typeof parsed !== "object") return {}; |
| return parsed as StoredMetadata; |
| } catch { |
| return {}; |
| } |
| }; |
|
|
| const writeAll = (next: StoredMetadata): void => { |
| if (typeof window === "undefined") return; |
| if (Object.keys(next).length === 0) { |
| window.localStorage.removeItem(STORAGE_KEY); |
| return; |
| } |
| window.localStorage.setItem(STORAGE_KEY, JSON.stringify(next)); |
| }; |
|
|
| export const getStoredConversationMetadata = ( |
| conversationId: string, |
| ): ConversationMetadata | null => readAll()[conversationId] ?? null; |
|
|
| export const setStoredConversationMetadata = ( |
| conversationId: string, |
| metadata: ConversationMetadata, |
| ): void => { |
| const all = readAll(); |
| all[conversationId] = metadata; |
| writeAll(all); |
| }; |
|
|
| |
| |
| |
| |
| |
| |
| export const mergeStoredConversationMetadata = ( |
| conversationId: string, |
| patch: Partial<ConversationMetadata>, |
| ): void => { |
| setStoredConversationMetadata(conversationId, { |
| selected_repository: null, |
| selected_branch: null, |
| git_provider: null, |
| ...(getStoredConversationMetadata(conversationId) ?? {}), |
| ...patch, |
| }); |
| }; |
|
|
| export const removeStoredConversationMetadata = ( |
| conversationId: string, |
| ): void => { |
| const all = readAll(); |
| if (!(conversationId in all)) return; |
| delete all[conversationId]; |
| writeAll(all); |
| }; |
|
|