Repository navigation
Add hermes-os driver (HTTP-based, wraps Tony's Agent OS hub) #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| // End-to-end smoke test for the hermes-os driver against a live hub. | ||
| // | ||
| // Run from the OpenMausBot checkout: | ||
| // HERMES_OS_URL=http://server.tail85e19.ts.net:8001 \ | ||
| // node --experimental-strip-types scripts/smoke-hermes-os.ts | ||
| // | ||
| // Or run on the homelab server itself (where :8001 is local): | ||
| // HERMES_OS_URL=http://127.0.0.1:8001 node --experimental-strip-types scripts/smoke-hermes-os.ts | ||
| // | ||
| // The script: | ||
| // 1. constructs the driver with HERMES_OS_URL | ||
| // 2. asks the hub for /v1/models to confirm reachability | ||
| // 3. sends a single turn with the default model | ||
| // 4. streams content.delta events to stdout as they arrive | ||
| // 5. prints the final turn summary | ||
| // 6. exits 0 on success, 1 on failure | ||
| // | ||
| // Designed to be safe to run from cron or a watchdog — no side effects, | ||
| // no writes to disk outside the native-log dir. | ||
|
|
||
| import { HermesOsDriver } from "../server/drivers/hermes-os.ts"; | ||
|
|
||
| const baseUrl = process.env.HERMES_OS_URL ?? "http://127.0.0.1:8001"; | ||
| const model = process.env.HERMES_OS_MODEL ?? "gemini"; | ||
| const prompt = process.env.HERMES_OS_PROMPT ?? "Reply with exactly: hermes-os smoke ok"; | ||
| const apiKey = process.env.HUB_API_TOKEN; | ||
|
|
||
| async function main(): Promise<number> { | ||
| console.log(`[smoke] baseUrl=${baseUrl} model=${model} auth=${apiKey ? "yes" : "no"}`); | ||
|
|
||
| const cfg = HermesOsDriver.decodeConfig({ baseUrl, apiKey, defaultModel: model }); | ||
| const instance = await HermesOsDriver.create({ | ||
| instanceId: "smoke", | ||
| displayName: "smoke", | ||
| environment: {}, | ||
| enabled: true, | ||
| config: cfg, | ||
| }); | ||
|
|
||
| // 1. reachability | ||
| const snap = await instance.snapshot(); | ||
| console.log(`[smoke] snapshot: state=${snap.state} reason=${snap.reason ?? "n/a"}`); | ||
| if (snap.state !== "available") { | ||
| console.error(`[smoke] hub unreachable; aborting`); | ||
| await instance.dispose(); | ||
| return 1; | ||
| } | ||
|
|
||
| // 2. send turn | ||
| let text = ""; | ||
| let deltas = 0; | ||
| let usage: { input: number; output: number } | null = null; | ||
| let stopReason: string | null = null; | ||
| let ok = false; | ||
| let errors: string[] = []; | ||
| let sessionId: string | null = null; | ||
|
|
||
| const done = new Promise<void>((resolve) => { | ||
| const unsub = instance.adapter.onEvent((e) => { | ||
| switch (e.type) { | ||
| case "session.started": | ||
| sessionId = e.sessionId; | ||
| console.log(`[smoke] session.started sessionId=${e.sessionId} model=${e.model}`); | ||
| break; | ||
| case "turn.started": | ||
| console.log(`[smoke] turn.started`); | ||
| break; | ||
| case "content.delta": | ||
| deltas++; | ||
| process.stdout.write(e.delta); | ||
| break; | ||
| case "item.completed": | ||
| if (e.itemType === "assistant_text") text = e.text; | ||
| break; | ||
| case "thread.token-usage.updated": | ||
| usage = { input: e.input, output: e.output }; | ||
| break; | ||
| case "turn.completed": | ||
| ok = e.ok; | ||
| stopReason = e.stopReason ?? null; | ||
| break; | ||
| case "session.exited": | ||
| console.log(`\n[smoke] session.exited reason=${e.reason}`); | ||
| unsub(); | ||
| resolve(); | ||
| break; | ||
| case "runtime.error": | ||
| errors.push(e.message); | ||
| break; | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| await instance.adapter.sendTurn({ | ||
| threadId: `smoke-${Date.now()}`, | ||
| text: prompt, | ||
| model, | ||
| }); | ||
| await done; | ||
| await instance.dispose(); | ||
|
|
||
| console.log(`[smoke] deltas=${deltas} ok=${ok} stopReason=${stopReason} text=${JSON.stringify(text.slice(0, 200))}`); | ||
| if (usage) console.log(`[smoke] usage: in=${usage.input} out=${usage.output}`); | ||
| if (errors.length) console.log(`[smoke] errors: ${JSON.stringify(errors)}`); | ||
|
|
||
| if (!ok || !text) { | ||
| console.error(`[smoke] FAILED: ok=${ok} text-empty=${!text}`); | ||
| return 1; | ||
| } | ||
| if (sessionId == null) { | ||
| console.error(`[smoke] FAILED: no sessionId`); | ||
| return 1; | ||
| } | ||
|
Comment on lines
+110
to
+113
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Do not require a non-null At Lines 110-113, the smoke test fails when 🤖 Prompt for AI Agents |
||
| console.log(`[smoke] OK`); | ||
| return 0; | ||
| } | ||
|
|
||
| main().then((code) => process.exit(code)).catch((e) => { | ||
| console.error(`[smoke] crashed:`, e); | ||
| process.exit(2); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,237 @@ | ||
| // hermes-os driver smoke test | ||
| // | ||
| // Spins up a tiny mock HTTP server that mimics hermes-os's | ||
| // /v1/chat/completions SSE response, then exercises the driver | ||
| // end-to-end. Verifies: | ||
| // - the driver emits the canonical session/turn/item event sequence | ||
| // - SSE content.delta events are reconstructed into a single | ||
| // item.completed: assistant_text | ||
| // - usage and turn completion are reported | ||
| // - a non-2xx response produces a runtime.error + turn.completed(ok=false) | ||
| // - a server that's unreachable produces an unavailable snapshot | ||
| // - defaultConfig() is callable without args | ||
| // | ||
| // Run with: pnpm vitest run server/drivers/hermes-os.test.ts | ||
|
|
||
| import { afterEach, describe, expect, it } from "vitest"; | ||
| import { createServer, type IncomingMessage, type ServerResponse } from "node:http"; | ||
| import { AddressInfo } from "node:net"; | ||
| import { HermesOsDriver } from "./hermes-os.ts"; | ||
| import type { RuntimeEvent, SendTurnInput } from "../contracts.ts"; | ||
|
|
||
| let server: ReturnType<typeof createServer> | null = null; | ||
| let baseUrl = ""; | ||
|
|
||
| function startMock(handler: (req: IncomingMessage, res: ServerResponse, body: string) => Promise<void> | void) { | ||
| return new Promise<void>((resolve) => { | ||
| server = createServer(async (req, res) => { | ||
| let body = ""; | ||
| for await (const chunk of req) body += chunk; | ||
| try { | ||
| await handler(req, res, body); | ||
| } catch (e: any) { | ||
| try { res.statusCode = 500; res.end(JSON.stringify({ error: e?.message ?? String(e) })); } catch {} | ||
| } | ||
| }); | ||
| server.listen(0, "127.0.0.1", () => { | ||
| const addr = server!.address() as AddressInfo; | ||
| baseUrl = `http://127.0.0.1:${addr.port}`; | ||
| resolve(); | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| function stopMock(): Promise<void> { | ||
| return new Promise((resolve) => { | ||
| if (!server) return resolve(); | ||
| server.close(() => { server = null; resolve(); }); | ||
| }); | ||
| } | ||
|
|
||
| function drain(instance: Awaited<ReturnType<typeof HermesOsDriver["create"]>>, turn: SendTurnInput): Promise<RuntimeEvent[]> { | ||
| return new Promise(async (resolve, reject) => { | ||
| const events: RuntimeEvent[] = []; | ||
| const unsub = instance.adapter.onEvent((e) => events.push(e)); | ||
| try { | ||
| await instance.adapter.sendTurn(turn); | ||
| } catch (e) { reject(e); } | ||
| unsub(); | ||
| resolve(events); | ||
| }); | ||
|
Comment on lines
+51
to
+60
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -eu
file="server/drivers/hermes-os.test.ts"
printf '%s\n' '--- target source ---'
cat -n "$file" | sed -n '35,75p'
printf '%s\n' '--- related symbols and call sites ---'
rg -n -C 3 'function drain|drain\(' "$file"
printf '%s\n' '--- Biome configuration and scripts ---'
rg -n -C 2 '"(biome|lint|check)"|async.*Promise|noAsyncPromiseExecutor' \
package.json biome.json biome.jsonc . 2>/dev/null | head -200
printf '%s\n' '--- repository status ---'
git diff --stat -- "$file"Repository: milind-soni/OpenMausBot Length of output: 14614 🏁 Script executed: #!/bin/bash
set -eu
python3 - <<'PY'
from pathlib import Path
import re
path = Path("server/drivers/hermes-os.test.ts")
text = path.read_text()
match = re.search(
r'function drain\([\s\S]*?\n\}',
text,
)
if not match:
raise SystemExit("drain function not found")
source = match.group(0)
print(source)
print("\nbehavioral checks:")
print("async Promise executor:", bool(re.search(r'new Promise\s*\(\s*async\b', source)))
print("catch rejects then resolves:", bool(re.search(r'catch\s*\([^)]*\)\s*\{\s*reject\([^)]*\);\s*\}', source)))
print("unsubscribe is in finally:", bool(re.search(r'finally\s*\{[\s\S]*?unsub\(\)', source)))
print("return events on success:", bool(re.search(r'return\s+events', source)))
PYRepository: milind-soni/OpenMausBot Length of output: 720 🏁 Script executed: #!/bin/bash
set -eu
python3 - <<'PY'
from pathlib import Path
import re
path = Path("server/drivers/hermes-os.test.ts")
text = path.read_text()
match = re.search(r'function drain\([\s\S]*?\n\}', text)
if not match:
raise SystemExit("drain function not found")
source = match.group(0)
print(source)
print("\nbehavioral checks:")
print("async Promise executor:", bool(re.search(r'new Promise\s*\(\s*async\b', source)))
print("catch rejects then resolves:", bool(re.search(r'catch\s*\([^)]*\)\s*\{\s*reject\([^)]*\);\s*\}', source)))
print("unsubscribe is in finally:", bool(re.search(r'finally\s*\{[\s\S]*?unsub\(\)', source)))
print("return events on success:", bool(re.search(r'return\s+events', source)))
PYRepository: milind-soni/OpenMausBot Length of output: 720 🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- tracked Biome/config files ---'
git ls-files | rg '(^|/)(package\.json|biome(\.jsonc?)?|.*biome.*)$' || true
printf '%s\n' '--- package scripts and dependencies ---'
if [ -f package.json ]; then
node - <<'JS'
const p = require("./package.json");
console.log(JSON.stringify({
scripts: p.scripts ?? {},
dependencies: p.dependencies ?? {},
devDependencies: p.devDependencies ?? {}
}, null, 2));
JS
fi
printf '%s\n' '--- lint rule references ---'
rg -n -i -C 2 'noAsyncPromiseExecutor|async.?promise.?executor|biome' \
--glob '!node_modules/**' --glob '!dist/**' --glob '!build/**' . || trueRepository: milind-soni/OpenMausBot Length of output: 1478 Remove the async Promise executor. If 🧰 Tools🪛 Biome (2.5.6)[error] 52-60: Promise executor functions should not be (lint/suspicious/noAsyncPromiseExecutor) 🤖 Prompt for AI AgentsSource: Linters/SAST tools |
||
| } | ||
|
|
||
| describe("hermes-os driver", () => { | ||
| afterEach(async () => { await stopMock(); }); | ||
|
|
||
| it("defaultConfig is callable without args", () => { | ||
| const cfg = HermesOsDriver.defaultConfig(); | ||
| expect(cfg.baseUrl).toMatch(/^https?:\/\//); | ||
| expect(cfg.defaultModel).toBe("gemini"); | ||
| }); | ||
|
|
||
| it("decodeConfig rejects missing baseUrl", () => { | ||
| expect(() => HermesOsDriver.decodeConfig({})).toThrow(/baseUrl/); | ||
| }); | ||
|
|
||
| it("decodeConfig strips trailing slashes and /v1 suffix", () => { | ||
| const a = HermesOsDriver.decodeConfig({ baseUrl: "http://h:8001/" }); | ||
| const b = HermesOsDriver.decodeConfig({ baseUrl: "http://h:8001/v1" }); | ||
| const c = HermesOsDriver.decodeConfig({ baseUrl: "http://h:8001/openai/v1" }); | ||
| expect(a.baseUrl).toBe("http://h:8001"); | ||
| expect(b.baseUrl).toBe("http://h:8001"); | ||
| expect(c.baseUrl).toBe("http://h:8001"); | ||
| }); | ||
|
|
||
| it("snapshot is unavailable when hub is unreachable", async () => { | ||
| // Pick a port nothing is bound to | ||
| const cfg = HermesOsDriver.decodeConfig({ baseUrl: "http://127.0.0.1:1" }); | ||
| const inst = await HermesOsDriver.create({ | ||
| instanceId: "test-1", | ||
| displayName: "test", | ||
| environment: {}, | ||
| enabled: true, | ||
| config: cfg, | ||
| }); | ||
| const snap = await inst.snapshot(); | ||
| expect(snap.state).toBe("unavailable"); | ||
| expect(snap.reason).toBeTruthy(); | ||
| await inst.dispose(); | ||
| }); | ||
|
|
||
| it("snapshot is available when hub /v1/models responds", async () => { | ||
| await startMock((req, res, _body) => { | ||
| if (req.url === "/v1/models") { | ||
| res.setHeader("content-type", "application/json"); | ||
| res.end(JSON.stringify({ data: [{ id: "gemini" }, { id: "openai" }] })); | ||
| return; | ||
| } | ||
| res.statusCode = 404; res.end(); | ||
| }); | ||
| const cfg = HermesOsDriver.decodeConfig({ baseUrl }); | ||
| const inst = await HermesOsDriver.create({ | ||
| instanceId: "test-2", | ||
| displayName: "test", | ||
| environment: {}, | ||
| enabled: true, | ||
| config: cfg, | ||
| }); | ||
| const snap = await inst.snapshot(); | ||
| expect(snap.state).toBe("available"); | ||
| await inst.dispose(); | ||
| }); | ||
|
|
||
| it("emits canonical event sequence for a successful SSE turn", async () => { | ||
| await startMock((req, res, _body) => { | ||
| if (req.url === "/v1/models") { | ||
| res.setHeader("content-type", "application/json"); | ||
| res.end(JSON.stringify({ data: [{ id: "gemini" }] })); | ||
| return; | ||
| } | ||
| if (req.url === "/v1/chat/completions") { | ||
| res.writeHead(200, { "content-type": "text/event-stream" }); | ||
| // one big string so the chunks the test sees are deterministic | ||
| const body = | ||
| `data: {"id":"x1","choices":[{"delta":{"content":"Hello"}}]}\n\n` + | ||
| `data: {"id":"x2","choices":[{"delta":{"content":", world"}}]}\n\n` + | ||
| `data: {"id":"x3","choices":[{"delta":{"content":"!"},"finish_reason":"stop"}],"usage":{"prompt_tokens":7,"completion_tokens":3}}\n\n` + | ||
| `data: [DONE]\n\n`; | ||
| res.end(body); | ||
| return; | ||
| } | ||
| res.statusCode = 404; res.end(); | ||
| }); | ||
| const cfg = HermesOsDriver.decodeConfig({ baseUrl, defaultModel: "gemini" }); | ||
| const inst = await HermesOsDriver.create({ | ||
| instanceId: "test-3", | ||
| displayName: "test", | ||
| environment: {}, | ||
| enabled: true, | ||
| config: cfg, | ||
| }); | ||
| const events = await drain(inst, { threadId: "t1", text: "hi", model: "gemini" }); | ||
|
|
||
| const types = events.map((e) => e.type); | ||
| expect(types[0]).toBe("session.started"); | ||
| expect(types).toContain("turn.started"); | ||
| expect(types).toContain("content.delta"); | ||
| expect(types).toContain("item.completed"); | ||
| expect(types).toContain("turn.completed"); | ||
| expect(types[types.length - 1]).toBe("session.exited"); | ||
|
|
||
| // delta count | ||
| const deltas = events.filter((e) => e.type === "content.delta"); | ||
| expect(deltas).toHaveLength(3); | ||
| expect(deltas.map((d) => (d as any).delta).join("")).toBe("Hello, world!"); | ||
|
|
||
| // final item | ||
| const final = events.find((e) => e.type === "item.completed" && (e as any).itemType === "assistant_text") as any; | ||
| expect(final?.text).toBe("Hello, world!"); | ||
|
|
||
| // turn completion reports success | ||
| const completed = events.find((e) => e.type === "turn.completed") as any; | ||
| expect(completed?.ok).toBe(true); | ||
| expect(completed?.stopReason).toBe("stop"); | ||
|
|
||
| // usage event | ||
| const usage = events.find((e) => e.type === "thread.token-usage.updated") as any; | ||
| expect(usage?.input).toBe(7); | ||
| expect(usage?.output).toBe(3); | ||
|
|
||
| await inst.dispose(); | ||
| }); | ||
|
|
||
| it("emits runtime.error + failed turn on non-2xx response", async () => { | ||
| await startMock((req, res, _body) => { | ||
| if (req.url === "/v1/models") { | ||
| res.setHeader("content-type", "application/json"); | ||
| res.end(JSON.stringify({ data: [] })); | ||
| return; | ||
| } | ||
| if (req.url === "/v1/chat/completions") { | ||
| res.statusCode = 429; | ||
| res.end(JSON.stringify({ error: { message: "rate limit" } })); | ||
| return; | ||
| } | ||
| res.statusCode = 404; res.end(); | ||
| }); | ||
| const cfg = HermesOsDriver.decodeConfig({ baseUrl }); | ||
| const inst = await HermesOsDriver.create({ | ||
| instanceId: "test-4", | ||
| displayName: "test", | ||
| environment: {}, | ||
| enabled: true, | ||
| config: cfg, | ||
| }); | ||
| const events = await drain(inst, { threadId: "t2", text: "hi" }); | ||
| const err = events.find((e) => e.type === "runtime.error") as any; | ||
| expect(err?.message).toMatch(/429/); | ||
| const completed = events.find((e) => e.type === "turn.completed") as any; | ||
| expect(completed?.ok).toBe(false); | ||
| expect(completed?.stopReason).toBe("rate_limit"); | ||
| await inst.dispose(); | ||
| }); | ||
|
|
||
| it("forwards Authorization header when apiKey is set", async () => { | ||
| let seenAuth: string | null = null; | ||
| await startMock((req, res, _body) => { | ||
| if (req.url === "/v1/models") { | ||
| seenAuth = req.headers["authorization"] ?? null; | ||
| res.setHeader("content-type", "application/json"); | ||
| res.end(JSON.stringify({ data: [] })); | ||
| return; | ||
| } | ||
| res.statusCode = 404; res.end(); | ||
| }); | ||
| const cfg = HermesOsDriver.decodeConfig({ baseUrl, apiKey: "secret-token-123" }); | ||
| const inst = await HermesOsDriver.create({ | ||
| instanceId: "test-5", | ||
| displayName: "test", | ||
| environment: {}, | ||
| enabled: true, | ||
| config: cfg, | ||
| }); | ||
| await inst.snapshot(); | ||
| expect(seenAuth).toBe("Bearer secret-token-123"); | ||
| await inst.dispose(); | ||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win
Do not log the raw hub URL.
At Line 29,
HERMES_OS_URLcan contain URL userinfo or query credentials. A cron or CI runner can retain stdout. Log a redacted URL or only its origin.Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents
Source: Linters/SAST tools