open-agents-ai 0.103.55 → 0.103.56
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 +43 -21
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -12962,23 +12962,16 @@ async function handleCmd(cmd) {
|
|
|
12962
12962
|
},
|
|
12963
12963
|
});
|
|
12964
12964
|
|
|
12965
|
-
//
|
|
12966
|
-
|
|
12967
|
-
|
|
12968
|
-
|
|
12969
|
-
|
|
12970
|
-
|
|
12971
|
-
|
|
12972
|
-
|
|
12973
|
-
|
|
12974
|
-
|
|
12975
|
-
outputBytes: (output || '').length,
|
|
12976
|
-
tokens: inputTokens + outputTokens,
|
|
12977
|
-
inputTokens: inputTokens,
|
|
12978
|
-
outputTokens: outputTokens,
|
|
12979
|
-
durationMs: Date.now() - logEntry.ts,
|
|
12980
|
-
}) + '\\n');
|
|
12981
|
-
} catch (mErr) { dlog('metering write error: ' + (mErr.message || mErr)); }
|
|
12965
|
+
// Stash token data for the metering hook (which fires after handler returns
|
|
12966
|
+
// and has the correct peerId from connection context)
|
|
12967
|
+
_tokensByRequest[request.requestId] = {
|
|
12968
|
+
model: model.name,
|
|
12969
|
+
inputBytes: prompt.length,
|
|
12970
|
+
outputBytes: (output || '').length,
|
|
12971
|
+
tokens: inputTokens + outputTokens,
|
|
12972
|
+
inputTokens: inputTokens,
|
|
12973
|
+
outputTokens: outputTokens,
|
|
12974
|
+
};
|
|
12982
12975
|
} catch (e) {
|
|
12983
12976
|
dlog('expose: inference error: ' + (e.message || e));
|
|
12984
12977
|
await swrite({
|
|
@@ -13205,9 +13198,37 @@ process.on('unhandledRejection', (reason) => {
|
|
|
13205
13198
|
dlog('WARNING: could not patch node.dialProtocol \u2014 node=' + !!_patchNode);
|
|
13206
13199
|
}
|
|
13207
13200
|
|
|
13208
|
-
// v1.5.0: Metering
|
|
13209
|
-
//
|
|
13210
|
-
//
|
|
13201
|
+
// v1.5.0: Metering hook that enriches nexus records with token counts.
|
|
13202
|
+
// The nexus library fires this hook AFTER handler returns, so it has the correct
|
|
13203
|
+
// peerId from connection context. We stash token data per requestId so the hook
|
|
13204
|
+
// can merge them into one complete record written to metering.jsonl.
|
|
13205
|
+
var _tokensByRequest = {};
|
|
13206
|
+
try {
|
|
13207
|
+
if (nexus.metering && typeof nexus.metering.addHook === 'function') {
|
|
13208
|
+
nexus.metering.addHook(function(record) {
|
|
13209
|
+
// Only enrich inference capability records
|
|
13210
|
+
if (!record.capability || !record.capability.startsWith('inference:')) return;
|
|
13211
|
+
var tokenData = _tokensByRequest[record.id];
|
|
13212
|
+
delete _tokensByRequest[record.id]; // consume
|
|
13213
|
+
try {
|
|
13214
|
+
appendFileSync(meteringFile, JSON.stringify({
|
|
13215
|
+
timestamp: record.timestamp || Date.now(),
|
|
13216
|
+
peerId: record.peerId || 'unknown',
|
|
13217
|
+
service: record.service || record.capability,
|
|
13218
|
+
capability: record.capability,
|
|
13219
|
+
model: tokenData ? tokenData.model : (record.capability || '').replace('inference:', ''),
|
|
13220
|
+
direction: record.direction || 'inbound',
|
|
13221
|
+
inputBytes: tokenData ? tokenData.inputBytes : (record.inputBytes || 0),
|
|
13222
|
+
outputBytes: tokenData ? tokenData.outputBytes : (record.outputBytes || 0),
|
|
13223
|
+
tokens: tokenData ? tokenData.tokens : 0,
|
|
13224
|
+
inputTokens: tokenData ? tokenData.inputTokens : 0,
|
|
13225
|
+
outputTokens: tokenData ? tokenData.outputTokens : 0,
|
|
13226
|
+
durationMs: record.durationMs || 0,
|
|
13227
|
+
}) + '\\n');
|
|
13228
|
+
} catch {}
|
|
13229
|
+
});
|
|
13230
|
+
}
|
|
13231
|
+
} catch {}
|
|
13211
13232
|
|
|
13212
13233
|
// Write payment events to ledger.jsonl
|
|
13213
13234
|
try {
|
|
@@ -28895,7 +28916,8 @@ ${this.formatConnectionInfo()}`);
|
|
|
28895
28916
|
user.tokensIn += tokIn;
|
|
28896
28917
|
user.tokensOut += tokOut;
|
|
28897
28918
|
if (record.model || record.capability || record.service) {
|
|
28898
|
-
|
|
28919
|
+
let modelName = record.model || (record.capability || record.service || "").replace("inference:", "") || "unknown";
|
|
28920
|
+
modelName = modelName.replace(/^open-agents-/, "").replace(/_latest$/, "").replace(/_/g, ":");
|
|
28899
28921
|
this._stats.modelUsage.set(modelName, (this._stats.modelUsage.get(modelName) ?? 0) + 1);
|
|
28900
28922
|
let mm = user.models.get(modelName);
|
|
28901
28923
|
if (!mm) {
|
package/package.json
CHANGED