sandcovery 0.2.0 → 0.3.0
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/README.md +8 -3
- package/dist/{Schema-C4ay0Aif.mjs → Schema-DiSfJzMf.mjs} +80 -4
- package/dist/cli/index.mjs +7 -7
- package/dist/{handlers-BxhSLDGk.mjs → handlers-rkx0CsMY.mjs} +277 -35
- package/dist/index.d.mts +9 -1
- package/dist/index.mjs +1 -1
- package/dist/{origin-Dj-n4EQa.mjs → origin-CIA-1Jia.mjs} +68 -11
- package/dist/posthog-project-BpOd2VxW.mjs +1 -0
- package/dist/{posthog-project-Bb0IFKUv.mjs → posthog-project-CdWw_ofg.mjs} +3 -1
- package/dist/{spec-ClAX0dAN.mjs → spec-DfgmzDj-.mjs} +177 -30
- package/dist/{src-D3WZodpF.mjs → src-YrynO3hz.mjs} +304 -77
- package/dist/{telemetry-delivery-1a7C-8DK.mjs → telemetry-delivery-zinKRHRc.mjs} +1 -1
- package/dist/{types-Dxh7amZB.d.mts → types-DMB8KnA3.d.mts} +202 -2
- package/dist/types.d.mts +2 -2
- package/dist/types.mjs +18 -2
- package/package.json +4 -4
- package/dist/posthog-project-B0jmQTwy.mjs +0 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
# Sandcovery
|
|
6
6
|
|
|
7
|
-
TypeScript client for the [Sandcovery API](https://www.sandcovery.com): one API and one key for ephemeral sandboxes across
|
|
7
|
+
TypeScript client for the [Sandcovery API](https://www.sandcovery.com): one API and one key for ephemeral sandboxes across [every routed provider](https://www.sandcovery.com/providers), running on your own provider accounts.
|
|
8
8
|
|
|
9
9
|
## Install
|
|
10
10
|
|
|
@@ -61,6 +61,7 @@ sandcovery sandboxes destroy "$id" --yes
|
|
|
61
61
|
- `sandcovery sandboxes exec` streams the command's output and exits with the command's exit code.
|
|
62
62
|
- `--json` prints one JSON document on stdout, and every failure prints a JSON error with a stable `reason` on stderr.
|
|
63
63
|
- `sandboxes destroy`, `keys revoke`, and `credentials delete` ask first, and need `--yes` without a terminal.
|
|
64
|
+
- `sandcovery providers list --routed` lists only the providers Sandcovery routes to, `sandcovery credentials offer` shows the free vCPU-hours your keys have earned, and `sandcovery billing inspect` and `sandcovery billing buy-credits --amount <USD>` show the plan and start a credit payment.
|
|
64
65
|
- `sandcovery help search <words>` finds a command, and `--help` works on every command.
|
|
65
66
|
- The CLI sends anonymous usage data: command paths, option names, failure reasons, and exit codes, never values or remote data. `sandcovery cli telemetry disable` or `SANDCOVERY_TELEMETRY_DISABLED=1` turns it off.
|
|
66
67
|
|
|
@@ -72,7 +73,7 @@ Provider, region, and size names are open strings, so a name the API adds later
|
|
|
72
73
|
|
|
73
74
|
## Keys and provider credentials
|
|
74
75
|
|
|
75
|
-
`keys`, `credentials`, and `
|
|
76
|
+
`keys`, `credentials`, `usage`, and `billing` need a management key, which an organization owner mints in the dashboard. An API key receives 403 there.
|
|
76
77
|
|
|
77
78
|
```ts
|
|
78
79
|
const admin = new Sandcovery({ apiKey: process.env.SANDCOVERY_MANAGEMENT_KEY })
|
|
@@ -80,7 +81,11 @@ const admin = new Sandcovery({ apiKey: process.env.SANDCOVERY_MANAGEMENT_KEY })
|
|
|
80
81
|
await admin.credentials.set('e2b', { api_key: process.env.E2B_API_KEY })
|
|
81
82
|
```
|
|
82
83
|
|
|
83
|
-
The fields each provider takes are its `credential_fields` on `sandcovery.providers.get(provider)`.
|
|
84
|
+
The fields each provider takes are its `credential_fields` on `sandcovery.providers.get(provider)`. `sandcovery.providers.catalog()` lists every provider on the [provider board](https://www.sandcovery.com/providers), where `routed` is `false` for a provider that is coming soon. `credentials.offer()` reads the free vCPU-hours your keys have earned, `billing.get()` reads the plan and the credit balance, and `billing.buyCredits({ amount_micro_usd })` answers the Stripe Checkout page that takes a credit payment.
|
|
85
|
+
|
|
86
|
+
## Interfaces
|
|
87
|
+
|
|
88
|
+
This client, the `sandcovery` command, and the Python client each reach every operation of the REST API, and a test of each fails when one of them leaves an operation out.
|
|
84
89
|
|
|
85
90
|
## Errors
|
|
86
91
|
|
|
@@ -2597,7 +2597,7 @@ const String$4 = /*#__PURE__*/ make$10((self, that) => self < that ? -1 : 1);
|
|
|
2597
2597
|
* @category instances
|
|
2598
2598
|
* @since 4.0.0
|
|
2599
2599
|
*/
|
|
2600
|
-
const Number$
|
|
2600
|
+
const Number$5 = /*#__PURE__*/ make$10((self, that) => {
|
|
2601
2601
|
if (globalThis.Number.isNaN(self) && globalThis.Number.isNaN(that)) return 0;
|
|
2602
2602
|
if (globalThis.Number.isNaN(self)) return -1;
|
|
2603
2603
|
if (globalThis.Number.isNaN(that)) return 1;
|
|
@@ -5719,6 +5719,49 @@ const formatIsoOffset = (self) => {
|
|
|
5719
5719
|
};
|
|
5720
5720
|
/** @internal */
|
|
5721
5721
|
const formatIsoZoned = (self) => self.zone._tag === "Offset" ? formatIsoOffset(self) : `${formatIsoOffset(self)}[${self.zone.id}]`;
|
|
5722
|
+
globalThis.Number;
|
|
5723
|
+
/**
|
|
5724
|
+
* Returns the remainder left over when one operand is divided by a second operand, always taking the sign of the dividend.
|
|
5725
|
+
*
|
|
5726
|
+
* **When to use**
|
|
5727
|
+
*
|
|
5728
|
+
* Use to compute a numeric remainder while preserving decimal precision better
|
|
5729
|
+
* than direct JavaScript `%` for decimal operands.
|
|
5730
|
+
*
|
|
5731
|
+
* **Example** (Calculating remainders)
|
|
5732
|
+
*
|
|
5733
|
+
* ```ts import.meta.vitest
|
|
5734
|
+
* import { Number } from "effect"
|
|
5735
|
+
*
|
|
5736
|
+
* Number.remainder(2, 2) // => 0
|
|
5737
|
+
* Number.remainder(3, 2) // => 1
|
|
5738
|
+
* Number.remainder(-4, 2) // => -0
|
|
5739
|
+
* ```
|
|
5740
|
+
*
|
|
5741
|
+
* @see {@link divide} for quotient calculation with division-by-zero represented as `Option.none`
|
|
5742
|
+
*
|
|
5743
|
+
* @stability stable
|
|
5744
|
+
* @category math
|
|
5745
|
+
* @since 2.0.0
|
|
5746
|
+
*/
|
|
5747
|
+
const remainder = /*#__PURE__*/ dual(2, (self, divisor) => {
|
|
5748
|
+
if (!globalThis.Number.isFinite(self) || !globalThis.Number.isFinite(divisor) || divisor === 0) return NaN;
|
|
5749
|
+
if (globalThis.Number.isInteger(self) && globalThis.Number.isInteger(divisor)) return self % divisor;
|
|
5750
|
+
const [selfCoefficient, selfExponent] = toScientificInteger(self);
|
|
5751
|
+
const [divisorCoefficient, divisorExponent] = toScientificInteger(divisor);
|
|
5752
|
+
const exponent = Math.min(selfExponent, divisorExponent);
|
|
5753
|
+
const out = selfCoefficient * BigInt(10) ** BigInt(selfExponent - exponent) % (divisorCoefficient * BigInt(10) ** BigInt(divisorExponent - exponent));
|
|
5754
|
+
if (out === BigInt(0)) return self < 0 || Object.is(self, -0) ? -0 : 0;
|
|
5755
|
+
const remainder = globalThis.Number(`${out}e${exponent}`);
|
|
5756
|
+
return remainder === 0 ? Math.sign(self) * globalThis.Number.MIN_VALUE : remainder;
|
|
5757
|
+
});
|
|
5758
|
+
function toScientificInteger(n) {
|
|
5759
|
+
if (globalThis.Number.isInteger(n)) return [BigInt(n), 0];
|
|
5760
|
+
const scientific = Math.abs(n).toExponential();
|
|
5761
|
+
const eIndex = scientific.indexOf("e");
|
|
5762
|
+
const digits = scientific.slice(0, eIndex).replace(".", "");
|
|
5763
|
+
return [BigInt(digits) * (n < 0 ? -BigInt(1) : BigInt(1)), globalThis.Number(scientific.slice(eIndex + 1)) - digits.length + 1];
|
|
5764
|
+
}
|
|
5722
5765
|
/**
|
|
5723
5766
|
* Creates an `Effect` that always succeeds with a given value.
|
|
5724
5767
|
*
|
|
@@ -11061,7 +11104,7 @@ function encodeNumberPayload(number) {
|
|
|
11061
11104
|
* @since 4.0.0
|
|
11062
11105
|
*/
|
|
11063
11106
|
const isGreaterThanOrEqualTo = /*#__PURE__*/ makeIsGreaterThanOrEqualTo({
|
|
11064
|
-
order: Number$
|
|
11107
|
+
order: Number$5,
|
|
11065
11108
|
annotate: (minimum) => ({
|
|
11066
11109
|
representation: {
|
|
11067
11110
|
id: "effect/schema/isGreaterThanOrEqualTo",
|
|
@@ -11094,7 +11137,7 @@ const isGreaterThanOrEqualTo = /*#__PURE__*/ makeIsGreaterThanOrEqualTo({
|
|
|
11094
11137
|
* @since 4.0.0
|
|
11095
11138
|
*/
|
|
11096
11139
|
const isBetween = /*#__PURE__*/ makeIsBetween({
|
|
11097
|
-
order: Number$
|
|
11140
|
+
order: Number$5,
|
|
11098
11141
|
annotate: (options) => {
|
|
11099
11142
|
const exclusiveMinimum = options.exclusiveMinimum ? true : void 0;
|
|
11100
11143
|
const exclusiveMaximum = options.exclusiveMaximum ? true : void 0;
|
|
@@ -11117,6 +11160,39 @@ const isBetween = /*#__PURE__*/ makeIsBetween({
|
|
|
11117
11160
|
}
|
|
11118
11161
|
});
|
|
11119
11162
|
/**
|
|
11163
|
+
* Validates that a number is a multiple of the specified divisor.
|
|
11164
|
+
*
|
|
11165
|
+
* **Details**
|
|
11166
|
+
*
|
|
11167
|
+
* JSON Schema:
|
|
11168
|
+
*
|
|
11169
|
+
* This check corresponds to the `multipleOf` constraint in JSON Schema.
|
|
11170
|
+
* Negative divisors are normalized to their absolute value because JSON
|
|
11171
|
+
* Schema requires `multipleOf` to be positive.
|
|
11172
|
+
*
|
|
11173
|
+
* **Gotchas**
|
|
11174
|
+
*
|
|
11175
|
+
* Throws a `RangeError` when `divisor` is zero or is not finite.
|
|
11176
|
+
*
|
|
11177
|
+
* @stability stable
|
|
11178
|
+
* @category validation
|
|
11179
|
+
* @since 4.0.0
|
|
11180
|
+
*/
|
|
11181
|
+
function isMultipleOf(divisor, annotations) {
|
|
11182
|
+
if (!globalThis.Number.isFinite(divisor) || divisor === 0) throw new globalThis.RangeError(`Expected a finite non-zero number, got ${globalThis.String(divisor)}`);
|
|
11183
|
+
divisor = globalThis.Math.abs(divisor);
|
|
11184
|
+
return makeFilter((input) => remainder(input, divisor) === 0, {
|
|
11185
|
+
expected: `a value that is a multiple of ${divisor}`,
|
|
11186
|
+
representation: {
|
|
11187
|
+
id: "effect/schema/isMultipleOf",
|
|
11188
|
+
payload: { divisor }
|
|
11189
|
+
},
|
|
11190
|
+
toJsonSchema: () => ({ multipleOf: divisor }),
|
|
11191
|
+
toCode: () => ({ runtime: `Schema.isMultipleOf(${format$1(divisor)})` }),
|
|
11192
|
+
...annotations
|
|
11193
|
+
});
|
|
11194
|
+
}
|
|
11195
|
+
/**
|
|
11120
11196
|
* Validates that a number is a safe integer (within the safe integer range
|
|
11121
11197
|
* that can be exactly represented in JavaScript).
|
|
11122
11198
|
*
|
|
@@ -11470,4 +11546,4 @@ const Json = /*#__PURE__*/ make(/*#__PURE__*/ annotate(Json$1, { toCode: () => (
|
|
|
11470
11546
|
runtime: "Schema.Json",
|
|
11471
11547
|
Type: "Schema.Json"
|
|
11472
11548
|
}) }));
|
|
11473
|
-
export {
|
|
11549
|
+
export { optionalKey as A, try_$2 as B, isBetween as C, isUUID as D, isMultipleOf as E, seconds as F, none as G, getOrUndefined as H, toMillis as I, isString$1 as J, hasProperty as K, getSuccess as L, makeFormatterStandardSchemaV1 as M, TaggedError as N, makeFilter as O, millis as P, isFailure as R, isBase64Url as S, isMaxLength as T, isNone as U, getOrElse as V, map$5 as W, decodeUnknownOption as _, Int as a, fromJsonString as b, Literals as c, NonEmptyString as d, NullOr as f, Union as g, Struct as h, Finite as i, tag as j, optional as k, Natural as l, String$1 as m, Boolean$1 as n, Json as o, Record as p, isPropertyKey as q, Error$1 as r, Literal as s, ArraySchema as t, NonEmptyArray as u, decodeUnknownResult as v, isGreaterThanOrEqualTo as w, is as x, decodeUnknownSync as y, isSuccess$1 as z };
|
package/dist/cli/index.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import { n as SANDCOVERY_ORIGIN } from "../origin-
|
|
4
|
-
import { A as
|
|
2
|
+
import { B as try_, F as seconds, H as getOrUndefined, I as toMillis, J as isString, K as hasProperty, N as TaggedError, P as millis, R as isFailure, _ as decodeUnknownOption, b as fromJsonString, h as Struct, k as optional, m as String$1, n as Boolean, o as Json, p as Record, y as decodeUnknownSync, z as isSuccess } from "../Schema-DiSfJzMf.mjs";
|
|
3
|
+
import { n as SANDCOVERY_ORIGIN } from "../origin-CIA-1Jia.mjs";
|
|
4
|
+
import { A as CliFailure, C as remoteLine, E as isDigit, M as statusOf$1, N as usageFailure, O as isUpper, P as Canceled, S as remoteCell, T as consistsOf, _ as glyph, a as closest, b as theme, c as isOptionValue, d as parseLeaf, f as readOptionToken, g as ellipsis, h as clearLine, i as version, j as exitCodeOf, k as isWordCharacter, l as lastValue, o as flagOf, p as rerunArgv, r as CLI, s as isOptionToken, t as BIN, u as parseFailure, v as plainPrefix, w as remoteText, x as escapeUnprintable, y as spinnerFrame } from "../spec-DfgmzDj-.mjs";
|
|
5
5
|
import { n as sendTelemetry$1, t as loopbackOrigin } from "../telemetry-BYnuVdoZ.mjs";
|
|
6
|
-
import "../posthog-project-
|
|
6
|
+
import "../posthog-project-CdWw_ofg.mjs";
|
|
7
7
|
import http from "node:http";
|
|
8
8
|
import fs from "node:fs";
|
|
9
9
|
import path from "node:path";
|
|
@@ -552,7 +552,7 @@ const takeOption = (walk, argv, token) => {
|
|
|
552
552
|
return;
|
|
553
553
|
}
|
|
554
554
|
const next = argv[walk.index];
|
|
555
|
-
if (read.option.kind === "value" && read.explicit === null && next !== void 0 &&
|
|
555
|
+
if (read.option.kind === "value" && read.explicit === null && next !== void 0 && isOptionValue(next)) {
|
|
556
556
|
walk.tokens.push(next);
|
|
557
557
|
walk.index += 1;
|
|
558
558
|
}
|
|
@@ -1456,7 +1456,7 @@ const runCommand = async ({ invocation, session }) => {
|
|
|
1456
1456
|
try {
|
|
1457
1457
|
const local = LOCAL_COMMANDS.get(key);
|
|
1458
1458
|
if (local !== void 0) return local(context);
|
|
1459
|
-
const { HANDLERS } = await import("../handlers-
|
|
1459
|
+
const { HANDLERS } = await import("../handlers-rkx0CsMY.mjs");
|
|
1460
1460
|
const handler = HANDLERS.get(key);
|
|
1461
1461
|
if (handler === void 0) throw internalFailure(invocation.path);
|
|
1462
1462
|
return await handler(context);
|
|
@@ -1699,7 +1699,7 @@ if (event === void 0) {
|
|
|
1699
1699
|
signal: controller.signal
|
|
1700
1700
|
});
|
|
1701
1701
|
} else {
|
|
1702
|
-
const [{ deliverTelemetry }, project] = await Promise.all([import("../telemetry-delivery-
|
|
1702
|
+
const [{ deliverTelemetry }, project] = await Promise.all([import("../telemetry-delivery-zinKRHRc.mjs"), import("../posthog-project-BpOd2VxW.mjs")]);
|
|
1703
1703
|
await deliverTelemetry({
|
|
1704
1704
|
host: process.env.__SANDCOVERY_POSTHOG_HOST,
|
|
1705
1705
|
productionHost: project.POSTHOG_INGEST_HOST,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as CredentialFields, i as ApiError, n as CalendarDay, r as EstimateRequest, t as Sandcovery } from "./src-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { G as none, H as getOrUndefined, L as getSuccess, M as makeFormatterStandardSchemaV1, R as isFailure, U as isNone, W as map, _ as decodeUnknownOption, b as fromJsonString, c as Literals, h as Struct, m as String$1, q as isPropertyKey, v as decodeUnknownResult, x as is } from "./Schema-DiSfJzMf.mjs";
|
|
2
|
+
import { a as CredentialFields, i as ApiError, n as CalendarDay, r as EstimateRequest, t as Sandcovery } from "./src-YrynO3hz.mjs";
|
|
3
|
+
import { A as KeyId, D as MICRO_USD_PER_DOLLAR, F as SandboxId, N as Provider, O as ApiKeyId, _ as SandboxStatus, b as ProviderSort, c as SpendLimit, d as CreateSandboxRequest, f as Port, j as KeySecret, l as UpdateKeyRequest, n as SANDCOVERY_ORIGIN, o as KeyKind, r as CreateKeyRequest } from "./origin-CIA-1Jia.mjs";
|
|
4
|
+
import { A as CliFailure, D as isDigits, N as usageFailure, P as Canceled, T as consistsOf, g as ellipsis, i as version, k as isWordCharacter, l as lastValue, m as valuesOf, n as CLEARABLE, o as flagOf, x as escapeUnprintable } from "./spec-DfgmzDj-.mjs";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { setTimeout } from "node:timers/promises";
|
|
7
7
|
// ../../node_modules/.pnpm/es-toolkit@1.53.1/node_modules/es-toolkit/dist/math/sumBy.mjs
|
|
@@ -96,7 +96,7 @@ const requiredKey = ({ action, context }) => {
|
|
|
96
96
|
userActionRequired: true
|
|
97
97
|
});
|
|
98
98
|
};
|
|
99
|
-
// ../
|
|
99
|
+
// ../format/src/display.ts
|
|
100
100
|
const LOCALE = "en-US";
|
|
101
101
|
const UTC = "UTC";
|
|
102
102
|
new Intl.DateTimeFormat(LOCALE, {
|
|
@@ -163,6 +163,11 @@ const moneyFormats = {
|
|
|
163
163
|
maximumSignificantDigits: 3,
|
|
164
164
|
style: "currency"
|
|
165
165
|
}),
|
|
166
|
+
trimmed: new Intl.NumberFormat(LOCALE, {
|
|
167
|
+
currency: "USD",
|
|
168
|
+
style: "currency",
|
|
169
|
+
trailingZeroDisplay: "stripIfInteger"
|
|
170
|
+
}),
|
|
166
171
|
whole: new Intl.NumberFormat(LOCALE, {
|
|
167
172
|
currency: "USD",
|
|
168
173
|
maximumFractionDigits: 0,
|
|
@@ -196,7 +201,7 @@ const formatPercent = ({ rate, style }) => percentFormats[style].format(rate);
|
|
|
196
201
|
// src/cli/format.ts
|
|
197
202
|
const MICROS_PER_CENT = 1e4;
|
|
198
203
|
const SECONDS_PER_MINUTE = 60;
|
|
199
|
-
const SECONDS_PER_HOUR = 3600;
|
|
204
|
+
const SECONDS_PER_HOUR$1 = 3600;
|
|
200
205
|
const moneyText = (micros) => formatMoney({
|
|
201
206
|
cents: micros / MICROS_PER_CENT,
|
|
202
207
|
style: "exact"
|
|
@@ -212,8 +217,8 @@ const shareText = (share) => share === null ? "-" : formatPercent({
|
|
|
212
217
|
const timeText = (iso) => iso === null ? "-" : `${iso.slice(0, 16).replace("T", " ")} UTC`;
|
|
213
218
|
const durationText = (seconds) => {
|
|
214
219
|
if (seconds < 120) return `${String(seconds)}s`;
|
|
215
|
-
if (seconds < SECONDS_PER_HOUR * 2) return `${String(Math.round(seconds / SECONDS_PER_MINUTE))}m`;
|
|
216
|
-
return `${String(Math.round(seconds / SECONDS_PER_HOUR * 10) / 10)}h`;
|
|
220
|
+
if (seconds < SECONDS_PER_HOUR$1 * 2) return `${String(Math.round(seconds / SECONDS_PER_MINUTE))}m`;
|
|
221
|
+
return `${String(Math.round(seconds / SECONDS_PER_HOUR$1 * 10) / 10)}h`;
|
|
217
222
|
};
|
|
218
223
|
const orDash = (value) => value ?? "-";
|
|
219
224
|
const countOrDash = (value) => value === null ? "-" : String(value);
|
|
@@ -849,6 +854,82 @@ const activityList = async (context) => {
|
|
|
849
854
|
})
|
|
850
855
|
};
|
|
851
856
|
};
|
|
857
|
+
// src/cli/commands/billing.ts
|
|
858
|
+
const BILLING_TARGET = "billing, which opens once Sandcovery sells credits";
|
|
859
|
+
const AMOUNT_FLAG = "--amount";
|
|
860
|
+
const billingInspect = async (context) => {
|
|
861
|
+
const billing = await callApi({
|
|
862
|
+
call: {
|
|
863
|
+
action: "show billing",
|
|
864
|
+
idempotent: true,
|
|
865
|
+
key: "required",
|
|
866
|
+
management: true,
|
|
867
|
+
run: async (client, signal) => await client.billing.get({ signal }),
|
|
868
|
+
target: BILLING_TARGET
|
|
869
|
+
},
|
|
870
|
+
context
|
|
871
|
+
});
|
|
872
|
+
const price = billing.pro_price;
|
|
873
|
+
context.io.details([
|
|
874
|
+
{
|
|
875
|
+
label: "Plan",
|
|
876
|
+
value: billing.plan === "pro" ? "Pro" : "Free"
|
|
877
|
+
},
|
|
878
|
+
{
|
|
879
|
+
label: "Credits",
|
|
880
|
+
value: moneyText(billing.credit_balance_micro_usd)
|
|
881
|
+
},
|
|
882
|
+
{
|
|
883
|
+
label: "Pro Price",
|
|
884
|
+
value: price === null ? "Not on sale" : `${moneyText(price.micro_usd)} a ${price.interval}`
|
|
885
|
+
}
|
|
886
|
+
]);
|
|
887
|
+
return {
|
|
888
|
+
document: { billing },
|
|
889
|
+
next: [{
|
|
890
|
+
argv: [
|
|
891
|
+
"billing",
|
|
892
|
+
"buy-credits",
|
|
893
|
+
"--amount",
|
|
894
|
+
"<USD>"
|
|
895
|
+
],
|
|
896
|
+
benefit: "Add credits through Stripe Checkout",
|
|
897
|
+
optional: true
|
|
898
|
+
}]
|
|
899
|
+
};
|
|
900
|
+
};
|
|
901
|
+
const billingBuyCredits = async (context) => {
|
|
902
|
+
const dollars = readInputs({
|
|
903
|
+
build: (inputs) => {
|
|
904
|
+
if (inputs.text("amount") === void 0) inputs.issue({
|
|
905
|
+
field: AMOUNT_FLAG,
|
|
906
|
+
message: `Can't buy credits without ${AMOUNT_FLAG}, in whole US dollars.`
|
|
907
|
+
});
|
|
908
|
+
return inputs.integer("amount", {
|
|
909
|
+
maximum: 1e3,
|
|
910
|
+
minimum: 25
|
|
911
|
+
}) ?? 0;
|
|
912
|
+
},
|
|
913
|
+
context,
|
|
914
|
+
verb: "buy credits"
|
|
915
|
+
});
|
|
916
|
+
const checkout = await callApi({
|
|
917
|
+
call: {
|
|
918
|
+
action: "start a credit purchase",
|
|
919
|
+
idempotent: false,
|
|
920
|
+
key: "required",
|
|
921
|
+
management: true,
|
|
922
|
+
run: async (client, signal) => await client.billing.buyCredits({ amount_micro_usd: dollars * MICRO_USD_PER_DOLLAR }, { signal }),
|
|
923
|
+
target: BILLING_TARGET
|
|
924
|
+
},
|
|
925
|
+
context
|
|
926
|
+
});
|
|
927
|
+
context.io.details([{
|
|
928
|
+
label: "Checkout",
|
|
929
|
+
value: checkout.url
|
|
930
|
+
}]);
|
|
931
|
+
return { document: { checkout } };
|
|
932
|
+
};
|
|
852
933
|
// ../cli-core/src/consent.ts
|
|
853
934
|
const SEVERE_ATTEMPTS = 3;
|
|
854
935
|
const typedName = async ({ attempts, io, prompter, request }) => {
|
|
@@ -906,6 +987,44 @@ const DELETE_ACTION = "delete the credential";
|
|
|
906
987
|
const decodeFields = decodeUnknownOption(fromJsonString(CredentialFields));
|
|
907
988
|
const FROM = "--from";
|
|
908
989
|
const credentialTarget = (provider) => `the ${provider} credential`;
|
|
990
|
+
const SECONDS_PER_HOUR = 3600;
|
|
991
|
+
const vcpuHours = (vcpuSeconds) => `${String(Math.floor(vcpuSeconds / SECONDS_PER_HOUR))} vCPU-hours`;
|
|
992
|
+
const credentialsOffer = async (context) => {
|
|
993
|
+
const offer = await callApi({
|
|
994
|
+
call: {
|
|
995
|
+
action: "show the offer",
|
|
996
|
+
idempotent: true,
|
|
997
|
+
key: "required",
|
|
998
|
+
management: true,
|
|
999
|
+
run: async (client, signal) => await client.credentials.offer({ signal }),
|
|
1000
|
+
target: "a running offer of free vCPU-hours"
|
|
1001
|
+
},
|
|
1002
|
+
context
|
|
1003
|
+
});
|
|
1004
|
+
context.io.details([
|
|
1005
|
+
{
|
|
1006
|
+
label: "Provider",
|
|
1007
|
+
value: offer.provider
|
|
1008
|
+
},
|
|
1009
|
+
{
|
|
1010
|
+
label: "Keys Counted",
|
|
1011
|
+
value: `${String(Math.min(offer.keys_counted, offer.keys_needed))}/${String(offer.keys_needed)}`
|
|
1012
|
+
},
|
|
1013
|
+
{
|
|
1014
|
+
label: "Free Left",
|
|
1015
|
+
value: `${vcpuHours(offer.remaining_vcpu_seconds)} of ${vcpuHours(offer.cap_vcpu_seconds)}`
|
|
1016
|
+
},
|
|
1017
|
+
{
|
|
1018
|
+
label: "Each Key Earns",
|
|
1019
|
+
value: vcpuHours(offer.vcpu_seconds_per_key)
|
|
1020
|
+
},
|
|
1021
|
+
{
|
|
1022
|
+
label: "Month Used Up",
|
|
1023
|
+
value: offer.month_used_up ? "Yes" : "No"
|
|
1024
|
+
}
|
|
1025
|
+
]);
|
|
1026
|
+
return { document: { offer } };
|
|
1027
|
+
};
|
|
909
1028
|
const credentialsList = async (context) => {
|
|
910
1029
|
const listed = await callApi({
|
|
911
1030
|
call: {
|
|
@@ -1471,42 +1590,100 @@ const keysRevoke = async (context) => {
|
|
|
1471
1590
|
};
|
|
1472
1591
|
// src/cli/commands/providers.ts
|
|
1473
1592
|
const LISTED_SIZE = "2x4";
|
|
1593
|
+
const NO_PROVIDERS = "No providers.";
|
|
1594
|
+
const PROVIDER = "Provider";
|
|
1595
|
+
const CREATE_P50 = "Create p50";
|
|
1596
|
+
const UPTIME_24H = "Uptime 24h";
|
|
1474
1597
|
const latencyText = (ms) => ms === null ? "-" : `${String(ms)} ms`;
|
|
1475
1598
|
const mibText = (mib) => mib === null ? "-" : `${String(mib)} MiB`;
|
|
1476
|
-
const
|
|
1477
|
-
|
|
1478
|
-
|
|
1599
|
+
const ISO_DAY_LENGTH = 10;
|
|
1600
|
+
const securityText = (fact) => {
|
|
1601
|
+
if (fact === null) return "unknown";
|
|
1602
|
+
const value = [fact.value].flat().join(", ");
|
|
1603
|
+
const read = `${fact.source_url}, read ${fact.read_at.slice(0, ISO_DAY_LENGTH)}`;
|
|
1604
|
+
return fact.source_changed_at === null ? `${value} (${read})` : `${value} (${read}, page changed ${fact.source_changed_at.slice(0, ISO_DAY_LENGTH)})`;
|
|
1605
|
+
};
|
|
1606
|
+
const COMING_SOON = "coming soon";
|
|
1607
|
+
const NOT_SHARED = "Not shared";
|
|
1608
|
+
const incidentsText = (incidents, statusUrl) => {
|
|
1609
|
+
if (incidents === null) return statusUrl === null ? "no public status page" : "not read yet";
|
|
1610
|
+
const active = incidents.data.filter(({ resolved_at }) => resolved_at === null).length;
|
|
1611
|
+
return active === 0 ? "none active" : `${String(active)} active`;
|
|
1612
|
+
};
|
|
1613
|
+
const listedRow = ({ entry, shared, status, statusUrl }) => {
|
|
1614
|
+
const hourly = entry.prices.find((candidate) => candidate.size === LISTED_SIZE)?.hourly_micro_usd;
|
|
1615
|
+
return [
|
|
1616
|
+
entry.provider,
|
|
1617
|
+
status,
|
|
1618
|
+
hourly === void 0 || hourly === null ? "-" : `${rateText(hourly)}/h`,
|
|
1619
|
+
shared ? latencyText(entry.create_latency_ms.p50) : NOT_SHARED,
|
|
1620
|
+
shared ? shareText(entry.uptime.last_24_hours) : NOT_SHARED,
|
|
1621
|
+
incidentsText(entry.incidents, statusUrl)
|
|
1622
|
+
];
|
|
1623
|
+
};
|
|
1624
|
+
const listProviders = ({ context, rows }) => {
|
|
1625
|
+
context.io.table({
|
|
1626
|
+
empty: NO_PROVIDERS,
|
|
1627
|
+
table: {
|
|
1628
|
+
columns: [
|
|
1629
|
+
{ header: PROVIDER },
|
|
1630
|
+
{ header: "Status" },
|
|
1631
|
+
{ header: `${LISTED_SIZE} Price` },
|
|
1632
|
+
{ header: CREATE_P50 },
|
|
1633
|
+
{ header: UPTIME_24H },
|
|
1634
|
+
{ header: "Incidents" }
|
|
1635
|
+
],
|
|
1636
|
+
rows
|
|
1637
|
+
}
|
|
1638
|
+
});
|
|
1479
1639
|
};
|
|
1640
|
+
const routedRow = (entry) => listedRow({
|
|
1641
|
+
entry,
|
|
1642
|
+
shared: entry.health_published,
|
|
1643
|
+
status: entry.status,
|
|
1644
|
+
statusUrl: entry.status_url
|
|
1645
|
+
});
|
|
1646
|
+
const catalogRow = (entry) => listedRow({
|
|
1647
|
+
entry,
|
|
1648
|
+
shared: entry.measurement !== "not_published",
|
|
1649
|
+
status: entry.routed ? entry.status : COMING_SOON,
|
|
1650
|
+
statusUrl: entry.links.status_url
|
|
1651
|
+
});
|
|
1480
1652
|
const providersList = async (context) => {
|
|
1481
|
-
|
|
1653
|
+
if (readInputs({
|
|
1654
|
+
build: (inputs) => inputs.flag("routed") === true,
|
|
1655
|
+
context,
|
|
1656
|
+
verb: "list the providers"
|
|
1657
|
+
})) {
|
|
1658
|
+
const board = await callApi({
|
|
1659
|
+
call: {
|
|
1660
|
+
action: "list the routed providers",
|
|
1661
|
+
idempotent: true,
|
|
1662
|
+
key: "optional",
|
|
1663
|
+
run: async (client, signal) => await client.providers.list({ signal })
|
|
1664
|
+
},
|
|
1665
|
+
context
|
|
1666
|
+
});
|
|
1667
|
+
listProviders({
|
|
1668
|
+
context,
|
|
1669
|
+
rows: board.data.map(routedRow)
|
|
1670
|
+
});
|
|
1671
|
+
return { document: { providers: board.data } };
|
|
1672
|
+
}
|
|
1673
|
+
const catalog = await callApi({
|
|
1482
1674
|
call: {
|
|
1483
1675
|
action: "list the providers",
|
|
1484
1676
|
idempotent: true,
|
|
1485
1677
|
key: "optional",
|
|
1486
|
-
run: async (client, signal) => await client.providers.
|
|
1678
|
+
run: async (client, signal) => await client.providers.catalog({ signal })
|
|
1487
1679
|
},
|
|
1488
1680
|
context
|
|
1489
1681
|
});
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
columns: [
|
|
1494
|
-
{ header: "Provider" },
|
|
1495
|
-
{ header: "Status" },
|
|
1496
|
-
{ header: `${LISTED_SIZE} Price` },
|
|
1497
|
-
{ header: "Create p50" },
|
|
1498
|
-
{ header: "Uptime 24h" }
|
|
1499
|
-
],
|
|
1500
|
-
rows: board.data.map((entry) => [
|
|
1501
|
-
entry.provider,
|
|
1502
|
-
entry.status,
|
|
1503
|
-
hourlyText(entry, LISTED_SIZE),
|
|
1504
|
-
latencyText(entry.create_latency_ms.p50),
|
|
1505
|
-
shareText(entry.uptime.last_24_hours)
|
|
1506
|
-
])
|
|
1507
|
-
}
|
|
1682
|
+
listProviders({
|
|
1683
|
+
context,
|
|
1684
|
+
rows: catalog.data.map(catalogRow)
|
|
1508
1685
|
});
|
|
1509
|
-
return { document: { providers:
|
|
1686
|
+
return { document: { providers: catalog.data } };
|
|
1510
1687
|
};
|
|
1511
1688
|
const providersInspect = async (context) => {
|
|
1512
1689
|
const provider = readInputs({
|
|
@@ -1527,7 +1704,7 @@ const providersInspect = async (context) => {
|
|
|
1527
1704
|
const { features } = entry;
|
|
1528
1705
|
context.io.details([
|
|
1529
1706
|
{
|
|
1530
|
-
label:
|
|
1707
|
+
label: PROVIDER,
|
|
1531
1708
|
value: entry.provider
|
|
1532
1709
|
},
|
|
1533
1710
|
{
|
|
@@ -1539,7 +1716,7 @@ const providersInspect = async (context) => {
|
|
|
1539
1716
|
value: entry.status
|
|
1540
1717
|
},
|
|
1541
1718
|
{
|
|
1542
|
-
label:
|
|
1719
|
+
label: CREATE_P50,
|
|
1543
1720
|
value: latencyText(entry.create_latency_ms.p50)
|
|
1544
1721
|
},
|
|
1545
1722
|
{
|
|
@@ -1550,6 +1727,22 @@ const providersInspect = async (context) => {
|
|
|
1550
1727
|
label: "Uptime 7d",
|
|
1551
1728
|
value: shareText(entry.uptime.last_7_days)
|
|
1552
1729
|
},
|
|
1730
|
+
{
|
|
1731
|
+
label: "Incidents",
|
|
1732
|
+
value: incidentsText(entry.incidents, entry.status_url)
|
|
1733
|
+
},
|
|
1734
|
+
{
|
|
1735
|
+
label: "Isolation",
|
|
1736
|
+
value: securityText(entry.security.isolation)
|
|
1737
|
+
},
|
|
1738
|
+
{
|
|
1739
|
+
label: "Compliance",
|
|
1740
|
+
value: securityText(entry.security.compliance)
|
|
1741
|
+
},
|
|
1742
|
+
{
|
|
1743
|
+
label: "Data Location",
|
|
1744
|
+
value: securityText(entry.security.data_location)
|
|
1745
|
+
},
|
|
1553
1746
|
{
|
|
1554
1747
|
label: "Regions",
|
|
1555
1748
|
value: features.regions.join(", ")
|
|
@@ -1605,6 +1798,23 @@ const providersInspect = async (context) => {
|
|
|
1605
1798
|
rows: entry.prices.map((price) => [price.size, rateText(price.hourly_micro_usd)])
|
|
1606
1799
|
}
|
|
1607
1800
|
});
|
|
1801
|
+
if (entry.incidents !== null) context.io.table({
|
|
1802
|
+
empty: "No incidents in the last 7 days.",
|
|
1803
|
+
table: {
|
|
1804
|
+
columns: [
|
|
1805
|
+
{ header: "Incident" },
|
|
1806
|
+
{ header: "Impact" },
|
|
1807
|
+
{ header: "Started" },
|
|
1808
|
+
{ header: "Resolved" }
|
|
1809
|
+
],
|
|
1810
|
+
rows: entry.incidents.data.map((incident) => [
|
|
1811
|
+
incident.title,
|
|
1812
|
+
incident.impact,
|
|
1813
|
+
timeText(incident.started_at),
|
|
1814
|
+
incident.resolved_at === null ? "active" : timeText(incident.resolved_at)
|
|
1815
|
+
])
|
|
1816
|
+
}
|
|
1817
|
+
});
|
|
1608
1818
|
return {
|
|
1609
1819
|
document: { provider: entry },
|
|
1610
1820
|
next: [{
|
|
@@ -1690,6 +1900,7 @@ const CREATE_TIMEOUT_SECONDS = 180;
|
|
|
1690
1900
|
const EXEC_MARGIN_SECONDS = 60;
|
|
1691
1901
|
const MAX_EXIT_CODE = 255;
|
|
1692
1902
|
const RUN_ACTION = "run the command";
|
|
1903
|
+
const START_ACTION = "start the detached command";
|
|
1693
1904
|
const DESTROY_ACTION = "destroy the sandbox";
|
|
1694
1905
|
const isPort = is(Port);
|
|
1695
1906
|
const sandboxTarget = (id) => `sandbox ${id}`;
|
|
@@ -1865,13 +2076,19 @@ const streamed = async ({ context, id, request }) => {
|
|
|
1865
2076
|
});
|
|
1866
2077
|
};
|
|
1867
2078
|
const sandboxesExec = async (context) => {
|
|
1868
|
-
const { id, request } = readInputs({
|
|
2079
|
+
const { detach, id, request } = readInputs({
|
|
1869
2080
|
build: (inputs) => {
|
|
1870
2081
|
const draft = { command: (context.arguments.command ?? []).join(" ") };
|
|
2082
|
+
const detached = inputs.flag("detach") === true;
|
|
1871
2083
|
put(draft, "cwd", inputs.text("cwd"));
|
|
1872
2084
|
put(draft, "env", inputs.pairs("env"));
|
|
1873
2085
|
put(draft, "timeout_seconds", inputs.integer("timeout", { minimum: 1 }));
|
|
2086
|
+
if (detached && draft.timeout_seconds !== void 0) inputs.issue({
|
|
2087
|
+
field: "--timeout",
|
|
2088
|
+
message: "Can't use --timeout with --detach, since a detached command runs until it exits or the sandbox ends."
|
|
2089
|
+
});
|
|
1874
2090
|
return {
|
|
2091
|
+
detach: detached,
|
|
1875
2092
|
id: sandboxIdOf(inputs) ?? "",
|
|
1876
2093
|
request: draft
|
|
1877
2094
|
};
|
|
@@ -1879,6 +2096,28 @@ const sandboxesExec = async (context) => {
|
|
|
1879
2096
|
context,
|
|
1880
2097
|
verb: RUN_ACTION
|
|
1881
2098
|
});
|
|
2099
|
+
if (detach) {
|
|
2100
|
+
const started = await callApi({
|
|
2101
|
+
call: {
|
|
2102
|
+
action: START_ACTION,
|
|
2103
|
+
idempotent: false,
|
|
2104
|
+
inspect: inspectArgv(id),
|
|
2105
|
+
key: "required",
|
|
2106
|
+
run: async (client, signal) => await client.sandboxes.execDetached(id, request, { signal }),
|
|
2107
|
+
target: sandboxTarget(id)
|
|
2108
|
+
},
|
|
2109
|
+
context
|
|
2110
|
+
});
|
|
2111
|
+
context.io.receipt({
|
|
2112
|
+
outcome: "Started",
|
|
2113
|
+
rows: [{
|
|
2114
|
+
label: "Started at",
|
|
2115
|
+
value: started.started_at
|
|
2116
|
+
}],
|
|
2117
|
+
target: sandboxTarget(id)
|
|
2118
|
+
});
|
|
2119
|
+
return { document: { exec: started } };
|
|
2120
|
+
}
|
|
1882
2121
|
if (context.mode.format === "human") return {
|
|
1883
2122
|
document: {},
|
|
1884
2123
|
exitCode: await streamed({
|
|
@@ -2189,8 +2428,11 @@ const usageEstimate = async (context) => {
|
|
|
2189
2428
|
// src/cli/handlers.ts
|
|
2190
2429
|
const HANDLERS = /* @__PURE__ */ new Map([
|
|
2191
2430
|
["activity list", activityList],
|
|
2431
|
+
["billing buy-credits", billingBuyCredits],
|
|
2432
|
+
["billing inspect", billingInspect],
|
|
2192
2433
|
["credentials delete", credentialsDelete],
|
|
2193
2434
|
["credentials list", credentialsList],
|
|
2435
|
+
["credentials offer", credentialsOffer],
|
|
2194
2436
|
["credentials set", credentialsSet],
|
|
2195
2437
|
["keys create", keysCreate],
|
|
2196
2438
|
["keys inspect", keysInspect],
|