refactor: implement refreshAgentPublicationState function to streamline agent publication updates
This commit is contained in:
@@ -60,6 +60,12 @@ test("publishing an AI Agent saves the current form before publishing", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
test("saving a published AI Agent keeps the active revision online", () => {
|
test("saving a published AI Agent keeps the active revision online", () => {
|
||||||
|
const saveFunction = configWorkbenchSource.match(
|
||||||
|
/async function saveAgentSettings\(\) \{([\s\S]*?)\n \}/,
|
||||||
|
)?.[1]
|
||||||
|
|
||||||
|
assert.ok(saveFunction)
|
||||||
assert.match(configWorkbenchSource, /配置已保存,当前已发布版本继续生效/)
|
assert.match(configWorkbenchSource, /配置已保存,当前已发布版本继续生效/)
|
||||||
assert.match(configWorkbenchSource, /已发布版本正在生效;再次发布后应用当前配置/)
|
assert.match(configWorkbenchSource, /已发布版本正在生效;再次发布后应用当前配置/)
|
||||||
|
assert.doesNotMatch(saveFunction, /loadData\(\)/)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -215,6 +215,19 @@ export function AIAgentConfigWorkbench({
|
|||||||
void loadData()
|
void loadData()
|
||||||
}, [loadData])
|
}, [loadData])
|
||||||
|
|
||||||
|
async function refreshAgentPublicationState(id: number) {
|
||||||
|
const [detail, revisions] = await Promise.all([
|
||||||
|
fetchAIAgent(id),
|
||||||
|
fetchAIAgentRevisions(id),
|
||||||
|
])
|
||||||
|
setAgent((current) =>
|
||||||
|
current
|
||||||
|
? { ...current, publishedRevisionId: detail.publishedRevisionId }
|
||||||
|
: detail,
|
||||||
|
)
|
||||||
|
setAgentRevisions(revisions ?? [])
|
||||||
|
}
|
||||||
|
|
||||||
const serviceModeOptions = useMemo(
|
const serviceModeOptions = useMemo(
|
||||||
() => [
|
() => [
|
||||||
{ value: String(IMConversationServiceMode.AIOnly), label: "仅 AI" },
|
{ value: String(IMConversationServiceMode.AIOnly), label: "仅 AI" },
|
||||||
@@ -395,7 +408,6 @@ export function AIAgentConfigWorkbench({
|
|||||||
? "配置已保存,当前已发布版本继续生效"
|
? "配置已保存,当前已发布版本继续生效"
|
||||||
: "Agent 配置已保存",
|
: "Agent 配置已保存",
|
||||||
)
|
)
|
||||||
await loadData()
|
|
||||||
} else {
|
} else {
|
||||||
const created = await createAIAgent(payload)
|
const created = await createAIAgent(payload)
|
||||||
setCurrentAgentId(created.id)
|
setCurrentAgentId(created.id)
|
||||||
@@ -419,7 +431,7 @@ export function AIAgentConfigWorkbench({
|
|||||||
const payload = buildPayload()
|
const payload = buildPayload()
|
||||||
await updateAIAgent({ id: agent.id, ...payload })
|
await updateAIAgent({ id: agent.id, ...payload })
|
||||||
await publishAIAgent(agent.id)
|
await publishAIAgent(agent.id)
|
||||||
await loadData()
|
await refreshAgentPublicationState(agent.id)
|
||||||
toast.success("Agent 配置已保存并发布")
|
toast.success("Agent 配置已保存并发布")
|
||||||
onAgentSaved?.()
|
onAgentSaved?.()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -435,7 +447,7 @@ export function AIAgentConfigWorkbench({
|
|||||||
try {
|
try {
|
||||||
await rollbackAIAgent(agent.id, revisionId)
|
await rollbackAIAgent(agent.id, revisionId)
|
||||||
toast.success("已回滚到选中的 Agent 版本")
|
toast.success("已回滚到选中的 Agent 版本")
|
||||||
await loadData()
|
await refreshAgentPublicationState(agent.id)
|
||||||
onAgentSaved?.()
|
onAgentSaved?.()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast.error(error instanceof Error ? error.message : "回滚 Agent 版本失败")
|
toast.error(error instanceof Error ? error.message : "回滚 Agent 版本失败")
|
||||||
|
|||||||
Reference in New Issue
Block a user