fix: Refine flow — optimistic UI update + instruction passthrough
- Add getActiveRefineAgent to spawn mutation optimistic updates and live event invalidation rules so the refine panel reflects agent state immediately without manual refresh - Accept optional instruction param in buildRefinePrompt() and inject it as <user_instruction> block so the agent knows what to focus on - Pass input.instruction through in architect router spawn call
This commit is contained in:
@@ -110,9 +110,11 @@ export function useRefineAgent(initiativeId: string): UseRefineAgentResult {
|
||||
onMutate: async ({ initiativeId, instruction }) => {
|
||||
// Cancel outgoing refetches
|
||||
await utils.listAgents.cancel();
|
||||
await utils.getActiveRefineAgent.cancel({ initiativeId });
|
||||
|
||||
// Snapshot previous value
|
||||
// Snapshot previous values
|
||||
const previousAgents = utils.listAgents.getData();
|
||||
const previousRefineAgent = utils.getActiveRefineAgent.getData({ initiativeId });
|
||||
|
||||
// Optimistically add a temporary agent
|
||||
const tempAgent = {
|
||||
@@ -133,20 +135,25 @@ export function useRefineAgent(initiativeId: string): UseRefineAgentResult {
|
||||
};
|
||||
|
||||
utils.listAgents.setData(undefined, (old = []) => [tempAgent, ...old]);
|
||||
utils.getActiveRefineAgent.setData({ initiativeId }, tempAgent as any);
|
||||
|
||||
return { previousAgents };
|
||||
return { previousAgents, previousRefineAgent };
|
||||
},
|
||||
onSuccess: () => {
|
||||
// Agent will appear in the list after invalidation
|
||||
},
|
||||
onError: (err, variables, context) => {
|
||||
// Revert optimistic update
|
||||
// Revert optimistic updates
|
||||
if (context?.previousAgents) {
|
||||
utils.listAgents.setData(undefined, context.previousAgents);
|
||||
}
|
||||
if (context?.previousRefineAgent !== undefined) {
|
||||
utils.getActiveRefineAgent.setData({ initiativeId }, context.previousRefineAgent);
|
||||
}
|
||||
},
|
||||
onSettled: () => {
|
||||
void utils.listAgents.invalidate();
|
||||
void utils.getActiveRefineAgent.invalidate({ initiativeId });
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ function InitiativeDetailPage() {
|
||||
useLiveUpdates([
|
||||
{ prefix: 'task:', invalidate: ['listPhases', 'listTasks', 'listInitiativeTasks'] },
|
||||
{ prefix: 'phase:', invalidate: ['listPhases', 'listTasks', 'listInitiativePhaseDependencies'] },
|
||||
{ prefix: 'agent:', invalidate: ['listAgents'] },
|
||||
{ prefix: 'agent:', invalidate: ['listAgents', 'getActiveRefineAgent'] },
|
||||
{ prefix: 'page:', invalidate: ['listPages', 'getPage', 'getRootPage'] },
|
||||
]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user