nextclaw 0.13.35 → 0.13.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/index.js +8 -8
- package/package.json +9 -9
- package/ui-dist/assets/ChannelsList-DhM0gvDV.js +1 -0
- package/ui-dist/assets/{ChatPage-Dmpau_7n.js → ChatPage-4niJBFCu.js} +14 -14
- package/ui-dist/assets/{DocBrowser-C3ijFxFF.js → DocBrowser-DpXDQNhb.js} +1 -1
- package/ui-dist/assets/{LogoBadge-BgjXmBcw.js → LogoBadge-nqabOtgk.js} +1 -1
- package/ui-dist/assets/MarketplacePage-CrkTftqZ.js +49 -0
- package/ui-dist/assets/{McpMarketplacePage-DPtH1xcY.js → McpMarketplacePage-DH1qKJqo.js} +1 -1
- package/ui-dist/assets/ModelConfig-CrrxPK_y.js +1 -0
- package/ui-dist/assets/{ProvidersList-DnWsJqMQ.js → ProvidersList-BG36JlSJ.js} +1 -1
- package/ui-dist/assets/{RemoteAccessPage-BrXq-x0-.js → RemoteAccessPage-Dcj2Pzpt.js} +1 -1
- package/ui-dist/assets/{RuntimeConfig-UE9VaFO7.js → RuntimeConfig-BrxgUzjJ.js} +1 -1
- package/ui-dist/assets/{SearchConfig-CP-RM3V3.js → SearchConfig-D-NLwowp.js} +1 -1
- package/ui-dist/assets/{SecretsConfig-CfN_bazs.js → SecretsConfig-DjNqBB05.js} +1 -1
- package/ui-dist/assets/{SessionsConfig-CgkKzKGv.js → SessionsConfig-DdlsWXQc.js} +1 -1
- package/ui-dist/assets/{chat-message-CGL3sMsS.js → chat-message-B7THd1Mh.js} +1 -1
- package/ui-dist/assets/index-CgqD0Jfg.js +8 -0
- package/ui-dist/assets/index-UC08nscf.css +1 -0
- package/ui-dist/assets/{label-CbOSodIL.js → label-B-TkPZRF.js} +1 -1
- package/ui-dist/assets/{page-layout-BtDnyNLf.js → page-layout-BTVBRo6H.js} +1 -1
- package/ui-dist/assets/{popover-DGlUjPQc.js → popover-DBZvpGcL.js} +1 -1
- package/ui-dist/assets/{security-config-D6Bs1yoK.js → security-config-DotxwVFR.js} +1 -1
- package/ui-dist/assets/skeleton-DGtduHZV.js +1 -0
- package/ui-dist/assets/{status-dot-C8vM3IN1.js → status-dot-BCUTVN2R.js} +1 -1
- package/ui-dist/assets/{switch-AuwUiga3.js → switch-Bp2mda29.js} +1 -1
- package/ui-dist/assets/{tabs-custom-CTS7SaFG.js → tabs-custom-BE8yZ2kE.js} +1 -1
- package/ui-dist/assets/{useConfirmDialog-DrMAdNfN.js → useConfirmDialog-DCy-eYnV.js} +1 -1
- package/ui-dist/assets/{vendor-TJ2hy_Lv.js → vendor-DJt0Azq5.js} +90 -80
- package/ui-dist/index.html +3 -3
- package/ui-dist/assets/ChannelsList-Cu_hLbps.js +0 -1
- package/ui-dist/assets/MarketplacePage-CAIdEiw8.js +0 -49
- package/ui-dist/assets/ModelConfig-D-pqArCg.js +0 -1
- package/ui-dist/assets/index-D4alkESd.js +0 -8
- package/ui-dist/assets/index-SGSkQCPi.css +0 -1
- package/ui-dist/assets/skeleton-BLV99JbX.js +0 -1
package/dist/cli/index.js
CHANGED
|
@@ -1494,7 +1494,7 @@ function toExtensionRegistry(pluginRegistry) {
|
|
|
1494
1494
|
}
|
|
1495
1495
|
|
|
1496
1496
|
// src/cli/commands/plugins.ts
|
|
1497
|
-
import { mergePluginConfigView, toPluginConfigView } from "@nextclaw/openclaw-compat";
|
|
1497
|
+
import { mergePluginConfigView as mergePluginConfigView2, toPluginConfigView as toPluginConfigView2 } from "@nextclaw/openclaw-compat";
|
|
1498
1498
|
function loadPluginRegistry(config2, workspaceDir) {
|
|
1499
1499
|
const workspaceExtensionsDir = resolveDevFirstPartyPluginDir(process.env.NEXTCLAW_DEV_FIRST_PARTY_PLUGIN_DIR);
|
|
1500
1500
|
const configWithDevPluginPaths = applyDevFirstPartyPluginLoadPaths(
|
|
@@ -2829,7 +2829,7 @@ var ChannelCommands = class {
|
|
|
2829
2829
|
url: opts.url,
|
|
2830
2830
|
httpUrl: opts.httpUrl
|
|
2831
2831
|
};
|
|
2832
|
-
const currentView =
|
|
2832
|
+
const currentView = toPluginConfigView2(config2, bindings);
|
|
2833
2833
|
const accountId = binding.channel.config?.defaultAccountId?.(currentView) ?? "default";
|
|
2834
2834
|
const validateError = setup.validateInput?.({
|
|
2835
2835
|
cfg: currentView,
|
|
@@ -2849,7 +2849,7 @@ var ChannelCommands = class {
|
|
|
2849
2849
|
console.error("Channel setup returned invalid config payload.");
|
|
2850
2850
|
process.exit(1);
|
|
2851
2851
|
}
|
|
2852
|
-
let next =
|
|
2852
|
+
let next = mergePluginConfigView2(config2, nextView, bindings);
|
|
2853
2853
|
next = enablePluginInConfig2(next, binding.pluginId);
|
|
2854
2854
|
saveConfig5(next);
|
|
2855
2855
|
console.log(`Configured channel "${binding.channelId}" via plugin "${binding.pluginId}".`);
|
|
@@ -4670,13 +4670,13 @@ import { setPluginRuntimeBridge } from "@nextclaw/openclaw-compat";
|
|
|
4670
4670
|
function installPluginRuntimeBridge(params) {
|
|
4671
4671
|
const { runtimePool, runtimeConfigPath, pluginChannelBindings } = params;
|
|
4672
4672
|
setPluginRuntimeBridge({
|
|
4673
|
-
loadConfig: () =>
|
|
4673
|
+
loadConfig: () => toPluginConfigView2(resolveConfigSecrets2(loadConfig14(), { configPath: runtimeConfigPath }), pluginChannelBindings),
|
|
4674
4674
|
writeConfigFile: async (nextConfigView) => {
|
|
4675
4675
|
if (!nextConfigView || typeof nextConfigView !== "object" || Array.isArray(nextConfigView)) {
|
|
4676
4676
|
throw new Error("plugin runtime writeConfigFile expects an object config");
|
|
4677
4677
|
}
|
|
4678
4678
|
const current = loadConfig14();
|
|
4679
|
-
const next =
|
|
4679
|
+
const next = mergePluginConfigView2(current, nextConfigView, pluginChannelBindings);
|
|
4680
4680
|
saveConfig9(next);
|
|
4681
4681
|
},
|
|
4682
4682
|
dispatchReplyWithBufferedBlockDispatcher: async ({ ctx, dispatcherOptions }) => {
|
|
@@ -9327,7 +9327,7 @@ ${this.logo} ${APP_NAME5} is ready! (${source})`);
|
|
|
9327
9327
|
logPluginDiagnostics(pluginRegistry);
|
|
9328
9328
|
const pluginChannelBindings = getPluginChannelBindings4(pluginRegistry);
|
|
9329
9329
|
setPluginRuntimeBridge3({
|
|
9330
|
-
loadConfig: () =>
|
|
9330
|
+
loadConfig: () => toPluginConfigView2(
|
|
9331
9331
|
resolveConfigSecrets4(loadConfig18(), { configPath }),
|
|
9332
9332
|
pluginChannelBindings
|
|
9333
9333
|
),
|
|
@@ -9338,7 +9338,7 @@ ${this.logo} ${APP_NAME5} is ready! (${source})`);
|
|
|
9338
9338
|
);
|
|
9339
9339
|
}
|
|
9340
9340
|
const current = loadConfig18();
|
|
9341
|
-
const next =
|
|
9341
|
+
const next = mergePluginConfigView2(
|
|
9342
9342
|
current,
|
|
9343
9343
|
nextConfigView,
|
|
9344
9344
|
pluginChannelBindings
|
|
@@ -9681,7 +9681,7 @@ channels.command("status").description("Show channel status").action(() => runti
|
|
|
9681
9681
|
channels.command("login").description("Link device via QR code").option("--channel <id>", "Plugin channel id").option("--account <id>", "Channel account id").option("--url <url>", "Channel API base URL").option("--http-url <url>", "Alias for --url").option("-v, --verbose", "Verbose output", false).action(async (opts) => runtime.channelsLogin(opts));
|
|
9682
9682
|
var cron = program.command("cron").description("Manage scheduled tasks");
|
|
9683
9683
|
cron.command("list").option("-a, --all", "Include disabled jobs").action((opts) => runtime.cronList(opts));
|
|
9684
|
-
cron.command("add").requiredOption("-n, --name <name>", "Job name").requiredOption("-m, --message <message>", "Message for agent").option("-e, --every <seconds>", "Run every N seconds").option("-c, --cron <expr>", "Cron expression").option("--at <iso>", "Run once at time (ISO format)").option("-d, --deliver", "Deliver response to channel").option("--to <recipient>", "Recipient for delivery").option("--channel <channel>", "Channel for delivery").action((opts) => runtime.cronAdd(opts));
|
|
9684
|
+
cron.command("add").requiredOption("-n, --name <name>", "Job name").requiredOption("-m, --message <message>", "Message for agent").option("-e, --every <seconds>", "Run every N seconds").option("-c, --cron <expr>", "Cron expression").option("--at <iso>", "Run once at time (ISO format)").option("-d, --deliver", "Deliver response to channel").option("--to <recipient>", "Recipient for delivery").option("--channel <channel>", "Channel for delivery").option("--account <id>", "Account id for channel delivery").action((opts) => runtime.cronAdd(opts));
|
|
9685
9685
|
cron.command("remove <jobId>").action((jobId) => runtime.cronRemove(jobId));
|
|
9686
9686
|
cron.command("enable <jobId>").option("--disable", "Disable instead of enable").action((jobId, opts) => runtime.cronEnable(jobId, opts));
|
|
9687
9687
|
cron.command("run <jobId>").option("-f, --force", "Run even if disabled").action(async (jobId, opts) => runtime.cronRun(jobId, opts));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nextclaw",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.36",
|
|
4
4
|
"description": "Lightweight personal AI assistant with CLI, multi-provider routing, and channel integrations.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -40,15 +40,15 @@
|
|
|
40
40
|
"commander": "^12.1.0",
|
|
41
41
|
"yaml": "^2.8.1",
|
|
42
42
|
"@nextclaw/core": "0.9.11",
|
|
43
|
-
"@nextclaw/mcp": "0.1.29",
|
|
44
|
-
"@nextclaw/ncp-mcp": "0.1.29",
|
|
45
43
|
"@nextclaw/ncp": "0.3.1",
|
|
44
|
+
"@nextclaw/mcp": "0.1.28",
|
|
45
|
+
"@nextclaw/ncp-agent-runtime": "0.2.1",
|
|
46
|
+
"@nextclaw/remote": "0.1.26",
|
|
47
|
+
"@nextclaw/server": "0.10.32",
|
|
46
48
|
"@nextclaw/ncp-toolkit": "0.4.1",
|
|
47
|
-
"@nextclaw/
|
|
48
|
-
"@nextclaw/
|
|
49
|
-
"@nextclaw/openclaw-compat": "0.3.
|
|
50
|
-
"@nextclaw/server": "0.10.31",
|
|
51
|
-
"@nextclaw/ncp-agent-runtime": "0.2.1"
|
|
49
|
+
"@nextclaw/runtime": "0.2.11",
|
|
50
|
+
"@nextclaw/ncp-mcp": "0.1.28",
|
|
51
|
+
"@nextclaw/openclaw-compat": "0.3.16"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@types/node": "^20.17.6",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"tsx": "^4.19.2",
|
|
58
58
|
"typescript": "^5.6.3",
|
|
59
59
|
"vitest": "^2.1.2",
|
|
60
|
-
"@nextclaw/ui": "0.9.
|
|
60
|
+
"@nextclaw/ui": "0.9.16"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
63
63
|
"dev": "tsx watch --tsconfig tsconfig.json src/cli/index.ts",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as A,j as t,X as se,K as ne,aq as le,b1 as re,b2 as oe,b3 as ie,a0 as ce,g as G,f as me,b4 as _,ae as de,b5 as ue,ai as H,e as k,a3 as pe,i as xe,G as be,H as ye}from"./vendor-DJt0Azq5.js";import{Z as he,t as e,c as T,I as F,S as ge,e as we,f as fe,g as je,h as ve,$ as K,B as U,n as Ae,u as z,a as J,b as Q,a0 as Ne,a1 as Ce}from"./index-CgqD0Jfg.js";import{S as W}from"./status-dot-BCUTVN2R.js";import{L as Y}from"./LogoBadge-nqabOtgk.js";import{h as D}from"./config-hints-CApS3K_7.js";import{c as Se,b as ke,a as Ie,C as Pe}from"./config-layout-BHnOoweL.js";import{L as Te}from"./label-B-TkPZRF.js";import{S as Fe}from"./switch-Bp2mda29.js";import{T as Me}from"./tabs-custom-BE8yZ2kE.js";import{P as Le,a as Ue}from"./page-layout-BTVBRo6H.js";function V(a){var o,r;const n=he();return((o=a.tutorialUrls)==null?void 0:o[n])||((r=a.tutorialUrls)==null?void 0:r.default)||a.tutorialUrl}const De={telegram:"telegram.svg",slack:"slack.svg",discord:"discord.svg",whatsapp:"whatsapp.svg",qq:"qq.svg",feishu:"feishu.svg",dingtalk:"dingtalk.svg",wecom:"wecom.svg",weixin:"weixin.svg",mochat:"mochat.svg",email:"email.svg"};function Ee(a,n){const l=n.toLowerCase(),o=a[l];return o?`/logos/${o}`:null}function X(a){return Ee(De,a)}function Oe({value:a,onChange:n,className:l,placeholder:o=""}){const[r,u]=A.useState(""),i=m=>{m.key==="Enter"&&r.trim()?(m.preventDefault(),n([...a,r.trim()]),u("")):m.key==="Backspace"&&!r&&a.length>0&&n(a.slice(0,-1))},s=m=>{n(a.filter((w,y)=>y!==m))};return t.jsxs("div",{className:T("flex flex-wrap gap-2 p-2 border rounded-md min-h-[42px]",l),children:[a.map((m,w)=>t.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 bg-primary text-primary-foreground rounded text-sm",children:[m,t.jsx("button",{type:"button",onClick:()=>s(w),className:"hover:text-red-300 transition-colors",children:t.jsx(se,{className:"h-3 w-3"})})]},w)),t.jsx("input",{type:"text",value:r,onChange:m=>u(m.target.value),onKeyDown:i,className:"flex-1 outline-none min-w-[100px] bg-transparent text-sm",placeholder:o||e("enterTag")})]})}function _e(a){return a.includes("token")||a.includes("secret")||a.includes("password")?t.jsx(ne,{className:"h-3.5 w-3.5 text-gray-500"}):a.includes("url")||a.includes("host")?t.jsx(le,{className:"h-3.5 w-3.5 text-gray-500"}):a.includes("email")||a.includes("mail")?t.jsx(re,{className:"h-3.5 w-3.5 text-gray-500"}):a.includes("id")||a.includes("from")?t.jsx(oe,{className:"h-3.5 w-3.5 text-gray-500"}):a==="enabled"||a==="consentGranted"?t.jsx(ie,{className:"h-3.5 w-3.5 text-gray-500"}):t.jsx(ce,{className:"h-3.5 w-3.5 text-gray-500"})}function q({channelName:a,fields:n,formData:l,jsonDrafts:o,setJsonDrafts:r,updateField:u,uiHints:i}){return t.jsx(t.Fragment,{children:n.map(s=>{const m=D(`channels.${a}.${s.name}`,i),w=(m==null?void 0:m.label)??s.label,y=m==null?void 0:m.placeholder;return t.jsxs("div",{className:"space-y-2.5",children:[t.jsxs(Te,{htmlFor:s.name,className:"flex items-center gap-2 text-sm font-medium text-gray-900",children:[_e(s.name),w]}),s.type==="boolean"&&t.jsxs("div",{className:"flex items-center justify-between rounded-xl bg-gray-50 p-3",children:[t.jsx("span",{className:"text-sm text-gray-500",children:l[s.name]?e("enabled"):e("disabled")}),t.jsx(Fe,{id:s.name,checked:l[s.name]||!1,onCheckedChange:c=>u(s.name,c),className:"data-[state=checked]:bg-emerald-500"})]}),(s.type==="text"||s.type==="email")&&t.jsx(F,{id:s.name,type:s.type,value:l[s.name]||"",onChange:c=>u(s.name,c.target.value),placeholder:y,className:"rounded-xl"}),s.type==="password"&&t.jsx(F,{id:s.name,type:"password",value:l[s.name]||"",onChange:c=>u(s.name,c.target.value),placeholder:y??e("leaveBlankToKeepUnchanged"),className:"rounded-xl"}),s.type==="number"&&t.jsx(F,{id:s.name,type:"number",value:l[s.name]||0,onChange:c=>u(s.name,parseInt(c.target.value,10)||0),placeholder:y,className:"rounded-xl"}),s.type==="tags"&&t.jsx(Oe,{value:l[s.name]||[],onChange:c=>u(s.name,c)}),s.type==="select"&&t.jsxs(ge,{value:l[s.name]||"",onValueChange:c=>u(s.name,c),children:[t.jsx(we,{className:"rounded-xl",children:t.jsx(fe,{})}),t.jsx(je,{children:(s.options??[]).map(c=>t.jsx(ve,{value:c.value,children:c.label},c.value))})]}),s.type==="json"&&t.jsx("textarea",{id:s.name,value:o[s.name]??"{}",onChange:c=>r(f=>({...f,[s.name]:c.target.value})),className:"min-h-[120px] w-full resize-none rounded-lg border border-gray-200 bg-white px-3 py-2 text-xs font-mono"})]},s.name)})})}const B=[{value:"pairing",label:"pairing"},{value:"allowlist",label:"allowlist"},{value:"open",label:"open"},{value:"disabled",label:"disabled"}],R=[{value:"open",label:"open"},{value:"allowlist",label:"allowlist"},{value:"disabled",label:"disabled"}],qe=[{value:"off",label:"off"},{value:"partial",label:"partial"},{value:"block",label:"block"},{value:"progress",label:"progress"}];function $(){return{telegram:[{name:"enabled",type:"boolean",label:e("enabled")},{name:"token",type:"password",label:e("botToken")},{name:"allowFrom",type:"tags",label:e("allowFrom")},{name:"proxy",type:"text",label:e("proxy")},{name:"accountId",type:"text",label:e("accountId")},{name:"dmPolicy",type:"select",label:e("dmPolicy"),options:B},{name:"groupPolicy",type:"select",label:e("groupPolicy"),options:R},{name:"groupAllowFrom",type:"tags",label:e("groupAllowFrom")},{name:"requireMention",type:"boolean",label:e("requireMention")},{name:"mentionPatterns",type:"tags",label:e("mentionPatterns")},{name:"groups",type:"json",label:e("groupRulesJson")}],discord:[{name:"enabled",type:"boolean",label:e("enabled")},{name:"token",type:"password",label:e("botToken")},{name:"allowBots",type:"boolean",label:e("allowBotMessages")},{name:"allowFrom",type:"tags",label:e("allowFrom")},{name:"gatewayUrl",type:"text",label:e("gatewayUrl")},{name:"intents",type:"number",label:e("intents")},{name:"proxy",type:"text",label:e("proxy")},{name:"mediaMaxMb",type:"number",label:e("attachmentMaxSizeMb")},{name:"streaming",type:"select",label:e("streamingMode"),options:qe},{name:"draftChunk",type:"json",label:e("draftChunkingJson")},{name:"textChunkLimit",type:"number",label:e("textChunkLimit")},{name:"accountId",type:"text",label:e("accountId")},{name:"dmPolicy",type:"select",label:e("dmPolicy"),options:B},{name:"groupPolicy",type:"select",label:e("groupPolicy"),options:R},{name:"groupAllowFrom",type:"tags",label:e("groupAllowFrom")},{name:"requireMention",type:"boolean",label:e("requireMention")},{name:"mentionPatterns",type:"tags",label:e("mentionPatterns")},{name:"groups",type:"json",label:e("groupRulesJson")}],whatsapp:[{name:"enabled",type:"boolean",label:e("enabled")},{name:"bridgeUrl",type:"text",label:e("bridgeUrl")},{name:"allowFrom",type:"tags",label:e("allowFrom")}],feishu:[{name:"enabled",type:"boolean",label:e("enabled")},{name:"appId",type:"text",label:e("appId")},{name:"appSecret",type:"password",label:e("appSecret")},{name:"encryptKey",type:"password",label:e("encryptKey")},{name:"verificationToken",type:"password",label:e("verificationToken")},{name:"allowFrom",type:"tags",label:e("allowFrom")}],dingtalk:[{name:"enabled",type:"boolean",label:e("enabled")},{name:"clientId",type:"text",label:e("clientId")},{name:"clientSecret",type:"password",label:e("clientSecret")},{name:"allowFrom",type:"tags",label:e("allowFrom")}],wecom:[{name:"enabled",type:"boolean",label:e("enabled")},{name:"corpId",type:"text",label:e("corpId")},{name:"agentId",type:"text",label:e("agentId")},{name:"secret",type:"password",label:e("secret")},{name:"token",type:"password",label:e("token")},{name:"callbackPort",type:"number",label:e("callbackPort")},{name:"callbackPath",type:"text",label:e("callbackPath")},{name:"allowFrom",type:"tags",label:e("allowFrom")}],weixin:[{name:"enabled",type:"boolean",label:e("enabled")},{name:"defaultAccountId",type:"text",label:e("defaultAccountId")},{name:"baseUrl",type:"text",label:e("baseUrl")},{name:"pollTimeoutMs",type:"number",label:e("pollTimeoutMs")},{name:"allowFrom",type:"tags",label:e("allowFrom")},{name:"accounts",type:"json",label:e("accountsJson")}],slack:[{name:"enabled",type:"boolean",label:e("enabled")},{name:"mode",type:"text",label:e("mode")},{name:"webhookPath",type:"text",label:e("webhookPath")},{name:"allowBots",type:"boolean",label:e("allowBotMessages")},{name:"botToken",type:"password",label:e("botToken")},{name:"appToken",type:"password",label:e("appToken")}],email:[{name:"enabled",type:"boolean",label:e("enabled")},{name:"consentGranted",type:"boolean",label:e("consentGranted")},{name:"imapHost",type:"text",label:e("imapHost")},{name:"imapPort",type:"number",label:e("imapPort")},{name:"imapUsername",type:"text",label:e("imapUsername")},{name:"imapPassword",type:"password",label:e("imapPassword")},{name:"fromAddress",type:"email",label:e("fromAddress")}],mochat:[{name:"enabled",type:"boolean",label:e("enabled")},{name:"baseUrl",type:"text",label:e("baseUrl")},{name:"clawToken",type:"password",label:e("clawToken")},{name:"agentUserId",type:"text",label:e("agentUserId")},{name:"allowFrom",type:"tags",label:e("allowFrom")}],qq:[{name:"enabled",type:"boolean",label:e("enabled")},{name:"appId",type:"text",label:e("appId")},{name:"secret",type:"password",label:e("appSecret")},{name:"markdownSupport",type:"boolean",label:e("markdownSupport")},{name:"allowFrom",type:"tags",label:e("allowFrom")}]}}async function Be(a,n={}){const l=await K.post(`/api/config/channels/${a}/auth/start`,n);if(!l.ok)throw new Error(l.error.message);return l.data}async function Re(a,n){const l=await K.post(`/api/config/channels/${a}/auth/poll`,n);if(!l.ok)throw new Error(l.error.message);return l.data}function $e(){return G({mutationFn:({channel:a,data:n})=>Be(a,n)})}function Ge(){return G({mutationFn:({channel:a,data:n})=>Re(a,n)})}function He(a){const n=a.accounts,l=new Set;if(typeof a.defaultAccountId=="string"&&a.defaultAccountId.trim()&&l.add(a.defaultAccountId.trim()),n&&typeof n=="object"&&!Array.isArray(n))for(const o of Object.keys(n)){const r=o.trim();r&&l.add(r)}return[...l]}function Ke(a,n){if(typeof a.baseUrl=="string"&&a.baseUrl.trim())return a.baseUrl.trim();if(typeof n.baseUrl=="string"&&n.baseUrl.trim())return n.baseUrl.trim()}function ze({channelConfig:a,formData:n,disabled:l=!1}){const o=me(),r=$e(),u=Ge(),[i,s]=A.useState(null),[m,w]=A.useState(null),y=A.useMemo(()=>He(a),[a]),c=y[0],f=Ke(n,a),j=y.length>0;A.useEffect(()=>{if(!i)return;let h=!1,N=null;const I=async()=>{try{const v=await u.mutateAsync({channel:"weixin",data:{sessionId:i.sessionId}});if(h)return;if(w(v),v.status==="authorized"){await o.invalidateQueries({queryKey:["config"]}),await o.invalidateQueries({queryKey:["config-meta"]}),k.success(v.message||e("weixinAuthAuthorized")),s(null);return}if(v.status==="expired"||v.status==="error"){k.error(v.message||e("weixinAuthRetryRequired")),s(null);return}N=setTimeout(I,v.nextPollMs??i.intervalMs)}catch(v){if(h)return;const P=v instanceof Error?v.message:String(v);k.error(`${e("error")}: ${P}`),s(null)}};return N=setTimeout(I,i.intervalMs),()=>{h=!0,N&&clearTimeout(N)}},[i,u,o]);const d=async()=>{try{const h=await r.mutateAsync({channel:"weixin",data:{baseUrl:f,accountId:typeof n.defaultAccountId=="string"&&n.defaultAccountId.trim()?n.defaultAccountId.trim():void 0}});s(h),w({channel:"weixin",status:"pending",message:h.note,nextPollMs:h.intervalMs})}catch(h){const N=h instanceof Error?h.message:String(h);k.error(`${e("error")}: ${N}`)}},b=i?(m==null?void 0:m.status)==="scanned"?e("weixinAuthScanned"):e("weixinAuthWaiting"):j?e("weixinAuthAuthorized"):e("weixinAuthNotConnected"),C=r.isPending?e("weixinAuthStarting"):i?e("weixinAuthWaiting"):j?e("weixinAuthReconnect"):e("weixinAuthConnect");return t.jsx("section",{className:"rounded-2xl border border-primary/20 bg-gradient-to-br from-primary-50/70 via-white to-emerald-50/60 p-5",children:t.jsxs("div",{className:"flex flex-col gap-4 lg:flex-row lg:items-start lg:justify-between",children:[t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"inline-flex items-center gap-2 rounded-full bg-white/90 px-3 py-1 text-xs font-medium text-primary shadow-sm",children:[t.jsx(_,{className:"h-3.5 w-3.5"}),e("weixinAuthTitle")]}),t.jsxs("div",{children:[t.jsx("h4",{className:"text-base font-semibold text-gray-900",children:e("weixinAuthDescription")}),t.jsx("p",{className:"mt-1 text-sm text-gray-600",children:e("weixinAuthHint")})]}),t.jsxs("div",{className:T("inline-flex w-fit items-center gap-2 rounded-full px-3 py-1 text-xs font-medium",i?"bg-amber-50 text-amber-700":j?"bg-emerald-50 text-emerald-700":"bg-gray-100 text-gray-600"),children:[i?t.jsx(de,{className:"h-3.5 w-3.5 animate-spin"}):t.jsx(ue,{className:"h-3.5 w-3.5"}),b]}),t.jsxs("div",{className:"space-y-1 text-sm text-gray-600",children:[t.jsx("p",{children:e("weixinAuthCapabilityHint")}),c?t.jsxs("p",{children:[e("weixinAuthPrimaryAccount"),": ",t.jsx("span",{className:"font-mono text-xs text-gray-900",children:c})]}):null,y.length>1?t.jsxs("p",{children:[e("weixinAuthConnectedAccounts"),": ",t.jsx("span",{className:"font-mono text-xs text-gray-900",children:y.join(", ")})]}):null,f?t.jsxs("p",{children:[e("weixinAuthBaseUrl"),": ",t.jsx("span",{className:"font-mono text-xs text-gray-900",children:f})]}):null]}),t.jsx(U,{type:"button",onClick:d,disabled:l||r.isPending||!!i,className:"rounded-xl",children:C})]}),t.jsx("div",{className:"w-full max-w-sm rounded-2xl border border-dashed border-primary/25 bg-white/85 p-4 shadow-sm",children:i?t.jsxs("div",{className:"space-y-3",children:[t.jsx("div",{className:"overflow-hidden rounded-2xl border border-gray-100 bg-white p-3",children:t.jsx("img",{src:i.qrCodeUrl,alt:e("weixinAuthQrAlt"),className:"mx-auto aspect-square w-full max-w-[240px] object-contain"})}),t.jsxs("div",{className:"space-y-1 text-xs text-gray-500",children:[t.jsx("p",{children:(m==null?void 0:m.message)||i.note||e("weixinAuthScanPrompt")}),t.jsxs("p",{children:[e("weixinAuthExpiresAt"),": ",Ae(i.expiresAt)]})]}),t.jsxs("a",{href:i.qrCodeUrl,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1.5 text-xs text-primary transition-colors hover:text-primary-hover",children:[t.jsx(H,{className:"h-3.5 w-3.5"}),e("weixinAuthOpenQr")]})]}):t.jsxs("div",{className:"flex min-h-[280px] flex-col items-center justify-center rounded-2xl bg-gray-50/80 px-6 text-center",children:[t.jsx(_,{className:"h-9 w-9 text-gray-300"}),t.jsx("p",{className:"mt-3 text-sm font-medium text-gray-700",children:e("weixinAuthReadyTitle")}),t.jsx("p",{className:"mt-1 text-xs leading-5 text-gray-500",children:e("weixinAuthReadyDescription")})]})})]})})}function M(a){return typeof a=="object"&&a!==null&&!Array.isArray(a)}function Z(a,n){const l={...a};for(const[o,r]of Object.entries(n)){const u=l[o];if(M(u)&&M(r)){l[o]=Z(u,r);continue}l[o]=r}return l}function Je(a,n){const l=a.split("."),o={};let r=o;for(let u=0;u<l.length-1;u+=1){const i=l[u];r[i]={},r=r[i]}return r[l[l.length-1]]=n,o}function Qe({channelName:a}){var E,O;const{data:n}=z(),{data:l}=J(),{data:o}=Q(),r=Ne(),u=Ce(),[i,s]=A.useState({}),[m,w]=A.useState({}),[y,c]=A.useState(null),f=a?n==null?void 0:n.channels[a]:null,j=a?$()[a]??[]:[],d=o==null?void 0:o.uiHints,b=a?`channels.${a}`:null,C=((E=o==null?void 0:o.actions)==null?void 0:E.filter(p=>p.scope===b))??[],h=a&&(((O=D(`channels.${a}`,d))==null?void 0:O.label)??a),N=l==null?void 0:l.channels.find(p=>p.name===a),I=N?V(N):void 0,v=a==="weixin";A.useEffect(()=>{if(f){s({...f});const p={};(a?$()[a]??[]:[]).filter(x=>x.type==="json").forEach(x=>{const S=f[x.name];p[x.name]=JSON.stringify(S??{},null,2)}),w(p)}else s({}),w({})},[f,a]);const P=(p,g)=>{s(x=>({...x,[p]:g}))},ee=p=>{if(p.preventDefault(),!a)return;const g={...i};for(const x of j){if(x.type!=="password")continue;const S=g[x.name];(typeof S!="string"||S.length===0)&&delete g[x.name]}for(const x of j){if(x.type!=="json")continue;const S=m[x.name]??"";try{g[x.name]=S.trim()?JSON.parse(S):{}}catch{k.error(`${e("invalidJson")}: ${x.name}`);return}}r.mutate({channel:a,data:g})},te=p=>{if(!p||!a)return;const g=p.channels;if(!M(g))return;const x=g[a];M(x)&&s(S=>Z(S,x))},ae=async p=>{if(!(!a||!b)){c(p.id);try{let g={...i};p.saveBeforeRun&&(g={...g,...p.savePatch??{}},s(g),await r.mutateAsync({channel:a,data:g}));const x=await u.mutateAsync({actionId:p.id,data:{scope:b,draftConfig:Je(b,g)}});te(x.patch),x.ok?k.success(x.message||e("success")):k.error(x.message||e("error"))}catch(g){const x=g instanceof Error?g.message:String(g);k.error(`${e("error")}: ${x}`)}finally{c(null)}}};if(!a||!N||!f)return t.jsx("div",{className:Se,children:t.jsxs("div",{children:[t.jsx("h3",{className:"text-base font-semibold text-gray-900",children:e("channelsSelectTitle")}),t.jsx("p",{className:"mt-2 text-sm text-gray-500",children:e("channelsSelectDescription")})]})});const L=!!f.enabled;return t.jsxs("div",{className:ke,children:[t.jsx("div",{className:"border-b border-gray-100 px-6 py-5",children:t.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx(Y,{name:a,src:X(a),className:T("h-9 w-9 rounded-lg border",L?"border-primary/30 bg-white":"border-gray-200/70 bg-white"),imgClassName:"h-5 w-5 object-contain",fallback:t.jsx("span",{className:"text-sm font-semibold uppercase text-gray-500",children:a[0]})}),t.jsx("h3",{className:"truncate text-lg font-semibold text-gray-900 capitalize",children:h})]}),t.jsx("p",{className:"mt-2 text-sm text-gray-500",children:e("channelsFormDescription")}),I&&t.jsxs("a",{href:I,className:"mt-2 inline-flex items-center gap-1.5 text-xs text-primary transition-colors hover:text-primary-hover",children:[t.jsx(pe,{className:"h-3.5 w-3.5"}),e("channelsGuideTitle")]})]}),t.jsx(W,{status:L?"active":"inactive",label:L?e("statusActive"):e("statusInactive")})]})}),t.jsxs("form",{onSubmit:ee,className:"flex min-h-0 flex-1 flex-col",children:[t.jsx("div",{className:"min-h-0 flex-1 space-y-6 overflow-y-auto overscroll-contain px-6 py-5",children:v?t.jsxs(t.Fragment,{children:[t.jsx(ze,{channelConfig:f,formData:i,disabled:r.isPending||!!y}),t.jsxs("details",{className:"group rounded-2xl border border-gray-200/80 bg-white",children:[t.jsxs("summary",{className:"flex cursor-pointer list-none items-center justify-between gap-3 px-5 py-4 text-sm font-medium text-gray-900",children:[t.jsxs("div",{children:[t.jsx("p",{children:e("weixinAuthAdvancedTitle")}),t.jsx("p",{className:"mt-1 text-xs font-normal text-gray-500",children:e("weixinAuthAdvancedDescription")})]}),t.jsx(xe,{className:"h-4 w-4 text-gray-400 transition-transform group-open:rotate-180"})]}),t.jsx("div",{className:"space-y-6 border-t border-gray-100 px-5 py-5",children:t.jsx(q,{channelName:a,fields:j,formData:i,jsonDrafts:m,setJsonDrafts:w,updateField:P,uiHints:d})})]})]}):t.jsx(q,{channelName:a,fields:j,formData:i,jsonDrafts:m,setJsonDrafts:w,updateField:P,uiHints:d})}),t.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 border-t border-gray-100 px-6 py-4",children:[t.jsx("div",{className:"flex flex-wrap items-center gap-2",children:C.filter(p=>p.trigger==="manual").map(p=>t.jsx(U,{type:"button",onClick:()=>ae(p),disabled:r.isPending||!!y,variant:"secondary",children:y===p.id?e("connecting"):p.title},p.id))}),t.jsx(U,{type:"submit",disabled:r.isPending||!!y,children:r.isPending?e("saving"):e("save")})]})]})]})}const We={telegram:"channelDescTelegram",slack:"channelDescSlack",email:"channelDescEmail",webhook:"channelDescWebhook",discord:"channelDescDiscord",feishu:"channelDescFeishu",weixin:"channelDescWeixin"};function rt(){const{data:a}=z(),{data:n}=J(),{data:l}=Q(),[o,r]=A.useState("enabled"),[u,i]=A.useState(),[s,m]=A.useState(""),w=l==null?void 0:l.uiHints,y=n==null?void 0:n.channels,c=a==null?void 0:a.channels,f=[{id:"enabled",label:e("channelsTabEnabled"),count:(y??[]).filter(d=>{var b;return(b=c==null?void 0:c[d.name])==null?void 0:b.enabled}).length},{id:"all",label:e("channelsTabAll"),count:(y??[]).length}],j=A.useMemo(()=>{const d=s.trim().toLowerCase();return(y??[]).filter(b=>{var h;const C=((h=c==null?void 0:c[b.name])==null?void 0:h.enabled)||!1;return o==="enabled"?C:!0}).filter(b=>d?(b.displayName||b.name).toLowerCase().includes(d)||b.name.toLowerCase().includes(d):!0)},[o,c,y,s]);return A.useEffect(()=>{if(j.length===0){i(void 0);return}j.some(b=>b.name===u)||i(j[0].name)},[j,u]),!a||!n?t.jsx("div",{className:"p-8 text-gray-400",children:e("channelsLoading")}):t.jsxs(Le,{className:"xl:flex xl:h-full xl:min-h-0 xl:flex-col xl:pb-0",children:[t.jsx(Ue,{title:e("channelsPageTitle"),description:e("channelsPageDescription")}),t.jsxs("div",{className:T(Pe,"xl:min-h-0 xl:flex-1"),children:[t.jsxs("section",{className:Ie,children:[t.jsx("div",{className:"border-b border-gray-100 px-4 pt-4",children:t.jsx(Me,{tabs:f,activeTab:o,onChange:r,className:"mb-0"})}),t.jsx("div",{className:"border-b border-gray-100 px-4 py-3",children:t.jsxs("div",{className:"relative",children:[t.jsx(be,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"}),t.jsx(F,{value:s,onChange:d=>m(d.target.value),placeholder:e("channelsFilterPlaceholder"),className:"h-10 rounded-xl pl-9"})]})}),t.jsxs("div",{className:"min-h-0 flex-1 space-y-2 overflow-y-auto overscroll-contain p-3",children:[j.map(d=>{const b=a.channels[d.name],C=(b==null?void 0:b.enabled)||!1,h=D(`channels.${d.name}`,w),N=V(d),I=(h==null?void 0:h.help)||e(We[d.name]||"channelDescriptionDefault"),v=u===d.name;return t.jsx("button",{type:"button",onClick:()=>i(d.name),className:T("w-full rounded-xl border p-2.5 text-left transition-all",v?"border-primary/30 bg-primary-50/40 shadow-sm":"border-gray-200/70 bg-white hover:border-gray-300 hover:bg-gray-50/70"),children:t.jsxs("div",{className:"flex items-start justify-between gap-3",children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[t.jsx(Y,{name:d.name,src:X(d.name),className:T("h-10 w-10 rounded-lg border",C?"border-primary/30 bg-white":"border-gray-200/70 bg-white"),imgClassName:"h-5 w-5 object-contain",fallback:t.jsx("span",{className:"text-sm font-semibold uppercase text-gray-500",children:d.name[0]})}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:"truncate text-sm font-semibold text-gray-900",children:d.displayName||d.name}),t.jsx("p",{className:"line-clamp-1 text-[11px] text-gray-500",children:I})]})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[N&&t.jsx("a",{href:N,onClick:P=>P.stopPropagation(),className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-gray-300 transition-colors hover:bg-gray-100/70 hover:text-gray-500",title:e("channelsGuideTitle"),children:t.jsx(H,{className:"h-3.5 w-3.5"})}),t.jsx(W,{status:C?"active":"inactive",label:C?e("statusActive"):e("statusInactive"),className:"min-w-[56px] justify-center"})]})]})},d.name)}),j.length===0&&t.jsxs("div",{className:"flex h-full min-h-[220px] flex-col items-center justify-center rounded-xl border border-dashed border-gray-200 bg-gray-50/70 py-10 text-center",children:[t.jsx("div",{className:"mb-3 flex h-10 w-10 items-center justify-center rounded-lg bg-white",children:t.jsx(ye,{className:"h-5 w-5 text-gray-300"})}),t.jsx("p",{className:"text-sm font-medium text-gray-700",children:e("channelsNoMatch")})]})]})]}),t.jsx(Qe,{channelName:u})]})]})}export{rt as ChannelsList};
|