mirror of
https://github.com/langgenius/dify.git
synced 2026-07-21 18:58:35 +08:00
Co-authored-by: Joel <iamjoel007@gmail.com> Co-authored-by: zyssyz123 <916125788@qq.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: 林玮 (Jade Lin) <linw1995@icloud.com> Co-authored-by: 盐粒 Yanli <mail@yanli.one>
78 lines
2.3 KiB
TypeScript
78 lines
2.3 KiB
TypeScript
import type {
|
|
AgentBuildDraftResponse,
|
|
AgentSoulConfig,
|
|
} from '@dify/contracts/api/console/agent/types.gen'
|
|
import { createApiContext, expectApiResponseOK } from '../../../support/api'
|
|
|
|
export async function checkoutAgentBuildDraft(agentId: string): Promise<AgentBuildDraftResponse> {
|
|
const ctx = await createApiContext()
|
|
try {
|
|
const response = await ctx.post(`/console/api/agent/${agentId}/build-draft/checkout`, {
|
|
data: { force: true },
|
|
})
|
|
await expectApiResponseOK(response, `Checkout Agent v2 build draft for ${agentId}`)
|
|
return (await response.json()) as AgentBuildDraftResponse
|
|
}
|
|
finally {
|
|
await ctx.dispose()
|
|
}
|
|
}
|
|
|
|
export async function saveAgentBuildDraft(
|
|
agentId: string,
|
|
agentSoul: AgentSoulConfig,
|
|
): Promise<AgentBuildDraftResponse> {
|
|
const ctx = await createApiContext()
|
|
try {
|
|
const response = await ctx.put(`/console/api/agent/${agentId}/build-draft`, {
|
|
data: {
|
|
agent_soul: agentSoul,
|
|
save_strategy: 'save_to_current_version',
|
|
variant: 'agent_app',
|
|
},
|
|
})
|
|
await expectApiResponseOK(response, `Save Agent v2 build draft for ${agentId}`)
|
|
return (await response.json()) as AgentBuildDraftResponse
|
|
}
|
|
finally {
|
|
await ctx.dispose()
|
|
}
|
|
}
|
|
|
|
export async function agentBuildDraftExists(agentId: string): Promise<boolean> {
|
|
const ctx = await createApiContext()
|
|
try {
|
|
const response = await ctx.get(`/console/api/agent/${agentId}/build-draft`)
|
|
if (response.status() === 404)
|
|
return false
|
|
|
|
await expectApiResponseOK(response, `Get Agent v2 build draft for ${agentId}`)
|
|
return true
|
|
}
|
|
finally {
|
|
await ctx.dispose()
|
|
}
|
|
}
|
|
|
|
export async function applyAgentBuildDraft(agentId: string): Promise<void> {
|
|
const ctx = await createApiContext()
|
|
try {
|
|
const response = await ctx.post(`/console/api/agent/${agentId}/build-draft/apply`)
|
|
await expectApiResponseOK(response, `Apply Agent v2 build draft for ${agentId}`)
|
|
}
|
|
finally {
|
|
await ctx.dispose()
|
|
}
|
|
}
|
|
|
|
export async function discardAgentBuildDraft(agentId: string): Promise<void> {
|
|
const ctx = await createApiContext()
|
|
try {
|
|
const response = await ctx.delete(`/console/api/agent/${agentId}/build-draft`)
|
|
await expectApiResponseOK(response, `Discard Agent v2 build draft for ${agentId}`)
|
|
}
|
|
finally {
|
|
await ctx.dispose()
|
|
}
|
|
}
|