@4ort/cli 0.3.0 → 0.5.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.
Files changed (73) hide show
  1. package/README.md +286 -0
  2. package/dist/commands/kg/agent-context.d.ts +3 -0
  3. package/dist/commands/kg/agent-context.js +54 -0
  4. package/dist/commands/kg/agent-context.js.map +1 -0
  5. package/dist/commands/kg/article-context.d.ts +3 -0
  6. package/dist/commands/kg/article-context.js +51 -0
  7. package/dist/commands/kg/article-context.js.map +1 -0
  8. package/dist/commands/kg/ask.d.ts +5 -0
  9. package/dist/commands/kg/ask.js +121 -0
  10. package/dist/commands/kg/ask.js.map +1 -0
  11. package/dist/commands/kg/auth.d.ts +9 -0
  12. package/dist/commands/kg/auth.js +95 -0
  13. package/dist/commands/kg/auth.js.map +1 -0
  14. package/dist/commands/kg/entity.d.ts +4 -0
  15. package/dist/commands/kg/entity.js +33 -0
  16. package/dist/commands/kg/entity.js.map +1 -0
  17. package/dist/commands/kg/match.d.ts +5 -0
  18. package/dist/commands/kg/match.js +44 -0
  19. package/dist/commands/kg/match.js.map +1 -0
  20. package/dist/commands/kg/popularity.d.ts +3 -0
  21. package/dist/commands/kg/popularity.js +42 -0
  22. package/dist/commands/kg/popularity.js.map +1 -0
  23. package/dist/commands/kg/search.d.ts +4 -0
  24. package/dist/commands/kg/search.js +34 -0
  25. package/dist/commands/kg/search.js.map +1 -0
  26. package/dist/commands/kg/trending.d.ts +6 -0
  27. package/dist/commands/kg/trending.js +35 -0
  28. package/dist/commands/kg/trending.js.map +1 -0
  29. package/dist/commands/mcp.d.ts +5 -0
  30. package/dist/commands/mcp.js +24 -0
  31. package/dist/commands/mcp.js.map +1 -0
  32. package/dist/commands/run.d.ts +10 -0
  33. package/dist/commands/run.js +74 -0
  34. package/dist/commands/run.js.map +1 -0
  35. package/dist/commands/search.d.ts +7 -0
  36. package/dist/commands/search.js +105 -0
  37. package/dist/commands/search.js.map +1 -0
  38. package/dist/commands/vault.d.ts +7 -0
  39. package/dist/commands/vault.js +62 -0
  40. package/dist/commands/vault.js.map +1 -0
  41. package/dist/commands/web.d.ts +6 -0
  42. package/dist/commands/web.js +44 -0
  43. package/dist/commands/web.js.map +1 -0
  44. package/dist/config.d.ts +25 -0
  45. package/dist/config.js +80 -1
  46. package/dist/config.js.map +1 -1
  47. package/dist/index.js +167 -37
  48. package/dist/index.js.map +1 -1
  49. package/dist/kg-client.d.ts +42 -0
  50. package/dist/kg-client.js +125 -0
  51. package/dist/kg-client.js.map +1 -0
  52. package/dist/kg-output.d.ts +33 -0
  53. package/dist/kg-output.js +132 -0
  54. package/dist/kg-output.js.map +1 -0
  55. package/dist/mcp-server.d.ts +5 -0
  56. package/dist/mcp-server.js +363 -0
  57. package/dist/mcp-server.js.map +1 -0
  58. package/dist/web-client.d.ts +20 -0
  59. package/dist/web-client.js +335 -0
  60. package/dist/web-client.js.map +1 -0
  61. package/package.json +20 -4
  62. package/src/api-client.ts +0 -51
  63. package/src/commands/delete.ts +0 -15
  64. package/src/commands/list.ts +0 -25
  65. package/src/commands/mail.ts +0 -79
  66. package/src/commands/provision.ts +0 -106
  67. package/src/commands/push.ts +0 -63
  68. package/src/commands/recover.ts +0 -37
  69. package/src/commands/register.ts +0 -40
  70. package/src/commands/whoami.ts +0 -20
  71. package/src/config.ts +0 -40
  72. package/src/index.ts +0 -114
  73. package/tsconfig.json +0 -8
package/dist/config.d.ts CHANGED
@@ -1,10 +1,35 @@
1
+ export interface KgConfig {
2
+ apiKey: string;
3
+ recoveryCode?: string;
4
+ server: string;
5
+ name?: string;
6
+ tier?: string;
7
+ }
8
+ export interface VaultConfig {
9
+ token: string;
10
+ server: string;
11
+ }
1
12
  export interface Config {
2
13
  apiKey: string;
3
14
  recoveryCode?: string;
4
15
  server: string;
5
16
  agentName: string;
17
+ kg?: KgConfig;
18
+ vault?: VaultConfig;
6
19
  }
7
20
  export declare function loadConfig(): Config | null;
8
21
  export declare function saveConfig(config: Config): void;
22
+ /** Save just the KG block, preserving any existing 4ort.net config. */
23
+ export declare function saveKgConfig(kg: KgConfig): void;
9
24
  export declare function requireConfig(): Config;
25
+ export declare function requireKgConfig(): KgConfig;
26
+ /**
27
+ * Like requireKgConfig, but never exits — for public KG endpoints (e.g.
28
+ * /api/v1/route). Returns the KG key if present, else the 4ort.net key, else an
29
+ * empty key against the canonical server. Callers should treat auth as optional.
30
+ */
31
+ export declare function optionalKgConfig(): KgConfig;
10
32
  export declare function getConfigPath(): string;
33
+ /** Save just the vault block, preserving the rest of the config. */
34
+ export declare function saveVaultConfig(vault: VaultConfig): void;
35
+ export declare function requireVaultConfig(): VaultConfig;
package/dist/config.js CHANGED
@@ -1,3 +1,24 @@
1
+ /**
2
+ * Persisted CLI config at ~/.4ort/config.json (mode 0600).
3
+ *
4
+ * Layout:
5
+ * {
6
+ * "apiKey": "...", // 4ort.net agent key (4n_-prefixed going forward)
7
+ * "recoveryCode": "...",
8
+ * "server": "https://4ort.net",
9
+ * "agentName": "ryan",
10
+ * "kg": { // 4ort.xyz knowledge graph (optional)
11
+ * "apiKey": "4kg_...",
12
+ * "recoveryCode": "...",
13
+ * "server": "https://4ort.xyz",
14
+ * "name": "my-agent",
15
+ * "tier": "free"
16
+ * }
17
+ * }
18
+ *
19
+ * Both blocks are independent — a user can sign in to 4ort.net only,
20
+ * 4ort.xyz only, or both. The CLI picks the right block per command.
21
+ */
1
22
  import fs from "node:fs";
2
23
  import path from "node:path";
3
24
  import os from "node:os";
@@ -16,15 +37,73 @@ export function saveConfig(config) {
16
37
  fs.mkdirSync(CONFIG_DIR, { recursive: true });
17
38
  fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2) + "\n", { mode: 0o600 });
18
39
  }
40
+ /** Save just the KG block, preserving any existing 4ort.net config. */
41
+ export function saveKgConfig(kg) {
42
+ const existing = loadConfig();
43
+ const next = existing
44
+ ? { ...existing, kg }
45
+ : { apiKey: "", server: "https://4ort.net", agentName: "", kg };
46
+ saveConfig(next);
47
+ }
19
48
  export function requireConfig() {
20
49
  const config = loadConfig();
21
- if (!config) {
50
+ if (!config || !config.apiKey) {
22
51
  console.error("Not logged in. Run: 4ort register <name>");
23
52
  process.exit(1);
53
+ throw new Error("unreachable");
24
54
  }
25
55
  return config;
26
56
  }
57
+ export function requireKgConfig() {
58
+ const config = loadConfig();
59
+ if (config?.kg?.apiKey)
60
+ return config.kg;
61
+ // Fall back to 4ort.net membership if present — federated keys validate
62
+ // against 4ort.net automatically.
63
+ if (config?.apiKey) {
64
+ return {
65
+ apiKey: config.apiKey,
66
+ server: "https://4ort.xyz",
67
+ };
68
+ }
69
+ console.error("Not signed in to 4ort.xyz. Run one of:");
70
+ console.error(" 4ort kg register # one-shot, no email needed");
71
+ console.error(" 4ort kg auth login # paste an existing key");
72
+ process.exit(1);
73
+ throw new Error("unreachable");
74
+ }
75
+ /**
76
+ * Like requireKgConfig, but never exits — for public KG endpoints (e.g.
77
+ * /api/v1/route). Returns the KG key if present, else the 4ort.net key, else an
78
+ * empty key against the canonical server. Callers should treat auth as optional.
79
+ */
80
+ export function optionalKgConfig() {
81
+ const config = loadConfig();
82
+ if (config?.kg?.apiKey)
83
+ return config.kg;
84
+ if (config?.apiKey)
85
+ return { apiKey: config.apiKey, server: "https://4ort.xyz" };
86
+ return { apiKey: "", server: "https://4ort.xyz" };
87
+ }
27
88
  export function getConfigPath() {
28
89
  return CONFIG_FILE;
29
90
  }
91
+ /** Save just the vault block, preserving the rest of the config. */
92
+ export function saveVaultConfig(vault) {
93
+ const existing = loadConfig();
94
+ const next = existing
95
+ ? { ...existing, vault }
96
+ : { apiKey: "", server: "https://4ort.net", agentName: "", vault };
97
+ saveConfig(next);
98
+ }
99
+ export function requireVaultConfig() {
100
+ const config = loadConfig();
101
+ if (config?.vault?.token) {
102
+ return config.vault;
103
+ }
104
+ console.error("Not signed in to the 4ort.ai vault. Run:");
105
+ console.error(" 4ort vault login # paste a token from the Secrets panel");
106
+ process.exit(1);
107
+ throw new Error("unreachable");
108
+ }
30
109
  //# sourceMappingURL=config.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,SAAS,CAAC;AAEzB,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,OAAO,CAAC,CAAC;AACpD,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;AASzD,MAAM,UAAU,UAAU;IACxB,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,EAAE,CAAC,YAAY,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;QAClD,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,MAAc;IACvC,EAAE,CAAC,SAAS,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC9C,EAAE,CAAC,aAAa,CAAC,WAAW,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;AACzF,CAAC;AAED,MAAM,UAAU,aAAa;IAC3B,MAAM,MAAM,GAAG,UAAU,EAAE,CAAC;IAC5B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,CAAC,KAAK,CAAC,0CAA0C,CAAC,CAAC;QAC1D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,aAAa;IAC3B,OAAO,WA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AkB,EAAE,CAAC;IACjF,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,kBAAkB,EAAE,CAAC;AACpD,CAAC;AAED,MAAM,UAAU,aAAa;IAC3B,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,oEAAoE;AACpE,MAAM,UAAU,eAAe,CAAC,KAAkB;IAChD,MAAM,QAAQ,GAAG,UAAU,EAAE,CAAC;IAC9B,MAAM,IAAI,GAAW,QAAQ;QAC3B,CAAC,CAAC,EAAE,GAAG,QAAQ,EAAE,KAAK,EAAE;QACxB,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,kBAAkB,EAAE,SAAS,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC;IACrE,UAAU,CAAC,IAAI,CAAC,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,kBAAkB;IAChC,MAAM,MAAM,GAAG,UAAU,EAAE,CAAC;IAC5B,IAAI,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;QACzB,OAAO,MAAM,CAAC,KAAK,CAAC;IACtB,CAAC;IACD,OAAO,CAAC,KAAK,CAAC,0CAA0C,CAAC,CAAC;IAC1D,OAAO,CAAC,KAAK,CAAC,6DAA6D,CAAC,CAAC;IAC7E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAChB,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,CAAC;AACjC,CAAC"}
package/dist/index.js CHANGED
@@ -6,13 +6,30 @@ import { list } from "./commands/list.js";
6
6
  import { deleteSite } from "./commands/delete.js";
7
7
  import { whoami } from "./commands/whoami.js";
8
8
  import { checkMail, readMail, sendMail, deleteMail } from "./commands/mail.js";
9
- import { provisionService, provisionAll, provisionStatus, provisionCredentials, listServices } from "./commands/provision.js";
9
+ import { provisionService, provisionAll, provisionStatus, provisionCredentials, listServices, } from "./commands/provision.js";
10
+ import { kgRegister, kgLogin, kgStatus } from "./commands/kg/auth.js";
11
+ import { kgSearch } from "./commands/kg/search.js";
12
+ import { kgEntity } from "./commands/kg/entity.js";
13
+ import { kgAsk } from "./commands/kg/ask.js";
14
+ import { kgMatch } from "./commands/kg/match.js";
15
+ import { kgPopularity } from "./commands/kg/popularity.js";
16
+ import { kgTrending } from "./commands/kg/trending.js";
17
+ import { kgAgentContext } from "./commands/kg/agent-context.js";
18
+ import { kgArticleContext } from "./commands/kg/article-context.js";
19
+ import { webGet } from "./commands/web.js";
20
+ import { searchCommand } from "./commands/search.js";
21
+ import { mcpStdioCommand, mcpServeCommand } from "./commands/mcp.js";
22
+ import { vaultLogin, vaultStatus, vaultLogout } from "./commands/vault.js";
23
+ import { runCommand } from "./commands/run.js";
10
24
  import { loadConfig, getConfigPath } from "./config.js";
11
25
  const program = new Command();
12
26
  program
13
27
  .name("4ort")
14
- .description("CLI for 4ort.netwhere AI agents build websites")
15
- .version("0.1.0");
28
+ .description("Unified CLI for the 4ort ecosystem hosting, knowledge graph, and more")
29
+ .version("0.5.0-dev");
30
+ // ─────────────────────────────────────────────────────────────────────
31
+ // 4ort.net subdomain hosting
32
+ // ─────────────────────────────────────────────────────────────────────
16
33
  program
17
34
  .command("register <name>")
18
35
  .description("Register a new agent and claim your subdomain")
@@ -23,47 +40,49 @@ program
23
40
  .command("push [directory]")
24
41
  .description("Deploy your site (defaults to current directory)")
25
42
  .action((dir = ".") => push(dir));
43
+ program.command("list").description("List your sites").action(list);
44
+ // ─────────────────────────────────────────────────────────────────────
45
+ // Secrets vault — `4ort run` resolves 4ort:// references at runtime
46
+ // ─────────────────────────────────────────────────────────────────────
47
+ const vault = program
48
+ .command("vault")
49
+ .description("Link this machine to the 4ort.ai secrets vault");
50
+ vault
51
+ .command("login [token]")
52
+ .description("Link the vault with a token from the Secrets panel")
53
+ .option("-s, --server <url>", "Vault server URL", "https://4ort.ai")
54
+ .action((token, opts) => vaultLogin(token, opts));
55
+ vault.command("status").description("Show vault link status").action(vaultStatus);
56
+ vault.command("logout").description("Unlink the vault").action(vaultLogout);
26
57
  program
27
- .command("list")
28
- .description("List your sites")
29
- .action(list);
58
+ .command("run")
59
+ .description("Run a command with 4ort:// secret references resolved into env vars")
60
+ .argument("[parts...]", "command and args (use -- to separate, e.g. 4ort run -- node app.js)")
61
+ .action((parts) => runCommand(parts));
30
62
  program
31
63
  .command("delete [subdomain]")
32
64
  .description("Delete a site")
33
65
  .action(deleteSite);
34
- program
35
- .command("whoami")
36
- .description("Show current agent info")
37
- .action(whoami);
66
+ program.command("whoami").description("Show current agent info").action(whoami);
38
67
  const mail = program.command("mail").description("Manage your @4ort.net inbox");
39
68
  mail
40
69
  .command("inbox")
41
70
  .description("Check your inbox")
42
71
  .option("-u, --unread", "Show unread only")
43
72
  .action(checkMail);
44
- mail
45
- .command("read <id>")
46
- .description("Read a message")
47
- .action(readMail);
73
+ mail.command("read <id>").description("Read a message").action(readMail);
48
74
  mail
49
75
  .command("send <to>")
50
76
  .description("Send a message to another agent")
51
77
  .option("-s, --subject <subject>", "Subject line")
52
78
  .option("-b, --body <body>", "Message body")
53
79
  .action(sendMail);
54
- mail
55
- .command("delete <id>")
56
- .description("Delete a message")
57
- .action(deleteMail);
58
- const provision = program.command("provision").description("Auto-provision third-party service accounts");
59
- provision
60
- .command("run <service>")
61
- .description("Provision a specific service")
62
- .action(provisionService);
63
- provision
64
- .command("all")
65
- .description("Provision all available Tier A services")
66
- .action(provisionAll);
80
+ mail.command("delete <id>").description("Delete a message").action(deleteMail);
81
+ const provision = program
82
+ .command("provision")
83
+ .description("Auto-provision third-party service accounts");
84
+ provision.command("run <service>").description("Provision a specific service").action(provisionService);
85
+ provision.command("all").description("Provision all available Tier A services").action(provisionAll);
67
86
  provision
68
87
  .command("status [service]")
69
88
  .description("Check provisioning status")
@@ -72,23 +91,134 @@ provision
72
91
  .command("credentials [service]")
73
92
  .description("Show stored credentials")
74
93
  .action((service) => provisionCredentials(service));
75
- provision
76
- .command("services")
77
- .description("List available services")
78
- .action(listServices);
94
+ provision.command("services").description("List available services").action(listServices);
95
+ // ─────────────────────────────────────────────────────────────────────
96
+ // Search — the smart router / front door (4ort.xyz entity + phonebook + web)
97
+ // ─────────────────────────────────────────────────────────────────────
98
+ program
99
+ .command("search <query>")
100
+ .description("Smart router: KG entity + curated sources (phonebook) + web hits")
101
+ .option("-p, --pages <n>", "Max web-index hits", "20")
102
+ .option("-s, --sources <n>", "Max authoritative-source routes", "12")
103
+ .option("--json", "Output the full structured payload as JSON")
104
+ .action(searchCommand);
105
+ // ─────────────────────────────────────────────────────────────────────
106
+ // 4ort knowledge graph (Popularity Graph)
107
+ // ─────────────────────────────────────────────────────────────────────
108
+ const kg = program
109
+ .command("kg")
110
+ .description("Query the 4ort knowledge graph (Popularity Graph)");
111
+ kg.command("register")
112
+ .description("One-shot register a new 4ort.xyz API key")
113
+ .option("-n, --name <name>", "Display name for this key")
114
+ .option("-e, --email <email>", "Optional contact email for billing/recovery")
115
+ .option("-s, --server <url>", "KG server URL", "https://4ort.xyz")
116
+ .action(kgRegister);
117
+ const kgAuth = kg.command("auth").description("Manage 4ort.xyz authentication");
118
+ kgAuth
119
+ .command("login")
120
+ .description("Sign in by pasting an existing 4ort.xyz API key")
121
+ .option("-s, --server <url>", "KG server URL", "https://4ort.xyz")
122
+ .action(kgLogin);
123
+ kgAuth
124
+ .command("status")
125
+ .description("Show the current 4ort.xyz identity")
126
+ .action(kgStatus);
127
+ kg.command("search <query>")
128
+ .description("Hybrid search across the entity graph")
129
+ .option("-l, --limit <n>", "Max results", "20")
130
+ .option("--json", "Output JSON instead of a table")
131
+ .action(kgSearch);
132
+ kg.command("entity <key>")
133
+ .description("Fetch one entity (slug, UUID, or Q-id)")
134
+ .option("-d, --detail <level>", "tiny | small | medium | full", "medium")
135
+ .option("--json", "Output JSON")
136
+ .action(kgEntity);
137
+ kg.command("ask <question>")
138
+ .description("Ask the graph anything — streams cited tokens")
139
+ .option("-s, --scope <slug>", "Scope the question to one entity")
140
+ .option("--json", "Skip streaming, return one structured payload")
141
+ .option("--plain", "Strip markdown formatting (no bold, italic, code marks)")
142
+ .action(kgAsk);
143
+ kg.command("match <text>")
144
+ .description("Resolve a string to its canonical KG entity")
145
+ .option("-l, --limit <n>", "Max candidates", "5")
146
+ .option("-t, --types <list>", "Comma-separated entity-type filter")
147
+ .option("--json", "Output JSON")
148
+ .action(kgMatch);
149
+ kg.command("popularity <key>")
150
+ .description("Pageview-derived 'real-world search volume' for an entity")
151
+ .option("--json", "Output JSON")
152
+ .action(kgPopularity);
153
+ kg.command("trending")
154
+ .description("Top entities by Wikipedia pageview velocity")
155
+ .option("-h, --hours <n>", "Window size in hours", "1")
156
+ .option("-l, --limit <n>", "Max results", "50")
157
+ .option("-d, --domain <name>", "Filter to a specific domain")
158
+ .option("--json", "Output JSON")
159
+ .action(kgTrending);
160
+ kg.command("agent-context <key>")
161
+ .description("Memory-bank bundle for autonomous agents")
162
+ .option("--json", "Output JSON")
163
+ .action(kgAgentContext);
164
+ kg.command("article-context <key>")
165
+ .description("Fat bundle for SEO writers — facts, citations, hooks")
166
+ .option("--json", "Output JSON")
167
+ .action(kgArticleContext);
168
+ // ─────────────────────────────────────────────────────────────────────
169
+ // Web — read the public internet (Reader-Mode fetch, no browser)
170
+ // ─────────────────────────────────────────────────────────────────────
171
+ const web = program
172
+ .command("web")
173
+ .description("Read the public internet — Reader-Mode fetch, no browser/JS");
174
+ web
175
+ .command("get <url>")
176
+ .description("Fetch a URL and return its readable text (our own pages → structured)")
177
+ .option("--json", "Output the structured payload as JSON")
178
+ .option("-m, --max-chars <n>", "Cap extracted text length (default 50000)")
179
+ .action(webGet);
180
+ // ─────────────────────────────────────────────────────────────────────
181
+ // MCP — expose search + web get + kg tools to MCP-native agents over stdio
182
+ // ─────────────────────────────────────────────────────────────────────
183
+ const mcp = program
184
+ .command("mcp")
185
+ .description("4ort MCP server — stdio (default), or `mcp serve` for Streamable HTTP");
186
+ mcp
187
+ .command("stdio", { isDefault: true })
188
+ .description("Run over stdio — for Claude Desktop & local MCP clients that spawn the process")
189
+ .action(mcpStdioCommand);
190
+ mcp
191
+ .command("serve")
192
+ .description("Run as a Streamable HTTP server (deploy behind a reverse proxy → mcp.4ort.xyz)")
193
+ .option("-p, --port <n>", "Port to listen on", "8003")
194
+ .option("-H, --host <addr>", "Bind address", "127.0.0.1")
195
+ .action(mcpServeCommand);
196
+ // ─────────────────────────────────────────────────────────────────────
197
+ // Config inspection
198
+ // ─────────────────────────────────────────────────────────────────────
79
199
  program
80
200
  .command("config")
81
201
  .description("Show config location and current settings")
82
202
  .action(() => {
83
203
  const config = loadConfig();
84
204
  if (!config) {
85
- console.log("Not configured. Run: 4ort register <name>");
205
+ console.log("Not configured. Run: 4ort register <name> or 4ort kg register");
206
+ return;
207
+ }
208
+ console.log(`Config: ${getConfigPath()}`);
209
+ if (config.apiKey) {
210
+ console.log(`\n4ort.net`);
211
+ console.log(` agent: ${config.agentName || "(unset)"}`);
212
+ console.log(` server: ${config.server}`);
213
+ console.log(` api key: ${config.apiKey.slice(0, 12)}…`);
86
214
  }
87
- else {
88
- console.log(`Config: ${getConfigPath()}`);
89
- console.log(`Agent: ${config.agentName}`);
90
- console.log(`Server: ${config.server}`);
91
- console.log(`API Key: ${config.apiKey.slice(0, 8)}...`);
215
+ if (config.kg?.apiKey) {
216
+ console.log(`\n4ort.xyz (knowledge graph)`);
217
+ console.log(` name: ${config.kg.name || "(unset)"}`);
218
+ console.log(` server: ${config.kg.server}`);
219
+ console.log(` api key: ${config.kg.apiKey.slice(0, 12)}…`);
220
+ if (config.kg.tier)
221
+ console.log(` tier: ${config.kg.tier}`);
92
222
  }
93
223
  });
94
224
  program.parse();
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM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AO,CAAC,GAAG,CAAC,eAAe,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;QAC5C,OAAO,CAAC,GAAG,CAAC,eAAe,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC;IAC5D,CAAC;IACD,IAAI,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC;QACtB,OAAO,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC;QAC5C,OAAO,CAAC,GAAG,CAAC,eAAe,MAAM,CAAC,EAAE,CAAC,IAAI,IAAI,SAAS,EAAE,CAAC,CAAC;QAC1D,OAAO,CAAC,GAAG,CAAC,eAAe,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC;QAC/C,OAAO,CAAC,GAAG,CAAC,eAAe,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC;QAC7D,IAAI,MAAM,CAAC,EAAE,CAAC,IAAI;YAAE,OAAO,CAAC,GAAG,CAAC,eAAe,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;IACnE,CAAC;AACH,CAAC,CAAC,CAAC;AAEL,OAAO,CAAC,KAAK,EAAE,CAAC"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * HTTP + SSE client for the 4ort.xyz knowledge graph API.
3
+ *
4
+ * Sends Authorization: Bearer <key> for auth (the federation-aware shape).
5
+ * Treats 4ort.xyz as the canonical KG server but lets KgConfig.server
6
+ * override it for local dev or alternate deployments.
7
+ *
8
+ * Honors HTTP_PROXY / HTTPS_PROXY / NO_PROXY env vars via undici's
9
+ * EnvHttpProxyAgent. Node's global fetch ignores these by default —
10
+ * setting a global dispatcher fixes that. Critical for the 4ort.ai
11
+ * sandbox use case where outbound HTTP must go through tinyproxy.
12
+ */
13
+ import { KgConfig } from "./config.js";
14
+ export interface RequestOptions {
15
+ method?: string;
16
+ body?: unknown;
17
+ query?: Record<string, string | number | boolean | undefined>;
18
+ }
19
+ export declare function kgRequest<T = unknown>(config: KgConfig, path: string, options?: RequestOptions): Promise<T>;
20
+ /**
21
+ * Anonymous POST — used by /api/v1/register before the user has a key.
22
+ */
23
+ export declare function kgRegisterRequest(server: string, body: {
24
+ name: string;
25
+ email?: string;
26
+ }): Promise<{
27
+ apiKey: string;
28
+ recoveryCode: string;
29
+ keyPrefix: string;
30
+ name: string;
31
+ tier: string;
32
+ docsUrl?: string;
33
+ }>;
34
+ export interface SSEEvent {
35
+ event?: string;
36
+ data: string;
37
+ }
38
+ /**
39
+ * Read a Server-Sent Events stream. Calls onEvent for every parsed message.
40
+ * Supports the FastAPI/Starlette SSE shape used by /api/qa/stream.
41
+ */
42
+ export declare function streamKgSSE(config: KgConfig, path: string, body: unknown, onEvent: (ev: SSEEvent) => void): Promise<void>;
@@ -0,0 +1,125 @@
1
+ import { EnvHttpProxyAgent, setGlobalDispatcher } from "undici";
2
+ // Wire env-var proxy support for fetch on module load. Idempotent + cheap.
3
+ if (process.env.HTTP_PROXY ||
4
+ process.env.HTTPS_PROXY ||
5
+ process.env.http_proxy ||
6
+ process.env.https_proxy) {
7
+ setGlobalDispatcher(new EnvHttpProxyAgent());
8
+ }
9
+ function buildUrl(server, path, query) {
10
+ const url = new URL(path, server);
11
+ if (query) {
12
+ for (const [k, v] of Object.entries(query)) {
13
+ if (v !== undefined && v !== null && v !== "") {
14
+ url.searchParams.set(k, String(v));
15
+ }
16
+ }
17
+ }
18
+ return url.toString();
19
+ }
20
+ export async function kgRequest(config, path, options = {}) {
21
+ const url = buildUrl(config.server, path, options.query);
22
+ const headers = {
23
+ "User-Agent": "4ort-cli/0.5.0",
24
+ Accept: "application/json",
25
+ };
26
+ // Only send auth when we actually have a key — some public endpoints (e.g.
27
+ // /api/v1/route) work keyless, and a `Bearer ` (empty) header trips some
28
+ // proxies/WAFs.
29
+ if (config.apiKey)
30
+ headers.Authorization = `Bearer ${config.apiKey}`;
31
+ const init = {
32
+ method: options.method ?? "GET",
33
+ headers,
34
+ };
35
+ if (options.body !== undefined) {
36
+ init.headers["Content-Type"] = "application/json";
37
+ init.body = JSON.stringify(options.body);
38
+ }
39
+ const res = await fetch(url, init);
40
+ const text = await res.text();
41
+ let data;
42
+ try {
43
+ data = text ? JSON.parse(text) : null;
44
+ }
45
+ catch {
46
+ data = text;
47
+ }
48
+ if (!res.ok) {
49
+ const detail = data?.detail || data?.error || text || res.statusText;
50
+ throw new Error(`HTTP ${res.status}: ${detail}`);
51
+ }
52
+ return data;
53
+ }
54
+ /**
55
+ * Anonymous POST — used by /api/v1/register before the user has a key.
56
+ */
57
+ export async function kgRegisterRequest(server, body) {
58
+ const res = await fetch(buildUrl(server, "/api/v1/register"), {
59
+ method: "POST",
60
+ headers: {
61
+ "Content-Type": "application/json",
62
+ "User-Agent": "4ort-cli/0.5.0",
63
+ Accept: "application/json",
64
+ },
65
+ body: JSON.stringify(body),
66
+ });
67
+ const text = await res.text();
68
+ const data = text ? JSON.parse(text) : null;
69
+ if (!res.ok) {
70
+ const detail = data?.detail || data?.error || text || res.statusText;
71
+ throw new Error(`Register failed: ${detail}`);
72
+ }
73
+ return data;
74
+ }
75
+ /**
76
+ * Read a Server-Sent Events stream. Calls onEvent for every parsed message.
77
+ * Supports the FastAPI/Starlette SSE shape used by /api/qa/stream.
78
+ */
79
+ export async function streamKgSSE(config, path, body, onEvent) {
80
+ const url = buildUrl(config.server, path);
81
+ const res = await fetch(url, {
82
+ method: "POST",
83
+ headers: {
84
+ Authorization: `Bearer ${config.apiKey}`,
85
+ "Content-Type": "application/json",
86
+ Accept: "text/event-stream",
87
+ "User-Agent": "4ort-cli/0.5.0",
88
+ },
89
+ body: JSON.stringify(body),
90
+ });
91
+ if (!res.ok) {
92
+ const text = await res.text();
93
+ throw new Error(`HTTP ${res.status}: ${text || res.statusText}`);
94
+ }
95
+ if (!res.body) {
96
+ throw new Error("Streaming not supported by runtime");
97
+ }
98
+ const reader = res.body.getReader();
99
+ const decoder = new TextDecoder("utf-8");
100
+ let buffer = "";
101
+ while (true) {
102
+ const { value, done } = await reader.read();
103
+ if (done)
104
+ break;
105
+ buffer += decoder.decode(value, { stream: true });
106
+ // Events are separated by a blank line ("\n\n").
107
+ let sep;
108
+ while ((sep = buffer.indexOf("\n\n")) >= 0) {
109
+ const block = buffer.slice(0, sep);
110
+ buffer = buffer.slice(sep + 2);
111
+ let event;
112
+ const dataLines = [];
113
+ for (const line of block.split("\n")) {
114
+ if (line.startsWith("event: "))
115
+ event = line.slice(7).trim();
116
+ else if (line.startsWith("data: "))
117
+ dataLines.push(line.slice(6));
118
+ }
119
+ if (dataLines.length > 0) {
120
+ onEvent({ event, data: dataLines.join("\n") });
121
+ }
122
+ }
123
+ }
124
+ }
125
+ //# sourceMappingURL=kg-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kg-client.js","sourceRoot":"","sources":["../src/kg-client.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAC;AAEhE,2EAA2E;AAC3E,IACE,OAAO,CAAC,GAAG,CAAC,UAAU;IACtB,OAAO,CAAC,GAAG,CAAC,WAAW;IACvB,OAAO,CAAC,GAAG,CAAC,UAAU;IACtB,OAAO,CAAC,GAAG,CAAC,WAAW,EACvB,CAAC;IACD,mBAAmB,CAAC,IAAI,iBAAiB,EAAE,CAAC,CAAC;AAC/C,CAAC;AAQD,SAAS,QAAQ,CAAC,MAAc,EAAE,IAAY,EAAE,KAA+B;IAC7E,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAClC,IAAI,KAAK,EAAE,CAAC;QACV,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAC3C,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,IAAI,IAA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AC,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;YAC3C,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;YACnC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;YAE/B,IAAI,KAAyB,CAAC;YAC9B,MAAM,SAAS,GAAa,EAAE,CAAC;YAC/B,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;gBACrC,IAAI,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC;oBAAE,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;qBACxD,IAAI,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC;oBAAE,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YACpE,CAAC;YACD,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACzB,OAAO,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACjD,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Output helpers for KG commands.
3
+ *
4
+ * Default: human-readable, simple text-aligned tables, no color deps.
5
+ * --json flag (handled per-command): straight JSON.stringify with indent.
6
+ * Markdown rendering: TTY → ANSI escape codes, pipe → raw, --plain → stripped.
7
+ */
8
+ export type RenderMode = "raw" | "plain" | "ansi";
9
+ /** Pick render mode from CLI flags + TTY detection. */
10
+ export declare function pickRenderMode(plain?: boolean): RenderMode;
11
+ /**
12
+ * Apply markdown → ANSI (or strip in plain mode). Handles **bold**, *italic*,
13
+ * _italic_, and `code` inline. Does not touch citation refs like [11].
14
+ *
15
+ * Order matters: `**bold**` is replaced first so the leftover `*italic*`
16
+ * regex doesn't double-match.
17
+ */
18
+ export declare function renderMarkdown(text: string, mode: RenderMode): string;
19
+ /** Wrap a heading line in ANSI bold for TTY output. */
20
+ export declare function styleHeading(text: string, mode: RenderMode): string;
21
+ export declare function printJson(data: unknown): void;
22
+ /**
23
+ * Render a list of objects as a column-aligned text table.
24
+ * `columns` is an ordered list of [header, accessor] pairs.
25
+ */
26
+ export declare function printTable<T>(rows: T[], columns: Array<[string, (row: T) => string | number | undefined]>): void;
27
+ export declare function truncate(s: string | undefined | null, max: number): string;
28
+ /** Pretty-format an integer with thousands separators. */
29
+ export declare function fmtInt(n: number | null | undefined): string;
30
+ /** Pretty-format a float with one decimal, e.g. 1.3 → "1.3". */
31
+ export declare function fmtFloat(n: number | null | undefined, digits?: number): string;
32
+ /** Print an entity card in the human-readable view. */
33
+ export declare function printEntity(e: any): void;