@tiens.nguyen/gonext-local-worker 1.0.1 → 1.0.3
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/README.md +8 -6
- package/gonext-local-worker.mjs +20 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -90,15 +90,17 @@ ngrok http 5001
|
|
|
90
90
|
|
|
91
91
|
Then in web app Settings set **Worker webhook URL** to:
|
|
92
92
|
|
|
93
|
-
`https://<your-ngrok-domain>/dispatch-job`
|
|
93
|
+
`https://<your-ngrok-domain>/api/dispatch-job`
|
|
94
94
|
|
|
95
95
|
Local worker API endpoints on port 5001:
|
|
96
96
|
|
|
97
|
-
- `POST /chat` -> proxies to `http://localhost:11434/api/chat`
|
|
98
|
-
- `POST /generate` -> proxies to `http://localhost:11434/api/generate`
|
|
99
|
-
- `GET /tags` -> proxies to `http://localhost:11434/api/tags`
|
|
100
|
-
- `POST /dispatch-job` -> cloud dispatch entrypoint (token-protected)
|
|
101
|
-
- `GET /health`
|
|
97
|
+
- `POST /api/chat` -> proxies to `http://localhost:11434/api/chat`
|
|
98
|
+
- `POST /api/generate` -> proxies to `http://localhost:11434/api/generate`
|
|
99
|
+
- `GET /api/tags` -> proxies to `http://localhost:11434/api/tags`
|
|
100
|
+
- `POST /api/dispatch-job` -> cloud dispatch entrypoint (token-protected)
|
|
101
|
+
- `GET /api/health`
|
|
102
|
+
|
|
103
|
+
Legacy non-prefixed routes (`/chat`, `/generate`, `/tags`, `/dispatch-job`, `/health`) are also available for compatibility.
|
|
102
104
|
|
|
103
105
|
## Run at login (macOS LaunchAgent)
|
|
104
106
|
|
package/gonext-local-worker.mjs
CHANGED
|
@@ -346,7 +346,7 @@ function startWebhookServer() {
|
|
|
346
346
|
const app = express();
|
|
347
347
|
app.use(express.json({ limit: "10mb" }));
|
|
348
348
|
|
|
349
|
-
|
|
349
|
+
const healthHandler = (_req, res) => {
|
|
350
350
|
const state =
|
|
351
351
|
activeJobId.length > 0 ? "running" : lastError ? "error" : "idle";
|
|
352
352
|
res.json({
|
|
@@ -363,9 +363,11 @@ function startWebhookServer() {
|
|
|
363
363
|
tagsPath: "/tags",
|
|
364
364
|
ollamaBase,
|
|
365
365
|
});
|
|
366
|
-
}
|
|
366
|
+
};
|
|
367
|
+
app.get("/health", healthHandler);
|
|
368
|
+
app.get("/api/health", healthHandler);
|
|
367
369
|
|
|
368
|
-
|
|
370
|
+
const tagsHandler = async (_req, res) => {
|
|
369
371
|
try {
|
|
370
372
|
const r = await fetch(`${ollamaBase}/api/tags`, { method: "GET" });
|
|
371
373
|
const raw = await r.text();
|
|
@@ -379,9 +381,11 @@ function startWebhookServer() {
|
|
|
379
381
|
} catch (e) {
|
|
380
382
|
res.status(500).json({ error: e instanceof Error ? e.message : "error" });
|
|
381
383
|
}
|
|
382
|
-
}
|
|
384
|
+
};
|
|
385
|
+
app.get("/tags", tagsHandler);
|
|
386
|
+
app.get("/api/tags", tagsHandler);
|
|
383
387
|
|
|
384
|
-
|
|
388
|
+
const dispatchJobHandler = async (req, res) => {
|
|
385
389
|
if (!requireDispatchToken(req, res)) return;
|
|
386
390
|
const body = req.body ?? {};
|
|
387
391
|
if (!body?.jobId || !body?.payload) {
|
|
@@ -406,9 +410,11 @@ function startWebhookServer() {
|
|
|
406
410
|
console.error("[dispatch-job] error:", e instanceof Error ? e.message : e);
|
|
407
411
|
});
|
|
408
412
|
res.status(202).json({ ok: true, accepted: true, jobId: body.jobId });
|
|
409
|
-
}
|
|
413
|
+
};
|
|
414
|
+
app.post("/dispatch-job", dispatchJobHandler);
|
|
415
|
+
app.post("/api/dispatch-job", dispatchJobHandler);
|
|
410
416
|
|
|
411
|
-
|
|
417
|
+
const chatHandler = async (req, res) => {
|
|
412
418
|
try {
|
|
413
419
|
const body = req.body ?? {};
|
|
414
420
|
const jobId = typeof body.jobId === "string" ? body.jobId : "";
|
|
@@ -425,9 +431,11 @@ function startWebhookServer() {
|
|
|
425
431
|
} catch (e) {
|
|
426
432
|
res.status(500).json({ error: e instanceof Error ? e.message : "error" });
|
|
427
433
|
}
|
|
428
|
-
}
|
|
434
|
+
};
|
|
435
|
+
app.post("/chat", chatHandler);
|
|
436
|
+
app.post("/api/chat", chatHandler);
|
|
429
437
|
|
|
430
|
-
|
|
438
|
+
const generateHandler = async (req, res) => {
|
|
431
439
|
try {
|
|
432
440
|
const body = req.body ?? {};
|
|
433
441
|
const jobId = typeof body.jobId === "string" ? body.jobId : "";
|
|
@@ -444,7 +452,9 @@ function startWebhookServer() {
|
|
|
444
452
|
} catch (e) {
|
|
445
453
|
res.status(500).json({ error: e instanceof Error ? e.message : "error" });
|
|
446
454
|
}
|
|
447
|
-
}
|
|
455
|
+
};
|
|
456
|
+
app.post("/generate", generateHandler);
|
|
457
|
+
app.post("/api/generate", generateHandler);
|
|
448
458
|
|
|
449
459
|
webhookServer = app.listen(webhookPort, "127.0.0.1", () => {
|
|
450
460
|
console.log(
|
package/package.json
CHANGED