import { z } from 'zod'; import { type APIClient, APIResponseSchema } from '@agentuity/api'; import { ProjectResponseError } from './util.ts'; // --- GET hostname --- export const ProjectHostnameGetRequestSchema = z.object({ projectId: z.string().describe('the project id'), }); const HostnameGetDataSchema = z.object({ hostname: z .string() .nullable() .describe('The vanity hostname for the project, or null if not set.'), url: z .string() .nullable() .describe('The full URL for the project hostname, or null if not set.'), }); const ProjectHostnameGetResponseSchema = APIResponseSchema(HostnameGetDataSchema); type ProjectHostnameGetRequest = z.infer; type ProjectHostnameGetResponse = z.infer; export type ProjectHostnameGetResult = z.infer; export async function projectHostnameGet( client: APIClient, request: ProjectHostnameGetRequest ): Promise { const resp = await client.get( `/cli/project/${request.projectId}/hostname`, ProjectHostnameGetResponseSchema ); if (resp.success) { return resp.data; } throw new ProjectResponseError({ message: resp.message }); } // --- SET hostname --- export const ProjectHostnameSetRequestSchema = z.object({ projectId: z.string().describe('the project id'), hostname: z.string().describe('the vanity hostname to set'), }); const HostnameSetDataSchema = z.object({ hostname: z.string().describe('The vanity hostname that was set.'), url: z.string().describe('The full URL for the project hostname.'), }); const ProjectHostnameSetResponseSchema = APIResponseSchema(HostnameSetDataSchema); type ProjectHostnameSetRequest = z.infer; type ProjectHostnameSetResponse = z.infer; export type ProjectHostnameSetResult = z.infer; export async function projectHostnameSet( client: APIClient, request: ProjectHostnameSetRequest ): Promise { const resp = await client.put( `/cli/project/${request.projectId}/hostname`, { hostname: request.hostname }, ProjectHostnameSetResponseSchema ); if (resp.success) { return resp.data; } throw new ProjectResponseError({ message: resp.message }); }