oasis_test 0.1.46 → 0.1.48
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 +153 -27
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -322,7 +322,7 @@ function fold(model, op) {
|
|
|
322
322
|
case "escalate": {
|
|
323
323
|
const p2 = op.payload;
|
|
324
324
|
const list = model.escalations.get(op.artifactId) ?? [];
|
|
325
|
-
list.push({ part: p2.part ?? null, reason: p2.reason, by: op.actor, at: op.timestamp, resolved: false });
|
|
325
|
+
list.push({ part: p2.part ?? null, reason: p2.reason, by: op.actor, ...op.hand !== void 0 ? { hand: op.hand } : {}, at: op.timestamp, resolved: false });
|
|
326
326
|
model.escalations.set(op.artifactId, list);
|
|
327
327
|
break;
|
|
328
328
|
}
|
|
@@ -565,7 +565,7 @@ function findGap(model, gapId) {
|
|
|
565
565
|
return null;
|
|
566
566
|
}
|
|
567
567
|
function unresolvedEscalationsOf(model, id) {
|
|
568
|
-
return (model.escalations.get(id) ?? []).filter((e) => !e.resolved).map((e) => ({ part: e.part, reason: e.reason, by: e.by, at: e.at }));
|
|
568
|
+
return (model.escalations.get(id) ?? []).filter((e) => !e.resolved).map((e) => ({ part: e.part, reason: e.reason, by: e.by, ...e.hand !== void 0 ? { hand: e.hand } : {}, at: e.at }));
|
|
569
569
|
}
|
|
570
570
|
function listPendingReviews(model, workspace) {
|
|
571
571
|
const all = [...model.pendingReviews.values()];
|
|
@@ -23082,7 +23082,8 @@ function resolveDiscussContext(model, input) {
|
|
|
23082
23082
|
if (!a) throw new Error(`\u8282\u70B9\u4E0D\u5B58\u5728\uFF1A${input.artifactId}`);
|
|
23083
23083
|
workspace = a.workspace;
|
|
23084
23084
|
const escs = unresolvedEscalationsOf(model, input.artifactId);
|
|
23085
|
-
|
|
23085
|
+
const lastEsc = escs.at(-1);
|
|
23086
|
+
initiator = lastEsc?.by.startsWith("actor:agent:") ? lastEsc.by : lastEsc?.hand;
|
|
23086
23087
|
seed = escs.length ? `\u53D1\u8D77\u4EBA\u5C31\u4F60\u4E0A\u62A5\u7684\u95EE\u9898\u6765\u627E\u4F60\u4E86\uFF1A${escs.at(-1).reason}\u3002\u8BF7\u8BCA\u65AD\u6839\u56E0\u3001\u7ED9 1\u20132 \u4E2A\u65B9\u6848\u3001\u95EE ta \u91C7\u7528\u54EA\u4E2A\u3002` : `\u53D1\u8D77\u4EBA\u60F3\u548C\u4F60\u8BA8\u8BBA\u300C${input.artifactId}\u300D\u5F53\u524D\u7684\u5361\u70B9\u3002\u8BF7\u8BFB\u56FE\u8BCA\u65AD\u3001\u7ED9\u65B9\u6848\u518D\u95EE ta\u3002`;
|
|
23087
23088
|
} else {
|
|
23088
23089
|
throw new Error("discuss \u9700\u8981 artifactId \u6216 draftId");
|
|
@@ -34362,7 +34363,7 @@ function priceForModel(model) {
|
|
|
34362
34363
|
function estimateRowCost(row) {
|
|
34363
34364
|
return estimateUsageCost(row.effectiveModel, row);
|
|
34364
34365
|
}
|
|
34365
|
-
function
|
|
34366
|
+
function estimateUsageCostBreakdown(model, usage) {
|
|
34366
34367
|
const price = priceForModel(model);
|
|
34367
34368
|
if (!price) return null;
|
|
34368
34369
|
const inputTokens = Math.max(usage.inputTokens ?? 0, 0);
|
|
@@ -34370,8 +34371,22 @@ function estimateUsageCost(model, usage) {
|
|
|
34370
34371
|
const cacheReadTokens = Math.max(usage.cacheReadTokens ?? 0, 0);
|
|
34371
34372
|
const cacheCreationTokens = Math.max(usage.cacheCreationTokens ?? 0, 0);
|
|
34372
34373
|
const cacheReadPrice = price.cachedInputPerMillion ?? price.inputPerMillion * 0.1;
|
|
34373
|
-
|
|
34374
|
-
|
|
34374
|
+
return {
|
|
34375
|
+
currency: price.currency,
|
|
34376
|
+
inputMicros: Math.round(inputTokens * price.inputPerMillion / 1e6 * 1e6),
|
|
34377
|
+
cacheMicros: Math.round(
|
|
34378
|
+
(cacheCreationTokens * price.inputPerMillion + cacheReadTokens * cacheReadPrice) / 1e6 * 1e6
|
|
34379
|
+
),
|
|
34380
|
+
outputMicros: Math.round(outputTokens * price.outputPerMillion / 1e6 * 1e6)
|
|
34381
|
+
};
|
|
34382
|
+
}
|
|
34383
|
+
function estimateUsageCost(model, usage) {
|
|
34384
|
+
const breakdown = estimateUsageCostBreakdown(model, usage);
|
|
34385
|
+
if (!breakdown) return null;
|
|
34386
|
+
return {
|
|
34387
|
+
currency: breakdown.currency,
|
|
34388
|
+
micros: breakdown.inputMicros + breakdown.cacheMicros + breakdown.outputMicros
|
|
34389
|
+
};
|
|
34375
34390
|
}
|
|
34376
34391
|
var FOREIGN_MODEL_MARKUP, usd, cny, MODEL_PRICES, PREFIX_PRICES;
|
|
34377
34392
|
var init_model_pricing = __esm({
|
|
@@ -34486,6 +34501,30 @@ var init_model_pricing = __esm({
|
|
|
34486
34501
|
});
|
|
34487
34502
|
|
|
34488
34503
|
// ../server/src/domains/actors/stats.ts
|
|
34504
|
+
function emptyCostBreakdown() {
|
|
34505
|
+
return {
|
|
34506
|
+
inputUsdMicros: 0,
|
|
34507
|
+
cacheUsdMicros: 0,
|
|
34508
|
+
outputUsdMicros: 0,
|
|
34509
|
+
inputCnyMicros: 0,
|
|
34510
|
+
cacheCnyMicros: 0,
|
|
34511
|
+
outputCnyMicros: 0
|
|
34512
|
+
};
|
|
34513
|
+
}
|
|
34514
|
+
function addEstimatedBreakdown(target, model, usage) {
|
|
34515
|
+
const estimated = estimateUsageCostBreakdown(model, usage);
|
|
34516
|
+
if (!estimated) return false;
|
|
34517
|
+
if (estimated.currency === "USD") {
|
|
34518
|
+
target.inputUsdMicros += estimated.inputMicros;
|
|
34519
|
+
target.cacheUsdMicros += estimated.cacheMicros;
|
|
34520
|
+
target.outputUsdMicros += estimated.outputMicros;
|
|
34521
|
+
} else {
|
|
34522
|
+
target.inputCnyMicros += estimated.inputMicros;
|
|
34523
|
+
target.cacheCnyMicros += estimated.cacheMicros;
|
|
34524
|
+
target.outputCnyMicros += estimated.outputMicros;
|
|
34525
|
+
}
|
|
34526
|
+
return true;
|
|
34527
|
+
}
|
|
34489
34528
|
async function actorStats(oplog, actorId, opts = {}) {
|
|
34490
34529
|
const myRevisions = /* @__PURE__ */ new Set();
|
|
34491
34530
|
const mergedTargets = /* @__PURE__ */ new Set();
|
|
@@ -34529,8 +34568,10 @@ async function actorStats(oplog, actorId, opts = {}) {
|
|
|
34529
34568
|
approveRateGiven: reviewsGiven === 0 ? null : approvalsGiven / reviewsGiven,
|
|
34530
34569
|
reworkReceived,
|
|
34531
34570
|
tokenWeek: weeklyUsage.tokenWeek,
|
|
34571
|
+
tokenWeekBreakdown: weeklyUsage.tokenWeekBreakdown,
|
|
34532
34572
|
costWeekUsdMicros: weeklyUsage.costWeekUsdMicros,
|
|
34533
34573
|
costWeekCnyMicros: weeklyUsage.costWeekCnyMicros,
|
|
34574
|
+
costWeekBreakdown: weeklyUsage.costWeekBreakdown,
|
|
34534
34575
|
usageWindow: { from, to },
|
|
34535
34576
|
unpricedModels: weeklyUsage.unpricedModels
|
|
34536
34577
|
};
|
|
@@ -34546,18 +34587,24 @@ async function listWeeklyRuns(trace, actorId, from, to) {
|
|
|
34546
34587
|
return out;
|
|
34547
34588
|
}
|
|
34548
34589
|
function summarizeWeeklyRuns(runs) {
|
|
34549
|
-
let
|
|
34590
|
+
let input = 0;
|
|
34591
|
+
let cache = 0;
|
|
34592
|
+
let output = 0;
|
|
34550
34593
|
let costWeekUsdMicros = 0;
|
|
34551
34594
|
let costWeekCnyMicros = 0;
|
|
34595
|
+
const costWeekBreakdown = emptyCostBreakdown();
|
|
34552
34596
|
const unpriced = /* @__PURE__ */ new Set();
|
|
34553
34597
|
for (const run of runs) {
|
|
34554
34598
|
const usage = run.usage;
|
|
34555
34599
|
if (!usage) continue;
|
|
34556
|
-
const
|
|
34557
|
-
const
|
|
34600
|
+
const inputTokens = Math.max(usage.inputTokens ?? 0, 0);
|
|
34601
|
+
const outputTokens = Math.max(usage.outputTokens ?? 0, 0);
|
|
34558
34602
|
const cacheCreation = Math.max(usage.cacheCreationTokens ?? 0, 0);
|
|
34559
34603
|
const cacheRead = Math.max(usage.cacheReadTokens ?? 0, 0);
|
|
34560
|
-
|
|
34604
|
+
input += inputTokens;
|
|
34605
|
+
cache += cacheCreation + cacheRead;
|
|
34606
|
+
output += outputTokens;
|
|
34607
|
+
const priced = addEstimatedBreakdown(costWeekBreakdown, run.effectiveModel ?? null, usage);
|
|
34561
34608
|
const storedCost = Math.max(usage.costUsdMicros ?? 0, 0);
|
|
34562
34609
|
if (storedCost > 0) {
|
|
34563
34610
|
costWeekUsdMicros += storedCost;
|
|
@@ -34569,28 +34616,36 @@ function summarizeWeeklyRuns(runs) {
|
|
|
34569
34616
|
else costWeekCnyMicros += estimated.micros;
|
|
34570
34617
|
continue;
|
|
34571
34618
|
}
|
|
34572
|
-
if (
|
|
34619
|
+
if (!priced && inputTokens + outputTokens + cacheCreation + cacheRead > 0) {
|
|
34573
34620
|
unpriced.add(run.effectiveModel ?? "unknown");
|
|
34574
34621
|
}
|
|
34575
34622
|
}
|
|
34576
34623
|
return {
|
|
34577
|
-
tokenWeek,
|
|
34624
|
+
tokenWeek: input + cache + output,
|
|
34625
|
+
tokenWeekBreakdown: { input, cache, output },
|
|
34578
34626
|
costWeekUsdMicros,
|
|
34579
34627
|
costWeekCnyMicros,
|
|
34628
|
+
costWeekBreakdown,
|
|
34580
34629
|
unpricedModels: [...unpriced].sort()
|
|
34581
34630
|
};
|
|
34582
34631
|
}
|
|
34583
34632
|
function summarizeWeeklyUsage(rows) {
|
|
34584
|
-
let
|
|
34633
|
+
let input = 0;
|
|
34634
|
+
let cache = 0;
|
|
34635
|
+
let output = 0;
|
|
34585
34636
|
let costWeekUsdMicros = 0;
|
|
34586
34637
|
let costWeekCnyMicros = 0;
|
|
34638
|
+
const costWeekBreakdown = emptyCostBreakdown();
|
|
34587
34639
|
const unpriced = /* @__PURE__ */ new Set();
|
|
34588
34640
|
for (const row of rows) {
|
|
34589
|
-
const
|
|
34590
|
-
const
|
|
34641
|
+
const inputTokens = Math.max(row.inputTokens, 0);
|
|
34642
|
+
const outputTokens = Math.max(row.outputTokens, 0);
|
|
34591
34643
|
const cacheCreation = Math.max(row.cacheCreationTokens, 0);
|
|
34592
34644
|
const cacheRead = Math.max(row.cacheReadTokens, 0);
|
|
34593
|
-
|
|
34645
|
+
input += inputTokens;
|
|
34646
|
+
cache += cacheCreation + cacheRead;
|
|
34647
|
+
output += outputTokens;
|
|
34648
|
+
const priced = addEstimatedBreakdown(costWeekBreakdown, row.effectiveModel, row);
|
|
34594
34649
|
const storedCost = Math.max(row.costUsdMicros, 0);
|
|
34595
34650
|
if (storedCost > 0) {
|
|
34596
34651
|
costWeekUsdMicros += storedCost;
|
|
@@ -34602,14 +34657,16 @@ function summarizeWeeklyUsage(rows) {
|
|
|
34602
34657
|
else costWeekCnyMicros += estimated.micros;
|
|
34603
34658
|
continue;
|
|
34604
34659
|
}
|
|
34605
|
-
if (
|
|
34660
|
+
if (!priced && inputTokens + outputTokens + cacheCreation + cacheRead > 0) {
|
|
34606
34661
|
unpriced.add(row.effectiveModel ?? "unknown");
|
|
34607
34662
|
}
|
|
34608
34663
|
}
|
|
34609
34664
|
return {
|
|
34610
|
-
tokenWeek,
|
|
34665
|
+
tokenWeek: input + cache + output,
|
|
34666
|
+
tokenWeekBreakdown: { input, cache, output },
|
|
34611
34667
|
costWeekUsdMicros,
|
|
34612
34668
|
costWeekCnyMicros,
|
|
34669
|
+
costWeekBreakdown,
|
|
34613
34670
|
unpricedModels: [...unpriced].sort()
|
|
34614
34671
|
};
|
|
34615
34672
|
}
|
|
@@ -37457,6 +37514,9 @@ var init_claude_code = __esm({
|
|
|
37457
37514
|
const telemetryCbs = [];
|
|
37458
37515
|
let eventSeq = 0;
|
|
37459
37516
|
let lastResult;
|
|
37517
|
+
const stderrTail = [];
|
|
37518
|
+
const STDERR_MAX_LINES = 40;
|
|
37519
|
+
const STDERR_MAX_BYTES = 4e3;
|
|
37460
37520
|
const usageAcc = newClaudeUsageAcc();
|
|
37461
37521
|
let sessionModel;
|
|
37462
37522
|
const outputCbs = [];
|
|
@@ -37496,7 +37556,19 @@ var init_claude_code = __esm({
|
|
|
37496
37556
|
for (const cb of outputCbs) cb(text);
|
|
37497
37557
|
});
|
|
37498
37558
|
}
|
|
37499
|
-
child.stderr
|
|
37559
|
+
const stderrRl = readline.createInterface({ input: child.stderr });
|
|
37560
|
+
stderrRl.on("line", (line) => {
|
|
37561
|
+
try {
|
|
37562
|
+
out.write(line + "\n");
|
|
37563
|
+
} catch {
|
|
37564
|
+
}
|
|
37565
|
+
stderrTail.push(line);
|
|
37566
|
+
while (stderrTail.length > STDERR_MAX_LINES) stderrTail.shift();
|
|
37567
|
+
let total = stderrTail.reduce((n, l) => n + l.length + 1, 0);
|
|
37568
|
+
while (total > STDERR_MAX_BYTES && stderrTail.length > 1) {
|
|
37569
|
+
total -= stderrTail.shift().length + 1;
|
|
37570
|
+
}
|
|
37571
|
+
});
|
|
37500
37572
|
const callbacks = [];
|
|
37501
37573
|
let exited;
|
|
37502
37574
|
let killedByUs = false;
|
|
@@ -37507,14 +37579,15 @@ var init_claude_code = __esm({
|
|
|
37507
37579
|
child.on("error", (err) => {
|
|
37508
37580
|
if (exited) return;
|
|
37509
37581
|
clearTimeout(timer);
|
|
37582
|
+
const spawnErr = err instanceof Error ? err.message : String(err);
|
|
37510
37583
|
try {
|
|
37511
37584
|
out.write(`
|
|
37512
|
-
[adapter] spawn \u5931\u8D25\uFF1A${
|
|
37585
|
+
[adapter] spawn \u5931\u8D25\uFF1A${spawnErr}
|
|
37513
37586
|
`);
|
|
37514
37587
|
out.end();
|
|
37515
37588
|
} catch {
|
|
37516
37589
|
}
|
|
37517
|
-
exited = { code: null, reason: "error", transcriptRef };
|
|
37590
|
+
exited = { code: null, reason: "error", transcriptRef, errorMessage: spawnErr };
|
|
37518
37591
|
for (const cb of callbacks.splice(0)) cb(exited);
|
|
37519
37592
|
});
|
|
37520
37593
|
child.on("exit", (code) => {
|
|
@@ -37539,7 +37612,24 @@ var init_claude_code = __esm({
|
|
|
37539
37612
|
}
|
|
37540
37613
|
}
|
|
37541
37614
|
const usage = buildClaudeUsage(usageAcc);
|
|
37542
|
-
|
|
37615
|
+
const isError = !killedByUs && (typeof code === "number" && code !== 0 || reason === "error" || reason === "output-limit" || reason === "rate-limit");
|
|
37616
|
+
const errorParts = [];
|
|
37617
|
+
if (lastResult?.is_error === true) {
|
|
37618
|
+
const subtype = typeof lastResult.subtype === "string" ? lastResult.subtype : "";
|
|
37619
|
+
const body = typeof lastResult.result === "string" ? lastResult.result : "";
|
|
37620
|
+
const composed = [subtype && `[${subtype}]`, body].filter(Boolean).join(" ").trim();
|
|
37621
|
+
if (composed) errorParts.push(composed);
|
|
37622
|
+
}
|
|
37623
|
+
if (stderrTail.length) errorParts.push(stderrTail.join("\n").trim());
|
|
37624
|
+
const errorMessage = isError ? errorParts.filter(Boolean).join("\n---\n").slice(-4e3).trim() || void 0 : void 0;
|
|
37625
|
+
exited = {
|
|
37626
|
+
code: killedByUs ? null : code,
|
|
37627
|
+
...reason ? { reason } : {},
|
|
37628
|
+
transcriptRef,
|
|
37629
|
+
...usage ? { usage } : {},
|
|
37630
|
+
...sessionModel ? { model: sessionModel } : {},
|
|
37631
|
+
...errorMessage ? { errorMessage } : {}
|
|
37632
|
+
};
|
|
37543
37633
|
for (const cb of callbacks.splice(0)) cb(exited);
|
|
37544
37634
|
});
|
|
37545
37635
|
return {
|
|
@@ -39906,7 +39996,18 @@ function runStreamJson(job, cfg) {
|
|
|
39906
39996
|
const { finish, exited } = makeFinish(id, cfg, transcriptRefPtr, transcriptOut, dir, exitCbs);
|
|
39907
39997
|
let killedByUs = false;
|
|
39908
39998
|
let seq = 0;
|
|
39909
|
-
|
|
39999
|
+
const stderrTail = [];
|
|
40000
|
+
const stderrRl = readline4.createInterface({ input: child.stderr });
|
|
40001
|
+
stderrRl.on("line", (line) => {
|
|
40002
|
+
try {
|
|
40003
|
+
transcriptOut.write(line + "\n");
|
|
40004
|
+
} catch {
|
|
40005
|
+
}
|
|
40006
|
+
stderrTail.push(line);
|
|
40007
|
+
while (stderrTail.length > 40) stderrTail.shift();
|
|
40008
|
+
let total = stderrTail.reduce((n, l) => n + l.length + 1, 0);
|
|
40009
|
+
while (total > 4e3 && stderrTail.length > 1) total -= stderrTail.shift().length + 1;
|
|
40010
|
+
});
|
|
39910
40011
|
const state = cfg.createState();
|
|
39911
40012
|
const rl = readline4.createInterface({ input: child.stdout });
|
|
39912
40013
|
rl.on("line", (line) => {
|
|
@@ -39927,7 +40028,14 @@ function runStreamJson(job, cfg) {
|
|
|
39927
40028
|
});
|
|
39928
40029
|
child.on("exit", (code) => {
|
|
39929
40030
|
clearTimeout(timer);
|
|
39930
|
-
|
|
40031
|
+
const isError = !killedByUs && typeof code === "number" && code !== 0;
|
|
40032
|
+
const errorMessage = isError ? stderrTail.join("\n").trim().slice(-4e3) || void 0 : void 0;
|
|
40033
|
+
finish({
|
|
40034
|
+
code: killedByUs ? null : code,
|
|
40035
|
+
reason: killedByUs ? "timeout" : code === 0 ? "clean" : "error",
|
|
40036
|
+
transcriptRef: transcriptRefPtr.value,
|
|
40037
|
+
...errorMessage ? { errorMessage } : {}
|
|
40038
|
+
});
|
|
39931
40039
|
});
|
|
39932
40040
|
const current = exited();
|
|
39933
40041
|
return Promise.resolve({
|
|
@@ -39967,7 +40075,18 @@ function runOneShotText(job, cfg) {
|
|
|
39967
40075
|
const text = chunk.toString("utf8");
|
|
39968
40076
|
for (const cb of outputCbs) cb(text);
|
|
39969
40077
|
});
|
|
39970
|
-
|
|
40078
|
+
const stderrTail = [];
|
|
40079
|
+
const stderrRl = readline4.createInterface({ input: child.stderr });
|
|
40080
|
+
stderrRl.on("line", (line) => {
|
|
40081
|
+
try {
|
|
40082
|
+
transcriptOut.write(line + "\n");
|
|
40083
|
+
} catch {
|
|
40084
|
+
}
|
|
40085
|
+
stderrTail.push(line);
|
|
40086
|
+
while (stderrTail.length > 40) stderrTail.shift();
|
|
40087
|
+
let total = stderrTail.reduce((n, l) => n + l.length + 1, 0);
|
|
40088
|
+
while (total > 4e3 && stderrTail.length > 1) total -= stderrTail.shift().length + 1;
|
|
40089
|
+
});
|
|
39971
40090
|
const timer = setTimeout(() => {
|
|
39972
40091
|
killedByUs = true;
|
|
39973
40092
|
child.kill("SIGKILL");
|
|
@@ -39978,7 +40097,14 @@ function runOneShotText(job, cfg) {
|
|
|
39978
40097
|
});
|
|
39979
40098
|
child.on("exit", (code) => {
|
|
39980
40099
|
clearTimeout(timer);
|
|
39981
|
-
|
|
40100
|
+
const isError = !killedByUs && typeof code === "number" && code !== 0;
|
|
40101
|
+
const errorMessage = isError ? stderrTail.join("\n").trim().slice(-4e3) || void 0 : void 0;
|
|
40102
|
+
finish({
|
|
40103
|
+
code: killedByUs ? null : code,
|
|
40104
|
+
reason: killedByUs ? "timeout" : code === 0 ? "clean" : "error",
|
|
40105
|
+
transcriptRef: transcriptRefPtr.value,
|
|
40106
|
+
...errorMessage ? { errorMessage } : {}
|
|
40107
|
+
});
|
|
39982
40108
|
});
|
|
39983
40109
|
const current = exited();
|
|
39984
40110
|
return Promise.resolve({
|
|
@@ -58645,7 +58771,7 @@ ${res.warning}`);
|
|
|
58645
58771
|
}
|
|
58646
58772
|
|
|
58647
58773
|
// src/index.ts
|
|
58648
|
-
var PKG_VERSION = true ? "0.1.
|
|
58774
|
+
var PKG_VERSION = true ? "0.1.48" : "dev";
|
|
58649
58775
|
var OASIS_DIR = path19.join(os11.homedir(), ".oasis");
|
|
58650
58776
|
var CONFIG_FILE = path19.join(OASIS_DIR, "node-config.json");
|
|
58651
58777
|
var PID_FILE = path19.join(OASIS_DIR, "node.pid");
|