window.__ModuleLoader__.load({ id: "@xmanrui/dsh-im", factory: (require) => { var module = { exports: {} }; var exports = module.exports; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name2 in all) __defProp(target, name2, { get: all[name2], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // plugin-src/client/index.js var index_exports = {}; __export(index_exports, { IMSettingsTab: () => IMSettingsTab, apply: () => apply, inject: () => inject, name: () => name }); module.exports = __toCommonJS(index_exports); var React3 = __toESM(require("react"), 1); // plugin-src/client/channels/feishu/index.js var React = __toESM(require("react"), 1); // plugin-src/client/channels/feishu/api.js var FEISHU_RPC_CHANNEL = "/feishu"; var FEISHU_ENDPOINTS = Object.freeze({ status: "connection.status", beginProvisioning: "provision.begin", pollProvisioning: "provision.poll", cancelProvisioning: "provision.cancel", reconnectBot: "bot.reconnect", disconnectBot: "bot.disconnect", deleteBot: "bot.delete", // Kept for rolling upgrades. The multi-bot UI never calls these endpoints. testConnection: "connection.test", disconnect: "connection.disconnect" }); var CONNECTION_STATES = /* @__PURE__ */ new Set([ "disconnected", "offline", "provisioning", "connecting", "reconnecting", "connected", "error" ]); var POLL_STATES = /* @__PURE__ */ new Set([ "pending", "scanned", "connecting", "connected", "expired", "failed" ]); function isRecord(value) { return value !== null && typeof value === "object" && !Array.isArray(value); } function optionalString(value) { return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0; } function optionalTimestamp(value) { if (typeof value === "number" && Number.isFinite(value)) return value; if (typeof value === "string" && value.length > 0) { const parsed = Date.parse(value); return Number.isNaN(parsed) ? void 0 : parsed; } return void 0; } function clamp(value, min, max, fallback) { return typeof value === "number" && Number.isFinite(value) ? Math.min(max, Math.max(min, value)) : fallback; } function unwrapRpcResult(result) { if (!isRecord(result) || typeof result.ok !== "boolean") { throw new Error("\u98DE\u4E66\u670D\u52A1\u8FD4\u56DE\u4E86\u65E0\u6CD5\u8BC6\u522B\u7684\u54CD\u5E94"); } if (!result.ok) { const message = optionalString(result.error?.message) ?? "\u98DE\u4E66\u670D\u52A1\u8BF7\u6C42\u5931\u8D25"; const error = new Error(message); error.code = optionalString(result.error?.code) ?? "FEISHU_RPC_ERROR"; throw error; } return result.value; } function normalizeProvisioning(value, now = Date.now()) { const source = isRecord(value?.provisioning) ? value.provisioning : value; if (!isRecord(source)) throw new Error("\u98DE\u4E66\u670D\u52A1\u6CA1\u6709\u8FD4\u56DE\u4E8C\u7EF4\u7801\u4FE1\u606F"); const attemptId = optionalString(source.attemptId) ?? optionalString(source.provisioningId); const verificationUrl = optionalString(source.verificationUrl); const qrCodeDataUrl = optionalString(source.qrCodeDataUrl); if (!attemptId || !verificationUrl && !qrCodeDataUrl) { throw new Error("\u98DE\u4E66\u670D\u52A1\u8FD4\u56DE\u7684\u4E8C\u7EF4\u7801\u4FE1\u606F\u4E0D\u5B8C\u6574"); } const explicitExpiry = optionalTimestamp(source.expiresAt); const expireIn = clamp(source.expireIn, 1, 60 * 60, 5 * 60); return { attemptId, verificationUrl, qrCodeDataUrl, expiresAt: explicitExpiry ?? now + expireIn * 1e3, pollIntervalMs: clamp(source.pollIntervalMs, 800, 1e4, 1800) }; } function normalizeBot(value) { const source = isRecord(value) ? value : {}; return { name: optionalString(source.name) ?? "\u98DE\u4E66\u673A\u5668\u4EBA", avatarUrl: optionalString(source.avatarUrl), appIdMasked: optionalString(source.appIdMasked), tenantName: optionalString(source.tenantName), domain: source.domain === "lark" ? "lark" : "feishu", activated: typeof source.activated === "boolean" || typeof source.activated === "number" ? source.activated : void 0 }; } function normalizeHealth(value, connected = false) { const source = isRecord(value) ? value : {}; const fallbackStatus = connected ? "healthy" : "offline"; const status = ["healthy", "degraded", "offline", "checking"].includes(source.status) ? source.status : fallbackStatus; return { status, summary: optionalString(source.summary) ?? (connected ? "\u957F\u8FDE\u63A5\u8FD0\u884C\u6B63\u5E38" : "\u673A\u5668\u4EBA\u5C1A\u672A\u8FDE\u63A5"), lastCheckedAt: optionalTimestamp(source.lastCheckedAt), lastConnectedAt: optionalTimestamp(source.lastConnectedAt) }; } function normalizeError(value) { if (!isRecord(value)) return void 0; const message = optionalString(value.message); if (!message) return void 0; return { message, code: optionalString(value.code) }; } function authoritativeState(value, connected) { if (connected) return "connected"; const reported = CONNECTION_STATES.has(value) ? value : "disconnected"; if (reported === "connected" || reported === "connecting" || reported === "reconnecting") { return "connecting"; } if (reported === "error") return "error"; return "offline"; } function normalizeBotConnection(value, fallbackBotId) { if (!isRecord(value)) throw new Error("\u98DE\u4E66\u670D\u52A1\u8FD4\u56DE\u4E86\u65E0\u6548\u7684\u673A\u5668\u4EBA\u72B6\u6001"); const botId = optionalString(value.botId) ?? optionalString(fallbackBotId); if (!botId) throw new Error("\u98DE\u4E66\u670D\u52A1\u8FD4\u56DE\u7684\u673A\u5668\u4EBA\u7F3A\u5C11 botId"); const connected = value.connected === true; return { botId, state: authoritativeState(value.state, connected), connected, configured: value.configured !== false, bot: normalizeBot(value.bot), health: normalizeHealth(value.health, connected), error: normalizeError(value.error) }; } function normalizeBotsSnapshot(value) { if (!isRecord(value)) throw new Error("\u98DE\u4E66\u670D\u52A1\u6CA1\u6709\u8FD4\u56DE\u8FDE\u63A5\u72B6\u6001"); let sourceBots = Array.isArray(value.bots) ? value.bots : []; if (sourceBots.length === 0 && value.configured === true) { sourceBots = [{ botId: optionalString(value.botId) ?? "legacy-default", state: value.state, connected: value.connected, configured: true, bot: value.bot, health: value.health, error: value.error }]; } const seen = /* @__PURE__ */ new Set(); const bots = []; for (const source of sourceBots) { const bot = normalizeBotConnection(source); if (seen.has(bot.botId)) continue; seen.add(bot.botId); bots.push(bot); } const configured = bots.filter((bot) => bot.configured).length; const connected = bots.filter((bot) => bot.connected).length; const revision = Number.isSafeInteger(value.revision) && value.revision >= 0 ? value.revision : 0; const state = CONNECTION_STATES.has(value.state) ? value.state : "disconnected"; return { schemaVersion: value.schemaVersion === 2 ? 2 : 1, revision, state, bots, // Derive counts from the authoritative list so stale summary fields never // make the UI claim that an unavailable bot is online. totals: { configured, connected }, provisioning: value.provisioning ? normalizeProvisioning(value.provisioning) : void 0, error: normalizeError(value.error) }; } function normalizeConnectionSnapshot(value) { if (!isRecord(value)) throw new Error("\u98DE\u4E66\u670D\u52A1\u6CA1\u6709\u8FD4\u56DE\u8FDE\u63A5\u72B6\u6001"); const connected = value.connected === true; const reportedState = CONNECTION_STATES.has(value.state) ? value.state : "disconnected"; const state = connected ? "connected" : reportedState === "connected" ? "connecting" : reportedState; const snapshot = { state, configured: value.configured === true, bot: normalizeBot(value.bot), health: normalizeHealth(value.health, connected), provisioning: void 0, errorMessage: optionalString(value.error?.message) ?? optionalString(value.message) }; if (value.provisioning) snapshot.provisioning = normalizeProvisioning(value.provisioning); return snapshot; } function normalizePollResult(value) { if (!isRecord(value)) throw new Error("\u98DE\u4E66\u670D\u52A1\u6CA1\u6709\u8FD4\u56DE\u521B\u5EFA\u8FDB\u5EA6"); const status = POLL_STATES.has(value.status) ? value.status : POLL_STATES.has(value.state) ? value.state : void 0; if (!status) throw new Error("\u98DE\u4E66\u670D\u52A1\u8FD4\u56DE\u4E86\u672A\u77E5\u7684\u521B\u5EFA\u72B6\u6001"); const normalized = { status, botId: optionalString(value.botId), message: optionalString(value.error?.message) ?? optionalString(value.message), connection: void 0, provisioning: void 0 }; if (value.provisioning) normalized.provisioning = normalizeProvisioning(value.provisioning); if (status === "connected" && isRecord(value.connection)) { normalized.connection = value.connection.botId ? normalizeBotConnection(value.connection) : normalizeConnectionSnapshot(value.connection); } return normalized; } function presentError(error) { const raw = optionalString(error?.message) ?? "\u64CD\u4F5C\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5"; const message = raw.replace(/(client[_-]?secret|app[_-]?secret|secret|token)\s*[:=]\s*[^\s,;]+/gi, "$1=\u2022\u2022\u2022\u2022\u2022\u2022").slice(0, 240); return { message, code: optionalString(error?.code) }; } function formatRemaining(milliseconds) { const totalSeconds = Math.max(0, Math.ceil(milliseconds / 1e3)); const minutes = Math.floor(totalSeconds / 60); const seconds = totalSeconds % 60; return `${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}`; } // plugin-src/client/channels/feishu/styles.js var FEISHU_STYLE_ID = "beihuixinghe-dsh-feishu-settings"; var CSS = String.raw` .bxf-page { --bxf-accent: var(--dsw-alias-state-business-primary, #3370ff); --bxf-success: var(--dsw-alias-state-success-primary, #20a162); --bxf-warning: var(--dsw-alias-state-warning-primary, #d97706); --bxf-error: var(--dsw-alias-state-error-primary, #d54941); box-sizing: border-box; width: 100%; max-width: 860px; color: var(--dsw-alias-label-primary, #1f2329); display: flex; flex-direction: column; container-type: inline-size; gap: 18px; padding: 2px 0 24px; } .bxf-page *, .bxf-page *::before, .bxf-page *::after { box-sizing: border-box; } .bxf-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; } .bxf-headingCopy { min-width: 0; } .bxf-heading h2, .bxf-heading p, .bxf-card h3, .bxf-card p { margin: 0; } .bxf-eyebrow { color: var(--dsw-alias-label-tertiary, #8f959e); font-size: 12px; font-weight: 600; line-height: 18px; letter-spacing: .08em; text-transform: uppercase; margin-bottom: 3px; } .bxf-heading h2 { font-size: 20px; line-height: 28px; font-weight: 650; letter-spacing: -.015em; } .bxf-heading p { max-width: 540px; color: var(--dsw-alias-label-secondary, #646a73); font-size: 13px; line-height: 20px; margin-top: 5px; white-space: nowrap; } .bxf-headingTools { flex: none; display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 8px; } .bxf-totalBadge { min-height: 28px; display: inline-flex; align-items: baseline; gap: 3px; border-radius: 999px; padding: 4px 10px; color: var(--dsw-alias-label-secondary, #646a73); background: var(--dsw-alias-bg-module-platform, #f2f3f5); font-size: 11px; line-height: 16px; white-space: nowrap; } .bxf-totalBadge strong { color: var(--bxf-success); font-size: 13px; } .bxf-localBadge { flex: none; display: inline-flex; align-items: center; gap: 6px; min-height: 28px; border: 1px solid var(--dsw-alias-border-l2, #dee0e3); border-radius: 999px; padding: 4px 10px; color: var(--dsw-alias-label-secondary, #646a73); background: var(--dsw-alias-bg-layer-1, #fff); font-size: 11px; line-height: 16px; white-space: nowrap; } .bxf-card { position: relative; overflow: hidden; border: 1px solid var(--dsw-alias-border-l2, #dee0e3); border-radius: 14px; background: var(--dsw-alias-bg-layer-3, #fff); box-shadow: var(--dsw-shadow-lv1, 0 3px 12px rgba(31, 35, 41, .05)); } .bxf-card::before { content: ""; pointer-events: none; position: absolute; inset: 0 0 auto; height: 88px; background: radial-gradient(circle at 86% -35%, color-mix(in srgb, var(--bxf-accent) 18%, transparent), transparent 68%); opacity: .85; } .bxf-cardBody { position: relative; padding: 24px; } .bxf-intro { min-height: 250px; display: grid; grid-template-columns: minmax(0, 1fr) 172px; gap: 32px; align-items: center; } .bxf-introCopy { max-width: 500px; } .bxf-stateLabel { display: inline-flex; align-items: center; gap: 7px; color: var(--dsw-alias-label-secondary, #646a73); font-size: 12px; font-weight: 600; line-height: 18px; margin-bottom: 13px; } .bxf-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--dsw-alias-label-tertiary, #8f959e); box-shadow: 0 0 0 4px color-mix(in srgb, var(--dsw-alias-label-tertiary, #8f959e) 12%, transparent); } .bxf-dot[data-tone="success"] { background: var(--bxf-success); box-shadow: 0 0 0 4px color-mix(in srgb, var(--bxf-success) 13%, transparent); } .bxf-dot[data-tone="warning"] { background: var(--bxf-warning); box-shadow: 0 0 0 4px color-mix(in srgb, var(--bxf-warning) 13%, transparent); } .bxf-dot[data-tone="error"] { background: var(--bxf-error); box-shadow: 0 0 0 4px color-mix(in srgb, var(--bxf-error) 13%, transparent); } .bxf-intro h3 { font-size: 24px; line-height: 34px; font-weight: 650; letter-spacing: -.02em; } .bxf-introCopy > p { max-width: 490px; color: var(--dsw-alias-label-secondary, #646a73); font-size: 14px; line-height: 23px; margin-top: 8px; } .bxf-note { display: flex; gap: 8px; align-items: flex-start; color: var(--dsw-alias-label-tertiary, #8f959e); font-size: 12px; line-height: 18px; margin-top: 16px; } .bxf-note svg { flex: none; margin-top: 1px; } .bxf-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-top: 22px; } .bxf-button { appearance: none; min-height: 36px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; border: 1px solid var(--dsw-alias-border-l2, #dee0e3); border-radius: 8px; padding: 7px 13px; color: var(--dsw-alias-label-primary, #1f2329); background: var(--dsw-alias-bg-layer-1, #fff); font: inherit; font-size: 13px; font-weight: 550; line-height: 20px; text-decoration: none; cursor: pointer; transition: background .15s var(--ds-ease-in-out, ease), border-color .15s var(--ds-ease-in-out, ease), transform .15s var(--ds-ease-in-out, ease); } .bxf-button:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover, #f2f3f5); border-color: var(--dsw-alias-border-l1, #c9cdd4); } .bxf-button:active:not(:disabled) { transform: translateY(1px); } .bxf-button:focus-visible, .bxf-link:focus-visible { outline: 2px solid var(--bxf-accent); outline-offset: 2px; } .bxf-button:disabled { cursor: not-allowed; opacity: .55; } .bxf-button[data-kind="primary"] { border-color: var(--bxf-accent); color: #fff; background: var(--bxf-accent); box-shadow: 0 4px 12px color-mix(in srgb, var(--bxf-accent) 24%, transparent); } .bxf-button[data-kind="primary"]:hover:not(:disabled) { border-color: color-mix(in srgb, var(--bxf-accent) 86%, #000); background: color-mix(in srgb, var(--bxf-accent) 90%, #000); } .bxf-button[data-kind="danger"] { color: var(--bxf-error); } .bxf-button[data-size="small"] { min-height: 32px; padding: 5px 10px; font-size: 12px; } .bxf-provisionCard { border-color: color-mix(in srgb, var(--bxf-accent) 32%, var(--dsw-alias-border-l2, #dee0e3)); } .bxf-markStage { position: relative; width: 156px; height: 156px; display: grid; place-items: center; justify-self: end; } .bxf-markStage::before, .bxf-markStage::after { content: ""; position: absolute; border-radius: 50%; } .bxf-markStage::before { inset: 12px; border: 1px solid color-mix(in srgb, var(--bxf-accent) 18%, var(--dsw-alias-border-l2, #dee0e3)); background: color-mix(in srgb, var(--bxf-accent) 4%, var(--dsw-alias-bg-layer-1, #fff)); } .bxf-markStage::after { inset: 0; border: 1px dashed color-mix(in srgb, var(--bxf-accent) 16%, transparent); animation: bxf-rotate 18s linear infinite; } .bxf-brandMark { position: relative; z-index: 1; width: 68px; height: 68px; display: grid; place-items: center; border-radius: 20px; color: #fff; background: var(--bxf-accent); box-shadow: 0 12px 28px color-mix(in srgb, var(--bxf-accent) 28%, transparent); } .bxf-qrLayout { display: grid; grid-template-columns: 236px minmax(0, 1fr); align-items: center; gap: 32px; } .bxf-qrColumn { min-width: 0; } .bxf-qrFrame { position: relative; width: 222px; height: 222px; display: grid; place-items: center; border: 1px solid var(--dsw-alias-border-l2, #dee0e3); border-radius: 14px; padding: 13px; background: #fff; box-shadow: 0 8px 24px rgba(31, 35, 41, .07); } .bxf-qrFrame::before, .bxf-qrFrame::after { content: ""; position: absolute; width: 24px; height: 24px; border-color: var(--bxf-accent); border-style: solid; } .bxf-qrFrame::before { inset: -3px auto auto -3px; border-width: 2px 0 0 2px; border-radius: 5px 0 0; } .bxf-qrFrame::after { inset: auto -3px -3px auto; border-width: 0 2px 2px 0; border-radius: 0 0 5px; } .bxf-qrFrame img { width: 100%; height: 100%; display: block; object-fit: contain; } .bxf-qrFallback { width: 100%; height: 100%; display: grid; place-items: center; border-radius: 8px; color: var(--bxf-accent); background: #f7f9ff; text-align: center; padding: 20px; } .bxf-qrFallback span { display: block; color: #646a73; font-size: 12px; line-height: 18px; margin-top: 8px; } .bxf-expiredOverlay { position: absolute; inset: 10px; display: grid; place-items: center; border-radius: 9px; color: #1f2329; background: rgba(255, 255, 255, .94); backdrop-filter: blur(3px); font-size: 13px; font-weight: 600; text-align: center; } .bxf-countdown { width: 222px; color: var(--dsw-alias-label-tertiary, #8f959e); font-variant-numeric: tabular-nums; font-size: 11px; line-height: 17px; margin-top: 11px; } .bxf-countdownTop { display: flex; align-items: center; justify-content: space-between; gap: 10px; } .bxf-progress { height: 3px; overflow: hidden; border-radius: 99px; background: var(--dsw-alias-bg-module-platform, #f2f3f5); margin-top: 6px; } .bxf-progress > span { display: block; width: var(--bxf-progress, 100%); height: 100%; border-radius: inherit; background: var(--bxf-accent); transition: width 1s linear; } .bxf-qrCopy h3 { font-size: 20px; line-height: 29px; font-weight: 650; } .bxf-qrCopy > p { color: var(--dsw-alias-label-secondary, #646a73); font-size: 13px; line-height: 21px; margin-top: 7px; } .bxf-steps { counter-reset: bxf-step; display: flex; flex-direction: column; gap: 11px; margin: 20px 0 0; padding: 0; list-style: none; } .bxf-steps li { counter-increment: bxf-step; display: grid; grid-template-columns: 23px minmax(0, 1fr); align-items: start; gap: 9px; color: var(--dsw-alias-label-secondary, #646a73); font-size: 12px; line-height: 19px; } .bxf-steps li::before { content: counter(bxf-step); width: 21px; height: 21px; display: grid; place-items: center; border: 1px solid var(--dsw-alias-border-l2, #dee0e3); border-radius: 50%; color: var(--dsw-alias-label-primary, #1f2329); background: var(--dsw-alias-bg-layer-1, #fff); font-size: 10px; font-weight: 650; } .bxf-connecting { min-height: 292px; display: grid; place-items: center; text-align: center; padding: 36px 24px; } .bxf-connectingCopy { max-width: 430px; } .bxf-orbit { position: relative; width: 86px; height: 86px; display: grid; place-items: center; margin: 0 auto 22px; } .bxf-orbit::before, .bxf-orbit::after { content: ""; position: absolute; border-radius: 50%; } .bxf-orbit::before { inset: 3px; border: 1px solid color-mix(in srgb, var(--bxf-accent) 24%, transparent); animation: bxf-pulse 1.8s var(--ds-ease-in-out, ease) infinite; } .bxf-orbit::after { inset: 0; border: 2px solid transparent; border-top-color: var(--bxf-accent); animation: bxf-rotate 1.2s linear infinite; } .bxf-orbitCore { width: 50px; height: 50px; display: grid; place-items: center; border-radius: 16px; color: var(--bxf-accent); background: color-mix(in srgb, var(--bxf-accent) 9%, var(--dsw-alias-bg-layer-1, #fff)); } .bxf-connecting h3 { font-size: 20px; line-height: 29px; } .bxf-connecting p { color: var(--dsw-alias-label-secondary, #646a73); font-size: 13px; line-height: 21px; margin-top: 7px; } .bxf-connectingCompact { min-height: 248px; } .bxf-inlineError { min-height: 190px; display: grid; grid-template-columns: 44px minmax(0, 1fr); align-content: center; gap: 15px; padding: 28px; } .bxf-inlineError h3 { font-size: 17px; line-height: 25px; margin: 0; } .bxf-inlineError p { color: var(--dsw-alias-label-secondary, #646a73); font-size: 13px; line-height: 21px; margin-top: 5px; overflow-wrap: anywhere; } .bxf-listSection { display: flex; flex-direction: column; gap: 10px; } .bxf-listHeading { min-height: 28px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 0 2px; } .bxf-listHeading h3 { font-size: 14px; line-height: 22px; font-weight: 650; margin: 0; } .bxf-listHeading span { color: var(--dsw-alias-label-tertiary, #8f959e); font-size: 12px; } .bxf-botList { display: flex; flex-direction: column; gap: 12px; margin: 0; padding: 0; list-style: none; } .bxf-botList > li { min-width: 0; } .bxf-botCard:focus { outline: none; } .bxf-botCard:focus-visible { outline: 2px solid var(--bxf-accent); outline-offset: 2px; } .bxf-connectedTop { display: flex; align-items: center; justify-content: space-between; gap: 20px; } .bxf-botIdentity { min-width: 0; display: flex; align-items: center; gap: 13px; } .bxf-avatar { flex: none; width: 48px; height: 48px; display: grid; place-items: center; overflow: hidden; border-radius: 14px; color: var(--bxf-accent); background: color-mix(in srgb, var(--bxf-accent) 9%, var(--dsw-alias-bg-layer-1, #fff)); } .bxf-avatar img { width: 100%; height: 100%; object-fit: cover; } .bxf-botName { min-width: 0; } .bxf-botName h3 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 17px; line-height: 24px; font-weight: 650; } .bxf-botName p { color: var(--dsw-alias-label-tertiary, #8f959e); font-size: 12px; line-height: 18px; margin-top: 2px; } .bxf-healthPill { flex: none; display: inline-flex; align-items: center; gap: 7px; min-height: 28px; border-radius: 999px; padding: 4px 10px; color: var(--bxf-success); background: color-mix(in srgb, var(--bxf-success) 10%, transparent); font-size: 12px; font-weight: 600; line-height: 18px; } .bxf-healthPill[data-health="degraded"], .bxf-healthPill[data-health="checking"], .bxf-healthPill[data-health="connecting"] { color: var(--bxf-warning); background: color-mix(in srgb, var(--bxf-warning) 10%, transparent); } .bxf-healthPill[data-health="offline"], .bxf-healthPill[data-health="error"] { color: var(--bxf-error); background: color-mix(in srgb, var(--bxf-error) 10%, transparent); } .bxf-statusGrid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 22px; } .bxf-metric { min-width: 0; border: 1px solid var(--dsw-alias-border-l2, #dee0e3); border-radius: 9px; padding: 12px 13px; background: var(--dsw-alias-bg-module-platform, #f7f8fa); } .bxf-metric dt { color: var(--dsw-alias-label-tertiary, #8f959e); font-size: 11px; line-height: 17px; } .bxf-metric dd { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--dsw-alias-label-primary, #1f2329); font-size: 12px; line-height: 18px; font-weight: 550; margin: 3px 0 0; } .bxf-divider { height: 1px; background: var(--dsw-alias-border-l2, #dee0e3); margin: 22px 0 0; } .bxf-connectedFooter { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 17px; } .bxf-healthSummary { min-width: 0; color: var(--dsw-alias-label-secondary, #646a73); font-size: 12px; line-height: 18px; } .bxf-healthSummary strong { color: var(--dsw-alias-label-primary, #1f2329); font-weight: 600; } .bxf-healthSummary[data-error="true"] { color: var(--bxf-error); } .bxf-botActions { margin-top: 0; justify-content: flex-end; } .bxf-confirm { border-top: 1px solid var(--dsw-alias-border-l2, #dee0e3); background: color-mix(in srgb, var(--bxf-error) 4%, var(--dsw-alias-bg-module-platform, #f7f8fa)); padding: 17px 24px 20px; } .bxf-confirm:focus { outline: none; } .bxf-confirm h4 { font-size: 13px; line-height: 20px; margin: 0; } .bxf-confirm p { color: var(--dsw-alias-label-secondary, #646a73); font-size: 12px; line-height: 19px; margin: 4px 0 0; } .bxf-confirm .bxf-actions { margin-top: 12px; } .bxf-error { min-height: 252px; display: grid; grid-template-columns: 44px minmax(0, 1fr); align-content: center; gap: 15px; padding: 30px; } .bxf-errorIcon { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 13px; color: var(--bxf-error); background: color-mix(in srgb, var(--bxf-error) 9%, transparent); } .bxf-error h3 { font-size: 17px; line-height: 25px; } .bxf-error p { color: var(--dsw-alias-label-secondary, #646a73); font-size: 13px; line-height: 21px; margin-top: 5px; overflow-wrap: anywhere; } .bxf-errorCode { display: inline-block; color: var(--dsw-alias-label-tertiary, #8f959e); font-family: var(--ds-font-family-code, monospace); font-size: 11px; margin-top: 7px; } .bxf-statusNotice { display: flex; align-items: center; gap: 9px; border: 1px solid color-mix(in srgb, var(--bxf-warning) 28%, var(--dsw-alias-border-l2, #dee0e3)); border-radius: 10px; padding: 9px 11px; color: var(--dsw-alias-label-secondary, #646a73); background: color-mix(in srgb, var(--bxf-warning) 5%, var(--dsw-alias-bg-layer-1, #fff)); font-size: 12px; line-height: 18px; } .bxf-statusNotice > svg { flex: none; color: var(--bxf-warning); } .bxf-statusNotice > span { min-width: 0; flex: 1; overflow-wrap: anywhere; } .bxf-skeleton { min-height: 260px; padding: 28px; } .bxf-skeletonLine { height: 12px; border-radius: 999px; background: linear-gradient(90deg, var(--dsw-alias-bg-module-platform, #f2f3f5), color-mix(in srgb, var(--dsw-alias-label-tertiary, #8f959e) 10%, transparent), var(--dsw-alias-bg-module-platform, #f2f3f5)); background-size: 220% 100%; animation: bxf-shimmer 1.5s linear infinite; } .bxf-skeletonLine:nth-child(1) { width: 92px; } .bxf-skeletonLine:nth-child(2) { width: 44%; height: 22px; margin-top: 23px; } .bxf-skeletonLine:nth-child(3) { width: 72%; margin-top: 14px; } .bxf-skeletonLine:nth-child(4) { width: 58%; margin-top: 9px; } .bxf-skeletonBox { width: 138px; height: 38px; border-radius: 8px; background: var(--dsw-alias-bg-module-platform, #f2f3f5); margin-top: 28px; } .bxf-visuallyHidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; } @keyframes bxf-rotate { to { transform: rotate(360deg); } } @keyframes bxf-pulse { 0%, 100% { transform: scale(.9); opacity: .45; } 50% { transform: scale(1.08); opacity: 1; } } @keyframes bxf-shimmer { to { background-position: -220% 0; } } @container (max-width: 620px) { .bxf-heading { flex-direction: column; gap: 10px; } .bxf-headingTools { width: 100%; justify-content: flex-start; } .bxf-headingTools .bxf-button { margin-left: auto; } } @media (max-width: 680px) { .bxf-heading { flex-direction: column; gap: 10px; } .bxf-headingTools { width: 100%; justify-content: flex-start; } .bxf-headingTools .bxf-button { margin-left: auto; } .bxf-intro { grid-template-columns: minmax(0, 1fr); } .bxf-markStage { display: none; } .bxf-qrLayout { grid-template-columns: minmax(0, 1fr); justify-items: center; } .bxf-qrCopy { width: 100%; } .bxf-statusGrid { grid-template-columns: minmax(0, 1fr); } .bxf-connectedTop, .bxf-connectedFooter { align-items: flex-start; flex-direction: column; } .bxf-botActions { width: 100%; justify-content: flex-start; } .bxf-botActions .bxf-button { min-height: 44px; } .bxf-inlineError { grid-template-columns: minmax(0, 1fr); padding: 20px; } .bxf-statusNotice { align-items: flex-start; flex-wrap: wrap; } .bxf-cardBody { padding: 20px; } } @media (prefers-reduced-motion: reduce) { .bxf-page *, .bxf-page *::before, .bxf-page *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; transition-duration: .01ms !important; } } `; function installFeishuStyles() { if (typeof document === "undefined") { return () => { }; } const existing = document.querySelector( `style[data-plugin-css="${FEISHU_STYLE_ID}"]` ); if (existing) { return () => { }; } const style = document.createElement("style"); style.dataset.plugin = "@xmanrui/dsh-feishu"; style.dataset.pluginCss = FEISHU_STYLE_ID; style.textContent = CSS; document.head.appendChild(style); return () => { style.remove(); }; } // plugin-src/client/channels/feishu/index.js var h = React.createElement; function SvgIcon({ children, size = 18, className, viewBox = "0 0 24 24" }) { return h("svg", { width: size, height: size, viewBox, fill: "none", xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true", focusable: "false", className }, children); } function ShieldIcon({ size = 18 }) { return h( SvgIcon, { size }, h("path", { d: "M12 3 5.5 5.8v5.1c0 4.25 2.72 7.87 6.5 9.1 3.78-1.23 6.5-4.85 6.5-9.1V5.8L12 3Z", stroke: "currentColor", strokeWidth: "1.7", strokeLinejoin: "round" }), h("path", { d: "m9.3 11.8 1.7 1.7 3.8-4", stroke: "currentColor", strokeWidth: "1.7", strokeLinecap: "round", strokeLinejoin: "round" }) ); } function RobotIcon({ size = 26 }) { return h( SvgIcon, { size }, h("rect", { x: "5", y: "7.5", width: "14", height: "11", rx: "4", stroke: "currentColor", strokeWidth: "1.7" }), h("path", { d: "M12 4.5v3M8.7 12h.01M15.3 12h.01M9.2 15.3c1.67 1.08 3.93 1.08 5.6 0M3.5 11.5v3M20.5 11.5v3", stroke: "currentColor", strokeWidth: "1.7", strokeLinecap: "round" }) ); } function SparkIcon({ size = 18 }) { return h( SvgIcon, { size }, h("path", { d: "M12 2.8c.75 3.67 2.7 5.62 6.4 6.4-3.7.77-5.65 2.72-6.4 6.4-.75-3.68-2.7-5.63-6.4-6.4 3.7-.78 5.65-2.73 6.4-6.4Z", stroke: "currentColor", strokeWidth: "1.55", strokeLinejoin: "round" }), h("path", { d: "M5.2 15.8c.35 1.7 1.28 2.63 3 3-1.72.36-2.65 1.29-3 3-.36-1.71-1.29-2.64-3-3 1.71-.37 2.64-1.3 3-3ZM18.7 2.7c.22 1.06.79 1.63 1.85 1.85-1.06.22-1.63.79-1.85 1.85-.22-1.06-.79-1.63-1.85-1.85 1.06-.22 1.63-.79 1.85-1.85Z", fill: "currentColor" }) ); } function PlusIcon({ size = 17 }) { return h(SvgIcon, { size }, h("path", { d: "M12 5v14M5 12h14", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round" })); } function RefreshIcon({ size = 16 }) { return h(SvgIcon, { size }, h("path", { d: "M19 7.5V4m0 0h-3.5M19 4l-2.1 2.1A7 7 0 1 0 19 13", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round", strokeLinejoin: "round" })); } function ExternalIcon({ size = 15 }) { return h(SvgIcon, { size }, h("path", { d: "M13 5h6v6M19 5l-8.5 8.5M18 13.5V18a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h4.5", stroke: "currentColor", strokeWidth: "1.7", strokeLinecap: "round", strokeLinejoin: "round" })); } function AlertIcon({ size = 22 }) { return h( SvgIcon, { size }, h("path", { d: "M12 3.4 21 19H3L12 3.4Z", stroke: "currentColor", strokeWidth: "1.7", strokeLinejoin: "round" }), h("path", { d: "M12 9v4.4M12 16.6v.01", stroke: "currentColor", strokeWidth: "1.9", strokeLinecap: "round" }) ); } function QrIcon({ size = 58 }) { return h(SvgIcon, { size }, h("path", { d: "M4 4h6v6H4V4Zm10 0h6v6h-6V4ZM4 14h6v6H4v-6Zm10 0h2v2h-2v-2Zm4 0h2v4h-2v-4Zm-4 4h4v2h-4v-2Z", fill: "currentColor" })); } var Button = React.forwardRef(function Button2({ children, kind = "secondary", size, icon, className = "", ...props }, ref) { return h("button", { ...props, ref, type: "button", className: `bxf-button ${className}`.trim(), "data-kind": kind, "data-size": size }, icon, h("span", null, children)); }); function BrandMark({ compact = false }) { return h( "div", { className: compact ? "bxf-avatar" : "bxf-brandMark" }, h(RobotIcon, { size: compact ? 25 : 34 }) ); } function Heading({ totals, onAdd, adding, busy, addButtonRef }) { const hasBots = totals.configured > 0; return h( "div", { className: "bxf-heading" }, h( "div", { className: "bxf-headingTools" }, hasBots ? h("div", { className: "bxf-totalBadge", "aria-label": `\u5DF2\u63A5\u5165 ${totals.configured} \u4E2A\u673A\u5668\u4EBA\uFF0C\u5176\u4E2D ${totals.connected} \u4E2A\u5728\u7EBF` }, h("strong", null, totals.connected), h("span", null, `/ ${totals.configured} \u5728\u7EBF`)) : null, h("div", { className: "bxf-localBadge", title: "\u6BCF\u4E2A\u5E94\u7528\u7684\u51ED\u636E\u5747\u7531 Host \u72EC\u7ACB\u4FDD\u5B58\uFF0C\u4E0D\u4F1A\u53D1\u9001\u5230\u6D4F\u89C8\u5668" }, h(ShieldIcon, { size: 14 }), h("span", null, "\u51ED\u636E\u4EC5\u4FDD\u5B58\u5728\u672C\u673A")), h(Button, { kind: "primary", size: "small", icon: h(PlusIcon), onClick: onAdd, disabled: adding || busy, ref: addButtonRef, "aria-busy": busy ? "true" : void 0 }, adding ? "\u6B63\u5728\u6DFB\u52A0" : "\u6DFB\u52A0\u673A\u5668\u4EBA") ) ); } function LoadingView() { return h("div", { className: "bxf-card", "aria-busy": "true", "aria-label": "\u6B63\u5728\u8BFB\u53D6\u98DE\u4E66\u673A\u5668\u4EBA\u5217\u8868" }, h( "div", { className: "bxf-skeleton" }, h("div", { className: "bxf-skeletonLine" }), h("div", { className: "bxf-skeletonLine" }), h("div", { className: "bxf-skeletonLine" }), h("div", { className: "bxf-skeletonLine" }), h("div", { className: "bxf-skeletonBox" }) )); } function EmptyView({ onStart, busy }) { return h( "div", { className: "bxf-card" }, h( "div", { className: "bxf-cardBody bxf-intro" }, h( "div", { className: "bxf-introCopy" }, h( "div", { className: "bxf-stateLabel" }, h("span", { className: "bxf-dot" }), h("span", null, "\u5C1A\u672A\u63A5\u5165\u673A\u5668\u4EBA") ), h("h3", null, "\u626B\u7801\uFF0C\u521B\u5EFA\u7B2C\u4E00\u4E2A\u98DE\u4E66\u5165\u53E3"), h("p", null, "\u65E0\u9700\u624B\u52A8\u586B\u5199 App ID\u3002\u4EE5\u540E\u8FD8\u53EF\u4EE5\u7EE7\u7EED\u6DFB\u52A0\u673A\u5668\u4EBA\uFF0C\u5206\u522B\u670D\u52A1\u4E0D\u540C\u56E2\u961F\u6216\u98DE\u4E66\u79DF\u6237\u3002"), h( "div", { className: "bxf-actions" }, h(Button, { kind: "primary", icon: h(SparkIcon), onClick: onStart, disabled: busy, "aria-busy": busy ? "true" : void 0 }, busy ? "\u6B63\u5728\u521B\u5EFA\u2026" : "\u4E00\u952E\u521B\u5EFA\u98DE\u4E66\u673A\u5668\u4EBA") ), h( "div", { className: "bxf-note" }, h(ShieldIcon, { size: 16 }), h("span", null, "\u6BCF\u4E2A App Secret \u90FD\u53EA\u5199\u5165 Host \u51ED\u636E\u5B58\u50A8\uFF0C\u6D4F\u89C8\u5668\u4E0D\u4F1A\u6536\u5230 Secret\u3002") ) ), h("div", { className: "bxf-markStage", "aria-hidden": "true" }, h(BrandMark)) ) ); } function safeVerificationHref(value) { if (!value) return void 0; try { const url = new URL(value); return url.protocol === "https:" ? url.toString() : void 0; } catch { return void 0; } } function safeQrSource(value) { if (!value) return void 0; return /^data:image\/(?:png|webp|svg\+xml)(?:;charset=[^;,]+)?;base64,/i.test(value) ? value : void 0; } function QrPane({ provision, now, onRefresh, onCancel, busy }) { const [imageFailed, setImageFailed] = React.useState(false); const qrSource = safeQrSource(provision.qrCodeDataUrl); const href = safeVerificationHref(provision.verificationUrl); const remaining = Math.max(0, provision.expiresAt - now); const expired = provision.expired === true || remaining === 0; const progress = Math.min(1, remaining / Math.max(1, provision.durationMs ?? remaining)); React.useEffect(() => setImageFailed(false), [qrSource]); return h( "div", { className: "bxf-card bxf-provisionCard" }, h( "div", { className: "bxf-cardBody bxf-qrLayout" }, h( "div", { className: "bxf-qrColumn" }, h( "div", { className: "bxf-qrFrame" }, qrSource && !imageFailed ? h("img", { src: qrSource, alt: "\u7528\u4E8E\u65B0\u589E DeepSeek Harness \u98DE\u4E66\u673A\u5668\u4EBA\u7684\u4E00\u6B21\u6027\u6388\u6743\u4E8C\u7EF4\u7801", onError: () => setImageFailed(true) }) : h( "div", { className: "bxf-qrFallback" }, h("div", null, h(QrIcon), h("span", null, "\u4E8C\u7EF4\u7801\u672A\u5C31\u7EEA\uFF0C\u8BF7\u6253\u5F00\u6388\u6743\u94FE\u63A5")) ), expired ? h( "div", { className: "bxf-expiredOverlay", role: "status" }, h("div", null, "\u4E8C\u7EF4\u7801\u5DF2\u5931\u6548", h("br"), "\u8BF7\u5237\u65B0\u540E\u91CD\u65B0\u626B\u7801") ) : null ), h( "div", { className: "bxf-countdown", "aria-label": expired ? "\u4E8C\u7EF4\u7801\u5DF2\u5931\u6548" : `\u4E8C\u7EF4\u7801\u5269\u4F59 ${formatRemaining(remaining)}` }, h( "div", { className: "bxf-countdownTop", "aria-hidden": "true" }, h("span", null, expired ? "\u7B49\u5F85\u5237\u65B0" : "\u4E8C\u7EF4\u7801\u6709\u6548\u65F6\u95F4"), h("strong", null, formatRemaining(remaining)) ), h( "div", { className: "bxf-progress", "aria-hidden": "true" }, h("span", { style: { "--bxf-progress": `${Math.round(progress * 100)}%` } }) ) ) ), h( "div", { className: "bxf-qrCopy" }, h( "div", { className: "bxf-stateLabel" }, h("span", { className: "bxf-dot", "data-tone": "warning" }), h("span", null, "\u6B63\u5728\u6DFB\u52A0\u65B0\u673A\u5668\u4EBA") ), h("h3", null, expired ? "\u5237\u65B0\u4E8C\u7EF4\u7801\u540E\u7EE7\u7EED" : "\u4F7F\u7528\u98DE\u4E66\u626B\u7801\u521B\u5EFA\u673A\u5668\u4EBA"), h("p", null, "\u626B\u7801\u53EA\u4F1A\u65B0\u589E\u4E00\u4E2A\u673A\u5668\u4EBA\uFF0C\u5DF2\u63A5\u5165\u7684\u673A\u5668\u4EBA\u4F1A\u7EE7\u7EED\u6B63\u5E38\u6536\u53D1\u6D88\u606F\u3002"), h( "ol", { className: "bxf-steps" }, h("li", null, "\u6253\u5F00\u98DE\u4E66\u79FB\u52A8\u7AEF\uFF0C\u4F7F\u7528\u626B\u4E00\u626B\u8BFB\u53D6\u4E8C\u7EF4\u7801"), h("li", null, "\u6838\u5BF9\u5E94\u7528\u540D\u79F0\u4E0E\u6743\u9650\u8303\u56F4\uFF0C\u5E76\u786E\u8BA4\u521B\u5EFA"), h("li", null, "\u4FDD\u6301\u672C\u9875\u6253\u5F00\uFF0C\u7B49\u5F85\u65B0\u673A\u5668\u4EBA\u7684\u957F\u8FDE\u63A5\u5C31\u7EEA") ), h( "div", { className: "bxf-actions" }, expired ? h(Button, { kind: "primary", icon: h(RefreshIcon), onClick: onRefresh, disabled: busy }, busy ? "\u5237\u65B0\u4E2D\u2026" : "\u5237\u65B0\u4E8C\u7EF4\u7801") : href ? h("a", { className: "bxf-button bxf-link", "data-kind": "secondary", href, target: "_blank", rel: "noopener noreferrer" }, h(ExternalIcon), h("span", null, "\u5728\u98DE\u4E66\u4E2D\u6253\u5F00")) : null, !expired ? h(Button, { icon: h(RefreshIcon), onClick: onRefresh, disabled: busy }, "\u6362\u4E00\u4E2A\u4E8C\u7EF4\u7801") : null, h(Button, { onClick: onCancel, disabled: busy }, "\u53D6\u6D88\u6DFB\u52A0") ) ) ) ); } function ProvisionProgress({ phase, onCancel, busy }) { const connecting = phase === "connecting"; return h( "div", { className: "bxf-card bxf-provisionCard", "aria-busy": "true" }, h( "div", { className: "bxf-connecting bxf-connectingCompact" }, h( "div", { className: "bxf-connectingCopy" }, h( "div", { className: "bxf-orbit" }, h( "div", { className: "bxf-orbitCore" }, connecting ? h(RobotIcon, { size: 24 }) : h(SparkIcon, { size: 24 }) ) ), h("h3", null, connecting ? "\u5DF2\u786E\u8BA4\uFF0C\u6B63\u5728\u8FDE\u63A5\u65B0\u673A\u5668\u4EBA" : "\u6B63\u5728\u51C6\u5907\u6388\u6743\u4E8C\u7EF4\u7801"), h("p", null, connecting ? "\u6B63\u5728\u5B89\u5168\u4FDD\u5B58\u51ED\u636E\u5E76\u68C0\u67E5\u65B0\u673A\u5668\u4EBA\u7684\u6D88\u606F\u901A\u9053\uFF0C\u5176\u4ED6\u673A\u5668\u4EBA\u4E0D\u4F1A\u4E2D\u65AD\u3002" : "\u6B63\u5728\u5411\u98DE\u4E66\u7533\u8BF7\u4E00\u6B21\u6027\u6388\u6743\u4E8C\u7EF4\u7801\uFF0C\u8BF7\u7A0D\u5019\u3002"), connecting ? h( "div", { className: "bxf-actions", style: { justifyContent: "center" } }, h(Button, { onClick: onCancel, disabled: busy }, "\u53D6\u6D88\u6DFB\u52A0") ) : null ) ) ); } function ProvisionError({ error, onRetry, onCancel, busy }) { return h( "div", { className: "bxf-card bxf-provisionCard" }, h( "div", { className: "bxf-inlineError", role: "alert" }, h("div", { className: "bxf-errorIcon" }, h(AlertIcon)), h( "div", null, h("h3", null, "\u65B0\u673A\u5668\u4EBA\u6CA1\u6709\u6DFB\u52A0\u5B8C\u6210"), h("p", null, error.message), error.code ? h("span", { className: "bxf-errorCode" }, error.code) : null, h( "div", { className: "bxf-actions" }, h( Button, { kind: "primary", icon: h(RefreshIcon), onClick: onRetry, disabled: busy }, busy ? "\u91CD\u8BD5\u4E2D\u2026" : "\u91CD\u65B0\u751F\u6210\u4E8C\u7EF4\u7801" ), h(Button, { onClick: onCancel, disabled: busy }, "\u5173\u95ED") ) ) ) ); } var HEALTH_LABELS = { connected: "\u8FD0\u884C\u6B63\u5E38", connecting: "\u6B63\u5728\u8FDE\u63A5", offline: "\u8FDE\u63A5\u4E2D\u65AD", error: "\u9700\u8981\u5904\u7406" }; function formatCheckedTime(timestamp2) { if (!timestamp2) return "\u5C1A\u672A\u68C0\u67E5"; try { return new Intl.DateTimeFormat("zh-CN", { hour: "2-digit", minute: "2-digit", second: "2-digit" }).format(new Date(timestamp2)); } catch { return "\u521A\u521A"; } } function RemoveConfirmation({ bot, busy, onConfirm, onCancel }) { const cancelRef = React.useRef(null); const idPart = bot.botId.replace(/[^a-zA-Z0-9_-]/g, "-"); const titleId = `bxf-remove-title-${idPart}`; const descriptionId = `bxf-remove-description-${idPart}`; React.useEffect(() => cancelRef.current?.focus(), []); return h( "div", { className: "bxf-confirm", role: "alertdialog", "aria-labelledby": titleId, "aria-describedby": descriptionId, onKeyDown: (event) => { if (event.key === "Escape" && !busy) { event.preventDefault(); onCancel(); } } }, h("h4", { id: titleId }, `\u4ECE DeepSeek Harness \u79FB\u9664\u201C${bot.bot.name}\u201D\uFF1F`), h( "p", { id: descriptionId }, "\u6B64\u64CD\u4F5C\u4F1A\u505C\u6B62\u8FD9\u4E2A\u673A\u5668\u4EBA\u7684\u8FDE\u63A5\uFF0C\u5E76\u5220\u9664\u4FDD\u5B58\u5728\u672C\u673A\u7684\u63A5\u5165\u914D\u7F6E\u548C\u51ED\u636E\u3002\u98DE\u4E66\u5F00\u653E\u5E73\u53F0\u4E2D\u7684\u5E94\u7528\u4E0D\u4F1A\u88AB\u81EA\u52A8\u5220\u9664\uFF0C\u5176\u4ED6\u673A\u5668\u4EBA\u4E5F\u4E0D\u53D7\u5F71\u54CD\u3002" ), h( "div", { className: "bxf-actions" }, h(Button, { ref: cancelRef, onClick: onCancel, disabled: busy }, "\u4FDD\u7559\u673A\u5668\u4EBA"), h( Button, { kind: "danger", onClick: onConfirm, disabled: busy }, busy ? "\u6B63\u5728\u79FB\u9664\u2026" : "\u786E\u8BA4\u79FB\u9664\u63A5\u5165" ) ) ); } function BotCard({ connection, busy, actionError, removing, onReconnect, onRequestRemove, onConfirmRemove, onCancelRemove, cardRef, removeButtonRef }) { const { bot, health, state, connected } = connection; const stateForDisplay = busy === "reconnect" ? "connecting" : state; const tone = stateForDisplay === "connected" ? "success" : stateForDisplay === "connecting" ? "warning" : "error"; const summary = actionError?.message ?? connection.error?.message ?? health.summary; const titleId = `bxf-bot-${connection.botId.replace(/[^a-zA-Z0-9_-]/g, "-")}`; const domainLabel = bot.domain === "lark" ? "Lark" : "\u98DE\u4E66"; return h( "article", { className: "bxf-card bxf-botCard", "aria-labelledby": titleId, "data-bot-id": connection.botId, tabIndex: -1, ref: cardRef }, h( "div", { className: "bxf-cardBody" }, h( "div", { className: "bxf-connectedTop" }, h( "div", { className: "bxf-botIdentity" }, bot.avatarUrl ? h("div", { className: "bxf-avatar" }, h("img", { src: bot.avatarUrl, alt: "" })) : h(BrandMark, { compact: true }), h( "div", { className: "bxf-botName" }, h("h3", { id: titleId, title: bot.name }, bot.name), h("p", null, bot.tenantName ? `${bot.tenantName} \xB7 ${domainLabel}\u673A\u5668\u4EBA` : `${domainLabel}\u673A\u5668\u4EBA`) ) ), h( "div", { className: "bxf-healthPill", "data-health": stateForDisplay }, h("span", { className: "bxf-dot", "data-tone": tone }), h("span", null, HEALTH_LABELS[stateForDisplay] ?? "\u72B6\u6001\u672A\u77E5") ) ), h( "dl", { className: "bxf-statusGrid" }, h( "div", { className: "bxf-metric" }, h("dt", null, "\u6D88\u606F\u901A\u9053"), h("dd", null, connected ? "\u957F\u8FDE\u63A5" : stateForDisplay === "connecting" ? "\u8FDE\u63A5\u4E2D" : "\u5DF2\u65AD\u5F00") ), h( "div", { className: "bxf-metric" }, h("dt", null, "\u5E94\u7528\u6807\u8BC6"), h("dd", { title: bot.appIdMasked }, bot.appIdMasked ?? "\u5DF2\u5B89\u5168\u4FDD\u5B58") ), h( "div", { className: "bxf-metric" }, h("dt", null, "\u6700\u8FD1\u68C0\u67E5"), h("dd", null, formatCheckedTime(health.lastCheckedAt)) ) ), h("div", { className: "bxf-divider" }), h( "div", { className: "bxf-connectedFooter" }, h( "div", { className: "bxf-healthSummary", "data-error": actionError || connection.error ? "true" : void 0 }, h("strong", null, "\u8FDE\u63A5\u72B6\u6001\uFF1A"), h("span", null, summary) ), h( "div", { className: "bxf-actions bxf-botActions" }, h(Button, { size: "small", icon: h(RefreshIcon), onClick: onReconnect, disabled: Boolean(busy), "aria-busy": busy === "reconnect" ? "true" : void 0, "aria-label": `${connected ? "\u68C0\u67E5\u8FDE\u63A5" : "\u91CD\u8BD5\u8FDE\u63A5"}${bot.name}` }, busy === "reconnect" ? connected ? "\u68C0\u67E5\u4E2D\u2026" : "\u6B63\u5728\u8FDE\u63A5\u2026" : connected ? "\u68C0\u67E5\u8FDE\u63A5" : "\u91CD\u8BD5\u8FDE\u63A5"), h(Button, { size: "small", kind: "danger", onClick: onRequestRemove, disabled: Boolean(busy), ref: removeButtonRef, "aria-label": `\u4ECE DeepSeek Harness \u79FB\u9664${bot.name}` }, "\u79FB\u9664\u63A5\u5165") ) ) ), removing ? h(RemoveConfirmation, { bot: connection, busy: busy === "delete", onConfirm: onConfirmRemove, onCancel: onCancelRemove }) : null ); } function BotList(props) { return h( "section", { className: "bxf-listSection", "aria-labelledby": "bxf-bot-list-title" }, h( "div", { className: "bxf-listHeading" }, h("h3", { id: "bxf-bot-list-title" }, "\u5DF2\u63A5\u5165\u7684\u673A\u5668\u4EBA"), h("span", null, `${props.bots.length} \u4E2A`) ), h( "ul", { className: "bxf-botList", role: "list" }, props.bots.map((bot) => h( "li", { key: bot.botId }, h(BotCard, { connection: bot, busy: props.busyByBot[bot.botId], actionError: props.errorsByBot[bot.botId], removing: props.removeTargetId === bot.botId, onReconnect: () => props.onReconnect(bot), onRequestRemove: () => props.onRequestRemove(bot), onConfirmRemove: () => props.onConfirmRemove(bot), onCancelRemove: props.onCancelRemove, cardRef: (node) => props.setCardRef(bot.botId, node), removeButtonRef: (node) => props.setRemoveButtonRef(bot.botId, node) }) )) ) ); } function PageError({ error, onRetry, busy }) { return h( "div", { className: "bxf-card" }, h( "div", { className: "bxf-error", role: "alert" }, h("div", { className: "bxf-errorIcon" }, h(AlertIcon)), h( "div", null, h("h3", null, "\u65E0\u6CD5\u8BFB\u53D6\u98DE\u4E66\u673A\u5668\u4EBA"), h("p", null, error.message), error.code ? h("span", { className: "bxf-errorCode" }, error.code) : null, h( "div", { className: "bxf-actions" }, h( Button, { kind: "primary", icon: h(RefreshIcon), onClick: onRetry, disabled: busy }, busy ? "\u91CD\u8BD5\u4E2D\u2026" : "\u91CD\u65B0\u8BFB\u53D6" ) ) ) ) ); } var EMPTY_TOTALS = Object.freeze({ configured: 0, connected: 0 }); function FeishuSettingsTab({ rpcCall }) { const [model, setModel] = React.useState({ phase: "loading", revision: 0, bots: [], totals: EMPTY_TOTALS, provisioning: null, pageError: null, statusError: null }); const [pageBusy, setPageBusy] = React.useState(false); const [provisionBusy, setProvisionBusy] = React.useState(false); const [busyByBot, setBusyByBot] = React.useState({}); const [errorsByBot, setErrorsByBot] = React.useState({}); const [removeTargetId, setRemoveTargetId] = React.useState(null); const [announcement, setAnnouncement] = React.useState(""); const [now, setNow] = React.useState(() => Date.now()); const [focusBotId, setFocusBotId] = React.useState(null); const cardRefs = React.useRef(/* @__PURE__ */ new Map()); const removeButtonRefs = React.useRef(/* @__PURE__ */ new Map()); const addButtonRef = React.useRef(null); const announce = React.useCallback((message) => { setAnnouncement(""); if (!message) return; window.requestAnimationFrame(() => setAnnouncement(message)); }, []); const invoke = React.useCallback(async (endpoint, payload = {}, signal) => { return unwrapRpcResult(await rpcCall(endpoint, payload, signal)); }, [rpcCall]); const mergeSnapshot = React.useCallback((snapshot, { restoreProvisioning = true } = {}) => { setModel((current) => { if (snapshot.revision > 0 && current.revision > snapshot.revision) return current; let provisioning = current.provisioning; if (!provisioning && restoreProvisioning && snapshot.provisioning) { provisioning = { phase: snapshot.state === "connecting" ? "connecting" : "qr", ...snapshot.provisioning, durationMs: Math.max(1, snapshot.provisioning.expiresAt - Date.now()), expired: snapshot.provisioning.expiresAt <= Date.now() }; } return { ...current, phase: "ready", revision: snapshot.revision, bots: snapshot.bots, totals: snapshot.totals, provisioning, pageError: null, statusError: null }; }); }, []); const loadStatus = React.useCallback(async ({ signal, silent = false, restoreProvisioning = true } = {}) => { if (!silent) setPageBusy(true); try { const snapshot = normalizeBotsSnapshot(await invoke(FEISHU_ENDPOINTS.status, {}, signal)); mergeSnapshot(snapshot, { restoreProvisioning }); return snapshot; } catch (error) { if (error?.name === "AbortError") return void 0; const presented = presentError(error); setModel((current) => current.phase === "loading" || !silent ? { ...current, phase: "error", pageError: presented } : { ...current, statusError: presented }); return void 0; } finally { if (!silent) setPageBusy(false); } }, [invoke, mergeSnapshot]); React.useEffect(() => { const controller = new AbortController(); void loadStatus({ signal: controller.signal }); return () => controller.abort(); }, [loadStatus]); React.useEffect(() => { if (model.phase !== "ready") return void 0; const controller = new AbortController(); let inFlight = false; const timer = window.setInterval(async () => { if (inFlight) return; inFlight = true; await loadStatus({ signal: controller.signal, silent: true }); inFlight = false; }, 15e3); return () => { controller.abort(); window.clearInterval(timer); }; }, [loadStatus, model.phase]); React.useEffect(() => { if (!focusBotId) return; const node = cardRefs.current.get(focusBotId); if (!node) return; node.scrollIntoView?.({ block: "nearest", behavior: "smooth" }); node.focus({ preventScroll: true }); setFocusBotId(null); }, [focusBotId, model.bots]); const startProvisioning = React.useCallback(async ({ replace = false } = {}) => { setProvisionBusy(true); announce(""); const previousAttemptId = model.provisioning?.attemptId; setModel((current) => ({ ...current, phase: current.phase === "loading" ? "ready" : current.phase, provisioning: { phase: "creating" } })); try { if (replace && previousAttemptId) { await invoke(FEISHU_ENDPOINTS.cancelProvisioning, { attemptId: previousAttemptId }); } const provision2 = normalizeProvisioning(await invoke( FEISHU_ENDPOINTS.beginProvisioning, { locale: "zh-CN" } )); const timestamp2 = Date.now(); setNow(timestamp2); setModel((current) => ({ ...current, provisioning: { phase: "qr", ...provision2, durationMs: Math.max(1, provision2.expiresAt - timestamp2), expired: false } })); announce("\u6388\u6743\u4E8C\u7EF4\u7801\u5DF2\u751F\u6210\uFF0C\u8BF7\u4F7F\u7528\u98DE\u4E66\u626B\u7801\u3002"); } catch (error) { setModel((current) => ({ ...current, provisioning: { phase: "error", error: presentError(error) } })); } finally { setProvisionBusy(false); } }, [announce, invoke, model.provisioning?.attemptId]); const cancelProvisioning = React.useCallback(async () => { const attemptId = model.provisioning?.attemptId; setProvisionBusy(true); try { if (attemptId) await invoke(FEISHU_ENDPOINTS.cancelProvisioning, { attemptId }); setModel((current) => ({ ...current, provisioning: null })); announce("\u5DF2\u53D6\u6D88\u6DFB\u52A0\u673A\u5668\u4EBA\u3002"); await loadStatus({ silent: true, restoreProvisioning: false }); window.requestAnimationFrame(() => addButtonRef.current?.focus()); } catch (error) { setModel((current) => ({ ...current, provisioning: { phase: "error", attemptId, error: presentError(error) } })); } finally { setProvisionBusy(false); } }, [announce, invoke, loadStatus, model.provisioning?.attemptId]); React.useEffect(() => { const provision2 = model.provisioning; if (!provision2 || provision2.phase !== "qr" || provision2.expired) return void 0; const tick = () => { const timestamp2 = Date.now(); setNow(timestamp2); if (timestamp2 >= provision2.expiresAt) { setModel((current) => current.provisioning?.attemptId === provision2.attemptId ? { ...current, provisioning: { ...current.provisioning, expired: true } } : current); } }; tick(); const timer = window.setInterval(tick, 1e3); return () => window.clearInterval(timer); }, [model.provisioning]); React.useEffect(() => { const provision2 = model.provisioning; if (!provision2 || !["qr", "connecting"].includes(provision2.phase) || !provision2.attemptId || provision2.expired) return void 0; const controller = new AbortController(); const timer = window.setTimeout(async () => { try { const result = normalizePollResult(await invoke( FEISHU_ENDPOINTS.pollProvisioning, { attemptId: provision2.attemptId }, controller.signal )); if (result.status === "connected") { const snapshot = await loadStatus({ signal: controller.signal, silent: true, restoreProvisioning: false }); const newBot = snapshot?.bots.find((bot) => bot.botId === result.botId); if (!snapshot) { throw new Error("\u673A\u5668\u4EBA\u5DF2\u7ECF\u521B\u5EFA\uFF0C\u4F46\u6682\u65F6\u65E0\u6CD5\u786E\u8BA4\u8FDE\u63A5\u72B6\u6001"); } if (!newBot?.connected) { setModel((current) => current.provisioning?.attemptId === provision2.attemptId ? { ...current, provisioning: { ...current.provisioning, phase: "connecting" } } : current); return; } setModel((current) => ({ ...current, provisioning: null })); announce(newBot ? `${newBot.bot.name}\u5DF2\u8FDE\u63A5\uFF0C\u53EF\u4EE5\u5728\u98DE\u4E66\u4E2D\u5F00\u59CB\u804A\u5929\u3002` : "\u65B0\u98DE\u4E66\u673A\u5668\u4EBA\u5DF2\u8FDE\u63A5\uFF0C\u53EF\u4EE5\u5F00\u59CB\u804A\u5929\u3002"); if (result.botId) setFocusBotId(result.botId); return; } if (result.status === "failed") { const error = new Error(result.message ?? "\u98DE\u4E66\u5E94\u7528\u521B\u5EFA\u5931\u8D25"); error.code = "FEISHU_PROVISION_FAILED"; throw error; } if (result.status === "expired") { setModel((current) => current.provisioning?.attemptId === provision2.attemptId ? { ...current, provisioning: { ...current.provisioning, phase: "qr", expired: true } } : current); return; } setModel((current) => { if (current.provisioning?.attemptId !== provision2.attemptId) return current; const next = result.provisioning ?? current.provisioning; return { ...current, provisioning: { ...current.provisioning, ...next, phase: ["scanned", "connecting"].includes(result.status) ? "connecting" : "qr" } }; }); } catch (error) { if (error?.name === "AbortError") return; setModel((current) => current.provisioning?.attemptId === provision2.attemptId ? { ...current, provisioning: { phase: "error", attemptId: provision2.attemptId, error: presentError(error) } } : current); } }, provision2.pollIntervalMs); return () => { controller.abort(); window.clearTimeout(timer); }; }, [announce, invoke, loadStatus, model.provisioning]); const setBotBusy = React.useCallback((botId, value) => { setBusyByBot((current) => { const next = { ...current }; if (value) next[botId] = value; else delete next[botId]; return next; }); }, []); const setBotError = React.useCallback((botId, error) => { setErrorsByBot((current) => { const next = { ...current }; if (error) next[botId] = presentError(error); else delete next[botId]; return next; }); }, []); const reconnectOneBot = React.useCallback(async (connection) => { const { botId, bot } = connection; setBotBusy(botId, "reconnect"); setBotError(botId, null); try { const snapshot = normalizeBotsSnapshot(await invoke(FEISHU_ENDPOINTS.reconnectBot, { botId })); mergeSnapshot(snapshot); const refreshed = snapshot.bots.find((item) => item.botId === botId); if (!refreshed?.connected) { const error = new Error( refreshed?.error?.message ?? refreshed?.health.summary ?? "\u673A\u5668\u4EBA\u4ECD\u672A\u8FDE\u63A5" ); error.code = refreshed?.error?.code ?? "FEISHU_BOT_OFFLINE"; throw error; } announce(connection.connected ? `${bot.name}\u8FDE\u63A5\u68C0\u67E5\u5B8C\u6210\u3002` : `${bot.name}\u5DF2\u91CD\u65B0\u8FDE\u63A5\u3002`); } catch (error) { setBotError(botId, error); announce(`${bot.name}\u64CD\u4F5C\u5931\u8D25\uFF0C\u8BF7\u67E5\u770B\u673A\u5668\u4EBA\u72B6\u6001\u3002`); } finally { setBotBusy(botId, null); } }, [announce, invoke, mergeSnapshot, setBotBusy, setBotError]); const requestRemove = React.useCallback((connection) => { setRemoveTargetId(connection.botId); }, []); const cancelRemove = React.useCallback(() => { const botId = removeTargetId; setRemoveTargetId(null); window.requestAnimationFrame(() => removeButtonRefs.current.get(botId)?.focus()); }, [removeTargetId]); const confirmRemove = React.useCallback(async (connection) => { const { botId, bot } = connection; setBotBusy(botId, "delete"); setBotError(botId, null); try { await invoke(FEISHU_ENDPOINTS.deleteBot, { botId, confirm: true }); setRemoveTargetId(null); setModel((current) => { const bots = current.bots.filter((item) => item.botId !== botId); return { ...current, bots, totals: { configured: bots.length, connected: bots.filter((item) => item.connected).length } }; }); announce(`${bot.name}\u5DF2\u4ECE\u6B64 DeepSeek Harness \u79FB\u9664\uFF1B\u98DE\u4E66\u5F00\u653E\u5E73\u53F0\u4E2D\u7684\u5E94\u7528\u672A\u88AB\u5220\u9664\u3002`); await loadStatus({ silent: true }); window.requestAnimationFrame(() => addButtonRef.current?.focus()); } catch (error) { setBotError(botId, error); announce(`${bot.name}\u79FB\u9664\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5\u3002`); } finally { setBotBusy(botId, null); } }, [announce, invoke, loadStatus, setBotBusy, setBotError]); const provision = model.provisioning; let provisionContent = null; if (provision?.phase === "creating") { provisionContent = h(ProvisionProgress, { phase: "creating", busy: provisionBusy }); } else if (provision?.phase === "qr") { provisionContent = h(QrPane, { provision, now, onRefresh: () => void startProvisioning({ replace: true }), onCancel: () => void cancelProvisioning(), busy: provisionBusy || model.phase !== "ready" }); } else if (provision?.phase === "connecting") { provisionContent = h(ProvisionProgress, { phase: "connecting", onCancel: () => void cancelProvisioning(), busy: provisionBusy }); } else if (provision?.phase === "error") { provisionContent = h(ProvisionError, { error: provision.error, onRetry: () => void startProvisioning({ replace: Boolean(provision.attemptId) }), onCancel: () => void cancelProvisioning(), busy: provisionBusy }); } const setCardRef = React.useCallback((botId, node) => { if (node) cardRefs.current.set(botId, node); else cardRefs.current.delete(botId); }, []); const setRemoveButtonRef = React.useCallback((botId, node) => { if (node) removeButtonRefs.current.set(botId, node); else removeButtonRefs.current.delete(botId); }, []); return h( "section", { className: "bxf-page", "aria-label": "\u98DE\u4E66\u673A\u5668\u4EBA\u8BBE\u7F6E" }, h(Heading, { totals: model.totals, onAdd: () => void startProvisioning(), adding: Boolean(provision), busy: provisionBusy, addButtonRef }), h("div", { className: "bxf-visuallyHidden", role: "status", "aria-live": "polite", "aria-atomic": "true" }, announcement), model.statusError ? h( "div", { className: "bxf-statusNotice", role: "status" }, h(AlertIcon, { size: 16 }), h("span", null, `\u72B6\u6001\u81EA\u52A8\u5237\u65B0\u5931\u8D25\uFF1A${model.statusError.message}`), h(Button, { size: "small", onClick: () => void loadStatus({ silent: true }), disabled: pageBusy }, "\u7ACB\u5373\u91CD\u8BD5") ) : null, model.phase === "loading" ? h(LoadingView) : model.phase === "error" ? h(PageError, { error: model.pageError ?? { message: "\u65E0\u6CD5\u8BFB\u53D6\u8FDE\u63A5\u72B6\u6001" }, onRetry: () => void loadStatus(), busy: pageBusy }) : h( React.Fragment, null, provisionContent, model.bots.length === 0 && !provision ? h(EmptyView, { onStart: () => void startProvisioning(), busy: provisionBusy }) : null, model.bots.length > 0 ? h(BotList, { bots: model.bots, busyByBot, errorsByBot, removeTargetId, onReconnect: (bot) => void reconnectOneBot(bot), onRequestRemove: requestRemove, onConfirmRemove: (bot) => void confirmRemove(bot), onCancelRemove: cancelRemove, setCardRef, setRemoveButtonRef }) : null ) ); } // plugin-src/client/channels/weixin/index.js var React2 = __toESM(require("react"), 1); // plugin-src/client/channels/weixin/api.js var WEIXIN_RPC_CHANNEL = "/weixin"; var WEIXIN_ENDPOINTS = Object.freeze({ status: "connection.status", beginProvisioning: "provision.begin", pollProvisioning: "provision.poll", submitVerification: "provision.verify", cancelProvisioning: "provision.cancel", reconnectBot: "bot.reconnect", deleteBot: "bot.delete" }); var ACCOUNT_STATES = /* @__PURE__ */ new Set(["connected", "connecting", "offline", "error"]); var PROVISION_STATES = /* @__PURE__ */ new Set([ "starting", "pending", "scanned", "needs_verification", "connecting", "connected", "expired", "failed", "cancelled" ]); function isRecord2(value) { return value !== null && typeof value === "object" && !Array.isArray(value); } function string(value, fallback = "") { return typeof value === "string" && value.trim() ? value.trim() : fallback; } function timestamp(value) { return typeof value === "number" && Number.isFinite(value) ? value : null; } function unwrapRpcResult2(result) { if (!isRecord2(result) || typeof result.ok !== "boolean") { throw new Error("\u5FAE\u4FE1\u670D\u52A1\u8FD4\u56DE\u4E86\u65E0\u6CD5\u8BC6\u522B\u7684\u54CD\u5E94"); } if (!result.ok) { const error = new Error(string(result.error?.message, "\u5FAE\u4FE1\u64CD\u4F5C\u5931\u8D25")); error.code = string(result.error?.code, "WEIXIN_RPC_ERROR"); throw error; } return result.value; } function safeQrSource2(value) { return typeof value === "string" && /^data:image\/(?:png|webp|svg\+xml)(?:;charset=[^;,]+)?;base64,/i.test(value) ? value : void 0; } function safeVerificationUrl(value) { if (typeof value !== "string") return void 0; try { const url = new URL(value); const host = url.hostname.toLowerCase(); return url.protocol === "https:" && (host === "weixin.qq.com" || host.endsWith(".weixin.qq.com")) ? url.toString() : void 0; } catch { return void 0; } } function normalizeProvisioning2(value) { if (!isRecord2(value) || !string(value.attemptId)) { throw new Error("\u5FAE\u4FE1\u626B\u7801\u670D\u52A1\u6CA1\u6709\u8FD4\u56DE\u6709\u6548\u7684\u7ED1\u5B9A\u4EFB\u52A1"); } const status = PROVISION_STATES.has(value.status) ? value.status : "failed"; const result = { attemptId: string(value.attemptId), status, expiresAt: timestamp(value.expiresAt) ?? Date.now(), pollIntervalMs: Math.min(5e3, Math.max(500, Number(value.pollIntervalMs) || 1e3)), verificationRequired: value.verificationRequired === true || status === "needs_verification" }; const verificationUrl = safeVerificationUrl(value.verificationUrl); const qrCodeDataUrl = safeQrSource2(value.qrCodeDataUrl); if (verificationUrl) result.verificationUrl = verificationUrl; if (qrCodeDataUrl) result.qrCodeDataUrl = qrCodeDataUrl; if (string(value.botId)) result.botId = string(value.botId); if (value.alreadyConnected === true) result.alreadyConnected = true; if (isRecord2(value.error)) { result.error = { code: string(value.error.code, "WEIXIN_PROVISION_FAILED"), message: string(value.error.message, "\u5FAE\u4FE1\u7ED1\u5B9A\u6CA1\u6709\u5B8C\u6210") }; } return result; } function normalizeBot2(value) { if (!isRecord2(value) || !string(value.botId) || !isRecord2(value.bot)) return null; const state = ACCOUNT_STATES.has(value.state) ? value.state : "error"; const connected = value.connected === true; return { botId: string(value.botId), state: connected ? "connected" : state, connected, configured: value.configured === true, bot: { name: string(value.bot.name, "\u5FAE\u4FE1\u673A\u5668\u4EBA"), accountIdMasked: string(value.bot.accountIdMasked, "\u5DF2\u5B89\u5168\u4FDD\u5B58") }, health: { status: string(value.health?.status, connected ? "healthy" : "offline"), summary: string(value.health?.summary, connected ? "\u5FAE\u4FE1\u8FDE\u63A5\u6B63\u5E38" : "\u5FAE\u4FE1\u8FDE\u63A5\u672A\u5C31\u7EEA"), lastCheckedAt: timestamp(value.health?.lastCheckedAt) }, stats: { messagesReceived: Math.max(0, Number(value.stats?.messagesReceived) || 0), messagesReplied: Math.max(0, Number(value.stats?.messagesReplied) || 0) }, error: isRecord2(value.error) ? { code: string(value.error.code, "WEIXIN_ACCOUNT_ERROR"), message: string(value.error.message, "\u5FAE\u4FE1\u8FDE\u63A5\u672A\u5C31\u7EEA") } : null }; } function normalizeSnapshot(value) { if (!isRecord2(value) || !Array.isArray(value.bots)) { throw new Error("\u5FAE\u4FE1\u670D\u52A1\u6CA1\u6709\u8FD4\u56DE\u6709\u6548\u7684\u8D26\u53F7\u5217\u8868"); } const bots = value.bots.map(normalizeBot2).filter(Boolean); return { schemaVersion: Number(value.schemaVersion) || 1, revision: Number(value.revision) || 0, state: string(value.state, "offline"), bots, totals: { configured: bots.length, connected: bots.filter((bot) => bot.connected).length }, provisioning: value.provisioning ? normalizeProvisioning2(value.provisioning) : null }; } function presentError2(error) { return { code: string(error?.code, "WEIXIN_ERROR"), message: string(error?.message, "\u5FAE\u4FE1\u64CD\u4F5C\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5") }; } function formatRemaining2(milliseconds) { const seconds = Math.max(0, Math.ceil(milliseconds / 1e3)); return `${Math.floor(seconds / 60)}:${String(seconds % 60).padStart(2, "0")}`; } // plugin-src/client/channels/weixin/styles.js var WEIXIN_STYLE_ID = "xmanrui-dsh-weixin-settings"; var CSS2 = String.raw` .dxw-page { --dxw-accent: #07c160; --dxw-accent-dark: #05994c; --dxw-success: var(--dsw-alias-state-success-primary, #20a162); --dxw-warning: var(--dsw-alias-state-warning-primary, #d97706); --dxw-error: var(--dsw-alias-state-error-primary, #d54941); width: 100%; max-width: 880px; display: flex; flex-direction: column; gap: 18px; padding: 2px 0 28px; color: var(--dsw-alias-label-primary, #1f2329); box-sizing: border-box; } .dxw-page *, .dxw-page *::before, .dxw-page *::after { box-sizing: border-box; } .dxw-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; } .dxw-heading h2, .dxw-heading p, .dxw-card h3, .dxw-card p { margin: 0; } .dxw-eyebrow { color: var(--dsw-alias-label-tertiary, #8f959e); font-size: 12px; font-weight: 650; letter-spacing: .08em; text-transform: uppercase; margin-bottom: 3px; } .dxw-heading h2 { font-size: 20px; line-height: 28px; font-weight: 680; } .dxw-heading p { color: var(--dsw-alias-label-secondary, #646a73); font-size: 13px; line-height: 20px; margin-top: 5px; white-space: nowrap; } .dxw-tools, .dxw-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; } .dxw-tools { justify-content: flex-end; } .dxw-badge { display: inline-flex; align-items: center; gap: 7px; min-height: 30px; padding: 0 11px; border-radius: 999px; color: var(--dsw-alias-label-secondary, #646a73); background: var(--dsw-alias-fill-secondary, #f2f3f5); font-size: 12px; white-space: nowrap; } .dxw-dot { width: 8px; height: 8px; border-radius: 50%; background: #aeb3bb; flex: none; } .dxw-dot[data-tone="success"] { background: var(--dxw-success); box-shadow: 0 0 0 3px color-mix(in srgb, var(--dxw-success) 14%, transparent); } .dxw-dot[data-tone="warning"] { background: var(--dxw-warning); } .dxw-dot[data-tone="error"] { background: var(--dxw-error); } .dxw-button { min-height: 34px; border: 1px solid var(--dsw-alias-line-border, #dfe1e5); border-radius: 8px; padding: 0 13px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; color: var(--dsw-alias-label-primary, #1f2329); background: var(--dsw-alias-bg-body, #fff); font: inherit; font-size: 13px; font-weight: 560; cursor: pointer; text-decoration: none; transition: border-color .15s ease, background .15s ease, transform .15s ease; } .dxw-button:hover:not(:disabled) { border-color: #aeb3bb; background: var(--dsw-alias-fill-tertiary, #f7f8fa); } .dxw-button:active:not(:disabled) { transform: translateY(1px); } .dxw-button:focus-visible, .dxw-input:focus-visible { outline: 2px solid color-mix(in srgb, var(--dxw-accent) 70%, white); outline-offset: 2px; } .dxw-button:disabled { cursor: not-allowed; opacity: .55; } .dxw-button[data-kind="primary"] { color: white; border-color: var(--dxw-accent); background: var(--dxw-accent); } .dxw-button[data-kind="primary"]:hover:not(:disabled) { border-color: var(--dxw-accent-dark); background: var(--dxw-accent-dark); } .dxw-button[data-kind="danger"] { color: var(--dxw-error); } .dxw-card { overflow: hidden; border: 1px solid var(--dsw-alias-line-border, #e5e6eb); border-radius: 14px; background: var(--dsw-alias-bg-body, #fff); box-shadow: 0 1px 2px rgb(31 35 41 / 3%); } .dxw-cardBody { padding: 24px; } .dxw-empty { min-height: 230px; display: grid; grid-template-columns: minmax(0, 1fr) 180px; align-items: center; gap: 30px; } .dxw-empty h3 { font-size: 18px; margin-bottom: 8px; } .dxw-empty p { max-width: 560px; color: var(--dsw-alias-label-secondary, #646a73); line-height: 1.65; } .dxw-empty .dxw-actions { margin-top: 20px; } .dxw-logo { width: 110px; height: 110px; display: grid; place-items: center; justify-self: center; border-radius: 28px; color: white; background: var(--dxw-accent); box-shadow: 0 18px 45px rgb(7 193 96 / 22%); } .dxw-logo svg { width: 62px; height: 62px; } .dxw-qrLayout { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 34px; align-items: center; } .dxw-qrColumn { display: flex; flex-direction: column; align-items: center; gap: 12px; } .dxw-qrFrame { position: relative; width: 270px; aspect-ratio: 1; display: grid; place-items: center; overflow: hidden; padding: 10px; border: 1px solid var(--dsw-alias-line-border, #e5e6eb); border-radius: 16px; background: white; } .dxw-qrFrame img { display: block; width: 100%; height: 100%; object-fit: contain; } .dxw-qrFallback { padding: 24px; text-align: center; color: #646a73; } .dxw-expired { position: absolute; inset: 0; display: grid; place-items: center; padding: 30px; color: white; text-align: center; font-weight: 650; background: rgb(31 35 41 / 76%); backdrop-filter: blur(3px); } .dxw-countdown { width: 270px; color: var(--dsw-alias-label-secondary, #646a73); font-size: 12px; } .dxw-countdown div { display: flex; justify-content: space-between; margin-bottom: 6px; } .dxw-progress { height: 4px; overflow: hidden; border-radius: 99px; background: #eef0f3; } .dxw-progress span { display: block; width: var(--dxw-progress); height: 100%; background: var(--dxw-accent); transition: width .2s linear; } .dxw-qrCopy h3 { margin: 9px 0 8px; font-size: 18px; } .dxw-qrCopy > p { color: var(--dsw-alias-label-secondary, #646a73); line-height: 1.65; } .dxw-steps { margin: 18px 0 22px; padding-left: 22px; color: var(--dsw-alias-label-secondary, #646a73); font-size: 13px; line-height: 1.9; } .dxw-stateLabel { display: inline-flex; align-items: center; gap: 8px; color: var(--dsw-alias-label-secondary, #646a73); font-size: 12px; font-weight: 600; } .dxw-verify { max-width: 560px; margin: 0 auto; padding: 32px; text-align: center; } .dxw-verify h3 { margin: 8px 0; font-size: 19px; } .dxw-verify p { color: var(--dsw-alias-label-secondary, #646a73); line-height: 1.6; } .dxw-codeRow { display: flex; justify-content: center; gap: 10px; margin: 24px 0 10px; } .dxw-input { width: 190px; height: 42px; padding: 0 14px; border: 1px solid var(--dsw-alias-line-border, #dfe1e5); border-radius: 9px; background: var(--dsw-alias-bg-body, white); color: inherit; font: inherit; font-size: 18px; letter-spacing: .16em; text-align: center; } .dxw-statusNotice, .dxw-error { display: flex; align-items: center; gap: 10px; padding: 13px 15px; border: 1px solid color-mix(in srgb, var(--dxw-error) 28%, transparent); border-radius: 10px; color: var(--dxw-error); background: color-mix(in srgb, var(--dxw-error) 7%, transparent); font-size: 13px; } .dxw-error { align-items: flex-start; flex-direction: column; padding: 22px; } .dxw-error h3 { font-size: 17px; } .dxw-errorCode { font-family: ui-monospace, SFMono-Regular, monospace; font-size: 11px; opacity: .8; } .dxw-listHeading { display: flex; justify-content: space-between; align-items: center; margin: 2px 0 9px; } .dxw-listHeading h3 { margin: 0; font-size: 14px; } .dxw-listHeading span { color: var(--dsw-alias-label-tertiary, #8f959e); font-size: 12px; } .dxw-list { display: grid; gap: 12px; margin: 0; padding: 0; list-style: none; } .dxw-accountTop { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; } .dxw-accountIdentity { display: flex; align-items: center; gap: 12px; min-width: 0; } .dxw-avatar { width: 42px; height: 42px; display: grid; place-items: center; flex: none; border-radius: 12px; color: white; background: var(--dxw-accent); } .dxw-accountIdentity h3 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; } .dxw-accountIdentity p { color: var(--dsw-alias-label-secondary, #646a73); font: 12px ui-monospace, SFMono-Regular, monospace; margin-top: 4px; } .dxw-health { display: inline-flex; align-items: center; gap: 7px; color: var(--dsw-alias-label-secondary, #646a73); font-size: 12px; white-space: nowrap; } .dxw-metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 20px 0; } .dxw-metric { padding: 12px 14px; border-radius: 9px; background: var(--dsw-alias-fill-tertiary, #f7f8fa); } .dxw-metric dt { color: var(--dsw-alias-label-tertiary, #8f959e); font-size: 11px; } .dxw-metric dd { overflow: hidden; margin: 5px 0 0; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; } .dxw-accountFooter { display: flex; align-items: center; justify-content: space-between; gap: 15px; padding-top: 16px; border-top: 1px solid var(--dsw-alias-line-divider, #eef0f3); } .dxw-summary { color: var(--dsw-alias-label-secondary, #646a73); font-size: 12px; } .dxw-confirm { padding: 18px 24px; border-top: 1px solid color-mix(in srgb, var(--dxw-error) 25%, transparent); background: color-mix(in srgb, var(--dxw-error) 5%, transparent); } .dxw-confirm strong { display: block; font-size: 14px; margin-bottom: 6px; } .dxw-confirm p { color: var(--dsw-alias-label-secondary, #646a73); font-size: 12px; line-height: 1.55; } .dxw-confirm .dxw-actions { margin-top: 13px; } .dxw-loading { padding: 36px; color: var(--dsw-alias-label-secondary, #646a73); text-align: center; } .dxw-spinner { width: 24px; height: 24px; margin: 0 auto 12px; border: 3px solid #e6e8eb; border-top-color: var(--dxw-accent); border-radius: 50%; animation: dxw-spin .8s linear infinite; } .dxw-visuallyHidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; } @keyframes dxw-spin { to { transform: rotate(360deg); } } @media (max-width: 720px) { .dxw-heading, .dxw-accountTop, .dxw-accountFooter { flex-direction: column; align-items: stretch; } .dxw-tools { justify-content: flex-start; } .dxw-empty { grid-template-columns: minmax(0, 1fr); } .dxw-logo { display: none; } .dxw-qrLayout { grid-template-columns: minmax(0, 1fr); justify-items: center; } .dxw-qrCopy { width: 100%; } .dxw-metrics { grid-template-columns: minmax(0, 1fr); } .dxw-cardBody { padding: 20px; } } @media (prefers-reduced-motion: reduce) { .dxw-page *, .dxw-page *::before, .dxw-page *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } } `; function installWeixinStyles() { if (typeof document === "undefined") return () => { }; const existing = document.querySelector(`style[data-plugin-css="${WEIXIN_STYLE_ID}"]`); if (existing) return () => { }; const style = document.createElement("style"); style.dataset.plugin = "@xmanrui/dsh-weixin"; style.dataset.pluginCss = WEIXIN_STYLE_ID; style.textContent = CSS2; document.head.appendChild(style); return () => style.remove(); } // plugin-src/client/channels/weixin/index.js var h2 = React2.createElement; function WeixinIcon({ size = 26 }) { return h2( "svg", { width: size, height: size, viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true" }, h2("path", { d: "M9.7 4.2c-4.15 0-7.5 2.72-7.5 6.08 0 1.91 1.08 3.61 2.78 4.72l-.7 2.35 2.75-1.37c.84.25 1.73.38 2.67.38 4.14 0 7.5-2.72 7.5-6.08S13.84 4.2 9.7 4.2Z", fill: "currentColor", opacity: ".96" }), h2("path", { d: "M14.4 8.2c4.08 0 7.4 2.66 7.4 5.95 0 1.78-.97 3.38-2.5 4.47l.58 2-2.36-1.18c-.97.43-2.03.65-3.12.65-4.09 0-7.4-2.66-7.4-5.94 0-3.29 3.31-5.95 7.4-5.95Z", fill: "currentColor", stroke: "white", strokeWidth: ".8" }), h2("circle", { cx: "7.25", cy: "9.5", r: "1", fill: "white" }), h2("circle", { cx: "11.55", cy: "9.5", r: "1", fill: "white" }), h2("circle", { cx: "12.1", cy: "13.2", r: ".9", fill: "white" }), h2("circle", { cx: "16.3", cy: "13.2", r: ".9", fill: "white" }) ); } var Button3 = React2.forwardRef(function Button4({ children, kind = "secondary", className = "", ...props }, ref) { return h2("button", { ...props, ref, type: "button", className: `dxw-button ${className}`.trim(), "data-kind": kind }, children); }); function Heading2({ totals, adding, busy, onAdd, addButtonRef }) { return h2( "div", { className: "dxw-heading" }, h2( "div", { className: "dxw-tools" }, totals.configured > 0 ? h2( "div", { className: "dxw-badge" }, h2("span", { className: "dxw-dot", "data-tone": totals.connected > 0 ? "success" : "warning" }), h2("span", null, `${totals.connected} / ${totals.configured} \u5728\u7EBF`) ) : null, h2( "div", { className: "dxw-badge", title: "bot_token \u4EC5\u4FDD\u5B58\u5728 Harness Host \u51ED\u636E\u670D\u52A1\u4E2D" }, h2("span", null, "\u51ED\u636E\u4EC5\u4FDD\u5B58\u5728\u672C\u673A") ), h2(Button3, { kind: "primary", onClick: onAdd, disabled: adding || busy, ref: addButtonRef }, adding ? "\u6B63\u5728\u7ED1\u5B9A" : "\u626B\u7801\u7ED1\u5B9A\u5FAE\u4FE1") ) ); } function LoadingView2() { return h2( "div", { className: "dxw-card dxw-loading", "aria-busy": "true" }, h2("div", { className: "dxw-spinner" }), h2("span", null, "\u6B63\u5728\u8BFB\u53D6\u5FAE\u4FE1\u8FDE\u63A5\u72B6\u6001\u2026") ); } function EmptyView2({ onStart, busy }) { return h2( "div", { className: "dxw-card" }, h2( "div", { className: "dxw-cardBody dxw-empty" }, h2( "div", null, h2( "div", { className: "dxw-stateLabel" }, h2("span", { className: "dxw-dot" }), h2("span", null, "\u5C1A\u672A\u7ED1\u5B9A\u5FAE\u4FE1") ), h2("h3", null, "\u626B\u4E00\u6B21\u7801\uFF0C\u5C31\u80FD\u5728\u5FAE\u4FE1\u91CC\u4F7F\u7528 Harness"), h2("p", null, "\u4E8C\u7EF4\u7801\u7531\u817E\u8BAF\u5FAE\u4FE1 iLink \u670D\u52A1\u7B7E\u53D1\u3002\u7528\u624B\u673A\u5FAE\u4FE1\u626B\u63CF\u5E76\u786E\u8BA4\u540E\uFF0C\u8D26\u53F7\u51ED\u636E\u4F1A\u76F4\u63A5\u5199\u5165 Harness Host\uFF0C\u6D4F\u89C8\u5668\u4E0D\u4F1A\u6536\u5230 bot_token\u3002"), h2( "div", { className: "dxw-actions" }, h2( Button3, { kind: "primary", onClick: onStart, disabled: busy }, busy ? "\u6B63\u5728\u751F\u6210\u4E8C\u7EF4\u7801\u2026" : "\u751F\u6210\u5FAE\u4FE1\u4E8C\u7EF4\u7801" ) ) ), h2("div", { className: "dxw-logo", "aria-hidden": "true" }, h2(WeixinIcon, { size: 64 })) ) ); } function QrPanel({ provision, now, busy, onRefresh, onCancel }) { const [imageFailed, setImageFailed] = React2.useState(false); const source = safeQrSource2(provision.qrCodeDataUrl); const href = safeVerificationUrl(provision.verificationUrl); const remaining = Math.max(0, provision.expiresAt - now); const expired = remaining === 0 || provision.status === "expired"; const duration = Math.max(1, provision.durationMs ?? 5 * 6e4); const progress = Math.round(Math.min(1, remaining / duration) * 100); React2.useEffect(() => setImageFailed(false), [source]); return h2( "div", { className: "dxw-card" }, h2( "div", { className: "dxw-cardBody dxw-qrLayout" }, h2( "div", { className: "dxw-qrColumn" }, h2( "div", { className: "dxw-qrFrame" }, source && !imageFailed ? h2("img", { src: source, alt: "\u7528\u4E8E\u628A\u5FAE\u4FE1\u673A\u5668\u4EBA\u7ED1\u5B9A\u5230 DeepSeek Harness \u7684\u4E00\u6B21\u6027\u4E8C\u7EF4\u7801", onError: () => setImageFailed(true) }) : h2("div", { className: "dxw-qrFallback" }, "\u4E8C\u7EF4\u7801\u56FE\u7247\u672A\u5C31\u7EEA\uFF0C\u8BF7\u4F7F\u7528\u5907\u7528\u94FE\u63A5\u3002"), expired ? h2("div", { className: "dxw-expired" }, "\u4E8C\u7EF4\u7801\u5DF2\u8FC7\u671F\n\u8BF7\u91CD\u65B0\u751F\u6210") : null ), h2( "div", { className: "dxw-countdown" }, h2("div", null, h2("span", null, "\u4E8C\u7EF4\u7801\u6709\u6548\u65F6\u95F4"), h2("strong", null, formatRemaining2(remaining))), h2( "div", { className: "dxw-progress", "aria-hidden": "true" }, h2("span", { style: { "--dxw-progress": `${progress}%` } }) ) ) ), h2( "div", { className: "dxw-qrCopy" }, h2( "div", { className: "dxw-stateLabel" }, h2("span", { className: "dxw-dot", "data-tone": provision.status === "scanned" ? "success" : "warning" }), h2("span", null, provision.status === "scanned" ? "\u5DF2\u626B\u7801\uFF0C\u8BF7\u5728\u624B\u673A\u4E0A\u786E\u8BA4" : "\u7B49\u5F85\u5FAE\u4FE1\u626B\u7801") ), h2("h3", null, expired ? "\u4E8C\u7EF4\u7801\u5DF2\u5931\u6548" : "\u4F7F\u7528\u624B\u673A\u5FAE\u4FE1\u626B\u63CF\u4E8C\u7EF4\u7801"), h2("p", null, "\u8BF7\u5728\u624B\u673A\u4E0A\u6838\u5BF9\u5E76\u786E\u8BA4\u6388\u6743\u3002\u90E8\u5206\u8D26\u53F7\u4F1A\u989D\u5916\u663E\u793A\u4E00\u4E2A\u914D\u5BF9\u6570\u5B57\uFF0C\u9875\u9762\u4F1A\u5728\u9700\u8981\u65F6\u63D0\u793A\u8F93\u5165\u3002"), h2( "ol", { className: "dxw-steps" }, h2("li", null, "\u6253\u5F00\u624B\u673A\u5FAE\u4FE1\u5E76\u626B\u63CF\u5DE6\u4FA7\u4E8C\u7EF4\u7801"), h2("li", null, "\u5728\u5FAE\u4FE1\u4E2D\u786E\u8BA4\u8FDE\u63A5\u8BE5\u673A\u5668\u4EBA"), h2("li", null, "\u4FDD\u6301\u672C\u9875\u6253\u5F00\uFF0C\u7B49\u5F85\u6D88\u606F\u957F\u8F6E\u8BE2\u53D8\u4E3A\u5728\u7EBF") ), h2( "div", { className: "dxw-actions" }, expired ? h2(Button3, { kind: "primary", onClick: onRefresh, disabled: busy }, "\u91CD\u65B0\u751F\u6210\u4E8C\u7EF4\u7801") : null, href ? h2("a", { className: "dxw-button", href, target: "_blank", rel: "noopener noreferrer" }, "\u6253\u5F00\u5907\u7528\u94FE\u63A5") : null, !expired ? h2(Button3, { onClick: onRefresh, disabled: busy }, "\u6362\u4E00\u4E2A\u4E8C\u7EF4\u7801") : null, h2(Button3, { onClick: onCancel, disabled: busy }, "\u53D6\u6D88") ) ) ) ); } function VerificationPanel({ provision, busy, onSubmit, onCancel }) { const [code, setCode] = React2.useState(""); const valid = /^\d{4,8}$/.test(code); React2.useEffect(() => setCode(""), [provision.attemptId]); return h2( "div", { className: "dxw-card" }, h2( "form", { className: "dxw-verify", onSubmit: (event) => { event.preventDefault(); if (valid && !busy) onSubmit(code); } }, h2( "div", { className: "dxw-stateLabel" }, h2("span", { className: "dxw-dot", "data-tone": "warning" }), h2("span", null, "\u9700\u8981\u914D\u5BF9\u7801") ), h2("h3", null, "\u8F93\u5165\u624B\u673A\u5FAE\u4FE1\u663E\u793A\u7684\u6570\u5B57"), h2("p", null, "\u8FD9\u662F\u5FAE\u4FE1\u9644\u52A0\u7684\u5B89\u5168\u786E\u8BA4\u6B65\u9AA4\u3002\u914D\u5BF9\u7801\u53EA\u7528\u4E8E\u672C\u6B21\u626B\u7801\u8F6E\u8BE2\uFF0C\u4E0D\u4F1A\u5199\u5165\u914D\u7F6E\u6216\u65E5\u5FD7\u3002"), h2( "div", { className: "dxw-codeRow" }, h2("input", { className: "dxw-input", value: code, inputMode: "numeric", autoComplete: "one-time-code", maxLength: 8, "aria-label": "\u5FAE\u4FE1\u914D\u5BF9\u7801", onChange: (event) => setCode(event.target.value.replace(/\D/g, "").slice(0, 8)), autoFocus: true }), h2("button", { type: "submit", className: "dxw-button", "data-kind": "primary", disabled: !valid || busy }, busy ? "\u6B63\u5728\u9A8C\u8BC1\u2026" : "\u7EE7\u7EED\u8FDE\u63A5") ), h2(Button3, { onClick: onCancel, disabled: busy }, "\u53D6\u6D88\u7ED1\u5B9A") ) ); } function ProgressPanel({ scanned, onCancel, busy }) { return h2( "div", { className: "dxw-card dxw-loading", "aria-busy": "true" }, h2("div", { className: "dxw-spinner" }), h2("h3", null, scanned ? "\u5FAE\u4FE1\u5DF2\u786E\u8BA4\uFF0C\u6B63\u5728\u542F\u52A8\u6D88\u606F\u8FDE\u63A5" : "\u6B63\u5728\u51C6\u5907\u5FAE\u4FE1\u4E8C\u7EF4\u7801"), h2("p", null, scanned ? "\u6B63\u5728\u4FDD\u5B58\u51ED\u636E\u5E76\u9A8C\u8BC1 Harness \u4E0E\u5FAE\u4FE1\u957F\u8F6E\u8BE2\u3002" : "\u6B63\u5728\u8054\u7CFB\u817E\u8BAF\u5FAE\u4FE1 iLink \u670D\u52A1\u3002"), onCancel ? h2( "div", { className: "dxw-actions", style: { justifyContent: "center", marginTop: 14 } }, h2(Button3, { onClick: onCancel, disabled: busy }, "\u53D6\u6D88") ) : null ); } function ProvisionError2({ provision, busy, onRetry, onClose }) { const error = provision.error ?? { code: "WEIXIN_PROVISION_FAILED", message: "\u5FAE\u4FE1\u7ED1\u5B9A\u6CA1\u6709\u5B8C\u6210" }; return h2( "div", { className: "dxw-card" }, h2( "div", { className: "dxw-error", role: "alert" }, h2("h3", null, provision.status === "expired" ? "\u4E8C\u7EF4\u7801\u5DF2\u8FC7\u671F" : "\u5FAE\u4FE1\u6CA1\u6709\u7ED1\u5B9A\u5B8C\u6210"), h2("p", null, error.message), h2("span", { className: "dxw-errorCode" }, error.code), h2( "div", { className: "dxw-actions" }, h2(Button3, { kind: "primary", onClick: onRetry, disabled: busy }, "\u91CD\u65B0\u751F\u6210\u4E8C\u7EF4\u7801"), h2(Button3, { onClick: onClose, disabled: busy }, "\u5173\u95ED") ) ) ); } function checkedTime(timestamp2) { if (!timestamp2) return "\u5C1A\u672A\u68C0\u67E5"; try { return new Intl.DateTimeFormat("zh-CN", { hour: "2-digit", minute: "2-digit", second: "2-digit" }).format(new Date(timestamp2)); } catch { return "\u521A\u521A"; } } function AccountCard({ account, busy, removing, onReconnect, onRequestRemove, onConfirmRemove, onCancelRemove }) { const state = busy === "reconnect" ? "connecting" : account.state; const tone = account.connected ? "success" : state === "error" ? "error" : "warning"; return h2( "article", { className: "dxw-card", tabIndex: -1, "data-bot-id": account.botId }, h2( "div", { className: "dxw-cardBody" }, h2( "div", { className: "dxw-accountTop" }, h2( "div", { className: "dxw-accountIdentity" }, h2("div", { className: "dxw-avatar", "aria-hidden": "true" }, h2(WeixinIcon, { size: 27 })), h2("div", null, h2("h3", null, account.bot.name), h2("p", null, account.bot.accountIdMasked)) ), h2( "div", { className: "dxw-health" }, h2("span", { className: "dxw-dot", "data-tone": tone }), h2("span", null, account.connected ? "\u8FD0\u884C\u6B63\u5E38" : state === "connecting" ? "\u6B63\u5728\u8FDE\u63A5" : "\u8FDE\u63A5\u672A\u5C31\u7EEA") ) ), h2( "dl", { className: "dxw-metrics" }, h2( "div", { className: "dxw-metric" }, h2("dt", null, "\u6D88\u606F\u901A\u9053"), h2("dd", null, account.connected ? "iLink \u957F\u8F6E\u8BE2" : "\u79BB\u7EBF") ), h2( "div", { className: "dxw-metric" }, h2("dt", null, "\u6536\u5230 / \u56DE\u590D"), h2("dd", null, `${account.stats.messagesReceived} / ${account.stats.messagesReplied}`) ), h2( "div", { className: "dxw-metric" }, h2("dt", null, "\u6700\u8FD1\u68C0\u67E5"), h2("dd", null, checkedTime(account.health.lastCheckedAt)) ) ), h2( "div", { className: "dxw-accountFooter" }, h2("div", { className: "dxw-summary" }, account.error?.message ?? account.health.summary), h2( "div", { className: "dxw-actions" }, h2( Button3, { onClick: onReconnect, disabled: Boolean(busy) }, busy === "reconnect" ? "\u68C0\u67E5\u4E2D\u2026" : account.connected ? "\u68C0\u67E5\u8FDE\u63A5" : "\u91CD\u8BD5\u8FDE\u63A5" ), h2(Button3, { kind: "danger", onClick: onRequestRemove, disabled: Boolean(busy) }, "\u79FB\u9664\u63A5\u5165") ) ) ), removing ? h2( "div", { className: "dxw-confirm", role: "alertdialog" }, h2("strong", null, "\u4ECE\u6B64 Harness \u79FB\u9664\u8FD9\u4E2A\u5FAE\u4FE1\u8D26\u53F7\uFF1F"), h2("p", null, "\u8FD9\u4F1A\u505C\u6B62\u6D88\u606F\u8FDE\u63A5\uFF0C\u5E76\u5220\u9664\u672C\u673A\u4FDD\u5B58\u7684 bot_token\u3001\u8D26\u53F7\u914D\u7F6E\u548C\u4F1A\u8BDD\u6620\u5C04\u3002\u5176\u4ED6\u5FAE\u4FE1\u8D26\u53F7\u4E0D\u53D7\u5F71\u54CD\u3002"), h2( "div", { className: "dxw-actions" }, h2(Button3, { onClick: onCancelRemove, disabled: busy === "delete" }, "\u4FDD\u7559\u8D26\u53F7"), h2( Button3, { kind: "danger", onClick: onConfirmRemove, disabled: busy === "delete" }, busy === "delete" ? "\u6B63\u5728\u79FB\u9664\u2026" : "\u786E\u8BA4\u79FB\u9664" ) ) ) : null ); } function AccountList(props) { return h2( "section", null, h2("div", { className: "dxw-listHeading" }, h2("h3", null, "\u5DF2\u63A5\u5165\u7684\u5FAE\u4FE1\u8D26\u53F7"), h2("span", null, `${props.bots.length} \u4E2A`)), h2("ul", { className: "dxw-list" }, props.bots.map((account) => h2( "li", { key: account.botId }, h2(AccountCard, { account, busy: props.busyByBot[account.botId], removing: props.removeTarget === account.botId, onReconnect: () => props.onReconnect(account), onRequestRemove: () => props.onRequestRemove(account), onConfirmRemove: () => props.onConfirmRemove(account), onCancelRemove: props.onCancelRemove }) ))) ); } var EMPTY_TOTALS2 = Object.freeze({ configured: 0, connected: 0 }); function WeixinSettingsTab({ rpcCall }) { const [model, setModel] = React2.useState({ phase: "loading", bots: [], totals: EMPTY_TOTALS2, revision: 0, error: null }); const [provision, setProvision] = React2.useState(null); const [busy, setBusy] = React2.useState(false); const [busyByBot, setBusyByBot] = React2.useState({}); const [removeTarget, setRemoveTarget] = React2.useState(null); const [notice, setNotice] = React2.useState(""); const [now, setNow] = React2.useState(() => Date.now()); const addButtonRef = React2.useRef(null); const announce = React2.useCallback((value) => { setNotice(""); if (value) window.requestAnimationFrame(() => setNotice(value)); }, []); const invoke = React2.useCallback(async (endpoint, payload = {}, signal) => { return unwrapRpcResult2(await rpcCall(endpoint, payload, signal)); }, [rpcCall]); const loadStatus = React2.useCallback(async ({ signal, silent = false } = {}) => { if (!silent) setModel((current) => ({ ...current, phase: "loading", error: null })); try { const snapshot = normalizeSnapshot(await invoke(WEIXIN_ENDPOINTS.status, {}, signal)); setModel({ phase: "ready", bots: snapshot.bots, totals: snapshot.totals, revision: snapshot.revision, error: null }); if (snapshot.provisioning) { setProvision((current) => !current || current.attemptId === snapshot.provisioning.attemptId ? { ...current, ...snapshot.provisioning, durationMs: current?.durationMs ?? 5 * 6e4 } : current); } return snapshot; } catch (error) { if (error?.name === "AbortError") return void 0; setModel((current) => ({ ...current, phase: silent && current.phase === "ready" ? "ready" : "error", error: presentError2(error) })); return void 0; } }, [invoke]); React2.useEffect(() => { const controller = new AbortController(); void loadStatus({ signal: controller.signal }); return () => controller.abort(); }, [loadStatus]); React2.useEffect(() => { if (model.phase !== "ready") return void 0; const controller = new AbortController(); let running = false; const timer = window.setInterval(async () => { if (running) return; running = true; await loadStatus({ signal: controller.signal, silent: true }); running = false; }, 15e3); return () => { controller.abort(); window.clearInterval(timer); }; }, [loadStatus, model.phase]); React2.useEffect(() => { if (!provision || !["pending", "scanned"].includes(provision.status)) return void 0; const timer = window.setInterval(() => setNow(Date.now()), 1e3); return () => window.clearInterval(timer); }, [provision?.attemptId, provision?.status]); const startProvisioning = React2.useCallback(async ({ replace = false } = {}) => { setBusy(true); try { if (replace && provision?.attemptId) { await invoke(WEIXIN_ENDPOINTS.cancelProvisioning, { attemptId: provision.attemptId }); } setProvision({ status: "starting" }); const started = normalizeProvisioning2(await invoke(WEIXIN_ENDPOINTS.beginProvisioning, { locale: "zh-CN" })); setNow(Date.now()); setProvision({ ...started, durationMs: Math.max(1, started.expiresAt - Date.now()) }); announce("\u5FAE\u4FE1\u4E8C\u7EF4\u7801\u5DF2\u751F\u6210\uFF0C\u8BF7\u4F7F\u7528\u624B\u673A\u5FAE\u4FE1\u626B\u63CF\u3002"); } catch (error) { setProvision({ status: "failed", error: presentError2(error), ...provision?.attemptId ? { attemptId: provision.attemptId } : {} }); } finally { setBusy(false); } }, [announce, invoke, provision?.attemptId]); const cancelProvisioning = React2.useCallback(async () => { setBusy(true); try { if (provision?.attemptId && !["failed", "expired", "cancelled"].includes(provision.status)) { await invoke(WEIXIN_ENDPOINTS.cancelProvisioning, { attemptId: provision.attemptId }); } setProvision(null); announce("\u5DF2\u53D6\u6D88\u5FAE\u4FE1\u7ED1\u5B9A\u3002"); window.requestAnimationFrame(() => addButtonRef.current?.focus()); } catch (error) { setProvision((current) => ({ ...current, status: "failed", error: presentError2(error) })); } finally { setBusy(false); } }, [announce, invoke, provision?.attemptId, provision?.status]); const submitVerification = React2.useCallback(async (verifyCode) => { if (!provision?.attemptId) return; setBusy(true); try { const next = normalizeProvisioning2(await invoke(WEIXIN_ENDPOINTS.submitVerification, { attemptId: provision.attemptId, verifyCode })); setProvision((current) => ({ ...current, ...next })); announce("\u914D\u5BF9\u7801\u5DF2\u63D0\u4EA4\uFF0C\u6B63\u5728\u7B49\u5F85\u5FAE\u4FE1\u786E\u8BA4\u3002"); } catch (error) { setProvision((current) => ({ ...current, status: "failed", error: presentError2(error) })); } finally { setBusy(false); } }, [announce, invoke, provision?.attemptId]); React2.useEffect(() => { const attemptId = provision?.attemptId; if (!attemptId || !["pending", "scanned", "connecting"].includes(provision.status)) return void 0; const controller = new AbortController(); let timer; const poll = async () => { try { const result = normalizeProvisioning2(await invoke( WEIXIN_ENDPOINTS.pollProvisioning, { attemptId }, controller.signal )); if (result.status === "connected") { const snapshot = await loadStatus({ signal: controller.signal, silent: true }); const account = snapshot?.bots.find((bot) => bot.botId === result.botId); if (!account?.connected) { setProvision((current) => current?.attemptId === attemptId ? { ...current, ...result, status: "connecting" } : current); timer = window.setTimeout(poll, result.pollIntervalMs); return; } setProvision(null); announce(result.alreadyConnected ? "\u8FD9\u4E2A\u5FAE\u4FE1\u8D26\u53F7\u5DF2\u7ECF\u7ED1\u5B9A\u5E76\u4FDD\u6301\u5728\u7EBF\u3002" : "\u5FAE\u4FE1\u5DF2\u7ED1\u5B9A\uFF0C\u53EF\u4EE5\u5F00\u59CB\u5411\u5DF2\u7ED1\u5B9A\u7684\u673A\u5668\u4EBA\u53D1\u6D88\u606F\u3002"); return; } setProvision((current) => current?.attemptId === attemptId ? { ...current, ...result, durationMs: current.durationMs } : current); if (["pending", "scanned", "connecting"].includes(result.status)) { timer = window.setTimeout(poll, result.pollIntervalMs); } } catch (error) { if (error?.name === "AbortError") return; setProvision((current) => current?.attemptId === attemptId ? { ...current, status: "failed", error: presentError2(error) } : current); } }; timer = window.setTimeout(poll, provision.pollIntervalMs ?? 1e3); return () => { controller.abort(); window.clearTimeout(timer); }; }, [announce, invoke, loadStatus, provision?.attemptId, provision?.status, provision?.pollIntervalMs]); const setBotBusy = React2.useCallback((botId, value) => { setBusyByBot((current) => { const next = { ...current }; if (value) next[botId] = value; else delete next[botId]; return next; }); }, []); const reconnect = React2.useCallback(async (account) => { setBotBusy(account.botId, "reconnect"); try { const snapshot = normalizeSnapshot(await invoke(WEIXIN_ENDPOINTS.reconnectBot, { botId: account.botId })); setModel((current) => ({ ...current, bots: snapshot.bots, totals: snapshot.totals, revision: snapshot.revision })); const refreshed = snapshot.bots.find((bot) => bot.botId === account.botId); announce(refreshed?.connected ? "\u5FAE\u4FE1\u8FDE\u63A5\u68C0\u67E5\u5B8C\u6210\u3002" : "\u5FAE\u4FE1\u4ECD\u672A\u8FDE\u63A5\uFF0C\u63D2\u4EF6\u4F1A\u7EE7\u7EED\u81EA\u52A8\u91CD\u8BD5\u3002"); } catch (error) { announce(`\u8FDE\u63A5\u68C0\u67E5\u5931\u8D25\uFF1A${presentError2(error).message}`); } finally { setBotBusy(account.botId, null); } }, [announce, invoke, setBotBusy]); const remove = React2.useCallback(async (account) => { setBotBusy(account.botId, "delete"); try { const snapshot = normalizeSnapshot(await invoke(WEIXIN_ENDPOINTS.deleteBot, { botId: account.botId, confirm: true })); setModel((current) => ({ ...current, bots: snapshot.bots, totals: snapshot.totals, revision: snapshot.revision })); setRemoveTarget(null); announce("\u5FAE\u4FE1\u8D26\u53F7\u53CA\u672C\u673A\u51ED\u636E\u5DF2\u79FB\u9664\u3002"); } catch (error) { announce(`\u79FB\u9664\u5931\u8D25\uFF1A${presentError2(error).message}`); } finally { setBotBusy(account.botId, null); } }, [announce, invoke, setBotBusy]); let provisionView = null; if (provision?.status === "starting") { provisionView = h2(ProgressPanel, { busy }); } else if (["pending", "scanned"].includes(provision?.status)) { provisionView = h2(QrPanel, { provision, now, busy, onRefresh: () => void startProvisioning({ replace: true }), onCancel: () => void cancelProvisioning() }); } else if (provision?.status === "needs_verification") { provisionView = h2(VerificationPanel, { provision, busy, onSubmit: (code) => void submitVerification(code), onCancel: () => void cancelProvisioning() }); } else if (provision?.status === "connecting") { provisionView = h2(ProgressPanel, { scanned: true, busy, onCancel: () => void cancelProvisioning() }); } else if (provision && ["failed", "expired", "cancelled"].includes(provision.status)) { provisionView = h2(ProvisionError2, { provision, busy, onRetry: () => void startProvisioning({ replace: Boolean(provision.attemptId) }), onClose: () => void cancelProvisioning() }); } return h2( "section", { className: "dxw-page", "aria-label": "\u5FAE\u4FE1\u8BBE\u7F6E" }, h2(Heading2, { totals: model.totals, adding: Boolean(provision), busy, onAdd: () => void startProvisioning(), addButtonRef }), h2("div", { className: "dxw-visuallyHidden", role: "status", "aria-live": "polite" }, notice), model.error && model.phase === "ready" ? h2("div", { className: "dxw-statusNotice" }, `\u72B6\u6001\u5237\u65B0\u5931\u8D25\uFF1A${model.error.message}`) : null, model.phase === "loading" ? h2(LoadingView2) : model.phase === "error" ? h2( "div", { className: "dxw-card" }, h2( "div", { className: "dxw-error" }, h2("h3", null, "\u65E0\u6CD5\u8BFB\u53D6\u5FAE\u4FE1\u72B6\u6001"), h2("p", null, model.error?.message ?? "\u8BF7\u7A0D\u540E\u91CD\u8BD5"), h2(Button3, { onClick: () => void loadStatus() }, "\u91CD\u65B0\u8BFB\u53D6") ) ) : h2( React2.Fragment, null, provisionView, model.bots.length === 0 && !provision ? h2(EmptyView2, { onStart: () => void startProvisioning(), busy }) : null, model.bots.length > 0 ? h2(AccountList, { bots: model.bots, busyByBot, removeTarget, onReconnect: (account) => void reconnect(account), onRequestRemove: (account) => setRemoveTarget(account.botId), onConfirmRemove: (account) => void remove(account), onCancelRemove: () => setRemoveTarget(null) }) : null ) ); } // plugin-src/client/styles.js var IM_STYLE_ID = "xmanrui-dsh-im-settings"; var CSS3 = String.raw` .dim-page { --dim-blue: #3370ff; --dim-blue-soft: color-mix(in srgb, var(--dim-blue) 9%, transparent); width: 100%; max-width: 1080px; padding: 2px 0 30px; color: var(--dsw-alias-label-primary, #1f2329); box-sizing: border-box; } .dim-page *, .dim-page *::before, .dim-page *::after { box-sizing: border-box; } .dim-title { display: flex; align-items: center; justify-content: space-between; gap: 22px; margin: 0 0 26px; } .dim-title p { margin: 0; color: var(--dsw-alias-label-secondary, #646a73); font-size: 13px; line-height: 20px; white-space: nowrap; } .dim-channelCount { flex: none; padding: 6px 11px; border-radius: 999px; color: var(--dsw-alias-label-secondary, #646a73); background: var(--dsw-alias-fill-secondary, #f2f3f5); font-size: 11px; white-space: nowrap; } .dim-layout { display: grid; grid-template-columns: 188px 1px minmax(0, 1fr); gap: 26px; align-items: start; } .dim-rail { display: grid; gap: 12px; } .dim-channel { width: 100%; min-height: 76px; display: grid; grid-template-columns: 42px minmax(0, 1fr) 14px; align-items: center; gap: 12px; padding: 13px 12px; border: 1px solid transparent; border-radius: 16px; color: inherit; background: var(--dsw-alias-bg-layer-3, #fff); box-shadow: 0 5px 18px rgb(31 35 41 / 5%); font: inherit; text-align: left; cursor: pointer; transition: border-color .16s ease, background .16s ease, box-shadow .16s ease, transform .16s ease; } .dim-channel:hover { transform: translateY(-1px); border-color: color-mix(in srgb, var(--dim-blue) 25%, transparent); box-shadow: 0 8px 24px rgb(31 35 41 / 8%); } .dim-channel[aria-selected="true"] { border-color: color-mix(in srgb, var(--dim-blue) 52%, transparent); color: var(--dim-blue); background: var(--dim-blue-soft); box-shadow: 0 0 0 1px color-mix(in srgb, var(--dim-blue) 8%, transparent), 0 10px 26px rgb(51 112 255 / 10%); } .dim-channel:focus-visible { outline: 2px solid color-mix(in srgb, var(--dim-blue) 68%, white); outline-offset: 2px; } .dim-logo { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 12px; box-shadow: 0 1px 4px rgb(31 35 41 / 8%); } .dim-logo svg { display: block; width: 27px; height: 27px; } .dim-logoWeixin { color: white; background: #07c160; } .dim-logoWeixin svg { width: 25px; height: 25px; } .dim-logoFeishu { background: white; border: 1px solid var(--dsw-alias-line-border, #e5e6eb); } .dim-logoFeishu svg { width: 30px; height: 30px; } .dim-channelCopy { min-width: 0; display: grid; gap: 2px; } .dim-channelCopy strong { overflow: hidden; color: inherit; font-size: 15px; line-height: 21px; font-weight: 680; text-overflow: ellipsis; white-space: nowrap; } .dim-channelCopy small { overflow: hidden; color: var(--dsw-alias-label-tertiary, #8f959e); font-size: 10px; line-height: 16px; text-overflow: ellipsis; white-space: nowrap; } .dim-chevron { color: var(--dsw-alias-label-tertiary, #8f959e); font-size: 22px; line-height: 1; transform: translateY(-1px); } .dim-channel[aria-selected="true"] .dim-chevron { color: var(--dim-blue); } .dim-divider { width: 1px; min-height: 520px; background: var(--dsw-alias-line-divider, #eef0f3); } .dim-panel { min-width: 0; } .dim-panel .bxf-page, .dim-panel .dxw-page { width: 100%; max-width: none; padding: 0 0 24px; } .dim-panel .bxf-heading, .dim-panel .dxw-heading { justify-content: flex-end; } .dim-panel .bxf-headingTools, .dim-panel .dxw-tools { width: 100%; justify-content: flex-end; } @media (max-width: 840px) { .dim-title { align-items: flex-start; } .dim-layout { grid-template-columns: minmax(0, 1fr); gap: 18px; } .dim-rail { grid-template-columns: repeat(2, minmax(0, 1fr)); } .dim-divider { display: none; } .dim-channel { min-height: 68px; } } @media (max-width: 560px) { .dim-title { flex-direction: column; gap: 10px; } .dim-title p { white-space: normal; } .dim-rail { grid-template-columns: minmax(0, 1fr); } } @media (prefers-reduced-motion: reduce) { .dim-page * { transition-duration: .01ms !important; } } `; function installImStyles() { if (typeof document === "undefined") return () => { }; const existing = document.querySelector(`style[data-plugin-css="${IM_STYLE_ID}"]`); if (existing) return () => { }; const style = document.createElement("style"); style.dataset.plugin = "@xmanrui/dsh-im"; style.dataset.pluginCss = IM_STYLE_ID; style.textContent = CSS3; document.head.appendChild(style); return () => style.remove(); } // plugin-src/client/index.js var h3 = React3.createElement; var name = "im-settings"; var inject = ["slots", "connection"]; var CHANNELS = Object.freeze([ { id: "weixin", label: "\u5FAE\u4FE1", description: "\u626B\u7801\u7ED1\u5B9A" }, { id: "feishu", label: "\u98DE\u4E66", description: "\u626B\u7801\u63A5\u5165" } ]); function WeixinLogo() { return h3( "span", { className: "dim-logo dim-logoWeixin", "aria-hidden": "true" }, h3( "svg", { viewBox: "0 0 24 24", focusable: "false" }, h3("path", { fill: "currentColor", d: "M8.691 2.188C3.891 2.188 0 5.476 0 9.53c0 2.212 1.17 4.203 3.002 5.55a.59.59 0 0 1 .213.665l-.39 1.48c-.019.07-.048.141-.048.213 0 .163.13.295.29.295a.326.326 0 0 0 .167-.054l1.903-1.114a.864.864 0 0 1 .717-.098 10.16 10.16 0 0 0 2.837.403c.276 0 .543-.027.811-.05-.857-2.578.157-4.972 1.932-6.446 1.703-1.415 3.882-1.98 5.853-1.838-.576-3.583-4.196-6.348-8.596-6.348zM5.785 5.991c.642 0 1.162.529 1.162 1.18a1.17 1.17 0 0 1-1.162 1.178A1.17 1.17 0 0 1 4.623 7.17c0-.651.52-1.18 1.162-1.18zm5.813 0c.642 0 1.162.529 1.162 1.18a1.17 1.17 0 0 1-1.162 1.178 1.17 1.17 0 0 1-1.162-1.178c0-.651.52-1.18 1.162-1.18zm5.34 2.867c-1.797-.052-3.746.512-5.28 1.786-1.72 1.428-2.687 3.72-1.78 6.22.942 2.453 3.666 4.229 6.884 4.229.826 0 1.622-.12 2.361-.336a.722.722 0 0 1 .598.082l1.584.926a.272.272 0 0 0 .14.047c.134 0 .24-.111.24-.247 0-.06-.023-.12-.038-.177l-.327-1.233a.582.582 0 0 1-.023-.156.49.49 0 0 1 .201-.398C23.024 18.48 24 16.82 24 14.98c0-3.21-2.931-5.837-6.656-6.088V8.89c-.135-.01-.27-.027-.407-.03zm-2.53 3.274c.535 0 .969.44.969.982a.976.976 0 0 1-.969.983.976.976 0 0 1-.969-.983c0-.542.434-.982.97-.982zm4.844 0c.535 0 .969.44.969.982a.976.976 0 0 1-.969.983.976.976 0 0 1-.969-.983c0-.542.434-.982.969-.982z" }) ) ); } function FeishuLogo() { return h3( "span", { className: "dim-logo dim-logoFeishu", "aria-hidden": "true" }, h3( "svg", { viewBox: "0 0 24 24", focusable: "false" }, h3("path", { fill: "#00D6B9", d: "M7.2 4.5h7.6c1.2 0 2.1.55 2.7 1.58 1.05 1.8 1.55 3.45 1.58 4.95-2.04-.62-4.2-.15-6.22 1.45C11.3 9.7 9.42 7.04 7.2 4.5Z" }), h3("path", { fill: "#1456B8", d: "M10.8 13.55c3.3-2.93 5.72-4.24 9.47-2.52-1.2 1.45-2.27 4.18-3.86 5.43-1.67 1.31-3.9.5-5.61-.64v-2.27Z" }), h3("path", { fill: "#3370FF", d: "M4.4 8.35c3.47 3.61 7.25 6.1 10.33 5.7 1.06-.14 2.2-.72 3.4-1.72-1.04 2.65-2.6 4.8-5.06 6-2.46 1.2-5.56.52-7.42-.72A2.76 2.76 0 0 1 4.4 15.3V8.35Z" }) ) ); } function ChannelLogo({ channel }) { return channel === "weixin" ? h3(WeixinLogo) : h3(FeishuLogo); } function IMSettingsTab({ feishuRpcCall, weixinRpcCall }) { const [selected, setSelected] = React3.useState("weixin"); const active = CHANNELS.find((channel) => channel.id === selected) ?? CHANNELS[0]; return h3( "section", { className: "dim-page", "aria-label": "IM\u673A\u5668\u4EBA\u8BBE\u7F6E" }, h3( "header", { className: "dim-title" }, h3("p", null, "\u901A\u8FC7\u626B\u7801\u628A\u673A\u5668\u4EBA\u63A5\u5165 DeepSeek Harness"), h3("div", { className: "dim-channelCount" }, "2 \u4E2A\u6E20\u9053") ), h3( "div", { className: "dim-layout" }, h3( "nav", { className: "dim-rail", role: "tablist", "aria-label": "IM \u6E20\u9053" }, CHANNELS.map((channel) => h3( "button", { key: channel.id, type: "button", role: "tab", id: `dim-tab-${channel.id}`, className: "dim-channel", "aria-selected": channel.id === active.id, "aria-controls": `dim-panel-${channel.id}`, onClick: () => setSelected(channel.id) }, h3(ChannelLogo, { channel: channel.id }), h3( "span", { className: "dim-channelCopy" }, h3("strong", null, channel.label), h3("small", null, channel.description) ), h3("span", { className: "dim-chevron", "aria-hidden": "true" }, "\u203A") )) ), h3("div", { className: "dim-divider", "aria-hidden": "true" }), h3("main", { className: "dim-panel", role: "tabpanel", id: `dim-panel-${active.id}`, "aria-labelledby": `dim-tab-${active.id}` }, active.id === "weixin" ? h3(WeixinSettingsTab, { rpcCall: weixinRpcCall }) : h3(FeishuSettingsTab, { rpcCall: feishuRpcCall })) ) ); } function apply(ctx) { ctx.effect(() => { const disposers = [installFeishuStyles(), installWeixinStyles(), installImStyles()]; return () => { for (const dispose of disposers.reverse()) dispose(); }; }, "im-settings: install combined channel styles"); const feishuRpcCall = (endpoint, payload, signal) => ctx.connection.rpc.call(FEISHU_RPC_CHANNEL, endpoint, payload, signal); const weixinRpcCall = (endpoint, payload, signal) => ctx.connection.rpc.call(WEIXIN_RPC_CHANNEL, endpoint, payload, signal); ctx.slots.inject("settings.plugins.tab", () => ctx.slots.register({ name: "settings.plugins.tab", id: "im", order: 20, label: "IM\u673A\u5668\u4EBA", inject: () => ({ feishuRpcCall, weixinRpcCall }) }, IMSettingsTab)); } return module.exports; } });