negotium 0.2.15 → 0.2.17
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/agent-helpers.js +220 -32
- package/dist/agent-helpers.js.map +12 -12
- package/dist/background-bash.js.map +1 -1
- package/dist/browser-runtime.js.map +1 -1
- package/dist/{chunk-5g5a63vv.js → chunk-5cpdbbeh.js} +56 -6
- package/dist/{chunk-5g5a63vv.js.map → chunk-5cpdbbeh.js.map} +5 -5
- package/dist/hosted-agent.js +119 -9
- package/dist/hosted-agent.js.map +8 -8
- package/dist/main.js +931 -419
- package/dist/main.js.map +25 -24
- package/dist/mcp-factories.js +289 -42
- package/dist/mcp-factories.js.map +13 -13
- package/dist/prompts.js.map +1 -1
- package/dist/query-runtime.js.map +1 -1
- package/dist/registry.js +3 -3
- package/dist/registry.js.map +2 -2
- package/dist/rollout.js +1 -1
- package/dist/runtime/src/agents/codex-provider.ts +53 -2
- package/dist/runtime/src/agents/compaction-support.ts +1 -1
- package/dist/runtime/src/agents/maestro-provider.ts +3 -0
- package/dist/runtime/src/agents/rollout/codex.ts +62 -0
- package/dist/runtime/src/index.ts +1 -0
- package/dist/runtime/src/mcp/factories/token-stats.ts +33 -11
- package/dist/runtime/src/mcp/runtime-spec.ts +58 -1
- package/dist/runtime/src/node-host.ts +1 -0
- package/dist/runtime/src/runtime/turn-event-stream.ts +43 -2
- package/dist/runtime/src/runtime/turn-runner.ts +20 -9
- package/dist/runtime/src/storage/token-stats.ts +200 -19
- package/dist/runtime/src/types.ts +6 -0
- package/dist/runtime/src/version.ts +1 -1
- package/dist/runtime-helpers.js.map +1 -1
- package/dist/storage.js +112 -11
- package/dist/storage.js.map +4 -4
- package/dist/types/packages/core/src/agents/codex-provider.d.ts +13 -0
- package/dist/types/packages/core/src/agents/compaction-support.d.ts +1 -0
- package/dist/types/packages/core/src/agents/rollout/codex.d.ts +9 -0
- package/dist/types/packages/core/src/mcp/factories/token-stats.d.ts +4 -2
- package/dist/types/packages/core/src/runtime/turn-runner.d.ts +4 -0
- package/dist/types/packages/core/src/storage/token-stats.d.ts +35 -6
- package/dist/types/packages/core/src/types.d.ts +6 -0
- package/dist/types/packages/core/src/version.d.ts +1 -1
- package/dist/vault.js.map +1 -1
- package/package.json +2 -2
package/dist/storage.js
CHANGED
|
@@ -3361,6 +3361,7 @@ var exports_token_stats = {};
|
|
|
3361
3361
|
__export(exports_token_stats, {
|
|
3362
3362
|
tokenStatsFileId: () => tokenStatsFileId,
|
|
3363
3363
|
recordUsage: () => recordUsage,
|
|
3364
|
+
getTopicStats: () => getTopicStats,
|
|
3364
3365
|
getStats: () => getStats,
|
|
3365
3366
|
calcCost: () => calcCost
|
|
3366
3367
|
});
|
|
@@ -3373,7 +3374,8 @@ function emptyBucket() {
|
|
|
3373
3374
|
outputTokens: 0,
|
|
3374
3375
|
cacheCreationInputTokens: 0,
|
|
3375
3376
|
cacheReadInputTokens: 0,
|
|
3376
|
-
queries: 0
|
|
3377
|
+
queries: 0,
|
|
3378
|
+
estimatedCostUsd: 0
|
|
3377
3379
|
};
|
|
3378
3380
|
}
|
|
3379
3381
|
function tokenStatsFileId(userId) {
|
|
@@ -3400,16 +3402,53 @@ function loadRecords(userId) {
|
|
|
3400
3402
|
}
|
|
3401
3403
|
}
|
|
3402
3404
|
function calcCost(b) {
|
|
3403
|
-
return b.
|
|
3405
|
+
return b.estimatedCostUsd;
|
|
3406
|
+
}
|
|
3407
|
+
var TOKEN_PRICES = {
|
|
3408
|
+
"codex:gpt-5.6-sol": { input: 5, cacheRead: 0.5, output: 30 },
|
|
3409
|
+
"codex:gpt-5.6-terra": { input: 2.5, cacheRead: 0.25, output: 15 },
|
|
3410
|
+
"codex:gpt-5.6-luna": { input: 1, cacheRead: 0.1, output: 6 },
|
|
3411
|
+
"claude:fable": { input: 10, cacheWrite: 12.5, cacheRead: 1, output: 50 },
|
|
3412
|
+
"claude:opus": { input: 5, cacheWrite: 6.25, cacheRead: 0.5, output: 25 },
|
|
3413
|
+
"claude:sonnet": { input: 2, cacheWrite: 2.5, cacheRead: 0.2, output: 10 },
|
|
3414
|
+
"maestro:kimi-k3": { input: 3, cacheRead: 0.3, output: 15 },
|
|
3415
|
+
"maestro:kimi-k2.7-code": { input: 0.95, cacheRead: 0.19, output: 4 },
|
|
3416
|
+
"maestro:deepseek-pro": { input: 0.435, cacheRead: 0.003625, output: 0.87 },
|
|
3417
|
+
"maestro:deepseek-flash": { input: 0.14, cacheRead: 0.0028, output: 0.28 }
|
|
3418
|
+
};
|
|
3419
|
+
function estimateUsageCost(agent, model, usage) {
|
|
3420
|
+
const prices = TOKEN_PRICES[`${agent}:${model}`];
|
|
3421
|
+
if (!prices)
|
|
3422
|
+
return 0;
|
|
3423
|
+
return (usage.inputTokens * prices.input + usage.outputTokens * prices.output + (agent === "claude" ? usage.cacheCreationInputTokens * (prices.cacheWrite ?? prices.input) : 0) + usage.cacheReadInputTokens * prices.cacheRead) / 1e6;
|
|
3404
3424
|
}
|
|
3405
|
-
function
|
|
3425
|
+
function isQueryRecord(value) {
|
|
3426
|
+
if (!value || typeof value !== "object")
|
|
3427
|
+
return false;
|
|
3428
|
+
const record = value;
|
|
3429
|
+
return record.schemaVersion === 2 && typeof record.timestamp === "string" && typeof record.session === "string" && typeof record.topicId === "string" && typeof record.agent === "string" && typeof record.model === "string" && typeof record.inputTokens === "number" && typeof record.outputTokens === "number" && typeof record.cacheCreationInputTokens === "number" && typeof record.cacheReadInputTokens === "number" && typeof record.estimatedCostUsd === "number";
|
|
3430
|
+
}
|
|
3431
|
+
function recordUsage(userId, session, usage, context) {
|
|
3432
|
+
const cacheReadInputTokens = usage.cacheReadInputTokens ?? 0;
|
|
3433
|
+
const inputTokens = context.agent === "claude" ? usage.inputTokens : Math.max(0, usage.inputTokens - cacheReadInputTokens);
|
|
3434
|
+
const normalized = {
|
|
3435
|
+
inputTokens,
|
|
3436
|
+
outputTokens: usage.outputTokens,
|
|
3437
|
+
cacheCreationInputTokens: usage.cacheCreationInputTokens ?? 0,
|
|
3438
|
+
cacheReadInputTokens
|
|
3439
|
+
};
|
|
3406
3440
|
const record = {
|
|
3441
|
+
schemaVersion: 2,
|
|
3407
3442
|
timestamp: new Date().toISOString(),
|
|
3408
3443
|
session,
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
|
|
3444
|
+
topicId: context.topicId,
|
|
3445
|
+
...context.providerSessionId ? { providerSessionId: context.providerSessionId } : {},
|
|
3446
|
+
agent: context.agent,
|
|
3447
|
+
model: context.model,
|
|
3448
|
+
...normalized,
|
|
3449
|
+
...usage.contextTokens !== undefined ? { contextTokens: usage.contextTokens } : {},
|
|
3450
|
+
...usage.contextWindow !== undefined ? { contextWindow: usage.contextWindow } : {},
|
|
3451
|
+
estimatedCostUsd: usage.costUsd ?? estimateUsageCost(context.agent, context.model, normalized)
|
|
3413
3452
|
};
|
|
3414
3453
|
try {
|
|
3415
3454
|
appendJsonlEntry(queriesPath(userId), record);
|
|
@@ -3423,12 +3462,26 @@ function getStats(userId, from, to) {
|
|
|
3423
3462
|
const toTs = to ? new Date(to).getTime() : Infinity;
|
|
3424
3463
|
if (from && Number.isNaN(fromTs) || to && Number.isNaN(toTs)) {
|
|
3425
3464
|
logger.warn({ from, to }, "token-stats: Invalid date range, returning empty");
|
|
3426
|
-
return {
|
|
3465
|
+
return {
|
|
3466
|
+
total: emptyBucket(),
|
|
3467
|
+
byHour: {},
|
|
3468
|
+
bySession: {},
|
|
3469
|
+
currentSessions: [],
|
|
3470
|
+
ignoredLegacyRecords: 0,
|
|
3471
|
+
estimatedCostUsd: 0
|
|
3472
|
+
};
|
|
3427
3473
|
}
|
|
3428
3474
|
const total = emptyBucket();
|
|
3429
3475
|
const byHour = {};
|
|
3430
3476
|
const bySession = {};
|
|
3431
|
-
|
|
3477
|
+
const currentSessions = new Map;
|
|
3478
|
+
let ignoredLegacyRecords = 0;
|
|
3479
|
+
for (const raw of records) {
|
|
3480
|
+
if (!isQueryRecord(raw)) {
|
|
3481
|
+
ignoredLegacyRecords += 1;
|
|
3482
|
+
continue;
|
|
3483
|
+
}
|
|
3484
|
+
const r = raw;
|
|
3432
3485
|
const ts = new Date(r.timestamp).getTime();
|
|
3433
3486
|
if (ts < fromTs || ts > toTs)
|
|
3434
3487
|
continue;
|
|
@@ -3443,9 +3496,56 @@ function getStats(userId, from, to) {
|
|
|
3443
3496
|
bucket.cacheCreationInputTokens += r.cacheCreationInputTokens;
|
|
3444
3497
|
bucket.cacheReadInputTokens += r.cacheReadInputTokens;
|
|
3445
3498
|
bucket.queries += 1;
|
|
3499
|
+
bucket.estimatedCostUsd += r.estimatedCostUsd;
|
|
3500
|
+
}
|
|
3501
|
+
if (r.contextTokens !== undefined && r.contextWindow !== undefined && r.contextWindow > 0) {
|
|
3502
|
+
currentSessions.set(r.topicId, {
|
|
3503
|
+
timestamp: r.timestamp,
|
|
3504
|
+
topicId: r.topicId,
|
|
3505
|
+
topicTitle: r.session,
|
|
3506
|
+
...r.providerSessionId ? { providerSessionId: r.providerSessionId } : {},
|
|
3507
|
+
agent: r.agent,
|
|
3508
|
+
model: r.model,
|
|
3509
|
+
contextTokens: r.contextTokens,
|
|
3510
|
+
contextWindow: r.contextWindow
|
|
3511
|
+
});
|
|
3512
|
+
}
|
|
3513
|
+
}
|
|
3514
|
+
return {
|
|
3515
|
+
total,
|
|
3516
|
+
byHour,
|
|
3517
|
+
bySession,
|
|
3518
|
+
currentSessions: [...currentSessions.values()].sort((a, b) => b.timestamp.localeCompare(a.timestamp)),
|
|
3519
|
+
ignoredLegacyRecords,
|
|
3520
|
+
estimatedCostUsd: calcCost(total)
|
|
3521
|
+
};
|
|
3522
|
+
}
|
|
3523
|
+
function getTopicStats(userId, topicId) {
|
|
3524
|
+
const total = emptyBucket();
|
|
3525
|
+
let currentSession;
|
|
3526
|
+
for (const raw of loadRecords(userId)) {
|
|
3527
|
+
if (!isQueryRecord(raw) || raw.topicId !== topicId)
|
|
3528
|
+
continue;
|
|
3529
|
+
total.inputTokens += raw.inputTokens;
|
|
3530
|
+
total.outputTokens += raw.outputTokens;
|
|
3531
|
+
total.cacheCreationInputTokens += raw.cacheCreationInputTokens;
|
|
3532
|
+
total.cacheReadInputTokens += raw.cacheReadInputTokens;
|
|
3533
|
+
total.queries += 1;
|
|
3534
|
+
total.estimatedCostUsd += raw.estimatedCostUsd;
|
|
3535
|
+
if (raw.contextTokens !== undefined && raw.contextWindow !== undefined && raw.contextWindow > 0 && (!currentSession || raw.timestamp > currentSession.timestamp)) {
|
|
3536
|
+
currentSession = {
|
|
3537
|
+
timestamp: raw.timestamp,
|
|
3538
|
+
topicId: raw.topicId,
|
|
3539
|
+
topicTitle: raw.session,
|
|
3540
|
+
...raw.providerSessionId ? { providerSessionId: raw.providerSessionId } : {},
|
|
3541
|
+
agent: raw.agent,
|
|
3542
|
+
model: raw.model,
|
|
3543
|
+
contextTokens: raw.contextTokens,
|
|
3544
|
+
contextWindow: raw.contextWindow
|
|
3545
|
+
};
|
|
3446
3546
|
}
|
|
3447
3547
|
}
|
|
3448
|
-
return {
|
|
3548
|
+
return { topicId, ...total, ...currentSession ? { currentSession } : {} };
|
|
3449
3549
|
}
|
|
3450
3550
|
// ../../packages/core/src/storage/topic-archive.ts
|
|
3451
3551
|
var exports_topic_archive = {};
|
|
@@ -3971,6 +4071,7 @@ export {
|
|
|
3971
4071
|
grantSubagentTellTarget,
|
|
3972
4072
|
getWikiDir,
|
|
3973
4073
|
getUserConfig,
|
|
4074
|
+
getTopicStats,
|
|
3974
4075
|
getTopicSessionId,
|
|
3975
4076
|
getTopicNames,
|
|
3976
4077
|
getTopicMemoryOrigin,
|
|
@@ -4065,4 +4166,4 @@ export {
|
|
|
4065
4166
|
ConversationLogDivergedError
|
|
4066
4167
|
};
|
|
4067
4168
|
|
|
4068
|
-
//# debugId=
|
|
4169
|
+
//# debugId=0E9898BA8C097A7864756E2164756E21
|