@agentuity/server 0.0.60 → 0.0.61

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 (133) hide show
  1. package/dist/api/api.d.ts +87 -23
  2. package/dist/api/api.d.ts.map +1 -1
  3. package/dist/api/api.js +87 -47
  4. package/dist/api/api.js.map +1 -1
  5. package/dist/api/apikey/create.d.ts.map +1 -1
  6. package/dist/api/apikey/create.js +2 -1
  7. package/dist/api/apikey/create.js.map +1 -1
  8. package/dist/api/apikey/delete.d.ts.map +1 -1
  9. package/dist/api/apikey/delete.js +2 -1
  10. package/dist/api/apikey/delete.js.map +1 -1
  11. package/dist/api/apikey/get.d.ts.map +1 -1
  12. package/dist/api/apikey/get.js +2 -1
  13. package/dist/api/apikey/get.js.map +1 -1
  14. package/dist/api/apikey/list.d.ts.map +1 -1
  15. package/dist/api/apikey/list.js +2 -1
  16. package/dist/api/apikey/list.js.map +1 -1
  17. package/dist/api/apikey/util.d.ts +23 -0
  18. package/dist/api/apikey/util.d.ts.map +1 -0
  19. package/dist/api/apikey/util.js +3 -0
  20. package/dist/api/apikey/util.js.map +1 -0
  21. package/dist/api/org/list.d.ts.map +1 -1
  22. package/dist/api/org/list.js +2 -1
  23. package/dist/api/org/list.js.map +1 -1
  24. package/dist/api/org/util.d.ts +23 -0
  25. package/dist/api/org/util.d.ts.map +1 -0
  26. package/dist/api/org/util.js +3 -0
  27. package/dist/api/org/util.js.map +1 -0
  28. package/dist/api/project/agent.d.ts.map +1 -1
  29. package/dist/api/project/agent.js +4 -3
  30. package/dist/api/project/agent.js.map +1 -1
  31. package/dist/api/project/create.d.ts.map +1 -1
  32. package/dist/api/project/create.js +2 -1
  33. package/dist/api/project/create.js.map +1 -1
  34. package/dist/api/project/delete.d.ts.map +1 -1
  35. package/dist/api/project/delete.js +2 -1
  36. package/dist/api/project/delete.js.map +1 -1
  37. package/dist/api/project/deploy.d.ts.map +1 -1
  38. package/dist/api/project/deploy.js +4 -3
  39. package/dist/api/project/deploy.js.map +1 -1
  40. package/dist/api/project/deployment.d.ts.map +1 -1
  41. package/dist/api/project/deployment.js +7 -6
  42. package/dist/api/project/deployment.js.map +1 -1
  43. package/dist/api/project/env-delete.d.ts.map +1 -1
  44. package/dist/api/project/env-delete.js +2 -1
  45. package/dist/api/project/env-delete.js.map +1 -1
  46. package/dist/api/project/env-update.d.ts.map +1 -1
  47. package/dist/api/project/env-update.js +2 -1
  48. package/dist/api/project/env-update.js.map +1 -1
  49. package/dist/api/project/exists.d.ts.map +1 -1
  50. package/dist/api/project/exists.js +6 -5
  51. package/dist/api/project/exists.js.map +1 -1
  52. package/dist/api/project/get.d.ts.map +1 -1
  53. package/dist/api/project/get.js +2 -1
  54. package/dist/api/project/get.js.map +1 -1
  55. package/dist/api/project/list.d.ts.map +1 -1
  56. package/dist/api/project/list.js +2 -1
  57. package/dist/api/project/list.js.map +1 -1
  58. package/dist/api/project/util.d.ts +49 -0
  59. package/dist/api/project/util.d.ts.map +1 -0
  60. package/dist/api/project/util.js +5 -0
  61. package/dist/api/project/util.js.map +1 -0
  62. package/dist/api/region/create.d.ts.map +1 -1
  63. package/dist/api/region/create.js +4 -1
  64. package/dist/api/region/create.js.map +1 -1
  65. package/dist/api/region/delete.d.ts.map +1 -1
  66. package/dist/api/region/delete.js +2 -1
  67. package/dist/api/region/delete.js.map +1 -1
  68. package/dist/api/region/list.d.ts.map +1 -1
  69. package/dist/api/region/list.js +2 -1
  70. package/dist/api/region/list.js.map +1 -1
  71. package/dist/api/region/resources.d.ts.map +1 -1
  72. package/dist/api/region/resources.js +2 -1
  73. package/dist/api/region/resources.js.map +1 -1
  74. package/dist/api/region/util.d.ts +23 -0
  75. package/dist/api/region/util.d.ts.map +1 -0
  76. package/dist/api/region/util.js +3 -0
  77. package/dist/api/region/util.js.map +1 -0
  78. package/dist/api/session/get.d.ts.map +1 -1
  79. package/dist/api/session/get.js +2 -1
  80. package/dist/api/session/get.js.map +1 -1
  81. package/dist/api/session/list.d.ts.map +1 -1
  82. package/dist/api/session/list.js +2 -1
  83. package/dist/api/session/list.js.map +1 -1
  84. package/dist/api/session/logs.d.ts.map +1 -1
  85. package/dist/api/session/logs.js +2 -1
  86. package/dist/api/session/logs.js.map +1 -1
  87. package/dist/api/session/util.d.ts +23 -0
  88. package/dist/api/session/util.d.ts.map +1 -0
  89. package/dist/api/session/util.js +3 -0
  90. package/dist/api/session/util.js.map +1 -0
  91. package/dist/api/user/util.d.ts +23 -0
  92. package/dist/api/user/util.d.ts.map +1 -0
  93. package/dist/api/user/util.js +3 -0
  94. package/dist/api/user/util.js.map +1 -0
  95. package/dist/api/user/whoami.d.ts.map +1 -1
  96. package/dist/api/user/whoami.js +2 -1
  97. package/dist/api/user/whoami.js.map +1 -1
  98. package/dist/server.d.ts +1 -1
  99. package/dist/server.d.ts.map +1 -1
  100. package/dist/server.js +4 -4
  101. package/dist/server.js.map +1 -1
  102. package/package.json +2 -2
  103. package/src/api/api.ts +127 -78
  104. package/src/api/apikey/create.ts +2 -1
  105. package/src/api/apikey/delete.ts +2 -1
  106. package/src/api/apikey/get.ts +2 -1
  107. package/src/api/apikey/list.ts +2 -1
  108. package/src/api/apikey/util.ts +3 -0
  109. package/src/api/org/list.ts +2 -1
  110. package/src/api/org/util.ts +3 -0
  111. package/src/api/project/agent.ts +4 -3
  112. package/src/api/project/create.ts +2 -1
  113. package/src/api/project/delete.ts +2 -1
  114. package/src/api/project/deploy.ts +4 -3
  115. package/src/api/project/deployment.ts +7 -6
  116. package/src/api/project/env-delete.ts +2 -1
  117. package/src/api/project/env-update.ts +2 -1
  118. package/src/api/project/exists.ts +5 -4
  119. package/src/api/project/get.ts +2 -1
  120. package/src/api/project/list.ts +2 -1
  121. package/src/api/project/util.ts +5 -0
  122. package/src/api/region/create.ts +4 -1
  123. package/src/api/region/delete.ts +2 -1
  124. package/src/api/region/list.ts +2 -1
  125. package/src/api/region/resources.ts +2 -1
  126. package/src/api/region/util.ts +3 -0
  127. package/src/api/session/get.ts +2 -1
  128. package/src/api/session/list.ts +2 -1
  129. package/src/api/session/logs.ts +2 -1
  130. package/src/api/session/util.ts +3 -0
  131. package/src/api/user/util.ts +3 -0
  132. package/src/api/user/whoami.ts +2 -1
  133. package/src/server.ts +5 -5
package/src/api/api.ts CHANGED
@@ -10,17 +10,7 @@
10
10
 
11
11
  import { z } from 'zod';
12
12
  import type { Logger } from '@agentuity/core';
13
-
14
- export interface APIErrorResponse {
15
- success: boolean;
16
- code?: string;
17
- message?: string;
18
- error?: {
19
- name?: string;
20
- issues?: z.ZodIssue[];
21
- };
22
- details?: Record<string, unknown>;
23
- }
13
+ import { StructuredError } from '@agentuity/core';
24
14
 
25
15
  export interface APIClientConfig {
26
16
  skipVersionCheck?: boolean;
@@ -29,36 +19,75 @@ export interface APIClientConfig {
29
19
  retryDelayMs?: number;
30
20
  }
31
21
 
32
- export class ValidationError extends Error {
33
- public url: string;
34
- constructor(
35
- url: string,
36
- message: string,
37
- public issues: z.ZodIssue[]
38
- ) {
39
- super(message);
40
- this.url = url;
41
- this.name = 'ValidationError';
42
- }
43
- }
44
-
45
- export class UpgradeRequiredError extends Error {
46
- constructor(message: string) {
47
- super(message);
48
- this.name = 'UpgradeRequiredError';
49
- }
50
- }
51
-
52
- export class APIError extends Error {
53
- constructor(
54
- message: string,
55
- public status: number,
56
- public code?: string
57
- ) {
58
- super(message);
59
- this.name = 'APIError';
60
- }
61
- }
22
+ const ZodIssuesSchema = z.array(
23
+ z.object({
24
+ code: z.string(),
25
+ input: z.unknown().optional(),
26
+ path: z.array(z.union([z.string(), z.number()])),
27
+ message: z.string(),
28
+ })
29
+ );
30
+
31
+ export type IssuesType = z.infer<typeof ZodIssuesSchema>;
32
+
33
+ const toIssues = (issues: z.core.$ZodIssue[]): IssuesType => {
34
+ return issues.map((issue) => ({
35
+ code: issue.code,
36
+ input: issue.input,
37
+ path: issue.path.map((x) => (typeof x === 'number' ? x : String(x))),
38
+ message: issue.message,
39
+ }));
40
+ };
41
+
42
+ const APIErrorSchema = z.object({
43
+ success: z.boolean(),
44
+ code: z.string().optional(),
45
+ message: z.string().optional(),
46
+ error: z.object({
47
+ name: z.string().optional(),
48
+ issues: ZodIssuesSchema.optional(),
49
+ }),
50
+ details: z.record(z.string(), z.unknown()).optional(),
51
+ });
52
+
53
+ export const APIError = StructuredError(
54
+ 'APIErrorResponse',
55
+ 'The API encountered an unexpected error attempting to reach the service.'
56
+ )<{
57
+ url: string;
58
+ error?: string;
59
+ status: number;
60
+ sessionId?: string | null;
61
+ }>();
62
+
63
+ export const ValidationInputError = StructuredError(
64
+ 'ValidationInputError',
65
+ 'There was an error validating the API input data.'
66
+ )<{
67
+ url: string;
68
+ issues: IssuesType;
69
+ }>();
70
+
71
+ export const ValidationOutputError = StructuredError(
72
+ 'ValidationOutputError',
73
+ 'There was an unexpected error validating the API response data.'
74
+ )<{
75
+ url: string;
76
+ issues: IssuesType;
77
+ sessionId?: string | null;
78
+ }>();
79
+
80
+ export const UpgradeRequiredError = StructuredError(
81
+ 'UpgradeRequiredError',
82
+ 'Upgrade required to continue. Please see https://agentuity.dev/CLI/installation to download the latest version of the SDK.'
83
+ )<{
84
+ sessionId?: string | null;
85
+ }>();
86
+
87
+ export const MaxRetriesError = StructuredError(
88
+ 'MaxRetriesError',
89
+ 'Max Retries attempted and continued failures exhausted.'
90
+ );
62
91
 
63
92
  export class APIClient {
64
93
  #baseUrl: string;
@@ -101,11 +130,10 @@ export class APIClient {
101
130
  if (body !== undefined && bodySchema) {
102
131
  const validationResult = bodySchema.safeParse(body);
103
132
  if (!validationResult.success) {
104
- throw new ValidationError(
105
- endpoint,
106
- 'Request body validation failed',
107
- validationResult.error.issues
108
- );
133
+ throw new ValidationInputError({
134
+ url: endpoint,
135
+ issues: toIssues(validationResult.error.issues),
136
+ });
109
137
  }
110
138
  }
111
139
 
@@ -133,11 +161,11 @@ export class APIClient {
133
161
  // Validate response
134
162
  const validationResult = responseSchema.safeParse(data);
135
163
  if (!validationResult.success) {
136
- throw new ValidationError(
137
- endpoint,
138
- 'Response validation failed',
139
- validationResult.error.issues
140
- );
164
+ throw new ValidationOutputError({
165
+ url: endpoint,
166
+ issues: toIssues(validationResult.error.issues),
167
+ sessionId: response.headers.get('x-session-id'),
168
+ });
141
169
  }
142
170
 
143
171
  return validationResult.data;
@@ -167,17 +195,35 @@ export class APIClient {
167
195
  headers['Authorization'] = `Bearer ${this.#apiKey}`;
168
196
  }
169
197
 
170
- // Log request body for debugging deployment issues
171
- if (body !== undefined && endpoint.includes('/deploy/')) {
172
- this.#logger.debug('Request body: %s', JSON.stringify(body, null, 2));
198
+ let response: Response;
199
+
200
+ try {
201
+ response = await fetch(url, {
202
+ method,
203
+ headers,
204
+ body: body !== undefined ? JSON.stringify(body) : undefined,
205
+ });
206
+ } catch (ex) {
207
+ const _ex = ex as { code?: string; name: string };
208
+ let retryable = false;
209
+ // Check for retryable network errors
210
+ if (_ex.code === 'ConnectionRefused' || _ex.code === 'ECONNREFUSED') {
211
+ retryable = true;
212
+ } else if (_ex.name === 'TypeError' || ex instanceof TypeError) {
213
+ // TypeError from fetch typically indicates network issues
214
+ retryable = true;
215
+ }
216
+ if (retryable) {
217
+ response = new Response(null, { status: 503 });
218
+ } else {
219
+ throw new APIError({
220
+ url,
221
+ status: 0,
222
+ cause: ex,
223
+ });
224
+ }
173
225
  }
174
226
 
175
- const response = await fetch(url, {
176
- method,
177
- headers,
178
- body: body !== undefined ? JSON.stringify(body) : undefined,
179
- });
180
-
181
227
  // Check if we should retry on specific status codes (409, 501, 503)
182
228
  const retryableStatuses = [409, 501, 503];
183
229
  if (retryableStatuses.includes(response.status) && attempt < maxRetries) {
@@ -206,16 +252,18 @@ export class APIClient {
206
252
  continue;
207
253
  }
208
254
 
255
+ const sessionId = response.headers.get('x-session-id');
256
+
209
257
  // Handle error responses
210
258
  if (!response.ok) {
211
259
  const responseBody = await response.text();
212
260
 
213
- // Try to parse error response
214
- let errorData: APIErrorResponse | null = null;
261
+ let errorData: z.infer<typeof APIErrorSchema> | undefined;
262
+
215
263
  try {
216
- errorData = JSON.parse(responseBody) as APIErrorResponse;
264
+ errorData = APIErrorSchema.parse(responseBody);
217
265
  } catch {
218
- // Not JSON, ignore
266
+ /** ignore */
219
267
  }
220
268
 
221
269
  // Sanitize headers to avoid leaking API keys
@@ -240,31 +288,32 @@ export class APIClient {
240
288
  this.#logger.debug('Skipping version check (configured to skip)');
241
289
  // Request is still rejected, but throw UpgradeRequiredError so callers
242
290
  // can detect it and handle UI behavior (e.g., suppress banner) based on skip flag
243
- throw new UpgradeRequiredError(
244
- errorData.message ||
245
- 'Version check skipped, but request failed. Try upgrading the client.'
246
- );
291
+ throw new UpgradeRequiredError({ sessionId });
247
292
  }
248
293
 
249
- throw new UpgradeRequiredError(
250
- errorData.message || 'Please upgrade to the latest version'
251
- );
294
+ throw new UpgradeRequiredError({ sessionId });
252
295
  }
253
296
 
254
297
  // Handle Zod validation errors from the API
255
298
  if (errorData?.error?.name === 'ZodError' && errorData.error.issues) {
256
- throw new ValidationError(url, 'API validation failed', errorData.error.issues);
299
+ throw new ValidationOutputError({
300
+ url,
301
+ issues: errorData.error.issues,
302
+ sessionId,
303
+ });
257
304
  }
258
305
 
259
306
  // Throw with message from API if available
260
307
  if (errorData?.message) {
261
- throw new APIError(errorData.message, response.status, errorData.code);
308
+ throw new APIError({
309
+ url,
310
+ status: response.status,
311
+ error: errorData.message,
312
+ sessionId,
313
+ });
262
314
  }
263
315
 
264
- throw new APIError(
265
- `API error: ${response.status} ${response.statusText}`,
266
- response.status
267
- );
316
+ throw new APIError({ url: url, status: response.status, sessionId });
268
317
  }
269
318
 
270
319
  // Successful response; handle empty bodies (e.g., 204 No Content)
@@ -290,7 +339,7 @@ export class APIClient {
290
339
  }
291
340
  }
292
341
 
293
- throw new Error('Max retries exceeded');
342
+ throw new MaxRetriesError();
294
343
  }
295
344
 
296
345
  #isRetryableError(error: unknown): boolean {
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { APIClient, APIResponseSchema } from '../api';
3
+ import { APIKeyResponseError } from './util';
3
4
 
4
5
  const APIKeyCreateResponseSchema = z.object({
5
6
  id: z.string().describe('the API key id'),
@@ -41,5 +42,5 @@ export async function apikeyCreate(
41
42
  return resp.data;
42
43
  }
43
44
 
44
- throw new Error(resp.message);
45
+ throw new APIKeyResponseError({ message: resp.message });
45
46
  }
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { APIClient, APIResponseSchema } from '../api';
3
+ import { APIKeyResponseError } from './util';
3
4
 
4
5
  const APIKeyDeleteResponseSchema = APIResponseSchema(
5
6
  z.number().describe('number of rows affected')
@@ -25,5 +26,5 @@ export async function apikeyDelete(client: APIClient, id: string): Promise<numbe
25
26
  return resp.data;
26
27
  }
27
28
 
28
- throw new Error(resp.message);
29
+ throw new APIKeyResponseError({ message: resp.message });
29
30
  }
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { APIClient, APIResponseSchema } from '../api';
3
+ import { APIKeyResponseError } from './util';
3
4
 
4
5
  const APIKeyDetailSchema = z.object({
5
6
  id: z.string().describe('the API key id'),
@@ -43,5 +44,5 @@ export async function apikeyGet(client: APIClient, id: string): Promise<APIKeyDe
43
44
  return resp.data;
44
45
  }
45
46
 
46
- throw new Error(resp.message);
47
+ throw new APIKeyResponseError({ message: resp.message });
47
48
  }
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { APIClient, APIResponseSchema } from '../api';
3
+ import { APIKeyResponseError } from './util';
3
4
 
4
5
  export const APIKeySchema = z.object({
5
6
  id: z.string().describe('the API key id'),
@@ -59,5 +60,5 @@ export async function apikeyList(
59
60
  return resp.data;
60
61
  }
61
62
 
62
- throw new Error(resp.message);
63
+ throw new APIKeyResponseError({ message: resp.message });
63
64
  }
@@ -0,0 +1,3 @@
1
+ import { StructuredError } from '@agentuity/core';
2
+
3
+ export const APIKeyResponseError = StructuredError('APIKeyResponseError');
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { APIResponseSchema, APIClient } from '../api';
3
+ import { OrgResponseError } from './util';
3
4
 
4
5
  const ListOrganizationsResponse = z.array(
5
6
  z.object({
@@ -27,5 +28,5 @@ export async function listOrganizations(client: APIClient): Promise<Organization
27
28
  if (resp.success) {
28
29
  return resp.data;
29
30
  }
30
- throw new Error(resp.message);
31
+ throw new OrgResponseError({ message: resp.message });
31
32
  }
@@ -0,0 +1,3 @@
1
+ import { StructuredError } from '@agentuity/core';
2
+
3
+ export const OrgResponseError = StructuredError('OrgResponseError');
@@ -1,6 +1,7 @@
1
1
  import { z } from 'zod';
2
2
  import type { APIClient } from '../api';
3
3
  import { APIResponseSchema } from '../api';
4
+ import { AgentNotFoundError, ProjectResponseError } from './util';
4
5
 
5
6
  const AgentSchema = z.object({
6
7
  id: z.string().describe('Agent ID (same as identifier)'),
@@ -54,7 +55,7 @@ export async function projectAgentList(
54
55
  if (resp.success) {
55
56
  return resp.data;
56
57
  }
57
- throw new Error(resp.message);
58
+ throw new ProjectResponseError({ message: resp.message });
58
59
  }
59
60
 
60
61
  /**
@@ -73,9 +74,9 @@ export async function projectAgentGet(
73
74
 
74
75
  if (resp.success) {
75
76
  if (resp.data.length === 0) {
76
- throw new Error(`Agent not found: ${agentId}`);
77
+ throw new AgentNotFoundError({ id: agentId, message: `Agent not found: ${agentId}` });
77
78
  }
78
79
  return resp.data[0];
79
80
  }
80
- throw new Error(resp.message);
81
+ throw new ProjectResponseError({ message: resp.message });
81
82
  }
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { APIClient, APIResponseSchema } from '../api';
3
+ import { ProjectResponseError } from './util';
3
4
 
4
5
  const CreateProjectRequestSchema = z.object({
5
6
  name: z.string().max(255).min(1).describe('the name of the new project'),
@@ -39,5 +40,5 @@ export async function projectCreate(
39
40
  if (resp.success) {
40
41
  return resp.data;
41
42
  }
42
- throw new Error(resp.message);
43
+ throw new ProjectResponseError({ message: resp.message });
43
44
  }
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { APIClient, APIResponseSchema } from '../api';
3
+ import { ProjectResponseError } from './util';
3
4
 
4
5
  const ProjectDeleteRequestSchema = z.object({ ids: z.array(z.string()) });
5
6
  const ProjectDeleteResponseSchema = APIResponseSchema(z.array(z.string()));
@@ -20,5 +21,5 @@ export async function projectDelete(client: APIClient, ...ids: string[]): Promis
20
21
  return resp.data;
21
22
  }
22
23
 
23
- throw new Error(resp.message ?? 'failed to delete project');
24
+ throw new ProjectResponseError({ message: resp.message ?? 'failed to delete project' });
24
25
  }
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { type APIClient, APIResponseSchema } from '../api';
3
+ import { ProjectResponseError } from './util';
3
4
 
4
5
  export const Resources = z.object({
5
6
  memory: z.string().default('500Mi').describe('The memory requirements'),
@@ -177,7 +178,7 @@ export async function projectDeploymentCreate(
177
178
  if (resp.success) {
178
179
  return resp.data;
179
180
  }
180
- throw new Error(resp.message);
181
+ throw new ProjectResponseError({ message: resp.message });
181
182
  }
182
183
 
183
184
  const DeploymentInstructionsObject = z.object({
@@ -217,7 +218,7 @@ export async function projectDeploymentUpdate(
217
218
  if (resp.success) {
218
219
  return resp.data;
219
220
  }
220
- throw new Error(resp.message);
221
+ throw new ProjectResponseError({ message: resp.message });
221
222
  }
222
223
 
223
224
  const DeploymentCompleteObject = z.object({
@@ -254,5 +255,5 @@ export async function projectDeploymentComplete(
254
255
  if (resp.success) {
255
256
  return resp.data;
256
257
  }
257
- throw new Error(resp.message);
258
+ throw new ProjectResponseError({ message: resp.message });
258
259
  }
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { type APIClient, APIResponseSchema, APIResponseSchemaOptionalData } from '../api';
3
+ import { ProjectResponseError } from './util';
3
4
 
4
5
  // Simplified metadata schema for the client
5
6
  const DeploymentMetadataSchema = z.object({
@@ -69,7 +70,7 @@ export async function projectDeploymentList(
69
70
  if (resp.success) {
70
71
  return resp.data;
71
72
  }
72
- throw new Error(resp.message);
73
+ throw new ProjectResponseError({ message: resp.message });
73
74
  }
74
75
 
75
76
  export async function projectDeploymentGet(
@@ -85,7 +86,7 @@ export async function projectDeploymentGet(
85
86
  if (resp.success) {
86
87
  return resp.data;
87
88
  }
88
- throw new Error(resp.message);
89
+ throw new ProjectResponseError({ message: resp.message });
89
90
  }
90
91
 
91
92
  export async function projectDeploymentDelete(
@@ -99,7 +100,7 @@ export async function projectDeploymentDelete(
99
100
  DeploymentActionResponseSchema
100
101
  );
101
102
  if (!resp.success) {
102
- throw new Error(resp.message);
103
+ throw new ProjectResponseError({ message: resp.message });
103
104
  }
104
105
  }
105
106
 
@@ -114,7 +115,7 @@ export async function projectDeploymentRollback(
114
115
  DeploymentActionResponseSchema
115
116
  );
116
117
  if (!resp.success) {
117
- throw new Error(resp.message);
118
+ throw new ProjectResponseError({ message: resp.message });
118
119
  }
119
120
  }
120
121
 
@@ -128,7 +129,7 @@ export async function projectDeploymentUndeploy(
128
129
  DeploymentActionResponseSchema
129
130
  );
130
131
  if (!resp.success) {
131
- throw new Error(resp.message);
132
+ throw new ProjectResponseError({ message: resp.message });
132
133
  }
133
134
  }
134
135
 
@@ -159,5 +160,5 @@ export async function projectDeploymentLogs(
159
160
  if (resp.success) {
160
161
  return resp.data;
161
162
  }
162
- throw new Error(resp.message);
163
+ throw new ProjectResponseError({ message: resp.message });
163
164
  }
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { APIClient, APIResponseSchemaNoData } from '../api';
3
+ import { ProjectResponseError } from './util';
3
4
 
4
5
  const _ProjectEnvDeleteRequestSchema = z.object({
5
6
  id: z.string().describe('the project id'),
@@ -33,7 +34,7 @@ export async function projectEnvDelete(
33
34
  );
34
35
 
35
36
  if (!resp.success) {
36
- throw new Error(resp.message ?? 'failed to delete project env');
37
+ throw new ProjectResponseError({ message: resp.message ?? 'failed to delete project env' });
37
38
  }
38
39
 
39
40
  // Delete operations don't return data, success is sufficient
@@ -2,6 +2,7 @@ import { z } from 'zod';
2
2
  import { APIClient, APIResponseSchema } from '../api';
3
3
  import type { Project } from './get';
4
4
  import { projectGet } from './get';
5
+ import { ProjectResponseError } from './util';
5
6
 
6
7
  const _ProjectEnvUpdateRequestSchema = z.object({
7
8
  id: z.string().describe('the project id'),
@@ -46,7 +47,7 @@ export async function projectEnvUpdate(
46
47
  );
47
48
 
48
49
  if (!resp.success) {
49
- throw new Error(resp.message ?? 'failed to update project env');
50
+ throw new ProjectResponseError({ message: resp.message ?? 'failed to update project env' });
50
51
  }
51
52
 
52
53
  if (resp.data) {
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { APIClient, APIResponseSchema, APIError } from '../api';
3
+ import { ProjectResponseError } from './util';
3
4
 
4
5
  const _ProjectExistsRequestSchema = z.object({
5
6
  name: z.string().max(255).min(1).describe('the name of the new project'),
@@ -42,16 +43,16 @@ export async function projectExists(
42
43
  return false;
43
44
  } catch (ex) {
44
45
  const _ex = ex as Error;
45
- if (_ex.name === 'APIError') {
46
- const apiError = _ex as APIError;
47
- switch (apiError.status) {
46
+ if (_ex instanceof APIError) {
47
+ switch (_ex.status) {
48
48
  case 409:
49
49
  return true;
50
50
  case 422:
51
51
  return false;
52
52
  default:
53
+ break;
53
54
  }
54
55
  }
55
- throw ex;
56
+ throw new ProjectResponseError({ cause: ex });
56
57
  }
57
58
  }
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { APIClient, APIResponseSchema } from '../api';
3
+ import { ProjectResponseError } from './util';
3
4
 
4
5
  const _ProjectGetRequestSchema = z.object({
5
6
  id: z.string().describe('the project id'),
@@ -32,5 +33,5 @@ export async function projectGet(client: APIClient, request: ProjectGetRequest):
32
33
  return resp.data;
33
34
  }
34
35
 
35
- throw new Error(resp.message);
36
+ throw new ProjectResponseError({ message: resp.message });
36
37
  }
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { APIClient, APIResponseSchema } from '../api';
3
+ import { ProjectResponseError } from './util';
3
4
 
4
5
  const ProjectListResponse = z.array(
5
6
  z.object({
@@ -38,5 +39,5 @@ export async function projectList(
38
39
  return resp.data;
39
40
  }
40
41
 
41
- throw new Error(resp.message);
42
+ throw new ProjectResponseError({ message: resp.message });
42
43
  }
@@ -0,0 +1,5 @@
1
+ import { StructuredError } from '@agentuity/core';
2
+
3
+ export const ProjectResponseError = StructuredError('ProjectResponseError');
4
+ export const ProjectNotFoundError = StructuredError('ProjectNotFoundError')<{ id: string }>();
5
+ export const AgentNotFoundError = StructuredError('AgentNotFoundError')<{ id: string }>();
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { APIResponseSchema, APIClient } from '../api';
3
+ import { RegionResponseError } from './util';
3
4
 
4
5
  const ResourceSpec = z.object({
5
6
  type: z.enum(['db', 's3']).describe('the resource type'),
@@ -51,5 +52,7 @@ export async function createResources(
51
52
  if (resp.success) {
52
53
  return resp.data.created;
53
54
  }
54
- throw new Error('message' in resp ? resp.message : 'Failed to create resources');
55
+ throw new RegionResponseError({
56
+ message: resp.message,
57
+ });
55
58
  }
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { APIResponseSchema, APIClient } from '../api';
3
+ import { RegionResponseError } from './util';
3
4
 
4
5
  const DeleteResourceSpec = z.object({
5
6
  type: z.enum(['db', 's3']).describe('the resource type'),
@@ -45,5 +46,5 @@ export async function deleteResources(
45
46
  if (resp.success) {
46
47
  return resp.data.deleted;
47
48
  }
48
- throw new Error('message' in resp ? resp.message : 'Failed to delete resources');
49
+ throw new RegionResponseError({ message: resp.message });
49
50
  }
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { APIResponseSchema, APIClient } from '../api';
3
+ import { RegionResponseError } from './util';
3
4
 
4
5
  const ListRegionsResponse = z.array(
5
6
  z.object({
@@ -27,5 +28,5 @@ export async function listRegions(client: APIClient): Promise<RegionList> {
27
28
  if (resp.success) {
28
29
  return resp.data;
29
30
  }
30
- throw new Error(resp.message);
31
+ throw new RegionResponseError({ message: resp.message });
31
32
  }
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { APIResponseSchema, APIClient } from '../api';
3
+ import { RegionResponseError } from './util';
3
4
 
4
5
  const ResourceListResponse = z.object({
5
6
  s3: z.array(
@@ -47,5 +48,5 @@ export async function listResources(
47
48
  if (resp.success) {
48
49
  return resp.data;
49
50
  }
50
- throw new Error(resp.message);
51
+ throw new RegionResponseError({ message: resp.message });
51
52
  }
@@ -0,0 +1,3 @@
1
+ import { StructuredError } from '@agentuity/core';
2
+
3
+ export const RegionResponseError = StructuredError('RegionResponseError');