@eduardo191labs/opencode-free-pi 0.3.5 → 0.3.7
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 +4 -0
- package/dist/catalog/v2.js +5 -4
- package/dist/errors/messages.js +1 -0
- package/dist/errors/parse.js +20 -1
- package/package.json +2 -2
- package/src/catalog/v2.ts +5 -4
- package/src/errors/messages.ts +1 -0
- package/src/errors/parse.ts +19 -1
package/README.md
CHANGED
|
@@ -78,6 +78,10 @@ Después de iniciar sesión, ejecuta `/reload` en OpenCode o reinícialo.
|
|
|
78
78
|
El plugin lo responde con la primera línea del primer mensaje, sin gastar
|
|
79
79
|
créditos, sin pedir un anuncio y sin dejar la sesión atascada en
|
|
80
80
|
«New session».
|
|
81
|
+
- **Imágenes nativas**: los modelos aceptan imágenes pegadas o adjuntas.
|
|
82
|
+
El CLI las bloquea porque pi-ai no transporta imágenes, pero el endpoint de
|
|
83
|
+
chat de free-pi sí las acepta (verificado en vivo), así que OpenCode las
|
|
84
|
+
envía de forma nativa como partes `image_url`.
|
|
81
85
|
- **Subagentes identificados**: las sesiones hijas envían
|
|
82
86
|
`x-freepi-subagent: 1`, igual que los proveedores que el CLI crea para sus
|
|
83
87
|
subagentes.
|
package/dist/catalog/v2.js
CHANGED
|
@@ -13,10 +13,11 @@ export function toV2Models(providerID, models) {
|
|
|
13
13
|
...(model.family ? { family: model.family } : {}),
|
|
14
14
|
capabilities: {
|
|
15
15
|
tools: model.tool_call !== false,
|
|
16
|
-
// The provider CLI registers every free-pi model as text-only
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
|
|
16
|
+
// The provider CLI registers every free-pi model as text-only because
|
|
17
|
+
// pi-ai cannot carry image parts, but the server's chat endpoint does
|
|
18
|
+
// accept OpenAI-style image_url parts (verified live), so OpenCode can
|
|
19
|
+
// attach images natively.
|
|
20
|
+
input: ["text", "image"],
|
|
20
21
|
output: ["text"],
|
|
21
22
|
...(model.temperature === undefined
|
|
22
23
|
? {}
|
package/dist/errors/messages.js
CHANGED
|
@@ -45,6 +45,7 @@ const FREE_PI_ERROR_TITLE = {
|
|
|
45
45
|
unauthorized: "free-pi sign-in",
|
|
46
46
|
expired_token: "free-pi sign-in",
|
|
47
47
|
guest_allowance: "free-pi sign-in",
|
|
48
|
+
free_usage_limit: "free-pi free limit",
|
|
48
49
|
guest_login_required: "free-pi sign-in",
|
|
49
50
|
guest_unavailable: "free-pi sign-in",
|
|
50
51
|
consent_required: "free-pi consent",
|
package/dist/errors/parse.js
CHANGED
|
@@ -26,6 +26,10 @@ const RAW_FREE_PI_ERROR_PATTERNS = [
|
|
|
26
26
|
"insufficient_credits",
|
|
27
27
|
],
|
|
28
28
|
[/guest trial used up|guest_allowance/i, "guest_allowance"],
|
|
29
|
+
[
|
|
30
|
+
/free usage limit|monthly usage limit/i,
|
|
31
|
+
"free_usage_limit",
|
|
32
|
+
],
|
|
29
33
|
[
|
|
30
34
|
/needs a github sign-in|sign in with github|guest_login_required/i,
|
|
31
35
|
"guest_login_required",
|
|
@@ -91,11 +95,26 @@ export function parseRawFreePiError(error) {
|
|
|
91
95
|
}
|
|
92
96
|
return undefined;
|
|
93
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Recovers a code from the server's message text when the envelope carries no
|
|
100
|
+
* `code` field, for example the free-usage-limit 429 that only sends a message.
|
|
101
|
+
*/
|
|
102
|
+
function codeFromText(message) {
|
|
103
|
+
if (typeof message !== "string" || !message.trim())
|
|
104
|
+
return undefined;
|
|
105
|
+
const text = message.trim();
|
|
106
|
+
for (const [pattern, code] of RAW_FREE_PI_ERROR_PATTERNS) {
|
|
107
|
+
if (pattern.test(text))
|
|
108
|
+
return code;
|
|
109
|
+
}
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
94
112
|
export function parseFreePiError(error, allowRaw = false) {
|
|
95
113
|
const candidates = [
|
|
96
114
|
error?.response?.body,
|
|
97
115
|
error?.data?.responseBody,
|
|
98
116
|
error?.responseBody,
|
|
117
|
+
error?.data,
|
|
99
118
|
error?.data?.message,
|
|
100
119
|
error?.message,
|
|
101
120
|
];
|
|
@@ -129,7 +148,7 @@ export function parseFreePiError(error, allowRaw = false) {
|
|
|
129
148
|
? codeValue
|
|
130
149
|
: status === 401
|
|
131
150
|
? "unauthorized"
|
|
132
|
-
:
|
|
151
|
+
: codeFromText(message);
|
|
133
152
|
if (!code && typeof message !== "string")
|
|
134
153
|
continue;
|
|
135
154
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eduardo191labs/opencode-free-pi",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.7",
|
|
4
4
|
"description": "Ad-supported free-pi provider plugin for OpenCode on Windows, Linux, macOS and Termux",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"scripts": {
|
|
25
25
|
"build": "tsc -p tsconfig.json",
|
|
26
26
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
27
|
-
"test": "npm run build && node test/smoke.mjs && node test/registry.mjs && node test/models.mjs && node test/hooks.mjs && node test/title.mjs",
|
|
27
|
+
"test": "npm run build && node test/smoke.mjs && node test/registry.mjs && node test/models.mjs && node test/hooks.mjs && node test/title.mjs && node test/errors.mjs",
|
|
28
28
|
"prepublishOnly": "npm run build",
|
|
29
29
|
"postinstall": "node scripts/postinstall.mjs"
|
|
30
30
|
},
|
package/src/catalog/v2.ts
CHANGED
|
@@ -32,10 +32,11 @@ export function toV2Models(providerID: string, models: ModelMap): any[] {
|
|
|
32
32
|
...(model.family ? { family: model.family } : {}),
|
|
33
33
|
capabilities: {
|
|
34
34
|
tools: model.tool_call !== false,
|
|
35
|
-
// The provider CLI registers every free-pi model as text-only
|
|
36
|
-
//
|
|
37
|
-
//
|
|
38
|
-
|
|
35
|
+
// The provider CLI registers every free-pi model as text-only because
|
|
36
|
+
// pi-ai cannot carry image parts, but the server's chat endpoint does
|
|
37
|
+
// accept OpenAI-style image_url parts (verified live), so OpenCode can
|
|
38
|
+
// attach images natively.
|
|
39
|
+
input: ["text", "image"],
|
|
39
40
|
output: ["text"],
|
|
40
41
|
...(model.temperature === undefined
|
|
41
42
|
? {}
|
package/src/errors/messages.ts
CHANGED
|
@@ -67,6 +67,7 @@ const FREE_PI_ERROR_TITLE: Record<string, string> = {
|
|
|
67
67
|
unauthorized: "free-pi sign-in",
|
|
68
68
|
expired_token: "free-pi sign-in",
|
|
69
69
|
guest_allowance: "free-pi sign-in",
|
|
70
|
+
free_usage_limit: "free-pi free limit",
|
|
70
71
|
guest_login_required: "free-pi sign-in",
|
|
71
72
|
guest_unavailable: "free-pi sign-in",
|
|
72
73
|
consent_required: "free-pi consent",
|
package/src/errors/parse.ts
CHANGED
|
@@ -29,6 +29,10 @@ const RAW_FREE_PI_ERROR_PATTERNS: Array<[RegExp, string]> = [
|
|
|
29
29
|
"insufficient_credits",
|
|
30
30
|
],
|
|
31
31
|
[/guest trial used up|guest_allowance/i, "guest_allowance"],
|
|
32
|
+
[
|
|
33
|
+
/free usage limit|monthly usage limit/i,
|
|
34
|
+
"free_usage_limit",
|
|
35
|
+
],
|
|
32
36
|
[
|
|
33
37
|
/needs a github sign-in|sign in with github|guest_login_required/i,
|
|
34
38
|
"guest_login_required",
|
|
@@ -91,6 +95,19 @@ export function parseRawFreePiError(error: any): FreePiError | undefined {
|
|
|
91
95
|
return undefined;
|
|
92
96
|
}
|
|
93
97
|
|
|
98
|
+
/**
|
|
99
|
+
* Recovers a code from the server's message text when the envelope carries no
|
|
100
|
+
* `code` field, for example the free-usage-limit 429 that only sends a message.
|
|
101
|
+
*/
|
|
102
|
+
function codeFromText(message: unknown): string | undefined {
|
|
103
|
+
if (typeof message !== "string" || !message.trim()) return undefined;
|
|
104
|
+
const text = message.trim();
|
|
105
|
+
for (const [pattern, code] of RAW_FREE_PI_ERROR_PATTERNS) {
|
|
106
|
+
if (pattern.test(text)) return code;
|
|
107
|
+
}
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
|
|
94
111
|
export function parseFreePiError(
|
|
95
112
|
error: any,
|
|
96
113
|
allowRaw = false,
|
|
@@ -99,6 +116,7 @@ export function parseFreePiError(
|
|
|
99
116
|
error?.response?.body,
|
|
100
117
|
error?.data?.responseBody,
|
|
101
118
|
error?.responseBody,
|
|
119
|
+
error?.data,
|
|
102
120
|
error?.data?.message,
|
|
103
121
|
error?.message,
|
|
104
122
|
];
|
|
@@ -129,7 +147,7 @@ export function parseFreePiError(
|
|
|
129
147
|
? codeValue
|
|
130
148
|
: status === 401
|
|
131
149
|
? "unauthorized"
|
|
132
|
-
:
|
|
150
|
+
: codeFromText(message);
|
|
133
151
|
if (!code && typeof message !== "string") continue;
|
|
134
152
|
return {
|
|
135
153
|
status: typeof body.status === "number" ? body.status : status,
|