troxy-cli 1.29.37 → 1.29.38
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "troxy-cli",
|
|
3
|
-
"version": "1.29.
|
|
3
|
+
"version": "1.29.38",
|
|
4
4
|
"description": "A secure control layer for AI agents: policies across payments, messages, logins, destructive actions, model usage, and secrets, all enforceable from the CLI",
|
|
5
5
|
"homepage": "https://troxy.io",
|
|
6
6
|
"bugs": {
|
|
@@ -113,28 +113,24 @@ function troxyCommand(args, paused) {
|
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
|
|
116
|
-
// Session
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
//
|
|
121
|
-
const MODEL_COST = {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
function calculateSavings(fromModel, toModel) {
|
|
128
|
-
const fromCost = MODEL_COST[fromModel] || 1.0;
|
|
129
|
-
const toCost = MODEL_COST[toModel] || 1.0;
|
|
130
|
-
if (toCost >= fromCost) return 0; // no savings if routing upward
|
|
131
|
-
return Math.round(((fromCost - toCost) / fromCost) * 100);
|
|
116
|
+
// Session usage tracking, one count per human prompt (not per step).
|
|
117
|
+
// Weights relative to Opus: list prices put Haiku at 0.25 and Sonnet at 0.5; a
|
|
118
|
+
// Pro-plan meter test (30 prompts each) put Haiku at ~0.33. Haiku sits between.
|
|
119
|
+
// ponytail: turn-weighted and ignores cache writes after a model switch, so it
|
|
120
|
+
// is an estimate; weight by r.usage tokens if the number must be exact.
|
|
121
|
+
const MODEL_COST = { haiku: 0.3, sonnet: 0.5, opus: 1.0 };
|
|
122
|
+
const stats = { prompts: 0, routed: 0, cost: 0 }; // cost: actual spend in "requested-model prompts"
|
|
123
|
+
|
|
124
|
+
function costRatio(fromModel, toModel) {
|
|
125
|
+
const f = MODEL_COST[tierOf(fromModel)], t = MODEL_COST[tierOf(toModel)];
|
|
126
|
+
return f && t ? t / f : 1;
|
|
132
127
|
}
|
|
133
128
|
|
|
134
|
-
//
|
|
135
|
-
function
|
|
136
|
-
const
|
|
137
|
-
|
|
129
|
+
// e.g. [████████░░░░░░░░░░░░] Troxy extended your usage by 87% · 2 of 3 prompts on a cheaper model
|
|
130
|
+
function usageLine({ prompts, routed, cost }) {
|
|
131
|
+
const extended = cost > 0 ? Math.round((prompts / cost - 1) * 100) : 0;
|
|
132
|
+
const filled = prompts ? Math.round((routed / prompts) * 20) : 0;
|
|
133
|
+
return `[${'█'.repeat(filled)}${'░'.repeat(20 - filled)}] Troxy extended your usage by ${extended}% · ${routed} of ${prompts} prompts on a cheaper model`;
|
|
138
134
|
}
|
|
139
135
|
|
|
140
136
|
// Where the local daemon looks for this session's routing note (see interceptor.js).
|
|
@@ -165,6 +161,10 @@ async function scorePrompt($, e, next) {
|
|
|
165
161
|
{ model: 'haiku', system: SCORER_SYSTEM, prompt: e.text.slice(0, SCORER_PROMPT_CHARS), maxTokens: 8, effort: 'low', timeoutMs: SCORE_TIMEOUT_MS },
|
|
166
162
|
);
|
|
167
163
|
const score = r.isAnswered ? parseScore(r.text) : null;
|
|
164
|
+
$.ui.log(`troxy scorer: ${r.isAnswered ? JSON.stringify(r.text) : r.reason} -> ${score}`, { to: 'debug' });
|
|
165
|
+
stats.prompts += 1;
|
|
166
|
+
stats.cost += 1; // until routeStep says otherwise
|
|
167
|
+
$.ui.status(usageLine(stats));
|
|
168
168
|
if (score !== null) {
|
|
169
169
|
const u = await $.session.usage();
|
|
170
170
|
decision = { score, tokens: estimateTokens(u.context && u.context.tokens, e.text) };
|
|
@@ -177,11 +177,11 @@ async function* routeStep($, e, next) {
|
|
|
177
177
|
if (!decision || e.agentId) return yield* next(e);
|
|
178
178
|
const model = pickModel(decision.score, e.model, decision.tokens);
|
|
179
179
|
if (model !== e.model) {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
$.ui.status(
|
|
180
|
+
if (!decision.counted) {
|
|
181
|
+
decision.counted = true;
|
|
182
|
+
stats.routed += 1;
|
|
183
|
+
stats.cost += costRatio(e.model, model) - 1;
|
|
184
|
+
$.ui.status(usageLine(stats));
|
|
185
185
|
}
|
|
186
186
|
const sid = await $.session.id();
|
|
187
187
|
const file = modRouteFile($.plugin.root, sid);
|
|
@@ -213,4 +213,4 @@ export function register(on) {
|
|
|
213
213
|
}
|
|
214
214
|
|
|
215
215
|
// Exported for tests only - not part of the mod's runtime contract.
|
|
216
|
-
export const _internal = { toDomainAndFields, guardBash, failClosed, parseScore, pickModel, troxyCommand, modRouteFile, estimateTokens, MODELS };
|
|
216
|
+
export const _internal = { toDomainAndFields, guardBash, failClosed, parseScore, pickModel, troxyCommand, modRouteFile, estimateTokens, MODELS, usageLine, costRatio };
|
|
@@ -62,3 +62,13 @@ test('real subprocess: a real Bash command still runs normally through the mod (
|
|
|
62
62
|
fs.rmSync(workdir, { recursive: true, force: true });
|
|
63
63
|
}
|
|
64
64
|
});
|
|
65
|
+
|
|
66
|
+
test('usageLine: counts every prompt, extension reflects routed share', () => {
|
|
67
|
+
const { usageLine, costRatio, MODELS } = _internal;
|
|
68
|
+
assert.equal(costRatio(MODELS.opus, MODELS.haiku), 0.3);
|
|
69
|
+
assert.equal(costRatio('some-new-model', MODELS.haiku), 1);
|
|
70
|
+
// 3 prompts, 2 routed opus->haiku: cost 1 + 0.3 + 0.3 = 1.6, 3/1.6 = +88%
|
|
71
|
+
assert.match(usageLine({ prompts: 3, routed: 2, cost: 1.6 }), /extended your usage by 88% · 2 of 3 prompts/);
|
|
72
|
+
assert.match(usageLine({ prompts: 3, routed: 0, cost: 3 }), /by 0% · 0 of 3/);
|
|
73
|
+
assert.match(usageLine({ prompts: 0, routed: 0, cost: 0 }), /by 0% · 0 of 0/);
|
|
74
|
+
});
|