@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
@@ -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');
@@ -1,6 +1,7 @@
1
1
  import { z } from 'zod';
2
2
  import { APIClient, APIResponseSchema } from '../api';
3
3
  import { SessionSchema } from './list';
4
+ import { SessionResponseError } from './util';
4
5
 
5
6
  const _SessionGetRequestSchema = z.object({
6
7
  id: z.string().describe('the session id'),
@@ -22,6 +23,7 @@ export interface SpanNode {
22
23
  operation: string;
23
24
  attributes: Record<string, unknown>;
24
25
  children?: SpanNode[];
26
+ error?: string;
25
27
  }
26
28
 
27
29
  const SpanNodeSchema: z.ZodType<SpanNode> = z.lazy(() =>
@@ -31,6 +33,7 @@ const SpanNodeSchema: z.ZodType<SpanNode> = z.lazy(() =>
31
33
  operation: z.string().describe('operation name'),
32
34
  attributes: z.record(z.string(), z.unknown()).describe('span attributes'),
33
35
  children: z.array(SpanNodeSchema).optional().describe('child spans'),
36
+ error: z.string().optional().describe('error message'),
34
37
  })
35
38
  );
36
39
 
@@ -99,5 +102,5 @@ export async function sessionGet(
99
102
  };
100
103
  }
101
104
 
102
- throw new Error(resp.message);
105
+ throw new SessionResponseError({ message: resp.message });
103
106
  }
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { APIClient, APIResponseSchema } from '../api';
3
+ import { SessionResponseError } from './util';
3
4
 
4
5
  const SessionSchema = z.object({
5
6
  id: z.string().describe('the session id'),
@@ -32,6 +33,7 @@ const SessionSchema = z.object({
32
33
  route_id: z.string().describe('the route id'),
33
34
  thread_id: z.string().describe('the thread id'),
34
35
  timeline: z.unknown().nullable().optional().describe('the session timeline tree'),
36
+ user_data: z.string().nullable().optional().describe('the user data as JSON'),
35
37
  });
36
38
 
37
39
  export { SessionSchema };
@@ -104,5 +106,5 @@ export async function sessionList(
104
106
  return resp.data;
105
107
  }
106
108
 
107
- throw new Error(resp.message);
109
+ throw new SessionResponseError({ message: resp.message });
108
110
  }
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { APIClient, APIResponseSchema } from '../api';
3
+ import { SessionResponseError } from './util';
3
4
 
4
5
  const _SessionLogsRequestSchema = z.object({
5
6
  id: z.string().describe('the session id'),
@@ -42,5 +43,5 @@ export async function sessionLogs(
42
43
  return resp.data;
43
44
  }
44
45
 
45
- throw new Error(resp.message);
46
+ throw new SessionResponseError({ message: resp.message });
46
47
  }
@@ -0,0 +1,3 @@
1
+ import { StructuredError } from '@agentuity/core';
2
+
3
+ export const SessionResponseError = StructuredError('SessionResponseError');
@@ -0,0 +1,31 @@
1
+ import { z } from 'zod';
2
+ import { APIClient, APIResponseSchemaNoData } from '../api';
3
+ import { ThreadResponseError } from './util';
4
+
5
+ const _ThreadDeleteRequestSchema = z.object({
6
+ id: z.string().describe('the thread id'),
7
+ });
8
+
9
+ const ThreadDeleteResponseSchema = APIResponseSchemaNoData();
10
+
11
+ type ThreadDeleteRequest = z.infer<typeof _ThreadDeleteRequestSchema>;
12
+ type ThreadDeleteResponse = z.infer<typeof ThreadDeleteResponseSchema>;
13
+
14
+ /**
15
+ * Delete a thread by id
16
+ *
17
+ * @param client
18
+ * @param request
19
+ * @returns
20
+ */
21
+ export async function threadDelete(client: APIClient, request: ThreadDeleteRequest): Promise<void> {
22
+ const resp = await client.request<ThreadDeleteResponse>(
23
+ 'DELETE',
24
+ `/thread/2025-03-17/${request.id}`,
25
+ ThreadDeleteResponseSchema
26
+ );
27
+
28
+ if (!resp.success) {
29
+ throw new ThreadResponseError({ message: resp.message });
30
+ }
31
+ }
@@ -0,0 +1,36 @@
1
+ import { z } from 'zod';
2
+ import { APIClient, APIResponseSchema } from '../api';
3
+ import { ThreadSchema } from './list';
4
+ import { ThreadResponseError } from './util';
5
+
6
+ const _ThreadGetRequestSchema = z.object({
7
+ id: z.string().describe('the thread id'),
8
+ });
9
+
10
+ const ThreadGetResponseSchema = APIResponseSchema(ThreadSchema);
11
+
12
+ type ThreadGetRequest = z.infer<typeof _ThreadGetRequestSchema>;
13
+ type ThreadGetResponse = z.infer<typeof ThreadGetResponseSchema>;
14
+
15
+ export type Thread = z.infer<typeof ThreadSchema>;
16
+
17
+ /**
18
+ * Get a single thread by id
19
+ *
20
+ * @param client
21
+ * @param request
22
+ * @returns
23
+ */
24
+ export async function threadGet(client: APIClient, request: ThreadGetRequest): Promise<Thread> {
25
+ const resp = await client.request<ThreadGetResponse>(
26
+ 'GET',
27
+ `/thread/2025-03-17/${request.id}`,
28
+ ThreadGetResponseSchema
29
+ );
30
+
31
+ if (resp.success) {
32
+ return resp.data;
33
+ }
34
+
35
+ throw new ThreadResponseError({ message: resp.message });
36
+ }
@@ -0,0 +1,4 @@
1
+ export { threadGet, type Thread } from './get';
2
+ export { threadList, type ThreadList, type ThreadListOptions, ThreadSchema } from './list';
3
+ export { threadDelete } from './delete';
4
+ export { ThreadResponseError } from './util';
@@ -0,0 +1,60 @@
1
+ import { z } from 'zod';
2
+ import { APIClient, APIResponseSchema } from '../api';
3
+ import { ThreadResponseError } from './util';
4
+
5
+ const ThreadSchema = z.object({
6
+ id: z.string().describe('the thread id'),
7
+ created_at: z.string().describe('the creation timestamp'),
8
+ updated_at: z.string().describe('the last update timestamp'),
9
+ deleted: z.boolean().describe('whether the thread is deleted'),
10
+ deleted_at: z.string().nullable().describe('the deletion timestamp'),
11
+ deleted_by: z.string().nullable().describe('who deleted the thread'),
12
+ org_id: z.string().describe('the organization id'),
13
+ project_id: z.string().describe('the project id'),
14
+ user_data: z.string().nullable().optional().describe('the user data as JSON'),
15
+ });
16
+
17
+ export { ThreadSchema };
18
+
19
+ const ThreadListResponse = z.array(ThreadSchema);
20
+
21
+ const ThreadListResponseSchema = APIResponseSchema(ThreadListResponse);
22
+
23
+ export type ThreadListResponse = z.infer<typeof ThreadListResponseSchema>;
24
+ export type ThreadList = z.infer<typeof ThreadListResponse>;
25
+ export type Thread = z.infer<typeof ThreadSchema>;
26
+
27
+ export interface ThreadListOptions {
28
+ count?: number;
29
+ orgId?: string;
30
+ projectId?: string;
31
+ }
32
+
33
+ /**
34
+ * List threads
35
+ *
36
+ * @param client
37
+ * @param options filtering and pagination options
38
+ * @returns
39
+ */
40
+ export async function threadList(
41
+ client: APIClient,
42
+ options: ThreadListOptions = {}
43
+ ): Promise<ThreadList> {
44
+ const { count = 10, orgId, projectId } = options;
45
+ const params = new URLSearchParams({ count: count.toString() });
46
+ if (orgId) params.set('orgId', orgId);
47
+ if (projectId) params.set('projectId', projectId);
48
+
49
+ const resp = await client.request<ThreadListResponse>(
50
+ 'GET',
51
+ `/thread/2025-03-17?${params.toString()}`,
52
+ ThreadListResponseSchema
53
+ );
54
+
55
+ if (resp.success) {
56
+ return resp.data;
57
+ }
58
+
59
+ throw new ThreadResponseError({ message: resp.message });
60
+ }
@@ -0,0 +1,3 @@
1
+ import { StructuredError } from '@agentuity/core';
2
+
3
+ export const ThreadResponseError = StructuredError('ThreadResponseError');
@@ -0,0 +1,3 @@
1
+ import { StructuredError } from '@agentuity/core';
2
+
3
+ export const UserResponseError = StructuredError('UserResponseError');
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { APIResponseSchema, APIClient } from '../api';
3
+ import { UserResponseError } from './util';
3
4
 
4
5
  const OrganizationSchema = z.object({
5
6
  id: z.string().describe('the unique id for the organization'),
@@ -27,5 +28,5 @@ export async function whoami(client: APIClient): Promise<User> {
27
28
  if (resp.success) {
28
29
  return resp.data;
29
30
  }
30
- throw new Error(resp.message);
31
+ throw new UserResponseError({ message: resp.message });
31
32
  }
package/src/server.ts CHANGED
@@ -15,7 +15,7 @@ interface ServiceAdapterConfig {
15
15
  url: string,
16
16
  options: FetchRequest,
17
17
  response: FetchResponse<T>,
18
- err?: ServiceException
18
+ err?: InstanceType<typeof ServiceException>
19
19
  ) => Promise<void>;
20
20
  }
21
21
 
@@ -148,17 +148,17 @@ class ServerFetchAdapter implements FetchAdapter {
148
148
  }
149
149
  } catch (ex) {
150
150
  err = ex as Error;
151
- if (this.#config.onAfter) {
151
+ if (this.#config.onAfter && err instanceof ServiceException) {
152
152
  await this.#config.onAfter(
153
153
  url,
154
154
  options,
155
155
  {
156
156
  ok: false,
157
- response: new Response((err as ServiceException).message ?? String(err), {
158
- status: (err as ServiceException).statusCode ?? 500,
157
+ response: new Response(err.message, {
158
+ status: err.statusCode,
159
159
  }),
160
160
  } as FetchErrorResponse,
161
- err as ServiceException
161
+ err
162
162
  );
163
163
  }
164
164
  }