@streamapp/stream 0.0.4 → 0.0.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/bin/stream.mjs +1 -1
- package/package.json +1 -1
- package/resources/server.mjs +62 -49
package/bin/stream.mjs
CHANGED
package/package.json
CHANGED
package/resources/server.mjs
CHANGED
|
@@ -174283,6 +174283,8 @@ async function typeInto(driver, step, params, foreground, find2) {
|
|
|
174283
174283
|
await driver.type(text3);
|
|
174284
174284
|
return "keyboard";
|
|
174285
174285
|
}
|
|
174286
|
+
var ForegroundRefused = class extends Error {
|
|
174287
|
+
};
|
|
174286
174288
|
var WINDOW_POLL_MS = 500;
|
|
174287
174289
|
async function waitForWindow(driver, match2, timeoutMs) {
|
|
174288
174290
|
const titles = match2.titleAnyOf ?? (match2.title == null ? [] : [match2.title]);
|
|
@@ -174326,7 +174328,13 @@ async function runDesktopRecipeLocked(recipe, params, driver) {
|
|
|
174326
174328
|
const stepFailed = (step, machine) => blocked("drift", step.label ? `${step.label}\uFF1A${machine}` : machine);
|
|
174327
174329
|
if (recipe.steps[0]?.kind !== "window") await driver.scopeWindow(recipe.app);
|
|
174328
174330
|
let scoped = recipe.app;
|
|
174329
|
-
const foreground = () =>
|
|
174331
|
+
const foreground = async () => {
|
|
174332
|
+
if (!await driver.focusApp(scoped)) {
|
|
174333
|
+
throw new ForegroundRefused(
|
|
174334
|
+
`\u6CA1\u80FD\u628A\u300C${scoped.title ?? scoped.process}\u300D\u62AC\u5230\u524D\u53F0\u2014\u2014\u5C4F\u5E55\u9501\u7740\u3001\u4F1A\u8BDD\u6CA1\u4EBA\u8FDE\u7740\u3001\u6216\u8005\u522B\u7684\u7A97\u53E3\u538B\u7740\u4E0D\u653E\u3002\u8FD9\u4E00\u6B65\u8981\u53D1\u7684\u662F\u952E\u76D8/\u9F20\u6807\u8F93\u5165\uFF0C\u6CA1\u6709\u524D\u53F0\u5C31\u6CA1\u6709\u6536\u4EF6\u4EBA\uFF0C\u6240\u4EE5\u505C\u624B\u3002`
|
|
174335
|
+
);
|
|
174336
|
+
}
|
|
174337
|
+
};
|
|
174330
174338
|
if (recipe.loginCheck) {
|
|
174331
174339
|
if ((await find2(subQuery(recipe.loginCheck.wall, params))).length > 0) return blocked("needsLogin");
|
|
174332
174340
|
}
|
|
@@ -174335,55 +174343,60 @@ async function runDesktopRecipeLocked(recipe, params, driver) {
|
|
|
174335
174343
|
for (const [i, step] of recipe.steps.entries()) {
|
|
174336
174344
|
probe2(`#${i} ${step.kind}${step.label ? ` (${step.label.slice(0, 24)}\u2026)` : ""}`);
|
|
174337
174345
|
if (step.skipIf && (await find2(subQuery(step.skipIf, params))).length > 0) continue;
|
|
174338
|
-
|
|
174339
|
-
|
|
174340
|
-
|
|
174341
|
-
|
|
174342
|
-
|
|
174343
|
-
|
|
174344
|
-
|
|
174345
|
-
|
|
174346
|
-
|
|
174347
|
-
|
|
174348
|
-
|
|
174349
|
-
|
|
174350
|
-
|
|
174351
|
-
|
|
174352
|
-
|
|
174353
|
-
|
|
174354
|
-
|
|
174355
|
-
|
|
174356
|
-
|
|
174357
|
-
|
|
174358
|
-
|
|
174359
|
-
|
|
174360
|
-
|
|
174361
|
-
|
|
174362
|
-
|
|
174363
|
-
|
|
174364
|
-
|
|
174365
|
-
|
|
174366
|
-
|
|
174367
|
-
} else if (step.kind === "invoke") {
|
|
174368
|
-
const q = subQuery(step.query, params);
|
|
174369
|
-
const els = await find2(q);
|
|
174370
|
-
if (els.length === 0 && step.optional) continue;
|
|
174371
|
-
if (els.length === 0) return stepFailed(step, `invoke target not found: ${JSON.stringify(q)}`);
|
|
174372
|
-
if (step.fallbackClick) {
|
|
174346
|
+
try {
|
|
174347
|
+
if (step.kind === "window") {
|
|
174348
|
+
const win = await waitForWindow(driver, step.match, step.timeoutMs ?? 12e3);
|
|
174349
|
+
if (!win && step.optional) continue;
|
|
174350
|
+
if (!win) return stepFailed(step, `window not found: ${JSON.stringify(step.match)}`);
|
|
174351
|
+
probe2(`#${i} window hit \u300C${win.title}\u300D (${win.process})`);
|
|
174352
|
+
scoped = { process: win.process, title: win.title };
|
|
174353
|
+
try {
|
|
174354
|
+
await driver.scopeWindow(scoped);
|
|
174355
|
+
} catch (e) {
|
|
174356
|
+
if (step.optional) continue;
|
|
174357
|
+
const now = (await driver.windows()).map((w) => w.title).join("\u3001");
|
|
174358
|
+
return stepFailed(step, `\u7A97\u53E3\u300C${win.title}\u300D\u5728\u88AB scope \u4E4B\u524D\u5C31\u6D88\u5931\u4E86\uFF08${e.message}\uFF09\uFF1B\u6B64\u523B\u8FD8\u5728\u7684\u7A97\u53E3\uFF1A${now}`);
|
|
174359
|
+
}
|
|
174360
|
+
if (step.focus) await foreground();
|
|
174361
|
+
if (step.waitFor) {
|
|
174362
|
+
const q = subQuery(step.waitFor, params);
|
|
174363
|
+
const rounds = Math.max(1, Math.ceil((step.timeoutMs ?? 12e3) / WINDOW_POLL_MS));
|
|
174364
|
+
let seen2 = false;
|
|
174365
|
+
for (let i2 = 0; i2 < rounds; i2++) {
|
|
174366
|
+
if ((await find2(q)).length > 0) {
|
|
174367
|
+
seen2 = true;
|
|
174368
|
+
break;
|
|
174369
|
+
}
|
|
174370
|
+
await driver.sleep(WINDOW_POLL_MS);
|
|
174371
|
+
}
|
|
174372
|
+
if (!seen2 && !step.optional) return stepFailed(step, `window is up but its UI never appeared: ${JSON.stringify(q)}`);
|
|
174373
|
+
}
|
|
174374
|
+
} else if (step.kind === "focus") {
|
|
174373
174375
|
await foreground();
|
|
174374
|
-
|
|
174375
|
-
|
|
174376
|
-
|
|
174377
|
-
|
|
174378
|
-
|
|
174379
|
-
|
|
174380
|
-
|
|
174381
|
-
|
|
174382
|
-
|
|
174383
|
-
|
|
174384
|
-
|
|
174385
|
-
|
|
174386
|
-
|
|
174376
|
+
} else if (step.kind === "invoke") {
|
|
174377
|
+
const q = subQuery(step.query, params);
|
|
174378
|
+
const els = await find2(q);
|
|
174379
|
+
if (els.length === 0 && step.optional) continue;
|
|
174380
|
+
if (els.length === 0) return stepFailed(step, `invoke target not found: ${JSON.stringify(q)}`);
|
|
174381
|
+
if (step.fallbackClick) {
|
|
174382
|
+
await foreground();
|
|
174383
|
+
await driver.click(els[0].rect);
|
|
174384
|
+
} else await driver.invoke(els[0].ref);
|
|
174385
|
+
} else if (step.kind === "type") {
|
|
174386
|
+
const via = await typeInto(driver, step, params, foreground, find2);
|
|
174387
|
+
if (via === "no-target") {
|
|
174388
|
+
return stepFailed(step, `type target not found: ${JSON.stringify(subQuery(step.query, params))}`);
|
|
174389
|
+
}
|
|
174390
|
+
typedVia = via;
|
|
174391
|
+
} else if (step.kind === "scroll") {
|
|
174392
|
+
await foreground();
|
|
174393
|
+
await driver.scroll(step.dir, step.amount);
|
|
174394
|
+
} else if (step.kind === "wait") {
|
|
174395
|
+
await driver.sleep(step.ms);
|
|
174396
|
+
}
|
|
174397
|
+
} catch (e) {
|
|
174398
|
+
if (e instanceof ForegroundRefused) return stepFailed(step, e.message);
|
|
174399
|
+
throw e;
|
|
174387
174400
|
}
|
|
174388
174401
|
}
|
|
174389
174402
|
if (!recipe.observer || !recipe.read) {
|