@lakitu/sdk 0.1.39 → 0.1.41
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.
|
@@ -28,6 +28,7 @@ export const execute = internalAction({
|
|
|
28
28
|
env: v.optional(v.object({
|
|
29
29
|
CONVEX_URL: v.optional(v.string()),
|
|
30
30
|
GATEWAY_URL: v.optional(v.string()),
|
|
31
|
+
LOCAL_CONVEX_URL: v.optional(v.string()),
|
|
31
32
|
SANDBOX_JWT: v.optional(v.string()),
|
|
32
33
|
CARD_ID: v.optional(v.string()),
|
|
33
34
|
THREAD_ID: v.optional(v.string()),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../cli/commands/build.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../cli/commands/build.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAaH,UAAU,YAAY;IACpB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AA6MD,wBAAsB,KAAK,CAAC,OAAO,EAAE,YAAY,iBAgBhD"}
|
|
@@ -7,13 +7,12 @@
|
|
|
7
7
|
import { Template, defaultBuildLogger, waitForPort } from "e2b";
|
|
8
8
|
import { existsSync, mkdirSync, rmSync, cpSync, writeFileSync, readFileSync, readdirSync } from "fs";
|
|
9
9
|
import { join, dirname } from "path";
|
|
10
|
-
import { execSync
|
|
10
|
+
import { execSync } from "child_process";
|
|
11
11
|
import { fileURLToPath } from "url";
|
|
12
12
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
13
13
|
const PACKAGE_ROOT = __dirname.includes("/dist/")
|
|
14
14
|
? join(__dirname, "../../..")
|
|
15
15
|
: join(__dirname, "../..");
|
|
16
|
-
const STATE_DIR = "/tmp/lakitu-convex-state";
|
|
17
16
|
function findApiKey() {
|
|
18
17
|
if (process.env.E2B_API_KEY) {
|
|
19
18
|
return { key: process.env.E2B_API_KEY, source: "E2B_API_KEY env var" };
|
|
@@ -53,80 +52,6 @@ function preflightCheck() {
|
|
|
53
52
|
console.log(`🔑 Using API key from ${result.source}\n`);
|
|
54
53
|
return result.key;
|
|
55
54
|
}
|
|
56
|
-
async function sleep(ms) {
|
|
57
|
-
return new Promise(resolve => setTimeout(resolve, ms));
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Pre-build Convex locally: start backend, deploy functions, capture state
|
|
61
|
-
*/
|
|
62
|
-
async function prebuildConvex() {
|
|
63
|
-
console.log("📦 Pre-building Convex functions locally...");
|
|
64
|
-
// Clean up any existing state
|
|
65
|
-
rmSync(STATE_DIR, { recursive: true, force: true });
|
|
66
|
-
mkdirSync(STATE_DIR, { recursive: true });
|
|
67
|
-
// Kill any existing convex-backend
|
|
68
|
-
try {
|
|
69
|
-
execSync("pkill -f 'convex-backend' || true", { stdio: "pipe" });
|
|
70
|
-
}
|
|
71
|
-
catch { /* ignore */ }
|
|
72
|
-
await sleep(1000);
|
|
73
|
-
console.log(" Starting local convex-backend...");
|
|
74
|
-
// Start convex-backend in background
|
|
75
|
-
const backend = spawn("convex-backend", [
|
|
76
|
-
`${STATE_DIR}/convex_local_backend.sqlite3`,
|
|
77
|
-
"--port", "3210",
|
|
78
|
-
"--site-proxy-port", "3211",
|
|
79
|
-
"--local-storage", STATE_DIR,
|
|
80
|
-
], {
|
|
81
|
-
cwd: STATE_DIR,
|
|
82
|
-
stdio: "pipe",
|
|
83
|
-
detached: true,
|
|
84
|
-
});
|
|
85
|
-
// Wait for backend to be ready
|
|
86
|
-
for (let i = 0; i < 30; i++) {
|
|
87
|
-
try {
|
|
88
|
-
const res = await fetch("http://127.0.0.1:3210/version");
|
|
89
|
-
if (res.ok) {
|
|
90
|
-
console.log(` Backend ready after ${i + 1} seconds`);
|
|
91
|
-
break;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
catch { /* not ready yet */ }
|
|
95
|
-
if (i === 29) {
|
|
96
|
-
backend.kill();
|
|
97
|
-
throw new Error("Backend failed to start after 30 seconds");
|
|
98
|
-
}
|
|
99
|
-
await sleep(1000);
|
|
100
|
-
}
|
|
101
|
-
// Deploy functions using convex dev --once
|
|
102
|
-
console.log(" Deploying functions with convex dev --once...");
|
|
103
|
-
// Build clean env without CONVEX_DEPLOYMENT
|
|
104
|
-
const cleanEnv = { ...process.env };
|
|
105
|
-
delete cleanEnv.CONVEX_DEPLOYMENT;
|
|
106
|
-
cleanEnv.CONVEX_SELF_HOSTED_URL = "http://127.0.0.1:3210";
|
|
107
|
-
cleanEnv.CONVEX_SELF_HOSTED_ADMIN_KEY = "0135d8598650f8f5cb0f30c34ec2e2bb62793bc28717c8eb6fb577996d50be5f4281b59181095065c5d0f86a2c31ddbe9b597ec62b47ded69782cd";
|
|
108
|
-
try {
|
|
109
|
-
execSync(`cd ${PACKAGE_ROOT} && npx convex dev --once --typecheck disable`, {
|
|
110
|
-
env: cleanEnv,
|
|
111
|
-
stdio: "pipe",
|
|
112
|
-
});
|
|
113
|
-
console.log(" ✓ Functions deployed successfully!");
|
|
114
|
-
}
|
|
115
|
-
catch (e) {
|
|
116
|
-
backend.kill();
|
|
117
|
-
throw new Error(`Convex deploy failed: ${e.message}`);
|
|
118
|
-
}
|
|
119
|
-
// Give backend a moment to flush state
|
|
120
|
-
await sleep(2000);
|
|
121
|
-
// Stop backend gracefully
|
|
122
|
-
console.log(" Stopping backend...");
|
|
123
|
-
backend.kill("SIGTERM");
|
|
124
|
-
await sleep(1000);
|
|
125
|
-
// Verify state was captured
|
|
126
|
-
const moduleFiles = readdirSync(`${STATE_DIR}/modules`).length;
|
|
127
|
-
console.log(` ✓ ${moduleFiles} modules deployed\n`);
|
|
128
|
-
return STATE_DIR;
|
|
129
|
-
}
|
|
130
55
|
// Base template using standard Template builder
|
|
131
56
|
const baseTemplate = Template()
|
|
132
57
|
.fromImage("e2bdev/code-interpreter:latest")
|
|
@@ -159,8 +84,6 @@ async function buildBase(apiKey) {
|
|
|
159
84
|
}
|
|
160
85
|
async function buildCustom(apiKey, baseId) {
|
|
161
86
|
const buildDir = "/tmp/lakitu-build";
|
|
162
|
-
// Step 1: Pre-build Convex functions locally
|
|
163
|
-
const stateDir = await prebuildConvex();
|
|
164
87
|
console.log("📦 Preparing Dockerfile build context...");
|
|
165
88
|
rmSync(buildDir, { recursive: true, force: true });
|
|
166
89
|
mkdirSync(buildDir, { recursive: true });
|
|
@@ -197,9 +120,6 @@ async function buildCustom(apiKey, baseId) {
|
|
|
197
120
|
}
|
|
198
121
|
// Copy start script
|
|
199
122
|
cpSync(join(PACKAGE_ROOT, "template/e2b/start.sh"), join(buildDir, "start.sh"));
|
|
200
|
-
// Copy pre-built Convex state
|
|
201
|
-
cpSync(stateDir, join(buildDir, "convex-state"), { recursive: true });
|
|
202
|
-
console.log(" ✓ Copied pre-built Convex state");
|
|
203
123
|
// Create Dockerfile - must use real Docker image, not E2B template alias
|
|
204
124
|
const dockerfile = `# Lakitu Custom Template
|
|
205
125
|
FROM e2bdev/code-interpreter:latest
|
|
@@ -245,8 +165,8 @@ RUN printf '#!/bin/bash\\nbun run /home/user/lakitu/runtime/browser/agent-browse
|
|
|
245
165
|
# Symlinks and ownership
|
|
246
166
|
RUN ln -sf /home/user/lakitu/ksa /home/user/ksa && chown -R user:user /home/user/lakitu /home/user/ksa
|
|
247
167
|
|
|
248
|
-
#
|
|
249
|
-
|
|
168
|
+
# Create Convex state directory (functions deploy at first boot via start.sh)
|
|
169
|
+
RUN mkdir -p /home/user/.convex/convex-backend-state/lakitu && chown -R user:user /home/user/.convex
|
|
250
170
|
|
|
251
171
|
ENV HOME=/home/user
|
|
252
172
|
ENV PATH="/home/user/.bun/bin:/usr/local/bin:/usr/bin:/bin"
|
package/package.json
CHANGED
package/template/e2b/start.sh
CHANGED
|
@@ -1,14 +1,37 @@
|
|
|
1
1
|
#!/bin/bash
|
|
2
|
-
#
|
|
3
|
-
# Skip logging and checks - template build already verified everything
|
|
2
|
+
# Start convex-backend and deploy functions if needed
|
|
4
3
|
|
|
5
4
|
STORAGE_DIR=/home/user/.convex/convex-backend-state/lakitu
|
|
6
5
|
SQLITE_DB=$STORAGE_DIR/convex_local_backend.sqlite3
|
|
6
|
+
MODULES_DIR=$STORAGE_DIR/modules
|
|
7
7
|
|
|
8
|
-
# Start convex-backend
|
|
9
|
-
|
|
8
|
+
# Start convex-backend in background
|
|
9
|
+
convex-backend \
|
|
10
10
|
"$SQLITE_DB" \
|
|
11
11
|
--port 3210 \
|
|
12
12
|
--site-proxy-port 3211 \
|
|
13
13
|
--local-storage "$STORAGE_DIR" \
|
|
14
|
-
--disable-beacon
|
|
14
|
+
--disable-beacon &
|
|
15
|
+
|
|
16
|
+
BACKEND_PID=$!
|
|
17
|
+
|
|
18
|
+
# Wait for backend to be ready
|
|
19
|
+
for i in {1..30}; do
|
|
20
|
+
if curl -s http://127.0.0.1:3210/version > /dev/null 2>&1; then
|
|
21
|
+
break
|
|
22
|
+
fi
|
|
23
|
+
sleep 1
|
|
24
|
+
done
|
|
25
|
+
|
|
26
|
+
# Deploy functions if not already deployed
|
|
27
|
+
if [ ! -d "$MODULES_DIR" ] || [ -z "$(ls -A $MODULES_DIR 2>/dev/null)" ]; then
|
|
28
|
+
echo "Deploying Convex functions..."
|
|
29
|
+
cd /home/user/lakitu
|
|
30
|
+
export CONVEX_SELF_HOSTED_URL=http://127.0.0.1:3210
|
|
31
|
+
export CONVEX_SELF_HOSTED_ADMIN_KEY=0135d8598650f8f5cb0f30c34ec2e2bb62793bc28717c8eb6fb577996d50be5f4281b59181095065c5d0f86a2c31ddbe9b597ec62b47ded69782cd
|
|
32
|
+
npx convex dev --once --typecheck disable > /tmp/convex-deploy.log 2>&1 || true
|
|
33
|
+
echo "Functions deployed"
|
|
34
|
+
fi
|
|
35
|
+
|
|
36
|
+
# Wait for backend process
|
|
37
|
+
wait $BACKEND_PID
|