femo-plugin 1.0.4 → 1.0.6
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/LICENSE +1 -1
- package/NOTICE +8 -0
- package/README.md +12 -1
- package/docs/ActiveRoadmaps/Func/345/201/234/346/255/242/350/257/255/344/271/211-/351/201/227/345/274/203/346/216/245/347/273/255-/346/226/275/345/267/245/346/270/205/345/215/225.md +91 -0
- package/docs/ActiveRoadmaps//345/217/214user/346/226/275/345/267/245/346/270/205/345/215/225.md +326 -0
- package/docs/Specs//346/212/225/345/275/261/344/270/255/345/277/203/350/241/214/345/215/217/350/256/256.md +616 -569
- package/femo2host/AGENTS.md +1 -1
- package/femo2host/femoGenConnector/engine-client.mjs +7 -2
- package/femo2host/femoGenConnector/file-dialogs.mjs +108 -2
- package/femo2host/femoToolcall/chronica.py +99 -19
- package/femo2host/femo_api.py +14 -1
- package/femo2host/host/actor-core.d.mts +25 -0
- package/femo2host/host/actor-core.mjs +72 -0
- package/femo2host/host/cast-core.d.mts +3 -0
- package/femo2host/host/cast-core.mjs +14 -0
- package/femo2host/host/daemon-client.mjs +59 -10
- package/femo2host/host/hub-render-core.d.mts +2 -0
- package/femo2host/host/hub-render-core.mjs +6 -2
- package/femo2host/host/run-state-core.d.mts +4 -0
- package/femo2host/host/run-state-core.mjs +4 -0
- package/femo2host/host/speech-core.mjs +11 -4
- package/femo2host/host/tools-core.d.mts +11 -0
- package/femo2host/host/tools-core.mjs +39 -0
- package/femo2host/mailbox.py +630 -545
- package/femo2host/projectionCenter/app.css +61 -0
- package/femo2host/projectionCenter/composer.mjs +233 -20
- package/femo2host/projectionCenter/identity.mjs +131 -0
- package/femo2host/projectionCenter/index.html +55 -1
- package/femo2host/projectionCenter/main.mjs +231 -35
- package/femo2host/projectionCenter/panels.mjs +108 -16
- package/femo2host/projectionCenter/render.mjs +813 -695
- package/femo2host/projectionCenter/state.mjs +30 -0
- package/femo2host/projectionCenter/util.mjs +28 -0
- package/femo2host/projection_hub.py +1796 -230
- package/femo2host/python/femo_bridge.py +303 -33
- package/femo2host/python/femo_daemon.py +1528 -1209
- package/femo2host/python/mirror_window.py +237 -0
- package/femoBridges/ContextExample.py +113 -71
- package/femoCompiler/AGENTS.md +1 -0
- package/femoCompiler/FEMO_parser.py +2641 -2567
- package/femoCompiler/FEMO_runtime.py +217 -44
- package/femoCompiler/FEMO_scope_resolver.py +26 -12
- package/femoCompiler/block_collector.py +24 -27
- package/femoCompiler/db_utils.py +560 -503
- package/femoCompiler/femoAsync.py +466 -436
- package/femoCompiler/func_registry.py +74 -0
- package/femoCompiler/protocol.py +127 -127
- package/femoCompiler/save_dialog.py +497 -446
- package/femoExamples/AI/350/201/212/345/244/251/345/256/244/AI/350/201/212/345/244/251/345/256/244-/345/270/246agent/347/211/210.femo +229 -142
- package/femoExamples/AI/350/201/212/345/244/251/345/256/244/random_wait_time.py +91 -2
- package/femoExamples/LuxFiat/luxfiat-loop.femo +0 -1
- package/femoExamples/LuxFiat/luxfiat-simple.femo +23 -24
- package/femoExamples/debug/347/245/236/345/231/250/debug/347/245/236/345/231/250.femo +221 -222
- package/femoExamples/discussion.femo +72 -72
- package/femoExamples//347/213/274/344/272/272/346/235/200//347/213/274/344/272/272/346/235/200-/350/255/246/351/225/277/347/211/210-9/344/272/272/351/242/204/345/245/263/347/214/216.femo +1 -2
- package/femoExamples//347/213/274/344/272/272/346/235/200//347/213/274/344/272/272/346/235/200-/350/255/246/351/225/277/347/211/210.femo +1 -2
- package/femoExamples//347/213/274/344/272/272/346/235/200//347/213/274/344/272/272/346/235/200.femo +1 -2
- package/femoExamples//350/260/201/346/230/257/345/215/247/345/272/225//350/260/201/346/230/257/345/215/247/345/272/225-/350/217/234/345/270/202/345/234/272/345/261/200.femo +1 -1
- package/femoExamples//350/260/201/346/230/257/345/215/247/345/272/225//350/260/201/346/230/257/345/215/247/345/272/225.femo +1 -1
- package/femoGen/document_ch.html +1 -0
- package/femoGen/document_en.html +1 -0
- package/femoGen/index.html +1 -0
- package/femoGen/intro_ch.html +1 -0
- package/femoGen/intro_en.html +1 -0
- package/femoGen/package.json +7 -0
- package/femoGen/public/femo-logo-slogan.svg +5 -0
- package/femoGen/public/femo-logo.svg +6 -1
- package/femoGen/src/femoParser.jsx +14 -0
- package/hostAdapter/dshAdapter/host/femo-skill.ts +23 -10
- package/hostAdapter/dshAdapter/host/routes/projection-input.ts +3 -0
- package/hostAdapter/dshAdapter/lib/client.js +20 -2
- package/hostAdapter/dshAdapter/lib/client.js.map +2 -2
- package/hostAdapter/dshAdapter/lib/main.js +161 -18
- package/hostAdapter/dshAdapter/lib/main.js.map +3 -3
- package/hostAdapter/dshAdapter/package.json +11 -1
- package/hostAdapter/webAdapter/console/index.html +13 -4
- package/hostAdapter/webAdapter/extension/background.js +16 -5
- package/hostAdapter/webAdapter/extension/seat-agent-core.js +836 -791
- package/hostAdapter/webAdapter/extension/sidepanel/actors.mjs +101 -0
- package/hostAdapter/webAdapter/extension/sidepanel/main.mjs +81 -20
- package/hostAdapter/webAdapter/extension/sidepanel/reconnect.mjs +33 -0
- package/hostAdapter/webAdapter/extension/sidepanel/run-control.mjs +22 -11
- package/hostAdapter/webAdapter/extension/sidepanel/seats.mjs +6 -20
- package/hostAdapter/webAdapter/extension/sidepanel.html +31 -8
- package/hostAdapter/webAdapter/native/install-native-host.mjs +1 -0
- package/hostAdapter/webAdapter/native/register-core.mjs +69 -28
- package/hostAdapter/webAdapter/native/web-launcher.sh +37 -0
- package/hostAdapter/webAdapter/package.json +7 -0
- package/hostAdapter/webAdapter/readme.md +51 -10
- package/hostAdapter/webAdapter/server/bridge.mjs +1 -1
- package/hostAdapter/webAdapter/server/runtime.mjs +51 -5
- package/hostAdapter/webAdapter/server/seats.mjs +11 -6
- package/hostAdapter/webAdapter/server/service.mjs +108 -15
- package/hostAdapter/webAdapter/shared/seats-core.mjs +31 -6
- package/hostAdapter/webAdapter/sites/chat.deepseek.com/SITE.md +7 -0
- package/hostAdapter/webAdapter/sites/chat.deepseek.com/content.js +83 -68
- package/hostAdapter/webAdapter/sites/chatglm.cn/inject.js +76 -4
- package/hostAdapter/webAdapter/sites/chatgpt.com/SITE.md +7 -1
- package/hostAdapter/webAdapter/sites/chatgpt.com/content.js +37 -5
- package/hostAdapter/webAdapter/sites/chatgpt.com/inject.js +40 -4
- package/hostAdapter/webAdapter/start-service.command +16 -0
- package/hostAdapter/webAdapter/tests/chatgpt-input.test.mjs +58 -0
- package/hostAdapter/webAdapter/tests/chatgpt-parser.test.mjs +37 -0
- package/hostAdapter/webAdapter/tests/deepseek-sanitize.test.mjs +68 -0
- package/hostAdapter/webAdapter/tests/runtime.test.mjs +42 -0
- package/hostAdapter/webAdapter/tests/seats-core.test.mjs +37 -1
- package/hostAdapter/webAdapter/tests/smoke-service.mjs +261 -232
- package/hostAdapter/zcodeAdapter/runtime/speech-collect.mjs +6 -0
- package/hostAdapter/zcodeAdapter/skills/femo/SKILL.md +3 -0
- package/hostAdapter/zcodeAdapter/tests/unbound-actors.test.mjs +51 -0
- package/package.json +7 -1
- package//350/257/255/346/263/225/346/226/207/346/241/243.md +1224 -1202
|
@@ -1157,9 +1157,9 @@ function diagTail(n) {
|
|
|
1157
1157
|
|
|
1158
1158
|
// ../../femo2host/host/daemon-client.mjs
|
|
1159
1159
|
import { spawn } from "node:child_process";
|
|
1160
|
-
import { closeSync, existsSync as existsSync2, mkdirSync as mkdirSync2, openSync, readFileSync as readFileSync2, unlinkSync as unlinkSync2, writeSync } from "node:fs";
|
|
1160
|
+
import { accessSync, closeSync, constants, existsSync as existsSync2, mkdirSync as mkdirSync2, openSync, readFileSync as readFileSync2, unlinkSync as unlinkSync2, writeSync } from "node:fs";
|
|
1161
1161
|
import { request as httpRequest } from "node:http";
|
|
1162
|
-
import { dirname as dirname4, join as join5 } from "node:path";
|
|
1162
|
+
import { delimiter, dirname as dirname4, isAbsolute, join as join5, sep } from "node:path";
|
|
1163
1163
|
|
|
1164
1164
|
// ../../femo2host/host/hub-client.mjs
|
|
1165
1165
|
import { readFileSync, statSync as statSync2 } from "node:fs";
|
|
@@ -1212,6 +1212,35 @@ var DAEMON_LOG_REL = join5("logs", "femo_daemon.log");
|
|
|
1212
1212
|
function sleep(ms) {
|
|
1213
1213
|
return new Promise((r) => setTimeout(r, ms));
|
|
1214
1214
|
}
|
|
1215
|
+
function findExecutableOnPath(name2, dirs) {
|
|
1216
|
+
for (const dir of dirs) {
|
|
1217
|
+
try {
|
|
1218
|
+
const full = join5(dir, name2);
|
|
1219
|
+
accessSync(full, constants.X_OK);
|
|
1220
|
+
return full;
|
|
1221
|
+
} catch {
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
return null;
|
|
1225
|
+
}
|
|
1226
|
+
function resolvePythonExe() {
|
|
1227
|
+
const fromEnv = process.env.FEMO_PYTHON;
|
|
1228
|
+
if (fromEnv) {
|
|
1229
|
+
if (isAbsolute(fromEnv) || fromEnv.includes(sep)) return fromEnv;
|
|
1230
|
+
return findExecutableOnPath(fromEnv, (process.env.PATH || "").split(delimiter).filter(Boolean)) ?? fromEnv;
|
|
1231
|
+
}
|
|
1232
|
+
const isWin = process.platform === "win32";
|
|
1233
|
+
const names = isWin ? ["python.exe", "python3.exe", "python", "python3"] : ["python3", "python"];
|
|
1234
|
+
const dirs = [
|
|
1235
|
+
...(process.env.PATH || "").split(delimiter).filter(Boolean),
|
|
1236
|
+
...isWin ? [] : ["/usr/bin", "/usr/local/bin", "/opt/homebrew/bin"]
|
|
1237
|
+
];
|
|
1238
|
+
for (const name2 of names) {
|
|
1239
|
+
const hit = findExecutableOnPath(name2, dirs);
|
|
1240
|
+
if (hit) return hit;
|
|
1241
|
+
}
|
|
1242
|
+
return null;
|
|
1243
|
+
}
|
|
1215
1244
|
function httpJson(base, pathAndQuery, { method = "GET", body, timeoutSec = 5 } = {}) {
|
|
1216
1245
|
return new Promise((resolve2, reject) => {
|
|
1217
1246
|
const { hostname, port, pathname, search } = new URL(base + pathAndQuery);
|
|
@@ -1291,7 +1320,7 @@ var DaemonClient = class {
|
|
|
1291
1320
|
this.hostManifestPath = opts.hostManifestPath || "";
|
|
1292
1321
|
this.dataDir = opts.dataDir || "";
|
|
1293
1322
|
this.pushUrl = opts.pushUrl || "";
|
|
1294
|
-
this.pythonPath = opts.python ??
|
|
1323
|
+
this.pythonPath = opts.python ?? resolvePythonExe() ?? "python";
|
|
1295
1324
|
this.onEvent = opts.onEvent;
|
|
1296
1325
|
this.onEngineLine = opts.onEngineLine;
|
|
1297
1326
|
this.onEngineStderr = opts.onEngineStderr;
|
|
@@ -1344,7 +1373,8 @@ var DaemonClient = class {
|
|
|
1344
1373
|
{ cwd: this.femoRoot, env, detached: true, windowsHide: true, stdio: ["ignore", logf, logf] }
|
|
1345
1374
|
);
|
|
1346
1375
|
child.unref();
|
|
1347
|
-
this.log(`daemon
|
|
1376
|
+
child.on("error", (e) => this.log(`daemon \u62C9\u8D77\u5931\u8D25\uFF08python=${this.pythonPath}\uFF09\uFF1A${e?.message ?? e} \u2014\u2014 \u5F15\u64CE\u4E0D\u53EF\u7528\uFF1B\u88C5 python3\uFF08mac\uFF1Axcode-select --install \u6216 brew install python3\uFF09\u6216\u8BBE FEMO_PYTHON \u6307\u5230\u53EF\u7528\u89E3\u91CA\u5668\u540E\u91CD\u8BD5`));
|
|
1377
|
+
this.log(`daemon spawned (pid=${child.pid ?? "\u672A\u8D77\uFF0C\u7B49 error \u843D\u75D5"}) log=${logPath}`);
|
|
1348
1378
|
}
|
|
1349
1379
|
/** 跨进程代拉意图锁(2026-09-28 镜窗成群事故):hub.json 死账谁探到谁就想
|
|
1350
1380
|
* 代拉,多客户端同刻齐醒就是一波孪生 daemon。锁文件 O_EXCL 建锁(驿站信柜
|
|
@@ -1569,14 +1599,16 @@ var DaemonClient = class {
|
|
|
1569
1599
|
this._doorbellAbort = stopFlag;
|
|
1570
1600
|
void (async () => {
|
|
1571
1601
|
while (!stopFlag.stop) {
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1602
|
+
if (this._base) {
|
|
1603
|
+
try {
|
|
1604
|
+
await httpJson(
|
|
1605
|
+
this._base,
|
|
1606
|
+
"/engine/doorbell",
|
|
1607
|
+
{ method: "POST", body: { host: this.host, url: this.pushUrl }, timeoutSec: 5 }
|
|
1608
|
+
);
|
|
1609
|
+
} catch (e) {
|
|
1610
|
+
this.log(`doorbell register failed: ${String(e.message ?? e).slice(0, 120)}`);
|
|
1611
|
+
}
|
|
1580
1612
|
}
|
|
1581
1613
|
for (let i = 0; i < DOORBELL_PERIOD_MS / 100 && !stopFlag.stop; i++) await sleep(100);
|
|
1582
1614
|
}
|
|
@@ -2136,13 +2168,17 @@ function femoSkillContent(femoRoot2) {
|
|
|
2136
2168
|
return skillContentCache;
|
|
2137
2169
|
}
|
|
2138
2170
|
function installFemoSkill(ctx, femoRoot2) {
|
|
2139
|
-
ctx.effect(() => installFemoRootSection(ctx) ?? (() => void 0), "femo-plugin: femo:root section");
|
|
2140
|
-
installTipsSection(ctx);
|
|
2141
2171
|
const inject2 = ctx.inject;
|
|
2142
2172
|
if (typeof inject2 !== "function") {
|
|
2143
|
-
console.log("[femo-plugin] femo skill: ctx.inject unavailable; /femo skill
|
|
2173
|
+
console.log("[femo-plugin] femo skill: ctx.inject unavailable; /femo skill \u4E0E\u4E24\u6BB5\u63D0\u793A\u6BB5\u90FD\u672A\u6302\u8F7D");
|
|
2144
2174
|
return;
|
|
2145
2175
|
}
|
|
2176
|
+
console.log("[femo-plugin] femo skill: waiting for ctx.systemPrompt \u2026");
|
|
2177
|
+
inject2(["systemPrompt"], (child) => {
|
|
2178
|
+
ctx.effect(() => installFemoRootSection(child) ?? (() => void 0), "femo-plugin: femo:root section");
|
|
2179
|
+
installTipsSection(child);
|
|
2180
|
+
console.log("[femo-plugin] femo:root / femo:tips sections installed (global)");
|
|
2181
|
+
});
|
|
2146
2182
|
console.log("[femo-plugin] femo skill: waiting for ctx.skills \u2026");
|
|
2147
2183
|
inject2(["skills"], (child) => {
|
|
2148
2184
|
const skills = child.skills;
|
|
@@ -4464,21 +4500,23 @@ var ApiRetryChain2 = class extends ApiRetryChain {
|
|
|
4464
4500
|
var apiRetry2 = new ApiRetryChain2();
|
|
4465
4501
|
|
|
4466
4502
|
// ../../femo2host/host/speech-core.mjs
|
|
4467
|
-
function humanSpeechArgs({ jobId, waitKey, soul, node, text, variables = {} }) {
|
|
4503
|
+
function humanSpeechArgs({ jobId, waitKey, soul, node, text, variables = {}, actor }) {
|
|
4468
4504
|
const cleanVars = {};
|
|
4469
4505
|
for (const [k, v] of Object.entries(variables ?? {})) {
|
|
4470
4506
|
if (typeof v === "string" && v.trim().length > 0) cleanVars[k] = v.trim();
|
|
4471
4507
|
}
|
|
4508
|
+
const actorClean = String(actor ?? "").trim();
|
|
4472
4509
|
return {
|
|
4473
4510
|
job_id: jobId,
|
|
4474
4511
|
wait_key: waitKey,
|
|
4475
4512
|
soul: soul || "human",
|
|
4476
4513
|
...node ? { node } : {},
|
|
4514
|
+
...actorClean ? { actor: actorClean } : {},
|
|
4477
4515
|
payload: text,
|
|
4478
4516
|
body: { chat_text: text, ...Object.keys(cleanVars).length > 0 ? { variables: cleanVars } : {} }
|
|
4479
4517
|
};
|
|
4480
4518
|
}
|
|
4481
|
-
function executorSpeechArgs({ jobId, waitKey, soul = "main", node, output, steps, modelId }) {
|
|
4519
|
+
function executorSpeechArgs({ jobId, waitKey, soul = "main", node, output, steps, modelId, actor }) {
|
|
4482
4520
|
const merged = (Array.isArray(steps) ? steps : []).map((s) => s && typeof s === "object" ? { ...s } : { reply: String(s ?? "") });
|
|
4483
4521
|
if (merged.length > 0) {
|
|
4484
4522
|
const last = merged[merged.length - 1];
|
|
@@ -4486,11 +4524,13 @@ function executorSpeechArgs({ jobId, waitKey, soul = "main", node, output, steps
|
|
|
4486
4524
|
} else {
|
|
4487
4525
|
merged.push({ step: 0, reply: output });
|
|
4488
4526
|
}
|
|
4527
|
+
const actorClean = String(actor ?? "").trim();
|
|
4489
4528
|
return {
|
|
4490
4529
|
job_id: jobId,
|
|
4491
4530
|
wait_key: waitKey,
|
|
4492
4531
|
soul,
|
|
4493
4532
|
...node ? { node } : {},
|
|
4533
|
+
...actorClean ? { actor: actorClean } : {},
|
|
4494
4534
|
payload: output,
|
|
4495
4535
|
body: {
|
|
4496
4536
|
steps: merged,
|
|
@@ -4816,6 +4856,10 @@ function waitingHumanFromEvent(d) {
|
|
|
4816
4856
|
return {
|
|
4817
4857
|
waitKey: String(d.wait_key ?? ""),
|
|
4818
4858
|
nodeName: typeof d.node_name === "string" ? d.node_name : void 0,
|
|
4859
|
+
// actor(2026-10-10 随行格):引擎报的执行者显示名,原样随行;交卷时
|
|
4860
|
+
// 透传 post_speech 信封(mailbox.actor 只入账不路由)。老引擎无此键时
|
|
4861
|
+
// 为 undefined,交卷侧自然不填。
|
|
4862
|
+
actor: typeof d.actor_name === "string" && d.actor_name ? d.actor_name : void 0,
|
|
4819
4863
|
context: typeof d.context === "string" ? d.context : "",
|
|
4820
4864
|
memory: typeof d.memory === "string" ? d.memory : "",
|
|
4821
4865
|
showprompt: typeof d.showprompt === "string" ? d.showprompt : void 0,
|
|
@@ -7931,6 +7975,9 @@ async function feedHumanNode(ctx, deps, mainSid, job, text, variables, debugLog)
|
|
|
7931
7975
|
jobId: job.jobId,
|
|
7932
7976
|
waitKey: waitKeyUsed,
|
|
7933
7977
|
soul: job.waitingHuman?.waitScope?.[0] ?? "human",
|
|
7978
|
+
// actor 随行格(2026-10-10):等待镜像里的执行者名(引擎报的权威),
|
|
7979
|
+
// 只随信入账不路由;老引擎无此键时 undefined → 信封不带。
|
|
7980
|
+
actor: job.waitingHuman?.actor,
|
|
7934
7981
|
node: job.waitingHuman?.nodeName,
|
|
7935
7982
|
text,
|
|
7936
7983
|
variables
|
|
@@ -8250,6 +8297,102 @@ var DIALOG_TIMEOUT_MS = 6e5;
|
|
|
8250
8297
|
function b64(s) {
|
|
8251
8298
|
return Buffer.from(String(s), "utf8").toString("base64");
|
|
8252
8299
|
}
|
|
8300
|
+
async function pickFemoFileViaDialog(opts) {
|
|
8301
|
+
if (process.platform === "darwin") return pickFemoFileViaDialogMac(opts);
|
|
8302
|
+
return pickFemoFileViaDialogWindows(opts);
|
|
8303
|
+
}
|
|
8304
|
+
async function pickFemoFileViaDialogMac(opts) {
|
|
8305
|
+
const { spawn: spawn2 } = await import("node:child_process");
|
|
8306
|
+
const os = await import("node:os");
|
|
8307
|
+
const path = await import("node:path");
|
|
8308
|
+
const fs = await import("node:fs");
|
|
8309
|
+
const po = path.join(os.tmpdir(), `femo-dialog-${process.pid}-${Date.now()}.po`);
|
|
8310
|
+
let defaultName = opts.defaultName !== void 0 ? String(opts.defaultName) : "flow";
|
|
8311
|
+
if (!/\.femo$/i.test(defaultName)) defaultName += ".femo";
|
|
8312
|
+
const env = {
|
|
8313
|
+
...process.env,
|
|
8314
|
+
FEMO_DIALOG_PO: po,
|
|
8315
|
+
FEMO_DIALOG_TITLE: b64(opts.title),
|
|
8316
|
+
FEMO_DIALOG_MODE: opts.mode === "save" ? "save" : "open",
|
|
8317
|
+
FEMO_DIALOG_DEFAULT_NAME: b64(defaultName),
|
|
8318
|
+
FEMO_DIALOG_DIR: b64(opts.initialDirectory ?? ""),
|
|
8319
|
+
FEMO_DIALOG_HAS_DIR: opts.initialDirectory ? "1" : "0"
|
|
8320
|
+
};
|
|
8321
|
+
const child = spawn2("/usr/bin/osascript", ["-"], { env, detached: true, windowsHide: true, stdio: ["pipe", "ignore", "pipe"] });
|
|
8322
|
+
child.stdin.end(macDialogAppleScript());
|
|
8323
|
+
let errOut = "";
|
|
8324
|
+
child.stderr.on("data", (c) => {
|
|
8325
|
+
errOut += c.toString("utf8");
|
|
8326
|
+
});
|
|
8327
|
+
const timer = setTimeout(() => {
|
|
8328
|
+
try {
|
|
8329
|
+
child.kill();
|
|
8330
|
+
} catch {
|
|
8331
|
+
}
|
|
8332
|
+
}, DIALOG_TIMEOUT_MS);
|
|
8333
|
+
const code = await new Promise((resolve2) => {
|
|
8334
|
+
child.on("close", (c) => {
|
|
8335
|
+
clearTimeout(timer);
|
|
8336
|
+
resolve2(c ?? 1);
|
|
8337
|
+
});
|
|
8338
|
+
child.on("error", () => {
|
|
8339
|
+
clearTimeout(timer);
|
|
8340
|
+
resolve2(-1);
|
|
8341
|
+
});
|
|
8342
|
+
});
|
|
8343
|
+
let picked = null, cancel = false, asErr = "";
|
|
8344
|
+
try {
|
|
8345
|
+
const raw = fs.readFileSync(po, "utf8").trim();
|
|
8346
|
+
if (raw.startsWith("ok ")) picked = Buffer.from(raw.slice(3).trim(), "base64").toString("utf8");
|
|
8347
|
+
else if (raw === "cancel") cancel = true;
|
|
8348
|
+
else if (raw.startsWith("err ")) asErr = Buffer.from(raw.slice(4).trim(), "base64").toString("utf8");
|
|
8349
|
+
} catch {
|
|
8350
|
+
}
|
|
8351
|
+
if (picked) return picked;
|
|
8352
|
+
if (cancel) return null;
|
|
8353
|
+
if (code !== 0 && /user canceled|用户已取消/i.test(errOut)) return null;
|
|
8354
|
+
const detail = [asErr, errOut.trim().slice(-400)].filter(Boolean).join(" | ");
|
|
8355
|
+
throw new Error(`${opts.mode === "open" ? "pick-script" : "pick-save-path"} failed (exit ${String(code)})${detail ? `: ${detail}` : ""}`);
|
|
8356
|
+
}
|
|
8357
|
+
function macDialogAppleScript() {
|
|
8358
|
+
return `set PO to (do shell script "printf %s $FEMO_DIALOG_PO")
|
|
8359
|
+
set T to (do shell script "printf %s $FEMO_DIALOG_TITLE | base64 -D")
|
|
8360
|
+
set M to (do shell script "printf %s $FEMO_DIALOG_MODE")
|
|
8361
|
+
try
|
|
8362
|
+
tell me to activate
|
|
8363
|
+
end try
|
|
8364
|
+
try
|
|
8365
|
+
set ospid to (do shell script "echo $PPID")
|
|
8366
|
+
tell application "System Events" to set frontmost of (first process whose unix id is (ospid as integer)) to true
|
|
8367
|
+
end try
|
|
8368
|
+
try
|
|
8369
|
+
set D to (do shell script "printf %s $FEMO_DIALOG_DEFAULT_NAME | base64 -D")
|
|
8370
|
+
if (do shell script "printf %s $FEMO_DIALOG_HAS_DIR") is "1" then
|
|
8371
|
+
set P to POSIX file (do shell script "printf %s $FEMO_DIALOG_DIR | base64 -D")
|
|
8372
|
+
if M is "save" then
|
|
8373
|
+
set f to choose file name with prompt T default name D default location P
|
|
8374
|
+
else
|
|
8375
|
+
set f to choose file with prompt T default location P
|
|
8376
|
+
end if
|
|
8377
|
+
else
|
|
8378
|
+
if M is "save" then
|
|
8379
|
+
set f to choose file name with prompt T default name D
|
|
8380
|
+
else
|
|
8381
|
+
set f to choose file with prompt T
|
|
8382
|
+
end if
|
|
8383
|
+
end if
|
|
8384
|
+
do shell script "printf 'ok ' > " & quoted form of PO & " ; printf %s " & quoted form of (POSIX path of f) & " | base64 >> " & quoted form of PO
|
|
8385
|
+
return "ok"
|
|
8386
|
+
on error e number n
|
|
8387
|
+
if n is -128 then
|
|
8388
|
+
do shell script "printf cancel > " & quoted form of PO
|
|
8389
|
+
else
|
|
8390
|
+
do shell script "printf 'err ' > " & quoted form of PO & " ; printf %s " & quoted form of (((e as text) & " (" & (n as text) & ")")) & " | base64 >> " & quoted form of PO
|
|
8391
|
+
end if
|
|
8392
|
+
error e number n
|
|
8393
|
+
end try
|
|
8394
|
+
`;
|
|
8395
|
+
}
|
|
8253
8396
|
function dialogPinCs() {
|
|
8254
8397
|
const cs = [
|
|
8255
8398
|
"using System; using System.Runtime.InteropServices; using System.Text;",
|
|
@@ -8275,7 +8418,7 @@ function dialogPinCs() {
|
|
|
8275
8418
|
].join("\n");
|
|
8276
8419
|
return Buffer.from(cs, "utf8").toString("base64");
|
|
8277
8420
|
}
|
|
8278
|
-
async function
|
|
8421
|
+
async function pickFemoFileViaDialogWindows(opts) {
|
|
8279
8422
|
const { spawn: spawn2 } = await import("node:child_process");
|
|
8280
8423
|
const dialogType = opts.mode === "open" ? "OpenFileDialog" : "SaveFileDialog";
|
|
8281
8424
|
const defaultNameLine = opts.defaultName !== void 0 ? `$d.FileName = [Text.Encoding]::UTF8.GetString([Convert]::FromBase64String('${b64(String(opts.defaultName).replace(/\.femo$/i, ""))}')) + '.femo'` : void 0;
|