mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-27 19:55:54 +01:00
Preserve unknown candidate USD cost and truthful provider attribution
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
aa4b88b169
commit
31a71c9170
4 files changed
+34
-4
No files matched your search
@@ -500,6 +500,11 @@ describe("Capability live projection", () => {
|
||||
.map((item) => item.body);
|
||||
expect(bodies.some((body) => body.includes("semantic-interaction-result"))).toBe(false);
|
||||
});
|
||||
it.each([["cursor", "Cursor"], ["copilot", "GitHub Copilot"], ["pi", "Pi"]] as const)("labels the %s provider truthfully", async (agent, label) => {
|
||||
const snapshot = await liveSnapshot();
|
||||
snapshot.config = { ...snapshot.config, provider: "acpx", driver: "acpx_runtime", acpxAgent: agent };
|
||||
expect(projectCapabilityIssueThread({ snapshot }).identity.agentLabel).toBe(`Real ${label} via ACPX`);
|
||||
});
|
||||
|
||||
it("separates exposed agent tools from withheld control-plane operations", async () => {
|
||||
const view = projectCapabilityIssueThread({ snapshot: await liveSnapshot() });
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
* change already exists in the input.
|
||||
*/
|
||||
|
||||
import { ACPX_CAPABILITY_PROFILES } from "../drivers/acpx/capability-profiles.js";
|
||||
import type {
|
||||
CapabilityFixtureInteraction,
|
||||
CapabilityFixtureState,
|
||||
@@ -761,7 +762,7 @@ export function projectCapabilityIssueThread(
|
||||
: snapshot.config.provider === "opencode" || snapshot.config.driver === "opencode_server"
|
||||
? "Real OpenCode"
|
||||
: snapshot.config.provider === "acpx" || snapshot.config.driver === "acpx_runtime"
|
||||
? `Real ${snapshot.config.acpxAgent === "claude" ? "Claude" : snapshot.config.acpxAgent === "codex" ? "Codex" : "Pi"} via ACPX`
|
||||
? `Real ${ACPX_CAPABILITY_PROFILES[snapshot.config.acpxAgent ?? "pi"].displayName} via ACPX`
|
||||
: "Real Codex"
|
||||
: mode === "replay" ? "Replay" : "Fake agent";
|
||||
const connection = input.connection ?? { state: "connected", attempt: 0 };
|
||||
|
||||
@@ -285,6 +285,7 @@ import {
|
||||
buildRemoteCodexLauncherCommand,
|
||||
mayUsePreinstalledRunnerArtifact,
|
||||
nativeUsageCostUsd,
|
||||
nativeUsageBiller,
|
||||
normalizeNativeUsage,
|
||||
parseRemoteRunnerProcessIdentity,
|
||||
REMOTE_RUNNER_CHILD_LAUNCH_SCRIPT,
|
||||
@@ -959,6 +960,13 @@ describe("native incomplete-bootstrap evidence", () => {
|
||||
});
|
||||
|
||||
describe("native provider usage normalization", () => {
|
||||
it.each([["cursor", "cursor"], ["copilot", "github"], ["pi", "openrouter"]] as const)("keeps %s cost unknown and attributes its actual biller", (agent, biller) => {
|
||||
const provider = { kind: "acpx", agent, model: "exact-model" } as NativeExecutionInput["provider"];
|
||||
expect(nativeUsageBiller(provider)).toBe(biller);
|
||||
const usage = { runDelta: { inputTokens: 100, outputTokens: 12, providerCostUsd: 0 }, cumulative: { providerCostUsd: 0.44 } };
|
||||
expect(nativeUsageCostUsd(usage, provider)).toBeUndefined();
|
||||
expect(normalizeNativeUsage(usage)).toMatchObject({ inputTokens: 100, outputTokens: 12 });
|
||||
});
|
||||
it("reads remote runner run-delta tokens and provider cost", () => {
|
||||
const usage = {
|
||||
total: {
|
||||
|
||||
@@ -9028,10 +9028,10 @@ async function executePaperclipNativeSessionWithinScope(
|
||||
summary: native.result.summary,
|
||||
sessionId: native.normalizedSessionId,
|
||||
sessionDisplayId: native.providerSessionId ?? native.normalizedSessionId,
|
||||
provider: "openai",
|
||||
provider: nativeUsageBiller(input.execution.provider),
|
||||
model: input.execution.provider.model,
|
||||
usage: normalizeNativeUsage(native.usage),
|
||||
costUsd: nativeUsageCostUsd(native.usage),
|
||||
costUsd: nativeUsageCostUsd(native.usage, input.execution.provider),
|
||||
usageBasis: "per_run",
|
||||
nativeFinalization: finalization,
|
||||
};
|
||||
@@ -9087,7 +9087,23 @@ function nativeUsageMeasurement(usage: Record<string, unknown>) {
|
||||
);
|
||||
}
|
||||
|
||||
export function nativeUsageCostUsd(usage: Record<string, unknown> | null) {
|
||||
export function nativeUsageBiller(provider: NativeExecutionInput["provider"]): string {
|
||||
if (provider.kind === "acpx") {
|
||||
if (provider.agent === "cursor") return "cursor";
|
||||
if (provider.agent === "copilot") return "github";
|
||||
if (provider.agent === "pi") return "openrouter";
|
||||
}
|
||||
return "openai";
|
||||
}
|
||||
|
||||
export function nativeUsageCostUsd(
|
||||
usage: Record<string, unknown> | null,
|
||||
provider?: NativeExecutionInput["provider"],
|
||||
) {
|
||||
// The ACP normalization contract fills absent per-turn cost with zero and
|
||||
// reports actual cost cumulatively. Until it carries an authoritative run
|
||||
// delta with provenance, neither value is a candidate's billed USD receipt.
|
||||
if (provider?.kind === "acpx" && ["cursor", "copilot", "pi"].includes(provider.agent)) return undefined;
|
||||
if (!usage) return undefined;
|
||||
const measurement = nativeUsageMeasurement(usage);
|
||||
const direct =
|
||||
|
||||
Reference in new issue
Block a user