@limitry/cli 1.0.0-rc.1 → 1.0.0-rc.10
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/CHANGELOG.md +188 -0
- package/README.md +57 -9
- package/dist/limitry.mjs +822 -585
- package/package.json +5 -4
package/dist/limitry.mjs
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __export = (target, all) => {
|
|
4
|
+
for (var name in all)
|
|
5
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
6
|
+
};
|
|
2
7
|
|
|
3
8
|
// src/main.ts
|
|
4
9
|
import { spawn } from "node:child_process";
|
|
@@ -12,7 +17,20 @@ var brand_default = {
|
|
|
12
17
|
productName: "Limitry",
|
|
13
18
|
legalName: "Omsome L.L.C-FZ",
|
|
14
19
|
releaseMirrors: true,
|
|
20
|
+
mirrorProfile: {
|
|
21
|
+
topics: [
|
|
22
|
+
"rate-limiting",
|
|
23
|
+
"usage-limits",
|
|
24
|
+
"credits",
|
|
25
|
+
"budgets",
|
|
26
|
+
"api-client",
|
|
27
|
+
"sdk"
|
|
28
|
+
]
|
|
29
|
+
},
|
|
15
30
|
domain: "limitry.com",
|
|
31
|
+
devDomain: "limitry.dev",
|
|
32
|
+
labs: ["lab"],
|
|
33
|
+
discordInvite: "https://discord.gg/Nb6QFd6ER4",
|
|
16
34
|
summary: "Limitry is the limits, credits and budgets layer for your software: give each of your users, teams, tenants, API keys or agents an allowance, and before any costly action one call tells your code whether it may happen.",
|
|
17
35
|
expectedAssets: [
|
|
18
36
|
"logo.svg",
|
|
@@ -39,6 +57,16 @@ var brand_default = {
|
|
|
39
57
|
display: "Archivo Variable",
|
|
40
58
|
body: "IBM Plex Sans"
|
|
41
59
|
},
|
|
60
|
+
layout: {
|
|
61
|
+
radius: "3px",
|
|
62
|
+
gutter: "1.5rem",
|
|
63
|
+
contentWidth: "64rem",
|
|
64
|
+
readableWidth: "42rem",
|
|
65
|
+
sectionGap: "2rem",
|
|
66
|
+
navGap: "1.5rem",
|
|
67
|
+
barPadding: "1rem",
|
|
68
|
+
navCurrentWeight: "400"
|
|
69
|
+
},
|
|
42
70
|
environments: [
|
|
43
71
|
{
|
|
44
72
|
name: "test",
|
|
@@ -57,7 +85,8 @@ var brand_default = {
|
|
|
57
85
|
signIn: {
|
|
58
86
|
providerOrder: ["github", "google"],
|
|
59
87
|
emailSignUp: "button"
|
|
60
|
-
}
|
|
88
|
+
},
|
|
89
|
+
devPortOffset: 100
|
|
61
90
|
};
|
|
62
91
|
|
|
63
92
|
// src/brand/index.ts
|
|
@@ -82,13 +111,39 @@ var brand = {
|
|
|
82
111
|
*/
|
|
83
112
|
legalName: optional.legalName ?? brand_default.productName,
|
|
84
113
|
domain: brand_default.domain,
|
|
114
|
+
/**
|
|
115
|
+
* The apex of everything that isn't prod: stage is `*.stage.<devDomain>`
|
|
116
|
+
* (docs/deployment.md "Domains for stage and lab"). `domain` unless
|
|
117
|
+
* brand.json sets one.
|
|
118
|
+
*/
|
|
119
|
+
devDomain: optional.devDomain ?? brand_default.domain,
|
|
120
|
+
/**
|
|
121
|
+
* Where the product's community talks: https://<domain>/discord, the
|
|
122
|
+
* site's redirect to brand.json `discordInvite` (pnpm brand:sync); null
|
|
123
|
+
* when the product has no Discord.
|
|
124
|
+
*/
|
|
125
|
+
discord: optional.discordInvite ? `https://${brand_default.domain}/discord` : null,
|
|
85
126
|
/** One sentence: what the product is — llms.txt and the agent skill lead with it. */
|
|
86
127
|
summary: optional.summary ?? `${brand_default.productName} documentation and API.`,
|
|
87
128
|
/** Where vulnerability reports go — /.well-known/security.txt and /security publish it. Defaults to security@<domain>. */
|
|
88
129
|
securityContact: optional.securityContact ?? `security@${brand_default.domain}`,
|
|
89
130
|
/** The support address the /contact page shows. Defaults to support@<domain>. */
|
|
90
131
|
supportContact: optional.supportContact ?? `support@${brand_default.domain}`,
|
|
132
|
+
/**
|
|
133
|
+
* Where operational alerts go (dead letters, failed crons, unhandled
|
|
134
|
+
* API errors, failed uptime probes — the worker's `sendOpsAlert`).
|
|
135
|
+
* Defaults to ops@<domain>; null when brand.json sets `false` (the
|
|
136
|
+
* platform's own deployment: no customers, alerts only logged).
|
|
137
|
+
*/
|
|
138
|
+
opsContact: optional.opsContact === false ? null : optional.opsContact ?? `ops@${brand_default.domain}`,
|
|
91
139
|
colors: brand_default.colors,
|
|
140
|
+
/**
|
|
141
|
+
* True once the product has launched (brand.json `launched`, set at
|
|
142
|
+
* launch, never back): its data is customers', so the pre-launch
|
|
143
|
+
* product reset's `/ops` route is not mounted at all
|
|
144
|
+
* (docs/deployment.md "Resetting product data"). False when absent.
|
|
145
|
+
*/
|
|
146
|
+
launched: optional.launched === true,
|
|
92
147
|
/** True once the product has its own brand (brand.json `status: "ready"`), not the platform's placeholders. */
|
|
93
148
|
ready: brand_default.status === "ready"
|
|
94
149
|
};
|
|
@@ -673,56 +728,272 @@ function apiErrorFrom(error, response) {
|
|
|
673
728
|
return new ApiError(response.status, envelope.error?.code ?? "http_error", envelope.error?.message ?? `HTTP ${response.status}`, envelope.error?.requestId);
|
|
674
729
|
}
|
|
675
730
|
|
|
731
|
+
// node_modules/@limitry/sdk/dist/product/index.js
|
|
732
|
+
var product_exports = {};
|
|
733
|
+
__export(product_exports, {
|
|
734
|
+
LimitReached: () => LimitReached,
|
|
735
|
+
Unavailable: () => Unavailable,
|
|
736
|
+
createLimits: () => createLimits,
|
|
737
|
+
productMethods: () => productMethods,
|
|
738
|
+
productRetry: () => productRetry
|
|
739
|
+
});
|
|
740
|
+
|
|
741
|
+
// node_modules/@limitry/sdk/dist/retry.js
|
|
742
|
+
var WRITES = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH", "DELETE"]);
|
|
743
|
+
var RETRY_STATUSES = /* @__PURE__ */ new Set([408, 429, 500, 502, 503, 504]);
|
|
744
|
+
var DEFAULT_MAX_RETRIES = 2;
|
|
745
|
+
var MAX_WAIT_MS = 2e4;
|
|
746
|
+
var MAX_BASE_KEY = 200;
|
|
747
|
+
var PRODUCT_RETRY_HEADER = "x-sdk-product-retry";
|
|
748
|
+
var productRetry2 = () => "productRetry" in product_exports ? productRetry ?? null : null;
|
|
749
|
+
var wait = (ms) => new Promise((done) => setTimeout(done, ms));
|
|
750
|
+
function backoff(attempt) {
|
|
751
|
+
const base = Math.min(500 * 2 ** attempt, 8e3);
|
|
752
|
+
return base * (0.75 + Math.random() * 0.25);
|
|
753
|
+
}
|
|
754
|
+
function retryAfter(response) {
|
|
755
|
+
const value = response.headers.get("retry-after");
|
|
756
|
+
if (!value)
|
|
757
|
+
return void 0;
|
|
758
|
+
const seconds = Number(value);
|
|
759
|
+
if (Number.isFinite(seconds))
|
|
760
|
+
return Math.max(0, seconds * 1e3);
|
|
761
|
+
const date = Date.parse(value);
|
|
762
|
+
return Number.isNaN(date) ? void 0 : Math.max(0, date - Date.now());
|
|
763
|
+
}
|
|
764
|
+
async function retryable(response) {
|
|
765
|
+
if (RETRY_STATUSES.has(response.status))
|
|
766
|
+
return true;
|
|
767
|
+
if (response.status !== 409)
|
|
768
|
+
return false;
|
|
769
|
+
try {
|
|
770
|
+
const body = await response.clone().json();
|
|
771
|
+
return body.error?.code === "idempotency_in_progress";
|
|
772
|
+
} catch {
|
|
773
|
+
return false;
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
function takeProductRetryHeader(request) {
|
|
777
|
+
if (!request.headers.has(PRODUCT_RETRY_HEADER))
|
|
778
|
+
return [request, false];
|
|
779
|
+
const returns = request.headers.get(PRODUCT_RETRY_HEADER) === "return";
|
|
780
|
+
const headers = new Headers(request.headers);
|
|
781
|
+
headers.delete(PRODUCT_RETRY_HEADER);
|
|
782
|
+
return [new Request(request, { headers }), returns];
|
|
783
|
+
}
|
|
784
|
+
function withoutProductRetryHeader(fetch2) {
|
|
785
|
+
return (request) => fetch2(takeProductRetryHeader(request)[0]);
|
|
786
|
+
}
|
|
787
|
+
function withRetries(fetch2, options = {}) {
|
|
788
|
+
const maxRetries = options.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
789
|
+
const sleep = options.sleep ?? wait;
|
|
790
|
+
const later = options.product === void 0 ? productRetry2() : options.product;
|
|
791
|
+
return async (request) => {
|
|
792
|
+
let returnLater;
|
|
793
|
+
[request, returnLater] = takeProductRetryHeader(request);
|
|
794
|
+
if (WRITES.has(request.method) && !request.headers.has("idempotency-key")) {
|
|
795
|
+
const url = new URL(request.url);
|
|
796
|
+
const key = options.key ? await options.key(request.method, url.pathname) : crypto.randomUUID();
|
|
797
|
+
const headers = new Headers(request.headers);
|
|
798
|
+
headers.set("idempotency-key", key);
|
|
799
|
+
request = new Request(request, { headers });
|
|
800
|
+
}
|
|
801
|
+
let laterTries = 0;
|
|
802
|
+
let laterWaited = 0;
|
|
803
|
+
for (let attempt = 0; ; attempt++) {
|
|
804
|
+
const last = attempt >= maxRetries;
|
|
805
|
+
const sending = last && !later ? request : request.clone();
|
|
806
|
+
let response;
|
|
807
|
+
try {
|
|
808
|
+
response = await fetch2(sending);
|
|
809
|
+
} catch (error) {
|
|
810
|
+
if (last || request.signal.aborted)
|
|
811
|
+
throw error;
|
|
812
|
+
await sleep(backoff(attempt));
|
|
813
|
+
continue;
|
|
814
|
+
}
|
|
815
|
+
const laterMs = later ? await later.wait(response, laterTries) : null;
|
|
816
|
+
if (laterMs !== null && later) {
|
|
817
|
+
if (returnLater || laterWaited + laterMs > later.budgetMs) {
|
|
818
|
+
return response;
|
|
819
|
+
}
|
|
820
|
+
laterTries++;
|
|
821
|
+
laterWaited += laterMs;
|
|
822
|
+
await response.body?.cancel();
|
|
823
|
+
await sleep(laterMs);
|
|
824
|
+
attempt--;
|
|
825
|
+
continue;
|
|
826
|
+
}
|
|
827
|
+
if (last || !await retryable(response))
|
|
828
|
+
return response;
|
|
829
|
+
const delay = retryAfter(response) ?? backoff(attempt);
|
|
830
|
+
if (delay > MAX_WAIT_MS)
|
|
831
|
+
return response;
|
|
832
|
+
await response.body?.cancel();
|
|
833
|
+
await sleep(delay);
|
|
834
|
+
}
|
|
835
|
+
};
|
|
836
|
+
}
|
|
837
|
+
var hex = (bytes) => Array.from(new Uint8Array(bytes), (b) => b.toString(16).padStart(2, "0")).join("");
|
|
838
|
+
function keysFrom(base) {
|
|
839
|
+
if (base !== void 0 && (base.length === 0 || base.length > MAX_BASE_KEY)) {
|
|
840
|
+
throw new Error(`the idempotency key must be 1\u2013${MAX_BASE_KEY} characters`);
|
|
841
|
+
}
|
|
842
|
+
if (base !== void 0 && !/^[\x21-\x7e]+$/.test(base)) {
|
|
843
|
+
throw new Error("the idempotency key must be printable ASCII with no spaces");
|
|
844
|
+
}
|
|
845
|
+
const seen = /* @__PURE__ */ new Map();
|
|
846
|
+
return async (method, path2) => {
|
|
847
|
+
if (base === void 0)
|
|
848
|
+
return crypto.randomUUID();
|
|
849
|
+
const target = `${method} ${path2}`;
|
|
850
|
+
const n = (seen.get(target) ?? 0) + 1;
|
|
851
|
+
seen.set(target, n);
|
|
852
|
+
const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(`${target}#${n}`));
|
|
853
|
+
return `${base}:${hex(digest).slice(0, 16)}`;
|
|
854
|
+
};
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
// node_modules/@limitry/sdk/dist/product/moving.js
|
|
858
|
+
var MOVING_MS = 3e4;
|
|
859
|
+
var JITTER_BASE_MS = 250;
|
|
860
|
+
var JITTER_CAP_MS = 4e3;
|
|
861
|
+
function retryWaitMs(retryAfterMs2, attempt, random = Math.random) {
|
|
862
|
+
const floor = Math.max(1e3, retryAfterMs2 ?? 1e3);
|
|
863
|
+
const ceiling = Math.min(JITTER_CAP_MS, JITTER_BASE_MS * 2 ** attempt);
|
|
864
|
+
return floor + random() * ceiling;
|
|
865
|
+
}
|
|
866
|
+
async function retryLater(response) {
|
|
867
|
+
if (response.status !== 503)
|
|
868
|
+
return null;
|
|
869
|
+
try {
|
|
870
|
+
const body = await response.clone().json();
|
|
871
|
+
const code2 = body.error?.code;
|
|
872
|
+
return code2 === "moving" || code2 === "busy" ? code2 : null;
|
|
873
|
+
} catch {
|
|
874
|
+
return null;
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
function retryAfter2(response) {
|
|
878
|
+
const value = response.headers.get("retry-after");
|
|
879
|
+
if (!value)
|
|
880
|
+
return void 0;
|
|
881
|
+
const seconds = Number(value);
|
|
882
|
+
if (Number.isFinite(seconds))
|
|
883
|
+
return Math.max(0, seconds * 1e3);
|
|
884
|
+
const date = Date.parse(value);
|
|
885
|
+
return Number.isNaN(date) ? void 0 : Math.max(0, date - Date.now());
|
|
886
|
+
}
|
|
887
|
+
function movingRetry(random = Math.random) {
|
|
888
|
+
return {
|
|
889
|
+
wait: async (response, tries) => await retryLater(response) ? retryWaitMs(retryAfter2(response), tries, random) : null,
|
|
890
|
+
budgetMs: MOVING_MS
|
|
891
|
+
};
|
|
892
|
+
}
|
|
893
|
+
|
|
676
894
|
// node_modules/@limitry/sdk/dist/product/limits.js
|
|
677
|
-
var
|
|
895
|
+
var MAX_COST = 1e9;
|
|
896
|
+
function checkedCost(units) {
|
|
897
|
+
if (!Number.isInteger(units) || units < 0 || units > MAX_COST) {
|
|
898
|
+
throw new RangeError(`reservation.cost(${units}): the cost must be a whole number from 0 to ${MAX_COST}`);
|
|
899
|
+
}
|
|
900
|
+
return units;
|
|
901
|
+
}
|
|
902
|
+
var LimitReached = class extends Error {
|
|
678
903
|
reason;
|
|
679
|
-
/** The limit that refused; null
|
|
680
|
-
|
|
904
|
+
/** The limit that refused; null for too many open reservations. */
|
|
905
|
+
limitId;
|
|
681
906
|
retryAfterSeconds;
|
|
682
907
|
decision;
|
|
683
908
|
constructor(decision) {
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
this.
|
|
687
|
-
this.
|
|
688
|
-
this.
|
|
689
|
-
this.retryAfterSeconds = decision?.retryAfterSeconds ?? null;
|
|
909
|
+
super(decision.reason?.message ?? "Refused");
|
|
910
|
+
this.name = "LimitReached";
|
|
911
|
+
this.reason = decision.reason?.code ?? "limit_reached";
|
|
912
|
+
this.limitId = decision.reason?.limitId ?? null;
|
|
913
|
+
this.retryAfterSeconds = decision.retryAfterSeconds ?? null;
|
|
690
914
|
this.decision = decision;
|
|
691
915
|
}
|
|
692
916
|
};
|
|
917
|
+
var Unavailable = class extends Error {
|
|
918
|
+
constructor() {
|
|
919
|
+
super("Limitry could not be reached and a limit refuses when unreachable");
|
|
920
|
+
this.name = "Unavailable";
|
|
921
|
+
}
|
|
922
|
+
};
|
|
693
923
|
var UNREACHABLE = /* @__PURE__ */ Symbol("unreachable");
|
|
694
924
|
var TIMED_OUT = /* @__PURE__ */ Symbol("timed out");
|
|
695
|
-
var
|
|
696
|
-
|
|
925
|
+
var FINISH_TIMEOUT_MS = 5e3;
|
|
926
|
+
var wait2 = (ms) => new Promise((done) => setTimeout(done, ms));
|
|
927
|
+
function retryAfterMs(response) {
|
|
928
|
+
const value = response.headers.get("retry-after");
|
|
929
|
+
const seconds = value === null ? NaN : Number(value);
|
|
930
|
+
return Number.isFinite(seconds) ? seconds * 1e3 : void 0;
|
|
931
|
+
}
|
|
932
|
+
function createLimits(client, options = {}, internals = {}) {
|
|
697
933
|
const timeoutMs = options.timeoutMs ?? 1500;
|
|
934
|
+
const sleep = internals.sleep ?? wait2;
|
|
935
|
+
const random = internals.random ?? Math.random;
|
|
698
936
|
const remembered = /* @__PURE__ */ new Map();
|
|
699
937
|
const key = (s, action) => `${s.kind}\0${s.id}\0${action}`;
|
|
700
938
|
const failMode = (s, action) => options.failMode ?? remembered.get(key(s, action)) ?? "open";
|
|
701
939
|
const remember = (s, action, decision) => {
|
|
702
940
|
if (options.failMode)
|
|
703
941
|
return;
|
|
704
|
-
const closed = decision.
|
|
942
|
+
const closed = decision.limits.some((r) => r.failMode === "closed");
|
|
705
943
|
remembered.set(key(s, action), closed ? "closed" : "open");
|
|
706
944
|
if (remembered.size > 1e4) {
|
|
707
945
|
remembered.delete(remembered.keys().next().value);
|
|
708
946
|
}
|
|
709
947
|
};
|
|
710
|
-
|
|
948
|
+
function budget(budgetMs) {
|
|
949
|
+
const started = Date.now();
|
|
950
|
+
let slept = 0;
|
|
951
|
+
return {
|
|
952
|
+
// Whole ms: AbortSignal.timeout refuses a fraction (jitter makes them).
|
|
953
|
+
left: () => Math.ceil(budgetMs - Math.max(Date.now() - started, slept)),
|
|
954
|
+
async sleep(ms) {
|
|
955
|
+
slept += ms;
|
|
956
|
+
await sleep(ms);
|
|
957
|
+
}
|
|
958
|
+
};
|
|
959
|
+
}
|
|
960
|
+
async function check(body, idempotencyKey, budgetMs = timeoutMs, finishOnly = false) {
|
|
961
|
+
const time = budget(budgetMs);
|
|
962
|
+
for (let tries = 0; ; tries++) {
|
|
963
|
+
const answer2 = await checkOnce(body, idempotencyKey, Math.max(1, time.left()), finishOnly);
|
|
964
|
+
if (answer2.kind !== "later")
|
|
965
|
+
return answer2.value;
|
|
966
|
+
const pause = retryWaitMs(answer2.retryAfterMs, tries, random);
|
|
967
|
+
if (pause >= time.left())
|
|
968
|
+
return UNREACHABLE;
|
|
969
|
+
await time.sleep(pause);
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
async function checkOnce(body, idempotencyKey, wait3, finishOnly) {
|
|
711
973
|
let timer;
|
|
712
974
|
const late = new Promise((resolve2) => {
|
|
713
|
-
timer = setTimeout(() => resolve2(TIMED_OUT),
|
|
975
|
+
timer = setTimeout(() => resolve2(TIMED_OUT), wait3);
|
|
714
976
|
});
|
|
715
977
|
const asked = (async () => {
|
|
716
978
|
try {
|
|
717
979
|
const { data, error, response } = await client.POST("/checks", {
|
|
718
980
|
body,
|
|
719
|
-
headers: {
|
|
720
|
-
|
|
981
|
+
headers: {
|
|
982
|
+
"idempotency-key": idempotencyKey,
|
|
983
|
+
// `moving` and `busy` come back here at once: this loop
|
|
984
|
+
// retries them.
|
|
985
|
+
[PRODUCT_RETRY_HEADER]: "return",
|
|
986
|
+
...finishOnly ? { "limitry-finish-only": "1" } : {}
|
|
987
|
+
},
|
|
988
|
+
signal: AbortSignal.timeout(wait3)
|
|
721
989
|
});
|
|
722
990
|
if (data)
|
|
723
991
|
return data;
|
|
724
|
-
if (response
|
|
992
|
+
if (isRetryLater(response, error))
|
|
993
|
+
return { later: retryAfterMs(response) };
|
|
994
|
+
if (response.status === 402 || response.status === 429) {
|
|
725
995
|
return UNREACHABLE;
|
|
996
|
+
}
|
|
726
997
|
if (response.status < 500 && error) {
|
|
727
998
|
return new Error(`Limitry refused the check (${response.status}): ${JSON.stringify(error)}`);
|
|
728
999
|
}
|
|
@@ -735,30 +1006,44 @@ function createLimits(client, options = {}) {
|
|
|
735
1006
|
const answer2 = await Promise.race([asked, late]);
|
|
736
1007
|
if (answer2 instanceof Error)
|
|
737
1008
|
throw answer2;
|
|
738
|
-
|
|
1009
|
+
if (typeof answer2 === "object" && "later" in answer2)
|
|
1010
|
+
return { kind: "later", retryAfterMs: answer2.later };
|
|
1011
|
+
return { kind: "answer", value: answer2 };
|
|
739
1012
|
} finally {
|
|
740
1013
|
clearTimeout(timer);
|
|
741
1014
|
}
|
|
742
1015
|
}
|
|
743
1016
|
async function settle(id, action, cost) {
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
1017
|
+
const idempotencyKey = crypto.randomUUID();
|
|
1018
|
+
const time = budget(timeoutMs);
|
|
1019
|
+
for (let tries = 0; ; tries++) {
|
|
1020
|
+
let retryMs = null;
|
|
1021
|
+
try {
|
|
1022
|
+
const headers = {
|
|
1023
|
+
"idempotency-key": idempotencyKey,
|
|
1024
|
+
[PRODUCT_RETRY_HEADER]: "return"
|
|
1025
|
+
};
|
|
1026
|
+
const { error, response } = action === "commit" ? await client.POST("/reservations/{reservationId}/commit", {
|
|
747
1027
|
params: { path: { reservationId: id } },
|
|
748
1028
|
body: { cost: cost ?? 0 },
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
await client.POST("/reservations/{reservationId}/release", {
|
|
1029
|
+
headers,
|
|
1030
|
+
signal: AbortSignal.timeout(Math.max(1, time.left()))
|
|
1031
|
+
}) : await client.POST("/reservations/{reservationId}/release", {
|
|
753
1032
|
params: { path: { reservationId: id } },
|
|
754
|
-
|
|
1033
|
+
headers,
|
|
1034
|
+
signal: AbortSignal.timeout(Math.max(1, time.left()))
|
|
755
1035
|
});
|
|
1036
|
+
if (isRetryLater(response, error))
|
|
1037
|
+
retryMs = retryWaitMs(retryAfterMs(response), tries, random);
|
|
1038
|
+
} catch {
|
|
756
1039
|
}
|
|
757
|
-
|
|
1040
|
+
if (retryMs === null || retryMs >= time.left())
|
|
1041
|
+
return;
|
|
1042
|
+
await time.sleep(retryMs);
|
|
758
1043
|
}
|
|
759
1044
|
}
|
|
760
1045
|
async function releaseUnheard(body, idempotencyKey) {
|
|
761
|
-
const replay = await check(body, idempotencyKey
|
|
1046
|
+
const replay = await check(body, idempotencyKey);
|
|
762
1047
|
if (typeof replay === "object" && replay.reservation) {
|
|
763
1048
|
await settle(replay.reservation.id, "release");
|
|
764
1049
|
}
|
|
@@ -775,8 +1060,7 @@ function createLimits(client, options = {}) {
|
|
|
775
1060
|
const { data, error, response } = await client.GET("/usage/standing", {
|
|
776
1061
|
params: {
|
|
777
1062
|
query: {
|
|
778
|
-
|
|
779
|
-
id: request.subject.id,
|
|
1063
|
+
subject: `${request.subject.kind}:${request.subject.id}`,
|
|
780
1064
|
...request.shared?.length ? {
|
|
781
1065
|
shared: request.shared.map((s) => `${s.kind}:${s.id}`).join(",")
|
|
782
1066
|
} : {}
|
|
@@ -789,49 +1073,59 @@ function createLimits(client, options = {}) {
|
|
|
789
1073
|
},
|
|
790
1074
|
/** Checks `cost`, runs `fn` only if allowed, and returns its result. */
|
|
791
1075
|
async guard(request, fn) {
|
|
792
|
-
const
|
|
1076
|
+
const body = {
|
|
793
1077
|
subject: request.subject,
|
|
794
1078
|
shared: request.shared,
|
|
795
1079
|
action: request.action,
|
|
796
1080
|
cost: request.cost ?? 1
|
|
797
|
-
}
|
|
1081
|
+
};
|
|
1082
|
+
const idempotencyKey = crypto.randomUUID();
|
|
1083
|
+
const decision = await check(body, idempotencyKey);
|
|
798
1084
|
if (decision === UNREACHABLE || decision === TIMED_OUT) {
|
|
799
1085
|
if (failMode(request.subject, request.action) === "closed") {
|
|
800
|
-
throw new
|
|
1086
|
+
throw new Unavailable();
|
|
1087
|
+
}
|
|
1088
|
+
if (decision === TIMED_OUT) {
|
|
1089
|
+
void check(body, idempotencyKey, FINISH_TIMEOUT_MS, true).catch(() => {
|
|
1090
|
+
});
|
|
801
1091
|
}
|
|
802
1092
|
return fn();
|
|
803
1093
|
}
|
|
804
1094
|
remember(request.subject, request.action, decision);
|
|
805
1095
|
if (!decision.allowed)
|
|
806
|
-
throw new
|
|
1096
|
+
throw new LimitReached(decision);
|
|
807
1097
|
return fn();
|
|
808
1098
|
},
|
|
809
1099
|
/**
|
|
810
|
-
*
|
|
811
|
-
* (`
|
|
812
|
-
* `fn` throws, and rethrows. A concurrent limit's slot
|
|
813
|
-
* exactly as long as `fn` runs.
|
|
1100
|
+
* Reserves `cost`, runs `fn`, then commits the cost it reported
|
|
1101
|
+
* (`reservation.cost(n)`, default the reserved cost) — or releases the
|
|
1102
|
+
* reservation if `fn` throws, and rethrows. A concurrent limit's slot
|
|
1103
|
+
* is taken for exactly as long as `fn` runs.
|
|
814
1104
|
*/
|
|
815
|
-
async
|
|
816
|
-
const
|
|
1105
|
+
async reserve(request, fn) {
|
|
1106
|
+
const reserved = request.cost ?? 1;
|
|
817
1107
|
const body = {
|
|
818
1108
|
subject: request.subject,
|
|
819
1109
|
shared: request.shared,
|
|
820
1110
|
action: request.action,
|
|
821
|
-
cost:
|
|
1111
|
+
cost: reserved,
|
|
822
1112
|
mode: "reserve",
|
|
823
1113
|
ttlSeconds: request.ttlSeconds
|
|
824
1114
|
};
|
|
825
1115
|
const idempotencyKey = crypto.randomUUID();
|
|
826
1116
|
const decision = await check(body, idempotencyKey);
|
|
827
|
-
const unmetered = {
|
|
828
|
-
|
|
829
|
-
|
|
1117
|
+
const unmetered = {
|
|
1118
|
+
// Checked even unmetered: the mistake shows whether or not
|
|
1119
|
+
// Limitry answered.
|
|
1120
|
+
cost: (units) => void checkedCost(units),
|
|
1121
|
+
extend: async () => {
|
|
1122
|
+
}
|
|
1123
|
+
};
|
|
830
1124
|
if (decision === UNREACHABLE || decision === TIMED_OUT) {
|
|
831
1125
|
const unheard = () => decision === TIMED_OUT ? releaseUnheard(body, idempotencyKey) : Promise.resolve();
|
|
832
1126
|
if (failMode(request.subject, request.action) === "closed") {
|
|
833
1127
|
await unheard();
|
|
834
|
-
throw new
|
|
1128
|
+
throw new Unavailable();
|
|
835
1129
|
}
|
|
836
1130
|
try {
|
|
837
1131
|
return await fn(unmetered);
|
|
@@ -841,25 +1135,27 @@ function createLimits(client, options = {}) {
|
|
|
841
1135
|
}
|
|
842
1136
|
remember(request.subject, request.action, decision);
|
|
843
1137
|
if (!decision.allowed || !decision.reservation) {
|
|
844
|
-
throw new
|
|
1138
|
+
throw new LimitReached(decision);
|
|
845
1139
|
}
|
|
846
1140
|
const id = decision.reservation.id;
|
|
847
|
-
let used =
|
|
848
|
-
const
|
|
1141
|
+
let used = reserved;
|
|
1142
|
+
const reservation = {
|
|
849
1143
|
cost(units) {
|
|
850
|
-
used = units;
|
|
1144
|
+
used = checkedCost(units);
|
|
851
1145
|
},
|
|
852
1146
|
async extend(ttlSeconds) {
|
|
853
|
-
await client.POST("/reservations/{reservationId}/extend", {
|
|
1147
|
+
const { error, response } = await client.POST("/reservations/{reservationId}/extend", {
|
|
854
1148
|
params: { path: { reservationId: id } },
|
|
855
|
-
body: ttlSeconds ? {
|
|
1149
|
+
body: ttlSeconds === void 0 ? {} : { ttlSeconds },
|
|
856
1150
|
signal: AbortSignal.timeout(timeoutMs)
|
|
857
1151
|
});
|
|
1152
|
+
if (error !== void 0)
|
|
1153
|
+
throw apiErrorFrom(error, response);
|
|
858
1154
|
}
|
|
859
1155
|
};
|
|
860
1156
|
let result;
|
|
861
1157
|
try {
|
|
862
|
-
result = await fn(
|
|
1158
|
+
result = await fn(reservation);
|
|
863
1159
|
} catch (error) {
|
|
864
1160
|
await settle(id, "release");
|
|
865
1161
|
throw error;
|
|
@@ -869,12 +1165,21 @@ function createLimits(client, options = {}) {
|
|
|
869
1165
|
}
|
|
870
1166
|
};
|
|
871
1167
|
}
|
|
1168
|
+
function isRetryLater(response, error) {
|
|
1169
|
+
const code2 = error?.error?.code;
|
|
1170
|
+
return response.status === 503 && (code2 === "moving" || code2 === "busy");
|
|
1171
|
+
}
|
|
872
1172
|
|
|
873
1173
|
// node_modules/@limitry/sdk/dist/product/index.js
|
|
874
1174
|
var productMethods = (client) => {
|
|
875
1175
|
const limits = createLimits(client);
|
|
876
|
-
return {
|
|
1176
|
+
return {
|
|
1177
|
+
guard: limits.guard,
|
|
1178
|
+
reserve: limits.reserve,
|
|
1179
|
+
standing: limits.standing
|
|
1180
|
+
};
|
|
877
1181
|
};
|
|
1182
|
+
var productRetry = movingRetry();
|
|
878
1183
|
|
|
879
1184
|
// node_modules/@limitry/sdk/dist/resources.js
|
|
880
1185
|
async function call(client, op, pathParams, input, options = {}, content) {
|
|
@@ -925,20 +1230,20 @@ function resources(client) {
|
|
|
925
1230
|
/** Create a limit */
|
|
926
1231
|
(input, options) => call(client, { "method": "post", "path": "/limits", "query": [], "hasBody": true }, {}, input, options)
|
|
927
1232
|
),
|
|
928
|
-
|
|
929
|
-
/** Get a limit */
|
|
930
|
-
(limitId, options) => call(client, { "method": "get", "path": "/limits/{limitId}", "query": [], "hasBody": false }, { "limitId": limitId }, void 0, options)
|
|
931
|
-
),
|
|
932
|
-
grants: {
|
|
1233
|
+
credits: {
|
|
933
1234
|
create: (
|
|
934
1235
|
/** Add credits to a balance */
|
|
935
|
-
(limitId, input, options) => call(client, { "method": "post", "path": "/limits/{limitId}/
|
|
1236
|
+
(limitId, input, options) => call(client, { "method": "post", "path": "/limits/{limitId}/credits", "query": [], "hasBody": true }, { "limitId": limitId }, input, options)
|
|
936
1237
|
),
|
|
937
1238
|
list: (
|
|
938
|
-
/** List a balance's
|
|
939
|
-
(limitId, options) => call(client, { "method": "get", "path": "/limits/{limitId}/
|
|
1239
|
+
/** List a balance's credits */
|
|
1240
|
+
(limitId, options) => call(client, { "method": "get", "path": "/limits/{limitId}/credits", "query": [], "hasBody": false }, { "limitId": limitId }, void 0, options)
|
|
940
1241
|
)
|
|
941
1242
|
},
|
|
1243
|
+
get: (
|
|
1244
|
+
/** Get a limit */
|
|
1245
|
+
(limitId, options) => call(client, { "method": "get", "path": "/limits/{limitId}", "query": [], "hasBody": false }, { "limitId": limitId }, void 0, options)
|
|
1246
|
+
),
|
|
942
1247
|
list: (
|
|
943
1248
|
/** List limits */
|
|
944
1249
|
(input, options) => call(client, { "method": "get", "path": "/limits", "query": ["limit", "cursor", "subjectKind", "action", "archived"], "hasBody": false }, {}, input, options)
|
|
@@ -980,18 +1285,18 @@ function resources(client) {
|
|
|
980
1285
|
(subjectKind, subjectId, input, options) => call(client, { "method": "post", "path": "/subjects/{subjectKind}/{subjectId}/reset", "query": [], "hasBody": true }, { "subjectKind": subjectKind, "subjectId": subjectId }, input, options)
|
|
981
1286
|
),
|
|
982
1287
|
update: (
|
|
983
|
-
/** Set a subject's
|
|
1288
|
+
/** Set a subject's billing date */
|
|
984
1289
|
(subjectKind, subjectId, input, options) => call(client, { "method": "patch", "path": "/subjects/{subjectKind}/{subjectId}", "query": [], "hasBody": true }, { "subjectKind": subjectKind, "subjectId": subjectId }, input, options)
|
|
985
1290
|
)
|
|
986
1291
|
},
|
|
987
1292
|
usage: {
|
|
988
1293
|
query: (
|
|
989
1294
|
/** Get a limit's usage over time */
|
|
990
|
-
(input, options) => call(client, { "method": "get", "path": "/usage", "query": ["limitId", "
|
|
1295
|
+
(input, options) => call(client, { "method": "get", "path": "/usage", "query": ["limitId", "subject", "from", "to", "granularity"], "hasBody": false }, {}, input, options)
|
|
991
1296
|
),
|
|
992
1297
|
standing: (
|
|
993
1298
|
/** Get where a subject stands */
|
|
994
|
-
(input, options) => call(client, { "method": "get", "path": "/usage/standing", "query": ["
|
|
1299
|
+
(input, options) => call(client, { "method": "get", "path": "/usage/standing", "query": ["subject", "shared"], "hasBody": false }, {}, input, options)
|
|
995
1300
|
),
|
|
996
1301
|
subjects: (
|
|
997
1302
|
/** List who is using a limit now */
|
|
@@ -1101,98 +1406,16 @@ function resources(client) {
|
|
|
1101
1406
|
test: (
|
|
1102
1407
|
/** Send a test event */
|
|
1103
1408
|
(endpointId, options) => call(client, { "method": "post", "path": "/workspace/webhook-endpoints/{endpointId}/test", "query": [], "hasBody": false }, { "endpointId": endpointId }, void 0, options)
|
|
1409
|
+
),
|
|
1410
|
+
update: (
|
|
1411
|
+
/** Update a webhook endpoint */
|
|
1412
|
+
(endpointId, input, options) => call(client, { "method": "patch", "path": "/workspace/webhook-endpoints/{endpointId}", "query": [], "hasBody": true }, { "endpointId": endpointId }, input, options)
|
|
1104
1413
|
)
|
|
1105
1414
|
}
|
|
1106
1415
|
}
|
|
1107
1416
|
};
|
|
1108
1417
|
}
|
|
1109
1418
|
|
|
1110
|
-
// node_modules/@limitry/sdk/dist/retry.js
|
|
1111
|
-
var WRITES = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH", "DELETE"]);
|
|
1112
|
-
var RETRY_STATUSES = /* @__PURE__ */ new Set([408, 429, 500, 502, 503, 504]);
|
|
1113
|
-
var DEFAULT_MAX_RETRIES = 2;
|
|
1114
|
-
var MAX_WAIT_MS = 2e4;
|
|
1115
|
-
var MAX_BASE_KEY = 200;
|
|
1116
|
-
var wait = (ms) => new Promise((done) => setTimeout(done, ms));
|
|
1117
|
-
function backoff(attempt) {
|
|
1118
|
-
const base = Math.min(500 * 2 ** attempt, 8e3);
|
|
1119
|
-
return base * (0.75 + Math.random() * 0.25);
|
|
1120
|
-
}
|
|
1121
|
-
function retryAfter(response) {
|
|
1122
|
-
const value = response.headers.get("retry-after");
|
|
1123
|
-
if (!value)
|
|
1124
|
-
return void 0;
|
|
1125
|
-
const seconds = Number(value);
|
|
1126
|
-
if (Number.isFinite(seconds))
|
|
1127
|
-
return Math.max(0, seconds * 1e3);
|
|
1128
|
-
const date = Date.parse(value);
|
|
1129
|
-
return Number.isNaN(date) ? void 0 : Math.max(0, date - Date.now());
|
|
1130
|
-
}
|
|
1131
|
-
async function retryable(response) {
|
|
1132
|
-
if (RETRY_STATUSES.has(response.status))
|
|
1133
|
-
return true;
|
|
1134
|
-
if (response.status !== 409)
|
|
1135
|
-
return false;
|
|
1136
|
-
try {
|
|
1137
|
-
const body = await response.clone().json();
|
|
1138
|
-
return body.error?.code === "idempotency_in_progress";
|
|
1139
|
-
} catch {
|
|
1140
|
-
return false;
|
|
1141
|
-
}
|
|
1142
|
-
}
|
|
1143
|
-
function withRetries(fetch2, options = {}) {
|
|
1144
|
-
const maxRetries = options.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
1145
|
-
const sleep = options.sleep ?? wait;
|
|
1146
|
-
return async (request) => {
|
|
1147
|
-
if (WRITES.has(request.method) && !request.headers.has("idempotency-key")) {
|
|
1148
|
-
const url = new URL(request.url);
|
|
1149
|
-
const key = options.key ? await options.key(request.method, url.pathname) : crypto.randomUUID();
|
|
1150
|
-
const headers = new Headers(request.headers);
|
|
1151
|
-
headers.set("idempotency-key", key);
|
|
1152
|
-
request = new Request(request, { headers });
|
|
1153
|
-
}
|
|
1154
|
-
for (let attempt = 0; ; attempt++) {
|
|
1155
|
-
const last = attempt >= maxRetries;
|
|
1156
|
-
const sending = last ? request : request.clone();
|
|
1157
|
-
let response;
|
|
1158
|
-
try {
|
|
1159
|
-
response = await fetch2(sending);
|
|
1160
|
-
} catch (error) {
|
|
1161
|
-
if (last || request.signal.aborted)
|
|
1162
|
-
throw error;
|
|
1163
|
-
await sleep(backoff(attempt));
|
|
1164
|
-
continue;
|
|
1165
|
-
}
|
|
1166
|
-
if (last || !await retryable(response))
|
|
1167
|
-
return response;
|
|
1168
|
-
const delay = retryAfter(response) ?? backoff(attempt);
|
|
1169
|
-
if (delay > MAX_WAIT_MS)
|
|
1170
|
-
return response;
|
|
1171
|
-
await response.body?.cancel();
|
|
1172
|
-
await sleep(delay);
|
|
1173
|
-
}
|
|
1174
|
-
};
|
|
1175
|
-
}
|
|
1176
|
-
var hex = (bytes) => Array.from(new Uint8Array(bytes), (b) => b.toString(16).padStart(2, "0")).join("");
|
|
1177
|
-
function keysFrom(base) {
|
|
1178
|
-
if (base !== void 0 && (base.length === 0 || base.length > MAX_BASE_KEY)) {
|
|
1179
|
-
throw new Error(`the idempotency key must be 1\u2013${MAX_BASE_KEY} characters`);
|
|
1180
|
-
}
|
|
1181
|
-
if (base !== void 0 && !/^[\x21-\x7e]+$/.test(base)) {
|
|
1182
|
-
throw new Error("the idempotency key must be printable ASCII with no spaces");
|
|
1183
|
-
}
|
|
1184
|
-
const seen = /* @__PURE__ */ new Map();
|
|
1185
|
-
return async (method, path2) => {
|
|
1186
|
-
if (base === void 0)
|
|
1187
|
-
return crypto.randomUUID();
|
|
1188
|
-
const target = `${method} ${path2}`;
|
|
1189
|
-
const n = (seen.get(target) ?? 0) + 1;
|
|
1190
|
-
seen.set(target, n);
|
|
1191
|
-
const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(`${target}#${n}`));
|
|
1192
|
-
return `${base}:${hex(digest).slice(0, 16)}`;
|
|
1193
|
-
};
|
|
1194
|
-
}
|
|
1195
|
-
|
|
1196
1419
|
// node_modules/@limitry/sdk/dist/webhooks.js
|
|
1197
1420
|
var WebhookVerificationError = class extends Error {
|
|
1198
1421
|
constructor(message) {
|
|
@@ -1283,11 +1506,11 @@ function createBaseClient(options) {
|
|
|
1283
1506
|
if (!token) {
|
|
1284
1507
|
throw new Error(`${brand2.productName}: no API key. Pass { token } or set ${API_KEY_ENV}.`);
|
|
1285
1508
|
}
|
|
1286
|
-
const origin = (options.api ?? DEFAULT_API)
|
|
1509
|
+
const origin = withoutTrailingSlashes(options.api ?? DEFAULT_API);
|
|
1287
1510
|
const send = options.fetch ?? ((request) => fetch(request));
|
|
1288
1511
|
const client = createClient({
|
|
1289
1512
|
baseUrl: `${origin}/v1`,
|
|
1290
|
-
fetch: options.maxRetries === 0 ? send : withRetries(send, { maxRetries: options.maxRetries })
|
|
1513
|
+
fetch: options.maxRetries === 0 ? withoutProductRetryHeader(send) : withRetries(send, { maxRetries: options.maxRetries })
|
|
1291
1514
|
});
|
|
1292
1515
|
client.use({
|
|
1293
1516
|
onRequest({ request }) {
|
|
@@ -1315,6 +1538,12 @@ function unwrap(result) {
|
|
|
1315
1538
|
}
|
|
1316
1539
|
return result.data;
|
|
1317
1540
|
}
|
|
1541
|
+
function withoutTrailingSlashes(url) {
|
|
1542
|
+
let end = url.length;
|
|
1543
|
+
while (end > 0 && url[end - 1] === "/")
|
|
1544
|
+
end--;
|
|
1545
|
+
return url.slice(0, end);
|
|
1546
|
+
}
|
|
1318
1547
|
|
|
1319
1548
|
// node_modules/commander/lib/error.js
|
|
1320
1549
|
var CommanderError = class extends Error {
|
|
@@ -4685,12 +4914,35 @@ function useColor() {
|
|
|
4685
4914
|
var program = new Command();
|
|
4686
4915
|
|
|
4687
4916
|
// src/browser-login.ts
|
|
4688
|
-
import {
|
|
4917
|
+
import {
|
|
4918
|
+
constants,
|
|
4919
|
+
generateKeyPairSync,
|
|
4920
|
+
privateDecrypt,
|
|
4921
|
+
randomBytes
|
|
4922
|
+
} from "node:crypto";
|
|
4689
4923
|
import { createServer } from "node:http";
|
|
4690
4924
|
var PAGE = (title, body) => `<!doctype html><html><head><meta charset="utf-8"><title>${title}</title><meta name="viewport" content="width=device-width, initial-scale=1"></head><body style="font-family:system-ui,sans-serif;max-width:32rem;margin:4rem auto;padding:0 1rem"><h1 style="font-size:1.25rem">${title}</h1><p>${body}</p></body></html>`;
|
|
4691
|
-
var
|
|
4925
|
+
var MAX_URL = 16 * 1024;
|
|
4692
4926
|
function browserLogin(options) {
|
|
4693
4927
|
const state = randomBytes(24).toString("base64url");
|
|
4928
|
+
const { publicKey, privateKey } = generateKeyPairSync("rsa", {
|
|
4929
|
+
modulusLength: 2048
|
|
4930
|
+
});
|
|
4931
|
+
const key = publicKey.export({ type: "spki", format: "der" }).toString("base64url");
|
|
4932
|
+
const decrypt = (sealed) => {
|
|
4933
|
+
try {
|
|
4934
|
+
return privateDecrypt(
|
|
4935
|
+
{
|
|
4936
|
+
key: privateKey,
|
|
4937
|
+
padding: constants.RSA_PKCS1_OAEP_PADDING,
|
|
4938
|
+
oaepHash: "sha256"
|
|
4939
|
+
},
|
|
4940
|
+
Buffer.from(sealed, "base64url")
|
|
4941
|
+
).toString("utf8");
|
|
4942
|
+
} catch {
|
|
4943
|
+
return null;
|
|
4944
|
+
}
|
|
4945
|
+
};
|
|
4694
4946
|
return new Promise((resolve2, reject) => {
|
|
4695
4947
|
let settled = false;
|
|
4696
4948
|
const finish = (outcome) => {
|
|
@@ -4701,44 +4953,41 @@ function browserLogin(options) {
|
|
|
4701
4953
|
outcome();
|
|
4702
4954
|
};
|
|
4703
4955
|
const server = createServer((req, res) => {
|
|
4704
|
-
|
|
4956
|
+
const url = new URL(req.url ?? "/", "http://127.0.0.1");
|
|
4957
|
+
if (req.method !== "GET" || url.pathname !== "/callback" || (req.url ?? "").length > MAX_URL) {
|
|
4705
4958
|
res.writeHead(404).end();
|
|
4706
4959
|
return;
|
|
4707
4960
|
}
|
|
4708
|
-
|
|
4709
|
-
|
|
4710
|
-
|
|
4711
|
-
|
|
4712
|
-
|
|
4713
|
-
});
|
|
4714
|
-
|
|
4715
|
-
const fields = new URLSearchParams(body);
|
|
4716
|
-
const send = (status, title, text) => res.writeHead(status, { "content-type": "text/html; charset=utf-8" }).end(PAGE(title, text));
|
|
4717
|
-
if (fields.get("state") !== state) {
|
|
4718
|
-
send(
|
|
4719
|
-
400,
|
|
4720
|
-
"Not this login",
|
|
4721
|
-
"This sign-in did not come from the terminal that is waiting. Run login again."
|
|
4722
|
-
);
|
|
4723
|
-
return;
|
|
4724
|
-
}
|
|
4725
|
-
if (fields.get("error")) {
|
|
4726
|
-
send(200, "Sign-in cancelled", "You can close this tab.");
|
|
4727
|
-
finish(() => reject(new Error("sign-in was denied in the browser")));
|
|
4728
|
-
return;
|
|
4729
|
-
}
|
|
4730
|
-
const token = fields.get("token");
|
|
4731
|
-
if (!token) {
|
|
4732
|
-
send(400, "Something went wrong", "Run login again.");
|
|
4733
|
-
return;
|
|
4734
|
-
}
|
|
4961
|
+
const fields = url.searchParams;
|
|
4962
|
+
const send = (status, title, text) => res.writeHead(status, {
|
|
4963
|
+
"content-type": "text/html; charset=utf-8",
|
|
4964
|
+
"cache-control": "no-store",
|
|
4965
|
+
"referrer-policy": "no-referrer"
|
|
4966
|
+
}).end(PAGE(title, text));
|
|
4967
|
+
if (fields.get("state") !== state) {
|
|
4735
4968
|
send(
|
|
4736
|
-
|
|
4737
|
-
"
|
|
4738
|
-
"
|
|
4969
|
+
400,
|
|
4970
|
+
"Not this login",
|
|
4971
|
+
"This sign-in did not come from the terminal that is waiting. Run login again."
|
|
4739
4972
|
);
|
|
4740
|
-
|
|
4741
|
-
}
|
|
4973
|
+
return;
|
|
4974
|
+
}
|
|
4975
|
+
if (fields.get("error")) {
|
|
4976
|
+
send(200, "Sign-in cancelled", "You can close this tab.");
|
|
4977
|
+
finish(() => reject(new Error("sign-in was denied in the browser")));
|
|
4978
|
+
return;
|
|
4979
|
+
}
|
|
4980
|
+
const token = decrypt(fields.get("token") ?? "");
|
|
4981
|
+
if (!token) {
|
|
4982
|
+
send(400, "Something went wrong", "Run login again.");
|
|
4983
|
+
return;
|
|
4984
|
+
}
|
|
4985
|
+
send(
|
|
4986
|
+
200,
|
|
4987
|
+
"You are signed in",
|
|
4988
|
+
"Return to your terminal \u2014 you can close this tab."
|
|
4989
|
+
);
|
|
4990
|
+
finish(() => resolve2(token));
|
|
4742
4991
|
});
|
|
4743
4992
|
const timer = setTimeout(
|
|
4744
4993
|
() => finish(
|
|
@@ -4755,6 +5004,7 @@ function browserLogin(options) {
|
|
|
4755
5004
|
const url = `${options.webOrigin}/cli/authorize?${new URLSearchParams({
|
|
4756
5005
|
port: String(port),
|
|
4757
5006
|
state,
|
|
5007
|
+
key,
|
|
4758
5008
|
name: options.computer
|
|
4759
5009
|
})}`;
|
|
4760
5010
|
options.onUrl(url);
|
|
@@ -4768,8 +5018,8 @@ function webOriginFor(api2) {
|
|
|
4768
5018
|
url.hostname = `app.${url.hostname.slice(4)}`;
|
|
4769
5019
|
return url.origin;
|
|
4770
5020
|
}
|
|
4771
|
-
if ((url.hostname === "localhost" || url.hostname === "127.0.0.1") && url.port
|
|
4772
|
-
url.port =
|
|
5021
|
+
if ((url.hostname === "localhost" || url.hostname === "127.0.0.1") && Number(url.port) >= 8787 && Number(url.port) % 100 === 87) {
|
|
5022
|
+
url.port = String(Number(url.port) - 5787);
|
|
4773
5023
|
return url.origin;
|
|
4774
5024
|
}
|
|
4775
5025
|
return null;
|
|
@@ -4814,11 +5064,18 @@ function resolveSettings(env, homeDir, flags = {}) {
|
|
|
4814
5064
|
const environment2 = flags.environment ? { environment: flags.environment, environmentSource: "flag" } : env[environmentEnvVar()] ? { environment: env[environmentEnvVar()], environmentSource: "env" } : config2.environment ? { environment: config2.environment, environmentSource: "config" } : { environment: void 0, environmentSource: null };
|
|
4815
5065
|
return {
|
|
4816
5066
|
...environment2,
|
|
4817
|
-
api: (
|
|
5067
|
+
api: withoutTrailingSlashes2(
|
|
5068
|
+
env[`${brand.identifier.toUpperCase()}_API`] ?? config2.api ?? DEFAULT_API
|
|
5069
|
+
),
|
|
4818
5070
|
token: env[tokenEnvVar()] ?? config2.token,
|
|
4819
5071
|
workspace: env[`${brand.identifier.toUpperCase()}_WORKSPACE`] ?? config2.workspace
|
|
4820
5072
|
};
|
|
4821
5073
|
}
|
|
5074
|
+
function withoutTrailingSlashes2(url) {
|
|
5075
|
+
let end = url.length;
|
|
5076
|
+
while (end > 0 && url[end - 1] === "/") end--;
|
|
5077
|
+
return url.slice(0, end);
|
|
5078
|
+
}
|
|
4822
5079
|
|
|
4823
5080
|
// src/http.ts
|
|
4824
5081
|
async function rawRequest(ctx, options) {
|
|
@@ -4974,7 +5231,7 @@ var login = (program2, ctx) => {
|
|
|
4974
5231
|
}
|
|
4975
5232
|
if (!ctx.io.interactive) {
|
|
4976
5233
|
ctx.io.stderr(
|
|
4977
|
-
`Paste a personal access token (Account \u2192
|
|
5234
|
+
`Paste a personal access token (Account \u2192 Personal access tokens in ${brand.productName}), then Enter:`
|
|
4978
5235
|
);
|
|
4979
5236
|
await saveToken(ctx, (await ctx.io.stdin()).trim(), options.api);
|
|
4980
5237
|
return;
|
|
@@ -5010,7 +5267,7 @@ var logout = (program2, ctx) => {
|
|
|
5010
5267
|
).catch(() => null);
|
|
5011
5268
|
if (revoked && !revoked.ok && revoked.status !== 401) {
|
|
5012
5269
|
ctx.io.stderr(
|
|
5013
|
-
`Could not revoke the token (HTTP ${revoked.status}) \u2014 revoke it under Account \u2192
|
|
5270
|
+
`Could not revoke the token (HTTP ${revoked.status}) \u2014 revoke it under Account \u2192 Personal access tokens.`
|
|
5014
5271
|
);
|
|
5015
5272
|
}
|
|
5016
5273
|
}
|
|
@@ -5167,8 +5424,11 @@ function operationRequest(op, input, body = {}) {
|
|
|
5167
5424
|
json2[field.name] = value;
|
|
5168
5425
|
}
|
|
5169
5426
|
}
|
|
5170
|
-
const
|
|
5171
|
-
|
|
5427
|
+
const open = path2.indexOf("{");
|
|
5428
|
+
const close = open === -1 ? -1 : path2.indexOf("}", open + 1);
|
|
5429
|
+
if (close > open + 1) {
|
|
5430
|
+
throw new Error(`missing ${path2.slice(open + 1, close)}`);
|
|
5431
|
+
}
|
|
5172
5432
|
const qs = query.toString();
|
|
5173
5433
|
return {
|
|
5174
5434
|
method: op.method.toUpperCase(),
|
|
@@ -5199,7 +5459,7 @@ var OPERATIONS = [
|
|
|
5199
5459
|
"idempotentHint": false
|
|
5200
5460
|
}
|
|
5201
5461
|
},
|
|
5202
|
-
"description": "Asks whether `subject` may do `action` at `cost`, given every enabled limit that applies, and \u2014 in `consume` mode \u2014 uses it. Always 200 for a decision: read `allowed`; `
|
|
5462
|
+
"description": "Asks whether `subject` may do `action` at `cost`, given every enabled limit that applies, and \u2014 in `consume` mode \u2014 uses it. Always 200 for a decision, allowed or refused: read `allowed`; `limits` shows what is left on each limit and `retryAfterSeconds` when to try again. An `Idempotency-Key` header makes a retried check return the same decision without using twice. Its API-key check is cached briefly for speed: a revoked key can keep working here for up to 60 seconds.",
|
|
5203
5463
|
"fields": [
|
|
5204
5464
|
{
|
|
5205
5465
|
"name": "subject",
|
|
@@ -5304,7 +5564,7 @@ var OPERATIONS = [
|
|
|
5304
5564
|
"in": "body",
|
|
5305
5565
|
"type": "string",
|
|
5306
5566
|
"required": false,
|
|
5307
|
-
"description": "`consume` (default) decides and uses; `preview` decides without using; `reserve` decides and
|
|
5567
|
+
"description": "`consume` (default) decides and uses; `preview` decides without using; `reserve` decides and reserves `cost` (what it will probably use) until you commit the actual amount or release it \u2014 see `reservation` in the answer. Only a reservation takes a slot of a `concurrent` limit.",
|
|
5308
5568
|
"example": "consume",
|
|
5309
5569
|
"schema": {
|
|
5310
5570
|
"type": "string",
|
|
@@ -5313,7 +5573,7 @@ var OPERATIONS = [
|
|
|
5313
5573
|
"preview",
|
|
5314
5574
|
"reserve"
|
|
5315
5575
|
],
|
|
5316
|
-
"description": "`consume` (default) decides and uses; `preview` decides without using; `reserve` decides and
|
|
5576
|
+
"description": "`consume` (default) decides and uses; `preview` decides without using; `reserve` decides and reserves `cost` (what it will probably use) until you commit the actual amount or release it \u2014 see `reservation` in the answer. Only a reservation takes a slot of a `concurrent` limit."
|
|
5317
5577
|
}
|
|
5318
5578
|
},
|
|
5319
5579
|
{
|
|
@@ -5321,13 +5581,13 @@ var OPERATIONS = [
|
|
|
5321
5581
|
"in": "body",
|
|
5322
5582
|
"type": "number",
|
|
5323
5583
|
"required": false,
|
|
5324
|
-
"description": "With `reserve`: how long the
|
|
5584
|
+
"description": "With `reserve`: how long the reservation lasts before it releases itself. Default 300, at most 3600.",
|
|
5325
5585
|
"example": 300,
|
|
5326
5586
|
"schema": {
|
|
5327
5587
|
"type": "integer",
|
|
5328
5588
|
"minimum": 1,
|
|
5329
5589
|
"maximum": 3600,
|
|
5330
|
-
"description": "With `reserve`: how long the
|
|
5590
|
+
"description": "With `reserve`: how long the reservation lasts before it releases itself. Default 300, at most 3600."
|
|
5331
5591
|
}
|
|
5332
5592
|
}
|
|
5333
5593
|
],
|
|
@@ -5356,14 +5616,14 @@ var OPERATIONS = [
|
|
|
5356
5616
|
"idempotentHint": false
|
|
5357
5617
|
}
|
|
5358
5618
|
},
|
|
5359
|
-
"description": "Stops a limit: checks stop enforcing it
|
|
5619
|
+
"description": "Stops a limit: checks stop enforcing it at once, and it leaves the list. It is archived, not erased \u2014 its usage history and credits stay, and `POST /v1/limits/{limitId}/restore` brings it back. Owners and admins only, for a person's token.",
|
|
5360
5620
|
"fields": [
|
|
5361
5621
|
{
|
|
5362
5622
|
"name": "limitId",
|
|
5363
5623
|
"in": "path",
|
|
5364
5624
|
"type": "string",
|
|
5365
5625
|
"required": true,
|
|
5366
|
-
"example": "
|
|
5626
|
+
"example": "lmt_3f0c\u2026",
|
|
5367
5627
|
"schema": {
|
|
5368
5628
|
"type": "string"
|
|
5369
5629
|
}
|
|
@@ -5392,64 +5652,68 @@ var OPERATIONS = [
|
|
|
5392
5652
|
"idempotentHint": false
|
|
5393
5653
|
}
|
|
5394
5654
|
},
|
|
5395
|
-
"description": "Limits how much
|
|
5655
|
+
"description": "Limits how much a subject may use per window \u2014 for example 200 cents a month for every `user`. Only `subject.kind`, `amount` and `window` are needed: `action` defaults to every action (`*`), `unit` to units, and `name` to the sentence the limit reads as. Checks enforce it from then on. What it counts (subject, action, unit, window, every, start, rolling) is fixed once created. Owners and admins only, for a person's token.",
|
|
5396
5656
|
"fields": [
|
|
5397
5657
|
{
|
|
5398
5658
|
"name": "name",
|
|
5399
5659
|
"in": "body",
|
|
5400
5660
|
"type": "string",
|
|
5401
|
-
"required":
|
|
5402
|
-
"description":
|
|
5661
|
+
"required": false,
|
|
5662
|
+
"description": `A name, unique among the environment's active limits. Default: the sentence the limit reads as, such as "200 cents per user per month". If a limit already has that name, the answer is 409: give this one a name.`,
|
|
5403
5663
|
"example": "AI budget",
|
|
5404
5664
|
"schema": {
|
|
5405
5665
|
"type": "string",
|
|
5406
5666
|
"minLength": 1,
|
|
5407
5667
|
"maxLength": 100,
|
|
5408
|
-
"description":
|
|
5668
|
+
"description": `A name, unique among the environment's active limits. Default: the sentence the limit reads as, such as "200 cents per user per month". If a limit already has that name, the answer is 409: give this one a name.`
|
|
5409
5669
|
}
|
|
5410
5670
|
},
|
|
5411
5671
|
{
|
|
5412
|
-
"name": "
|
|
5672
|
+
"name": "subject",
|
|
5413
5673
|
"in": "body",
|
|
5414
|
-
"type": "
|
|
5674
|
+
"type": "json",
|
|
5415
5675
|
"required": true,
|
|
5416
|
-
"description": "
|
|
5417
|
-
"example":
|
|
5418
|
-
|
|
5419
|
-
|
|
5420
|
-
"minLength": 1,
|
|
5421
|
-
"maxLength": 100,
|
|
5422
|
-
"description": "Your own label for who is checked."
|
|
5423
|
-
}
|
|
5424
|
-
},
|
|
5425
|
-
{
|
|
5426
|
-
"name": "subjectId",
|
|
5427
|
-
"in": "body",
|
|
5428
|
-
"type": "string",
|
|
5429
|
-
"required": false,
|
|
5430
|
-
"description": "One subject; omit or null for every subject of the kind. A subject's own limit replaces the kind's limits with the same action and window.",
|
|
5676
|
+
"description": 'Who it applies to: `{"kind": "user"}` for every user, `{"kind": "user", "id": "usr_123"}` for one.',
|
|
5677
|
+
"example": {
|
|
5678
|
+
"kind": "user"
|
|
5679
|
+
},
|
|
5431
5680
|
"schema": {
|
|
5432
|
-
"type":
|
|
5433
|
-
|
|
5434
|
-
"
|
|
5681
|
+
"type": "object",
|
|
5682
|
+
"properties": {
|
|
5683
|
+
"kind": {
|
|
5684
|
+
"type": "string",
|
|
5685
|
+
"minLength": 1,
|
|
5686
|
+
"maxLength": 100,
|
|
5687
|
+
"description": "Your own label for who is checked: user, team, apikey \u2026"
|
|
5688
|
+
},
|
|
5689
|
+
"id": {
|
|
5690
|
+
"type": [
|
|
5691
|
+
"string",
|
|
5692
|
+
"null"
|
|
5693
|
+
],
|
|
5694
|
+
"minLength": 1,
|
|
5695
|
+
"maxLength": 100,
|
|
5696
|
+
"description": "One subject; omit or null for every subject of the kind. A subject's own limit replaces the kind's limits with the same action and window."
|
|
5697
|
+
}
|
|
5698
|
+
},
|
|
5699
|
+
"required": [
|
|
5700
|
+
"kind"
|
|
5435
5701
|
],
|
|
5436
|
-
"
|
|
5437
|
-
"maxLength": 100,
|
|
5438
|
-
"description": "One subject; omit or null for every subject of the kind. A subject's own limit replaces the kind's limits with the same action and window."
|
|
5702
|
+
"description": 'Who it applies to: `{"kind": "user"}` for every user, `{"kind": "user", "id": "usr_123"}` for one.'
|
|
5439
5703
|
}
|
|
5440
5704
|
},
|
|
5441
5705
|
{
|
|
5442
5706
|
"name": "action",
|
|
5443
5707
|
"in": "body",
|
|
5444
5708
|
"type": "string",
|
|
5445
|
-
"required":
|
|
5446
|
-
"description": "The action to limit
|
|
5709
|
+
"required": false,
|
|
5710
|
+
"description": "The action to limit. Default: `*`, every action.",
|
|
5447
5711
|
"example": "ai-call",
|
|
5448
5712
|
"schema": {
|
|
5449
5713
|
"type": "string",
|
|
5450
5714
|
"minLength": 1,
|
|
5451
5715
|
"maxLength": 100,
|
|
5452
|
-
"description": "The action to limit
|
|
5716
|
+
"description": "The action to limit. Default: `*`, every action."
|
|
5453
5717
|
}
|
|
5454
5718
|
},
|
|
5455
5719
|
{
|
|
@@ -5471,13 +5735,13 @@ var OPERATIONS = [
|
|
|
5471
5735
|
"in": "body",
|
|
5472
5736
|
"type": "string",
|
|
5473
5737
|
"required": false,
|
|
5474
|
-
"description": "What the amount counts
|
|
5738
|
+
"description": "What the amount counts, in words. Default: units.",
|
|
5475
5739
|
"example": "cents",
|
|
5476
5740
|
"schema": {
|
|
5477
5741
|
"type": "string",
|
|
5478
5742
|
"minLength": 1,
|
|
5479
5743
|
"maxLength": 40,
|
|
5480
|
-
"description": "What the amount counts
|
|
5744
|
+
"description": "What the amount counts, in words. Default: units."
|
|
5481
5745
|
}
|
|
5482
5746
|
},
|
|
5483
5747
|
{
|
|
@@ -5485,7 +5749,7 @@ var OPERATIONS = [
|
|
|
5485
5749
|
"in": "body",
|
|
5486
5750
|
"type": "string",
|
|
5487
5751
|
"required": true,
|
|
5488
|
-
"description": "`minute`, `hour`, `day`, `week`, `month` or `year`: a period of `every` of them,
|
|
5752
|
+
"description": "`minute`, `hour`, `day`, `week`, `month` or `year`: a period of `every` of them, reset where `start` says (or rolling: see `rolling`). `total`: a balance that never resets, raised by credits. `concurrent`: at most `amount` open reservations at once.",
|
|
5489
5753
|
"example": "month",
|
|
5490
5754
|
"schema": {
|
|
5491
5755
|
"type": "string",
|
|
@@ -5499,7 +5763,7 @@ var OPERATIONS = [
|
|
|
5499
5763
|
"total",
|
|
5500
5764
|
"concurrent"
|
|
5501
5765
|
],
|
|
5502
|
-
"description": "`minute`, `hour`, `day`, `week`, `month` or `year`: a period of `every` of them,
|
|
5766
|
+
"description": "`minute`, `hour`, `day`, `week`, `month` or `year`: a period of `every` of them, reset where `start` says (or rolling: see `rolling`). `total`: a balance that never resets, raised by credits. `concurrent`: at most `amount` open reservations at once."
|
|
5503
5767
|
}
|
|
5504
5768
|
},
|
|
5505
5769
|
{
|
|
@@ -5521,16 +5785,16 @@ var OPERATIONS = [
|
|
|
5521
5785
|
"in": "body",
|
|
5522
5786
|
"type": "string",
|
|
5523
5787
|
"required": false,
|
|
5524
|
-
"description": "Where a period begins. `calendar`: UTC boundaries (midnight, Monday, the 1st, 1 January). `
|
|
5788
|
+
"description": "Where a period begins. `calendar`: UTC boundaries (midnight, Monday, the 1st, 1 January). `billing_date`: from the subject's billing date, set with `subjects.update` (its first check until then), so an annual plan can reset monthly from its start day. `first_use`: at the first check after the previous period ended. Default: calendar.",
|
|
5525
5789
|
"example": "calendar",
|
|
5526
5790
|
"schema": {
|
|
5527
5791
|
"type": "string",
|
|
5528
5792
|
"enum": [
|
|
5529
5793
|
"calendar",
|
|
5530
|
-
"
|
|
5794
|
+
"billing_date",
|
|
5531
5795
|
"first_use"
|
|
5532
5796
|
],
|
|
5533
|
-
"description": "Where a period begins. `calendar`: UTC boundaries (midnight, Monday, the 1st, 1 January). `
|
|
5797
|
+
"description": "Where a period begins. `calendar`: UTC boundaries (midnight, Monday, the 1st, 1 January). `billing_date`: from the subject's billing date, set with `subjects.update` (its first check until then), so an annual plan can reset monthly from its start day. `first_use`: at the first check after the previous period ended. Default: calendar."
|
|
5534
5798
|
}
|
|
5535
5799
|
},
|
|
5536
5800
|
{
|
|
@@ -5576,50 +5840,12 @@ var OPERATIONS = [
|
|
|
5576
5840
|
"scope": "limits:write"
|
|
5577
5841
|
},
|
|
5578
5842
|
{
|
|
5579
|
-
"operationId": "limits.
|
|
5580
|
-
"method": "get",
|
|
5581
|
-
"path": "/limits/{limitId}",
|
|
5582
|
-
"summary": "Get a limit",
|
|
5583
|
-
"cli": {
|
|
5584
|
-
"command": "limits get",
|
|
5585
|
-
"args": [
|
|
5586
|
-
"limitId"
|
|
5587
|
-
],
|
|
5588
|
-
"confirm": false
|
|
5589
|
-
},
|
|
5590
|
-
"mcp": {
|
|
5591
|
-
"exposed": true,
|
|
5592
|
-
"name": "limits_get",
|
|
5593
|
-
"hints": {
|
|
5594
|
-
"readOnlyHint": true,
|
|
5595
|
-
"destructiveHint": false,
|
|
5596
|
-
"idempotentHint": true
|
|
5597
|
-
}
|
|
5598
|
-
},
|
|
5599
|
-
"description": "One limit: who it applies to, the action, amount and window.",
|
|
5600
|
-
"fields": [
|
|
5601
|
-
{
|
|
5602
|
-
"name": "limitId",
|
|
5603
|
-
"in": "path",
|
|
5604
|
-
"type": "string",
|
|
5605
|
-
"required": true,
|
|
5606
|
-
"example": "lim_3f0c\u2026",
|
|
5607
|
-
"schema": {
|
|
5608
|
-
"type": "string"
|
|
5609
|
-
}
|
|
5610
|
-
}
|
|
5611
|
-
],
|
|
5612
|
-
"hasBody": false,
|
|
5613
|
-
"workspace": true,
|
|
5614
|
-
"scope": "limits:read"
|
|
5615
|
-
},
|
|
5616
|
-
{
|
|
5617
|
-
"operationId": "limits.grants.create",
|
|
5843
|
+
"operationId": "limits.credits.create",
|
|
5618
5844
|
"method": "post",
|
|
5619
|
-
"path": "/limits/{limitId}/
|
|
5845
|
+
"path": "/limits/{limitId}/credits",
|
|
5620
5846
|
"summary": "Add credits to a balance",
|
|
5621
5847
|
"cli": {
|
|
5622
|
-
"command": "limits
|
|
5848
|
+
"command": "limits credits create",
|
|
5623
5849
|
"args": [
|
|
5624
5850
|
"limitId"
|
|
5625
5851
|
],
|
|
@@ -5627,16 +5853,16 @@ var OPERATIONS = [
|
|
|
5627
5853
|
},
|
|
5628
5854
|
"mcp": {
|
|
5629
5855
|
"exposed": false,
|
|
5630
|
-
"reason": "Adding credits gives value away; an agent asks a person (limit.
|
|
5856
|
+
"reason": "Adding credits gives value away; an agent asks a person (limit.credit approval)"
|
|
5631
5857
|
},
|
|
5632
|
-
"description": "Adds `amount` to one subject's balance \u2014 a limit whose window is `total`. A negative `amount` takes credits back (a refund, a chargeback) and needs a `note` saying why; the balance may go below zero, and checks are refused until
|
|
5858
|
+
"description": "Adds `amount` credits to one subject's balance \u2014 a limit whose window is `total`. A negative `amount` takes credits back (a refund, a chargeback) and needs a `note` saying why; the balance may go below zero, and checks are refused until more credits are added. Owners and admins, or a workspace API key; an agent asks a person (the `limit.credit` approval).",
|
|
5633
5859
|
"fields": [
|
|
5634
5860
|
{
|
|
5635
5861
|
"name": "limitId",
|
|
5636
5862
|
"in": "path",
|
|
5637
5863
|
"type": "string",
|
|
5638
5864
|
"required": true,
|
|
5639
|
-
"example": "
|
|
5865
|
+
"example": "lmt_3f0c\u2026",
|
|
5640
5866
|
"schema": {
|
|
5641
5867
|
"type": "string"
|
|
5642
5868
|
}
|
|
@@ -5690,7 +5916,7 @@ var OPERATIONS = [
|
|
|
5690
5916
|
"type": "string",
|
|
5691
5917
|
"required": false,
|
|
5692
5918
|
"description": "Required when `amount` is negative.",
|
|
5693
|
-
"example": "October
|
|
5919
|
+
"example": "October credits",
|
|
5694
5920
|
"schema": {
|
|
5695
5921
|
"type": "string",
|
|
5696
5922
|
"maxLength": 200,
|
|
@@ -5703,12 +5929,50 @@ var OPERATIONS = [
|
|
|
5703
5929
|
"scope": "limits:write"
|
|
5704
5930
|
},
|
|
5705
5931
|
{
|
|
5706
|
-
"operationId": "limits.
|
|
5932
|
+
"operationId": "limits.credits.list",
|
|
5933
|
+
"method": "get",
|
|
5934
|
+
"path": "/limits/{limitId}/credits",
|
|
5935
|
+
"summary": "List a balance's credits",
|
|
5936
|
+
"cli": {
|
|
5937
|
+
"command": "limits credits list",
|
|
5938
|
+
"args": [
|
|
5939
|
+
"limitId"
|
|
5940
|
+
],
|
|
5941
|
+
"confirm": false
|
|
5942
|
+
},
|
|
5943
|
+
"mcp": {
|
|
5944
|
+
"exposed": true,
|
|
5945
|
+
"name": "limits_credits_list",
|
|
5946
|
+
"hints": {
|
|
5947
|
+
"readOnlyHint": true,
|
|
5948
|
+
"destructiveHint": false,
|
|
5949
|
+
"idempotentHint": true
|
|
5950
|
+
}
|
|
5951
|
+
},
|
|
5952
|
+
"description": "Credits added to (or taken back from) subjects' balances for this limit, newest first.",
|
|
5953
|
+
"fields": [
|
|
5954
|
+
{
|
|
5955
|
+
"name": "limitId",
|
|
5956
|
+
"in": "path",
|
|
5957
|
+
"type": "string",
|
|
5958
|
+
"required": true,
|
|
5959
|
+
"example": "lmt_3f0c\u2026",
|
|
5960
|
+
"schema": {
|
|
5961
|
+
"type": "string"
|
|
5962
|
+
}
|
|
5963
|
+
}
|
|
5964
|
+
],
|
|
5965
|
+
"hasBody": false,
|
|
5966
|
+
"workspace": true,
|
|
5967
|
+
"scope": "limits:read"
|
|
5968
|
+
},
|
|
5969
|
+
{
|
|
5970
|
+
"operationId": "limits.get",
|
|
5707
5971
|
"method": "get",
|
|
5708
|
-
"path": "/limits/{limitId}
|
|
5709
|
-
"summary": "
|
|
5972
|
+
"path": "/limits/{limitId}",
|
|
5973
|
+
"summary": "Get a limit",
|
|
5710
5974
|
"cli": {
|
|
5711
|
-
"command": "limits
|
|
5975
|
+
"command": "limits get",
|
|
5712
5976
|
"args": [
|
|
5713
5977
|
"limitId"
|
|
5714
5978
|
],
|
|
@@ -5716,21 +5980,21 @@ var OPERATIONS = [
|
|
|
5716
5980
|
},
|
|
5717
5981
|
"mcp": {
|
|
5718
5982
|
"exposed": true,
|
|
5719
|
-
"name": "
|
|
5983
|
+
"name": "limits_get",
|
|
5720
5984
|
"hints": {
|
|
5721
5985
|
"readOnlyHint": true,
|
|
5722
5986
|
"destructiveHint": false,
|
|
5723
5987
|
"idempotentHint": true
|
|
5724
5988
|
}
|
|
5725
5989
|
},
|
|
5726
|
-
"description": "
|
|
5990
|
+
"description": "One limit: who it applies to, the action, amount and window.",
|
|
5727
5991
|
"fields": [
|
|
5728
5992
|
{
|
|
5729
5993
|
"name": "limitId",
|
|
5730
5994
|
"in": "path",
|
|
5731
5995
|
"type": "string",
|
|
5732
5996
|
"required": true,
|
|
5733
|
-
"example": "
|
|
5997
|
+
"example": "lmt_3f0c\u2026",
|
|
5734
5998
|
"schema": {
|
|
5735
5999
|
"type": "string"
|
|
5736
6000
|
}
|
|
@@ -5861,7 +6125,7 @@ var OPERATIONS = [
|
|
|
5861
6125
|
"in": "path",
|
|
5862
6126
|
"type": "string",
|
|
5863
6127
|
"required": true,
|
|
5864
|
-
"example": "
|
|
6128
|
+
"example": "lmt_3f0c\u2026",
|
|
5865
6129
|
"schema": {
|
|
5866
6130
|
"type": "string"
|
|
5867
6131
|
}
|
|
@@ -5891,18 +6155,20 @@ var OPERATIONS = [
|
|
|
5891
6155
|
"idempotentHint": false
|
|
5892
6156
|
}
|
|
5893
6157
|
},
|
|
5894
|
-
"description": "Makes the environment's limits match `limits`, by name: creates the missing, changes those that differ (an omitted field means its default) and, with `archiveMissing`, archives active limits the list doesn't name. Running it twice changes nothing the second time. Limitry checks the whole list first, and a problem anywhere changes nothing (400, each problem in `details`); then it writes every change at once. `
|
|
6158
|
+
"description": "Makes the environment's limits match `limits`, by name: creates the missing, changes those that differ (an omitted field means its default) and, with `archiveMissing`, archives active limits the list doesn't name. Running it twice changes nothing the second time. Limitry checks the whole list first, and a problem anywhere changes nothing (400, each problem in `details`); then it writes every change at once. What a limit counts is fixed: a different subject, action, unit or window under an existing name is refused until the entry is renamed. `preview` answers what it would do without writing. For keeping limits in a file in your repository (`limitry sync`). Owners and admins only, for a person's token.",
|
|
5895
6159
|
"fields": [
|
|
5896
6160
|
{
|
|
5897
6161
|
"name": "limits",
|
|
5898
6162
|
"in": "body",
|
|
5899
6163
|
"type": "json",
|
|
5900
6164
|
"required": true,
|
|
5901
|
-
"description": "Every limit you want, each described whole: an omitted field is its default, as on create. Names are the key and must be unique in the list. At most 200.",
|
|
6165
|
+
"description": "Every limit you want, each described whole: an omitted field is its default, as on create. Names are the key and must be unique in the list. What a limit counts (subject, action, unit, window, every, start, rolling) is fixed: to change it, rename the entry, which creates a new limit. At most 200.",
|
|
5902
6166
|
"example": [
|
|
5903
6167
|
{
|
|
5904
6168
|
"name": "AI budget",
|
|
5905
|
-
"
|
|
6169
|
+
"subject": {
|
|
6170
|
+
"kind": "user"
|
|
6171
|
+
},
|
|
5906
6172
|
"action": "ai-call",
|
|
5907
6173
|
"amount": 200,
|
|
5908
6174
|
"unit": "cents",
|
|
@@ -5912,103 +6178,29 @@ var OPERATIONS = [
|
|
|
5912
6178
|
"schema": {
|
|
5913
6179
|
"type": "array",
|
|
5914
6180
|
"items": {
|
|
5915
|
-
"
|
|
5916
|
-
|
|
5917
|
-
|
|
5918
|
-
"type": "string",
|
|
5919
|
-
"minLength": 1,
|
|
5920
|
-
"maxLength": 100,
|
|
5921
|
-
"description": "A name for the limit, unique among its environment's active limits."
|
|
6181
|
+
"allOf": [
|
|
6182
|
+
{
|
|
6183
|
+
"$ref": "#/components/schemas/LimitInput"
|
|
5922
6184
|
},
|
|
5923
|
-
|
|
5924
|
-
"type": "
|
|
5925
|
-
"
|
|
5926
|
-
|
|
5927
|
-
|
|
5928
|
-
|
|
5929
|
-
|
|
5930
|
-
|
|
5931
|
-
|
|
5932
|
-
|
|
5933
|
-
|
|
5934
|
-
"
|
|
5935
|
-
|
|
5936
|
-
|
|
5937
|
-
},
|
|
5938
|
-
"action": {
|
|
5939
|
-
"type": "string",
|
|
5940
|
-
"minLength": 1,
|
|
5941
|
-
"maxLength": 100,
|
|
5942
|
-
"description": "The action to limit; `*` for every action."
|
|
5943
|
-
},
|
|
5944
|
-
"amount": {
|
|
5945
|
-
"type": "integer",
|
|
5946
|
-
"minimum": 1,
|
|
5947
|
-
"maximum": 1e9,
|
|
5948
|
-
"description": "How many units each subject may use per window."
|
|
5949
|
-
},
|
|
5950
|
-
"unit": {
|
|
5951
|
-
"type": "string",
|
|
5952
|
-
"minLength": 1,
|
|
5953
|
-
"maxLength": 40,
|
|
5954
|
-
"description": "What the amount counts (display only). Default: units."
|
|
5955
|
-
},
|
|
5956
|
-
"window": {
|
|
5957
|
-
"type": "string",
|
|
5958
|
-
"enum": [
|
|
5959
|
-
"minute",
|
|
5960
|
-
"hour",
|
|
5961
|
-
"day",
|
|
5962
|
-
"week",
|
|
5963
|
-
"month",
|
|
5964
|
-
"year",
|
|
5965
|
-
"total",
|
|
5966
|
-
"concurrent"
|
|
5967
|
-
],
|
|
5968
|
-
"description": "`minute`, `hour`, `day`, `week`, `month` or `year`: a period of `every` of them, refilled where `start` says (or rolling: see `rolling`). `total`: a balance that never resets, topped up by grants. `concurrent`: at most `amount` held reservations at once."
|
|
5969
|
-
},
|
|
5970
|
-
"every": {
|
|
5971
|
-
"type": "integer",
|
|
5972
|
-
"minimum": 1,
|
|
5973
|
-
"maximum": 1e3,
|
|
5974
|
-
"description": 'How many `window` units a period lasts: `window: "month", every: 3` is a quarter, `window: "hour", every: 5` five hours. Default: 1.'
|
|
5975
|
-
},
|
|
5976
|
-
"start": {
|
|
5977
|
-
"type": "string",
|
|
5978
|
-
"enum": [
|
|
5979
|
-
"calendar",
|
|
5980
|
-
"anchor",
|
|
5981
|
-
"first_use"
|
|
5982
|
-
],
|
|
5983
|
-
"description": "Where a period begins. `calendar`: UTC boundaries (midnight, Monday, the 1st, 1 January). `anchor`: from the subject's anchor, its billing date, set with `subjects.update` (its first check until then), so an annual plan can refill monthly from its start day. `first_use`: at the first check after the previous period ended. Default: calendar."
|
|
5984
|
-
},
|
|
5985
|
-
"rolling": {
|
|
5986
|
-
"type": "boolean",
|
|
5987
|
-
"description": "Count the last window instead of the calendar one (minute, hour or day only). Default: false."
|
|
5988
|
-
},
|
|
5989
|
-
"enabled": {
|
|
5990
|
-
"type": "boolean",
|
|
5991
|
-
"description": "Whether checks enforce it. Default: true."
|
|
5992
|
-
},
|
|
5993
|
-
"failMode": {
|
|
5994
|
-
"type": "string",
|
|
5995
|
-
"enum": [
|
|
5996
|
-
"open",
|
|
5997
|
-
"closed"
|
|
5998
|
-
],
|
|
5999
|
-
"description": "What your code should do when Limitry can't be reached: `open` (allow) or `closed` (deny). Default: open."
|
|
6185
|
+
{
|
|
6186
|
+
"type": "object",
|
|
6187
|
+
"properties": {
|
|
6188
|
+
"name": {
|
|
6189
|
+
"type": "string",
|
|
6190
|
+
"minLength": 1,
|
|
6191
|
+
"maxLength": 100,
|
|
6192
|
+
"example": "AI budget",
|
|
6193
|
+
"description": "The limit's name: the key a sync matches on, unique in the list."
|
|
6194
|
+
}
|
|
6195
|
+
},
|
|
6196
|
+
"required": [
|
|
6197
|
+
"name"
|
|
6198
|
+
]
|
|
6000
6199
|
}
|
|
6001
|
-
},
|
|
6002
|
-
"required": [
|
|
6003
|
-
"name",
|
|
6004
|
-
"subjectKind",
|
|
6005
|
-
"action",
|
|
6006
|
-
"amount",
|
|
6007
|
-
"window"
|
|
6008
6200
|
]
|
|
6009
6201
|
},
|
|
6010
6202
|
"maxItems": 200,
|
|
6011
|
-
"description": "Every limit you want, each described whole: an omitted field is its default, as on create. Names are the key and must be unique in the list. At most 200."
|
|
6203
|
+
"description": "Every limit you want, each described whole: an omitted field is its default, as on create. Names are the key and must be unique in the list. What a limit counts (subject, action, unit, window, every, start, rolling) is fixed: to change it, rename the entry, which creates a new limit. At most 200."
|
|
6012
6204
|
}
|
|
6013
6205
|
},
|
|
6014
6206
|
{
|
|
@@ -6023,7 +6215,7 @@ var OPERATIONS = [
|
|
|
6023
6215
|
}
|
|
6024
6216
|
},
|
|
6025
6217
|
{
|
|
6026
|
-
"name": "
|
|
6218
|
+
"name": "preview",
|
|
6027
6219
|
"in": "body",
|
|
6028
6220
|
"type": "boolean",
|
|
6029
6221
|
"required": false,
|
|
@@ -6059,14 +6251,14 @@ var OPERATIONS = [
|
|
|
6059
6251
|
"idempotentHint": false
|
|
6060
6252
|
}
|
|
6061
6253
|
},
|
|
6062
|
-
"description": "Changes
|
|
6254
|
+
"description": "Changes a limit's name, amount, fail mode or whether it is enabled; checks use the new rule at once. What a limit counts (subject, action, unit, window, every, start, rolling) is fixed: a different value is refused (400) \u2014 create a new limit and archive this one. Owners and admins only, for a person's token.",
|
|
6063
6255
|
"fields": [
|
|
6064
6256
|
{
|
|
6065
6257
|
"name": "limitId",
|
|
6066
6258
|
"in": "path",
|
|
6067
6259
|
"type": "string",
|
|
6068
6260
|
"required": true,
|
|
6069
|
-
"example": "
|
|
6261
|
+
"example": "lmt_3f0c\u2026",
|
|
6070
6262
|
"schema": {
|
|
6071
6263
|
"type": "string"
|
|
6072
6264
|
}
|
|
@@ -6076,43 +6268,84 @@ var OPERATIONS = [
|
|
|
6076
6268
|
"in": "body",
|
|
6077
6269
|
"type": "string",
|
|
6078
6270
|
"required": false,
|
|
6079
|
-
"description": "A name
|
|
6271
|
+
"description": "A new name, unique among the environment's active limits.",
|
|
6080
6272
|
"example": "AI budget",
|
|
6081
6273
|
"schema": {
|
|
6082
6274
|
"type": "string",
|
|
6083
6275
|
"minLength": 1,
|
|
6084
6276
|
"maxLength": 100,
|
|
6085
|
-
"description": "A name
|
|
6277
|
+
"description": "A new name, unique among the environment's active limits."
|
|
6086
6278
|
}
|
|
6087
6279
|
},
|
|
6088
6280
|
{
|
|
6089
|
-
"name": "
|
|
6281
|
+
"name": "amount",
|
|
6090
6282
|
"in": "body",
|
|
6091
|
-
"type": "
|
|
6283
|
+
"type": "number",
|
|
6092
6284
|
"required": false,
|
|
6093
|
-
"description": "
|
|
6094
|
-
"example":
|
|
6285
|
+
"description": "How many units each subject may use per window.",
|
|
6286
|
+
"example": 300,
|
|
6095
6287
|
"schema": {
|
|
6096
|
-
"type": "
|
|
6097
|
-
"
|
|
6098
|
-
"
|
|
6099
|
-
"description": "
|
|
6288
|
+
"type": "integer",
|
|
6289
|
+
"minimum": 1,
|
|
6290
|
+
"maximum": 1e9,
|
|
6291
|
+
"description": "How many units each subject may use per window."
|
|
6100
6292
|
}
|
|
6101
6293
|
},
|
|
6102
6294
|
{
|
|
6103
|
-
"name": "
|
|
6295
|
+
"name": "enabled",
|
|
6296
|
+
"in": "body",
|
|
6297
|
+
"type": "boolean",
|
|
6298
|
+
"required": false,
|
|
6299
|
+
"description": "Whether checks enforce it.",
|
|
6300
|
+
"schema": {
|
|
6301
|
+
"type": "boolean",
|
|
6302
|
+
"description": "Whether checks enforce it."
|
|
6303
|
+
}
|
|
6304
|
+
},
|
|
6305
|
+
{
|
|
6306
|
+
"name": "failMode",
|
|
6104
6307
|
"in": "body",
|
|
6105
6308
|
"type": "string",
|
|
6106
6309
|
"required": false,
|
|
6107
|
-
"description": "
|
|
6310
|
+
"description": "What your code should do when Limitry can't be reached: `open` (allow) or `closed` (deny).",
|
|
6108
6311
|
"schema": {
|
|
6109
|
-
"type":
|
|
6110
|
-
|
|
6111
|
-
"
|
|
6312
|
+
"type": "string",
|
|
6313
|
+
"enum": [
|
|
6314
|
+
"open",
|
|
6315
|
+
"closed"
|
|
6112
6316
|
],
|
|
6113
|
-
"
|
|
6114
|
-
|
|
6115
|
-
|
|
6317
|
+
"description": "What your code should do when Limitry can't be reached: `open` (allow) or `closed` (deny)."
|
|
6318
|
+
}
|
|
6319
|
+
},
|
|
6320
|
+
{
|
|
6321
|
+
"name": "subject",
|
|
6322
|
+
"in": "body",
|
|
6323
|
+
"type": "json",
|
|
6324
|
+
"required": false,
|
|
6325
|
+
"description": "Who it applies to. Fixed once the limit is created: to change it, create a new limit and archive this one.",
|
|
6326
|
+
"example": {
|
|
6327
|
+
"kind": "user"
|
|
6328
|
+
},
|
|
6329
|
+
"schema": {
|
|
6330
|
+
"type": "object",
|
|
6331
|
+
"properties": {
|
|
6332
|
+
"kind": {
|
|
6333
|
+
"type": "string",
|
|
6334
|
+
"minLength": 1,
|
|
6335
|
+
"maxLength": 100,
|
|
6336
|
+
"description": "Your own label for who is checked: user, team, apikey \u2026"
|
|
6337
|
+
},
|
|
6338
|
+
"id": {
|
|
6339
|
+
"type": [
|
|
6340
|
+
"string",
|
|
6341
|
+
"null"
|
|
6342
|
+
],
|
|
6343
|
+
"minLength": 1,
|
|
6344
|
+
"maxLength": 100,
|
|
6345
|
+
"description": "One subject; omit or null for every subject of the kind. A subject's own limit replaces the kind's limits with the same action and window."
|
|
6346
|
+
}
|
|
6347
|
+
},
|
|
6348
|
+
"description": "Who it applies to. Fixed once the limit is created: to change it, create a new limit and archive this one."
|
|
6116
6349
|
}
|
|
6117
6350
|
},
|
|
6118
6351
|
{
|
|
@@ -6120,27 +6353,12 @@ var OPERATIONS = [
|
|
|
6120
6353
|
"in": "body",
|
|
6121
6354
|
"type": "string",
|
|
6122
6355
|
"required": false,
|
|
6123
|
-
"description": "The action to limit
|
|
6124
|
-
"example": "ai-call",
|
|
6356
|
+
"description": "The action. Fixed once the limit is created: to change it, create a new limit and archive this one.",
|
|
6125
6357
|
"schema": {
|
|
6126
6358
|
"type": "string",
|
|
6127
6359
|
"minLength": 1,
|
|
6128
6360
|
"maxLength": 100,
|
|
6129
|
-
"description": "The action to limit
|
|
6130
|
-
}
|
|
6131
|
-
},
|
|
6132
|
-
{
|
|
6133
|
-
"name": "amount",
|
|
6134
|
-
"in": "body",
|
|
6135
|
-
"type": "number",
|
|
6136
|
-
"required": false,
|
|
6137
|
-
"description": "How many units each subject may use per window.",
|
|
6138
|
-
"example": 200,
|
|
6139
|
-
"schema": {
|
|
6140
|
-
"type": "integer",
|
|
6141
|
-
"minimum": 1,
|
|
6142
|
-
"maximum": 1e9,
|
|
6143
|
-
"description": "How many units each subject may use per window."
|
|
6361
|
+
"description": "The action. Fixed once the limit is created: to change it, create a new limit and archive this one."
|
|
6144
6362
|
}
|
|
6145
6363
|
},
|
|
6146
6364
|
{
|
|
@@ -6148,13 +6366,12 @@ var OPERATIONS = [
|
|
|
6148
6366
|
"in": "body",
|
|
6149
6367
|
"type": "string",
|
|
6150
6368
|
"required": false,
|
|
6151
|
-
"description": "What the amount counts
|
|
6152
|
-
"example": "cents",
|
|
6369
|
+
"description": "What the amount counts. Fixed once the limit is created: to change it, create a new limit and archive this one.",
|
|
6153
6370
|
"schema": {
|
|
6154
6371
|
"type": "string",
|
|
6155
6372
|
"minLength": 1,
|
|
6156
6373
|
"maxLength": 40,
|
|
6157
|
-
"description": "What the amount counts
|
|
6374
|
+
"description": "What the amount counts. Fixed once the limit is created: to change it, create a new limit and archive this one."
|
|
6158
6375
|
}
|
|
6159
6376
|
},
|
|
6160
6377
|
{
|
|
@@ -6162,8 +6379,7 @@ var OPERATIONS = [
|
|
|
6162
6379
|
"in": "body",
|
|
6163
6380
|
"type": "string",
|
|
6164
6381
|
"required": false,
|
|
6165
|
-
"description": "
|
|
6166
|
-
"example": "month",
|
|
6382
|
+
"description": "The window. Fixed once the limit is created: to change it, create a new limit and archive this one.",
|
|
6167
6383
|
"schema": {
|
|
6168
6384
|
"type": "string",
|
|
6169
6385
|
"enum": [
|
|
@@ -6176,7 +6392,7 @@ var OPERATIONS = [
|
|
|
6176
6392
|
"total",
|
|
6177
6393
|
"concurrent"
|
|
6178
6394
|
],
|
|
6179
|
-
"description": "
|
|
6395
|
+
"description": "The window. Fixed once the limit is created: to change it, create a new limit and archive this one."
|
|
6180
6396
|
}
|
|
6181
6397
|
},
|
|
6182
6398
|
{
|
|
@@ -6184,13 +6400,12 @@ var OPERATIONS = [
|
|
|
6184
6400
|
"in": "body",
|
|
6185
6401
|
"type": "number",
|
|
6186
6402
|
"required": false,
|
|
6187
|
-
"description":
|
|
6188
|
-
"example": 1,
|
|
6403
|
+
"description": "How many windows a period lasts. Fixed once the limit is created: to change it, create a new limit and archive this one.",
|
|
6189
6404
|
"schema": {
|
|
6190
6405
|
"type": "integer",
|
|
6191
6406
|
"minimum": 1,
|
|
6192
6407
|
"maximum": 1e3,
|
|
6193
|
-
"description":
|
|
6408
|
+
"description": "How many windows a period lasts. Fixed once the limit is created: to change it, create a new limit and archive this one."
|
|
6194
6409
|
}
|
|
6195
6410
|
},
|
|
6196
6411
|
{
|
|
@@ -6198,16 +6413,15 @@ var OPERATIONS = [
|
|
|
6198
6413
|
"in": "body",
|
|
6199
6414
|
"type": "string",
|
|
6200
6415
|
"required": false,
|
|
6201
|
-
"description": "Where a period begins.
|
|
6202
|
-
"example": "calendar",
|
|
6416
|
+
"description": "Where a period begins. Fixed once the limit is created: to change it, create a new limit and archive this one.",
|
|
6203
6417
|
"schema": {
|
|
6204
6418
|
"type": "string",
|
|
6205
6419
|
"enum": [
|
|
6206
6420
|
"calendar",
|
|
6207
|
-
"
|
|
6421
|
+
"billing_date",
|
|
6208
6422
|
"first_use"
|
|
6209
6423
|
],
|
|
6210
|
-
"description": "Where a period begins.
|
|
6424
|
+
"description": "Where a period begins. Fixed once the limit is created: to change it, create a new limit and archive this one."
|
|
6211
6425
|
}
|
|
6212
6426
|
},
|
|
6213
6427
|
{
|
|
@@ -6215,36 +6429,10 @@ var OPERATIONS = [
|
|
|
6215
6429
|
"in": "body",
|
|
6216
6430
|
"type": "boolean",
|
|
6217
6431
|
"required": false,
|
|
6218
|
-
"description": "
|
|
6219
|
-
"schema": {
|
|
6220
|
-
"type": "boolean",
|
|
6221
|
-
"description": "Count the last window instead of the calendar one (minute, hour or day only). Default: false."
|
|
6222
|
-
}
|
|
6223
|
-
},
|
|
6224
|
-
{
|
|
6225
|
-
"name": "enabled",
|
|
6226
|
-
"in": "body",
|
|
6227
|
-
"type": "boolean",
|
|
6228
|
-
"required": false,
|
|
6229
|
-
"description": "Whether checks enforce it. Default: true.",
|
|
6432
|
+
"description": "Whether it counts the last window. Fixed once the limit is created: to change it, create a new limit and archive this one.",
|
|
6230
6433
|
"schema": {
|
|
6231
6434
|
"type": "boolean",
|
|
6232
|
-
"description": "Whether
|
|
6233
|
-
}
|
|
6234
|
-
},
|
|
6235
|
-
{
|
|
6236
|
-
"name": "failMode",
|
|
6237
|
-
"in": "body",
|
|
6238
|
-
"type": "string",
|
|
6239
|
-
"required": false,
|
|
6240
|
-
"description": "What your code should do when Limitry can't be reached: `open` (allow) or `closed` (deny). Default: open.",
|
|
6241
|
-
"schema": {
|
|
6242
|
-
"type": "string",
|
|
6243
|
-
"enum": [
|
|
6244
|
-
"open",
|
|
6245
|
-
"closed"
|
|
6246
|
-
],
|
|
6247
|
-
"description": "What your code should do when Limitry can't be reached: `open` (allow) or `closed` (deny). Default: open."
|
|
6435
|
+
"description": "Whether it counts the last window. Fixed once the limit is created: to change it, create a new limit and archive this one."
|
|
6248
6436
|
}
|
|
6249
6437
|
}
|
|
6250
6438
|
],
|
|
@@ -6273,7 +6461,7 @@ var OPERATIONS = [
|
|
|
6273
6461
|
"idempotentHint": false
|
|
6274
6462
|
}
|
|
6275
6463
|
},
|
|
6276
|
-
"description": "
|
|
6464
|
+
"description": "Commits a reservation with the ACTUAL amount used (`cost`): less than reserved gives the rest back at once; more is charged in full \u2014 the work happened. A commit after the reservation expired still charges `cost`. Repeating a commit answers the same. Its API-key check is cached briefly for speed: a revoked key can keep working here for up to 60 seconds.",
|
|
6277
6465
|
"fields": [
|
|
6278
6466
|
{
|
|
6279
6467
|
"name": "reservationId",
|
|
@@ -6323,7 +6511,7 @@ var OPERATIONS = [
|
|
|
6323
6511
|
"idempotentHint": false
|
|
6324
6512
|
}
|
|
6325
6513
|
},
|
|
6326
|
-
"description": "Keeps a
|
|
6514
|
+
"description": "Keeps a reservation for longer work: it now expires `ttlSeconds` from now (default 300, at most 3600) \u2014 call it again as a heartbeat. Only an open reservation can be extended. Its API-key check is cached briefly for speed: a revoked key can keep working here for up to 60 seconds.",
|
|
6327
6515
|
"fields": [
|
|
6328
6516
|
{
|
|
6329
6517
|
"name": "reservationId",
|
|
@@ -6374,7 +6562,7 @@ var OPERATIONS = [
|
|
|
6374
6562
|
"idempotentHint": false
|
|
6375
6563
|
}
|
|
6376
6564
|
},
|
|
6377
|
-
"description": "Gives the whole
|
|
6565
|
+
"description": "Gives the whole reservation back \u2014 the work did not happen. Repeating a release answers the same; releasing a committed reservation is refused. Its API-key check is cached briefly for speed: a revoked key can keep working here for up to 60 seconds.",
|
|
6378
6566
|
"fields": [
|
|
6379
6567
|
{
|
|
6380
6568
|
"name": "reservationId",
|
|
@@ -6412,7 +6600,7 @@ var OPERATIONS = [
|
|
|
6412
6600
|
"idempotentHint": true
|
|
6413
6601
|
}
|
|
6414
6602
|
},
|
|
6415
|
-
"description": "A subject's
|
|
6603
|
+
"description": "A subject's billing date: when its `billing_date` limits' periods start from. A subject is yours (a user, a team, an agent) and exists once a check names it.",
|
|
6416
6604
|
"fields": [
|
|
6417
6605
|
{
|
|
6418
6606
|
"name": "subjectKind",
|
|
@@ -6465,7 +6653,7 @@ var OPERATIONS = [
|
|
|
6465
6653
|
"idempotentHint": false
|
|
6466
6654
|
}
|
|
6467
6655
|
},
|
|
6468
|
-
"description": "
|
|
6656
|
+
"description": "Resets one limit on a subject (`limitId`), or every limit on it (`{}`), at once: for goodwill, a promotion or support. The schedule doesn't move: the next reset is still the usual one. A balance goes back to its amount; a concurrent limit is skipped. Send an Idempotency-Key and a repeat resets once. Owners and admins only, for a person's token.",
|
|
6469
6657
|
"fields": [
|
|
6470
6658
|
{
|
|
6471
6659
|
"name": "subjectKind",
|
|
@@ -6497,7 +6685,7 @@ var OPERATIONS = [
|
|
|
6497
6685
|
"type": "string",
|
|
6498
6686
|
"required": false,
|
|
6499
6687
|
"description": "Just this limit. Default: every limit on the subject.",
|
|
6500
|
-
"example": "
|
|
6688
|
+
"example": "lmt_3f0c\u2026",
|
|
6501
6689
|
"schema": {
|
|
6502
6690
|
"type": "string",
|
|
6503
6691
|
"description": "Just this limit. Default: every limit on the subject."
|
|
@@ -6512,7 +6700,7 @@ var OPERATIONS = [
|
|
|
6512
6700
|
"operationId": "subjects.update",
|
|
6513
6701
|
"method": "patch",
|
|
6514
6702
|
"path": "/subjects/{subjectKind}/{subjectId}",
|
|
6515
|
-
"summary": "Set a subject's
|
|
6703
|
+
"summary": "Set a subject's billing date",
|
|
6516
6704
|
"cli": {
|
|
6517
6705
|
"command": "subjects update",
|
|
6518
6706
|
"args": [
|
|
@@ -6530,7 +6718,7 @@ var OPERATIONS = [
|
|
|
6530
6718
|
"idempotentHint": false
|
|
6531
6719
|
}
|
|
6532
6720
|
},
|
|
6533
|
-
"description": "Sets when a subject's `
|
|
6721
|
+
"description": "Sets when a subject's `billing_date` limits' periods start from: typically its subscription's start date, from your billing system's webhook, so its allowance resets on its own billing day (monthly for an annual plan, too). Owners and admins only, for a person's token.",
|
|
6534
6722
|
"fields": [
|
|
6535
6723
|
{
|
|
6536
6724
|
"name": "subjectKind",
|
|
@@ -6557,7 +6745,7 @@ var OPERATIONS = [
|
|
|
6557
6745
|
}
|
|
6558
6746
|
},
|
|
6559
6747
|
{
|
|
6560
|
-
"name": "
|
|
6748
|
+
"name": "billingDate",
|
|
6561
6749
|
"in": "body",
|
|
6562
6750
|
"type": "string",
|
|
6563
6751
|
"required": true,
|
|
@@ -6593,7 +6781,7 @@ var OPERATIONS = [
|
|
|
6593
6781
|
"idempotentHint": true
|
|
6594
6782
|
}
|
|
6595
6783
|
},
|
|
6596
|
-
"description": "Units used, checks allowed and
|
|
6784
|
+
"description": "Units used, checks allowed and refused for one limit \u2014 across all subjects, or one (`subject`, as `kind:id`) \u2014 per hour or per day (UTC), every bucket in the range included. Up to about a minute behind live checks. Default: the last 30 days, by day.",
|
|
6597
6785
|
"fields": [
|
|
6598
6786
|
{
|
|
6599
6787
|
"name": "limitId",
|
|
@@ -6601,34 +6789,24 @@ var OPERATIONS = [
|
|
|
6601
6789
|
"type": "string",
|
|
6602
6790
|
"required": true,
|
|
6603
6791
|
"description": "The limit.",
|
|
6604
|
-
"example": "
|
|
6792
|
+
"example": "lmt_3f0c\u2026",
|
|
6605
6793
|
"schema": {
|
|
6606
6794
|
"type": "string",
|
|
6607
6795
|
"description": "The limit."
|
|
6608
6796
|
}
|
|
6609
6797
|
},
|
|
6610
6798
|
{
|
|
6611
|
-
"name": "
|
|
6612
|
-
"in": "query",
|
|
6613
|
-
"type": "string",
|
|
6614
|
-
"required": false,
|
|
6615
|
-
"description": "With `subjectId`: one subject's usage, not every subject's.",
|
|
6616
|
-
"example": "user",
|
|
6617
|
-
"schema": {
|
|
6618
|
-
"type": "string",
|
|
6619
|
-
"description": "With `subjectId`: one subject's usage, not every subject's."
|
|
6620
|
-
}
|
|
6621
|
-
},
|
|
6622
|
-
{
|
|
6623
|
-
"name": "subjectId",
|
|
6799
|
+
"name": "subject",
|
|
6624
6800
|
"in": "query",
|
|
6625
6801
|
"type": "string",
|
|
6626
6802
|
"required": false,
|
|
6627
|
-
"description": "
|
|
6628
|
-
"example": "usr_123",
|
|
6803
|
+
"description": "One subject's usage, not every subject's, as `kind:id`.",
|
|
6804
|
+
"example": "user:usr_123",
|
|
6629
6805
|
"schema": {
|
|
6630
6806
|
"type": "string",
|
|
6631
|
-
"
|
|
6807
|
+
"minLength": 3,
|
|
6808
|
+
"maxLength": 301,
|
|
6809
|
+
"description": "One subject's usage, not every subject's, as `kind:id`."
|
|
6632
6810
|
}
|
|
6633
6811
|
},
|
|
6634
6812
|
{
|
|
@@ -6697,34 +6875,20 @@ var OPERATIONS = [
|
|
|
6697
6875
|
"idempotentHint": true
|
|
6698
6876
|
}
|
|
6699
6877
|
},
|
|
6700
|
-
"description": "Every enabled limit on one subject \u2014 and on its shared subjects (`shared`, comma-separated `kind:id`, such as `team:team_42`) \u2014 with what is used, what is left and when it resets, exact as of now. For showing an end user where they stand: call it from your server with your key, never from a browser. Not a check: nothing is counted. A subject with no limit here answers an empty `limits` list.",
|
|
6878
|
+
"description": "Every enabled limit on one subject (`subject`, as `kind:id`, such as `user:usr_123`) \u2014 and on its shared subjects (`shared`, comma-separated `kind:id`, such as `team:team_42`) \u2014 with what is used, what is left and when it resets, exact as of now. For showing an end user where they stand: call it from your server with your key, never from a browser. Not a check: nothing is counted. A subject with no limit here answers an empty `limits` list.",
|
|
6701
6879
|
"fields": [
|
|
6702
6880
|
{
|
|
6703
|
-
"name": "
|
|
6704
|
-
"in": "query",
|
|
6705
|
-
"type": "string",
|
|
6706
|
-
"required": true,
|
|
6707
|
-
"description": "The subject's kind, as your checks send it.",
|
|
6708
|
-
"example": "user",
|
|
6709
|
-
"schema": {
|
|
6710
|
-
"type": "string",
|
|
6711
|
-
"minLength": 1,
|
|
6712
|
-
"maxLength": 100,
|
|
6713
|
-
"description": "The subject's kind, as your checks send it."
|
|
6714
|
-
}
|
|
6715
|
-
},
|
|
6716
|
-
{
|
|
6717
|
-
"name": "id",
|
|
6881
|
+
"name": "subject",
|
|
6718
6882
|
"in": "query",
|
|
6719
6883
|
"type": "string",
|
|
6720
6884
|
"required": true,
|
|
6721
|
-
"description": "The subject
|
|
6722
|
-
"example": "usr_123",
|
|
6885
|
+
"description": "The subject, as `kind:id`: its kind and id as your checks send them.",
|
|
6886
|
+
"example": "user:usr_123",
|
|
6723
6887
|
"schema": {
|
|
6724
6888
|
"type": "string",
|
|
6725
|
-
"minLength":
|
|
6726
|
-
"maxLength":
|
|
6727
|
-
"description": "The subject
|
|
6889
|
+
"minLength": 3,
|
|
6890
|
+
"maxLength": 301,
|
|
6891
|
+
"description": "The subject, as `kind:id`: its kind and id as your checks send them."
|
|
6728
6892
|
}
|
|
6729
6893
|
},
|
|
6730
6894
|
{
|
|
@@ -6763,7 +6927,7 @@ var OPERATIONS = [
|
|
|
6763
6927
|
"idempotentHint": true
|
|
6764
6928
|
}
|
|
6765
6929
|
},
|
|
6766
|
-
"description": "A limit's subjects in its CURRENT window, most used first: units used, what is left, how many checks
|
|
6930
|
+
"description": "A limit's subjects in its CURRENT window, most used first: units used, what is left, and how many checks it refused. Up to about a minute behind live checks.",
|
|
6767
6931
|
"fields": [
|
|
6768
6932
|
{
|
|
6769
6933
|
"name": "limitId",
|
|
@@ -6771,7 +6935,7 @@ var OPERATIONS = [
|
|
|
6771
6935
|
"type": "string",
|
|
6772
6936
|
"required": true,
|
|
6773
6937
|
"description": "The limit.",
|
|
6774
|
-
"example": "
|
|
6938
|
+
"example": "lmt_3f0c\u2026",
|
|
6775
6939
|
"schema": {
|
|
6776
6940
|
"type": "string",
|
|
6777
6941
|
"description": "The limit."
|
|
@@ -7278,7 +7442,7 @@ var OPERATIONS = [
|
|
|
7278
7442
|
"idempotentHint": true
|
|
7279
7443
|
}
|
|
7280
7444
|
},
|
|
7281
|
-
"description": "How much of each meter the workspace used this period, with the plan's limit for it (null = unlimited). A period is a month from the workspace's billing date: its subscription's (an annual plan
|
|
7445
|
+
"description": "How much of each meter the workspace used this period, with the plan's limit for it (null = unlimited). A period is a month from the workspace's billing date: its subscription's (an annual plan's counts reset monthly from its start), else the day the workspace was created.",
|
|
7282
7446
|
"fields": [],
|
|
7283
7447
|
"hasBody": false,
|
|
7284
7448
|
"workspace": true,
|
|
@@ -7628,6 +7792,89 @@ var OPERATIONS = [
|
|
|
7628
7792
|
"hasBody": false,
|
|
7629
7793
|
"workspace": true,
|
|
7630
7794
|
"scope": "workspace.webhooks:write"
|
|
7795
|
+
},
|
|
7796
|
+
{
|
|
7797
|
+
"operationId": "workspace.webhookEndpoints.update",
|
|
7798
|
+
"method": "patch",
|
|
7799
|
+
"path": "/workspace/webhook-endpoints/{endpointId}",
|
|
7800
|
+
"summary": "Update a webhook endpoint",
|
|
7801
|
+
"cli": {
|
|
7802
|
+
"command": "workspace webhook-endpoints update",
|
|
7803
|
+
"args": [
|
|
7804
|
+
"endpointId"
|
|
7805
|
+
],
|
|
7806
|
+
"confirm": false
|
|
7807
|
+
},
|
|
7808
|
+
"mcp": {
|
|
7809
|
+
"exposed": false,
|
|
7810
|
+
"reason": "Changes where workspace data is sent. A person configures webhook endpoints (Settings \u2192 Webhooks in the app)."
|
|
7811
|
+
},
|
|
7812
|
+
"description": "Changes an endpoint's URL, description or event types in place; only the fields sent change. The endpoint keeps its signing secret, so receivers keep verifying deliveries. A new URL passes the same checks as on create: https only, no private hosts.",
|
|
7813
|
+
"fields": [
|
|
7814
|
+
{
|
|
7815
|
+
"name": "endpointId",
|
|
7816
|
+
"in": "path",
|
|
7817
|
+
"type": "string",
|
|
7818
|
+
"required": true,
|
|
7819
|
+
"example": "we_3f0c\u2026",
|
|
7820
|
+
"schema": {
|
|
7821
|
+
"type": "string"
|
|
7822
|
+
}
|
|
7823
|
+
},
|
|
7824
|
+
{
|
|
7825
|
+
"name": "url",
|
|
7826
|
+
"in": "body",
|
|
7827
|
+
"type": "string",
|
|
7828
|
+
"required": false,
|
|
7829
|
+
"description": "The https URL that receives the events.",
|
|
7830
|
+
"example": "https://example.com/hooks",
|
|
7831
|
+
"schema": {
|
|
7832
|
+
"type": "string",
|
|
7833
|
+
"minLength": 1,
|
|
7834
|
+
"maxLength": 2048,
|
|
7835
|
+
"description": "The https URL that receives the events."
|
|
7836
|
+
}
|
|
7837
|
+
},
|
|
7838
|
+
{
|
|
7839
|
+
"name": "description",
|
|
7840
|
+
"in": "body",
|
|
7841
|
+
"type": "string",
|
|
7842
|
+
"required": false,
|
|
7843
|
+
"description": "A note for people managing the endpoint; null clears it.",
|
|
7844
|
+
"schema": {
|
|
7845
|
+
"type": [
|
|
7846
|
+
"string",
|
|
7847
|
+
"null"
|
|
7848
|
+
],
|
|
7849
|
+
"maxLength": 200,
|
|
7850
|
+
"description": "A note for people managing the endpoint; null clears it."
|
|
7851
|
+
}
|
|
7852
|
+
},
|
|
7853
|
+
{
|
|
7854
|
+
"name": "eventTypes",
|
|
7855
|
+
"in": "body",
|
|
7856
|
+
"type": "json",
|
|
7857
|
+
"required": false,
|
|
7858
|
+
"description": "Only these event types (see event-types); null or an empty list for every event.",
|
|
7859
|
+
"example": [
|
|
7860
|
+
"workspace.member.joined"
|
|
7861
|
+
],
|
|
7862
|
+
"schema": {
|
|
7863
|
+
"type": [
|
|
7864
|
+
"array",
|
|
7865
|
+
"null"
|
|
7866
|
+
],
|
|
7867
|
+
"items": {
|
|
7868
|
+
"type": "string"
|
|
7869
|
+
},
|
|
7870
|
+
"maxItems": 100,
|
|
7871
|
+
"description": "Only these event types (see event-types); null or an empty list for every event."
|
|
7872
|
+
}
|
|
7873
|
+
}
|
|
7874
|
+
],
|
|
7875
|
+
"hasBody": true,
|
|
7876
|
+
"workspace": true,
|
|
7877
|
+
"scope": "workspace.webhooks:write"
|
|
7631
7878
|
}
|
|
7632
7879
|
];
|
|
7633
7880
|
|
|
@@ -7850,11 +8097,61 @@ function print(ctx, data, asJson) {
|
|
|
7850
8097
|
ctx.io.stdout(String(data));
|
|
7851
8098
|
}
|
|
7852
8099
|
|
|
8100
|
+
// src/product/check.ts
|
|
8101
|
+
var checkCommand = (program2, ctx) => {
|
|
8102
|
+
program2.command("check").description(`Short for \`${brand.name} checks create\``).argument("<subject>", "who is acting, as kind:id (user:usr_123)").argument("<action>", "what they want to do (ai-call)").option("--cost <n>", "units it would use (default 1)").option(
|
|
8103
|
+
"--shared <kind:id>",
|
|
8104
|
+
"a shared subject it also draws from (a team's pool); repeat for more",
|
|
8105
|
+
(value, previous = []) => [...previous, value]
|
|
8106
|
+
).option("--workspace <slug>", "act in this workspace for one call").option("--json", "the decision as the API answers it").addHelpText(
|
|
8107
|
+
"after",
|
|
8108
|
+
`
|
|
8109
|
+
Example: ${brand.name} check user:usr_123 ai-call --cost 5
|
|
8110
|
+
A refusal exits 0: it's an answer. Errors exit 1.`
|
|
8111
|
+
).action(
|
|
8112
|
+
async (subject, action, options) => {
|
|
8113
|
+
const cost = options.cost === void 0 ? void 0 : Number(options.cost);
|
|
8114
|
+
if (cost !== void 0 && !Number.isInteger(cost)) {
|
|
8115
|
+
throw new Error("--cost must be a whole number");
|
|
8116
|
+
}
|
|
8117
|
+
const decision = await ctx.client({ workspace: options.workspace }).checks.create(
|
|
8118
|
+
{
|
|
8119
|
+
subject: parseSubject(subject),
|
|
8120
|
+
action,
|
|
8121
|
+
...cost !== void 0 ? { cost } : {},
|
|
8122
|
+
...options.shared?.length ? { shared: options.shared.map(parseSubject) } : {}
|
|
8123
|
+
},
|
|
8124
|
+
{ idempotencyKey: crypto.randomUUID() }
|
|
8125
|
+
);
|
|
8126
|
+
if (!decision) throw new Error("Limitry answered without a decision");
|
|
8127
|
+
ctx.io.stdout(options.json ? json(decision) : answer(decision));
|
|
8128
|
+
}
|
|
8129
|
+
);
|
|
8130
|
+
};
|
|
8131
|
+
function parseSubject(value) {
|
|
8132
|
+
const at = value.indexOf(":");
|
|
8133
|
+
if (at <= 0 || at === value.length - 1) {
|
|
8134
|
+
throw new Error(
|
|
8135
|
+
`"${value}": write a subject as kind:id, e.g. user:usr_123`
|
|
8136
|
+
);
|
|
8137
|
+
}
|
|
8138
|
+
return { kind: value.slice(0, at), id: value.slice(at + 1) };
|
|
8139
|
+
}
|
|
8140
|
+
var left = (r) => `${r.name}: ${r.remaining} ${r.unit} left${r.resetsAt ? `, resets ${r.resetsAt}` : ""}`;
|
|
8141
|
+
function answer(decision) {
|
|
8142
|
+
if (decision.allowed) {
|
|
8143
|
+
return decision.limits.length === 0 ? "Allowed. No limit applies." : `Allowed. ${decision.limits.map(left).join("; ")}`;
|
|
8144
|
+
}
|
|
8145
|
+
return decision.reason?.message ?? "Refused.";
|
|
8146
|
+
}
|
|
8147
|
+
|
|
7853
8148
|
// src/product/limits-sync.ts
|
|
7854
8149
|
import { readFileSync as readFileSync4 } from "node:fs";
|
|
7855
8150
|
import { resolve } from "node:path";
|
|
7856
8151
|
var limitsSyncCommand = (program2, ctx) => {
|
|
7857
|
-
const group = program2.commands.find((c) => c.name() === "limits") ?? program2.command("limits").description(
|
|
8152
|
+
const group = program2.commands.find((c) => c.name() === "limits") ?? program2.command("limits").description(
|
|
8153
|
+
"archive, create, credits, get, list, restore, sync, update"
|
|
8154
|
+
);
|
|
7858
8155
|
syncCommand(
|
|
7859
8156
|
group.command("sync"),
|
|
7860
8157
|
ctx,
|
|
@@ -7869,27 +8166,21 @@ Shortcut: \`${brand.name} sync\`, the same command.`
|
|
|
7869
8166
|
""
|
|
7870
8167
|
);
|
|
7871
8168
|
};
|
|
7872
|
-
function clientFor(ctx, workspace2) {
|
|
7873
|
-
const token = ctx.settings().token ?? "";
|
|
7874
|
-
return ctx.client({
|
|
7875
|
-
workspace: token.startsWith("pat_") ? workspace2 : false
|
|
7876
|
-
});
|
|
7877
|
-
}
|
|
7878
8169
|
function syncCommand(command, ctx, description, more) {
|
|
7879
|
-
command.description(description).argument("[file]", "the file to read", "limitry.json").option("--
|
|
8170
|
+
command.description(description).argument("[file]", "the file to read", "limitry.json").option("--preview", "show what would change, and change nothing").option("--limits <json>", "the limits as a JSON array, instead of a file").option(
|
|
7880
8171
|
"--archive-missing",
|
|
7881
8172
|
"archive active limits the file doesn't name (restorable)"
|
|
7882
8173
|
).option("--workspace <slug>", "act in this workspace for one call").option("--json", "machine-readable output").addHelpText(
|
|
7883
8174
|
"after",
|
|
7884
|
-
'\nThe file: { "limits": [ { "name": "AI budget", "
|
|
8175
|
+
'\nThe file: { "limits": [ { "name": "AI budget", "subject": { "kind": "user" }, "action": "ai-call", "amount": 200, "unit": "cents", "window": "month" } ] }\nEach limit is described whole: a field left out is its default, as on `limits create`. Names are the key.\nWhat a limit counts (subject, action, unit, window, every, start, rolling) is fixed: to change it, give the entry a new name.' + more
|
|
7885
8176
|
).action(
|
|
7886
8177
|
async (file, options) => {
|
|
7887
8178
|
const limits = options.limits === void 0 ? readLimitsFile(file) : parseLimits(options.limits, "--limits");
|
|
7888
|
-
const result = await
|
|
8179
|
+
const result = await ctx.client({ workspace: options.workspace }).limits.sync(
|
|
7889
8180
|
{
|
|
7890
8181
|
limits,
|
|
7891
8182
|
archiveMissing: options.archiveMissing ?? false,
|
|
7892
|
-
|
|
8183
|
+
preview: options.preview ?? false
|
|
7893
8184
|
},
|
|
7894
8185
|
{ idempotencyKey: crypto.randomUUID() }
|
|
7895
8186
|
);
|
|
@@ -7939,7 +8230,7 @@ function parseLimits(text, flag2) {
|
|
|
7939
8230
|
}
|
|
7940
8231
|
var show = (value) => typeof value === "string" ? value : JSON.stringify(value);
|
|
7941
8232
|
function summary(result) {
|
|
7942
|
-
const dry = result.
|
|
8233
|
+
const dry = result.preview;
|
|
7943
8234
|
const lines = [
|
|
7944
8235
|
...result.created.map(
|
|
7945
8236
|
(name) => `${dry ? "Would create" : "Created"}: ${name}`
|
|
@@ -7959,64 +8250,10 @@ function summary(result) {
|
|
|
7959
8250
|
];
|
|
7960
8251
|
}
|
|
7961
8252
|
if (same2 > 0) lines.push(`Unchanged: ${same2}`);
|
|
7962
|
-
if (dry) lines.push("
|
|
8253
|
+
if (dry) lines.push("Preview: nothing was changed.");
|
|
7963
8254
|
return lines;
|
|
7964
8255
|
}
|
|
7965
8256
|
|
|
7966
|
-
// src/product/check.ts
|
|
7967
|
-
var checkCommand = (program2, ctx) => {
|
|
7968
|
-
program2.command("check").description(`Short for \`${brand.name} checks create\``).argument("<subject>", "who is acting, as kind:id (user:usr_123)").argument("<action>", "what they want to do (ai-call)").option("--cost <n>", "units it would use (default 1)").option(
|
|
7969
|
-
"--shared <kind:id>",
|
|
7970
|
-
"a shared subject it also draws from (a team's pool); repeat for more",
|
|
7971
|
-
(value, previous = []) => [...previous, value]
|
|
7972
|
-
).option("--workspace <slug>", "act in this workspace for one call").option("--json", "the decision as the API answers it").addHelpText(
|
|
7973
|
-
"after",
|
|
7974
|
-
`
|
|
7975
|
-
Example: ${brand.name} check user:usr_123 ai-call --cost 5
|
|
7976
|
-
A refusal exits 0: it's an answer. Errors exit 1.`
|
|
7977
|
-
).action(
|
|
7978
|
-
async (subject, action, options) => {
|
|
7979
|
-
const cost = options.cost === void 0 ? void 0 : Number(options.cost);
|
|
7980
|
-
if (cost !== void 0 && !Number.isInteger(cost)) {
|
|
7981
|
-
throw new Error("--cost must be a whole number");
|
|
7982
|
-
}
|
|
7983
|
-
const decision = await clientFor(ctx, options.workspace).checks.create(
|
|
7984
|
-
{
|
|
7985
|
-
subject: parseSubject(subject),
|
|
7986
|
-
action,
|
|
7987
|
-
...cost !== void 0 ? { cost } : {},
|
|
7988
|
-
...options.shared?.length ? { shared: options.shared.map(parseSubject) } : {}
|
|
7989
|
-
},
|
|
7990
|
-
{ idempotencyKey: crypto.randomUUID() }
|
|
7991
|
-
);
|
|
7992
|
-
ctx.io.stdout(options.json ? json(decision) : answer(decision));
|
|
7993
|
-
}
|
|
7994
|
-
);
|
|
7995
|
-
};
|
|
7996
|
-
function parseSubject(value) {
|
|
7997
|
-
const at = value.indexOf(":");
|
|
7998
|
-
if (at <= 0 || at === value.length - 1) {
|
|
7999
|
-
throw new Error(
|
|
8000
|
-
`"${value}": write a subject as kind:id, e.g. user:usr_123`
|
|
8001
|
-
);
|
|
8002
|
-
}
|
|
8003
|
-
return { kind: value.slice(0, at), id: value.slice(at + 1) };
|
|
8004
|
-
}
|
|
8005
|
-
var left = (r) => `${r.name}: ${r.remaining} ${r.unit} left${r.resetsAt ? `, resets ${r.resetsAt}` : ""}`;
|
|
8006
|
-
function answer(decision) {
|
|
8007
|
-
if (decision.allowed) {
|
|
8008
|
-
return decision.remaining.length === 0 ? "Allowed. No limit applies." : `Allowed. ${decision.remaining.map(left).join("; ")}`;
|
|
8009
|
-
}
|
|
8010
|
-
const retry = decision.retryAfterSeconds !== null ? ` Try again in ${decision.retryAfterSeconds} s.` : "";
|
|
8011
|
-
if (decision.reason?.code === "too_many_reservations") {
|
|
8012
|
-
return `Refused: too many open reservations for this subject.${retry}`;
|
|
8013
|
-
}
|
|
8014
|
-
const limit = decision.remaining.find(
|
|
8015
|
-
(r) => r.limit === decision.reason?.limit
|
|
8016
|
-
);
|
|
8017
|
-
return limit ? `Refused by ${left(limit)}.${retry}` : `Refused: a limit is used up.${retry}`;
|
|
8018
|
-
}
|
|
8019
|
-
|
|
8020
8257
|
// src/product/index.ts
|
|
8021
8258
|
var productCommands = [limitsSyncCommand, checkCommand];
|
|
8022
8259
|
|
|
@@ -8034,7 +8271,7 @@ function tokenEnvVar() {
|
|
|
8034
8271
|
function build(io) {
|
|
8035
8272
|
let actedIn = null;
|
|
8036
8273
|
let sending;
|
|
8037
|
-
const program2 = new Command().name(brand.name).description(`${brand.productName} command line`).version("1.0.0-rc.
|
|
8274
|
+
const program2 = new Command().name(brand.name).description(`${brand.productName} command line`).version("1.0.0-rc.10").addHelpText(
|
|
8038
8275
|
"after",
|
|
8039
8276
|
`
|
|
8040
8277
|
Token: \`${brand.name} login\` stores it in ~/.config/${brand.name}/; ${tokenEnvVar()} overrides.
|