@bctrl/cli 0.1.4 → 0.1.6
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/commands/ai/index.js +29 -21
- package/dist/commands/api-key/index.js +10 -10
- package/dist/commands/browser-extension/index.js +18 -19
- package/dist/commands/file/index.js +17 -18
- package/dist/commands/help/index.js +3 -3
- package/dist/commands/proxy/index.js +26 -20
- package/dist/commands/run/index.js +44 -27
- package/dist/commands/runtime/index.js +159 -130
- package/dist/commands/shared/help.d.ts +1 -0
- package/dist/commands/shared/help.js +9 -5
- package/dist/commands/shared/operation.d.ts +83 -0
- package/dist/commands/shared/{rest.js → operation.js} +87 -46
- package/dist/commands/space/index.js +61 -52
- package/dist/commands/space/list.js +14 -13
- package/dist/commands/subaccount/index.js +35 -53
- package/dist/commands/tool/index.js +18 -20
- package/dist/commands/tool-call/index.js +5 -5
- package/dist/commands/toolset/index.js +11 -13
- package/dist/commands/usage/index.js +3 -3
- package/dist/commands/vault/index.js +23 -21
- package/dist/generated/help.d.ts +5990 -128
- package/dist/generated/help.js +7905 -221
- package/dist/generated/openapi-routes.d.ts +391 -0
- package/dist/generated/openapi-routes.js +100 -0
- package/dist/generated/openapi-types.d.ts +13830 -0
- package/dist/generated/openapi-types.js +5 -0
- package/dist/openapi.d.ts +20 -0
- package/dist/openapi.js +1 -0
- package/package.json +1 -1
- package/dist/commands/shared/rest.d.ts +0 -55
|
@@ -1,11 +1,10 @@
|
|
|
1
|
+
import { CLI_OPENAPI_ROUTES } from '../../generated/openapi-routes.js';
|
|
1
2
|
import { Command } from 'commander';
|
|
2
|
-
import { CliError } from '../../runtime/errors.js';
|
|
3
3
|
import { readJsonFile } from './io.js';
|
|
4
4
|
import { parsePositiveInteger } from './options.js';
|
|
5
5
|
import { addOutputFlags, outputData } from './output.js';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
6
|
+
import { CliError } from '../../runtime/errors.js';
|
|
7
|
+
import { addCliOperationHelp } from './help.js';
|
|
9
8
|
export function addPaginationFlags(command) {
|
|
10
9
|
return command
|
|
11
10
|
.option('-L, --limit <number>', 'Maximum number of results to return', parsePositiveInteger)
|
|
@@ -14,80 +13,125 @@ export function addPaginationFlags(command) {
|
|
|
14
13
|
export function addJsonBodyFlag(command) {
|
|
15
14
|
return command.option('--input <path>', 'Read JSON request body from file, or - for stdin');
|
|
16
15
|
}
|
|
17
|
-
export
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
export function outputFlags(options) {
|
|
17
|
+
return {
|
|
18
|
+
...(typeof options.json === 'string' || typeof options.json === 'boolean'
|
|
19
|
+
? { json: options.json }
|
|
20
|
+
: {}),
|
|
21
|
+
...(typeof options.jq === 'string' ? { jq: options.jq } : {}),
|
|
22
|
+
...(typeof options.template === 'string' ? { template: options.template } : {}),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export function operationPath(operationId, pathParams) {
|
|
26
|
+
const route = CLI_OPENAPI_ROUTES[operationId];
|
|
27
|
+
return route.path.replace(/\{([^}]+)\}/g, (_match, key) => {
|
|
28
|
+
const value = pathParams?.[key];
|
|
29
|
+
if (value === undefined) {
|
|
30
|
+
throw new Error(`Missing path parameter "${key}" for ${operationId}`);
|
|
24
31
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
32
|
+
return encodeURIComponent(String(value));
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
export async function requestOperationAndPrint(deps, operationId, input) {
|
|
36
|
+
const result = await requestOperation(deps, operationId, input);
|
|
37
|
+
await outputData(deps.io, result, input.output);
|
|
38
|
+
}
|
|
39
|
+
export async function requestOperation(deps, operationId, input) {
|
|
40
|
+
const route = CLI_OPENAPI_ROUTES[operationId];
|
|
41
|
+
const client = await deps.apiClient();
|
|
42
|
+
const path = operationPath(operationId, input.pathParams);
|
|
43
|
+
const requestOptions = {
|
|
44
|
+
...('query' in input && input.query !== undefined ? { query: input.query } : {}),
|
|
45
|
+
...('body' in input && input.body !== undefined ? { body: input.body } : {}),
|
|
46
|
+
...(input.idempotencyKey ? { idempotencyKey: input.idempotencyKey } : {}),
|
|
47
|
+
};
|
|
48
|
+
const options = Object.keys(requestOptions).length > 0 ? requestOptions : undefined;
|
|
49
|
+
const result = route.method === 'get'
|
|
50
|
+
? await client.get(path, options)
|
|
51
|
+
: route.method === 'post'
|
|
52
|
+
? await client.post(path, options)
|
|
53
|
+
: route.method === 'patch'
|
|
54
|
+
? await client.patch(path, options)
|
|
55
|
+
: route.method === 'put'
|
|
56
|
+
? await client.put(path, options)
|
|
57
|
+
: await client.delete(path, options);
|
|
58
|
+
return result;
|
|
40
59
|
}
|
|
41
|
-
export function
|
|
60
|
+
export async function uploadOperationFile(deps, operationId, input) {
|
|
61
|
+
const client = await deps.apiClient();
|
|
62
|
+
return client.uploadFile(operationPath(operationId, input.pathParams), {
|
|
63
|
+
file: input.file,
|
|
64
|
+
fileName: input.fileName,
|
|
65
|
+
...('query' in input && input.query !== undefined ? { query: input.query } : {}),
|
|
66
|
+
...(input.fields ? { fields: input.fields } : {}),
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
export async function downloadOperation(deps, operationId, input) {
|
|
70
|
+
const client = await deps.apiClient();
|
|
71
|
+
return client.download(operationPath(operationId, input.pathParams));
|
|
72
|
+
}
|
|
73
|
+
export async function streamOperationText(deps, operationId, input) {
|
|
74
|
+
const client = await deps.apiClient();
|
|
75
|
+
return client.streamText(operationPath(operationId, input.pathParams), {
|
|
76
|
+
...('query' in input && input.query !== undefined ? { query: input.query } : {}),
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
export function createOperationListCommand(factory, config) {
|
|
42
80
|
let command = new Command(config.name ?? 'list').description(config.description);
|
|
81
|
+
command = addCliOperationHelp(command, config.operationId);
|
|
43
82
|
command = config.configure ? config.configure(command) : addPaginationFlags(command);
|
|
44
83
|
command = addOutputFlags(command);
|
|
45
84
|
return command.action(async (options) => {
|
|
46
|
-
await
|
|
85
|
+
await requestOperationAndPrint(factory, config.operationId, {
|
|
47
86
|
query: config.query ? config.query(options) : defaultListQuery(options),
|
|
48
87
|
output: outputFlags(options),
|
|
49
88
|
});
|
|
50
89
|
});
|
|
51
90
|
}
|
|
52
|
-
export function
|
|
91
|
+
export function createOperationViewCommand(factory, config) {
|
|
53
92
|
const argName = config.argName ?? 'id';
|
|
54
93
|
let command = new Command(config.name ?? 'view')
|
|
55
94
|
.description(config.description)
|
|
56
95
|
.argument(`<${argName}>`);
|
|
96
|
+
command = addCliOperationHelp(command, config.operationId);
|
|
57
97
|
command = config.configure ? config.configure(command) : command;
|
|
58
98
|
command = addOutputFlags(command);
|
|
59
99
|
return command.action(async (id, options) => {
|
|
60
|
-
await
|
|
100
|
+
await requestOperationAndPrint(factory, config.operationId, {
|
|
101
|
+
pathParams: { [argName]: id, id },
|
|
61
102
|
query: config.query ? config.query(id, options) : undefined,
|
|
62
103
|
output: outputFlags(options),
|
|
63
104
|
});
|
|
64
105
|
});
|
|
65
106
|
}
|
|
66
|
-
export function
|
|
107
|
+
export function createOperationDeleteCommand(factory, config) {
|
|
67
108
|
const argNames = config.argNames ?? ['id'];
|
|
68
109
|
let command = new Command(config.name ?? 'delete').description(config.description);
|
|
110
|
+
command = addCliOperationHelp(command, config.operationId);
|
|
69
111
|
for (const arg of argNames)
|
|
70
112
|
command = command.argument(`<${arg}>`);
|
|
71
113
|
command = command.option('-y, --yes', 'Confirm deletion');
|
|
72
114
|
command = config.configure ? config.configure(command) : command;
|
|
73
115
|
command = addOutputFlags(command);
|
|
74
|
-
return command.action(async (...
|
|
75
|
-
const options = getActionOptions(
|
|
116
|
+
return command.action(async (...actionArgs) => {
|
|
117
|
+
const options = getActionOptions(actionArgs);
|
|
76
118
|
if (options.yes !== true) {
|
|
77
119
|
throw new CliError('Refusing to delete without --yes');
|
|
78
120
|
}
|
|
79
121
|
const params = {};
|
|
80
122
|
for (let i = 0; i < argNames.length; i += 1)
|
|
81
|
-
params[argNames[i]] = String(
|
|
82
|
-
await
|
|
123
|
+
params[argNames[i]] = String(actionArgs[i]);
|
|
124
|
+
await requestOperationAndPrint(factory, config.operationId, {
|
|
125
|
+
pathParams: params,
|
|
83
126
|
query: config.query ? config.query(params, options) : undefined,
|
|
84
127
|
output: outputFlags(options),
|
|
85
128
|
});
|
|
86
129
|
});
|
|
87
130
|
}
|
|
88
|
-
export function
|
|
131
|
+
export function createOperationJsonBodyCommand(factory, config) {
|
|
89
132
|
const argNames = config.argNames ?? [];
|
|
90
133
|
let command = new Command(config.name).description(config.description);
|
|
134
|
+
command = addCliOperationHelp(command, config.operationId);
|
|
91
135
|
for (const arg of argNames)
|
|
92
136
|
command = command.argument(`<${arg}>`);
|
|
93
137
|
command = config.configure ? config.configure(command) : addJsonBodyFlag(command);
|
|
@@ -97,8 +141,11 @@ export function createJsonBodyCommand(factory, config) {
|
|
|
97
141
|
const args = {};
|
|
98
142
|
for (let i = 0; i < argNames.length; i += 1)
|
|
99
143
|
args[argNames[i]] = String(actionArgs[i]);
|
|
100
|
-
const body = config.body
|
|
101
|
-
|
|
144
|
+
const body = config.body
|
|
145
|
+
? await config.body(args, options)
|
|
146
|
+
: await bodyFromInputOption(String(options.input ?? ''));
|
|
147
|
+
await requestOperationAndPrint(factory, config.operationId, {
|
|
148
|
+
pathParams: args,
|
|
102
149
|
body,
|
|
103
150
|
query: config.query ? config.query(args, options) : undefined,
|
|
104
151
|
output: outputFlags(options),
|
|
@@ -111,14 +158,8 @@ function defaultListQuery(options) {
|
|
|
111
158
|
cursor: typeof options.cursor === 'string' ? options.cursor : undefined,
|
|
112
159
|
};
|
|
113
160
|
}
|
|
114
|
-
|
|
115
|
-
return {
|
|
116
|
-
...(typeof options.json === 'string' || typeof options.json === 'boolean'
|
|
117
|
-
? { json: options.json }
|
|
118
|
-
: {}),
|
|
119
|
-
...(typeof options.jq === 'string' ? { jq: options.jq } : {}),
|
|
120
|
-
...(typeof options.template === 'string' ? { template: options.template } : {}),
|
|
121
|
-
};
|
|
161
|
+
async function bodyFromInputOption(path) {
|
|
162
|
+
return path ? readJsonFile(path) : {};
|
|
122
163
|
}
|
|
123
164
|
function getActionOptions(args) {
|
|
124
165
|
const candidate = args.at(-2);
|
|
@@ -1,71 +1,80 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
-
import { createDeleteCommand, createJsonBodyCommand, createViewCommand } from '../shared/rest.js';
|
|
3
2
|
import { readJsonFile } from '../shared/io.js';
|
|
3
|
+
import { outputFlags, requestOperationAndPrint } from '../shared/operation.js';
|
|
4
|
+
import { addOutputFlags } from '../shared/output.js';
|
|
5
|
+
import { CliError } from '../../runtime/errors.js';
|
|
4
6
|
import { createSpaceListCommand } from './list.js';
|
|
5
7
|
export function createSpaceCommand(factory) {
|
|
6
8
|
const command = new Command('space').description('Manage BCTRL spaces');
|
|
7
9
|
command.addCommand(createSpaceListCommand(factory));
|
|
8
|
-
command.addCommand(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
command.addCommand(addOutputFlags(new Command('get').description('View a space').argument('<spaceId>')).action(async (spaceId, options) => {
|
|
11
|
+
await requestOperationAndPrint(factory, 'spaces.get', {
|
|
12
|
+
pathParams: { spaceId },
|
|
13
|
+
output: outputFlags(options),
|
|
14
|
+
});
|
|
13
15
|
}));
|
|
14
|
-
command.addCommand(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
path
|
|
19
|
-
|
|
20
|
-
.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
subaccountId: options.subaccountId,
|
|
29
|
-
};
|
|
30
|
-
},
|
|
16
|
+
command.addCommand(addOutputFlags(new Command('create')
|
|
17
|
+
.description('Create a space')
|
|
18
|
+
.option('--name <name>', 'Space name')
|
|
19
|
+
.option('--subaccount-id <id>', 'Subaccount id')
|
|
20
|
+
.option('--input <path>', 'Read JSON request body from file, or - for stdin')).action(async (options) => {
|
|
21
|
+
await requestOperationAndPrint(factory, 'spaces.create', {
|
|
22
|
+
body: typeof options.input === 'string'
|
|
23
|
+
? (await readJsonFile(options.input))
|
|
24
|
+
: {
|
|
25
|
+
name: options.name,
|
|
26
|
+
subaccountId: options.subaccountId,
|
|
27
|
+
},
|
|
28
|
+
output: outputFlags(options),
|
|
29
|
+
});
|
|
31
30
|
}));
|
|
32
|
-
command.addCommand(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
path
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return { name: options.name };
|
|
45
|
-
},
|
|
31
|
+
command.addCommand(addOutputFlags(new Command('patch')
|
|
32
|
+
.description('Edit a space')
|
|
33
|
+
.argument('<spaceId>')
|
|
34
|
+
.option('--name <name>', 'Space name')
|
|
35
|
+
.option('--input <path>', 'Read JSON request body from file, or - for stdin')).action(async (spaceId, options) => {
|
|
36
|
+
await requestOperationAndPrint(factory, 'spaces.update', {
|
|
37
|
+
pathParams: { spaceId },
|
|
38
|
+
body: typeof options.input === 'string'
|
|
39
|
+
? (await readJsonFile(options.input))
|
|
40
|
+
: { name: options.name },
|
|
41
|
+
output: outputFlags(options),
|
|
42
|
+
});
|
|
46
43
|
}));
|
|
47
|
-
command.addCommand(
|
|
48
|
-
description
|
|
49
|
-
|
|
50
|
-
|
|
44
|
+
command.addCommand(addOutputFlags(new Command('delete')
|
|
45
|
+
.description('Delete a space')
|
|
46
|
+
.argument('<spaceId>')
|
|
47
|
+
.option('-y, --yes', 'Confirm deletion')).action(async (spaceId, options) => {
|
|
48
|
+
if (options.yes !== true) {
|
|
49
|
+
throw new CliError('Refusing to delete without --yes');
|
|
50
|
+
}
|
|
51
|
+
await requestOperationAndPrint(factory, 'spaces.delete', {
|
|
52
|
+
pathParams: { spaceId },
|
|
53
|
+
output: outputFlags(options),
|
|
54
|
+
});
|
|
51
55
|
}));
|
|
52
56
|
command.addCommand(createSpaceEnvironmentCommand(factory));
|
|
53
57
|
return command;
|
|
54
58
|
}
|
|
55
59
|
function createSpaceEnvironmentCommand(factory) {
|
|
56
60
|
const command = new Command('env').description('Manage a space environment');
|
|
57
|
-
command.addCommand(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
61
|
+
command.addCommand(addOutputFlags(new Command('get').description('Get a space environment').argument('<spaceId>')).action(async (spaceId, options) => {
|
|
62
|
+
await requestOperationAndPrint(factory, 'spaces.environment.get', {
|
|
63
|
+
pathParams: { spaceId },
|
|
64
|
+
output: outputFlags(options),
|
|
65
|
+
});
|
|
62
66
|
}));
|
|
63
|
-
command.addCommand(
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
command.addCommand(addOutputFlags(new Command('patch')
|
|
68
|
+
.description('Update a space environment')
|
|
69
|
+
.argument('<spaceId>')
|
|
70
|
+
.option('--input <path>', 'Read JSON request body from file, or - for stdin')).action(async (spaceId, options) => {
|
|
71
|
+
await requestOperationAndPrint(factory, 'spaces.environment.update', {
|
|
72
|
+
pathParams: { spaceId },
|
|
73
|
+
body: typeof options.input === 'string'
|
|
74
|
+
? (await readJsonFile(options.input))
|
|
75
|
+
: {},
|
|
76
|
+
output: outputFlags(options),
|
|
77
|
+
});
|
|
69
78
|
}));
|
|
70
79
|
return command;
|
|
71
80
|
}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { addPaginationFlags, outputFlags, requestOperationAndPrint } from '../shared/operation.js';
|
|
3
|
+
import { addOutputFlags } from '../shared/output.js';
|
|
2
4
|
export function createSpaceListCommand(factory) {
|
|
3
|
-
return
|
|
4
|
-
description
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}),
|
|
5
|
+
return addOutputFlags(addPaginationFlags(new Command('list')
|
|
6
|
+
.description('List spaces')
|
|
7
|
+
.option('--subaccount <id>', 'Filter by subaccount id'))).action(async (options) => {
|
|
8
|
+
await requestOperationAndPrint(factory, 'spaces.list', {
|
|
9
|
+
query: {
|
|
10
|
+
subaccountId: options.subaccount,
|
|
11
|
+
limit: options.limit,
|
|
12
|
+
cursor: options.cursor,
|
|
13
|
+
},
|
|
14
|
+
output: outputFlags(options),
|
|
15
|
+
});
|
|
15
16
|
});
|
|
16
17
|
}
|
|
@@ -2,12 +2,12 @@ import { Command } from 'commander';
|
|
|
2
2
|
import { readJsonFile } from '../shared/io.js';
|
|
3
3
|
import { parsePositiveInteger } from '../shared/options.js';
|
|
4
4
|
import { addOutputFlags } from '../shared/output.js';
|
|
5
|
-
import {
|
|
5
|
+
import { addPaginationFlags, createOperationJsonBodyCommand, createOperationListCommand, createOperationViewCommand, outputFlags, requestOperationAndPrint, } from '../shared/operation.js';
|
|
6
6
|
export function createSubaccountCommand(factory) {
|
|
7
7
|
const command = new Command('subaccount').description('Manage subaccounts');
|
|
8
|
-
command.addCommand(
|
|
8
|
+
command.addCommand(createOperationListCommand(factory, {
|
|
9
|
+
operationId: 'subaccounts.list',
|
|
9
10
|
description: 'List subaccounts',
|
|
10
|
-
path: '/subaccounts',
|
|
11
11
|
query: (options) => ({
|
|
12
12
|
limit: typeof options.limit === 'number' ? options.limit : undefined,
|
|
13
13
|
cursor: typeof options.cursor === 'string' ? options.cursor : undefined,
|
|
@@ -22,52 +22,45 @@ export function createSubaccountCommand(factory) {
|
|
|
22
22
|
.option('--external-id <id>', 'Filter by external id')
|
|
23
23
|
.option('--query <text>', 'Search by id, name, or external id'),
|
|
24
24
|
}));
|
|
25
|
-
command.addCommand(
|
|
25
|
+
command.addCommand(createOperationViewCommand(factory, {
|
|
26
|
+
operationId: 'subaccounts.get',
|
|
26
27
|
name: 'get',
|
|
27
28
|
description: 'Get a subaccount',
|
|
28
|
-
path: '/subaccounts/{subaccountId}',
|
|
29
29
|
argName: 'subaccountId',
|
|
30
30
|
configure: (cmd) => cmd.option('--include <value>', 'Include related data, for example usage'),
|
|
31
31
|
query: (_id, options) => ({
|
|
32
32
|
include: typeof options.include === 'string' ? options.include : undefined,
|
|
33
33
|
}),
|
|
34
34
|
}));
|
|
35
|
-
command.addCommand(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
body: async (_args, options) => {
|
|
46
|
-
if (typeof options.input === 'string')
|
|
47
|
-
return readJsonFile(options.input);
|
|
48
|
-
return {
|
|
49
|
-
name: options.name,
|
|
50
|
-
externalId: options.externalId,
|
|
51
|
-
metadata: typeof options.metadataFile === 'string'
|
|
52
|
-
? await readJsonFile(options.metadataFile, '--metadata-file')
|
|
53
|
-
: undefined,
|
|
54
|
-
};
|
|
55
|
-
},
|
|
35
|
+
command.addCommand(createSubaccountWriteCommand(factory, 'create', 'subaccounts.create'));
|
|
36
|
+
command.addCommand(createSubaccountWriteCommand(factory, 'patch', 'subaccounts.update', ['subaccountId']));
|
|
37
|
+
command.addCommand(addOutputFlags(new Command('archive')
|
|
38
|
+
.description('Archive a subaccount')
|
|
39
|
+
.argument('<subaccountId>')
|
|
40
|
+
.requiredOption('-y, --yes', 'Confirm archive')).action(async (subaccountId, options) => {
|
|
41
|
+
await requestOperationAndPrint(factory, 'subaccounts.archive', {
|
|
42
|
+
pathParams: { subaccountId },
|
|
43
|
+
output: outputFlags(options),
|
|
44
|
+
});
|
|
56
45
|
}));
|
|
57
|
-
command.addCommand(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
46
|
+
command.addCommand(createSubaccountUsageCommand(factory));
|
|
47
|
+
return command;
|
|
48
|
+
}
|
|
49
|
+
function createSubaccountWriteCommand(factory, name, operationId, argNames = []) {
|
|
50
|
+
return createOperationJsonBodyCommand(factory, {
|
|
51
|
+
operationId,
|
|
52
|
+
name,
|
|
53
|
+
description: name === 'create' ? 'Create a subaccount' : 'Update a subaccount',
|
|
54
|
+
argNames,
|
|
63
55
|
configure: (cmd) => cmd
|
|
64
56
|
.option('--name <name>', 'Subaccount name')
|
|
65
57
|
.option('--external-id <id>', 'External id')
|
|
66
58
|
.option('--metadata-file <path>', 'Metadata JSON file')
|
|
67
59
|
.option('--input <path>', 'Read full JSON request body from file, or - for stdin'),
|
|
68
60
|
body: async (_args, options) => {
|
|
69
|
-
if (typeof options.input === 'string')
|
|
70
|
-
return readJsonFile(options.input);
|
|
61
|
+
if (typeof options.input === 'string') {
|
|
62
|
+
return (await readJsonFile(options.input));
|
|
63
|
+
}
|
|
71
64
|
return {
|
|
72
65
|
name: options.name,
|
|
73
66
|
externalId: options.externalId,
|
|
@@ -76,36 +69,25 @@ export function createSubaccountCommand(factory) {
|
|
|
76
69
|
: undefined,
|
|
77
70
|
};
|
|
78
71
|
},
|
|
79
|
-
})
|
|
80
|
-
command.addCommand(addOutputFlags(new Command('archive')
|
|
81
|
-
.description('Archive a subaccount')
|
|
82
|
-
.argument('<id>')
|
|
83
|
-
.requiredOption('-y, --yes', 'Confirm archive'))
|
|
84
|
-
.action(async (id, options) => {
|
|
85
|
-
await requestAndPrint(factory, 'post', `/subaccounts/${encodeURIComponent(id)}/archive`, {
|
|
86
|
-
output: options,
|
|
87
|
-
});
|
|
88
|
-
}));
|
|
89
|
-
command.addCommand(createSubaccountUsageCommand(factory));
|
|
90
|
-
return command;
|
|
72
|
+
});
|
|
91
73
|
}
|
|
92
74
|
function createSubaccountUsageCommand(factory) {
|
|
93
75
|
return addOutputFlags(new Command('usage')
|
|
94
76
|
.description('Show subaccount usage')
|
|
95
77
|
.argument('[id]')
|
|
96
78
|
.option('-L, --limit <number>', 'Maximum number of usage records to return', parsePositiveInteger)
|
|
97
|
-
.option('--cursor <cursor>', 'Pagination cursor'))
|
|
98
|
-
.action(async (id, options) => {
|
|
79
|
+
.option('--cursor <cursor>', 'Pagination cursor')).action(async (id, options) => {
|
|
99
80
|
if (id) {
|
|
100
|
-
await
|
|
101
|
-
|
|
102
|
-
|
|
81
|
+
await requestOperationAndPrint(factory, 'subaccounts.get', {
|
|
82
|
+
pathParams: { subaccountId: id },
|
|
83
|
+
query: { include: ['usage'] },
|
|
84
|
+
output: outputFlags(options),
|
|
103
85
|
});
|
|
104
86
|
return;
|
|
105
87
|
}
|
|
106
|
-
await
|
|
88
|
+
await requestOperationAndPrint(factory, 'subaccounts.usage.list', {
|
|
107
89
|
query: { limit: options.limit, cursor: options.cursor },
|
|
108
|
-
output: options,
|
|
90
|
+
output: outputFlags(options),
|
|
109
91
|
});
|
|
110
92
|
});
|
|
111
93
|
}
|
|
@@ -1,48 +1,46 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
-
import {
|
|
2
|
+
import { parsePositiveInteger } from '../shared/options.js';
|
|
3
|
+
import { createOperationDeleteCommand, createOperationJsonBodyCommand, createOperationListCommand, createOperationViewCommand, } from '../shared/operation.js';
|
|
3
4
|
export function createToolCommand(factory) {
|
|
4
5
|
const command = new Command('tool').description('Manage tools');
|
|
5
|
-
command.addCommand(
|
|
6
|
+
command.addCommand(createOperationListCommand(factory, {
|
|
7
|
+
operationId: 'tools.list',
|
|
6
8
|
description: 'List tools',
|
|
7
|
-
path: '/tools',
|
|
8
9
|
configure: (cmd) => cmd
|
|
9
10
|
.option('--space <id>', 'Filter by space id')
|
|
10
|
-
.option('--
|
|
11
|
-
.option('--
|
|
11
|
+
.option('-L, --limit <number>', 'Maximum number of results to return', parsePositiveInteger)
|
|
12
|
+
.option('--cursor <cursor>', 'Pagination cursor'),
|
|
12
13
|
query: (options) => ({
|
|
13
14
|
spaceId: typeof options.space === 'string' ? options.space : undefined,
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
limit: typeof options.limit === 'number' ? options.limit : undefined,
|
|
16
|
+
cursor: typeof options.cursor === 'string' ? options.cursor : undefined,
|
|
16
17
|
}),
|
|
17
18
|
}));
|
|
18
|
-
command.addCommand(
|
|
19
|
+
command.addCommand(createOperationViewCommand(factory, {
|
|
20
|
+
operationId: 'tools.get',
|
|
19
21
|
name: 'get',
|
|
20
22
|
description: 'Get a tool',
|
|
21
|
-
path: '/tools/{id}',
|
|
22
23
|
}));
|
|
23
|
-
command.addCommand(
|
|
24
|
+
command.addCommand(createOperationJsonBodyCommand(factory, {
|
|
25
|
+
operationId: 'tools.create',
|
|
24
26
|
name: 'create',
|
|
25
27
|
description: 'Create a tool',
|
|
26
|
-
method: 'post',
|
|
27
|
-
path: '/tools',
|
|
28
28
|
}));
|
|
29
|
-
command.addCommand(
|
|
29
|
+
command.addCommand(createOperationJsonBodyCommand(factory, {
|
|
30
|
+
operationId: 'tools.update',
|
|
30
31
|
name: 'patch',
|
|
31
32
|
description: 'Update a tool',
|
|
32
|
-
method: 'patch',
|
|
33
|
-
path: '/tools/{id}',
|
|
34
33
|
argNames: ['id'],
|
|
35
34
|
}));
|
|
36
|
-
command.addCommand(
|
|
35
|
+
command.addCommand(createOperationJsonBodyCommand(factory, {
|
|
36
|
+
operationId: 'tools.test',
|
|
37
37
|
name: 'test',
|
|
38
38
|
description: 'Test a tool',
|
|
39
|
-
method: 'post',
|
|
40
|
-
path: '/tools/{id}/test',
|
|
41
39
|
argNames: ['id'],
|
|
42
40
|
}));
|
|
43
|
-
command.addCommand(
|
|
41
|
+
command.addCommand(createOperationDeleteCommand(factory, {
|
|
42
|
+
operationId: 'tools.delete',
|
|
44
43
|
description: 'Delete a tool',
|
|
45
|
-
path: '/tools/{id}',
|
|
46
44
|
}));
|
|
47
45
|
return command;
|
|
48
46
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
-
import {
|
|
2
|
+
import { createOperationListCommand, createOperationViewCommand } from '../shared/operation.js';
|
|
3
3
|
export function createToolCallCommand(factory) {
|
|
4
4
|
const command = new Command('tool-call').description('Inspect BCTRL tool calls');
|
|
5
|
-
command.addCommand(
|
|
5
|
+
command.addCommand(createOperationListCommand(factory, {
|
|
6
|
+
operationId: 'tool-calls.list',
|
|
6
7
|
description: 'List tool calls',
|
|
7
|
-
path: '/tool-calls',
|
|
8
8
|
configure: (cmd) => cmd
|
|
9
9
|
.option('--space <id>', 'Space id')
|
|
10
10
|
.option('--tool <id>', 'Filter by tool id')
|
|
@@ -21,10 +21,10 @@ export function createToolCallCommand(factory) {
|
|
|
21
21
|
actor: typeof options.actor === 'string' ? options.actor : undefined,
|
|
22
22
|
}),
|
|
23
23
|
}));
|
|
24
|
-
command.addCommand(
|
|
24
|
+
command.addCommand(createOperationViewCommand(factory, {
|
|
25
|
+
operationId: 'tool-calls.get',
|
|
25
26
|
name: 'get',
|
|
26
27
|
description: 'View a tool call',
|
|
27
|
-
path: '/tool-calls/{id}',
|
|
28
28
|
}));
|
|
29
29
|
return command;
|
|
30
30
|
}
|