@eduardo191labs/opencode-free-pi 0.3.17 → 0.3.18
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 +3 -1
- package/dist/session/hooks.js +31 -1
- package/dist/session/tools.d.ts +1 -0
- package/dist/session/tools.js +1 -1
- package/package.json +1 -1
- package/src/session/hooks.ts +26 -0
- package/src/session/tools.ts +1 -1
package/README.md
CHANGED
|
@@ -83,7 +83,9 @@ Después de iniciar sesión, ejecuta `/reload` en OpenCode o reinícialo.
|
|
|
83
83
|
imagen), y enviarlas como partes `image_url` incrusta cada imagen leída
|
|
84
84
|
(cientos de KB) en la petición, desborda la ventana de 200k y gasta la
|
|
85
85
|
cuota diaria en tokens de imagen. OpenCode sustituye las imágenes por un
|
|
86
|
-
aviso de que el modelo no acepta esa entrada
|
|
86
|
+
aviso de que el modelo no acepta esa entrada, y el plugin aplica el mismo
|
|
87
|
+
aviso al terminar la herramienta para que el base64 no quede guardado en la
|
|
88
|
+
sesión.
|
|
87
89
|
- **Subagentes identificados**: las sesiones hijas envían
|
|
88
90
|
`x-freepi-subagent: 1`, igual que los proveedores que el CLI crea para sus
|
|
89
91
|
subagentes.
|
package/dist/session/hooks.js
CHANGED
|
@@ -12,7 +12,7 @@ import { rememberReplayBody, replayConcurrentResponse, } from "./replay.js";
|
|
|
12
12
|
import { localTitle } from "./title.js";
|
|
13
13
|
import { rememberFreePiSession } from "./track.js";
|
|
14
14
|
import { markWireSessionDirty, rotateWireSessionID, takeWireSessionDirty, wireSessionID, } from "./wire.js";
|
|
15
|
-
import { recordCompaction, recordToolEnd, recordToolStart, toolHeaders, } from "./tools.js";
|
|
15
|
+
import { isFreePiSession, recordCompaction, recordToolEnd, recordToolStart, toolHeaders, } from "./tools.js";
|
|
16
16
|
import { rememberTrackedModel } from "./usage.js";
|
|
17
17
|
const PENDING_LIMIT = 400;
|
|
18
18
|
/** Each agent gets its own ad turn, so a subagent never reuses the parent's. */
|
|
@@ -246,8 +246,38 @@ async function registerToolHooks(ctx, deps, registrations) {
|
|
|
246
246
|
status: event.status,
|
|
247
247
|
...(event.status === "completed" ? { result: event.result } : {}),
|
|
248
248
|
});
|
|
249
|
+
replaceUnsupportedImages(deps, event);
|
|
249
250
|
}));
|
|
250
251
|
}
|
|
252
|
+
/**
|
|
253
|
+
* free-pi only accepts text, like the provider CLI. OpenCode already swaps
|
|
254
|
+
* media for this notice when it builds a request for a text-only model, but
|
|
255
|
+
* doing it when the tool settles keeps the base64 image out of the session
|
|
256
|
+
* (and out of compaction) instead of storing hundreds of KB per read.
|
|
257
|
+
*/
|
|
258
|
+
function replaceUnsupportedImages(deps, event) {
|
|
259
|
+
if (event.status !== "completed")
|
|
260
|
+
return;
|
|
261
|
+
if (!isFreePiSession(deps, event.sessionID))
|
|
262
|
+
return;
|
|
263
|
+
const content = event.result?.content;
|
|
264
|
+
if (!Array.isArray(content))
|
|
265
|
+
return;
|
|
266
|
+
const replaced = content.map((part) => {
|
|
267
|
+
if (part?.type !== "file" || typeof part.mime !== "string")
|
|
268
|
+
return part;
|
|
269
|
+
if (!part.mime.toLowerCase().startsWith("image/"))
|
|
270
|
+
return part;
|
|
271
|
+
const name = typeof part.name === "string" ? part.name : part.mime;
|
|
272
|
+
return {
|
|
273
|
+
type: "text",
|
|
274
|
+
text: `ERROR: Cannot read "${name}" (this model does not support image input). Inform the user.`,
|
|
275
|
+
};
|
|
276
|
+
});
|
|
277
|
+
if (replaced.every((part, index) => part === content[index]))
|
|
278
|
+
return;
|
|
279
|
+
event.result = { ...event.result, content: replaced };
|
|
280
|
+
}
|
|
251
281
|
async function hookForProviders(ctx, name, callback, registrations) {
|
|
252
282
|
for (const providerID of [PROVIDER_ID, DEFENSE_PROVIDER_ID]) {
|
|
253
283
|
registrations.push(await ctx.session.hook(name, callback, {
|
package/dist/session/tools.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ type ToolEnd = {
|
|
|
16
16
|
status: "completed" | "error";
|
|
17
17
|
result?: ToolResultLike;
|
|
18
18
|
};
|
|
19
|
+
export declare function isFreePiSession(deps: Deps, sessionID: string): boolean;
|
|
19
20
|
export declare function recordToolStart(deps: Deps, sessionID: string, id: string): void;
|
|
20
21
|
export declare function recordToolEnd(deps: Deps, sessionID: string, end: ToolEnd): void;
|
|
21
22
|
export declare function recordCompaction(deps: Deps, sessionID: string, droppedMessages: number): void;
|
package/dist/session/tools.js
CHANGED
|
@@ -11,7 +11,7 @@ import { trimMap } from "../utils/async.js";
|
|
|
11
11
|
const ID_PATTERN = /^[\w.:-]{1,100}$/;
|
|
12
12
|
const MAX_ENTRY_LENGTH = 150;
|
|
13
13
|
const MAX_STARTED = 200;
|
|
14
|
-
function isFreePiSession(deps, sessionID) {
|
|
14
|
+
export function isFreePiSession(deps, sessionID) {
|
|
15
15
|
if (deps.state.freePiSessions.has(sessionID))
|
|
16
16
|
return true;
|
|
17
17
|
const tracked = deps.state.trackedModels.get(sessionID);
|
package/package.json
CHANGED
package/src/session/hooks.ts
CHANGED
|
@@ -43,6 +43,7 @@ import {
|
|
|
43
43
|
wireSessionID,
|
|
44
44
|
} from "./wire.js";
|
|
45
45
|
import {
|
|
46
|
+
isFreePiSession,
|
|
46
47
|
recordCompaction,
|
|
47
48
|
recordToolEnd,
|
|
48
49
|
recordToolStart,
|
|
@@ -355,10 +356,35 @@ async function registerToolHooks(
|
|
|
355
356
|
status: event.status,
|
|
356
357
|
...(event.status === "completed" ? { result: event.result } : {}),
|
|
357
358
|
});
|
|
359
|
+
replaceUnsupportedImages(deps, event);
|
|
358
360
|
}),
|
|
359
361
|
);
|
|
360
362
|
}
|
|
361
363
|
|
|
364
|
+
/**
|
|
365
|
+
* free-pi only accepts text, like the provider CLI. OpenCode already swaps
|
|
366
|
+
* media for this notice when it builds a request for a text-only model, but
|
|
367
|
+
* doing it when the tool settles keeps the base64 image out of the session
|
|
368
|
+
* (and out of compaction) instead of storing hundreds of KB per read.
|
|
369
|
+
*/
|
|
370
|
+
function replaceUnsupportedImages(deps: Deps, event: any): void {
|
|
371
|
+
if (event.status !== "completed") return;
|
|
372
|
+
if (!isFreePiSession(deps, event.sessionID)) return;
|
|
373
|
+
const content = event.result?.content;
|
|
374
|
+
if (!Array.isArray(content)) return;
|
|
375
|
+
const replaced = content.map((part: any) => {
|
|
376
|
+
if (part?.type !== "file" || typeof part.mime !== "string") return part;
|
|
377
|
+
if (!part.mime.toLowerCase().startsWith("image/")) return part;
|
|
378
|
+
const name = typeof part.name === "string" ? part.name : part.mime;
|
|
379
|
+
return {
|
|
380
|
+
type: "text",
|
|
381
|
+
text: `ERROR: Cannot read "${name}" (this model does not support image input). Inform the user.`,
|
|
382
|
+
};
|
|
383
|
+
});
|
|
384
|
+
if (replaced.every((part, index) => part === content[index])) return;
|
|
385
|
+
event.result = { ...event.result, content: replaced };
|
|
386
|
+
}
|
|
387
|
+
|
|
362
388
|
async function hookForProviders(
|
|
363
389
|
ctx: Plugin.Context,
|
|
364
390
|
name: SessionHookName,
|
package/src/session/tools.ts
CHANGED
|
@@ -35,7 +35,7 @@ type ToolEnd = {
|
|
|
35
35
|
result?: ToolResultLike;
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
-
function isFreePiSession(deps: Deps, sessionID: string): boolean {
|
|
38
|
+
export function isFreePiSession(deps: Deps, sessionID: string): boolean {
|
|
39
39
|
if (deps.state.freePiSessions.has(sessionID)) return true;
|
|
40
40
|
const tracked = deps.state.trackedModels.get(sessionID);
|
|
41
41
|
return (
|