@eduardo191labs/opencode-free-pi 0.6.6 → 0.6.8
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 +28 -1
- package/dist/agents/definitions.d.ts +2 -2
- package/dist/agents/definitions.js +7 -1
- package/dist/catalog/catalog.js +42 -26
- package/dist/constants.d.ts +19 -1
- package/dist/constants.js +21 -1
- package/dist/deps.d.ts +4 -1
- package/dist/plugin.js +130 -34
- package/dist/session/hooks.js +36 -1
- package/dist/session/tools.d.ts +1 -1
- package/dist/session/tools.js +1 -0
- package/dist/tools/subagent.d.ts +29 -0
- package/dist/tools/subagent.js +197 -0
- package/dist/types.d.ts +11 -0
- package/package.json +2 -2
- package/src/agents/definitions.ts +7 -1
- package/src/catalog/catalog.ts +43 -25
- package/src/constants.ts +22 -1
- package/src/deps.ts +8 -1
- package/src/plugin.ts +133 -33
- package/src/session/hooks.ts +43 -0
- package/src/session/tools.ts +1 -0
- package/src/tools/subagent.ts +271 -0
- package/src/types.ts +18 -0
package/README.md
CHANGED
|
@@ -185,6 +185,13 @@ Después de iniciar sesión, ejecuta `/reload` en OpenCode o reinícialo.
|
|
|
185
185
|
ya esté en memoria en vez de inventar límites. Los avisos que el servidor
|
|
186
186
|
manda en el catálogo y en `/me` (`notice`) se registran una vez en el log del
|
|
187
187
|
plugin.
|
|
188
|
+
- **Catálogo que se recupera solo**: si `/client-version` no responde, el
|
|
189
|
+
proveedor quedaría registrado sin modelos y el selector de esa ubicación
|
|
190
|
+
mostraría «Model unavailable» para todos los modelos free-pi. Por eso la
|
|
191
|
+
petición se reintenta una vez de inmediato y, si aun así falla, el plugin
|
|
192
|
+
vuelve a pedir el catálogo en segundo plano (2 s, 5 s, 10 s, 20 s, 30 s y 60 s)
|
|
193
|
+
y, en cuanto lo obtiene, registra los modelos y recarga proveedor y modelo en
|
|
194
|
+
caliente. No hace falta reiniciar OpenCode ni elegir otra carpeta.
|
|
188
195
|
- **Aislamiento por proveedor**: todo lo que añade el plugin —herramientas,
|
|
189
196
|
cabeceras, anuncios, reglas de prompt, compactación, reintentos, topes de
|
|
190
197
|
tokens y ajustes— se aplica solo a `free-pi` y `free-pi-defense`. Los demás
|
|
@@ -238,6 +245,7 @@ demás modelos no las ven ni pueden ejecutarlas.
|
|
|
238
245
|
| `web_search` | Busca en la web y devuelve título, URL, fecha y texto de cada resultado. |
|
|
239
246
|
| `docs_lookup` | Consulta documentación actual de una librería o framework. |
|
|
240
247
|
| `free_pi_usage` | Muestra cuota restante, créditos, tokens y tier de la cuenta. |
|
|
248
|
+
| `free_pi_subagent_read` | Lee la transcripción de una sesión hija: prompts, herramientas y respuesta. |
|
|
241
249
|
|
|
242
250
|
`generate_image` acepta `prompt`, `aspect_ratio` (`1:1`, `16:9`, `9:16`, `4:3`,
|
|
243
251
|
`3:2`) y un `name` opcional para el archivo. Rechaza tipos que no sean PNG,
|
|
@@ -257,6 +265,15 @@ con su hora de recarga en ET, los créditos premium o de referidos y los tokens
|
|
|
257
265
|
de hoy y de por vida. Si el servidor asigna el carril lento, incluye el aviso
|
|
258
266
|
del CLI.
|
|
259
267
|
|
|
268
|
+
`free_pi_subagent_read` recibe el `sessionID` que devuelve la herramienta
|
|
269
|
+
`subagent` y devuelve la conversación de esa sesión hija: el prompt recibido,
|
|
270
|
+
cada llamada a herramienta con su entrada y su resultado, y el texto final del
|
|
271
|
+
subagente. Antes de leer comprueba con `session.get` que `parentID` sea la sesión
|
|
272
|
+
que llama, así que no puede abrir sesiones ajenas. Sin `sessionID` lista las
|
|
273
|
+
sesiones hijas de la sesión actual con su agente y su resultado. El transcript se
|
|
274
|
+
mantiene dentro de un presupuesto de caracteres (`maxChars`, 60k por defecto) y,
|
|
275
|
+
si no cabe, conserva los turnos más recientes y lo indica.
|
|
276
|
+
|
|
260
277
|
La compra de créditos y la guía de free-pi ya no se exponen como herramientas:
|
|
261
278
|
se resuelven en el dashboard y la documentación de free-pi, sin gastar cuota ni
|
|
262
279
|
añadir ruido al contexto.
|
|
@@ -292,7 +309,10 @@ La herramienta `subagent` es la de OpenCode y está disponible para **cualquier
|
|
|
292
309
|
modelo**, no solo para los agentes `free-pi/*`: también puede lanzarlos un
|
|
293
310
|
modelo de otro proveedor configurado en OpenCode. El plugin garantiza además que
|
|
294
311
|
todos los modelos gratuitos anuncien soporte de tools, de modo que el runner
|
|
295
|
-
nunca oculte `subagent` por una capacidad incorrecta de models.dev.
|
|
312
|
+
nunca oculte `subagent` por una capacidad incorrecta de models.dev. Cuando el
|
|
313
|
+
hijo termina, OpenCode inyecta su informe en la sesión padre; para ver lo que
|
|
314
|
+
realmente ejecutó, el padre llama a `free_pi_subagent_read` con el `sessionID`
|
|
315
|
+
del hijo.
|
|
296
316
|
|
|
297
317
|
El plugin solo reescribe estos archivos si conservan su marca de gestión; si el
|
|
298
318
|
usuario edita o reemplaza uno, se respeta tal cual.
|
|
@@ -388,6 +408,13 @@ turno que se aborta o falla a mitad de stream marca su `x-session-id` como sucio
|
|
|
388
408
|
la siguiente petición arranca directamente con un id nuevo y libera el anterior,
|
|
389
409
|
de modo que la sesión continúa sin interrupciones y sin pasar por un reintento.
|
|
390
410
|
|
|
411
|
+
Los fallos de transporte (`ECONNREFUSED`, `ECONNRESET`, `ETIMEDOUT`, DNS
|
|
412
|
+
temporal, `socket hang up`) no son límites de cuenta: el plugin los reintenta con
|
|
413
|
+
espera exponencial hasta cinco veces más (2 s, 4 s, 8 s, 16 s y 30 s) y marca el
|
|
414
|
+
`x-session-id` como sucio para que el siguiente intento use una conexión y un
|
|
415
|
+
slot nuevos. Así un corte breve de red, del router o del servicio local de
|
|
416
|
+
OpenCode no termina el turno en el segundo intento.
|
|
417
|
+
|
|
391
418
|
## Rutas por plataforma
|
|
392
419
|
|
|
393
420
|
| Elemento | Windows | Linux / macOS / Termux |
|
|
@@ -21,13 +21,13 @@ export type FreePiAgentID = (typeof FREE_PI_AGENT_IDS)[number];
|
|
|
21
21
|
export declare const FREE_PI_SKILL_ID = "free-pi";
|
|
22
22
|
export declare const FREE_PI_SKILL_NAME = "free-pi";
|
|
23
23
|
export declare const FREE_PI_SKILL_DESCRIPTION = "How free-pi works in OpenCode: its tools, the installed native subagents, allowance and limits, and where sessions and memory live.";
|
|
24
|
-
export declare const FREE_PI_SKILL = "# free-pi in OpenCode\n\nfree-pi is a free, ad-supported provider for OpenCode. You sign in with GitHub\nand ads in the session pay for the inference; there is no model API key. The\nfree daily allowance is shared by every free-pi model and every tool that spends\nit.\n\n## Tools\n- `free_pi_usage` shows today's remaining allowance, credits, token counts and\n the account tier. Read-only.\n- `look_at_image` asks a vision model about a PNG, JPEG or WebP inside the\n project. Use it when the current model takes text only, or when the image is a\n file on disk and you want a targeted answer instead of attaching it.\n- `generate_image` draws one image from a prompt and saves it under `images/`.\n- `web_search` searches the web for current information.\n- `docs_lookup` looks up current library and framework documentation.\n\nEvery tool except `free_pi_usage` spends allowance. Usage limits\n(`daily_cap`, `rolling_cap`, concurrency) are terminal: stop and continue\nwithout the tool instead of retrying.\n\n## Subagents\n\nUse OpenCode's native subagent tool with the agents this plugin installs:\n\n| Agent | Use it for |\n| --- | --- |\n| `free-pi/scout` | Read-only recon: locate code and return structured findings. |\n| `free-pi/planner` | Read-only plan for a change, ready for a worker. |\n| `free-pi/worker` | Carry out one full task in its own context window. |\n| `free-pi/reviewer` | Read-only review with file and line references. |\n\nSubagents inherit the free-pi model, share the same daily allowance, and run as\nchild sessions in the background. Keep large exploration in a subagent so it\ndoes not fill your own context. Use OpenCode's agent picker or the `subagent`\ntool; do not try to launch them through shell commands.\n\n## Memory and sessions\n\nOpenCode owns memory and context: `AGENTS.md` and configured instruction files\nare loaded natively, sessions persist and resume, and compaction folds long\nconversations into a summary. Put durable project facts in `AGENTS.md` (or a\nfile listed under `instructions`) instead of repeating them in every prompt.\n\n## Native integrations\n\nMCP servers, skills, commands, references and permissions are configured in\nOpenCode as usual; free-pi does not replace them. Prefer those native features\nover running an external CLI.\n";
|
|
24
|
+
export declare const FREE_PI_SKILL = "# free-pi in OpenCode\n\nfree-pi is a free, ad-supported provider for OpenCode. You sign in with GitHub\nand ads in the session pay for the inference; there is no model API key. The\nfree daily allowance is shared by every free-pi model and every tool that spends\nit.\n\n## Tools\n- `free_pi_usage` shows today's remaining allowance, credits, token counts and\n the account tier. Read-only.\n- `free_pi_subagent_read` reads the transcript of a child session started with\n the `subagent` tool: its prompts, every tool call with input and result, and\n its final answer. Read-only; omit `sessionID` to list this session's children.\n- `look_at_image` asks a vision model about a PNG, JPEG or WebP inside the\n project. Use it when the current model takes text only, or when the image is a\n file on disk and you want a targeted answer instead of attaching it.\n- `generate_image` draws one image from a prompt and saves it under `images/`.\n- `web_search` searches the web for current information.\n- `docs_lookup` looks up current library and framework documentation.\n\nEvery tool except `free_pi_usage` spends allowance. Usage limits\n(`daily_cap`, `rolling_cap`, concurrency) are terminal: stop and continue\nwithout the tool instead of retrying.\n\n## Subagents\n\nUse OpenCode's native subagent tool with the agents this plugin installs:\n\n| Agent | Use it for |\n| --- | --- |\n| `free-pi/scout` | Read-only recon: locate code and return structured findings. |\n| `free-pi/planner` | Read-only plan for a change, ready for a worker. |\n| `free-pi/worker` | Carry out one full task in its own context window. |\n| `free-pi/reviewer` | Read-only review with file and line references. |\n\nSubagents inherit the free-pi model, share the same daily allowance, and run as\nchild sessions in the background. Keep large exploration in a subagent so it\ndoes not fill your own context. Use OpenCode's agent picker or the `subagent`\ntool; do not try to launch them through shell commands. The `subagent` tool\nreturns the child `sessionID` and OpenCode injects the child's report when it\ngoes idle; call `free_pi_subagent_read` with that id to see what the child ran\nand why its answer says what it says.\n\n## Memory and sessions\n\nOpenCode owns memory and context: `AGENTS.md` and configured instruction files\nare loaded natively, sessions persist and resume, and compaction folds long\nconversations into a summary. Put durable project facts in `AGENTS.md` (or a\nfile listed under `instructions`) instead of repeating them in every prompt.\n\n## Native integrations\n\nMCP servers, skills, commands, references and permissions are configured in\nOpenCode as usual; free-pi does not replace them. Prefer those native features\nover running an external CLI.\n";
|
|
25
25
|
/**
|
|
26
26
|
* The same skill as a native `SKILL.md`. OpenCode discovers it from the global
|
|
27
27
|
* skills directory, so the file, its ID, its permissions and the `skill` tool
|
|
28
28
|
* all belong to OpenCode instead of a runtime registration.
|
|
29
29
|
*/
|
|
30
|
-
export declare const FREE_PI_SKILL_FILE = "---\nname: free-pi\ndescription: How free-pi works in OpenCode: its tools, the installed native subagents, allowance and limits, and where sessions and memory live.\n---\n\n<!-- managed by @eduardo191labs/opencode-free-pi; delete this line to keep your own copy -->\n\n# free-pi in OpenCode\n\nfree-pi is a free, ad-supported provider for OpenCode. You sign in with GitHub\nand ads in the session pay for the inference; there is no model API key. The\nfree daily allowance is shared by every free-pi model and every tool that spends\nit.\n\n## Tools\n- `free_pi_usage` shows today's remaining allowance, credits, token counts and\n the account tier. Read-only.\n- `look_at_image` asks a vision model about a PNG, JPEG or WebP inside the\n project. Use it when the current model takes text only, or when the image is a\n file on disk and you want a targeted answer instead of attaching it.\n- `generate_image` draws one image from a prompt and saves it under `images/`.\n- `web_search` searches the web for current information.\n- `docs_lookup` looks up current library and framework documentation.\n\nEvery tool except `free_pi_usage` spends allowance. Usage limits\n(`daily_cap`, `rolling_cap`, concurrency) are terminal: stop and continue\nwithout the tool instead of retrying.\n\n## Subagents\n\nUse OpenCode's native subagent tool with the agents this plugin installs:\n\n| Agent | Use it for |\n| --- | --- |\n| `free-pi/scout` | Read-only recon: locate code and return structured findings. |\n| `free-pi/planner` | Read-only plan for a change, ready for a worker. |\n| `free-pi/worker` | Carry out one full task in its own context window. |\n| `free-pi/reviewer` | Read-only review with file and line references. |\n\nSubagents inherit the free-pi model, share the same daily allowance, and run as\nchild sessions in the background. Keep large exploration in a subagent so it\ndoes not fill your own context. Use OpenCode's agent picker or the `subagent`\ntool; do not try to launch them through shell commands.\n\n## Memory and sessions\n\nOpenCode owns memory and context: `AGENTS.md` and configured instruction files\nare loaded natively, sessions persist and resume, and compaction folds long\nconversations into a summary. Put durable project facts in `AGENTS.md` (or a\nfile listed under `instructions`) instead of repeating them in every prompt.\n\n## Native integrations\n\nMCP servers, skills, commands, references and permissions are configured in\nOpenCode as usual; free-pi does not replace them. Prefer those native features\nover running an external CLI.\n";
|
|
30
|
+
export declare const FREE_PI_SKILL_FILE = "---\nname: free-pi\ndescription: How free-pi works in OpenCode: its tools, the installed native subagents, allowance and limits, and where sessions and memory live.\n---\n\n<!-- managed by @eduardo191labs/opencode-free-pi; delete this line to keep your own copy -->\n\n# free-pi in OpenCode\n\nfree-pi is a free, ad-supported provider for OpenCode. You sign in with GitHub\nand ads in the session pay for the inference; there is no model API key. The\nfree daily allowance is shared by every free-pi model and every tool that spends\nit.\n\n## Tools\n- `free_pi_usage` shows today's remaining allowance, credits, token counts and\n the account tier. Read-only.\n- `free_pi_subagent_read` reads the transcript of a child session started with\n the `subagent` tool: its prompts, every tool call with input and result, and\n its final answer. Read-only; omit `sessionID` to list this session's children.\n- `look_at_image` asks a vision model about a PNG, JPEG or WebP inside the\n project. Use it when the current model takes text only, or when the image is a\n file on disk and you want a targeted answer instead of attaching it.\n- `generate_image` draws one image from a prompt and saves it under `images/`.\n- `web_search` searches the web for current information.\n- `docs_lookup` looks up current library and framework documentation.\n\nEvery tool except `free_pi_usage` spends allowance. Usage limits\n(`daily_cap`, `rolling_cap`, concurrency) are terminal: stop and continue\nwithout the tool instead of retrying.\n\n## Subagents\n\nUse OpenCode's native subagent tool with the agents this plugin installs:\n\n| Agent | Use it for |\n| --- | --- |\n| `free-pi/scout` | Read-only recon: locate code and return structured findings. |\n| `free-pi/planner` | Read-only plan for a change, ready for a worker. |\n| `free-pi/worker` | Carry out one full task in its own context window. |\n| `free-pi/reviewer` | Read-only review with file and line references. |\n\nSubagents inherit the free-pi model, share the same daily allowance, and run as\nchild sessions in the background. Keep large exploration in a subagent so it\ndoes not fill your own context. Use OpenCode's agent picker or the `subagent`\ntool; do not try to launch them through shell commands. The `subagent` tool\nreturns the child `sessionID` and OpenCode injects the child's report when it\ngoes idle; call `free_pi_subagent_read` with that id to see what the child ran\nand why its answer says what it says.\n\n## Memory and sessions\n\nOpenCode owns memory and context: `AGENTS.md` and configured instruction files\nare loaded natively, sessions persist and resume, and compaction folds long\nconversations into a summary. Put durable project facts in `AGENTS.md` (or a\nfile listed under `instructions`) instead of repeating them in every prompt.\n\n## Native integrations\n\nMCP servers, skills, commands, references and permissions are configured in\nOpenCode as usual; free-pi does not replace them. Prefer those native features\nover running an external CLI.\n";
|
|
31
31
|
/** OpenCode's user-wide config directory, where it loads custom agents. */
|
|
32
32
|
export declare function openCodeConfigDir(): string;
|
|
33
33
|
export declare function freePiAgentPath(configDir: string, id: FreePiAgentID): string;
|
|
@@ -39,6 +39,9 @@ it.
|
|
|
39
39
|
## Tools
|
|
40
40
|
- \`free_pi_usage\` shows today's remaining allowance, credits, token counts and
|
|
41
41
|
the account tier. Read-only.
|
|
42
|
+
- \`free_pi_subagent_read\` reads the transcript of a child session started with
|
|
43
|
+
the \`subagent\` tool: its prompts, every tool call with input and result, and
|
|
44
|
+
its final answer. Read-only; omit \`sessionID\` to list this session's children.
|
|
42
45
|
- \`look_at_image\` asks a vision model about a PNG, JPEG or WebP inside the
|
|
43
46
|
project. Use it when the current model takes text only, or when the image is a
|
|
44
47
|
file on disk and you want a targeted answer instead of attaching it.
|
|
@@ -64,7 +67,10 @@ Use OpenCode's native subagent tool with the agents this plugin installs:
|
|
|
64
67
|
Subagents inherit the free-pi model, share the same daily allowance, and run as
|
|
65
68
|
child sessions in the background. Keep large exploration in a subagent so it
|
|
66
69
|
does not fill your own context. Use OpenCode's agent picker or the \`subagent\`
|
|
67
|
-
tool; do not try to launch them through shell commands.
|
|
70
|
+
tool; do not try to launch them through shell commands. The \`subagent\` tool
|
|
71
|
+
returns the child \`sessionID\` and OpenCode injects the child's report when it
|
|
72
|
+
goes idle; call \`free_pi_subagent_read\` with that id to see what the child ran
|
|
73
|
+
and why its answer says what it says.
|
|
68
74
|
|
|
69
75
|
## Memory and sessions
|
|
70
76
|
|
package/dist/catalog/catalog.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/** Fetches the live free-pi model catalog. */
|
|
2
2
|
import { resolveToken } from "../auth/token.js";
|
|
3
|
-
import { CATALOG_TIMEOUT_MS, CATALOG_TTL_MS, } from "../constants.js";
|
|
3
|
+
import { CATALOG_ATTEMPTS, CATALOG_RETRY_MS, CATALOG_TIMEOUT_MS, CATALOG_TTL_MS, } from "../constants.js";
|
|
4
|
+
import { sleep } from "../utils/async.js";
|
|
4
5
|
import { resolveBaseUrl } from "../utils/urls.js";
|
|
5
6
|
function isCatalog(value) {
|
|
6
7
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
@@ -32,33 +33,48 @@ export function refreshCatalog(deps) {
|
|
|
32
33
|
if (state.catalogPromise)
|
|
33
34
|
return state.catalogPromise;
|
|
34
35
|
const pending = (async () => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
36
|
+
let lastError;
|
|
37
|
+
for (let attempt = 1; attempt <= CATALOG_ATTEMPTS; attempt += 1) {
|
|
38
|
+
try {
|
|
39
|
+
const token = await resolveToken(deps).catch(() => undefined);
|
|
40
|
+
const headers = {
|
|
41
|
+
accept: "application/json",
|
|
42
|
+
};
|
|
43
|
+
if (token)
|
|
44
|
+
headers.authorization = `Bearer ${token}`;
|
|
45
|
+
const response = await fetch(`${resolveBaseUrl()}/client-version`, {
|
|
46
|
+
headers,
|
|
47
|
+
signal: AbortSignal.timeout(CATALOG_TIMEOUT_MS),
|
|
48
|
+
});
|
|
49
|
+
if (!response.ok)
|
|
50
|
+
throw new Error(`HTTP ${response.status}`);
|
|
51
|
+
const catalog = (await response.json());
|
|
52
|
+
if (!isCatalog(catalog)) {
|
|
53
|
+
throw new Error("free-pi returned an unexpected catalog payload");
|
|
54
|
+
}
|
|
55
|
+
applyCatalog(deps, catalog);
|
|
56
|
+
return catalog;
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
lastError = error;
|
|
60
|
+
// A timeout or a dropped connection is often transient. Retrying here
|
|
61
|
+
// avoids registering a provider with zero models for this location,
|
|
62
|
+
// which would hide every free-pi model from the picker until OpenCode
|
|
63
|
+
// restarts.
|
|
64
|
+
if (attempt < CATALOG_ATTEMPTS) {
|
|
65
|
+
deps.log.info("free-pi catalog request failed; retrying", {
|
|
66
|
+
attempt,
|
|
67
|
+
reason: reasonText(error),
|
|
68
|
+
});
|
|
69
|
+
await sleep(CATALOG_RETRY_MS * attempt);
|
|
70
|
+
}
|
|
51
71
|
}
|
|
52
|
-
applyCatalog(deps, catalog);
|
|
53
|
-
return catalog;
|
|
54
|
-
}
|
|
55
|
-
catch (error) {
|
|
56
|
-
const cached = state.cachedCatalog;
|
|
57
|
-
deps.log.warn(cached
|
|
58
|
-
? "free-pi catalog is unreachable; using the cached model list"
|
|
59
|
-
: "free-pi catalog is unreachable; no free-pi models were registered", { reason: reasonText(error) });
|
|
60
|
-
return cached;
|
|
61
72
|
}
|
|
73
|
+
const cached = state.cachedCatalog;
|
|
74
|
+
deps.log.warn(cached
|
|
75
|
+
? "free-pi catalog is unreachable; using the cached model list"
|
|
76
|
+
: "free-pi catalog is unreachable; no free-pi models were registered", { reason: reasonText(lastError) });
|
|
77
|
+
return cached;
|
|
62
78
|
})();
|
|
63
79
|
state.catalogPromise = pending;
|
|
64
80
|
void pending.finally(() => {
|
package/dist/constants.d.ts
CHANGED
|
@@ -50,7 +50,7 @@ export declare const DEFAULT_THINKING_LEVELS: readonly ["none", "minimal", "low"
|
|
|
50
50
|
* models show: skipping analysis, inventing verification, and ignoring the
|
|
51
51
|
* context the conversation already established.
|
|
52
52
|
*/
|
|
53
|
-
export declare const FREE_PI_GUIDANCE = "# free-pi working rules\n- Answer the user's latest request and keep their constraints; do not switch to a different task.\n- Slow down on multi-step work (arithmetic, counting, logic, dates, units, planning, debugging): write out each step, recompute the result a second way, and only then answer. On those tasks a correct answer after a dozen explicit steps beats a fast guess; do not stop at the first plausible number.\n- Read the files involved before editing and run the project's checks afterwards. Never say a test, build or command passed unless you ran it and saw it pass.\n- Treat the conversation above as memory: reuse earlier decisions, file paths, identifiers and results. If something is genuinely missing, say what is missing instead of guessing.\n- Use the available tools (read, grep, glob, bash, edit) for real work; do not describe hypothetical commands as if they ran.\n- Delegate large or self-contained work with OpenCode's native `subagent` tool: `free-pi/scout` and `free-pi/planner` for read-only recon and planning, `free-pi/worker` for a full task, `free-pi/reviewer` for review. A subagent runs in its own context and reports back; never launch a subagent from inside one.\n- Load a skill with the native `skill` tool when its description matches the task.\n- `AGENTS.md` and the files listed under `instructions` are the project's memory. Follow them; do not restate or replace them.\n- Never claim to have compacted, summarized or cleared context unless that actually happened.\n- Continue until the request is finished, then report concisely what changed and what you verified.";
|
|
53
|
+
export declare const FREE_PI_GUIDANCE = "# free-pi working rules\n- Answer the user's latest request and keep their constraints; do not switch to a different task.\n- Slow down on multi-step work (arithmetic, counting, logic, dates, units, planning, debugging): write out each step, recompute the result a second way, and only then answer. On those tasks a correct answer after a dozen explicit steps beats a fast guess; do not stop at the first plausible number.\n- Read the files involved before editing and run the project's checks afterwards. Never say a test, build or command passed unless you ran it and saw it pass.\n- Treat the conversation above as memory: reuse earlier decisions, file paths, identifiers and results. If something is genuinely missing, say what is missing instead of guessing.\n- Use the available tools (read, grep, glob, bash, edit) for real work; do not describe hypothetical commands as if they ran.\n- Delegate large or self-contained work with OpenCode's native `subagent` tool: `free-pi/scout` and `free-pi/planner` for read-only recon and planning, `free-pi/worker` for a full task, `free-pi/reviewer` for review. A subagent runs in its own context and reports back; never launch a subagent from inside one. The `subagent` tool returns a child `sessionID` and OpenCode injects the child's report when it goes idle; to inspect what that child actually did, call `free_pi_subagent_read` with its `sessionID` (omit it to list this session's children).\n- Load a skill with the native `skill` tool when its description matches the task.\n- `AGENTS.md` and the files listed under `instructions` are the project's memory. Follow them; do not restate or replace them.\n- Never claim to have compacted, summarized or cleared context unless that actually happened.\n- Continue until the request is finished, then report concisely what changed and what you verified.";
|
|
54
54
|
export declare const FREE_PI_GUIDANCE_MARKER = "# free-pi working rules";
|
|
55
55
|
/**
|
|
56
56
|
* Appended to OpenCode's compaction request. Its default summary prompt asks
|
|
@@ -66,6 +66,15 @@ export declare const CHUNK_TIMEOUT_MS = 300000;
|
|
|
66
66
|
export declare const RETRY_MAX_RETRIES = 3;
|
|
67
67
|
export declare const RETRY_BASE_DELAY_MS = 2000;
|
|
68
68
|
export declare const RETRY_MAX_DELAY_MS = 60000;
|
|
69
|
+
/**
|
|
70
|
+
* Transport failures (a refused or dropped connection, DNS blips) usually
|
|
71
|
+
* clear on their own. OpenCode stops after its own retries, which can end a
|
|
72
|
+
* turn during a brief local network or service restart, so the plugin gives
|
|
73
|
+
* them a longer budget before giving up.
|
|
74
|
+
*/
|
|
75
|
+
export declare const TRANSPORT_RETRY_MAX = 5;
|
|
76
|
+
export declare const TRANSPORT_RETRY_BASE_MS = 2000;
|
|
77
|
+
export declare const TRANSPORT_RETRY_MAX_DELAY_MS = 30000;
|
|
69
78
|
/**
|
|
70
79
|
* free-pi allows one in-flight request per `x-session-id` and answers a second
|
|
71
80
|
* one with `429 concurrent`. OpenCode does not retry that itself, and a slot
|
|
@@ -94,6 +103,15 @@ export declare const AD_IMPRESSION_LIMIT = 200;
|
|
|
94
103
|
export declare const CREDITS_PER_USD: number;
|
|
95
104
|
export declare const CATALOG_TTL_MS: number;
|
|
96
105
|
export declare const CATALOG_TIMEOUT_MS = 8000;
|
|
106
|
+
export declare const CATALOG_ATTEMPTS = 2;
|
|
107
|
+
export declare const CATALOG_RETRY_MS = 1000;
|
|
108
|
+
/**
|
|
109
|
+
* When the catalog cannot be fetched, the provider is registered with no models
|
|
110
|
+
* and the model picker loses every free-pi entry for that location. These are
|
|
111
|
+
* the delays before each background attempt to fetch it again and re-register
|
|
112
|
+
* the models, so a transient timeout heals without restarting OpenCode.
|
|
113
|
+
*/
|
|
114
|
+
export declare const CATALOG_RECOVERY_DELAYS_MS: readonly [2000, 5000, 10000, 20000, 30000, 60000];
|
|
97
115
|
export declare const REGISTRY_TTL_MS: number;
|
|
98
116
|
export declare const REGISTRY_RETRY_MS = 60000;
|
|
99
117
|
export declare const REGISTRY_TIMEOUT_MS = 3500;
|
package/dist/constants.js
CHANGED
|
@@ -70,7 +70,7 @@ export const FREE_PI_GUIDANCE = `# free-pi working rules
|
|
|
70
70
|
- Read the files involved before editing and run the project's checks afterwards. Never say a test, build or command passed unless you ran it and saw it pass.
|
|
71
71
|
- Treat the conversation above as memory: reuse earlier decisions, file paths, identifiers and results. If something is genuinely missing, say what is missing instead of guessing.
|
|
72
72
|
- Use the available tools (read, grep, glob, bash, edit) for real work; do not describe hypothetical commands as if they ran.
|
|
73
|
-
- Delegate large or self-contained work with OpenCode's native \`subagent\` tool: \`free-pi/scout\` and \`free-pi/planner\` for read-only recon and planning, \`free-pi/worker\` for a full task, \`free-pi/reviewer\` for review. A subagent runs in its own context and reports back; never launch a subagent from inside one.
|
|
73
|
+
- Delegate large or self-contained work with OpenCode's native \`subagent\` tool: \`free-pi/scout\` and \`free-pi/planner\` for read-only recon and planning, \`free-pi/worker\` for a full task, \`free-pi/reviewer\` for review. A subagent runs in its own context and reports back; never launch a subagent from inside one. The \`subagent\` tool returns a child \`sessionID\` and OpenCode injects the child's report when it goes idle; to inspect what that child actually did, call \`free_pi_subagent_read\` with its \`sessionID\` (omit it to list this session's children).
|
|
74
74
|
- Load a skill with the native \`skill\` tool when its description matches the task.
|
|
75
75
|
- \`AGENTS.md\` and the files listed under \`instructions\` are the project's memory. Follow them; do not restate or replace them.
|
|
76
76
|
- Never claim to have compacted, summarized or cleared context unless that actually happened.
|
|
@@ -94,6 +94,15 @@ export const CHUNK_TIMEOUT_MS = 300_000;
|
|
|
94
94
|
export const RETRY_MAX_RETRIES = 3;
|
|
95
95
|
export const RETRY_BASE_DELAY_MS = 2_000;
|
|
96
96
|
export const RETRY_MAX_DELAY_MS = 60_000;
|
|
97
|
+
/**
|
|
98
|
+
* Transport failures (a refused or dropped connection, DNS blips) usually
|
|
99
|
+
* clear on their own. OpenCode stops after its own retries, which can end a
|
|
100
|
+
* turn during a brief local network or service restart, so the plugin gives
|
|
101
|
+
* them a longer budget before giving up.
|
|
102
|
+
*/
|
|
103
|
+
export const TRANSPORT_RETRY_MAX = 5;
|
|
104
|
+
export const TRANSPORT_RETRY_BASE_MS = 2_000;
|
|
105
|
+
export const TRANSPORT_RETRY_MAX_DELAY_MS = 30_000;
|
|
97
106
|
/**
|
|
98
107
|
* free-pi allows one in-flight request per `x-session-id` and answers a second
|
|
99
108
|
* one with `429 concurrent`. OpenCode does not retry that itself, and a slot
|
|
@@ -122,6 +131,17 @@ export const AD_IMPRESSION_LIMIT = 200;
|
|
|
122
131
|
export const CREDITS_PER_USD = 40_000 / 3;
|
|
123
132
|
export const CATALOG_TTL_MS = 10 * 60_000;
|
|
124
133
|
export const CATALOG_TIMEOUT_MS = 8_000;
|
|
134
|
+
export const CATALOG_ATTEMPTS = 2;
|
|
135
|
+
export const CATALOG_RETRY_MS = 1_000;
|
|
136
|
+
/**
|
|
137
|
+
* When the catalog cannot be fetched, the provider is registered with no models
|
|
138
|
+
* and the model picker loses every free-pi entry for that location. These are
|
|
139
|
+
* the delays before each background attempt to fetch it again and re-register
|
|
140
|
+
* the models, so a transient timeout heals without restarting OpenCode.
|
|
141
|
+
*/
|
|
142
|
+
export const CATALOG_RECOVERY_DELAYS_MS = [
|
|
143
|
+
2_000, 5_000, 10_000, 20_000, 30_000, 60_000,
|
|
144
|
+
];
|
|
125
145
|
export const REGISTRY_TTL_MS = 5 * 60_000;
|
|
126
146
|
export const REGISTRY_RETRY_MS = 60_000;
|
|
127
147
|
export const REGISTRY_TIMEOUT_MS = 3_500;
|
package/dist/deps.d.ts
CHANGED
|
@@ -3,12 +3,15 @@ import type { Credential } from "@opencode/schema/credential";
|
|
|
3
3
|
import type { Plugin } from "@opencode/plugin";
|
|
4
4
|
import type { Logger } from "./logging.js";
|
|
5
5
|
import type { RuntimeState } from "./state.js";
|
|
6
|
-
import type { ReadContext } from "./types.js";
|
|
6
|
+
import type { ListSubagentSessions, ReadContext, ReadSessionInfo } from "./types.js";
|
|
7
7
|
export type Deps = {
|
|
8
8
|
readonly state: RuntimeState;
|
|
9
9
|
readonly log: Logger;
|
|
10
10
|
readonly activeCredential: () => Promise<Credential.Value | undefined>;
|
|
11
11
|
readonly readContext: ReadContext;
|
|
12
|
+
/** Session headers, used to prove a session is really this session's child. */
|
|
13
|
+
readonly readSession?: ReadSessionInfo;
|
|
14
|
+
readonly listSubagentSessions?: ListSubagentSessions;
|
|
12
15
|
/** Plugin-scoped durable storage, used to reconnect provider sessions. */
|
|
13
16
|
readonly storage?: Plugin.Context["storage"];
|
|
14
17
|
};
|
package/dist/plugin.js
CHANGED
|
@@ -10,7 +10,7 @@ import { currentLiveLimits, loadLiveLimits, shouldVerifyWindow, verifyGatewayWin
|
|
|
10
10
|
import { accountAccess, buildModels, filterAccessibleModels, isReasoningEffort, modelRegistryCandidates, partitionModels, } from "./catalog/models.js";
|
|
11
11
|
import { fetchModelsRegistry } from "./catalog/registry.js";
|
|
12
12
|
import { applyProvider } from "./catalog/v2.js";
|
|
13
|
-
import { DEFENSE_PROVIDER_ID, PROVIDER_ID, } from "./constants.js";
|
|
13
|
+
import { CATALOG_RECOVERY_DELAYS_MS, DEFENSE_PROVIDER_ID, PROVIDER_ID, } from "./constants.js";
|
|
14
14
|
import { registerIntegration } from "./integration/setup.js";
|
|
15
15
|
import { createLogger } from "./logging.js";
|
|
16
16
|
import { subscribeEvents } from "./session/events.js";
|
|
@@ -19,6 +19,7 @@ import { cancelAllFinalizeTimers } from "./session/track.js";
|
|
|
19
19
|
import { createRuntimeState } from "./state.js";
|
|
20
20
|
import { registerGenerateImageTool } from "./tools/image-generate.js";
|
|
21
21
|
import { registerUsageTool } from "./tools/usage.js";
|
|
22
|
+
import { registerSubagentTool } from "./tools/subagent.js";
|
|
22
23
|
import { registerVisionTool } from "./tools/vision.js";
|
|
23
24
|
import { registerWebTools } from "./tools/web.js";
|
|
24
25
|
import { settle } from "./utils/async.js";
|
|
@@ -51,6 +52,38 @@ async function setup(ctx) {
|
|
|
51
52
|
return [];
|
|
52
53
|
}
|
|
53
54
|
},
|
|
55
|
+
readSession: async (sessionID) => {
|
|
56
|
+
try {
|
|
57
|
+
const info = await ctx.session.get({ sessionID });
|
|
58
|
+
return {
|
|
59
|
+
id: info.id,
|
|
60
|
+
parentID: info.parentID,
|
|
61
|
+
title: info.title,
|
|
62
|
+
agent: info.agent,
|
|
63
|
+
outcome: info.outcome,
|
|
64
|
+
updated: info.time?.updated,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
listSubagentSessions: async (parentID) => {
|
|
72
|
+
try {
|
|
73
|
+
const result = await ctx.session.list({ parentID, limit: 50 });
|
|
74
|
+
return (result.data ?? []).map((info) => ({
|
|
75
|
+
id: info.id,
|
|
76
|
+
parentID: info.parentID,
|
|
77
|
+
title: info.title,
|
|
78
|
+
agent: info.agent,
|
|
79
|
+
outcome: info.outcome,
|
|
80
|
+
updated: info.time?.updated,
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
return [];
|
|
85
|
+
}
|
|
86
|
+
},
|
|
54
87
|
storage: ctx.storage,
|
|
55
88
|
};
|
|
56
89
|
// OpenCode owns agents and skills. The plugin only installs the CLI's
|
|
@@ -117,8 +150,9 @@ async function setup(ctx) {
|
|
|
117
150
|
// Without a quota snapshot every model stays visible.
|
|
118
151
|
const access = accountAccess(quota?.me);
|
|
119
152
|
const { main: catalogMain, defense: catalogDefense } = partitionModels(catalog);
|
|
120
|
-
|
|
121
|
-
|
|
153
|
+
let currentCatalog = catalog;
|
|
154
|
+
let currentMain = filterAccessibleModels(catalogMain, access);
|
|
155
|
+
let currentDefense = filterAccessibleModels(catalogDefense, access);
|
|
122
156
|
const candidates = modelRegistryCandidates(registry);
|
|
123
157
|
const live = await loadLiveLimits();
|
|
124
158
|
const configuredEffort = ctx.options?.reasoningEffort;
|
|
@@ -130,34 +164,41 @@ async function setup(ctx) {
|
|
|
130
164
|
? { reasoningEffort: configuredEffort }
|
|
131
165
|
: {}),
|
|
132
166
|
};
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
167
|
+
// Rebuilt on every call so a learned context ceiling or a recovered catalog
|
|
168
|
+
// applies without restarting OpenCode.
|
|
169
|
+
const buildMain = () => buildModels(currentMain, candidates, {
|
|
170
|
+
...buildOptions,
|
|
171
|
+
live: currentLiveLimits() ?? live,
|
|
172
|
+
});
|
|
173
|
+
const buildDefense = () => buildModels(currentDefense, candidates, {
|
|
174
|
+
...buildOptions,
|
|
175
|
+
live: currentLiveLimits() ?? live,
|
|
176
|
+
});
|
|
177
|
+
function indexModelState() {
|
|
178
|
+
const mainNow = buildMain();
|
|
179
|
+
const defenseNow = buildDefense();
|
|
180
|
+
for (const [id, model] of Object.entries(mainNow)) {
|
|
181
|
+
state.outputLimits.set(`${PROVIDER_ID}/${id}`, model.limit.output);
|
|
182
|
+
if (model.modalities.input.includes("image")) {
|
|
183
|
+
state.imageModels.add(`${PROVIDER_ID}/${id}`);
|
|
184
|
+
}
|
|
139
185
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
186
|
+
for (const [id, model] of Object.entries(defenseNow)) {
|
|
187
|
+
state.outputLimits.set(`${DEFENSE_PROVIDER_ID}/${id}`, model.limit.output);
|
|
188
|
+
if (model.modalities.input.includes("image")) {
|
|
189
|
+
state.imageModels.add(`${DEFENSE_PROVIDER_ID}/${id}`);
|
|
190
|
+
}
|
|
145
191
|
}
|
|
146
192
|
}
|
|
193
|
+
indexModelState();
|
|
147
194
|
const credential = await deps.activeCredential().catch(() => undefined);
|
|
148
195
|
state.providerToken =
|
|
149
196
|
tokenFromCredential(credential) ?? (await readCredentialsToken());
|
|
150
197
|
await registerIntegration(ctx, deps);
|
|
151
198
|
await ctx.provider.transform((editor) => {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
const buildOptionsNow = { ...buildOptions, live: active };
|
|
156
|
-
const mainNow = buildModels(main, candidates, buildOptionsNow);
|
|
157
|
-
const defenseNow = buildModels(defense, candidates, buildOptionsNow);
|
|
158
|
-
applyProvider(editor, PROVIDER_ID, "Free Pi", mainNow, state.providerToken);
|
|
159
|
-
if (includeDefense && defense.length > 0) {
|
|
160
|
-
applyProvider(editor, DEFENSE_PROVIDER_ID, "Free Pi Defense", defenseNow, state.providerToken);
|
|
199
|
+
applyProvider(editor, PROVIDER_ID, "Free Pi", buildMain(), state.providerToken);
|
|
200
|
+
if (includeDefense && currentDefense.length > 0) {
|
|
201
|
+
applyProvider(editor, DEFENSE_PROVIDER_ID, "Free Pi Defense", buildDefense(), state.providerToken);
|
|
161
202
|
}
|
|
162
203
|
});
|
|
163
204
|
// The gateway does not publish its context ceiling. Verify the compiled
|
|
@@ -166,19 +207,19 @@ async function setup(ctx) {
|
|
|
166
207
|
// the largest prompt already accepted in real traffic: it has the most
|
|
167
208
|
// evidence behind it, so the growth probes describe the window sessions use.
|
|
168
209
|
if (ctx.options?.liveLimits !== false && shouldVerifyWindow(live)) {
|
|
169
|
-
const free =
|
|
210
|
+
const free = currentMain.filter((model) => model.free === true && typeof model.id === "string");
|
|
170
211
|
const probe = free
|
|
171
212
|
.map((model) => ({
|
|
172
213
|
id: model.id,
|
|
173
214
|
seen: live?.models[model.id ?? ""]?.maxPromptTokens ?? 0,
|
|
174
215
|
}))
|
|
175
216
|
.sort((a, b) => b.seen - a.seen)[0]?.id ??
|
|
176
|
-
(
|
|
177
|
-
free.some((model) => model.id ===
|
|
178
|
-
?
|
|
217
|
+
(currentCatalog?.default_model &&
|
|
218
|
+
free.some((model) => model.id === currentCatalog?.default_model)
|
|
219
|
+
? currentCatalog.default_model
|
|
179
220
|
: undefined) ??
|
|
180
221
|
free[0]?.id ??
|
|
181
|
-
Object.keys(
|
|
222
|
+
Object.keys(buildMain())[0];
|
|
182
223
|
if (probe) {
|
|
183
224
|
void verifyGatewayWindow(deps, { model: probe }).catch(() => undefined);
|
|
184
225
|
}
|
|
@@ -187,9 +228,10 @@ async function setup(ctx) {
|
|
|
187
228
|
await ctx.model.transform((editor) => {
|
|
188
229
|
if (editor.default.get())
|
|
189
230
|
return;
|
|
190
|
-
const
|
|
191
|
-
|
|
192
|
-
|
|
231
|
+
const models = buildMain();
|
|
232
|
+
const preferred = (currentCatalog?.default_model && models[currentCatalog.default_model]
|
|
233
|
+
? currentCatalog.default_model
|
|
234
|
+
: undefined) ?? Object.keys(models)[0];
|
|
193
235
|
if (preferred)
|
|
194
236
|
editor.default.set(PROVIDER_ID, preferred);
|
|
195
237
|
});
|
|
@@ -198,6 +240,10 @@ async function setup(ctx) {
|
|
|
198
240
|
const tools = [
|
|
199
241
|
{ name: "look_at_image", register: () => registerVisionTool(ctx, deps) },
|
|
200
242
|
{ name: "free_pi_usage", register: () => registerUsageTool(ctx, deps) },
|
|
243
|
+
{
|
|
244
|
+
name: "free_pi_subagent_read",
|
|
245
|
+
register: () => registerSubagentTool(ctx, deps),
|
|
246
|
+
},
|
|
201
247
|
{ name: "web", register: () => registerWebTools(ctx, deps) },
|
|
202
248
|
{ name: "generate_image", register: () => registerGenerateImageTool(ctx, deps) },
|
|
203
249
|
];
|
|
@@ -211,11 +257,61 @@ async function setup(ctx) {
|
|
|
211
257
|
}
|
|
212
258
|
const abort = new AbortController();
|
|
213
259
|
const eventTask = subscribeEvents(ctx, deps, abort.signal);
|
|
214
|
-
|
|
215
|
-
|
|
260
|
+
// A failed catalog fetch registers the provider with zero models, which
|
|
261
|
+
// hides every free-pi entry from the model picker for this location until
|
|
262
|
+
// OpenCode restarts. Retry in the background and re-register the models as
|
|
263
|
+
// soon as the gateway answers, so a transient timeout heals on its own.
|
|
264
|
+
const waitForAbort = (ms) => new Promise((resolve) => {
|
|
265
|
+
if (abort.signal.aborted)
|
|
266
|
+
return resolve();
|
|
267
|
+
const finish = () => {
|
|
268
|
+
clearTimeout(timer);
|
|
269
|
+
abort.signal.removeEventListener("abort", finish);
|
|
270
|
+
resolve();
|
|
271
|
+
};
|
|
272
|
+
const timer = setTimeout(finish, ms);
|
|
273
|
+
abort.signal.addEventListener("abort", finish, { once: true });
|
|
274
|
+
});
|
|
275
|
+
const catalogRecovery = (async () => {
|
|
276
|
+
// Only a missing catalog needs recovery; an empty model list after access
|
|
277
|
+
// filtering means the account cannot use these models, not a timeout.
|
|
278
|
+
if (currentCatalog)
|
|
279
|
+
return;
|
|
280
|
+
for (const delay of CATALOG_RECOVERY_DELAYS_MS) {
|
|
281
|
+
if (abort.signal.aborted || currentMain.length > 0)
|
|
282
|
+
return;
|
|
283
|
+
await waitForAbort(delay);
|
|
284
|
+
if (abort.signal.aborted || currentMain.length > 0)
|
|
285
|
+
return;
|
|
286
|
+
const next = await fetchCatalog(deps).catch(() => undefined);
|
|
287
|
+
if (!next)
|
|
288
|
+
continue;
|
|
289
|
+
const parts = partitionModels(next);
|
|
290
|
+
const accessNow = accountAccess(state.quotaCache?.me);
|
|
291
|
+
const nextMain = filterAccessibleModels(parts.main, accessNow);
|
|
292
|
+
if (nextMain.length === 0)
|
|
293
|
+
continue;
|
|
294
|
+
currentCatalog = next;
|
|
295
|
+
currentMain = nextMain;
|
|
296
|
+
currentDefense = filterAccessibleModels(parts.defense, accessNow);
|
|
297
|
+
indexModelState();
|
|
298
|
+
await ctx.provider.reload().catch(() => undefined);
|
|
299
|
+
await ctx.model.reload().catch(() => undefined);
|
|
300
|
+
log.info(`free-pi catalog recovered; registered ${currentMain.length} model(s)`, {
|
|
301
|
+
defaultModel: currentCatalog?.default_model,
|
|
302
|
+
clientVersion: state.latestClientVersion,
|
|
303
|
+
models: currentMain.map((model) => model.id),
|
|
304
|
+
});
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
log.warn("free-pi catalog stayed unreachable; free-pi models remain unavailable", { attempts: CATALOG_RECOVERY_DELAYS_MS.length });
|
|
308
|
+
})();
|
|
309
|
+
void catalogRecovery.catch(() => undefined);
|
|
310
|
+
log.info(`Loaded ${currentMain.length} free-pi model(s) and ${includeDefense ? currentDefense.length : 0} defense model(s)`, {
|
|
311
|
+
defaultModel: currentCatalog?.default_model,
|
|
216
312
|
clientVersion: state.latestClientVersion,
|
|
217
313
|
capabilities: candidates.length,
|
|
218
|
-
models:
|
|
314
|
+
models: currentMain.map((model) => model.id),
|
|
219
315
|
});
|
|
220
316
|
return async () => {
|
|
221
317
|
abort.abort();
|
package/dist/session/hooks.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { ensureAdImpression } from "../ads/impression.js";
|
|
3
3
|
import { resolveAdTurn } from "../ads/resolve.js";
|
|
4
4
|
import { resolveToken } from "../auth/token.js";
|
|
5
|
-
import { AD_CONTEXT_HEADER, AD_CONTEXT_OPT_OUT, CONCURRENT_RETRY_BASE_MS, CONCURRENT_RETRY_MAX, CONCURRENT_RETRY_MAX_DELAY_MS, DEFENSE_PROVIDER_ID, FREE_PI_COMPACTION_GUIDANCE, FREE_PI_COMPACTION_MARKER, FREE_PI_GUIDANCE, FREE_PI_GUIDANCE_MARKER, MAX_OUTPUT_TOKENS, MAX_OUTPUT_TOKENS_CEILING, PROVIDER_ID, RETRY_BASE_DELAY_MS, RETRY_MAX_DELAY_MS, RETRY_MAX_RETRIES, SUBAGENT_HEADER, } from "../constants.js";
|
|
5
|
+
import { AD_CONTEXT_HEADER, AD_CONTEXT_OPT_OUT, CONCURRENT_RETRY_BASE_MS, CONCURRENT_RETRY_MAX, CONCURRENT_RETRY_MAX_DELAY_MS, DEFENSE_PROVIDER_ID, FREE_PI_COMPACTION_GUIDANCE, FREE_PI_COMPACTION_MARKER, FREE_PI_GUIDANCE, FREE_PI_GUIDANCE_MARKER, MAX_OUTPUT_TOKENS, MAX_OUTPUT_TOKENS_CEILING, PROVIDER_ID, RETRY_BASE_DELAY_MS, RETRY_MAX_DELAY_MS, RETRY_MAX_RETRIES, SUBAGENT_HEADER, TRANSPORT_RETRY_BASE_MS, TRANSPORT_RETRY_MAX, TRANSPORT_RETRY_MAX_DELAY_MS, } from "../constants.js";
|
|
6
6
|
import { currentLiveLimits, learnedContextWindow, noteRejectedPrompt, } from "../catalog/live.js";
|
|
7
7
|
import { closeFreePiSession } from "../api/session.js";
|
|
8
8
|
import { rewriteContextOverflowResponse, rewriteLimitResponse, } from "../errors/limit.js";
|
|
@@ -215,6 +215,20 @@ const TERMINAL_RETRY_CODES = new Set([
|
|
|
215
215
|
"subagents_unavailable",
|
|
216
216
|
]);
|
|
217
217
|
const TERMINAL_RETRY_PATTERN = /free usage limit|monthly usage limit|available balance|insufficient_quota|out of budget|quota exceeded|billing|subscription_sharing_usage_limit_exceeded/i;
|
|
218
|
+
/**
|
|
219
|
+
* A request that never reached the gateway. `provider.transport` covers the
|
|
220
|
+
* typed path, while the pattern catches bare fetch errors. These are worth
|
|
221
|
+
* retrying beyond the usual budget: a brief offline moment or a background
|
|
222
|
+
* service restart is not a provider limit.
|
|
223
|
+
*/
|
|
224
|
+
const TRANSPORT_RETRY_PATTERN = /ECONNREFUSED|ECONNRESET|ETIMEDOUT|ENOTFOUND|EHOSTUNREACH|ENETUNREACH|EAI_AGAIN|EPIPE|socket hang up|fetch failed|Unable to connect|connection (?:refused|reset)/i;
|
|
225
|
+
function isTransportFailure(error) {
|
|
226
|
+
const type = typeof error?.type === "string" ? error.type : "";
|
|
227
|
+
if (/transport|network|connection/i.test(type))
|
|
228
|
+
return true;
|
|
229
|
+
const message = `${error?.message ?? ""}\n${error?.cause?.message ?? ""}`;
|
|
230
|
+
return TRANSPORT_RETRY_PATTERN.test(message);
|
|
231
|
+
}
|
|
218
232
|
function isTerminalFailure(error) {
|
|
219
233
|
if (error?.type === "aborted" ||
|
|
220
234
|
/aborted|cancelled|canceled|interrupted|AbortError/i.test(`${error?.message ?? ""}`)) {
|
|
@@ -266,6 +280,27 @@ function applyRetryPolicy(deps, event) {
|
|
|
266
280
|
event.decision = { retry: false };
|
|
267
281
|
return;
|
|
268
282
|
}
|
|
283
|
+
if (isTransportFailure(event.error)) {
|
|
284
|
+
if (event.attempt > TRANSPORT_RETRY_MAX + 1) {
|
|
285
|
+
event.decision = { retry: false };
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
// A connection that dropped mid-turn can leave the gateway's per-session
|
|
289
|
+
// slot marked busy, so the next attempt should not reuse the wire id.
|
|
290
|
+
markWireSessionDirty(deps, event.sessionID);
|
|
291
|
+
const attempt = Math.max(1, event.attempt - 1);
|
|
292
|
+
event.decision = {
|
|
293
|
+
retry: true,
|
|
294
|
+
delay: Math.min(TRANSPORT_RETRY_BASE_MS * 2 ** (attempt - 1), TRANSPORT_RETRY_MAX_DELAY_MS),
|
|
295
|
+
};
|
|
296
|
+
deps.log.warn("free-pi could not be reached; retrying", {
|
|
297
|
+
sessionID: event.sessionID,
|
|
298
|
+
attempt: event.attempt,
|
|
299
|
+
delay: event.decision.delay,
|
|
300
|
+
error: typeof event.error?.message === "string" ? event.error.message : undefined,
|
|
301
|
+
});
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
269
304
|
if (event.attempt > RETRY_MAX_RETRIES + 1) {
|
|
270
305
|
event.decision = { retry: false };
|
|
271
306
|
return;
|
package/dist/session/tools.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ import type { Deps } from "../deps.js";
|
|
|
13
13
|
* served by another provider (see `hideFreePiTools`) and refuses to run them
|
|
14
14
|
* outside a free-pi session.
|
|
15
15
|
*/
|
|
16
|
-
export declare const FREE_PI_TOOL_NAMES: readonly ["look_at_image", "free_pi_usage", "web_search", "docs_lookup", "generate_image"];
|
|
16
|
+
export declare const FREE_PI_TOOL_NAMES: readonly ["look_at_image", "free_pi_usage", "free_pi_subagent_read", "web_search", "docs_lookup", "generate_image"];
|
|
17
17
|
type ToolResultLike = {
|
|
18
18
|
metadata?: Record<string, unknown>;
|
|
19
19
|
};
|