opencode-supertask 0.1.18 → 0.1.20
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 +87 -76
- package/dist/cli/index.js +48 -17
- package/dist/cli/index.js.map +1 -1
- package/dist/gateway/index.js +47 -18
- package/dist/gateway/index.js.map +1 -1
- package/dist/plugin/supertask.js +20362 -20950
- package/dist/plugin/supertask.js.map +1 -1
- package/dist/web/index.js +33 -13
- package/dist/web/index.js.map +1 -1
- package/dist/worker/index.js +19 -7
- package/dist/worker/index.js.map +1 -1
- package/package.json +1 -1
package/dist/web/index.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
#!/usr/bin/env bun
|
|
2
|
-
|
|
3
1
|
var __create = Object.create;
|
|
4
2
|
var __defProp = Object.defineProperty;
|
|
5
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -16561,12 +16559,21 @@ import { existsSync, mkdirSync } from "fs";
|
|
|
16561
16559
|
import { homedir } from "os";
|
|
16562
16560
|
import { join, dirname } from "path";
|
|
16563
16561
|
import { fileURLToPath } from "url";
|
|
16564
|
-
var
|
|
16562
|
+
var DEFAULT_DB_PATH = join(homedir(), ".local/share/opencode/tasks.db");
|
|
16563
|
+
var DB_FILE_PATH = process.env.SUPERTASK_DB_PATH || DEFAULT_DB_PATH;
|
|
16565
16564
|
var _sqlite = null;
|
|
16566
16565
|
var _db = null;
|
|
16567
16566
|
var _migrationRan = false;
|
|
16568
16567
|
function getMigrationsFolder() {
|
|
16569
16568
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
16569
|
+
let dir = __dirname;
|
|
16570
|
+
for (let i = 0; i < 5; i++) {
|
|
16571
|
+
const candidate = join(dir, "drizzle", "meta", "_journal.json");
|
|
16572
|
+
if (existsSync(candidate)) {
|
|
16573
|
+
return join(dir, "drizzle");
|
|
16574
|
+
}
|
|
16575
|
+
dir = dirname(dir);
|
|
16576
|
+
}
|
|
16570
16577
|
return join(__dirname, "../../drizzle");
|
|
16571
16578
|
}
|
|
16572
16579
|
function initDb() {
|
|
@@ -16591,7 +16598,9 @@ function initDb() {
|
|
|
16591
16598
|
try {
|
|
16592
16599
|
migrate(_db, { migrationsFolder: getMigrationsFolder() });
|
|
16593
16600
|
} catch (err) {
|
|
16594
|
-
|
|
16601
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
16602
|
+
console.error(`[supertask] migration failed: ${msg}`);
|
|
16603
|
+
throw new Error(`[supertask] DB migration failed: ${msg}`);
|
|
16595
16604
|
}
|
|
16596
16605
|
}
|
|
16597
16606
|
return _db;
|
|
@@ -17143,6 +17152,10 @@ function formatDate(ts) {
|
|
|
17143
17152
|
const d = ts instanceof Date ? ts : new Date(ts);
|
|
17144
17153
|
return d.toLocaleString("zh-CN", { month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit" });
|
|
17145
17154
|
}
|
|
17155
|
+
function esc(s) {
|
|
17156
|
+
if (!s) return "";
|
|
17157
|
+
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
17158
|
+
}
|
|
17146
17159
|
function readCurrentConfig() {
|
|
17147
17160
|
if (!existsSync3(CONFIG_PATH)) return {};
|
|
17148
17161
|
try {
|
|
@@ -17238,6 +17251,7 @@ async function retryTask(id){if(!confirm('\u786E\u5B9A\u91CD\u8BD5\u4EFB\u52A1 #
|
|
|
17238
17251
|
async function deleteTask(id){if(!confirm('\u786E\u5B9A\u5220\u9664\u4EFB\u52A1 #'+id+'?'))return;await fetch('/api/tasks/'+id,{method:'DELETE'});location.reload();}
|
|
17239
17252
|
async function showDetail(id){try{const r=await fetch('/api/tasks/'+id);const t=await r.json();document.getElementById('dc').textContent=JSON.stringify(t,null,2);document.getElementById('dd').showModal();}catch(e){alert('\u83B7\u53D6\u8BE6\u60C5\u5931\u8D25');}}
|
|
17240
17253
|
async function showRunDetail(id){try{const r=await fetch('/api/runs/'+id);const t=await r.json();document.getElementById('dc').textContent=JSON.stringify(t,null,2);document.getElementById('dd').showModal();}catch(e){alert('\u83B7\u53D6\u8BE6\u60C5\u5931\u8D25');}}
|
|
17254
|
+
async function showTemplateDetail(id){try{const r=await fetch('/api/templates/'+id);const t=await r.json();document.getElementById('dc').textContent=JSON.stringify(t,null,2);document.getElementById('dd').showModal();}catch(e){alert('\u83B7\u53D6\u8BE6\u60C5\u5931\u8D25');}}
|
|
17241
17255
|
async function enableTmpl(id){await fetch('/api/templates/'+id+'/enable',{method:'POST'});location.reload();}
|
|
17242
17256
|
async function disableTmpl(id){if(!confirm('\u786E\u5B9A\u7981\u7528\u6B64\u6A21\u677F?'))return;await fetch('/api/templates/'+id+'/disable',{method:'POST'});location.reload();}
|
|
17243
17257
|
async function deleteTmpl(id){if(!confirm('\u786E\u5B9A\u5220\u9664\u6B64\u6A21\u677F? \u6B64\u64CD\u4F5C\u4E0D\u53EF\u6062\u590D!'))return;await fetch('/api/templates/'+id,{method:'DELETE'});location.reload();}
|
|
@@ -17334,8 +17348,8 @@ app.get("/", async (c) => {
|
|
|
17334
17348
|
const st = (task.status ?? "").toUpperCase();
|
|
17335
17349
|
rows += `<tr>
|
|
17336
17350
|
<td class="mu">#${task.id}</td>
|
|
17337
|
-
<td><div style="font-weight:500">${task.name}</div><div class="mu sm el">${task.prompt.substring(0, 120)}</div></td>
|
|
17338
|
-
<td><span class="tag">${task.agent}</span></td>
|
|
17351
|
+
<td><div style="font-weight:500">${esc(task.name)}</div><div class="mu sm el">${esc(task.prompt.substring(0, 120))}</div></td>
|
|
17352
|
+
<td><span class="tag">${esc(task.agent)}</span></td>
|
|
17339
17353
|
<td><span class="badge b-${task.status}">${st}</span></td>
|
|
17340
17354
|
<td class="sm ${task.status === "running" ? "" : "mu"}">${formatDuration(task.startedAt, task.finishedAt)}</td>
|
|
17341
17355
|
<td class="mu sm">${(task.retryCount ?? 0) > 0 ? task.retryCount : "-"}</td>
|
|
@@ -17391,15 +17405,15 @@ app.get("/templates", async (c) => {
|
|
|
17391
17405
|
const toggleBtn = t.enabled ? `<button class="btn btn-sm btn-warn" onclick="disableTmpl(${t.id})">\u7981\u7528</button>` : `<button class="btn btn-sm" onclick="enableTmpl(${t.id})">\u542F\u7528</button>`;
|
|
17392
17406
|
rows += `<tr>
|
|
17393
17407
|
<td class="mu">#${t.id}</td>
|
|
17394
|
-
<td><div style="font-weight:500">${t.name}</div><div class="mu sm el">${t.prompt.substring(0, 100)}</div>
|
|
17395
|
-
<div class="sm" style="margin-top:2px"><span class="tag">${t.agent}</span>${t.model && t.model !== "default" ? ` <span class="tag">${t.model}</span>` : ""}</div></td>
|
|
17408
|
+
<td><div style="font-weight:500">${esc(t.name)}</div><div class="mu sm el">${esc(t.prompt.substring(0, 100))}</div>
|
|
17409
|
+
<div class="sm" style="margin-top:2px"><span class="tag">${esc(t.agent)}</span>${t.model && t.model !== "default" ? ` <span class="tag">${esc(t.model)}</span>` : ""}</div></td>
|
|
17396
17410
|
<td><span class="${typeClass}">${typeLabel}</span></td>
|
|
17397
17411
|
<td class="m sm">${rule}</td>
|
|
17398
17412
|
<td>${statusBadge}</td>
|
|
17399
17413
|
<td class="sm">${t.lastRunAt ? timeAgo(t.lastRunAt) : "-"}</td>
|
|
17400
17414
|
<td class="sm">${t.nextRunAt ? timeUntil(t.nextRunAt) : "-"}</td>
|
|
17401
17415
|
<td>
|
|
17402
|
-
<button class="btn btn-sm" onclick="
|
|
17416
|
+
<button class="btn btn-sm" onclick="showTemplateDetail(${t.id})">\u8BE6\u60C5</button>
|
|
17403
17417
|
<button class="btn btn-sm btn-primary" onclick="triggerTmpl(${t.id})">\u89E6\u53D1</button>
|
|
17404
17418
|
${toggleBtn}
|
|
17405
17419
|
<button class="btn btn-sm btn-danger" onclick="deleteTmpl(${t.id})">\u5220\u9664</button>
|
|
@@ -17451,9 +17465,9 @@ app.get("/runs", async (c) => {
|
|
|
17451
17465
|
const logBtn = run.log ? `<button class="btn btn-sm" onclick="toggleLog(${run.id})">\u65E5\u5FD7</button>` : "";
|
|
17452
17466
|
rows += `<tr>
|
|
17453
17467
|
<td class="mu">#${run.id}</td>
|
|
17454
|
-
<td><div style="font-weight:500">${run.taskName} <span class="mu">(#${run.taskId})</span></div>
|
|
17455
|
-
${run.model ? `<div class="sm"><span class="tag">${run.model}</span></div>` : ""}</td>
|
|
17456
|
-
<td><span class="tag">${run.taskAgent}</span></td>
|
|
17468
|
+
<td><div style="font-weight:500">${esc(run.taskName)} <span class="mu">(#${run.taskId})</span></div>
|
|
17469
|
+
${run.model ? `<div class="sm"><span class="tag">${esc(run.model)}</span></div>` : ""}</td>
|
|
17470
|
+
<td><span class="tag">${esc(run.taskAgent)}</span></td>
|
|
17457
17471
|
<td><span class="badge b-${run.status}">${(run.status ?? "").toUpperCase()}</span></td>
|
|
17458
17472
|
<td class="sm">${formatDuration(run.startedAt, run.finishedAt)}</td>
|
|
17459
17473
|
<td class="sm mu">${run.heartbeatAt ? timeAgo(run.heartbeatAt) : "-"}</td>
|
|
@@ -17499,7 +17513,7 @@ app.get("/system", async (c) => {
|
|
|
17499
17513
|
runRows += `<tr>
|
|
17500
17514
|
<td class="mu">#${run.id}</td><td>#${run.taskId}</td>
|
|
17501
17515
|
<td class="m sm">${shortS}</td>
|
|
17502
|
-
<td class="sm">${run.model || "-"}</td>
|
|
17516
|
+
<td class="sm">${esc(run.model) || "-"}</td>
|
|
17503
17517
|
<td class="sm">${formatDate(run.startedAt)}</td>
|
|
17504
17518
|
<td class="sm">${run.heartbeatAt ? timeAgo(run.heartbeatAt) : "-"}</td>
|
|
17505
17519
|
<td class="m sm">W:${run.workerPid ?? "-"} C:${run.childPid ?? "-"}</td>
|
|
@@ -17588,6 +17602,12 @@ app.get("/api/runs/:id", async (c) => {
|
|
|
17588
17602
|
if (!run) return c.json({ error: "not found" }, 404);
|
|
17589
17603
|
return c.json(run);
|
|
17590
17604
|
});
|
|
17605
|
+
app.get("/api/templates/:id", async (c) => {
|
|
17606
|
+
const id = Number(c.req.param("id"));
|
|
17607
|
+
const tmpl = await TaskTemplateService.getById(id);
|
|
17608
|
+
if (!tmpl) return c.json({ error: "not found" }, 404);
|
|
17609
|
+
return c.json(tmpl);
|
|
17610
|
+
});
|
|
17591
17611
|
app.post("/api/tasks/:id/retry", async (c) => {
|
|
17592
17612
|
await TaskService.retry(Number(c.req.param("id")));
|
|
17593
17613
|
return c.json({ success: true });
|