Files
agents-marketplace/supplier/.env.example
david 2f7b0194a5 feat(supplier,gateway,buyer): N-slot chat suppliers + entry-ticket settle mode
Two structural fixes for demo concurrency (3 single-slot suppliers thrashed
under Open WebUI's ~3 conversations per message):

Multi-slot suppliers (MAX_CHAT_SESSIONS, default 1):
- SupplierState is now capacity-aware: a Set of active escrow refs with
  free-until-full status semantics, ref-scoped release(ref) (also fixes the
  latent bug where handler catch-alls released another request's slot), and
  a walletMutex serializing every wallet-spending chain op — Claim, Submit,
  and wallet-health consolidation queue instead of racing the single
  working/collateral UTxO. /status gains active_sessions/max_sessions.

Entry-ticket settle mode (CHAT_SETTLE_MODE=ticket, default full, both sides):
- The buyer's escrow post at session open is the ONLY chain op. The supplier
  verifies the Open escrow as an entry ticket but never Claims/Submits
  (/v1/chat/start → {status:"ticket"}; /v1/chat/end → receipt-less
  {status:"ended"}); no hard-cap timer, so sessions may outlive deliver_by.
  Used tickets can't reopen sessions (records retained; 409 session_exists).
- Buyer SDK: startChat/endChat are settle-mode aware, driven by the
  supplier's response — mixed-mode rollout windows settle correctly.
- Gateway: ticket closes bill cost 0; the sweeper Reclaims Open tickets
  after deliver_by WITHOUT closing live sessions (the conversation and its
  affinity mirror survive their reclaimed ticket), gates reclaims on
  deliver_by, and keeps an in-process settled-refs memory so terminal
  indexer rows aren't retried every sweep forever.

Deployment (kimi-chat trio + gateway): ticket mode, 8 slots per supplier,
idle policy gateway 10 min / supplier 15 min (fixes the inversion where the
supplier idle-closed before the gateway janitor).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-09 20:48:52 +02:00

135 lines
6.3 KiB
Plaintext

# supplier/.env.example
#
# Copy to supplier/.env and fill in real values before `docker compose up`.
# .env is gitignored — NEVER commit a populated copy.
#
# To generate a fresh Ed25519 wallet seed:
# openssl rand -hex 32
# Fund the resulting address with ~5 AP3X on Vector testnet via the faucet
# before running. See deploy/README.md §2.
#
# Lines marked SECRET must never be shared, logged, or committed.
# ─── Required ─────────────────────────────────────────────────────────────
# 64-char hex Ed25519 private key seed for the supplier wallet. SECRET.
# Generate via: openssl rand -hex 32
SUPPLIER_PRIV_KEY_HEX=PASTE_64_HEX_CHARS_HERE
# Ogmios WebSocket URL. For external hosted Ogmios (recommended for M1-F):
# wss://ogmios.vector.testnet.apexfusion.org
# For a local Ogmios container (M1-F-vector-stack follow-up): ws://ogmios:1337
OGMIOS_URL=wss://ogmios.vector.testnet.apexfusion.org
# Ollama HTTP base URL. Inside compose this is the service name.
OLLAMA_URL=http://ollama:11434
# OutputReference of this supplier's on-chain advertisement UTxO.
# Format: "<64-hex-tx-hash>#<int-output-index>"
# Posting an advert is a one-shot operation — see deploy/README.md §4.
ADVERT_REF=PASTE_TXHASH_HERE#0
# Cardano network ID. "0" = testnet, "1" = mainnet.
# IMPORTANT: leave at "0" until ARCHITECTURE.md §9 #5 mainnet safety lands.
NETWORK_ID=0
# ─── Optional ─────────────────────────────────────────────────────────────
# HTTP listen port inside the container. Compose maps this to the host.
PORT=8080
# Ollama request timeout (ms). Tiny CPU model on Hetzner CX is slow — keep
# generous. Increase if you see ollama_timeout reasons in logs.
OLLAMA_TIMEOUT_MS=120000
# ─── Optional — OpenAI-compatible backend (LLM_BACKEND=openai) ────────────
# Switch the chat job runner to POST /v1/chat/completions at OPENAI_BASE_URL
# instead of Ollama. Used by the mainnet ChatMock-backed supplier and any
# hosted OpenAI-compatible API (OpenAI, DeepSeek, etc.).
# LLM_BACKEND=openai
# OPENAI_BASE_URL=http://marketplace-mainnet-chatmock:8000 # or https://api.deepseek.com
# OPENAI_TIMEOUT_MS=180000
# OPENAI_API_KEY — optional bearer token. When set, the supplier forwards it
# as `Authorization: Bearer <key>` on every /v1/chat/completions request.
# Leave empty for endpoints that don't require auth (ChatMock, other local
# proxies). REQUIRED for hosted APIs (DeepSeek, OpenAI). SECRET.
# OPENAI_API_KEY=
# ─── Optional (not in supplier/src/config.ts; consumed by index.ts boot) ──
# Pre-derived public-key + pkh + bech32 address. M1-D will derive these from
# SUPPLIER_PRIV_KEY_HEX automatically; until then index.ts reads them from
# env. Tests inject WalletKey directly.
# SUPPLIER_PUB_KEY_HEX=
# SUPPLIER_PKH=
# SUPPLIER_ADDRESS=
# ─── Optional — chain provider selection (M1-F-2) ─────────────────────────
# LIVE_CHAIN: opt-in to real Ogmios submitTx + awaitTx.
# Default unset = ReadOnlyOgmiosProvider (no real chain writes; safe for dev).
# Set to literal "1" to enable LiveOgmiosProvider — REAL TESTNET/MAINNET
# SUBMISSIONS WILL HAPPEN. Any other value (including "true", "yes", "TRUE")
# is treated as off, by design (safety against misconfiguration).
LIVE_CHAIN=
# ─── tx:post-advert — run once before first deploy (M1-F-3) ───────────────────
# Execute: pnpm --filter @marketplace/supplier tx:post-advert
# On success, copy the printed "<txHash>#0" string into ADVERT_REF above.
# Capability published in the on-chain advertisement. // added M1-F-3
ADVERT_CAPABILITY_ID=llm.text.generate.v1
# Ollama model name served by this supplier. // added M1-F-3
ADVERT_MODEL=qwen2.5:0.5b
# Maximum output tokens the supplier will honour per request. // added M1-F-3
ADVERT_MAX_OUTPUT_TOKENS=512
# Maximum processing time the supplier guarantees (ms). // added M1-F-3
ADVERT_MAX_PROCESSING_MS=60000
# Flat price per prompt in AP3X lovelace. // added M1-F-3
ADVERT_PRICE_LOVELACE=2000000
# Supplier bond deposited into the advert UTxO (lovelace). // added M1-F-3
# Default 1_000_000 if omitted.
ADVERT_SUPPLIER_BOND_LOVELACE=1000000
# Buyer bond required per escrow (lovelace). // added M1-F-3
# Default 1_000_000 if omitted.
ADVERT_BUYER_BOND_LOVELACE=1000000
# HTTPS endpoint buyers will call (must be publicly reachable). // added M1-F-3
ADVERT_ENDPOINT_URL=https://mp-supplier.vector.testnet.apexfusion.org
# Optional off-chain detail pointer (IPFS / HTTPS URI). // added M1-F-3
# Leave empty for v1 if no extended metadata is published.
ADVERT_DETAIL_URI=
# Optional sha256 of the detail JSON (64 hex chars). // added M1-F-3
# If empty, defaults to sha256("") =
# e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
ADVERT_DETAIL_HASH=
# ─── Optional: CIP-33 reference scripts ───────────────────────────────────
# Saves witness-set fee on script-spending txs (Claim, Submit, Accept,
# Reclaim, RetireAdvert) by referencing on-chain script UTxOs instead of
# inlining the full validator CBOR. Leave unset to use inlined scripts
# (current behavior).
#
# Publish the two reference UTxOs (one-shot; uses SUPPLIER_PRIV_KEY_HEX +
# OGMIOS_URL + NETWORK_ID from this env file):
# docker compose -f deploy/testnet/docker-compose.supplier.yml run --rm \
# --entrypoint sh supplier \
# -c "node_modules/.bin/tsx supplier/src/cli/publish-reference-scripts.ts"
# Paste the two printed refs here AND into buyer/.env, then
# `docker compose down && up -d` to apply.
# ESCROW_REF_UTXO=<txhash>#0
# ADVERT_REF_UTXO=<txhash>#1
# ─── Optional: chat-session tuning (CAPABILITY_KIND=chat-session only) ─────
# CHAT_IDLE_TIMEOUT_MS=300000 # auto-end sessions idle this long
# MAX_CHAT_SESSIONS=1 # concurrent session slots (default 1)
# CHAT_SETTLE_MODE=full # "full" (Claim/Submit) or "ticket" (no supplier
# # chain ops; buyer reclaims the Open escrow)