import {z} from 'zod' export type PmsvoPmsControlObjS = {app_account_ids?: Array | undefined, department_ids?: Array | undefined, role_ids?: Array | undefined, user_group_ids?: Array | undefined, user_ids?: Array | undefined}; export type CdaenumPublishToBe = 'api_agent' | 'web_sdk_agent' | 'skill_agent' | 'data_flow_agent'; export type DaenumPublishToWhere = 'custom_space' | 'square'; export type ReleasereqUpdatePublishInfoReq = {category_ids?: Array | undefined, description?: string | undefined, pms_control?: PmsvoPmsControlObjS | undefined, publish_to_bes?: Array | undefined, publish_to_where?: Array | undefined}; export type CreateApiV3AgentAgentIdPublishArgs = {agent_id: string, body: ReleasereqUpdatePublishInfoReq}; export type CreateApiV3AgentAgentIdPublishOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV3AgentAgentIdPublishResponse = z.object({}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * 发布智能体 * * POST /v3/agent/{agent_id}/publish */ export const createApiV3AgentAgentIdPublish = async (args: CreateApiV3AgentAgentIdPublishArgs, options: CreateApiV3AgentAgentIdPublishOptions) => { const {baseUrl, fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set("Authorization", BearerAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v3/agent/${encodeURIComponent(String(args.agent_id))}/publish${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiV3AgentAgentIdPublishResponse, await res.json()) };