@naia-team/cli 0.1.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.
@@ -0,0 +1,48 @@
1
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
2
+ import { dirname, join } from "node:path";
3
+ import { homedir } from "node:os";
4
+
5
+ const DEFAULT_CONFIG = {
6
+ defaultProfile: "default",
7
+ runtimeUrl: "http://localhost:4310",
8
+ webappUrl: "http://localhost:5173",
9
+ executor: {
10
+ id: "naia-cli",
11
+ name: "CLI",
12
+ type: "agent",
13
+ },
14
+ };
15
+
16
+ export function getConfigPath() {
17
+ return join(homedir(), ".config", "naia", "config.json");
18
+ }
19
+
20
+ export async function readCliConfig() {
21
+ const filePath = getConfigPath();
22
+ try {
23
+ const raw = await readFile(filePath, "utf8");
24
+ const parsed = JSON.parse(raw);
25
+ return {
26
+ defaultProfile: parsed.defaultProfile || DEFAULT_CONFIG.defaultProfile,
27
+ runtimeUrl: parsed.runtimeUrl || DEFAULT_CONFIG.runtimeUrl,
28
+ webappUrl: parsed.webappUrl || DEFAULT_CONFIG.webappUrl,
29
+ executor: {
30
+ id: parsed.executor?.id || DEFAULT_CONFIG.executor.id,
31
+ name: parsed.executor?.name || DEFAULT_CONFIG.executor.name,
32
+ type: parsed.executor?.type === "user" ? "user" : "agent",
33
+ },
34
+ };
35
+ } catch {
36
+ return structuredClone(DEFAULT_CONFIG);
37
+ }
38
+ }
39
+
40
+ export async function writeCliConfig(config) {
41
+ const filePath = getConfigPath();
42
+ await mkdir(dirname(filePath), { recursive: true });
43
+ await writeFile(filePath, JSON.stringify(config, null, 2), { mode: 0o600 });
44
+ }
45
+
46
+ export function defaultCliConfig() {
47
+ return structuredClone(DEFAULT_CONFIG);
48
+ }
@@ -0,0 +1,34 @@
1
+ export function buildMcpServerDefinition(input) {
2
+ return {
3
+ command: "naia",
4
+ args: ["mcp", "serve"],
5
+ env: {
6
+ NAIA_RUNTIME_URL: input.runtimeUrl,
7
+ NAIA_EXECUTOR_NAME: input.executorName,
8
+ NAIA_EXECUTOR_ID: input.executorId,
9
+ NAIA_EXECUTOR_TYPE: input.executorType,
10
+ },
11
+ };
12
+ }
13
+
14
+ export function buildCodexTomlSnippet(input) {
15
+ return [
16
+ `[mcp_servers.naia]`,
17
+ `command = "naia"`,
18
+ `args = ["mcp", "serve"]`,
19
+ `[mcp_servers.naia.env]`,
20
+ `NAIA_RUNTIME_URL = "${input.runtimeUrl}"`,
21
+ `NAIA_EXECUTOR_NAME = "${input.executorName}"`,
22
+ `NAIA_EXECUTOR_ID = "${input.executorId}"`,
23
+ `NAIA_EXECUTOR_TYPE = "${input.executorType}"`,
24
+ ].join("\n");
25
+ }
26
+
27
+ export function buildClaudeDesktopJsonSnippet(input) {
28
+ return JSON.stringify({
29
+ mcpServers: {
30
+ naia: buildMcpServerDefinition(input),
31
+ },
32
+ }, null, 2);
33
+ }
34
+
@@ -0,0 +1,8 @@
1
+ export function printJson(value) {
2
+ console.log(JSON.stringify(value, null, 2));
3
+ }
4
+
5
+ export function fail(message) {
6
+ throw new Error(message);
7
+ }
8
+
@@ -0,0 +1,49 @@
1
+ import { readAuthProfile } from "./auth-store.js";
2
+ import { readCliConfig } from "./config-store.js";
3
+
4
+ export async function loadPlatformRuntimeContext(input) {
5
+ const config = await readCliConfig();
6
+ const profile = input.profile ?? config.defaultProfile ?? "default";
7
+ const stored = await readAuthProfile(profile);
8
+ if (!stored) {
9
+ throw new Error(`No auth profile '${profile}'. Run: naia auth login --org-slug <slug>`);
10
+ }
11
+ const runtimeUrl = input.runtimeUrl ?? process.env.NAIA_RUNTIME_URL ?? config.runtimeUrl;
12
+ const executorId = input.executorId ?? process.env.NAIA_EXECUTOR_ID ?? config.executor.id;
13
+ const executorName = input.executorName ?? process.env.NAIA_EXECUTOR_NAME ?? config.executor.name;
14
+ const executorType = input.executorType === "user" || process.env.NAIA_EXECUTOR_TYPE === "user" || config.executor.type === "user"
15
+ ? "user"
16
+ : "agent";
17
+
18
+ return {
19
+ runtimeUrl: runtimeUrl.replace(/\/+$/, ""),
20
+ profile,
21
+ organizationId: stored.organizationId,
22
+ memberId: stored.memberId,
23
+ token: stored.token,
24
+ executorId,
25
+ executorName,
26
+ executorType,
27
+ };
28
+ }
29
+
30
+ export async function platformApiCall(context, path, input) {
31
+ const response = await fetch(`${context.runtimeUrl}${path}`, {
32
+ method: input.method,
33
+ headers: {
34
+ "content-type": "application/json",
35
+ "x-naia-organization-id": context.organizationId,
36
+ "x-naia-member-id": context.memberId,
37
+ "x-naia-executor-id": context.executorId,
38
+ "x-naia-executor-name": context.executorName,
39
+ "x-naia-executor-type": context.executorType,
40
+ authorization: `Bearer ${context.token}`,
41
+ },
42
+ body: input.body ? JSON.stringify(input.body) : undefined,
43
+ });
44
+ const json = await response.json().catch(() => ({}));
45
+ if (!response.ok || json?.ok === false) {
46
+ throw new Error(`${json?.error ?? "request_failed"}: ${json?.message ?? response.statusText}`);
47
+ }
48
+ return json;
49
+ }
package/src/main.js ADDED
@@ -0,0 +1,59 @@
1
+ import { runAuthLogin } from "./commands/auth-login.js";
2
+ import { runInstall } from "./commands/install.js";
3
+ import { runDoctor } from "./commands/doctor.js";
4
+ import { runPlatform } from "./commands/platform.js";
5
+ import { runMcpServe } from "./commands/mcp-serve.js";
6
+ import { runSession } from "./commands/session-run.js";
7
+
8
+ export async function main() {
9
+ const args = process.argv.slice(2);
10
+ const [group, action, ...rest] = args;
11
+
12
+ if (!group) {
13
+ await runInstall([]);
14
+ return;
15
+ }
16
+ if (group === "auth" && action === "login") {
17
+ await runAuthLogin(rest);
18
+ return;
19
+ }
20
+ if (group === "install") {
21
+ await runInstall([action, ...rest].filter(Boolean));
22
+ return;
23
+ }
24
+ if (group === "doctor") {
25
+ await runDoctor([action, ...rest].filter(Boolean));
26
+ return;
27
+ }
28
+ if (group === "session" && action === "run") {
29
+ await runSession(rest);
30
+ return;
31
+ }
32
+ if (group === "platform") {
33
+ await runPlatform([action, ...rest].filter(Boolean));
34
+ return;
35
+ }
36
+ if (group === "mcp" && action === "serve") {
37
+ await runMcpServe();
38
+ return;
39
+ }
40
+ if (group === "help" || group === "--help" || group === "-h") {
41
+ printUsage();
42
+ return;
43
+ }
44
+
45
+ printUsage();
46
+ process.exitCode = 1;
47
+ }
48
+
49
+ function printUsage() {
50
+ console.log(`Usage:
51
+ naia install [--runtime-url <url>] [--webapp-url <url>] [--targets codex,claude-code]
52
+ naia doctor [--runtime-url <url>] [--profile default]
53
+ naia auth login --org-slug <slug> [--webapp-url <url>] [--profile default]
54
+ naia session run --message "hola" [--runtime-url <url>]
55
+ naia platform invoices list [--runtime-url <url>]
56
+ naia mcp serve
57
+ `);
58
+ }
59
+