openfleet 0.4.0 → 0.4.1
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/dist/index.js +2 -111
- package/dist/models.d.ts +3 -3
- package/dist/transcript/hooks.d.ts +0 -13
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -59,7 +59,7 @@ var models = {
|
|
|
59
59
|
bigPickle: "opencode/big-pickle"
|
|
60
60
|
}
|
|
61
61
|
};
|
|
62
|
-
var defaultModel = models.anthropic.sonnet;
|
|
62
|
+
var defaultModel = process.env.OPENFLEET_MODEL ?? models.anthropic.sonnet;
|
|
63
63
|
var bigModel = defaultModel;
|
|
64
64
|
var fallbackModel = models.freeModels.minimaxM25Free;
|
|
65
65
|
|
|
@@ -1144,83 +1144,6 @@ Use this tool:
|
|
|
1144
1144
|
import { existsSync as existsSync3, readFileSync } from "fs";
|
|
1145
1145
|
import path3 from "path";
|
|
1146
1146
|
|
|
1147
|
-
// src/lib/fallback.ts
|
|
1148
|
-
var CREDIT_BALANCE_PATTERNS = [
|
|
1149
|
-
"credit balance is too low",
|
|
1150
|
-
"insufficient credits",
|
|
1151
|
-
"please go to plans & billing",
|
|
1152
|
-
"purchase credits"
|
|
1153
|
-
];
|
|
1154
|
-
var fallbackInProgress = new Set;
|
|
1155
|
-
var fallbackSessions = new Set;
|
|
1156
|
-
var lastFallbackTime = new Map;
|
|
1157
|
-
var COOLDOWN_MS = 30000;
|
|
1158
|
-
function isCreditBalanceError(message) {
|
|
1159
|
-
const lower = message.toLowerCase();
|
|
1160
|
-
return CREDIT_BALANCE_PATTERNS.some((p) => lower.includes(p));
|
|
1161
|
-
}
|
|
1162
|
-
function isSessionInFallback(sessionID) {
|
|
1163
|
-
return fallbackSessions.has(sessionID);
|
|
1164
|
-
}
|
|
1165
|
-
function markSessionFallback(sessionID) {
|
|
1166
|
-
fallbackSessions.add(sessionID);
|
|
1167
|
-
}
|
|
1168
|
-
function getFallbackModelOverride() {
|
|
1169
|
-
const [providerID, modelID] = fallbackModel.split("/");
|
|
1170
|
-
return { providerID, modelID };
|
|
1171
|
-
}
|
|
1172
|
-
async function handleCreditBalanceFallback(client, sessionID) {
|
|
1173
|
-
if (fallbackInProgress.has(sessionID))
|
|
1174
|
-
return;
|
|
1175
|
-
const last = lastFallbackTime.get(sessionID);
|
|
1176
|
-
if (last && Date.now() - last < COOLDOWN_MS)
|
|
1177
|
-
return;
|
|
1178
|
-
fallbackInProgress.add(sessionID);
|
|
1179
|
-
fallbackSessions.add(sessionID);
|
|
1180
|
-
lastFallbackTime.set(sessionID, Date.now());
|
|
1181
|
-
try {
|
|
1182
|
-
await client.session.abort({ path: { id: sessionID } });
|
|
1183
|
-
const { data: messages } = await client.session.messages({
|
|
1184
|
-
path: { id: sessionID }
|
|
1185
|
-
});
|
|
1186
|
-
if (!messages || messages.length === 0) {
|
|
1187
|
-
throw new Error("No messages found after abort");
|
|
1188
|
-
}
|
|
1189
|
-
const lastUserMsg = [...messages].reverse().find((m) => m.info.role === "user");
|
|
1190
|
-
if (!lastUserMsg) {
|
|
1191
|
-
throw new Error("No user message found to revert to");
|
|
1192
|
-
}
|
|
1193
|
-
const textPart = lastUserMsg.parts.find((p) => p.type === "text");
|
|
1194
|
-
if (!textPart || textPart.type !== "text")
|
|
1195
|
-
return;
|
|
1196
|
-
const messageID = lastUserMsg.info.id;
|
|
1197
|
-
const text = textPart.text;
|
|
1198
|
-
await client.session.revert({
|
|
1199
|
-
path: { id: sessionID },
|
|
1200
|
-
body: { messageID }
|
|
1201
|
-
});
|
|
1202
|
-
const [providerID, modelID] = fallbackModel.split("/");
|
|
1203
|
-
await client.session.prompt({
|
|
1204
|
-
path: { id: sessionID },
|
|
1205
|
-
body: {
|
|
1206
|
-
model: { providerID, modelID },
|
|
1207
|
-
parts: [{ type: "text", text }]
|
|
1208
|
-
}
|
|
1209
|
-
});
|
|
1210
|
-
logger.info("Credit balance fallback triggered", { sessionID, fallbackModel });
|
|
1211
|
-
await client.tui.showToast({
|
|
1212
|
-
body: {
|
|
1213
|
-
message: "\u26A0\uFE0F Anthropic credit balance low \u2014 switched to Minimax M2.5 Free",
|
|
1214
|
-
variant: "warning"
|
|
1215
|
-
}
|
|
1216
|
-
});
|
|
1217
|
-
} catch (err) {
|
|
1218
|
-
logger.error("Credit balance fallback failed", { sessionID, err });
|
|
1219
|
-
} finally {
|
|
1220
|
-
fallbackInProgress.delete(sessionID);
|
|
1221
|
-
}
|
|
1222
|
-
}
|
|
1223
|
-
|
|
1224
1147
|
// src/transcript/writer.ts
|
|
1225
1148
|
import { existsSync as existsSync2 } from "fs";
|
|
1226
1149
|
import { appendFile, mkdir } from "fs/promises";
|
|
@@ -1425,11 +1348,6 @@ function createTranscriptHooks(ctx) {
|
|
|
1425
1348
|
const session = await getSessionInfo(ctx, input.sessionID);
|
|
1426
1349
|
await recordUserMessage(session, output.message, output.parts);
|
|
1427
1350
|
},
|
|
1428
|
-
"chat.model": async (input, output) => {
|
|
1429
|
-
if (isSessionInFallback(input.sessionID)) {
|
|
1430
|
-
output.model = getFallbackModelOverride();
|
|
1431
|
-
}
|
|
1432
|
-
},
|
|
1433
1351
|
"tool.execute.before": async (input, output) => {
|
|
1434
1352
|
const session = await getSessionInfo(ctx, input.sessionID);
|
|
1435
1353
|
await recordToolUse(session, input.tool, input.callID, output.args);
|
|
@@ -1460,34 +1378,7 @@ function createTranscriptHooks(ctx) {
|
|
|
1460
1378
|
});
|
|
1461
1379
|
}
|
|
1462
1380
|
},
|
|
1463
|
-
event: async ({ event }) => {
|
|
1464
|
-
if (event.type === "session.created") {
|
|
1465
|
-
const { info } = event.properties;
|
|
1466
|
-
if (info.parentID && isSessionInFallback(info.parentID)) {
|
|
1467
|
-
markSessionFallback(info.id);
|
|
1468
|
-
}
|
|
1469
|
-
}
|
|
1470
|
-
if (event.type === "session.status") {
|
|
1471
|
-
const { sessionID, status } = event.properties;
|
|
1472
|
-
if (status.type === "retry" && isCreditBalanceError(status.message)) {
|
|
1473
|
-
await handleCreditBalanceFallback(ctx.client, sessionID);
|
|
1474
|
-
}
|
|
1475
|
-
}
|
|
1476
|
-
if (event.type === "session.error") {
|
|
1477
|
-
const { sessionID, error } = event.properties;
|
|
1478
|
-
if (sessionID && error && "message" in error.data && isCreditBalanceError(String(error.data.message))) {
|
|
1479
|
-
await handleCreditBalanceFallback(ctx.client, sessionID);
|
|
1480
|
-
}
|
|
1481
|
-
}
|
|
1482
|
-
if (event.type === "message.updated") {
|
|
1483
|
-
const { info } = event.properties;
|
|
1484
|
-
if (info.role === "assistant" && info.error) {
|
|
1485
|
-
if ("message" in info.error.data && isCreditBalanceError(String(info.error.data.message))) {
|
|
1486
|
-
await handleCreditBalanceFallback(ctx.client, info.sessionID);
|
|
1487
|
-
}
|
|
1488
|
-
}
|
|
1489
|
-
}
|
|
1490
|
-
}
|
|
1381
|
+
event: async ({ event }) => {}
|
|
1491
1382
|
};
|
|
1492
1383
|
}
|
|
1493
1384
|
// src/utils/directory-init.ts
|
package/dist/models.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export declare const models: {
|
|
|
25
25
|
readonly bigPickle: "opencode/big-pickle";
|
|
26
26
|
};
|
|
27
27
|
};
|
|
28
|
-
export declare const defaultModel:
|
|
29
|
-
export declare const bigModel:
|
|
30
|
-
export declare const smallModel:
|
|
28
|
+
export declare const defaultModel: string;
|
|
29
|
+
export declare const bigModel: string;
|
|
30
|
+
export declare const smallModel: string;
|
|
31
31
|
export declare const fallbackModel: "opencode/minimax-m2.5-free";
|
|
@@ -8,19 +8,6 @@ export declare function createTranscriptHooks(ctx: PluginInput): {
|
|
|
8
8
|
message: unknown;
|
|
9
9
|
parts: unknown[];
|
|
10
10
|
}) => Promise<void>;
|
|
11
|
-
"chat.model": (input: {
|
|
12
|
-
sessionID: string;
|
|
13
|
-
agent: string;
|
|
14
|
-
model: {
|
|
15
|
-
providerID: string;
|
|
16
|
-
modelID: string;
|
|
17
|
-
};
|
|
18
|
-
}, output: {
|
|
19
|
-
model: {
|
|
20
|
-
providerID: string;
|
|
21
|
-
modelID: string;
|
|
22
|
-
};
|
|
23
|
-
}) => Promise<void>;
|
|
24
11
|
"tool.execute.before": (input: {
|
|
25
12
|
sessionID: string;
|
|
26
13
|
tool: string;
|