Implement honest accounting post-job completion, calculating actual costs, adding margin, and enabling automatic refunds for overpayments via a new endpoint. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 418bf6f8-212b-4bb0-a7a5-8231a061da4e Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: c6386de2-d5f4-47cc-a557-73416f09e118 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/9f85e954-647c-46a5-90a7-396e495a805a/418bf6f8-212b-4bb0-a7a5-8231a061da4e/sPDHkg8 Replit-Helium-Checkpoint-Created: true
168 lines
4.4 KiB
TypeScript
168 lines
4.4 KiB
TypeScript
/**
|
|
* Generated by orval v8.5.3 🍺
|
|
* Do not edit manually.
|
|
* Api
|
|
* API specification
|
|
* OpenAPI spec version: 0.1.0
|
|
*/
|
|
import * as zod from "zod";
|
|
|
|
/**
|
|
* Returns server health status
|
|
* @summary Health check
|
|
*/
|
|
export const HealthCheckResponse = zod.object({
|
|
status: zod.string(),
|
|
});
|
|
|
|
/**
|
|
* Accepts a request, creates a job row, and issues an eval fee Lightning invoice.
|
|
* @summary Create a new agent job
|
|
*/
|
|
|
|
export const CreateJobBody = zod.object({
|
|
request: zod.string().min(1),
|
|
});
|
|
|
|
/**
|
|
* Returns current job state. Automatically advances the state machine when a pending invoice is found to be paid.
|
|
* @summary Get job status
|
|
*/
|
|
export const GetJobParams = zod.object({
|
|
id: zod.coerce.string(),
|
|
});
|
|
|
|
export const GetJobResponse = zod.object({
|
|
jobId: zod.string(),
|
|
state: zod.enum([
|
|
"awaiting_eval_payment",
|
|
"evaluating",
|
|
"rejected",
|
|
"awaiting_work_payment",
|
|
"executing",
|
|
"complete",
|
|
"failed",
|
|
]),
|
|
evalInvoice: zod
|
|
.object({
|
|
paymentRequest: zod.string(),
|
|
amountSats: zod.number(),
|
|
})
|
|
.optional(),
|
|
workInvoice: zod
|
|
.object({
|
|
paymentRequest: zod.string(),
|
|
amountSats: zod.number(),
|
|
})
|
|
.optional(),
|
|
pricingBreakdown: zod
|
|
.object({
|
|
estimatedCostUsd: zod
|
|
.number()
|
|
.optional()
|
|
.describe(
|
|
"Total estimated cost in USD (token cost + DO infra + margin)",
|
|
),
|
|
marginPct: zod
|
|
.number()
|
|
.optional()
|
|
.describe("Originator margin percentage applied"),
|
|
btcPriceUsd: zod
|
|
.number()
|
|
.optional()
|
|
.describe("BTC\/USD spot price used to convert the invoice to sats"),
|
|
})
|
|
.optional()
|
|
.describe(
|
|
"Cost breakdown shown with the work invoice (estimations at invoice-creation time)",
|
|
),
|
|
reason: zod.string().optional(),
|
|
result: zod.string().optional(),
|
|
costLedger: zod
|
|
.object({
|
|
actualInputTokens: zod.number().optional(),
|
|
actualOutputTokens: zod.number().optional(),
|
|
totalTokens: zod
|
|
.number()
|
|
.optional()
|
|
.describe("Sum of actualInputTokens + actualOutputTokens"),
|
|
actualCostUsd: zod
|
|
.number()
|
|
.optional()
|
|
.describe("Raw Anthropic token cost (no infra, no margin)"),
|
|
actualChargeUsd: zod
|
|
.number()
|
|
.optional()
|
|
.describe(
|
|
"What we honestly charged in USD (actual token cost + DO infra + margin)",
|
|
),
|
|
estimatedCostUsd: zod
|
|
.number()
|
|
.optional()
|
|
.describe("Original estimate used to create the work invoice"),
|
|
actualAmountSats: zod
|
|
.number()
|
|
.optional()
|
|
.describe(
|
|
"Honest sats charge (actual cost converted at the locked BTC price)",
|
|
),
|
|
workAmountSats: zod
|
|
.number()
|
|
.optional()
|
|
.describe("Amount the user originally paid in sats"),
|
|
refundAmountSats: zod
|
|
.number()
|
|
.optional()
|
|
.describe(
|
|
"Sats owed back to the user (workAmountSats - actualAmountSats, >= 0)",
|
|
),
|
|
refundState: zod
|
|
.enum(["not_applicable", "pending", "paid"])
|
|
.optional()
|
|
.describe("Lifecycle of the refund for this job"),
|
|
marginPct: zod.number().optional(),
|
|
btcPriceUsd: zod
|
|
.number()
|
|
.optional()
|
|
.describe("BTC\/USD price locked at invoice creation time"),
|
|
})
|
|
.optional()
|
|
.describe("Honest post-work accounting stored after the job completes"),
|
|
errorMessage: zod.string().optional(),
|
|
});
|
|
|
|
/**
|
|
* After a job completes, if the actual cost (tokens used + infra + margin) was
|
|
less than the work invoice amount, the difference is owed back to the user.
|
|
Submit a BOLT11 invoice for exactly `refundAmountSats` to receive the payment.
|
|
Idempotent: returns 409 if already paid or if no refund is owed.
|
|
|
|
* @summary Claim a refund for overpayment
|
|
*/
|
|
export const ClaimRefundParams = zod.object({
|
|
id: zod.coerce.string(),
|
|
});
|
|
|
|
export const ClaimRefundBody = zod.object({
|
|
invoice: zod.string().describe("BOLT11 invoice for exactly refundAmountSats"),
|
|
});
|
|
|
|
export const ClaimRefundResponse = zod.object({
|
|
ok: zod.boolean(),
|
|
refundAmountSats: zod.number(),
|
|
paymentHash: zod.string(),
|
|
message: zod.string(),
|
|
});
|
|
|
|
/**
|
|
* Runs the agent without payment. Limited to 5 requests per IP per hour.
|
|
* @summary Free demo (rate-limited)
|
|
*/
|
|
export const RunDemoQueryParams = zod.object({
|
|
request: zod.coerce.string(),
|
|
});
|
|
|
|
export const RunDemoResponse = zod.object({
|
|
result: zod.string(),
|
|
});
|