Materialize built-in bundles after approval

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
DottaandPaperclip committed 2026-07-09 20:50:34 +00:00
1 parent b63e5a624d
commit 4f2419f7b2
2 files changed
+15 -1

No files matched your search

+7 -1
View File
@@ -591,13 +591,19 @@ describeEmbeddedPostgres("built-in agents", () => {
});
await approvalService(db).approve(approval.id, "board-user", "Approved Reflection Coach");
await expect(builtInAgentService(db).get(companyId, "reflection-coach")).resolves.toMatchObject({
const approvedState = await builtInAgentService(db).get(companyId, "reflection-coach");
expect(approvedState).toMatchObject({
agent: {
permissions: {
builtInMutationPolicy: mutationPolicy,
},
},
});
expect(approvedState.resources.map((resource) => resource.stockStatus)).toEqual([
"stock_current",
"stock_current",
"stock_current",
]);
await reconcileBuiltInAgentsOnStartup(db);
const agentRows = await db.select().from(agents).where(eq(agents.companyId, companyId));
+8
View File
@@ -24,6 +24,13 @@ export function approvalService(db: Db) {
};
}
async function reconcileApprovedBuiltInAgent(companyId: string, payload: Record<string, unknown>) {
const sourceBuiltInAgentKey = typeof payload.sourceBuiltInAgentKey === "string" ? payload.sourceBuiltInAgentKey : null;
if (!sourceBuiltInAgentKey) return;
const { builtInAgentService } = await import("./built-in-agents.js");
await builtInAgentService(db).ensure(companyId, sourceBuiltInAgentKey);
}
async function getExistingApproval(id: string) {
const existing = await db
.select()
@@ -129,6 +136,7 @@ export function approvalService(db: Db) {
const payloadAgentId = typeof payload.agentId === "string" ? payload.agentId : null;
if (payloadAgentId) {
await agentsSvc.activatePendingApproval(payloadAgentId, payload);
await reconcileApprovedBuiltInAgent(updated.companyId, payload);
hireApprovedAgentId = payloadAgentId;
} else {
const created = await agentsSvc.create(updated.companyId, {