feat: add agent lifecycle transitions

This commit is contained in:
a.tolmachev
2026-03-31 15:30:33 +03:00
parent 84f4437ce0
commit 97ea969a29
11 changed files with 382 additions and 26 deletions
+54 -7
View File
@@ -1,6 +1,6 @@
function agentUiStatus(status) {
if (status === 'published') return 'active';
if (status === 'archived') return 'inactive';
if (status === 'published') return 'published';
if (status === 'archived') return 'archived';
return status || 'draft';
}
@@ -55,7 +55,7 @@ document.addEventListener('alpine:init', function() {
display_name: '',
slug: '',
description: '',
status: 'active',
status: 'published',
selectedOps: [],
},
@@ -132,7 +132,7 @@ document.addEventListener('alpine:init', function() {
get activeCount() {
return this.agents.filter(function(agent) {
return agent.status === 'active';
return agent.status === 'published';
}).length;
},
@@ -158,7 +158,7 @@ document.addEventListener('alpine:init', function() {
display_name: '',
slug: '',
description: '',
status: 'active',
status: 'published',
selectedOps: [],
};
this.opSearch = '';
@@ -173,7 +173,7 @@ document.addEventListener('alpine:init', function() {
display_name: agent.display_name,
slug: agent.slug,
description: agent.description,
status: agent.status === 'active' ? 'active' : 'draft',
status: agent.raw_status || agent.status || 'draft',
selectedOps: [].concat(agent.operation_ids || []),
};
this.opSearch = '';
@@ -230,6 +230,10 @@ document.addEventListener('alpine:init', function() {
try {
var agentId = this.editingId;
var currentVersion = 1;
var existingAgent = this.drawerMode === 'edit'
? this.agents.find(function(item) { return item.id === agentId; })
: null;
var previousStatus = existingAgent ? (existingAgent.raw_status || 'draft') : 'draft';
if (this.drawerMode === 'create') {
var created = await window.CrankApi.createAgent(this.workspaceId, {
@@ -273,10 +277,14 @@ document.addEventListener('alpine:init', function() {
}),
);
if (this.form.status === 'active') {
if (this.form.status === 'published') {
await window.CrankApi.publishAgent(this.workspaceId, agentId, {
version: currentVersion,
});
} else if (this.form.status === 'archived') {
await window.CrankApi.archiveAgent(this.workspaceId, agentId);
} else if (this.drawerMode === 'edit' && previousStatus !== 'draft') {
await window.CrankApi.unpublishAgent(this.workspaceId, agentId);
}
await this.reload();
@@ -298,6 +306,45 @@ document.addEventListener('alpine:init', function() {
}
},
async applyLifecycle(agent, action) {
if (!this.workspaceId || !window.CrankApi) {
return;
}
try {
if (action === 'publish') {
await window.CrankApi.publishAgent(this.workspaceId, agent.id, {
version: agent.current_draft_version || 1,
});
} else if (action === 'unpublish') {
await window.CrankApi.unpublishAgent(this.workspaceId, agent.id);
} else if (action === 'archive') {
await window.CrankApi.archiveAgent(this.workspaceId, agent.id);
}
await this.reload();
} catch (error) {
if (window.CrankUi) {
window.CrankUi.error(error.message || 'Failed to update agent lifecycle', 'Lifecycle update failed');
}
}
},
lifecycleAction(agent) {
if (agent.raw_status === 'published') {
return { key: 'unpublish', label: 'Unpublish' };
}
if (agent.raw_status === 'archived') {
return { key: 'unpublish', label: 'Restore draft' };
}
return { key: 'publish', label: 'Publish' };
},
lifecycleLabel(agent) {
if (agent.raw_status === 'published') return 'Published';
if (agent.raw_status === 'archived') return 'Archived';
return 'Draft';
},
mcpEndpoint(agent) {
if (agent.mcp_endpoint) return agent.mcp_endpoint;
var workspace = window.getCurrentWorkspace ? window.getCurrentWorkspace() : null;