This repository has been archived on 2026-03-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
token-gated-economy/artifacts/api-server/src/smoke.ts

47 lines
1.5 KiB
TypeScript
Raw Normal View History

Task #2: MVP Foundation — injectable services, DB schema, smoke test DB schema - jobs and invoices tables added to lib/db/src/schema/ - schema barrel updated (jobs, invoices, conversations, messages) - pnpm --filter @workspace/db run push applied successfully LNbitsService (artifacts/api-server/src/lib/lnbits.ts) - Injectable class accepting optional { url, apiKey } config - Falls back to LNBITS_URL / LNBITS_API_KEY env vars - Auto-detects stub mode when credentials are absent; logs warning - createInvoice() -> { paymentHash, paymentRequest } - checkInvoicePaid() -> boolean - stubMarkPaid() helper for dev/test flows - Real LNbits REST v1 calls wired behind the stub guard AgentService (artifacts/api-server/src/lib/agent.ts) - Injectable class with configurable evalModel / workModel - evaluateRequest(text) -> { accepted: boolean, reason: string } uses claude-haiku-4-5; strips markdown fences before JSON parse - executeWork(text) -> { result: string } uses claude-sonnet-4-6 - Wired via Replit Anthropic AI Integration (no user API key) PricingService (artifacts/api-server/src/lib/pricing.ts) - Injectable class with configurable fee/bucket thresholds - calculateEvalFeeSats() -> 10 sats (fixed) - calculateWorkFeeSats(text) -> 50/100/250 by char-length bucket - Zero LLM involvement; fully deterministic Smoke test (scripts/src/smoke.ts) - pnpm --filter @workspace/scripts run smoke - Verifies LNbits stub: create, check unpaid, mark paid, check paid - Verifies Anthropic: evaluateRequest round-trip - Both checks passed replit.md - Documented required (LNBITS_URL, LNBITS_API_KEY) and auto-provisioned secrets - Stub-mode behaviour explained
2026-03-18 15:14:23 +00:00
/**
* Smoke test: confirms LNbitsService and AgentService are reachable.
Task #2: MVP Foundation — injectable services, DB schema, smoke test DB schema - jobs and invoices tables in lib/db/src/schema/ - schema barrel exports jobs, invoices, conversations, messages - Schema pushed successfully LNbitsService (artifacts/api-server/src/lib/lnbits.ts) - Injectable class: constructor accepts optional { url, apiKey } config - Falls back to LNBITS_URL / LNBITS_API_KEY env vars - Auto-detects stub mode when credentials absent; logs clear warning - createInvoice(amountSats, memo) -> { paymentHash, paymentRequest } - checkInvoicePaid(paymentHash) -> boolean - stubMarkPaid(hash) helper for dev flows (guarded to stub mode only) - Real LNbits REST v1 calls wired behind stub guard AgentService (artifacts/api-server/src/lib/agent.ts) - Injectable class with configurable evalModel/workModel - evaluateRequest(text) -> { accepted: boolean, reason: string } uses claude-haiku-4-5; strips markdown fences before JSON parse - executeWork(text) -> { result: string } uses claude-sonnet-4-6 - No @anthropic-ai/sdk import; types inferred from SDK response union - Wired via Replit Anthropic AI Integration PricingService (artifacts/api-server/src/lib/pricing.ts) - Injectable class with configurable fee/bucket thresholds - calculateEvalFeeSats() -> 10 sats (fixed) - calculateWorkFeeSats(text) -> 50/100/250 by char-length bucket - Fully deterministic, no LLM Smoke test (artifacts/api-server/src/smoke.ts) - pnpm --filter @workspace/api-server run smoke - LNbits: create invoice, check unpaid, mark paid, check paid — all pass - Anthropic: evaluateRequest round-trip — passes replit.md: documented LNBITS_URL, LNBITS_API_KEY and auto-provisioned secrets
2026-03-18 15:18:23 +00:00
* Run: pnpm --filter @workspace/api-server run smoke
Task #2: MVP Foundation — injectable services, DB schema, smoke test DB schema - jobs and invoices tables added to lib/db/src/schema/ - schema barrel updated (jobs, invoices, conversations, messages) - pnpm --filter @workspace/db run push applied successfully LNbitsService (artifacts/api-server/src/lib/lnbits.ts) - Injectable class accepting optional { url, apiKey } config - Falls back to LNBITS_URL / LNBITS_API_KEY env vars - Auto-detects stub mode when credentials are absent; logs warning - createInvoice() -> { paymentHash, paymentRequest } - checkInvoicePaid() -> boolean - stubMarkPaid() helper for dev/test flows - Real LNbits REST v1 calls wired behind the stub guard AgentService (artifacts/api-server/src/lib/agent.ts) - Injectable class with configurable evalModel / workModel - evaluateRequest(text) -> { accepted: boolean, reason: string } uses claude-haiku-4-5; strips markdown fences before JSON parse - executeWork(text) -> { result: string } uses claude-sonnet-4-6 - Wired via Replit Anthropic AI Integration (no user API key) PricingService (artifacts/api-server/src/lib/pricing.ts) - Injectable class with configurable fee/bucket thresholds - calculateEvalFeeSats() -> 10 sats (fixed) - calculateWorkFeeSats(text) -> 50/100/250 by char-length bucket - Zero LLM involvement; fully deterministic Smoke test (scripts/src/smoke.ts) - pnpm --filter @workspace/scripts run smoke - Verifies LNbits stub: create, check unpaid, mark paid, check paid - Verifies Anthropic: evaluateRequest round-trip - Both checks passed replit.md - Documented required (LNBITS_URL, LNBITS_API_KEY) and auto-provisioned secrets - Stub-mode behaviour explained
2026-03-18 15:14:23 +00:00
*/
Task #2: MVP Foundation — injectable services, DB schema, smoke test DB schema - jobs and invoices tables in lib/db/src/schema/ - schema barrel exports jobs, invoices, conversations, messages - Schema pushed successfully LNbitsService (artifacts/api-server/src/lib/lnbits.ts) - Injectable class: constructor accepts optional { url, apiKey } config - Falls back to LNBITS_URL / LNBITS_API_KEY env vars - Auto-detects stub mode when credentials absent; logs clear warning - createInvoice(amountSats, memo) -> { paymentHash, paymentRequest } - checkInvoicePaid(paymentHash) -> boolean - stubMarkPaid(hash) helper for dev flows (guarded to stub mode only) - Real LNbits REST v1 calls wired behind stub guard AgentService (artifacts/api-server/src/lib/agent.ts) - Injectable class with configurable evalModel/workModel - evaluateRequest(text) -> { accepted: boolean, reason: string } uses claude-haiku-4-5; strips markdown fences before JSON parse - executeWork(text) -> { result: string } uses claude-sonnet-4-6 - No @anthropic-ai/sdk import; types inferred from SDK response union - Wired via Replit Anthropic AI Integration PricingService (artifacts/api-server/src/lib/pricing.ts) - Injectable class with configurable fee/bucket thresholds - calculateEvalFeeSats() -> 10 sats (fixed) - calculateWorkFeeSats(text) -> 50/100/250 by char-length bucket - Fully deterministic, no LLM Smoke test (artifacts/api-server/src/smoke.ts) - pnpm --filter @workspace/api-server run smoke - LNbits: create invoice, check unpaid, mark paid, check paid — all pass - Anthropic: evaluateRequest round-trip — passes replit.md: documented LNBITS_URL, LNBITS_API_KEY and auto-provisioned secrets
2026-03-18 15:18:23 +00:00
import { LNbitsService } from "./lib/lnbits.js";
import { AgentService } from "./lib/agent.js";
Task #2: MVP Foundation — injectable services, DB schema, smoke test DB schema - jobs and invoices tables added to lib/db/src/schema/ - schema barrel updated (jobs, invoices, conversations, messages) - pnpm --filter @workspace/db run push applied successfully LNbitsService (artifacts/api-server/src/lib/lnbits.ts) - Injectable class accepting optional { url, apiKey } config - Falls back to LNBITS_URL / LNBITS_API_KEY env vars - Auto-detects stub mode when credentials are absent; logs warning - createInvoice() -> { paymentHash, paymentRequest } - checkInvoicePaid() -> boolean - stubMarkPaid() helper for dev/test flows - Real LNbits REST v1 calls wired behind the stub guard AgentService (artifacts/api-server/src/lib/agent.ts) - Injectable class with configurable evalModel / workModel - evaluateRequest(text) -> { accepted: boolean, reason: string } uses claude-haiku-4-5; strips markdown fences before JSON parse - executeWork(text) -> { result: string } uses claude-sonnet-4-6 - Wired via Replit Anthropic AI Integration (no user API key) PricingService (artifacts/api-server/src/lib/pricing.ts) - Injectable class with configurable fee/bucket thresholds - calculateEvalFeeSats() -> 10 sats (fixed) - calculateWorkFeeSats(text) -> 50/100/250 by char-length bucket - Zero LLM involvement; fully deterministic Smoke test (scripts/src/smoke.ts) - pnpm --filter @workspace/scripts run smoke - Verifies LNbits stub: create, check unpaid, mark paid, check paid - Verifies Anthropic: evaluateRequest round-trip - Both checks passed replit.md - Documented required (LNBITS_URL, LNBITS_API_KEY) and auto-provisioned secrets - Stub-mode behaviour explained
2026-03-18 15:14:23 +00:00
async function smokeLnbits(): Promise<void> {
const svc = new LNbitsService();
const invoice = await svc.createInvoice(1, "smoke-test");
console.log("✓ LNbits createInvoice:", invoice.paymentHash.slice(0, 16), "...");
const paidBefore = await svc.checkInvoicePaid(invoice.paymentHash);
console.log("✓ LNbits checkInvoicePaid (unpaid, expect false):", paidBefore);
if (svc.stubMode) {
svc.stubMarkPaid(invoice.paymentHash);
const paidAfter = await svc.checkInvoicePaid(invoice.paymentHash);
console.log("✓ LNbits checkInvoicePaid (after stub mark, expect true):", paidAfter);
}
}
async function smokeAnthropic(): Promise<void> {
const svc = new AgentService();
const evalResult = await svc.evaluateRequest("What is 2 + 2?");
console.log("✓ AgentService evaluateRequest:", JSON.stringify(evalResult));
}
(async () => {
console.log("--- Timmy smoke test ---");
try {
await smokeLnbits();
} catch (err) {
console.error("✗ LNbits smoke failed:", err);
process.exitCode = 1;
}
try {
await smokeAnthropic();
} catch (err) {
console.error("✗ Anthropic smoke failed:", err);
process.exitCode = 1;
}
if (!process.exitCode) {
console.log("--- All smoke checks passed ---");
}
})();