@agentuity/server 0.0.41 → 0.0.43
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 +5 -1
- package/dist/api/api.d.ts.map +1 -1
- package/dist/api/api.js +4 -0
- package/dist/api/api.js.map +1 -1
- 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/project/create.d.ts +1 -1
- package/dist/api/project/create.js +1 -1
- package/dist/api/project/delete.d.ts +3 -0
- package/dist/api/project/delete.d.ts.map +1 -0
- package/dist/api/project/delete.js +12 -0
- package/dist/api/project/delete.js.map +1 -0
- package/dist/api/project/env-delete.d.ts +15 -0
- package/dist/api/project/env-delete.d.ts.map +1 -0
- package/dist/api/project/env-delete.js +24 -0
- package/dist/api/project/env-delete.js.map +1 -0
- package/dist/api/project/env-update.d.ts +17 -0
- package/dist/api/project/env-update.d.ts.map +1 -0
- package/dist/api/project/env-update.js +37 -0
- package/dist/api/project/env-update.js.map +1 -0
- package/dist/api/project/exists.d.ts +1 -1
- package/dist/api/project/exists.d.ts.map +1 -1
- package/dist/api/project/exists.js +1 -18
- package/dist/api/project/exists.js.map +1 -1
- package/dist/api/project/get.d.ts +23 -0
- package/dist/api/project/get.d.ts.map +1 -0
- package/dist/api/project/get.js +21 -0
- package/dist/api/project/get.js.map +1 -0
- package/dist/api/project/index.d.ts +5 -0
- package/dist/api/project/index.d.ts.map +1 -1
- package/dist/api/project/index.js +5 -0
- package/dist/api/project/index.js.map +1 -1
- package/dist/api/project/list.d.ts +24 -0
- package/dist/api/project/list.d.ts.map +1 -0
- package/dist/api/project/list.js +23 -0
- package/dist/api/project/list.js.map +1 -0
- package/dist/api/user/index.d.ts +2 -0
- package/dist/api/user/index.d.ts.map +1 -0
- package/dist/api/user/index.js +2 -0
- package/dist/api/user/index.js.map +1 -0
- package/dist/api/user/whoami.d.ts +25 -0
- package/dist/api/user/whoami.d.ts.map +1 -0
- package/dist/api/user/whoami.js +23 -0
- package/dist/api/user/whoami.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/logger.d.ts +39 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +238 -0
- package/dist/logger.js.map +1 -0
- package/package.json +1 -1
- package/src/api/api.ts +10 -1
- package/src/api/index.ts +1 -0
- package/src/api/project/create.ts +1 -1
- package/src/api/project/delete.ts +24 -0
- package/src/api/project/env-delete.ts +40 -0
- package/src/api/project/env-update.ts +57 -0
- package/src/api/project/exists.ts +1 -20
- package/src/api/project/get.ts +36 -0
- package/src/api/project/index.ts +5 -0
- package/src/api/project/list.ts +37 -0
- package/src/api/user/index.ts +1 -0
- package/src/api/user/whoami.ts +30 -0
- package/src/index.ts +1 -0
- package/src/logger.ts +287 -0
package/dist/logger.js
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { format, inspect } from 'node:util';
|
|
2
|
+
const LOG_LEVELS = {
|
|
3
|
+
trace: 0,
|
|
4
|
+
debug: 1,
|
|
5
|
+
info: 2,
|
|
6
|
+
warn: 3,
|
|
7
|
+
error: 4,
|
|
8
|
+
};
|
|
9
|
+
const BOLD = '\x1b[1m';
|
|
10
|
+
const RESET = '\x1b[0m';
|
|
11
|
+
// Helper to convert hex color to ANSI 24-bit color code
|
|
12
|
+
function hexToAnsi(hex) {
|
|
13
|
+
const r = parseInt(hex.slice(1, 3), 16);
|
|
14
|
+
const g = parseInt(hex.slice(3, 5), 16);
|
|
15
|
+
const b = parseInt(hex.slice(5, 7), 16);
|
|
16
|
+
return `\x1b[38;2;${r};${g};${b}m`;
|
|
17
|
+
}
|
|
18
|
+
function shouldUseColors() {
|
|
19
|
+
// Check for NO_COLOR environment variable (any non-empty value disables colors)
|
|
20
|
+
if (process.env.NO_COLOR) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
// Check for TERM=dumb
|
|
24
|
+
if (process.env.TERM === 'dumb') {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
// Check if stdout is a TTY
|
|
28
|
+
if (process.stdout && typeof process.stdout.isTTY !== 'undefined' && !process.stdout.isTTY) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
const USE_COLORS = shouldUseColors();
|
|
34
|
+
function getLogColors(scheme) {
|
|
35
|
+
if (scheme === 'light') {
|
|
36
|
+
// Darker, high-contrast colors for light backgrounds
|
|
37
|
+
return {
|
|
38
|
+
trace: {
|
|
39
|
+
level: hexToAnsi('#008B8B') + BOLD, // Dark cyan
|
|
40
|
+
message: hexToAnsi('#4B4B4B'), // Dark gray
|
|
41
|
+
timestamp: hexToAnsi('#808080'), // Gray
|
|
42
|
+
},
|
|
43
|
+
debug: {
|
|
44
|
+
level: hexToAnsi('#0000CD') + BOLD, // Medium blue
|
|
45
|
+
message: hexToAnsi('#006400'), // Dark green
|
|
46
|
+
timestamp: hexToAnsi('#808080'),
|
|
47
|
+
},
|
|
48
|
+
info: {
|
|
49
|
+
level: hexToAnsi('#FF8C00') + BOLD, // Dark orange
|
|
50
|
+
message: hexToAnsi('#0066CC') + BOLD, // Strong blue
|
|
51
|
+
timestamp: hexToAnsi('#808080'),
|
|
52
|
+
},
|
|
53
|
+
warn: {
|
|
54
|
+
level: hexToAnsi('#9400D3') + BOLD, // Dark violet
|
|
55
|
+
message: hexToAnsi('#8B008B'), // Dark magenta
|
|
56
|
+
timestamp: hexToAnsi('#808080'),
|
|
57
|
+
},
|
|
58
|
+
error: {
|
|
59
|
+
level: hexToAnsi('#DC143C') + BOLD, // Crimson
|
|
60
|
+
message: hexToAnsi('#8B0000') + BOLD, // Dark red
|
|
61
|
+
timestamp: hexToAnsi('#808080'),
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
// Dark mode colors (brighter for dark backgrounds)
|
|
66
|
+
return {
|
|
67
|
+
trace: {
|
|
68
|
+
level: hexToAnsi('#00FFFF') + BOLD, // Cyan
|
|
69
|
+
message: hexToAnsi('#A0A0A0'), // Light gray
|
|
70
|
+
timestamp: hexToAnsi('#666666'),
|
|
71
|
+
},
|
|
72
|
+
debug: {
|
|
73
|
+
level: hexToAnsi('#5C9CFF') + BOLD, // Blue
|
|
74
|
+
message: hexToAnsi('#90EE90'), // Light green
|
|
75
|
+
timestamp: hexToAnsi('#666666'),
|
|
76
|
+
},
|
|
77
|
+
info: {
|
|
78
|
+
level: hexToAnsi('#FFD700') + BOLD, // Gold/Yellow
|
|
79
|
+
message: hexToAnsi('#FFFFFF') + BOLD, // White
|
|
80
|
+
timestamp: hexToAnsi('#666666'),
|
|
81
|
+
},
|
|
82
|
+
warn: {
|
|
83
|
+
level: hexToAnsi('#FF00FF') + BOLD, // Magenta
|
|
84
|
+
message: hexToAnsi('#FF00FF'), // Magenta
|
|
85
|
+
timestamp: hexToAnsi('#666666'),
|
|
86
|
+
},
|
|
87
|
+
error: {
|
|
88
|
+
level: hexToAnsi('#FF4444') + BOLD, // Red
|
|
89
|
+
message: hexToAnsi('#FF4444'), // Red
|
|
90
|
+
timestamp: hexToAnsi('#666666'),
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Console logger implementation
|
|
96
|
+
*/
|
|
97
|
+
export class ConsoleLogger {
|
|
98
|
+
level;
|
|
99
|
+
showTimestamp;
|
|
100
|
+
colorScheme;
|
|
101
|
+
colors;
|
|
102
|
+
showPrefix = true;
|
|
103
|
+
context;
|
|
104
|
+
constructor(level = 'info', showTimestamp = false, colorScheme = 'dark', context = {}) {
|
|
105
|
+
this.level = level;
|
|
106
|
+
this.showTimestamp = showTimestamp;
|
|
107
|
+
this.colorScheme = colorScheme;
|
|
108
|
+
this.colors = getLogColors(this.colorScheme);
|
|
109
|
+
this.context = context;
|
|
110
|
+
}
|
|
111
|
+
setLevel(level) {
|
|
112
|
+
this.level = level;
|
|
113
|
+
}
|
|
114
|
+
setTimestamp(enabled) {
|
|
115
|
+
this.showTimestamp = enabled;
|
|
116
|
+
}
|
|
117
|
+
setColorScheme(scheme) {
|
|
118
|
+
this.colorScheme = scheme;
|
|
119
|
+
this.colors = getLogColors(this.colorScheme);
|
|
120
|
+
}
|
|
121
|
+
setShowPrefix(show) {
|
|
122
|
+
this.showPrefix = show;
|
|
123
|
+
}
|
|
124
|
+
shouldLog(level) {
|
|
125
|
+
return LOG_LEVELS[level] >= LOG_LEVELS[this.level];
|
|
126
|
+
}
|
|
127
|
+
formatMessage(message, args) {
|
|
128
|
+
try {
|
|
129
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
130
|
+
const base = format(message, ...args);
|
|
131
|
+
if (!this.context || Object.keys(this.context).length === 0) {
|
|
132
|
+
return base;
|
|
133
|
+
}
|
|
134
|
+
const ctx = Object.entries(this.context)
|
|
135
|
+
.map(([k, v]) => `${k}=${typeof v === 'object' ? inspect(v, { depth: 2, maxArrayLength: 50, colors: false }) : String(v)}`)
|
|
136
|
+
.join(' ');
|
|
137
|
+
const result = `${base} ${ctx}`;
|
|
138
|
+
const MAX_LENGTH = 10000;
|
|
139
|
+
if (result.length > MAX_LENGTH) {
|
|
140
|
+
return `${result.slice(0, MAX_LENGTH)} …(+${result.length - MAX_LENGTH} chars truncated)`;
|
|
141
|
+
}
|
|
142
|
+
return result;
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
const base = [String(message), ...args.map((a) => String(a))].join(' ');
|
|
146
|
+
return this.context && Object.keys(this.context).length > 0
|
|
147
|
+
? `${base} ${JSON.stringify(this.context)}`
|
|
148
|
+
: base;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
log(level, message, ...args) {
|
|
152
|
+
if (!this.shouldLog(level)) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
const colors = this.colors[level];
|
|
156
|
+
const levelText = `[${level.toUpperCase()}]`;
|
|
157
|
+
const formattedMessage = this.formatMessage(message, args);
|
|
158
|
+
let output = '';
|
|
159
|
+
if (USE_COLORS) {
|
|
160
|
+
if (this.showPrefix) {
|
|
161
|
+
if (this.showTimestamp) {
|
|
162
|
+
const timestamp = new Date().toISOString();
|
|
163
|
+
output = `${colors.timestamp}[${timestamp}]${RESET} ${colors.level}${levelText}${RESET} ${colors.message}${formattedMessage}${RESET}`;
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
output = `${colors.level}${levelText}${RESET} ${colors.message}${formattedMessage}${RESET}`;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
// No prefix - just the message with color
|
|
171
|
+
output = `${colors.message}${formattedMessage}${RESET}`;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
// No colors - plain text output
|
|
176
|
+
if (this.showPrefix) {
|
|
177
|
+
if (this.showTimestamp) {
|
|
178
|
+
const timestamp = new Date().toISOString();
|
|
179
|
+
output = `[${timestamp}] ${levelText} ${formattedMessage}`;
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
output = `${levelText} ${formattedMessage}`;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
// No prefix, no colors - just message
|
|
187
|
+
output = formattedMessage;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (level === 'error') {
|
|
191
|
+
console.error(output);
|
|
192
|
+
}
|
|
193
|
+
else if (level === 'warn') {
|
|
194
|
+
console.warn(output);
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
console.log(output);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
trace(message, ...args) {
|
|
201
|
+
this.log('trace', message, ...args);
|
|
202
|
+
}
|
|
203
|
+
debug(message, ...args) {
|
|
204
|
+
this.log('debug', message, ...args);
|
|
205
|
+
}
|
|
206
|
+
info(message, ...args) {
|
|
207
|
+
this.log('info', message, ...args);
|
|
208
|
+
}
|
|
209
|
+
warn(message, ...args) {
|
|
210
|
+
this.log('warn', message, ...args);
|
|
211
|
+
}
|
|
212
|
+
error(message, ...args) {
|
|
213
|
+
this.log('error', message, ...args);
|
|
214
|
+
}
|
|
215
|
+
fatal(message, ...args) {
|
|
216
|
+
this.log('error', message, ...args);
|
|
217
|
+
process.exit(1);
|
|
218
|
+
}
|
|
219
|
+
child(opts) {
|
|
220
|
+
return new ConsoleLogger(this.level, this.showTimestamp, this.colorScheme, {
|
|
221
|
+
...this.context,
|
|
222
|
+
...opts,
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Create a new console logger instance
|
|
228
|
+
*
|
|
229
|
+
* @param level - The minimum log level to display
|
|
230
|
+
* @param showTimestamp - Whether to show timestamps in log messages
|
|
231
|
+
* @param colorScheme - The color scheme to use ('light' or 'dark')
|
|
232
|
+
* @param context - Initial context for the logger
|
|
233
|
+
* @returns A new ConsoleLogger instance
|
|
234
|
+
*/
|
|
235
|
+
export function createLogger(level = 'info', showTimestamp = false, colorScheme = 'dark', context = {}) {
|
|
236
|
+
return new ConsoleLogger(level, showTimestamp, colorScheme, context);
|
|
237
|
+
}
|
|
238
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE5C,MAAM,UAAU,GAA6B;IAC5C,KAAK,EAAE,CAAC;IACR,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,CAAC;CACR,CAAC;AAEF,MAAM,IAAI,GAAG,SAAS,CAAC;AACvB,MAAM,KAAK,GAAG,SAAS,CAAC;AAExB,w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
CHANGED
package/src/api/api.ts
CHANGED
|
@@ -13,7 +13,11 @@ import { z } from 'zod';
|
|
|
13
13
|
export interface APIErrorResponse {
|
|
14
14
|
success: boolean;
|
|
15
15
|
code?: string;
|
|
16
|
-
message
|
|
16
|
+
message?: string;
|
|
17
|
+
error?: {
|
|
18
|
+
name?: string;
|
|
19
|
+
issues?: z.ZodIssue[];
|
|
20
|
+
};
|
|
17
21
|
details?: Record<string, unknown>;
|
|
18
22
|
}
|
|
19
23
|
|
|
@@ -189,6 +193,11 @@ export class APIClient {
|
|
|
189
193
|
);
|
|
190
194
|
}
|
|
191
195
|
|
|
196
|
+
// Handle Zod validation errors from the API
|
|
197
|
+
if (errorData?.error?.name === 'ZodError' && errorData.error.issues) {
|
|
198
|
+
throw new ValidationError('API validation failed', errorData.error.issues);
|
|
199
|
+
}
|
|
200
|
+
|
|
192
201
|
// Throw with message from API if available
|
|
193
202
|
if (errorData?.message) {
|
|
194
203
|
throw new APIError(errorData.message, response.status, errorData.code);
|
package/src/api/index.ts
CHANGED
|
@@ -29,7 +29,7 @@ export type CreateProjectResponse = z.infer<typeof CreateProjectResponseSchema>;
|
|
|
29
29
|
* @param body
|
|
30
30
|
* @returns
|
|
31
31
|
*/
|
|
32
|
-
export async function
|
|
32
|
+
export async function projectCreate(
|
|
33
33
|
client: APIClient,
|
|
34
34
|
body: CreateProjectRequest
|
|
35
35
|
): Promise<Omit<CreateProjectResponse, 'projectKey'>> {
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { APIClient, APIResponseSchema } from '../api';
|
|
3
|
+
|
|
4
|
+
const ProjectDeleteRequestSchema = z.object({ ids: z.array(z.string()) });
|
|
5
|
+
const ProjectDeleteResponseSchema = APIResponseSchema(z.array(z.string()));
|
|
6
|
+
|
|
7
|
+
type ProjectDeleteRequest = z.infer<typeof ProjectDeleteRequestSchema>;
|
|
8
|
+
type ProjectDeleteResponse = z.infer<typeof ProjectDeleteResponseSchema>;
|
|
9
|
+
|
|
10
|
+
export async function projectDelete(client: APIClient, ...ids: string[]) {
|
|
11
|
+
const resp = await client.request<ProjectDeleteResponse, ProjectDeleteRequest>(
|
|
12
|
+
'DELETE',
|
|
13
|
+
'/cli/project',
|
|
14
|
+
ProjectDeleteResponseSchema,
|
|
15
|
+
{ ids },
|
|
16
|
+
ProjectDeleteRequestSchema
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
if (resp.data) {
|
|
20
|
+
return resp.data;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
throw new Error(resp.message ?? 'failed to delete project');
|
|
24
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { APIClient, APIResponseSchema } from '../api';
|
|
3
|
+
|
|
4
|
+
const _ProjectEnvDeleteRequestSchema = z.object({
|
|
5
|
+
id: z.string().describe('the project id'),
|
|
6
|
+
env: z.array(z.string()).optional().describe('environment variable keys to delete'),
|
|
7
|
+
secrets: z.array(z.string()).optional().describe('secret keys to delete'),
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
const ProjectEnvDeleteResponseSchema = APIResponseSchema(z.object({}));
|
|
11
|
+
|
|
12
|
+
type ProjectEnvDeleteRequest = z.infer<typeof _ProjectEnvDeleteRequestSchema>;
|
|
13
|
+
type ProjectEnvDeleteResponse = z.infer<typeof ProjectEnvDeleteResponseSchema>;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Delete environment variables and/or secrets from a project.
|
|
17
|
+
* Provide arrays of keys to delete.
|
|
18
|
+
*/
|
|
19
|
+
export async function projectEnvDelete(
|
|
20
|
+
client: APIClient,
|
|
21
|
+
request: ProjectEnvDeleteRequest
|
|
22
|
+
): Promise<void> {
|
|
23
|
+
const { id, env, secrets } = request;
|
|
24
|
+
|
|
25
|
+
const resp = await client.request<ProjectEnvDeleteResponse, Omit<ProjectEnvDeleteRequest, 'id'>>(
|
|
26
|
+
'DELETE',
|
|
27
|
+
`/cli/project/${id}/env`,
|
|
28
|
+
ProjectEnvDeleteResponseSchema,
|
|
29
|
+
{
|
|
30
|
+
env,
|
|
31
|
+
secrets,
|
|
32
|
+
}
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
if (!resp.success) {
|
|
36
|
+
throw new Error(resp.message ?? 'failed to delete project env');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Delete operations don't return data, success is sufficient
|
|
40
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { APIClient, APIResponseSchema } from '../api';
|
|
3
|
+
import type { Project } from './get';
|
|
4
|
+
import { projectGet } from './get';
|
|
5
|
+
|
|
6
|
+
const _ProjectEnvUpdateRequestSchema = z.object({
|
|
7
|
+
id: z.string().describe('the project id'),
|
|
8
|
+
env: z.record(z.string(), z.string()).optional().describe('environment variables to set/update'),
|
|
9
|
+
secrets: z.record(z.string(), z.string()).optional().describe('secrets to set/update'),
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
const ProjectEnvUpdateResponseSchema = APIResponseSchema(
|
|
13
|
+
z.object({
|
|
14
|
+
id: z.string().describe('the project id'),
|
|
15
|
+
orgId: z.string().describe('the organization id'),
|
|
16
|
+
api_key: z.string().optional().describe('the SDK api key for the project'),
|
|
17
|
+
env: z.record(z.string(), z.string()).optional().describe('the environment key/values'),
|
|
18
|
+
secrets: z.record(z.string(), z.string()).optional().describe('the secrets key/values'),
|
|
19
|
+
})
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
type ProjectEnvUpdateRequest = z.infer<typeof _ProjectEnvUpdateRequestSchema>;
|
|
23
|
+
type ProjectEnvUpdateResponse = z.infer<typeof ProjectEnvUpdateResponseSchema>;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Update environment variables and/or secrets for a project.
|
|
27
|
+
* This will merge the provided env/secrets with existing values.
|
|
28
|
+
* Keys starting with 'AGENTUITY_' should be filtered out before calling this function.
|
|
29
|
+
*/
|
|
30
|
+
export async function projectEnvUpdate(
|
|
31
|
+
client: APIClient,
|
|
32
|
+
request: ProjectEnvUpdateRequest
|
|
33
|
+
): Promise<Project> {
|
|
34
|
+
const { id, env, secrets } = request;
|
|
35
|
+
|
|
36
|
+
const resp = await client.request<ProjectEnvUpdateResponse, Omit<ProjectEnvUpdateRequest, 'id'>>(
|
|
37
|
+
'PUT',
|
|
38
|
+
`/cli/project/${id}/env`,
|
|
39
|
+
ProjectEnvUpdateResponseSchema,
|
|
40
|
+
{
|
|
41
|
+
env,
|
|
42
|
+
secrets,
|
|
43
|
+
}
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
if (!resp.success) {
|
|
47
|
+
throw new Error(resp.message ?? 'failed to update project env');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (resp.data) {
|
|
51
|
+
return resp.data;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// If the API didn't return data, fetch the updated project
|
|
55
|
+
// This handles backends that return success without the full project data
|
|
56
|
+
return projectGet(client, { id, mask: false });
|
|
57
|
+
}
|
|
@@ -1,25 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { APIClient, APIResponseSchema, APIError } from '../api';
|
|
3
3
|
|
|
4
|
-
// func ProjectWithNameExists(ctx context.Context, logger logger.Logger, baseUrl string, token string, orgId string, name string) (bool, error) {
|
|
5
|
-
// client := util.NewAPIClient(ctx, logger, baseUrl, token)
|
|
6
|
-
|
|
7
|
-
// var resp Response[bool]
|
|
8
|
-
// if err := client.Do("GET", fmt.Sprintf("/cli/project/exists/%s?orgId=%s", url.PathEscape(name), url.PathEscape(orgId)), nil, &resp); err != nil {
|
|
9
|
-
// var apiErr *util.APIError
|
|
10
|
-
// if errors.As(err, &apiErr) {
|
|
11
|
-
// if apiErr.Status == http.StatusConflict {
|
|
12
|
-
// return true, nil
|
|
13
|
-
// }
|
|
14
|
-
// if apiErr.Status == http.StatusUnprocessableEntity {
|
|
15
|
-
// return false, apiErr
|
|
16
|
-
// }
|
|
17
|
-
// }
|
|
18
|
-
// return false, fmt.Errorf("error validating project name: %w", err)
|
|
19
|
-
// }
|
|
20
|
-
// return resp.Data, nil
|
|
21
|
-
// }
|
|
22
|
-
|
|
23
4
|
const _ProjectExistsRequestSchema = z.object({
|
|
24
5
|
name: z.string().max(255).min(1).describe('the name of the new project'),
|
|
25
6
|
organization_id: z
|
|
@@ -35,7 +16,7 @@ export type ProjectExistsRequest = z.infer<typeof _ProjectExistsRequestSchema>;
|
|
|
35
16
|
export type ProjectExistsResponse = z.infer<typeof ProjectExistsResponseSchema>;
|
|
36
17
|
|
|
37
18
|
/**
|
|
38
|
-
*
|
|
19
|
+
* Check if a project exists by name within an organization
|
|
39
20
|
*
|
|
40
21
|
* @param client
|
|
41
22
|
* @param body
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { APIClient, APIResponseSchema } from '../api';
|
|
3
|
+
|
|
4
|
+
const _ProjectGetRequestSchema = z.object({
|
|
5
|
+
id: z.string().describe('the project id'),
|
|
6
|
+
mask: z.boolean().default(true).describe('if the secrets should be returned masked'),
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
const ProjectGetResponseSchema = APIResponseSchema(
|
|
10
|
+
z.object({
|
|
11
|
+
id: z.string().describe('the project id'),
|
|
12
|
+
orgId: z.string().describe('the organization id'),
|
|
13
|
+
api_key: z.string().optional().describe('the SDK api key for the project'),
|
|
14
|
+
env: z.record(z.string(), z.string()).optional().describe('the environment key/values'),
|
|
15
|
+
secrets: z.record(z.string(), z.string()).optional().describe('the secrets key/values'),
|
|
16
|
+
})
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
type ProjectGetRequest = z.infer<typeof _ProjectGetRequestSchema>;
|
|
20
|
+
type ProjectGetResponse = z.infer<typeof ProjectGetResponseSchema>;
|
|
21
|
+
|
|
22
|
+
export type Project = NonNullable<ProjectGetResponse['data']>;
|
|
23
|
+
|
|
24
|
+
export async function projectGet(client: APIClient, request: ProjectGetRequest): Promise<Project> {
|
|
25
|
+
const resp = await client.request<ProjectGetResponse, ProjectGetRequest>(
|
|
26
|
+
'GET',
|
|
27
|
+
`/cli/project/${request.id}?mask=${request.mask ?? true}`,
|
|
28
|
+
ProjectGetResponseSchema
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
if (resp.data) {
|
|
32
|
+
return resp.data;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
throw new Error(resp.message ?? 'failed to get project');
|
|
36
|
+
}
|
package/src/api/project/index.ts
CHANGED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { APIClient, APIResponseSchema } from '../api';
|
|
3
|
+
|
|
4
|
+
const ProjectListResponseSchema = APIResponseSchema(
|
|
5
|
+
z.array(
|
|
6
|
+
z.object({
|
|
7
|
+
id: z.string().describe('the project id'),
|
|
8
|
+
name: z.string().describe('the project name'),
|
|
9
|
+
description: z.string().optional().describe('the project description'),
|
|
10
|
+
orgId: z.string().describe('the organization id that this project is registered with'),
|
|
11
|
+
orgName: z.string().describe('the organization name'),
|
|
12
|
+
})
|
|
13
|
+
)
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
export type ProjectListResponse = z.infer<typeof ProjectListResponseSchema>;
|
|
17
|
+
export type ProjectList = NonNullable<ProjectListResponse['data']>;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* List all projects
|
|
21
|
+
*
|
|
22
|
+
* @param client
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
export async function projectList(client: APIClient): Promise<ProjectList> {
|
|
26
|
+
const resp = await client.request<ProjectListResponse>(
|
|
27
|
+
'GET',
|
|
28
|
+
'/cli/project',
|
|
29
|
+
ProjectListResponseSchema
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
if (resp.data) {
|
|
33
|
+
return resp.data;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
throw new Error(resp.message ?? 'failed to list projects');
|
|
37
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './whoami';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { APIResponseSchema, APIClient } from '../api';
|
|
3
|
+
|
|
4
|
+
const OrganizationSchema = z.object({
|
|
5
|
+
id: z.string().describe('the unique id for the organization'),
|
|
6
|
+
name: z.string().describe('the name of the organization'),
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
const WhoamiResponseSchema = APIResponseSchema(
|
|
10
|
+
z.object({
|
|
11
|
+
firstName: z.string().describe('the first name of the user'),
|
|
12
|
+
lastName: z.string().describe('the last name of the user'),
|
|
13
|
+
organizations: z
|
|
14
|
+
.array(OrganizationSchema)
|
|
15
|
+
.describe('the organizations the user is a member of'),
|
|
16
|
+
})
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
export type WhoamiResponse = z.infer<typeof WhoamiResponseSchema>;
|
|
20
|
+
export type User = NonNullable<WhoamiResponse['data']>;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Get the current authenticated user information
|
|
24
|
+
*
|
|
25
|
+
* @param client
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
export async function whoami(client: APIClient): Promise<WhoamiResponse> {
|
|
29
|
+
return client.request<WhoamiResponse>('GET', '/cli/auth/user', WhoamiResponseSchema);
|
|
30
|
+
}
|