deepline 0.1.104 → 0.1.106
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/cli/index.js +586 -15
- package/dist/cli/index.mjs +586 -15
- package/dist/index.d.mts +184 -1
- package/dist/index.d.ts +184 -1
- package/dist/index.js +135 -9
- package/dist/index.mjs +135 -9
- package/dist/repo/sdk/src/client.ts +312 -6
- package/dist/repo/sdk/src/http.ts +12 -1
- package/dist/repo/sdk/src/index.ts +6 -0
- package/dist/repo/sdk/src/release.ts +5 -2
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -239,10 +239,13 @@ var SDK_RELEASE = {
|
|
|
239
239
|
// scrubbing, and word-boundary watch truncation.
|
|
240
240
|
// 0.1.103 ships the refined SDK CLI command surface.
|
|
241
241
|
// 0.1.104 ships postgres_fast suspension/billing parity and runtime worker hardening.
|
|
242
|
-
|
|
242
|
+
// 0.1.105 ships the billing catalog surface: billing plans, subscribe,
|
|
243
|
+
// subscription status/cancel, invoices, and the client.billing namespace.
|
|
244
|
+
// 0.1.106 ships play cell provenance metadata and v2 preview retry hardening.
|
|
245
|
+
version: "0.1.106",
|
|
243
246
|
apiContract: "2026-06-dataset-column-cell-stale-hard-cutover",
|
|
244
247
|
supportPolicy: {
|
|
245
|
-
latest: "0.1.
|
|
248
|
+
latest: "0.1.106",
|
|
246
249
|
minimumSupported: "0.1.53",
|
|
247
250
|
deprecatedBelow: "0.1.53"
|
|
248
251
|
}
|
|
@@ -373,7 +376,7 @@ var HttpClient = class {
|
|
|
373
376
|
signal: controller.signal
|
|
374
377
|
});
|
|
375
378
|
clearTimeout(timeoutId);
|
|
376
|
-
if (response.status === 401 || response.status === 403) {
|
|
379
|
+
if (response.status === 401 || response.status === 403 && !options?.forbiddenAsApiError) {
|
|
377
380
|
throw new AuthError();
|
|
378
381
|
}
|
|
379
382
|
if (response.status === 429) {
|
|
@@ -1465,6 +1468,9 @@ var INCLUDE_TOOL_METADATA_HEADER = "x-deepline-include-tool-metadata";
|
|
|
1465
1468
|
var EXECUTE_RESPONSE_CONTRACT_HEADER = "x-deepline-execute-response-contract";
|
|
1466
1469
|
var V2_EXECUTE_RESPONSE_CONTRACT = "v2-tool-response";
|
|
1467
1470
|
var COMPILE_MANIFEST_RETRY_DELAYS_MS = [250, 1e3];
|
|
1471
|
+
var REGISTER_PLAY_ARTIFACTS_COMPILE_CONCURRENCY = 3;
|
|
1472
|
+
var REGISTER_PLAY_ARTIFACTS_MAX_BATCH_COUNT = 3;
|
|
1473
|
+
var REGISTER_PLAY_ARTIFACTS_MAX_BATCH_BYTES = 25e5;
|
|
1468
1474
|
function sleep2(ms) {
|
|
1469
1475
|
return new Promise((resolve16) => setTimeout(resolve16, ms));
|
|
1470
1476
|
}
|
|
@@ -1477,6 +1483,45 @@ function isTransientCompileManifestError(error) {
|
|
|
1477
1483
|
message
|
|
1478
1484
|
);
|
|
1479
1485
|
}
|
|
1486
|
+
async function mapWithConcurrency(items, concurrency, mapper) {
|
|
1487
|
+
const results = new Array(items.length);
|
|
1488
|
+
let nextIndex = 0;
|
|
1489
|
+
const workerCount = Math.min(Math.max(1, concurrency), items.length);
|
|
1490
|
+
await Promise.all(
|
|
1491
|
+
Array.from({ length: workerCount }, async () => {
|
|
1492
|
+
for (; ; ) {
|
|
1493
|
+
const index = nextIndex;
|
|
1494
|
+
nextIndex += 1;
|
|
1495
|
+
if (index >= items.length) {
|
|
1496
|
+
return;
|
|
1497
|
+
}
|
|
1498
|
+
results[index] = await mapper(items[index], index);
|
|
1499
|
+
}
|
|
1500
|
+
})
|
|
1501
|
+
);
|
|
1502
|
+
return results;
|
|
1503
|
+
}
|
|
1504
|
+
function jsonUtf8Bytes(value) {
|
|
1505
|
+
return new TextEncoder().encode(JSON.stringify(value)).length;
|
|
1506
|
+
}
|
|
1507
|
+
function chunkRegisterPlayArtifacts(artifacts) {
|
|
1508
|
+
const chunks = [];
|
|
1509
|
+
let current = [];
|
|
1510
|
+
for (const artifact of artifacts) {
|
|
1511
|
+
const candidate = [...current, artifact];
|
|
1512
|
+
const candidateTooLarge = candidate.length > REGISTER_PLAY_ARTIFACTS_MAX_BATCH_COUNT || jsonUtf8Bytes({ artifacts: candidate }) > REGISTER_PLAY_ARTIFACTS_MAX_BATCH_BYTES;
|
|
1513
|
+
if (current.length > 0 && candidateTooLarge) {
|
|
1514
|
+
chunks.push(current);
|
|
1515
|
+
current = [artifact];
|
|
1516
|
+
} else {
|
|
1517
|
+
current = candidate;
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1520
|
+
if (current.length > 0) {
|
|
1521
|
+
chunks.push(current);
|
|
1522
|
+
}
|
|
1523
|
+
return chunks;
|
|
1524
|
+
}
|
|
1480
1525
|
var RUN_LOGS_PAGE_LIMIT = 1e3;
|
|
1481
1526
|
function isRecord2(value) {
|
|
1482
1527
|
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
@@ -1644,6 +1689,8 @@ var DeeplineClient = class {
|
|
|
1644
1689
|
config;
|
|
1645
1690
|
/** Canonical run lifecycle namespace backed by `/api/v2/runs`. */
|
|
1646
1691
|
runs;
|
|
1692
|
+
/** Billing namespace: subscription status/cancel and invoice history. */
|
|
1693
|
+
billing;
|
|
1647
1694
|
/**
|
|
1648
1695
|
* Create a low-level SDK client.
|
|
1649
1696
|
*
|
|
@@ -1664,6 +1711,16 @@ var DeeplineClient = class {
|
|
|
1664
1711
|
exportDatasetRows: (input2) => this.getPlaySheetRows(input2),
|
|
1665
1712
|
stop: (runId, options2) => this.stopRun(runId, options2)
|
|
1666
1713
|
};
|
|
1714
|
+
this.billing = {
|
|
1715
|
+
plans: () => this.getBillingPlans(),
|
|
1716
|
+
subscription: {
|
|
1717
|
+
status: () => this.getBillingSubscriptionStatus(),
|
|
1718
|
+
cancel: (options2) => this.cancelBillingSubscription(options2)
|
|
1719
|
+
},
|
|
1720
|
+
invoices: {
|
|
1721
|
+
list: (options2) => this.listBillingInvoices(options2)
|
|
1722
|
+
}
|
|
1723
|
+
};
|
|
1667
1724
|
}
|
|
1668
1725
|
/** The resolved base URL this client is targeting (e.g. `"http://localhost:3000"`). */
|
|
1669
1726
|
get baseUrl() {
|
|
@@ -2032,8 +2089,13 @@ var DeeplineClient = class {
|
|
|
2032
2089
|
* first when a compiler manifest is not already supplied.
|
|
2033
2090
|
*/
|
|
2034
2091
|
async registerPlayArtifacts(artifacts) {
|
|
2035
|
-
|
|
2036
|
-
|
|
2092
|
+
if (artifacts.length === 0) {
|
|
2093
|
+
return this.http.post("/api/v2/plays/artifacts", { artifacts });
|
|
2094
|
+
}
|
|
2095
|
+
const compiledArtifacts = await mapWithConcurrency(
|
|
2096
|
+
artifacts,
|
|
2097
|
+
REGISTER_PLAY_ARTIFACTS_COMPILE_CONCURRENCY,
|
|
2098
|
+
async (artifact) => ({
|
|
2037
2099
|
...artifact,
|
|
2038
2100
|
compilerManifest: artifact.compilerManifest ?? await this.compilePlayManifest({
|
|
2039
2101
|
name: artifact.name,
|
|
@@ -2041,11 +2103,20 @@ var DeeplineClient = class {
|
|
|
2041
2103
|
sourceFiles: artifact.sourceFiles,
|
|
2042
2104
|
artifact: artifact.artifact
|
|
2043
2105
|
})
|
|
2044
|
-
})
|
|
2106
|
+
})
|
|
2045
2107
|
);
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2108
|
+
const responses = [];
|
|
2109
|
+
for (const chunk of chunkRegisterPlayArtifacts(compiledArtifacts)) {
|
|
2110
|
+
responses.push(
|
|
2111
|
+
await this.http.post("/api/v2/plays/artifacts", {
|
|
2112
|
+
artifacts: chunk
|
|
2113
|
+
})
|
|
2114
|
+
);
|
|
2115
|
+
}
|
|
2116
|
+
return {
|
|
2117
|
+
success: responses.every((response) => response.success),
|
|
2118
|
+
artifacts: responses.flatMap((response) => response.artifacts)
|
|
2119
|
+
};
|
|
2049
2120
|
}
|
|
2050
2121
|
/**
|
|
2051
2122
|
* Compile a bundled play artifact into the server-side compiler manifest.
|
|
@@ -3018,6 +3089,61 @@ var DeeplineClient = class {
|
|
|
3018
3089
|
// ——————————————————————————————————————————————————————————
|
|
3019
3090
|
// Health
|
|
3020
3091
|
// ——————————————————————————————————————————————————————————
|
|
3092
|
+
/**
|
|
3093
|
+
* Published plans plus the caller's active plan: prices, monthly grant
|
|
3094
|
+
* credits, rollover policy, and which plans are open for subscription.
|
|
3095
|
+
* Prefer `client.billing.plans()`.
|
|
3096
|
+
*
|
|
3097
|
+
* @returns Snake_case catalog from `GET /api/v2/billing/catalog/current`
|
|
3098
|
+
*/
|
|
3099
|
+
async getBillingPlans() {
|
|
3100
|
+
return this.http.get("/api/v2/billing/catalog/current");
|
|
3101
|
+
}
|
|
3102
|
+
/**
|
|
3103
|
+
* Subscription state for the active workspace: active plan, whether a
|
|
3104
|
+
* Stripe subscription backs it, renewal/cancellation facts, and remaining
|
|
3105
|
+
* Deepline credit pools. Prefer `client.billing.subscription.status()`.
|
|
3106
|
+
*
|
|
3107
|
+
* @returns Snake_case subscription status from `GET /api/v2/billing/subscription/status`
|
|
3108
|
+
*/
|
|
3109
|
+
async getBillingSubscriptionStatus() {
|
|
3110
|
+
return this.http.get(
|
|
3111
|
+
"/api/v2/billing/subscription/status"
|
|
3112
|
+
);
|
|
3113
|
+
}
|
|
3114
|
+
/**
|
|
3115
|
+
* Schedule subscription cancellation at period end, or reverse a pending
|
|
3116
|
+
* cancellation with `{ undo: true }`. The customer keeps the cycle they
|
|
3117
|
+
* paid for and every remaining credit — cancellation never claws back
|
|
3118
|
+
* credits. Prefer `client.billing.subscription.cancel(...)`.
|
|
3119
|
+
*
|
|
3120
|
+
* @throws {@link DeeplineError} with `statusCode: 409` when the workspace
|
|
3121
|
+
* has no active subscription, and `statusCode: 502` when Stripe rejects
|
|
3122
|
+
* the update (the server message is preserved).
|
|
3123
|
+
*/
|
|
3124
|
+
async cancelBillingSubscription(options) {
|
|
3125
|
+
return this.http.post(
|
|
3126
|
+
"/api/v2/billing/subscription/cancel",
|
|
3127
|
+
{ action: options?.undo ? "undo_cancel" : "cancel" }
|
|
3128
|
+
);
|
|
3129
|
+
}
|
|
3130
|
+
/**
|
|
3131
|
+
* Customer-facing billing history: subscription invoices plus one-time
|
|
3132
|
+
* credit purchase receipts, newest first, with Stripe-hosted links.
|
|
3133
|
+
* Prefer `client.billing.invoices.list(...)`.
|
|
3134
|
+
*
|
|
3135
|
+
* @param options.limit - Maximum entries to return (server clamps to 1–100, default 24).
|
|
3136
|
+
*/
|
|
3137
|
+
async listBillingInvoices(options) {
|
|
3138
|
+
const params = new URLSearchParams();
|
|
3139
|
+
if (options?.limit !== void 0) {
|
|
3140
|
+
params.set("limit", String(options.limit));
|
|
3141
|
+
}
|
|
3142
|
+
const suffix = Array.from(params).length > 0 ? `?${params.toString()}` : "";
|
|
3143
|
+
return this.http.get(
|
|
3144
|
+
`/api/v2/billing/invoices${suffix}`
|
|
3145
|
+
);
|
|
3146
|
+
}
|
|
3021
3147
|
/**
|
|
3022
3148
|
* Check API connectivity and server health.
|
|
3023
3149
|
*
|
|
@@ -4142,6 +4268,56 @@ var import_commander = require("commander");
|
|
|
4142
4268
|
var import_promises2 = require("fs/promises");
|
|
4143
4269
|
var import_node_path5 = require("path");
|
|
4144
4270
|
var import_sync3 = require("csv-stringify/sync");
|
|
4271
|
+
var SUBSCRIPTION_STATUS_NEXT_COMMAND = "deepline billing subscription status --json";
|
|
4272
|
+
var SUBSCRIPTION_CANCEL_PATH = "/api/v2/billing/subscription/cancel";
|
|
4273
|
+
function billingFailureFromError(error, options) {
|
|
4274
|
+
if (error instanceof AuthError) {
|
|
4275
|
+
return {
|
|
4276
|
+
exitCode: 3,
|
|
4277
|
+
code: "AUTH_ERROR",
|
|
4278
|
+
message: error.message,
|
|
4279
|
+
next: "deepline auth status --json"
|
|
4280
|
+
};
|
|
4281
|
+
}
|
|
4282
|
+
if (!(error instanceof DeeplineError) || typeof error.statusCode !== "number") {
|
|
4283
|
+
return null;
|
|
4284
|
+
}
|
|
4285
|
+
if (error.statusCode === 404 || error.statusCode === 409) {
|
|
4286
|
+
return {
|
|
4287
|
+
exitCode: 4,
|
|
4288
|
+
code: options.notFoundCode,
|
|
4289
|
+
message: error.message,
|
|
4290
|
+
next: SUBSCRIPTION_STATUS_NEXT_COMMAND
|
|
4291
|
+
};
|
|
4292
|
+
}
|
|
4293
|
+
if (error.statusCode >= 500) {
|
|
4294
|
+
return {
|
|
4295
|
+
exitCode: 5,
|
|
4296
|
+
code: "BILLING_SERVER_ERROR",
|
|
4297
|
+
message: error.message,
|
|
4298
|
+
next: SUBSCRIPTION_STATUS_NEXT_COMMAND
|
|
4299
|
+
};
|
|
4300
|
+
}
|
|
4301
|
+
return null;
|
|
4302
|
+
}
|
|
4303
|
+
function reportBillingFailure(failure, options) {
|
|
4304
|
+
const textLines = [failure.message];
|
|
4305
|
+
if (failure.next) {
|
|
4306
|
+
textLines.push(`Next: ${failure.next}`);
|
|
4307
|
+
}
|
|
4308
|
+
printCommandEnvelope(
|
|
4309
|
+
{
|
|
4310
|
+
ok: false,
|
|
4311
|
+
exitCode: failure.exitCode,
|
|
4312
|
+
code: failure.code,
|
|
4313
|
+
message: failure.message,
|
|
4314
|
+
...failure.next ? { next: failure.next } : {}
|
|
4315
|
+
},
|
|
4316
|
+
{ json: options.json, text: `${textLines.join("\n")}
|
|
4317
|
+
` }
|
|
4318
|
+
);
|
|
4319
|
+
process.exitCode = failure.exitCode;
|
|
4320
|
+
}
|
|
4145
4321
|
function humanize(value) {
|
|
4146
4322
|
return String(value || "").split("_").filter(Boolean).map((token) => token[0]?.toUpperCase() + token.slice(1)).join(" ") || "Unknown";
|
|
4147
4323
|
}
|
|
@@ -4417,6 +4593,273 @@ async function handleLedgerExportAll(options) {
|
|
|
4417
4593
|
{ json: options.json }
|
|
4418
4594
|
);
|
|
4419
4595
|
}
|
|
4596
|
+
function planPriceText(priceUsd, priceInterval) {
|
|
4597
|
+
if (priceUsd === null || priceUsd === void 0) {
|
|
4598
|
+
return "no list price";
|
|
4599
|
+
}
|
|
4600
|
+
return `$${priceUsd}${priceInterval ? `/${priceInterval}` : ""}`;
|
|
4601
|
+
}
|
|
4602
|
+
function planRolloverText(rollover) {
|
|
4603
|
+
const mode = rollover?.mode ?? "none";
|
|
4604
|
+
if (mode === "none") return "no rollover";
|
|
4605
|
+
if (mode === "bounded") {
|
|
4606
|
+
return `rollover up to ${rollover?.max_credits ?? "(unknown)"} credits`;
|
|
4607
|
+
}
|
|
4608
|
+
return `rollover ${mode}`;
|
|
4609
|
+
}
|
|
4610
|
+
async function handlePlans(options) {
|
|
4611
|
+
const { http } = getAuthedHttpClient();
|
|
4612
|
+
const payload = await http.get(
|
|
4613
|
+
"/api/v2/billing/catalog/current"
|
|
4614
|
+
);
|
|
4615
|
+
const activePlan = payload.active_plan ?? {};
|
|
4616
|
+
const plans = Array.isArray(payload.plans) ? payload.plans : [];
|
|
4617
|
+
const metrics = Array.isArray(payload.metrics) ? payload.metrics : [];
|
|
4618
|
+
const lines = [
|
|
4619
|
+
`Catalog: ${payload.catalog_id ?? "(unknown)"} (version ${payload.catalog_version ?? "(unknown)"})`,
|
|
4620
|
+
`Active plan: ${activePlan.public_name ?? "(unknown)"} (${activePlan.plan_version_id ?? "(unknown)"})`,
|
|
4621
|
+
`Assigned by: ${activePlan.assigned_by ?? "default"} | subscription: ${activePlan.has_subscription ? "yes" : "no"}`,
|
|
4622
|
+
...plans.length === 0 ? ["Plans: none published"] : [
|
|
4623
|
+
"Plans:",
|
|
4624
|
+
...plans.map(
|
|
4625
|
+
(plan) => `${plan.public_name ?? "(unknown)"} (${plan.plan_version_id ?? "(unknown)"}) | ${planPriceText(plan.price_usd, plan.price_interval)} | ${plan.monthly_grant_credits ?? 0} credits/cycle | ${planRolloverText(plan.rollover)} | ${plan.acquirable ? "acquirable" : "not acquirable"}`
|
|
4626
|
+
)
|
|
4627
|
+
],
|
|
4628
|
+
...metrics.length === 0 ? ["Metrics: none"] : [
|
|
4629
|
+
"Metrics:",
|
|
4630
|
+
...metrics.map(
|
|
4631
|
+
(metric) => `${metric.id ?? "(unknown)"} | ${metric.name ?? "(unknown)"}`
|
|
4632
|
+
)
|
|
4633
|
+
]
|
|
4634
|
+
];
|
|
4635
|
+
printCommandEnvelope(
|
|
4636
|
+
{
|
|
4637
|
+
...payload,
|
|
4638
|
+
render: { sections: [{ title: "billing plans", lines }] }
|
|
4639
|
+
},
|
|
4640
|
+
{ json: options.json }
|
|
4641
|
+
);
|
|
4642
|
+
}
|
|
4643
|
+
async function handleSubscribe(planVersionId, options) {
|
|
4644
|
+
const { http } = getAuthedHttpClient();
|
|
4645
|
+
const payload = await http.request(
|
|
4646
|
+
"/api/v2/billing/subscription/checkout",
|
|
4647
|
+
{
|
|
4648
|
+
method: "POST",
|
|
4649
|
+
body: { plan_version_id: planVersionId },
|
|
4650
|
+
forbiddenAsApiError: true
|
|
4651
|
+
}
|
|
4652
|
+
);
|
|
4653
|
+
const url = String(payload.checkout_url || "");
|
|
4654
|
+
if (!options.json && options.open !== false && url) openInBrowser(url);
|
|
4655
|
+
printCommandEnvelope(
|
|
4656
|
+
{
|
|
4657
|
+
...payload,
|
|
4658
|
+
render: {
|
|
4659
|
+
sections: [
|
|
4660
|
+
{
|
|
4661
|
+
title: "billing subscribe",
|
|
4662
|
+
lines: [url || "Subscription checkout session created."]
|
|
4663
|
+
}
|
|
4664
|
+
]
|
|
4665
|
+
}
|
|
4666
|
+
},
|
|
4667
|
+
{ json: options.json }
|
|
4668
|
+
);
|
|
4669
|
+
}
|
|
4670
|
+
async function handleSubscriptionStatus(options) {
|
|
4671
|
+
const client2 = new DeeplineClient();
|
|
4672
|
+
const payload = await client2.billing.subscription.status();
|
|
4673
|
+
const pools = payload.credit_pools ?? [];
|
|
4674
|
+
const lines = [
|
|
4675
|
+
`Plan: ${payload.plan_name ?? "(unknown)"} (${payload.plan_version_id ?? "(unknown)"})`,
|
|
4676
|
+
`Subscribed: ${payload.subscribed ? "yes" : "no"}`,
|
|
4677
|
+
...payload.cancel_at_period_end ? [
|
|
4678
|
+
`Cancellation scheduled: ends ${payload.current_period_end ?? "(unknown)"} at period end (credits are kept)`
|
|
4679
|
+
] : [],
|
|
4680
|
+
`Price: ${planPriceText(payload.price_usd, payload.price_interval)}`,
|
|
4681
|
+
`Monthly grant: ${payload.monthly_grant_credits ?? 0} credits`,
|
|
4682
|
+
`Pooled credits remaining: ${payload.pooled_credits_remaining ?? 0}`,
|
|
4683
|
+
...pools.length === 0 ? ["Credit pools: none"] : [
|
|
4684
|
+
"Credit pools:",
|
|
4685
|
+
...pools.map(
|
|
4686
|
+
(pool) => `${pool.pool ?? "(unknown)"} | ${pool.credits_remaining ?? 0}/${pool.credits_granted ?? 0} credits remaining | ${pool.source ?? "(unknown)"}`
|
|
4687
|
+
)
|
|
4688
|
+
],
|
|
4689
|
+
`Assigned by: ${payload.assigned_by ?? "default"}`
|
|
4690
|
+
];
|
|
4691
|
+
printCommandEnvelope(
|
|
4692
|
+
{
|
|
4693
|
+
...payload,
|
|
4694
|
+
render: { sections: [{ title: "billing subscription", lines }] }
|
|
4695
|
+
},
|
|
4696
|
+
{ json: options.json }
|
|
4697
|
+
);
|
|
4698
|
+
}
|
|
4699
|
+
async function handleSubscriptionCancel(options) {
|
|
4700
|
+
const client2 = new DeeplineClient();
|
|
4701
|
+
const action = options.undo ? "undo_cancel" : "cancel";
|
|
4702
|
+
if (options.dryRun) {
|
|
4703
|
+
const status = await client2.billing.subscription.status();
|
|
4704
|
+
if (!status.subscribed) {
|
|
4705
|
+
reportBillingFailure(
|
|
4706
|
+
{
|
|
4707
|
+
exitCode: 4,
|
|
4708
|
+
code: "NO_ACTIVE_SUBSCRIPTION",
|
|
4709
|
+
message: "This workspace has no active subscription to cancel.",
|
|
4710
|
+
next: SUBSCRIPTION_STATUS_NEXT_COMMAND
|
|
4711
|
+
},
|
|
4712
|
+
options
|
|
4713
|
+
);
|
|
4714
|
+
return;
|
|
4715
|
+
}
|
|
4716
|
+
const consequence = action === "cancel" ? `Would schedule cancellation at period end${status.current_period_end ? ` (${status.current_period_end})` : ""}. The subscription stays active until then and remaining credits are kept.` : "Would reverse the pending cancellation; the subscription would renew normally.";
|
|
4717
|
+
printCommandEnvelope(
|
|
4718
|
+
{
|
|
4719
|
+
ok: true,
|
|
4720
|
+
dry_run: true,
|
|
4721
|
+
action,
|
|
4722
|
+
plan_version_id: status.plan_version_id,
|
|
4723
|
+
plan_name: status.plan_name,
|
|
4724
|
+
cancel_at_period_end: status.cancel_at_period_end,
|
|
4725
|
+
current_period_end: status.current_period_end,
|
|
4726
|
+
consequence,
|
|
4727
|
+
planned_request: {
|
|
4728
|
+
method: "POST",
|
|
4729
|
+
path: SUBSCRIPTION_CANCEL_PATH,
|
|
4730
|
+
body: { action }
|
|
4731
|
+
},
|
|
4732
|
+
render: {
|
|
4733
|
+
sections: [
|
|
4734
|
+
{
|
|
4735
|
+
title: "billing subscription cancel (dry run)",
|
|
4736
|
+
lines: [
|
|
4737
|
+
`Plan: ${status.plan_name} (${status.plan_version_id})`,
|
|
4738
|
+
`Planned request: POST ${SUBSCRIPTION_CANCEL_PATH} {"action":"${action}"}`,
|
|
4739
|
+
consequence,
|
|
4740
|
+
"No request was sent. Re-run without --dry-run to apply."
|
|
4741
|
+
]
|
|
4742
|
+
}
|
|
4743
|
+
]
|
|
4744
|
+
}
|
|
4745
|
+
},
|
|
4746
|
+
{ json: options.json }
|
|
4747
|
+
);
|
|
4748
|
+
return;
|
|
4749
|
+
}
|
|
4750
|
+
let result;
|
|
4751
|
+
try {
|
|
4752
|
+
result = await client2.billing.subscription.cancel({
|
|
4753
|
+
undo: Boolean(options.undo)
|
|
4754
|
+
});
|
|
4755
|
+
} catch (error) {
|
|
4756
|
+
const failure = billingFailureFromError(error, {
|
|
4757
|
+
notFoundCode: "NO_ACTIVE_SUBSCRIPTION"
|
|
4758
|
+
});
|
|
4759
|
+
if (!failure) throw error;
|
|
4760
|
+
reportBillingFailure(failure, options);
|
|
4761
|
+
return;
|
|
4762
|
+
}
|
|
4763
|
+
const lines = options.undo ? [
|
|
4764
|
+
"Pending cancellation reversed; the subscription will renew normally.",
|
|
4765
|
+
`Subscription: ${result.subscription_id}`
|
|
4766
|
+
] : [
|
|
4767
|
+
`Cancellation scheduled for subscription ${result.subscription_id}.`,
|
|
4768
|
+
`The subscription stays active until ${result.current_period_end ?? "the end of the current billing period"}, then cancels at period end.`,
|
|
4769
|
+
"Remaining credits are yours to keep \u2014 cancellation never removes credits.",
|
|
4770
|
+
"Undo with: deepline billing subscription cancel --undo"
|
|
4771
|
+
];
|
|
4772
|
+
printCommandEnvelope(
|
|
4773
|
+
{
|
|
4774
|
+
ok: true,
|
|
4775
|
+
...result,
|
|
4776
|
+
render: {
|
|
4777
|
+
sections: [{ title: "billing subscription cancel", lines }]
|
|
4778
|
+
}
|
|
4779
|
+
},
|
|
4780
|
+
{ json: options.json }
|
|
4781
|
+
);
|
|
4782
|
+
}
|
|
4783
|
+
function invoiceAmountText(amountCents, currency) {
|
|
4784
|
+
const value = (Number(amountCents ?? 0) / 100).toFixed(2);
|
|
4785
|
+
return String(currency ?? "usd").toLowerCase() === "usd" ? `$${value}` : `${value} ${String(currency).toUpperCase()}`;
|
|
4786
|
+
}
|
|
4787
|
+
function invoiceDateText(createdAt) {
|
|
4788
|
+
return String(createdAt ?? "").slice(0, 10);
|
|
4789
|
+
}
|
|
4790
|
+
function invoiceLine(entry, compact) {
|
|
4791
|
+
const amount = invoiceAmountText(entry.amount_cents, entry.currency);
|
|
4792
|
+
const link = entry.url ?? "(no link)";
|
|
4793
|
+
if (compact) {
|
|
4794
|
+
return [
|
|
4795
|
+
entry.id,
|
|
4796
|
+
invoiceDateText(entry.created_at),
|
|
4797
|
+
amount,
|
|
4798
|
+
entry.status,
|
|
4799
|
+
link
|
|
4800
|
+
].join(" | ");
|
|
4801
|
+
}
|
|
4802
|
+
return [
|
|
4803
|
+
invoiceDateText(entry.created_at),
|
|
4804
|
+
entry.description,
|
|
4805
|
+
amount,
|
|
4806
|
+
entry.status,
|
|
4807
|
+
link
|
|
4808
|
+
].join(" | ");
|
|
4809
|
+
}
|
|
4810
|
+
async function handleInvoices(options) {
|
|
4811
|
+
let limit;
|
|
4812
|
+
if (options.limit !== void 0) {
|
|
4813
|
+
limit = Number.parseInt(options.limit, 10);
|
|
4814
|
+
if (!Number.isInteger(limit) || limit < 1 || limit > 100) {
|
|
4815
|
+
reportBillingFailure(
|
|
4816
|
+
{
|
|
4817
|
+
exitCode: 2,
|
|
4818
|
+
code: "INVALID_LIMIT",
|
|
4819
|
+
message: "--limit must be an integer between 1 and 100."
|
|
4820
|
+
},
|
|
4821
|
+
options
|
|
4822
|
+
);
|
|
4823
|
+
return;
|
|
4824
|
+
}
|
|
4825
|
+
}
|
|
4826
|
+
const client2 = new DeeplineClient();
|
|
4827
|
+
let payload;
|
|
4828
|
+
try {
|
|
4829
|
+
payload = await client2.billing.invoices.list(
|
|
4830
|
+
limit === void 0 ? void 0 : { limit }
|
|
4831
|
+
);
|
|
4832
|
+
} catch (error) {
|
|
4833
|
+
const failure = billingFailureFromError(error, {
|
|
4834
|
+
notFoundCode: "NOT_FOUND"
|
|
4835
|
+
});
|
|
4836
|
+
if (!failure) throw error;
|
|
4837
|
+
reportBillingFailure(failure, options);
|
|
4838
|
+
return;
|
|
4839
|
+
}
|
|
4840
|
+
const entries = Array.isArray(payload.entries) ? payload.entries : [];
|
|
4841
|
+
const compact = Boolean(options.compact);
|
|
4842
|
+
const header = compact ? "id | date | amount | status | link" : "date | description | amount | status | link";
|
|
4843
|
+
const lines = entries.length === 0 ? ["No invoices or receipts yet."] : [header, ...entries.map((entry) => invoiceLine(entry, compact))];
|
|
4844
|
+
const envelope = compact ? {
|
|
4845
|
+
org_id: payload.org_id,
|
|
4846
|
+
count: entries.length,
|
|
4847
|
+
entries: entries.map((entry) => ({
|
|
4848
|
+
id: entry.id,
|
|
4849
|
+
date: invoiceDateText(entry.created_at),
|
|
4850
|
+
amount: invoiceAmountText(entry.amount_cents, entry.currency),
|
|
4851
|
+
status: entry.status,
|
|
4852
|
+
url: entry.url
|
|
4853
|
+
}))
|
|
4854
|
+
} : { ...payload, count: entries.length };
|
|
4855
|
+
printCommandEnvelope(
|
|
4856
|
+
{
|
|
4857
|
+
...envelope,
|
|
4858
|
+
render: { sections: [{ title: "billing invoices", lines }] }
|
|
4859
|
+
},
|
|
4860
|
+
{ json: options.json }
|
|
4861
|
+
);
|
|
4862
|
+
}
|
|
4420
4863
|
async function handleCheckout(options) {
|
|
4421
4864
|
const { http } = getAuthedHttpClient();
|
|
4422
4865
|
const payload = await http.post(
|
|
@@ -4465,19 +4908,33 @@ async function handleRedeemCode(code, options) {
|
|
|
4465
4908
|
);
|
|
4466
4909
|
}
|
|
4467
4910
|
function registerBillingCommands(program) {
|
|
4468
|
-
const billing = program.command("billing").description("
|
|
4911
|
+
const billing = program.command("billing").description("See your plan and credits, buy more, and manage billing.").addHelpText(
|
|
4469
4912
|
"after",
|
|
4470
4913
|
`
|
|
4471
4914
|
Concepts:
|
|
4472
4915
|
Billing commands show Deepline credits, not raw provider spend.
|
|
4473
|
-
|
|
4474
|
-
a browser unless --no-open is set.
|
|
4916
|
+
checkout/subscribe/redeem-code can open a browser unless --no-open is set.
|
|
4475
4917
|
|
|
4476
4918
|
Examples:
|
|
4919
|
+
# See where you stand
|
|
4477
4920
|
deepline billing balance --json
|
|
4478
4921
|
deepline billing usage --limit 20 --json
|
|
4479
|
-
deepline billing
|
|
4922
|
+
deepline billing plans --json
|
|
4923
|
+
deepline billing subscription status --json
|
|
4924
|
+
|
|
4925
|
+
# Buy credits or a plan
|
|
4480
4926
|
deepline billing checkout --credits 1000 --no-open --json
|
|
4927
|
+
deepline billing subscribe runtime-395-2026-07-v1 --no-open --json
|
|
4928
|
+
deepline billing redeem-code --code ABC123 --no-open --json
|
|
4929
|
+
|
|
4930
|
+
# Manage
|
|
4931
|
+
deepline billing subscription cancel --dry-run --json
|
|
4932
|
+
deepline billing set-limit 500 --json
|
|
4933
|
+
|
|
4934
|
+
# Records
|
|
4935
|
+
deepline billing invoices --limit 12 --json
|
|
4936
|
+
deepline billing history --time 1m --json
|
|
4937
|
+
deepline billing ledger export all --json
|
|
4481
4938
|
`
|
|
4482
4939
|
);
|
|
4483
4940
|
billing.command("balance").description("Show current billing balance.").addHelpText(
|
|
@@ -4603,6 +5060,110 @@ Examples:
|
|
|
4603
5060
|
deepline billing checkout --credits 1000 --discount-code LAUNCH --no-open
|
|
4604
5061
|
`
|
|
4605
5062
|
).option("--tier <tierId>", "Named pricing tier").option("--credits <credits>", "Custom credit amount").option("--discount-code <code>", "Apply a discount code").option("--no-open", "Print the checkout URL without opening a browser").option("--json", "Emit JSON output. Also automatic when stdout is piped").action(handleCheckout);
|
|
5063
|
+
billing.command("plans").description("Show published plans and the plan you are on.").addHelpText(
|
|
5064
|
+
"after",
|
|
5065
|
+
`
|
|
5066
|
+
Notes:
|
|
5067
|
+
Read-only. Answers "what plans exist and what am I on": each plan's price,
|
|
5068
|
+
monthly grant credits, rollover policy, and whether it is open for
|
|
5069
|
+
subscription, plus the catalog's usage metrics. All amounts are Deepline
|
|
5070
|
+
credits and Deepline-facing USD, never raw provider spend. Subscribe to a
|
|
5071
|
+
listed plan with: deepline billing subscribe <plan_version_id>
|
|
5072
|
+
|
|
5073
|
+
Examples:
|
|
5074
|
+
deepline billing plans
|
|
5075
|
+
deepline billing plans --json
|
|
5076
|
+
`
|
|
5077
|
+
).option("--json", "Emit JSON output. Also automatic when stdout is piped").action(handlePlans);
|
|
5078
|
+
billing.command("subscribe").description(
|
|
5079
|
+
"Start a subscription checkout for a plan and optionally open it in your browser."
|
|
5080
|
+
).addHelpText(
|
|
5081
|
+
"after",
|
|
5082
|
+
`
|
|
5083
|
+
Notes:
|
|
5084
|
+
Creates a Stripe subscription checkout session for the given plan version.
|
|
5085
|
+
Opens the checkout URL in a browser unless --no-open is set. Fails loudly
|
|
5086
|
+
with the server error when subscription checkout is not enabled or the plan
|
|
5087
|
+
is not open for subscription.
|
|
5088
|
+
|
|
5089
|
+
Examples:
|
|
5090
|
+
deepline billing subscribe runtime-395-2026-07-v1
|
|
5091
|
+
deepline billing subscribe runtime-395-2026-07-v1 --no-open --json
|
|
5092
|
+
`
|
|
5093
|
+
).argument("<plan_version_id>", "Plan version id from `billing plans`").option("--no-open", "Print the checkout URL without opening a browser").option("--json", "Emit JSON output. Also automatic when stdout is piped").action(handleSubscribe);
|
|
5094
|
+
billing.command("subscription").description("Inspect and manage subscription state for the workspace.").addHelpText(
|
|
5095
|
+
"after",
|
|
5096
|
+
`
|
|
5097
|
+
Examples:
|
|
5098
|
+
deepline billing subscription status
|
|
5099
|
+
deepline billing subscription status --json
|
|
5100
|
+
deepline billing subscription cancel --dry-run
|
|
5101
|
+
deepline billing subscription cancel --json
|
|
5102
|
+
deepline billing subscription cancel --undo --json
|
|
5103
|
+
`
|
|
5104
|
+
).addCommand(
|
|
5105
|
+
new import_commander.Command("status").description("Show active plan, subscription state, and credit pools.").addHelpText(
|
|
5106
|
+
"after",
|
|
5107
|
+
`
|
|
5108
|
+
Notes:
|
|
5109
|
+
Read-only. Shows the active plan, whether a Stripe subscription backs it,
|
|
5110
|
+
scheduled cancellation state, and remaining Deepline credits per grant pool.
|
|
5111
|
+
|
|
5112
|
+
Examples:
|
|
5113
|
+
deepline billing subscription status
|
|
5114
|
+
deepline billing subscription status --json
|
|
5115
|
+
`
|
|
5116
|
+
).option(
|
|
5117
|
+
"--json",
|
|
5118
|
+
"Emit JSON output. Also automatic when stdout is piped"
|
|
5119
|
+
).action(handleSubscriptionStatus)
|
|
5120
|
+
).addCommand(
|
|
5121
|
+
new import_commander.Command("cancel").description("Cancel the subscription at period end. Credits are kept.").addHelpText(
|
|
5122
|
+
"after",
|
|
5123
|
+
`
|
|
5124
|
+
Notes:
|
|
5125
|
+
Mutates subscription state. Cancellation is always AT PERIOD END: the
|
|
5126
|
+
subscription stays active until the end of the paid cycle and remaining
|
|
5127
|
+
Deepline credits are kept \u2014 cancellation never removes credits. --undo
|
|
5128
|
+
reverses a pending cancellation before the period ends. --dry-run reads
|
|
5129
|
+
subscription status and prints the planned mutation without calling the
|
|
5130
|
+
cancel endpoint.
|
|
5131
|
+
|
|
5132
|
+
Exit codes:
|
|
5133
|
+
0 cancellation scheduled (or reversed with --undo)
|
|
5134
|
+
3 auth error
|
|
5135
|
+
4 no active subscription to cancel
|
|
5136
|
+
5 Stripe/server failure (the server message is preserved)
|
|
5137
|
+
|
|
5138
|
+
Examples:
|
|
5139
|
+
deepline billing subscription cancel --dry-run
|
|
5140
|
+
deepline billing subscription cancel
|
|
5141
|
+
deepline billing subscription cancel --undo
|
|
5142
|
+
deepline billing subscription cancel --json
|
|
5143
|
+
`
|
|
5144
|
+
).option("--undo", "Reverse a pending cancellation before period end").option(
|
|
5145
|
+
"--dry-run",
|
|
5146
|
+
"Print the planned cancellation without calling the cancel endpoint"
|
|
5147
|
+
).option(
|
|
5148
|
+
"--json",
|
|
5149
|
+
"Emit JSON output. Also automatic when stdout is piped"
|
|
5150
|
+
).action(handleSubscriptionCancel)
|
|
5151
|
+
);
|
|
5152
|
+
billing.command("invoices").description("List subscription invoices and credit purchase receipts.").addHelpText(
|
|
5153
|
+
"after",
|
|
5154
|
+
`
|
|
5155
|
+
Notes:
|
|
5156
|
+
Read-only. Shows customer-facing billing history from Stripe, newest first:
|
|
5157
|
+
subscription invoices plus one-time Deepline credit purchase receipts, with
|
|
5158
|
+
Stripe-hosted links. Amounts are what you paid \u2014 never provider spend.
|
|
5159
|
+
--compact keeps id/date/amount/status/url only.
|
|
5160
|
+
|
|
5161
|
+
Examples:
|
|
5162
|
+
deepline billing invoices
|
|
5163
|
+
deepline billing invoices --limit 12 --json
|
|
5164
|
+
deepline billing invoices --compact --json
|
|
5165
|
+
`
|
|
5166
|
+
).option("--limit <n>", "Maximum entries to return (1-100, default 24)").option("--compact", "Keep only id, date, amount, status, and url").option("--json", "Emit JSON output. Also automatic when stdout is piped").action(handleInvoices);
|
|
4606
5167
|
billing.command("redeem-code").description("Redeem a billing code.").addHelpText(
|
|
4607
5168
|
"after",
|
|
4608
5169
|
`
|
|
@@ -11711,8 +12272,13 @@ function exportableSheetRow(row) {
|
|
|
11711
12272
|
function mergeExportColumns(preferredColumns, rows) {
|
|
11712
12273
|
const columns = [];
|
|
11713
12274
|
const seen = /* @__PURE__ */ new Set();
|
|
12275
|
+
const hasActualColumn = (column) => rows.some((row) => Object.prototype.hasOwnProperty.call(row, column));
|
|
12276
|
+
const hasCanonicalReplacement = (column) => {
|
|
12277
|
+
const canonical = sqlSafeExportColumnName(column);
|
|
12278
|
+
return canonical !== column && hasActualColumn(canonical);
|
|
12279
|
+
};
|
|
11714
12280
|
for (const column of preferredColumns) {
|
|
11715
|
-
if (!column || seen.has(column)) {
|
|
12281
|
+
if (!column || seen.has(column) || hasCanonicalReplacement(column)) {
|
|
11716
12282
|
continue;
|
|
11717
12283
|
}
|
|
11718
12284
|
seen.add(column);
|
|
@@ -11720,7 +12286,7 @@ function mergeExportColumns(preferredColumns, rows) {
|
|
|
11720
12286
|
}
|
|
11721
12287
|
for (const row of rows) {
|
|
11722
12288
|
for (const column of Object.keys(row)) {
|
|
11723
|
-
if (seen.has(column)) {
|
|
12289
|
+
if (seen.has(column) || hasCanonicalReplacement(column)) {
|
|
11724
12290
|
continue;
|
|
11725
12291
|
}
|
|
11726
12292
|
seen.add(column);
|
|
@@ -11729,6 +12295,11 @@ function mergeExportColumns(preferredColumns, rows) {
|
|
|
11729
12295
|
}
|
|
11730
12296
|
return columns;
|
|
11731
12297
|
}
|
|
12298
|
+
function sqlSafeExportColumnName(id) {
|
|
12299
|
+
const normalized = id.trim().replace(/\.+/g, "__").replace(/[^A-Za-z0-9_]+/g, "_").replace(/^_+|_+$/g, "").toLowerCase();
|
|
12300
|
+
const safe = normalized || "column";
|
|
12301
|
+
return /^[A-Za-z_]/.test(safe) ? safe : `c_${safe}`;
|
|
12302
|
+
}
|
|
11732
12303
|
async function fetchBackingDatasetRows(input2) {
|
|
11733
12304
|
const playName = extractRunPlayName(input2.status);
|
|
11734
12305
|
const tableNamespace = input2.rowsInfo.tableNamespace?.trim();
|