merge: agent-lifecycle-polish
# Conflicts: # TASKS.md
This commit is contained in:
+54
-7
@@ -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();
|
||||
@@ -302,6 +310,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;
|
||||
|
||||
@@ -305,6 +305,12 @@
|
||||
publishAgent: function(workspaceId, agentId, payload) {
|
||||
return post('/workspaces/' + encodeURIComponent(workspaceId) + '/agents/' + encodeURIComponent(agentId) + '/publish', payload);
|
||||
},
|
||||
unpublishAgent: function(workspaceId, agentId) {
|
||||
return post('/workspaces/' + encodeURIComponent(workspaceId) + '/agents/' + encodeURIComponent(agentId) + '/unpublish', {});
|
||||
},
|
||||
archiveAgent: function(workspaceId, agentId) {
|
||||
return post('/workspaces/' + encodeURIComponent(workspaceId) + '/agents/' + encodeURIComponent(agentId) + '/archive', {});
|
||||
},
|
||||
listPlatformApiKeys: function(workspaceId) {
|
||||
return get('/workspaces/' + encodeURIComponent(workspaceId) + '/platform-api-keys');
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user