feat(notifications): emit at maintenance/turn/sync/reauth events

This commit is contained in:
Gabriel Brown
2026-07-11 16:08:22 -04:00
parent 4eb0c963ff
commit 3766a29871
7 changed files with 270 additions and 2 deletions
+27
View File
@@ -4,6 +4,7 @@ import type { Doc, Id } from './_generated/dataModel';
import type { MutationCtx } from './_generated/server';
import { internalMutation, mutation, query } from './_generated/server';
import { getOwnedSpoon, getRequiredUserId, optionalText } from './model';
import { emitNotification } from './notifications';
import type { AgentRuntimeName } from './runtimeSupport';
import { runtimesForProfile } from './runtimeSupport';
import { assertWorkerToken } from './workerAuth';
@@ -1344,6 +1345,21 @@ export const updateStatus = mutation({
}
await ctx.db.patch(job.threadId, threadPatch);
}
if (
(args.status === 'changes_ready' ||
args.status === 'draft_pr_opened') &&
job.status !== args.status
) {
await emitNotification(ctx, {
userId: job.ownerId,
kind: 'agent_turn_finished',
title: 'Agent turn finished',
body: args.summary ?? job.summary ?? '',
link: `/threads/${job.threadId}`,
threadId: job.threadId,
spoonId: job.spoonId,
});
}
}
return { success: true };
},
@@ -1687,6 +1703,17 @@ export const applyMaintenanceDecision = mutation({
createdAt: now,
updatedAt: now,
});
if (status === 'waiting_for_user') {
await emitNotification(ctx, {
userId: job.ownerId,
kind: 'agent_needs_input',
title: 'Agent needs your input',
body: args.summary,
link: `/threads/${job.threadId}`,
threadId: job.threadId,
spoonId: job.spoonId,
});
}
return { success: true };
},
});