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.
- package/LICENSE +21 -21
- package/README.md +73 -241
- package/README.npm.md +128 -0
- package/dist/bin.js +24634 -42274
- package/dist/liate.js +39468 -0
- package/dist/runtime/hono.js +28061 -0
- package/dist/runtime/index.js +28061 -0
- package/hub/agents/docgyan-agent/agent.json +27 -0
- package/hub/agents/docgyan-agent/agent.ts +39 -0
- package/hub/agents/gnani-agent/agent.json +17 -0
- package/hub/agents/neon-agent/agent.json +18 -0
- package/hub/agents/prism-agent/agent.json +17 -0
- package/hub/agents/sarvam-agent/agent.json +1 -3
- package/package.json +33 -21
- package/src/cli/index.ts +346 -0
- package/src/cli/resolver.ts +153 -0
- package/src/core/aum.ts +87 -28
- package/src/core/om.ts +159 -0
- package/src/core/spec.ts +112 -0
- package/src/core/uuid.ts +5 -16
- package/src/core/version.ts +2 -0
- package/src/layers/agent/harness.ts +118 -0
- package/src/{agent → layers/agent}/loop.ts +44 -24
- package/src/layers/agent/skills.ts +302 -0
- package/src/{agent → layers/agent}/types.ts +14 -1
- package/src/{environment/environment.ts → layers/environment/sandbox.ts} +24 -5
- package/src/{environment → layers/environment}/types.ts +8 -0
- package/src/layers/integration/knowledge.ts +187 -0
- package/src/layers/integration/lib.ts +167 -0
- package/src/{integration → layers/integration}/memory.ts +49 -67
- package/src/layers/integration/repo.ts +273 -0
- package/src/{integration → layers/integration}/types.ts +60 -31
- package/src/layers/llm/model.ts +916 -0
- package/src/layers/llm/types.ts +64 -0
- package/src/{tools → layers/tools}/mcp.ts +24 -10
- package/src/layers/tools/registry.ts +307 -0
- package/src/{tools → layers/tools}/server.ts +12 -13
- package/src/{tools → layers/tools}/types.ts +3 -2
- package/src/liate.ts +64 -24
- package/src/routes/skills.ts +73 -0
- package/src/runtime/hono.ts +346 -0
- package/src/runtime/wasm.ts +23 -0
- package/src/scaffold/project.ts +188 -0
- package/dist/engine/engine.zip +0 -0
- package/dist/engine/index.js +0 -36790
- package/hub/agents/email-agent/agent.json +0 -19
- package/hub/agents/general-agent/agent.json +0 -18
- package/hub/agents/identity-agent/agent.json +0 -19
- package/hub/agents/research-agent/agent.json +0 -18
- package/hub/llm/sarvam.json +0 -27
- package/hub/mcp/agentmail.json +0 -10
- package/hub/mcp/fetch.json +0 -9
- package/hub/mcp/neon.json +0 -12
- package/hub/mcp/sarvam.json +0 -12
- package/hub/mcp/supabase.json +0 -12
- package/hub/mcp/vercel.json +0 -12
- package/src/agent/agent.ts +0 -165
- package/src/cli.ts +0 -272
- package/src/engine/types.ts +0 -104
- package/src/integration/integration.ts +0 -37
- package/src/link/index.ts +0 -317
- package/src/link/neon.ts +0 -646
- package/src/link/supabase.ts +0 -567
- package/src/link/vercel.ts +0 -633
- package/src/llm/config.ts +0 -46
- package/src/llm/hub.ts +0 -59
- package/src/llm/llm.ts +0 -60
- package/src/llm/sarvam.ts +0 -136
- package/src/server/engine.ts +0 -277
- package/src/server/index.ts +0 -32
- package/src/tools/builtin/fetch.ts +0 -66
- package/src/tools/builtin/identity.ts +0 -131
- package/src/tools/registry.ts +0 -218
package/src/link/neon.ts
DELETED
|
@@ -1,646 +0,0 @@
|
|
|
1
|
-
import { createHash, randomBytes } from "crypto";
|
|
2
|
-
import http from "http";
|
|
3
|
-
import fs from "fs";
|
|
4
|
-
import path from "path";
|
|
5
|
-
import os from "os";
|
|
6
|
-
import JSZip from "jszip";
|
|
7
|
-
import { generateUUIDv7 } from "../core/uuid";
|
|
8
|
-
|
|
9
|
-
export const NEON_MCP_ENDPOINT = "https://mcp.neon.tech/mcp";
|
|
10
|
-
export const NEON_REGISTER_ENDPOINT = "https://mcp.neon.tech/api/register";
|
|
11
|
-
export const NEON_AUTH_ENDPOINT = "https://mcp.neon.tech/api/authorize";
|
|
12
|
-
export const NEON_TOKEN_ENDPOINT = "https://mcp.neon.tech/api/token";
|
|
13
|
-
export const DEFAULT_CALLBACK_PORT = 54321;
|
|
14
|
-
export const DEFAULT_CALLBACK_URL = `http://localhost:${DEFAULT_CALLBACK_PORT}/callback`;
|
|
15
|
-
|
|
16
|
-
export function base64url(buffer: Buffer): string {
|
|
17
|
-
return buffer
|
|
18
|
-
.toString("base64")
|
|
19
|
-
.replace(/\+/g, "-")
|
|
20
|
-
.replace(/\//g, "_")
|
|
21
|
-
.replace(/=+$/, "");
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function generatePKCE() {
|
|
25
|
-
const codeVerifier = base64url(randomBytes(32));
|
|
26
|
-
const codeChallenge = base64url(createHash("sha256").update(codeVerifier).digest());
|
|
27
|
-
return { codeVerifier, codeChallenge };
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface NeonTokenData {
|
|
31
|
-
access_token: string;
|
|
32
|
-
refresh_token?: string;
|
|
33
|
-
saved_at: string;
|
|
34
|
-
projectId?: string;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export interface ClientRegistration {
|
|
38
|
-
client_id: string;
|
|
39
|
-
client_secret?: string;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export class NeonMcpOAuth {
|
|
43
|
-
/**
|
|
44
|
-
* Path to persistent Liate config (~/.liate/neon_token.json or .liate/neon_token.json).
|
|
45
|
-
*/
|
|
46
|
-
public static getTokenPath(): string {
|
|
47
|
-
if (process.env.LIATE_CONFIG_DIR) {
|
|
48
|
-
if (!fs.existsSync(process.env.LIATE_CONFIG_DIR)) {
|
|
49
|
-
fs.mkdirSync(process.env.LIATE_CONFIG_DIR, { recursive: true });
|
|
50
|
-
}
|
|
51
|
-
return path.join(process.env.LIATE_CONFIG_DIR, "neon_token.json");
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// Always prefer workspace .liate directory so it works reliably in sandboxes & CI
|
|
55
|
-
const candidateDirs = [
|
|
56
|
-
path.resolve(process.cwd(), ".liate"),
|
|
57
|
-
path.resolve(process.cwd(), "..", ".liate"),
|
|
58
|
-
path.resolve(__dirname, "..", "..", ".liate")
|
|
59
|
-
];
|
|
60
|
-
|
|
61
|
-
for (const d of candidateDirs) {
|
|
62
|
-
try {
|
|
63
|
-
if (!fs.existsSync(d)) {
|
|
64
|
-
fs.mkdirSync(d, { recursive: true });
|
|
65
|
-
}
|
|
66
|
-
return path.join(d, "neon_token.json");
|
|
67
|
-
} catch {}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
try {
|
|
71
|
-
const homeDir = path.join(os.homedir(), ".liate");
|
|
72
|
-
if (!fs.existsSync(homeDir)) {
|
|
73
|
-
fs.mkdirSync(homeDir, { recursive: true });
|
|
74
|
-
}
|
|
75
|
-
return path.join(homeDir, "neon_token.json");
|
|
76
|
-
} catch {
|
|
77
|
-
return path.resolve(process.cwd(), ".liate", "neon_token.json");
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
public static loadSavedToken(): NeonTokenData | null {
|
|
82
|
-
const candidatePaths = [
|
|
83
|
-
process.env.LIATE_CONFIG_DIR ? path.join(process.env.LIATE_CONFIG_DIR, "neon_token.json") : "",
|
|
84
|
-
path.resolve(process.cwd(), ".liate", "neon_token.json"),
|
|
85
|
-
path.resolve(process.cwd(), "..", ".liate", "neon_token.json"),
|
|
86
|
-
path.resolve(__dirname, "..", "..", ".liate", "neon_token.json"),
|
|
87
|
-
path.resolve(os.homedir(), ".liate", "neon_token.json")
|
|
88
|
-
].filter(Boolean);
|
|
89
|
-
|
|
90
|
-
for (const p of candidatePaths) {
|
|
91
|
-
try {
|
|
92
|
-
if (fs.existsSync(p)) {
|
|
93
|
-
const raw = fs.readFileSync(p, "utf-8");
|
|
94
|
-
const parsed = JSON.parse(raw);
|
|
95
|
-
if (parsed && parsed.access_token) {
|
|
96
|
-
return parsed;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
} catch {}
|
|
100
|
-
}
|
|
101
|
-
return null;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
public static saveToken(data: NeonTokenData): void {
|
|
105
|
-
const p = NeonMcpOAuth.getTokenPath();
|
|
106
|
-
fs.writeFileSync(p, JSON.stringify(data, null, 2), "utf-8");
|
|
107
|
-
|
|
108
|
-
// Do not modify workspace configuration if running inside an isolated test environment
|
|
109
|
-
if (process.env.LIATE_CONFIG_DIR) {
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// Also mirror to workspace .liate if running from subfolder
|
|
114
|
-
const mirrorPath = path.resolve(process.cwd(), ".liate", "neon_token.json");
|
|
115
|
-
if (mirrorPath !== p) {
|
|
116
|
-
try {
|
|
117
|
-
if (!fs.existsSync(path.dirname(mirrorPath))) {
|
|
118
|
-
fs.mkdirSync(path.dirname(mirrorPath), { recursive: true });
|
|
119
|
-
}
|
|
120
|
-
fs.writeFileSync(mirrorPath, JSON.stringify(data, null, 2), "utf-8");
|
|
121
|
-
} catch {}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// Always update .env.local with fresh token
|
|
125
|
-
try {
|
|
126
|
-
const envPath = path.join(process.cwd(), ".env.local");
|
|
127
|
-
let content = fs.existsSync(envPath) ? fs.readFileSync(envPath, "utf-8") : "";
|
|
128
|
-
if (content.includes("NEON_MCP_TOKEN=")) {
|
|
129
|
-
content = content.replace(/NEON_MCP_TOKEN="?[^"\r\n]+"?/g, `NEON_MCP_TOKEN="${data.access_token}"`);
|
|
130
|
-
} else {
|
|
131
|
-
content += `\nNEON_MCP_TOKEN="${data.access_token}"\n`;
|
|
132
|
-
}
|
|
133
|
-
fs.writeFileSync(envPath, content.trim() + "\n", "utf-8");
|
|
134
|
-
} catch {}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
public static clearSavedToken(): void {
|
|
138
|
-
const candidatePaths = [
|
|
139
|
-
process.env.LIATE_CONFIG_DIR ? path.join(process.env.LIATE_CONFIG_DIR, "neon_token.json") : "",
|
|
140
|
-
NeonMcpOAuth.getTokenPath(),
|
|
141
|
-
path.resolve(process.cwd(), ".liate", "neon_token.json"),
|
|
142
|
-
path.resolve(process.cwd(), "..", ".liate", "neon_token.json"),
|
|
143
|
-
path.resolve(__dirname, "..", "..", ".liate", "neon_token.json"),
|
|
144
|
-
path.resolve(os.homedir(), ".liate", "neon_token.json")
|
|
145
|
-
].filter(Boolean);
|
|
146
|
-
|
|
147
|
-
for (const p of candidatePaths) {
|
|
148
|
-
try {
|
|
149
|
-
if (fs.existsSync(p)) {
|
|
150
|
-
fs.unlinkSync(p);
|
|
151
|
-
}
|
|
152
|
-
} catch {}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
try {
|
|
156
|
-
const envPath = path.join(process.cwd(), ".env.local");
|
|
157
|
-
if (fs.existsSync(envPath)) {
|
|
158
|
-
let content = fs.readFileSync(envPath, "utf-8");
|
|
159
|
-
content = content.replace(/NEON_MCP_TOKEN="?[^"\r\n]+"?(\r?\n|$)/g, "");
|
|
160
|
-
fs.writeFileSync(envPath, content.trim() + "\n", "utf-8");
|
|
161
|
-
}
|
|
162
|
-
} catch {}
|
|
163
|
-
|
|
164
|
-
delete process.env.NEON_MCP_TOKEN;
|
|
165
|
-
delete process.env.NEON_API_KEY;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Modern 2026 Dynamic Client Registration (RFC 7591)
|
|
170
|
-
* Registers OpenLiate dynamically with Neon's MCP server.
|
|
171
|
-
*/
|
|
172
|
-
public static async registerClient(callbackUrl: string = DEFAULT_CALLBACK_URL): Promise<ClientRegistration> {
|
|
173
|
-
try {
|
|
174
|
-
const res = await fetch(NEON_REGISTER_ENDPOINT, {
|
|
175
|
-
method: "POST",
|
|
176
|
-
headers: { "Content-Type": "application/json" },
|
|
177
|
-
body: JSON.stringify({
|
|
178
|
-
client_name: "OpenLiate CLI",
|
|
179
|
-
client_uri: "https://openliate.tech",
|
|
180
|
-
redirect_uris: [callbackUrl],
|
|
181
|
-
grant_types: ["authorization_code", "refresh_token"],
|
|
182
|
-
response_types: ["code"],
|
|
183
|
-
token_endpoint_auth_method: "none"
|
|
184
|
-
})
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
if (!res.ok) {
|
|
188
|
-
const text = await res.text();
|
|
189
|
-
throw new Error(`Neon Dynamic Client Registration failed (${res.status}): ${text}`);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
const json = await res.json() as any;
|
|
193
|
-
return {
|
|
194
|
-
client_id: json.client_id,
|
|
195
|
-
client_secret: json.client_secret
|
|
196
|
-
};
|
|
197
|
-
} catch (err: any) {
|
|
198
|
-
throw err;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Constructs 1-Click Authorization URL for Neon MCP OAuth 2.1
|
|
204
|
-
*/
|
|
205
|
-
public static buildAuthorizeUrl(options: {
|
|
206
|
-
clientId: string;
|
|
207
|
-
codeChallenge: string;
|
|
208
|
-
state: string;
|
|
209
|
-
callbackUrl?: string;
|
|
210
|
-
}): string {
|
|
211
|
-
const callbackUrl = options.callbackUrl || DEFAULT_CALLBACK_URL;
|
|
212
|
-
const authUrl = new URL(NEON_AUTH_ENDPOINT);
|
|
213
|
-
authUrl.searchParams.set("response_type", "code");
|
|
214
|
-
authUrl.searchParams.set("client_id", options.clientId);
|
|
215
|
-
authUrl.searchParams.set("redirect_uri", callbackUrl);
|
|
216
|
-
authUrl.searchParams.set("scope", "read write");
|
|
217
|
-
authUrl.searchParams.set("code_challenge", options.codeChallenge);
|
|
218
|
-
authUrl.searchParams.set("code_challenge_method", "S256");
|
|
219
|
-
authUrl.searchParams.set("state", options.state);
|
|
220
|
-
return authUrl.toString();
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* Exchanges authorization code for Neon MCP access token.
|
|
225
|
-
*/
|
|
226
|
-
public static async exchangeToken(options: {
|
|
227
|
-
code: string;
|
|
228
|
-
codeVerifier: string;
|
|
229
|
-
clientId: string;
|
|
230
|
-
clientSecret?: string;
|
|
231
|
-
callbackUrl?: string;
|
|
232
|
-
}): Promise<NeonTokenData> {
|
|
233
|
-
const callbackUrl = options.callbackUrl || DEFAULT_CALLBACK_URL;
|
|
234
|
-
const params = new URLSearchParams({
|
|
235
|
-
grant_type: "authorization_code",
|
|
236
|
-
code: options.code,
|
|
237
|
-
redirect_uri: callbackUrl,
|
|
238
|
-
client_id: options.clientId,
|
|
239
|
-
code_verifier: options.codeVerifier
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
if (options.clientSecret) {
|
|
243
|
-
params.append("client_secret", options.clientSecret);
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
try {
|
|
247
|
-
const res = await fetch(NEON_TOKEN_ENDPOINT, {
|
|
248
|
-
method: "POST",
|
|
249
|
-
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
250
|
-
body: params
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
if (!res.ok) {
|
|
254
|
-
const text = await res.text();
|
|
255
|
-
throw new Error(`Neon Token Exchange failed (${res.status}): ${text}`);
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
const json = await res.json() as any;
|
|
259
|
-
const tokenData: NeonTokenData = {
|
|
260
|
-
access_token: json.access_token,
|
|
261
|
-
refresh_token: json.refresh_token,
|
|
262
|
-
saved_at: new Date().toISOString()
|
|
263
|
-
};
|
|
264
|
-
NeonMcpOAuth.saveToken(tokenData);
|
|
265
|
-
return tokenData;
|
|
266
|
-
} catch (err: any) {
|
|
267
|
-
throw err;
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
* Ephemeral HTTP server on port 54321 to receive OAuth callback
|
|
273
|
-
*/
|
|
274
|
-
public static waitForCallback(port: number = DEFAULT_CALLBACK_PORT): Promise<{ code: string; state?: string }> {
|
|
275
|
-
return new Promise((resolve, reject) => {
|
|
276
|
-
let resolved = false;
|
|
277
|
-
|
|
278
|
-
const server = http.createServer((req, res) => {
|
|
279
|
-
try {
|
|
280
|
-
const reqUrl = new URL(req.url || "/", `http://localhost:${port}`);
|
|
281
|
-
if (reqUrl.pathname !== "/callback") {
|
|
282
|
-
res.writeHead(404, { "Content-Type": "text/plain" });
|
|
283
|
-
res.end("Not Found");
|
|
284
|
-
return;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
const code = reqUrl.searchParams.get("code");
|
|
288
|
-
const state = reqUrl.searchParams.get("state") || undefined;
|
|
289
|
-
const error = reqUrl.searchParams.get("error");
|
|
290
|
-
|
|
291
|
-
if (error) {
|
|
292
|
-
res.writeHead(400, { "Content-Type": "text/html" });
|
|
293
|
-
res.end(`<h3>Neon MCP OAuth Error: ${error}</h3>`);
|
|
294
|
-
server.close();
|
|
295
|
-
if (!resolved) {
|
|
296
|
-
resolved = true;
|
|
297
|
-
reject(new Error(`OAuth Error: ${error}`));
|
|
298
|
-
}
|
|
299
|
-
return;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
if (!code) {
|
|
303
|
-
res.writeHead(400, { "Content-Type": "text/plain" });
|
|
304
|
-
res.end("Missing authorization code.");
|
|
305
|
-
return;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
|
|
309
|
-
res.end(`<!DOCTYPE html>
|
|
310
|
-
<html>
|
|
311
|
-
<head>
|
|
312
|
-
<title>Liate — Authentication Successful</title>
|
|
313
|
-
</head>
|
|
314
|
-
<body style="font-family: -apple-system, system-ui, sans-serif; padding: 40px; text-align: center; color: #111;">
|
|
315
|
-
<h2>Authentication successful</h2>
|
|
316
|
-
<p>You can close this window and return to your terminal.</p>
|
|
317
|
-
<script>try { window.close(); } catch(e) {}</script>
|
|
318
|
-
</body>
|
|
319
|
-
</html>`);
|
|
320
|
-
|
|
321
|
-
server.close();
|
|
322
|
-
if (!resolved) {
|
|
323
|
-
resolved = true;
|
|
324
|
-
resolve({ code, state });
|
|
325
|
-
}
|
|
326
|
-
} catch (err: any) {
|
|
327
|
-
server.close();
|
|
328
|
-
if (!resolved) {
|
|
329
|
-
resolved = true;
|
|
330
|
-
reject(err);
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
});
|
|
334
|
-
|
|
335
|
-
server.on("error", (err) => {
|
|
336
|
-
if (!resolved) {
|
|
337
|
-
resolved = true;
|
|
338
|
-
reject(err);
|
|
339
|
-
}
|
|
340
|
-
});
|
|
341
|
-
|
|
342
|
-
server.listen(port);
|
|
343
|
-
|
|
344
|
-
setTimeout(() => {
|
|
345
|
-
if (!resolved) {
|
|
346
|
-
resolved = true;
|
|
347
|
-
server.close();
|
|
348
|
-
reject(new Error("Neon MCP OAuth timed out after 60 seconds."));
|
|
349
|
-
}
|
|
350
|
-
}, 60000);
|
|
351
|
-
});
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
/**
|
|
356
|
-
* Neon MCP Client: Calls tools directly on https://mcp.neon.tech/mcp
|
|
357
|
-
*/
|
|
358
|
-
export class NeonMcpClient {
|
|
359
|
-
private token: string;
|
|
360
|
-
|
|
361
|
-
constructor(token?: string) {
|
|
362
|
-
const saved = NeonMcpOAuth.loadSavedToken();
|
|
363
|
-
this.token = token || saved?.access_token || process.env.NEON_MCP_TOKEN || "";
|
|
364
|
-
if (!this.token) {
|
|
365
|
-
throw new Error("No Neon MCP token found. Run 'liate link --neon' first.");
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
public async callTool(name: string, args: Record<string, any> = {}): Promise<any> {
|
|
370
|
-
const payload = {
|
|
371
|
-
jsonrpc: "2.0",
|
|
372
|
-
id: Date.now(),
|
|
373
|
-
method: "tools/call",
|
|
374
|
-
params: {
|
|
375
|
-
name,
|
|
376
|
-
arguments: args
|
|
377
|
-
}
|
|
378
|
-
};
|
|
379
|
-
|
|
380
|
-
const res = await fetch(NEON_MCP_ENDPOINT, {
|
|
381
|
-
method: "POST",
|
|
382
|
-
headers: {
|
|
383
|
-
"Content-Type": "application/json",
|
|
384
|
-
"Authorization": `Bearer ${this.token}`,
|
|
385
|
-
"Accept": "application/json, text/event-stream"
|
|
386
|
-
},
|
|
387
|
-
body: JSON.stringify(payload)
|
|
388
|
-
});
|
|
389
|
-
|
|
390
|
-
if (res.status === 401) {
|
|
391
|
-
NeonMcpOAuth.clearSavedToken();
|
|
392
|
-
throw new Error("Neon MCP Token has expired or is invalid. Please run 'liate relink --neon' to re-authenticate.");
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
const text = await res.text();
|
|
396
|
-
let data: any;
|
|
397
|
-
const match = text.match(/data: ({.*})/);
|
|
398
|
-
if (match) {
|
|
399
|
-
try {
|
|
400
|
-
const parsed = JSON.parse(match[1]);
|
|
401
|
-
if (parsed.result?.content?.[0]?.text) {
|
|
402
|
-
try {
|
|
403
|
-
data = JSON.parse(parsed.result.content[0].text);
|
|
404
|
-
} catch {
|
|
405
|
-
data = parsed.result.content[0].text;
|
|
406
|
-
}
|
|
407
|
-
} else {
|
|
408
|
-
data = parsed;
|
|
409
|
-
}
|
|
410
|
-
} catch {
|
|
411
|
-
data = text;
|
|
412
|
-
}
|
|
413
|
-
} else {
|
|
414
|
-
try {
|
|
415
|
-
data = JSON.parse(text);
|
|
416
|
-
} catch {
|
|
417
|
-
data = text;
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
if (data && typeof data === "object" && data.error) {
|
|
422
|
-
if (data.error === "invalid_token" || data.error_description?.includes("expired")) {
|
|
423
|
-
throw new Error("Neon MCP Token has expired. Please run 'liate relink --neon' to re-authenticate.");
|
|
424
|
-
}
|
|
425
|
-
throw new Error(`Neon MCP Error (${data.error}): ${data.error_description || JSON.stringify(data)}`);
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
return data;
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
public async listProjects(): Promise<any[]> {
|
|
432
|
-
const res = await this.callTool("list_projects");
|
|
433
|
-
return Array.isArray(res) ? res : res.projects || [];
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
public async listBranches(projectId: string): Promise<any[]> {
|
|
437
|
-
const res = await this.callTool("list_branches", { project_id: projectId });
|
|
438
|
-
return Array.isArray(res) ? res : res.branches || [];
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
public async listFunctions(projectId: string, branchId: string): Promise<any[]> {
|
|
442
|
-
const res = await this.callTool("list_functions", { project_id: projectId, branch_id: branchId });
|
|
443
|
-
return Array.isArray(res) ? res : res.functions || [];
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
public async deployEngine(options?: {
|
|
447
|
-
slug?: string;
|
|
448
|
-
projectId?: string;
|
|
449
|
-
branchId?: string;
|
|
450
|
-
branchName?: string;
|
|
451
|
-
usePrimaryBranch?: boolean;
|
|
452
|
-
createNewBranch?: boolean;
|
|
453
|
-
}): Promise<{
|
|
454
|
-
deploymentId: number;
|
|
455
|
-
uuid7: string;
|
|
456
|
-
slug: string;
|
|
457
|
-
projectId: string;
|
|
458
|
-
projectName: string;
|
|
459
|
-
branchId: string;
|
|
460
|
-
branchName: string;
|
|
461
|
-
invocationUrl: string;
|
|
462
|
-
status: string;
|
|
463
|
-
}> {
|
|
464
|
-
// 1. Build universal serverless engine bundle into dist/engine/
|
|
465
|
-
const engineDistDir = path.resolve(process.cwd(), "dist", "engine");
|
|
466
|
-
if (!fs.existsSync(engineDistDir)) {
|
|
467
|
-
fs.mkdirSync(engineDistDir, { recursive: true });
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
const entrypoint = path.resolve(__dirname, "..", "server", "index.ts");
|
|
471
|
-
const buildResult = await (globalThis as any).Bun.build({
|
|
472
|
-
entrypoints: [entrypoint],
|
|
473
|
-
target: "node",
|
|
474
|
-
format: "esm",
|
|
475
|
-
minify: false,
|
|
476
|
-
naming: "[name].[ext]",
|
|
477
|
-
outdir: engineDistDir
|
|
478
|
-
});
|
|
479
|
-
if (!buildResult.success || buildResult.outputs.length === 0) {
|
|
480
|
-
throw new Error("Failed to bundle Liate Engine for Neon deployment.");
|
|
481
|
-
}
|
|
482
|
-
const bundleText = await buildResult.outputs[0].text();
|
|
483
|
-
|
|
484
|
-
// 2. Create physical package dist/engine/engine.zip for transparency and portability
|
|
485
|
-
const zip = new JSZip();
|
|
486
|
-
zip.file("index.js", bundleText);
|
|
487
|
-
const zipBuffer = await zip.generateAsync({ type: "nodebuffer" });
|
|
488
|
-
fs.writeFileSync(path.join(engineDistDir, "engine.zip"), zipBuffer);
|
|
489
|
-
const zipBase64 = zipBuffer.toString("base64");
|
|
490
|
-
|
|
491
|
-
// 3. Resolve or Automatically Create Project "openliate"
|
|
492
|
-
let projects = await this.listProjects();
|
|
493
|
-
let project = projects.find((p: any) => p.name === "openliate" || p.name === "liate");
|
|
494
|
-
|
|
495
|
-
if (!project) {
|
|
496
|
-
try {
|
|
497
|
-
const createProjRes = await this.callTool("create_project", {
|
|
498
|
-
name: "openliate",
|
|
499
|
-
branch: { name: "main" }
|
|
500
|
-
});
|
|
501
|
-
project = createProjRes?.project || createProjRes;
|
|
502
|
-
} catch {
|
|
503
|
-
project = projects.find((p: any) => p.name === "openliate" || p.name === "liate") || projects[0];
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
if (!project) {
|
|
508
|
-
throw new Error("Unable to resolve or create a Neon project for Liate.");
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
// 4. Generate RFC 9562 UUIDv7 for deployment traceability
|
|
512
|
-
const uuid7 = generateUUIDv7();
|
|
513
|
-
const cleanId = uuid7.replace(/-/g, "").slice(0, 8);
|
|
514
|
-
const targetBranchName = options?.branchName || `liate-branch-${cleanId}`;
|
|
515
|
-
|
|
516
|
-
// 5. Resolve Branch (Dedicated isolated branch or Project's primary branch)
|
|
517
|
-
let branch: any;
|
|
518
|
-
if (options?.branchId) {
|
|
519
|
-
const branches = await this.listBranches(project.id);
|
|
520
|
-
branch = branches.find((b: any) => b.id === options.branchId) || branches[0];
|
|
521
|
-
} else if (options?.usePrimaryBranch) {
|
|
522
|
-
const branches = await this.listBranches(project.id);
|
|
523
|
-
branch = branches.find((b: any) => b.primary || b.default) || branches[0];
|
|
524
|
-
} else {
|
|
525
|
-
try {
|
|
526
|
-
const branchRes = await this.callTool("create_branch", {
|
|
527
|
-
project_id: project.id,
|
|
528
|
-
name: targetBranchName
|
|
529
|
-
});
|
|
530
|
-
branch = branchRes?.branch || branchRes;
|
|
531
|
-
} catch {
|
|
532
|
-
const branches = await this.listBranches(project.id);
|
|
533
|
-
branch = branches.find((b: any) => b.primary || b.default) || branches[0];
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
if (!branch || !branch.id) {
|
|
538
|
-
const branches = await this.listBranches(project.id);
|
|
539
|
-
branch = branches.find((b: any) => b.primary || b.default) || branches[0];
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
const slug = options?.slug || "engine";
|
|
543
|
-
|
|
544
|
-
// 6. Call deploy_function on Neon MCP
|
|
545
|
-
const deployRes = await this.callTool("deploy_function", {
|
|
546
|
-
project_id: project.id,
|
|
547
|
-
branch_id: branch.id,
|
|
548
|
-
slug,
|
|
549
|
-
zip: zipBase64,
|
|
550
|
-
runtime: "nodejs24"
|
|
551
|
-
});
|
|
552
|
-
|
|
553
|
-
// 7. Query function details to retrieve live invocation URL
|
|
554
|
-
const fnRes = await this.callTool("get_function", {
|
|
555
|
-
project_id: project.id,
|
|
556
|
-
branch_id: branch.id,
|
|
557
|
-
slug
|
|
558
|
-
});
|
|
559
|
-
|
|
560
|
-
const result = {
|
|
561
|
-
deploymentId: deployRes?.id || fnRes?.current_deployment?.id || 0,
|
|
562
|
-
uuid7,
|
|
563
|
-
slug,
|
|
564
|
-
projectId: project.id,
|
|
565
|
-
projectName: project.name,
|
|
566
|
-
branchId: branch.id,
|
|
567
|
-
branchName: branch.name || targetBranchName,
|
|
568
|
-
invocationUrl: fnRes?.invocation_url || "",
|
|
569
|
-
status: fnRes?.current_deployment?.status || deployRes?.status || "unknown"
|
|
570
|
-
};
|
|
571
|
-
|
|
572
|
-
// Persist deployment metadata
|
|
573
|
-
try {
|
|
574
|
-
const deployPath = path.resolve(process.cwd(), ".liate", "neon_deployment.json");
|
|
575
|
-
if (!fs.existsSync(path.dirname(deployPath))) {
|
|
576
|
-
fs.mkdirSync(path.dirname(deployPath), { recursive: true });
|
|
577
|
-
}
|
|
578
|
-
fs.writeFileSync(deployPath, JSON.stringify(result, null, 2), "utf-8");
|
|
579
|
-
} catch {}
|
|
580
|
-
|
|
581
|
-
return result;
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
public async getEngineDeployment(): Promise<{
|
|
585
|
-
deploymentId?: number;
|
|
586
|
-
uuid7?: string;
|
|
587
|
-
slug?: string;
|
|
588
|
-
projectId: string;
|
|
589
|
-
projectName: string;
|
|
590
|
-
branchId: string;
|
|
591
|
-
branchName: string;
|
|
592
|
-
invocationUrl: string;
|
|
593
|
-
runtime: string;
|
|
594
|
-
status: string;
|
|
595
|
-
}> {
|
|
596
|
-
// Check saved deployment first
|
|
597
|
-
try {
|
|
598
|
-
const deployPath = path.resolve(process.cwd(), ".liate", "neon_deployment.json");
|
|
599
|
-
if (fs.existsSync(deployPath)) {
|
|
600
|
-
const saved = JSON.parse(fs.readFileSync(deployPath, "utf-8"));
|
|
601
|
-
if (saved && saved.invocationUrl) {
|
|
602
|
-
return {
|
|
603
|
-
deploymentId: saved.deploymentId,
|
|
604
|
-
uuid7: saved.uuid7,
|
|
605
|
-
slug: saved.slug,
|
|
606
|
-
projectId: saved.projectId,
|
|
607
|
-
projectName: saved.projectName,
|
|
608
|
-
branchId: saved.branchId,
|
|
609
|
-
branchName: saved.branchName,
|
|
610
|
-
invocationUrl: saved.invocationUrl,
|
|
611
|
-
runtime: "nodejs24",
|
|
612
|
-
status: saved.status || "completed"
|
|
613
|
-
};
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
} catch {}
|
|
617
|
-
|
|
618
|
-
const projects = await this.listProjects();
|
|
619
|
-
if (!projects || projects.length === 0) {
|
|
620
|
-
throw new Error("No Neon projects found in your account.");
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
const project = projects.find((p: any) => p.name === "liate-engine") || projects[0];
|
|
624
|
-
const branches = await this.listBranches(project.id);
|
|
625
|
-
const branch = branches.find((b: any) => b.primary || b.default) || branches[0];
|
|
626
|
-
|
|
627
|
-
const functions = await this.listFunctions(project.id, branch.id);
|
|
628
|
-
let fn = functions.find((f: any) => f.slug?.startsWith("liate") || f.id?.startsWith("liate")) || functions[0];
|
|
629
|
-
|
|
630
|
-
if (!fn || !fn.invocation_url) {
|
|
631
|
-
throw new Error(`No deployed Liate engine function found on branch ${branch.name}.`);
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
return {
|
|
635
|
-
slug: fn.slug,
|
|
636
|
-
projectId: project.id,
|
|
637
|
-
projectName: project.name,
|
|
638
|
-
branchId: branch.id,
|
|
639
|
-
branchName: branch.name,
|
|
640
|
-
invocationUrl: fn.invocation_url,
|
|
641
|
-
runtime: fn.current_deployment?.runtime || "nodejs24",
|
|
642
|
-
status: fn.current_deployment?.status || "completed"
|
|
643
|
-
};
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
|