@ornncompute/cli 0.2.18 → 0.2.20

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/src/color.mjs ADDED
@@ -0,0 +1,71 @@
1
+ // SGR open/close pairs for the four styles the CLI uses.
2
+ const CODES = { red: [31, 39], green: [32, 39], bold: [1, 22], dim: [2, 22] };
3
+
4
+ function createColors(enabled) {
5
+ return Object.fromEntries(
6
+ Object.entries(CODES).map(([name, [open, close]]) => [
7
+ name,
8
+ enabled ? (text) => `\x1b[${open}m${text}\x1b[${close}m` : (text) => text,
9
+ ])
10
+ );
11
+ }
12
+
13
+ const NO_COLOR_FLAG = "--no-color";
14
+
15
+ // Structured-error label prefixes that get dim/bold styling. Matched at the
16
+ // start of a line; the remainder of the line (the value) is left untouched.
17
+ const LABEL_PREFIX_RE = /^(Code|Reason|Next steps?):/;
18
+
19
+ // `--no-color` is global: strip it anywhere in argv so per-command parsing
20
+ // never sees it as an unknown option.
21
+ export function extractNoColorFlag(argv) {
22
+ return {
23
+ argv: argv.filter((arg) => arg !== NO_COLOR_FLAG),
24
+ noColor: argv.includes(NO_COLOR_FLAG),
25
+ };
26
+ }
27
+
28
+ function streamSupportsColor(stream, env, noColorFlag) {
29
+ if (noColorFlag || Object.hasOwn(env ?? {}, "NO_COLOR")) {
30
+ return false;
31
+ }
32
+ if (Object.hasOwn(env ?? {}, "FORCE_COLOR")) {
33
+ return String(env.FORCE_COLOR) !== "0";
34
+ }
35
+ return Boolean(stream.isTTY);
36
+ }
37
+
38
+ // stdout and stderr are evaluated independently: one can be a TTY while the
39
+ // other is piped.
40
+ export function attachStreamColors({ env, noColorFlag, stdout, stderr }) {
41
+ stdout.pc = createColors(streamSupportsColor(stdout, env, noColorFlag));
42
+ stderr.pc = createColors(streamSupportsColor(stderr, env, noColorFlag));
43
+ }
44
+
45
+ export function writeColored(stream, variant, text) {
46
+ const colorize = stream.pc?.[variant];
47
+ stream.write(`${colorize ? colorize(text) : text}\n`);
48
+ }
49
+
50
+ // First line is the error summary (red); later `Code:`/`Reason:`/`Next step:`
51
+ // label prefixes are dim/bold, their values left plain.
52
+ export function colorizeErrorMessage(message, stream) {
53
+ const pc = stream?.pc;
54
+ if (!pc) {
55
+ return message;
56
+ }
57
+ return message
58
+ .split("\n")
59
+ .map((line, index) => {
60
+ if (index === 0) {
61
+ return line ? pc.red(line) : line;
62
+ }
63
+ const match = line.match(LABEL_PREFIX_RE);
64
+ if (!match) {
65
+ return line;
66
+ }
67
+ const label = match[0];
68
+ return `${pc.bold(pc.dim(label))}${line.slice(label.length)}`;
69
+ })
70
+ .join("\n");
71
+ }
@@ -44,6 +44,7 @@ export declare const listingCreateInput: z.ZodObject<{
44
44
  }, z.core.$strip>;
45
45
  export declare const listCatalogTermsCapability: import("../capability.ts").Capability<unknown, unknown>;
46
46
  export declare const listListingsCapability: import("../capability.ts").Capability<unknown, unknown>;
47
+ export declare const forecastListingsCapability: import("../capability.ts").Capability<unknown, unknown>;
47
48
  export declare const createListingCapability: import("../capability.ts").Capability<unknown, unknown>;
48
49
  export declare const listingCapabilities: import("../capability.ts").Capability<unknown, unknown>[];
49
50
  /** @deprecated Use createListingCapability. */
@@ -1,6 +1,14 @@
1
1
  import { z } from "zod";
2
2
  import { defineCapability, preview } from "../capability.js";
3
3
  import { bindHardwareFields, HARDWARE_LISTING_FIELDS, HARDWARE_LISTING_FILTERS, loadHardwareCatalog, projectCatalogTerms, } from "../spec-catalog.js";
4
+ function queryPath(path, params) {
5
+ const parts = [];
6
+ for (const [key, value] of Object.entries(params)) {
7
+ if (value?.trim())
8
+ parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(value.trim())}`);
9
+ }
10
+ return parts.length ? `${path}?${parts.join("&")}` : path;
11
+ }
4
12
  export const listingCreateInput = z.object({
5
13
  operatorId: z.string().optional(),
6
14
  operator_id: z.string().optional(),
@@ -46,6 +54,10 @@ export const listingCreateInput = z.object({
46
54
  confirm: z.boolean().optional(),
47
55
  });
48
56
  const catalogTermsInput = z.object({ kind: z.enum(["gpu", "cpu", "node", "link"]).optional() });
57
+ const listingForecastInput = z.object({
58
+ limit: z.number().int().min(1).max(500).optional(),
59
+ cursor: z.string().min(1).optional(),
60
+ });
49
61
  const slackListingCreateParams = {
50
62
  type: "object",
51
63
  properties: {
@@ -135,6 +147,23 @@ export const listListingsCapability = defineCapability({
135
147
  return ctx.fetch("/listings/available", { method: "GET", body: bound.payload });
136
148
  },
137
149
  });
150
+ export const forecastListingsCapability = defineCapability({
151
+ id: "listings.forecast",
152
+ domain: "listings",
153
+ roles: ["user"],
154
+ description: "List the next 48 hourly availability buckets for customer-visible compute listings.",
155
+ mutation: "read",
156
+ http: { method: "GET", path: "/v1/cli/compute/listings/forecast" },
157
+ slack: false,
158
+ input: listingForecastInput,
159
+ execute: async (ctx, input) => {
160
+ const parsed = listingForecastInput.parse(input);
161
+ return ctx.fetch(queryPath("/v1/cli/compute/listings/forecast", {
162
+ limit: parsed.limit?.toString(),
163
+ cursor: parsed.cursor,
164
+ }), { method: "GET" });
165
+ },
166
+ });
138
167
  /** Commerce parses listing windows as RFC3339 timestamps, not bare dates. */
139
168
  function rfc3339(value) {
140
169
  const trimmed = value.trim();
@@ -317,6 +346,7 @@ export const createListingCapability = defineCapability({
317
346
  export const listingCapabilities = [
318
347
  listCatalogTermsCapability,
319
348
  listListingsCapability,
349
+ forecastListingsCapability,
320
350
  createListingCapability,
321
351
  ];
322
352
  /** @deprecated Use createListingCapability. */
@@ -0,0 +1,171 @@
1
+ import { z } from "zod";
2
+ export declare const gtmCompanyListInput: z.ZodObject<{
3
+ q: z.ZodOptional<z.ZodString>;
4
+ limit: z.ZodOptional<z.ZodNumber>;
5
+ }, z.core.$strip>;
6
+ export declare const gtmCompanyListCapability: import("../capability.ts").Capability<unknown, unknown>;
7
+ export declare const gtmCompanyWriteInput: z.ZodObject<{
8
+ confirm: z.ZodOptional<z.ZodBoolean>;
9
+ name: z.ZodString;
10
+ ownerTags: z.ZodDefault<z.ZodString>;
11
+ notes: z.ZodOptional<z.ZodString>;
12
+ companyId: z.ZodOptional<z.ZodNumber>;
13
+ }, z.core.$strip>;
14
+ export declare const gtmCompanyWriteCapability: import("../capability.ts").Capability<unknown, unknown>;
15
+ export declare const gtmDealListInput: z.ZodObject<{
16
+ q: z.ZodOptional<z.ZodString>;
17
+ limit: z.ZodOptional<z.ZodNumber>;
18
+ }, z.core.$strip>;
19
+ export declare const gtmDealListCapability: import("../capability.ts").Capability<unknown, unknown>;
20
+ export declare const gtmDealWriteInput: z.ZodObject<{
21
+ listingId: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodLiteral<"">]>>;
22
+ currentBid: z.ZodOptional<z.ZodString>;
23
+ confirm: z.ZodOptional<z.ZodBoolean>;
24
+ customer: z.ZodString;
25
+ owner: z.ZodString;
26
+ supplier: z.ZodString;
27
+ gpuType: z.ZodString;
28
+ dealId: z.ZodOptional<z.ZodNumber>;
29
+ }, z.core.$strip>;
30
+ export declare const gtmDealWriteCapability: import("../capability.ts").Capability<unknown, unknown>;
31
+ export declare const gtmCommentListInput: z.ZodObject<{
32
+ dealId: z.ZodOptional<z.ZodNumber>;
33
+ companyId: z.ZodOptional<z.ZodNumber>;
34
+ }, z.core.$strip>;
35
+ export declare const gtmCommentListCapability: import("../capability.ts").Capability<unknown, unknown>;
36
+ export declare const gtmCommentWriteInput: z.ZodObject<{
37
+ dealId: z.ZodOptional<z.ZodNumber>;
38
+ companyId: z.ZodOptional<z.ZodNumber>;
39
+ commentId: z.ZodOptional<z.ZodNumber>;
40
+ parentId: z.ZodOptional<z.ZodNumber>;
41
+ body: z.ZodString;
42
+ bid: z.ZodDefault<z.ZodBoolean>;
43
+ confirm: z.ZodOptional<z.ZodBoolean>;
44
+ }, z.core.$strip>;
45
+ export declare const gtmCommentWriteCapability: import("../capability.ts").Capability<unknown, unknown>;
46
+ export declare const gtmMentionDismissInput: z.ZodObject<{
47
+ commentId: z.ZodNumber;
48
+ confirm: z.ZodOptional<z.ZodBoolean>;
49
+ }, z.core.$strip>;
50
+ export declare const gtmMentionDismissCapability: import("../capability.ts").Capability<unknown, unknown>;
51
+ export declare const gtmWorkspaceShowInput: z.ZodObject<{}, z.core.$strip>;
52
+ export declare const gtmWorkspaceShowCapability: import("../capability.ts").Capability<unknown, unknown>;
53
+ export declare const gtmTaskListInput: z.ZodObject<{
54
+ q: z.ZodOptional<z.ZodString>;
55
+ limit: z.ZodOptional<z.ZodNumber>;
56
+ }, z.core.$strip>;
57
+ export declare const gtmTaskListCapability: import("../capability.ts").Capability<unknown, unknown>;
58
+ export declare const gtmTaskWriteInput: z.ZodObject<{
59
+ taskId: z.ZodOptional<z.ZodNumber>;
60
+ title: z.ZodString;
61
+ body: z.ZodDefault<z.ZodString>;
62
+ companyId: z.ZodNumber;
63
+ dealId: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
64
+ assignee: z.ZodString;
65
+ status: z.ZodOptional<z.ZodEnum<{
66
+ open: "open";
67
+ done: "done";
68
+ }>>;
69
+ confirm: z.ZodOptional<z.ZodBoolean>;
70
+ }, z.core.$strip>;
71
+ export declare const gtmTaskWriteCapability: import("../capability.ts").Capability<unknown, unknown>;
72
+ export declare const gtmCompanyDeleteInput: z.ZodObject<{
73
+ [x: string]: z.ZodNumber | z.ZodOptional<z.ZodBoolean>;
74
+ confirm: z.ZodOptional<z.ZodBoolean>;
75
+ }, z.core.$strip>;
76
+ export declare const gtmCompanyDeleteCapability: import("../capability.ts").Capability<unknown, unknown>;
77
+ export declare const gtmDealDeleteInput: z.ZodObject<{
78
+ [x: string]: z.ZodNumber | z.ZodOptional<z.ZodBoolean>;
79
+ confirm: z.ZodOptional<z.ZodBoolean>;
80
+ }, z.core.$strip>;
81
+ export declare const gtmDealDeleteCapability: import("../capability.ts").Capability<unknown, unknown>;
82
+ export declare const gtmCommentDeleteInput: z.ZodObject<{
83
+ [x: string]: z.ZodNumber | z.ZodOptional<z.ZodBoolean>;
84
+ confirm: z.ZodOptional<z.ZodBoolean>;
85
+ }, z.core.$strip>;
86
+ export declare const gtmCommentDeleteCapability: import("../capability.ts").Capability<unknown, unknown>;
87
+ export declare const gtmTaskDeleteInput: z.ZodObject<{
88
+ [x: string]: z.ZodNumber | z.ZodOptional<z.ZodBoolean>;
89
+ confirm: z.ZodOptional<z.ZodBoolean>;
90
+ }, z.core.$strip>;
91
+ export declare const gtmTaskDeleteCapability: import("../capability.ts").Capability<unknown, unknown>;
92
+ /**
93
+ * Listing verbs. GTM never touches a Commerce table directly: these call
94
+ * Commerce's own listing routes through the gateway, exactly as the staff app
95
+ * does. Nothing here writes a gtm_ row, and nothing in the CRM constrains a
96
+ * listing.
97
+ */
98
+ export declare const gtmListingListInput: z.ZodObject<{
99
+ gpuType: z.ZodOptional<z.ZodString>;
100
+ limit: z.ZodOptional<z.ZodNumber>;
101
+ }, z.core.$strip>;
102
+ export declare const gtmListingListCapability: import("../capability.ts").Capability<unknown, unknown>;
103
+ export declare const gtmListingUpdateInput: z.ZodObject<{
104
+ listingId: z.ZodString;
105
+ buyNowRatePerGpuHour: z.ZodOptional<z.ZodString>;
106
+ costPerGpuHour: z.ZodOptional<z.ZodString>;
107
+ monthToMonth: z.ZodOptional<z.ZodBoolean>;
108
+ allowsDepositPlan: z.ZodOptional<z.ZodBoolean>;
109
+ downPaymentPct: z.ZodOptional<z.ZodString>;
110
+ capacityNodes: z.ZodOptional<z.ZodNumber>;
111
+ state: z.ZodOptional<z.ZodEnum<{
112
+ delisted: "delisted";
113
+ draft: "draft";
114
+ listed: "listed";
115
+ }>>;
116
+ confirm: z.ZodOptional<z.ZodBoolean>;
117
+ }, z.core.$strip>;
118
+ export declare const gtmListingUpdateCapability: import("../capability.ts").Capability<unknown, unknown>;
119
+ export declare const gtmTaskActivityListInput: z.ZodObject<{
120
+ taskId: z.ZodNumber;
121
+ }, z.core.$strip>;
122
+ export declare const gtmTaskActivityListCapability: import("../capability.ts").Capability<unknown, unknown>;
123
+ export declare const gtmTaskActivityWriteInput: z.ZodObject<{
124
+ taskId: z.ZodNumber;
125
+ body: z.ZodString;
126
+ parentId: z.ZodOptional<z.ZodNumber>;
127
+ confirm: z.ZodOptional<z.ZodBoolean>;
128
+ }, z.core.$strip>;
129
+ export declare const gtmTaskActivityWriteCapability: import("../capability.ts").Capability<unknown, unknown>;
130
+ export declare const gtmCellCommentListInput: z.ZodObject<{
131
+ companyId: z.ZodNumber;
132
+ field: z.ZodEnum<{
133
+ name: "name";
134
+ notes: "notes";
135
+ owner_tags: "owner_tags";
136
+ tickets: "tickets";
137
+ }>;
138
+ }, z.core.$strip>;
139
+ export declare const gtmCellCommentListCapability: import("../capability.ts").Capability<unknown, unknown>;
140
+ export declare const gtmCellCommentWriteInput: z.ZodObject<{
141
+ companyId: z.ZodOptional<z.ZodNumber>;
142
+ field: z.ZodOptional<z.ZodEnum<{
143
+ name: "name";
144
+ notes: "notes";
145
+ owner_tags: "owner_tags";
146
+ tickets: "tickets";
147
+ }>>;
148
+ commentId: z.ZodOptional<z.ZodNumber>;
149
+ parentId: z.ZodOptional<z.ZodNumber>;
150
+ body: z.ZodString;
151
+ confirm: z.ZodOptional<z.ZodBoolean>;
152
+ }, z.core.$strip>;
153
+ export declare const gtmCellCommentWriteCapability: import("../capability.ts").Capability<unknown, unknown>;
154
+ export declare const gtmCellCommentDeleteInput: z.ZodObject<{
155
+ [x: string]: z.ZodNumber | z.ZodOptional<z.ZodBoolean>;
156
+ confirm: z.ZodOptional<z.ZodBoolean>;
157
+ }, z.core.$strip>;
158
+ export declare const gtmCellCommentDeleteCapability: import("../capability.ts").Capability<unknown, unknown>;
159
+ /**
160
+ * Bulk owner-tag reassignment. This is the one GTM edit that is genuinely
161
+ * N-at-a-time — a book of companies moving to a new owner — and doing it one
162
+ * confirmation at a time is both slow and easy to half-finish. Every other
163
+ * bulk case is a loop over the single-record verbs.
164
+ */
165
+ export declare const gtmCompanyBulkRetagInput: z.ZodObject<{
166
+ companyIds: z.ZodArray<z.ZodNumber>;
167
+ ownerTags: z.ZodString;
168
+ confirm: z.ZodOptional<z.ZodBoolean>;
169
+ }, z.core.$strip>;
170
+ export declare const gtmCompanyBulkRetagCapability: import("../capability.ts").Capability<unknown, unknown>;
171
+ export declare const staffGTMCapabilities: import("../capability.ts").Capability<unknown, unknown>[];