tines 0.0.179 → 0.0.182
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 -25
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3529,10 +3529,21 @@ function runDurationLabel(run, now = Date.now()) {
|
|
|
3529
3529
|
function runCostLabel(run) {
|
|
3530
3530
|
const usage = run.usage;
|
|
3531
3531
|
if (!usage) return null;
|
|
3532
|
-
if (usage.cost_usd !== void 0)
|
|
3533
|
-
|
|
3532
|
+
if (usage.cost_usd !== void 0) {
|
|
3533
|
+
const dollars = usage.cost_usd === 0 ? "$0" : usage.cost_usd < 0.01 ? "<$0.01" : `$${usage.cost_usd.toFixed(2)}`;
|
|
3534
|
+
const source = usage.cost_source === "provider" ? "Reported" : usage.cost_source === "priced" ? "Estimated" : "Recorded";
|
|
3535
|
+
return `${dollars} ${source}`;
|
|
3536
|
+
}
|
|
3537
|
+
if (usage.pricing?.status === "unpriced") return "Unpriced";
|
|
3538
|
+
if (usage.cost_source === "none") return "Unreported";
|
|
3539
|
+
const measured = [
|
|
3540
|
+
usage.input_tokens,
|
|
3541
|
+
usage.output_tokens,
|
|
3542
|
+
usage.cache_read_tokens,
|
|
3543
|
+
usage.cache_write_tokens
|
|
3544
|
+
].some((value) => value !== void 0);
|
|
3534
3545
|
const tokens = (usage.input_tokens ?? 0) + (usage.output_tokens ?? 0) + (usage.cache_read_tokens ?? 0) + (usage.cache_write_tokens ?? 0);
|
|
3535
|
-
return tokens > 0 ? `${tokens.toLocaleString()} tok` : null;
|
|
3546
|
+
return tokens > 0 ? `${tokens.toLocaleString()} tok` : measured ? "Unpriced" : null;
|
|
3536
3547
|
}
|
|
3537
3548
|
function utilizationLabel(quota, activeRuns, stateName = (id2) => id2) {
|
|
3538
3549
|
if (quota.type === "global_cap") {
|
|
@@ -4177,6 +4188,14 @@ function createApiClient(options) {
|
|
|
4177
4188
|
"/api/v1/library/prepare",
|
|
4178
4189
|
body
|
|
4179
4190
|
),
|
|
4191
|
+
installWorkflowPackage: (body) => request(
|
|
4192
|
+
"POST",
|
|
4193
|
+
"/api/v1/library/install",
|
|
4194
|
+
body
|
|
4195
|
+
),
|
|
4196
|
+
getWorkflowPackageReceipt: (planId) => get(
|
|
4197
|
+
`/api/v1/library/installs/${encodeURIComponent(planId)}`
|
|
4198
|
+
),
|
|
4180
4199
|
validateLibrary: (body) => request(
|
|
4181
4200
|
"POST",
|
|
4182
4201
|
"/api/v1/library/validate",
|
|
@@ -7591,7 +7610,16 @@ function validProviderSessionId(value) {
|
|
|
7591
7610
|
return typeof value === "string" && value.length >= 1 && value.length <= 255 && Boolean(value.trim()) && !/[\x00-\x1f\x7f]/.test(value);
|
|
7592
7611
|
}
|
|
7593
7612
|
function copySummary(value) {
|
|
7594
|
-
return {
|
|
7613
|
+
return {
|
|
7614
|
+
...value,
|
|
7615
|
+
...value.usage ? { usage: { ...value.usage } } : {},
|
|
7616
|
+
...value.pricingEvidence ? {
|
|
7617
|
+
pricingEvidence: {
|
|
7618
|
+
...value.pricingEvidence,
|
|
7619
|
+
...value.pricingEvidence.raw_usage ? { raw_usage: { ...value.pricingEvidence.raw_usage } } : {}
|
|
7620
|
+
}
|
|
7621
|
+
} : {}
|
|
7622
|
+
};
|
|
7595
7623
|
}
|
|
7596
7624
|
|
|
7597
7625
|
// src/daemon/claude-stream.ts
|
|
@@ -7792,8 +7820,24 @@ var CodexStreamRenderer = class {
|
|
|
7792
7820
|
}
|
|
7793
7821
|
emit;
|
|
7794
7822
|
pending = "";
|
|
7795
|
-
collected = {
|
|
7823
|
+
collected = {
|
|
7824
|
+
pricingEvidence: {
|
|
7825
|
+
version: 1,
|
|
7826
|
+
harness: "codex",
|
|
7827
|
+
model: null,
|
|
7828
|
+
identity_source: "launch_argument",
|
|
7829
|
+
usage_scope: "thread_total",
|
|
7830
|
+
session_mode: "cold",
|
|
7831
|
+
normalization: "codex-jsonl-v1",
|
|
7832
|
+
model_rerouted: false,
|
|
7833
|
+
measurement_status: "missing",
|
|
7834
|
+
terminal_snapshots: 0
|
|
7835
|
+
}
|
|
7836
|
+
};
|
|
7796
7837
|
finished = false;
|
|
7838
|
+
threadId;
|
|
7839
|
+
stickyStatus;
|
|
7840
|
+
awaitingTerminal = false;
|
|
7797
7841
|
write(chunk) {
|
|
7798
7842
|
this.pending += chunk;
|
|
7799
7843
|
let nl = this.pending.indexOf("\n");
|
|
@@ -7831,24 +7875,75 @@ var CodexStreamRenderer = class {
|
|
|
7831
7875
|
`);
|
|
7832
7876
|
}
|
|
7833
7877
|
collect(event) {
|
|
7834
|
-
if (event.type === "thread.started" &&
|
|
7835
|
-
this.
|
|
7878
|
+
if (event.type === "thread.started" && validProviderSessionId(event.thread_id)) {
|
|
7879
|
+
if (this.threadId && this.threadId !== event.thread_id)
|
|
7880
|
+
this.stickyStatus = "multiple_threads";
|
|
7881
|
+
this.threadId ??= event.thread_id;
|
|
7882
|
+
this.collected.providerSessionId ??= event.thread_id;
|
|
7883
|
+
}
|
|
7884
|
+
if (event.type === "turn.started") {
|
|
7885
|
+
this.awaitingTerminal = true;
|
|
7886
|
+
this.updateEvidence("incomplete_attempt");
|
|
7887
|
+
return;
|
|
7888
|
+
}
|
|
7889
|
+
if (event.type === "item.completed") {
|
|
7890
|
+
const item = object2(event.item);
|
|
7891
|
+
if (item?.type === "error" && /^model rerouted:/.test(text3(item.message) ?? "")) {
|
|
7892
|
+
this.updateEvidence(void 0, true);
|
|
7893
|
+
}
|
|
7894
|
+
return;
|
|
7836
7895
|
}
|
|
7837
7896
|
if (event.type !== "turn.completed") return;
|
|
7897
|
+
this.awaitingTerminal = false;
|
|
7838
7898
|
const raw = object2(event.usage);
|
|
7839
|
-
|
|
7840
|
-
const
|
|
7841
|
-
const
|
|
7842
|
-
const
|
|
7843
|
-
|
|
7899
|
+
const previous = this.collected.pricingEvidence?.raw_usage;
|
|
7900
|
+
const metric = (value) => Number.isSafeInteger(value) && value >= 0 ? value : void 0;
|
|
7901
|
+
const totalInput = metric(raw?.input_tokens);
|
|
7902
|
+
const rawCached = metric(raw?.cached_input_tokens);
|
|
7903
|
+
const rawWrite = metric(raw?.cache_write_input_tokens);
|
|
7904
|
+
const output = metric(raw?.output_tokens);
|
|
7905
|
+
const rawUsage = {
|
|
7906
|
+
...totalInput !== void 0 ? { input_tokens: totalInput } : {},
|
|
7907
|
+
...rawCached !== void 0 ? { cached_input_tokens: rawCached } : {},
|
|
7908
|
+
...rawWrite !== void 0 ? { cache_write_input_tokens: rawWrite } : {},
|
|
7909
|
+
...output !== void 0 ? { output_tokens: output } : {}
|
|
7910
|
+
};
|
|
7911
|
+
const supplied = raw ? ["input_tokens", "cached_input_tokens", "cache_write_input_tokens", "output_tokens"].filter(
|
|
7912
|
+
(key) => raw[key] !== void 0
|
|
7913
|
+
).length : 0;
|
|
7914
|
+
const complete = supplied === 4 && Object.keys(rawUsage).length === 4 && rawCached + rawWrite <= totalInput;
|
|
7915
|
+
const previousInput = previous ? metric(previous.input_tokens) !== void 0 && metric(previous.cached_input_tokens) !== void 0 && metric(previous.cache_write_input_tokens) !== void 0 ? previous.input_tokens - previous.cached_input_tokens - previous.cache_write_input_tokens : void 0 : void 0;
|
|
7916
|
+
const input = complete ? totalInput - rawCached - rawWrite : void 0;
|
|
7917
|
+
let status = complete ? "complete" : supplied < 4 ? "missing" : "invalid";
|
|
7918
|
+
if (complete && previous && ["input_tokens", "cached_input_tokens", "cache_write_input_tokens", "output_tokens"].some(
|
|
7919
|
+
(key) => rawUsage[key] < previous[key]
|
|
7920
|
+
) || input !== void 0 && previousInput !== void 0 && input < previousInput) {
|
|
7921
|
+
this.stickyStatus = "nonmonotonic";
|
|
7922
|
+
}
|
|
7923
|
+
status = this.stickyStatus ?? status;
|
|
7844
7924
|
const usage = {};
|
|
7845
|
-
if (
|
|
7846
|
-
|
|
7847
|
-
|
|
7848
|
-
if (cached !== void 0) usage.cache_read_tokens = cached;
|
|
7849
|
-
} else if (rawCached !== void 0) usage.cache_read_tokens = rawCached;
|
|
7925
|
+
if (complete) usage.input_tokens = input;
|
|
7926
|
+
if (rawCached !== void 0) usage.cache_read_tokens = rawCached;
|
|
7927
|
+
if (rawWrite !== void 0) usage.cache_write_tokens = rawWrite;
|
|
7850
7928
|
if (output !== void 0) usage.output_tokens = output;
|
|
7851
7929
|
this.collected.usage = usage;
|
|
7930
|
+
this.updateEvidence(status, void 0, rawUsage);
|
|
7931
|
+
}
|
|
7932
|
+
updateEvidence(status, rerouted, rawUsage) {
|
|
7933
|
+
const old = this.collected.pricingEvidence;
|
|
7934
|
+
this.collected.pricingEvidence = {
|
|
7935
|
+
version: 1,
|
|
7936
|
+
harness: "codex",
|
|
7937
|
+
model: null,
|
|
7938
|
+
identity_source: "launch_argument",
|
|
7939
|
+
usage_scope: "thread_total",
|
|
7940
|
+
session_mode: "cold",
|
|
7941
|
+
normalization: "codex-jsonl-v1",
|
|
7942
|
+
...rawUsage ? { raw_usage: rawUsage } : old?.raw_usage ? { raw_usage: old.raw_usage } : {},
|
|
7943
|
+
model_rerouted: rerouted || old?.model_rerouted || false,
|
|
7944
|
+
measurement_status: this.stickyStatus ?? status ?? old?.measurement_status ?? (this.awaitingTerminal ? "incomplete_attempt" : "missing"),
|
|
7945
|
+
terminal_snapshots: (old?.terminal_snapshots ?? 0) + (rawUsage ? 1 : 0)
|
|
7946
|
+
};
|
|
7852
7947
|
}
|
|
7853
7948
|
};
|
|
7854
7949
|
|
|
@@ -8731,6 +8826,14 @@ async function runDaemon(opts) {
|
|
|
8731
8826
|
...error ? { error } : {},
|
|
8732
8827
|
...judgment,
|
|
8733
8828
|
usage: summary?.usage ?? { cost_source: "none" },
|
|
8829
|
+
...summary?.pricingEvidence ? {
|
|
8830
|
+
pricing_evidence: {
|
|
8831
|
+
...summary.pricingEvidence,
|
|
8832
|
+
model: run.pricingModel ?? null,
|
|
8833
|
+
session_mode: run.pricingSessionMode ?? "cold",
|
|
8834
|
+
daemon_version: DAEMON_VERSION
|
|
8835
|
+
}
|
|
8836
|
+
} : {},
|
|
8734
8837
|
...summary?.providerSessionId ? { provider_session_id: summary.providerSessionId } : {},
|
|
8735
8838
|
...summary?.numTurns !== void 0 ? { turn_count: summary.numTurns } : {},
|
|
8736
8839
|
// The whole conversation's turns, which for a resumed run is
|
|
@@ -8908,6 +9011,10 @@ async function runDaemon(opts) {
|
|
|
8908
9011
|
{ harness: opts.harness, command: opts.command },
|
|
8909
9012
|
harnessInput
|
|
8910
9013
|
);
|
|
9014
|
+
if (opts.harness === "codex") {
|
|
9015
|
+
run.pricingModel = harnessInput.model;
|
|
9016
|
+
run.pricingSessionMode = resume ? "resumed" : "cold";
|
|
9017
|
+
}
|
|
8911
9018
|
run.batcher.append(
|
|
8912
9019
|
formatLaunchBanner(invocation, harnessInput, {
|
|
8913
9020
|
harness: opts.harness,
|
|
@@ -9576,16 +9683,37 @@ function register8(program3) {
|
|
|
9576
9683
|
);
|
|
9577
9684
|
if (run.usage) {
|
|
9578
9685
|
const u = run.usage;
|
|
9579
|
-
const
|
|
9580
|
-
|
|
9581
|
-
|
|
9582
|
-
|
|
9686
|
+
const costLabel = runCostLabel(run);
|
|
9687
|
+
const metric = (value) => value === void 0 ? "unknown" : value.toLocaleString();
|
|
9688
|
+
console.log(
|
|
9689
|
+
`usage: input ${metric(u.input_tokens)} cache-read ${metric(u.cache_read_tokens)} cache-write ${metric(u.cache_write_tokens)} output ${metric(u.output_tokens)}`
|
|
9690
|
+
);
|
|
9691
|
+
if (u.cost_usd !== void 0)
|
|
9692
|
+
console.log(
|
|
9693
|
+
`cost: ${runCostLabel(run)}${u.cost_source === void 0 ? " \xB7 source unavailable" : ""}`
|
|
9694
|
+
);
|
|
9695
|
+
const pricing = u.pricing;
|
|
9696
|
+
if (pricing?.status === "provider_authoritative")
|
|
9697
|
+
console.log("cost provenance: provider-reported amount is authoritative");
|
|
9698
|
+
if (pricing?.status === "unpriced") console.log(`cost: Unpriced (${pricing.reason})`);
|
|
9699
|
+
else if (u.cost_usd === void 0 && costLabel === "Unpriced")
|
|
9700
|
+
console.log("cost: Unpriced");
|
|
9701
|
+
if (pricing?.status === "calculated") {
|
|
9702
|
+
const b = pricing.basis;
|
|
9703
|
+
console.log(`cost provenance: Estimated standard API list-price equivalent`);
|
|
9704
|
+
console.log(` model: ${b.model} (${b.model_identity})`);
|
|
9705
|
+
console.log(
|
|
9706
|
+
` rate: ${b.rate_id} v${b.rate_version}; adopted ${new Date(b.rate_adopted_at).toISOString()}`
|
|
9707
|
+
);
|
|
9708
|
+
console.log(
|
|
9709
|
+
` source: ${b.source_url} (checked ${b.source_checked_at}${b.source_effective_at ? `; effective ${b.source_effective_at}` : ""})`
|
|
9710
|
+
);
|
|
9711
|
+
console.log(
|
|
9712
|
+
` rates USD/1M: input ${b.rates.input_tokens} cache-read ${b.rates.cache_read_tokens} cache-write ${b.rates.cache_write_tokens ?? "unpublished"} output ${b.rates.output_tokens}`
|
|
9583
9713
|
);
|
|
9714
|
+
console.log(` exact estimated USD: ${b.cost_usd_exact}`);
|
|
9715
|
+
console.log(" Standard API list-price estimate; not an invoice or subscription usage.");
|
|
9584
9716
|
}
|
|
9585
|
-
if (u.cost_usd !== void 0) parts.push(`$${u.cost_usd.toFixed(2)}`);
|
|
9586
|
-
if (u.cost_source)
|
|
9587
|
-
parts.push(`(${u.cost_source === "provider" ? "provider-reported" : u.cost_source})`);
|
|
9588
|
-
if (parts.length > 0) console.log(`usage: ${parts.join(" ")}`);
|
|
9589
9717
|
}
|
|
9590
9718
|
if (run.provider_session_id) console.log(`provider session: ${run.provider_session_id}`);
|
|
9591
9719
|
if (run.provider_url) console.log(`provider console: ${run.provider_url}`);
|