feat(agent-model): add per-agent model override with default-reset UX and runtime sync (#651)
This commit is contained in:
@@ -6,6 +6,7 @@ import type { AgentSummary, AgentsSnapshot } from '@/types/agent';
|
||||
interface AgentsState {
|
||||
agents: AgentSummary[];
|
||||
defaultAgentId: string;
|
||||
defaultModelRef: string | null;
|
||||
configuredChannelTypes: string[];
|
||||
channelOwners: Record<string, string>;
|
||||
channelAccountOwners: Record<string, string>;
|
||||
@@ -14,6 +15,7 @@ interface AgentsState {
|
||||
fetchAgents: () => Promise<void>;
|
||||
createAgent: (name: string, options?: { inheritWorkspace?: boolean }) => Promise<void>;
|
||||
updateAgent: (agentId: string, name: string) => Promise<void>;
|
||||
updateAgentModel: (agentId: string, modelRef: string | null) => Promise<void>;
|
||||
deleteAgent: (agentId: string) => Promise<void>;
|
||||
assignChannel: (agentId: string, channelType: ChannelType) => Promise<void>;
|
||||
removeChannel: (agentId: string, channelType: ChannelType) => Promise<void>;
|
||||
@@ -24,6 +26,7 @@ function applySnapshot(snapshot: AgentsSnapshot | undefined) {
|
||||
return snapshot ? {
|
||||
agents: snapshot.agents ?? [],
|
||||
defaultAgentId: snapshot.defaultAgentId ?? 'main',
|
||||
defaultModelRef: snapshot.defaultModelRef ?? null,
|
||||
configuredChannelTypes: snapshot.configuredChannelTypes ?? [],
|
||||
channelOwners: snapshot.channelOwners ?? {},
|
||||
channelAccountOwners: snapshot.channelAccountOwners ?? {},
|
||||
@@ -33,6 +36,7 @@ function applySnapshot(snapshot: AgentsSnapshot | undefined) {
|
||||
export const useAgentsStore = create<AgentsState>((set) => ({
|
||||
agents: [],
|
||||
defaultAgentId: 'main',
|
||||
defaultModelRef: null,
|
||||
configuredChannelTypes: [],
|
||||
channelOwners: {},
|
||||
channelAccountOwners: {},
|
||||
@@ -83,6 +87,23 @@ export const useAgentsStore = create<AgentsState>((set) => ({
|
||||
}
|
||||
},
|
||||
|
||||
updateAgentModel: async (agentId: string, modelRef: string | null) => {
|
||||
set({ error: null });
|
||||
try {
|
||||
const snapshot = await hostApiFetch<AgentsSnapshot & { success?: boolean }>(
|
||||
`/api/agents/${encodeURIComponent(agentId)}/model`,
|
||||
{
|
||||
method: 'PUT',
|
||||
body: JSON.stringify({ modelRef }),
|
||||
}
|
||||
);
|
||||
set(applySnapshot(snapshot));
|
||||
} catch (error) {
|
||||
set({ error: String(error) });
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
deleteAgent: async (agentId: string) => {
|
||||
set({ error: null });
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user