shennian 0.2.104 → 0.2.106
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.
|
@@ -411,8 +411,8 @@
|
|
|
411
411
|
},
|
|
412
412
|
{
|
|
413
413
|
"file": "src/commands/wechat/ipc.js",
|
|
414
|
-
"beforeBytes":
|
|
415
|
-
"afterBytes":
|
|
414
|
+
"beforeBytes": 5656,
|
|
415
|
+
"afterBytes": 3272
|
|
416
416
|
},
|
|
417
417
|
{
|
|
418
418
|
"file": "src/commands/wechat/operations.js",
|
|
@@ -421,8 +421,8 @@
|
|
|
421
421
|
},
|
|
422
422
|
{
|
|
423
423
|
"file": "src/commands/wechat/output.js",
|
|
424
|
-
"beforeBytes":
|
|
425
|
-
"afterBytes":
|
|
424
|
+
"beforeBytes": 12200,
|
|
425
|
+
"afterBytes": 7478
|
|
426
426
|
},
|
|
427
427
|
{
|
|
428
428
|
"file": "src/commands/wechat/types.js",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import p from"node:fs";import d from"node:path";import{resolveShennianPath as m}from"../../config/index.js";import{weChatChannelConversationId as w}from"../../channels/wechat-rpa/product-channel.js";import{clampPositiveInteger as
|
|
1
|
+
import p from"node:fs";import d from"node:path";import{resolveShennianPath as m}from"../../config/index.js";import{weChatChannelConversationId as w}from"../../channels/wechat-rpa/product-channel.js";import{clampPositiveInteger as f,isAbortError as I,processExists as g,safePathSegment as y,stableId as v}from"./utils.js";function c(){const r=m("runtime","manager-ipc.json");let e;try{e=JSON.parse(p.readFileSync(r,"utf-8"))}catch{throw new Error("Manager IPC is not available. Open Shennian Desktop or run `shennian start` first.")}const t=Number(e.pid);if(Number.isInteger(t)&&t>0&&!g(t))throw new Error(`Manager IPC runtime file is stale for PID ${t}. Restart Shennian Desktop or run \`shennian restart\`.`);const n=typeof e.url=="string"?e.url.replace(/\/+$/,""):"",o=typeof e.token=="string"?e.token:"";if(!n||!o)throw new Error(`Manager IPC runtime file is incomplete: ${r}`);return{url:n,token:o}}function C(){try{return c()}catch{return null}}function $(r){if(r.directRuntime)return null;const e=r.transport??"auto";if(e==="direct")return null;if(r.ipc)return{ctx:r.ipc,mode:"session"};if(r.sessionId?.trim())return{ctx:c(),mode:"session"};if(e==="daemon")return{ctx:c(),mode:"tool"};if(S(r)){const t=C();if(t)return{ctx:t,mode:"tool"}}return null}function S(r){return(r.platform??process.platform)==="win32"}function D(r,e){if((r.transport??"auto")!=="auto"||r.sessionId?.trim()||r.ipc)return!1;const n=e instanceof Error?e.message:String(e||"");return/Unknown manager IPC path:\s*\/wechat-rpa\/tool\//i.test(n)}async function E(r,e,t){return h(r,"/wechat-rpa/channel/upsert",{managerSessionId:e.sessionId,id:e.channelId,name:`WeChat ${e.conversationName}`,workDir:e.workDir,enabled:!0,groups:[{name:e.conversationName}],canReply:!0,source:t.source||"wechat-channel",recentLimit:f(t.recentLimit,20),pollIntervalMs:f(t.pollIntervalMs,3e4),forceForeground:!0,downloadAttachments:t.download!=="never",privacyConsentAccepted:!0},t.fetchImpl,t.timeoutMs)}async function h(r,e,t,n=fetch,o){const l=String(t.managerSessionId||"");if(!l)throw new Error("managerSessionId is required");const s=o?new AbortController:null,u=s?setTimeout(()=>s.abort(),o):null;try{const a=await n(`${r.url}${e}`,{method:"POST",headers:{authorization:`Bearer ${r.token}`,"content-type":"application/json","x-shennian-manager-session-id":l},body:JSON.stringify(t),signal:s?.signal}),i=await a.json().catch(()=>({ok:!1,error:a.statusText}));if(!a.ok||!i.ok)throw new Error(i.error||`Manager IPC failed: ${a.status}`);return i}finally{u&&clearTimeout(u)}}function F(r){const e=r.conversation.trim();if(!e)throw new Error("--conversation is required");const t=v("wechat-cli-conversation",e),n=r.sessionId?.trim()||`wechat-cli-${t.slice(-24)}`,o=`wechat-rpa:${n}`;return{sessionId:n,channelId:o,conversationId:w(e),conversationName:e,workDir:d.resolve(r.workDir||m("wechat-cli",y(e)))}}async function N(r,e,t){try{return await h(r,"/wechat-rpa/channel/sync",{managerSessionId:e.sessionId},t.fetchImpl,t.timeoutMs)}catch(n){if(I(n))return null;throw n}}export{F as buildWeChatToolBinding,E as ensureWeChatToolChannel,h as ipc,c as loadManagerIpcFromRuntimeFile,$ as resolveWeChatManagerIpc,D as shouldFallbackManagerToolToDirect,C as tryLoadManagerIpcFromRuntimeFile,N as trySyncWeChatToolChannel};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
`;for(const n of e.messages)t.push(`${
|
|
1
|
+
import b from"node:path";import{cleanInline as a,stringValue as o}from"./utils.js";const y=["SHENNIAN_WECHAT_CHANNEL_HELPER_DIR","SHENNIAN_HELPER_RUNTIME_DIR","packages/helper-runtime/wechat-channel","packages\\helper-runtime\\wechat-channel","packages/helper-runtime/dist","packages\\helper-runtime\\dist","wechat-rpa-windows-product-send-runner","PowerShell one-shot runner","activity.snapshot","automation.lease."],w=new Set(["wechat_not_running","wechat_window_not_found"]);function x(e,t){if(t){console.log(JSON.stringify(e,null,2));return}console.log(e.sendStatus)}function H(e,t){if(t==="json"){console.log(JSON.stringify(e,null,2));return}console.log(W(e).trimEnd())}function M(e,t,n,i){const r=k(e,t,n);i?console.log(JSON.stringify(r,null,2)):console.error(`${r.reasonCode}: ${r.message}`),process.exitCode=1}function k(e,t,n){const i=n instanceof Error?n.message:String(n||"wechat_tool_failed"),r=a(i)||"wechat_tool_failed",c=/^([a-z][a-z0-9_]*)(?::\s*(.*))?$/i.exec(r),s=o(n?.reasonCode)||c?.[1]||"wechat_tool_failed",l=q(s,r),_=a(c?.[2]||r),v=R(l,_,s),h=o(n?.outDir),d=o(n?.helperTracePath),p=o(n?.activityGuardPath),m=o(n?.traceId),f=E(l);return{ok:!1,operation:e,...t?.trim()?{conversation:t.trim()}:{},reasonCode:l,...S(s,l,_)?{rawReasonCode:s}:{},message:v,...m?{traceId:m}:{},...h?{outDir:h}:{},...d?{helperTracePath:d}:{},...p?{activityGuardPath:p}:{},...f?{userAction:f}:{}}}function W(e){const t=[];if(e.messages.length===0)return`\uFF08\u6CA1\u6709\u8BFB\u5230\uFF09
|
|
2
|
+
`;for(const n of e.messages)t.push(`${P(n)}: ${C(n)}`);return`${t.join(`
|
|
3
3
|
`)}
|
|
4
|
-
`}function
|
|
4
|
+
`}function q(e,t=""){const n=e.trim().toLowerCase(),i=`${n} ${t}`.toLowerCase();return n?n==="insufficient_credits"?"insufficient_credits":n==="entitlement_required"||n==="enterprise_required"||n.includes("entitlement")?"entitlement_required":n==="manual_review_required"||n.includes("manual_review")?"manual_review_required":n==="attachment_pending"||/attachment.*pending|media_original_pending/.test(i)?"attachment_pending":/helper_runtime_required|helper_runtime_source_missing|helper_runtime_package_manifest_missing|manifest_missing|helper_missing|helper_not_executable/.test(n)?"helper_missing":/helper_runtime_cli_too_old|helper_runtime_version_mismatch|helper_runtime_protocol_mismatch|helper_runtime_platform_mismatch|helper_runtime_package_manifest_invalid|integrity_mismatch/.test(n)?"helper_version_incompatible":/^user_active|recent_(keyboard|mouse|scroll)|frontmost_app_changed|user_takeover|activity/.test(n)?"user_active_retry_later":/helper_command_timeout/.test(n)?"wechat_window_unavailable":u(i)?"wechat_tool_failed":/permission|accessibility|screen_recording|automation|mac_input|input-monitoring/.test(i)?"permission_required":/wechat_login_required|login_required|安全验证|扫码登录|重新登录/.test(i)?"wechat_login_required":/wechat_single_main_window_required|wechat_duplicate_instance|duplicate_main_window/.test(n)?"wechat_single_main_window_required":/visible_desktop|desktop_session|screen_locked|session_locked|rdp_disconnected|rdp.*visible|rdp.*desktop/.test(i)?"windows_visible_desktop_unavailable":/dpi_mapping_failed|display_topology|monitor_topology|multi_?monitor|multi_?screen/.test(i)?"dpi_mapping_failed":/conversation_not|conversation_title_not_confirmed|conversation_not_visible|open_read_required|search_result_not_visible/.test(n)?"conversation_not_found":/wechat_window|wechat_not_running|window_not|window_unavailable|window_unresponsive/.test(n)?"wechat_window_unavailable":n:"wechat_tool_failed"}function E(e){if(e==="wechat_login_required")return"Open WeChat on this machine, complete login or security verification, then retry.";if(e==="wechat_window_unavailable")return"Open Shennian Desktop and the main WeChat window on the active desktop, then retry. If running this command over SSH on Windows, retry with the local daemon available.";if(e==="wechat_single_main_window_required")return"Close duplicate WeChat main windows, login prompts, or security prompts, then retry with exactly one signed-in WeChat main window.";if(e==="windows_visible_desktop_unavailable")return"Unlock or reconnect the Windows visible desktop session, keep WeChat visible, then retry.";if(e==="dpi_mapping_failed")return"Move WeChat fully onto one visible display or use a supported display scaling setup, then retry.";if(e==="conversation_not_found")return"Check the WeChat conversation name and make sure the conversation can be searched.";if(e==="helper_missing")return"Open Shennian Desktop or run `shennian runtime install helper`, then retry.";if(e==="helper_version_incompatible")return"Run `shennian runtime repair helper` or upgrade Shennian CLI, then retry.";if(e==="permission_required")return"Grant Shennian Helper/Desktop the required macOS permissions, then retry.";if(e==="entitlement_required")return"Enable the WeChat capability for this account in Shennian.";if(e==="insufficient_credits")return"Add credits or adjust the account plan in Shennian.";if(e==="user_active_retry_later")return"Wait until the user is idle, then retry.";if(e==="attachment_pending")return"Open WeChat and let the attachment finish downloading, then retry.";if(e==="manual_review_required")return"Review the current WeChat window before retrying."}function R(e,t,n){const i=n.trim().toLowerCase();return!t||t===e||u(t)||w.has(i)?$(e):t}function S(e,t,n){const i=e.trim().toLowerCase();return!(e===t||w.has(i)||u(`${e} ${n}`))}function u(e){const t=e.replace(/\\/g,"/").toLowerCase();return y.some(n=>{const i=n.replace(/\\/g,"/").toLowerCase();return t.includes(i)})}function $(e){return e==="wechat_login_required"?"WeChat needs login or security verification on this machine.":e==="wechat_window_unavailable"?"WeChat window is not available on the active desktop.":e==="wechat_single_main_window_required"?"Exactly one signed-in WeChat main window is required.":e==="windows_visible_desktop_unavailable"?"Windows visible desktop session is unavailable.":e==="dpi_mapping_failed"?"Windows display scaling or monitor geometry cannot be mapped safely.":e==="conversation_not_found"?"WeChat conversation was not found.":e==="helper_missing"?"Shennian Helper runtime is not installed or cannot be found.":e==="helper_version_incompatible"?"Shennian Helper runtime is incompatible with this CLI.":e==="permission_required"?"Required local permissions are missing.":e==="entitlement_required"?"WeChat capability is not enabled for this account.":e==="insufficient_credits"?"Insufficient credits.":e==="user_active_retry_later"?"User activity is in progress; retry later.":e==="attachment_pending"?"WeChat attachment is still pending.":e==="manual_review_required"?"Manual review is required before retrying.":e}function C(e){const t=e.attachments||[],n=a(e.text);return n&&t.length===0?n:n&&t.length>0?`${n} ${t.map(g).join("\u3001")}`:t.length>0?t.map(g).join("\u3001"):"\uFF08\u6D88\u606F\uFF09"}function P(e){return a(e.sender.name||e.sender.id||"\u5BF9\u65B9")}function g(e){const t=a(e.name||b.basename(e.localPath||"")||e.type||"\u9644\u4EF6"),n=e.localPath||e.url||"",i=e.availability&&e.availability!=="edge-local"?` (${e.availability})`:"";return n?`[${I(t)}](${A(n)})${i}`:`${t}${i}`}function A(e){const t=e.replace(/\\/g,"/");return/[\s()<>]/.test(t)?`<${t.replace(/[<>]/g,"")}>`:t}function I(e){return a(e).replace(/([\\\]])/g,"\\$1")}export{W as buildWeChatReadMarkdown,k as buildWeChatToolErrorResult,H as printReadLatestResult,M as printToolError,x as printToolResult};
|