github-issue-tower-defence-management 2.82.1 → 2.82.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/bin/adapter/entry-points/handlers/LiveSessionOauthTokenSelectHandler.js +11 -4
- package/bin/adapter/entry-points/handlers/LiveSessionOauthTokenSelectHandler.js.map +1 -1
- package/bin/domain/usecases/LiveSessionOauthTokenSelectUseCase.js +24 -2
- package/bin/domain/usecases/LiveSessionOauthTokenSelectUseCase.js.map +1 -1
- package/package.json +1 -1
- package/types/adapter/entry-points/handlers/LiveSessionOauthTokenSelectHandler.d.ts.map +1 -1
- package/types/domain/usecases/LiveSessionOauthTokenSelectUseCase.d.ts +1 -0
- package/types/domain/usecases/LiveSessionOauthTokenSelectUseCase.d.ts.map +1 -1
package/README.md
CHANGED
|
@@ -166,7 +166,7 @@ The `checkIssueReviewReadiness` sub-command lets an agent self-check whether an
|
|
|
166
166
|
|
|
167
167
|
The `selectOauthToken` sub-command reads the same per-token rate-limit cache that the `startDaemon` proxy writes (see "Claude OAuth Token Rotation" below) and prints exactly one token string to stdout so a caller can choose an appropriate token before launching Claude Code. It is read-only: it never starts the proxy, never mutates any cache file, and never writes the token anywhere. Selection runs in two stages. First, a candidate filter keeps tokens whose 5-hour window is at least 60% free (5-hour utilization at most 0.40) AND whose 7-day window is at least 14% free (7-day utilization at most 0.86), where "% free" is `1 - utilization`. A token with no cache file, or whose window reset epoch has already passed, is treated as fully free (utilization 0) for these checks. The filter additionally excludes any token carrying a non-expired reactive `seven_day_fable` rejection marker — set when a `fable`-model request on that token was rejected with HTTP 429 (see "Claude OAuth Token Rotation" below) — because these interactive sessions run on the `fable` model; a token without the marker is treated as `fable`-usable, and the marker is ignored once its stored reset epoch has passed. Second, among the surviving candidates it selects the single token whose 7-day window reset epoch is nearest in the future (soonest reset), so weekly quota that would otherwise reset unused is consumed first; a candidate with no active 7-day window is treated as having the farthest reset (now + 7 days) and therefore sorts last. Each token entry may carry an optional `selectionWeight` (a positive number, default `1`); when the eligible candidates carry differing weights the selection among them becomes weighted-random by that weight, so a token with a smaller weight is chosen proportionally less often, while a token that is the only eligible candidate is always chosen regardless of its weight. When every eligible candidate shares the same weight (the default), the deterministic soonest-reset selection above is used unchanged. The selected token string is written to stdout (pipeable) and the per-candidate decision trace is written to stderr. When no token passes the filter, nothing is written to stdout and the command exits non-zero with an explanatory message on stderr. The token-list path comes from `--tokenListJsonPath` or the `CLAUDE_CODE_OAUTH_TOKEN_LIST_JSON_PATH` environment variable; the cache directory comes from `--cacheDir` or the `TDPM_RATELIMIT_CACHE_DIR` environment variable, defaulting to `${XDG_CACHE_HOME:-~/.cache}/tdpm/ratelimit`.
|
|
168
168
|
|
|
169
|
-
The `selectLiveSessionOauthToken` sub-command picks a token for a new live interactive Claude Code session a human is about to start, so that concurrent interactive sessions spread across distinct tokens instead of stacking onto the same one. It loads the token list and reads the same per-token rate-limit cache as `selectOauthToken`, and it is read-only in exactly the same way: it never starts the proxy, never mutates any cache file, and never writes the token anywhere. It applies a base rate-limit eligibility filter (5-hour window at least 25% free AND 7-day window at least 1% free, with a missing cache file or an expired window treated as fully free, and any token carrying a non-expired reactive `seven_day_fable` rejection marker excluded), and additionally excludes any token whose 5-hour window is less than `minFiveHourFreeRatio` (default 60%) free or whose 7-day window is less than `minSevenDayFreeRatio` (default 14%) free; these stricter thresholds prevent the `cl` script from starting a new interactive session on a token that is nearly exhausted. It additionally measures current live occupancy per token by scanning running Claude Code processes on the local Linux host: for each process under `/proc` it reads the NUL-separated `/proc/<pid>/environ` and, when the process is a Claude Code process, takes its `CLAUDE_CODE_OAUTH_TOKEN` and `CLAUDE_CODE_SESSION_ID`. A token's occupancy is the number of distinct `CLAUDE_CODE_SESSION_ID` values bound to it, so child processes that inherit one session id count once. Processes without `CLAUDE_CODE_OAUTH_TOKEN` (for example API-key sessions) are ignored, and a process whose environ cannot be read is skipped. Among the eligible tokens the selection is deterministic and reset-first. Each eligible token is given a concurrent session limit of `maxConcurrentSessionCount` (default `10`), scaled by its optional `selectionWeight` (a positive number, default `1`). That limit is held at its full value while the free share of the token's 5-hour window is at or above `fullSpeedFiveHourFreeRatio` (default `0.5`), and is tapered linearly in proportion to the free share below that point, never dropping under `1`. The 5-hour window is the only window that lowers the limit: it is the one that runs out within a single working stretch, and a session that hits it mid-flight has to be restarted, which costs more than it saves. The 7-day window never lowers the limit, so a weekly allowance that is about to expire is drained at full speed rather than discarded unused; the 7-day window is instead what orders the candidates. The token whose 7-day window resets soonest among those still under their limit is selected, so allowance that is about to expire is consumed before the reset discards it; ties are broken by the fewer live sessions. All four tuning numbers (`maxConcurrentSessionCount`, `fullSpeedFiveHourFreeRatio`, `minFiveHourFreeRatio`, `minSevenDayFreeRatio`) are read from the fleet-wide config file named by `--fleetConfigFilePath` or the `TDPM_FLEET_CONFIG` environment variable, under a `liveSessionOauthTokenSelection` mapping; a key the file omits keeps its built-in value, while an unreadable file or an out-of-range value is reported as an error rather than silently ignored. A token at its limit is skipped in favour of the next soonest-resetting token that still has room, and when every eligible token is at its limit the soonest-resetting one is returned rather than none. A token that is the only eligible candidate is always chosen regardless of its weight or occupancy. The selected token string is written to stdout (pipeable) and the per-candidate decision trace is written to stderr; when no token passes the filter, nothing is written to stdout and the command exits non-zero with an explanatory message on stderr. The token-list path and cache directory are resolved exactly as for `selectOauthToken`. Because occupancy is read from `/proc/<pid>/environ`, this sub-command is Linux-specific.
|
|
169
|
+
The `selectLiveSessionOauthToken` sub-command picks a token for a new live interactive Claude Code session a human is about to start, so that concurrent interactive sessions spread across distinct tokens instead of stacking onto the same one. It loads the token list and reads the same per-token rate-limit cache as `selectOauthToken`, and it is read-only in exactly the same way: it never starts the proxy, never mutates any cache file, and never writes the token anywhere. It applies a base rate-limit eligibility filter (5-hour window at least 25% free AND 7-day window at least 1% free, with a missing cache file or an expired window treated as fully free, and any token carrying a non-expired reactive `seven_day_fable` rejection marker excluded), and additionally excludes any token whose 5-hour window is less than `minFiveHourFreeRatio` (default 60%) free or whose 7-day window is less than `minSevenDayFreeRatio` (default 14%) free; these stricter thresholds prevent the `cl` script from starting a new interactive session on a token that is nearly exhausted. It additionally measures current live occupancy per token by scanning running Claude Code processes on the local Linux host: for each process under `/proc` it reads the NUL-separated `/proc/<pid>/environ` and, when the process is a Claude Code process, takes its `CLAUDE_CODE_OAUTH_TOKEN` and `CLAUDE_CODE_SESSION_ID`. A token's occupancy is the number of distinct `CLAUDE_CODE_SESSION_ID` values bound to it, so child processes that inherit one session id count once. Processes without `CLAUDE_CODE_OAUTH_TOKEN` (for example API-key sessions) are ignored, and a process whose environ cannot be read is skipped. Among the eligible tokens the selection is deterministic and reset-first. Each eligible token is given a concurrent session limit of `maxConcurrentSessionCount` (default `10`), scaled by its optional `selectionWeight` (a positive number, default `1`). That limit is held at its full value while the free share of the token's 5-hour window is at or above `fullSpeedFiveHourFreeRatio` (default `0.5`), and is tapered linearly in proportion to the free share below that point, never dropping under `1`. The 5-hour window is the only window that lowers the limit: it is the one that runs out within a single working stretch, and a session that hits it mid-flight has to be restarted, which costs more than it saves. The 7-day window never lowers the limit, so a weekly allowance that is about to expire is drained at full speed rather than discarded unused; the 7-day window is instead what orders the candidates. The token whose 7-day window resets soonest among those still under their limit is selected, so allowance that is about to expire is consumed before the reset discards it; ties are broken by the fewer live sessions. All four tuning numbers (`maxConcurrentSessionCount`, `fullSpeedFiveHourFreeRatio`, `minFiveHourFreeRatio`, `minSevenDayFreeRatio`) are read from the fleet-wide config file named by `--fleetConfigFilePath` or the `TDPM_FLEET_CONFIG` environment variable, under a `liveSessionOauthTokenSelection` mapping; a key the file omits keeps its built-in value, while an unreadable file or an out-of-range value is reported as an error rather than silently ignored. A token at its limit is skipped in favour of the next soonest-resetting token that still has room, and when every eligible token is at its limit the soonest-resetting one is returned rather than none. A token that is the only eligible candidate is always chosen regardless of its weight or occupancy. When no token passes the primary live session filter (5h >= 60%, 7d >= 14%), a fallback stage runs: it keeps any non-excluded token (not subscription-disabled, not unified-rejected, not fable-rejected) whose 7-day window is at least 3% free, then selects the one with the highest 5-hour free ratio among those (ties broken by fewer live sessions), so a session can still start when all tokens are near the strict threshold. The selected token string is written to stdout (pipeable) and the per-candidate decision trace is written to stderr; when no token passes both the primary filter and the fallback, nothing is written to stdout and the command exits non-zero with an explanatory message on stderr. The token-list path and cache directory are resolved exactly as for `selectOauthToken`. Because occupancy is read from `/proc/<pid>/environ`, this sub-command is Linux-specific.
|
|
170
170
|
|
|
171
171
|
The `startDaemon` command supports a `preparationWorker` mapping in the fleet-wide config file named by `--fleetConfigFilePath` or the `TDPM_FLEET_CONFIG` environment variable. This section controls per-token concurrency for the preparation worker pool. Supported keys:
|
|
172
172
|
|
|
@@ -61,10 +61,10 @@ class LiveSessionOauthTokenSelectHandler {
|
|
|
61
61
|
return {
|
|
62
62
|
selectedToken: result.selected?.token ?? null,
|
|
63
63
|
selectedName: result.selected?.name ?? null,
|
|
64
|
-
diagnostics: this.formatDiagnostics(result, input.nowEpochSeconds),
|
|
64
|
+
diagnostics: this.formatDiagnostics(result, input.nowEpochSeconds, input.selectionSettings),
|
|
65
65
|
};
|
|
66
66
|
};
|
|
67
|
-
this.formatDiagnostics = (result, nowEpochSeconds) => {
|
|
67
|
+
this.formatDiagnostics = (result, nowEpochSeconds, settings) => {
|
|
68
68
|
const lines = result.metrics.map((metric) => {
|
|
69
69
|
const secondsUntilSevenDayEnd = Math.round(metric.sevenDayEndEpoch - nowEpochSeconds);
|
|
70
70
|
const status = metric.eligible
|
|
@@ -73,10 +73,17 @@ class LiveSessionOauthTokenSelectHandler {
|
|
|
73
73
|
return `${metric.name}: ${metric.liveSessionCount}/${metric.concurrentSessionLimit} live session(s), 5h ${Math.round(metric.fiveHourFreeRatio * 100)}% free, 7d ${Math.round(metric.sevenDayFreeRatio * 100)}% free, 7d-end in ${secondsUntilSevenDayEnd}s, weight ${metric.selectionWeight} -> ${status}`;
|
|
74
74
|
});
|
|
75
75
|
if (result.selected === null) {
|
|
76
|
-
lines.push(`No eligible token:
|
|
76
|
+
lines.push(`No eligible token: all tokens are below the live session thresholds (5h >= ${Math.round(settings.minFiveHourFreeRatio * 100)}% free, 7d >= ${Math.round(settings.minSevenDayFreeRatio * 100)}% free) and no token met the ${Math.round(LiveSessionOauthTokenSelectUseCase_1.LIVE_SESSION_FALLBACK_SEVEN_DAY_MIN_FREE_RATIO * 100)}% 7d fallback condition either.`);
|
|
77
77
|
}
|
|
78
78
|
else {
|
|
79
|
-
|
|
79
|
+
const selectedMetric = result.metrics.find((m) => m.name === result.selected?.name);
|
|
80
|
+
const usedFallback = selectedMetric !== undefined && !selectedMetric.eligible;
|
|
81
|
+
if (usedFallback) {
|
|
82
|
+
lines.push(`Selected ${result.selected.name} via fallback (highest 5h free ratio among non-excluded tokens with 7d >= ${Math.round(LiveSessionOauthTokenSelectUseCase_1.LIVE_SESSION_FALLBACK_SEVEN_DAY_MIN_FREE_RATIO * 100)}% free; no token met the live session thresholds of 5h >= ${Math.round(settings.minFiveHourFreeRatio * 100)}% and 7d >= ${Math.round(settings.minSevenDayFreeRatio * 100)}%).`);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
lines.push(`Selected ${result.selected.name} (the soonest-resetting 7d window among tokens still under their concurrent session limit, which is set by the free share of the 5h window alone).`);
|
|
86
|
+
}
|
|
80
87
|
}
|
|
81
88
|
return lines;
|
|
82
89
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LiveSessionOauthTokenSelectHandler.js","sourceRoot":"","sources":["../../../../src/adapter/entry-points/handlers/LiveSessionOauthTokenSelectHandler.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"LiveSessionOauthTokenSelectHandler.js","sourceRoot":"","sources":["../../../../src/adapter/entry-points/handlers/LiveSessionOauthTokenSelectHandler.ts"],"names":[],"mappings":";;;AACA,oHAKqE;AACrE,8FAG0D;AAC1D,+DAA6E;AAC7E,iEAA+D;AAC/D,wGAAqG;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AAQ,CAAC,oBAAoB,GAAG,GAAG,CAAC,KAAK,CAC7V,CAAC;gBACJ,CAAC;qBAAM,CAAC;oBACN,KAAK,CAAC,IAAI,CACR,YAAY,MAAM,CAAC,QAAQ,CAAC,IAAI,oJAAoJ,CACrL,CAAC;gBACJ,CAAC;YACH,CAAC;YAED,OAAO,KAAK,CAAC;QACf,CAAC,CAAC;IAlHC,CAAC;CAmHL;AAvHD,gFAuHC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LiveSessionOauthTokenSelectUseCase = exports.liveSessionConcurrentLimitOf = exports.DEFAULT_LIVE_SESSION_OAUTH_TOKEN_SELECTION_SETTINGS = void 0;
|
|
3
|
+
exports.LiveSessionOauthTokenSelectUseCase = exports.liveSessionConcurrentLimitOf = exports.DEFAULT_LIVE_SESSION_OAUTH_TOKEN_SELECTION_SETTINGS = exports.LIVE_SESSION_FALLBACK_SEVEN_DAY_MIN_FREE_RATIO = void 0;
|
|
4
4
|
const OauthTokenSelectUseCase_1 = require("./OauthTokenSelectUseCase");
|
|
5
|
+
exports.LIVE_SESSION_FALLBACK_SEVEN_DAY_MIN_FREE_RATIO = 0.03;
|
|
5
6
|
exports.DEFAULT_LIVE_SESSION_OAUTH_TOKEN_SELECTION_SETTINGS = {
|
|
6
7
|
maxConcurrentSessionCount: 10,
|
|
7
8
|
fullSpeedFiveHourFreeRatio: 0.5,
|
|
@@ -59,7 +60,28 @@ class LiveSessionOauthTokenSelectUseCase {
|
|
|
59
60
|
const metrics = evaluated.map((entry) => entry.metric);
|
|
60
61
|
const eligible = evaluated.filter((entry) => entry.metric.eligible);
|
|
61
62
|
if (eligible.length === 0) {
|
|
62
|
-
|
|
63
|
+
const fallbackEligible = evaluated.filter((entry) => !entry.candidate.subscriptionDisabled &&
|
|
64
|
+
!entry.candidate.unifiedRejected &&
|
|
65
|
+
!entry.candidate.fableRejected &&
|
|
66
|
+
entry.metric.sevenDayFreeRatio >=
|
|
67
|
+
exports.LIVE_SESSION_FALLBACK_SEVEN_DAY_MIN_FREE_RATIO);
|
|
68
|
+
if (fallbackEligible.length === 0) {
|
|
69
|
+
return { selected: null, metrics };
|
|
70
|
+
}
|
|
71
|
+
const fallbackSelected = fallbackEligible.reduce((bestEntry, currentEntry) => {
|
|
72
|
+
if (currentEntry.metric.fiveHourFreeRatio >
|
|
73
|
+
bestEntry.metric.fiveHourFreeRatio) {
|
|
74
|
+
return currentEntry;
|
|
75
|
+
}
|
|
76
|
+
if (currentEntry.metric.fiveHourFreeRatio ===
|
|
77
|
+
bestEntry.metric.fiveHourFreeRatio &&
|
|
78
|
+
currentEntry.metric.liveSessionCount <
|
|
79
|
+
bestEntry.metric.liveSessionCount) {
|
|
80
|
+
return currentEntry;
|
|
81
|
+
}
|
|
82
|
+
return bestEntry;
|
|
83
|
+
});
|
|
84
|
+
return { selected: fallbackSelected.candidate, metrics };
|
|
63
85
|
}
|
|
64
86
|
const selected = eligible.reduce((bestEntry, currentEntry) => this.preferred(currentEntry.metric, bestEntry.metric)
|
|
65
87
|
? currentEntry
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LiveSessionOauthTokenSelectUseCase.js","sourceRoot":"","sources":["../../../src/domain/usecases/LiveSessionOauthTokenSelectUseCase.ts"],"names":[],"mappings":";;;AACA,uEAOmC;
|
|
1
|
+
{"version":3,"file":"LiveSessionOauthTokenSelectUseCase.js","sourceRoot":"","sources":["../../../src/domain/usecases/LiveSessionOauthTokenSelectUseCase.ts"],"names":[],"mappings":";;;AACA,uEAOmC;AAEtB,QAAA,8CAA8C,GAAG,IAAI,CAAC;AAStD,QAAA,mDAAmD,GAC9D;IACE,yBAAyB,EAAE,EAAE;IAC7B,0BAA0B,EAAE,GAAG;IAC/B,oBAAoB,EAAE,GAAG;IACzB,oBAAoB,EAAE,IAAI;CAC3B,CAAC;AAEG,MAAM,4BAA4B,GAAG,CAC1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CAAC;YAChD,CAAC;YACD,IACE,eAAe,CAAC,iBAAiB,KAAK,eAAe,CAAC,iBAAiB,EACvE,CAAC;gBACD,OAAO,CACL,eAAe,CAAC,iBAAiB,GAAG,eAAe,CAAC,iBAAiB,CACtE,CAAC;YACJ,CAAC;YACD,OAAO,eAAe,CAAC,gBAAgB,GAAG,eAAe,CAAC,gBAAgB,CAAC;QAC7E,CAAC,CAAC;QAEM,4BAAuB,GAAG,CAChC,YAAiC,EACZ,EAAE;YACvB,MAAM,kBAAkB,GAAG,IAAI,GAAG,EAAuB,CAAC;YAC1D,KAAK,MAAM,WAAW,IAAI,YAAY,EAAE,CAAC;gBACvC,MAAM,WAAW,GACf,kBAAkB,CAAC,GAAG,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,IAAI,GAAG,EAAU,CAAC;gBACjE,WAAW,CAAC,GAAG,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;gBACxC,kBAAkB,CAAC,GAAG,CAAC,WAAW,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;YACzD,CAAC;YACD,MAAM,YAAY,GAAG,IAAI,GAAG,EAAkB,CAAC;YAC/C,KAAK,MAAM,CAAC,KAAK,EAAE,WAAW,CAAC,IAAI,kBAAkB,CAAC,OAAO,EAAE,EAAE,CAAC;gBAChE,YAAY,CAAC,GAAG,CAAC,KAAK,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC;YAC5C,CAAC;YACD,OAAO,YAAY,CAAC;QACtB,CAAC,CAAC;IAhLC,CAAC;CAiLL;AApLD,gFAoLC"}
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LiveSessionOauthTokenSelectHandler.d.ts","sourceRoot":"","sources":["../../../../src/adapter/entry-points/handlers/LiveSessionOauthTokenSelectHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,yEAAyE,CAAC;AAC3H,OAAO,
|
|
1
|
+
{"version":3,"file":"LiveSessionOauthTokenSelectHandler.d.ts","sourceRoot":"","sources":["../../../../src/adapter/entry-points/handlers/LiveSessionOauthTokenSelectHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,yEAAyE,CAAC;AAC3H,OAAO,EAEL,KAAK,sCAAsC,EAE3C,kCAAkC,EACnC,MAAM,6DAA6D,CAAC;AAarE,MAAM,MAAM,uCAAuC,GAAG;IACpD,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,eAAe,EAAE,MAAM,CAAC;IACxB,iBAAiB,EAAE,sCAAsC,CAAC;CAC3D,CAAC;AAEF,MAAM,MAAM,wCAAwC,GAAG;IACrD,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,WAAW,EAAE,MAAM,EAAE,CAAC;CACvB,CAAC;AAEF,qBAAa,kCAAkC;IAE3C,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,qBAAqB;gBADrB,OAAO,GAAE,kCAA6E,EACtF,qBAAqB,GAAE,2BAAmE;IAG7G,MAAM,GACJ,OAAO,uCAAuC,KAC7C,wCAAwC,CAuEzC;IAEF,OAAO,CAAC,iBAAiB,CAqCvB;CACH"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ClaudeLiveSession } from './adapter-interfaces/ClaudeLiveSessionRepository';
|
|
2
2
|
import { type OauthTokenCandidate, OauthTokenSelectUseCase } from './OauthTokenSelectUseCase';
|
|
3
|
+
export declare const LIVE_SESSION_FALLBACK_SEVEN_DAY_MIN_FREE_RATIO = 0.03;
|
|
3
4
|
export type LiveSessionOauthTokenSelectionSettings = {
|
|
4
5
|
maxConcurrentSessionCount: number;
|
|
5
6
|
fullSpeedFiveHourFreeRatio: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-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AAE,EACjC,cAAc,iBAAiB,EAAE,EACjC,iBAAiB,MAAM,EACvB,UAAU,sCAAsC,KAC/C,iCAAiC,
|
|
1
|
+
{"version":3,"file":"LiveSessionOauthTokenSelectUseCase.d.ts","sourceRoot":"","sources":["../../../src/domain/usecases/LiveSessionOauthTokenSelectUseCase.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kDAAkD,CAAC;AAC1F,OAAO,EAEL,KAAK,mBAAmB,EACxB,uBAAuB,EAIxB,MAAM,2BAA2B,CAAC;AAEnC,eAAO,MAAM,8CAA8C,OAAO,CAAC;AAEnE,MAAM,MAAM,sCAAsC,GAAG;IACnD,yBAAyB,EAAE,MAAM,CAAC;IAClC,0BAA0B,EAAE,MAAM,CAAC;IACnC,oBAAoB,EAAE,MAAM,CAAC;IAC7B,oBAAoB,EAAE,MAAM,CAAC;CAC9B,CAAC;AAEF,eAAO,MAAM,mDAAmD,EAAE,sCAM/D,CAAC;AAEJ,eAAO,MAAM,4BAA4B,GACvC,mBAAmB,MAAM,EACzB,iBAAiB,MAAM,EACvB,UAAU,sCAAsC,EAChD,6BAAwB,KACvB,MAoBF,CAAC;AAEF,MAAM,MAAM,qCAAqC,GAAG;IAClD,IAAI,EAAE,MAAM,CAAC;IACb,iBAAiB,EAAE,MAAM,CAAC;IAC1B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,gBAAgB,EAAE,MAAM,CAAC;IACzB,gBAAgB,EAAE,MAAM,CAAC;IACzB,sBAAsB,EAAE,MAAM,CAAC;IAC/B,sBAAsB,EAAE,OAAO,CAAC;IAChC,QAAQ,EAAE,OAAO,CAAC;IAClB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,iCAAiC,GAAG;IAC9C,QAAQ,EAAE,mBAAmB,GAAG,IAAI,CAAC;IACrC,OAAO,EAAE,qCAAqC,EAAE,CAAC;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