@agentuity/server 0.0.43 → 0.0.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/dist/api/api.d.ts +28 -12
  2. package/dist/api/api.d.ts.map +1 -1
  3. package/dist/api/api.js +208 -84
  4. package/dist/api/api.js.map +1 -1
  5. package/dist/api/index.d.ts +1 -0
  6. package/dist/api/index.d.ts.map +1 -1
  7. package/dist/api/index.js +1 -0
  8. package/dist/api/index.js.map +1 -1
  9. package/dist/api/org/list.d.ts +14 -8
  10. package/dist/api/org/list.d.ts.map +1 -1
  11. package/dist/api/org/list.js +8 -3
  12. package/dist/api/org/list.js.map +1 -1
  13. package/dist/api/project/create.d.ts +15 -7
  14. package/dist/api/project/create.d.ts.map +1 -1
  15. package/dist/api/project/create.js +8 -3
  16. package/dist/api/project/create.js.map +1 -1
  17. package/dist/api/project/delete.d.ts.map +1 -1
  18. package/dist/api/project/delete.js +1 -1
  19. package/dist/api/project/delete.js.map +1 -1
  20. package/dist/api/project/deploy.d.ts +184 -0
  21. package/dist/api/project/deploy.d.ts.map +1 -0
  22. package/dist/api/project/deploy.js +160 -0
  23. package/dist/api/project/deploy.js.map +1 -0
  24. package/dist/api/project/env-delete.d.ts.map +1 -1
  25. package/dist/api/project/env-delete.js +2 -2
  26. package/dist/api/project/env-delete.js.map +1 -1
  27. package/dist/api/project/env-update.d.ts.map +1 -1
  28. package/dist/api/project/env-update.js +4 -2
  29. package/dist/api/project/env-update.js.map +1 -1
  30. package/dist/api/project/exists.d.ts +7 -5
  31. package/dist/api/project/exists.d.ts.map +1 -1
  32. package/dist/api/project/exists.js +1 -1
  33. package/dist/api/project/exists.js.map +1 -1
  34. package/dist/api/project/get.d.ts +7 -12
  35. package/dist/api/project/get.d.ts.map +1 -1
  36. package/dist/api/project/get.js +5 -4
  37. package/dist/api/project/get.js.map +1 -1
  38. package/dist/api/project/index.d.ts +1 -0
  39. package/dist/api/project/index.d.ts.map +1 -1
  40. package/dist/api/project/index.js +1 -0
  41. package/dist/api/project/index.js.map +1 -1
  42. package/dist/api/project/list.d.ts +20 -8
  43. package/dist/api/project/list.d.ts.map +1 -1
  44. package/dist/api/project/list.js +9 -6
  45. package/dist/api/project/list.js.map +1 -1
  46. package/dist/api/region/create.d.ts +46 -0
  47. package/dist/api/region/create.d.ts.map +1 -0
  48. package/dist/api/region/create.js +35 -0
  49. package/dist/api/region/create.js.map +1 -0
  50. package/dist/api/region/delete.d.ts +38 -0
  51. package/dist/api/region/delete.d.ts.map +1 -0
  52. package/dist/api/region/delete.js +31 -0
  53. package/dist/api/region/delete.js.map +1 -0
  54. package/dist/api/region/index.d.ts +5 -0
  55. package/dist/api/region/index.d.ts.map +1 -0
  56. package/dist/api/region/index.js +5 -0
  57. package/dist/api/region/index.js.map +1 -0
  58. package/dist/api/region/list.d.ts +27 -0
  59. package/dist/api/region/list.d.ts.map +1 -0
  60. package/dist/api/region/list.js +21 -0
  61. package/dist/api/region/list.js.map +1 -0
  62. package/dist/api/region/resources.d.ts +53 -0
  63. package/dist/api/region/resources.d.ts.map +1 -0
  64. package/dist/api/region/resources.js +35 -0
  65. package/dist/api/region/resources.js.map +1 -0
  66. package/dist/api/user/whoami.d.ts +18 -8
  67. package/dist/api/user/whoami.d.ts.map +1 -1
  68. package/dist/api/user/whoami.js +9 -6
  69. package/dist/api/user/whoami.js.map +1 -1
  70. package/dist/config.d.ts +1 -0
  71. package/dist/config.d.ts.map +1 -1
  72. package/dist/config.js +1 -0
  73. package/dist/config.js.map +1 -1
  74. package/dist/logger.d.ts.map +1 -1
  75. package/dist/logger.js +4 -1
  76. package/dist/logger.js.map +1 -1
  77. package/dist/server.js +2 -2
  78. package/dist/server.js.map +1 -1
  79. package/package.json +4 -2
  80. package/src/api/api-example.md +16 -11
  81. package/src/api/api.ts +254 -93
  82. package/src/api/index.ts +1 -0
  83. package/src/api/org/list.ts +13 -10
  84. package/src/api/project/create.ts +14 -9
  85. package/src/api/project/delete.ts +2 -2
  86. package/src/api/project/deploy.ts +224 -0
  87. package/src/api/project/env-delete.ts +2 -2
  88. package/src/api/project/env-update.ts +9 -7
  89. package/src/api/project/exists.ts +1 -1
  90. package/src/api/project/get.ts +12 -12
  91. package/src/api/project/index.ts +1 -0
  92. package/src/api/project/list.ts +20 -15
  93. package/src/api/region/create.ts +55 -0
  94. package/src/api/region/delete.ts +49 -0
  95. package/src/api/region/index.ts +4 -0
  96. package/src/api/region/list.ts +31 -0
  97. package/src/api/region/resources.ts +51 -0
  98. package/src/api/user/whoami.ts +13 -12
  99. package/src/config.ts +2 -0
  100. package/src/logger.ts +5 -1
  101. package/src/server.ts +2 -2
@@ -11,16 +11,17 @@ const CreateProjectRequestSchema = z.object({
11
11
  provider: z.string().max(255).min(1),
12
12
  });
13
13
 
14
- const CreateProjectResponseSchema = APIResponseSchema(
15
- z.object({
16
- id: z.string().describe('the unique id for the project'),
17
- api_key: z.string().describe('the SDK api key for the project'),
18
- projectKey: z.string().describe('the Project api key for the project'),
19
- })
20
- );
14
+ const CreateProjectResponse = z.object({
15
+ id: z.string().describe('the unique id for the project'),
16
+ api_key: z.string().describe('the SDK api key for the project'),
17
+ projectKey: z.string().describe('the Project api key for the project'),
18
+ });
19
+
20
+ const CreateProjectResponseSchema = APIResponseSchema(CreateProjectResponse);
21
21
 
22
22
  export type CreateProjectRequest = z.infer<typeof CreateProjectRequestSchema>;
23
23
  export type CreateProjectResponse = z.infer<typeof CreateProjectResponseSchema>;
24
+ export type NewProject = Omit<z.infer<typeof CreateProjectResponse>, 'projectKey'>;
24
25
 
25
26
  /**
26
27
  * Create a new Project
@@ -32,12 +33,16 @@ export type CreateProjectResponse = z.infer<typeof CreateProjectResponseSchema>;
32
33
  export async function projectCreate(
33
34
  client: APIClient,
34
35
  body: CreateProjectRequest
35
- ): Promise<Omit<CreateProjectResponse, 'projectKey'>> {
36
- return client.request<CreateProjectResponse, CreateProjectRequest>(
36
+ ): Promise<NewProject> {
37
+ const resp = await client.request<CreateProjectResponse, CreateProjectRequest>(
37
38
  'POST',
38
39
  '/cli/project',
39
40
  CreateProjectResponseSchema,
40
41
  body,
41
42
  CreateProjectRequestSchema
42
43
  );
44
+ if (resp.success) {
45
+ return resp.data;
46
+ }
47
+ throw new Error(resp.message);
43
48
  }
@@ -7,7 +7,7 @@ const ProjectDeleteResponseSchema = APIResponseSchema(z.array(z.string()));
7
7
  type ProjectDeleteRequest = z.infer<typeof ProjectDeleteRequestSchema>;
8
8
  type ProjectDeleteResponse = z.infer<typeof ProjectDeleteResponseSchema>;
9
9
 
10
- export async function projectDelete(client: APIClient, ...ids: string[]) {
10
+ export async function projectDelete(client: APIClient, ...ids: string[]): Promise<string[]> {
11
11
  const resp = await client.request<ProjectDeleteResponse, ProjectDeleteRequest>(
12
12
  'DELETE',
13
13
  '/cli/project',
@@ -16,7 +16,7 @@ export async function projectDelete(client: APIClient, ...ids: string[]) {
16
16
  ProjectDeleteRequestSchema
17
17
  );
18
18
 
19
- if (resp.data) {
19
+ if (resp.success) {
20
20
  return resp.data;
21
21
  }
22
22
 
@@ -0,0 +1,224 @@
1
+ import { z } from 'zod';
2
+ import { type APIClient, APIResponseSchema } from '../api';
3
+
4
+ export const Resources = z.object({
5
+ memory: z.string().default('500Mi').describe('The memory requirements'),
6
+ cpu: z.string().default('500m').describe('The CPU requirements'),
7
+ disk: z.string().default('500Mi').describe('The disk requirements'),
8
+ db: z.string().optional().describe('the name of the database to use'),
9
+ storage: z.string().optional().describe('the name of the storage bucket to use'),
10
+ });
11
+
12
+ export const Mode = z.object({
13
+ type: z
14
+ .enum(['on-demand', 'provisioned'])
15
+ .default('on-demand')
16
+ .describe('on-demand or provisioned'),
17
+ idle: z.string().optional().describe('duration in seconds if on-demand'),
18
+ });
19
+
20
+ export const Deployment = z.object({
21
+ resources: Resources.optional().describe('the resource requirements for your deployed project'),
22
+ mode: Mode.optional().describe('the provisioning mode for the project'),
23
+ dependencies: z
24
+ .array(z.string().describe('APT dependencies to install prior to launching your project'))
25
+ .optional(),
26
+ domains: z.array(z.string().describe('the custom domain')).optional(),
27
+ });
28
+
29
+ const BaseFileFields = {
30
+ filename: z.string().describe('the relative path for the file'),
31
+ version: z.string().describe('the SHA256 content of the file'),
32
+ identifier: z.string().describe('the folder for the file'),
33
+ };
34
+
35
+ const EvalSchema = z.object({
36
+ ...BaseFileFields,
37
+ id: z.string().describe('the unique calculated id for the eval'),
38
+ name: z.string().describe('the name of the eval'),
39
+ description: z.string().optional().describe('the eval description'),
40
+ });
41
+
42
+ const BaseAgentFields = {
43
+ ...BaseFileFields,
44
+ id: z.string().describe('the unique calculated id for the agent'),
45
+ name: z.string().describe('the name of the agent'),
46
+ description: z.string().optional().describe('the agent description'),
47
+ evals: z.array(EvalSchema).optional().describe('the evals for the agent'),
48
+ };
49
+
50
+ const AgentSchema = z.object({
51
+ ...BaseAgentFields,
52
+ subagents: z.array(z.object(BaseAgentFields)).optional().describe('subagents of this agent'),
53
+ });
54
+
55
+ export const BuildMetadataSchema = z.object({
56
+ routes: z.array(
57
+ z.object({
58
+ id: z.string().describe('the unique calculated id for the route'),
59
+ filename: z.string().describe('the relative path for the file'),
60
+ path: z.string().describe('the route path'),
61
+ method: z.enum(['get', 'post', 'put', 'delete', 'patch']).describe('the HTTP method'),
62
+ version: z.string().describe('the SHA256 content of the file'),
63
+ type: z.enum(['api', 'sms', 'email', 'cron', 'websocket', 'sse', 'stream']),
64
+ config: z
65
+ .record(z.string(), z.unknown())
66
+ .optional()
67
+ .describe('type specific configuration'),
68
+ })
69
+ ),
70
+ agents: z.array(AgentSchema),
71
+ assets: z.array(
72
+ z.object({
73
+ filename: z.string().describe('the relative path for the file'),
74
+ kind: z.string().describe('the type of asset'),
75
+ contentType: z.string().describe('the content-type for the file'),
76
+ size: z.number().describe('the size in bytes for the file'),
77
+ })
78
+ ),
79
+ project: z.object({
80
+ id: z.string().describe('the project id'),
81
+ name: z.string().describe('the name of the project (from package.json)'),
82
+ version: z.string().optional().describe('the version of the project (from package.json)'),
83
+ orgId: z.string().describe('the organization id for the project'),
84
+ }),
85
+ deployment: z.intersection(
86
+ Deployment,
87
+ z.object({
88
+ id: z.string().describe('the deployment id'),
89
+ date: z.string().describe('the date the deployment was created in UTC format'),
90
+ git: z
91
+ .object({
92
+ repo: z.string().optional().describe('the repository name'),
93
+ commit: z.string().optional().describe('the git commit sha'),
94
+ message: z.string().optional().describe('the git commit message'),
95
+ branch: z.string().optional().describe('the git branch'),
96
+ tags: z.array(z.string()).optional().describe('the tags for the current branch'),
97
+ pr: z.string().optional().describe('the pull request number'),
98
+ })
99
+ .optional()
100
+ .describe('git commit information'),
101
+ build: z.object({
102
+ bun: z.string().describe('the version of bun that was used to build the deployment'),
103
+ agentuity: z.string().describe('the version of the agentuity runtime'),
104
+ arch: z.string().describe('the machine architecture'),
105
+ platform: z.string().describe('the machine os platform'),
106
+ }),
107
+ })
108
+ ),
109
+ });
110
+
111
+ export type BuildMetadata = z.infer<typeof BuildMetadataSchema>;
112
+
113
+ const CreateProjectDeployment = z.object({
114
+ id: z.string().describe('the unique id for the deployment'),
115
+ orgId: z.string().describe('the organization id'),
116
+ publicKey: z.string().describe('the public key to use for encrypting the deployment'),
117
+ });
118
+
119
+ const CreateProjectDeploymentSchema = APIResponseSchema(CreateProjectDeployment);
120
+
121
+ type CreateProjectDeploymentPayload = z.infer<typeof CreateProjectDeploymentSchema>;
122
+
123
+ export type Deployment = z.infer<typeof CreateProjectDeployment>;
124
+
125
+ /**
126
+ * Create a new project deployment
127
+ *
128
+ * @param client
129
+ * @param projectId
130
+ * @returns
131
+ */
132
+ export async function projectDeploymentCreate(
133
+ client: APIClient,
134
+ projectId: string,
135
+ deploymentConfig?: z.infer<typeof Deployment>
136
+ ): Promise<Deployment> {
137
+ const resp = await client.request<CreateProjectDeploymentPayload>(
138
+ 'POST',
139
+ `/cli/deploy/1/start/${projectId}`,
140
+ CreateProjectDeploymentSchema,
141
+ deploymentConfig
142
+ );
143
+ if (resp.success) {
144
+ return resp.data;
145
+ }
146
+ throw new Error(resp.message);
147
+ }
148
+
149
+ const DeploymentInstructionsObject = z.object({
150
+ deployment: z.string().describe('the url for uploading the encrypted deployment archive'),
151
+ assets: z
152
+ .record(
153
+ z.string().describe('the asset id'),
154
+ z.string().describe('the url for the asset upload')
155
+ )
156
+ .describe('the upload metadata for public assets'),
157
+ });
158
+
159
+ const DeploymentInstructionsSchema = APIResponseSchema(DeploymentInstructionsObject);
160
+
161
+ type DeploymentInstructionsResponse = z.infer<typeof DeploymentInstructionsSchema>;
162
+ export type DeploymentInstructions = z.infer<typeof DeploymentInstructionsObject>;
163
+
164
+ /**
165
+ * Update the deployment with the build metadata
166
+ *
167
+ * @param client
168
+ * @param deploymentId
169
+ * @returns
170
+ */
171
+ export async function projectDeploymentUpdate(
172
+ client: APIClient,
173
+ deploymentId: string,
174
+ deployment: BuildMetadata
175
+ ): Promise<DeploymentInstructions> {
176
+ const resp = await client.request<DeploymentInstructionsResponse, BuildMetadata>(
177
+ 'PUT',
178
+ `/cli/deploy/1/start/${deploymentId}`,
179
+ DeploymentInstructionsSchema,
180
+ deployment,
181
+ BuildMetadataSchema
182
+ );
183
+ if (resp.success) {
184
+ return resp.data;
185
+ }
186
+ throw new Error(resp.message);
187
+ }
188
+
189
+ const DeploymentCompleteObject = z.object({
190
+ publicUrls: z
191
+ .object({
192
+ latest: z.url().describe('the public url for the latest deployment'),
193
+ deployment: z.url().describe('the public url for this deployment'),
194
+ custom: z.array(z.string().describe('the custom domain')),
195
+ })
196
+ .describe('the map of public urls'),
197
+ });
198
+
199
+ const DeploymentCompleteObjectSchema = APIResponseSchema(DeploymentCompleteObject);
200
+
201
+ type DeploymentCompleteResponse = z.infer<typeof DeploymentCompleteObjectSchema>;
202
+ export type DeploymentComplete = z.infer<typeof DeploymentCompleteObject>;
203
+
204
+ /**
205
+ * Complete the deployment once build is uploaded
206
+ *
207
+ * @param client
208
+ * @param deploymentId
209
+ * @returns
210
+ */
211
+ export async function projectDeploymentComplete(
212
+ client: APIClient,
213
+ deploymentId: string
214
+ ): Promise<DeploymentComplete> {
215
+ const resp = await client.request<DeploymentCompleteResponse>(
216
+ 'POST',
217
+ `/cli/deploy/1/complete/${deploymentId}`,
218
+ DeploymentCompleteObjectSchema
219
+ );
220
+ if (resp.success) {
221
+ return resp.data;
222
+ }
223
+ throw new Error(resp.message);
224
+ }
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { APIClient, APIResponseSchema } from '../api';
2
+ import { APIClient, APIResponseSchemaNoData } from '../api';
3
3
 
4
4
  const _ProjectEnvDeleteRequestSchema = z.object({
5
5
  id: z.string().describe('the project id'),
@@ -7,7 +7,7 @@ const _ProjectEnvDeleteRequestSchema = z.object({
7
7
  secrets: z.array(z.string()).optional().describe('secret keys to delete'),
8
8
  });
9
9
 
10
- const ProjectEnvDeleteResponseSchema = APIResponseSchema(z.object({}));
10
+ const ProjectEnvDeleteResponseSchema = APIResponseSchemaNoData();
11
11
 
12
12
  type ProjectEnvDeleteRequest = z.infer<typeof _ProjectEnvDeleteRequestSchema>;
13
13
  type ProjectEnvDeleteResponse = z.infer<typeof ProjectEnvDeleteResponseSchema>;
@@ -10,13 +10,15 @@ const _ProjectEnvUpdateRequestSchema = z.object({
10
10
  });
11
11
 
12
12
  const ProjectEnvUpdateResponseSchema = APIResponseSchema(
13
- z.object({
14
- id: z.string().describe('the project id'),
15
- orgId: z.string().describe('the organization id'),
16
- api_key: z.string().optional().describe('the SDK api key for the project'),
17
- env: z.record(z.string(), z.string()).optional().describe('the environment key/values'),
18
- secrets: z.record(z.string(), z.string()).optional().describe('the secrets key/values'),
19
- })
13
+ z
14
+ .object({
15
+ id: z.string().describe('the project id'),
16
+ orgId: z.string().describe('the organization id'),
17
+ api_key: z.string().optional().describe('the SDK api key for the project'),
18
+ env: z.record(z.string(), z.string()).optional().describe('the environment key/values'),
19
+ secrets: z.record(z.string(), z.string()).optional().describe('the secrets key/values'),
20
+ })
21
+ .optional()
20
22
  );
21
23
 
22
24
  type ProjectEnvUpdateRequest = z.infer<typeof _ProjectEnvUpdateRequestSchema>;
@@ -35,7 +35,7 @@ export async function projectExists(
35
35
  ProjectExistsResponseSchema
36
36
  );
37
37
 
38
- if (resp.data) {
38
+ if (resp.success) {
39
39
  return resp.data;
40
40
  }
41
41
 
@@ -6,20 +6,20 @@ const _ProjectGetRequestSchema = z.object({
6
6
  mask: z.boolean().default(true).describe('if the secrets should be returned masked'),
7
7
  });
8
8
 
9
- const ProjectGetResponseSchema = APIResponseSchema(
10
- z.object({
11
- id: z.string().describe('the project id'),
12
- orgId: z.string().describe('the organization id'),
13
- api_key: z.string().optional().describe('the SDK api key for the project'),
14
- env: z.record(z.string(), z.string()).optional().describe('the environment key/values'),
15
- secrets: z.record(z.string(), z.string()).optional().describe('the secrets key/values'),
16
- })
17
- );
9
+ const ProjectSchema = z.object({
10
+ id: z.string().describe('the project id'),
11
+ orgId: z.string().describe('the organization id'),
12
+ api_key: z.string().optional().describe('the SDK api key for the project'),
13
+ env: z.record(z.string(), z.string()).optional().describe('the environment key/values'),
14
+ secrets: z.record(z.string(), z.string()).optional().describe('the secrets key/values'),
15
+ });
16
+
17
+ const ProjectGetResponseSchema = APIResponseSchema(ProjectSchema);
18
18
 
19
19
  type ProjectGetRequest = z.infer<typeof _ProjectGetRequestSchema>;
20
20
  type ProjectGetResponse = z.infer<typeof ProjectGetResponseSchema>;
21
21
 
22
- export type Project = NonNullable<ProjectGetResponse['data']>;
22
+ export type Project = z.infer<typeof ProjectSchema>;
23
23
 
24
24
  export async function projectGet(client: APIClient, request: ProjectGetRequest): Promise<Project> {
25
25
  const resp = await client.request<ProjectGetResponse, ProjectGetRequest>(
@@ -28,9 +28,9 @@ export async function projectGet(client: APIClient, request: ProjectGetRequest):
28
28
  ProjectGetResponseSchema
29
29
  );
30
30
 
31
- if (resp.data) {
31
+ if (resp.success) {
32
32
  return resp.data;
33
33
  }
34
34
 
35
- throw new Error(resp.message ?? 'failed to get project');
35
+ throw new Error(resp.message);
36
36
  }
@@ -1,5 +1,6 @@
1
1
  export * from './create';
2
2
  export * from './delete';
3
+ export * from './deploy';
3
4
  export * from './env-delete';
4
5
  export * from './env-update';
5
6
  export * from './exists';
@@ -1,37 +1,42 @@
1
1
  import { z } from 'zod';
2
2
  import { APIClient, APIResponseSchema } from '../api';
3
3
 
4
- const ProjectListResponseSchema = APIResponseSchema(
5
- z.array(
6
- z.object({
7
- id: z.string().describe('the project id'),
8
- name: z.string().describe('the project name'),
9
- description: z.string().optional().describe('the project description'),
10
- orgId: z.string().describe('the organization id that this project is registered with'),
11
- orgName: z.string().describe('the organization name'),
12
- })
13
- )
4
+ const ProjectListResponse = z.array(
5
+ z.object({
6
+ id: z.string().describe('the project id'),
7
+ name: z.string().describe('the project name'),
8
+ description: z.string().optional().describe('the project description'),
9
+ orgId: z.string().describe('the organization id that this project is registered with'),
10
+ orgName: z.string().describe('the organization name'),
11
+ latestDeploymentId: z.string().nullable().describe('the latest deployment id'),
12
+ })
14
13
  );
15
14
 
15
+ const ProjectListResponseSchema = APIResponseSchema(ProjectListResponse);
16
+
16
17
  export type ProjectListResponse = z.infer<typeof ProjectListResponseSchema>;
17
- export type ProjectList = NonNullable<ProjectListResponse['data']>;
18
+ export type ProjectList = z.infer<typeof ProjectListResponse>;
18
19
 
19
20
  /**
20
21
  * List all projects
21
22
  *
22
23
  * @param client
24
+ * @param hasDeployment if true, filter by projects with at least one deployment
23
25
  * @returns
24
26
  */
25
- export async function projectList(client: APIClient): Promise<ProjectList> {
27
+ export async function projectList(
28
+ client: APIClient,
29
+ hasDeployment?: boolean
30
+ ): Promise<ProjectList> {
26
31
  const resp = await client.request<ProjectListResponse>(
27
32
  'GET',
28
- '/cli/project',
33
+ `/cli/project${hasDeployment ? '?hasDeployment=true' : ''}`,
29
34
  ProjectListResponseSchema
30
35
  );
31
36
 
32
- if (resp.data) {
37
+ if (resp.success) {
33
38
  return resp.data;
34
39
  }
35
40
 
36
- throw new Error(resp.message ?? 'failed to list projects');
41
+ throw new Error(resp.message);
37
42
  }
@@ -0,0 +1,55 @@
1
+ import { z } from 'zod';
2
+ import { APIResponseSchema, APIClient } from '../api';
3
+
4
+ const ResourceSpec = z.object({
5
+ type: z.enum(['db', 's3']).describe('the resource type'),
6
+ name: z.string().optional().describe('optional custom name for db'),
7
+ });
8
+
9
+ const CreateResourcesRequest = z.object({
10
+ resources: z.array(ResourceSpec).describe('list of resources to create'),
11
+ });
12
+
13
+ const CreatedResource = z.object({
14
+ type: z.string().describe('the resource type'),
15
+ name: z.string().describe('the resource name'),
16
+ });
17
+
18
+ const CreateResourcesResponse = z.object({
19
+ created: z.array(CreatedResource),
20
+ });
21
+
22
+ const CreateResourcesResponseSchema = APIResponseSchema(CreateResourcesResponse);
23
+
24
+ export type CreateResourcesRequest = z.infer<typeof CreateResourcesRequest>;
25
+ export type CreateResourcesResponse = z.infer<typeof CreateResourcesResponseSchema>;
26
+ export type CreatedResource = z.infer<typeof CreatedResource>;
27
+
28
+ /**
29
+ * Create one or more resources (DB or S3) for an organization in a specific region
30
+ * Requires CLI authentication
31
+ *
32
+ * @param client - Catalyst API client
33
+ * @param orgId - Organization ID
34
+ * @param region - Cloud region
35
+ * @param resources - Array of resources to create
36
+ * @returns
37
+ */
38
+ export async function createResources(
39
+ client: APIClient,
40
+ orgId: string,
41
+ region: string,
42
+ resources: Array<{ type: 'db' | 's3'; name?: string }>
43
+ ): Promise<CreatedResource[]> {
44
+ const resp = await client.request<CreateResourcesResponse, CreateResourcesRequest>(
45
+ 'POST',
46
+ `/resource/2025-11-16/${orgId}/${region}`,
47
+ CreateResourcesResponseSchema,
48
+ { resources },
49
+ CreateResourcesRequest
50
+ );
51
+ if (resp.success) {
52
+ return resp.data.created;
53
+ }
54
+ throw new Error('message' in resp ? resp.message : 'Failed to create resources');
55
+ }
@@ -0,0 +1,49 @@
1
+ import { z } from 'zod';
2
+ import { APIResponseSchema, APIClient } from '../api';
3
+
4
+ const DeleteResourceSpec = z.object({
5
+ type: z.enum(['db', 's3']).describe('the resource type'),
6
+ name: z.string().describe('the resource name (bucket_name for S3, db_name for DB)'),
7
+ });
8
+
9
+ const DeleteResourcesRequest = z.object({
10
+ resources: z.array(DeleteResourceSpec).describe('list of resources to delete'),
11
+ });
12
+
13
+ const DeleteResourcesResponse = z.object({
14
+ deleted: z.array(z.string()).describe('list of deleted resource names'),
15
+ });
16
+
17
+ const DeleteResourcesResponseSchema = APIResponseSchema(DeleteResourcesResponse);
18
+
19
+ export type DeleteResourcesRequest = z.infer<typeof DeleteResourcesRequest>;
20
+ export type DeleteResourcesResponse = z.infer<typeof DeleteResourcesResponseSchema>;
21
+
22
+ /**
23
+ * Delete one or more resources (DB or S3) for an organization in a specific region
24
+ * Requires CLI authentication
25
+ *
26
+ * @param client - Catalyst API client
27
+ * @param orgId - Organization ID
28
+ * @param region - Cloud region
29
+ * @param resources - Array of resources to delete
30
+ * @returns
31
+ */
32
+ export async function deleteResources(
33
+ client: APIClient,
34
+ orgId: string,
35
+ region: string,
36
+ resources: Array<{ type: 'db' | 's3'; name: string }>
37
+ ): Promise<string[]> {
38
+ const resp = await client.request<DeleteResourcesResponse, DeleteResourcesRequest>(
39
+ 'DELETE',
40
+ `/resource/2025-11-16/${orgId}/${region}`,
41
+ DeleteResourcesResponseSchema,
42
+ { resources },
43
+ DeleteResourcesRequest
44
+ );
45
+ if (resp.success) {
46
+ return resp.data.deleted;
47
+ }
48
+ throw new Error('message' in resp ? resp.message : 'Failed to delete resources');
49
+ }
@@ -0,0 +1,4 @@
1
+ export * from './list';
2
+ export * from './resources';
3
+ export * from './create';
4
+ export * from './delete';
@@ -0,0 +1,31 @@
1
+ import { z } from 'zod';
2
+ import { APIResponseSchema, APIClient } from '../api';
3
+
4
+ const ListRegionsResponse = z.array(
5
+ z.object({
6
+ region: z.string().describe('the region identifier'),
7
+ description: z.string().describe('the human-readable description of the region'),
8
+ })
9
+ );
10
+ const ListRegionsResponseSchema = APIResponseSchema(ListRegionsResponse);
11
+
12
+ export type ListRegionsResponse = z.infer<typeof ListRegionsResponseSchema>;
13
+ export type RegionList = z.infer<typeof ListRegionsResponse>;
14
+
15
+ /**
16
+ * List all available cloud regions
17
+ *
18
+ * @param client
19
+ * @returns
20
+ */
21
+ export async function listRegions(client: APIClient): Promise<RegionList> {
22
+ const resp = await client.request<ListRegionsResponse>(
23
+ 'GET',
24
+ '/cli/region',
25
+ ListRegionsResponseSchema
26
+ );
27
+ if (resp.success) {
28
+ return resp.data;
29
+ }
30
+ throw new Error(resp.message);
31
+ }
@@ -0,0 +1,51 @@
1
+ import { z } from 'zod';
2
+ import { APIResponseSchema, APIClient } from '../api';
3
+
4
+ const ResourceListResponse = z.object({
5
+ s3: z.array(
6
+ z.object({
7
+ bucket_name: z.string().describe('the S3 bucket name'),
8
+ access_key: z.string().nullable().optional().describe('the S3 access key'),
9
+ secret_key: z.string().nullable().optional().describe('the S3 secret key'),
10
+ region: z.string().nullable().optional().describe('the S3 region'),
11
+ endpoint: z.string().nullable().optional().describe('the S3 endpoint'),
12
+ cname: z.string().nullable().optional().describe('the S3 CNAME'),
13
+ })
14
+ ),
15
+ db: z.array(
16
+ z.object({
17
+ name: z.string().describe('the database name'),
18
+ username: z.string().nullable().optional().describe('the database username'),
19
+ password: z.string().nullable().optional().describe('the database password'),
20
+ url: z.string().nullable().optional().describe('the full database connection URL'),
21
+ })
22
+ ),
23
+ });
24
+ const ResourceListResponseSchema = APIResponseSchema(ResourceListResponse);
25
+
26
+ export type ResourceListResponse = z.infer<typeof ResourceListResponseSchema>;
27
+ export type ResourceList = z.infer<typeof ResourceListResponse>;
28
+
29
+ /**
30
+ * List all resources for a given organization and region
31
+ *
32
+ * @param client
33
+ * @param orgId
34
+ * @param region
35
+ * @returns
36
+ */
37
+ export async function listResources(
38
+ client: APIClient,
39
+ orgId: string,
40
+ region: string
41
+ ): Promise<ResourceList> {
42
+ const resp = await client.request<ResourceListResponse>(
43
+ 'GET',
44
+ `/resource/2025-03-17/${orgId}/${region}`,
45
+ ResourceListResponseSchema
46
+ );
47
+ if (resp.success) {
48
+ return resp.data;
49
+ }
50
+ throw new Error(resp.message);
51
+ }