@agentuity/cli 0.0.48 → 0.0.50
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/bin/cli.ts +26 -5
- package/dist/banner.d.ts +1 -1
- package/dist/banner.d.ts.map +1 -1
- package/dist/cli-logger.d.ts +27 -0
- package/dist/cli-logger.d.ts.map +1 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cmd/agents/index.d.ts +2 -0
- package/dist/cmd/agents/index.d.ts.map +1 -0
- package/dist/cmd/auth/index.d.ts.map +1 -1
- package/dist/cmd/auth/login.d.ts.map +1 -1
- package/dist/cmd/auth/logout.d.ts.map +1 -1
- package/dist/cmd/auth/signup.d.ts.map +1 -1
- package/dist/cmd/auth/ssh/add.d.ts.map +1 -1
- package/dist/cmd/auth/ssh/delete.d.ts.map +1 -1
- package/dist/cmd/auth/ssh/index.d.ts +1 -2
- package/dist/cmd/auth/ssh/index.d.ts.map +1 -1
- package/dist/cmd/auth/ssh/list.d.ts.map +1 -1
- package/dist/cmd/auth/whoami.d.ts.map +1 -1
- package/dist/cmd/bundle/ast.d.ts +3 -1
- package/dist/cmd/bundle/ast.d.ts.map +1 -1
- package/dist/cmd/bundle/index.d.ts.map +1 -1
- package/dist/cmd/bundle/plugin.d.ts.map +1 -1
- package/dist/cmd/capabilities/index.d.ts +4 -0
- package/dist/cmd/capabilities/index.d.ts.map +1 -0
- package/dist/cmd/capabilities/show.d.ts +20 -0
- package/dist/cmd/capabilities/show.d.ts.map +1 -0
- package/dist/cmd/cloud/deploy.d.ts.map +1 -1
- package/dist/cmd/cloud/deployment/index.d.ts.map +1 -1
- package/dist/cmd/cloud/deployment/list.d.ts.map +1 -1
- package/dist/cmd/cloud/deployment/remove.d.ts.map +1 -1
- package/dist/cmd/cloud/deployment/rollback.d.ts.map +1 -1
- package/dist/cmd/cloud/deployment/show.d.ts.map +1 -1
- package/dist/cmd/cloud/deployment/undeploy.d.ts.map +1 -1
- package/dist/cmd/cloud/deployment/utils.d.ts +4 -2
- package/dist/cmd/cloud/deployment/utils.d.ts.map +1 -1
- package/dist/cmd/cloud/domain.d.ts.map +1 -1
- package/dist/cmd/cloud/index.d.ts.map +1 -1
- package/dist/cmd/cloud/resource/add.d.ts.map +1 -1
- package/dist/cmd/cloud/resource/delete.d.ts.map +1 -1
- package/dist/cmd/cloud/resource/index.d.ts +1 -2
- package/dist/cmd/cloud/resource/index.d.ts.map +1 -1
- package/dist/cmd/cloud/resource/list.d.ts.map +1 -1
- package/dist/cmd/cloud/scp/download.d.ts.map +1 -1
- package/dist/cmd/cloud/scp/index.d.ts +1 -2
- package/dist/cmd/cloud/scp/index.d.ts.map +1 -1
- package/dist/cmd/cloud/scp/upload.d.ts.map +1 -1
- package/dist/cmd/cloud/session/get.d.ts +2 -0
- package/dist/cmd/cloud/session/get.d.ts.map +1 -0
- package/dist/cmd/cloud/session/index.d.ts +2 -0
- package/dist/cmd/cloud/session/index.d.ts.map +1 -0
- package/dist/cmd/cloud/session/list.d.ts +2 -0
- package/dist/cmd/cloud/session/list.d.ts.map +1 -0
- package/dist/cmd/cloud/session/logs.d.ts +2 -0
- package/dist/cmd/cloud/session/logs.d.ts.map +1 -0
- package/dist/cmd/cloud/ssh.d.ts.map +1 -1
- package/dist/cmd/dev/agents.d.ts +2 -0
- package/dist/cmd/dev/agents.d.ts.map +1 -0
- package/dist/cmd/dev/index.d.ts.map +1 -1
- package/dist/cmd/dev/sync.d.ts +12 -0
- package/dist/cmd/dev/sync.d.ts.map +1 -0
- package/dist/cmd/env/delete.d.ts.map +1 -1
- package/dist/cmd/env/get.d.ts.map +1 -1
- package/dist/cmd/env/import.d.ts.map +1 -1
- package/dist/cmd/env/index.d.ts.map +1 -1
- package/dist/cmd/env/list.d.ts.map +1 -1
- package/dist/cmd/env/pull.d.ts.map +1 -1
- package/dist/cmd/env/push.d.ts.map +1 -1
- package/dist/cmd/env/set.d.ts.map +1 -1
- package/dist/cmd/index.d.ts.map +1 -1
- package/dist/cmd/kv/create-namespace.d.ts +3 -0
- package/dist/cmd/kv/create-namespace.d.ts.map +1 -0
- package/dist/cmd/kv/delete-namespace.d.ts +3 -0
- package/dist/cmd/kv/delete-namespace.d.ts.map +1 -0
- package/dist/cmd/kv/delete.d.ts +3 -0
- package/dist/cmd/kv/delete.d.ts.map +1 -0
- package/dist/cmd/kv/get.d.ts +3 -0
- package/dist/cmd/kv/get.d.ts.map +1 -0
- package/dist/cmd/kv/index.d.ts +2 -0
- package/dist/cmd/kv/index.d.ts.map +1 -0
- package/dist/cmd/kv/keys.d.ts +3 -0
- package/dist/cmd/kv/keys.d.ts.map +1 -0
- package/dist/cmd/kv/list-namespaces.d.ts +3 -0
- package/dist/cmd/kv/list-namespaces.d.ts.map +1 -0
- package/dist/cmd/kv/repl.d.ts +3 -0
- package/dist/cmd/kv/repl.d.ts.map +1 -0
- package/dist/cmd/kv/search.d.ts +3 -0
- package/dist/cmd/kv/search.d.ts.map +1 -0
- package/dist/cmd/kv/set.d.ts +3 -0
- package/dist/cmd/kv/set.d.ts.map +1 -0
- package/dist/cmd/kv/stats.d.ts +3 -0
- package/dist/cmd/kv/stats.d.ts.map +1 -0
- package/dist/cmd/kv/util.d.ts +8 -0
- package/dist/cmd/kv/util.d.ts.map +1 -0
- package/dist/cmd/objectstore/delete-bucket.d.ts +3 -0
- package/dist/cmd/objectstore/delete-bucket.d.ts.map +1 -0
- package/dist/cmd/objectstore/delete.d.ts +3 -0
- package/dist/cmd/objectstore/delete.d.ts.map +1 -0
- package/dist/cmd/objectstore/get.d.ts +3 -0
- package/dist/cmd/objectstore/get.d.ts.map +1 -0
- package/dist/cmd/objectstore/index.d.ts +2 -0
- package/dist/cmd/objectstore/index.d.ts.map +1 -0
- package/dist/cmd/objectstore/list-buckets.d.ts +3 -0
- package/dist/cmd/objectstore/list-buckets.d.ts.map +1 -0
- package/dist/cmd/objectstore/list-keys.d.ts +3 -0
- package/dist/cmd/objectstore/list-keys.d.ts.map +1 -0
- package/dist/cmd/objectstore/put.d.ts +3 -0
- package/dist/cmd/objectstore/put.d.ts.map +1 -0
- package/dist/cmd/objectstore/repl.d.ts +3 -0
- package/dist/cmd/objectstore/repl.d.ts.map +1 -0
- package/dist/cmd/objectstore/url.d.ts +3 -0
- package/dist/cmd/objectstore/url.d.ts.map +1 -0
- package/dist/cmd/objectstore/util.d.ts +8 -0
- package/dist/cmd/objectstore/util.d.ts.map +1 -0
- package/dist/cmd/profile/create.d.ts.map +1 -1
- package/dist/cmd/profile/delete.d.ts.map +1 -1
- package/dist/cmd/profile/index.d.ts.map +1 -1
- package/dist/cmd/profile/list.d.ts +1 -2
- package/dist/cmd/profile/list.d.ts.map +1 -1
- package/dist/cmd/profile/show.d.ts.map +1 -1
- package/dist/cmd/profile/use.d.ts.map +1 -1
- package/dist/cmd/project/create.d.ts.map +1 -1
- package/dist/cmd/project/delete.d.ts.map +1 -1
- package/dist/cmd/project/index.d.ts.map +1 -1
- package/dist/cmd/project/list.d.ts.map +1 -1
- package/dist/cmd/project/show.d.ts.map +1 -1
- package/dist/cmd/project/template-flow.d.ts +1 -1
- package/dist/cmd/project/template-flow.d.ts.map +1 -1
- package/dist/cmd/prompt/index.d.ts +4 -0
- package/dist/cmd/prompt/index.d.ts.map +1 -0
- package/dist/cmd/prompt/llm.d.ts +3 -0
- package/dist/cmd/prompt/llm.d.ts.map +1 -0
- package/dist/cmd/repl/index.d.ts +3 -0
- package/dist/cmd/repl/index.d.ts.map +1 -0
- package/dist/cmd/schema/index.d.ts +4 -0
- package/dist/cmd/schema/index.d.ts.map +1 -0
- package/dist/cmd/schema/show.d.ts +3 -0
- package/dist/cmd/schema/show.d.ts.map +1 -0
- package/dist/cmd/secret/delete.d.ts.map +1 -1
- package/dist/cmd/secret/get.d.ts.map +1 -1
- package/dist/cmd/secret/import.d.ts.map +1 -1
- package/dist/cmd/secret/index.d.ts.map +1 -1
- package/dist/cmd/secret/list.d.ts.map +1 -1
- package/dist/cmd/secret/pull.d.ts.map +1 -1
- package/dist/cmd/secret/push.d.ts.map +1 -1
- package/dist/cmd/secret/set.d.ts.map +1 -1
- package/dist/cmd/version/index.d.ts.map +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/errors.d.ts +83 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/explain.d.ts +47 -0
- package/dist/explain.d.ts.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/json.d.ts +3 -0
- package/dist/json.d.ts.map +1 -0
- package/dist/output.d.ts +136 -0
- package/dist/output.d.ts.map +1 -0
- package/dist/repl.d.ts +120 -0
- package/dist/repl.d.ts.map +1 -0
- package/dist/schema-generator.d.ts +67 -0
- package/dist/schema-generator.d.ts.map +1 -0
- package/dist/tui.d.ts +35 -1
- package/dist/tui.d.ts.map +1 -1
- package/dist/types.d.ts +77 -6
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/format.d.ts +9 -0
- package/dist/utils/format.d.ts.map +1 -0
- package/package.json +12 -4
- package/src/banner.ts +7 -7
- package/src/cli-logger.ts +80 -0
- package/src/cli.ts +192 -58
- package/src/cmd/agents/index.ts +147 -0
- package/src/cmd/auth/index.ts +1 -0
- package/src/cmd/auth/login.ts +7 -2
- package/src/cmd/auth/logout.ts +4 -0
- package/src/cmd/auth/signup.ts +7 -2
- package/src/cmd/auth/ssh/add.ts +20 -3
- package/src/cmd/auth/ssh/delete.ts +57 -4
- package/src/cmd/auth/ssh/index.ts +4 -3
- package/src/cmd/auth/ssh/list.ts +38 -27
- package/src/cmd/auth/whoami.ts +32 -21
- package/src/cmd/bundle/ast.test.ts +2 -2
- package/src/cmd/bundle/ast.ts +112 -22
- package/src/cmd/bundle/index.ts +20 -0
- package/src/cmd/bundle/plugin.ts +60 -14
- package/src/cmd/capabilities/index.ts +12 -0
- package/src/cmd/capabilities/show.ts +256 -0
- package/src/cmd/cloud/deploy.ts +54 -0
- package/src/cmd/cloud/deployment/index.ts +1 -0
- package/src/cmd/cloud/deployment/list.ts +66 -25
- package/src/cmd/cloud/deployment/remove.ts +26 -2
- package/src/cmd/cloud/deployment/rollback.ts +35 -4
- package/src/cmd/cloud/deployment/show.ts +37 -2
- package/src/cmd/cloud/deployment/undeploy.ts +12 -1
- package/src/cmd/cloud/deployment/utils.ts +5 -2
- package/src/cmd/cloud/domain.ts +3 -2
- package/src/cmd/cloud/index.ts +10 -1
- package/src/cmd/cloud/resource/add.ts +19 -0
- package/src/cmd/cloud/resource/delete.ts +24 -3
- package/src/cmd/cloud/resource/index.ts +4 -3
- package/src/cmd/cloud/resource/list.ts +36 -10
- package/src/cmd/cloud/scp/download.ts +27 -1
- package/src/cmd/cloud/scp/index.ts +4 -3
- package/src/cmd/cloud/scp/upload.ts +27 -1
- package/src/cmd/cloud/session/get.ts +164 -0
- package/src/cmd/cloud/session/index.ts +11 -0
- package/src/cmd/cloud/session/list.ts +145 -0
- package/src/cmd/cloud/session/logs.ts +68 -0
- package/src/cmd/cloud/ssh.ts +12 -0
- package/src/cmd/dev/agents.ts +122 -0
- package/src/cmd/dev/index.ts +106 -8
- package/src/cmd/dev/sync.ts +414 -0
- package/src/cmd/dev/templates.ts +1 -1
- package/src/cmd/env/delete.ts +17 -0
- package/src/cmd/env/get.ts +17 -1
- package/src/cmd/env/import.ts +47 -3
- package/src/cmd/env/index.ts +1 -0
- package/src/cmd/env/list.ts +13 -1
- package/src/cmd/env/pull.ts +20 -0
- package/src/cmd/env/push.ts +33 -1
- package/src/cmd/env/set.ts +25 -1
- package/src/cmd/index.ts +9 -2
- package/src/cmd/kv/create-namespace.ts +45 -0
- package/src/cmd/kv/delete-namespace.ts +73 -0
- package/src/cmd/kv/delete.ts +51 -0
- package/src/cmd/kv/get.ts +65 -0
- package/src/cmd/kv/index.ts +31 -0
- package/src/cmd/kv/keys.ts +57 -0
- package/src/cmd/kv/list-namespaces.ts +43 -0
- package/src/cmd/kv/repl.ts +284 -0
- package/src/cmd/kv/search.ts +80 -0
- package/src/cmd/kv/set.ts +63 -0
- package/src/cmd/kv/stats.ts +96 -0
- package/src/cmd/kv/util.ts +32 -0
- package/src/cmd/objectstore/delete-bucket.ts +72 -0
- package/src/cmd/objectstore/delete.ts +59 -0
- package/src/cmd/objectstore/get.ts +64 -0
- package/src/cmd/objectstore/index.ts +27 -0
- package/src/cmd/objectstore/list-buckets.ts +45 -0
- package/src/cmd/objectstore/list-keys.ts +60 -0
- package/src/cmd/objectstore/put.ts +62 -0
- package/src/cmd/objectstore/repl.ts +235 -0
- package/src/cmd/objectstore/url.ts +59 -0
- package/src/cmd/objectstore/util.ts +28 -0
- package/src/cmd/profile/create.ts +28 -2
- package/src/cmd/profile/delete.ts +17 -2
- package/src/cmd/profile/index.ts +1 -0
- package/src/cmd/profile/list.ts +7 -3
- package/src/cmd/profile/show.ts +20 -5
- package/src/cmd/profile/use.ts +8 -0
- package/src/cmd/project/create.ts +31 -0
- package/src/cmd/project/delete.ts +24 -2
- package/src/cmd/project/index.ts +1 -0
- package/src/cmd/project/list.ts +24 -10
- package/src/cmd/project/show.ts +28 -9
- package/src/cmd/project/template-flow.ts +10 -6
- package/src/cmd/prompt/index.ts +12 -0
- package/src/cmd/prompt/llm.ts +368 -0
- package/src/cmd/repl/index.ts +477 -0
- package/src/cmd/schema/index.ts +12 -0
- package/src/cmd/schema/show.ts +27 -0
- package/src/cmd/secret/delete.ts +17 -0
- package/src/cmd/secret/get.ts +20 -1
- package/src/cmd/secret/import.ts +45 -2
- package/src/cmd/secret/index.ts +1 -0
- package/src/cmd/secret/list.ts +10 -1
- package/src/cmd/secret/pull.ts +20 -0
- package/src/cmd/secret/push.ts +33 -1
- package/src/cmd/secret/set.ts +20 -0
- package/src/cmd/version/index.ts +15 -2
- package/src/config.ts +17 -4
- package/src/errors.ts +222 -0
- package/src/explain.ts +126 -0
- package/src/index.ts +51 -0
- package/src/json.ts +28 -0
- package/src/output.ts +307 -0
- package/src/repl.ts +1507 -0
- package/src/schema-generator.ts +389 -0
- package/src/tui.ts +178 -13
- package/src/types.ts +75 -22
- package/src/utils/format.ts +17 -0
package/src/cmd/env/import.ts
CHANGED
|
@@ -13,14 +13,32 @@ import {
|
|
|
13
13
|
} from '../../env-util';
|
|
14
14
|
import { getCommand } from '../../command-prefix';
|
|
15
15
|
|
|
16
|
+
const EnvImportResponseSchema = z.object({
|
|
17
|
+
success: z.boolean().describe('Whether import succeeded'),
|
|
18
|
+
imported: z.number().describe('Number of items imported'),
|
|
19
|
+
skipped: z.number().describe('Number of items skipped'),
|
|
20
|
+
path: z.string().describe('Local file path where variables were saved'),
|
|
21
|
+
file: z.string().describe('Source file path'),
|
|
22
|
+
});
|
|
23
|
+
|
|
16
24
|
export const importSubcommand = createSubcommand({
|
|
17
25
|
name: 'import',
|
|
18
26
|
description: 'Import environment variables from a file to cloud and local .env.production',
|
|
27
|
+
tags: [
|
|
28
|
+
'mutating',
|
|
29
|
+
'creates-resource',
|
|
30
|
+
'slow',
|
|
31
|
+
'api-intensive',
|
|
32
|
+
'requires-auth',
|
|
33
|
+
'requires-project',
|
|
34
|
+
],
|
|
35
|
+
idempotent: false,
|
|
19
36
|
requires: { auth: true, project: true, apiClient: true },
|
|
20
37
|
schema: {
|
|
21
38
|
args: z.object({
|
|
22
39
|
file: z.string().describe('path to the .env file to import'),
|
|
23
40
|
}),
|
|
41
|
+
response: EnvImportResponseSchema,
|
|
24
42
|
},
|
|
25
43
|
|
|
26
44
|
async handler(ctx) {
|
|
@@ -31,7 +49,13 @@ export const importSubcommand = createSubcommand({
|
|
|
31
49
|
|
|
32
50
|
if (Object.keys(importedEnv).length === 0) {
|
|
33
51
|
tui.warning(`No environment variables found in ${args.file}`);
|
|
34
|
-
return
|
|
52
|
+
return {
|
|
53
|
+
success: false,
|
|
54
|
+
imported: 0,
|
|
55
|
+
skipped: 0,
|
|
56
|
+
path: '',
|
|
57
|
+
file: args.file,
|
|
58
|
+
};
|
|
35
59
|
}
|
|
36
60
|
|
|
37
61
|
// Filter out AGENTUITY_ prefixed keys
|
|
@@ -39,7 +63,13 @@ export const importSubcommand = createSubcommand({
|
|
|
39
63
|
|
|
40
64
|
if (Object.keys(filteredEnv).length === 0) {
|
|
41
65
|
tui.warning('No valid environment variables to import (all were AGENTUITY_ prefixed)');
|
|
42
|
-
return
|
|
66
|
+
return {
|
|
67
|
+
success: false,
|
|
68
|
+
imported: 0,
|
|
69
|
+
skipped: Object.keys(importedEnv).length,
|
|
70
|
+
path: '',
|
|
71
|
+
file: args.file,
|
|
72
|
+
};
|
|
43
73
|
}
|
|
44
74
|
|
|
45
75
|
// Check for potential secrets in the imported variables
|
|
@@ -69,7 +99,13 @@ export const importSubcommand = createSubcommand({
|
|
|
69
99
|
tui.info(
|
|
70
100
|
`Cancelled. Use "${getCommand('secret import')}" to store these as secrets instead.`
|
|
71
101
|
);
|
|
72
|
-
return
|
|
102
|
+
return {
|
|
103
|
+
success: false,
|
|
104
|
+
imported: 0,
|
|
105
|
+
skipped: Object.keys(filteredEnv).length,
|
|
106
|
+
path: '',
|
|
107
|
+
file: args.file,
|
|
108
|
+
};
|
|
73
109
|
}
|
|
74
110
|
}
|
|
75
111
|
|
|
@@ -98,5 +134,13 @@ export const importSubcommand = createSubcommand({
|
|
|
98
134
|
tui.success(
|
|
99
135
|
`Imported ${count} environment variable${count !== 1 ? 's' : ''} from ${args.file} to cloud and ${localEnvPath}`
|
|
100
136
|
);
|
|
137
|
+
|
|
138
|
+
return {
|
|
139
|
+
success: true,
|
|
140
|
+
imported: count,
|
|
141
|
+
skipped: Object.keys(importedEnv).length - count,
|
|
142
|
+
path: localEnvPath,
|
|
143
|
+
file: args.file,
|
|
144
|
+
};
|
|
101
145
|
},
|
|
102
146
|
});
|
package/src/cmd/env/index.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { listSubcommand } from './list';
|
|
|
10
10
|
export const command = createCommand({
|
|
11
11
|
name: 'env',
|
|
12
12
|
description: 'Manage environment variables for your project',
|
|
13
|
+
tags: ['fast', 'requires-auth', 'requires-project'],
|
|
13
14
|
subcommands: [
|
|
14
15
|
listSubcommand,
|
|
15
16
|
pullSubcommand,
|
package/src/cmd/env/list.ts
CHANGED
|
@@ -3,12 +3,21 @@ import { createSubcommand } from '../../types';
|
|
|
3
3
|
import * as tui from '../../tui';
|
|
4
4
|
import { projectGet } from '@agentuity/server';
|
|
5
5
|
import { maskSecret } from '../../env-util';
|
|
6
|
+
import { getCommand } from '../../command-prefix';
|
|
7
|
+
|
|
8
|
+
const EnvListResponseSchema = z.record(
|
|
9
|
+
z.string(),
|
|
10
|
+
z.string().describe('Environment variable value')
|
|
11
|
+
);
|
|
6
12
|
|
|
7
13
|
export const listSubcommand = createSubcommand({
|
|
8
14
|
name: 'list',
|
|
9
15
|
aliases: ['ls'],
|
|
10
16
|
description: 'List all environment variables',
|
|
17
|
+
tags: ['read-only', 'fast', 'requires-auth', 'requires-project'],
|
|
18
|
+
examples: [getCommand('env list'), getCommand('env list --mask')],
|
|
11
19
|
requires: { auth: true, project: true, apiClient: true },
|
|
20
|
+
idempotent: true,
|
|
12
21
|
schema: {
|
|
13
22
|
options: z.object({
|
|
14
23
|
mask: z
|
|
@@ -16,6 +25,7 @@ export const listSubcommand = createSubcommand({
|
|
|
16
25
|
.default(false)
|
|
17
26
|
.describe('mask the values in output (default: false for env vars)'),
|
|
18
27
|
}),
|
|
28
|
+
response: EnvListResponseSchema,
|
|
19
29
|
},
|
|
20
30
|
|
|
21
31
|
async handler(ctx) {
|
|
@@ -30,7 +40,7 @@ export const listSubcommand = createSubcommand({
|
|
|
30
40
|
|
|
31
41
|
if (Object.keys(env).length === 0) {
|
|
32
42
|
tui.info('No environment variables found');
|
|
33
|
-
return;
|
|
43
|
+
return {};
|
|
34
44
|
}
|
|
35
45
|
|
|
36
46
|
// Display the variables
|
|
@@ -52,5 +62,7 @@ export const listSubcommand = createSubcommand({
|
|
|
52
62
|
console.log(`${key}=${displayValue}`);
|
|
53
63
|
}
|
|
54
64
|
}
|
|
65
|
+
|
|
66
|
+
return env;
|
|
55
67
|
},
|
|
56
68
|
});
|
package/src/cmd/env/pull.ts
CHANGED
|
@@ -10,15 +10,28 @@ import {
|
|
|
10
10
|
writeEnvFile,
|
|
11
11
|
mergeEnvVars,
|
|
12
12
|
} from '../../env-util';
|
|
13
|
+
import { getCommand } from '../../command-prefix';
|
|
14
|
+
|
|
15
|
+
const EnvPullResponseSchema = z.object({
|
|
16
|
+
success: z.boolean().describe('Whether pull succeeded'),
|
|
17
|
+
pulled: z.number().describe('Number of items pulled'),
|
|
18
|
+
path: z.string().describe('Local file path where variables were saved'),
|
|
19
|
+
force: z.boolean().describe('Whether force mode was used'),
|
|
20
|
+
});
|
|
13
21
|
|
|
14
22
|
export const pullSubcommand = createSubcommand({
|
|
15
23
|
name: 'pull',
|
|
16
24
|
description: 'Pull environment variables from cloud to local .env.production file',
|
|
25
|
+
tags: ['slow', 'requires-auth', 'requires-project'],
|
|
26
|
+
idempotent: true,
|
|
27
|
+
examples: [getCommand('env pull'), getCommand('env pull --force')],
|
|
17
28
|
requires: { auth: true, project: true, apiClient: true },
|
|
29
|
+
prerequisites: ['cloud deploy'],
|
|
18
30
|
schema: {
|
|
19
31
|
options: z.object({
|
|
20
32
|
force: z.boolean().default(false).describe('overwrite local values with cloud values'),
|
|
21
33
|
}),
|
|
34
|
+
response: EnvPullResponseSchema,
|
|
22
35
|
},
|
|
23
36
|
|
|
24
37
|
async handler(ctx) {
|
|
@@ -76,5 +89,12 @@ export const pullSubcommand = createSubcommand({
|
|
|
76
89
|
tui.success(
|
|
77
90
|
`Pulled ${count} environment variable${count !== 1 ? 's' : ''} to ${targetEnvPath}`
|
|
78
91
|
);
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
success: true,
|
|
95
|
+
pulled: count,
|
|
96
|
+
path: targetEnvPath,
|
|
97
|
+
force: opts?.force ?? false,
|
|
98
|
+
};
|
|
79
99
|
},
|
|
80
100
|
});
|
package/src/cmd/env/push.ts
CHANGED
|
@@ -1,12 +1,34 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
1
2
|
import { createSubcommand } from '../../types';
|
|
2
3
|
import * as tui from '../../tui';
|
|
3
4
|
import { projectEnvUpdate } from '@agentuity/server';
|
|
4
5
|
import { findExistingEnvFile, readEnvFile, filterAgentuitySdkKeys } from '../../env-util';
|
|
6
|
+
import { getCommand } from '../../command-prefix';
|
|
7
|
+
|
|
8
|
+
const EnvPushResponseSchema = z.object({
|
|
9
|
+
success: z.boolean().describe('Whether push succeeded'),
|
|
10
|
+
pushed: z.number().describe('Number of items pushed'),
|
|
11
|
+
source: z.string().describe('Source file path'),
|
|
12
|
+
});
|
|
5
13
|
|
|
6
14
|
export const pushSubcommand = createSubcommand({
|
|
7
15
|
name: 'push',
|
|
8
16
|
description: 'Push environment variables from local .env.production file to cloud',
|
|
17
|
+
tags: [
|
|
18
|
+
'mutating',
|
|
19
|
+
'updates-resource',
|
|
20
|
+
'slow',
|
|
21
|
+
'api-intensive',
|
|
22
|
+
'requires-auth',
|
|
23
|
+
'requires-project',
|
|
24
|
+
],
|
|
25
|
+
idempotent: true,
|
|
26
|
+
examples: [getCommand('env push')],
|
|
9
27
|
requires: { auth: true, project: true, apiClient: true },
|
|
28
|
+
prerequisites: ['env set'],
|
|
29
|
+
schema: {
|
|
30
|
+
response: EnvPushResponseSchema,
|
|
31
|
+
},
|
|
10
32
|
|
|
11
33
|
async handler(ctx) {
|
|
12
34
|
const { apiClient, project, projectDir } = ctx;
|
|
@@ -20,7 +42,11 @@ export const pushSubcommand = createSubcommand({
|
|
|
20
42
|
|
|
21
43
|
if (Object.keys(filteredEnv).length === 0) {
|
|
22
44
|
tui.warning('No environment variables to push');
|
|
23
|
-
return
|
|
45
|
+
return {
|
|
46
|
+
success: false,
|
|
47
|
+
pushed: 0,
|
|
48
|
+
source: envFilePath,
|
|
49
|
+
};
|
|
24
50
|
}
|
|
25
51
|
|
|
26
52
|
// Push to cloud
|
|
@@ -33,5 +59,11 @@ export const pushSubcommand = createSubcommand({
|
|
|
33
59
|
|
|
34
60
|
const count = Object.keys(filteredEnv).length;
|
|
35
61
|
tui.success(`Pushed ${count} environment variable${count !== 1 ? 's' : ''} to cloud`);
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
success: true,
|
|
65
|
+
pushed: count,
|
|
66
|
+
source: envFilePath,
|
|
67
|
+
};
|
|
36
68
|
},
|
|
37
69
|
});
|
package/src/cmd/env/set.ts
CHANGED
|
@@ -11,15 +11,29 @@ import {
|
|
|
11
11
|
} from '../../env-util';
|
|
12
12
|
import { getCommand } from '../../command-prefix';
|
|
13
13
|
|
|
14
|
+
const EnvSetResponseSchema = z.object({
|
|
15
|
+
success: z.boolean().describe('Whether the operation succeeded'),
|
|
16
|
+
key: z.string().describe('Environment variable key'),
|
|
17
|
+
path: z.string().describe('Local file path where env var was saved'),
|
|
18
|
+
});
|
|
19
|
+
|
|
14
20
|
export const setSubcommand = createSubcommand({
|
|
15
21
|
name: 'set',
|
|
16
22
|
description: 'Set an environment variable',
|
|
23
|
+
tags: ['mutating', 'updates-resource', 'slow', 'requires-auth', 'requires-project'],
|
|
24
|
+
idempotent: true,
|
|
17
25
|
requires: { auth: true, project: true, apiClient: true },
|
|
26
|
+
examples: [
|
|
27
|
+
getCommand('env set NODE_ENV production'),
|
|
28
|
+
getCommand('env set PORT 3000'),
|
|
29
|
+
getCommand('env set LOG_LEVEL debug'),
|
|
30
|
+
],
|
|
18
31
|
schema: {
|
|
19
32
|
args: z.object({
|
|
20
33
|
key: z.string().describe('the environment variable key'),
|
|
21
34
|
value: z.string().describe('the environment variable value'),
|
|
22
35
|
}),
|
|
36
|
+
response: EnvSetResponseSchema,
|
|
23
37
|
},
|
|
24
38
|
|
|
25
39
|
async handler(ctx) {
|
|
@@ -45,7 +59,11 @@ export const setSubcommand = createSubcommand({
|
|
|
45
59
|
tui.info(
|
|
46
60
|
`Cancelled. Use "${getCommand('secret set')}" to store this as a secret instead.`
|
|
47
61
|
);
|
|
48
|
-
return
|
|
62
|
+
return {
|
|
63
|
+
success: false,
|
|
64
|
+
key: args.key,
|
|
65
|
+
path: '',
|
|
66
|
+
};
|
|
49
67
|
}
|
|
50
68
|
}
|
|
51
69
|
|
|
@@ -67,5 +85,11 @@ export const setSubcommand = createSubcommand({
|
|
|
67
85
|
await writeEnvFile(envFilePath, filteredEnv);
|
|
68
86
|
|
|
69
87
|
tui.success(`Environment variable '${args.key}' set successfully (cloud + ${envFilePath})`);
|
|
88
|
+
|
|
89
|
+
return {
|
|
90
|
+
success: true,
|
|
91
|
+
key: args.key,
|
|
92
|
+
path: envFilePath,
|
|
93
|
+
};
|
|
70
94
|
},
|
|
71
95
|
});
|
package/src/cmd/index.ts
CHANGED
|
@@ -22,7 +22,8 @@ export async function discoverCommands(): Promise<CommandDefinition[]> {
|
|
|
22
22
|
if (cmd.subcommands) {
|
|
23
23
|
for (const subcommand of cmd.subcommands) {
|
|
24
24
|
if (subcommand.toplevel) {
|
|
25
|
-
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
|
+
const alias: any = {
|
|
26
27
|
name: subcommand.name,
|
|
27
28
|
description: subcommand.description,
|
|
28
29
|
aliases: subcommand.aliases,
|
|
@@ -31,8 +32,14 @@ export async function discoverCommands(): Promise<CommandDefinition[]> {
|
|
|
31
32
|
optional: subcommand.optional,
|
|
32
33
|
schema: subcommand.schema,
|
|
33
34
|
handler: subcommand.handler,
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
36
|
+
idempotent: (subcommand as any).idempotent,
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
38
|
+
prerequisites: (subcommand as any).prerequisites,
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
40
|
+
tags: (subcommand as any).tags,
|
|
34
41
|
};
|
|
35
|
-
commands.push(alias);
|
|
42
|
+
commands.push(alias as CommandDefinition);
|
|
36
43
|
}
|
|
37
44
|
}
|
|
38
45
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { createCommand } from '../../types';
|
|
3
|
+
import * as tui from '../../tui';
|
|
4
|
+
import { createStorageAdapter } from './util';
|
|
5
|
+
import { getCommand } from '../../command-prefix';
|
|
6
|
+
|
|
7
|
+
export const createNamespaceSubcommand = createCommand({
|
|
8
|
+
name: 'create-namespace',
|
|
9
|
+
aliases: ['create'],
|
|
10
|
+
description: 'Create a new keyvalue namespace',
|
|
11
|
+
tags: ['mutating', 'creates-resource', 'slow', 'requires-auth'],
|
|
12
|
+
idempotent: false,
|
|
13
|
+
requires: { auth: true, project: true },
|
|
14
|
+
examples: [
|
|
15
|
+
`${getCommand('kv create-namespace production')} - Create production namespace`,
|
|
16
|
+
`${getCommand('kv create staging')} - Create staging namespace (using alias)`,
|
|
17
|
+
`${getCommand('kv create cache')} - Create cache namespace`,
|
|
18
|
+
],
|
|
19
|
+
schema: {
|
|
20
|
+
args: z.object({
|
|
21
|
+
name: z.string().min(1).max(64).describe('the namespace name'),
|
|
22
|
+
}),
|
|
23
|
+
response: z.object({
|
|
24
|
+
success: z.boolean().describe('Whether the operation succeeded'),
|
|
25
|
+
namespace: z.string().describe('Namespace name'),
|
|
26
|
+
message: z.string().optional().describe('Success message'),
|
|
27
|
+
}),
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
async handler(ctx) {
|
|
31
|
+
const { args } = ctx;
|
|
32
|
+
const kv = await createStorageAdapter(ctx);
|
|
33
|
+
|
|
34
|
+
await kv.createNamespace(args.name);
|
|
35
|
+
tui.success(`Namespace ${tui.bold(args.name)} created`);
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
success: true,
|
|
39
|
+
namespace: args.name,
|
|
40
|
+
message: `Namespace ${args.name} created`,
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
export default createNamespaceSubcommand;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { createCommand } from '../../types';
|
|
3
|
+
import { ErrorCode } from '../../errors';
|
|
4
|
+
import * as tui from '../../tui';
|
|
5
|
+
import { createStorageAdapter } from './util';
|
|
6
|
+
import { getCommand } from '../../command-prefix';
|
|
7
|
+
|
|
8
|
+
export const deleteNamespaceSubcommand = createCommand({
|
|
9
|
+
name: 'delete-namespace',
|
|
10
|
+
aliases: ['rm-namespace'],
|
|
11
|
+
description: 'Delete a keyvalue namespace and all its keys',
|
|
12
|
+
tags: ['destructive', 'deletes-resource', 'slow', 'requires-auth', 'requires-project'],
|
|
13
|
+
idempotent: true,
|
|
14
|
+
requires: { auth: true, project: true },
|
|
15
|
+
examples: [
|
|
16
|
+
`${getCommand('kv delete-namespace staging')} - Delete staging namespace (interactive)`,
|
|
17
|
+
`${getCommand('kv rm-namespace cache --confirm')} - Delete cache without confirmation`,
|
|
18
|
+
`${getCommand('kv delete-namespace production --confirm')} - Force delete production`,
|
|
19
|
+
],
|
|
20
|
+
schema: {
|
|
21
|
+
args: z.object({
|
|
22
|
+
name: z.string().min(1).max(64).describe('the namespace name'),
|
|
23
|
+
confirm: z
|
|
24
|
+
.boolean()
|
|
25
|
+
.optional()
|
|
26
|
+
.default(false)
|
|
27
|
+
.describe('if true will not prompt for confirmation'),
|
|
28
|
+
}),
|
|
29
|
+
response: z.object({
|
|
30
|
+
success: z.boolean().describe('Whether the deletion succeeded'),
|
|
31
|
+
namespace: z.string().describe('Deleted namespace name'),
|
|
32
|
+
message: z.string().optional().describe('Confirmation message'),
|
|
33
|
+
}),
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
async handler(ctx) {
|
|
37
|
+
const { args } = ctx;
|
|
38
|
+
const kv = await createStorageAdapter(ctx);
|
|
39
|
+
|
|
40
|
+
if (!args.confirm) {
|
|
41
|
+
if (!process.stdin.isTTY) {
|
|
42
|
+
tui.fatal(
|
|
43
|
+
'No TTY and --confirm is not set. Refusing to delete',
|
|
44
|
+
ErrorCode.VALIDATION_FAILED
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
tui.warning(`This will delete namespace ${tui.bold(args.name)} and ALL its keys.`);
|
|
48
|
+
const confirm = await new Promise<boolean>((resolve) => {
|
|
49
|
+
process.stdout.write('Are you sure? (yes/no): ');
|
|
50
|
+
process.stdin.once('data', (data) => {
|
|
51
|
+
const answer = data.toString().trim().toLowerCase();
|
|
52
|
+
resolve(answer === 'yes' || answer === 'y');
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
if (!confirm) {
|
|
57
|
+
tui.info('Cancelled');
|
|
58
|
+
return { success: false, namespace: args.name, message: 'Cancelled' };
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
await kv.deleteNamespace(args.name);
|
|
63
|
+
tui.success(`Namespace ${tui.bold(args.name)} deleted`);
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
success: true,
|
|
67
|
+
namespace: args.name,
|
|
68
|
+
message: `Namespace ${args.name} deleted`,
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
export default deleteNamespaceSubcommand;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { createCommand } from '../../types';
|
|
3
|
+
import * as tui from '../../tui';
|
|
4
|
+
import { createStorageAdapter } from './util';
|
|
5
|
+
import { getCommand } from '../../command-prefix';
|
|
6
|
+
|
|
7
|
+
const KVDeleteResponseSchema = z.object({
|
|
8
|
+
success: z.boolean().describe('Whether the operation succeeded'),
|
|
9
|
+
namespace: z.string().describe('Namespace name'),
|
|
10
|
+
key: z.string().describe('Key name'),
|
|
11
|
+
durationMs: z.number().describe('Operation duration in milliseconds'),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export const deleteSubcommand = createCommand({
|
|
15
|
+
name: 'delete',
|
|
16
|
+
aliases: ['del', 'rm', 'remove'],
|
|
17
|
+
description: 'Delete a key from the keyvalue storage',
|
|
18
|
+
tags: ['destructive', 'deletes-resource', 'slow', 'requires-auth'],
|
|
19
|
+
idempotent: true,
|
|
20
|
+
requires: { auth: true, project: true },
|
|
21
|
+
examples: [
|
|
22
|
+
`${getCommand('kv delete production user:123')} - Delete user data`,
|
|
23
|
+
`${getCommand('kv delete cache session:abc')} - Delete cached session`,
|
|
24
|
+
`${getCommand('kv rm staging cache:homepage')} - Delete homepage cache (using alias)`,
|
|
25
|
+
],
|
|
26
|
+
schema: {
|
|
27
|
+
args: z.object({
|
|
28
|
+
namespace: z.string().min(1).describe('the namespace name'),
|
|
29
|
+
key: z.string().min(1).describe('the key name'),
|
|
30
|
+
}),
|
|
31
|
+
response: KVDeleteResponseSchema,
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
async handler(ctx) {
|
|
35
|
+
const { args } = ctx;
|
|
36
|
+
const started = Date.now();
|
|
37
|
+
const storage = await createStorageAdapter(ctx);
|
|
38
|
+
await storage.delete(args.namespace, args.key);
|
|
39
|
+
const durationMs = Date.now() - started;
|
|
40
|
+
tui.success(`deleted in ${durationMs.toFixed(1)}ms`);
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
success: true,
|
|
44
|
+
namespace: args.namespace,
|
|
45
|
+
key: args.key,
|
|
46
|
+
durationMs,
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
export default deleteSubcommand;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { createCommand } from '../../types';
|
|
3
|
+
import * as tui from '../../tui';
|
|
4
|
+
import { tryParseJSON } from '../../json';
|
|
5
|
+
import { createStorageAdapter } from './util';
|
|
6
|
+
import { getCommand } from '../../command-prefix';
|
|
7
|
+
|
|
8
|
+
const KVGetResponseSchema = z.object({
|
|
9
|
+
exists: z.boolean().describe('Whether the key exists'),
|
|
10
|
+
data: z.union([z.string(), z.any()]).optional().describe('Value data (string or binary)'),
|
|
11
|
+
contentType: z.string().optional().describe('Content type'),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export const getSubcommand = createCommand({
|
|
15
|
+
name: 'get',
|
|
16
|
+
description: 'Get a value from the keyvalue storage',
|
|
17
|
+
tags: ['read-only', 'fast', 'requires-auth'],
|
|
18
|
+
requires: { auth: true, project: true },
|
|
19
|
+
examples: [
|
|
20
|
+
`${getCommand('kv get production user:123')} - Get user data`,
|
|
21
|
+
`${getCommand('kv get cache session:abc')} - Get cached session`,
|
|
22
|
+
`${getCommand('kv get staging cache:homepage')} - Get homepage cache`,
|
|
23
|
+
],
|
|
24
|
+
schema: {
|
|
25
|
+
args: z.object({
|
|
26
|
+
namespace: z.string().min(1).describe('the namespace name'),
|
|
27
|
+
key: z.string().min(1).describe('the key name'),
|
|
28
|
+
}),
|
|
29
|
+
response: KVGetResponseSchema,
|
|
30
|
+
},
|
|
31
|
+
idempotent: true,
|
|
32
|
+
|
|
33
|
+
async handler(ctx) {
|
|
34
|
+
const { args } = ctx;
|
|
35
|
+
const storage = await createStorageAdapter(ctx);
|
|
36
|
+
const started = Date.now();
|
|
37
|
+
const res = await storage.get(args.namespace, args.key);
|
|
38
|
+
if (res.exists) {
|
|
39
|
+
if (res.data) {
|
|
40
|
+
if (res.contentType?.includes('json')) {
|
|
41
|
+
const val = tryParseJSON(res.data as unknown as string);
|
|
42
|
+
tui.json(val);
|
|
43
|
+
} else if (res.contentType?.includes('text')) {
|
|
44
|
+
console.log(String(res.data));
|
|
45
|
+
} else {
|
|
46
|
+
const b = res.data as ArrayBuffer;
|
|
47
|
+
tui.info(`Read ${b.byteLength} bytes (${res.contentType})`);
|
|
48
|
+
}
|
|
49
|
+
tui.success(`retrieved in ${(Date.now() - started).toFixed(1)}ms (${res.contentType})`);
|
|
50
|
+
} else {
|
|
51
|
+
tui.warning(`${args.key} returned empty data for ${args.namespace}`);
|
|
52
|
+
}
|
|
53
|
+
} else {
|
|
54
|
+
tui.warning(`${args.key} does not exist in ${args.namespace}`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
exists: res.exists,
|
|
59
|
+
data: res.data,
|
|
60
|
+
contentType: res.exists ? res.contentType : undefined,
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
export default getSubcommand;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { createCommand } from '../../types';
|
|
2
|
+
import { createNamespaceSubcommand } from './create-namespace';
|
|
3
|
+
import { deleteSubcommand } from './delete';
|
|
4
|
+
import { deleteNamespaceSubcommand } from './delete-namespace';
|
|
5
|
+
import { getSubcommand } from './get';
|
|
6
|
+
import { keysSubcommand } from './keys';
|
|
7
|
+
import { listNamespacesSubcommand } from './list-namespaces';
|
|
8
|
+
import { replSubcommand } from './repl';
|
|
9
|
+
import { searchSubcommand } from './search';
|
|
10
|
+
import { setSubcommand } from './set';
|
|
11
|
+
import { statsSubcommand } from './stats';
|
|
12
|
+
|
|
13
|
+
export const command = createCommand({
|
|
14
|
+
name: 'keyvalue',
|
|
15
|
+
aliases: ['kv'],
|
|
16
|
+
description: 'Manage keyvalue storage for your projects',
|
|
17
|
+
tags: ['read-only', 'fast', 'requires-auth'],
|
|
18
|
+
subcommands: [
|
|
19
|
+
replSubcommand,
|
|
20
|
+
getSubcommand,
|
|
21
|
+
setSubcommand,
|
|
22
|
+
deleteSubcommand,
|
|
23
|
+
statsSubcommand,
|
|
24
|
+
searchSubcommand,
|
|
25
|
+
keysSubcommand,
|
|
26
|
+
listNamespacesSubcommand,
|
|
27
|
+
createNamespaceSubcommand,
|
|
28
|
+
deleteNamespaceSubcommand,
|
|
29
|
+
],
|
|
30
|
+
requires: { auth: true, project: true },
|
|
31
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { createCommand } from '../../types';
|
|
3
|
+
import * as tui from '../../tui';
|
|
4
|
+
import { createStorageAdapter } from './util';
|
|
5
|
+
import { getCommand } from '../../command-prefix';
|
|
6
|
+
|
|
7
|
+
const KVKeysResponseSchema = z.object({
|
|
8
|
+
namespace: z.string().describe('Namespace name'),
|
|
9
|
+
keys: z.array(z.string()).describe('List of keys in the namespace'),
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export const keysSubcommand = createCommand({
|
|
13
|
+
name: 'keys',
|
|
14
|
+
aliases: ['ls', 'list'],
|
|
15
|
+
description: 'List all keys in a keyvalue namespace',
|
|
16
|
+
tags: ['read-only', 'slow', 'requires-auth'],
|
|
17
|
+
requires: { auth: true, project: true },
|
|
18
|
+
idempotent: true,
|
|
19
|
+
examples: [
|
|
20
|
+
`${getCommand('kv keys production')} - List all keys in production`,
|
|
21
|
+
`${getCommand('kv ls cache')} - List all cached keys (using alias)`,
|
|
22
|
+
`${getCommand('kv list staging')} - List all staging keys`,
|
|
23
|
+
],
|
|
24
|
+
schema: {
|
|
25
|
+
args: z.object({
|
|
26
|
+
name: z.string().min(1).describe('the namespace name'),
|
|
27
|
+
}),
|
|
28
|
+
response: KVKeysResponseSchema,
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
async handler(ctx) {
|
|
32
|
+
const { args } = ctx;
|
|
33
|
+
const kv = await createStorageAdapter(ctx);
|
|
34
|
+
|
|
35
|
+
const keys = await kv.getKeys(args.name);
|
|
36
|
+
|
|
37
|
+
if (keys.length === 0) {
|
|
38
|
+
tui.info(`No keys found in namespace ${tui.bold(args.name)}`);
|
|
39
|
+
return {
|
|
40
|
+
namespace: args.name,
|
|
41
|
+
keys: [],
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
tui.info(`Found ${keys.length} key(s) in ${tui.bold(args.name)}:`);
|
|
46
|
+
for (const key of keys) {
|
|
47
|
+
tui.info(` ${key}`);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
namespace: args.name,
|
|
52
|
+
keys,
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
export default keysSubcommand;
|