@kaitranntt/ccs 8.10.0-dev.17 → 8.10.0-dev.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cliproxy/accounts/claude-pool-policy-api.d.ts +12 -0
- package/dist/cliproxy/accounts/claude-pool-policy-api.d.ts.map +1 -0
- package/dist/cliproxy/accounts/claude-pool-policy-api.js +74 -0
- package/dist/cliproxy/accounts/claude-pool-policy-api.js.map +1 -0
- package/dist/cliproxy/accounts/claude-pool-policy-lease.d.ts +11 -0
- package/dist/cliproxy/accounts/claude-pool-policy-lease.d.ts.map +1 -0
- package/dist/cliproxy/accounts/claude-pool-policy-lease.js +55 -0
- package/dist/cliproxy/accounts/claude-pool-policy-lease.js.map +1 -0
- package/dist/cliproxy/accounts/claude-pool-policy-reconciliation.d.ts +13 -0
- package/dist/cliproxy/accounts/claude-pool-policy-reconciliation.d.ts.map +1 -0
- package/dist/cliproxy/accounts/claude-pool-policy-reconciliation.js +215 -0
- package/dist/cliproxy/accounts/claude-pool-policy-reconciliation.js.map +1 -0
- package/dist/cliproxy/accounts/claude-pool-policy-runtime.d.ts +19 -0
- package/dist/cliproxy/accounts/claude-pool-policy-runtime.d.ts.map +1 -0
- package/dist/cliproxy/accounts/claude-pool-policy-runtime.js +65 -0
- package/dist/cliproxy/accounts/claude-pool-policy-runtime.js.map +1 -0
- package/dist/cliproxy/accounts/claude-pool-policy-state.d.ts +37 -0
- package/dist/cliproxy/accounts/claude-pool-policy-state.d.ts.map +1 -0
- package/dist/cliproxy/accounts/claude-pool-policy-state.js +205 -0
- package/dist/cliproxy/accounts/claude-pool-policy-state.js.map +1 -0
- package/dist/cliproxy/accounts/claude-pool-policy.d.ts +48 -0
- package/dist/cliproxy/accounts/claude-pool-policy.d.ts.map +1 -0
- package/dist/cliproxy/accounts/claude-pool-policy.js +401 -0
- package/dist/cliproxy/accounts/claude-pool-policy.js.map +1 -0
- package/dist/cliproxy/accounts/drain-order.d.ts +1 -1
- package/dist/cliproxy/accounts/drain-order.d.ts.map +1 -1
- package/dist/cliproxy/accounts/drain-order.js +17 -0
- package/dist/cliproxy/accounts/drain-order.js.map +1 -1
- package/dist/cliproxy/accounts/pool-state.d.ts +1 -1
- package/dist/cliproxy/accounts/pool-state.d.ts.map +1 -1
- package/dist/cliproxy/accounts/registry-config.d.ts +4 -0
- package/dist/cliproxy/accounts/registry-config.d.ts.map +1 -0
- package/dist/cliproxy/accounts/registry-config.js +46 -0
- package/dist/cliproxy/accounts/registry-config.js.map +1 -0
- package/dist/cliproxy/accounts/token-file-ops.d.ts +1 -2
- package/dist/cliproxy/accounts/token-file-ops.d.ts.map +1 -1
- package/dist/cliproxy/accounts/token-file-ops.js +2 -7
- package/dist/cliproxy/accounts/token-file-ops.js.map +1 -1
- package/dist/cliproxy/accounts/types.d.ts +1 -1
- package/dist/cliproxy/accounts/types.d.ts.map +1 -1
- package/dist/cliproxy/config/generator.d.ts +2 -1
- package/dist/cliproxy/config/generator.d.ts.map +1 -1
- package/dist/cliproxy/config/generator.js +7 -2
- package/dist/cliproxy/config/generator.js.map +1 -1
- package/dist/cliproxy/quota/quota-fetcher-claude-normalizer.d.ts +17 -4
- package/dist/cliproxy/quota/quota-fetcher-claude-normalizer.d.ts.map +1 -1
- package/dist/cliproxy/quota/quota-fetcher-claude-normalizer.js +246 -153
- package/dist/cliproxy/quota/quota-fetcher-claude-normalizer.js.map +1 -1
- package/dist/cliproxy/quota/quota-fetcher-claude-probe-state.d.ts +3 -0
- package/dist/cliproxy/quota/quota-fetcher-claude-probe-state.d.ts.map +1 -1
- package/dist/cliproxy/quota/quota-fetcher-claude-probe-state.js +17 -10
- package/dist/cliproxy/quota/quota-fetcher-claude-probe-state.js.map +1 -1
- package/dist/cliproxy/quota/quota-fetcher-claude.d.ts +4 -4
- package/dist/cliproxy/quota/quota-fetcher-claude.d.ts.map +1 -1
- package/dist/cliproxy/quota/quota-fetcher-claude.js +118 -29
- package/dist/cliproxy/quota/quota-fetcher-claude.js.map +1 -1
- package/dist/cliproxy/quota/quota-label-sanitizer.d.ts +3 -2
- package/dist/cliproxy/quota/quota-label-sanitizer.d.ts.map +1 -1
- package/dist/cliproxy/quota/quota-label-sanitizer.js +6 -5
- package/dist/cliproxy/quota/quota-label-sanitizer.js.map +1 -1
- package/dist/cliproxy/quota/quota-manager.d.ts.map +1 -1
- package/dist/cliproxy/quota/quota-manager.js +3 -9
- package/dist/cliproxy/quota/quota-manager.js.map +1 -1
- package/dist/cliproxy/quota/quota-types.d.ts +12 -0
- package/dist/cliproxy/quota/quota-types.d.ts.map +1 -1
- package/dist/commands/cliproxy/help-subcommand.d.ts.map +1 -1
- package/dist/commands/cliproxy/help-subcommand.js +9 -0
- package/dist/commands/cliproxy/help-subcommand.js.map +1 -1
- package/dist/commands/cliproxy/order-subcommand.d.ts.map +1 -1
- package/dist/commands/cliproxy/order-subcommand.js +86 -44
- package/dist/commands/cliproxy/order-subcommand.js.map +1 -1
- package/dist/commands/cliproxy/pool-state-renderer.d.ts.map +1 -1
- package/dist/commands/cliproxy/pool-state-renderer.js +9 -2
- package/dist/commands/cliproxy/pool-state-renderer.js.map +1 -1
- package/dist/commands/cliproxy/quota-subcommand/claude-window-helpers.d.ts +1 -2
- package/dist/commands/cliproxy/quota-subcommand/claude-window-helpers.d.ts.map +1 -1
- package/dist/commands/cliproxy/quota-subcommand/claude-window-helpers.js +5 -16
- package/dist/commands/cliproxy/quota-subcommand/claude-window-helpers.js.map +1 -1
- package/dist/commands/cliproxy/quota-subcommand/sections/claude.d.ts.map +1 -1
- package/dist/commands/cliproxy/quota-subcommand/sections/claude.js +1 -1
- package/dist/commands/cliproxy/quota-subcommand/sections/claude.js.map +1 -1
- package/dist/docker/docker-bootstrap.d.ts.map +1 -1
- package/dist/docker/docker-bootstrap.js +29 -5
- package/dist/docker/docker-bootstrap.js.map +1 -1
- package/dist/shared/claude-pool-policy.d.ts +20 -0
- package/dist/shared/claude-pool-policy.d.ts.map +1 -0
- package/dist/shared/claude-pool-policy.js +3 -0
- package/dist/shared/claude-pool-policy.js.map +1 -0
- package/dist/ui/assets/{Trans-ButNUgI0.js → Trans-Dlb02vqu.js} +1 -1
- package/dist/ui/assets/{accounts-MLY7WLik.js → accounts-NMmfEBnl.js} +1 -1
- package/dist/ui/assets/{alert-dialog-B5gsPnVB.js → alert-dialog-CLeTz0Di.js} +1 -1
- package/dist/ui/assets/{api-Bz71asnK.js → api-DxGxeHbw.js} +1 -1
- package/dist/ui/assets/{auth-section-BqGQc4ub.js → auth-section-AI2YNrUB.js} +1 -1
- package/dist/ui/assets/{backups-section-BP8fVjA2.js → backups-section-CxyuzCda.js} +1 -1
- package/dist/ui/assets/{channels-CXItlOs8.js → channels-SBcIEMn0.js} +1 -1
- package/dist/ui/assets/{checkbox-D3_x-6PV.js → checkbox-C1D6YcRy.js} +1 -1
- package/dist/ui/assets/{claude-extension-DvAAS238.js → claude-extension-C3Ik79tl.js} +1 -1
- package/dist/ui/assets/{cliproxy-io8Z1slq.js → cliproxy-BySCuRxu.js} +1 -1
- package/dist/ui/assets/{cliproxy-ai-providers-DkgBWX_r.js → cliproxy-ai-providers-B8LPZhj3.js} +1 -1
- package/dist/ui/assets/{cliproxy-control-panel-C6IMwMpu.js → cliproxy-control-panel-Dsv31SI_.js} +1 -1
- package/dist/ui/assets/{codex-BKntGtWm.js → codex-CWZlSLEn.js} +1 -1
- package/dist/ui/assets/{confirm-dialog-CU4RRUuI.js → confirm-dialog-tpU9d5TR.js} +1 -1
- package/dist/ui/assets/{copilot-S045zi-v.js → copilot-C5uwBK-k.js} +1 -1
- package/dist/ui/assets/{cursor-q4VVsOHM.js → cursor-BwoYXKM4.js} +1 -1
- package/dist/ui/assets/{droid-C4hxPz1p.js → droid-Cv6mZctn.js} +1 -1
- package/dist/ui/assets/{globalenv-section-DeVJimxG.js → globalenv-section-CKc1Udhj.js} +1 -1
- package/dist/ui/assets/{health-D5k73-1v.js → health-Ctfcm6p0.js} +1 -1
- package/dist/ui/assets/{index-BJJcWQcN.js → index--TAxR0Iy.js} +1 -1
- package/dist/ui/assets/index-0hASk2BU.css +1 -0
- package/dist/ui/assets/{index-DpL-rgkN.js → index-C2ABCKof.js} +1 -1
- package/dist/ui/assets/{index-CSfupFf3.js → index-C5YaR--I.js} +1 -1
- package/dist/ui/assets/{index-9RHJNAlK.js → index-CBKaNavQ.js} +1 -1
- package/dist/ui/assets/{index-DQWeKrTw.js → index-DnnSa3K6.js} +1 -1
- package/dist/ui/assets/{index-Nd8v14jh.js → index-G9JzuSyw.js} +1 -1
- package/dist/ui/assets/{index-B7Y50Pmj.js → index-gX7Mi5Ws.js} +37 -37
- package/dist/ui/assets/{logs-DBRI0Vct.js → logs-D6LiKkzU.js} +1 -1
- package/dist/ui/assets/{masked-input-CO6eBTBI.js → masked-input-CmtENW5h.js} +1 -1
- package/dist/ui/assets/proxy-status-widget-DqVBhfEP.js +1 -0
- package/dist/ui/assets/{raw-json-settings-editor-panel-Czb-dWwA.js → raw-json-settings-editor-panel-C9-_RC57.js} +1 -1
- package/dist/ui/assets/{searchable-select-EyJfxEUO.js → searchable-select-BeEQJh2E.js} +1 -1
- package/dist/ui/assets/{separator-DbhOtMVl.js → separator-CB-e5SCL.js} +1 -1
- package/dist/ui/assets/{shared-Dx9MtTlc.js → shared-GU9wziRt.js} +1 -1
- package/dist/ui/assets/{table-NcM1_A4G.js → table-BFrniqUJ.js} +1 -1
- package/dist/ui/assets/{updates-BmhLCm82.js → updates-DYhBCREi.js} +1 -1
- package/dist/ui/assets/{use-accounts-sRp8XTDE.js → use-accounts-xaNW9KeG.js} +1 -1
- package/dist/ui/index.html +2 -2
- package/dist/web-server/index.d.ts +1 -1
- package/dist/web-server/index.d.ts.map +1 -1
- package/dist/web-server/index.js +4 -1
- package/dist/web-server/index.js.map +1 -1
- package/dist/web-server/routes/bar-pool-account-quota-adapter.d.ts.map +1 -1
- package/dist/web-server/routes/bar-pool-account-quota-adapter.js +1 -3
- package/dist/web-server/routes/bar-pool-account-quota-adapter.js.map +1 -1
- package/dist/web-server/routes/cliproxy-routing-routes.d.ts.map +1 -1
- package/dist/web-server/routes/cliproxy-routing-routes.js +16 -0
- package/dist/web-server/routes/cliproxy-routing-routes.js.map +1 -1
- package/dist/web-server/shutdown.d.ts +2 -3
- package/dist/web-server/shutdown.d.ts.map +1 -1
- package/dist/web-server/shutdown.js +16 -8
- package/dist/web-server/shutdown.js.map +1 -1
- package/dist/web-server/usage/native-quota-collector.d.ts.map +1 -1
- package/dist/web-server/usage/native-quota-collector.js +33 -65
- package/dist/web-server/usage/native-quota-collector.js.map +1 -1
- package/package.json +1 -1
- package/dist/ui/assets/index-h0wykXqj.css +0 -1
- package/dist/ui/assets/proxy-status-widget-Bfp37KO_.js +0 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ProxyTarget } from '../proxy/proxy-target-resolver';
|
|
2
|
+
export interface ClaudePoolCredential {
|
|
3
|
+
name: string;
|
|
4
|
+
priority: number | null;
|
|
5
|
+
}
|
|
6
|
+
export interface ClaudePoolManagementApi {
|
|
7
|
+
checkCapabilities(): Promise<void>;
|
|
8
|
+
listCredentials(): Promise<ClaudePoolCredential[]>;
|
|
9
|
+
setPriority(name: string, priority: number | null, expectedPriority: number | null): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
export declare function createClaudePoolManagementApi(target: ProxyTarget, lifecycleSignal?: AbortSignal): ClaudePoolManagementApi;
|
|
12
|
+
//# sourceMappingURL=claude-pool-policy-api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude-pool-policy-api.d.ts","sourceRoot":"","sources":["../../../src/cliproxy/accounts/claude-pool-policy-api.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,WAAW,EACjB,MAAM,gCAAgC,CAAC;AAExC,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB;AAED,MAAM,WAAW,uBAAuB;IACtC,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC,eAAe,IAAI,OAAO,CAAC,oBAAoB,EAAE,CAAC,CAAC;IACnD,WAAW,CACT,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,GAAG,IAAI,EACvB,gBAAgB,EAAE,MAAM,GAAG,IAAI,GAC9B,OAAO,CAAC,IAAI,CAAC,CAAC;CAClB;AAED,wBAAgB,6BAA6B,CAC3C,MAAM,EAAE,WAAW,EACnB,eAAe,CAAC,EAAE,WAAW,GAC5B,uBAAuB,CAoEzB"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createClaudePoolManagementApi = void 0;
|
|
4
|
+
const error_types_1 = require("../../errors/error-types");
|
|
5
|
+
const proxy_target_resolver_1 = require("../proxy/proxy-target-resolver");
|
|
6
|
+
function createClaudePoolManagementApi(target, lifecycleSignal) {
|
|
7
|
+
async function request(endpoint, options = {}) {
|
|
8
|
+
if (lifecycleSignal?.aborted)
|
|
9
|
+
throw new error_types_1.ConfigError('Claude pool controller is stopping. Retry after it restarts.');
|
|
10
|
+
const controller = new AbortController();
|
|
11
|
+
const abort = () => controller.abort();
|
|
12
|
+
if (lifecycleSignal?.aborted)
|
|
13
|
+
controller.abort();
|
|
14
|
+
lifecycleSignal?.addEventListener('abort', abort, { once: true });
|
|
15
|
+
const timeout = setTimeout(() => controller.abort(), 5000);
|
|
16
|
+
try {
|
|
17
|
+
const response = await fetch((0, proxy_target_resolver_1.buildProxyUrl)(target, `/v8/management/${endpoint}`), {
|
|
18
|
+
...options,
|
|
19
|
+
headers: (0, proxy_target_resolver_1.buildManagementHeaders)(target, { 'Content-Type': 'application/json' }),
|
|
20
|
+
signal: controller.signal,
|
|
21
|
+
});
|
|
22
|
+
if (!response.ok)
|
|
23
|
+
throw new error_types_1.ConfigError(`Claude pool management request failed (${response.status}).`);
|
|
24
|
+
return await response.json();
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
if (error instanceof Error && error.message.startsWith('Claude pool management'))
|
|
28
|
+
throw error;
|
|
29
|
+
throw new error_types_1.ConfigError('Claude pool management request failed. Verify the local proxy and management access.');
|
|
30
|
+
}
|
|
31
|
+
finally {
|
|
32
|
+
clearTimeout(timeout);
|
|
33
|
+
lifecycleSignal?.removeEventListener('abort', abort);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
async checkCapabilities() {
|
|
38
|
+
const capabilities = (await request('routing/capabilities'));
|
|
39
|
+
if (capabilities.provider_affinity_overrides !== true ||
|
|
40
|
+
capabilities.local_builtin_selector !== true ||
|
|
41
|
+
capabilities.credential_priority_cas !== true) {
|
|
42
|
+
throw new error_types_1.ConfigError('Claude quota ordering requires provider-affinity support and the built-in local selector. Home and plugin schedulers are not supported.');
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
async listCredentials() {
|
|
46
|
+
const response = (await request('credentials'));
|
|
47
|
+
if (!Array.isArray(response.files))
|
|
48
|
+
throw new error_types_1.ConfigError('Invalid local proxy credential listing.');
|
|
49
|
+
return response.files.flatMap((entry) => {
|
|
50
|
+
if (!entry || typeof entry !== 'object')
|
|
51
|
+
return [];
|
|
52
|
+
const credential = entry;
|
|
53
|
+
if (typeof credential.name !== 'string')
|
|
54
|
+
return [];
|
|
55
|
+
const priority = credential.priority;
|
|
56
|
+
if (priority !== undefined &&
|
|
57
|
+
(typeof priority !== 'number' || !Number.isSafeInteger(priority))) {
|
|
58
|
+
throw new error_types_1.ConfigError('Invalid priority in local proxy credential listing.');
|
|
59
|
+
}
|
|
60
|
+
return [
|
|
61
|
+
{ name: credential.name, priority: priority === undefined ? null : priority },
|
|
62
|
+
];
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
async setPriority(name, priority, expectedPriority) {
|
|
66
|
+
await request('credentials/priority', {
|
|
67
|
+
method: 'PATCH',
|
|
68
|
+
body: JSON.stringify({ name, priority, expected_priority: expectedPriority }),
|
|
69
|
+
});
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
exports.createClaudePoolManagementApi = createClaudePoolManagementApi;
|
|
74
|
+
//# sourceMappingURL=claude-pool-policy-api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude-pool-policy-api.js","sourceRoot":"","sources":["../../../src/cliproxy/accounts/claude-pool-policy-api.ts"],"names":[],"mappings":";;;AAAA,0DAAuD;AACvD,0EAIwC;AAiBxC,SAAgB,6BAA6B,CAC3C,MAAmB,EACnB,eAA6B;IAE7B,KAAK,UAAU,OAAO,CAAC,QAAgB,EAAE,UAAuB,EAAE;QAChE,IAAI,eAAe,EAAE,OAAO;YAC1B,MAAM,IAAI,yBAAW,CAAC,8DAA8D,CAAC,CAAC;QACxF,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;QACzC,MAAM,KAAK,GAAG,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;QACvC,IAAI,eAAe,EAAE,OAAO;YAAE,UAAU,CAAC,KAAK,EAAE,CAAC;QACjD,eAAe,EAAE,gBAAgB,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QAClE,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,EAAE,IAAI,CAAC,CAAC;QAC3D,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,IAAA,qCAAa,EAAC,MAAM,EAAE,kBAAkB,QAAQ,EAAE,CAAC,EAAE;gBAChF,GAAG,OAAO;gBACV,OAAO,EAAE,IAAA,8CAAsB,EAAC,MAAM,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,CAAC;gBAC/E,MAAM,EAAE,UAAU,CAAC,MA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AAC;gBACnD,MAAM,UAAU,GAAG,KAAgC,CAAC;gBACpD,IAAI,OAAO,UAAU,CAAC,IAAI,KAAK,QAAQ;oBAAE,OAAO,EAAE,CAAC;gBACnD,MAAM,QAAQ,GAAG,UAAU,CAAC,QAAQ,CAAC;gBACrC,IACE,QAAQ,KAAK,SAAS;oBACtB,CAAC,OAAO,QAAQ,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,EACjE,CAAC;oBACD,MAAM,IAAI,yBAAW,CAAC,qDAAqD,CAAC,CAAC;gBAC/E,CAAC;gBACD,OAAO;oBACL,EAAE,IAAI,EAAE,UAAU,CAAC,IAAI,EAAE,QAAQ,EAAE,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAE,QAAmB,EAAE;iBAC1F,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC;QACD,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,gBAAgB;YAChD,MAAM,OAAO,CAAC,sBAAsB,EAAE;gBACpC,MAAM,EAAE,OAAO;gBACf,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,CAAC;aAC9E,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC;AAvED,sEAuEC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface ClaudePoolControllerLease {
|
|
2
|
+
owner: string;
|
|
3
|
+
pid: number;
|
|
4
|
+
hostname: string;
|
|
5
|
+
target: string;
|
|
6
|
+
updatedAt: number;
|
|
7
|
+
startedAt?: number;
|
|
8
|
+
}
|
|
9
|
+
export declare function readActiveClaudePoolControllerLease(file: string, target: string, now: number, staleMs: number): ClaudePoolControllerLease | null;
|
|
10
|
+
export declare function writeClaudePoolControllerLease(file: string, lease: ClaudePoolControllerLease): void;
|
|
11
|
+
//# sourceMappingURL=claude-pool-policy-lease.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude-pool-policy-lease.d.ts","sourceRoot":"","sources":["../../../src/cliproxy/accounts/claude-pool-policy-lease.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,yBAAyB;IACxC,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,wBAAgB,mCAAmC,CACjD,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,GACd,yBAAyB,GAAG,IAAI,CAmBlC;AAED,wBAAgB,8BAA8B,CAC5C,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,yBAAyB,GAC/B,IAAI,CAIN"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.writeClaudePoolControllerLease = exports.readActiveClaudePoolControllerLease = void 0;
|
|
27
|
+
const fs = __importStar(require("node:fs"));
|
|
28
|
+
const os = __importStar(require("node:os"));
|
|
29
|
+
function readActiveClaudePoolControllerLease(file, target, now, staleMs) {
|
|
30
|
+
try {
|
|
31
|
+
const lease = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
32
|
+
if (lease.hostname !== os.hostname() ||
|
|
33
|
+
lease.target !== target ||
|
|
34
|
+
typeof lease.owner !== 'string' ||
|
|
35
|
+
!Number.isSafeInteger(lease.pid) ||
|
|
36
|
+
lease.pid <= 0 ||
|
|
37
|
+
!Number.isFinite(lease.updatedAt) ||
|
|
38
|
+
now - lease.updatedAt >= staleMs ||
|
|
39
|
+
lease.updatedAt > now)
|
|
40
|
+
return null;
|
|
41
|
+
process.kill(lease.pid, 0);
|
|
42
|
+
return lease;
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.readActiveClaudePoolControllerLease = readActiveClaudePoolControllerLease;
|
|
49
|
+
function writeClaudePoolControllerLease(file, lease) {
|
|
50
|
+
const temporary = `${file}.${lease.owner}.tmp`;
|
|
51
|
+
fs.writeFileSync(temporary, JSON.stringify(lease), { mode: 0o600 });
|
|
52
|
+
fs.renameSync(temporary, file);
|
|
53
|
+
}
|
|
54
|
+
exports.writeClaudePoolControllerLease = writeClaudePoolControllerLease;
|
|
55
|
+
//# sourceMappingURL=claude-pool-policy-lease.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude-pool-policy-lease.js","sourceRoot":"","sources":["../../../src/cliproxy/accounts/claude-pool-policy-lease.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA8B;AAC9B,4CAA8B;AAW9B,SAAgB,mCAAmC,CACjD,IAAY,EACZ,MAAc,EACd,GAAW,EACX,OAAe;IAEf,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAA8B,CAAC;QACrF,IACE,KAAK,CAAC,QAAQ,KAAK,EAAE,CAAC,QAAQ,EAAE;YAChC,KAAK,CAAC,MAAM,KAAK,MAAM;YACvB,OAAO,KAAK,CAAC,KAAK,KAAK,QAAQ;YAC/B,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC;YAChC,KAAK,CAAC,GAAG,IAAI,CAAC;YACd,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC;YACjC,GAAG,GAAG,KAAK,CAAC,SAAS,IAAI,OAAO;YAChC,KAAK,CAAC,SAAS,GAAG,GAAG;YAErB,OAAO,IAAI,CAAC;QACd,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QAC3B,OAAO,KAAK,CAAC;IACf,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAxBD,kFAwBC;AAED,SAAgB,8BAA8B,CAC5C,IAAY,EACZ,KAAgC;IAEhC,MAAM,SAAS,GAAG,GAAG,IAAI,IAAI,KAAK,CAAC,KAAK,MAAM,CAAC;IAC/C,EAAE,CAAC,aAAa,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IACpE,EAAE,CAAC,UAAU,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;AACjC,CAAC;AAPD,wEAOC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ProxyTarget } from '../proxy/proxy-target-resolver';
|
|
2
|
+
import type { ClaudePoolManagementApi } from './claude-pool-policy-api';
|
|
3
|
+
import type { ClaudePoolPolicyDependencies } from './claude-pool-policy-runtime';
|
|
4
|
+
import { type ClaudePoolPolicyState } from './claude-pool-policy-state';
|
|
5
|
+
export interface ReconciliationContext {
|
|
6
|
+
deps: ClaudePoolPolicyDependencies;
|
|
7
|
+
readState: () => ClaudePoolPolicyState | null;
|
|
8
|
+
writeState: (state: ClaudePoolPolicyState) => void;
|
|
9
|
+
signal: AbortSignal;
|
|
10
|
+
}
|
|
11
|
+
export declare function restoreClaudePoolPriorities(context: ReconciliationContext, state: ClaudePoolPolicyState, api: ClaudePoolManagementApi, valid: () => boolean): Promise<void>;
|
|
12
|
+
export declare function reconcileClaudePoolPriorities(context: ReconciliationContext, api: ClaudePoolManagementApi, target: ProxyTarget, valid: () => boolean): Promise<void>;
|
|
13
|
+
//# sourceMappingURL=claude-pool-policy-reconciliation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude-pool-policy-reconciliation.d.ts","sourceRoot":"","sources":["../../../src/cliproxy/accounts/claude-pool-policy-reconciliation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AACxE,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,8BAA8B,CAAC;AAEjF,OAAO,EAKL,KAAK,qBAAqB,EAC3B,MAAM,4BAA4B,CAAC;AAEpC,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,4BAA4B,CAAC;IACnC,SAAS,EAAE,MAAM,qBAAqB,GAAG,IAAI,CAAC;IAC9C,UAAU,EAAE,CAAC,KAAK,EAAE,qBAAqB,KAAK,IAAI,CAAC;IACnD,MAAM,EAAE,WAAW,CAAC;CACrB;AAMD,wBAAsB,2BAA2B,CAC/C,OAAO,EAAE,qBAAqB,EAC9B,KAAK,EAAE,qBAAqB,EAC5B,GAAG,EAAE,uBAAuB,EAC5B,KAAK,EAAE,MAAM,OAAO,GACnB,OAAO,CAAC,IAAI,CAAC,CAwDf;AAED,wBAAsB,6BAA6B,CACjD,OAAO,EAAE,qBAAqB,EAC9B,GAAG,EAAE,uBAAuB,EAC5B,MAAM,EAAE,WAAW,EACnB,KAAK,EAAE,MAAM,OAAO,GACnB,OAAO,CAAC,IAAI,CAAC,CA0Jf"}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.reconcileClaudePoolPriorities = exports.restoreClaudePoolPriorities = void 0;
|
|
4
|
+
const error_types_1 = require("../../errors/error-types");
|
|
5
|
+
const claude_pool_policy_state_1 = require("./claude-pool-policy-state");
|
|
6
|
+
function targetKey(target) {
|
|
7
|
+
return `${target.protocol}://${target.host}:${target.port}`;
|
|
8
|
+
}
|
|
9
|
+
async function restoreClaudePoolPriorities(context, state, api, valid) {
|
|
10
|
+
const credentials = new Map((await api.listCredentials()).map((entry) => [entry.name, entry.priority]));
|
|
11
|
+
const registeredFiles = new Set(context.deps.accounts().map((account) => account.tokenFile));
|
|
12
|
+
let pending = false;
|
|
13
|
+
let drift = false;
|
|
14
|
+
for (const entry of Object.values(state.entries)) {
|
|
15
|
+
if (!entry.ownsPriority && entry.pendingPriority === undefined)
|
|
16
|
+
continue;
|
|
17
|
+
if (!valid())
|
|
18
|
+
throw new error_types_1.ConfigError('Claude pool controller ownership was lost.');
|
|
19
|
+
if (!credentials.has(entry.tokenFile)) {
|
|
20
|
+
if (registeredFiles.has(entry.tokenFile))
|
|
21
|
+
pending = true;
|
|
22
|
+
else {
|
|
23
|
+
// Deleted accounts no longer have a runtime field to restore.
|
|
24
|
+
entry.ownsPriority = false;
|
|
25
|
+
delete entry.pendingPriority;
|
|
26
|
+
}
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
const current = credentials.get(entry.tokenFile) ?? null;
|
|
30
|
+
entry.effectivePriority = current;
|
|
31
|
+
if (current !== entry.lastAppliedPriority && current !== entry.pendingPriority) {
|
|
32
|
+
// A user or external manager changed this field: preserve their value.
|
|
33
|
+
drift = true;
|
|
34
|
+
entry.state = 'drift';
|
|
35
|
+
entry.ownsPriority = false;
|
|
36
|
+
delete entry.pendingPriority;
|
|
37
|
+
context.writeState(state);
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if (current !== entry.originalPriority) {
|
|
41
|
+
entry.pendingPriority = entry.originalPriority;
|
|
42
|
+
context.writeState(state);
|
|
43
|
+
await api.setPriority(entry.tokenFile, entry.originalPriority, current);
|
|
44
|
+
const readback = (await api.listCredentials()).find((credential) => credential.name === entry.tokenFile);
|
|
45
|
+
if (!readback || readback.priority !== entry.originalPriority) {
|
|
46
|
+
pending = true;
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
entry.ownsPriority = false;
|
|
51
|
+
entry.lastAppliedPriority = entry.originalPriority;
|
|
52
|
+
entry.effectivePriority = entry.originalPriority;
|
|
53
|
+
entry.state = 'applied';
|
|
54
|
+
delete entry.pendingPriority;
|
|
55
|
+
context.writeState(state);
|
|
56
|
+
}
|
|
57
|
+
state.restoring = pending;
|
|
58
|
+
state.status = pending || drift ? 'degraded' : 'inactive';
|
|
59
|
+
state.lastReconciledAt = context.deps.now();
|
|
60
|
+
if (pending)
|
|
61
|
+
state.error = 'Priority restoration is pending for unavailable credentials.';
|
|
62
|
+
else if (drift)
|
|
63
|
+
state.error = 'External priority changes were preserved during restoration.';
|
|
64
|
+
else
|
|
65
|
+
delete state.error;
|
|
66
|
+
context.writeState(state);
|
|
67
|
+
}
|
|
68
|
+
exports.restoreClaudePoolPriorities = restoreClaudePoolPriorities;
|
|
69
|
+
async function reconcileClaudePoolPriorities(context, api, target, valid) {
|
|
70
|
+
const state = context.readState();
|
|
71
|
+
if (!state)
|
|
72
|
+
return;
|
|
73
|
+
if (state.target !== targetKey(target))
|
|
74
|
+
throw new error_types_1.ConfigError('The local proxy target differs from the captured Claude pool ownership state.');
|
|
75
|
+
if (context.deps.drainOrder()?.mode !== 'quota' || !context.deps.poolEnabled()) {
|
|
76
|
+
if (context.deps.drainOrder()?.mode === 'quota') {
|
|
77
|
+
context.deps.saveDrainOrder(state.previousDrainOrder);
|
|
78
|
+
await context.deps.regenerate(target);
|
|
79
|
+
state.restoring = true;
|
|
80
|
+
context.writeState(state);
|
|
81
|
+
}
|
|
82
|
+
if (state.restoring)
|
|
83
|
+
await restoreClaudePoolPriorities(context, state, api, valid);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const accounts = context.deps.accounts();
|
|
87
|
+
const credentials = new Map((await api.listCredentials()).map((entry) => [entry.name, entry.priority]));
|
|
88
|
+
const observations = new Map();
|
|
89
|
+
const candidates = accounts.filter((account) => !account.paused && credentials.has(account.tokenFile));
|
|
90
|
+
for (let index = 0; index < candidates.length; index += 2) {
|
|
91
|
+
if (!valid() || context.deps.drainOrder()?.mode !== 'quota' || !context.deps.poolEnabled())
|
|
92
|
+
throw new error_types_1.ConfigError('Claude pool policy changed during reconciliation.');
|
|
93
|
+
await Promise.all(candidates.slice(index, index + 2).map(async (account) => {
|
|
94
|
+
try {
|
|
95
|
+
observations.set(account.id, await context.deps.quota(account.id, context.signal));
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
observations.set(account.id, {
|
|
99
|
+
success: false,
|
|
100
|
+
windows: [],
|
|
101
|
+
lastUpdated: context.deps.now(),
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}));
|
|
105
|
+
}
|
|
106
|
+
let degraded = false;
|
|
107
|
+
let pending = false;
|
|
108
|
+
for (const account of accounts) {
|
|
109
|
+
if (!valid() || context.deps.drainOrder()?.mode !== 'quota' || !context.deps.poolEnabled())
|
|
110
|
+
throw new error_types_1.ConfigError('Claude pool policy changed during reconciliation.');
|
|
111
|
+
if (account.paused)
|
|
112
|
+
continue;
|
|
113
|
+
if (!credentials.has(account.tokenFile)) {
|
|
114
|
+
const missing = state.entries[account.id];
|
|
115
|
+
if (missing)
|
|
116
|
+
missing.state = 'missing';
|
|
117
|
+
pending = true;
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
const current = credentials.get(account.tokenFile) ?? null;
|
|
121
|
+
let entry = Object.prototype.hasOwnProperty.call(state.entries, account.id)
|
|
122
|
+
? state.entries[account.id]
|
|
123
|
+
: undefined;
|
|
124
|
+
if (!entry) {
|
|
125
|
+
entry = {
|
|
126
|
+
tokenFile: account.tokenFile,
|
|
127
|
+
originalPriority: current,
|
|
128
|
+
lastAppliedPriority: current,
|
|
129
|
+
ownsPriority: false,
|
|
130
|
+
class: 'unknown',
|
|
131
|
+
confirmedAt: null,
|
|
132
|
+
};
|
|
133
|
+
Object.defineProperty(state.entries, account.id, {
|
|
134
|
+
value: entry,
|
|
135
|
+
enumerable: true,
|
|
136
|
+
configurable: true,
|
|
137
|
+
writable: true,
|
|
138
|
+
});
|
|
139
|
+
context.writeState(state);
|
|
140
|
+
}
|
|
141
|
+
entry.effectivePriority = current;
|
|
142
|
+
if (entry.tokenFile !== account.tokenFile ||
|
|
143
|
+
((entry.ownsPriority || entry.pendingPriority !== undefined) &&
|
|
144
|
+
current !== entry.lastAppliedPriority &&
|
|
145
|
+
current !== entry.pendingPriority)) {
|
|
146
|
+
degraded = true;
|
|
147
|
+
entry.state = 'drift';
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (entry.pendingPriority !== undefined && current === entry.pendingPriority) {
|
|
151
|
+
// A previous PATCH succeeded but its acknowledgement was lost. Claim it before
|
|
152
|
+
// journaling a different target, so a second lost response is not mistaken for drift.
|
|
153
|
+
entry.lastAppliedPriority = current;
|
|
154
|
+
entry.ownsPriority = true;
|
|
155
|
+
delete entry.pendingPriority;
|
|
156
|
+
context.writeState(state);
|
|
157
|
+
}
|
|
158
|
+
const quota = observations.get(account.id) ?? {
|
|
159
|
+
success: false,
|
|
160
|
+
windows: [],
|
|
161
|
+
lastUpdated: context.deps.now(),
|
|
162
|
+
};
|
|
163
|
+
if (quota.accountId !== undefined && quota.accountId !== account.id) {
|
|
164
|
+
degraded = true;
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
Object.assign(entry, (0, claude_pool_policy_state_1.confirmClaudePoolClass)(entry, quota, context.deps.now()));
|
|
168
|
+
const desired = (0, claude_pool_policy_state_1.claudePoolClassPriority)((0, claude_pool_policy_state_1.effectiveClaudePoolClass)(entry, context.deps.now()));
|
|
169
|
+
if (!valid() || context.deps.drainOrder()?.mode !== 'quota' || !context.deps.poolEnabled())
|
|
170
|
+
throw new error_types_1.ConfigError('Claude pool policy changed during reconciliation.');
|
|
171
|
+
if (current !== desired) {
|
|
172
|
+
const beforeWrite = (await api.listCredentials()).find((credential) => credential.name === account.tokenFile);
|
|
173
|
+
if (!beforeWrite || beforeWrite.priority !== current) {
|
|
174
|
+
degraded = true;
|
|
175
|
+
entry.state = 'drift';
|
|
176
|
+
entry.effectivePriority = beforeWrite?.priority ?? null;
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
// Persist intent before PATCH: a crash or lost response is recovered by readback.
|
|
180
|
+
entry.pendingPriority = desired;
|
|
181
|
+
entry.state = 'pending';
|
|
182
|
+
context.writeState(state);
|
|
183
|
+
try {
|
|
184
|
+
await api.setPriority(account.tokenFile, desired, current);
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
pending = true;
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
const readback = (await api.listCredentials()).find((credential) => credential.name === account.tokenFile);
|
|
191
|
+
if (!readback || readback.priority !== desired) {
|
|
192
|
+
pending = true;
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
entry.lastAppliedPriority = desired;
|
|
197
|
+
entry.effectivePriority = desired;
|
|
198
|
+
entry.state = 'applied';
|
|
199
|
+
entry.ownsPriority = true;
|
|
200
|
+
delete entry.pendingPriority;
|
|
201
|
+
context.writeState(state);
|
|
202
|
+
}
|
|
203
|
+
state.status = degraded ? 'degraded' : pending ? 'pending' : 'active';
|
|
204
|
+
state.lastReconciledAt = context.deps.now();
|
|
205
|
+
if (degraded)
|
|
206
|
+
state.error =
|
|
207
|
+
'External priority or account identity changes were preserved. Disable and re-enable quota ordering to accept a new baseline, or choose a manual order.';
|
|
208
|
+
else if (pending)
|
|
209
|
+
state.error = 'Some priorities are pending application or runtime verification.';
|
|
210
|
+
else
|
|
211
|
+
delete state.error;
|
|
212
|
+
context.writeState(state);
|
|
213
|
+
}
|
|
214
|
+
exports.reconcileClaudePoolPriorities = reconcileClaudePoolPriorities;
|
|
215
|
+
//# sourceMappingURL=claude-pool-policy-reconciliation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude-pool-policy-reconciliation.js","sourceRoot":"","sources":["../../../src/cliproxy/accounts/claude-pool-policy-reconciliation.ts"],"names":[],"mappings":";;;AAAA,0DAAuD;AAKvD,yEAMoC;AASpC,SAAS,SAAS,CAAC,MAAmB;IACpC,OAAO,GAAG,MAAM,CAAC,QAAQ,MAAM,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;AAC9D,CAAC;AAEM,KAAK,UAAU,2BAA2B,CAC/C,OAA8B,EAC9B,KAA4B,EAC5B,GAA4B,EAC5B,KAAoB;IAEpB,MAAM,WAAW,GAAG,IAAI,GAAG,CACzB,CAAC,MAAM,GAAG,CAAC,eAAe,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,C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I,CAAC;gBACf,SAAS;YACX,CAAC;YACD,MAAM,QAAQ,GAAG,CAAC,MAAM,GAAG,CAAC,eAAe,EAAE,CAAC,CAAC,IAAI,CACjD,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,KAAK,OAAO,CAAC,SAAS,CACtD,CAAC;YACF,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;gBAC/C,OAAO,GAAG,IAAI,CAAC;gBACf,SAAS;YACX,CAAC;QACH,CAAC;QACD,KAAK,CAAC,mBAAmB,GAAG,OAAO,CAAC;QACpC,KAAK,CAAC,iBAAiB,GAAG,OAAO,CAAC;QAClC,KAAK,CAAC,KAAK,GAAG,SAAS,CAAC;QACxB,KAAK,CAAC,YAAY,GAAG,IAAI,CAAC;QAC1B,OAAO,KAAK,CAAC,eAAe,CAAC;QAC7B,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IAC5B,CAAC;IACD,KAAK,CAAC,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC;IACtE,KAAK,CAAC,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;IAC5C,IAAI,QAAQ;QACV,KAAK,CAAC,KAAK;YACT,wJAAwJ,CAAC;SACxJ,IAAI,OAAO;QACd,KAAK,CAAC,KAAK,GAAG,kEAAkE,CAAC;;QAC9E,OAAO,KAAK,CAAC,KAAK,CAAC;IACxB,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;AAC5B,CAAC;AA/JD,sEA+JC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { AccountInfo, DrainOrderConfig } from './types';
|
|
2
|
+
import type { ClaudeQuotaResult } from '../quota/quota-types';
|
|
3
|
+
import { type ProxyTarget } from '../proxy/proxy-target-resolver';
|
|
4
|
+
import { type ClaudePoolManagementApi } from './claude-pool-policy-api';
|
|
5
|
+
export interface ClaudePoolPolicyDependencies {
|
|
6
|
+
file: string;
|
|
7
|
+
now: () => number;
|
|
8
|
+
target: () => ProxyTarget;
|
|
9
|
+
accounts: () => AccountInfo[];
|
|
10
|
+
quota: (accountId: string, signal?: AbortSignal) => Promise<ClaudeQuotaResult>;
|
|
11
|
+
poolEnabled: () => boolean;
|
|
12
|
+
drainOrder: () => DrainOrderConfig | undefined;
|
|
13
|
+
saveDrainOrder: (config: DrainOrderConfig | null) => void;
|
|
14
|
+
verifyProxy: (target: ProxyTarget) => Promise<boolean>;
|
|
15
|
+
management: (target: ProxyTarget, signal?: AbortSignal) => ClaudePoolManagementApi;
|
|
16
|
+
regenerate: (target: ProxyTarget) => Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
export declare function createClaudePoolPolicyDependencies(overrides: Partial<ClaudePoolPolicyDependencies>): ClaudePoolPolicyDependencies;
|
|
19
|
+
//# sourceMappingURL=claude-pool-policy-runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude-pool-policy-runtime.d.ts","sourceRoot":"","sources":["../../../src/cliproxy/accounts/claude-pool-policy-runtime.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC7D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAK9D,OAAO,EAAkB,KAAK,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAElF,OAAO,EAEL,KAAK,uBAAuB,EAC7B,MAAM,0BAA0B,CAAC;AAGlC,MAAM,WAAW,4BAA4B;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,WAAW,CAAC;IAC1B,QAAQ,EAAE,MAAM,WAAW,EAAE,CAAC;IAC9B,KAAK,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAC/E,WAAW,EAAE,MAAM,OAAO,CAAC;IAC3B,UAAU,EAAE,MAAM,gBAAgB,GAAG,SAAS,CAAC;IAC/C,cAAc,EAAE,CAAC,MAAM,EAAE,gBAAgB,GAAG,IAAI,KAAK,IAAI,CAAC;IAC1D,WAAW,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACvD,UAAU,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,CAAC,EAAE,WAAW,KAAK,uBAAuB,CAAC;IACnF,UAAU,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACpD;AAED,wBAAgB,kCAAkC,CAChD,SAAS,EAAE,OAAO,CAAC,4BAA4B,CAAC,GAC/C,4BAA4B,CA6B9B"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.createClaudePoolPolicyDependencies = void 0;
|
|
27
|
+
const error_types_1 = require("../../errors/error-types");
|
|
28
|
+
const query_1 = require("./query");
|
|
29
|
+
const registry_1 = require("./registry");
|
|
30
|
+
const quota_fetcher_claude_1 = require("../quota/quota-fetcher-claude");
|
|
31
|
+
const config_loader_facade_1 = require("../../config/config-loader-facade");
|
|
32
|
+
const proxy_target_resolver_1 = require("../proxy/proxy-target-resolver");
|
|
33
|
+
const proxy_detector_1 = require("../proxy/proxy-detector");
|
|
34
|
+
const claude_pool_policy_api_1 = require("./claude-pool-policy-api");
|
|
35
|
+
const claude_pool_policy_state_1 = require("./claude-pool-policy-state");
|
|
36
|
+
function createClaudePoolPolicyDependencies(overrides) {
|
|
37
|
+
return {
|
|
38
|
+
file: (0, claude_pool_policy_state_1.getClaudePoolPolicyStatePath)(),
|
|
39
|
+
now: Date.now,
|
|
40
|
+
target: proxy_target_resolver_1.getProxyTarget,
|
|
41
|
+
accounts: () => (0, query_1.getProviderAccounts)('claude'),
|
|
42
|
+
quota: (accountId, signal) => (0, quota_fetcher_claude_1.fetchClaudeQuota)(accountId, false, signal),
|
|
43
|
+
poolEnabled: () => (0, config_loader_facade_1.loadOrCreateUnifiedConfig)().cliproxy?.pool_routing?.enabled === true,
|
|
44
|
+
drainOrder: () => (0, registry_1.loadDrainOrderConfig)('claude'),
|
|
45
|
+
saveDrainOrder: (config) => {
|
|
46
|
+
const saved = config
|
|
47
|
+
? (0, registry_1.saveDrainOrderConfig)('claude', config)
|
|
48
|
+
: (0, registry_1.clearDrainOrderConfig)('claude');
|
|
49
|
+
if (config && !saved)
|
|
50
|
+
throw new error_types_1.ConfigError('No Claude account registry is available. Add an account before enabling quota ordering.');
|
|
51
|
+
},
|
|
52
|
+
verifyProxy: async (target) => {
|
|
53
|
+
const status = await (0, proxy_detector_1.detectRunningProxy)(target.port);
|
|
54
|
+
return status.running && status.verified;
|
|
55
|
+
},
|
|
56
|
+
management: claude_pool_policy_api_1.createClaudePoolManagementApi,
|
|
57
|
+
regenerate: async (target) => {
|
|
58
|
+
const { regenerateConfig } = await Promise.resolve().then(() => __importStar(require('../config/generator')));
|
|
59
|
+
regenerateConfig(target.port);
|
|
60
|
+
},
|
|
61
|
+
...overrides,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
exports.createClaudePoolPolicyDependencies = createClaudePoolPolicyDependencies;
|
|
65
|
+
//# sourceMappingURL=claude-pool-policy-runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude-pool-policy-runtime.js","sourceRoot":"","sources":["../../../src/cliproxy/accounts/claude-pool-policy-runtime.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAAuD;AAGvD,mCAA8C;AAC9C,yCAA+F;AAC/F,wEAAiE;AACjE,4EAA8E;AAC9E,0EAAkF;AAClF,4DAA6D;AAC7D,qEAGkC;AAClC,yEAA0E;AAgB1E,SAAgB,kCAAkC,CAChD,SAAgD;IAEhD,OAAO;QACL,IAAI,EAAE,IAAA,uDAA4B,GAAE;QACpC,GAAG,EAAE,IAAI,CAAC,GAAG;QACb,MAAM,EAAE,sCAAc;QACtB,QAAQ,EAAE,GAAG,EAAE,CAAC,IAAA,2BAAmB,EAAC,QAAQ,CAAC;QAC7C,KAAK,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,CAAC,IAAA,uCAAgB,EAAC,SAAS,EAAE,KAAK,EAAE,MAAM,CAAC;QACxE,WAAW,EAAE,GAAG,EAAE,CAAC,IAAA,gDAAyB,GAAE,CAAC,QAAQ,EAAE,YAAY,EAAE,OAAO,KAAK,IAAI;QACvF,UAAU,EAAE,GAAG,EAAE,CAAC,IAAA,+BAAoB,EAAC,QAAQ,CAAC;QAChD,cAAc,EAAE,CAAC,MAAM,EAAE,EAAE;YACzB,MAAM,KAAK,GAAG,MAAM;gBAClB,CAAC,CAAC,IAAA,+BAAoB,EAAC,QAAQ,EAAE,MAAM,CAAC;gBACxC,CAAC,CAAC,IAAA,gCAAqB,EAAC,QAAQ,CAAC,CAAC;YACpC,IAAI,MAAM,IAAI,CAAC,KAAK;gBAClB,MAAM,IAAI,yBAAW,CACnB,yFAAyF,CAC1F,CAAC;QACN,CAAC;QACD,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;YAC5B,MAAM,MAAM,GAAG,MAAM,IAAA,mCAAkB,EAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YACrD,OAAO,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,QAAQ,CAAC;QAC3C,CAAC;QACD,UAAU,EAAE,sDAA6B;QACzC,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;YAC3B,MAAM,EAAE,gBAAgB,EAAE,GAAG,wDAAa,qBAAqB,GAAC,CAAC;YACjE,gBAAgB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAChC,CAAC;QACD,GAAG,SAAS;KACb,CAAC;AACJ,CAAC;AA/BD,gFA+BC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ClaudePoolQuotaClass, ClaudePoolPolicyStatus } from '../../shared/claude-pool-policy';
|
|
2
|
+
import type { ClaudeQuotaResult } from '../quota/quota-types';
|
|
3
|
+
import type { DrainOrderConfig, AccountInfo } from './types';
|
|
4
|
+
export declare const CLAUDE_POOL_CLASS_MAX_AGE_MS: number;
|
|
5
|
+
export declare const CLAUDE_POOL_RECONCILE_MS = 60000;
|
|
6
|
+
export interface ClaudePoolPolicyEntry {
|
|
7
|
+
tokenFile: string;
|
|
8
|
+
originalPriority: number | null;
|
|
9
|
+
lastAppliedPriority: number | null;
|
|
10
|
+
ownsPriority: boolean;
|
|
11
|
+
pendingPriority?: number | null;
|
|
12
|
+
class: ClaudePoolQuotaClass;
|
|
13
|
+
confirmedAt: number | null;
|
|
14
|
+
effectivePriority?: number | null;
|
|
15
|
+
state?: 'applied' | 'pending' | 'drift' | 'paused' | 'missing';
|
|
16
|
+
}
|
|
17
|
+
export interface ClaudePoolPolicyState {
|
|
18
|
+
version: 1;
|
|
19
|
+
target: string;
|
|
20
|
+
previousDrainOrder: DrainOrderConfig | null;
|
|
21
|
+
entries: Record<string, ClaudePoolPolicyEntry>;
|
|
22
|
+
lastReconciledAt: number | null;
|
|
23
|
+
status: ClaudePoolPolicyStatus['status'];
|
|
24
|
+
error?: string;
|
|
25
|
+
restoring?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export declare function getClaudePoolPolicyStatePath(): string;
|
|
28
|
+
export declare function createClaudePoolPolicyState(target: string): ClaudePoolPolicyState;
|
|
29
|
+
/** Corrupt ownership records must never be silently replaced before mutation. */
|
|
30
|
+
export declare function readClaudePoolPolicyState(file?: string): ClaudePoolPolicyState | null;
|
|
31
|
+
export declare function writeClaudePoolPolicyState(state: ClaudePoolPolicyState, file?: string): void;
|
|
32
|
+
export declare function claudePoolClassPriority(value: ClaudePoolQuotaClass): number;
|
|
33
|
+
export declare function effectiveClaudePoolClass(entry: Pick<ClaudePoolPolicyEntry, 'class' | 'confirmedAt'>, now: number): ClaudePoolQuotaClass;
|
|
34
|
+
/** Only fresh, complete provider observations confirm shape, never filtered stale windows. */
|
|
35
|
+
export declare function confirmClaudePoolClass(previous: Pick<ClaudePoolPolicyEntry, 'class' | 'confirmedAt'>, quota: ClaudeQuotaResult, now: number): Pick<ClaudePoolPolicyEntry, 'class' | 'confirmedAt'>;
|
|
36
|
+
export declare function buildClaudePoolPolicyStatus(enabled: boolean, controllerActive: boolean, state: ClaudePoolPolicyState | null, inputAccounts: AccountInfo[], now: number, startedAt?: number): ClaudePoolPolicyStatus;
|
|
37
|
+
//# sourceMappingURL=claude-pool-policy-state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude-pool-policy-state.d.ts","sourceRoot":"","sources":["../../../src/cliproxy/accounts/claude-pool-policy-state.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,oBAAoB,EACpB,sBAAsB,EAEvB,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAG7D,eAAO,MAAM,4BAA4B,QAAkB,CAAC;AAC5D,eAAO,MAAM,wBAAwB,QAAS,CAAC;AAE/C,MAAM,WAAW,qBAAqB;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,mBAAmB,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,YAAY,EAAE,OAAO,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,KAAK,EAAE,oBAAoB,CAAC;IAC5B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,KAAK,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,CAAC;CAChE;AAED,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,CAAC,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,kBAAkB,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAC5C,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC;IAC/C,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,MAAM,EAAE,sBAAsB,CAAC,QAAQ,CA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