openliate 0.0.1 → 0.1.5

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/LICENSE +21 -21
  2. package/README.md +73 -241
  3. package/README.npm.md +128 -0
  4. package/dist/bin.js +24634 -42274
  5. package/dist/liate.js +39468 -0
  6. package/dist/runtime/hono.js +28061 -0
  7. package/dist/runtime/index.js +28061 -0
  8. package/hub/agents/docgyan-agent/agent.json +27 -0
  9. package/hub/agents/docgyan-agent/agent.ts +39 -0
  10. package/hub/agents/gnani-agent/agent.json +17 -0
  11. package/hub/agents/neon-agent/agent.json +18 -0
  12. package/hub/agents/prism-agent/agent.json +17 -0
  13. package/hub/agents/sarvam-agent/agent.json +1 -3
  14. package/package.json +33 -21
  15. package/src/cli/index.ts +346 -0
  16. package/src/cli/resolver.ts +153 -0
  17. package/src/core/aum.ts +87 -28
  18. package/src/core/om.ts +159 -0
  19. package/src/core/spec.ts +112 -0
  20. package/src/core/uuid.ts +5 -16
  21. package/src/core/version.ts +2 -0
  22. package/src/layers/agent/harness.ts +118 -0
  23. package/src/{agent → layers/agent}/loop.ts +44 -24
  24. package/src/layers/agent/skills.ts +302 -0
  25. package/src/{agent → layers/agent}/types.ts +14 -1
  26. package/src/{environment/environment.ts → layers/environment/sandbox.ts} +24 -5
  27. package/src/{environment → layers/environment}/types.ts +8 -0
  28. package/src/layers/integration/knowledge.ts +187 -0
  29. package/src/layers/integration/lib.ts +167 -0
  30. package/src/{integration → layers/integration}/memory.ts +49 -67
  31. package/src/layers/integration/repo.ts +273 -0
  32. package/src/{integration → layers/integration}/types.ts +60 -31
  33. package/src/layers/llm/model.ts +916 -0
  34. package/src/layers/llm/types.ts +64 -0
  35. package/src/{tools → layers/tools}/mcp.ts +24 -10
  36. package/src/layers/tools/registry.ts +307 -0
  37. package/src/{tools → layers/tools}/server.ts +12 -13
  38. package/src/{tools → layers/tools}/types.ts +3 -2
  39. package/src/liate.ts +64 -24
  40. package/src/routes/skills.ts +73 -0
  41. package/src/runtime/hono.ts +346 -0
  42. package/src/runtime/wasm.ts +23 -0
  43. package/src/scaffold/project.ts +188 -0
  44. package/dist/engine/engine.zip +0 -0
  45. package/dist/engine/index.js +0 -36790
  46. package/hub/agents/email-agent/agent.json +0 -19
  47. package/hub/agents/general-agent/agent.json +0 -18
  48. package/hub/agents/identity-agent/agent.json +0 -19
  49. package/hub/agents/research-agent/agent.json +0 -18
  50. package/hub/llm/sarvam.json +0 -27
  51. package/hub/mcp/agentmail.json +0 -10
  52. package/hub/mcp/fetch.json +0 -9
  53. package/hub/mcp/neon.json +0 -12
  54. package/hub/mcp/sarvam.json +0 -12
  55. package/hub/mcp/supabase.json +0 -12
  56. package/hub/mcp/vercel.json +0 -12
  57. package/src/agent/agent.ts +0 -165
  58. package/src/cli.ts +0 -272
  59. package/src/engine/types.ts +0 -104
  60. package/src/integration/integration.ts +0 -37
  61. package/src/link/index.ts +0 -317
  62. package/src/link/neon.ts +0 -646
  63. package/src/link/supabase.ts +0 -567
  64. package/src/link/vercel.ts +0 -633
  65. package/src/llm/config.ts +0 -46
  66. package/src/llm/hub.ts +0 -59
  67. package/src/llm/llm.ts +0 -60
  68. package/src/llm/sarvam.ts +0 -136
  69. package/src/server/engine.ts +0 -277
  70. package/src/server/index.ts +0 -32
  71. package/src/tools/builtin/fetch.ts +0 -66
  72. package/src/tools/builtin/identity.ts +0 -131
  73. package/src/tools/registry.ts +0 -218
@@ -1,19 +0,0 @@
1
- {
2
- "L": "sarvam/sarvam-105b",
3
- "I": {
4
- "memory": "sessions/email-agent"
5
- },
6
- "A": {
7
- "name": "email_agent",
8
- "version": "1.0.0",
9
- "intent": "Autonomous Email Management Agent",
10
- "maxSteps": 5
11
- },
12
- "T": [
13
- "mcp:agentmail:list_inboxes,get_inbox,search_messages"
14
- ],
15
- "E": {
16
- "SARVAM_API_KEY": "$SARVAM_API_KEY",
17
- "AGENTMAIL_API_KEY": "$AGENTMAIL_API_KEY"
18
- }
19
- }
@@ -1,18 +0,0 @@
1
- {
2
- "L": "sarvam/sarvam-105b",
3
- "I": {
4
- "memory": "sessions/general-agent"
5
- },
6
- "A": {
7
- "name": "general_agent",
8
- "version": "1.0.0",
9
- "intent": "Explain Liate: The Open Source Backend Layer for AI Agents",
10
- "maxSteps": 5
11
- },
12
- "T": [
13
- "fetch"
14
- ],
15
- "E": {
16
- "SARVAM_API_KEY": "$SARVAM_API_KEY"
17
- }
18
- }
@@ -1,19 +0,0 @@
1
- {
2
- "L": "sarvam/sarvam-105b",
3
- "I": {
4
- "memory": "sessions/identity-agent"
5
- },
6
- "A": {
7
- "name": "identity_agent",
8
- "version": "1.0.0",
9
- "intent": "Verify and validate Indian identity credentials including 12-digit Aadhaar (Verhoeff checksum) and 10-character PAN card format with taxpayer classification.",
10
- "maxSteps": 5
11
- },
12
- "T": [
13
- "verify_identity"
14
- ],
15
- "E": {
16
- "SARVAM_API_KEY": "$SARVAM_API_KEY"
17
- }
18
- }
19
-
@@ -1,18 +0,0 @@
1
- {
2
- "L": "sarvam/sarvam-105b",
3
- "I": {
4
- "memory": "sessions/research-agent"
5
- },
6
- "A": {
7
- "name": "research_agent",
8
- "version": "1.0.0",
9
- "intent": "Autonomous Web Research and Knowledge Extraction Agent",
10
- "maxSteps": 5
11
- },
12
- "T": [
13
- "mcp:fetch"
14
- ],
15
- "E": {
16
- "SARVAM_API_KEY": "$SARVAM_API_KEY"
17
- }
18
- }
@@ -1,27 +0,0 @@
1
- {
2
- "name": "sarvam",
3
- "provider": "sarvam",
4
- "version": "v2",
5
- "base_url": "https://api.sarvam.ai/v2",
6
- "endpoint": "https://api.sarvam.ai/v2/chat/completions",
7
- "default_model": "sarvam-105b",
8
- "available_models": [
9
- "sarvam-105b",
10
- "sarvam-105b-conversations",
11
- "glm5.3",
12
- "glm5.3-flash",
13
- "gemma4",
14
- "deepseekv4.1-flash-1017",
15
- "kimi-k3"
16
- ],
17
- "headers": {
18
- "api-subscription-key": "$SARVAM_API_KEY",
19
- "Authorization": "Bearer $SARVAM_API_KEY",
20
- "Content-Type": "application/json"
21
- },
22
- "features": {
23
- "tool_calling": true,
24
- "streaming": true,
25
- "reasoning": true
26
- }
27
- }
@@ -1,10 +0,0 @@
1
- {
2
- "id": "agentmail",
3
- "name": "AgentMail",
4
- "description": "Send and receive agent emails via native MCP v2 API",
5
- "transport": "http",
6
- "url": "https://mcp.agentmail.to/mcp?apiKey=$AGENTMAIL_API_KEY",
7
- "headers": {
8
- "Accept": "application/json, text/event-stream"
9
- }
10
- }
@@ -1,9 +0,0 @@
1
- {
2
- "id": "fetch",
3
- "name": "Fetch",
4
- "description": "Web fetch and content extraction MCP server via uvx",
5
- "transport": "stdio",
6
- "command": "uvx",
7
- "args": ["mcp-server-fetch"]
8
- }
9
-
package/hub/mcp/neon.json DELETED
@@ -1,12 +0,0 @@
1
- {
2
- "id": "neon",
3
- "name": "Neon",
4
- "description": "Serverless Postgres database management, branching, and compute via Neon MCP",
5
- "transport": "http",
6
- "url": "https://mcp.neon.tech/mcp",
7
- "headers": {
8
- "Authorization": "Bearer $NEON_MCP_TOKEN",
9
- "Accept": "application/json, text/event-stream"
10
- }
11
- }
12
-
@@ -1,12 +0,0 @@
1
- {
2
- "id": "sarvam",
3
- "name": "Sarvam AI",
4
- "description": "Official Sarvam AI MCP server for speech, translation, Bulbul v4 TTS, and document intelligence",
5
- "transport": "stdio",
6
- "command": "uvx",
7
- "args": ["sarvam-mcp"],
8
- "env": {
9
- "SARVAM_API_KEY": "$SARVAM_API_KEY"
10
- }
11
- }
12
-
@@ -1,12 +0,0 @@
1
- {
2
- "id": "supabase",
3
- "name": "Supabase",
4
- "description": "Supabase Edge Functions, pgvector database, and storage management via Supabase MCP",
5
- "transport": "http",
6
- "url": "https://mcp.supabase.com/mcp",
7
- "headers": {
8
- "Authorization": "Bearer $SUPABASE_MCP_TOKEN",
9
- "Accept": "application/json, text/event-stream"
10
- }
11
- }
12
-
@@ -1,12 +0,0 @@
1
- {
2
- "id": "vercel",
3
- "name": "Vercel",
4
- "description": "Vercel deployment management, projects, and fluid compute via official Vercel MCP",
5
- "transport": "http",
6
- "url": "https://mcp.vercel.com",
7
- "headers": {
8
- "Authorization": "Bearer $VERCEL_TOKEN",
9
- "Accept": "application/json, text/event-stream"
10
- }
11
- }
12
-
@@ -1,165 +0,0 @@
1
- import fs from "fs";
2
- import path from "path";
3
- import { AUM } from "../core/aum";
4
- import type { AgentManifest } from "../engine/types";
5
- import { SarvamClient } from "../llm/sarvam";
6
- import { normalizeModelConfig } from "../llm/config";
7
- import { IntegrationResolver } from "../integration/integration";
8
- import type { MemoryProvider } from "../integration/types";
9
- import { ReActLoop } from "./loop";
10
- import type { AgentTool, AgentContext, AgentRunResult, AgentExecutionOptions } from "./types";
11
- import { ToolRegistry } from "../tools/registry";
12
- import { EnvironmentResolver } from "../environment/environment";
13
-
14
- export interface AgentConfigOptions {
15
- manifest?: string | AgentManifest;
16
- name?: string;
17
- version?: string;
18
- intent?: string;
19
- model?: string;
20
- memory?: string | MemoryProvider;
21
- sessionId?: string;
22
- tools?: Array<string | AgentTool>;
23
- apiKey?: string;
24
- }
25
-
26
- export class Agent {
27
- public readonly name: string;
28
- public readonly version: string;
29
- public readonly intent: string;
30
- public readonly model: string;
31
- public readonly manifest?: AgentManifest;
32
- private memory: MemoryProvider;
33
- private llm: SarvamClient;
34
- private tools: Map<string, AgentTool> = new Map();
35
- private maxSteps: number = 10;
36
- private toolsInitialized: boolean = false;
37
- private rawToolSpecs: Array<string | AgentTool> = [];
38
-
39
- constructor(options: AgentConfigOptions = {}) {
40
- let resolvedManifest: AgentManifest | undefined;
41
-
42
- if (typeof options.manifest === "string") {
43
- const manifestPath = path.resolve(process.cwd(), options.manifest);
44
- EnvironmentResolver.loadEnv(manifestPath);
45
- const raw = fs.readFileSync(manifestPath, "utf-8");
46
- resolvedManifest = AUM.resolveEnvironment(AUM.parse(raw));
47
- } else if (typeof options.manifest === "object") {
48
- EnvironmentResolver.loadEnv();
49
- resolvedManifest = AUM.resolveEnvironment(AUM.parse(options.manifest));
50
- }
51
-
52
- this.manifest = resolvedManifest;
53
-
54
- // Resolve Name, Version, and Intent from manifest or programmatic options
55
- this.name = options.name || resolvedManifest?.A?.name || "unnamed_agent";
56
- this.version = options.version || resolvedManifest?.A?.version || "1.0.0";
57
- this.intent = options.intent || resolvedManifest?.A?.intent || "Autonomous AI Agent";
58
- this.maxSteps = resolvedManifest?.A?.maxSteps ?? 10;
59
-
60
- // Resolve Model ([L] Layer) - strictly dynamic, no hardcoding
61
- const normalizedL = resolvedManifest?.L ? normalizeModelConfig(resolvedManifest.L) : undefined;
62
- const resolvedModel = options.model || normalizedL?.model;
63
- if (!resolvedModel) {
64
- throw new Error("Missing required model definition in Layer [L]");
65
- }
66
- this.model = resolvedModel;
67
-
68
- // Resolve Memory Provider ([I] Layer)
69
- if (options.memory && typeof options.memory === "object" && "append" in options.memory) {
70
- this.memory = options.memory as MemoryProvider;
71
- } else {
72
- const memoryConfig = options.memory || resolvedManifest?.I;
73
- const sId = options.sessionId || (typeof resolvedManifest?.I === "object" ? (resolvedManifest.I as any).sessionId || (resolvedManifest.I as any).session : undefined);
74
- this.memory = IntegrationResolver.resolveMemory(memoryConfig, {
75
- agentName: this.name,
76
- agentVersion: this.version
77
- }, sId);
78
- }
79
-
80
- // Resolve LLM Provider ([L] Layer)
81
- const apiKey = options.apiKey || resolvedManifest?.E?.SARVAM_API_KEY || process.env.SARVAM_API_KEY;
82
- this.llm = new SarvamClient(apiKey);
83
-
84
- // Collect tool specs from options or manifest ([T] Layer)
85
- if (options.tools) {
86
- this.rawToolSpecs.push(...options.tools);
87
- }
88
- if (resolvedManifest?.T) {
89
- if (Array.isArray(resolvedManifest.T)) {
90
- this.rawToolSpecs.push(...resolvedManifest.T);
91
- } else if (typeof resolvedManifest.T === "object") {
92
- for (const [key, val] of Object.entries(resolvedManifest.T)) {
93
- if (typeof val === "object" && val !== null) {
94
- this.rawToolSpecs.push({ id: key, name: key, ...val });
95
- } else {
96
- this.rawToolSpecs.push(key);
97
- }
98
- }
99
- }
100
- }
101
- }
102
-
103
- public registerTool(tool: AgentTool): void {
104
- this.tools.set(tool.name, tool);
105
- }
106
-
107
- public getMemory(): MemoryProvider {
108
- return this.memory;
109
- }
110
-
111
- public getContext(): AgentContext {
112
- return {
113
- agentName: this.name,
114
- agentVersion: this.version,
115
- sessionId: this.memory.sessionId,
116
- state: {
117
- intent: this.intent
118
- }
119
- };
120
- }
121
-
122
- public async getTools(): Promise<AgentTool[]> {
123
- await this.initializeTools();
124
- return Array.from(this.tools.values());
125
- }
126
-
127
- public async initializeTools(): Promise<void> {
128
- if (this.toolsInitialized) return;
129
-
130
- if (this.rawToolSpecs.length > 0) {
131
- const customEnv = (this.manifest?.E as Record<string, string>) || process.env;
132
- const resolved = await ToolRegistry.resolveTools(this.rawToolSpecs, customEnv);
133
- for (const t of resolved) {
134
- this.tools.set(t.name, t);
135
- }
136
- }
137
-
138
- this.toolsInitialized = true;
139
- }
140
-
141
- public async run(input: string, options: AgentExecutionOptions = {}): Promise<AgentRunResult> {
142
- await this.initializeTools();
143
-
144
- const allTools = [
145
- ...Array.from(this.tools.values()),
146
- ...(options.tools || [])
147
- ];
148
-
149
- const context = this.getContext();
150
-
151
- return ReActLoop.execute(
152
- input,
153
- this.llm,
154
- this.memory,
155
- allTools,
156
- context,
157
- {
158
- model: options.model ?? this.model,
159
- maxSteps: options.maxSteps ?? this.maxSteps,
160
- systemPrompt: options.systemPrompt,
161
- temperature: options.temperature
162
- }
163
- );
164
- }
165
- }
package/src/cli.ts DELETED
@@ -1,272 +0,0 @@
1
- #!/usr/bin/env node
2
- import path from "path";
3
- import fs from "fs";
4
- import { Agent } from "./agent/agent";
5
- import { EnvironmentResolver } from "./environment/environment";
6
- import { LiateMcp } from "./tools/mcp";
7
- import { link, relink, unlink, linkNeon, linkVercel, linkSupabase } from "./link/index";
8
- import { NeonMcpOAuth, NeonMcpClient } from "./link/neon";
9
- import { VercelMcpOAuth, VercelMcpClient } from "./link/vercel";
10
- import { startEngineServer } from "./server/engine";
11
-
12
- const VERSION = "0.1.0";
13
- const BANNER = `
14
- ===========================================================
15
- LIATE — Open Source Backend Layer for AI Agents
16
- "Don't build AI agents. Integrate by parts."
17
- Version: ${VERSION} (Standalone Autonomous Engine)
18
- ===========================================================
19
- `;
20
-
21
- function resolveManifestPath(input: string): string | null {
22
- const candidates = [
23
- path.resolve(process.cwd(), input),
24
- path.resolve(process.cwd(), "hub", "agents", input, "agent.json"),
25
- path.resolve(process.cwd(), "hub", "agents", input),
26
- path.resolve(__dirname, "..", "hub", "agents", input, "agent.json")
27
- ];
28
-
29
- for (const c of candidates) {
30
- if (fs.existsSync(c)) {
31
- const stat = fs.statSync(c);
32
- if (stat.isFile()) return c;
33
- if (stat.isDirectory()) {
34
- const sub = path.join(c, "agent.json");
35
- if (fs.existsSync(sub)) return sub;
36
- }
37
- }
38
- }
39
- return null;
40
- }
41
-
42
- async function main() {
43
- const args = process.argv.slice(2);
44
- const command = args[0];
45
-
46
- if (!command || command === "--help" || command === "-h" || command === "help") {
47
- console.log(BANNER);
48
- console.log(`Usage:
49
- liate run <agent.json|agent-name> "<prompt>" Execute an agent locally
50
- liate serve [--port <port>] Start the pure Liate engine HTTP server
51
- liate link Link Vercel, Neon & Supabase in 1 click (2.5M Free Runs)
52
- liate link --neon Link Neon & auto-deploy engine (1M runs, 2 vCPU, 8GB RAM)
53
- liate link --vercel Link Vercel & auto-deploy serverless engine (1M runs)
54
- liate link --vercel-daemons Link Vercel & auto-deploy 24/7 background daemon
55
- liate link --supabase Link Supabase & auto-deploy Edge Function (500k runs + pgvector)
56
- liate relink [--neon|--vercel|--supabase|--all] Relink cloud via fresh OAuth & redeploy
57
- liate unlink [--neon|--vercel|--supabase|--all] Unlink cloud & clear saved credentials
58
- liate env set <KEY>=<VALUE> Save persistent secret for engine
59
- liate version Show version and engine info
60
- liate help Show this help menu
61
-
62
- Examples:
63
- liate run agent.json "Hello Agent World!"
64
- liate run research-agent "Fetch https://skills.sh and summarize"
65
- liate serve --port 3000
66
- liate link
67
- liate link --neon
68
- liate link --vercel
69
- liate link --supabase
70
- liate relink --supabase
71
- liate unlink --all
72
- liate env set SARVAM_API_KEY="sk_live_..."
73
- `);
74
- process.exit(0);
75
- }
76
-
77
- if (command === "version" || command === "--version" || command === "-v") {
78
- console.log(`Liate Engine v${VERSION} (Bun native binary)`);
79
- process.exit(0);
80
- }
81
-
82
- // 1. Run Command
83
- if (command === "run") {
84
- const manifestArg = args[1];
85
- const promptArg = args[2];
86
-
87
- if (!manifestArg || !promptArg) {
88
- console.error("Error: 'liate run' requires an agent manifest or name and a prompt string.");
89
- console.error("Usage: liate run <agent.json|agent-name> \"<prompt>\"");
90
- process.exit(1);
91
- }
92
-
93
- const manifestPath = resolveManifestPath(manifestArg);
94
- if (!manifestPath) {
95
- console.error(`Error: Agent manifest not found for '${manifestArg}'.`);
96
- console.error(`Checked: ${path.resolve(process.cwd(), manifestArg)} and hub/agents/${manifestArg}/agent.json`);
97
- process.exit(1);
98
- }
99
-
100
- EnvironmentResolver.loadEnv(manifestPath);
101
-
102
- try {
103
- const agent = new Agent({ manifest: manifestPath });
104
- console.log(`[Liate] Booting ${agent.name} (v${agent.version})...`);
105
- console.log(`[Liate] Intent: "${agent.intent}"`);
106
-
107
- const t0 = Date.now();
108
- const result = await agent.run(promptArg);
109
- const latency = Date.now() - t0;
110
-
111
- if (result.thought) {
112
- console.log(`\n[Thought / Reasoning]:\n${result.thought}\n`);
113
- }
114
-
115
- console.log(`[Answer]:\n${result.text.trim()}\n`);
116
- console.log(`-----------------------------------------------------------`);
117
- console.log(`Model: ${result.model} | Latency: ${latency}ms | Steps: ${result.totalSteps}`);
118
- } catch (err: any) {
119
- console.error(`[Liate Error]: ${err.message}`);
120
- process.exit(1);
121
- } finally {
122
- await LiateMcp.closeAll();
123
- }
124
- return;
125
- }
126
-
127
- // 2. Serve Command (Pure Engine HTTP Server)
128
- if (command === "serve") {
129
- let port = 3000;
130
- const portIdx = args.indexOf("--port");
131
- if (portIdx !== -1 && args[portIdx + 1]) {
132
- port = parseInt(args[portIdx + 1], 10) || 3000;
133
- }
134
-
135
- EnvironmentResolver.loadEnv();
136
- const engine = startEngineServer({ port });
137
- console.log(`\n[Liate OM] Pure Runtime Engine running at: http://localhost:${port}`);
138
- console.log(`[Endpoints]:`);
139
- console.log(` - Health: GET http://localhost:${port}/health`);
140
- console.log(` - Agents: GET http://localhost:${port}/agents`);
141
- console.log(` - Run: POST http://localhost:${port}/run\n`);
142
- console.log(`Ready to execute AI agents on the fly.`);
143
-
144
- // Keep process alive
145
- return;
146
- }
147
-
148
- // 3. Link Command (1-Click Multi-Cloud Link & Instant Deployment)
149
- if (command === "link") {
150
- const isNeon = args.includes("--neon");
151
- const isVercelDaemon = args.includes("--vercel-daemons") || args.includes("--vercel-daemon") || (args.includes("--vercel") && (args.includes("--daemons") || args.includes("--daemon")));
152
- const isVercel = args.includes("--vercel") || isVercelDaemon;
153
- const isSupabase = args.includes("--supabase");
154
- const isBoth = args.includes("--both");
155
- // If no provider flag specified, default to --all (links Neon, Vercel & Supabase in 1 click!)
156
- const isAll = args.includes("--all") || (!isNeon && !isVercel && !isSupabase && !isBoth);
157
- const isRelink = args.includes("--relink") || args.includes("--force") || args.includes("-f");
158
- const keyIdx = args.indexOf("--key");
159
- const key = keyIdx !== -1 ? args[keyIdx + 1] : undefined;
160
-
161
- let provider: "neon" | "vercel" | "supabase" | "both" | "all" = "all";
162
- if (isAll) {
163
- provider = "all";
164
- } else if (isBoth) {
165
- provider = "both";
166
- } else if (isSupabase) {
167
- provider = "supabase";
168
- } else if (isVercel) {
169
- provider = "vercel";
170
- } else if (isNeon) {
171
- provider = "neon";
172
- }
173
-
174
- try {
175
- await link({ provider, key, isDaemon: isVercelDaemon, relink: isRelink });
176
- } catch (err: any) {
177
- console.error(`\n[Link Error]: ${err.message}`);
178
- process.exit(1);
179
- }
180
- return;
181
- }
182
-
183
- // 4. Relink Command (Force fresh OAuth authorization & redeployment)
184
- if (command === "relink") {
185
- const isNeon = args.includes("--neon");
186
- const isVercelDaemon = args.includes("--vercel-daemons") || args.includes("--vercel-daemon") || (args.includes("--vercel") && (args.includes("--daemons") || args.includes("--daemon")));
187
- const isVercel = args.includes("--vercel") || isVercelDaemon;
188
- const isSupabase = args.includes("--supabase");
189
- const isBoth = args.includes("--both");
190
- const isAll = args.includes("--all") || (!isNeon && !isVercel && !isSupabase && !isBoth);
191
- const keyIdx = args.indexOf("--key");
192
- const key = keyIdx !== -1 ? args[keyIdx + 1] : undefined;
193
-
194
- let provider: "neon" | "vercel" | "supabase" | "both" | "all" = "all";
195
- if (isAll) {
196
- provider = "all";
197
- } else if (isBoth) {
198
- provider = "both";
199
- } else if (isSupabase) {
200
- provider = "supabase";
201
- } else if (isVercel) {
202
- provider = "vercel";
203
- } else if (isNeon) {
204
- provider = "neon";
205
- }
206
-
207
- try {
208
- await relink({ provider, key, isDaemon: isVercelDaemon });
209
- } catch (err: any) {
210
- console.error(`\n[Relink Error]: ${err.message}`);
211
- process.exit(1);
212
- }
213
- return;
214
- }
215
-
216
- // 5. Unlink Command (Clear credentials & logout from providers)
217
- if (command === "unlink") {
218
- const isNeon = args.includes("--neon");
219
- const isVercel = args.includes("--vercel");
220
- const isSupabase = args.includes("--supabase");
221
- let provider: "neon" | "vercel" | "supabase" | "all" = "all";
222
- if (isNeon && !isVercel && !isSupabase) {
223
- provider = "neon";
224
- } else if (isVercel && !isNeon && !isSupabase) {
225
- provider = "vercel";
226
- } else if (isSupabase && !isNeon && !isVercel) {
227
- provider = "supabase";
228
- }
229
-
230
- try {
231
- await unlink(provider);
232
- } catch (err: any) {
233
- console.error(`\n[Unlink Error]: ${err.message}`);
234
- process.exit(1);
235
- }
236
- return;
237
- }
238
-
239
- // 5. Env Command (liate env set KEY=VALUE)
240
- if (command === "env") {
241
- const sub = args[1];
242
- if (sub === "set") {
243
- const pair = args[2];
244
- if (!pair || !pair.includes("=")) {
245
- console.error("Usage: liate env set KEY=VALUE");
246
- process.exit(1);
247
- }
248
- const [k, ...rest] = pair.split("=");
249
- const v = rest.join("=").replace(/^["']|["']$/g, "");
250
-
251
- const envPath = path.join(process.cwd(), ".env.local");
252
- let content = fs.existsSync(envPath) ? fs.readFileSync(envPath, "utf-8") : "";
253
- const regex = new RegExp(`^${k}=.*$`, "m");
254
- if (regex.test(content)) {
255
- content = content.replace(regex, `${k}="${v}"`);
256
- } else {
257
- content += `\n${k}="${v}"\n`;
258
- }
259
- fs.writeFileSync(envPath, content.trim() + "\n", "utf-8");
260
- console.log(`✔ Set ${k} in .env.local (Masked: ${v.slice(0, 4)}...${v.slice(-4)})`);
261
- return;
262
- }
263
- }
264
-
265
- console.error(`Unknown command: '${command}'. Run 'liate help' for available commands.`);
266
- process.exit(1);
267
- }
268
-
269
- main().catch(err => {
270
- console.error("Fatal:", err);
271
- process.exit(1);
272
- });