saros-proxy 0.7.4 → 0.10.0
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/LICENSE +0 -0
- package/README.md +116 -64
- package/dist/cli/autostart.d.ts +0 -0
- package/dist/cli/autostart.js +0 -0
- package/dist/cli/autostart.js.map +0 -0
- package/dist/cli/daemon.d.ts +0 -0
- package/dist/cli/daemon.js +4 -0
- package/dist/cli/daemon.js.map +1 -1
- package/dist/cli/dsh-config.d.ts +32 -0
- package/dist/cli/dsh-config.js +122 -0
- package/dist/cli/dsh-config.js.map +1 -0
- package/dist/cli/harness-models.d.ts +26 -2
- package/dist/cli/harness-models.js +192 -2
- package/dist/cli/harness-models.js.map +1 -1
- package/dist/cli/harness-sync.d.ts +3 -6
- package/dist/cli/harness-sync.js +14 -7
- package/dist/cli/harness-sync.js.map +1 -1
- package/dist/cli/help.d.ts +0 -0
- package/dist/cli/help.js +2 -2
- package/dist/cli/help.js.map +0 -0
- package/dist/cli/omp-config.d.ts +0 -0
- package/dist/cli/omp-config.js +11 -1
- package/dist/cli/omp-config.js.map +1 -1
- package/dist/cli/opencode-config.d.ts +0 -0
- package/dist/cli/opencode-config.js +0 -0
- package/dist/cli/opencode-config.js.map +0 -0
- package/dist/cli/overview.d.ts +0 -0
- package/dist/cli/overview.js +2 -1
- package/dist/cli/overview.js.map +1 -1
- package/dist/cli/pi-config.d.ts +0 -0
- package/dist/cli/pi-config.js +11 -1
- package/dist/cli/pi-config.js.map +1 -1
- package/dist/cli/setup.d.ts +6 -10
- package/dist/cli/setup.js +100 -232
- package/dist/cli/setup.js.map +1 -1
- package/dist/cli/ui.d.ts +1 -2
- package/dist/cli/ui.js +0 -16
- package/dist/cli/ui.js.map +1 -1
- package/dist/cli/update-check.d.ts +0 -0
- package/dist/cli/update-check.js +0 -0
- package/dist/cli/update-check.js.map +0 -0
- package/dist/cli/usage.d.ts +12 -0
- package/dist/cli/usage.js +182 -0
- package/dist/cli/usage.js.map +1 -0
- package/dist/config.d.ts +13 -17
- package/dist/config.js +29 -78
- package/dist/config.js.map +1 -1
- package/dist/constants.d.ts +9 -5
- package/dist/constants.js +14 -5
- package/dist/constants.js.map +1 -1
- package/dist/index.d.ts +0 -0
- package/dist/index.js +9 -25
- package/dist/index.js.map +1 -1
- package/dist/key-encryption.d.ts +0 -0
- package/dist/key-encryption.js +0 -0
- package/dist/key-encryption.js.map +0 -0
- package/dist/logger.d.ts +0 -0
- package/dist/logger.js +0 -0
- package/dist/logger.js.map +0 -0
- package/dist/model-probe.d.ts +0 -0
- package/dist/model-probe.js +0 -0
- package/dist/model-probe.js.map +0 -0
- package/dist/model-stats.d.ts +20 -0
- package/dist/model-stats.js +135 -0
- package/dist/model-stats.js.map +1 -0
- package/dist/models-fetcher.d.ts +0 -0
- package/dist/models-fetcher.js +0 -0
- package/dist/models-fetcher.js.map +0 -0
- package/dist/models-sync.d.ts +0 -0
- package/dist/models-sync.js +0 -0
- package/dist/models-sync.js.map +0 -0
- package/dist/probe-cache.d.ts +0 -0
- package/dist/probe-cache.js +0 -0
- package/dist/probe-cache.js.map +0 -0
- package/dist/providers/commandcode.d.ts +17 -0
- package/dist/providers/commandcode.js +237 -0
- package/dist/providers/commandcode.js.map +1 -0
- package/dist/providers/index.d.ts +43 -0
- package/dist/providers/index.js +75 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/infer.d.ts +23 -0
- package/dist/providers/infer.js +13 -0
- package/dist/providers/infer.js.map +1 -0
- package/dist/providers/opencode-go.d.ts +4 -0
- package/dist/providers/opencode-go.js +190 -0
- package/dist/providers/opencode-go.js.map +1 -0
- package/dist/providers/types.d.ts +135 -0
- package/dist/providers/types.js +10 -0
- package/dist/providers/types.js.map +1 -0
- package/dist/proxy-logic.d.ts +61 -22
- package/dist/proxy-logic.js +163 -106
- package/dist/proxy-logic.js.map +1 -1
- package/dist/proxy.d.ts +43 -2
- package/dist/proxy.js +327 -62
- package/dist/proxy.js.map +1 -1
- package/dist/token-usage.d.ts +53 -0
- package/dist/token-usage.js +198 -0
- package/dist/token-usage.js.map +1 -0
- package/dist/usage-client.d.ts +62 -0
- package/dist/usage-client.js +155 -0
- package/dist/usage-client.js.map +1 -0
- package/dist/validation.d.ts +5 -5
- package/dist/validation.js +7 -9
- package/dist/validation.js.map +1 -1
- package/package.json +11 -7
- package/dist/dashboard-parser.d.ts +0 -47
- package/dist/dashboard-parser.js +0 -88
- package/dist/dashboard-parser.js.map +0 -1
- package/dist/firefox-cookies.d.ts +0 -42
- package/dist/firefox-cookies.js +0 -170
- package/dist/firefox-cookies.js.map +0 -1
- package/dist/scraper.d.ts +0 -70
- package/dist/scraper.js +0 -239
- package/dist/scraper.js.map +0 -1
package/dist/validation.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Centralises input validation patterns used across config.ts and setup.ts
|
|
5
5
|
* to ensure consistent rules and reduce duplication.
|
|
6
6
|
*/
|
|
7
|
-
import {
|
|
7
|
+
import { isPlausibleKey } from './providers/index.js';
|
|
8
8
|
/**
|
|
9
9
|
* Check if the given value is a valid TCP port number (1–65535).
|
|
10
10
|
*/
|
|
@@ -19,10 +19,14 @@ export function isValidPort(value) {
|
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* Check if the given string looks like a valid API key.
|
|
22
|
-
*
|
|
22
|
+
*
|
|
23
|
+
* Multi-provider aware: accepts `oc_sk_` (OpenCode-Go), `sk-` (opencode-go /
|
|
24
|
+
* commandcode console keys) and `user_` (commandcode tokens) of at least
|
|
25
|
+
* {@link MIN_KEY_LENGTH} characters. Structural check only — provider
|
|
26
|
+
* identity is confirmed by the smoke test in `identifyKey()`.
|
|
23
27
|
*/
|
|
24
28
|
export function isValidApiKey(key) {
|
|
25
|
-
return typeof key === 'string' && key
|
|
29
|
+
return typeof key === 'string' && isPlausibleKey(key);
|
|
26
30
|
}
|
|
27
31
|
/**
|
|
28
32
|
* Check if the given value is a valid HTTPS URL.
|
|
@@ -55,10 +59,4 @@ export function isValidPositiveInt(val, min = 1, max = 100) {
|
|
|
55
59
|
const n = Number.parseInt(trimmed, 10);
|
|
56
60
|
return n >= min && n <= max;
|
|
57
61
|
}
|
|
58
|
-
/**
|
|
59
|
-
* Check if the given string is a valid workspace ID (matches `wrk_[A-Za-z0-9]+`).
|
|
60
|
-
*/
|
|
61
|
-
export function isValidWorkspaceId(id) {
|
|
62
|
-
return typeof id === 'string' && WORKSPACE_ID_REGEX.test(id);
|
|
63
|
-
}
|
|
64
62
|
//# sourceMappingURL=validation.js.map
|
package/dist/validation.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;QAC7B,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC;YAAE,OAAO,KAAK,CAAC;QACzC,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IACvC,CAAC;IACD,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,KAAK,IAAI,KAAK,CAAC;AAC9F,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAAC,GAAY;IACxC,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,cAAc,CAAC,GAAG,CAAC,CAAC;AACxD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,GAAY;IAC1C,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC1C,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;QAC5B,OAAO,MAAM,CAAC,QAAQ,KAAK,QAAQ,CAAC;IACtC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAW,EAAE,GAAG,GAAG,CAAC,EAAE,GAAG,GAAG,GAAG;IAChE,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;IAC3B,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC;QAAE,OAAO,KAAK,CAAC;IACzC,MAAM,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IACvC,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,GAAG,CAAC;AAC9B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "saros-proxy",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Saros — predictive multi-account proxy for the OpenCode-Go API. Cycles between accounts before they exhaust.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -21,11 +21,15 @@
|
|
|
21
21
|
"test": "vitest",
|
|
22
22
|
"coverage": "vitest run --coverage",
|
|
23
23
|
"test:npm": "vitest run test/npm-package.test.ts",
|
|
24
|
+
"test:live-model": "npm run build && vitest run --config vitest.e2e.config.ts test/live-model.e2e.test.ts",
|
|
24
25
|
"test:source": "vitest run test/source-install.test.ts",
|
|
26
|
+
"test:install": "npm run build && vitest run --config vitest.e2e.config.ts test/install.e2e.test.ts",
|
|
27
|
+
"test:model-e2e": "npm run build && vitest run --config vitest.e2e.config.ts test/model-e2e.test.ts",
|
|
25
28
|
"test:docker": "vitest run test/docker-install.test.ts",
|
|
26
29
|
"docker:build": "docker compose build proxy",
|
|
27
30
|
"docker:run": "docker compose up proxy",
|
|
28
|
-
"docker:test": "docker compose run --rm test"
|
|
31
|
+
"docker:test": "docker compose run --rm test",
|
|
32
|
+
"test:e2e": "npm run build && vitest run --config vitest.e2e.config.ts"
|
|
29
33
|
},
|
|
30
34
|
"keywords": [
|
|
31
35
|
"opencode",
|
|
@@ -52,16 +56,16 @@
|
|
|
52
56
|
},
|
|
53
57
|
"homepage": "https://github.com/vitorvilaca3011/saros-proxy#readme",
|
|
54
58
|
"devDependencies": {
|
|
55
|
-
"@types/node": "^26.
|
|
56
|
-
"@vitest/coverage-v8": "^
|
|
59
|
+
"@types/node": "^26.6.4",
|
|
60
|
+
"@vitest/coverage-v8": "^5.0.3",
|
|
57
61
|
"pino-pretty": "^13.1.3",
|
|
58
62
|
"tsx": "^4.23.12",
|
|
59
63
|
"typescript": "^7.0.2",
|
|
60
|
-
"vitest": "^
|
|
64
|
+
"vitest": "^5.0.3"
|
|
61
65
|
},
|
|
62
66
|
"dependencies": {
|
|
63
|
-
"@clack/prompts": "^1.
|
|
64
|
-
"@hono/node-server": "^2.
|
|
67
|
+
"@clack/prompts": "^1.8.1",
|
|
68
|
+
"@hono/node-server": "^2.1.3",
|
|
65
69
|
"chalk": "^6.0.0",
|
|
66
70
|
"hono": "^4.12.23",
|
|
67
71
|
"hono-rate-limiter": "^0.5.3",
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* dashboard-parser.ts — Parse usage percentages from the OpenCode-Go dashboard HTML.
|
|
3
|
-
*
|
|
4
|
-
* The dashboard returns SolidJS SSR hydration data with usage percentages
|
|
5
|
-
* for three time windows: rolling (~5h), weekly, and monthly.
|
|
6
|
-
*
|
|
7
|
-
* Example hydration data:
|
|
8
|
-
* ```
|
|
9
|
-
* rollingUsage:$R[3]={usagePercent:45.2,resetInSec:18000}
|
|
10
|
-
* weeklyUsage:$R[4]={usagePercent:60.5,resetInSec:604800}
|
|
11
|
-
* monthlyUsage:$R[5]={usagePercent:30.0,resetInSec:2592000}
|
|
12
|
-
* ```
|
|
13
|
-
*
|
|
14
|
-
* Field order (usagePercent vs resetInSec) can vary between responses.
|
|
15
|
-
* These functions handle both orderings by trying two regex patterns per window.
|
|
16
|
-
*/
|
|
17
|
-
export interface UsageData {
|
|
18
|
-
rolling: number | null;
|
|
19
|
-
weekly: number | null;
|
|
20
|
-
monthly: number | null;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Parse all three usage windows (rolling, weekly, monthly) from dashboard HTML.
|
|
24
|
-
* Returns null for any window that couldn't be parsed.
|
|
25
|
-
*
|
|
26
|
-
* @param html — Raw HTML from the OpenCode-Go dashboard page.
|
|
27
|
-
* @returns An object with `rolling`, `weekly`, and `monthly` usage percentages,
|
|
28
|
-
* or null for windows that could not be parsed.
|
|
29
|
-
*/
|
|
30
|
-
export declare function parseAllUsage(html: string): UsageData;
|
|
31
|
-
/**
|
|
32
|
-
* Parse a single usage window from dashboard HTML.
|
|
33
|
-
*
|
|
34
|
-
* Tries two regex patterns to handle field order variance
|
|
35
|
-
* (usagePercent before or after resetInSec).
|
|
36
|
-
*
|
|
37
|
-
* Returns null if:
|
|
38
|
-
* - The window data is not found in the HTML
|
|
39
|
-
* - The extracted value is not a finite number
|
|
40
|
-
* - The HTML is malformed or from a non-dashboard page
|
|
41
|
-
*
|
|
42
|
-
* @param html — Raw HTML from the OpenCode-Go dashboard page.
|
|
43
|
-
* @param window — The time window to parse: `'rolling'`, `'weekly'`, or `'monthly'`.
|
|
44
|
-
* @returns The usage percentage as a number (may be negative or exceed 100),
|
|
45
|
-
* or null if the value could not be extracted.
|
|
46
|
-
*/
|
|
47
|
-
export declare function parseUsagePercent(html: string, window: 'rolling' | 'weekly' | 'monthly'): number | null;
|
package/dist/dashboard-parser.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* dashboard-parser.ts — Parse usage percentages from the OpenCode-Go dashboard HTML.
|
|
3
|
-
*
|
|
4
|
-
* The dashboard returns SolidJS SSR hydration data with usage percentages
|
|
5
|
-
* for three time windows: rolling (~5h), weekly, and monthly.
|
|
6
|
-
*
|
|
7
|
-
* Example hydration data:
|
|
8
|
-
* ```
|
|
9
|
-
* rollingUsage:$R[3]={usagePercent:45.2,resetInSec:18000}
|
|
10
|
-
* weeklyUsage:$R[4]={usagePercent:60.5,resetInSec:604800}
|
|
11
|
-
* monthlyUsage:$R[5]={usagePercent:30.0,resetInSec:2592000}
|
|
12
|
-
* ```
|
|
13
|
-
*
|
|
14
|
-
* Field order (usagePercent vs resetInSec) can vary between responses.
|
|
15
|
-
* These functions handle both orderings by trying two regex patterns per window.
|
|
16
|
-
*/
|
|
17
|
-
// ---------------------------------------------------------------------------
|
|
18
|
-
// Regex patterns
|
|
19
|
-
// ---------------------------------------------------------------------------
|
|
20
|
-
const SCRAPED_NUMBER_PATTERN = String.raw `(-?\d+(?:\.\d+)?)`;
|
|
21
|
-
const RE_ROLLING_PCT_FIRST = new RegExp(String.raw `rollingUsage:\$R\[\d+\]=\{[^}]*usagePercent:${SCRAPED_NUMBER_PATTERN}[^}]*resetInSec:${SCRAPED_NUMBER_PATTERN}[^}]*\}`);
|
|
22
|
-
const RE_ROLLING_RESET_FIRST = new RegExp(String.raw `rollingUsage:\$R\[\d+\]=\{[^}]*resetInSec:${SCRAPED_NUMBER_PATTERN}[^}]*usagePercent:${SCRAPED_NUMBER_PATTERN}[^}]*\}`);
|
|
23
|
-
const RE_WEEKLY_PCT_FIRST = new RegExp(String.raw `weeklyUsage:\$R\[\d+\]=\{[^}]*usagePercent:${SCRAPED_NUMBER_PATTERN}[^}]*resetInSec:${SCRAPED_NUMBER_PATTERN}[^}]*\}`);
|
|
24
|
-
const RE_WEEKLY_RESET_FIRST = new RegExp(String.raw `weeklyUsage:\$R\[\d+\]=\{[^}]*resetInSec:${SCRAPED_NUMBER_PATTERN}[^}]*usagePercent:${SCRAPED_NUMBER_PATTERN}[^}]*\}`);
|
|
25
|
-
const RE_MONTHLY_PCT_FIRST = new RegExp(String.raw `monthlyUsage:\$R\[\d+\]=\{[^}]*usagePercent:${SCRAPED_NUMBER_PATTERN}[^}]*resetInSec:${SCRAPED_NUMBER_PATTERN}[^}]*\}`);
|
|
26
|
-
const RE_MONTHLY_RESET_FIRST = new RegExp(String.raw `monthlyUsage:\$R\[\d+\]=\{[^}]*resetInSec:${SCRAPED_NUMBER_PATTERN}[^}]*usagePercent:${SCRAPED_NUMBER_PATTERN}[^}]*\}`);
|
|
27
|
-
// Map from window name to its two regex alternatives
|
|
28
|
-
const PATTERNS = {
|
|
29
|
-
rolling: [RE_ROLLING_PCT_FIRST, RE_ROLLING_RESET_FIRST],
|
|
30
|
-
weekly: [RE_WEEKLY_PCT_FIRST, RE_WEEKLY_RESET_FIRST],
|
|
31
|
-
monthly: [RE_MONTHLY_PCT_FIRST, RE_MONTHLY_RESET_FIRST],
|
|
32
|
-
};
|
|
33
|
-
// ---------------------------------------------------------------------------
|
|
34
|
-
// Public API
|
|
35
|
-
// ---------------------------------------------------------------------------
|
|
36
|
-
/**
|
|
37
|
-
* Parse all three usage windows (rolling, weekly, monthly) from dashboard HTML.
|
|
38
|
-
* Returns null for any window that couldn't be parsed.
|
|
39
|
-
*
|
|
40
|
-
* @param html — Raw HTML from the OpenCode-Go dashboard page.
|
|
41
|
-
* @returns An object with `rolling`, `weekly`, and `monthly` usage percentages,
|
|
42
|
-
* or null for windows that could not be parsed.
|
|
43
|
-
*/
|
|
44
|
-
export function parseAllUsage(html) {
|
|
45
|
-
return {
|
|
46
|
-
rolling: parseUsagePercent(html, 'rolling'),
|
|
47
|
-
weekly: parseUsagePercent(html, 'weekly'),
|
|
48
|
-
monthly: parseUsagePercent(html, 'monthly'),
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Parse a single usage window from dashboard HTML.
|
|
53
|
-
*
|
|
54
|
-
* Tries two regex patterns to handle field order variance
|
|
55
|
-
* (usagePercent before or after resetInSec).
|
|
56
|
-
*
|
|
57
|
-
* Returns null if:
|
|
58
|
-
* - The window data is not found in the HTML
|
|
59
|
-
* - The extracted value is not a finite number
|
|
60
|
-
* - The HTML is malformed or from a non-dashboard page
|
|
61
|
-
*
|
|
62
|
-
* @param html — Raw HTML from the OpenCode-Go dashboard page.
|
|
63
|
-
* @param window — The time window to parse: `'rolling'`, `'weekly'`, or `'monthly'`.
|
|
64
|
-
* @returns The usage percentage as a number (may be negative or exceed 100),
|
|
65
|
-
* or null if the value could not be extracted.
|
|
66
|
-
*/
|
|
67
|
-
export function parseUsagePercent(html, window) {
|
|
68
|
-
const patterns = PATTERNS[window];
|
|
69
|
-
if (!patterns)
|
|
70
|
-
return null;
|
|
71
|
-
const [rePctFirst, reResetFirst] = patterns;
|
|
72
|
-
// Try usagePercent-first pattern
|
|
73
|
-
const pctMatch = rePctFirst.exec(html);
|
|
74
|
-
if (pctMatch) {
|
|
75
|
-
// pct-first: usagePercent:$1,resetInSec:$2
|
|
76
|
-
const val = Number(pctMatch[1]);
|
|
77
|
-
return Number.isFinite(val) ? val : null;
|
|
78
|
-
}
|
|
79
|
-
// Try resetInSec-first pattern
|
|
80
|
-
const resetMatch = reResetFirst.exec(html);
|
|
81
|
-
if (resetMatch) {
|
|
82
|
-
// reset-first: resetInSec:$1,usagePercent:$2
|
|
83
|
-
const val = Number(resetMatch[2]);
|
|
84
|
-
return Number.isFinite(val) ? val : null;
|
|
85
|
-
}
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
//# sourceMappingURL=dashboard-parser.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dashboard-parser.js","sourceRoot":"","sources":["../src/dashboard-parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;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,iBAAiB,CAAC,IAAI,EAAE,QAAQ,CAAC;QACzC,OAAO,EAAE,iBAAiB,CAAC,IAAI,EAAE,SAAS,CAAC;KAC5C,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAY,EAAE,MAAwC;IACtF,MAAM,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;IAClC,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAC;IAE3B,MAAM,CAAC,UAAU,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAC;IAE5C,iCAAiC;IACjC,MAAM,QAAQ,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACvC,IAAI,QAAQ,EAAE,CAAC;QACb,2CAA2C;QAC3C,MAAM,GAAG,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;QAChC,OAAO,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;IAC3C,CAAC;IAED,+BAA+B;IAC/B,MAAM,UAAU,GAAG,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3C,IAAI,UAAU,EAAE,CAAC;QACf,6CAA6C;QAC7C,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;QAClC,OAAO,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;IAC3C,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* firefox-cookies.ts — Firefox cookie and history extraction.
|
|
3
|
-
*
|
|
4
|
-
* Reads cookies.sqlite and places.sqlite from the default Firefox profile.
|
|
5
|
-
* Uses Node.js built-in node:sqlite (requires Node >= 22).
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Find the default Firefox profile directory on this system.
|
|
9
|
-
*
|
|
10
|
-
* Scans the platform-specific Firefox profiles directory and prefers the
|
|
11
|
-
* `default-release` profile if it exists, otherwise returns the first
|
|
12
|
-
* profile directory found.
|
|
13
|
-
*
|
|
14
|
-
* @returns The path to the Firefox profile directory, or `null` if not found.
|
|
15
|
-
*/
|
|
16
|
-
export declare function findFirefoxProfileDir(): string | null;
|
|
17
|
-
/**
|
|
18
|
-
* Extract the `auth` cookie value for `opencode.ai` from Firefox's cookies.sqlite.
|
|
19
|
-
*
|
|
20
|
-
* Makes a temporary copy of the database (including WAL/SHM sidecars) to avoid
|
|
21
|
-
* locking conflicts with Firefox. The temp copy is cleaned up after extraction.
|
|
22
|
-
*
|
|
23
|
-
* @returns An object with `cookie` (the auth cookie value, or `null` if not found)
|
|
24
|
-
* and an optional `error` message describing what went wrong.
|
|
25
|
-
*/
|
|
26
|
-
export declare function extractFirefoxAuthCookie(): {
|
|
27
|
-
cookie: string | null;
|
|
28
|
-
error?: string;
|
|
29
|
-
};
|
|
30
|
-
/**
|
|
31
|
-
* Extract OpenCode workspace IDs from Firefox's places.sqlite (browser history).
|
|
32
|
-
*
|
|
33
|
-
* Searches `moz_places` for URLs containing `opencode.ai/workspace/` and
|
|
34
|
-
* returns unique workspace IDs (wrk_...) from the most recently visited pages.
|
|
35
|
-
*
|
|
36
|
-
* A temporary copy of the database (including WAL/SHM sidecars) is used to
|
|
37
|
-
* avoid locking conflicts with Firefox, then cleaned up after extraction.
|
|
38
|
-
*
|
|
39
|
-
* @returns An array of unique workspace ID strings (e.g. `["wrk_abc123"]`).
|
|
40
|
-
* Returns an empty array if none are found or if an error occurs.
|
|
41
|
-
*/
|
|
42
|
-
export declare function extractFirefoxWorkspaceIds(): string[];
|
package/dist/firefox-cookies.js
DELETED
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* firefox-cookies.ts — Firefox cookie and history extraction.
|
|
3
|
-
*
|
|
4
|
-
* Reads cookies.sqlite and places.sqlite from the default Firefox profile.
|
|
5
|
-
* Uses Node.js built-in node:sqlite (requires Node >= 22).
|
|
6
|
-
*/
|
|
7
|
-
import { existsSync, copyFileSync, mkdirSync, rmSync, readdirSync } from 'node:fs';
|
|
8
|
-
import { join } from 'node:path';
|
|
9
|
-
import { homedir, tmpdir } from 'node:os';
|
|
10
|
-
import { DatabaseSync } from 'node:sqlite';
|
|
11
|
-
import { logger } from './logger.js';
|
|
12
|
-
/**
|
|
13
|
-
* Find the default Firefox profile directory on this system.
|
|
14
|
-
*
|
|
15
|
-
* Scans the platform-specific Firefox profiles directory and prefers the
|
|
16
|
-
* `default-release` profile if it exists, otherwise returns the first
|
|
17
|
-
* profile directory found.
|
|
18
|
-
*
|
|
19
|
-
* @returns The path to the Firefox profile directory, or `null` if not found.
|
|
20
|
-
*/
|
|
21
|
-
export function findFirefoxProfileDir() {
|
|
22
|
-
const platform = process.platform;
|
|
23
|
-
let root;
|
|
24
|
-
if (platform === 'win32') {
|
|
25
|
-
const appData = process.env.APPDATA;
|
|
26
|
-
if (!appData)
|
|
27
|
-
return null;
|
|
28
|
-
root = join(appData, 'Mozilla', 'Firefox', 'Profiles');
|
|
29
|
-
}
|
|
30
|
-
else if (platform === 'darwin') {
|
|
31
|
-
root = join(homedir(), 'Library', 'Application Support', 'Firefox', 'Profiles');
|
|
32
|
-
}
|
|
33
|
-
else if (platform === 'linux') {
|
|
34
|
-
root = join(homedir(), '.mozilla', 'firefox');
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
if (!existsSync(root))
|
|
40
|
-
return null;
|
|
41
|
-
try {
|
|
42
|
-
const profiles = readdirSync(root, { withFileTypes: true })
|
|
43
|
-
.filter(e => e.isDirectory())
|
|
44
|
-
.map(e => e.name);
|
|
45
|
-
if (profiles.length === 0)
|
|
46
|
-
return null;
|
|
47
|
-
const preferred = profiles.find(p => p.includes('default-release')) ?? profiles[0];
|
|
48
|
-
return join(root, preferred);
|
|
49
|
-
}
|
|
50
|
-
catch {
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Extract the `auth` cookie value for `opencode.ai` from Firefox's cookies.sqlite.
|
|
56
|
-
*
|
|
57
|
-
* Makes a temporary copy of the database (including WAL/SHM sidecars) to avoid
|
|
58
|
-
* locking conflicts with Firefox. The temp copy is cleaned up after extraction.
|
|
59
|
-
*
|
|
60
|
-
* @returns An object with `cookie` (the auth cookie value, or `null` if not found)
|
|
61
|
-
* and an optional `error` message describing what went wrong.
|
|
62
|
-
*/
|
|
63
|
-
export function extractFirefoxAuthCookie() {
|
|
64
|
-
const profileDir = findFirefoxProfileDir();
|
|
65
|
-
if (!profileDir)
|
|
66
|
-
return { cookie: null, error: 'Firefox profile not found' };
|
|
67
|
-
const cookiesDb = join(profileDir, 'cookies.sqlite');
|
|
68
|
-
if (!existsSync(cookiesDb))
|
|
69
|
-
return { cookie: null, error: 'cookies.sqlite not found' };
|
|
70
|
-
const tempDir = mkdirSync(join(tmpdir(), 'proto-setup-' + Date.now()), { recursive: true });
|
|
71
|
-
const tempDb = join(tempDir, 'cookies.sqlite');
|
|
72
|
-
try {
|
|
73
|
-
copyFileSync(cookiesDb, tempDb);
|
|
74
|
-
for (const ext of ['-wal', '-shm']) {
|
|
75
|
-
const sidecar = cookiesDb + ext;
|
|
76
|
-
if (existsSync(sidecar)) {
|
|
77
|
-
copyFileSync(sidecar, tempDb + ext);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
const db = new DatabaseSync(tempDb, { readOnly: true });
|
|
81
|
-
try {
|
|
82
|
-
const stmt = db.prepare(`
|
|
83
|
-
SELECT name, value, host
|
|
84
|
-
FROM moz_cookies
|
|
85
|
-
WHERE (host = 'opencode.ai' OR host = '.opencode.ai')
|
|
86
|
-
AND name = 'auth'
|
|
87
|
-
ORDER BY expiry DESC
|
|
88
|
-
LIMIT 1
|
|
89
|
-
`);
|
|
90
|
-
const rows = stmt.all();
|
|
91
|
-
return rows.length > 0
|
|
92
|
-
? { cookie: rows[0].value }
|
|
93
|
-
: { cookie: null, error: 'No auth cookie found for opencode.ai' };
|
|
94
|
-
}
|
|
95
|
-
finally {
|
|
96
|
-
db.close();
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
catch (err) {
|
|
100
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
101
|
-
if (msg.includes('EBUSY') || msg.includes('EPERM') || msg.includes('locked')) {
|
|
102
|
-
return { cookie: null, error: 'Firefox has the database locked. Close Firefox and try again.' };
|
|
103
|
-
}
|
|
104
|
-
return { cookie: null, error: msg };
|
|
105
|
-
}
|
|
106
|
-
finally {
|
|
107
|
-
rmSync(tempDir, { recursive: true, force: true });
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Extract OpenCode workspace IDs from Firefox's places.sqlite (browser history).
|
|
112
|
-
*
|
|
113
|
-
* Searches `moz_places` for URLs containing `opencode.ai/workspace/` and
|
|
114
|
-
* returns unique workspace IDs (wrk_...) from the most recently visited pages.
|
|
115
|
-
*
|
|
116
|
-
* A temporary copy of the database (including WAL/SHM sidecars) is used to
|
|
117
|
-
* avoid locking conflicts with Firefox, then cleaned up after extraction.
|
|
118
|
-
*
|
|
119
|
-
* @returns An array of unique workspace ID strings (e.g. `["wrk_abc123"]`).
|
|
120
|
-
* Returns an empty array if none are found or if an error occurs.
|
|
121
|
-
*/
|
|
122
|
-
export function extractFirefoxWorkspaceIds() {
|
|
123
|
-
const profileDir = findFirefoxProfileDir();
|
|
124
|
-
if (!profileDir)
|
|
125
|
-
return [];
|
|
126
|
-
const placesDb = join(profileDir, 'places.sqlite');
|
|
127
|
-
if (!existsSync(placesDb))
|
|
128
|
-
return [];
|
|
129
|
-
const tempDir = mkdirSync(join(tmpdir(), 'proto-setup-history-' + Date.now()), { recursive: true });
|
|
130
|
-
const tempDb = join(tempDir, 'places.sqlite');
|
|
131
|
-
try {
|
|
132
|
-
copyFileSync(placesDb, tempDb);
|
|
133
|
-
for (const ext of ['-wal', '-shm']) {
|
|
134
|
-
const sidecar = placesDb + ext;
|
|
135
|
-
if (existsSync(sidecar)) {
|
|
136
|
-
copyFileSync(sidecar, tempDb + ext);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
const db = new DatabaseSync(tempDb, { readOnly: true });
|
|
140
|
-
try {
|
|
141
|
-
const stmt = db.prepare(`
|
|
142
|
-
SELECT url
|
|
143
|
-
FROM moz_places
|
|
144
|
-
WHERE url LIKE '%opencode.ai/workspace/%'
|
|
145
|
-
ORDER BY last_visit_date DESC
|
|
146
|
-
LIMIT 50
|
|
147
|
-
`);
|
|
148
|
-
const rows = stmt.all();
|
|
149
|
-
const workspaceIds = new Set();
|
|
150
|
-
for (const row of rows) {
|
|
151
|
-
const match = row.url.match(/\/workspace\/(wrk_[A-Za-z0-9]+)/);
|
|
152
|
-
if (match) {
|
|
153
|
-
workspaceIds.add(match[1]);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
return Array.from(workspaceIds);
|
|
157
|
-
}
|
|
158
|
-
finally {
|
|
159
|
-
db.close();
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
catch (err) {
|
|
163
|
-
logger.warn({ err }, 'Failed to extract Firefox workspace IDs');
|
|
164
|
-
return [];
|
|
165
|
-
}
|
|
166
|
-
finally {
|
|
167
|
-
rmSync(tempDir, { recursive: true, force: true });
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
//# sourceMappingURL=firefox-cookies.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"firefox-cookies.js","sourceRoot":"","sources":["../src/firefox-cookies.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,EAAE,WA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D,IAAI,KAAK,EAAE,CAAC;oBACV,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC7B,CAAC;YACH,CAAC;YAED,OAAO,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAClC,CAAC;gBAAS,CAAC;YACT,EAAE,CAAC,KAAK,EAAE,CAAC;QACb,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,EAAE,yCAAyC,CAAC,CAAC;QAChE,OAAO,EAAE,CAAC;IACZ,CAAC;YAAS,CAAC;QACT,MAAM,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACpD,CAAC;AACH,CAAC"}
|
package/dist/scraper.d.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* scraper.ts — Dashboard scraper; Saros uses this to predict account exhaustion.
|
|
3
|
-
*
|
|
4
|
-
* Provides both one-shot scraping (scrapeDashboard) and a background scraper
|
|
5
|
-
* that periodically fetches dashboard pages for all configured accounts.
|
|
6
|
-
* Uses recursive setTimeout (not setInterval) with AbortController to prevent
|
|
7
|
-
* overlapping cycles and to support clean shutdown.
|
|
8
|
-
*/
|
|
9
|
-
import { type UsageData } from './dashboard-parser.js';
|
|
10
|
-
import type { ScrapingAccount } from './config.js';
|
|
11
|
-
export interface ScrapeResult {
|
|
12
|
-
/** Whether the fetch and parse completed successfully. */
|
|
13
|
-
success: boolean;
|
|
14
|
-
/** Parsed usage data when successful. */
|
|
15
|
-
usage?: UsageData;
|
|
16
|
-
/** Human-readable error message on failure. */
|
|
17
|
-
error?: string;
|
|
18
|
-
/** HTTP status code returned by the upstream server, if reachable. */
|
|
19
|
-
httpStatus?: number;
|
|
20
|
-
/** Wall-clock duration of the entire fetch+parse operation in milliseconds. */
|
|
21
|
-
durationMs?: number;
|
|
22
|
-
}
|
|
23
|
-
interface AccountUsage {
|
|
24
|
-
usage: UsageData;
|
|
25
|
-
lastScrapedAt: Date;
|
|
26
|
-
lastError?: string;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Fetch the OpenCode-Go dashboard and parse usage percentages.
|
|
30
|
-
*
|
|
31
|
-
* Makes a single HTTP GET request to `https://opencode.ai/workspace/{workspaceId}/go`
|
|
32
|
-
* with the provided auth cookie. On a successful 2xx response the HTML is parsed
|
|
33
|
-
* with {@link parseAllUsage} and the resulting usage data is returned.
|
|
34
|
-
*
|
|
35
|
-
* @param workspaceId — The OpenCode workspace identifier.
|
|
36
|
-
* @param authCookie — The `auth` cookie value for authentication.
|
|
37
|
-
* @param options - Optional settings.
|
|
38
|
-
* @param options.timeoutMs - Request timeout in milliseconds (default: 15000).
|
|
39
|
-
* @returns A {@link ScrapeResult} with status, parsed data, and timing info.
|
|
40
|
-
*/
|
|
41
|
-
export declare function scrapeDashboard(workspaceId: string, authCookie: string, options?: {
|
|
42
|
-
timeoutMs?: number;
|
|
43
|
-
signal?: AbortSignal;
|
|
44
|
-
}): Promise<ScrapeResult>;
|
|
45
|
-
/**
|
|
46
|
-
* Get all usage data (for health endpoint).
|
|
47
|
-
*/
|
|
48
|
-
export declare function getAllUsage(): Map<string, AccountUsage>;
|
|
49
|
-
/**
|
|
50
|
-
* Clear the in-memory usage store (for testing).
|
|
51
|
-
* Production code should NOT call this unless resetting state is intentional.
|
|
52
|
-
*/
|
|
53
|
-
export declare function clearUsageStore(): void;
|
|
54
|
-
/**
|
|
55
|
-
* Start the background scraper.
|
|
56
|
-
* Scrapes all configured accounts every intervalMs using recursive setTimeout,
|
|
57
|
-
* preventing overlapping cycles. If already running, aborts the previous cycle
|
|
58
|
-
* and clears its timer first.
|
|
59
|
-
*/
|
|
60
|
-
export declare function startScraper(accounts: ScrapingAccount[], intervalMs: number): void;
|
|
61
|
-
/**
|
|
62
|
-
* Stop the background scraper.
|
|
63
|
-
* Aborts any in-flight scrape cycle and clears the scheduled timer.
|
|
64
|
-
*/
|
|
65
|
-
export declare function stopScraper(): void;
|
|
66
|
-
/**
|
|
67
|
-
* Check if the scraper is currently running (either a cycle in flight or a timer scheduled).
|
|
68
|
-
*/
|
|
69
|
-
export declare function isScraperRunning(): boolean;
|
|
70
|
-
export {};
|