@agentuity/server 0.0.60 → 0.0.62

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 (165) 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/index.d.ts +1 -0
  22. package/dist/api/index.d.ts.map +1 -1
  23. package/dist/api/index.js +1 -0
  24. package/dist/api/index.js.map +1 -1
  25. package/dist/api/org/list.d.ts.map +1 -1
  26. package/dist/api/org/list.js +2 -1
  27. package/dist/api/org/list.js.map +1 -1
  28. package/dist/api/org/util.d.ts +23 -0
  29. package/dist/api/org/util.d.ts.map +1 -0
  30. package/dist/api/org/util.js +3 -0
  31. package/dist/api/org/util.js.map +1 -0
  32. package/dist/api/project/agent.d.ts.map +1 -1
  33. package/dist/api/project/agent.js +4 -3
  34. package/dist/api/project/agent.js.map +1 -1
  35. package/dist/api/project/create.d.ts.map +1 -1
  36. package/dist/api/project/create.js +2 -1
  37. package/dist/api/project/create.js.map +1 -1
  38. package/dist/api/project/delete.d.ts.map +1 -1
  39. package/dist/api/project/delete.js +2 -1
  40. package/dist/api/project/delete.js.map +1 -1
  41. package/dist/api/project/deploy.d.ts.map +1 -1
  42. package/dist/api/project/deploy.js +4 -3
  43. package/dist/api/project/deploy.js.map +1 -1
  44. package/dist/api/project/deployment.d.ts.map +1 -1
  45. package/dist/api/project/deployment.js +7 -6
  46. package/dist/api/project/deployment.js.map +1 -1
  47. package/dist/api/project/env-delete.d.ts.map +1 -1
  48. package/dist/api/project/env-delete.js +2 -1
  49. package/dist/api/project/env-delete.js.map +1 -1
  50. package/dist/api/project/env-update.d.ts.map +1 -1
  51. package/dist/api/project/env-update.js +2 -1
  52. package/dist/api/project/env-update.js.map +1 -1
  53. package/dist/api/project/exists.d.ts.map +1 -1
  54. package/dist/api/project/exists.js +6 -5
  55. package/dist/api/project/exists.js.map +1 -1
  56. package/dist/api/project/get.d.ts.map +1 -1
  57. package/dist/api/project/get.js +2 -1
  58. package/dist/api/project/get.js.map +1 -1
  59. package/dist/api/project/list.d.ts.map +1 -1
  60. package/dist/api/project/list.js +2 -1
  61. package/dist/api/project/list.js.map +1 -1
  62. package/dist/api/project/util.d.ts +49 -0
  63. package/dist/api/project/util.d.ts.map +1 -0
  64. package/dist/api/project/util.js +5 -0
  65. package/dist/api/project/util.js.map +1 -0
  66. package/dist/api/region/create.d.ts.map +1 -1
  67. package/dist/api/region/create.js +4 -1
  68. package/dist/api/region/create.js.map +1 -1
  69. package/dist/api/region/delete.d.ts.map +1 -1
  70. package/dist/api/region/delete.js +2 -1
  71. package/dist/api/region/delete.js.map +1 -1
  72. package/dist/api/region/list.d.ts.map +1 -1
  73. package/dist/api/region/list.js +2 -1
  74. package/dist/api/region/list.js.map +1 -1
  75. package/dist/api/region/resources.d.ts.map +1 -1
  76. package/dist/api/region/resources.js +2 -1
  77. package/dist/api/region/resources.js.map +1 -1
  78. package/dist/api/region/util.d.ts +23 -0
  79. package/dist/api/region/util.d.ts.map +1 -0
  80. package/dist/api/region/util.js +3 -0
  81. package/dist/api/region/util.js.map +1 -0
  82. package/dist/api/session/get.d.ts +1 -0
  83. package/dist/api/session/get.d.ts.map +1 -1
  84. package/dist/api/session/get.js +3 -1
  85. package/dist/api/session/get.js.map +1 -1
  86. package/dist/api/session/list.d.ts +3 -0
  87. package/dist/api/session/list.d.ts.map +1 -1
  88. package/dist/api/session/list.js +3 -1
  89. package/dist/api/session/list.js.map +1 -1
  90. package/dist/api/session/logs.d.ts.map +1 -1
  91. package/dist/api/session/logs.js +2 -1
  92. package/dist/api/session/logs.js.map +1 -1
  93. package/dist/api/session/util.d.ts +23 -0
  94. package/dist/api/session/util.d.ts.map +1 -0
  95. package/dist/api/session/util.js +3 -0
  96. package/dist/api/session/util.js.map +1 -0
  97. package/dist/api/thread/delete.d.ts +16 -0
  98. package/dist/api/thread/delete.d.ts.map +1 -0
  99. package/dist/api/thread/delete.js +21 -0
  100. package/dist/api/thread/delete.js.map +1 -0
  101. package/dist/api/thread/get.d.ts +18 -0
  102. package/dist/api/thread/get.d.ts.map +1 -0
  103. package/dist/api/thread/get.js +23 -0
  104. package/dist/api/thread/get.js.map +1 -0
  105. package/dist/api/thread/index.d.ts +5 -0
  106. package/dist/api/thread/index.d.ts.map +1 -0
  107. package/dist/api/thread/index.js +5 -0
  108. package/dist/api/thread/index.js.map +1 -0
  109. package/dist/api/thread/list.d.ts +59 -0
  110. package/dist/api/thread/list.d.ts.map +1 -0
  111. package/dist/api/thread/list.js +38 -0
  112. package/dist/api/thread/list.js.map +1 -0
  113. package/dist/api/thread/util.d.ts +23 -0
  114. package/dist/api/thread/util.d.ts.map +1 -0
  115. package/dist/api/thread/util.js +3 -0
  116. package/dist/api/thread/util.js.map +1 -0
  117. package/dist/api/user/util.d.ts +23 -0
  118. package/dist/api/user/util.d.ts.map +1 -0
  119. package/dist/api/user/util.js +3 -0
  120. package/dist/api/user/util.js.map +1 -0
  121. package/dist/api/user/whoami.d.ts.map +1 -1
  122. package/dist/api/user/whoami.js +2 -1
  123. package/dist/api/user/whoami.js.map +1 -1
  124. package/dist/server.d.ts +1 -1
  125. package/dist/server.d.ts.map +1 -1
  126. package/dist/server.js +4 -4
  127. package/dist/server.js.map +1 -1
  128. package/package.json +2 -2
  129. package/src/api/api.ts +127 -78
  130. package/src/api/apikey/create.ts +2 -1
  131. package/src/api/apikey/delete.ts +2 -1
  132. package/src/api/apikey/get.ts +2 -1
  133. package/src/api/apikey/list.ts +2 -1
  134. package/src/api/apikey/util.ts +3 -0
  135. package/src/api/index.ts +1 -0
  136. package/src/api/org/list.ts +2 -1
  137. package/src/api/org/util.ts +3 -0
  138. package/src/api/project/agent.ts +4 -3
  139. package/src/api/project/create.ts +2 -1
  140. package/src/api/project/delete.ts +2 -1
  141. package/src/api/project/deploy.ts +4 -3
  142. package/src/api/project/deployment.ts +7 -6
  143. package/src/api/project/env-delete.ts +2 -1
  144. package/src/api/project/env-update.ts +2 -1
  145. package/src/api/project/exists.ts +5 -4
  146. package/src/api/project/get.ts +2 -1
  147. package/src/api/project/list.ts +2 -1
  148. package/src/api/project/util.ts +5 -0
  149. package/src/api/region/create.ts +4 -1
  150. package/src/api/region/delete.ts +2 -1
  151. package/src/api/region/list.ts +2 -1
  152. package/src/api/region/resources.ts +2 -1
  153. package/src/api/region/util.ts +3 -0
  154. package/src/api/session/get.ts +4 -1
  155. package/src/api/session/list.ts +3 -1
  156. package/src/api/session/logs.ts +2 -1
  157. package/src/api/session/util.ts +3 -0
  158. package/src/api/thread/delete.ts +31 -0
  159. package/src/api/thread/get.ts +36 -0
  160. package/src/api/thread/index.ts +4 -0
  161. package/src/api/thread/list.ts +60 -0
  162. package/src/api/thread/util.ts +3 -0
  163. package/src/api/user/util.ts +3 -0
  164. package/src/api/user/whoami.ts +2 -1
  165. package/src/server.ts +5 -5
@@ -0,0 +1,23 @@
1
+ export declare const UserResponseError: {
2
+ new (args?: {
3
+ message?: string;
4
+ cause?: unknown;
5
+ } | undefined): import("@agentuity/core").RichError & {
6
+ readonly _tag: "UserResponseError";
7
+ } & Readonly<Record<string, never>>;
8
+ readonly defaultMessage?: string;
9
+ } & (<Shape extends {
10
+ [x: string]: any;
11
+ } = Record<string, never>>() => {
12
+ new (args?: (Shape extends Record<string, never> ? {
13
+ message?: string;
14
+ cause?: unknown;
15
+ } : Shape & {
16
+ message?: string;
17
+ cause?: unknown;
18
+ }) | undefined): import("@agentuity/core").RichError & {
19
+ readonly _tag: "UserResponseError";
20
+ } & Readonly<Shape>;
21
+ readonly defaultMessage?: string;
22
+ });
23
+ //# sourceMappingURL=util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../src/api/user/util.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;EAAuC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { StructuredError } from '@agentuity/core';
2
+ export const UserResponseError = StructuredError('UserResponseError');
3
+ //# sourceMappingURL=util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.js","sourceRoot":"","sources":["../../../src/api/user/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD,MAAM,CAAC,MAAM,iBAAiB,GAAG,eAAe,CAAC,mBAAmB,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"whoami.d.ts","sourceRoot":"","sources":["../../../src/api/user/whoami.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAqB,SAAS,EAAE,MAAM,QAAQ,CAAC;AAOtD,QAAA,MAAM,cAAc;;;;;;;iBAIlB,CAAC;AACH,QAAA,MAAM,oBAAoB;;;;;;;;;;;;;8BAAoC,CAAC;AAE/D,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAClE,MAAM,MAAM,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AAElD;;;;;GAKG;AACH,wBAAsB,MAAM,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAM7D"}
1
+ {"version":3,"file":"whoami.d.ts","sourceRoot":"","sources":["../../../src/api/user/whoami.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAqB,SAAS,EAAE,MAAM,QAAQ,CAAC;AAQtD,QAAA,MAAM,cAAc;;;;;;;iBAIlB,CAAC;AACH,QAAA,MAAM,oBAAoB;;;;;;;;;;;;;8BAAoC,CAAC;AAE/D,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAClE,MAAM,MAAM,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AAElD;;;;;GAKG;AACH,wBAAsB,MAAM,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAM7D"}
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { APIResponseSchema } from '../api';
3
+ import { UserResponseError } from './util';
3
4
  const OrganizationSchema = z.object({
4
5
  id: z.string().describe('the unique id for the organization'),
5
6
  name: z.string().describe('the name of the organization'),
@@ -21,6 +22,6 @@ export async function whoami(client) {
21
22
  if (resp.success) {
22
23
  return resp.data;
23
24
  }
24
- throw new Error(resp.message);
25
+ throw new UserResponseError({ message: resp.message });
25
26
  }
26
27
  //# sourceMappingURL=whoami.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"whoami.js","sourceRoot":"","sources":["../../../src/api/user/whoami.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAa,MAAM,QAAQ,CAAC;AAEtD,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,EAAE,EAAE,CAAC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AAC,MAAM,EAAE,CAAC,QAAQ,CAAC,8BAA8B,CAAC;CACzD,CAAC,CAAC;AAEH,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/B,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,4BAA4B,CAAC;IAC5D,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,2BAA2B,CAAC;IAC1D,aAAa,EAAE,CAAC,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC,QAAQ,CAAC,2CAA2C,CAAC;CAChG,CAAC,CAAC;AACH,MAAM,oBAAoB,GAAG,iBAAiB,CAAC,cAAc,CAAC,CAAC;AAK/D;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,MAAiB;IAC7C,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,OAAO,CAAiB,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,CAAC,CAAC;IACjG,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;QAClB,OAAO,IAAI,CAAC,IAAI,CAAC;IAClB,CAAC;IACD,MAAM,IAAI,iBAAiB,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;AACxD,CAAC"}
package/dist/server.d.ts CHANGED
@@ -3,7 +3,7 @@ import { ServiceException } from '@agentuity/core';
3
3
  interface ServiceAdapterConfig {
4
4
  headers: Record<string, string>;
5
5
  onBefore?: (url: string, options: FetchRequest, invoke: () => Promise<void>) => Promise<void>;
6
- onAfter?: <T>(url: string, options: FetchRequest, response: FetchResponse<T>, err?: ServiceException) => Promise<void>;
6
+ onAfter?: <T>(url: string, options: FetchRequest, response: FetchResponse<T>, err?: InstanceType<typeof ServiceException>) => Promise<void>;
7
7
  }
8
8
  /**
9
9
  * Redacts the middle of a string while keeping a prefix and suffix visible.
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],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AC;AACzB,OAAO,EAAE,gBAAgB,EAAoC,MAAM,iBAAiB,CAAC;AAErF,UAAU,oBAAoB;IAC7B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9F,OAAO,CAAC,EAAE,CAAC,CAAC,EACX,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,YAAY,EACrB,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC,EAC1B,GAAG,CAAC,EAAE,YAAY,CAAC,OAAO,gBAAgB,CAAC,KACvC,OAAO,CAAC,IAAI,CAAC,CAAC;CACnB;AAID;;;;;;;;GAQG;AACH,wBAAgB,MAAM,CACrB,KAAK,EAAE,MAAM,EACb,MAAM,GAAE,MAAU,EAClB,MAAM,GAAE,MAAU,EAClB,IAAI,GAAE,MAAY,GAChB,MAAM,CAaR;AAgBD,cAAM,kBAAmB,YAAW,YAAY;;gBAInC,MAAM,EAAE,oBAAoB,EAAE,MAAM,EAAE,MAAM;YAI1C,OAAO;IA6Df,MAAM,CAAC,CAAC,EACb,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,YAAiC,GACxC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;CAmC5B;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,oBAAoB,EAAE,MAAM,EAAE,MAAM,sBAEpF"}
package/dist/server.js CHANGED
@@ -1,4 +1,4 @@
1
- import { toServiceException, fromResponse } from '@agentuity/core';
1
+ import { ServiceException, toServiceException, fromResponse } from '@agentuity/core';
2
2
  const sensitiveHeaders = new Set(['authorization', 'x-api-key']);
3
3
  /**
4
4
  * Redacts the middle of a string while keeping a prefix and suffix visible.
@@ -115,11 +115,11 @@ class ServerFetchAdapter {
115
115
  }
116
116
  catch (ex) {
117
117
  err = ex;
118
- if (this.#config.onAfter) {
118
+ if (this.#config.onAfter && err instanceof ServiceException) {
119
119
  await this.#config.onAfter(url, options, {
120
120
  ok: false,
121
- response: new Response(err.message ?? String(err), {
122
- status: err.statusCode ?? 500,
121
+ response: new Response(err.message, {
122
+ status: err.statusCode,
123
123
  }),
124
124
  }, err);
125
125
  }
@@ -1 +1 @@
1
- {"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAQA,OAAO,EAAoB,kBAAkB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAarF,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC,CAAC,eAAe,EAAE,WAAW,CAAC,CAAC,CAAC;AAEjE;;;;;;;;GAQG;AACH,MAAM,UAAU,MAAM,CACrB,KAAa,EACb,SAAiB,CAAC,EAClB,SAAiB,CAAC,EAClB,OAAe,GAAG;IAElB,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,CAAC;IAEtB,6DAA6D;IAC7D,IAAI,KAAK,CAAC,MAAM,IAAI,MAAM,GAAG,MAAM,EAAE,CAAC;QACrC,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC;IAED,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IACrC,MAAM,GAAG,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC;IACjC,MAAM,YAAY,GAAG,KAAK,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IAEpD,OAAO,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,GAAG,CAAC;AAChD,CAAC;AAED,MAAM,aAAa,GAAG,CAAC,EAA0B,EAAU,EAAE;IAC5D,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,KAAK,MAAM,CAAC,IAAI,M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I,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QACzC,CAAC;IACF,CAAC;CACD;AAED;;;;;GAKG;AACH,MAAM,UAAU,wBAAwB,CAAC,MAA4B,EAAE,MAAc;IACpF,OAAO,IAAI,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAC/C,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentuity/server",
3
- "version": "0.0.60",
3
+ "version": "0.0.62",
4
4
  "license": "Apache-2.0",
5
5
  "author": "Agentuity employees and contributors",
6
6
  "type": "module",
@@ -25,7 +25,7 @@
25
25
  "prepublishOnly": "bun run clean && bun run build"
26
26
  },
27
27
  "dependencies": {
28
- "@agentuity/core": "0.0.60",
28
+ "@agentuity/core": "0.0.62",
29
29
  "zod": "^4.1.12"
30
30
  },
31
31
  "devDependencies": {
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');
package/src/api/index.ts CHANGED
@@ -4,4 +4,5 @@ export * from './org';
4
4
  export * from './project';
5
5
  export * from './region';
6
6
  export * from './session';
7
+ export * from './thread';
7
8
  export * from './user';
@@ -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
  }