@eduardo191labs/opencode-free-pi 0.7.29 → 0.7.31
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 +21 -69
- package/dist/auth/credential.d.ts +0 -1
- package/dist/auth/credential.js +1 -11
- package/dist/auth/credentials.d.ts +0 -1
- package/dist/auth/credentials.js +0 -8
- package/dist/auth/jwt.d.ts +1 -2
- package/dist/auth/jwt.js +0 -26
- package/dist/catalog/live.js +2 -2
- package/dist/constants.d.ts +0 -3
- package/dist/constants.js +0 -3
- package/dist/deps.d.ts +1 -4
- package/dist/errors/handle.js +0 -1
- package/dist/errors/limit.d.ts +0 -2
- package/dist/errors/limit.js +0 -14
- package/dist/legacy.d.ts +17 -0
- package/dist/legacy.js +58 -0
- package/dist/plugin.js +10 -84
- package/dist/session/overflow.d.ts +0 -1
- package/dist/session/overflow.js +0 -3
- package/dist/session/tools.d.ts +1 -1
- package/dist/session/tools.js +0 -1
- package/dist/state.d.ts +1 -4
- package/dist/state.js +0 -2
- package/dist/tools/api.d.ts +1 -1
- package/dist/tools/api.js +1 -1
- package/dist/tools/web.js +1 -1
- package/dist/types.d.ts +0 -23
- package/dist/utils/numbers.d.ts +0 -1
- package/dist/utils/numbers.js +0 -6
- package/package.json +2 -2
- package/src/auth/credential.ts +1 -13
- package/src/auth/credentials.ts +0 -8
- package/src/auth/jwt.ts +1 -31
- package/src/catalog/live.ts +1 -2
- package/src/constants.ts +0 -4
- package/src/deps.ts +1 -8
- package/src/errors/handle.ts +0 -1
- package/src/errors/limit.ts +0 -18
- package/src/legacy.ts +62 -0
- package/src/plugin.ts +11 -97
- package/src/session/hooks.ts +0 -1
- package/src/session/overflow.ts +0 -4
- package/src/session/tools.ts +0 -1
- package/src/state.ts +0 -6
- package/src/tools/api.ts +0 -1
- package/src/tools/usage.ts +0 -1
- package/src/tools/web.ts +1 -1
- package/src/types.ts +0 -31
- package/src/utils/numbers.ts +0 -8
- package/dist/agents/definitions.d.ts +0 -56
- package/dist/agents/definitions.js +0 -317
- package/dist/tools/subagent.d.ts +0 -29
- package/dist/tools/subagent.js +0 -197
- package/src/agents/definitions.ts +0 -354
- package/src/tools/subagent.ts +0 -271
package/dist/types.d.ts
CHANGED
|
@@ -210,18 +210,6 @@ export type FreePiError = {
|
|
|
210
210
|
allowance_credits?: number;
|
|
211
211
|
};
|
|
212
212
|
export type TokenCheckState = "ok" | "invalid" | "unknown";
|
|
213
|
-
export type RequestUsage = {
|
|
214
|
-
at: number;
|
|
215
|
-
messageID: string;
|
|
216
|
-
providerID: string;
|
|
217
|
-
modelID: string;
|
|
218
|
-
cost: number;
|
|
219
|
-
input: number;
|
|
220
|
-
output: number;
|
|
221
|
-
reasoning: number;
|
|
222
|
-
cacheRead: number;
|
|
223
|
-
cacheWrite: number;
|
|
224
|
-
};
|
|
225
213
|
export type Credentials = {
|
|
226
214
|
token: string;
|
|
227
215
|
issuer?: string;
|
|
@@ -298,14 +286,3 @@ export type SessionMessageInfo = {
|
|
|
298
286
|
[key: string]: unknown;
|
|
299
287
|
};
|
|
300
288
|
export type ReadContext = (sessionID: string) => Promise<readonly SessionMessageInfo[]>;
|
|
301
|
-
/** Minimal view of an OpenCode V2 session header. */
|
|
302
|
-
export type SubagentSessionInfo = {
|
|
303
|
-
id: string;
|
|
304
|
-
parentID?: string;
|
|
305
|
-
title?: string;
|
|
306
|
-
agent?: string;
|
|
307
|
-
outcome?: string;
|
|
308
|
-
updated?: number;
|
|
309
|
-
};
|
|
310
|
-
export type ReadSessionInfo = (sessionID: string) => Promise<SubagentSessionInfo | undefined>;
|
|
311
|
-
export type ListSubagentSessions = (parentID: string) => Promise<readonly SubagentSessionInfo[]>;
|
package/dist/utils/numbers.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/** Numeric and human-readable formatting helpers. */
|
|
2
2
|
export declare function duplicateNumber(value: unknown): number | undefined;
|
|
3
3
|
export declare function positiveNumber(...values: Array<number | undefined>): number | undefined;
|
|
4
|
-
export declare function creditsToUsd(credits: number | undefined): number;
|
|
5
4
|
export declare function formatRefillTime(value: string | undefined): string;
|
|
6
5
|
export declare function formatWait(seconds: number | undefined): string | undefined;
|
package/dist/utils/numbers.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/** Numeric and human-readable formatting helpers. */
|
|
2
|
-
import { CREDITS_PER_USD } from "../constants.js";
|
|
3
2
|
export function duplicateNumber(value) {
|
|
4
3
|
return typeof value === "number" && Number.isFinite(value) && value > 0
|
|
5
4
|
? value
|
|
@@ -13,11 +12,6 @@ export function positiveNumber(...values) {
|
|
|
13
12
|
}
|
|
14
13
|
return undefined;
|
|
15
14
|
}
|
|
16
|
-
export function creditsToUsd(credits) {
|
|
17
|
-
return typeof credits === "number" && Number.isFinite(credits) && credits > 0
|
|
18
|
-
? credits / CREDITS_PER_USD
|
|
19
|
-
: 0;
|
|
20
|
-
}
|
|
21
15
|
export function formatRefillTime(value) {
|
|
22
16
|
if (!value)
|
|
23
17
|
return "unknown";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eduardo191labs/opencode-free-pi",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.31",
|
|
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": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.json",
|
|
26
26
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
27
|
-
"test": "npm run build && node test/catalog.mjs && node test/smoke.mjs && node test/registry.mjs && node test/models.mjs && node test/live.mjs && node test/hooks.mjs && node test/errors.mjs && node test/overflow.mjs && node test/vision.mjs && node test/
|
|
27
|
+
"test": "npm run build && node test/catalog.mjs && node test/smoke.mjs && node test/registry.mjs && node test/models.mjs && node test/live.mjs && node test/hooks.mjs && node test/errors.mjs && node test/overflow.mjs && node test/vision.mjs && node test/legacy.mjs && node test/wire.mjs && node test/network.mjs && node test/tools.mjs && node test/slots.mjs",
|
|
28
28
|
"prepublishOnly": "npm run build",
|
|
29
29
|
"postinstall": "node scripts/postinstall.mjs"
|
|
30
30
|
},
|
package/src/auth/credential.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/** Translates OpenCode V2 credentials into free-pi tokens. */
|
|
2
2
|
|
|
3
3
|
import type { Credential } from "@opencode/schema/credential";
|
|
4
|
-
import {
|
|
5
|
-
import { normalizeIssuer } from "../utils/urls.js";
|
|
4
|
+
import { tokenExpiry } from "./jwt.js";
|
|
6
5
|
|
|
7
6
|
export function tokenFromCredential(
|
|
8
7
|
credential: Credential.Value | undefined,
|
|
@@ -26,14 +25,3 @@ export function expiryFromCredential(
|
|
|
26
25
|
const token = tokenFromCredential(credential);
|
|
27
26
|
return token ? tokenExpiry(token) : undefined;
|
|
28
27
|
}
|
|
29
|
-
|
|
30
|
-
export function issuerFromCredential(
|
|
31
|
-
credential: Credential.Value | undefined,
|
|
32
|
-
): string | undefined {
|
|
33
|
-
if (!credential) return undefined;
|
|
34
|
-
if (credential.type === "oauth")
|
|
35
|
-
return decodeRefreshToken(credential.refresh)?.issuer;
|
|
36
|
-
if (credential.type === "key")
|
|
37
|
-
return normalizeIssuer(credential.metadata?.issuer);
|
|
38
|
-
return undefined;
|
|
39
|
-
}
|
package/src/auth/credentials.ts
CHANGED
|
@@ -12,14 +12,6 @@ export function credentialsPath(): string {
|
|
|
12
12
|
return join(homedir(), ".free-pi", "agent", "credentials.json");
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export function credentialsDisplayPath(): string {
|
|
16
|
-
const override = process.env.FREEPI_CREDENTIALS_PATH?.trim();
|
|
17
|
-
if (override) return override;
|
|
18
|
-
return process.platform === "win32"
|
|
19
|
-
? join("%USERPROFILE%", ".free-pi", "agent", "credentials.json")
|
|
20
|
-
: "~/.free-pi/agent/credentials.json";
|
|
21
|
-
}
|
|
22
|
-
|
|
23
15
|
export async function readCredentials(): Promise<Credentials | undefined> {
|
|
24
16
|
const envToken = process.env.FREEPI_JWT?.trim();
|
|
25
17
|
if (envToken) return { token: envToken, issuer: resolveBaseUrl() };
|
package/src/auth/jwt.ts
CHANGED
|
@@ -4,8 +4,7 @@ import {
|
|
|
4
4
|
AUTH_SKEW_MS,
|
|
5
5
|
REFRESH_PREFIX,
|
|
6
6
|
} from "../constants.js";
|
|
7
|
-
import type {
|
|
8
|
-
import { normalizeIssuer } from "../utils/urls.js";
|
|
7
|
+
import type { JwtClaims } from "../types.js";
|
|
9
8
|
|
|
10
9
|
export function parseJwtClaims(token: string): JwtClaims | undefined {
|
|
11
10
|
const payload = token.split(".")[1];
|
|
@@ -44,32 +43,3 @@ export function encodeRefreshToken(token: string, issuer?: string): string {
|
|
|
44
43
|
const payload = JSON.stringify(issuer ? { token, issuer } : { token });
|
|
45
44
|
return `${REFRESH_PREFIX}${Buffer.from(payload).toString("base64url")}`;
|
|
46
45
|
}
|
|
47
|
-
|
|
48
|
-
export function decodeRefreshToken(
|
|
49
|
-
value: string | undefined,
|
|
50
|
-
): Credentials | undefined {
|
|
51
|
-
if (!value) return undefined;
|
|
52
|
-
if (value.startsWith(REFRESH_PREFIX)) {
|
|
53
|
-
try {
|
|
54
|
-
const parsed = JSON.parse(
|
|
55
|
-
Buffer.from(value.slice(REFRESH_PREFIX.length), "base64url").toString(
|
|
56
|
-
"utf8",
|
|
57
|
-
),
|
|
58
|
-
) as { token?: unknown; issuer?: unknown };
|
|
59
|
-
if (typeof parsed.token === "string" && parsed.token.length > 0) {
|
|
60
|
-
const issuer = normalizeIssuer(parsed.issuer);
|
|
61
|
-
return issuer
|
|
62
|
-
? { token: parsed.token, issuer }
|
|
63
|
-
: { token: parsed.token };
|
|
64
|
-
}
|
|
65
|
-
} catch {}
|
|
66
|
-
}
|
|
67
|
-
try {
|
|
68
|
-
const parsed = JSON.parse(value) as { token?: unknown; issuer?: unknown };
|
|
69
|
-
if (typeof parsed.token === "string" && parsed.token.length > 0) {
|
|
70
|
-
const issuer = normalizeIssuer(parsed.issuer);
|
|
71
|
-
return issuer ? { token: parsed.token, issuer } : { token: parsed.token };
|
|
72
|
-
}
|
|
73
|
-
} catch {}
|
|
74
|
-
return { token: value };
|
|
75
|
-
}
|
package/src/catalog/live.ts
CHANGED
|
@@ -341,7 +341,6 @@ export function settleWindow(
|
|
|
341
341
|
* proven value instead of losing the whole run.
|
|
342
342
|
*/
|
|
343
343
|
async function commitWindow(
|
|
344
|
-
deps: Deps,
|
|
345
344
|
tokens: number,
|
|
346
345
|
modelID: string,
|
|
347
346
|
): Promise<number> {
|
|
@@ -432,7 +431,7 @@ export async function verifyGatewayWindow(
|
|
|
432
431
|
const settled = settleWindow(samples);
|
|
433
432
|
if (settled) {
|
|
434
433
|
// Never go below the window that already worked for this account.
|
|
435
|
-
verified = await commitWindow(
|
|
434
|
+
verified = await commitWindow(Math.max(settled, floor), modelID);
|
|
436
435
|
}
|
|
437
436
|
if (accepted >= MAX_WINDOW) break;
|
|
438
437
|
const next = Math.min(MAX_WINDOW, Math.floor(accepted * 1.2));
|
package/src/constants.ts
CHANGED
|
@@ -2,10 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
export const PROVIDER_ID = "free-pi";
|
|
4
4
|
export const DEFENSE_PROVIDER_ID = "free-pi-defense";
|
|
5
|
-
export const INTEGRATION_ID = PROVIDER_ID;
|
|
6
|
-
|
|
7
|
-
export const PROVIDER_NAME = "Free Pi";
|
|
8
|
-
export const DEFENSE_PROVIDER_NAME = "Free Pi Defense";
|
|
9
5
|
|
|
10
6
|
export const DEFAULT_BASE_URL = "https://api.freepi.ai";
|
|
11
7
|
export const DEFAULT_CLIENT_VERSION = "0.6.28";
|
package/src/deps.ts
CHANGED
|
@@ -4,20 +4,13 @@ import type { Credential } from "@opencode/schema/credential";
|
|
|
4
4
|
import type { Plugin } from "@opencode/plugin";
|
|
5
5
|
import type { Logger } from "./logging.js";
|
|
6
6
|
import type { RuntimeState } from "./state.js";
|
|
7
|
-
import type {
|
|
8
|
-
ListSubagentSessions,
|
|
9
|
-
ReadContext,
|
|
10
|
-
ReadSessionInfo,
|
|
11
|
-
} from "./types.js";
|
|
7
|
+
import type { ReadContext } from "./types.js";
|
|
12
8
|
|
|
13
9
|
export type Deps = {
|
|
14
10
|
readonly state: RuntimeState;
|
|
15
11
|
readonly log: Logger;
|
|
16
12
|
readonly activeCredential: () => Promise<Credential.Value | undefined>;
|
|
17
13
|
readonly readContext: ReadContext;
|
|
18
|
-
/** Session headers, used to prove a session is really this session's child. */
|
|
19
|
-
readonly readSession?: ReadSessionInfo;
|
|
20
|
-
readonly listSubagentSessions?: ListSubagentSessions;
|
|
21
14
|
/** Plugin-scoped durable storage, used to reconnect provider sessions. */
|
|
22
15
|
readonly storage?: Plugin.Context["storage"];
|
|
23
16
|
};
|
package/src/errors/handle.ts
CHANGED
package/src/errors/limit.ts
CHANGED
|
@@ -111,24 +111,6 @@ function contextOverflowCode(body: string): string | undefined {
|
|
|
111
111
|
return undefined;
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
/** The free-pi overflow code carried by a response, when it is one. */
|
|
115
|
-
export async function overflowCodeOf(
|
|
116
|
-
response: Response,
|
|
117
|
-
): Promise<string | undefined> {
|
|
118
|
-
if (
|
|
119
|
-
response.status !== 413 &&
|
|
120
|
-
response.status !== 429 &&
|
|
121
|
-
response.status !== 400
|
|
122
|
-
)
|
|
123
|
-
return undefined;
|
|
124
|
-
const body = await response
|
|
125
|
-
.clone()
|
|
126
|
-
.text()
|
|
127
|
-
.catch(() => "");
|
|
128
|
-
if (!body) return undefined;
|
|
129
|
-
return contextOverflowCode(body);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
114
|
/**
|
|
133
115
|
* Returns a replacement response when `response` is a free-pi context overflow.
|
|
134
116
|
* The replacement is a 400 with a message OpenCode recognizes as context
|
package/src/legacy.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One-time cleanup for files older plugin versions wrote into OpenCode's config
|
|
3
|
+
* directory.
|
|
4
|
+
*
|
|
5
|
+
* Agents, skills and their prompts belong to OpenCode. Earlier releases seeded
|
|
6
|
+
* a free-pi skill and four Markdown agents next to the user's own files, which
|
|
7
|
+
* kept those prompts active after the plugin stopped owning them. This removes
|
|
8
|
+
* only files that still carry the old management marker; anything the user
|
|
9
|
+
* edited or replaced is left untouched.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { readFile, rm, rmdir } from "node:fs/promises";
|
|
13
|
+
import { homedir } from "node:os";
|
|
14
|
+
import { join } from "node:path";
|
|
15
|
+
|
|
16
|
+
const MARKER =
|
|
17
|
+
"<!-- managed by @eduardo191labs/opencode-free-pi; delete this line to keep your own copy -->";
|
|
18
|
+
|
|
19
|
+
const LEGACY_FILES = [
|
|
20
|
+
["agents", "free-pi", "scout.md"],
|
|
21
|
+
["agents", "free-pi", "planner.md"],
|
|
22
|
+
["agents", "free-pi", "worker.md"],
|
|
23
|
+
["agents", "free-pi", "reviewer.md"],
|
|
24
|
+
["skills", "free-pi", "SKILL.md"],
|
|
25
|
+
] as const;
|
|
26
|
+
|
|
27
|
+
/** OpenCode's user-wide config directory. */
|
|
28
|
+
export function openCodeConfigDir(): string {
|
|
29
|
+
const explicit = process.env.OPENCODE_CONFIG_DIR?.trim();
|
|
30
|
+
if (explicit) return explicit;
|
|
31
|
+
const xdg = process.env.XDG_CONFIG_HOME?.trim();
|
|
32
|
+
if (xdg) return join(xdg, "opencode");
|
|
33
|
+
return join(homedir(), ".config", "opencode");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Deletes the plugin-managed agent and skill files from previous versions and
|
|
38
|
+
* returns their paths. User-owned files are never touched.
|
|
39
|
+
*/
|
|
40
|
+
export async function removeLegacyFreePiFiles(
|
|
41
|
+
configDir = openCodeConfigDir(),
|
|
42
|
+
): Promise<string[]> {
|
|
43
|
+
const removed: string[] = [];
|
|
44
|
+
for (const parts of LEGACY_FILES) {
|
|
45
|
+
const path = join(configDir, ...parts);
|
|
46
|
+
try {
|
|
47
|
+
const current = await readFile(path, "utf8");
|
|
48
|
+
if (!current.slice(0, 1024).includes(MARKER)) continue;
|
|
49
|
+
await rm(path, { force: true });
|
|
50
|
+
removed.push(path);
|
|
51
|
+
} catch {
|
|
52
|
+
// Missing or unreadable: nothing to clean up.
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (removed.length > 0) {
|
|
56
|
+
// Drop the now-empty plugin folders without touching user-owned entries.
|
|
57
|
+
for (const parts of [["agents", "free-pi"], ["skills", "free-pi"]]) {
|
|
58
|
+
await rmdir(join(configDir, ...parts)).catch(() => undefined);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return removed;
|
|
62
|
+
}
|
package/src/plugin.ts
CHANGED
|
@@ -1,16 +1,6 @@
|
|
|
1
1
|
/** OpenCode V2 plugin entry point for free-pi. */
|
|
2
2
|
|
|
3
3
|
import { Plugin } from "@opencode/plugin";
|
|
4
|
-
import {
|
|
5
|
-
FREE_PI_SKILL,
|
|
6
|
-
FREE_PI_SKILL_DESCRIPTION,
|
|
7
|
-
FREE_PI_SKILL_ID,
|
|
8
|
-
FREE_PI_SKILL_NAME,
|
|
9
|
-
freePiSkillPath,
|
|
10
|
-
installFreePiAgents,
|
|
11
|
-
installFreePiSkill,
|
|
12
|
-
openCodeConfigDir,
|
|
13
|
-
} from "./agents/definitions.js";
|
|
14
4
|
import { fetchQuota } from "./api/quota.js";
|
|
15
5
|
import { closeFreePiSession } from "./api/session.js";
|
|
16
6
|
import { readCredentialsToken } from "./auth/credentials.js";
|
|
@@ -38,6 +28,7 @@ import type { Deps } from "./deps.js";
|
|
|
38
28
|
import type { ModelMap } from "./types.js";
|
|
39
29
|
import { registerIntegration } from "./integration/setup.js";
|
|
40
30
|
import { createLogger } from "./logging.js";
|
|
31
|
+
import { removeLegacyFreePiFiles } from "./legacy.js";
|
|
41
32
|
import { applyDirectNetwork } from "./network/direct.js";
|
|
42
33
|
import { subscribeEvents } from "./session/events.js";
|
|
43
34
|
import { registerSessionHooks } from "./session/hooks.js";
|
|
@@ -45,7 +36,6 @@ import { cancelAllFinalizeTimers } from "./session/track.js";
|
|
|
45
36
|
import { createRuntimeState } from "./state.js";
|
|
46
37
|
import { registerGenerateImageTool } from "./tools/image-generate.js";
|
|
47
38
|
import { registerUsageTool } from "./tools/usage.js";
|
|
48
|
-
import { registerSubagentTool } from "./tools/subagent.js";
|
|
49
39
|
import { registerVisionTool } from "./tools/vision.js";
|
|
50
40
|
import { registerWebTools } from "./tools/web.js";
|
|
51
41
|
import { settle } from "./utils/async.js";
|
|
@@ -82,95 +72,24 @@ async function setup(ctx: Plugin.Context): Promise<() => Promise<void>> {
|
|
|
82
72
|
return [];
|
|
83
73
|
}
|
|
84
74
|
},
|
|
85
|
-
readSession: async (sessionID) => {
|
|
86
|
-
try {
|
|
87
|
-
const info = await ctx.session.get({ sessionID });
|
|
88
|
-
return {
|
|
89
|
-
id: info.id,
|
|
90
|
-
parentID: info.parentID,
|
|
91
|
-
title: info.title,
|
|
92
|
-
agent: info.agent,
|
|
93
|
-
outcome: info.outcome,
|
|
94
|
-
updated: info.time?.updated,
|
|
95
|
-
};
|
|
96
|
-
} catch {
|
|
97
|
-
return undefined;
|
|
98
|
-
}
|
|
99
|
-
},
|
|
100
|
-
listSubagentSessions: async (parentID) => {
|
|
101
|
-
try {
|
|
102
|
-
const result = await ctx.session.list({ parentID, limit: 50 });
|
|
103
|
-
return (result.data ?? []).map((info) => ({
|
|
104
|
-
id: info.id,
|
|
105
|
-
parentID: info.parentID,
|
|
106
|
-
title: info.title,
|
|
107
|
-
agent: info.agent,
|
|
108
|
-
outcome: info.outcome,
|
|
109
|
-
updated: info.time?.updated,
|
|
110
|
-
}));
|
|
111
|
-
} catch {
|
|
112
|
-
return [];
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
75
|
storage: ctx.storage,
|
|
116
76
|
};
|
|
117
77
|
|
|
118
|
-
//
|
|
119
|
-
//
|
|
120
|
-
// so the picker, the subagent tool, permissions and reloads stay native.
|
|
121
|
-
const nativeRegistrations: Array<{ dispose: () => Promise<void> }> = [];
|
|
78
|
+
// Agents, skills and their prompts are OpenCode's. Remove the files earlier
|
|
79
|
+
// releases seeded so their prompts stop applying; user-owned files stay.
|
|
122
80
|
try {
|
|
123
|
-
const
|
|
124
|
-
if (
|
|
125
|
-
await ctx.agent.reload();
|
|
81
|
+
const removed = await removeLegacyFreePiFiles();
|
|
82
|
+
if (removed.length > 0) {
|
|
126
83
|
log.info(
|
|
127
|
-
`
|
|
128
|
-
|
|
129
|
-
);
|
|
130
|
-
}
|
|
131
|
-
if (agents.skipped.length > 0) {
|
|
132
|
-
log.warn(
|
|
133
|
-
"Left user-owned free-pi agent files untouched",
|
|
134
|
-
agents.skipped,
|
|
84
|
+
`Removed ${removed.length} legacy free-pi agent/skill file(s); OpenCode now owns them`,
|
|
85
|
+
removed,
|
|
135
86
|
);
|
|
87
|
+
// Let OpenCode's own registry drop the files it loaded from disk.
|
|
88
|
+
await ctx.agent.reload().catch(() => undefined);
|
|
89
|
+
await ctx.skill.reload().catch(() => undefined);
|
|
136
90
|
}
|
|
137
91
|
} catch (error) {
|
|
138
|
-
log.warn("Could not
|
|
139
|
-
}
|
|
140
|
-
// OpenCode's own skill loader reads `skills/free-pi/SKILL.md`. Install the
|
|
141
|
-
// file first so the skill has a real path, supporting files and permissions
|
|
142
|
-
// like any other native skill; the transform below only fills the gap when
|
|
143
|
-
// the config directory is not writable.
|
|
144
|
-
try {
|
|
145
|
-
const skill = await installFreePiSkill();
|
|
146
|
-
if (skill.changed) {
|
|
147
|
-
await ctx.skill.reload();
|
|
148
|
-
log.info("Installed the native free-pi skill");
|
|
149
|
-
}
|
|
150
|
-
if (skill.skipped) {
|
|
151
|
-
log.warn(
|
|
152
|
-
"Left the user-owned free-pi skill file untouched",
|
|
153
|
-
freePiSkillPath(openCodeConfigDir()),
|
|
154
|
-
);
|
|
155
|
-
}
|
|
156
|
-
} catch (error) {
|
|
157
|
-
log.warn("Could not install the free-pi skill file", error);
|
|
158
|
-
}
|
|
159
|
-
try {
|
|
160
|
-
nativeRegistrations.push(
|
|
161
|
-
await ctx.skill.transform((editor) => {
|
|
162
|
-
if (editor.get(FREE_PI_SKILL_ID)) return;
|
|
163
|
-
editor.add({
|
|
164
|
-
id: FREE_PI_SKILL_ID,
|
|
165
|
-
name: FREE_PI_SKILL_NAME,
|
|
166
|
-
description: FREE_PI_SKILL_DESCRIPTION,
|
|
167
|
-
path: freePiSkillPath(openCodeConfigDir()),
|
|
168
|
-
content: FREE_PI_SKILL,
|
|
169
|
-
} as any);
|
|
170
|
-
}),
|
|
171
|
-
);
|
|
172
|
-
} catch (error) {
|
|
173
|
-
log.warn("Could not register the free-pi skill", error);
|
|
92
|
+
log.warn("Could not remove the legacy free-pi agent/skill files", error);
|
|
174
93
|
}
|
|
175
94
|
|
|
176
95
|
const [catalogResult, registryResult, quotaResult] = await Promise.all([
|
|
@@ -287,17 +206,12 @@ async function setup(ctx: Plugin.Context): Promise<() => Promise<void>> {
|
|
|
287
206
|
});
|
|
288
207
|
|
|
289
208
|
const registrations = await registerSessionHooks(ctx, deps);
|
|
290
|
-
registrations.push(...nativeRegistrations);
|
|
291
209
|
const tools: Array<{
|
|
292
210
|
name: string;
|
|
293
211
|
register: () => Promise<{ dispose: () => Promise<void> }>;
|
|
294
212
|
}> = [
|
|
295
213
|
{ name: "look_at_image", register: () => registerVisionTool(ctx, deps) },
|
|
296
214
|
{ name: "free_pi_usage", register: () => registerUsageTool(ctx, deps) },
|
|
297
|
-
{
|
|
298
|
-
name: "free_pi_subagent_read",
|
|
299
|
-
register: () => registerSubagentTool(ctx, deps),
|
|
300
|
-
},
|
|
301
215
|
{ name: "web", register: () => registerWebTools(ctx, deps) },
|
|
302
216
|
{ name: "generate_image", register: () => registerGenerateImageTool(ctx, deps) },
|
|
303
217
|
];
|
package/src/session/hooks.ts
CHANGED
|
@@ -20,7 +20,6 @@ import {
|
|
|
20
20
|
rewriteContextOverflowResponse,
|
|
21
21
|
rewriteLimitResponse,
|
|
22
22
|
} from "../errors/limit.js";
|
|
23
|
-
import { parseFreePiError } from "../errors/parse.js";
|
|
24
23
|
import { trimMap } from "../utils/async.js";
|
|
25
24
|
import { watchFreePiNotice } from "./notices.js";
|
|
26
25
|
import {
|
package/src/session/overflow.ts
CHANGED
|
@@ -129,10 +129,6 @@ export function noteSpuriousOverflow(deps: Deps, sessionID: string): number {
|
|
|
129
129
|
return count;
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
-
export function clearSpuriousOverflows(deps: Deps, sessionID: string): void {
|
|
133
|
-
deps.state.spuriousOverflows.delete(sessionID);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
132
|
/** Whether the session has had enough spurious rejections to stop compacting. */
|
|
137
133
|
export function overflowingSpuriously(deps: Deps, sessionID: string): boolean {
|
|
138
134
|
const entry = deps.state.spuriousOverflows.get(sessionID);
|
package/src/session/tools.ts
CHANGED
package/src/state.ts
CHANGED
|
@@ -4,7 +4,6 @@ import { DEFAULT_CLIENT_VERSION } from "./constants.js";
|
|
|
4
4
|
import type {
|
|
5
5
|
AdTurn,
|
|
6
6
|
Catalog,
|
|
7
|
-
FreePiError,
|
|
8
7
|
ModelRegistry,
|
|
9
8
|
QuotaSnapshot,
|
|
10
9
|
SessionResetOutcome,
|
|
@@ -26,15 +25,12 @@ export type RuntimeState = {
|
|
|
26
25
|
registryPromise?: Promise<ModelRegistry | undefined>;
|
|
27
26
|
lastCatalogNotice?: string;
|
|
28
27
|
lastQuotaNotice?: string;
|
|
29
|
-
catalogModels: Catalog;
|
|
30
28
|
/** `provider/model` ids whose upstream accepts image input. */
|
|
31
29
|
imageModels: Set<string>;
|
|
32
30
|
|
|
33
31
|
quotaCache?: QuotaSnapshot;
|
|
34
32
|
quotaPromise?: Promise<QuotaSnapshot>;
|
|
35
|
-
lastQuotaRefreshAt: number;
|
|
36
33
|
|
|
37
|
-
lastFreePiError?: FreePiError;
|
|
38
34
|
lastErrorLogKey?: string;
|
|
39
35
|
lastErrorLogAt: number;
|
|
40
36
|
lastInvalidToken?: string;
|
|
@@ -74,9 +70,7 @@ export function createRuntimeState(): RuntimeState {
|
|
|
74
70
|
cachedCatalogAt: 0,
|
|
75
71
|
cachedRegistryAt: 0,
|
|
76
72
|
registryAttemptAt: 0,
|
|
77
|
-
catalogModels: {},
|
|
78
73
|
imageModels: new Set(),
|
|
79
|
-
lastQuotaRefreshAt: 0,
|
|
80
74
|
lastErrorLogAt: 0,
|
|
81
75
|
tokenChecks: new Map(),
|
|
82
76
|
sessionClosePromises: new Map(),
|
package/src/tools/api.ts
CHANGED
|
@@ -169,7 +169,6 @@ export async function freePiRequest(
|
|
|
169
169
|
export function mappedText(
|
|
170
170
|
table: Record<string, string>,
|
|
171
171
|
result: Extract<ApiResult, { ok: false }>,
|
|
172
|
-
library?: string,
|
|
173
172
|
): string {
|
|
174
173
|
if (result.code === "no_token") return NO_TOKEN_TEXT;
|
|
175
174
|
const mapped = table[result.code];
|
package/src/tools/usage.ts
CHANGED
package/src/tools/web.ts
CHANGED
|
@@ -164,7 +164,7 @@ async function executeDocsLookup(
|
|
|
164
164
|
signal: context.signal,
|
|
165
165
|
label: "The documentation lookup",
|
|
166
166
|
});
|
|
167
|
-
if (!lookup.ok) return fail(mappedText(ERRORS, lookup
|
|
167
|
+
if (!lookup.ok) return fail(mappedText(ERRORS, lookup));
|
|
168
168
|
const data = lookup.data ?? {};
|
|
169
169
|
deps.log.info("docs_lookup answered", {
|
|
170
170
|
library,
|
package/src/types.ts
CHANGED
|
@@ -192,19 +192,6 @@ export type FreePiError = {
|
|
|
192
192
|
|
|
193
193
|
export type TokenCheckState = "ok" | "invalid" | "unknown";
|
|
194
194
|
|
|
195
|
-
export type RequestUsage = {
|
|
196
|
-
at: number;
|
|
197
|
-
messageID: string;
|
|
198
|
-
providerID: string;
|
|
199
|
-
modelID: string;
|
|
200
|
-
cost: number;
|
|
201
|
-
input: number;
|
|
202
|
-
output: number;
|
|
203
|
-
reasoning: number;
|
|
204
|
-
cacheRead: number;
|
|
205
|
-
cacheWrite: number;
|
|
206
|
-
};
|
|
207
|
-
|
|
208
195
|
export type Credentials = {
|
|
209
196
|
token: string;
|
|
210
197
|
issuer?: string;
|
|
@@ -285,21 +272,3 @@ export type SessionMessageInfo =
|
|
|
285
272
|
export type ReadContext = (
|
|
286
273
|
sessionID: string,
|
|
287
274
|
) => Promise<readonly SessionMessageInfo[]>;
|
|
288
|
-
|
|
289
|
-
/** Minimal view of an OpenCode V2 session header. */
|
|
290
|
-
export type SubagentSessionInfo = {
|
|
291
|
-
id: string;
|
|
292
|
-
parentID?: string;
|
|
293
|
-
title?: string;
|
|
294
|
-
agent?: string;
|
|
295
|
-
outcome?: string;
|
|
296
|
-
updated?: number;
|
|
297
|
-
};
|
|
298
|
-
|
|
299
|
-
export type ReadSessionInfo = (
|
|
300
|
-
sessionID: string,
|
|
301
|
-
) => Promise<SubagentSessionInfo | undefined>;
|
|
302
|
-
|
|
303
|
-
export type ListSubagentSessions = (
|
|
304
|
-
parentID: string,
|
|
305
|
-
) => Promise<readonly SubagentSessionInfo[]>;
|
package/src/utils/numbers.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
/** Numeric and human-readable formatting helpers. */
|
|
2
2
|
|
|
3
|
-
import { CREDITS_PER_USD } from "../constants.js";
|
|
4
|
-
|
|
5
3
|
export function duplicateNumber(value: unknown): number | undefined {
|
|
6
4
|
return typeof value === "number" && Number.isFinite(value) && value > 0
|
|
7
5
|
? value
|
|
@@ -19,12 +17,6 @@ export function positiveNumber(
|
|
|
19
17
|
return undefined;
|
|
20
18
|
}
|
|
21
19
|
|
|
22
|
-
export function creditsToUsd(credits: number | undefined): number {
|
|
23
|
-
return typeof credits === "number" && Number.isFinite(credits) && credits > 0
|
|
24
|
-
? credits / CREDITS_PER_USD
|
|
25
|
-
: 0;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
20
|
export function formatRefillTime(value: string | undefined): string {
|
|
29
21
|
if (!value) return "unknown";
|
|
30
22
|
const date = new Date(value);
|