hatz-provider 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,18 @@
1
+ # Changelog
2
+
3
+ ## [1.0.0] — 2026-07-21
4
+
5
+ ### Added
6
+ - Initial release: Hatz AI provider installer for coding agents
7
+ - Multi-agent support: omp, pi, Claude Code, Hermes, OpenClaw
8
+ - Live model catalog fetch from Hatz API (80+ models)
9
+ - `install` / `update` / `uninstall` / `status` / `list` / `catalog` commands
10
+ - Auto-detection of installed agents
11
+ - Per-agent API surface selection (anthropic-messages vs openai-completions)
12
+ - Guard-commented config blocks — safe to merge with existing configs
13
+ - Zero hardcoded secrets — API key always from environment
14
+
15
+ ### Design decisions
16
+ - **Anthropic Messages** for omp/pi/claude-code: proper SSE streaming, full event payloads
17
+ - **OpenAI Completions** for hermes/openclaw: only OpenAI-compatible surfaces supported
18
+ - **Literal API keys** in config files: agents that don't resolve `$VAR` env references get the key directly; pi resolves `$HATZ_API_KEY` natively
package/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # @hatz-ai/provider
2
+
3
+ **One command, five agents.** Install Hatz AI as a provider for any coding agent.
4
+
5
+ ```bash
6
+ export HATZ_API_KEY="your-key"
7
+ npx @hatz-ai/provider install
8
+ ```
9
+
10
+ ## Supported Agents
11
+
12
+ | Agent | Config | API surface |
13
+ |-------|--------|-------------|
14
+ | [omp](https://omp.sh) | `~/.omp/agent/models.yml` | anthropic-messages |
15
+ | [pi](https://pi.dev) | `~/.pi/extensions/hatz/` | anthropic-messages |
16
+ | [Claude Code](https://claude.ai) | `~/.claude/.env` | anthropic-messages |
17
+ | [Hermes](https://hermesagent.com) | `~/.hermes/config.yaml` + `.env` | openai-completions |
18
+ | [OpenClaw](https://openclaw.ai) | `~/.openclaw/openclaw.json` | openai-completions |
19
+
20
+ ## Quick Start
21
+
22
+ ```bash
23
+ # One-time: set your Hatz API key
24
+ export HATZ_API_KEY="hzat-..."
25
+
26
+ # Install for all detected agents
27
+ npx @hatz-ai/provider install
28
+
29
+ # Or target one
30
+ npx @hatz-ai/provider install omp
31
+ npx @hatz-ai/provider install claude-code
32
+ ```
33
+
34
+ ## Commands
35
+
36
+ ```
37
+ hatz-provider install [agent] Install for one or all agents
38
+ hatz-provider update [agent] Refresh models from live catalog
39
+ hatz-provider uninstall [agent] Remove from one or all agents
40
+ hatz-provider status Show install status across agents
41
+ hatz-provider list List all 80+ available Hatz models
42
+ hatz-provider catalog Print omp models.yml block
43
+ ```
44
+
45
+ ## Model Updates
46
+
47
+ Re-run `install` or `update` anytime to refresh from Hatz's live catalog. Only the Hatz block in each agent's config is touched — other providers are safe.
48
+
49
+ ## API Key
50
+
51
+ Generate from **Workspace > API Keys** in your [Hatz dashboard](https://ai.hatz.ai).
52
+
53
+ ```bash
54
+ export HATZ_API_KEY="hzat-..."
55
+ # or add to ~/.bashrc / ~/.zshrc
56
+ ```
57
+
58
+ ## How It Works
59
+
60
+ Each agent gets the appropriate config format and API surface:
61
+
62
+ - **omp, pi, Claude Code** → Anthropic Messages gateway (`https://ai.hatz.ai/v1/anthropic`) — proper SSE streaming, full event payloads
63
+ - **Hermes, OpenClaw** → OpenAI Chat Completions (`https://ai.hatz.ai/v1`) — standard OpenAI-compatible endpoint
64
+
65
+ The installer fetches Hatz's live model catalog (80+ models across Anthropic, OpenAI, Google, xAI, DeepSeek, Meta, Mistral, and more) and writes the appropriate config for each agent.
66
+
67
+ ## Publishing
68
+
69
+ This package is published to npm from a private source repository:
70
+
71
+ ```bash
72
+ # From the private repo
73
+ cd providers/hatz
74
+ npm version patch # bump version
75
+ npm publish --access public
76
+ ```
77
+
78
+ The published tarball contains only the files listed in `package.json#files`. No secrets, tokens, or private-repo internals are included.
package/cli.js ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env node
2
+ import { spawn } from "node:child_process";
3
+ import { dirname, join } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+
6
+ const __dirname = dirname(fileURLToPath(import.meta.url));
7
+ const cli = join(__dirname, "src", "cli.ts");
8
+ const child = spawn("bun", ["run", cli, ...process.argv.slice(2)], {
9
+ stdio: "inherit",
10
+ env: process.env,
11
+ });
12
+ child.on("exit", (code) => process.exit(code ?? 1));
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "hatz-provider",
3
+ "version": "1.0.0",
4
+ "description": "Hatz AI provider installer for coding agents — omp, pi, hermes, claude-code, openclaw",
5
+ "type": "module",
6
+ "bin": {
7
+ "hatz-provider": "./cli.js"
8
+ },
9
+ "files": [
10
+ "src",
11
+ "cli.js",
12
+ "README.md",
13
+ "CHANGELOG.md"
14
+ ],
15
+ "keywords": [
16
+ "hatz",
17
+ "hatz-ai",
18
+ "provider",
19
+ "llm",
20
+ "ai",
21
+ "omp",
22
+ "oh-my-pi",
23
+ "pi",
24
+ "hermes",
25
+ "claude-code",
26
+ "openclaw",
27
+ "gateway"
28
+ ],
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://github.com/GodSpoon/ai-tooling.git",
32
+ "directory": "providers/hatz"
33
+ },
34
+ "license": "MIT"
35
+ }
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Claude Code config generator.
3
+ *
4
+ * Sets ANTHROPIC_BASE_URL + ANTHROPIC_API_KEY env vars.
5
+ * Writes to ~/.claude/.env (shell-sourced) and offers shell profile option.
6
+ */
7
+ import { writeFile, mkdir, readFile } from "node:fs/promises";
8
+ import { homedir } from "node:os";
9
+ import { join } from "node:path";
10
+ import type { HatzModel } from "../catalog";
11
+
12
+ const ENV_FILE = join(homedir(), ".claude", ".env");
13
+ const BASE_URL = "https://ai.hatz.ai/v1/anthropic";
14
+
15
+ export function agentName(): string {
16
+ return "Claude Code";
17
+ }
18
+
19
+ export async function isInstalled(): Promise<boolean> {
20
+ try {
21
+ const content = await readFile(ENV_FILE, "utf-8");
22
+ return content.includes("# === Hatz AI ===");
23
+ } catch {
24
+ return false;
25
+ }
26
+ }
27
+
28
+ export async function install(models: HatzModel[], apiKey: string): Promise<void> {
29
+ await mkdir(join(homedir(), ".claude"), { recursive: true });
30
+
31
+ const block = [
32
+ "# === Hatz AI ===",
33
+ `ANTHROPIC_BASE_URL=${BASE_URL}`,
34
+ `ANTHROPIC_API_KEY=${apiKey}`,
35
+ "# Model aliases: sonnet, opus, haiku resolve to latest Claude family models",
36
+ `# Available: ${models.filter(m => m.developer === "Anthropic").map(m => m.name).slice(0, 5).join(", ")}...`,
37
+ "# === end Hatz AI ===",
38
+ ].join("\n") + "\n";
39
+
40
+ let existing = "";
41
+ try { existing = await readFile(ENV_FILE, "utf-8"); } catch { /* new file */ }
42
+
43
+ const guard = "# === Hatz AI ===";
44
+ const guardEnd = "# === end Hatz AI ===";
45
+ const start = existing.indexOf(guard);
46
+ const end = existing.indexOf(guardEnd);
47
+ if (start !== -1 && end !== -1) {
48
+ existing = existing.slice(0, start) + existing.slice(end + guardEnd.length);
49
+ }
50
+
51
+ await writeFile(ENV_FILE, [existing.trimEnd(), block].filter(Boolean).join("\n\n") + "\n", "utf-8");
52
+ }
53
+
54
+ export async function uninstall(): Promise<void> {
55
+ let content = "";
56
+ try { content = await readFile(ENV_FILE, "utf-8"); } catch { return; }
57
+ const guard = "# === Hatz AI ===";
58
+ const guardEnd = "# === end Hatz AI ===";
59
+ const start = content.indexOf(guard);
60
+ const end = content.indexOf(guardEnd);
61
+ if (start !== -1 && end !== -1) {
62
+ content = content.slice(0, start) + content.slice(end + guardEnd.length);
63
+ await writeFile(ENV_FILE, content.trimEnd() + "\n", "utf-8");
64
+ }
65
+ }
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Hermes agent config generator.
3
+ *
4
+ * Writes to ~/.hermes/config.yaml + ~/.hermes/.env
5
+ * Uses openai-completions API (Hermes is OpenAI-compatible only).
6
+ */
7
+ import { writeFile, mkdir, readFile } from "node:fs/promises";
8
+ import { homedir } from "node:os";
9
+ import { join } from "node:path";
10
+ import type { HatzModel } from "../catalog";
11
+
12
+ const HERMES_DIR = join(homedir(), ".hermes");
13
+ const CONFIG_PATH = join(HERMES_DIR, "config.yaml");
14
+ const ENV_PATH = join(HERMES_DIR, ".env");
15
+ const BASE_URL = "https://ai.hatz.ai/v1";
16
+ const API = "openai-completions";
17
+ const GUARD = "# === Hatz AI ===";
18
+ const GUARD_END = "# === end Hatz AI ===";
19
+
20
+ export function agentName(): string {
21
+ return "Hermes Agent";
22
+ }
23
+
24
+ export async function isInstalled(): Promise<boolean> {
25
+ try {
26
+ const content = await readFile(CONFIG_PATH, "utf-8");
27
+ return content.includes(GUARD);
28
+ } catch {
29
+ return false;
30
+ }
31
+ }
32
+
33
+ export async function install(models: HatzModel[], apiKey: string): Promise<void> {
34
+ await mkdir(HERMES_DIR, { recursive: true });
35
+
36
+ // Write .env with API key
37
+ const envBlock = [
38
+ GUARD,
39
+ `HATZ_API_KEY=${apiKey}`,
40
+ GUARD_END,
41
+ ].join("\n") + "\n";
42
+
43
+ let existingEnv = "";
44
+ try { existingEnv = await readFile(ENV_PATH, "utf-8"); } catch { /* new */ }
45
+ const envStart = existingEnv.indexOf(GUARD);
46
+ const envEnd = existingEnv.indexOf(GUARD_END);
47
+ if (envStart !== -1 && envEnd !== -1) {
48
+ existingEnv = existingEnv.slice(0, envStart) + existingEnv.slice(envEnd + GUARD_END.length);
49
+ }
50
+ await writeFile(ENV_PATH, [existingEnv.trimEnd(), envBlock].filter(Boolean).join("\n\n") + "\n", "utf-8");
51
+
52
+ // Write config.yaml with provider definition
53
+ const modelIds = models.map(m => `hatz/${m.name}`).join("\n");
54
+ const configBlock = [
55
+ GUARD,
56
+ "# Hermes uses the standard OpenAI chat completions endpoint.",
57
+ `# Base URL: ${BASE_URL}`,
58
+ "# API key: $HATZ_API_KEY (from ~/.hermes/.env)",
59
+ "#",
60
+ "# Add models to your defaults:",
61
+ "# models:",
62
+ "# - hatz/gpt-5.2",
63
+ "# - hatz/anthropic.claude-sonnet-4-5",
64
+ "#",
65
+ "# Run `hermes doctor` to verify after setup.",
66
+ GUARD_END,
67
+ ].join("\n") + "\n";
68
+
69
+ let existingConfig = "";
70
+ try { existingConfig = await readFile(CONFIG_PATH, "utf-8"); } catch { /* new */ }
71
+ const cfgStart = existingConfig.indexOf(GUARD);
72
+ const cfgEnd = existingConfig.indexOf(GUARD_END);
73
+ if (cfgStart !== -1 && cfgEnd !== -1) {
74
+ existingConfig = existingConfig.slice(0, cfgStart) + existingConfig.slice(cfgEnd + GUARD_END.length);
75
+ }
76
+ await writeFile(CONFIG_PATH, [existingConfig.trimEnd(), configBlock].filter(Boolean).join("\n\n") + "\n", "utf-8");
77
+ }
78
+
79
+ export async function uninstall(): Promise<void> {
80
+ for (const path of [CONFIG_PATH, ENV_PATH]) {
81
+ try {
82
+ let content = await readFile(path, "utf-8");
83
+ const start = content.indexOf(GUARD);
84
+ const end = content.indexOf(GUARD_END);
85
+ if (start !== -1 && end !== -1) {
86
+ content = content.slice(0, start) + content.slice(end + GUARD_END.length);
87
+ await writeFile(path, content.trimEnd() + "\n", "utf-8");
88
+ }
89
+ } catch { /* didn't exist */ }
90
+ }
91
+ }
@@ -0,0 +1,77 @@
1
+ /**
2
+ * omp (Oh My Pi) config generator.
3
+ *
4
+ * Writes to ~/.omp/agent/models.yml using anthropic-messages API.
5
+ * Guard-commented block, safe to merge with existing config.
6
+ */
7
+ import { readFile, writeFile, mkdir, stat } from "node:fs/promises";
8
+ import { homedir } from "node:os";
9
+ import { join } from "node:path";
10
+ import type { HatzModel } from "../catalog";
11
+ import { estimateContextWindow, clampMaxTokens, inputCapabilities } from "../catalog";
12
+
13
+ const OMP_DIR = join(homedir(), ".omp", "agent");
14
+ const CONFIG_PATH = join(OMP_DIR, "models.yml");
15
+ const GUARD = "# === Hatz AI ===";
16
+ const GUARD_END = "# === end Hatz AI ===";
17
+
18
+ const BASE_URL = "https://ai.hatz.ai/v1/anthropic";
19
+ const API = "anthropic-messages";
20
+
21
+ export function agentName(): string {
22
+ return "omp (Oh My Pi)";
23
+ }
24
+
25
+ export async function isInstalled(): Promise<boolean> {
26
+ try { await stat(CONFIG_PATH); return true; } catch { return false; }
27
+ }
28
+
29
+ export function generateBlock(models: HatzModel[], apiKey: string): string {
30
+ const lines = [GUARD];
31
+ lines.push(" hatz:");
32
+ lines.push(` baseUrl: ${BASE_URL}`);
33
+ lines.push(` api: ${API}`);
34
+ lines.push(` apiKey: "${apiKey}"`);
35
+ lines.push(" models:");
36
+
37
+ for (const m of models) {
38
+ lines.push(` - id: ${m.name}`);
39
+ lines.push(` name: ${m.display_name} (Hatz)`);
40
+ lines.push(` contextWindow: ${estimateContextWindow(m)}`);
41
+ lines.push(` maxTokens: ${clampMaxTokens(m.max_tokens)}`);
42
+ lines.push(" reasoning: true");
43
+ lines.push(` input: ${inputCapabilities(m)}`);
44
+ }
45
+
46
+ lines.push(GUARD_END);
47
+ return lines.join("\n");
48
+ }
49
+
50
+ export async function install(models: HatzModel[], apiKey: string): Promise<void> {
51
+ await mkdir(OMP_DIR, { recursive: true });
52
+
53
+ let existing = "";
54
+ try { existing = await readFile(CONFIG_PATH, "utf-8"); } catch { /* new file */ }
55
+
56
+ const start = existing.indexOf(GUARD);
57
+ const end = existing.indexOf(GUARD_END);
58
+ if (start !== -1 && end !== -1) {
59
+ existing = existing.slice(0, start) + existing.slice(end + GUARD_END.length);
60
+ }
61
+
62
+ const block = generateBlock(models, apiKey);
63
+ const merged = [existing.trimEnd(), block].filter(Boolean).join("\n\n") + "\n";
64
+ await writeFile(CONFIG_PATH, merged, "utf-8");
65
+ }
66
+
67
+ export async function uninstall(): Promise<void> {
68
+ let content = "";
69
+ try { content = await readFile(CONFIG_PATH, "utf-8"); } catch { return; }
70
+
71
+ const start = content.indexOf(GUARD);
72
+ const end = content.indexOf(GUARD_END);
73
+ if (start !== -1 && end !== -1) {
74
+ content = content.slice(0, start) + content.slice(end + GUARD_END.length);
75
+ await writeFile(CONFIG_PATH, content.trimEnd() + "\n", "utf-8");
76
+ }
77
+ }
@@ -0,0 +1,84 @@
1
+ /**
2
+ * OpenClaw config generator.
3
+ *
4
+ * Writes to ~/.openclaw/openclaw.json — merges into existing config.
5
+ * Uses openai-completions API.
6
+ */
7
+ import { readFile, writeFile, mkdir } from "node:fs/promises";
8
+ import { homedir } from "node:os";
9
+ import { join } from "node:path";
10
+ import type { HatzModel } from "../catalog";
11
+ import { estimateContextWindow, clampMaxTokens, inputCapabilities } from "../catalog";
12
+
13
+ const CONFIG_PATH = join(homedir(), ".openclaw", "openclaw.json");
14
+ const BASE_URL = "https://ai.hatz.ai/v1";
15
+ const API = "openai-completions";
16
+ const PROVIDER_ID = "hatz";
17
+
18
+ export function agentName(): string {
19
+ return "OpenClaw";
20
+ }
21
+
22
+ export async function isInstalled(): Promise<boolean> {
23
+ try {
24
+ const raw = await readFile(CONFIG_PATH, "utf-8");
25
+ const cfg = JSON.parse(raw);
26
+ return cfg?.models?.providers?.[PROVIDER_ID] != null;
27
+ } catch {
28
+ return false;
29
+ }
30
+ }
31
+
32
+ export function generateConfig(models: HatzModel[], apiKey: string): Record<string, unknown> {
33
+ return {
34
+ models: {
35
+ providers: {
36
+ [PROVIDER_ID]: {
37
+ baseUrl: BASE_URL,
38
+ apiKey: apiKey,
39
+ api: API,
40
+ models: models.map((m) => ({
41
+ id: m.name,
42
+ name: `${m.display_name} (Hatz)`,
43
+ })),
44
+ },
45
+ },
46
+ },
47
+ };
48
+ }
49
+
50
+ export async function install(models: HatzModel[], apiKey: string): Promise<void> {
51
+ await mkdir(join(homedir(), ".openclaw"), { recursive: true });
52
+
53
+ let cfg: Record<string, unknown> = {};
54
+ try {
55
+ const raw = await readFile(CONFIG_PATH, "utf-8");
56
+ cfg = JSON.parse(raw);
57
+ } catch { /* new file */ }
58
+
59
+ // Deep merge the provider config
60
+ const modelsCfg = (cfg.models as Record<string, unknown>) ?? {};
61
+ const providers = (modelsCfg.providers as Record<string, unknown>) ?? {};
62
+ const newCfg = generateConfig(models, apiKey);
63
+ const newProviders = (newCfg.models as Record<string, unknown>).providers as Record<string, unknown>;
64
+
65
+ cfg.models = { ...modelsCfg, providers: { ...providers, ...newProviders } };
66
+
67
+ await writeFile(CONFIG_PATH, JSON.stringify(cfg, null, 2) + "\n", "utf-8");
68
+ }
69
+
70
+ export async function uninstall(): Promise<void> {
71
+ let cfg: Record<string, unknown> = {};
72
+ try {
73
+ const raw = await readFile(CONFIG_PATH, "utf-8");
74
+ cfg = JSON.parse(raw);
75
+ } catch { return; }
76
+
77
+ const modelsCfg = cfg.models as Record<string, unknown> | undefined;
78
+ if (!modelsCfg) return;
79
+ const providers = modelsCfg.providers as Record<string, unknown> | undefined;
80
+ if (!providers) return;
81
+
82
+ delete providers[PROVIDER_ID];
83
+ await writeFile(CONFIG_PATH, JSON.stringify(cfg, null, 2) + "\n", "utf-8");
84
+ }
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Pi (pi.dev) extension generator.
3
+ *
4
+ * Creates ~/.pi/extensions/hatz/ with package.json + index.ts.
5
+ * Pi resolves $VAR env references in apiKey — no literal key needed.
6
+ */
7
+ import { writeFile, mkdir } from "node:fs/promises";
8
+ import { homedir } from "node:os";
9
+ import { join } from "node:path";
10
+ import type { HatzModel } from "../catalog";
11
+ import { estimateContextWindow, clampMaxTokens, inputCapabilities } from "../catalog";
12
+
13
+ const EXT_DIR = join(homedir(), ".pi", "extensions", "hatz");
14
+ const BASE_URL = "https://ai.hatz.ai/v1/anthropic";
15
+ const API = "anthropic-messages";
16
+
17
+ export function agentName(): string {
18
+ return "pi (pi.dev)";
19
+ }
20
+
21
+ export async function isInstalled(): Promise<boolean> {
22
+ try { await (await import("node:fs/promises")).stat(join(EXT_DIR, "index.ts")); return true; } catch { return false; }
23
+ }
24
+
25
+ function generateIndex(models: HatzModel[]): string {
26
+ const modelDefs = models.map((m) => {
27
+ return ` {
28
+ id: "${m.name}",
29
+ name: "${m.display_name} (Hatz)",
30
+ reasoning: true,
31
+ input: [${m.vision ? '"text", "image"' : '"text"'}],
32
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
33
+ contextWindow: ${estimateContextWindow(m)},
34
+ maxTokens: ${clampMaxTokens(m.max_tokens)},
35
+ }`;
36
+ }).join(",\n");
37
+
38
+ return `import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
39
+
40
+ export default function (pi: ExtensionAPI) {
41
+ pi.registerProvider("hatz", {
42
+ name: "Hatz AI",
43
+ baseUrl: "${BASE_URL}",
44
+ apiKey: "$HATZ_API_KEY",
45
+ api: "${API}",
46
+ models: [
47
+ ${modelDefs}
48
+ ],
49
+ });
50
+ }
51
+ `;
52
+ }
53
+
54
+ export async function install(models: HatzModel[], _apiKey: string): Promise<void> {
55
+ await mkdir(EXT_DIR, { recursive: true });
56
+
57
+ await writeFile(join(EXT_DIR, "package.json"), JSON.stringify({
58
+ name: "pi-extension-hatz",
59
+ version: "1.0.0",
60
+ private: true,
61
+ type: "module",
62
+ main: "index.ts",
63
+ dependencies: {
64
+ "@earendil-works/pi-coding-agent": "*",
65
+ },
66
+ }, null, 2) + "\n", "utf-8");
67
+
68
+ await writeFile(join(EXT_DIR, "index.ts"), generateIndex(models), "utf-8");
69
+ }
70
+
71
+ export async function uninstall(): Promise<void> {
72
+ const { rm } = await import("node:fs/promises");
73
+ try { await rm(EXT_DIR, { recursive: true }); } catch { /* didn't exist */ }
74
+ }
package/src/catalog.ts ADDED
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Hatz AI model catalog — fetches and normalizes the full model list.
3
+ */
4
+
5
+ export interface HatzModel {
6
+ name: string;
7
+ developer: string;
8
+ display_name: string;
9
+ max_tokens: number;
10
+ vision: boolean;
11
+ }
12
+
13
+ const CATALOG_URL = "https://ai.hatz.ai/v1/chat/models";
14
+
15
+ export async function fetchCatalog(apiKey: string): Promise<HatzModel[]> {
16
+ const resp = await fetch(CATALOG_URL, {
17
+ headers: { "X-API-Key": apiKey, Accept: "application/json" },
18
+ });
19
+ if (!resp.ok) throw new Error(`Hatz catalog fetch failed: ${resp.status}`);
20
+ const data = (await resp.json()) as { data?: HatzModel[]; models?: HatzModel[] };
21
+ const models = data.data ?? data.models ?? [];
22
+ return models.filter((m) => m.name !== "auto");
23
+ }
24
+
25
+ /** Estimate context window for a model based on its name/developer. */
26
+ export function estimateContextWindow(model: HatzModel): number {
27
+ const n = model.name;
28
+ if (/gpt.*(5\.[12456]|5-nano|5-mini|5-chat|[o]3|[o]4|4o)/.test(n)) return 128_000;
29
+ if (/gpt-4\.1/.test(n)) return 1_048_576;
30
+ if (/gemini-3|gemini-2\.5/.test(n)) return 1_048_576;
31
+ if (/llama/.test(n)) return 128_000;
32
+ if (/deepseek/.test(n)) return 128_000;
33
+ if (/claude/.test(n)) return 200_000;
34
+ if (/grok/.test(n)) return 131_072;
35
+ if (/kimi|moonshot/.test(n)) return 131_072;
36
+ return 200_000;
37
+ }
38
+
39
+ /** Cap max tokens to a reasonable value. */
40
+ export function clampMaxTokens(raw: number): number {
41
+ return Math.min(raw, 128_000) || 16_384;
42
+ }
43
+
44
+ /** Resolve input modalities. */
45
+ export function inputCapabilities(model: HatzModel): string {
46
+ return model.vision ? "[text, image]" : "[text]";
47
+ }
package/src/cli.ts ADDED
@@ -0,0 +1,153 @@
1
+ #!/usr/bin/env bun
2
+ /**
3
+ * hatz-provider — Hatz AI provider installer for coding agents.
4
+ *
5
+ * Commands:
6
+ * hatz-provider install [agent] Install for one or all agents
7
+ * hatz-provider update [agent] Refresh models (same as install)
8
+ * hatz-provider uninstall [agent] Remove from one or all agents
9
+ * hatz-provider list List available models from Hatz
10
+ * hatz-provider status Show install status across agents
11
+ * hatz-provider catalog Print models.yml block (for omp)
12
+ *
13
+ * Agents: omp, pi, hermes, claude-code, openclaw, all
14
+ *
15
+ * Auto-detects installed agents. Uses anthropic-messages gateway
16
+ * for omp/pi/claude-code and openai-completions for hermes/openclaw.
17
+ */
18
+ import { fetchCatalog, type HatzModel } from "./catalog";
19
+
20
+ // Lazy-load agent modules to avoid importing fs for agents not being used.
21
+ type AgentModule = {
22
+ agentName: () => string;
23
+ isInstalled: () => Promise<boolean>;
24
+ install: (models: HatzModel[], apiKey: string) => Promise<void>;
25
+ uninstall: () => Promise<void>;
26
+ };
27
+
28
+ const AGENT_IDS = ["omp", "pi", "hermes", "claude-code", "openclaw"] as const;
29
+ type AgentId = (typeof AGENT_IDS)[number];
30
+
31
+ async function loadAgent(id: AgentId): Promise<AgentModule> {
32
+ return import(`./agents/${id}.ts`);
33
+ }
34
+
35
+ function getApiKey(): string {
36
+ return process.env.HATZ_API_KEY || "";
37
+ }
38
+
39
+ function bail(msg: string): never {
40
+ console.error(`❌ ${msg}`);
41
+ process.exit(1);
42
+ }
43
+
44
+ // ── Commands ───────────────────────────────────────────────────────────
45
+
46
+ async function cmdInstall(agentId?: string): Promise<void> {
47
+ const apiKey = getApiKey();
48
+ if (!apiKey) bail("HATZ_API_KEY is not set.\n export HATZ_API_KEY=\"your-key\"");
49
+
50
+ console.log("📡 Fetching Hatz model catalog...");
51
+ let models: HatzModel[];
52
+ try {
53
+ models = await fetchCatalog(apiKey);
54
+ console.log(` Found ${models.length} models`);
55
+ } catch (err: unknown) {
56
+ bail(`Failed to fetch catalog: ${err instanceof Error ? err.message : err}`);
57
+ }
58
+
59
+ const targets = agentId ? [agentId as AgentId] : [...AGENT_IDS];
60
+ for (const id of targets) {
61
+ try {
62
+ const agent = await loadAgent(id);
63
+ console.log(`\n🔧 ${agent.agentName()}...`);
64
+ await agent.install(models, apiKey);
65
+ console.log(` ✅ Installed`);
66
+ } catch (err: unknown) {
67
+ console.log(` ⚠ Skipped: ${err instanceof Error ? err.message : err}`);
68
+ }
69
+ }
70
+ console.log(`\n🎉 Done!`);
71
+ }
72
+
73
+ async function cmdUninstall(agentId?: string): Promise<void> {
74
+ const targets = agentId ? [agentId as AgentId] : [...AGENT_IDS];
75
+ for (const id of targets) {
76
+ try {
77
+ const agent = await loadAgent(id);
78
+ console.log(`🗑 ${agent.agentName()}...`);
79
+ await agent.uninstall();
80
+ console.log(` ✅ Removed`);
81
+ } catch {
82
+ console.log(` ⚠ Skipped (not found)`);
83
+ }
84
+ }
85
+ console.log(`\n✅ Done.`);
86
+ }
87
+
88
+ async function cmdStatus(): Promise<void> {
89
+ console.log("Hatz AI provider status:\n");
90
+ for (const id of AGENT_IDS) {
91
+ try {
92
+ const agent = await loadAgent(id);
93
+ const installed = await agent.isInstalled();
94
+ console.log(` ${installed ? "✅" : "⬜"} ${agent.agentName()}`);
95
+ } catch {
96
+ console.log(` ❓ ${id}`);
97
+ }
98
+ }
99
+ }
100
+
101
+ async function cmdList(): Promise<void> {
102
+ const apiKey = getApiKey();
103
+ if (!apiKey) bail("HATZ_API_KEY is not set.");
104
+
105
+ console.log("📡 Fetching Hatz model catalog...\n");
106
+ const models = await fetchCatalog(apiKey);
107
+ for (const m of models) {
108
+ console.log(` ${m.name.padEnd(48)} ${m.developer.padEnd(14)} ${m.vision ? "👁 " : "📝"} ${(m.max_tokens / 1000).toFixed(0)}K max`);
109
+ }
110
+ console.log(`\n ${models.length} models total`);
111
+ }
112
+
113
+ async function cmdHelp(): Promise<void> {
114
+ console.log("hatz-provider — Hatz AI provider for coding agents\n");
115
+ console.log("Usage:");
116
+ console.log(" hatz-provider install [agent] Install Hatz provider");
117
+ console.log(" hatz-provider update [agent] Refresh models from live catalog");
118
+ console.log(" hatz-provider uninstall [agent] Remove Hatz provider");
119
+ console.log(" hatz-provider status Show install status");
120
+ console.log(" hatz-provider list List available Hatz models");
121
+ console.log(" hatz-provider catalog Print omp models.yml block\n");
122
+ console.log("Agents: omp, pi, hermes, claude-code, openclaw, all (default)");
123
+ console.log("Auto-detects installed agents. Uses appropriate API per agent.");
124
+ console.log("\nAPI surfaces used:");
125
+ console.log(" omp, pi, claude-code → anthropic-messages");
126
+ console.log(" hermes, openclaw → openai-completions");
127
+ console.log("\nEnvironment:");
128
+ console.log(" HATZ_API_KEY Your Hatz API key (required)");
129
+ }
130
+
131
+ // ── Main ───────────────────────────────────────────────────────────────
132
+
133
+ const cmd = process.argv[2];
134
+ const target = process.argv[3];
135
+
136
+ if (cmd === "install" || cmd === "i" || cmd === "update" || cmd === "up") {
137
+ await cmdInstall(target);
138
+ } else if (cmd === "uninstall" || cmd === "u" || cmd === "remove" || cmd === "rm") {
139
+ await cmdUninstall(target);
140
+ } else if (cmd === "status" || cmd === "st") {
141
+ await cmdStatus();
142
+ } else if (cmd === "list" || cmd === "ls") {
143
+ await cmdList();
144
+ } else if (cmd === "catalog" || cmd === "cat") {
145
+ // Just the omp block for backward compat
146
+ const apiKey = getApiKey();
147
+ if (!apiKey) bail("HATZ_API_KEY is not set.");
148
+ const models = await fetchCatalog(apiKey);
149
+ const { generateBlock } = await import("./agents/omp.ts");
150
+ console.log(generateBlock(models, apiKey));
151
+ } else {
152
+ await cmdHelp();
153
+ }