mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-08 01:57:31 +01:00
merge: integrate agent lifecycle ownership from master
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
commit
ad5d8826ad
159 files changed
+7173
-2805
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import { createAgentLifecycle } from "./agent-lifecycle.js";
|
||||
import { and, eq, isNull, ne } from "drizzle-orm";
|
||||
import type { Db } from "@paperclipai/db";
|
||||
import {
|
||||
@@ -184,6 +185,7 @@ export function pluginManagedAgentService(
|
||||
options: PluginManagedAgentServiceOptions,
|
||||
) {
|
||||
const agentSvc = agentService(db);
|
||||
const agentSvcLifecycle = createAgentLifecycle(db);
|
||||
const approvalSvc = approvalService(db);
|
||||
const instructions = agentInstructionsService(db);
|
||||
|
||||
@@ -487,7 +489,7 @@ export function pluginManagedAgentService(
|
||||
const requiresApproval = company.requireBoardApprovalForNewAgents;
|
||||
const adapterType = await resolveManagedAdapterType(companyId, declaration);
|
||||
const initialStatus = requiresApproval ? "pending_approval" : declaration.status ?? "idle";
|
||||
let created = await agentSvc.create(companyId, {
|
||||
let created = await agentSvcLifecycle.requestHire(companyId, {
|
||||
...declarationPatch(declaration, { adapterType }),
|
||||
status: initialStatus,
|
||||
pauseReason: initialStatus === "paused" ? managedAgentPauseReason(options.pluginKey) : null,
|
||||
@@ -570,26 +572,13 @@ export function pluginManagedAgentService(
|
||||
) {
|
||||
if (
|
||||
declaration.status !== "paused"
|
||||
|| agent.status !== "paused"
|
||||
|| agent.lifecycleState !== "paused"
|
||||
|| agent.pauseReason !== null
|
||||
) {
|
||||
return agent;
|
||||
}
|
||||
|
||||
const updated = await db
|
||||
.update(agents)
|
||||
.set({
|
||||
pauseReason: managedAgentPauseReason(options.pluginKey),
|
||||
updatedAt: new Date(),
|
||||
})
|
||||
.where(and(
|
||||
eq(agents.id, agent.id),
|
||||
eq(agents.companyId, companyId),
|
||||
eq(agents.status, "paused"),
|
||||
isNull(agents.pauseReason),
|
||||
))
|
||||
.returning({ id: agents.id })
|
||||
.then((rows) => rows[0] ?? null);
|
||||
const updated = await agentSvcLifecycle.pauseAgent(agent.id, managedAgentPauseReason(options.pluginKey));
|
||||
|
||||
if (!updated) {
|
||||
const current = await agentSvc.getById(agent.id) as Agent | null;
|
||||
|
||||
Reference in new issue
Block a user