import { z } from 'zod'; import { type APIClient, APIResponseSchema } from '@agentuity/api'; import { ProjectResponseError } from './util.ts'; export const ProjectListItemSchema = z.object({ id: z.string().describe('the project id'), name: z.string().describe('the project name'), description: z.string().nullable().optional().describe('the project description'), orgId: z.string().describe('the organization id that this project is registered with'), orgName: z.string().describe('the organization name'), cloudRegion: z.string().nullable().optional().describe('the cloud region'), latestDeploymentId: z.string().nullable().describe('the latest deployment id'), }); export const ProjectListSchema = z.array(ProjectListItemSchema); export const ProjectListResponseSchema = APIResponseSchema(ProjectListSchema); export type ProjectListResponse = z.infer; export type ProjectList = z.infer; /** * List all projects * * @param client * @param hasDeployment if true, filter by projects with at least one deployment * @param limit maximum number of projects to return (default: 1000, max: 10000) * @returns */ export async function projectList( client: APIClient, hasDeployment?: boolean, limit?: number ): Promise { const params = new URLSearchParams(); if (hasDeployment) { params.append('hasDeployment', 'true'); } if (limit !== undefined) { params.append('limit', limit.toString()); } const queryString = params.toString(); const resp = await client.request( 'GET', `/cli/project${queryString ? `?${queryString}` : ''}`, ProjectListResponseSchema ); if (resp.success) { return resp.data; } throw new ProjectResponseError({ message: resp.message }); }