@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.
- package/dist/api/api.d.ts +87 -23
- package/dist/api/api.d.ts.map +1 -1
- package/dist/api/api.js +87 -47
- package/dist/api/api.js.map +1 -1
- package/dist/api/apikey/create.d.ts.map +1 -1
- package/dist/api/apikey/create.js +2 -1
- package/dist/api/apikey/create.js.map +1 -1
- package/dist/api/apikey/delete.d.ts.map +1 -1
- package/dist/api/apikey/delete.js +2 -1
- package/dist/api/apikey/delete.js.map +1 -1
- package/dist/api/apikey/get.d.ts.map +1 -1
- package/dist/api/apikey/get.js +2 -1
- package/dist/api/apikey/get.js.map +1 -1
- package/dist/api/apikey/list.d.ts.map +1 -1
- package/dist/api/apikey/list.js +2 -1
- package/dist/api/apikey/list.js.map +1 -1
- package/dist/api/apikey/util.d.ts +23 -0
- package/dist/api/apikey/util.d.ts.map +1 -0
- package/dist/api/apikey/util.js +3 -0
- package/dist/api/apikey/util.js.map +1 -0
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +1 -0
- package/dist/api/index.js.map +1 -1
- package/dist/api/org/list.d.ts.map +1 -1
- package/dist/api/org/list.js +2 -1
- package/dist/api/org/list.js.map +1 -1
- package/dist/api/org/util.d.ts +23 -0
- package/dist/api/org/util.d.ts.map +1 -0
- package/dist/api/org/util.js +3 -0
- package/dist/api/org/util.js.map +1 -0
- package/dist/api/project/agent.d.ts.map +1 -1
- package/dist/api/project/agent.js +4 -3
- package/dist/api/project/agent.js.map +1 -1
- package/dist/api/project/create.d.ts.map +1 -1
- package/dist/api/project/create.js +2 -1
- package/dist/api/project/create.js.map +1 -1
- package/dist/api/project/delete.d.ts.map +1 -1
- package/dist/api/project/delete.js +2 -1
- package/dist/api/project/delete.js.map +1 -1
- package/dist/api/project/deploy.d.ts.map +1 -1
- package/dist/api/project/deploy.js +4 -3
- package/dist/api/project/deploy.js.map +1 -1
- package/dist/api/project/deployment.d.ts.map +1 -1
- package/dist/api/project/deployment.js +7 -6
- package/dist/api/project/deployment.js.map +1 -1
- package/dist/api/project/env-delete.d.ts.map +1 -1
- package/dist/api/project/env-delete.js +2 -1
- package/dist/api/project/env-delete.js.map +1 -1
- package/dist/api/project/env-update.d.ts.map +1 -1
- package/dist/api/project/env-update.js +2 -1
- package/dist/api/project/env-update.js.map +1 -1
- package/dist/api/project/exists.d.ts.map +1 -1
- package/dist/api/project/exists.js +6 -5
- package/dist/api/project/exists.js.map +1 -1
- package/dist/api/project/get.d.ts.map +1 -1
- package/dist/api/project/get.js +2 -1
- package/dist/api/project/get.js.map +1 -1
- package/dist/api/project/list.d.ts.map +1 -1
- package/dist/api/project/list.js +2 -1
- package/dist/api/project/list.js.map +1 -1
- package/dist/api/project/util.d.ts +49 -0
- package/dist/api/project/util.d.ts.map +1 -0
- package/dist/api/project/util.js +5 -0
- package/dist/api/project/util.js.map +1 -0
- package/dist/api/region/create.d.ts.map +1 -1
- package/dist/api/region/create.js +4 -1
- package/dist/api/region/create.js.map +1 -1
- package/dist/api/region/delete.d.ts.map +1 -1
- package/dist/api/region/delete.js +2 -1
- package/dist/api/region/delete.js.map +1 -1
- package/dist/api/region/list.d.ts.map +1 -1
- package/dist/api/region/list.js +2 -1
- package/dist/api/region/list.js.map +1 -1
- package/dist/api/region/resources.d.ts.map +1 -1
- package/dist/api/region/resources.js +2 -1
- package/dist/api/region/resources.js.map +1 -1
- package/dist/api/region/util.d.ts +23 -0
- package/dist/api/region/util.d.ts.map +1 -0
- package/dist/api/region/util.js +3 -0
- package/dist/api/region/util.js.map +1 -0
- package/dist/api/session/get.d.ts +1 -0
- package/dist/api/session/get.d.ts.map +1 -1
- package/dist/api/session/get.js +3 -1
- package/dist/api/session/get.js.map +1 -1
- package/dist/api/session/list.d.ts +3 -0
- package/dist/api/session/list.d.ts.map +1 -1
- package/dist/api/session/list.js +3 -1
- package/dist/api/session/list.js.map +1 -1
- package/dist/api/session/logs.d.ts.map +1 -1
- package/dist/api/session/logs.js +2 -1
- package/dist/api/session/logs.js.map +1 -1
- package/dist/api/session/util.d.ts +23 -0
- package/dist/api/session/util.d.ts.map +1 -0
- package/dist/api/session/util.js +3 -0
- package/dist/api/session/util.js.map +1 -0
- package/dist/api/thread/delete.d.ts +16 -0
- package/dist/api/thread/delete.d.ts.map +1 -0
- package/dist/api/thread/delete.js +21 -0
- package/dist/api/thread/delete.js.map +1 -0
- package/dist/api/thread/get.d.ts +18 -0
- package/dist/api/thread/get.d.ts.map +1 -0
- package/dist/api/thread/get.js +23 -0
- package/dist/api/thread/get.js.map +1 -0
- package/dist/api/thread/index.d.ts +5 -0
- package/dist/api/thread/index.d.ts.map +1 -0
- package/dist/api/thread/index.js +5 -0
- package/dist/api/thread/index.js.map +1 -0
- package/dist/api/thread/list.d.ts +59 -0
- package/dist/api/thread/list.d.ts.map +1 -0
- package/dist/api/thread/list.js +38 -0
- package/dist/api/thread/list.js.map +1 -0
- package/dist/api/thread/util.d.ts +23 -0
- package/dist/api/thread/util.d.ts.map +1 -0
- package/dist/api/thread/util.js +3 -0
- package/dist/api/thread/util.js.map +1 -0
- package/dist/api/user/util.d.ts +23 -0
- package/dist/api/user/util.d.ts.map +1 -0
- package/dist/api/user/util.js +3 -0
- package/dist/api/user/util.js.map +1 -0
- package/dist/api/user/whoami.d.ts.map +1 -1
- package/dist/api/user/whoami.js +2 -1
- package/dist/api/user/whoami.js.map +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +4 -4
- package/dist/server.js.map +1 -1
- package/package.json +2 -2
- package/src/api/api.ts +127 -78
- package/src/api/apikey/create.ts +2 -1
- package/src/api/apikey/delete.ts +2 -1
- package/src/api/apikey/get.ts +2 -1
- package/src/api/apikey/list.ts +2 -1
- package/src/api/apikey/util.ts +3 -0
- package/src/api/index.ts +1 -0
- package/src/api/org/list.ts +2 -1
- package/src/api/org/util.ts +3 -0
- package/src/api/project/agent.ts +4 -3
- package/src/api/project/create.ts +2 -1
- package/src/api/project/delete.ts +2 -1
- package/src/api/project/deploy.ts +4 -3
- package/src/api/project/deployment.ts +7 -6
- package/src/api/project/env-delete.ts +2 -1
- package/src/api/project/env-update.ts +2 -1
- package/src/api/project/exists.ts +5 -4
- package/src/api/project/get.ts +2 -1
- package/src/api/project/list.ts +2 -1
- package/src/api/project/util.ts +5 -0
- package/src/api/region/create.ts +4 -1
- package/src/api/region/delete.ts +2 -1
- package/src/api/region/list.ts +2 -1
- package/src/api/region/resources.ts +2 -1
- package/src/api/region/util.ts +3 -0
- package/src/api/session/get.ts +4 -1
- package/src/api/session/list.ts +3 -1
- package/src/api/session/logs.ts +2 -1
- package/src/api/session/util.ts +3 -0
- package/src/api/thread/delete.ts +31 -0
- package/src/api/thread/get.ts +36 -0
- package/src/api/thread/index.ts +4 -0
- package/src/api/thread/list.ts +60 -0
- package/src/api/thread/util.ts +3 -0
- package/src/api/user/util.ts +3 -0
- package/src/api/user/whoami.ts +2 -1
- 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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
46
|
-
|
|
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
|
}
|
package/src/api/project/get.ts
CHANGED
|
@@ -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
|
|
36
|
+
throw new ProjectResponseError({ message: resp.message });
|
|
36
37
|
}
|
package/src/api/project/list.ts
CHANGED
|
@@ -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
|
|
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 }>();
|
package/src/api/region/create.ts
CHANGED
|
@@ -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
|
|
55
|
+
throw new RegionResponseError({
|
|
56
|
+
message: resp.message,
|
|
57
|
+
});
|
|
55
58
|
}
|
package/src/api/region/delete.ts
CHANGED
|
@@ -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
|
|
49
|
+
throw new RegionResponseError({ message: resp.message });
|
|
49
50
|
}
|
package/src/api/region/list.ts
CHANGED
|
@@ -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
|
|
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
|
|
51
|
+
throw new RegionResponseError({ message: resp.message });
|
|
51
52
|
}
|
package/src/api/session/get.ts
CHANGED
|
@@ -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
|
|
105
|
+
throw new SessionResponseError({ message: resp.message });
|
|
103
106
|
}
|
package/src/api/session/list.ts
CHANGED
|
@@ -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
|
|
109
|
+
throw new SessionResponseError({ message: resp.message });
|
|
108
110
|
}
|
package/src/api/session/logs.ts
CHANGED
|
@@ -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
|
|
46
|
+
throw new SessionResponseError({ message: resp.message });
|
|
46
47
|
}
|
|
@@ -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,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
|
+
}
|
package/src/api/user/whoami.ts
CHANGED
|
@@ -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
|
|
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(
|
|
158
|
-
status:
|
|
157
|
+
response: new Response(err.message, {
|
|
158
|
+
status: err.statusCode,
|
|
159
159
|
}),
|
|
160
160
|
} as FetchErrorResponse,
|
|
161
|
-
err
|
|
161
|
+
err
|
|
162
162
|
);
|
|
163
163
|
}
|
|
164
164
|
}
|