● Zion Boggan
repos/Darwin/face/src/lib/mock-gateway.ts
zionboggan.com ↗
164 lines · typescript
History for this file →
1
 
2
import type { AskResponse, HealthResponse } from "./types";
3
 
4
 
5
const MOCK_ASK_RESPONSE: AskResponse = {
6
  answer:
7
    "Hermes v2.5 is running on CT-REDACTED (REDACTED-IP). The service is active and auto-restarting via systemd. " +
8
    "Last deployment was from /shared/projects/hermes/main.py. The bot uses RSA-PSS auth against the Kalshi API " +
9
    "and Grok's /v1/responses endpoint with web_search + x_search tools for market intelligence. " +
10
    "Auto-execute trading is enabled. The radar v2 pipeline handles signal generation.",
11
  receipts: [
12
    {
13
      id: "r1",
14
      source: "rag",
15
      path: "/shared/projects/CLAUDE.md",
16
      last_seen: "2026-06-23T18:42:00Z",
17
      confidence: 0.96,
18
      snippet:
19
        "Hermes v2.5 - Kalshi Trading Bot (CT-REDACTED). Code: $HERMES_HOME/main.py on CT-REDACTED (3883 lines). Service: systemd hermes (enabled, auto-restarts).",
20
    },
21
    {
22
      id: "r2",
23
      source: "cbm",
24
      path: "/shared/projects/hermes/main.py#RadarV2Pipeline",
25
      last_seen: "2026-06-23T17:15:00Z",
26
      confidence: 0.89,
27
      snippet:
28
        "class RadarV2Pipeline: async def run(self, market_id: str) -> Signal: ... # Grok web_search + x_search, RSA-PSS Kalshi auth",
29
    },
30
    {
31
      id: "r3",
32
      source: "memgraph",
33
      path: "entity:hermes-trading-bot",
34
      last_seen: "2026-06-23T16:00:00Z",
35
      confidence: 0.82,
36
      snippet: "Hermes v2.5 deployed CT-REDACTED pve-gpu node. Auto-execute enabled. Last trade signal 14m ago.",
37
    },
38
    {
39
      id: "r4",
40
      source: "proxmox",
41
      path: "ct/210/status",
42
      last_seen: "2026-06-23T18:55:00Z",
43
      confidence: 0.99,
44
      snippet: "CT-REDACTED status: running. CPU 1.2% / 2c. RAM 812MB / 2GB. Uptime 4d 7h 22m.",
45
    },
46
  ],
47
  hits: [
48
    {
49
      engine: "homelab-rag",
50
      title: "Hermes Trading Bot - CLAUDE.md",
51
      path: "/shared/projects/CLAUDE.md",
52
      snippet: "Hermes v2.5 - Kalshi Trading Bot (CT-REDACTED). Stack: Python - Discord bot + FastAPI + Kalshi API + Grok Responses API",
53
      score: 0.97,
54
      last_seen: "2026-06-23T18:42:00Z",
55
      confidence: 0.96,
56
    },
57
    {
58
      engine: "cbm-homelab",
59
      title: "RadarV2Pipeline class",
60
      path: "/shared/projects/hermes/main.py",
61
      snippet: "class RadarV2Pipeline - signal generation, Grok API integration, market scoring",
62
      score: 0.91,
63
      last_seen: "2026-06-23T17:15:00Z",
64
      confidence: 0.89,
65
    },
66
    {
67
      engine: "proxmox-api",
68
      title: "CT-REDACTED - hermes container",
69
      path: "pve-gpu/lxc/210",
70
      snippet: "Container running on pve-gpu (REDACTED-IP). Resources: 2c/2GB/30GB.",
71
      score: 0.88,
72
      last_seen: "2026-06-23T18:55:00Z",
73
      confidence: 0.99,
74
    },
75
    {
76
      engine: "memory-graph",
77
      title: "Hermes entity",
78
      path: "graph:hermes-v25",
79
      snippet: "Bot active. Auto-execute mode. Last deploy 2026-06-22. Radar v2 pipeline live.",
80
      score: 0.84,
81
      last_seen: "2026-06-23T16:00:00Z",
82
      confidence: 0.82,
83
    },
84
    {
85
      engine: "serena",
86
      title: "KalshiClient.place_order()",
87
      path: "/shared/projects/hermes/main.py#L2104",
88
      snippet: "async def place_order(self, ticker: str, count: int, side: str, price: float) -> dict",
89
      score: 0.79,
90
      last_seen: "2026-06-23T14:30:00Z",
91
      confidence: 0.77,
92
    },
93
  ],
94
  conflicts: [],
95
  engines: [
96
    { engine: "homelab-rag", status: "up", ms: 42 },
97
    { engine: "cbm-homelab", status: "up", ms: 88 },
98
    { engine: "serena", status: "up", ms: 134 },
99
    { engine: "memory-graph", status: "up", ms: 22 },
100
    { engine: "proxmox-api", status: "up", ms: 61 },
101
  ],
102
  took_ms: 312,
103
};
104
 
105
const MOCK_HEALTH_RESPONSE: HealthResponse = {
106
  engines: [
107
    { engine: "proxmox", status: "up", last_ingest: "2026-06-23T18:55:00Z", staleness_h: 0.08 },
108
    { engine: "white-pc", status: "up", last_ingest: "2026-06-23T17:30:00Z", staleness_h: 1.4 },
109
    { engine: "3060", status: "up", last_ingest: "2026-06-23T18:45:00Z", staleness_h: 0.17 },
110
    { engine: "browser-history", status: "down", last_ingest: "2026-06-22T08:00:00Z", staleness_h: 34.9 },
111
    { engine: "agents", status: "up", last_ingest: "2026-06-23T18:58:00Z", staleness_h: 0.03 },
112
    { engine: "rag", status: "up", last_ingest: "2026-06-23T18:50:00Z", staleness_h: 0.13 },
113
    { engine: "cbm", status: "up", last_ingest: "2026-06-23T17:15:00Z", staleness_h: 1.73 },
114
    { engine: "serena", status: "up", last_ingest: "2026-06-23T18:00:00Z", staleness_h: 0.97 },
115
    { engine: "memgraph", status: "up", last_ingest: "2026-06-23T16:00:00Z", staleness_h: 2.97 },
116
    { engine: "inbox", status: "up", last_ingest: "2026-06-23T18:59:00Z", staleness_h: 0.02 },
117
  ],
118
  ok: true,
119
};
120
 
121
 
122
const CORTEX_URL_DEFAULT = "http://REDACTED-IP:9890";
123
 
124
function getCortexUrl(): string {
125
  if (typeof window === "undefined") return CORTEX_URL_DEFAULT;
126
  return (process.env.NEXT_PUBLIC_CORTEX_URL as string) || CORTEX_URL_DEFAULT;
127
}
128
 
129
export async function ask(query: string): Promise<AskResponse> {
130
  const base = getCortexUrl();
131
  try {
132
    const res = await fetch(`${base}/ask`, {
133
      method: "POST",
134
      headers: { "Content-Type": "application/json" },
135
      body: JSON.stringify({ query }),
136
      signal: AbortSignal.timeout(30_000),
137
      cache: "no-store",
138
    });
139
    if (!res.ok) throw new Error(`HTTP ${res.status}`);
140
    return (await res.json()) as AskResponse;
141
  } catch (err) {
142
    console.warn("[darwin] /ask failed, using mock:", err);
143
    return simulateDelay(MOCK_ASK_RESPONSE);
144
  }
145
}
146
 
147
export async function health(): Promise<HealthResponse> {
148
  const base = getCortexUrl();
149
  try {
150
    const res = await fetch(`${base}/health`, {
151
      signal: AbortSignal.timeout(8_000),
152
      cache: "no-store",
153
    });
154
    if (!res.ok) throw new Error(`HTTP ${res.status}`);
155
    return (await res.json()) as HealthResponse;
156
  } catch (err) {
157
    console.warn("[darwin] /health failed, using mock:", err);
158
    return simulateDelay(MOCK_HEALTH_RESPONSE, 200);
159
  }
160
}
161
 
162
function simulateDelay<T>(data: T, ms = 800): Promise<T> {
163
  return new Promise((resolve) => setTimeout(() => resolve(data), ms));
164
}