Files
agents-marketplace/buyer/.env.example
david c552c4caa3 buyer: PDF book summarizer (/book) — chunk → map-reduce over suppliers
Adds an authenticated upload flow to the buyer web app: an operator
uploads a PDF, the server extracts + paragraph-aligned-chunks it
(~2.2k tokens), then runs a hierarchical map-reduce summarization by
paying marketplace suppliers per chunk — one on-chain escrow per map
call and per reduce node. One book upload fans out into dozens of real
mainnet escrows (the intended marketplace traffic) while producing a
genuine full-book summary.

Server module (buyer/src/pdf/): PDF extraction (text-only, rejects
scanned), token-aware chunker, supplier discovery/round-robin filtered
to capable models (kimi/deepseek/gpt; excludes qwen2.5:0.5b), pre-spend
cost estimate + wallet-floor guard, and a JobStore orchestrator that
reuses submitPrompt → findSubmittedEscrowRef → runAccept per call.
v1 serializes PostEscrow under a mutex (the shared tx builder can't pin
wallet inputs, so parallel escrows would double-spend); retries failed
calls on a different supplier then continues with gaps. 6 /v1/pdf-*
routes (multipart upload, estimate, confirm-gated start, SSE progress,
result, .md download) behind the existing session auth + page/chunk/
balance caps. SPA adds a 4-step BookSummarizer wizard.

Tests: chunk/estimate/supplier-pool/extract unit tests + orchestrator
(happy/gap/failover) + routes integration. Full buyer suite green
(181 tests); SPA build + typecheck clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-03 11:37:49 +02:00

77 lines
4.0 KiB
Plaintext

# buyer/.env.example
#
# Copy to buyer/.env and fill in. .env is gitignored — never commit.
#
# To generate a fresh Ed25519 wallet seed:
# openssl rand -hex 32
# Fund the resulting address with enough AP3X to cover prompt payment +
# bond + tx fees before posting any escrow.
# ─── Required ─────────────────────────────────────────────────────────────
# 64-char hex Ed25519 private key seed for the buyer wallet. SECRET.
BUYER_PRIV_KEY_HEX=PASTE_64_HEX_CHARS_HERE
# Indexer base URL. Inside compose this is the service name.
INDEXER_URL=http://indexer:8090
# Single-operator login password. Anyone who knows this can spend funds
# via /v1/submit-prompt + /v1/accept, so treat it like BUYER_PRIV_KEY_HEX.
BUYER_PASSWORD=CHANGE_ME
# HMAC key for the buyer_session cookie (HttpOnly, SameSite=Lax, 7-day rolling).
# Minimum 32 chars. Generate with: openssl rand -hex 32
SESSION_SECRET=PASTE_64_HEX_CHARS_HERE_OR_LONGER
# ─── Optional ─────────────────────────────────────────────────────────────
# HTTP listen port (default 3002 in buyer/src/config.ts; we override to
# 8070 in compose to free up the 3xxx range for local dev tooling).
BUYER_PORT=8070
# Cardano network ID. "0" = testnet, "1" = mainnet. (Note: this matches
# the supplier convention, NOT indexer's "testnet"/"mainnet" string.
# See ARCHITECTURE.md §9 follow-up — naming drift to be reconciled.)
NETWORK_ID=0
# Set "0" for plain-HTTP local dev so the buyer_session cookie still rides
# along over loopback. Production behind TLS should leave this unset / "1".
# COOKIE_SECURE=1
# ─── Optional: PDF Book Summarizer (/book page, /v1/pdf-* routes) ─────────
# Upload a PDF → chunk it → pay suppliers to summarize each chunk (one escrow
# per map + reduce call) → full-book summary. All knobs are optional; defaults
# shown. Tune the caps to bound spend/abuse on mainnet.
#
# Hard caps (a job is refused if it would exceed these):
# PDF_MAX_PAGES=400 # reject books larger than this
# PDF_MAX_CHUNKS=200 # reject books that chunk into more calls
# PDF_MAX_PDF_BYTES=25000000 # multipart upload size limit (bytes)
# Refuse to START a job if projected spend would drop the wallet below this:
# PDF_WALLET_FLOOR_LOVELACE=50000000 # 50 AP3X
# Chunking + reduce shape:
# PDF_CHUNK_TARGET_TOKENS=2200 # target tokens per chunk
# PDF_CHUNK_MAX_TOKENS=3000 # hard ceiling per chunk
# PDF_REDUCE_FANIN=8 # summaries collapsed per reduce node
# PDF_RETRY_K=2 # per-call retries on a different supplier
# Supplier selection (comma-separated model-name substrings):
# PDF_MODEL_ALLOWLIST=kimi,deepseek,gpt
# PDF_MODEL_DENYLIST=qwen2.5:0.5b,qwen2.5-0.5b
# Concurrency. v1 must stay 1 (serial PostEscrow — the shared tx builder
# can't pin wallet inputs yet, so parallel escrows would double-spend):
# PDF_LANE_COUNT=1
# ─── Optional: CIP-33 reference scripts ───────────────────────────────────
# When set, buyer-signed script-spending txs (Accept, Reclaim) read the
# escrow validator from an on-chain reference UTxO instead of inlining
# its CBOR — saving witness-set fees. Must match the values published
# by `supplier tx:publish-reference-scripts` (printed to stdout by that
# CLI). Leave unset to use inlined scripts (current behavior).
# ESCROW_REF_UTXO=<txhash>#0
# ADVERT_REF_UTXO=<txhash>#1 # not used by buyer; kept for env-file symmetry
# ─── Reserved for M1-F ────────────────────────────────────────────────────
# INDEXER_TIMEOUT_MS is referenced in deploy/README.md but is NOT yet read
# by buyer/src/config.ts. M1-F should add it; see follow-ups.
# INDEXER_TIMEOUT_MS=15000