troxy-cli 1.29.39 → 1.29.40
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.40",
|
|
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": {
|
|
@@ -119,7 +119,16 @@ function troxyCommand(args, paused) {
|
|
|
119
119
|
// ponytail: turn-weighted and ignores cache writes after a model switch, so it
|
|
120
120
|
// is an estimate; weight by r.usage tokens if the number must be exact.
|
|
121
121
|
const MODEL_COST = { haiku: 0.3, sonnet: 0.5, opus: 1.0 };
|
|
122
|
-
|
|
122
|
+
// Kept in $.state (per session) so a `troxy update` hot reload keeps the counts.
|
|
123
|
+
// cost: actual spend in "requested-model prompts".
|
|
124
|
+
const STATS = { plugin: 'troxy-guard', key: 'stats' };
|
|
125
|
+
|
|
126
|
+
async function addStats($, prompts, routed, cost) {
|
|
127
|
+
const { value: s = { prompts: 0, routed: 0, cost: 0 } } = await $.state.get(STATS);
|
|
128
|
+
const next = { prompts: s.prompts + prompts, routed: s.routed + routed, cost: s.cost + cost };
|
|
129
|
+
await $.state.set(STATS, next);
|
|
130
|
+
$.ui.status(usageLine(next));
|
|
131
|
+
}
|
|
123
132
|
|
|
124
133
|
function costRatio(fromModel, toModel) {
|
|
125
134
|
const f = MODEL_COST[tierOf(fromModel)], t = MODEL_COST[tierOf(toModel)];
|
|
@@ -162,9 +171,7 @@ async function scorePrompt($, e, next) {
|
|
|
162
171
|
);
|
|
163
172
|
const score = r.isAnswered ? parseScore(r.text) : null;
|
|
164
173
|
$.ui.log(`troxy scorer: ${r.isAnswered ? JSON.stringify(r.text) : r.reason} -> ${score}`, { to: 'debug' });
|
|
165
|
-
|
|
166
|
-
stats.cost += 1; // until routeStep says otherwise
|
|
167
|
-
$.ui.status(usageLine(stats));
|
|
174
|
+
await addStats($, 1, 0, 1); // full cost until routeStep says otherwise
|
|
168
175
|
if (score !== null) {
|
|
169
176
|
const u = await $.session.usage();
|
|
170
177
|
decision = { score, tokens: estimateTokens(u.context && u.context.tokens, e.text) };
|
|
@@ -179,9 +186,7 @@ async function* routeStep($, e, next) {
|
|
|
179
186
|
if (model !== e.model) {
|
|
180
187
|
if (!decision.counted) {
|
|
181
188
|
decision.counted = true;
|
|
182
|
-
|
|
183
|
-
stats.cost += costRatio(e.model, model) - 1;
|
|
184
|
-
$.ui.status(usageLine(stats));
|
|
189
|
+
await addStats($, 0, 1, costRatio(e.model, model) - 1);
|
|
185
190
|
}
|
|
186
191
|
const sid = await $.session.id();
|
|
187
192
|
const file = modRouteFile($.plugin.root, sid);
|
|
@@ -198,6 +203,9 @@ export function register(on) {
|
|
|
198
203
|
on('tool.call', { tool: 'Bash' }, guardBash).catch(failClosed);
|
|
199
204
|
on('session.start', async ($, e, next) => {
|
|
200
205
|
await $.command.register({ name: 'troxy', description: 'Pause or resume Troxy model routing', argumentHint: '[on|off|status]' });
|
|
206
|
+
// session.start fires again on a hot reload: put the bar back from the kept counts
|
|
207
|
+
const { value } = await $.state.get(STATS);
|
|
208
|
+
if (value && value.prompts && !(await $.store.get('paused'))) $.ui.status(usageLine(value));
|
|
201
209
|
return next(e);
|
|
202
210
|
});
|
|
203
211
|
on('command.run', { command: 'troxy' }, async ($, e) => {
|