import {z} from 'zod' export type CompanyStatus = 'draft' | 'active' | 'paused' | 'archived'; export type UpdateCompanyRequest = {auto_start_goals?: (boolean | null) | undefined, one_liner?: (string | null) | undefined, mission?: (string | null) | undefined, status?: (CompanyStatus | null) | undefined, cycle_interval_seconds?: (number | null) | undefined, max_daily_tasks?: (number | null) | undefined, custom_domain?: (string | null) | undefined, outbound_email_paused?: (boolean | null) | undefined, outbound_prospect_search_paused?: (boolean | null) | undefined, status_emails_paused?: (boolean | null) | undefined, source?: (string | null) | undefined}; export type UpdateApiCompaniesCompanyIdArgs = {company_id: string, body: UpdateCompanyRequest}; export type UpdateApiCompaniesCompanyIdOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const companyStatus = z.enum(["draft", "active", "paused", "archived"]); export const companyResponse = z.object({id: z.string(), conglomerate_id: z.string(), name: z.string(), handle: z.string(), one_liner: z.string().nullable().optional(), mission: z.string().nullable().optional(), initial_prompt: z.string().nullable().optional(), status: companyStatus, auto_start_goals: z.boolean().optional(), balance_cents: z.number().int().optional(), balance_real_cents: z.number().int().optional(), github_repo_url: z.string().nullable().optional(), github_repo_full_name: z.string().nullable().optional(), cycle_interval_seconds: z.number().int().optional(), max_daily_tasks: z.number().int().optional(), tasks_used_today: z.number().int().optional(), harness_version: z.number().optional(), custom_domain: z.string().nullable().optional(), custom_domain_verified: z.boolean().optional(), email_address: z.string().optional(), platform_email_address: z.string().optional(), website_url: z.string().optional(), dashboard_url: z.string().optional(), outbound_email_paused: z.boolean().optional(), outbound_prospect_search_paused: z.boolean().optional(), status_emails_paused: z.boolean().optional(), selling_paused: z.boolean().optional(), open_ask_count: z.number().int().optional(), open_proposal_count: z.number().int().optional(), open_connection_request_count: z.number().int().optional(), next_scheduled_run_at: z.string().nullable().optional(), active_routine_task_ids: z.array(z.string()).optional(), coordinator_session_id: z.string().nullable().optional(), created_at: z.string(), updated_at: z.string()}); 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 }; /** * Update Company * * PUT /companies/{company_id} */ export const updateApiCompaniesCompanyId = async (args: UpdateApiCompaniesCompanyIdArgs, options: UpdateApiCompaniesCompanyIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/companies/${encodeURIComponent(String(args.company_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(companyResponse, await res.json()) };