dify/e2e/features/agent-v2/support/agent-build-draft.ts
yyh acb5ee29e1
test(e2e): validate generated console contracts (#39400)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-07-22 07:48:37 +00:00

35 lines
932 B
TypeScript

import type {
AgentBuildDraftResponse,
AgentSoulConfig,
} from '@dify/contracts/api/console/agent/types.gen'
import type { ConsoleClient } from '../../../support/api/console-client'
import { ORPCError } from '@orpc/client'
export async function saveAgentBuildDraft(
client: ConsoleClient,
agentId: string,
agentSoul: AgentSoulConfig,
): Promise<AgentBuildDraftResponse> {
return client.agent.byAgentId.buildDraft.put({
body: {
agent_soul: agentSoul,
save_strategy: 'save_to_current_version',
variant: 'agent_app',
},
params: { agent_id: agentId },
})
}
export async function agentBuildDraftExists(
client: ConsoleClient,
agentId: string,
): Promise<boolean> {
try {
await client.agent.byAgentId.buildDraft.get({ params: { agent_id: agentId } })
return true
} catch (error) {
if (error instanceof ORPCError && error.status === 404) return false
throw error
}
}