


























@@ -709,6 +709,102 @@ for channel in "${!SETUP_ENTRY_DEP_SENTINELS[@]}"; do
709709 fi
710710done
711711712+echo "Running packaged guided WhatsApp setup; runtime deps should be staged before finalize..."
713+OPENCLAW_PACKAGE_ROOT="$root" node --input-type=module - <<'NODE'
714+import path from "node:path";
715+import { readdir } from "node:fs/promises";
716+import { pathToFileURL } from "node:url";
717+718+const root = process.env.OPENCLAW_PACKAGE_ROOT;
719+if (!root) {
720+ throw new Error("missing OPENCLAW_PACKAGE_ROOT");
721+}
722+const distDir = path.join(root, "dist");
723+const onboardChannelFiles = (await readdir(distDir))
724+ .filter((entry) => /^onboard-channels-.*\.js$/.test(entry))
725+ .sort();
726+let setupChannels;
727+for (const entry of onboardChannelFiles) {
728+ const module = await import(pathToFileURL(path.join(distDir, entry)));
729+ if (typeof module.setupChannels === "function") {
730+ setupChannels = module.setupChannels;
731+ break;
732+ }
733+}
734+if (!setupChannels) {
735+ throw new Error(
736+ `could not find packaged setupChannels export in ${JSON.stringify(onboardChannelFiles)}`,
737+ );
738+}
739+740+let channelSelectCount = 0;
741+const notes = [];
742+const prompter = {
743+ intro: async () => {},
744+ outro: async () => {},
745+ note: async (body, title) => {
746+ notes.push({ title, body });
747+ },
748+ confirm: async ({ message, initialValue }) => {
749+ if (message === "Link WhatsApp now (QR)?") {
750+ return false;
751+ }
752+ return initialValue ?? true;
753+ },
754+ select: async ({ message }) => {
755+ if (message === "Select a channel") {
756+ channelSelectCount += 1;
757+ return channelSelectCount === 1 ? "whatsapp" : "__done__";
758+ }
759+ if (message === "WhatsApp phone setup") {
760+ return "separate";
761+ }
762+ if (message === "WhatsApp DM policy") {
763+ return "disabled";
764+ }
765+ throw new Error(`unexpected select prompt: ${message}`);
766+ },
767+ multiselect: async ({ message }) => {
768+ throw new Error(`unexpected multiselect prompt: ${message}`);
769+ },
770+ text: async ({ message }) => {
771+ throw new Error(`unexpected text prompt: ${message}`);
772+ },
773+};
774+const runtime = {
775+ log: (message) => console.log(message),
776+ error: (message) => console.error(message),
777+};
778+779+const result = await setupChannels(
780+ { plugins: { enabled: true } },
781+ runtime,
782+ prompter,
783+ {
784+ deferStatusUntilSelection: true,
785+ skipConfirm: true,
786+ skipStatusNote: true,
787+ skipDmPolicyPrompt: true,
788+ initialSelection: ["whatsapp"],
789+ },
790+);
791+792+if (!result.channels?.whatsapp) {
793+ throw new Error(`WhatsApp setup did not write channel config: ${JSON.stringify(result)}`);
794+}
795+console.log("packaged guided WhatsApp setup completed");
796+NODE
797+798+if [ -e "$root/dist/extensions/whatsapp/node_modules/@whiskeysockets/baileys/package.json" ]; then
799+ echo "expected guided WhatsApp setup deps to be installed externally, not into bundled plugin tree" >&2
800+ exit 1
801+fi
802+if ! find "$OPENCLAW_PLUGIN_STAGE_DIR" -maxdepth 12 -path "*/node_modules/@whiskeysockets/baileys/package.json" -type f | grep -q .; then
803+ echo "guided WhatsApp setup did not stage @whiskeysockets/baileys before finalize" >&2
804+ find "$OPENCLAW_PLUGIN_STAGE_DIR" -maxdepth 12 -type f | sort | head -160 >&2 || true
805+ exit 1
806+fi
807+712808echo "Configuring setup-entry channels; doctor should now install bundled runtime deps externally..."
713809node - <<'NODE'
714810const fs = require("node:fs");
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。