import {z} from 'zod' export type AgentInvitationCreate = {name?: string | undefined, email: string, permission?: string | undefined, knowledge_base?: string | undefined}; export type CreateApiAgentSendInvitationArgs = {team_id?: string | undefined, body: AgentInvitationCreate}; export type CreateApiAgentSendInvitationOptions = {baseUrl: string, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const agentInvitation = z.object({id: z.string().optional(), date_created: z.string().optional(), date_updated: z.string().optional(), invited_by_user_id: z.string().optional(), name: z.string().optional(), email: z.string().optional(), permission: z.string().optional(), knowledge_base: z.string().optional(), invitation_token: z.string().optional(), accepted: z.boolean().optional()}); 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 }; /** * Send Agent Invitation * * POST /agent/send-invitation * * Also accepts auth: OAuth2PasswordBearer */ export const createApiAgentSendInvitation = async (args: CreateApiAgentSendInvitationArgs, options: CreateApiAgentSendInvitationOptions) => { const {baseUrl, fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.team_id != null) query.append("team_id", String(args.team_id)) if (APIKeyHeader !== undefined) headers.set("x-api-key", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/agent/send-invitation${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(agentInvitation, await res.json()) };