agl 40.4.0 → 40.5.1
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 +33 -0
- package/dist_serve/bundle.js +2228 -2177
- package/dist_serve/bundle.js.map +2 -2
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/aglapi/aglapisurface.document.js +2 -2
- package/dist_ts/classes.accountsactions.d.ts +11 -1
- package/dist_ts/classes.accountsactions.js +59 -2
- package/dist_ts/classes.controller.js +5 -5
- package/dist_ts/classes.flexaccountaccess.js +3 -2
- package/dist_ts/classes.harnessreleases.d.ts +14 -4
- package/dist_ts/classes.harnessreleases.js +28 -4
- package/dist_ts/classes.inferencegateway.d.ts +28 -3
- package/dist_ts/classes.inferencegateway.js +177 -61
- package/dist_ts/classes.inferenceplacement.d.ts +5 -3
- package/dist_ts/classes.inferenceplacement.js +2 -2
- package/dist_ts/classes.inferencerouter.d.ts +349 -91
- package/dist_ts/classes.inferencerouter.js +804 -297
- package/dist_ts/classes.inferenceservice.d.ts +14 -2
- package/dist_ts/classes.inferenceservice.js +53 -14
- package/dist_ts/classes.inferencespend.d.ts +339 -0
- package/dist_ts/classes.inferencespend.js +815 -0
- package/dist_ts/classes.inferenceusagecache.d.ts +8 -0
- package/dist_ts/classes.inferenceusagecache.js +9 -5
- package/dist_ts/classes.inferenceusagetap.d.ts +50 -9
- package/dist_ts/classes.inferenceusagetap.js +185 -31
- package/dist_ts/classes.proxycontrol.d.ts +3 -2
- package/dist_ts/classes.proxycontrol.js +1 -2
- package/dist_ts/classes.proxydaemon.js +3 -2
- package/dist_ts/classes.proxystore.d.ts +6 -0
- package/dist_ts/classes.proxystore.js +11 -2
- package/dist_ts/fleet/classes.claudeworkers.d.ts +5 -4
- package/dist_ts/fleet/classes.claudeworkers.js +10 -9
- package/dist_ts/functions.claudecoderelease.d.ts +12 -6
- package/dist_ts/functions.claudecoderelease.js +13 -7
- package/dist_ts/functions.inferencecli.js +12 -8
- package/dist_ts/interfaces.auth.d.ts +1 -1
- package/dist_ts/interfaces.auth.js +3 -1
- package/dist_ts/plugins.d.ts +3 -1
- package/dist_ts/plugins.js +7 -2
- package/dist_ts_authswitch/authority-apikeys.d.ts +32 -0
- package/dist_ts_authswitch/authority-apikeys.js +65 -0
- package/dist_ts_authswitch/authority-contract.d.ts +172 -33
- package/dist_ts_authswitch/authority-contract.js +54 -1
- package/dist_ts_authswitch/authority-overview.js +8 -1
- package/dist_ts_authswitch/authority-placement.d.ts +7 -2
- package/dist_ts_authswitch/authority-placement.js +10 -3
- package/dist_ts_authswitch/authority-runtime-contract.d.ts +2 -2
- package/dist_ts_authswitch/authority-spend.d.ts +103 -0
- package/dist_ts_authswitch/authority-spend.js +110 -0
- package/dist_ts_authswitch/authority-subscription.d.ts +12 -1
- package/dist_ts_authswitch/authority-subscription.js +24 -1
- package/dist_ts_authswitch/authority-usagelimit.d.ts +7 -4
- package/dist_ts_authswitch/authority-usagelimit.js +89 -39
- package/dist_ts_authswitch/authority-usagewindows.d.ts +4 -1
- package/dist_ts_authswitch/authority-usagewindows.js +41 -16
- package/dist_ts_authswitch/classes.authoritybroker.d.ts +30 -19
- package/dist_ts_authswitch/classes.authoritybroker.js +152 -61
- package/dist_ts_authswitch/classes.authoritycli.d.ts +9 -4
- package/dist_ts_authswitch/classes.authoritycli.js +99 -30
- package/dist_ts_authswitch/classes.authorityclient.d.ts +24 -7
- package/dist_ts_authswitch/classes.authorityclient.js +45 -15
- package/dist_ts_authswitch/classes.authoritydaemon.js +39 -12
- package/dist_ts_authswitch/classes.authoritydatabase.d.ts +28 -5
- package/dist_ts_authswitch/classes.authoritydatabase.js +171 -9
- package/dist_ts_authswitch/classes.authorityimport.js +2 -2
- package/dist_ts_authswitch/classes.authoritymodels.d.ts +71 -3
- package/dist_ts_authswitch/classes.authoritymodels.js +249 -20
- package/dist_ts_authswitch/classes.authorityregistry.js +4 -2
- package/dist_ts_authswitch/classes.authorityusage.d.ts +69 -7
- package/dist_ts_authswitch/classes.authorityusage.js +118 -4
- package/dist_ts_authswitch/classes.claudenative.d.ts +23 -8
- package/dist_ts_authswitch/classes.claudenative.js +49 -21
- package/dist_ts_authswitch/classes.claudesignin.d.ts +14 -2
- package/dist_ts_authswitch/classes.claudesignin.js +72 -23
- package/dist_ts_authswitch/classes.codexmanaged.d.ts +8 -0
- package/dist_ts_authswitch/classes.codexmanaged.js +33 -18
- package/dist_ts_authswitch/classes.harnessprocesses.d.ts +8 -0
- package/dist_ts_authswitch/classes.harnessprocesses.js +41 -9
- package/dist_ts_authswitch/testsupport.d.ts +24 -5
- package/dist_ts_authswitch/testsupport.js +56 -12
- package/dist_ts_authswitch/ts_migration/0011_account_api_key_fields.d.ts +12 -0
- package/dist_ts_authswitch/ts_migration/0011_account_api_key_fields.js +21 -0
- package/dist_ts_authswitch/ts_migration/index.js +3 -1
- package/dist_ts_interfaces/functions.authorityscope.d.ts +18 -7
- package/dist_ts_interfaces/functions.authorityscope.js +35 -8
- package/dist_ts_interfaces/interfaces.d.ts +1 -1
- package/dist_ts_interfaces/interfaces.js +1 -1
- package/dist_ts_interfaces/plugins.d.ts +2 -1
- package/dist_ts_interfaces/plugins.js +7 -4
- package/dist_ts_interfaces/requests.accounts.d.ts +56 -0
- package/dist_ts_interfaces/requests.accounts.js +11 -1
- package/dist_ts_interfaces/requests.d.ts +2 -2
- package/dist_ts_interfaces/requests.js +1 -1
- package/docs/authswitch.md +75 -12
- package/package.json +5 -5
- package/readme.md +199 -22
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/aglapi/aglapisurface.document.ts +2 -2
- package/ts/classes.accountsactions.ts +75 -1
- package/ts/classes.controller.ts +4 -4
- package/ts/classes.flexaccountaccess.ts +2 -1
- package/ts/classes.harnessreleases.ts +25 -4
- package/ts/classes.inferencegateway.ts +184 -64
- package/ts/classes.inferenceplacement.ts +6 -4
- package/ts/classes.inferencerouter.ts +1026 -314
- package/ts/classes.inferenceservice.ts +56 -13
- package/ts/classes.inferencespend.ts +870 -0
- package/ts/classes.inferenceusagecache.ts +16 -4
- package/ts/classes.inferenceusagetap.ts +159 -34
- package/ts/classes.proxycontrol.ts +3 -3
- package/ts/classes.proxydaemon.ts +2 -1
- package/ts/classes.proxystore.ts +11 -1
- package/ts/fleet/classes.claudeworkers.ts +9 -8
- package/ts/functions.claudecoderelease.ts +13 -6
- package/ts/functions.inferencecli.ts +11 -7
- package/ts/interfaces.auth.ts +2 -0
- package/ts/plugins.ts +7 -0
- package/ts_authswitch/authority-apikeys.ts +85 -0
- package/ts_authswitch/authority-contract.ts +201 -34
- package/ts_authswitch/authority-overview.ts +7 -0
- package/ts_authswitch/authority-placement.ts +12 -4
- package/ts_authswitch/authority-runtime-contract.ts +2 -2
- package/ts_authswitch/authority-spend.ts +168 -0
- package/ts_authswitch/authority-subscription.ts +28 -1
- package/ts_authswitch/authority-usagelimit.ts +95 -40
- package/ts_authswitch/authority-usagewindows.ts +42 -17
- package/ts_authswitch/classes.authoritybroker.ts +161 -68
- package/ts_authswitch/classes.authoritycli.ts +112 -32
- package/ts_authswitch/classes.authorityclient.ts +66 -19
- package/ts_authswitch/classes.authoritydaemon.ts +43 -13
- package/ts_authswitch/classes.authoritydatabase.ts +178 -8
- package/ts_authswitch/classes.authorityimport.ts +1 -1
- package/ts_authswitch/classes.authoritymodels.ts +165 -19
- package/ts_authswitch/classes.authorityregistry.ts +3 -0
- package/ts_authswitch/classes.authorityusage.ts +171 -10
- package/ts_authswitch/classes.claudenative.ts +51 -22
- package/ts_authswitch/classes.claudesignin.ts +74 -24
- package/ts_authswitch/classes.codexmanaged.ts +30 -16
- package/ts_authswitch/classes.harnessprocesses.ts +39 -8
- package/ts_authswitch/native-contracts.md +82 -21
- package/ts_authswitch/readme.md +1 -1
- package/ts_authswitch/testsupport.ts +58 -11
- package/ts_authswitch/ts_migration/0011_account_api_key_fields.ts +20 -0
- package/ts_authswitch/ts_migration/index.ts +2 -0
- package/ts_interfaces/functions.authorityscope.ts +43 -8
- package/ts_interfaces/interfaces.ts +1 -1
- package/ts_interfaces/plugins.ts +6 -3
- package/ts_interfaces/requests.accounts.ts +48 -0
- package/ts_interfaces/requests.ts +4 -0
- package/ts_web/00_commitinfo_data.ts +1 -1
- package/ts_web/accounts.plugins.ts +7 -1
- package/ts_web/accounts.templates.ts +20 -11
- package/ts_web/classes.accountsreadmodel.ts +326 -71
- package/ts_web/elements.accounts.ts +219 -20
- package/ts_web/elements.codexconnections.ts +3 -1
- package/ts_web/plugins.ts +4 -2
|
@@ -11,28 +11,51 @@ const openAiWindows = (limitNameArg, detailsArg) => ([detailsArg?.primaryWindow,
|
|
|
11
11
|
estimatedUsedPercent: windowArg.estimated ? windowArg.estimatedUsedPercent ?? null : null,
|
|
12
12
|
resetAt: new Date(windowArg.resetsAt * 1000).toISOString(),
|
|
13
13
|
})));
|
|
14
|
+
/** The name of an API key's one window, its spend in the calendar month against its limit. */
|
|
15
|
+
export const authSwitchSpendWindowLabel = 'Monthly spend';
|
|
14
16
|
/**
|
|
15
17
|
* The windows of a reading: for ChatGPT the main limit's two windows, then each named extra limit's; for Claude the
|
|
16
|
-
* windows as the service reported them
|
|
18
|
+
* windows as the service reported them; for an API key with a spend limit one account window, the month's spend in
|
|
19
|
+
* percent of the limit, which resets when the month ends -- a key without a limit has none. A missing reading has none.
|
|
17
20
|
*/
|
|
18
21
|
export const authSwitchUsageWindows = (readingArg) => {
|
|
19
22
|
if (readingArg === null)
|
|
20
23
|
return [];
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
switch (readingArg.kind) {
|
|
25
|
+
case 'openai':
|
|
26
|
+
return [
|
|
27
|
+
...openAiWindows(null, readingArg.rateLimits.rateLimit),
|
|
28
|
+
...readingArg.rateLimits.additionalRateLimits.flatMap((limitArg) => (openAiWindows(limitArg.limitName, limitArg.rateLimit))),
|
|
29
|
+
];
|
|
30
|
+
case 'anthropic':
|
|
31
|
+
return (readingArg.status.windows ?? []).map((windowArg) => ({
|
|
32
|
+
label: windowArg.label,
|
|
33
|
+
limitName: null,
|
|
34
|
+
scope: windowArg.scope,
|
|
35
|
+
durationSeconds: windowArg.durationSeconds,
|
|
36
|
+
usedPercent: windowArg.usedPercent,
|
|
37
|
+
estimatedUsedPercent: windowArg.estimated ? windowArg.estimatedUsedPercent ?? null : null,
|
|
38
|
+
resetAt: windowArg.resetAt,
|
|
39
|
+
}));
|
|
40
|
+
case 'spend': {
|
|
41
|
+
const spend = readingArg.spend;
|
|
42
|
+
if (spend.limitMicroUsd === null)
|
|
43
|
+
return [];
|
|
44
|
+
return [{
|
|
45
|
+
label: authSwitchSpendWindowLabel,
|
|
46
|
+
limitName: null,
|
|
47
|
+
scope: 'account',
|
|
48
|
+
durationSeconds: (Date.parse(spend.resetAt) - Date.parse(spend.periodStart)) / 1000,
|
|
49
|
+
usedPercent: spend.spentMicroUsd * 100 / spend.limitMicroUsd,
|
|
50
|
+
estimatedUsedPercent: null,
|
|
51
|
+
resetAt: spend.resetAt,
|
|
52
|
+
}];
|
|
53
|
+
}
|
|
54
|
+
default: {
|
|
55
|
+
const unhandledReading = readingArg;
|
|
56
|
+
return unhandledReading;
|
|
57
|
+
}
|
|
26
58
|
}
|
|
27
|
-
return (readingArg.status.windows ?? []).map((windowArg) => ({
|
|
28
|
-
label: windowArg.label,
|
|
29
|
-
limitName: null,
|
|
30
|
-
scope: windowArg.scope,
|
|
31
|
-
durationSeconds: windowArg.durationSeconds,
|
|
32
|
-
usedPercent: windowArg.usedPercent,
|
|
33
|
-
estimatedUsedPercent: windowArg.estimated ? windowArg.estimatedUsedPercent ?? null : null,
|
|
34
|
-
resetAt: windowArg.resetAt,
|
|
35
|
-
}));
|
|
36
59
|
};
|
|
37
60
|
/** The percent a window is used to as far as AGL knows: the estimate between reads, else the reported value. */
|
|
38
61
|
export const authSwitchUsageWindowPercent = (windowArg) => windowArg.estimatedUsedPercent ?? windowArg.usedPercent;
|
|
@@ -53,6 +76,8 @@ export const authSwitchUsageProblemText = (problemArg) => {
|
|
|
53
76
|
case 'expired': return 'The last reading is too old to show.';
|
|
54
77
|
case 'held_in_container': return 'This login is in use in a container, so its usage is not read here.';
|
|
55
78
|
case 'pending': return 'The account\'s usage has not been read yet.';
|
|
79
|
+
case 'spend_unavailable': return 'The key\'s spend could not be read, so AGL places nothing on it while it has a '
|
|
80
|
+
+ 'spend limit.';
|
|
56
81
|
}
|
|
57
82
|
};
|
|
58
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
83
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXV0aG9yaXR5LXVzYWdld2luZG93cy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3RzX2F1dGhzd2l0Y2gvYXV0aG9yaXR5LXVzYWdld2luZG93cy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFTQSxPQUFPLEVBQUUsaUJBQWlCLEVBQUUsTUFBTSxlQUFlLENBQUM7QUErQmxELDRGQUE0RjtBQUM1RixNQUFNLGFBQWEsR0FBRyxDQUFDLFlBQTJCLEVBQ2hELFVBQStDLEVBQTRCLEVBQUUsQ0FBQyxDQUM5RSxDQUFDLFVBQVUsRUFBRSxhQUFhLEVBQUUsVUFBVSxFQUFFLGVBQWUsQ0FBQztLQUNyRCxNQUFNLENBQUMsQ0FBQyxTQUFTLEVBQThDLEVBQUUsQ0FBQyxTQUFTLEtBQUssU0FBUyxDQUFDO0tBQzFGLEdBQUcsQ0FBQyxDQUFDLFNBQVMsRUFBRSxFQUFFLENBQUMsQ0FBQztJQUNuQixLQUFLLEVBQUUsSUFBSTtJQUNYLFNBQVMsRUFBRSxZQUFZO0lBQ3ZCLEtBQUssRUFBRSxZQUFZLEtBQUssSUFBSSxDQUFDLENBQUMsQ0FBQyxTQUFrQixDQUFDLENBQUMsQ0FBQyxTQUFrQjtJQUN0RSxlQUFlLEVBQUUsU0FBUy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BTywyQ0FBMkMsQ0FBQztRQUMvRSxLQUFLLG1CQUFtQixFQUFFLE9BQU8sZ0RBQWdELENBQUM7UUFDbEYsS0FBSyxpQkFBaUIsRUFBRSxPQUFPLDREQUE0RCxDQUFDO1FBQzVGLEtBQUssU0FBUyxFQUFFLE9BQU8sc0NBQXNDLENBQUM7UUFDOUQsS0FBSyxtQkFBbUIsRUFBRSxPQUFPLHFFQUFxRSxDQUFDO1FBQ3ZHLEtBQUssU0FBUyxFQUFFLE9BQU8sNkNBQTZDLENBQUM7UUFDckUsS0FBSyxtQkFBbUIsRUFBRSxPQUFPLGlGQUFpRjtjQUM5RyxjQUFjLENBQUM7SUFDckIsQ0FBQztBQUNILENBQUMsQ0FBQyJ9
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { AuthSwitchOpenAiProvider } from './classes.openaiprovider.js';
|
|
2
2
|
import type { IOpenAiOAuthCredential } from './interfaces.openai.js';
|
|
3
3
|
import type { IAuthSwitchAccount, IAuthSwitchAccountEvent, IAuthSwitchBinding, IAuthSwitchOperation, IAuthSwitchSnapshot, IReq_AuthSwitchSnapshot, TAuthSwitchRevocation } from './authority-contract.js';
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
4
|
+
import { type TAuthSwitchApiKeyProvider } from './authority-contract.js';
|
|
5
|
+
import { type TAuthSwitchApiKeyVerifier } from './authority-apikeys.js';
|
|
6
|
+
import { AuthSwitchAuthorityDatabase, type TAuthSwitchBindPurpose } from './classes.authoritydatabase.js';
|
|
7
|
+
import { type IStoredAuthorityAccount, type IStoredAuthorityGrant } from './classes.authoritymodels.js';
|
|
6
8
|
import type { IAuthSwitchUsageContext } from './classes.authorityusage.js';
|
|
7
9
|
import type { IClaudeNativeLogin } from './classes.claudenative.js';
|
|
8
10
|
import { type IAuthSwitchSecretCodec } from './classes.authoritysecrets.js';
|
|
@@ -14,11 +16,10 @@ export interface IAuthSwitchAuthorityBrokerOptions {
|
|
|
14
16
|
now?: () => number;
|
|
15
17
|
proactive?: boolean;
|
|
16
18
|
/**
|
|
17
|
-
* Asks
|
|
18
|
-
*
|
|
19
|
-
* kept the question from being answered.
|
|
19
|
+
* Asks a provider whether it accepts an API key before the authority stores it (`TAuthSwitchApiKeyVerifier`): by
|
|
20
|
+
* default a read of the models the key may use (`authSwitchApiKeyVerifier`).
|
|
20
21
|
*/
|
|
21
|
-
|
|
22
|
+
verifyApiKey?: TAuthSwitchApiKeyVerifier;
|
|
22
23
|
}
|
|
23
24
|
export interface IAuthSwitchResolvedAccess {
|
|
24
25
|
accessToken: string;
|
|
@@ -48,7 +49,7 @@ export declare class AuthSwitchAuthorityBroker {
|
|
|
48
49
|
private readonly secrets;
|
|
49
50
|
private readonly now;
|
|
50
51
|
private readonly proactive;
|
|
51
|
-
private readonly
|
|
52
|
+
private readonly verifyApiKey;
|
|
52
53
|
private readonly starts;
|
|
53
54
|
private readonly operations;
|
|
54
55
|
private readonly refreshes;
|
|
@@ -130,6 +131,11 @@ export declare class AuthSwitchAuthorityBroker {
|
|
|
130
131
|
setAccountMaxUsage(accountId: string, expectedRevision: number, maxUsagePercent: number | null): Promise<IAuthSwitchAccount>;
|
|
131
132
|
/** Lifts only the reserve, atomically with the account revision; the original threshold stays saved. */
|
|
132
133
|
liftAccountReserve(accountId: string, expectedRevision: number, hours: number): Promise<IAuthSwitchAccount>;
|
|
134
|
+
/**
|
|
135
|
+
* Sets or clears an API key account's monthly spend limit, as `setAccountMaxUsage` changes a sign-in's threshold.
|
|
136
|
+
* A key's limit applies from the next request on, to the month's spend so far.
|
|
137
|
+
*/
|
|
138
|
+
setAccountSpendLimit(accountId: string, expectedRevision: number, spendLimitMicroUsd: number | null): Promise<IAuthSwitchAccount>;
|
|
133
139
|
/**
|
|
134
140
|
* Sets or clears the date an account's subscription ends, as `setAccountMaxUsage` changes its threshold. The date is
|
|
135
141
|
* stored in its ISO 8601 UTC form; a past one is kept as given and means the account lapsed already.
|
|
@@ -167,7 +173,7 @@ export declare class AuthSwitchAuthorityBroker {
|
|
|
167
173
|
bindAccount(input: {
|
|
168
174
|
accountId: string;
|
|
169
175
|
loginId: string;
|
|
170
|
-
purpose:
|
|
176
|
+
purpose: TAuthSwitchBindPurpose;
|
|
171
177
|
runtime: IAuthSwitchBinding['runtime'];
|
|
172
178
|
scopeId: string;
|
|
173
179
|
incarnationId: string;
|
|
@@ -215,20 +221,25 @@ export declare class AuthSwitchAuthorityBroker {
|
|
|
215
221
|
*/
|
|
216
222
|
private resolveClaudeAccess;
|
|
217
223
|
/**
|
|
218
|
-
* A bound Anthropic API key, with the refusals `resolveManagedAccess` gives. A key is never renewed: one
|
|
219
|
-
* rejected for exactly this generation ends (`needs_reauth`, `provider_rejected`), and only adding a key
|
|
220
|
-
* brings the account back.
|
|
224
|
+
* A bound Anthropic or OpenAI API key, with the refusals `resolveManagedAccess` gives. A key is never renewed: one its
|
|
225
|
+
* provider rejected for exactly this generation ends (`needs_reauth`, `provider_rejected`), and only adding a key the
|
|
226
|
+
* provider accepts brings the account back.
|
|
227
|
+
*/
|
|
228
|
+
private resolveApiKeyAccess;
|
|
229
|
+
/**
|
|
230
|
+
* The key a daemon-held API key grant seals, proven to be the key its account is named by: its provider's sealed
|
|
231
|
+
* kind (`apiKeySealedKinds`) and a key whose digest is the account's subject.
|
|
221
232
|
*/
|
|
222
|
-
private
|
|
223
|
-
/** The key a daemon-held Anthropic API key grant seals, proven to be the key its account is named by. */
|
|
224
|
-
private openAnthropicApiKeyAccess;
|
|
233
|
+
private openApiKeyAccess;
|
|
225
234
|
/**
|
|
226
|
-
* Adds an Anthropic API key as an account of its own once
|
|
227
|
-
* the
|
|
228
|
-
*
|
|
229
|
-
*
|
|
235
|
+
* Adds an Anthropic or OpenAI API key as an account of its own once its provider accepted it. A key that begins the
|
|
236
|
+
* way the other provider's keys do is refused before any request. The key is sealed like every login the authority
|
|
237
|
+
* holds and never answered on the management socket again; the account keeps only how it ends (`keyHint`). A key the
|
|
238
|
+
* authority holds already is refused while its account is ready; adding it after its account was removed, or after
|
|
239
|
+
* its provider rejected it, brings that account back with a new authorization, so a runtime bound to it binds again,
|
|
240
|
+
* and with the spend limit it had unless the request names one.
|
|
230
241
|
*/
|
|
231
|
-
|
|
242
|
+
addApiKey(providerId: TAuthSwitchApiKeyProvider, apiKey: string, label?: string, spendLimitMicroUsd?: number): Promise<{
|
|
232
243
|
account: IAuthSwitchAccount;
|
|
233
244
|
loginId: string;
|
|
234
245
|
}>;
|