@2kw/ai 6.3.0-dev.105 → 6.3.0-dev.111

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.
@@ -1,7 +1,22 @@
1
1
  import { Command } from "commander";
2
2
  import { getClient, runAction } from "../lib/client.js";
3
+ import { CliUsageError } from "../lib/errors.js";
3
4
  import { formatPage, formatDetail, formatList, formatSuccess } from "../lib/output.js";
4
5
  import { addPaginationOptions, paginationParams } from "../lib/pagination.js";
6
+ const MIN_MONTHLY_PERCENT = 0;
7
+ const MAX_MONTHLY_PERCENT = 1000;
8
+ /**
9
+ * Validated inside the action rather than as commander's argument parser, so the refusal
10
+ * travels through `runAction` and exits 2 like every other usage error (see `parsePort` in
11
+ * connectors.ts).
12
+ */
13
+ function parseMonthlyPercent(value) {
14
+ const percent = /^\d+$/.test(value) ? Number(value) : NaN;
15
+ if (!Number.isInteger(percent) || percent < MIN_MONTHLY_PERCENT || percent > MAX_MONTHLY_PERCENT) {
16
+ throw new CliUsageError(`percent must be a whole number between ${MIN_MONTHLY_PERCENT} and ${MAX_MONTHLY_PERCENT}, not '${value}'`);
17
+ }
18
+ return percent;
19
+ }
5
20
  export function makeInstallationsCommand() {
6
21
  const cmd = new Command("installations").description("Manage surface installations");
7
22
  const list = new Command("list").description("List installations");
@@ -172,6 +187,36 @@ export function makeInstallationsCommand() {
172
187
  });
173
188
  });
174
189
  cmd.addCommand(keys);
190
+ const budget = new Command("budget").description("Manage an installation's monthly budget: a share of the organisation's pool");
191
+ budget
192
+ .command("get")
193
+ .description("Read an installation's current budget: percent, period, and usage")
194
+ .argument("<id>", "Installation ID")
195
+ .action(async (id, _opts, command) => {
196
+ await runAction(command, async () => {
197
+ const client = getClient(command);
198
+ const { data } = await client.GET("/v1/installations/{id}/budget", {
199
+ params: { path: { id } },
200
+ });
201
+ formatDetail(data, command);
202
+ });
203
+ });
204
+ budget
205
+ .command("set")
206
+ .description("Set or change an installation's monthly budget share, 0-1000 percent")
207
+ .argument("<id>", "Installation ID")
208
+ .argument("<percent>", "Monthly percent of the organisation's pool, 0-1000")
209
+ .action(async (id, percent, _opts, command) => {
210
+ await runAction(command, async () => {
211
+ const client = getClient(command);
212
+ const { data } = await client.PUT("/v1/installations/{id}/budget", {
213
+ params: { path: { id } },
214
+ body: { monthlyPercent: parseMonthlyPercent(percent) },
215
+ });
216
+ formatDetail(data, command);
217
+ });
218
+ });
219
+ cmd.addCommand(budget);
175
220
  return cmd;
176
221
  }
177
222
  //# sourceMappingURL=installations.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@2kw/ai",
3
- "version": "6.3.0-dev.105",
3
+ "version": "6.3.0-dev.111",
4
4
  "description": "CLI for 2kw.ai — schema-driven document extraction, an OpenAI-compatible EU LLM gateway, transcription, prompts, datasets, and experiments from your terminal or agentic workflows. Ships as 2kw, backbone, and bb.",
5
5
  "keywords": [
6
6
  "cli",