@qablehq/atto 0.0.10 → 0.0.11
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/out/main/index.js +52 -1
- package/package.json +1 -1
package/out/main/index.js
CHANGED
|
@@ -3117,7 +3117,7 @@ async function tesboFetch(link, path, init) {
|
|
|
3117
3117
|
headers: {
|
|
3118
3118
|
accept: "application/json",
|
|
3119
3119
|
[ACCESS_HEADER]: link.code,
|
|
3120
|
-
...{},
|
|
3120
|
+
...init?.body ? { "content-type": "application/json" } : {},
|
|
3121
3121
|
...init?.headers
|
|
3122
3122
|
}
|
|
3123
3123
|
});
|
|
@@ -3244,11 +3244,62 @@ async function tesboAgents(projectId) {
|
|
|
3244
3244
|
}
|
|
3245
3245
|
return { projectId, agents: [...SERVER_AGENTS, ...COMING_SOON], notice: null };
|
|
3246
3246
|
}
|
|
3247
|
+
function safeTargetPath(savePath, fileName) {
|
|
3248
|
+
const folder = node_path.resolve(node_path.normalize(savePath.trim()));
|
|
3249
|
+
if (!node_path.isAbsolute(folder)) throw new Error("Save location from Tesbo must be an absolute path.");
|
|
3250
|
+
const base = String(fileName || "script.spec.ts").replace(/[/\\]/g, "_").trim() || "script.spec.ts";
|
|
3251
|
+
const target = node_path.resolve(folder, base);
|
|
3252
|
+
const root = folder.endsWith(node_path.sep) ? folder : folder + node_path.sep;
|
|
3253
|
+
if (target !== folder && !target.startsWith(root)) {
|
|
3254
|
+
throw new Error("Refusing to write outside the configured save location.");
|
|
3255
|
+
}
|
|
3256
|
+
return target;
|
|
3257
|
+
}
|
|
3258
|
+
async function pullAndSavePendingScripts() {
|
|
3259
|
+
const link = readLink();
|
|
3260
|
+
if (!link) return { saved: 0, errors: [] };
|
|
3261
|
+
const response = await tesboFetch(link, "/api/atto/scripts/pending");
|
|
3262
|
+
if (response.status === 401) {
|
|
3263
|
+
clearLink();
|
|
3264
|
+
return { saved: 0, errors: ["Access code stopped."] };
|
|
3265
|
+
}
|
|
3266
|
+
if (!response.ok) throw new Error(await errorMessage(response));
|
|
3267
|
+
const body = await response.json();
|
|
3268
|
+
const scripts = Array.isArray(body.scripts) ? body.scripts : [];
|
|
3269
|
+
let saved = 0;
|
|
3270
|
+
const errors = [];
|
|
3271
|
+
for (const item of scripts) {
|
|
3272
|
+
if (!item?.id || !item.script || !item.savePath) continue;
|
|
3273
|
+
try {
|
|
3274
|
+
const target = safeTargetPath(item.savePath, item.fileName || `${item.externalId || "script"}.spec.ts`);
|
|
3275
|
+
node_fs.mkdirSync(node_path.resolve(node_path.normalize(item.savePath.trim())), { recursive: true });
|
|
3276
|
+
node_fs.writeFileSync(target, item.script, { encoding: "utf8" });
|
|
3277
|
+
const ack = await tesboFetch(link, `/api/atto/scripts/${encodeURIComponent(item.id)}/ack`, { method: "POST", body: "{}" });
|
|
3278
|
+
if (!ack.ok) throw new Error(await errorMessage(ack));
|
|
3279
|
+
saved += 1;
|
|
3280
|
+
} catch (error) {
|
|
3281
|
+
errors.push(error instanceof Error ? error.message : "Could not save a script.");
|
|
3282
|
+
}
|
|
3283
|
+
}
|
|
3284
|
+
return { saved, errors };
|
|
3285
|
+
}
|
|
3286
|
+
let scriptPollTimer = null;
|
|
3287
|
+
function startAttoScriptPoller(intervalMs = 5e3) {
|
|
3288
|
+
if (scriptPollTimer) return;
|
|
3289
|
+
const tick = () => {
|
|
3290
|
+
void pullAndSavePendingScripts().catch(() => void 0);
|
|
3291
|
+
};
|
|
3292
|
+
tick();
|
|
3293
|
+
scriptPollTimer = setInterval(tick, intervalMs);
|
|
3294
|
+
scriptPollTimer.unref?.();
|
|
3295
|
+
}
|
|
3247
3296
|
function registerTesboHandlers() {
|
|
3248
3297
|
electron.ipcMain.handle(IPC_CHANNELS.tesboStatus, () => tesboStatus());
|
|
3249
3298
|
electron.ipcMain.handle(IPC_CHANNELS.tesboLogin, (_event, cmd) => tesboLogin(cmd));
|
|
3250
3299
|
electron.ipcMain.handle(IPC_CHANNELS.tesboLogout, () => tesboLogout());
|
|
3251
3300
|
electron.ipcMain.handle(IPC_CHANNELS.tesboAgents, (_event, projectId) => tesboAgents(projectId));
|
|
3301
|
+
startAttoScriptPoller();
|
|
3302
|
+
void pullAndSavePendingScripts().catch(() => void 0);
|
|
3252
3303
|
}
|
|
3253
3304
|
const SCHEME = "taa-media";
|
|
3254
3305
|
const sessionRoots = /* @__PURE__ */ new Map();
|