fabro/lib/crates/fabro-workflow/src
Scott Werner 480ff56aba feat(llm): add Response.cost_usd and CostSource across all adapters
Adds two new fields to the unified completion Response:

- cost_usd: Option<f64> — USD cost for the completion
- cost_source: Option<CostSource> — Authoritative | Estimated

A new fabro_llm::cost::estimate_cost_usd helper centralizes the catalog
math (tokens × catalog price → USD micros → f64). Every adapter response
path (Anthropic, OpenAI, Gemini, openai_chat) calls the helper when a
catalog is available, producing Estimated costs. Adapters with
authoritative provider-side pricing (e.g. OpenRouter, in a later commit)
will bypass the helper and set Authoritative.

The openai_chat streaming path now plumbs catalog + speed through
StreamState so finish_events can call the helper before assembling the
final Response.

Public API surface: CompletionResponse in fabro-api.yaml is extended
with cost_usd and cost_source. Progenitor + the TS client are
regenerated; apps/fabro-web typechecks clean since both fields are
optional.

42 Response constructor sites updated:
- 5 live adapter sites call estimate_cost_usd
- ~32 synthesized/fallback/test sites set (None, None) explicitly
- 5 test fixtures in types.rs set (None, None)

397 lib tests pass (was 392, +5 new helper unit tests).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-28 17:05:08 -04:00
..
event refactor: remove devcontainer support (#433) 2026-05-27 12:48:40 -04:00
graph refactor(workflow): update stage outcome semantics 2026-04-30 06:06:51 -04:00
handler feat(automation): persist automation refs on runs (#428) 2026-05-27 11:52:57 -04:00
lifecycle feat(automation): persist automation refs on runs (#428) 2026-05-27 11:52:57 -04:00
operations Replace stdin JSONL control pipe with WebSocket worker control bus (#440) 2026-05-27 20:24:25 -04:00
pipeline feat(llm): add Response.cost_usd and CostSource across all adapters 2026-05-28 17:05:08 -04:00
records refactor: unify run vocabulary and metadata snapshot layout 2026-04-20 22:17:23 -04:00
transforms Replace vague expect/panic messages with invariant-explaining messages (#422) 2026-05-27 10:38:20 -04:00
artifact.rs fix(agent): use raw sandbox reads for edits 2026-05-22 21:26:36 -04:00
artifact_snapshot.rs fix(agent): use raw sandbox reads for edits 2026-05-22 21:26:36 -04:00
artifact_upload.rs feat(run): separate stage state and artifact retries 2026-05-01 20:10:47 -04:00
billing_rollup.rs feat(automation): persist automation refs on runs (#428) 2026-05-27 11:52:57 -04:00
command_log.rs refactor(run): add rich failure contract (#256) 2026-05-13 12:32:28 -04:00
condition.rs Replace bare unwrap() with documented expect() across production runtim… (#415) 2026-05-26 17:46:39 -04:00
context.rs feat(runs): merge command output streams 2026-05-07 22:07:13 -07:00
error.rs Fix cancelled projection for failed commands 2026-05-24 12:15:56 -04:00
event.rs Surface silent fallback warnings in runs and logs (#205) 2026-05-05 09:18:05 -04:00
file_resolver.rs fix(workflow): allow workflow-root template partials (#322) 2026-05-20 09:22:28 -04:00
git.rs feat(automation): persist automation refs on runs (#428) 2026-05-27 11:52:57 -04:00
github_token_source.rs refactor: simplify token plumbing and parallelize read_many_files 2026-05-06 07:15:18 -04:00
graph.rs refactor(unwrap): clear non-test workspace warnings 2026-04-19 20:56:38 -04:00
hook_context.rs Rename fabro-workflows crate to fabro-workflow 2026-03-30 12:27:40 -04:00
interview_runtime.rs Migrate sandbox config to named environments; add InterviewOption metad… (#372) 2026-05-23 15:47:33 -04:00
lib.rs refactor: remove devcontainer support (#433) 2026-05-27 12:48:40 -04:00
node_handler.rs fix(workflow): honor human gate timeout defaults (#323) 2026-05-20 09:26:20 -04:00
outcome.rs refactor(model): move provider facts into catalog (#298) 2026-05-17 20:59:08 -04:00
pull_request.rs refactor: remove compatibility shims (#281) 2026-05-16 15:29:25 -04:00
retry.rs ci: switch clippy to pinned nightly, clean up workspace lints 2026-04-16 18:59:11 -04:00
run_control.rs fmt: apply nightly rustfmt after merge 2026-04-11 13:43:30 -04:00
run_dir.rs fmt 2026-04-11 11:27:46 -04:00
run_lookup.rs feat(automation): persist automation refs on runs (#428) 2026-05-27 11:52:57 -04:00
run_materialization.rs feat(model): support open provider catalog data (#245) 2026-05-12 15:42:49 -04:00
run_metadata.rs feat(automation): persist automation refs on runs (#428) 2026-05-27 11:52:57 -04:00
run_options.rs refactor: remove devcontainer support (#433) 2026-05-27 12:48:40 -04:00
run_status.rs refactor(run-status): unify tagged lifecycle states 2026-04-22 17:15:13 -04:00
runtime_store.rs feat(automation): persist automation refs on runs (#428) 2026-05-27 11:52:57 -04:00
sandbox_git.rs fix(agent): use raw sandbox reads for edits 2026-05-22 21:26:36 -04:00
sandbox_git_runtime.rs fix(workflow): retain exec output tails on failures 2026-05-03 21:30:34 -04:00
services.rs refactor: remove devcontainer support (#433) 2026-05-27 12:48:40 -04:00
stage_scope.rs refactor(workflow): split event module by responsibility 2026-05-02 14:52:10 -04:00
static_reference.rs Add output_schema validation with same-context repair for agent and pro… (#374) 2026-05-23 19:45:16 -04:00
steering_hub.rs Stage-based pairing API and fabro_run_pair MCP tool (#344) 2026-05-21 21:57:55 -04:00
test_support.rs feat(automation): persist automation refs on runs (#428) 2026-05-27 11:52:57 -04:00
workflow_bundle.rs fix: MiniJinja can't find partials (#301) 2026-05-17 22:15:45 -04:00