repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | /** |
| #2 | * Resource Monitor |
| #3 | * |
| #4 | * Continuously monitors the automaton's resources and triggers |
| #5 | * survival mode transitions when needed. |
| #6 | */ |
| #7 | import { getSurvivalTier, formatCredits } from "../clawd/credits.js"; |
| #8 | import { getUsdcBalance } from "../clawd/x402.js"; |
| #9 | /** |
| #10 | * Check all resources and return current status. |
| #11 | */ |
| #12 | export async function checkResources(identity, runtime, db) { |
| #13 | // Check credits |
| #14 | let creditsCents = 0; |
| #15 | try { |
| #16 | creditsCents = await runtime.getCreditsBalance(); |
| #17 | } |
| #18 | catch { } |
| #19 | // Check USDC |
| #20 | let usdcBalance = 0; |
| #21 | try { |
| #22 | usdcBalance = await getUsdcBalance(identity.address); |
| #23 | } |
| #24 | catch { } |
| #25 | // Check sandbox health |
| #26 | let sandboxHealthy = true; |
| #27 | try { |
| #28 | const result = await runtime.exec("echo ok", 5000); |
| #29 | sandboxHealthy = result.exitCode === 0; |
| #30 | } |
| #31 | catch { |
| #32 | sandboxHealthy = false; |
| #33 | } |
| #34 | const financial = { |
| #35 | creditsCents, |
| #36 | usdcBalance, |
| #37 | lastChecked: new Date().toISOString(), |
| #38 | }; |
| #39 | const tier = getSurvivalTier(creditsCents); |
| #40 | const prevTierStr = db.getKV("current_tier"); |
| #41 | const previousTier = prevTierStr || null; |
| #42 | const tierChanged = previousTier !== null && previousTier !== tier; |
| #43 | // Store current tier |
| #44 | db.setKV("current_tier", tier); |
| #45 | // Store financial state |
| #46 | db.setKV("financial_state", JSON.stringify(financial)); |
| #47 | return { |
| #48 | financial, |
| #49 | tier, |
| #50 | previousTier, |
| #51 | tierChanged, |
| #52 | sandboxHealthy, |
| #53 | }; |
| #54 | } |
| #55 | /** |
| #56 | * Generate a human-readable resource report. |
| #57 | */ |
| #58 | export function formatResourceReport(status) { |
| #59 | const lines = [ |
| #60 | `=== RESOURCE STATUS ===`, |
| #61 | `Credits: ${formatCredits(status.financial.creditsCents)}`, |
| #62 | `USDC: ${status.financial.usdcBalance.toFixed(6)}`, |
| #63 | `Tier: ${status.tier}${status.tierChanged ? ` (changed from ${status.previousTier})` : ""}`, |
| #64 | `Sandbox: ${status.sandboxHealthy ? "healthy" : "UNHEALTHY"}`, |
| #65 | `Checked: ${status.financial.lastChecked}`, |
| #66 | `========================`, |
| #67 | ]; |
| #68 | return lines.join("\n"); |
| #69 | } |
| #70 | //# sourceMappingURL=monitor.js.map |