@agentuity/server 0.0.42 → 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/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/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/index.d.ts +2 -0
- package/dist/api/project/index.d.ts.map +1 -1
- package/dist/api/project/index.js +2 -0
- package/dist/api/project/index.js.map +1 -1
- 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/index.ts +1 -0
- package/src/api/project/env-delete.ts +40 -0
- package/src/api/project/env-update.ts +57 -0
- package/src/api/project/index.ts +2 -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/api/index.d.ts
CHANGED
package/dist/api/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,OAAO,CAAC;AACtB,cAAc,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,OAAO,CAAC;AACtB,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC"}
|
package/dist/api/index.js
CHANGED
package/dist/api/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,OAAO,CAAC;AACtB,cAAc,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,OAAO,CAAC;AACtB,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { APIClient } from '../api';
|
|
3
|
+
declare const _ProjectEnvDeleteRequestSchema: z.ZodObject<{
|
|
4
|
+
id: z.ZodString;
|
|
5
|
+
env: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
6
|
+
secrets: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
7
|
+
}, z.core.$strip>;
|
|
8
|
+
type ProjectEnvDeleteRequest = z.infer<typeof _ProjectEnvDeleteRequestSchema>;
|
|
9
|
+
/**
|
|
10
|
+
* Delete environment variables and/or secrets from a project.
|
|
11
|
+
* Provide arrays of keys to delete.
|
|
12
|
+
*/
|
|
13
|
+
export declare function projectEnvDelete(client: APIClient, request: ProjectEnvDeleteRequest): Promise<void>;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=env-delete.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env-delete.d.ts","sourceRoot":"","sources":["../../../src/api/project/env-delete.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,SAAS,EAAqB,MAAM,QAAQ,CAAC;AAEtD,QAAA,MAAM,8BAA8B;;;;iBAIlC,CAAC;AAIH,KAAK,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,8BAA8B,CAAC,CAAC;AAG9E;;;GAGG;AACH,wBAAsB,gBAAgB,CACrC,MAAM,EAAE,SAAS,EACjB,OAAO,EAAE,uBAAuB,GAC9B,OAAO,CAAC,IAAI,CAAC,CAkBf"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { APIResponseSchema } from '../api';
|
|
3
|
+
const _ProjectEnvDeleteRequestSchema = z.object({
|
|
4
|
+
id: z.string().describe('the project id'),
|
|
5
|
+
env: z.array(z.string()).optional().describe('environment variable keys to delete'),
|
|
6
|
+
secrets: z.array(z.string()).optional().describe('secret keys to delete'),
|
|
7
|
+
});
|
|
8
|
+
const ProjectEnvDeleteResponseSchema = APIResponseSchema(z.object({}));
|
|
9
|
+
/**
|
|
10
|
+
* Delete environment variables and/or secrets from a project.
|
|
11
|
+
* Provide arrays of keys to delete.
|
|
12
|
+
*/
|
|
13
|
+
export async function projectEnvDelete(client, request) {
|
|
14
|
+
const { id, env, secrets } = request;
|
|
15
|
+
const resp = await client.request('DELETE', `/cli/project/${id}/env`, ProjectEnvDeleteResponseSchema, {
|
|
16
|
+
env,
|
|
17
|
+
secrets,
|
|
18
|
+
});
|
|
19
|
+
if (!resp.success) {
|
|
20
|
+
throw new Error(resp.message ?? 'failed to delete project env');
|
|
21
|
+
}
|
|
22
|
+
// Delete operations don't return data, success is sufficient
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=env-delete.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env-delete.js","sourceRoot":"","sources":["../../../src/api/project/env-delete.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAa,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAEtD,MAAM,8BAA8B,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/C,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,gBAAgB,CAAC;IACzC,GAAG,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,qCAAqC,CAAC;IACnF,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,uBAAuB,CAAC;CACzE,CAAC,CAAC;AAEH,MAAM,8BAA8B,GAAG,iBAAiB,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;AAKvE;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACrC,MAAiB,EACjB,OAAgC;IAEhC,MAAM,EAAE,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAErC,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,OAAO,CAChC,QAAQ,EACR,gBAAgB,EAAE,MAAM,EACxB,8BAA8B,EAC9B;QACC,GAAG;QACH,OAAO;KACP,CACD,CAAC;IAEF,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,OAAO,IAAI,8BAA8B,CAAC,CAAC;IACjE,CAAC;IAED,6DAA6D;AAC9D,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { APIClient } from '../api';
|
|
3
|
+
import type { Project } from './get';
|
|
4
|
+
declare const _ProjectEnvUpdateRequestSchema: z.ZodObject<{
|
|
5
|
+
id: z.ZodString;
|
|
6
|
+
env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
7
|
+
secrets: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
8
|
+
}, z.core.$strip>;
|
|
9
|
+
type ProjectEnvUpdateRequest = z.infer<typeof _ProjectEnvUpdateRequestSchema>;
|
|
10
|
+
/**
|
|
11
|
+
* Update environment variables and/or secrets for a project.
|
|
12
|
+
* This will merge the provided env/secrets with existing values.
|
|
13
|
+
* Keys starting with 'AGENTUITY_' should be filtered out before calling this function.
|
|
14
|
+
*/
|
|
15
|
+
export declare function projectEnvUpdate(client: APIClient, request: ProjectEnvUpdateRequest): Promise<Project>;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=env-update.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env-update.d.ts","sourceRoot":"","sources":["../../../src/api/project/env-update.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,SAAS,EAAqB,MAAM,QAAQ,CAAC;AACtD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAGrC,QAAA,MAAM,8BAA8B;;;;iBAIlC,CAAC;AAYH,KAAK,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,8BAA8B,CAAC,CAAC;AAG9E;;;;GAIG;AACH,wBAAsB,gBAAgB,CACrC,MAAM,EAAE,SAAS,EACjB,OAAO,EAAE,uBAAuB,GAC9B,OAAO,CAAC,OAAO,CAAC,CAwBlB"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { APIResponseSchema } from '../api';
|
|
3
|
+
import { projectGet } from './get';
|
|
4
|
+
const _ProjectEnvUpdateRequestSchema = z.object({
|
|
5
|
+
id: z.string().describe('the project id'),
|
|
6
|
+
env: z.record(z.string(), z.string()).optional().describe('environment variables to set/update'),
|
|
7
|
+
secrets: z.record(z.string(), z.string()).optional().describe('secrets to set/update'),
|
|
8
|
+
});
|
|
9
|
+
const ProjectEnvUpdateResponseSchema = APIResponseSchema(z.object({
|
|
10
|
+
id: z.string().describe('the project id'),
|
|
11
|
+
orgId: z.string().describe('the organization id'),
|
|
12
|
+
api_key: z.string().optional().describe('the SDK api key for the project'),
|
|
13
|
+
env: z.record(z.string(), z.string()).optional().describe('the environment key/values'),
|
|
14
|
+
secrets: z.record(z.string(), z.string()).optional().describe('the secrets key/values'),
|
|
15
|
+
}));
|
|
16
|
+
/**
|
|
17
|
+
* Update environment variables and/or secrets for a project.
|
|
18
|
+
* This will merge the provided env/secrets with existing values.
|
|
19
|
+
* Keys starting with 'AGENTUITY_' should be filtered out before calling this function.
|
|
20
|
+
*/
|
|
21
|
+
export async function projectEnvUpdate(client, request) {
|
|
22
|
+
const { id, env, secrets } = request;
|
|
23
|
+
const resp = await client.request('PUT', `/cli/project/${id}/env`, ProjectEnvUpdateResponseSchema, {
|
|
24
|
+
env,
|
|
25
|
+
secrets,
|
|
26
|
+
});
|
|
27
|
+
if (!resp.success) {
|
|
28
|
+
throw new Error(resp.message ?? 'failed to update project env');
|
|
29
|
+
}
|
|
30
|
+
if (resp.data) {
|
|
31
|
+
return resp.data;
|
|
32
|
+
}
|
|
33
|
+
// If the API didn't return data, fetch the updated project
|
|
34
|
+
// This handles backends that return success without the full project data
|
|
35
|
+
return projectGet(client, { id, mask: false });
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=env-update.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env-update.js","sourceRoot":"","sources":["../../../src/api/project/env-update.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAa,iBAAiB,EAAE,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AiB,EACjB,OAAgC;IAEhC,MAAM,EAAE,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAErC,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,OAAO,CAChC,KAAK,EACL,gBAAgB,EAAE,MAAM,EACxB,8BAA8B,EAC9B;QACC,GAAG;QACH,OAAO;KACP,CACD,CAAC;IAEF,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,OAAO,IAAI,8BAA8B,CAAC,CAAC;IACjE,CAAC;IAED,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;QACf,OAAO,IAAI,CAAC,IAAI,CAAC;IAClB,CAAC;IAED,2DAA2D;IAC3D,0EAA0E;IAC1E,OAAO,UAAU,CAAC,MAAM,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;AAChD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/project/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,OAAO,CAAC;AACtB,cAAc,QAAQ,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/project/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,OAAO,CAAC;AACtB,cAAc,QAAQ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/project/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,OAAO,CAAC;AACtB,cAAc,QAAQ,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/project/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,OAAO,CAAC;AACtB,cAAc,QAAQ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/user/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/user/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { APIClient } from '../api';
|
|
3
|
+
declare const WhoamiResponseSchema: z.ZodObject<{
|
|
4
|
+
success: z.ZodBoolean;
|
|
5
|
+
message: z.ZodOptional<z.ZodString>;
|
|
6
|
+
data: z.ZodOptional<z.ZodObject<{
|
|
7
|
+
firstName: z.ZodString;
|
|
8
|
+
lastName: z.ZodString;
|
|
9
|
+
organizations: z.ZodArray<z.ZodObject<{
|
|
10
|
+
id: z.ZodString;
|
|
11
|
+
name: z.ZodString;
|
|
12
|
+
}, z.core.$strip>>;
|
|
13
|
+
}, z.core.$strip>>;
|
|
14
|
+
}, z.core.$strip>;
|
|
15
|
+
export type WhoamiResponse = z.infer<typeof WhoamiResponseSchema>;
|
|
16
|
+
export type User = NonNullable<WhoamiResponse['data']>;
|
|
17
|
+
/**
|
|
18
|
+
* Get the current authenticated user information
|
|
19
|
+
*
|
|
20
|
+
* @param client
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
23
|
+
export declare function whoami(client: APIClient): Promise<WhoamiResponse>;
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=whoami.d.ts.map
|
|
@@ -0,0 +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,oBAAoB;;;;;;;;;;;iBAQzB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAClE,MAAM,MAAM,IAAI,GAAG,WAAW,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;AAEvD;;;;;GAKG;AACH,wBAAsB,MAAM,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,cAAc,CAAC,CAEvE"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { APIResponseSchema } from '../api';
|
|
3
|
+
const OrganizationSchema = z.object({
|
|
4
|
+
id: z.string().describe('the unique id for the organization'),
|
|
5
|
+
name: z.string().describe('the name of the organization'),
|
|
6
|
+
});
|
|
7
|
+
const WhoamiResponseSchema = APIResponseSchema(z.object({
|
|
8
|
+
firstName: z.string().describe('the first name of the user'),
|
|
9
|
+
lastName: z.string().describe('the last name of the user'),
|
|
10
|
+
organizations: z
|
|
11
|
+
.array(OrganizationSchema)
|
|
12
|
+
.describe('the organizations the user is a member of'),
|
|
13
|
+
}));
|
|
14
|
+
/**
|
|
15
|
+
* Get the current authenticated user information
|
|
16
|
+
*
|
|
17
|
+
* @param client
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
export async function whoami(client) {
|
|
21
|
+
return client.request('GET', '/cli/auth/user', WhoamiResponseSchema);
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=whoami.js.map
|
|
@@ -0,0 +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,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,oCAAoC,CAAC;IAC7D,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,8BAA8B,CAAC;CACzD,CAAC,CAAC;AAEH,MAAM,oBAAoB,GAAG,iBAAiB,CAC7C,CAAC,CAAC,MAAM,CAAC;IACR,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;SACd,KAAK,CAAC,kBAAkB,CAAC;SACzB,QAAQ,CAAC,2CAA2C,CAAC;CACvD,CAAC,CACF,CAAC;AAKF;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,MAAiB;IAC7C,OAAO,MAAM,CAAC,OAAO,CAAiB,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,CAAC,CAAC;AACtF,CAAC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,OAAO,CAAC;AACtB,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,YAAY,EACX,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,oBAAoB,EACpB,kBAAkB,EAClB,IAAI,EACJ,gBAAgB,GAChB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,OAAO,CAAC;AACtB,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,YAAY,EACX,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,oBAAoB,EACpB,kBAAkB,EAClB,IAAI,EACJ,gBAAgB,GAChB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,OAAO,CAAC;AACtB,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAUxB,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,OAAO,CAAC;AACtB,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAUxB,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Logger, LogLevel } from '@agentuity/core';
|
|
2
|
+
export type ColorScheme = 'light' | 'dark';
|
|
3
|
+
/**
|
|
4
|
+
* Console logger implementation
|
|
5
|
+
*/
|
|
6
|
+
export declare class ConsoleLogger implements Logger {
|
|
7
|
+
level: LogLevel;
|
|
8
|
+
private showTimestamp;
|
|
9
|
+
private colorScheme;
|
|
10
|
+
private colors;
|
|
11
|
+
private showPrefix;
|
|
12
|
+
private context;
|
|
13
|
+
constructor(level?: LogLevel, showTimestamp?: boolean, colorScheme?: ColorScheme, context?: Record<string, unknown>);
|
|
14
|
+
setLevel(level: LogLevel): void;
|
|
15
|
+
setTimestamp(enabled: boolean): void;
|
|
16
|
+
setColorScheme(scheme: ColorScheme): void;
|
|
17
|
+
setShowPrefix(show: boolean): void;
|
|
18
|
+
private shouldLog;
|
|
19
|
+
private formatMessage;
|
|
20
|
+
private log;
|
|
21
|
+
trace(message: unknown, ...args: unknown[]): void;
|
|
22
|
+
debug(message: unknown, ...args: unknown[]): void;
|
|
23
|
+
info(message: unknown, ...args: unknown[]): void;
|
|
24
|
+
warn(message: unknown, ...args: unknown[]): void;
|
|
25
|
+
error(message: unknown, ...args: unknown[]): void;
|
|
26
|
+
fatal(message: unknown, ...args: unknown[]): never;
|
|
27
|
+
child(opts: Record<string, unknown>): Logger;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Create a new console logger instance
|
|
31
|
+
*
|
|
32
|
+
* @param level - The minimum log level to display
|
|
33
|
+
* @param showTimestamp - Whether to show timestamps in log messages
|
|
34
|
+
* @param colorScheme - The color scheme to use ('light' or 'dark')
|
|
35
|
+
* @param context - Initial context for the logger
|
|
36
|
+
* @returns A new ConsoleLogger instance
|
|
37
|
+
*/
|
|
38
|
+
export declare function createLogger(level?: LogLevel, showTimestamp?: boolean, colorScheme?: ColorScheme, context?: Record<string, unknown>): Logger;
|
|
39
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAiDxD,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,MAAM,CAAC;AAgE3C;;GAEG;AACH,qBAAa,aAAc,YAAW,MAAM;IACpC,KAAK,EAAE,QAAQ,CAAC;IACvB,OAAO,CAAC,aAAa,CAAU;IAC/B,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,MAAM,CAA8B;IAC5C,OAAO,CAAC,UAAU,CAAQ;IAC1B,OAAO,CAAC,OAAO,CAA0B;gBAGxC,KAAK,GAAE,QAAiB,EACxB,aAAa,GAAE,OAAe,EAC9B,WAAW,GAAE,WAAoB,EACjC,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM;IAStC,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;IAI/B,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAIpC,cAAc,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI;IAKzC,aAAa,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI;IAIlC,OAAO,CAAC,SAAS;IAIjB,OAAO,CAAC,aAAa;IAgCrB,OAAO,CAAC,GAAG;IA+CX,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAIjD,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAIjD,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAIhD,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAIhD,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAIjD,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,KAAK;IAKlD,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;CAM5C;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAC3B,KAAK,GAAE,QAAiB,EACxB,aAAa,GAAE,OAAe,EAC9B,WAAW,GAAE,WAAoB,EACjC,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GACnC,MAAM,CAER"}
|
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,wDAAwD;AACxD,SAAS,SAAS,CAAC,GAAW;IAC7B,MAAM,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC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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
|
+
}
|
package/src/api/project/index.ts
CHANGED
|
@@ -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
|
+
}
|
package/src/index.ts
CHANGED
package/src/logger.ts
ADDED
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import type { Logger, LogLevel } from '@agentuity/core';
|
|
2
|
+
import { format, inspect } from 'node:util';
|
|
3
|
+
|
|
4
|
+
const LOG_LEVELS: Record<LogLevel, number> = {
|
|
5
|
+
trace: 0,
|
|
6
|
+
debug: 1,
|
|
7
|
+
info: 2,
|
|
8
|
+
warn: 3,
|
|
9
|
+
error: 4,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const BOLD = '\x1b[1m';
|
|
13
|
+
const RESET = '\x1b[0m';
|
|
14
|
+
|
|
15
|
+
// Helper to convert hex color to ANSI 24-bit color code
|
|
16
|
+
function hexToAnsi(hex: string): string {
|
|
17
|
+
const r = parseInt(hex.slice(1, 3), 16);
|
|
18
|
+
const g = parseInt(hex.slice(3, 5), 16);
|
|
19
|
+
const b = parseInt(hex.slice(5, 7), 16);
|
|
20
|
+
return `\x1b[38;2;${r};${g};${b}m`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function shouldUseColors(): boolean {
|
|
24
|
+
// Check for NO_COLOR environment variable (any non-empty value disables colors)
|
|
25
|
+
if (process.env.NO_COLOR) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Check for TERM=dumb
|
|
30
|
+
if (process.env.TERM === 'dumb') {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Check if stdout is a TTY
|
|
35
|
+
if (process.stdout && typeof process.stdout.isTTY !== 'undefined' && !process.stdout.isTTY) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const USE_COLORS = shouldUseColors();
|
|
43
|
+
|
|
44
|
+
interface LogColors {
|
|
45
|
+
level: string;
|
|
46
|
+
message: string;
|
|
47
|
+
timestamp: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export type ColorScheme = 'light' | 'dark';
|
|
51
|
+
|
|
52
|
+
function getLogColors(scheme: ColorScheme): Record<LogLevel, LogColors> {
|
|
53
|
+
if (scheme === 'light') {
|
|
54
|
+
// Darker, high-contrast colors for light backgrounds
|
|
55
|
+
return {
|
|
56
|
+
trace: {
|
|
57
|
+
level: hexToAnsi('#008B8B') + BOLD, // Dark cyan
|
|
58
|
+
message: hexToAnsi('#4B4B4B'), // Dark gray
|
|
59
|
+
timestamp: hexToAnsi('#808080'), // Gray
|
|
60
|
+
},
|
|
61
|
+
debug: {
|
|
62
|
+
level: hexToAnsi('#0000CD') + BOLD, // Medium blue
|
|
63
|
+
message: hexToAnsi('#006400'), // Dark green
|
|
64
|
+
timestamp: hexToAnsi('#808080'),
|
|
65
|
+
},
|
|
66
|
+
info: {
|
|
67
|
+
level: hexToAnsi('#FF8C00') + BOLD, // Dark orange
|
|
68
|
+
message: hexToAnsi('#0066CC') + BOLD, // Strong blue
|
|
69
|
+
timestamp: hexToAnsi('#808080'),
|
|
70
|
+
},
|
|
71
|
+
warn: {
|
|
72
|
+
level: hexToAnsi('#9400D3') + BOLD, // Dark violet
|
|
73
|
+
message: hexToAnsi('#8B008B'), // Dark magenta
|
|
74
|
+
timestamp: hexToAnsi('#808080'),
|
|
75
|
+
},
|
|
76
|
+
error: {
|
|
77
|
+
level: hexToAnsi('#DC143C') + BOLD, // Crimson
|
|
78
|
+
message: hexToAnsi('#8B0000') + BOLD, // Dark red
|
|
79
|
+
timestamp: hexToAnsi('#808080'),
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Dark mode colors (brighter for dark backgrounds)
|
|
85
|
+
return {
|
|
86
|
+
trace: {
|
|
87
|
+
level: hexToAnsi('#00FFFF') + BOLD, // Cyan
|
|
88
|
+
message: hexToAnsi('#A0A0A0'), // Light gray
|
|
89
|
+
timestamp: hexToAnsi('#666666'),
|
|
90
|
+
},
|
|
91
|
+
debug: {
|
|
92
|
+
level: hexToAnsi('#5C9CFF') + BOLD, // Blue
|
|
93
|
+
message: hexToAnsi('#90EE90'), // Light green
|
|
94
|
+
timestamp: hexToAnsi('#666666'),
|
|
95
|
+
},
|
|
96
|
+
info: {
|
|
97
|
+
level: hexToAnsi('#FFD700') + BOLD, // Gold/Yellow
|
|
98
|
+
message: hexToAnsi('#FFFFFF') + BOLD, // White
|
|
99
|
+
timestamp: hexToAnsi('#666666'),
|
|
100
|
+
},
|
|
101
|
+
warn: {
|
|
102
|
+
level: hexToAnsi('#FF00FF') + BOLD, // Magenta
|
|
103
|
+
message: hexToAnsi('#FF00FF'), // Magenta
|
|
104
|
+
timestamp: hexToAnsi('#666666'),
|
|
105
|
+
},
|
|
106
|
+
error: {
|
|
107
|
+
level: hexToAnsi('#FF4444') + BOLD, // Red
|
|
108
|
+
message: hexToAnsi('#FF4444'), // Red
|
|
109
|
+
timestamp: hexToAnsi('#666666'),
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Console logger implementation
|
|
116
|
+
*/
|
|
117
|
+
export class ConsoleLogger implements Logger {
|
|
118
|
+
public level: LogLevel;
|
|
119
|
+
private showTimestamp: boolean;
|
|
120
|
+
private colorScheme: ColorScheme;
|
|
121
|
+
private colors: Record<LogLevel, LogColors>;
|
|
122
|
+
private showPrefix = true;
|
|
123
|
+
private context: Record<string, unknown>;
|
|
124
|
+
|
|
125
|
+
constructor(
|
|
126
|
+
level: LogLevel = 'info',
|
|
127
|
+
showTimestamp: boolean = false,
|
|
128
|
+
colorScheme: ColorScheme = 'dark',
|
|
129
|
+
context: Record<string, unknown> = {}
|
|
130
|
+
) {
|
|
131
|
+
this.level = level;
|
|
132
|
+
this.showTimestamp = showTimestamp;
|
|
133
|
+
this.colorScheme = colorScheme;
|
|
134
|
+
this.colors = getLogColors(this.colorScheme);
|
|
135
|
+
this.context = context;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
setLevel(level: LogLevel): void {
|
|
139
|
+
this.level = level;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
setTimestamp(enabled: boolean): void {
|
|
143
|
+
this.showTimestamp = enabled;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
setColorScheme(scheme: ColorScheme): void {
|
|
147
|
+
this.colorScheme = scheme;
|
|
148
|
+
this.colors = getLogColors(this.colorScheme);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
setShowPrefix(show: boolean): void {
|
|
152
|
+
this.showPrefix = show;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
private shouldLog(level: LogLevel): boolean {
|
|
156
|
+
return LOG_LEVELS[level] >= LOG_LEVELS[this.level];
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
private formatMessage(message: unknown, args: unknown[]): string {
|
|
160
|
+
try {
|
|
161
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
162
|
+
const base = format(message as any, ...(args as any[]));
|
|
163
|
+
|
|
164
|
+
if (!this.context || Object.keys(this.context).length === 0) {
|
|
165
|
+
return base;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const ctx = Object.entries(this.context)
|
|
169
|
+
.map(
|
|
170
|
+
([k, v]) =>
|
|
171
|
+
`${k}=${typeof v === 'object' ? inspect(v, { depth: 2, maxArrayLength: 50, colors: false }) : String(v)}`
|
|
172
|
+
)
|
|
173
|
+
.join(' ');
|
|
174
|
+
|
|
175
|
+
const result = `${base} ${ctx}`;
|
|
176
|
+
|
|
177
|
+
const MAX_LENGTH = 10000;
|
|
178
|
+
if (result.length > MAX_LENGTH) {
|
|
179
|
+
return `${result.slice(0, MAX_LENGTH)} …(+${result.length - MAX_LENGTH} chars truncated)`;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return result;
|
|
183
|
+
} catch {
|
|
184
|
+
const base = [String(message), ...args.map((a) => String(a))].join(' ');
|
|
185
|
+
return this.context && Object.keys(this.context).length > 0
|
|
186
|
+
? `${base} ${JSON.stringify(this.context)}`
|
|
187
|
+
: base;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
private log(level: LogLevel, message: unknown, ...args: unknown[]): void {
|
|
192
|
+
if (!this.shouldLog(level)) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const colors = this.colors[level];
|
|
197
|
+
const levelText = `[${level.toUpperCase()}]`;
|
|
198
|
+
const formattedMessage = this.formatMessage(message, args);
|
|
199
|
+
|
|
200
|
+
let output = '';
|
|
201
|
+
|
|
202
|
+
if (USE_COLORS) {
|
|
203
|
+
if (this.showPrefix) {
|
|
204
|
+
if (this.showTimestamp) {
|
|
205
|
+
const timestamp = new Date().toISOString();
|
|
206
|
+
output = `${colors.timestamp}[${timestamp}]${RESET} ${colors.level}${levelText}${RESET} ${colors.message}${formattedMessage}${RESET}`;
|
|
207
|
+
} else {
|
|
208
|
+
output = `${colors.level}${levelText}${RESET} ${colors.message}${formattedMessage}${RESET}`;
|
|
209
|
+
}
|
|
210
|
+
} else {
|
|
211
|
+
// No prefix - just the message with color
|
|
212
|
+
output = `${colors.message}${formattedMessage}${RESET}`;
|
|
213
|
+
}
|
|
214
|
+
} else {
|
|
215
|
+
// No colors - plain text output
|
|
216
|
+
if (this.showPrefix) {
|
|
217
|
+
if (this.showTimestamp) {
|
|
218
|
+
const timestamp = new Date().toISOString();
|
|
219
|
+
output = `[${timestamp}] ${levelText} ${formattedMessage}`;
|
|
220
|
+
} else {
|
|
221
|
+
output = `${levelText} ${formattedMessage}`;
|
|
222
|
+
}
|
|
223
|
+
} else {
|
|
224
|
+
// No prefix, no colors - just message
|
|
225
|
+
output = formattedMessage;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (level === 'error') {
|
|
230
|
+
console.error(output);
|
|
231
|
+
} else if (level === 'warn') {
|
|
232
|
+
console.warn(output);
|
|
233
|
+
} else {
|
|
234
|
+
console.log(output);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
trace(message: unknown, ...args: unknown[]): void {
|
|
239
|
+
this.log('trace', message, ...args);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
debug(message: unknown, ...args: unknown[]): void {
|
|
243
|
+
this.log('debug', message, ...args);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
info(message: unknown, ...args: unknown[]): void {
|
|
247
|
+
this.log('info', message, ...args);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
warn(message: unknown, ...args: unknown[]): void {
|
|
251
|
+
this.log('warn', message, ...args);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
error(message: unknown, ...args: unknown[]): void {
|
|
255
|
+
this.log('error', message, ...args);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
fatal(message: unknown, ...args: unknown[]): never {
|
|
259
|
+
this.log('error', message, ...args);
|
|
260
|
+
process.exit(1);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
child(opts: Record<string, unknown>): Logger {
|
|
264
|
+
return new ConsoleLogger(this.level, this.showTimestamp, this.colorScheme, {
|
|
265
|
+
...this.context,
|
|
266
|
+
...opts,
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Create a new console logger instance
|
|
273
|
+
*
|
|
274
|
+
* @param level - The minimum log level to display
|
|
275
|
+
* @param showTimestamp - Whether to show timestamps in log messages
|
|
276
|
+
* @param colorScheme - The color scheme to use ('light' or 'dark')
|
|
277
|
+
* @param context - Initial context for the logger
|
|
278
|
+
* @returns A new ConsoleLogger instance
|
|
279
|
+
*/
|
|
280
|
+
export function createLogger(
|
|
281
|
+
level: LogLevel = 'info',
|
|
282
|
+
showTimestamp: boolean = false,
|
|
283
|
+
colorScheme: ColorScheme = 'dark',
|
|
284
|
+
context: Record<string, unknown> = {}
|
|
285
|
+
): Logger {
|
|
286
|
+
return new ConsoleLogger(level, showTimestamp, colorScheme, context);
|
|
287
|
+
}
|