zyntry 0.2.0 → 0.4.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/index.mjs +288 -53
- package/package.json +5 -1
- package/postinstall.js +15 -0
package/index.mjs
CHANGED
|
@@ -145,6 +145,8 @@ function yamlFor(project, credentials) {
|
|
|
145
145
|
` name: "${project.name}"`,
|
|
146
146
|
` slug: "${project.slug || ""}"`,
|
|
147
147
|
` environment: "${project.environment}"`,
|
|
148
|
+
` plan: "${project.plan_code || "free"}"`,
|
|
149
|
+
` region: "automatic"`,
|
|
148
150
|
``,
|
|
149
151
|
`api:`,
|
|
150
152
|
` base_url: "${credentials.api_base_url}"`,
|
|
@@ -292,6 +294,9 @@ Usage:
|
|
|
292
294
|
zyntry plans [create|list] Manage end-user rate plans
|
|
293
295
|
zyntry users [list|add] Manage end users and their usage
|
|
294
296
|
zyntry quota <user_id> Check an end-user's quota
|
|
297
|
+
zyntry upgrade [pro|studio] Upgrade this project's plan (opens checkout)
|
|
298
|
+
zyntry apply Apply zyntry.yaml to the project: plan,
|
|
299
|
+
region, and runtimes are reconciled
|
|
295
300
|
zyntry updates Show recent product updates
|
|
296
301
|
zyntry mcp Start the Zyntry MCP server (stdio) for
|
|
297
302
|
Claude Code, Cursor, Windsurf, and any MCP client
|
|
@@ -576,7 +581,7 @@ async function commandRun(rest) {
|
|
|
576
581
|
}
|
|
577
582
|
if (!result.ok) {
|
|
578
583
|
fail("Invoke failed: " + (result.data?.message || result.data?.error || result.status));
|
|
579
|
-
if (result.status === 402) dim("
|
|
584
|
+
if (result.status === 402) dim("This project's plan limit was reached. Upgrade with: " + COLORS.bold("zyntry upgrade pro"));
|
|
580
585
|
if (result.status === 429) dim(String(result.data?.reason || "Rate limited — retry shortly."));
|
|
581
586
|
process.exit(1);
|
|
582
587
|
}
|
|
@@ -613,91 +618,210 @@ const MCP_TOOLS = [
|
|
|
613
618
|
model: { type: "string", description: "Optional model id (e.g. gpt-4o-mini). Defaults to the runtime's routed model." },
|
|
614
619
|
project_id: { type: "string", description: "Optional project id; defaults to the zyntry.yaml project in the working directory." },
|
|
615
620
|
runtime_id: { type: "string", description: "Optional runtime id; defaults to the project's routing." },
|
|
621
|
+
end_user_id: { type: "string", description: "Optional end-user id for metering and quota enforcement." },
|
|
616
622
|
},
|
|
617
623
|
required: ["prompt"],
|
|
618
624
|
},
|
|
619
625
|
},
|
|
620
|
-
{
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
},
|
|
625
|
-
{
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
},
|
|
630
|
-
{
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
},
|
|
635
|
-
{
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
},
|
|
640
|
-
{
|
|
641
|
-
name: "recent_logs",
|
|
642
|
-
description: "Recent request logs for a Zyntry project: status, model, provider, latency, errors.",
|
|
643
|
-
inputSchema: { type: "object", properties: { project_id: { type: "string" }, limit: { type: "number", description: "Max entries (default 20)." } } },
|
|
644
|
-
},
|
|
626
|
+
{ name: "list_projects", description: "List the developer's Zyntry projects with plan and environment.", inputSchema: { type: "object", properties: {} } },
|
|
627
|
+
{ name: "create_project", description: "Create a new Zyntry project (Free tier; the paid-plan consent flow requires the interactive CLI).", inputSchema: { type: "object", properties: { name: { type: "string" } }, required: ["name"] } },
|
|
628
|
+
{ name: "list_runtimes", description: "List the runtimes of a Zyntry project with environment, region, and health.", inputSchema: { type: "object", properties: { project_id: { type: "string" } } } },
|
|
629
|
+
{ name: "list_regions", description: "List the deployment regions available to the project's plan.", inputSchema: { type: "object", properties: { project_id: { type: "string" } } } },
|
|
630
|
+
{ name: "list_deployments", description: "List a runtime's deployments with region, status, version, and endpoint.", inputSchema: { type: "object", properties: { runtime_id: { type: "string" }, project_id: { type: "string" } } } },
|
|
631
|
+
{ name: "redeploy_runtime", description: "Queue a redeployment for a runtime. The new version replaces the active deployment once healthy.", inputSchema: { type: "object", properties: { runtime_id: { type: "string" }, project_id: { type: "string" } } } },
|
|
632
|
+
{ name: "recent_logs", description: "Recent request logs for a Zyntry project: status, model, provider, latency, errors.", inputSchema: { type: "object", properties: { project_id: { type: "string" }, limit: { type: "number" } } } },
|
|
633
|
+
{ name: "list_traces", description: "Recent request traces with span counts and outcome.", inputSchema: { type: "object", properties: { project_id: { type: "string" }, limit: { type: "number" } } } },
|
|
634
|
+
{ name: "usage_summary", description: "Project usage metrics: request volume, success rate, latency percentiles, and cost.", inputSchema: { type: "object", properties: { project_id: { type: "string" }, days: { type: "number", description: "Window in days (1, 7, 30). Default 7." } } } },
|
|
635
|
+
{ name: "list_models", description: "The model catalog available to the project's plan: provider, model ids, context windows, and pricing.", inputSchema: { type: "object", properties: { project_id: { type: "string" } } } },
|
|
636
|
+
{ name: "list_security_groups", description: "List the enforced security groups of a Zyntry project, with their rules.", inputSchema: { type: "object", properties: { project_id: { type: "string" } } } },
|
|
637
|
+
{ name: "security_activity", description: "Recent security activity: blocked requests, quota hits, and group changes.", inputSchema: { type: "object", properties: { project_id: { type: "string" } } } },
|
|
638
|
+
{ name: "quota", description: "The project's rate plans (end-user metering configuration).", inputSchema: { type: "object", properties: { project_id: { type: "string" } } } },
|
|
639
|
+
{ name: "list_end_users", description: "List the project's end users with their usage.", inputSchema: { type: "object", properties: { project_id: { type: "string" }, search: { type: "string" } } } },
|
|
640
|
+
{ name: "upsert_end_user", description: "Add or update an end user (idempotent by external_id). Optionally attach a rate plan.", inputSchema: { type: "object", properties: { external_id: { type: "string" }, display_name: { type: "string" }, email: { type: "string" }, rate_plan_id: { type: "string" }, project_id: { type: "string" } }, required: ["external_id"] } },
|
|
641
|
+
{ name: "list_api_keys", description: "List the project's API keys (prefix, scopes, runtime scope, last use — secrets are never returned).", inputSchema: { type: "object", properties: { project_id: { type: "string" } } } },
|
|
642
|
+
{ name: "list_webhooks", description: "List the project's webhook endpoints and their subscribed events.", inputSchema: { type: "object", properties: { project_id: { type: "string" } } } },
|
|
643
|
+
{ name: "list_backups", description: "List a runtime's backups with status and size.", inputSchema: { type: "object", properties: { runtime_id: { type: "string" }, project_id: { type: "string" } } } },
|
|
644
|
+
{ name: "create_backup", description: "Queue a backup for a runtime.", inputSchema: { type: "object", properties: { runtime_id: { type: "string" }, project_id: { type: "string" } } } },
|
|
645
|
+
{ name: "product_updates", description: "Recent Zyntry product updates.", inputSchema: { type: "object", properties: {} } },
|
|
645
646
|
];
|
|
647
|
+
|
|
648
|
+
const say = (text) => ({ content: [{ type: "text", text: String(text) }] });
|
|
649
|
+
const err = (text) => ({ isError: true, content: [{ type: "text", text: String(text) }] });
|
|
650
|
+
|
|
651
|
+
async function resolveRuntimeId(token, projectId, runtimeIdArg) {
|
|
652
|
+
if (runtimeIdArg) return String(runtimeIdArg);
|
|
653
|
+
const result = await api("/api/v1/runtimes?project_id=" + encodeURIComponent(projectId) + "&limit=50", {}, token);
|
|
654
|
+
const runtimes = result.ok ? (result.data.runtimes || result.data.items || []) : [];
|
|
655
|
+
return runtimes.length ? String(runtimes[0].id) : null;
|
|
656
|
+
}
|
|
646
657
|
|
|
647
658
|
async function mcpInvokeTool(name, args) {
|
|
648
659
|
const token = loadToken();
|
|
649
|
-
if (!token) return
|
|
650
|
-
|
|
660
|
+
if (!token) return err("Not logged in. The developer must run 'zyntry login' first.");
|
|
661
|
+
args = args || {};
|
|
662
|
+
let projectId = args.project_id || readProjectIdFromYamlOptional();
|
|
663
|
+
const needsProject = !["list_projects", "create_project", "product_updates", "invoke"].includes(name);
|
|
664
|
+
|
|
651
665
|
if (name === "invoke") {
|
|
652
|
-
if (!args
|
|
653
|
-
if (!projectId) return
|
|
666
|
+
if (!args.prompt) return err("prompt is required");
|
|
667
|
+
if (!projectId) return err("No project context: pass project_id or run zyntry init in the working directory.");
|
|
654
668
|
const body = { project_id: projectId, messages: [{ role: "user", content: String(args.prompt) }] };
|
|
655
669
|
if (args.model) body.model = String(args.model);
|
|
656
670
|
if (args.runtime_id) body.runtime_id = String(args.runtime_id);
|
|
671
|
+
if (args.end_user_id) body.end_user_id = String(args.end_user_id);
|
|
657
672
|
const result = await api("/api/v1/invoke", { method: "POST", body: JSON.stringify(body) }, token);
|
|
658
673
|
if (result.status === 202 && result.data?.status === "approval_required") {
|
|
659
|
-
return
|
|
674
|
+
return say("A tool requested approval before running: " + JSON.stringify(result.data.tool_call) + ". The developer can approve by re-running the CLI with --approve <call_id>.");
|
|
660
675
|
}
|
|
661
|
-
if (!result.ok) return
|
|
676
|
+
if (!result.ok) return err("Invoke failed (" + result.status + "): " + (result.data?.message || result.data?.error || "unknown"));
|
|
662
677
|
const usage = result.data.usage || {};
|
|
663
|
-
return
|
|
678
|
+
return say(String(result.data.output ?? "") + "\n\n[provider " + (result.data.provider ?? "—") + " · model " + (result.data.model ?? "—") + " · " + (usage.input_tokens ?? 0) + "→" + (usage.output_tokens ?? 0) + " tokens · $" + Number(usage.cost_usd ?? 0).toFixed(6) + " · request " + (result.data.request_id ?? "—") + "]");
|
|
664
679
|
}
|
|
680
|
+
|
|
665
681
|
if (name === "list_projects") {
|
|
666
682
|
const result = await api("/api/v1/projects", {}, token);
|
|
667
|
-
if (!result.ok) return
|
|
668
|
-
const
|
|
669
|
-
return
|
|
683
|
+
if (!result.ok) return err("Failed (" + result.status + ")");
|
|
684
|
+
const projects = result.data.projects || [];
|
|
685
|
+
return say(projects.length ? projects.map((p) => p.name + " [" + (p.plan_code ?? "free") + "/" + (p.environment ?? "—") + "] id=" + p.id).join("\n") : "No projects yet.");
|
|
670
686
|
}
|
|
671
|
-
if (
|
|
687
|
+
if (name === "create_project") {
|
|
688
|
+
if (!args.name) return err("name is required");
|
|
689
|
+
const account = await api("/api/v1/cli/account", {}, token);
|
|
690
|
+
if (!account.ok) return err("Account check failed (" + account.status + ")");
|
|
691
|
+
if (!account.data.free_project_available) return err("Free allowance used; paid plans need the interactive 'zyntry init' consent flow.");
|
|
692
|
+
const init = await api("/api/v1/cli/init", { method: "POST", body: JSON.stringify({ name: String(args.name), plan_code: "free" }) }, token);
|
|
693
|
+
if (!init.ok) return err(init.data?.message || "Creation failed (" + init.status + ")");
|
|
694
|
+
return say("Created project " + init.data.project.name + " (" + init.data.project.id + ")");
|
|
695
|
+
}
|
|
696
|
+
if (name === "product_updates") {
|
|
697
|
+
const result = await api("/api/v1/product-updates", {}, token);
|
|
698
|
+
if (!result.ok) return err("Failed (" + result.status + ")");
|
|
699
|
+
const updates = result.data.items || [];
|
|
700
|
+
return say(updates.length ? updates.map((u) => String(u.published_at ?? "").slice(0, 10) + " — " + u.title).join("\n") : "No product updates yet.");
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
if (needsProject && !projectId) return err("No project context: pass project_id or run zyntry init in the working directory.");
|
|
704
|
+
|
|
672
705
|
if (name === "list_runtimes") {
|
|
673
706
|
const result = await api("/api/v1/runtimes?project_id=" + encodeURIComponent(projectId) + "&limit=50", {}, token);
|
|
674
|
-
if (!result.ok) return
|
|
707
|
+
if (!result.ok) return err("Failed (" + result.status + ")");
|
|
675
708
|
const runtimes = result.data.runtimes || result.data.items || [];
|
|
676
|
-
return
|
|
709
|
+
return say(runtimes.length ? runtimes.map((r) => r.name + " [" + (r.environment ?? "—") + "/" + (r.region ?? "automatic") + " · " + String(r.health ?? r.status ?? "?") + "] id=" + r.id).join("\n") : "No runtimes.");
|
|
710
|
+
}
|
|
711
|
+
if (name === "list_regions") {
|
|
712
|
+
const result = await api("/api/v1/regions?project_id=" + encodeURIComponent(projectId), {}, token);
|
|
713
|
+
if (!result.ok) return err("Failed (" + result.status + ")");
|
|
714
|
+
const regions = result.data.regions || result.data.items || [];
|
|
715
|
+
return say(regions.length ? regions.map((r) => r.name + " [" + String(r.status ?? (r.available ? "available" : "plan required")) + "] id=" + r.id).join("\n") : "No regions returned.");
|
|
716
|
+
}
|
|
717
|
+
if (name === "list_deployments") {
|
|
718
|
+
const runtimeId = await resolveRuntimeId(token, projectId, args.runtime_id);
|
|
719
|
+
if (!runtimeId) return err("No runtimes in this project.");
|
|
720
|
+
const result = await api("/api/v1/runtimes/" + encodeURIComponent(runtimeId) + "/deployments", {}, token);
|
|
721
|
+
if (!result.ok) return err("Failed (" + result.status + ")");
|
|
722
|
+
const deployments = result.data.deployments || result.data.items || [];
|
|
723
|
+
return say(deployments.length ? deployments.map((d) => (d.region ?? "automatic") + " [" + String(d.health ?? d.status ?? "?") + "] v" + (d.version ?? "—") + (d.endpoint ? " " + d.endpoint : "")).join("\n") : "No deployments recorded.");
|
|
724
|
+
}
|
|
725
|
+
if (name === "redeploy_runtime") {
|
|
726
|
+
const runtimeId = await resolveRuntimeId(token, projectId, args.runtime_id);
|
|
727
|
+
if (!runtimeId) return err("No runtimes in this project.");
|
|
728
|
+
const result = await api("/api/v1/runtimes/" + encodeURIComponent(runtimeId) + "/deployments", { method: "POST" }, token);
|
|
729
|
+
if (!result.ok) return err("Redeploy failed (" + result.status + "): " + (result.data?.message || result.data?.error || ""));
|
|
730
|
+
return say("Redeployment queued for runtime " + runtimeId + " — the new version replaces the active deployment when healthy.");
|
|
731
|
+
}
|
|
732
|
+
if (name === "recent_logs") {
|
|
733
|
+
const limit = Math.min(Math.max(Number(args.limit) || 20, 1), 50);
|
|
734
|
+
const runtimeId = await resolveRuntimeId(token, projectId, args.runtime_id);
|
|
735
|
+
if (!runtimeId) return say("No runtimes — no logs yet.");
|
|
736
|
+
const result = await api("/api/v1/runtimes/" + encodeURIComponent(runtimeId) + "/logs?limit=" + limit, {}, token);
|
|
737
|
+
if (!result.ok) return err("Logs failed (" + result.status + ")");
|
|
738
|
+
const logs = result.data.logs || result.data.items || [];
|
|
739
|
+
return say(logs.length ? logs.map((l) => (l.created_at ?? "") + " [" + (l.status ?? "?") + "] " + (l.model ?? "—") + "/" + (l.provider ?? "—") + " " + (l.latency_ms ?? "—") + "ms" + (l.error_category ? " err=" + l.error_category : "")).join("\n") : "No logs yet.");
|
|
740
|
+
}
|
|
741
|
+
if (name === "list_traces") {
|
|
742
|
+
const limit = Math.min(Math.max(Number(args.limit) || 20, 1), 100);
|
|
743
|
+
const result = await api("/api/v1/insights/projects/" + encodeURIComponent(projectId) + "/traces?limit=" + limit, {}, token);
|
|
744
|
+
if (!result.ok) return err("Failed (" + result.status + ")");
|
|
745
|
+
const traces = result.data.items || [];
|
|
746
|
+
return say(traces.length ? traces.map((t) => (t.started_at ?? "") + " [" + (t.status ?? "?") + " · " + (t.spans?.length ?? t.span_count ?? 0) + " spans] " + (t.id ?? "")).join("\n") : "No traces yet.");
|
|
747
|
+
}
|
|
748
|
+
if (name === "usage_summary") {
|
|
749
|
+
const days = [1, 7, 30].includes(Number(args.days)) ? Number(args.days) : 7;
|
|
750
|
+
const result = await api("/api/v1/insights/projects/" + encodeURIComponent(projectId) + "/metrics?days=" + days, {}, token);
|
|
751
|
+
if (!result.ok) return err("Failed (" + result.status + ")");
|
|
752
|
+
const m = result.data;
|
|
753
|
+
return say("Requests: " + (m.requests ?? 0) + " · success rate: " + (m.success_rate ?? 0) + "% · p50: " + (m.p50_latency_ms ?? "—") + "ms · p95: " + (m.p95_latency_ms ?? "—") + "ms · cost: $" + Number(m.cost ?? 0).toFixed(4) + " (last " + days + " day" + (days === 1 ? "" : "s") + ")");
|
|
754
|
+
}
|
|
755
|
+
if (name === "list_models") {
|
|
756
|
+
const result = await api("/api/v1/models?project_id=" + encodeURIComponent(projectId), {}, token);
|
|
757
|
+
if (!result.ok) return err("Failed (" + result.status + ")");
|
|
758
|
+
const models = result.data.models || result.data.items || result.data || [];
|
|
759
|
+
const list = Array.isArray(models) ? models : [];
|
|
760
|
+
return say(list.length ? list.map((mm) => (mm.provider ?? "—") + "/" + (mm.id ?? mm.model ?? "—") + " [ctx " + (mm.context_window ?? mm.context ?? "?") + "]").join("\n") : "No models returned.");
|
|
677
761
|
}
|
|
678
762
|
if (name === "list_security_groups") {
|
|
679
763
|
const result = await api("/api/v1/projects/" + encodeURIComponent(projectId) + "/security-groups", {}, token);
|
|
680
|
-
if (!result.ok) return
|
|
764
|
+
if (!result.ok) return err("Failed (" + result.status + "): " + (result.data?.message || result.data?.error || ""));
|
|
681
765
|
const groups = result.data.items || [];
|
|
682
|
-
return
|
|
766
|
+
return say(groups.length ? groups.map((g) => g.name + " [" + (g.enabled ? "enabled" : "disabled") + " · " + (g.rules || []).length + " rules · " + (g.runtime_ids || []).length + " runtimes] id=" + g.id).join("\n") : "No security groups.");
|
|
767
|
+
}
|
|
768
|
+
if (name === "security_activity") {
|
|
769
|
+
const result = await api("/api/v1/projects/" + encodeURIComponent(projectId) + "/security-groups/activity", {}, token);
|
|
770
|
+
if (!result.ok) return err("Failed (" + result.status + "): " + (result.data?.message || result.data?.error || ""));
|
|
771
|
+
const events = result.data.items || [];
|
|
772
|
+
return say(events.length ? events.slice(0, 20).map((e) => (e.created_at ?? "") + " " + (e.event_type ?? "?") + (e.data?.reason ? " · " + e.data.reason : "")).join("\n") : "No security activity yet.");
|
|
683
773
|
}
|
|
684
774
|
if (name === "quota") {
|
|
685
775
|
const result = await api("/api/v1/projects/" + encodeURIComponent(projectId) + "/rate-plans", {}, token);
|
|
686
|
-
if (!result.ok) return
|
|
776
|
+
if (!result.ok) return err("Failed (" + result.status + ")");
|
|
687
777
|
const plans = result.data.items || result.data.plans || [];
|
|
688
|
-
return
|
|
778
|
+
return say(plans.length ? JSON.stringify(plans, null, 2) : "No rate plans configured; end-user metering is inactive for this project.");
|
|
689
779
|
}
|
|
690
|
-
if (name === "
|
|
691
|
-
const
|
|
692
|
-
const
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
780
|
+
if (name === "list_end_users") {
|
|
781
|
+
const search = args.search ? "&search=" + encodeURIComponent(String(args.search)) : "";
|
|
782
|
+
const result = await api("/api/v1/projects/" + encodeURIComponent(projectId) + "/end-users?limit=50" + search, {}, token);
|
|
783
|
+
if (!result.ok) return err("Failed (" + result.status + ")");
|
|
784
|
+
const users = result.data.end_users || result.data.items || [];
|
|
785
|
+
return say(users.length ? users.map((u) => (u.external_id ?? u.id) + (u.display_name ? " — " + u.display_name : "") + (u.rate_plan_id ? " [plan " + u.rate_plan_id + "]" : "")).join("\n") : "No end users yet.");
|
|
786
|
+
}
|
|
787
|
+
if (name === "upsert_end_user") {
|
|
788
|
+
if (!args.external_id) return err("external_id is required");
|
|
789
|
+
const body = { external_id: String(args.external_id) };
|
|
790
|
+
if (args.display_name) body.display_name = String(args.display_name);
|
|
791
|
+
if (args.email) body.email = String(args.email);
|
|
792
|
+
if (args.rate_plan_id) body.rate_plan_id = String(args.rate_plan_id);
|
|
793
|
+
const result = await api("/api/v1/projects/" + encodeURIComponent(projectId) + "/end-users", { method: "POST", body: JSON.stringify(body) }, token);
|
|
794
|
+
if (!result.ok) return err("Failed (" + result.status + "): " + (result.data?.message || result.data?.error || ""));
|
|
795
|
+
return say("End user " + (result.data.external_id ?? args.external_id) + " saved.");
|
|
699
796
|
}
|
|
700
|
-
|
|
797
|
+
if (name === "list_api_keys") {
|
|
798
|
+
const result = await api("/api/v1/apikeys?project_id=" + encodeURIComponent(projectId), {}, token);
|
|
799
|
+
if (!result.ok) return err("Failed (" + result.status + ")");
|
|
800
|
+
const keys = result.data.api_keys || result.data.items || [];
|
|
801
|
+
return say(keys.length ? keys.map((k) => (k.name ?? "key") + " [" + (k.environment ?? "—") + " · " + (k.status ?? (k.revoked ? "revoked" : "active")) + " · prefix " + (k.prefix ?? k.key_prefix ?? "—") + "]").join("\n") : "No API keys.");
|
|
802
|
+
}
|
|
803
|
+
if (name === "list_webhooks") {
|
|
804
|
+
const result = await api("/api/v1/webhooks?project_id=" + encodeURIComponent(projectId), {}, token);
|
|
805
|
+
if (!result.ok) return err("Failed (" + result.status + ")");
|
|
806
|
+
const webhooks = result.data.items || [];
|
|
807
|
+
return say(webhooks.length ? webhooks.map((w) => (w.url ?? "endpoint") + " [" + (w.events || []).length + " events · " + (w.active ? "active" : "inactive") + "]").join("\n") : "No webhooks.");
|
|
808
|
+
}
|
|
809
|
+
if (name === "list_backups") {
|
|
810
|
+
const runtimeId = await resolveRuntimeId(token, projectId, args.runtime_id);
|
|
811
|
+
if (!runtimeId) return err("No runtimes in this project.");
|
|
812
|
+
const result = await api("/api/v1/insights/runtimes/" + encodeURIComponent(runtimeId) + "/backups", {}, token);
|
|
813
|
+
if (!result.ok) return err("Failed (" + result.status + ")");
|
|
814
|
+
const backups = result.data.items || result.data.backups || [];
|
|
815
|
+
return say(backups.length ? backups.map((b) => (b.created_at ?? "") + " [" + (b.status ?? "?") + (b.size_bytes ? " · " + b.size_bytes + " bytes" : "") + "] " + (b.id ?? "")).join("\n") : "No backups yet.");
|
|
816
|
+
}
|
|
817
|
+
if (name === "create_backup") {
|
|
818
|
+
const runtimeId = await resolveRuntimeId(token, projectId, args.runtime_id);
|
|
819
|
+
if (!runtimeId) return err("No runtimes in this project.");
|
|
820
|
+
const result = await api("/api/v1/insights/runtimes/" + encodeURIComponent(runtimeId) + "/backups", { method: "POST" }, token);
|
|
821
|
+
if (!result.ok) return err("Failed (" + result.status + "): " + (result.data?.message || result.data?.error || ""));
|
|
822
|
+
return say("Backup queued for runtime " + runtimeId + ".");
|
|
823
|
+
}
|
|
824
|
+
return err("Unknown tool: " + name);
|
|
701
825
|
}
|
|
702
826
|
|
|
703
827
|
function commandMcp() {
|
|
@@ -729,6 +853,115 @@ function commandMcp() {
|
|
|
729
853
|
rl.on("close", () => process.exit(0));
|
|
730
854
|
}
|
|
731
855
|
|
|
856
|
+
/* ------------------------------- upgrade ---------------------------------- */
|
|
857
|
+
|
|
858
|
+
async function commandUpgrade(planArg, projectIdArg) {
|
|
859
|
+
const token = requireToken();
|
|
860
|
+
const planCode = (planArg || "pro").toLowerCase();
|
|
861
|
+
if (!["pro", "studio"].includes(planCode)) { fail("Plans available from the CLI: pro, studio. (Enterprise is sales-assisted.)"); return; }
|
|
862
|
+
const projectId = projectIdArg || readProjectIdFromYamlOptional();
|
|
863
|
+
if (!projectId) { fail("No project context. Run " + COLORS.bold("zyntry init") + " in this directory, or pass -p <project_id>."); return; }
|
|
864
|
+
|
|
865
|
+
const catalog = await api("/api/v1/projects/plans/catalog", {}, token);
|
|
866
|
+
const plan = catalog.ok ? (catalog.data.plans || []).find((p) => p.code === planCode) : null;
|
|
867
|
+
const price = plan ? ("$" + (plan.price_cents / 100).toFixed(2) + "/" + (plan.billing_interval || "month")) : planCode;
|
|
868
|
+
log("Upgrading project to " + COLORS.bold(planCode) + " (" + price + " per project).");
|
|
869
|
+
const consent = await confirm("Authorize the charge? This opens Zyntry checkout in your browser.");
|
|
870
|
+
if (!consent) { dim("Nothing was charged and nothing changed."); return; }
|
|
871
|
+
|
|
872
|
+
const idem = "cli-upgrade-" + projectId + "-" + planCode + "-" + Date.now();
|
|
873
|
+
const result = await api("/api/v1/billing/subscriptions/checkout", {
|
|
874
|
+
method: "POST",
|
|
875
|
+
headers: { "Idempotency-Key": idem },
|
|
876
|
+
body: JSON.stringify({ project_id: projectId, plan_code: planCode }),
|
|
877
|
+
}, token);
|
|
878
|
+
if (!result.ok || !result.data?.url) { fail("Checkout could not be created: " + (result.data?.message || result.status)); process.exit(1); }
|
|
879
|
+
log("\n Complete payment: " + COLORS.cyan(result.data.url));
|
|
880
|
+
openBrowser(result.data.url);
|
|
881
|
+
dim(" The plan activates as soon as checkout and the billing webhook complete —");
|
|
882
|
+
dim(" then every " + planCode + " capability unlocks on this project.");
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
/* -------------------------------- apply ----------------------------------- */
|
|
886
|
+
|
|
887
|
+
function parseYamlConfig() {
|
|
888
|
+
const yamlPath = join(process.cwd(), "zyntry.yaml");
|
|
889
|
+
if (!existsSync(yamlPath)) { fail("No zyntry.yaml in this directory. Run zyntry init first."); process.exit(1); }
|
|
890
|
+
const yaml = readFileSync(yamlPath, "utf8");
|
|
891
|
+
const head = yaml.split("runtimes:")[0];
|
|
892
|
+
const config = {
|
|
893
|
+
projectId: yaml.match(/id:\s*"([^"]+)"/)?.[1] ?? null,
|
|
894
|
+
plan: head.match(/plan:\s*"([^"]+)"/)?.[1] ?? null,
|
|
895
|
+
region: head.match(/region:\s*"([^"]+)"/)?.[1] ?? null,
|
|
896
|
+
runtimes: [],
|
|
897
|
+
};
|
|
898
|
+
const runtimesBlock = yaml.split(/^runtimes:\s*$/m)[1];
|
|
899
|
+
if (runtimesBlock) {
|
|
900
|
+
let current = null;
|
|
901
|
+
for (const rawLine of runtimesBlock.split("\n")) {
|
|
902
|
+
const line = rawLine.trim();
|
|
903
|
+
if (!line || line.startsWith("#")) continue;
|
|
904
|
+
if (line.startsWith("- ")) { if (current) config.runtimes.push(current); current = { name: line.slice(2).replace(/^name:\s*/, "").replace(/"/g, "").trim() }; }
|
|
905
|
+
else if (current && line.startsWith("environment:")) current.environment = line.split(":")[1].trim().replace(/"/g, "");
|
|
906
|
+
else if (current && line.startsWith("region:")) current.region = line.split(":")[1].trim().replace(/"/g, "");
|
|
907
|
+
else if (line && !rawLine.startsWith(" ") && !rawLine.startsWith("-")) { if (current) { config.runtimes.push(current); current = null; } break; }
|
|
908
|
+
}
|
|
909
|
+
if (current) config.runtimes.push(current);
|
|
910
|
+
config.runtimes = config.runtimes.filter((r) => r && r.name);
|
|
911
|
+
}
|
|
912
|
+
return config;
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
async function commandApply() {
|
|
916
|
+
const token = requireToken();
|
|
917
|
+
const config = parseYamlConfig();
|
|
918
|
+
if (!config.projectId) { fail("Could not read project id from zyntry.yaml."); return; }
|
|
919
|
+
|
|
920
|
+
const projectsResult = await api("/api/v1/projects", {}, token);
|
|
921
|
+
if (!projectsResult.ok) { fail("Unable to load projects (" + projectsResult.status + ")."); process.exit(1); }
|
|
922
|
+
const project = (projectsResult.data.projects || []).find((p) => p.id === config.projectId);
|
|
923
|
+
if (!project) { fail("The project in zyntry.yaml is not on this account."); process.exit(1); }
|
|
924
|
+
|
|
925
|
+
log("Applying " + COLORS.bold("zyntry.yaml") + " to " + COLORS.bold(project.name) + " (" + (project.plan_code ?? "free") + ")…");
|
|
926
|
+
|
|
927
|
+
if (config.plan && String(config.plan) !== String(project.plan_code ?? "free")) {
|
|
928
|
+
log(" plan: " + (project.plan_code ?? "free") + " → " + config.plan);
|
|
929
|
+
if (["pro", "studio"].includes(config.plan)) {
|
|
930
|
+
await commandUpgrade(config.plan, config.projectId);
|
|
931
|
+
} else {
|
|
932
|
+
warn(" plan '" + config.plan + "' is not upgradable from the CLI; only pro and studio checkouts are supported.");
|
|
933
|
+
}
|
|
934
|
+
} else {
|
|
935
|
+
dim(" plan: " + (project.plan_code ?? "free") + " (unchanged)");
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
if (config.region && config.region !== "automatic") {
|
|
939
|
+
const patch = await api("/api/v1/projects/" + config.projectId, { method: "PATCH", body: JSON.stringify({ settings: { region: config.region } }) }, token);
|
|
940
|
+
if (patch.ok) ok(" region: " + config.region + " applied");
|
|
941
|
+
else if (patch.data?.error === "region_selection_unavailable") warn(" region: " + config.region + " requires a higher plan — unchanged.");
|
|
942
|
+
else warn(" region: could not apply (" + (patch.data?.message || patch.data?.error || patch.status) + ")");
|
|
943
|
+
} else {
|
|
944
|
+
dim(" region: automatic (unchanged)");
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
const runtimesResult = await api("/api/v1/runtimes?project_id=" + encodeURIComponent(config.projectId) + "&limit=50", {}, token);
|
|
948
|
+
const existing = runtimesResult.ok ? (runtimesResult.data.runtimes || runtimesResult.data.items || []) : [];
|
|
949
|
+
const existingNames = new Set(existing.map((r) => r.name));
|
|
950
|
+
let created = 0;
|
|
951
|
+
for (const wanted of config.runtimes) {
|
|
952
|
+
if (existingNames.has(wanted.name)) { dim(" runtime " + wanted.name + ": exists"); continue; }
|
|
953
|
+
const body = { project_id: config.projectId, name: wanted.name, environment: wanted.environment || "development" };
|
|
954
|
+
if (wanted.region && wanted.region !== "automatic") body.region = wanted.region;
|
|
955
|
+
const create = await api("/api/v1/runtimes", { method: "POST", body: JSON.stringify(body) }, token);
|
|
956
|
+
if (create.ok) { ok(" runtime " + wanted.name + ": created — provisioning"); created++; }
|
|
957
|
+
else warn(" runtime " + wanted.name + ": " + (create.data?.message || create.data?.error || "failed (" + create.status + ")"));
|
|
958
|
+
}
|
|
959
|
+
if (!config.runtimes.length) dim(" runtimes: none declared in zyntry.yaml");
|
|
960
|
+
log("");
|
|
961
|
+
if (created) ok("Apply complete — " + created + " runtime" + (created === 1 ? "" : "s") + " provisioning.");
|
|
962
|
+
else log("Apply complete.");
|
|
963
|
+
}
|
|
964
|
+
|
|
732
965
|
const [command, ...rest] = process.argv.slice(2);
|
|
733
966
|
switch (command) {
|
|
734
967
|
case "login": await commandLogin(); break;
|
|
@@ -738,6 +971,8 @@ switch (command) {
|
|
|
738
971
|
case "plans": await commandPlans(rest[0]); break;
|
|
739
972
|
case "users": await commandUsers(rest[0]); break;
|
|
740
973
|
case "quota": await commandQuota(rest[0]); break;
|
|
974
|
+
case "upgrade": await commandUpgrade(rest[0], rest[1]); break;
|
|
975
|
+
case "apply": case "up": await commandApply(); break;
|
|
741
976
|
case "projects": await commandProjects(rest[0], rest[1]); break;
|
|
742
977
|
case "run": case "invoke": await commandRun(rest); break;
|
|
743
978
|
case "mcp": commandMcp(); break;
|
package/package.json
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zyntry",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "The Zyntry CLI — run AI inference, manage runtimes, security groups, and end-user metering from the terminal. Ships with a built-in MCP server for Claude Code, Cursor, and Windsurf.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"bin": {
|
|
8
8
|
"zyntry": "./index.mjs"
|
|
9
9
|
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"postinstall": "node postinstall.js"
|
|
12
|
+
},
|
|
10
13
|
"engines": {
|
|
11
14
|
"node": ">=18"
|
|
12
15
|
},
|
|
@@ -27,6 +30,7 @@
|
|
|
27
30
|
},
|
|
28
31
|
"files": [
|
|
29
32
|
"index.mjs",
|
|
33
|
+
"postinstall.js",
|
|
30
34
|
"README.md"
|
|
31
35
|
],
|
|
32
36
|
"preferGlobal": true
|
package/postinstall.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/** Post-install welcome for the Zyntry CLI. Prints only — no network, no
|
|
3
|
+
* filesystem writes, safe in CI and offline installs. */
|
|
4
|
+
const line = process.platform === "win32" ? "" : "";
|
|
5
|
+
process.stdout.write([
|
|
6
|
+
"",
|
|
7
|
+
"\x1b[1mZyntry CLI installed\x1b[0m",
|
|
8
|
+
"",
|
|
9
|
+
" \x1b[36mzyntry login\x1b[0m approve this device in your browser",
|
|
10
|
+
" \x1b[36mzyntry init\x1b[0m create or link a project in this folder",
|
|
11
|
+
" \x1b[36mzyntry run \"hello\"\x1b[0m run your first inference",
|
|
12
|
+
"",
|
|
13
|
+
" Docs: https://zyntry.space/docs",
|
|
14
|
+
"",
|
|
15
|
+
].join("\n") + "\n");
|