refactor: enhance AI Agent publishing process to ensure form is saved before publishing
This commit is contained in:
@@ -40,3 +40,21 @@ test("AI Agent config uses one Agent Loop without a runtime mode selector", () =
|
|||||||
assert.doesNotMatch(configWorkbenchSource, /管理工作流/)
|
assert.doesNotMatch(configWorkbenchSource, /管理工作流/)
|
||||||
assert.match(configWorkbenchSource, /写操作(需确认)/)
|
assert.match(configWorkbenchSource, /写操作(需确认)/)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test("publishing an AI Agent saves the current form before publishing", () => {
|
||||||
|
const publishFunction = configWorkbenchSource.match(
|
||||||
|
/async function publishAgent\(\) \{([\s\S]*?)\n \}/,
|
||||||
|
)?.[1]
|
||||||
|
|
||||||
|
assert.ok(publishFunction)
|
||||||
|
assert.match(publishFunction, /const payload = buildPayload\(\)/)
|
||||||
|
|
||||||
|
const saveIndex = publishFunction.indexOf(
|
||||||
|
"await updateAIAgent({ id: agent.id, ...payload })",
|
||||||
|
)
|
||||||
|
const publishIndex = publishFunction.indexOf("await publishAIAgent(agent.id)")
|
||||||
|
|
||||||
|
assert.ok(saveIndex >= 0)
|
||||||
|
assert.ok(publishIndex > saveIndex)
|
||||||
|
assert.match(publishFunction, /Agent 配置已保存并发布/)
|
||||||
|
})
|
||||||
|
|||||||
@@ -412,12 +412,14 @@ export function AIAgentConfigWorkbench({
|
|||||||
if (!validateForm()) return
|
if (!validateForm()) return
|
||||||
setSaving(true)
|
setSaving(true)
|
||||||
try {
|
try {
|
||||||
|
const payload = buildPayload()
|
||||||
|
await updateAIAgent({ id: agent.id, ...payload })
|
||||||
await publishAIAgent(agent.id)
|
await publishAIAgent(agent.id)
|
||||||
await loadData()
|
await loadData()
|
||||||
toast.success("Agent 已发布")
|
toast.success("Agent 配置已保存并发布")
|
||||||
onAgentSaved?.()
|
onAgentSaved?.()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast.error(error instanceof Error ? error.message : "发布 Agent 失败")
|
toast.error(error instanceof Error ? error.message : "保存并发布 Agent 失败")
|
||||||
} finally {
|
} finally {
|
||||||
setSaving(false)
|
setSaving(false)
|
||||||
}
|
}
|
||||||
@@ -825,7 +827,9 @@ export function AIAgentConfigWorkbench({
|
|||||||
agentPublished ? "bg-emerald-500" : "bg-amber-500",
|
agentPublished ? "bg-emerald-500" : "bg-amber-500",
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
<span>{agentPublished ? "当前配置已发布" : "保存配置后再发布 Agent"}</span>
|
<span>
|
||||||
|
{agentPublished ? "Agent 已发布;再次发布会保存当前配置" : "发布时会先保存当前配置"}
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<Button type="button" variant="outline" onClick={onCancel}>
|
<Button type="button" variant="outline" onClick={onCancel}>
|
||||||
|
|||||||
Reference in New Issue
Block a user