mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
feat: add model state persistence and improve model selection sync (#209)
* feat: add persistent model state storage with database backend - Create opencode_model_state table for storing user model preferences - Implement database-backed model state management (recent, favorite, variant) - Add atomic JSON file utilities with file locking for concurrent safety - Migrate providers routes from file-based to database storage - Add backfill migration to preserve existing model.json data - Include comprehensive tests for model-state and atomic-json modules - Refactor useSessionAgent hook to simplify agent/model resolution logic - Update getFileApiUrl to use consistent query parameter approach * fix: include workspace dependencies in Docker image * fix: overlay workspace node_modules after source to prevent layer overwrite * fix: ensure model state table exists for existing databases * feat: add model state persistence and improve model selection sync - Add setActiveModel to modelStore and useModelSelection for direct model updates - Sync session agent model/variant to store when messages load - Include model, agent, and variant in optimistic user messages - Fix useSessionAgent to check isFetching during message loading - Update env.ts to use getter for BASE_PATH for dynamic resolution - Fix test environment variable from OPENCODE_WORKSPACE_PATH to WORKSPACE_PATH
This commit is contained in:
1 parent
f0c87ffa5d
commit
549e0ac7b2
27 files changed
+1429
-177
No files matched your search
@@ -193,13 +193,30 @@ const createOptimisticUserMessageParts = (
|
||||
const createOptimisticUserMessageInfo = (
|
||||
sessionID: string,
|
||||
optimisticID: string,
|
||||
model?: string,
|
||||
agent?: string,
|
||||
variant?: string,
|
||||
): Message => {
|
||||
return {
|
||||
const message = {
|
||||
id: optimisticID,
|
||||
role: "user",
|
||||
sessionID,
|
||||
time: { created: Date.now() },
|
||||
} as Message;
|
||||
|
||||
if (model) {
|
||||
const [providerID, modelID] = model.split("/");
|
||||
if (providerID && modelID) {
|
||||
return {
|
||||
...message,
|
||||
model: { providerID, modelID },
|
||||
agent,
|
||||
variant,
|
||||
} as Message;
|
||||
}
|
||||
}
|
||||
|
||||
return { ...message, agent, variant } as Message;
|
||||
};
|
||||
|
||||
export const useSendPrompt = (opcodeUrl: string | null | undefined, directory?: string) => {
|
||||
@@ -241,7 +258,7 @@ export const useSendPrompt = (opcodeUrl: string | null | undefined, directory?:
|
||||
contentParts,
|
||||
optimisticUserID,
|
||||
);
|
||||
const userMessageInfo = createOptimisticUserMessageInfo(sessionID, optimisticUserID);
|
||||
const userMessageInfo = createOptimisticUserMessageInfo(sessionID, optimisticUserID, model, agent, variant);
|
||||
|
||||
const messagesQueryKey = ["opencode", "messages", opcodeUrl, sessionID, directory];
|
||||
await queryClient.cancelQueries({ queryKey: messagesQueryKey });
|
||||
|
||||
Reference in new issue
Block a user