@eduardo191labs/opencode-free-pi 0.7.33 → 0.7.35
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 +10 -9
- package/dist/api/quota.d.ts +1 -2
- package/dist/api/quota.js +10 -10
- package/dist/catalog/v2.js +4 -0
- package/dist/errors/handle.js +1 -3
- package/dist/errors/messages.js +3 -3
- package/dist/state.d.ts +1 -5
- package/dist/state.js +0 -1
- package/dist/types.d.ts +0 -1
- package/package.json +1 -1
- package/src/api/quota.ts +8 -15
- package/src/catalog/v2.ts +4 -0
- package/src/errors/handle.ts +1 -2
- package/src/errors/messages.ts +3 -3
- package/src/state.ts +0 -3
- package/src/types.ts +0 -2
package/README.md
CHANGED
|
@@ -222,12 +222,13 @@ Después de iniciar sesión, ejecuta `/reload` en OpenCode o reinícialo.
|
|
|
222
222
|
forma perezosa: si falta, el redimensionado de imágenes cae a la ruta sin WASM
|
|
223
223
|
en vez de romper el arranque.
|
|
224
224
|
- **Aislamiento por proveedor**: todo lo que añade el plugin —herramientas,
|
|
225
|
-
cabeceras, anuncios
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
225
|
+
cabeceras, anuncios y el `x-session-id` del proveedor— se aplica solo a
|
|
226
|
+
`free-pi` y `free-pi-defense`. Los reintentos, la compactación, el uso y los
|
|
227
|
+
topes son de OpenCode para todos los proveedores. Los demás proveedores no
|
|
228
|
+
reciben las herramientas en su lista (el plugin las quita de la petición), no
|
|
229
|
+
ven las cabeceras free-pi y conservan sus propias imágenes y su propio uso.
|
|
230
|
+
Si una sesión cambia de free-pi a otro modelo, pierde las herramientas en la
|
|
231
|
+
siguiente petición y las llamadas directas se rechazan.
|
|
231
232
|
- Compatible con rutas, credenciales y navegador de cada sistema operativo.
|
|
232
233
|
|
|
233
234
|
## Lectura de imágenes
|
|
@@ -500,15 +501,15 @@ src/
|
|
|
500
501
|
catalog/ catálogo en vivo, models.dev y límites medidos
|
|
501
502
|
errors/ parseo, mensajes y reescritura de límites
|
|
502
503
|
integration/ integración y métodos de inicio de sesión
|
|
503
|
-
session/ hooks, eventos, seguimiento y
|
|
504
|
+
session/ hooks, eventos, seguimiento y slots de proveedor
|
|
504
505
|
utils/ helpers pequeños (directorio de datos y URLs)
|
|
505
506
|
dist/ build ESM y tipos
|
|
506
507
|
scripts/postinstall.mjs registro en opencode.json
|
|
507
508
|
test/smoke.mjs prueba de humo del build
|
|
508
509
|
test/registry.mjs models.dev en vivo y tolerancia a fallos
|
|
509
510
|
test/models.mjs capacidades, variantes y límites
|
|
510
|
-
test/live.mjs
|
|
511
|
-
test/
|
|
511
|
+
test/live.mjs observaciones de tráfico real y ventana aprendida
|
|
512
|
+
test/legacy.mjs limpieza de agentes y skills de versiones anteriores
|
|
512
513
|
test/hooks.mjs hooks de sesión, anuncios, cuota y compactación
|
|
513
514
|
```
|
|
514
515
|
|
package/dist/api/quota.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/** Account quota fetching shared by error handling and usage tracking. */
|
|
2
2
|
import type { Deps } from "../deps.js";
|
|
3
|
-
import type { QuotaSnapshot
|
|
4
|
-
export declare function rememberTokenCheck(deps: Deps, token: string, state: TokenCheckState): void;
|
|
3
|
+
import type { QuotaSnapshot } from "../types.js";
|
|
5
4
|
export declare function fetchQuota(deps: Deps, opts?: {
|
|
6
5
|
force?: boolean;
|
|
7
6
|
stats?: boolean;
|
package/dist/api/quota.js
CHANGED
|
@@ -2,13 +2,8 @@
|
|
|
2
2
|
import { resolveToken } from "../auth/token.js";
|
|
3
3
|
import { QUOTA_HTTP_TIMEOUT_MS, QUOTA_TTL_MS } from "../constants.js";
|
|
4
4
|
import { logInvalidToken } from "../errors/invalid.js";
|
|
5
|
-
import { trimMap } from "../utils/async.js";
|
|
6
5
|
import { readJson } from "../utils/json.js";
|
|
7
6
|
import { resolveBaseUrl } from "../utils/urls.js";
|
|
8
|
-
export function rememberTokenCheck(deps, token, state) {
|
|
9
|
-
trimMap(deps.state.tokenChecks, 100);
|
|
10
|
-
deps.state.tokenChecks.set(token, { at: Date.now(), state });
|
|
11
|
-
}
|
|
12
7
|
export async function fetchQuota(deps, opts = {}) {
|
|
13
8
|
const current = deps.state.quotaCache;
|
|
14
9
|
if (!opts.force &&
|
|
@@ -17,8 +12,16 @@ export async function fetchQuota(deps, opts = {}) {
|
|
|
17
12
|
(!opts.stats || current.stats)) {
|
|
18
13
|
return current;
|
|
19
14
|
}
|
|
20
|
-
if (deps.state.quotaPromise)
|
|
21
|
-
|
|
15
|
+
if (deps.state.quotaPromise) {
|
|
16
|
+
const pending = deps.state.quotaPromise;
|
|
17
|
+
if (!opts.stats)
|
|
18
|
+
return pending;
|
|
19
|
+
// A stats request cannot reuse an in-flight `/me`-only refresh: it would
|
|
20
|
+
// resolve without the very numbers the usage tool asked for.
|
|
21
|
+
const settled = await pending;
|
|
22
|
+
if (settled.stats)
|
|
23
|
+
return settled;
|
|
24
|
+
}
|
|
22
25
|
const pending = (async () => {
|
|
23
26
|
const token = await resolveToken(deps);
|
|
24
27
|
if (!token) {
|
|
@@ -46,7 +49,6 @@ export async function fetchQuota(deps, opts = {}) {
|
|
|
46
49
|
statsRequest,
|
|
47
50
|
]);
|
|
48
51
|
if (meResponse?.status === 401 || statsResponse?.status === 401) {
|
|
49
|
-
rememberTokenCheck(deps, token, "invalid");
|
|
50
52
|
await logInvalidToken(deps, token);
|
|
51
53
|
const invalid = {
|
|
52
54
|
fetchedAt: Date.now(),
|
|
@@ -63,8 +65,6 @@ export async function fetchQuota(deps, opts = {}) {
|
|
|
63
65
|
const stats = statsResponse?.ok
|
|
64
66
|
? (await readJson(statsResponse))
|
|
65
67
|
: undefined;
|
|
66
|
-
if (meResponse?.ok || statsResponse?.ok)
|
|
67
|
-
rememberTokenCheck(deps, token, "ok");
|
|
68
68
|
if (typeof me?.notice === "string" &&
|
|
69
69
|
me.notice &&
|
|
70
70
|
me.notice !== deps.state.lastQuotaNotice) {
|
package/dist/catalog/v2.js
CHANGED
|
@@ -87,6 +87,10 @@ export function applyProvider(editor, providerID, name, models, token) {
|
|
|
87
87
|
settings: {
|
|
88
88
|
...base.settings,
|
|
89
89
|
...(existing.provider?.settings ?? {}),
|
|
90
|
+
// The key belongs to the active sign-in, not to the stored provider
|
|
91
|
+
// record. Keeping the previous one here left the provider using the token
|
|
92
|
+
// from the first transform after the user signed in again.
|
|
93
|
+
apiKey: base.settings.apiKey,
|
|
90
94
|
},
|
|
91
95
|
};
|
|
92
96
|
const merged = new Map();
|
package/dist/errors/handle.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Central handling for free-pi failures reported by the provider or session. */
|
|
2
|
-
import { fetchQuota
|
|
2
|
+
import { fetchQuota } from "../api/quota.js";
|
|
3
3
|
import { resetFreePiSessions } from "../api/session.js";
|
|
4
4
|
import { logInvalidToken } from "./invalid.js";
|
|
5
5
|
import { freePiErrorSeverity, freePiErrorTitle, friendlyFreePiError, } from "./messages.js";
|
|
@@ -12,8 +12,6 @@ export async function handleFreePiError(deps, error, opts = {}) {
|
|
|
12
12
|
parsed.code === "unauthorized" ||
|
|
13
13
|
parsed.code === "expired_token") {
|
|
14
14
|
const token = deps.state.quotaCache?.token;
|
|
15
|
-
if (token)
|
|
16
|
-
rememberTokenCheck(deps, token, "invalid");
|
|
17
15
|
await logInvalidToken(deps, token);
|
|
18
16
|
void fetchQuota(deps, { force: true }).catch(() => undefined);
|
|
19
17
|
return;
|
package/dist/errors/messages.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** Human-readable copy for free-pi error codes. */
|
|
2
2
|
import { formatRefillTime, formatWait } from "../utils/numbers.js";
|
|
3
3
|
const FREE_PI_ERROR_TEXT = {
|
|
4
|
-
daily_cap: "Out of free credits today; they refill at
|
|
4
|
+
daily_cap: "Out of free credits today; they refill at the next reset, or add credits to keep going now.",
|
|
5
5
|
queue_wait: "free-pi is near its daily budget; wait and retry.",
|
|
6
6
|
rolling_cap: "Over the rolling spend cap on the free tier; wait for the retry window or add credits.",
|
|
7
7
|
concurrent: "Only one request at a time on the free tier; wait for the current one to finish.",
|
|
@@ -11,7 +11,7 @@ const FREE_PI_ERROR_TEXT = {
|
|
|
11
11
|
global_cap: "free-pi is over its shared daily budget; back tomorrow.",
|
|
12
12
|
consent_required: "Consent required. Run `opencode auth login -p free-pi` to review the terms.",
|
|
13
13
|
upgrade_required: "The free-pi client is out of date; update the plugin or free-pi-cli.",
|
|
14
|
-
hourly_ceiling: "Daily allowance still applies; it refills at
|
|
14
|
+
hourly_ceiling: "Daily allowance still applies; it refills at the next reset.",
|
|
15
15
|
account_review: "This account is under review; contact support.",
|
|
16
16
|
ads_required: "Ads are not displaying for this account, so free completions are paused. Run `npx free-pi-cli@latest` so ads can show, then retry.",
|
|
17
17
|
guest_allowance: "Guest trial used up; sign in with GitHub for a larger allowance.",
|
|
@@ -104,7 +104,7 @@ export function friendlyFreePiError(error) {
|
|
|
104
104
|
return `This account hit its hourly limit; ${reset ? `it resets ${reset}` : "wait for it to reset"}. Switch models or retry later.`;
|
|
105
105
|
}
|
|
106
106
|
if (error.code === "daily_cap") {
|
|
107
|
-
return `Out of free credits today; ${reset ? `it resets ${reset}` : "it refills at
|
|
107
|
+
return `Out of free credits today; ${reset ? `it resets ${reset}` : "it refills at the next reset"}.`;
|
|
108
108
|
}
|
|
109
109
|
if (error.code === "rolling_cap") {
|
|
110
110
|
return `Over the rolling spend cap; ${reset ? `retry ${reset}` : "wait for the retry window"}.`;
|
package/dist/state.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Per-plugin-instance mutable state. */
|
|
2
|
-
import type { AdTurn, Catalog, ModelRegistry, QuotaSnapshot, SessionResetOutcome,
|
|
2
|
+
import type { AdTurn, Catalog, ModelRegistry, QuotaSnapshot, SessionResetOutcome, ToolStats, TrackedModel } from "./types.js";
|
|
3
3
|
export type RuntimeState = {
|
|
4
4
|
latestClientVersion: string;
|
|
5
5
|
providerToken?: string;
|
|
@@ -19,10 +19,6 @@ export type RuntimeState = {
|
|
|
19
19
|
lastErrorLogKey?: string;
|
|
20
20
|
lastErrorLogAt: number;
|
|
21
21
|
lastInvalidToken?: string;
|
|
22
|
-
tokenChecks: Map<string, {
|
|
23
|
-
at: number;
|
|
24
|
-
state: TokenCheckState;
|
|
25
|
-
}>;
|
|
26
22
|
lastExpiredToken?: string;
|
|
27
23
|
sessionClosePromises: Map<string, Promise<void>>;
|
|
28
24
|
sessionResetPromise?: Promise<SessionResetOutcome>;
|
package/dist/state.js
CHANGED
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
package/src/api/quota.ts
CHANGED
|
@@ -8,21 +8,10 @@ import type {
|
|
|
8
8
|
MeResponse,
|
|
9
9
|
MeStatsResponse,
|
|
10
10
|
QuotaSnapshot,
|
|
11
|
-
TokenCheckState,
|
|
12
11
|
} from "../types.js";
|
|
13
|
-
import { trimMap } from "../utils/async.js";
|
|
14
12
|
import { readJson } from "../utils/json.js";
|
|
15
13
|
import { resolveBaseUrl } from "../utils/urls.js";
|
|
16
14
|
|
|
17
|
-
export function rememberTokenCheck(
|
|
18
|
-
deps: Deps,
|
|
19
|
-
token: string,
|
|
20
|
-
state: TokenCheckState,
|
|
21
|
-
): void {
|
|
22
|
-
trimMap(deps.state.tokenChecks, 100);
|
|
23
|
-
deps.state.tokenChecks.set(token, { at: Date.now(), state });
|
|
24
|
-
}
|
|
25
|
-
|
|
26
15
|
export async function fetchQuota(
|
|
27
16
|
deps: Deps,
|
|
28
17
|
opts: { force?: boolean; stats?: boolean } = {},
|
|
@@ -36,7 +25,14 @@ export async function fetchQuota(
|
|
|
36
25
|
) {
|
|
37
26
|
return current;
|
|
38
27
|
}
|
|
39
|
-
if (deps.state.quotaPromise)
|
|
28
|
+
if (deps.state.quotaPromise) {
|
|
29
|
+
const pending = deps.state.quotaPromise;
|
|
30
|
+
if (!opts.stats) return pending;
|
|
31
|
+
// A stats request cannot reuse an in-flight `/me`-only refresh: it would
|
|
32
|
+
// resolve without the very numbers the usage tool asked for.
|
|
33
|
+
const settled = await pending;
|
|
34
|
+
if (settled.stats) return settled;
|
|
35
|
+
}
|
|
40
36
|
|
|
41
37
|
const pending = (async () => {
|
|
42
38
|
const token = await resolveToken(deps);
|
|
@@ -66,7 +62,6 @@ export async function fetchQuota(
|
|
|
66
62
|
statsRequest,
|
|
67
63
|
]);
|
|
68
64
|
if (meResponse?.status === 401 || statsResponse?.status === 401) {
|
|
69
|
-
rememberTokenCheck(deps, token, "invalid");
|
|
70
65
|
await logInvalidToken(deps, token);
|
|
71
66
|
const invalid: QuotaSnapshot = {
|
|
72
67
|
fetchedAt: Date.now(),
|
|
@@ -84,8 +79,6 @@ export async function fetchQuota(
|
|
|
84
79
|
const stats = statsResponse?.ok
|
|
85
80
|
? ((await readJson(statsResponse)) as MeStatsResponse | undefined)
|
|
86
81
|
: undefined;
|
|
87
|
-
if (meResponse?.ok || statsResponse?.ok)
|
|
88
|
-
rememberTokenCheck(deps, token, "ok");
|
|
89
82
|
if (
|
|
90
83
|
typeof me?.notice === "string" &&
|
|
91
84
|
me.notice &&
|
package/src/catalog/v2.ts
CHANGED
|
@@ -119,6 +119,10 @@ export function applyProvider(
|
|
|
119
119
|
settings: {
|
|
120
120
|
...base.settings,
|
|
121
121
|
...(existing.provider?.settings ?? {}),
|
|
122
|
+
// The key belongs to the active sign-in, not to the stored provider
|
|
123
|
+
// record. Keeping the previous one here left the provider using the token
|
|
124
|
+
// from the first transform after the user signed in again.
|
|
125
|
+
apiKey: base.settings.apiKey,
|
|
122
126
|
},
|
|
123
127
|
};
|
|
124
128
|
|
package/src/errors/handle.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** Central handling for free-pi failures reported by the provider or session. */
|
|
2
2
|
|
|
3
|
-
import { fetchQuota
|
|
3
|
+
import { fetchQuota } from "../api/quota.js";
|
|
4
4
|
import { resetFreePiSessions } from "../api/session.js";
|
|
5
5
|
import type { Deps } from "../deps.js";
|
|
6
6
|
import type { SessionResetOutcome } from "../types.js";
|
|
@@ -26,7 +26,6 @@ export async function handleFreePiError(
|
|
|
26
26
|
parsed.code === "expired_token"
|
|
27
27
|
) {
|
|
28
28
|
const token = deps.state.quotaCache?.token;
|
|
29
|
-
if (token) rememberTokenCheck(deps, token, "invalid");
|
|
30
29
|
await logInvalidToken(deps, token);
|
|
31
30
|
void fetchQuota(deps, { force: true }).catch(() => undefined);
|
|
32
31
|
return;
|
package/src/errors/messages.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { formatRefillTime, formatWait } from "../utils/numbers.js";
|
|
|
5
5
|
|
|
6
6
|
const FREE_PI_ERROR_TEXT: Record<string, string> = {
|
|
7
7
|
daily_cap:
|
|
8
|
-
"Out of free credits today; they refill at
|
|
8
|
+
"Out of free credits today; they refill at the next reset, or add credits to keep going now.",
|
|
9
9
|
queue_wait: "free-pi is near its daily budget; wait and retry.",
|
|
10
10
|
rolling_cap:
|
|
11
11
|
"Over the rolling spend cap on the free tier; wait for the retry window or add credits.",
|
|
@@ -21,7 +21,7 @@ const FREE_PI_ERROR_TEXT: Record<string, string> = {
|
|
|
21
21
|
"Consent required. Run `opencode auth login -p free-pi` to review the terms.",
|
|
22
22
|
upgrade_required:
|
|
23
23
|
"The free-pi client is out of date; update the plugin or free-pi-cli.",
|
|
24
|
-
hourly_ceiling: "Daily allowance still applies; it refills at
|
|
24
|
+
hourly_ceiling: "Daily allowance still applies; it refills at the next reset.",
|
|
25
25
|
account_review: "This account is under review; contact support.",
|
|
26
26
|
ads_required:
|
|
27
27
|
"Ads are not displaying for this account, so free completions are paused. Run `npx free-pi-cli@latest` so ads can show, then retry.",
|
|
@@ -135,7 +135,7 @@ export function friendlyFreePiError(error: FreePiError): string {
|
|
|
135
135
|
}
|
|
136
136
|
if (error.code === "daily_cap") {
|
|
137
137
|
return `Out of free credits today; ${
|
|
138
|
-
reset ? `it resets ${reset}` : "it refills at
|
|
138
|
+
reset ? `it resets ${reset}` : "it refills at the next reset"
|
|
139
139
|
}.`;
|
|
140
140
|
}
|
|
141
141
|
if (error.code === "rolling_cap") {
|
package/src/state.ts
CHANGED
|
@@ -7,7 +7,6 @@ import type {
|
|
|
7
7
|
ModelRegistry,
|
|
8
8
|
QuotaSnapshot,
|
|
9
9
|
SessionResetOutcome,
|
|
10
|
-
TokenCheckState,
|
|
11
10
|
ToolStats,
|
|
12
11
|
TrackedModel,
|
|
13
12
|
} from "./types.js";
|
|
@@ -34,7 +33,6 @@ export type RuntimeState = {
|
|
|
34
33
|
lastErrorLogKey?: string;
|
|
35
34
|
lastErrorLogAt: number;
|
|
36
35
|
lastInvalidToken?: string;
|
|
37
|
-
tokenChecks: Map<string, { at: number; state: TokenCheckState }>;
|
|
38
36
|
lastExpiredToken?: string;
|
|
39
37
|
|
|
40
38
|
sessionClosePromises: Map<string, Promise<void>>;
|
|
@@ -72,7 +70,6 @@ export function createRuntimeState(): RuntimeState {
|
|
|
72
70
|
registryAttemptAt: 0,
|
|
73
71
|
imageModels: new Set(),
|
|
74
72
|
lastErrorLogAt: 0,
|
|
75
|
-
tokenChecks: new Map(),
|
|
76
73
|
sessionClosePromises: new Map(),
|
|
77
74
|
lastSessionResetAt: 0,
|
|
78
75
|
freePiSessions: new Set(),
|