@roll-agent/browser-use-agent 0.15.0 → 0.16.1
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/SKILL.md +6 -1
- package/dist/index.js +1 -1
- package/dist/native-reload.d.ts +30 -0
- package/dist/pages/zhipin/native-page.d.ts +18 -0
- package/dist/reply-authority/prepared-reply-store.d.ts +1 -0
- package/dist/tools/browser-reload-active-tab.d.ts +28 -0
- package/dist/tools/zhipin-open-chat-page.d.ts +11 -3
- package/dist/tools/zhipin-send-reply.d.ts +1 -0
- package/package.json +2 -2
- package/references/zhipin-workflows.md +15 -2
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{defineAgent as e,createAgentLogger as t}from"@roll-agent/sdk";import{defineTool as n}from"@roll-agent/sdk";import{z as r}from"zod";import{createAgentLogger as a}from"@roll-agent/sdk";import"@roll-agent/browser";import{AsyncLocalStorage as o}from"node:async_hooks";import{access as i}from"node:fs/promises";import{constants as s}from"node:fs";import{homedir as c}from"node:os";import{join as l}from"node:path";import{createHash as d}from"node:crypto";import{StructuredToolError as u}from"@roll-agent/sdk";import{BrowserContextManager as m,BrowserRuntime as p,BrowserRuntimeConfigSchema as g,probeBrowserRuntimeCdpHealth as f,SessionStore as h}from"@roll-agent/browser";import{execFileSync as b}from"node:child_process";var y,v={x:0,y:0,width:1920,height:1080},w=25,x=80,S=4,I=["Add-Type -AssemblyName System.Windows.Forms;","$area = [System.Windows.Forms.Screen]::PrimaryScreen.WorkingArea;","[pscustomobject]@{ x = $area.X; y = $area.Y; width = $area.Width; height = $area.Height } | ConvertTo-Json -Compress"].join(" ");function C(){return y??=A(),y}function R(e){if(e<=1)return[1];if(2===e)return[2];if(3===e)return[3];if(4===e)return[2,2];const t=Math.ceil(e/S),n=Math.floor(e/t),r=e%t;return Array.from({length:t},(e,t)=>n+(t<r?1:0))}function k(e){if(!Number.isInteger(e.index)||e.index<0||!Number.isInteger(e.total)||e.total<=0||e.index>=e.total)throw new RangeError("Auto window layout index must be within the configured instance count.");const t=R(e.total),n=t.length;let r=0,a=e.index;for(const[e,n]of t.entries()){if(a<n){r=e;break}a-=n}const o=t[r]??1,i=e.workArea.x+Math.floor(e.workArea.width*a/o),s=e.workArea.x+Math.floor(e.workArea.width*(a+1)/o),c=e.workArea.y+Math.floor(e.workArea.height*r/n);return{x:i,y:c,width:s-i,height:e.workArea.y+Math.floor(e.workArea.height*(r+1)/n)-c}}function A(){const e=N(process.env.ROLL_BROWSER_WORK_AREA);if(void 0!==e)return e;if("darwin"===process.platform){const e=B();if(void 0!==e)return{x:e.x,y:e.y+w,width:e.width,height:Math.max(400,e.height-w-x)}}if("linux"===process.platform){const e=$();if(void 0!==e)return e}if("win32"===process.platform){const e=O();if(void 0!==e)return e}return v}function N(e){if(void 0===e||0===e.trim().length)return;const t=e.split(",").map(e=>Number.parseInt(e.trim(),10));if(4!==t.length||t.some(e=>!Number.isFinite(e)||e<0))return;const[n,r,a,o]=t;return a<=0||o<=0?void 0:{x:n,y:r,width:a,height:o}}function M(e){const t=E(e,/UI Looks like:\s*(\d+)\s*x\s*(\d+)/i);if(void 0!==t)return t;for(const t of e.split("\n")){if(!t.includes("Resolution:")||/\bRetina\b/i.test(t))continue;const e=E(t,/Resolution:\s*(\d+)\s*x\s*(\d+)/i);if(void 0!==e)return e}}function E(e,t){const n=e.match(t);if(void 0===n?.[1]||void 0===n[2])return;const r=Number.parseInt(n[1],10),a=Number.parseInt(n[2],10);return r<=0||a<=0?void 0:{x:0,y:0,width:r,height:a}}function P(e){const t=e.trim().replace(/^\uFEFF/,"");if(0===t.length)return;let n;try{n=JSON.parse(t)}catch{return}if(!T(n))return;const r=_(n.x),a=_(n.y),o=_(n.width),i=_(n.height);return void 0===r||void 0===a||void 0===o||void 0===i||o<=0||i<=0?void 0:{x:r,y:a,width:o,height:i}}function T(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function _(e){if("number"==typeof e&&Number.isInteger(e))return e;if("string"==typeof e&&e.trim().length>0){const t=Number(e.trim());return Number.isInteger(t)?t:void 0}}function B(){try{return M(b("system_profiler",["SPDisplaysDataType"],{encoding:"utf8",timeout:2e3,stdio:["ignore","pipe","ignore"]}).trim())}catch{return}}function O(){try{return P(b("powershell.exe",["-NoProfile","-NonInteractive","-Command",I],{encoding:"utf8",timeout:2e3,windowsHide:!0,stdio:["ignore","pipe","ignore"]}))}catch{return}}function $(){try{const e=b("xrandr",["--current"],{encoding:"utf8",timeout:2e3,stdio:["ignore","pipe","ignore"]}).match(/(\d+)x(\d+)\+/);if(void 0===e?.[1]||void 0===e[2])return;const t=Number.parseInt(e[1],10),n=Number.parseInt(e[2],10);if(t<=0||n<=0)return;return{x:0,y:0,width:t,height:n}}catch{return}}var D,q,j,F,L="default",z=l(c(),".roll-agent","browser","sessions"),J=["#2563EB","#DC2626","#16A34A","#D97706","#7C3AED","#0891B2","#DB2777","#65A30D"],V=["stopped","not_running","not_found","failed"],H=new o,U=class{bundles=new Map;defaultInstanceId;startPromises=new Map;constructor(e,t){if(void 0===t||0===Object.keys(t.instances).length){const t=ne({id:L,runtimeConfig:e});return this.bundles.set(t.id,t),void(this.defaultInstanceId=t.id)}this.defaultInstanceId=t.defaultInstance;const n=Object.entries(t.instances);for(const[t,[r,a]]of n.entries()){const o=ne({id:r,runtimeConfig:G(e,r,a,{index:t,total:n.length}),...void 0!==a.platform?{platform:a.platform}:{},...void 0!==a.trackingAgentId?{trackingAgentId:a.trackingAgentId}:{}});this.bundles.set(r,o)}}getDefaultInstanceId(){return this.defaultInstanceId}listBundles(){return[...this.bundles.values()]}isLegacySingleInstancePool(){return 1===this.bundles.size&&this.bundles.keys().next().value===L}resolvePrimaryInstanceId(){return this.defaultInstanceId??this.getOnlyInstanceId()}async ensureBundleStarted(e){const t=this.getBundle(e);return await this.ensureStarted(t.id),t}async ensureStarted(e){const t=this.bundles.get(e);if(void 0===t)throw new Error(`Browser instance "${e}" was not found.`);if(t.runtime.isRunning())return;const n=this.startPromises.get(e);if(void 0!==n)return void await n;const r=t.runtime.start().catch(async t=>{throw this.startPromises.delete(e),t});this.startPromises.set(e,r);try{await r}finally{this.startPromises.delete(e)}}getBundle(e){const t=e??H.getStore()??this.defaultInstanceId??this.getOnlyInstanceId();if(void 0===t)throw new u({code:"needs_input",message:"browserInstance is required because multiple browser instances are configured.",details:{availableInstances:[...this.bundles.keys()]}});const n=this.bundles.get(t);if(void 0===n)throw new u({code:"browser_instance_not_found",message:`Browser instance "${t}" was not found.`,details:{availableInstances:[...this.bundles.keys()]}});return n}async getInstanceStatuses(){return await Promise.all(this.listBundles().map(async e=>{const[t,n]=await Promise.all([f(e.config),re(e.config.userDataDir)]);return{id:e.id,...void 0!==e.platform?{platform:e.platform}:{},mode:e.config.mode,cdp:t,profile:n,tracking:oe(e.trackingAgentId)}}))}async closeAll(){const e=(await this.closeInstances([...this.bundles.keys()])).filter(e=>"failed"===e.status).map(e=>new Error(`Failed to stop browser runtime for ${e.browserInstance}: ${e.message??"unknown error"}`));if(e.length>0)throw new AggregateError(e,"Browser instance pool shutdown failed")}async closeInstances(e){const t=[...new Set(e)];return await Promise.all(t.map(async e=>await this.closeInstance(e)))}async closeInstance(e){const t=this.bundles.get(e);if(void 0===t)return{browserInstance:e,status:"not_found",message:`Browser instance "${e}" was not found.`};const n=[],r=this.startPromises.get(e);if(void 0!==r)try{await r}catch(t){n.push(new Error(`Failed to finish browser startup for ${e}`,{cause:t}))}if(!t.runtime.isRunning())return n.length>0?{browserInstance:e,status:"failed",mode:t.config.mode,message:W(n)}:{browserInstance:e,status:"not_running",mode:t.config.mode};try{await t.contextManager.closeAll()}catch(t){n.push(new Error(`Failed to close browser contexts for ${e}`,{cause:t}))}try{"managed-cdp"===t.config.mode?await t.runtime.stop():await t.runtime.disconnect()}catch(t){n.push(new Error(`Failed to stop browser runtime for ${e}`,{cause:t}))}return n.length>0?{browserInstance:e,status:"failed",mode:t.config.mode,message:W(n)}:{browserInstance:e,status:"stopped",mode:t.config.mode}}getOnlyInstanceId(){if(1===this.bundles.size)return this.bundles.keys().next().value}};function W(e){return e.map(e=>void 0===e.cause?e.message:`${e.message}: ${K(e.cause)}`).join("; ")}function K(e){return e instanceof Error?e.message:String(e)}async function Y(e,t){return await H.run(e,t)}function G(e,t,n,r){const a=n.headless??e.headless,o=n.windowBounds??te({instance:n,headless:a,...r});return g.parse({...e,mode:n.mode,headless:a,instanceId:t,profileName:n.profileName??t,profileColor:n.profileColor??X(r.index),cdpUrl:n.cdpUrl,cdpHost:n.cdpHost,cdpPort:n.cdpPort,channel:n.channel,executablePath:n.executablePath,userDataDir:n.userDataDir,args:n.args,windowBounds:o,sessionsDir:n.sessionsDir??l(z,t)})}function X(e){return J[e]??Z(e)}function Z(e){return Q(137.508*e%360,.68,.45)}function Q(e,t,n){const r=(1-Math.abs(2*n-1))*t,a=e/60,o=r*(1-Math.abs(a%2-1));let i,s,c;[i,s,c]=a<1?[r,o,0]:a<2?[o,r,0]:a<3?[0,r,o]:a<4?[0,o,r]:a<5?[o,0,r]:[r,0,o];const l=n-r/2;return`#${ee(i+l)}${ee(s+l)}${ee(c+l)}`}function ee(e){return Math.round(255*e).toString(16).padStart(2,"0").toUpperCase()}function te(e){if(!(e.total<=1||e.headless||"managed-cdp"!==e.instance.mode))return k({index:e.index,total:e.total,workArea:C()})}function ne(e){const t=new h(e.runtimeConfig.sessionsDir),n=new p(e.runtimeConfig),r=new m(n,t);return{id:e.id,...void 0!==e.platform?{platform:e.platform}:{},...void 0!==e.trackingAgentId?{trackingAgentId:e.trackingAgentId}:{},runtime:n,contextManager:r,sessionStore:t,config:e.runtimeConfig}}async function re(e){if(void 0===e)return{exists:!1,writable:!1};return{userDataDir:e,exists:await ae(e,s.F_OK),writable:await ae(e,s.W_OK)}}async function ae(e,t){try{return await i(e,t),!0}catch{return!1}}function oe(e){if(void 0!==e)return{source:"instance",agentIdFingerprint:ie(e)};const t=process.env.RECRUITMENT_EVENTS_DEFAULT_AGENT_ID?.trim();return void 0!==t&&t.length>0?{source:"default-env",agentIdFingerprint:ie(t)}:{source:"missing"}}function ie(e){return d("sha256").update(e).digest("hex").slice(0,8)}var se=!1,ce=a("browser-use-agent");async function le(e,t){if(D||q)return;se=!1;const n=(D=new U(e,t)).getDefaultInstanceId(),r=D.listBundles()[0],a=void 0!==n?D.getBundle(n):r;void 0!==a&&(q=a.runtime,j=a.contextManager,F=a.sessionStore)}function de(){if(D)return D.getBundle().runtime;if(!q)throw new Error("BrowserRuntime not initialized. Call initRuntime() first.");return q}function ue(){if(D)return D.getBundle().contextManager;if(!j)throw new Error("BrowserContextManager not initialized. Call initRuntime() first.");return j}function me(e){se=e}function pe(){return se}function ge(){if(!D)throw new Error("BrowserInstancePool not initialized. Call initRuntime() first.");return D}async function fe(){await ge().ensureBundleStarted()}function he(){return void 0!==D&&!D.isLegacySingleInstancePool()}function be(e){if(!D)return e;let t;try{t=D.getBundle()}catch{return}return t.trackingAgentId??e}function ye(){return ge().getBundle()}async function ve(){const e=D,t=j,n=q,r=[];if(D=void 0,j=void 0,q=void 0,F=void 0,se=!1,e){ce.info("Closing browser instance pool...");try{await e.closeAll()}catch(e){r.push(new Error("Failed to close browser instance pool",{cause:e})),ce.error(`Failed to close browser instance pool: ${e instanceof Error?e.stack??e.message:String(e)}`)}}else if(t){ce.info("Closing browser contexts...");try{await t.closeAll()}catch(e){r.push(new Error("Failed to close browser contexts",{cause:e})),ce.error(`Failed to close browser contexts: ${e instanceof Error?e.stack??e.message:String(e)}`)}}if(!e&&n){ce.info("Stopping browser process...");try{await n.stop()}catch(e){r.push(new Error("Failed to stop browser runtime",{cause:e})),ce.error(`Failed to stop browser runtime: ${e instanceof Error?e.stack??e.message:String(e)}`)}}if(ce.info("Browser runtime shutdown complete"),r.length>0)throw new AggregateError(r,"Browser runtime shutdown failed")}var we=r.object({success:r.boolean(),mode:r.string(),connected:r.boolean()}),xe=n({name:"attach_browser_session",description:"调试工具:显式执行一次 connectOverCDP(),仅建立 Playwright Browser 连接,不做页面导航或 DOM 操作。",input:r.object({}),output:we,execute:async(e,t)=>{const n=de();return t.logger.info("Attaching Playwright browser session over CDP"),await n.getBrowser(),{success:!0,mode:n.mode,connected:!0}}});import{defineTool as Se}from"@roll-agent/sdk";import{z as Ie}from"zod";import{BrowserSecurityConfigSchema as Ce,BrowserStatusSchema as Re}from"@roll-agent/browser";import{createHash as ke}from"node:crypto";import{z as Ae}from"zod";var Ne=["REPLY_AUTHORITY_URL","REPLY_AUTHORITY_BEARER_TOKEN","REPLY_AUTHORITY_KEYS_URL","RECRUITMENT_EVENTS_ENABLED","RECRUITMENT_EVENTS_API_BASE_URL","RECRUITMENT_EVENTS_API_TOKEN","RECRUITMENT_EVENTS_DEFAULT_AGENT_ID","BROWSER_SECURITY_JSON","BROWSER_INSTANCES_JSON","BROWSER_USE_POLICY_JSON","BROWSER_VISUAL_CURSOR","BROWSER_VISUAL_ACTIVITY"],Me=/^[0-9a-f]{8}$/,Ee=Ae.object({present:Ae.boolean(),fingerprint:Ae.string().regex(Me).optional()}),Pe=Ae.record(Ee);function Te(e,t=process.env){return Object.fromEntries(e.map(e=>{const n=t[e];return"string"==typeof n&&n.length>0?[e,{present:!0,fingerprint:_e(n)}]:[e,{present:!1}]}))}function _e(e){return ke("sha256").update(e).digest("hex").slice(0,8)}var Be,Oe,$e=180,De=60,qe=280,je="roll-agent-visual-cursor-root",Fe="__rollVisualCursorState";function Le(e){if(void 0!==e)return"true"===e||"false"!==e&&void 0}function ze(){return void 0!==Be?Be:Le(process.env.BROWSER_VISUAL_CURSOR)??!0}async function Je(e){return await e.evaluate(e=>{const t=e.getBoundingClientRect();return t.width<=0||t.height<=0?null:{x:Math.round(t.left+t.width/2),y:Math.round(t.top+t.height/2)}})}async function Ve(e,t){await e.evaluate(e=>{const t="roll-agent-visual-cursor-root",n="roll-agent-visual-cursor-pointer",r="__rollVisualCursorState",a=(()=>{const e=document.getElementById(t);if(e)return e;const r=document.createElement("div");r.id=t,r.style.position="fixed",r.style.left="0",r.style.top="0",r.style.width="0",r.style.height="0",r.style.pointerEvents="none",r.style.zIndex="2147483647";const a=document.createElement("div");return a.id=n,a.setAttribute("aria-hidden","true"),a.style.position="fixed",a.style.left="0",a.style.top="0",a.style.width="24px",a.style.height="24px",a.style.opacity="0",a.style.transform="translate(-9999px, -9999px)",a.style.willChange="transform, opacity",a.style.filter="drop-shadow(0 4px 8px rgba(15, 23, 42, 0.28))",a.innerHTML='<svg viewBox="0 0 24 24" width="24" height="24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M4 2L18 14L11.4 15.3L14.6 22L10.7 23.5L7.6 16.8L3 21V2Z" fill="#FFFFFF" stroke="#0F172A" stroke-width="1.5" stroke-linejoin="round"/></svg>',r.append(a),document.documentElement.append(r),r})(),o=a.querySelector(`#${n}`);if(!o)return;const i=window[r],s=e.point,c=e.durationMs,l=s.x-2,d=s.y-2;if(i?o.style.transition=`transform ${c}ms cubic-bezier(0.22, 1, 0.36, 1), opacity 120ms ease`:(o.style.transition="opacity 120ms ease",o.style.transform=`translate(${l}px, ${d}px)`),o.style.opacity="1",o.style.transform=`translate(${l}px, ${d}px)`,window[r]={x:s.x,y:s.y},!e.clickPulse)return;const u=document.createElement("div");u.setAttribute("aria-hidden","true"),u.style.position="fixed",u.style.left="0",u.style.top="0",u.style.width="18px",u.style.height="18px",u.style.borderRadius="9999px",u.style.border="2px solid rgba(20, 184, 166, 0.95)",u.style.background="rgba(20, 184, 166, 0.18)",u.style.pointerEvents="none",u.style.opacity="0.9",u.style.transform=`translate(${s.x-9}px, ${s.y-9}px) scale(0.55)`,u.style.transition=`transform ${e.pulseDurationMs}ms ease, opacity ${e.pulseDurationMs}ms ease`,a.append(u),requestAnimationFrame(()=>{u.style.opacity="0",u.style.transform=`translate(${s.x-18}px, ${s.y-18}px) scale(2)`}),globalThis.setTimeout(()=>{u.remove()},e.pulseDurationMs+40)},{point:t.point,durationMs:t.durationMs,clickPulse:t.clickPulse,pulseDurationMs:t.pulseDurationMs})}function He(e){const t=[e],n="function"==typeof e.frames?e.frames():[];return t.push(...n),t}async function Ue(e){await e.evaluate(({rootId:e,stateKey:t})=>{document.getElementById(e)?.remove(),delete window[t]},{rootId:je,stateKey:Fe})}async function We(e,t={}){if(e.isClosed())return!1;let n=!1;for(const r of He(e))if(r!==t.preserveTarget)try{await Ue(r),n=!0}catch{}return n}async function Ke(e,t,n={}){if(!ze()||e.isClosed())return!1;try{await t.scrollIntoViewIfNeeded();const r=await Je(t);if(!r)return!1;const a=n.durationMs??$e,o=n.settleMs??De,i=n.target??e;return await We(e,{preserveTarget:i}),await Ve(n.target??e,{point:r,durationMs:a,clickPulse:!1,pulseDurationMs:qe}),await e.waitForTimeout(Math.max(a+o,0)),!0}catch{return!1}}async function Ye(e,t,n={}){if(!ze()||e.isClosed())return!1;try{const r=await Je(t);if(!r)return!1;const a=n.pulseDurationMs??qe,o=n.target??e;return await We(e,{preserveTarget:o}),await Ve(o,{point:r,durationMs:0,clickPulse:!0,pulseDurationMs:a}),await e.waitForTimeout(a),!0}catch{return!1}}function Ge(e){if(void 0!==e)return"true"===e||"false"!==e&&void 0}function Xe(){return void 0!==Oe?Oe:Ge(process.env.BROWSER_VISUAL_ACTIVITY)??!0}import{StructuredToolError as Ze}from"@roll-agent/sdk";import{z as Qe}from"zod";import{randomUUID as et}from"node:crypto";import{z as tt}from"zod";var nt=tt.object({id:tt.string().trim().min(1)}),rt=new Map;function at(e=Date.now()){for(const[t,n]of rt)n.expiresAtMs<=e&&rt.delete(t)}function ot(e,t){return e.tool===t.tool&&e.target===t.target&&e.digest===t.digest}function it(e,t,n=Date.now()){at(n);const r=et(),a=n+t;return rt.set(r,{id:r,tool:e.tool,target:e.target,digest:e.digest,...void 0!==e.summary?{summary:e.summary}:{},expiresAtMs:a}),{id:r,expiresAt:new Date(a).toISOString(),tool:e.tool,target:e.target,...void 0!==e.summary?{summary:e.summary}:{},retryInput:{toolActionApproval:{id:r}}}}function st(e){return at(),!!ct(e)&&(rt.delete(e.approval.id),!0)}function ct(e){at();const t=rt.get(e.approval.id);return void 0!==t&&!!ot(e.subject,t)}var lt=["log","deny","confirm"],dt=Qe.enum(lt),ut=["zhipin_send_prepared_reply"],mt=["unknown_tool_policy","double_confirmation","browser_action_policy_not_recommended"],pt=Qe.object({code:Qe.enum(mt),message:Qe.string()}),gt=Qe.object({policy:dt}),ft=Qe.object({approvalTtlMs:Qe.number().int().positive().max(36e5).default(3e5),tools:Qe.record(gt).default({})}),ht=ft.parse({}),bt=new Set(ut),yt=ht;function vt(e){if(void 0===e)return{};try{return JSON.parse(e)}catch(e){throw new Error(`BROWSER_USE_POLICY_JSON must be valid JSON: ${e instanceof Error?e.message:String(e)}`)}}function wt(e=process.env){try{return ft.parse(vt(e.BROWSER_USE_POLICY_JSON))}catch(e){if(e instanceof Error&&e.message.startsWith("BROWSER_USE_POLICY_JSON must be valid JSON"))throw e;throw new Error(`BROWSER_USE_POLICY_JSON is invalid: ${e instanceof Error?e.message:String(e)}`)}}function xt(e){yt=ft.parse(e)}function St(){return yt}function It(e){const t=e.toolPolicy??yt,n=[];for(const e of Object.keys(t.tools))bt.has(e)||n.push({code:"unknown_tool_policy",message:`BROWSER_USE_POLICY_JSON 配置了未接入 tool-level policy 的工具: ${e}`});return"confirm"===e.browserSecurity.actionPolicy&&Object.values(t.tools).some(e=>"confirm"===e.policy)&&n.push({code:"double_confirmation",message:"BROWSER_SECURITY_JSON.actionPolicy=confirm 与 tool policy confirm 同时启用,可能导致双重确认。"}),"confirm"!==e.browserSecurity.actionPolicy&&"deny"!==e.browserSecurity.actionPolicy||n.push({code:"browser_action_policy_not_recommended",message:"BROWSER_SECURITY_JSON.actionPolicy=confirm/deny 是高级调试模式,Boss 日常编排建议使用 actionPolicy=log。"}),n}function Ct(e,t){const n=yt.tools[t.subject.tool],r=n?.policy??"log";if("log"===r)return e.logger.info(`Browser-use tool allowed by tool policy: ${t.subject.tool}`),{consumeApproval:()=>{}};if("deny"===r){const n="Tool execution denied by browser-use tool policy.";throw e.logger.warn(`${n} ${JSON.stringify(Rt(t.subject,"tool_policy_deny"))}`),new Ze({code:"action_denied",message:n,details:Rt(t.subject,"tool_policy_deny")})}if(void 0!==t.approval&&(!0===t.deferApprovalConsumption?ct({approval:t.approval,subject:t.subject}):st({approval:t.approval,subject:t.subject})))return e.logger.info(`Browser-use tool approved by toolActionApproval: ${t.subject.tool}`),{consumeApproval:()=>{!0===t.deferApprovalConsumption&&void 0!==t.approval&&st({approval:t.approval,subject:t.subject})}};const a="Tool execution requires confirmation by browser-use tool policy.",o={...Rt(t.subject,"tool_policy_confirm"),approvalRequest:it(t.subject,yt.approvalTtlMs)};throw e.logger.warn(`${a} ${JSON.stringify(Rt(t.subject,"tool_policy_confirm"))}`),new Ze({code:"needs_confirmation",message:a,details:o})}function Rt(e,t){return{reason:t,tool:e.tool,target:e.target,...void 0!==e.summary?{summary:e.summary}:{}}}var kt=Re.extend({replyAuthorityKeysLoaded:Ie.boolean(),visualCursorEnabled:Ie.boolean(),visualActivityEnabled:Ie.boolean(),security:Ce,toolPolicy:ft,policyWarnings:Ie.array(pt),effectiveEnvSources:Pe}),At=Se({name:"browser_status",description:"查询浏览器运行状态和活跃 session 信息",input:Ie.object({}),output:kt,execute:async(e,t)=>{t.logger.info("Querying browser status");const n=ge(),r=n.listBundles(),a=n.resolvePrimaryInstanceId(),o=r.find(e=>e.id===a)??r[0];if(void 0===o)throw new Error("BrowserInstancePool has no runtime bundles.");const i=r.some(e=>e.runtime.isRunning()),{headless:s,mode:c,security:l}=o.runtime.getConfig(),d=St(),u=[];for(const e of r){const t=e.runtime,n=e.contextManager,r=e.sessionStore,a=n.getActivePlatforms();for(const o of a){const a=n.getPageCount(o),i=n.getCurrentUrl(o);let s=null,c="unknown";if(t.shouldRestoreSessionSnapshot()){const[e,t]=await Promise.all([r.loadCookies(o),r.loadLocalStorage(o)]);s=void 0!==e&&e.length>0||void 0!==t&&Object.keys(t).length>0,c=s?"snapshot":"none"}else t.usesPersistentProfile()&&(s=null,c="profile");u.push({browserInstance:e.id,platform:o,pagesOpen:a,currentUrl:i,hasLoginState:s,loginStateSource:c})}}return{running:i,headless:s,mode:c,activeSessions:u,defaultInstanceId:n.getDefaultInstanceId(),primaryInstanceId:a,instances:await n.getInstanceStatuses(),replyAuthorityKeysLoaded:pe(),visualCursorEnabled:ze(),visualActivityEnabled:Xe(),security:l,toolPolicy:d,policyWarnings:It({browserSecurity:l,toolPolicy:d}),effectiveEnvSources:Te(Ne)}}});import{BrowserRuntimeModeSchema as Nt}from"@roll-agent/browser";import{StructuredToolError as Mt,defineTool as Et}from"@roll-agent/sdk";import{z as Pt}from"zod";var Tt=Pt.object({browserInstance:Pt.string().trim().min(1).optional(),browserInstances:Pt.array(Pt.string().trim().min(1)).min(1).optional(),all:Pt.boolean().optional()}).superRefine((e,t)=>{const n=void 0!==e.browserInstance||void 0!==e.browserInstances&&e.browserInstances.length>0;e.all&&n&&t.addIssue({code:Pt.ZodIssueCode.custom,path:["all"],message:"all cannot be combined with browserInstance or browserInstances"})}),_t=Pt.object({browserInstance:Pt.string(),status:Pt.enum(V),mode:Nt.optional(),message:Pt.string().optional()}),Bt=Pt.object({ok:Pt.boolean(),stopped:Pt.number().int().nonnegative(),results:Pt.array(_t)}),Ot=Et({name:"browser_stop",description:"关闭 browser-use-agent 当前托管的一个、多个或全部浏览器实例;不停止 browser-use-agent 服务进程。",input:Tt,output:Bt,execute:async(e,t)=>{const n=ge(),r=$t(e,n.listBundles().map(e=>e.id));t.logger.info(`Stopping browser instances: ${r.join(", ")}`);return Dt(await n.closeInstances(r))}});function $t(e,t){if(!0===e.all)return t;const n=[...void 0!==e.browserInstance?[e.browserInstance]:[],...e.browserInstances??[]],r=[...new Set(n)];if(0===r.length)throw new Mt({code:"needs_input",message:"browserInstance, browserInstances, or all is required.",details:{availableInstances:t}});return r}function Dt(e){return{ok:e.every(e=>"not_found"!==e.status&&"failed"!==e.status),stopped:e.filter(e=>"stopped"===e.status).length,results:[...e]}}import{defineTool as qt}from"@roll-agent/sdk";import{BrowserPageInfoSchema as jt,PlatformSchema as Ft}from"@roll-agent/browser";import{z as Lt}from"zod";import{PLATFORMS as zt}from"@roll-agent/browser";var Jt={zhipin:"https://www.zhipin.com",yupao:"https://www.yupao.com"};function Vt(e){return new URL(Jt[e]).host}function Ht(e,t){try{return new URL(e).host.includes(Vt(t))}catch{return!1}}function Ut(e){return zt.find(t=>Ht(e,t))}function Wt(e,t){const n=Ut(t.url)??null;return{pageId:t.targetId,url:t.url,title:t.title,boundPlatform:e.getBoundPlatformForNativePage(t.targetId)??null,detectedPlatform:n,isSelectedForPlatform:e.isNativePageSelected(t.targetId)}}async function Kt(e,t){const n=t.url();return{pageId:e.getPageId(t),url:n,title:await t.title().catch(()=>""),boundPlatform:e.getBoundPlatformForPage(t)??null,detectedPlatform:Ut(n)??null,isSelectedForPlatform:e.isSelectedPageForPlatform(t)}}var Yt=Lt.object({platform:Ft.optional().describe("可选:仅返回指定平台相关的页面")}),Gt=Lt.object({pages:Lt.array(jt)}),Xt=qt({name:"list_pages",description:"通过原生 CDP 列出当前浏览器可见页面及其可选择的 pageId;登录前该值等同于原生 targetId。",input:Yt,output:Gt,execute:async(e,t)=>{const n=ue();t.logger.info("Listing browser pages");const r=(await n.listNativePages()).map(e=>Wt(n,e));return{pages:void 0===e.platform?r:r.filter(t=>t.boundPlatform===e.platform||t.detectedPlatform===e.platform)}}});import{setTimeout as Zt}from"node:timers/promises";import{defineTool as Qt}from"@roll-agent/sdk";import{BrowserActionApprovalSchema as en,BrowserPageInfoSchema as tn}from"@roll-agent/browser";import{z as nn}from"zod";import{StructuredToolError as rn}from"@roll-agent/sdk";import{isBrowserActionPolicyError as an,preflightBrowserAction as on}from"@roll-agent/browser";import{randomUUID as sn}from"node:crypto";var cn=6e4,ln=new Map;function dn(e=Date.now()){for(const[t,n]of ln)n.expiresAtMs<=e&&ln.delete(t)}function un(e,t){return e.action===t.action&&e.target===t.target&&(e.url??void 0)===(t.url??void 0)}function mn(e,t=Date.now()){dn(t);const n=sn(),r=t+cn,a={id:n,action:e.action,target:e.target,...void 0!==e.url?{url:e.url}:{},expiresAtMs:r};return ln.set(n,a),{id:n,expiresAt:new Date(r).toISOString(),action:e.action,target:e.target,...void 0!==e.url?{url:e.url}:{},retryInput:{browserActionApproval:{id:n}}}}function pn(e){dn();const t=ln.get(e.approval.id);return void 0!==t&&(!!un(e.details,t)&&(ln.delete(e.approval.id),!0))}function gn(e,t){const n=e.getConfig().security;return!0===t.approvedByConfirmation&&"confirm"===n.actionPolicy?{...n,actionPolicy:"log"}:n}function fn(e,t,n={}){return{security:gn(t,n),approveAction:pn,...void 0!==n.approval?{approval:n.approval}:{},...!1===n.logActions?{}:{onActionLog:t=>{e.logger.info(t)}}}}function hn(e,t,n){const r=on({security:t.getConfig().security,action:n.action,target:n.target,...void 0!==n.url?{url:n.url}:{}});if(r.ok)return r.log&&e.logger.info(r.message),{approvedByConfirmation:!1};if("needs_confirmation"===r.code&&void 0!==n.approval&&pn({approval:n.approval,details:r.details}))return e.logger.info(`Browser action approved by browserActionApproval: ${n.action} ${n.target}`),{approvedByConfirmation:!0};throw e.logger.warn(`${r.message} ${JSON.stringify(r.details)}`),new rn({code:r.code,message:r.message,details:{...r.details,..."needs_confirmation"===r.code?{approvalRequest:mn(r.details)}:{}}})}function bn(e){if(an(e))return new rn({code:e.payload.code,message:e.payload.message,details:{...e.payload.details,..."needs_confirmation"===e.payload.code?{approvalRequest:mn(e.payload.details)}:{}}})}function yn(){try{return de()}catch{return}}async function vn(e){await e.bringToFront().catch(()=>{})}async function wn(e,t={}){const n=t.runtime??yn();if(void 0===n)return;const r=n.getConfig().security.foregroundPolicy;if("never"===r)return;if("always"===r)return void await vn(e);const a=n.getNativePageWindowState;if("function"!=typeof a)return;"minimized"===await a.call(n,e.targetId).catch(()=>"unknown")&&await vn(e)}var xn,Sn=15e3,In=250,Cn=["/web/chat"],Rn=nn.object({url:nn.string().url().describe("要导航到的目标 URL"),browserActionApproval:en.optional().describe("当 actionPolicy=confirm 返回 needs_confirmation 后,由 orchestrator 原样带回的批准 ID。")}),kn=nn.object({success:nn.boolean(),page:tn});function An(){return{getContextManager:ue,getRuntime:de,detectPlatformFromUrl:Ut,matchesPlatformHost:Ht,toNativePageInfo:Wt,delay:Zt,...xn}}function Nn(e){return"object"==typeof e&&null!==e}function Mn(e){return!!Nn(e)&&("string"==typeof e.url&&"string"==typeof e.title&&"string"==typeof e.readyState)}function En(e,t){if("zhipin"!==t)return;const n=new URL(e).pathname;if(void 0!==Cn.find(e=>n===e||n.startsWith(`${e}/`)))throw new Error("navigate_active_tab 不支持直接导航 BOSS 后台聊天/推荐路径;请使用 zhipin_open_chat_page 或 zhipin_open_recommend_page。")}async function Pn(e,t,n,r,a){const o=n.detectPlatformFromUrl(r),i=await t.listNativePages();if(o){const s=i.find(e=>n.matchesPlatformHost(e.url,o));if(s)return a.info(`Reusing native ${o} page for navigation`),await t.activateNativePage(s.targetId),e.rememberNativePageSelection(o,s),{page:s,platform:o};a.info(`Opening native ${o} page for navigation`);const c=await t.openNativePage(r);return e.rememberNativePageSelection(o,c),{page:c,platform:o}}return a.info("Opening a new native page for non-platform navigation"),{page:await t.openNativePage(r)}}async function Tn(e){const t=await e.evaluateJson("(() => ({ url: location.href, title: document.title, readyState: document.readyState }))()");if(!Mn(t))throw new Error("Native CDP Runtime.evaluate returned an unexpected page load state.");return t}async function _n(e,t,n,r){const a=Date.now();let o;for(;Date.now()-a<Sn;){try{const t=await Tn(e);if(("interactive"===t.readyState||"complete"===t.readyState)&&Bn(t.url,n,r))return t}catch(e){o=e instanceof Error?e:new Error(String(e))}await t.delay(In)}throw new Error(`Native navigation did not reach document ready state within ${Sn}ms${o?`: ${o.message}`:""}`)}function Bn(e,t,n){if(e===t)return!0;try{const t=new URL(e);return("http:"===t.protocol||"https:"===t.protocol)&&e!==n}catch{return!1}}async function On(e,t,n){t.url!==n&&await e.navigate(n)}async function $n(e,t,n){return{...(await e.listNativePages()).find(e=>e.targetId===t.targetId)??t,url:n.url,title:n.title}}var Dn=Qt({name:"navigate_active_tab",description:"通过 native CDP 打开或导航页面;已知平台优先复用平台 tab,不触发 Playwright attach,不直接跳转 BOSS 后台聊天/推荐路径。",input:Rn,output:kn,execute:async(e,t)=>{const n=An(),r=n.getContextManager(),a=n.getRuntime(),o=n.detectPlatformFromUrl(e.url);En(e.url,o);const i=hn(t,a,{action:"navigate",target:e.url,url:e.url,...void 0!==e.browserActionApproval?{approval:e.browserActionApproval}:{}});t.logger.info(`Native navigating to ${e.url}`);const s=await Pn(r,a,n,e.url,t.logger),c=await a.connectNativePage(s.page,{...fn(t,a,{approval:e.browserActionApproval,approvedByConfirmation:i.approvedByConfirmation,logActions:!1})});try{await wn({targetId:s.page.targetId,bringToFront:async()=>{await c.bringToFront()}},{runtime:a}),await On(c,s.page,e.url);const o=await _n(c,n,e.url,s.page.url),i=await $n(a,s.page,o),l=s.platform??n.detectPlatformFromUrl(i.url);return l&&(r.rememberNativePageSelection(l,i),t.logger.info(`Bound native navigated page to ${l}`)),{success:!0,page:n.toNativePageInfo(r,i)}}finally{c.close()}}});import{defineTool as qn}from"@roll-agent/sdk";import{BrowserActionApprovalSchema as jn,BrowserPageInfoSchema as Fn,PlatformSchema as Ln}from"@roll-agent/browser";import{z as zn}from"zod";async function Jn(e,t){return(await e.listNativePages()).find(e=>Ht(e.url,t))}async function Vn(e,t,n={}){const r=await Jn(e,t);if(r)return await e.activateNativePage(r.targetId),{page:r,reusedExistingPage:!0};return{page:await e.openNativePage(Jt[t],n),reusedExistingPage:!1}}var Hn=zn.object({platform:Ln.describe("目标平台:`zhipin` 代表 BOSS直聘,`yupao` 代表鱼泡"),browserActionApproval:jn.optional().describe("当 actionPolicy=confirm 返回 needs_confirmation 后,由 orchestrator 原样带回的批准 ID。")}),Un=zn.object({success:zn.boolean(),page:Fn,reusedExistingTab:zn.boolean()}),Wn=qn({name:"open_platform",description:"打开并聚焦招聘平台主页,供用户手动登录或后续执行站内操作。",input:Hn,output:Un,execute:async(e,t)=>{const{platform:n}=e,r=de(),a=ue(),o=Jt[n],i=hn(t,r,{action:"navigate",target:o,url:o,...void 0!==e.browserActionApproval?{approval:e.browserActionApproval}:{}});t.logger.info(`Opening platform page for ${n}`);const{page:s,reusedExistingPage:c}=await Vn(r,n,fn(t,r,{approval:e.browserActionApproval,approvedByConfirmation:i.approvedByConfirmation,logActions:!1}));return a.rememberNativePageSelection(n,s),{success:!0,page:Wt(a,s),reusedExistingTab:c}}});import{defineTool as Kn}from"@roll-agent/sdk";import{BrowserPageInfoSchema as Yn,PlatformSchema as Gn}from"@roll-agent/browser";import{z as Xn}from"zod";var Zn=Xn.object({platform:Gn.describe("要将该页面绑定为当前活跃页的平台"),pageId:Xn.string().describe("通过 list_pages 返回的 pageId;登录前就是原生 targetId,登录后仍可作为稳定选择句柄")}),Qn=Xn.object({success:Xn.boolean(),page:Yn}),er=Kn({name:"select_page",description:"将指定 pageId 绑定为平台当前活跃页,并切换到前台;登录前走原生 CDP target 激活。",input:Zn,output:Qn,execute:async(e,t)=>{const n=ue();t.logger.info(`Selecting page ${e.pageId} for ${e.platform}`);const r=await n.selectNativePage(e.platform,e.pageId);return{success:!0,page:Wt(n,r)}}});import{defineTool as tr}from"@roll-agent/sdk";import{BrowserAxSnapshotSchema as nr,BrowserPageInfoSchema as rr,createBrowserAxSnapshot as ar}from"@roll-agent/browser";import{z as or}from"zod";import{BrowserElementRefStore as ir}from"@roll-agent/browser";var sr=new ir;async function cr(e){const t=await e.runtime.listNativePages();if(void 0!==e.pageId){const n=t.find(t=>t.targetId===e.pageId);if(void 0===n)throw new Error(`Page "${e.pageId}" not found. Run list_pages to inspect pageId values.`);return n}const n=t.filter(t=>e.ctxManager.isNativePageSelected(t.targetId));if(1===n.length&&void 0!==n[0])return n[0];if(1===t.length&&void 0!==t[0])return t[0];throw new Error("browser_snapshot/click_ref/type_ref need pageId when multiple native pages are open. Run list_pages first.")}import{randomUUID as lr}from"node:crypto";var dr="data-roll-browser-action-",ur=120;function mr(){return`${dr}${lr().replaceAll("-","")}`}function pr(e){return Number.isFinite(e)?Math.max(0,Math.min(Math.trunc(e),ur)):ur}function gr(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function fr(e){if(!gr(e)||!gr(e.root))return;const t=e.root.nodeId;return"number"==typeof t&&Number.isInteger(t)?t:void 0}function hr(e){if(Array.isArray(e)&&!e.some(e=>"string"!=typeof e))return e}function br(e){return Array.isArray(e)?e.flatMap(e=>{const t=yr(e);return void 0===t?[]:[t]}):[]}function yr(e){if(!gr(e))return;const t=e.nodeId,n=e.backendNodeId,r=hr(e.attributes),a=yr(e.contentDocument),o=yr(e.templateContent);return{..."number"==typeof t&&Number.isInteger(t)?{nodeId:t}:{},..."number"==typeof n&&Number.isInteger(n)?{backendNodeId:n}:{},...void 0!==r?{attributes:r}:{},children:br(e.children),...void 0!==a?{contentDocument:a}:{},pseudoElements:br(e.pseudoElements),shadowRoots:br(e.shadowRoots),...void 0!==o?{templateContent:o}:{}}}function vr(e,t){if(void 0!==t)for(let n=0;n<t.length-1;n+=2)if(t[n]===e)return t[n+1]}function wr(e){if(!gr(e))return;const t=e.marker,n=e.name;return"string"==typeof t&&"string"==typeof n&&0!==n.trim().length?{marker:t,name:n.trim(),disabled:!0===e.disabled,hasClassHint:!0===e.hasClassHint,hasCursorPointer:!0===e.hasCursorPointer,hasOnClick:!0===e.hasOnClick,hasTabIndex:!0===e.hasTabIndex,isEditable:!0===e.isEditable}:void 0}function xr(e){return Array.isArray(e)?e.flatMap(e=>{const t=wr(e);return void 0===t?[]:[t]}):[]}function Sr(e){return e.isEditable?"editable":e.hasCursorPointer||e.hasOnClick||e.hasClassHint?"clickable":"focusable"}function Ir(e){const t=[];return e.hasCursorPointer&&t.push("cursor:pointer"),e.hasOnClick&&t.push("onclick"),e.hasTabIndex&&t.push("tabindex"),e.isEditable&&t.push("contenteditable"),e.hasClassHint&&t.push("class:action"),t}function Cr(e,t){const n=new Map;for(const r of t){const t=vr(e,r.attributes);void 0!==t&&void 0!==r.backendNodeId&&n.set(t,r.backendNodeId)}return n}function Rr(e,t){const n=new Map,r=t=>{const a=vr(e,t.attributes);void 0!==a&&void 0!==t.backendNodeId&&n.set(a,t.backendNodeId);for(const e of t.children)r(e);void 0!==t.contentDocument&&r(t.contentDocument);for(const e of t.pseudoElements)r(e);for(const e of t.shadowRoots)r(e);void 0!==t.templateContent&&r(t.templateContent)};return r(t),n}function kr(e,t){return`(() => {\n const markerAttribute = ${JSON.stringify(e)};\n const maxCandidates = ${JSON.stringify(t)};\n const normalize = (value) => String(value ?? "").replace(/\\s+/g, " ").trim();\n const classTextOf = (element) => String(element.getAttribute("class") ?? "");\n const directTextOf = (element) => normalize(Array.from(element.childNodes)\n .filter((node) => node.nodeType === Node.TEXT_NODE)\n .map((node) => node.textContent ?? "")\n .join(" "));\n const visibleTextOf = (element) => normalize(\n element instanceof HTMLElement ? element.innerText : element.textContent\n );\n const hasCompositeOptionHint = (element) => {\n const pattern = /dropdown|menu|option|select|item/i;\n let current = element;\n for (let depth = 0; current && depth < 4; depth += 1) {\n if (pattern.test(classTextOf(current))) return true;\n current = current.parentElement;\n }\n return false;\n };\n const domActionNameOf = (element) => {\n const direct = directTextOf(element);\n if (direct) return direct;\n if (element.childElementCount === 0) return visibleTextOf(element);\n if (hasCompositeOptionHint(element)) return visibleTextOf(element);\n return "";\n };\n const isVisible = (element) => {\n if (element.closest("[hidden], [aria-hidden=\\"true\\"]")) return false;\n const style = window.getComputedStyle(element);\n if (style.visibility === "hidden" || style.display === "none") return false;\n const rect = element.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0;\n };\n const isDisabled = (element) =>\n element.matches(":disabled") ||\n element.getAttribute("aria-disabled") === "true" ||\n element.getAttribute("disabled") !== null;\n const isNativeSemantic = (element) => {\n const tag = element.tagName.toLowerCase();\n return (\n (tag === "a" && element.hasAttribute("href")) ||\n tag === "button" ||\n tag === "input" ||\n tag === "textarea" ||\n tag === "select" ||\n tag === "option" ||\n tag === "summary" ||\n element.hasAttribute("role")\n );\n };\n const hasNearbyClassHint = (element) => {\n const pattern = /btn|button|click|dropdown|tab|tabs|filter|menu|nav|option|select|switch|toggle/i;\n let current = element;\n for (let depth = 0; current && depth < 4; depth += 1) {\n if (pattern.test(classTextOf(current))) return true;\n current = current.parentElement;\n }\n return false;\n };\n const isCandidate = (element) => {\n if (!isVisible(element) || isNativeSemantic(element)) return false;\n const tag = element.tagName.toLowerCase();\n if (!["span", "div", "li", "label", "em", "i", "b", "strong"].includes(tag)) return false;\n const name = domActionNameOf(element);\n if (name.length === 0 || name.length > 100) return false;\n const style = window.getComputedStyle(element);\n const hasCursorPointer = style.cursor === "pointer";\n const hasOnClick = element.hasAttribute("onclick") || element.onclick !== null;\n const hasTabIndex = element.getAttribute("tabindex") !== null && element.getAttribute("tabindex") !== "-1";\n const contentEditable = element.getAttribute("contenteditable");\n const isEditable = contentEditable === "" || contentEditable === "true";\n const hasClassHint = hasNearbyClassHint(element);\n\n if (!hasCursorPointer && !hasOnClick && !hasTabIndex && !isEditable && !hasClassHint) {\n return false;\n }\n\n if (hasCursorPointer && !hasOnClick && !hasTabIndex && !isEditable && !hasClassHint) {\n const parent = element.parentElement;\n if (parent && window.getComputedStyle(parent).cursor === "pointer") return false;\n }\n return true;\n };\n const output = [];\n for (const element of document.querySelectorAll("body *")) {\n if (!isCandidate(element)) continue;\n if (element.closest("[" + markerAttribute + "]")) continue;\n const marker = String(output.length);\n const style = window.getComputedStyle(element);\n const contentEditable = element.getAttribute("contenteditable");\n element.setAttribute(markerAttribute, marker);\n output.push({\n marker,\n name: domActionNameOf(element),\n disabled: isDisabled(element),\n hasClassHint: hasNearbyClassHint(element),\n hasCursorPointer: style.cursor === "pointer",\n hasOnClick: element.hasAttribute("onclick") || element.onclick !== null,\n hasTabIndex: element.getAttribute("tabindex") !== null && element.getAttribute("tabindex") !== "-1",\n isEditable: contentEditable === "" || contentEditable === "true"\n });\n if (output.length >= maxCandidates) break;\n }\n return output;\n })()`}function Ar(e){return`(() => {\n const markerAttribute = ${JSON.stringify(e)};\n const elements = document.querySelectorAll("[" + markerAttribute + "]");\n for (const element of elements) {\n element.removeAttribute(markerAttribute);\n }\n return elements.length;\n })()`}async function Nr(e,t,n){if(void 0!==n.frameId){const n=await e.getDocument({depth:-1,pierce:!0});if(!gr(n))return new Map;const r=yr(n.root);return void 0===r?new Map:Rr(t,r)}const r=fr(await e.getDocument({depth:0}));if(void 0===r)return new Map;const a=await e.querySelectorAllByNodeId({nodeId:r,selector:`[${t}]`});return Cr(t,await Promise.all(a.map(async t=>await e.describeNode({nodeId:t}))))}async function Mr(e,t={}){const n="number"==typeof t?{maxCandidates:t}:t,r=pr(n.maxCandidates??ur);if(0===r)return[];const a=mr(),o=void 0===n.frameId?void 0:await e.createIsolatedWorld(n.frameId,{worldName:`roll-dom-action-${a.slice(dr.length)}`}).catch(()=>{});if(void 0!==n.frameId&&void 0===o)return[];const i=void 0===o?{}:{contextId:o},s=xr(await e.evaluateJson(kr(a,r),i).catch(()=>[]));try{if(0===s.length)return[];const t=await Nr(e,a,n);return s.flatMap(e=>{const n=t.get(e.marker);return void 0===n?[]:[{backendNodeId:n,kind:Sr(e),name:e.name,hints:Ir(e),disabled:e.disabled}]})}finally{await e.evaluateJson(Ar(a),i).catch(()=>{})}}var Er=28,Pr=90,Tr=250,_r=620,Br=8,Or=32,$r=8;function Dr(e){return new Promise(t=>{setTimeout(t,e)})}function qr(e,t,n){return Math.min(Math.max(e,t),n)}function jr(e,t){return Math.max(0,Math.floor(e??t))}function Fr(e){return{x:Math.round(Number.isFinite(e.x)?e.x:0),y:Math.round(Number.isFinite(e.y)?e.y:0)}}function Lr(e,t){return Math.hypot(t.x-e.x,t.y-e.y)}function zr(e){return e<.5?4*e*e*e:1-Math.pow(-2*e+2,3)/2}function Jr(e){const t=e.x>=96?-72:72,n=e.y>=72?-36:36;return{x:Math.max(1,e.x+t),y:Math.max(1,e.y+n)}}function Vr(e,t){return Math.round(e.x+e.y+t.x+t.y)%2==0?1:-1}function Hr(e,t){const n=Lr(e,t);if(n<=Br)return[e,t];const r=qr(Math.round(n/30),$r,Or),a=t.x-e.x,o=t.y-e.y,i=Math.max(n,1),s=-o/i,c=a/i,l=qr(.08*n,4,28)*Vr(e,t),d=[e];for(let i=1;i<r;i+=1){const u=i/r,m=zr(u),p=Math.sin(Math.PI*u)*l,g=Math.sin(.13*(e.x+t.y+17*i))*Math.min(1.8,n/180);d.push({x:Math.round(e.x+a*m+s*(p+g)),y:Math.round(e.y+o*m+c*(p+g))})}return d.push(t),d}function Ur(e,t){const n=Fr(t);return Hr(void 0===e?Jr(n):Fr(e),n)}var Wr=class{dispatcher;sleep;defaultStepDelayMs;lastPoint;constructor(e,t={}){this.dispatcher=e,this.sleep=t.sleep??Dr,this.defaultStepDelayMs=jr(t.stepDelayMs,Er)}reset(e){this.lastPoint=void 0===e?void 0:Fr(e)}async moveTo(e,t={}){const n=jr(t.stepDelayMs,this.defaultStepDelayMs),r=Ur(this.lastPoint,e),a=Math.max(r.length-1,0)*n;await(t.motionObserver?.previewMouseMotion({points:r,durationMs:a}));for(let e=0;e<r.length;e+=1){const a=r[e];void 0!==a&&(await this.dispatcher.dispatchMouseEvent({type:"mouseMoved",x:a.x,y:a.y,...void 0!==t.button?{button:t.button}:{},buttons:t.buttons??0}),e<r.length-1&&n>0&&await this.sleep(n))}return this.lastPoint=Fr(e),{points:r,durationMs:a}}async click(e,t={}){const n=t.button??"left",r=t.clickCount??1;await this.moveTo(e,{button:"none",buttons:0,...void 0!==t.motionObserver?{motionObserver:t.motionObserver}:{}}),await this.delayIfPositive(t.preClickDelayMs),await(t.motionObserver?.previewMouseClick?.({point:Fr(e),durationMs:_r})),await this.dispatcher.dispatchMouseEvent({type:"mousePressed",x:Math.round(e.x),y:Math.round(e.y),button:n,buttons:"left"===n?1:0,clickCount:r}),await this.delayIfPositive(t.pressDurationMs??Pr),await this.dispatcher.dispatchMouseEvent({type:"mouseReleased",x:Math.round(e.x),y:Math.round(e.y),button:n,buttons:0,clickCount:r}),await this.delayIfPositive(t.settleMs??Tr),this.lastPoint=Fr(e)}async drag(e,t,n={}){await this.moveTo(e,{button:"none",buttons:0,...void 0!==n.motionObserver?{motionObserver:n.motionObserver}:{},...void 0!==n.stepDelayMs?{stepDelayMs:n.stepDelayMs}:{}}),await this.dispatcher.dispatchMouseEvent({type:"mousePressed",x:Math.round(e.x),y:Math.round(e.y),button:"left",buttons:1,clickCount:1}),await this.delayIfPositive(n.pressDurationMs??Pr),this.reset(e),await this.moveTo(t,{button:"left",buttons:1,...void 0!==n.motionObserver?{motionObserver:n.motionObserver}:{},...void 0!==n.stepDelayMs?{stepDelayMs:n.stepDelayMs}:{}}),await this.dispatcher.dispatchMouseEvent({type:"mouseReleased",x:Math.round(t.x),y:Math.round(t.y),button:"left",buttons:0,clickCount:1}),this.lastPoint=Fr(t)}async delayIfPositive(e){const t=Math.max(0,Math.floor(e??0));t>0&&await this.sleep(t)}},Kr=14,Yr=720;function Gr(e){return`(() => {\n const args = ${JSON.stringify(e)};\n const activityRootId = "roll-agent-visual-activity-root";\n const activityViewportId = "roll-agent-visual-activity-viewport";\n const activityRegionId = "roll-agent-visual-activity-region";\n const activityCapsuleId = "roll-agent-visual-activity-capsule";\n const activityDotId = "roll-agent-visual-activity-dot";\n const activityLabelId = "roll-agent-visual-activity-label";\n const cursorRootId = "roll-agent-visual-cursor-root";\n const cursorPointerId = "roll-agent-visual-cursor-pointer";\n const cursorStateKey = "__rollVisualCursorState";\n\n const themes = {\n info: {\n accent: "#14b8a6",\n accentSoft: "rgba(20, 184, 166, 0.42)",\n accentGlow: "rgba(20, 184, 166, 0.18)",\n capsuleBg: "rgba(15, 23, 42, 0.82)",\n capsuleBorder: "rgba(45, 212, 191, 0.38)",\n text: "#F8FAFC",\n dot: "#2DD4BF"\n },\n success: {\n accent: "#22c55e",\n accentSoft: "rgba(34, 197, 94, 0.42)",\n accentGlow: "rgba(34, 197, 94, 0.18)",\n capsuleBg: "rgba(10, 24, 16, 0.86)",\n capsuleBorder: "rgba(74, 222, 128, 0.38)",\n text: "#F0FDF4",\n dot: "#4ADE80"\n },\n error: {\n accent: "#f59e0b",\n accentSoft: "rgba(245, 158, 11, 0.42)",\n accentGlow: "rgba(245, 158, 11, 0.2)",\n capsuleBg: "rgba(41, 24, 10, 0.88)",\n capsuleBorder: "rgba(251, 191, 36, 0.4)",\n text: "#FFFBEB",\n dot: "#FBBF24"\n }\n };\n\n const readRect = (selector, padding) => {\n if (!selector) return null;\n const element = document.querySelector(selector);\n if (!element) return null;\n const rect = element.getBoundingClientRect();\n if (rect.width <= 0 || rect.height <= 0) return null;\n const safePadding = Math.max(padding ?? 0, 0);\n const left = Math.max(rect.left - safePadding, 0);\n const top = Math.max(rect.top - safePadding, 0);\n const right = Math.min(rect.right + safePadding, window.innerWidth);\n const bottom = Math.min(rect.bottom + safePadding, window.innerHeight);\n return {\n x: Math.round(left),\n y: Math.round(top),\n width: Math.max(Math.round(right - left), 0),\n height: Math.max(Math.round(bottom - top), 0),\n centerX: Math.round(rect.left + rect.width / 2),\n centerY: Math.round(rect.top + rect.height / 2)\n };\n };\n\n const normalizeActivityViewport = (viewport) => {\n viewport.style.position = "fixed";\n viewport.style.inset = "0";\n viewport.style.opacity = "0";\n viewport.style.pointerEvents = "none";\n viewport.style.display = "none";\n viewport.style.border = "0";\n viewport.style.boxShadow = "none";\n viewport.style.borderRadius = "0";\n viewport.style.transform = "none";\n viewport.style.transition = "none";\n viewport.style.background = "transparent";\n };\n\n const showActivityViewportFrame = (viewport, theme, mode) => {\n normalizeActivityViewport(viewport);\n viewport.style.display = "block";\n viewport.style.opacity = mode === "complete" ? "0.28" : "0.22";\n viewport.style.background =\n "linear-gradient(180deg, " +\n theme.accentGlow +\n " 0%, transparent 16%, transparent 84%, " +\n theme.accentGlow +\n " 100%), linear-gradient(90deg, " +\n theme.accentGlow +\n " 0%, transparent 12%, transparent 88%, " +\n theme.accentGlow +\n " 100%)";\n viewport.style.boxShadow =\n "inset 0 0 0 2px " + theme.accentSoft + ", inset 0 0 28px " + theme.accentGlow;\n };\n\n const ensureActivityRoot = () => {\n let root = document.getElementById(activityRootId);\n if (root) {\n const viewport = document.getElementById(activityViewportId);\n if (viewport) normalizeActivityViewport(viewport);\n return root;\n }\n root = document.createElement("div");\n root.id = activityRootId;\n root.style.position = "fixed";\n root.style.inset = "0";\n root.style.pointerEvents = "none";\n root.style.zIndex = "2147483646";\n\n const viewport = document.createElement("div");\n viewport.id = activityViewportId;\n normalizeActivityViewport(viewport);\n\n const region = document.createElement("div");\n region.id = activityRegionId;\n region.style.position = "fixed";\n region.style.left = "0";\n region.style.top = "0";\n region.style.width = "0";\n region.style.height = "0";\n region.style.borderRadius = "18px";\n region.style.opacity = "0";\n region.style.transform = "translate(-9999px, -9999px)";\n region.style.transition =\n "transform 220ms cubic-bezier(0.22, 1, 0.36, 1), width 220ms ease, height 220ms ease, opacity 180ms ease";\n\n const capsule = document.createElement("div");\n capsule.id = activityCapsuleId;\n capsule.style.position = "fixed";\n capsule.style.left = "50%";\n capsule.style.top = "20px";\n capsule.style.display = "inline-flex";\n capsule.style.alignItems = "center";\n capsule.style.gap = "10px";\n capsule.style.padding = "10px 14px";\n capsule.style.borderRadius = "999px";\n capsule.style.opacity = "0";\n capsule.style.transform = "translate(-50%, -8px)";\n capsule.style.transition = "opacity 180ms ease, transform 220ms ease";\n capsule.style.backdropFilter = "blur(12px)";\n capsule.style.fontSize = "13px";\n capsule.style.fontWeight = "600";\n capsule.style.lineHeight = "18px";\n capsule.style.whiteSpace = "nowrap";\n\n const dot = document.createElement("div");\n dot.id = activityDotId;\n dot.style.width = "8px";\n dot.style.height = "8px";\n dot.style.borderRadius = "999px";\n\n const label = document.createElement("div");\n label.id = activityLabelId;\n label.setAttribute("aria-live", "polite");\n\n capsule.append(dot, label);\n root.append(viewport, region, capsule);\n document.documentElement.append(root);\n return root;\n };\n\n const applyTheme = (themeName, mode) => {\n const theme = themes[themeName] ?? themes.info;\n const viewport = document.getElementById(activityViewportId);\n const region = document.getElementById(activityRegionId);\n const capsule = document.getElementById(activityCapsuleId);\n const dot = document.getElementById(activityDotId);\n if (!viewport || !region || !capsule || !dot) return;\n showActivityViewportFrame(viewport, theme, mode);\n region.style.border = "1px solid " + theme.accentSoft;\n region.style.background = theme.accentGlow;\n region.style.boxShadow =\n "0 0 0 1px " + theme.accentSoft + ", 0 16px 42px " + theme.accentGlow;\n capsule.style.border = "1px solid " + theme.capsuleBorder;\n capsule.style.background = theme.capsuleBg;\n capsule.style.color = theme.text;\n capsule.style.boxShadow =\n "0 18px 46px rgba(15, 23, 42, 0.24), 0 0 0 1px " + theme.capsuleBorder;\n dot.style.background = theme.dot;\n dot.style.boxShadow = "0 0 0 5px " + theme.accentGlow;\n };\n\n const renderActivity = () => {\n if (!args.activity) return;\n ensureActivityRoot();\n const viewport = document.getElementById(activityViewportId);\n const region = document.getElementById(activityRegionId);\n const capsule = document.getElementById(activityCapsuleId);\n const label = document.getElementById(activityLabelId);\n if (!viewport || !region || !capsule || !label) return;\n\n if (args.activity.mode === "clear") {\n normalizeActivityViewport(viewport);\n region.style.opacity = "0";\n region.style.transform = "translate(-9999px, -9999px)";\n capsule.style.opacity = "0";\n capsule.style.transform = "translate(-50%, -8px)";\n return;\n }\n\n applyTheme(args.activity.tone ?? "info", args.activity.mode);\n\n if (typeof args.activity.label === "string") {\n label.textContent = args.activity.label;\n }\n\n capsule.style.opacity = "1";\n capsule.style.transform = "translate(-50%, 0)";\n\n const rect = args.activity.selector\n ? readRect(args.activity.selector, args.activity.padding ?? 14)\n : null;\n if (rect) {\n region.style.width = rect.width + "px";\n region.style.height = rect.height + "px";\n region.style.transform = "translate(" + rect.x + "px, " + rect.y + "px)";\n region.style.opacity = "1";\n } else {\n region.style.opacity = "0";\n region.style.transform = "translate(-9999px, -9999px)";\n }\n\n if (args.activity.mode === "complete") {\n window.setTimeout(() => {\n normalizeActivityViewport(viewport);\n region.style.opacity = "0";\n capsule.style.opacity = "0";\n capsule.style.transform = "translate(-50%, -8px)";\n }, Math.max(args.activity.lingerMs ?? 720, 0));\n }\n };\n\n const ensureCursorRoot = () => {\n let root = document.getElementById(cursorRootId);\n if (root) return root;\n root = document.createElement("div");\n root.id = cursorRootId;\n root.style.position = "fixed";\n root.style.left = "0";\n root.style.top = "0";\n root.style.width = "0";\n root.style.height = "0";\n root.style.pointerEvents = "none";\n root.style.zIndex = "2147483647";\n\n const pointer = document.createElement("div");\n pointer.id = cursorPointerId;\n pointer.setAttribute("aria-hidden", "true");\n pointer.style.position = "fixed";\n pointer.style.left = "0";\n pointer.style.top = "0";\n pointer.style.width = "24px";\n pointer.style.height = "24px";\n pointer.style.opacity = "0";\n pointer.style.transform = "translate(-9999px, -9999px)";\n pointer.style.willChange = "transform, opacity";\n pointer.style.filter = "drop-shadow(0 4px 8px rgba(15, 23, 42, 0.28))";\n pointer.innerHTML =\n '<svg viewBox="0 0 24 24" width="24" height="24" fill="none" xmlns="http://www.w3.org/2000/svg">' +\n '<path d="M4 2L18 14L11.4 15.3L14.6 22L10.7 23.5L7.6 16.8L3 21V2Z" fill="#FFFFFF" stroke="#0F172A" stroke-width="1.5" stroke-linejoin="round"/>' +\n '</svg>';\n\n root.append(pointer);\n document.documentElement.append(root);\n return root;\n };\n\n const readCursorPath = () => {\n if (!Array.isArray(args.cursor?.path?.points)) return null;\n const points = args.cursor.path.points\n .map((point) => {\n const x = Number(point?.x);\n const y = Number(point?.y);\n return Number.isFinite(x) && Number.isFinite(y)\n ? { centerX: Math.round(x), centerY: Math.round(y) }\n : null;\n })\n .filter((point) => point !== null);\n return points.length > 0 ? points : null;\n };\n\n const readCursorClick = () => {\n const point = args.cursor?.click?.point;\n const x = Number(point?.x);\n const y = Number(point?.y);\n if (!Number.isFinite(x) || !Number.isFinite(y)) return null;\n return {\n point: { centerX: Math.round(x), centerY: Math.round(y) },\n durationMs: Math.max(Number(args.cursor?.click?.durationMs ?? 620), 0)\n };\n };\n\n const renderClickPulse = (root, point, durationMs) => {\n const createPulse = (size, border, background, shadow, startScale, endScale, delayMs) => {\n const radius = size / 2;\n const pulse = document.createElement("div");\n pulse.setAttribute("aria-hidden", "true");\n pulse.style.position = "fixed";\n pulse.style.left = "0";\n pulse.style.top = "0";\n pulse.style.width = size + "px";\n pulse.style.height = size + "px";\n pulse.style.borderRadius = "9999px";\n pulse.style.border = border;\n pulse.style.background = background;\n pulse.style.boxShadow = shadow;\n pulse.style.pointerEvents = "none";\n pulse.style.opacity = "0.96";\n pulse.style.transformOrigin = "center center";\n pulse.style.transform =\n "translate(" + (point.centerX - radius) + "px, " + (point.centerY - radius) + "px) scale(" + startScale + ")";\n pulse.style.transition =\n "transform " + durationMs + "ms cubic-bezier(0.16, 1, 0.3, 1), opacity " + durationMs + "ms ease-out";\n root.append(pulse);\n\n window.setTimeout(() => {\n window.requestAnimationFrame(() => {\n pulse.style.opacity = "0";\n pulse.style.transform =\n "translate(" + (point.centerX - radius) + "px, " + (point.centerY - radius) + "px) scale(" + endScale + ")";\n });\n }, delayMs);\n\n window.setTimeout(() => {\n pulse.remove();\n }, durationMs + delayMs + 80);\n };\n\n createPulse(\n 28,\n "3px solid rgba(45, 212, 191, 0.98)",\n "rgba(20, 184, 166, 0.24)",\n "0 0 0 5px rgba(20, 184, 166, 0.18), 0 0 26px rgba(20, 184, 166, 0.34)",\n 0.55,\n 2.35,\n 0\n );\n createPulse(\n 14,\n "2px solid rgba(255, 255, 255, 0.95)",\n "rgba(255, 255, 255, 0.34)",\n "0 0 18px rgba(45, 212, 191, 0.45)",\n 0.7,\n 1.55,\n 65\n );\n };\n\n const renderCursor = () => {\n const path = readCursorPath();\n const click = readCursorClick();\n const point = path ? path[path.length - 1] : click?.point ?? null;\n if (!point) return;\n const root = ensureCursorRoot();\n const pointer = document.getElementById(cursorPointerId);\n if (!pointer) return;\n const targetX = point.centerX - 2;\n const targetY = point.centerY - 2;\n if (path && path.length > 1 && typeof pointer.animate === "function") {\n for (const animation of pointer.getAnimations()) {\n animation.cancel();\n }\n pointer.style.opacity = "1";\n const keyframes = path.map((entry) => ({\n transform: "translate(" + (entry.centerX - 2) + "px, " + (entry.centerY - 2) + "px)"\n }));\n const duration = Math.max(args.cursor.path.durationMs ?? 180, 0);\n const animation = pointer.animate(keyframes, {\n duration,\n easing: "cubic-bezier(0.22, 1, 0.36, 1)",\n fill: "forwards"\n });\n animation.onfinish = () => {\n pointer.style.transform = "translate(" + targetX + "px, " + targetY + "px)";\n };\n window[cursorStateKey] = { x: point.centerX, y: point.centerY };\n if (click) {\n renderClickPulse(root, click.point, click.durationMs);\n }\n return;\n }\n pointer.style.transition = "opacity 120ms ease";\n pointer.style.opacity = "1";\n pointer.style.transform = "translate(" + targetX + "px, " + targetY + "px)";\n window[cursorStateKey] = { x: point.centerX, y: point.centerY };\n if (click) {\n renderClickPulse(root, click.point, click.durationMs);\n }\n };\n\n renderActivity();\n renderCursor();\n return true;\n })()`}var Xr=class{target;constructor(e){this.target=e}async begin(e,t="info"){return!!Xe()&&await this.render({activity:{mode:"begin",label:e,tone:t}})}async highlightSelector(e,t={}){const n={...Xe()?{activity:{mode:"highlight",selector:e,label:t.label,padding:t.padding??Kr,tone:t.tone??"info"}}:{}};return"activity"in n&&await this.render(n)}async previewMouseMotion(e){ze()&&0!==e.points.length&&await this.render({cursor:{path:{points:e.points,durationMs:e.durationMs}}})}async previewMouseClick(e){ze()&&await this.render({cursor:{click:{point:e.point,durationMs:e.durationMs}}})}async succeed(e,t=Yr){return!!Xe()&&await this.render({activity:{mode:"complete",label:e,tone:"success",lingerMs:t}})}async fail(e,t=Yr){return!!Xe()&&await this.render({activity:{mode:"complete",label:e,tone:"error",lingerMs:t}})}async clear(){return!!Xe()&&await this.render({activity:{mode:"clear"}})}async render(e){try{return await this.target.evaluateJson(Gr(e))}catch{return!1}}};function Zr(e){return new Xr(e)}async function Qr(e,t,n){const r=new Wr(e);await r.click({x:n.x,y:n.y},{motionObserver:t})}var ea=or.object({pageId:or.string().optional().describe("可选:通过 list_pages 返回的 pageId/native targetId"),maxDepth:or.number().int().nonnegative().optional().describe("可选:限制 AX Tree 深度"),maxNodes:or.number().int().positive().optional().describe("可选:返回节点上限;实际值不会超过 Browser security maxSnapshotNodes"),interactiveOnly:or.boolean().default(!0).describe("默认 true:只返回可交互节点")}),ta=or.object({page:rr,snapshot:nr});function na(e){const t=[],n=e=>{"iframe"===e.role.toLowerCase()&&void 0!==e.backendNodeId&&t.push(e);for(const t of e.children??[])n(t)};for(const t of e)n(t);return t}async function ra(e,t){if(void 0===t.backendNodeId)return;const n=await e.describeNode({backendNodeId:t.backendNodeId,depth:1}).catch(()=>{});return n?.contentDocumentFrameId??n?.frameId}async function aa(e,t){const n=na(t);return(await Promise.all(n.map(async t=>{const n=await ra(e,t);return void 0===n?void 0:{node:t,frameId:n}}))).filter(e=>void 0!==e)}function oa(e){const t=Number.parseInt(e.slice(2),10);return Number.isFinite(t)?t:0}function ia(e){return e.refs.reduce((e,t)=>Math.max(e,oa(t.ref)),0)}function sa(e,t){return e.flatMap(e=>{const n=void 0===e.ref?void 0:t.get(e.ref);return void 0===n?[e]:[e,...sa(n.nodes,t)]})}function ca(e,t){return e.map(e=>{const n=void 0===e.ref?void 0:t.get(e.ref),r=ca(e.children??[],t),a=void 0===n?[]:ca(n.nodes,t),o=void 0===n?r:[...r,...a];return 0===o.length?e:{...e,children:o}})}async function la(e){let t=ia(e.snapshot),n=Math.max(0,e.snapshot.maxNodes-e.snapshot.nodeCount),r=e.snapshot.truncated;const a=new Set,o=[],i=[...await aa(e.controller,e.snapshot.nodes)];for(let s=0;s<i.length;s+=1){const c=i[s];if(void 0===c)continue;if(n<=0){r=!0;break}if(void 0===c.node.ref||a.has(c.frameId))continue;a.add(c.frameId);const l=await Mr(e.controller,{frameId:c.frameId,maxCandidates:n}).catch(()=>[]),d=await ar(e.controller,{depthOffset:c.node.depth+1,domActionHints:l,frameId:c.frameId,initialRefCount:t,interactiveOnly:e.snapshot.interactiveOnly,maxNodes:n,...void 0!==e.maxDepth?{maxDepth:e.maxDepth}:{}}).catch(()=>{});if(void 0===d||0===d.nodeCount||0===d.refs.length)continue;const u=await aa(e.controller,d.nodes);o.push({iframeRef:c.node.ref,snapshot:d}),i.push(...u),t=ia(d),n=Math.max(0,n-d.nodeCount),r=r||d.truncated}if(0===o.length)return{...e.snapshot,truncated:r};const s=new Map(o.map(e=>[e.iframeRef,e.snapshot])),c=o.flatMap(e=>e.snapshot.refs),l=o.reduce((e,t)=>e+t.snapshot.nodeCount,0);return{...e.snapshot,nodes:e.snapshot.interactiveOnly?sa(e.snapshot.nodes,s):ca(e.snapshot.nodes,s),refs:[...e.snapshot.refs,...c],nodeCount:e.snapshot.nodeCount+l,truncated:r}}var da=tr({name:"browser_snapshot",description:"读取当前或指定页面的 Accessibility Tree,并为可交互节点生成 @eN ref;默认只返回可交互节点。",input:ea,output:ta,execute:async(e,t)=>{const n=de(),r=ue(),a=await cr({runtime:n,ctxManager:r,...void 0!==e.pageId?{pageId:e.pageId}:{}});t.logger.info(`Creating browser AX snapshot for page ${a.targetId}`);const o=await n.connectNativePage(a),i=Zr(o);try{await i.begin("正在读取页面快照");const t=n.getConfig().security,s=Math.min(e.maxNodes??t.maxSnapshotNodes,t.maxSnapshotNodes),c=await Mr(o,s),l=await ar(o,{domActionHints:c,interactiveOnly:e.interactiveOnly??!0,maxNodes:s,...void 0!==e.maxDepth?{maxDepth:e.maxDepth}:{}}),d=await la({controller:o,snapshot:l,...void 0!==e.maxDepth?{maxDepth:e.maxDepth}:{}});return sr.saveSnapshot(a.targetId,d),await i.succeed(`已识别 ${d.refs.length} 个可操作元素`),{page:Wt(r,a),snapshot:d}}catch(e){throw await i.fail("读取页面快照失败"),e}finally{o.close()}}});import{StructuredToolError as ua,defineTool as ma}from"@roll-agent/sdk";import{BrowserActionApprovalSchema as pa,BrowserElementRefHandleSchema as ga,clickElementRef as fa}from"@roll-agent/browser";import{z as ha}from"zod";import{BrowserElementRefHandleSchema as ba}from"@roll-agent/browser";import{z as ya}from"zod";var va=ya.enum(["backend_node_id","role_name_nth"]),wa=ya.object({ref:ba,role:ya.string(),name:ya.string(),x:ya.number(),y:ya.number(),resolvedBy:va,backendNodeId:ya.number().int().positive().optional(),frameId:ya.string().optional(),disabled:ya.boolean()}),xa=ya.object({success:ya.literal(!0),ref:ba,resolvedBy:va,target:wa}),Sa=ha.object({ref:ga.describe("browser_snapshot 返回的 @eN element ref"),pageId:ha.string().optional().describe("可选:通过 list_pages 返回的 pageId/native targetId"),browserActionApproval:pa.optional().describe("当 actionPolicy=confirm 返回 needs_confirmation 后,由 orchestrator 原样带回的批准 ID。")}),Ia=ma({name:"click_ref",description:"点击 browser_snapshot 返回的 @eN ref;优先使用 backendNodeId,失效时使用 role/name/nth fallback。",input:Sa,output:xa,execute:async(e,t)=>{const n=de(),r=ue(),a=await cr({runtime:n,ctxManager:r,...void 0!==e.pageId?{pageId:e.pageId}:{}}),o=sr.getRef(a.targetId,e.ref);if(void 0===o)throw new ua({code:"not_found",message:`Element ref ${e.ref} is not available. Run browser_snapshot for this page first.`,details:{ref:e.ref,pageId:a.targetId}});const i=hn(t,n,{action:"click",target:e.ref,...void 0!==e.browserActionApproval?{approval:e.browserActionApproval}:{}}),s=await n.connectNativePage(a,{...fn(t,n,{approval:e.browserActionApproval,approvedByConfirmation:i.approvedByConfirmation,logActions:!1})});try{await wn({targetId:a.targetId,bringToFront:async()=>{await s.bringToFront()}},{runtime:n});const t=Zr(s);await t.begin(`正在点击 ${e.ref}`);const r=await fa({controller:s,elementRef:o,options:{clickTarget:async e=>{await Qr(s,t,e)}}});return await t.succeed(`已点击 ${e.ref}`),r}catch(t){await Zr(s).fail(`点击 ${e.ref} 失败`);const n=bn(t);if(void 0!==n)throw n;throw t}finally{s.close()}}});import{StructuredToolError as Ca,defineTool as Ra}from"@roll-agent/sdk";import{BrowserActionApprovalSchema as ka,BrowserElementRefHandleSchema as Aa,typeElementRef as Na}from"@roll-agent/browser";import{z as Ma}from"zod";var Ea=Ma.object({ref:Aa.describe("browser_snapshot 返回的 @eN element ref"),text:Ma.string().describe("要输入的文本"),clear:Ma.boolean().default(!1).describe("输入前是否先清空当前控件内容"),pageId:Ma.string().optional().describe("可选:通过 list_pages 返回的 pageId/native targetId"),browserActionApproval:ka.optional().describe("当 actionPolicy=confirm 返回 needs_confirmation 后,由 orchestrator 原样带回的批准 ID。")}),Pa=Ra({name:"type_ref",description:"向 browser_snapshot 返回的 @eN ref 输入文本;优先使用 backendNodeId,失效时使用 role/name/nth fallback。",input:Ea,output:xa,execute:async(e,t)=>{const n=de(),r=ue(),a=await cr({runtime:n,ctxManager:r,...void 0!==e.pageId?{pageId:e.pageId}:{}}),o=sr.getRef(a.targetId,e.ref);if(void 0===o)throw new Ca({code:"not_found",message:`Element ref ${e.ref} is not available. Run browser_snapshot for this page first.`,details:{ref:e.ref,pageId:a.targetId}});const i=hn(t,n,{action:"type",target:e.ref,...void 0!==e.browserActionApproval?{approval:e.browserActionApproval}:{}}),s=await n.connectNativePage(a,{...fn(t,n,{approval:e.browserActionApproval,approvedByConfirmation:i.approvedByConfirmation,logActions:!1})});try{await wn({targetId:a.targetId,bringToFront:async()=>{await s.bringToFront()}},{runtime:n});const t=Zr(s);await t.begin(`正在输入到 ${e.ref}`);const r=await Na({controller:s,elementRef:o,text:e.text,options:{...void 0!==e.clear?{clear:e.clear}:{},clickTarget:async e=>{await Qr(s,t,e)}}});return await t.succeed(`已输入到 ${e.ref}`),r}catch(t){await Zr(s).fail(`输入到 ${e.ref} 失败`);const n=bn(t);if(void 0!==n)throw n;throw t}finally{s.close()}}});import{defineTool as Ta}from"@roll-agent/sdk";import{BrowserPageInfoSchema as _a}from"@roll-agent/browser";import{z as Ba}from"zod";var Oa=["native","native-watch","native-ws-connect","native-page-bring-front","native-evaluate-url-no-runtime-enable","native-dom-read-no-runtime-enable","native-input-move-no-runtime-enable","native-runtime-enable","native-evaluate-url","native-dom-read","browser-attach","page-attach","network-watch","page-evaluate","detector-fingerprint","storage-summary"],$a=[...Oa,"native-ws-connect-watch","native-page-bring-front-watch","native-evaluate-url-no-runtime-enable-watch","native-dom-read-no-runtime-enable-watch","native-input-move-no-runtime-enable-watch","native-runtime-enable-watch","native-evaluate-url-watch","native-dom-read-watch","browser-attach-watch"],Da=Ba.enum(["localStorage","sessionStorage"]),qa=Ba.enum(["array","object","string","number","boolean","null"]),ja=Ba.enum(["empty","json","string"]),Fa=Ba.enum(Oa),La=Ba.enum($a),za=Ba.enum(["request","response"]),Ja=Ba.enum(["apm-action-log","device-action-report","boss-risk-report","zhipin-security"]),Va=Ba.object({area:Da,key:Ba.string(),valueLength:Ba.number().int().nonnegative(),valueKind:ja,jsonKind:qa.optional(),jsonTopLevelKeys:Ba.array(Ba.string()).optional(),jsonArrayLength:Ba.number().int().nonnegative().optional(),numericFields:Ba.record(Ba.number()).optional(),booleanFields:Ba.record(Ba.boolean()).optional(),arrayLengths:Ba.record(Ba.number().int().nonnegative()).optional()}),Ha=Ba.object({name:Ba.string(),domain:Ba.string(),path:Ba.string(),expires:Ba.string(),valueLength:Ba.number().int().nonnegative(),httpOnly:Ba.boolean(),secure:Ba.boolean(),sameSite:Ba.string().optional()}),Ua=Ba.object({before:Ba.number().optional(),after:Ba.number().optional(),delta:Ba.number().optional()}),Wa=Ba.object({before:Ba.boolean().optional(),after:Ba.boolean().optional()}),Ka=Ba.object({before:Ba.number().int().nonnegative().optional(),after:Ba.number().int().nonnegative().optional(),delta:Ba.number().int().optional()}),Ya=Ba.object({area:Da,key:Ba.string(),beforePresent:Ba.boolean(),afterPresent:Ba.boolean(),numericDeltas:Ba.record(Ua).optional(),booleanChanges:Ba.record(Wa).optional(),arrayLengthDeltas:Ba.record(Ka).optional()}),Ga=Ba.object({url:Ba.string(),title:Ba.string(),visibilityState:Ba.string(),hasFocus:Ba.boolean()}),Xa=Ba.object({navigatorWebdriver:Ba.boolean().optional(),userAgentContainsHeadless:Ba.boolean(),languagesLength:Ba.number().int().nonnegative(),pluginsLength:Ba.number().int().nonnegative(),hasChromeRuntime:Ba.boolean(),permissionQueryIsNative:Ba.boolean().optional(),hasPlaywrightBinding:Ba.boolean(),hasPwInitScripts:Ba.boolean(),cdcKeys:Ba.array(Ba.string()),webdriverKeys:Ba.array(Ba.string()),automationLikeWindowKeys:Ba.array(Ba.string())}),Za=Ba.object({rootNodeId:Ba.number().int(),rootNodeName:Ba.string(),childNodeCount:Ba.number().int().nonnegative().optional(),bodyTextLength:Ba.number().int().nonnegative().optional(),elementCount:Ba.number().int().nonnegative().optional()}),Qa=Ba.object({type:Ba.literal("mouseMoved"),x:Ba.number(),y:Ba.number()}),eo=Ba.object({targetId:Ba.string(),websocketUrlAvailable:Ba.boolean(),connected:Ba.boolean(),pageBroughtToFront:Ba.boolean().optional(),runtimeEnabled:Ba.boolean().optional(),evaluate:Ga.optional(),dom:Za.optional(),input:Qa.optional()}),to=Ba.object({phase:Fa,success:Ba.boolean(),durationMs:Ba.number().int().nonnegative(),error:Ba.string().optional()}),no=Ba.object({phase:La,capturedAt:Ba.string(),targetFound:Ba.boolean(),page:_a.optional(),urlChangedFromPrevious:Ba.boolean(),titleChangedFromPrevious:Ba.boolean(),previousUrl:Ba.string().optional(),currentUrl:Ba.string().optional(),previousTitle:Ba.string().optional(),currentTitle:Ba.string().optional()}),ro=Ba.object({kind:za,reason:Ja,capturedAt:Ba.string(),url:Ba.string(),method:Ba.string().optional(),resourceType:Ba.string().optional(),status:Ba.number().int().optional()}),ao=Ba.object({capturedAt:Ba.string(),url:Ba.string()}),oo=Ba.object({phase:Fa.default("native").describe("诊断阶段。默认 native 只枚举原生 CDP target;native-* 阶段使用原生 CDP page WebSocket;browser-attach 及更深阶段才会使用 Playwright attach。"),targetPageId:Ba.string().optional().describe("可选:通过 list_pages 或本工具 native 阶段看到的 BOSS 页面 pageId/targetId。"),watchMs:Ba.number().int().min(500).max(1e4).default(3e3).describe("native-watch / browser-attach 后置观察 / network-watch / storage-summary 内部等待窗口,单位毫秒。"),networkEventLimit:Ba.number().int().min(1).max(100).default(30).describe("network-watch 最多返回的相关 request/response 事件数。")}),io=Ba.object({success:Ba.boolean(),requestedPhase:Fa,mode:Ba.string(),nativePages:Ba.array(_a),targetPage:_a.optional(),browserAttached:Ba.boolean(),pageAttached:Ba.boolean(),nativeTimeline:Ba.array(no),networkEvents:Ba.array(ro).optional(),navigationEvents:Ba.array(ao).optional(),nativeCdp:eo.optional(),evaluate:Ga.optional(),detectorFingerprint:Xa.optional(),storage:Ba.object({localStorage:Ba.array(Va),sessionStorage:Ba.array(Va),cookies:Ba.array(Ha),counterDiffs:Ba.array(Ya)}).optional(),phases:Ba.array(to),warnings:Ba.array(Ba.string())}),so=["_AEG_CNT","_ZP_CNT_","__local__sec__store___"],co=new Set(so),lo=["native-ws-connect","native-page-bring-front","native-evaluate-url-no-runtime-enable","native-dom-read-no-runtime-enable","native-input-move-no-runtime-enable","native-runtime-enable","native-evaluate-url","native-dom-read"],uo=["native-page-bring-front","native-evaluate-url-no-runtime-enable","native-dom-read-no-runtime-enable","native-input-move-no-runtime-enable"],mo={"native-ws-connect":"native-ws-connect-watch","native-page-bring-front":"native-page-bring-front-watch","native-evaluate-url-no-runtime-enable":"native-evaluate-url-no-runtime-enable-watch","native-dom-read-no-runtime-enable":"native-dom-read-no-runtime-enable-watch","native-input-move-no-runtime-enable":"native-input-move-no-runtime-enable-watch","native-runtime-enable":"native-runtime-enable-watch","native-evaluate-url":"native-evaluate-url-watch","native-dom-read":"native-dom-read-watch"};function po(e){if(null===e)return"null";if(Array.isArray(e))return"array";switch(typeof e){case"boolean":return"boolean";case"number":return"number";case"string":default:return"string";case"object":return"object"}}function go(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function fo(e){return lo.includes(e)}function ho(e){return uo.includes(e)}function bo(e){try{return JSON.parse(e)}catch{return}}function yo(e){const t=Object.fromEntries(Object.entries(e).filter(e=>"number"==typeof e[1])),n=Object.fromEntries(Object.entries(e).filter(e=>"boolean"==typeof e[1])),r=Object.fromEntries(Object.entries(e).filter(e=>Array.isArray(e[1])).map(([e,t])=>[e,t.length]));return{...Object.keys(t).length>0?{numericFields:t}:{},...Object.keys(n).length>0?{booleanFields:n}:{},...Object.keys(r).length>0?{arrayLengths:r}:{}}}function vo(e){return new Promise(t=>{setTimeout(t,e)})}function wo(e){return co.has(e)}function xo(e,t){if(0===t.value.length)return{area:e,key:t.key,valueLength:0,valueKind:"empty"};const n=bo(t.value);if(void 0===n)return{area:e,key:t.key,valueLength:t.value.length,valueKind:"string"};const r=po(n),a=go(n)&&wo(t.key)?yo(n):{};return{area:e,key:t.key,valueLength:t.value.length,valueKind:"json",jsonKind:r,...go(n)?{jsonTopLevelKeys:Object.keys(n)}:{},...Array.isArray(n)?{jsonArrayLength:n.length}:{},...a}}function So(e){return{name:e.name,domain:e.domain,path:e.path,expires:e.expires>0?new Date(1e3*e.expires).toISOString():"Session",valueLength:e.value.length,httpOnly:e.httpOnly,secure:e.secure,...void 0!==e.sameSite?{sameSite:e.sameSite}:{}}}async function Io(e,t){const n=Date.now();try{return{result:await t(),phaseResult:{phase:e,success:!0,durationMs:Date.now()-n}}}catch(t){return{phaseResult:{phase:e,success:!1,durationMs:Date.now()-n,error:t instanceof Error?t.message:String(t)}}}}function Co(e,t,n){if(void 0!==t){const r=e.find(e=>e.targetId===t);return r?Ht(r.url,"zhipin")?r:void n.push(`targetPageId "${t}" is not a zhipin page.`):void n.push(`targetPageId "${t}" not found in native pages.`)}const r=e.filter(e=>Ht(e.url,"zhipin"));if(1===r.length)return r[0];0===r.length?n.push("No zhipin native page found. Open Boss first or pass targetPageId."):n.push("Multiple zhipin native pages found. Pass targetPageId to avoid ambiguity.")}function Ro(e,t,n,r){const a=n?.url,o=n?.title,i=r?.currentUrl,s=r?.currentTitle;return{phase:t,capturedAt:(new Date).toISOString(),targetFound:void 0!==n,...void 0!==n?{page:Wt(e,n)}:{},urlChangedFromPrevious:void 0!==i&&void 0!==a&&i!==a,titleChangedFromPrevious:void 0!==s&&void 0!==o&&s!==o,...void 0!==i?{previousUrl:i}:{},...void 0!==a?{currentUrl:a}:{},...void 0!==s?{previousTitle:s}:{},...void 0!==o?{currentTitle:o}:{}}}async function ko(e,t,n,r){const a=await e.listNativePages();return Ro(e,t,void 0!==n?a.find(e=>e.targetId===n):a.filter(e=>Ht(e.url,"zhipin"))[0],r)}async function Ao(e,t,n,r,a){try{const o=t[t.length-1],i=await ko(e,n,r,o);t.push(i),i.urlChangedFromPrevious&&a.push(`Target URL changed after ${n}: ${i.previousUrl??"(unknown)"} -> ${i.currentUrl??"(missing)"}.`)}catch(e){a.push(`Failed to capture native snapshot after ${n}: ${e instanceof Error?e.message:String(e)}.`)}}async function No(e,t,n,r,a,o){const i=t.length,s=Date.now();for(;;){await Ao(e,t,n,r,o);const i=a-(Date.now()-s);if(i<=0)break;await vo(Math.min(500,i))}return t.slice(i).some(e=>e.urlChangedFromPrevious)}function Mo(e){if(!go(e))throw new Error("Native CDP evaluate did not return an object value.");const t=e.url,n=e.title,r=e.visibilityState,a=e.hasFocus;if("string"!=typeof t||"string"!=typeof n||"string"!=typeof r||"boolean"!=typeof a)throw new Error("Native CDP evaluate returned an unexpected page summary shape.");return{url:t,title:n,visibilityState:r,hasFocus:a}}function Eo(e,t){if(!go(e))throw new Error("Native CDP DOM.getDocument did not return an object.");const n=e.root;if(!go(n))throw new Error("Native CDP DOM.getDocument did not return a root node.");const r=n.nodeId,a=n.nodeName,o=n.childNodeCount;if("number"!=typeof r||"string"!=typeof a)throw new Error("Native CDP DOM root node has an unexpected shape.");const i=go(t)?t:{},s=i.bodyTextLength,c=i.elementCount;return{rootNodeId:r,rootNodeName:a,..."number"==typeof o?{childNodeCount:o}:{},..."number"==typeof s?{bodyTextLength:s}:{},..."number"==typeof c?{elementCount:c}:{}}}async function Po(e){return Mo(await e.evaluateJson("(() => ({\n url: location.href,\n title: document.title,\n visibilityState: document.visibilityState,\n hasFocus: document.hasFocus()\n }))()"))}async function To(e){return Eo(await e.getDocument({depth:1,pierce:!1}),await e.evaluateJson('(() => ({\n bodyTextLength: document.body?.innerText?.length ?? 0,\n elementCount: document.querySelectorAll("*").length\n }))()'))}async function _o(e){return Eo(await e.getDocument({depth:1,pierce:!1}),void 0)}async function Bo(e){return await e.bringToFront(),!0}async function Oo(e){const t={type:"mouseMoved",x:0,y:0};return await e.dispatchMouseEvent({type:t.type,x:t.x,y:t.y}),t}async function $o(e,t,n,r,a,o){await Ao(e,t,n,r,o);const i=await No(e,t,mo[n],r,a,o);return i&&o.push(`Native CDP phase ${n} was followed by a native URL change; stop before deeper native CDP operations.`),i}async function Do(e,t,n,r){switch(e){case"native-page-bring-front":{const a=await Io(e,async()=>await Bo(t));return n.push(a.phaseResult),void 0!==a.result&&(r.pageBroughtToFront=a.result),a.phaseResult}case"native-evaluate-url-no-runtime-enable":{const a=await Io(e,async()=>await Po(t));return n.push(a.phaseResult),void 0!==a.result&&(r.evaluate=a.result),a.phaseResult}case"native-dom-read-no-runtime-enable":{const a=await Io(e,async()=>await _o(t));return n.push(a.phaseResult),void 0!==a.result&&(r.dom=a.result),a.phaseResult}case"native-input-move-no-runtime-enable":{const a=await Io(e,async()=>await Oo(t));return n.push(a.phaseResult),void 0!==a.result&&(r.input=a.result),a.phaseResult}}}async function qo(e){const t={targetId:e.target.targetId,websocketUrlAvailable:"string"==typeof e.target.webSocketDebuggerUrl&&e.target.webSocketDebuggerUrl.length>0,connected:!1},n=e.target.webSocketDebuggerUrl;let r;try{const a=await Io("native-ws-connect",async()=>{if(void 0===n||0===n.length)throw new Error("Native CDP target does not expose webSocketDebuggerUrl.");return await e.runtime.connectNativePage(e.target,{allowUnsafeRuntimeEnableForDiagnostics:!0})});if(e.phases.push(a.phaseResult),r=a.result,t.connected=a.phaseResult.success,!a.phaseResult.success||void 0===r)return{summary:t,triggeredNavigation:!1};const o=r;let i=await $o(e.ctxManager,e.nativeTimeline,"native-ws-connect",e.targetPageId,e.watchMs,e.warnings);if("native-ws-connect"===e.requestedPhase||i)return{summary:t,triggeredNavigation:i};if(ho(e.requestedPhase))return await Do(e.requestedPhase,o,e.phases,t),i=await $o(e.ctxManager,e.nativeTimeline,e.requestedPhase,e.targetPageId,e.watchMs,e.warnings),{summary:t,triggeredNavigation:i};const s=await Io("native-runtime-enable",async()=>await o.unsafeEnableRuntimeForDiagnostics());if(e.phases.push(s.phaseResult),t.runtimeEnabled=s.phaseResult.success,i=await $o(e.ctxManager,e.nativeTimeline,"native-runtime-enable",e.targetPageId,e.watchMs,e.warnings),!s.phaseResult.success||"native-runtime-enable"===e.requestedPhase||i)return{summary:t,triggeredNavigation:i};const c=await Io("native-evaluate-url",async()=>await Po(o));if(e.phases.push(c.phaseResult),void 0!==c.result&&(t.evaluate=c.result),i=await $o(e.ctxManager,e.nativeTimeline,"native-evaluate-url",e.targetPageId,e.watchMs,e.warnings),!c.phaseResult.success||"native-evaluate-url"===e.requestedPhase||i)return{summary:t,triggeredNavigation:i};const l=await Io("native-dom-read",async()=>await To(o));return e.phases.push(l.phaseResult),void 0!==l.result&&(t.dom=l.result),i=await $o(e.ctxManager,e.nativeTimeline,"native-dom-read",e.targetPageId,e.watchMs,e.warnings),l.phaseResult.success,{summary:t,triggeredNavigation:i}}finally{r?.close()}}function jo(e){const t=e.toLowerCase();return t.includes("device-action-report")?"device-action-report":t.includes("boss_risk_report")?"boss-risk-report":t.includes("apm-fe.zhipin.com")||t.includes("/wapi/zpapm/actionlog/")?"apm-action-log":t.includes("zhipin-security")||t.includes("/security/")?"zhipin-security":void 0}async function Fo(e,t,n){const r=[],a=[],o=e=>{r.length<n&&r.push(e)},i=e=>{const t=e.url(),n=jo(t);void 0!==n&&o({kind:"request",reason:n,capturedAt:(new Date).toISOString(),url:t,method:e.method(),resourceType:e.resourceType()})},s=e=>{const t=e.url(),n=jo(t);if(void 0===n)return;const r=e.request();o({kind:"response",reason:n,capturedAt:(new Date).toISOString(),url:t,method:r.method(),resourceType:r.resourceType(),status:e.status()})},c=e=>{a.push({capturedAt:(new Date).toISOString(),url:e.url()})};e.on("request",i),e.on("response",s),e.on("framenavigated",c);try{await vo(t)}finally{e.off("request",i),e.off("response",s),e.off("framenavigated",c)}return{networkEvents:r,navigationEvents:a}}function Lo(e,t){const n=e.contexts().flatMap(e=>e.pages()).filter(e=>!e.isClosed()&&Ht(e.url(),"zhipin"));return n.find(e=>e.url()===t.url)??n[0]}function zo(e,t){return{networkEvents:e.flatMap(e=>e.networkEvents).slice(0,t),navigationEvents:e.flatMap(e=>e.navigationEvents)}}async function Jo(e,t){return await e.evaluate(e=>{const t="localStorage"===e?window.localStorage:window.sessionStorage;return Array.from({length:t.length},(e,n)=>{const r=t.key(n)??"";return{key:r,value:r.length>0?t.getItem(r)??"":""}}).filter(e=>e.key.length>0)},t)}async function Vo(e){return(await e.evaluate(e=>{const t=["localStorage","sessionStorage"],n=[];for(const r of t){const t="localStorage"===r?window.localStorage:window.sessionStorage;for(const a of e){const e=t.getItem(a);null!==e&&n.push({area:r,key:a,value:e})}}return n},so)).map(e=>xo(e.area,{key:e.key,value:e.value}))}async function Ho(e){return await e.evaluate(()=>({url:location.href,title:document.title,visibilityState:document.visibilityState,hasFocus:document.hasFocus()}))}async function Uo(e){return await e.evaluate(()=>{const e=window,t=Object.keys(e),n=t.filter(e=>e.startsWith("cdc_")||e.includes("_cdc_")).slice(0,20),r=t.filter(e=>e.toLowerCase().includes("webdriver")).slice(0,20),a=t.filter(e=>{const t=e.toLowerCase();return t.includes("playwright")||t.includes("puppeteer")||t.includes("selenium")||t.includes("chromedriver")}).slice(0,20),o=navigator.permissions?.query,i="function"==typeof o?o.toString().includes("[native code]"):void 0;return{..."boolean"==typeof navigator.webdriver?{navigatorWebdriver:navigator.webdriver}:{},userAgentContainsHeadless:navigator.userAgent.toLowerCase().includes("headless"),languagesLength:navigator.languages?.length??0,pluginsLength:navigator.plugins?.length??0,hasChromeRuntime:"object"==typeof e.chrome&&null!==e.chrome&&"runtime"in e.chrome,...void 0!==i?{permissionQueryIsNative:i}:{},hasPlaywrightBinding:"__playwright__binding__"in e,hasPwInitScripts:"__pwInitScripts"in e,cdcKeys:n,webdriverKeys:r,automationLikeWindowKeys:a}})}function Wo(e){return new Map(e.map(e=>[`${e.area}:${e.key}`,e]))}function Ko(e,t){return[...new Set([...Object.keys(e??{}),...Object.keys(t??{})])]}function Yo(e,t){return{...void 0!==e?{before:e}:{},...void 0!==t?{after:t}:{},...void 0!==e&&void 0!==t?{delta:t-e}:{}}}function Go(e,t){return{...void 0!==e?{before:e}:{},...void 0!==t?{after:t}:{},...void 0!==e&&void 0!==t?{delta:t-e}:{}}}function Xo(e,t){const n=Wo(e),r=Wo(t),a=[...new Set([...n.keys(),...r.keys()])],o=[];for(const e of a){const t=n.get(e),a=r.get(e),i=a??t;if(!i)continue;const s={};for(const e of Ko(t?.numericFields,a?.numericFields)){const n=t?.numericFields?.[e],r=a?.numericFields?.[e];n!==r&&(s[e]=Yo(n,r))}const c={};for(const e of Ko(t?.booleanFields,a?.booleanFields)){const n=t?.booleanFields?.[e],r=a?.booleanFields?.[e];n!==r&&(c[e]={...void 0!==n?{before:n}:{},...void 0!==r?{after:r}:{}})}const l={};for(const e of Ko(t?.arrayLengths,a?.arrayLengths)){const n=t?.arrayLengths?.[e],r=a?.arrayLengths?.[e];n!==r&&(l[e]=Go(n,r))}void 0!==t&&void 0!==a&&0===Object.keys(s).length&&0===Object.keys(c).length&&0===Object.keys(l).length||o.push({area:i.area,key:i.key,beforePresent:void 0!==t,afterPresent:void 0!==a,...Object.keys(s).length>0?{numericDeltas:s}:{},...Object.keys(c).length>0?{booleanChanges:c}:{},...Object.keys(l).length>0?{arrayLengthDeltas:l}:{}})}return o}async function Zo(e,t){const[n,r,a]=await Promise.all([Jo(e,"localStorage"),Jo(e,"sessionStorage"),e.context().cookies()]),o=[...n.filter(e=>wo(e.key)).map(e=>xo("localStorage",e)),...r.filter(e=>wo(e.key)).map(e=>xo("sessionStorage",e))];return{localStorage:n.map(e=>xo("localStorage",e)),sessionStorage:r.map(e=>xo("sessionStorage",e)),cookies:a.filter(e=>e.domain.includes("zhipin.com")||e.domain.includes("bosszhipin.com")).map(e=>So(e)),counterDiffs:Xo(t,o)}}var Qo=Ta({name:"zhipin_diagnose_browser_state",description:"分阶段诊断 Boss 页面在原生 CDP page WebSocket、Playwright CDP attach、页面绑定、网络上报、evaluate、检测指纹、storage/cookie 读取时的状态;默认只做 native target 枚举,所有 storage/cookie 值均脱敏。",input:oo,output:io,execute:async(e,t)=>{const n=e.phase??"native",r=e.watchMs??3e3,a=e.networkEventLimit??30,o=ue(),i=de(),s=[],c=[],l=[];let d,u,m,p=!1,g=!1,f=e.targetPageId;t.logger.info(`Diagnosing zhipin browser state (phase: ${n})`);const h=await Io("native",async()=>await o.listNativePages());c.push(h.phaseResult);const b=h.result??[],y=b.map(e=>Wt(o,e)),v=Co(b,e.targetPageId,s);if(v&&(d=Wt(o,v),f=v.targetId,l.push(Ro(o,"native",v,void 0))),!h.phaseResult.success||"native"===n)return{success:h.phaseResult.success,requestedPhase:n,mode:i.mode,nativePages:y,...void 0!==d?{targetPage:d}:{},browserAttached:p,pageAttached:g,nativeTimeline:l,phases:c,warnings:s};if("native-watch"===n)return await No(o,l,"native-watch",f,r,s),{success:h.phaseResult.success&&void 0!==f,requestedPhase:n,mode:i.mode,nativePages:y,...void 0!==d?{targetPage:d}:{},browserAttached:p,pageAttached:g,nativeTimeline:l,phases:c,warnings:s};if(!v)return{success:!1,requestedPhase:n,mode:i.mode,nativePages:y,browserAttached:p,pageAttached:g,nativeTimeline:l,phases:c,warnings:s};if(fo(n)){const e=await qo({requestedPhase:n,target:v,runtime:i,ctxManager:o,targetPageId:f,watchMs:r,phases:c,nativeTimeline:l,warnings:s});return{success:c.every(e=>e.success)&&!e.triggeredNavigation,requestedPhase:n,mode:i.mode,nativePages:y,...void 0!==d?{targetPage:d}:{},browserAttached:p,pageAttached:g,nativeTimeline:l,nativeCdp:e.summary,phases:c,warnings:s}}const w=await Io("browser-attach",async()=>await i.getBrowser());c.push(w.phaseResult);const x=w.result;p=w.phaseResult.success,await Ao(o,l,"browser-attach",f,s);const S=await No(o,l,"browser-attach-watch",f,r,s);if(S&&s.push("Browser attach was followed by a native URL change; treat this account/browser profile as unsafe for Playwright-backed zhipin tools."),!w.phaseResult.success||"browser-attach"===n)return{success:c.every(e=>e.success)&&!S,requestedPhase:n,mode:i.mode,nativePages:y,...void 0!==d?{targetPage:d}:{},browserAttached:p,pageAttached:g,nativeTimeline:l,phases:c,warnings:s};if(S)return{success:!1,requestedPhase:n,mode:i.mode,nativePages:y,...void 0!==d?{targetPage:d}:{},browserAttached:p,pageAttached:g,nativeTimeline:l,phases:c,warnings:s};const I=[];let C;"network-watch"===n&&void 0!==x&&(C=Lo(x,v),C?I.push(Fo(C,r,a)):s.push("No attached zhipin page found before page-attach; network-watch starts after page-attach.")),o.rememberNativePageSelection("zhipin",v);const R=await Io("page-attach",async()=>await o.getPage("zhipin"));c.push(R.phaseResult);const k=R.result;if(g=R.phaseResult.success,k&&(d=await Kt(o,k)),await Ao(o,l,"page-attach",f,s),!R.phaseResult.success||!k){if("network-watch"===n&&I.length>0){const e=await Io("network-watch",async()=>zo(await Promise.all(I),a));c.push(e.phaseResult),e.result&&(u=e.result.networkEvents,m=e.result.navigationEvents)}return{success:c.every(e=>e.success),requestedPhase:n,mode:i.mode,nativePages:y,...void 0!==d?{targetPage:d}:{},browserAttached:p,pageAttached:g,nativeTimeline:l,...void 0!==u?{networkEvents:u}:{},...void 0!==m?{navigationEvents:m}:{},phases:c,warnings:s}}if("page-attach"===n)return{success:c.every(e=>e.success),requestedPhase:n,mode:i.mode,nativePages:y,...void 0!==d?{targetPage:d}:{},browserAttached:p,pageAttached:g,nativeTimeline:l,phases:c,warnings:s};if("network-watch"===n){C!==k&&I.push(Fo(k,r,a));const e=await Io("network-watch",async()=>zo(await Promise.all(I),a));return c.push(e.phaseResult),e.result&&(u=e.result.networkEvents,m=e.result.navigationEvents),await Ao(o,l,"network-watch",f,s),{success:c.every(e=>e.success),requestedPhase:n,mode:i.mode,nativePages:y,...void 0!==d?{targetPage:d}:{},browserAttached:p,pageAttached:g,nativeTimeline:l,...void 0!==u?{networkEvents:u}:{},...void 0!==m?{navigationEvents:m}:{},phases:c,warnings:s}}let A=[];if("storage-summary"===n){try{A=await Vo(k)}catch(e){s.push(`Failed to read storage counter baseline: ${e instanceof Error?e.message:String(e)}.`)}r>0&&await vo(r)}const N=await Io("page-evaluate",async()=>await Ho(k));c.push(N.phaseResult);const M=N.result;if(await Ao(o,l,"page-evaluate",f,s),!N.phaseResult.success||"page-evaluate"===n)return{success:c.every(e=>e.success),requestedPhase:n,mode:i.mode,nativePages:y,...void 0!==d?{targetPage:d}:{},browserAttached:p,pageAttached:g,nativeTimeline:l,...void 0!==M?{evaluate:M}:{},phases:c,warnings:s};const E=await Io("detector-fingerprint",async()=>await Uo(k));c.push(E.phaseResult);const P=E.result;if(await Ao(o,l,"detector-fingerprint",f,s),!E.phaseResult.success||"detector-fingerprint"===n)return{success:c.every(e=>e.success),requestedPhase:n,mode:i.mode,nativePages:y,...void 0!==d?{targetPage:d}:{},browserAttached:p,pageAttached:g,nativeTimeline:l,...void 0!==M?{evaluate:M}:{},...void 0!==P?{detectorFingerprint:P}:{},phases:c,warnings:s};const T=await Io("storage-summary",async()=>await Zo(k,A));c.push(T.phaseResult);const _=T.result;return await Ao(o,l,"storage-summary",f,s),{success:c.every(e=>e.success),requestedPhase:n,mode:i.mode,nativePages:y,...void 0!==d?{targetPage:d}:{},browserAttached:p,pageAttached:g,nativeTimeline:l,...void 0!==M?{evaluate:M}:{},...void 0!==P?{detectorFingerprint:P}:{},...void 0!==_?{storage:_}:{},phases:c,warnings:s}}});import{defineTool as ei}from"@roll-agent/sdk";import{z as ti}from"zod";import{setTimeout as ni}from"node:timers/promises";async function ri(e,t=300,n=800){const r=Math.floor(Math.random()*(n-t))+t;await e.waitForTimeout(r)}function ai(e){return e.trim().toLocaleLowerCase("zh-CN")}function oi(e,t){let n=0;for(const r of e)t.includes(r)&&(n+=1);return n}function ii(e,t){if(void 0!==t.conversationId){const n=e.find(e=>e.conversationId===t.conversationId);if(n)return n}const n=t.candidateName;if(n){const t=ai(n),r=e.filter(e=>e.name.length>0);let a=r.find(e=>ai(e.name)===t);if(a)return a;if(a=r.find(e=>{const n=ai(e.name);return n.includes(t)||t.includes(n)}),a)return a;const o=t.length<=2?1:t.length<=4?.75:.6;if(a=r.find(e=>{const n=ai(e.name);return oi(t,n)>=Math.ceil(Math.min(t.length,n.length)*o)}),a)return a}if(void 0!==t.index)return e[t.index]}var si=["chat-list","chat-history","recommend-list"],ci={"chat-list":{surface:"chat-list",defaultDirection:"down",containerSelectors:[".user-list.b-scroll-stable",".chat-user .user-list",".chat-user-list",".chat-list-wrapper",".chat-list-wrap",".chat-user .b-scroll-stable",".b-scroll-stable",".chat-user .user-container",".chat-user"],itemSelector:'.user-list.b-scroll-stable [role="listitem"], .geek-item',highlightSelector:".user-list.b-scroll-stable, .chat-user .user-container, .chat-user"},"chat-history":{surface:"chat-history",defaultDirection:"up",containerSelectors:[".conversation-message",".chat-message-list",".conversation-main",".conversation-box"],itemSelector:".chat-message-list > .message-item, .conversation-message .message-item",highlightSelector:".conversation-message, .chat-message-list, .conversation-main"},"recommend-list":{surface:"recommend-list",defaultDirection:"down",containerSelectors:["#recommend-list",".list-wrap.card-list-wrap",".card-list-wrap",".recommend-list-wrap",".recommend-list",".card-list",".candidate-list",".candidate-body",".geek-list",".list-wrap",".recommendV2"],itemSelector:".candidate-card-wrap, li.card-item, .geek-item",highlightSelector:".candidate-card-wrap, li.card-item, .geek-item"}};function li(e){return ci[e]}var di={login:{notLoggedIn:".header-login-btn"},unread:{container:".chat-list-wrap",listItem:'[role="listitem"]',geekItemWrap:".geek-item-wrap",item:".chat-item",unreadBadge:".badge-count",unreadBadgeNew:".badge-count.badge-count-common-less",unreadBadgeSpan:".badge-count span",unreadDot:".red-dot",figure:".figure",badge:".badge",candidateName:".candidate-name",candidateNameAlt:".chat-item-name",candidateNameSelectors:'[class*="name"], .nickname, .geek-name',candidateNameNew:".geek-name",jobTitle:".source-job",lastMessage:".push-text",lastMessageAlt:".chat-last-msg",messageTime:".time, .time-shadow",clickArea:".chat-item-content",unreadCandidates:".geek-item"},chat:{chatContainer:".chat-container",messageList:".message-list",messageItem:".message-item",messageContent:".message-content",messageText:".text-content",userMessage:".message-right",candidateMessage:".message-left",messageTime:".message-time",senderName:".sender-name",inputBox:".chat-input",inputTextarea:"textarea.chat-input",inputEditorId:"#boss-chat-editor-input",sendButton:".btn-send",conversationEditor:".conversation-editor",submitButton:".submit-content .submit",submitButtonActive:".submit-content .submit.active",submitContent:".submit-content",sendButtonAlt:".conversation-editor .submit-content",sendIcon:".submit-content .icon-send",systemMessage:".system-msg"},chatDetails:{candidateInfoContainer:".base-info-single-container, .base-info-content",candidateName:".name-box, .geek-name, .base-name",candidateInfoItem:".geek-info-item, .base-info-item, .base-info-single-detial > div",candidateTag:".geek-tag, .high-light-boss",communicationPosition:".position-name",communicationPositionAlt:".position-item:not(.expect) .value.high-light-boss",candidateExpectContainer:".position-item.expect",candidateExpectValue:".position-item.expect .value.job",candidateExpectSalary:".position-item.expect .high-light-orange",candidatePosition:".geek-position, .position-name",candidatePositionAlt:".position-content .value, .position-item .value",chatMessageContainer:".conversation-message, .message-list",messageItem:".message-item",messageTime:".message-time .time",messageTextSpan:".text span",systemMessage:".item-system",friendMessage:".item-friend",myMessage:".item-myself",resumeMessage:".item-resume",readStatus:".status-read"},exchangeWechat:{exchangeButtonPath:"#container > div:nth-child(1) > div > div.chat-box > div.chat-container > div.chat-conversation > div.conversation-box > div.conversation-operate > div.toolbar-box > div.toolbar-box-right > div.operate-exchange-left > div:nth-child(3) > span.operate-btn",exchangeButtonFallback:".operate-exchange-left .operate-btn",confirmDialog:".exchange-tooltip",confirmButton:".exchange-tooltip .btn-box .boss-btn-primary.boss-btn",confirmButtonPath:"#container > div:nth-child(1) > div > div.chat-box > div.chat-container > div.chat-conversation > div.conversation-box > div.conversation-operate > div.toolbar-box > div.toolbar-box-right > div.operate-exchange-left > div:nth-child(3) > div > div > span.boss-btn-primary.boss-btn",cancelButton:".exchange-tooltip .btn-box .boss-btn-outline.boss-btn",wechatCard:".message-card-top-wrap",wechatCardAlt:'[class*="d-top-text"]'},username:{primary:".nav-item.nav-logout .user-name",fallbacks:["#header > div > div > div.nav-item.nav-logout > div.top-profile-logout.ui-dropmenu.ui-dropmenu-drop-arrow > div.ui-dropmenu-label > div > span.user-name",".ui-dropmenu-label .user-name",".nav-logout .user-name","#header .user-name",".top-profile .user-name",".nav-user .user-name",".user-name",'[class*="user-name"]','[class*="username"]','[data-qa="user-name"]',".header-user-name","#header .label-name"]},nav:{sidebar:".side-wrap.side-wrap-v2",chatLink:'.side-wrap.side-wrap-v2 a[href*="/web/chat/index"]',recommendLink:'.side-wrap.side-wrap-v2 a[href*="/web/chat/recommend"]'},recommend:{iframe:"#recommendFrame",resumeIframe:'iframe[src*="c-resume"]',filterButton:".recommend-filter .filter-label, .filter-label-wrap .filter-label, .filter-label",filterPanel:".filter-panel",candidateItem:"[data-geek], .geek-item",candidateName:".name",candidateBaseInfo:".base-info",workExps:".timeline-wrap.work-exps",expectInfo:".row-flex, .timeline-wrap.expect",salaryWrap:".salary-wrap",tagsWrap:".tags-wrap",greetButton:".btn-greet, .op-btn",resumeCanvas:"div#resume > canvas#resume, canvas#resume",closeResumeBtn:".close-btn, .dialog-close",closeResumeBtnV2:".recommendV2 .close-btn"},candidateProfile:{panel:".candidate-info, .resume-info, .geek-info",name:".candidate-info .name, .geek-info .name",age:".candidate-info .age, .geek-info .age",gender:".candidate-info .gender, .geek-info .gender",experience:".candidate-info .experience, .geek-info .work-exp",education:".candidate-info .education, .geek-info .edu",expectedSalary:".candidate-info .salary, .geek-info .expect-salary",expectedPosition:".candidate-info .position, .geek-info .expect-position",activeTime:".candidate-info .active-time, .geek-info .active"}},ui=30,mi=new Set(["招聘规范","消息","首页","推荐牛人","看简历","我的客服","面试","招聘数据","账号权益","升级VIP","职位","职位管理","牛人","公司","数据统计","设置","帮助中心","登录","注册","退出登录","退出","BOSS直聘","下载APP","搜索","发布职位"]);function pi(e){const t=e.trim();return!(0===t.length||t.length>ui)&&(!mi.has(t)&&!/登录|注册|退出|下载|帮助|设置|管理/.test(t))}function gi(e){let t=e.priority;return mi.has(e.text.trim())&&(t+=10),e.text.trim().length>10&&(t+=5),/^[\u4e00-\u9fff]{2,4}$/.test(e.text.trim())&&(t-=.5),void 0!==e.xRatio&&(t-=4*(e.xRatio-.5)),t}function fi(e){const t=e.filter(e=>pi(e.text));if(0===t.length)return{found:!1};const n=new Map;for(const e of t){const t=e.text.trim(),r=n.get(t)??new Set;r.add(e.strategy),n.set(t,r)}const r=t.map(e=>{let t=gi(e);const r=n.get(e.text.trim())?.size??1;return r>1&&(t-=.5*r),{evidence:e,score:t}}).sort((e,t)=>e.score-t.score)[0];return r?{found:!0,username:r.evidence.text.trim(),strategy:r.evidence.strategy,source:r.evidence.source}:{found:!1}}var hi='.user-list.b-scroll-stable [role="listitem"], .geek-item',bi='.user-list.b-scroll-stable, .user-list.b-scroll-stable [role="listitem"], .geek-item',yi=".candidate-card-wrap",vi="[data-geek], .geek-item",wi=`${yi}, ${vi}`,xi=["/web/chat/recommend"],Si=250,Ii=300,Ci=900,Ri=1200,ki=4,Ai=4,Ni=250,Mi=90,Ei=520,Pi=16,Ti=50,_i=650,Bi=10,Oi=.015,$i="button, a, label, li, span, div, [role='button'], [role='radio']";function Di(e){return new Promise(t=>{setTimeout(t,e)})}function qi(e){return{x:e.x,y:e.y}}function ji(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function Fi(e){return e.includes("/web/chat/index")}function Li(e){return e.trim().toLocaleLowerCase("zh-CN")}function zi(e){return e.replace(/\s+/g,"").trim().toLocaleLowerCase("zh-CN")}function Ji(e,t){const n=Li(e),r=Li(t);return n.length>0&&r.length>0&&(n===r||n.includes(r)||r.includes(n))}function Vi(e){return"string"==typeof e?e:""}function Hi(e){return"number"==typeof e&&Number.isFinite(e)?e:0}function Ui(e){return"boolean"==typeof e&&e}function Wi(e){return Array.isArray(e)?e.map((e,t)=>{const n=ji(e)?e:{};return{conversationId:Vi(n.conversationId),candidateId:Vi(n.candidateId),name:Vi(n.name),index:"number"==typeof n.index&&Number.isInteger(n.index)?n.index:t,position:Vi(n.position),hasUnread:Ui(n.hasUnread),unreadCount:"number"==typeof n.unreadCount&&Number.isInteger(n.unreadCount)?n.unreadCount:0,lastMessageTime:Vi(n.lastMessageTime),messagePreview:Vi(n.messagePreview)}}):[]}function Ki(e){return Array.isArray(e)?e.flatMap(e=>{if(!ji(e))return[];const t=e.text,n=e.strategy,r=e.priority,a=e.source,o=e.xRatio;return"string"!=typeof t||"role-link"!==n&&"role-button"!==n&&"leaf-text"!==n&&"css-fallback"!==n||"number"!=typeof r||"string"!=typeof a?[]:[{text:t,strategy:n,priority:r,source:a,..."number"==typeof o?{xRatio:o}:{}}]}):[]}function Yi(e){return Array.isArray(e)?e.map((e,t)=>{const n=ji(e)?e:{},r=n.tags;return{index:"number"==typeof n.index&&Number.isInteger(n.index)?n.index:t,candidateId:Vi(n.candidateId),name:Vi(n.name),age:Vi(n.age),experience:Vi(n.experience),education:Vi(n.education),workStatus:Vi(n.workStatus),company:Vi(n.company),currentPosition:Vi(n.currentPosition),expectedLocation:Vi(n.expectedLocation),expectedPosition:Vi(n.expectedPosition),expectedSalary:Vi(n.expectedSalary),tags:Array.isArray(r)?r.map(e=>Vi(e)).filter(Boolean):[],buttonText:Vi(n.buttonText)}}):[]}function Gi(e){return Array.isArray(e)?e.map((e,t)=>{const n=ji(e)?e:{};return{index:"number"==typeof n.index&&Number.isInteger(n.index)?n.index:t,value:Vi(n.value),label:Vi(n.label),isCurrent:Ui(n.isCurrent)}}):[]}function Xi(e){return ji(e)?{found:Ui(e.found),isOpen:Ui(e.isOpen),currentLabel:Vi(e.currentLabel),currentValue:Vi(e.currentValue),options:Gi(e.options)}:{found:!1,isOpen:!1,currentLabel:"",currentValue:"",options:[]}}function Zi(e){if(!ji(e))return null;const t=Vi(e.conversationId),n=Vi(e.candidateId);return 0===t.length||0===n.length?null:{conversationId:t,candidateId:n,candidateName:Vi(e.candidateName)}}function Qi(e){if(!ji(e))return null;const t=Vi(e.candidateName);return t.length>0?{candidateName:t}:null}function es(e){return Array.isArray(e)?e.flatMap((e,t)=>{if(!ji(e))return[];const n=e.sender,r=e.messageType;return"candidate"!==n&&"recruiter"!==n&&"system"!==n||"text"!==r&&"system"!==r&&"resume"!==r&&"wechat-exchange"!==r?[]:[{index:"number"==typeof e.index&&Number.isInteger(e.index)?e.index:t,sender:n,messageType:r,content:Vi(e.content),time:Vi(e.time)}]}):[]}function ts(e){const t=ji(e)?e:{},n=t.tags;return{name:Vi(t.name),age:Vi(t.age),experience:Vi(t.experience),education:Vi(t.education),communicationPosition:Vi(t.communicationPosition),expectedJobText:Vi(t.expectedJobText),expectedSalary:Vi(t.expectedSalary),tags:Array.isArray(n)?n.map(e=>Vi(e)).filter(Boolean):[]}}function ns(e){const t=ji(e)?e:{};return{selectedTarget:Zi(t.selectedTarget),activePanel:Qi(t.activePanel),candidateInfo:ts(t.candidateInfo),messages:es(t.messages)}}function rs(e){return ji(e)?{found:Ui(e.found),x:Hi(e.x),y:Hi(e.y)}:{found:!1,x:0,y:0}}function as(e){return ji(e)?{found:Ui(e.found),left:Hi(e.left),top:Hi(e.top)}:{found:!1,left:0,top:0}}function os(e){return ji(e)?{found:Ui(e.found),cardSelector:Vi(e.cardSelector)||yi,candidateId:Vi(e.candidateId),name:Vi(e.name),..."string"==typeof e.age?{age:e.age}:{},..."string"==typeof e.experience?{experience:e.experience}:{},..."string"==typeof e.education?{education:e.education}:{},..."string"==typeof e.workStatus?{workStatus:e.workStatus}:{},..."string"==typeof e.company?{company:e.company}:{},..."string"==typeof e.currentPosition?{currentPosition:e.currentPosition}:{},..."string"==typeof e.expectedLocation?{expectedLocation:e.expectedLocation}:{},..."string"==typeof e.expectedPosition?{expectedPosition:e.expectedPosition}:{},..."string"==typeof e.expectedSalary?{expectedSalary:e.expectedSalary}:{},hasGreetButton:Ui(e.hasGreetButton),..."string"==typeof e.error?{error:e.error}:{}}:{found:!1,cardSelector:yi,candidateId:"",name:"",hasGreetButton:!1}}function is(e){return ji(e)?{..."number"==typeof e.ageMin?{ageMin:e.ageMin}:{},..."number"==typeof e.ageMax?{ageMax:e.ageMax}:{},..."number"==typeof e.minRatio?{minRatio:e.minRatio}:{},..."number"==typeof e.maxRatio?{maxRatio:e.maxRatio}:{}}:{}}function ss(e){return ji(e)&&!0===e.ok?{ok:!0,current:is(e.current),trackLeft:Hi(e.trackLeft),trackTop:Hi(e.trackTop),trackWidth:Hi(e.trackWidth),trackHeight:Hi(e.trackHeight),minHandleX:Hi(e.minHandleX),minHandleY:Hi(e.minHandleY),maxHandleX:Hi(e.maxHandleX),maxHandleY:Hi(e.maxHandleY)}:{ok:!1,error:ji(e)&&Vi(e.error)||"未找到年龄滑块"}}function cs(e){return ji(e)?{containerFound:Ui(e.containerFound),containerLabel:Vi(e.containerLabel),scrollTop:Hi(e.scrollTop),scrollHeight:Hi(e.scrollHeight),clientHeight:Hi(e.clientHeight),itemCount:Hi(e.itemCount),atStart:Ui(e.atStart),atEnd:Ui(e.atEnd)}:{containerFound:!1,containerLabel:"",scrollTop:0,scrollHeight:0,clientHeight:0,itemCount:0,atStart:!0,atEnd:!0}}function ls(e){return[e,...(e.childFrames??[]).flatMap(e=>ls(e))]}function ds(e){const t=new Set,n=[];for(const r of e){const e=r.conversationId.length>0?`conversation:${r.conversationId}`:`fallback:${r.name}:${r.messagePreview}:${r.index}`;t.has(e)||(t.add(e),n.push(r))}return n}function us(e){return e.candidateId.length>0?e.candidateId:0!==e.name.length?[e.name,e.age,e.experience,e.expectedLocation,e.expectedPosition,e.expectedSalary].join("|"):void 0}function ms(e,t,n){const r=t.filter(e=>Ht(e.url,"zhipin")),a=r.find(t=>e.isNativePageSelected(t.targetId));if(n.requireChatPage){if(a&&Fi(a.url))return a;const e=r.filter(e=>Fi(e.url));if(1===e.length){const t=e[0];if(t)return t}if(a)throw new Error("Selected BOSS page is not a chat page; switch to chat page first.");if(e.length>1)throw new Error("Multiple BOSS chat pages found; select the target tab first.");throw new Error("No BOSS chat page found; switch to chat page first.")}if(a)return a;if(1===r.length){const e=r[0];if(e)return e}if(r.length>1)throw new Error("Multiple BOSS pages found; select the target tab first.");throw new Error("No BOSS page found.")}async function ps(e={},t={}){const n=t.ctxManager??ue(),r=t.runtime??de(),a=ms(n,await n.listNativePages(),e),o=await r.connectNativePage(a);return new gs({target:a,controller:o})}var gs=class{target;controller;mouse;recommendFrameContextId;recommendFrameContextFrameId;constructor(e){this.target=e.target,this.controller=e.controller,this.mouse=new Wr(e.controller)}get targetId(){return this.target.targetId}async inspectPage(){return{...this.target,url:await this.url().catch(()=>this.target.url),title:await this.title().catch(()=>this.target.title)}}async url(){return await this.evaluateJson("location.href")}async title(){return await this.evaluateJson("document.title")}async waitForSelector(e,t=5e3){const n=Date.now();for(;Date.now()-n<t;){if(await this.evaluateJson(`document.querySelector(${JSON.stringify(e)}) !== null`).catch(()=>!1))return!0;await Di(Si)}return!1}async evaluateJson(e){return await this.controller.evaluateJson(e)}async bringToFront(){await this.controller.bringToFront()}async isChatSurfaceOpen(){return await this.evaluateJson(`location.href.includes("/web/chat/index") ||\n document.querySelector("#container.chat-container-private") !== null ||\n document.querySelector(${JSON.stringify(bi)}) !== null`)}async waitForChatSurface(e=8e3){const t=Date.now();for(;Date.now()-t<e;){if(await this.isChatSurfaceOpen().catch(()=>!1))return!0;await Di(Si)}return!1}async isRecommendSurfaceOpen(){const e=[di.recommend.iframe,'iframe[name="recommendFrame"]','iframe[src*="recommend"]'].join(", ");return await this.evaluateJson(`(() => {\n const href = location.href;\n const recommendUrlMarkers = ${JSON.stringify(xi)};\n const hasRecommendUrl = recommendUrlMarkers.some((marker) => href.includes(marker));\n if (hasRecommendUrl) {\n return true;\n }\n\n if (href.includes("/web/chat/index")) {\n return false;\n }\n\n const recommendFrame = document.querySelector(${JSON.stringify(e)});\n return recommendFrame !== null;\n })()`)}async waitForRecommendSurface(e=8e3){const t=Date.now();for(;Date.now()-t<e;){if(await this.isRecommendSurfaceOpen().catch(()=>!1))return!0;await Di(Si)}return!1}async resolveRecommendFrameContextId(){const e=await this.controller.getFrameTree().catch(()=>{});if(void 0===e)return;const t=ls(e).map(e=>e.frame),n=t.find(e=>"recommendFrame"===e.name),r=t.find(t=>t.id!==e.frame.id&&t.url.includes("recommend")),a=n??r;if(void 0===a)return;if(void 0!==this.recommendFrameContextId&&this.recommendFrameContextFrameId===a.id)return this.recommendFrameContextId;const o=await this.controller.createIsolatedWorld(a.id).catch(()=>{});return void 0!==o?(this.recommendFrameContextId=o,this.recommendFrameContextFrameId=a.id,o):void 0}async evaluateRecommendFrameJson(e){const t=await this.resolveRecommendFrameContextId();if(void 0!==t)return await this.controller.evaluateJson(e,{contextId:t}).catch(()=>{})}async readRecommendFrameOffset(){return as(await this.evaluateJson(`(() => {\n const iframe =\n document.querySelector(${JSON.stringify(di.recommend.iframe)}) ??\n document.querySelector('iframe[name="recommendFrame"]') ??\n document.querySelector('iframe[src*="recommend"]');\n if (!iframe) {\n return { found: false, left: 0, top: 0 };\n }\n const rect = iframe.getBoundingClientRect();\n return { found: rect.width > 0 && rect.height > 0, left: rect.left, top: rect.top };\n })()`).catch(()=>{}))}async resolveRecommendClickTarget(e){const t=rs(await this.evaluateJson(e).catch(()=>{}));if(t.found)return t;const n=rs(await this.evaluateRecommendFrameJson(e));if(!n.found)return n;const r=await this.readRecommendFrameOffset();return r.found?{found:!0,x:Math.round(n.x+r.left),y:Math.round(n.y+r.top)}:n}async dispatchNativeClick(e,t={}){return!!e.found&&(await this.mouse.click(qi(e),{...void 0!==t.motionObserver?{motionObserver:t.motionObserver}:{},...void 0!==t.preClickDelayMs?{preClickDelayMs:t.preClickDelayMs}:{},pressDurationMs:t.pressDurationMs??Mi,settleMs:t.settleMs??Ni}),!0)}async hasRecommendList(){if(!await this.isRecommendSurfaceOpen().catch(()=>!1))return!1;const e=`document.querySelector(${JSON.stringify(wi)}) !== null`;return!!await this.evaluateJson(e).catch(()=>!1)||(await this.evaluateRecommendFrameJson(e)??!1)}async waitForRecommendList(e=1e4){const t=Date.now();for(;Date.now()-t<e;)if(await this.isRecommendSurfaceOpen().catch(()=>!1)){if(await this.hasRecommendList().catch(()=>!1))return!0;await Di(Si)}else await Di(Si);return await this.hasRecommendList().catch(()=>!1)}async readRecommendJobSelectorState(){const e='(() => {\n const visible = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0;\n };\n const text = (element) => (element.textContent ?? "").replace(/\\s+/g, " ").trim();\n const wrap = document.querySelector(".job-selecter-wrap");\n if (!wrap) {\n return {\n found: false,\n isOpen: false,\n currentLabel: "",\n currentValue: "",\n options: []\n };\n }\n\n const list = wrap.querySelector(".ui-dropmenu-list");\n const options = Array.from(wrap.querySelectorAll(".job-list .job-item")).map(\n (item, index) => {\n const labelElement = item.querySelector(".label") ?? item;\n return {\n index,\n value: item.getAttribute("value") ?? item.getAttribute("data-value") ?? "",\n label: text(labelElement),\n isCurrent: item.classList.contains("curr")\n };\n },\n );\n const current = options.find((option) => option.isCurrent);\n const label = wrap.querySelector(".ui-dropmenu-label");\n return {\n found: true,\n isOpen: Boolean(list && visible(list)),\n currentLabel: current?.label ?? (label ? text(label) : ""),\n currentValue: current?.value ?? "",\n options\n };\n })()',t=Xi(await this.evaluateJson(e).catch(()=>{}));return t.found?t:Xi(await this.evaluateRecommendFrameJson(e))}async openRecommendJobSelector(e={}){if((await this.readRecommendJobSelectorState()).isOpen)return!0;const t=await this.resolveRecommendClickTarget('(() => {\n const visible = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0;\n };\n const wrap = document.querySelector(".job-selecter-wrap");\n const label = wrap?.querySelector(".ui-dropmenu-label") ?? wrap;\n if (!label || !visible(label)) {\n return { found: false, x: 0, y: 0 };\n }\n label.scrollIntoView({ block: "center", inline: "center" });\n const rect = label.getBoundingClientRect();\n return {\n found: true,\n x: Math.round(rect.left + rect.width / 2),\n y: Math.round(rect.top + rect.height / 2)\n };\n })()');return!!await this.dispatchNativeClick(t,e)&&(await Di(900),(await this.readRecommendJobSelectorState()).isOpen)}async setRecommendJobSearch(e,t={}){const n=await this.resolveRecommendClickTarget('(() => {\n const visible = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0;\n };\n const input = document.querySelector(".job-selecter-wrap .top-chat-search input.ipt.chat-job-search");\n if (!(input instanceof HTMLInputElement) || !visible(input)) {\n return { found: false, x: 0, y: 0 };\n }\n input.scrollIntoView({ block: "center", inline: "center" });\n const rect = input.getBoundingClientRect();\n return {\n found: true,\n x: Math.round(rect.left + rect.width / 2),\n y: Math.round(rect.top + rect.height / 2)\n };\n })()');if(!await this.dispatchNativeClick(n,t))return!1;if(await Di(260),await this.selectAllFocusedText(),await Di(160),await this.controller.dispatchKeyEvent({type:"rawKeyDown",key:"Backspace",code:"Backspace",windowsVirtualKeyCode:8,nativeVirtualKeyCode:8}),await Di(90),await this.controller.dispatchKeyEvent({type:"keyUp",key:"Backspace",code:"Backspace",windowsVirtualKeyCode:8,nativeVirtualKeyCode:8}),0===e.length)return await Di(500),!0;await Di(350);for(const t of Array.from(e))await this.controller.insertText(t),await Di(110);return await Di(650),!0}selectRecommendJobMatch(e,t){const n=e=>{const t=e[0];return{...void 0!==t?{selected:t}:{},matchedCount:e.length}};if(void 0!==e.jobValue){return n(t.filter(t=>t.value===e.jobValue))}if(void 0!==e.jobName){const r=zi(e.jobName),a=t.filter(e=>zi(e.label)===r);if(a.length>0)return n(a);return n(t.filter(e=>zi(e.label).includes(r)))}if(void 0!==e.index){return n(t.filter(t=>t.index===e.index))}return{matchedCount:0}}getCurrentRecommendJobOption(e){const t=e.options.find(e=>e.isCurrent);return void 0!==t?t:0!==e.currentLabel.length||0!==e.currentValue.length?{index:-1,value:e.currentValue,label:e.currentLabel,isCurrent:!0}:void 0}currentRecommendJobMatchesRequest(e,t){if(void 0===t)return!1;if(void 0!==e.jobValue&&t.value.length>0)return t.value===e.jobValue;if(void 0!==e.jobName&&t.label.length>0){const n=zi(e.jobName),r=zi(t.label);return r===n||r.includes(n)}return void 0!==e.index&&t.index===e.index}hasRecommendJobAlternative(e,t){return t.some(n=>!n.isCurrent&&(void 0===e?t.length>1:n.value.length>0&&e.value.length>0?n.value!==e.value:n.label!==e.label||n.index!==e.index))}async clickRecommendJobOption(e,t={}){const n=await this.resolveRecommendClickTarget(`(() => {\n const expectedValue = ${JSON.stringify(e.value)};\n const expectedIndex = ${JSON.stringify(e.index)};\n const visible = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0;\n };\n const items = Array.from(document.querySelectorAll(".job-selecter-wrap .job-list .job-item"));\n const item = items.find((candidate, index) => {\n const value = candidate.getAttribute("value") ?? candidate.getAttribute("data-value") ?? "";\n return expectedValue.length > 0 ? value === expectedValue : index === expectedIndex;\n });\n if (!item || !visible(item)) {\n return { found: false, x: 0, y: 0 };\n }\n item.scrollIntoView({ block: "center", inline: "center" });\n const rect = item.getBoundingClientRect();\n return {\n found: true,\n x: Math.round(rect.left + rect.width / 2),\n y: Math.round(rect.top + rect.height / 2)\n };\n })()`);return await this.dispatchNativeClick(n,t)}async listRecommendJobs(e={}){if(!await this.waitForRecommendList(3e3))return{success:!1,status:"recommend_not_ready",options:[],availableCount:0,canSwitch:!1,error:"推荐牛人页未就绪"};if(!await this.openRecommendJobSelector(e)){const e=await this.readRecommendJobSelectorState(),t=this.getCurrentRecommendJobOption(e);return{success:!1,status:e.found?"selector_not_found":"recommend_not_ready",...void 0!==t?{current:t}:{},options:e.options,availableCount:e.options.length,canSwitch:!1,error:e.found?"未找到或无法打开岗位下拉":"未找到岗位下拉"}}await this.setRecommendJobSearch("",e),await Di(700);const t=await this.readRecommendJobSelectorState(),n=this.getCurrentRecommendJobOption(t);return{success:!0,status:"listed",...void 0!==n?{current:n}:{},options:t.options,availableCount:t.options.length,canSwitch:this.hasRecommendJobAlternative(n,t.options)}}async selectRecommendJob(e,t={}){const n={...e};if(!await this.waitForRecommendList(3e3))return{success:!1,status:"recommend_not_ready",requested:n,options:[],matchedCount:0,error:"推荐牛人页未就绪"};if(!await this.openRecommendJobSelector(t)){const e=await this.readRecommendJobSelectorState(),t=e.options.find(e=>e.isCurrent);return{success:!1,status:e.found?"selector_not_found":"recommend_not_ready",requested:n,...void 0!==t?{current:t}:{},options:e.options,matchedCount:0,error:e.found?"未找到或无法打开岗位下拉":"未找到岗位下拉"}}await this.setRecommendJobSearch("",t),await Di(700);let r=await this.readRecommendJobSelectorState();const a=this.getCurrentRecommendJobOption(r);if(void 0!==a&&this.currentRecommendJobMatchesRequest(n,a)&&!0!==n.forceClick)return{success:!0,status:"already_selected",requested:n,current:a,selected:a,options:r.options,matchedCount:1};let o=this.selectRecommendJobMatch(n,r.options);const i=n.searchKeyword??n.jobName;void 0===o.selected&&!1!==n.useSearch&&void 0!==i&&i.trim().length>0&&await this.setRecommendJobSearch(i,t)&&(await Di(900),r=await this.readRecommendJobSelectorState(),o=this.selectRecommendJobMatch(n,r.options));const s=this.getCurrentRecommendJobOption(r);if(void 0===o.selected)return{success:!1,status:"not_found",requested:n,...void 0!==s?{current:s}:{},options:r.options,matchedCount:o.matchedCount,error:"未找到匹配的招聘岗位"};if(o.selected.isCurrent&&!0!==n.forceClick)return{success:!0,status:"already_selected",requested:n,current:o.selected,selected:o.selected,options:r.options,matchedCount:o.matchedCount};if(!await this.clickRecommendJobOption(o.selected,t))return{success:!1,status:"selector_not_found",requested:n,...void 0!==s?{current:s}:{},selected:o.selected,options:r.options,matchedCount:o.matchedCount,error:"未能点击匹配的招聘岗位"};let c=await this.readRecommendJobSelectorState();for(let e=0;e<6;e+=1){const e=this.getCurrentRecommendJobOption(c);if(e?.value===o.selected.value||e?.label===o.selected.label)break;await Di(600),c=await this.readRecommendJobSelectorState()}const l=c.options.find(e=>e.value===o.selected?.value)??o.selected;return{success:!0,status:"selected",requested:n,current:l,selected:l,options:c.options.length>0?c.options:r.options,matchedCount:o.matchedCount}}async clickSidebarSection(e,t={}){const n="chat"===e?di.nav.chatLink:di.nav.recommendLink,r=rs(await this.evaluateJson(`(() => {\n const selector = ${JSON.stringify(n)};\n const labels = ${JSON.stringify("chat"===e?["沟通","消息"]:["推荐牛人"])};\n const normalizedLabels = labels.map((label) => label.replace(/\\s+/g, ""));\n const interactiveSelector = 'a, button, [role="link"], [role="button"]';\n const textSelector = 'span, div, li, a, button, [role="link"], [role="button"]';\n const visible = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0;\n };\n const normalizeText = (element) =>\n (element.textContent ?? "").replace(/\\s+/g, "").trim();\n const matchesExactLabel = (element) => {\n const text = normalizeText(element);\n return normalizedLabels.some((label) => text === label);\n };\n const matchesInteractiveLabel = (element) => {\n const text = normalizeText(element);\n return normalizedLabels.some(\n (label) =>\n text === label ||\n text.startsWith(label) ||\n (text.includes(label) && text.length <= label.length + 8),\n );\n };\n const area = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width * rect.height;\n };\n const readCenter = (element) => {\n element.scrollIntoView({ block: "center", inline: "center" });\n const rect = element.getBoundingClientRect();\n return {\n found: true,\n x: Math.round(rect.left + rect.width / 2),\n y: Math.round(rect.top + rect.height / 2)\n };\n };\n\n const sidebar = document.querySelector(${JSON.stringify(di.nav.sidebar)}) ?? document;\n const selectorTargets = Array.from(document.querySelectorAll(selector))\n .filter((element) => visible(element))\n .sort((left, right) => area(left) - area(right));\n if (selectorTargets[0]) {\n return readCenter(selectorTargets[0]);\n }\n\n const interactiveTargets = Array.from(sidebar.querySelectorAll(interactiveSelector))\n .filter((element) => visible(element) && matchesInteractiveLabel(element))\n .sort((left, right) => area(left) - area(right));\n if (interactiveTargets[0]) {\n return readCenter(interactiveTargets[0]);\n }\n\n const exactTextTargets = Array.from(sidebar.querySelectorAll(textSelector))\n .filter((element) => visible(element) && matchesExactLabel(element))\n .sort((left, right) => area(left) - area(right));\n if (exactTextTargets[0]) {\n return readCenter(exactTextTargets[0]);\n }\n\n return { found: false, x: 0, y: 0 };\n })()`));return!!r.found&&await this.dispatchNativeClick(r,t)}async scrollSurface(e,t={}){const n=li(e),r=t.direction??n.defaultDirection,a=Math.max(0,Math.floor(t.steps??1)),o=Math.max(0,Math.floor(t.settleMs??700)),i=await this.inspectSurface(e);let s=i,c=0;for(let n=0;n<a;n+=1){if("chat-list"===e&&s.itemCount>0){const n=await this.scrollSurfaceWithWheel(e,r,t.distance);if(void 0===n)break;if(s=n,c+=1,o>0){await Di(o);const t=await this.inspectSurface(e);s=t.containerFound||!s.containerFound?t:s}continue}if("up"===r&&s.atStart||"down"===r&&s.atEnd){if(s.itemCount<=0)break;const n=await this.scrollSurfaceWithWheel(e,r,t.distance);if(void 0===n)break;if(s=n,c+=1,o>0){await Di(o);const t=await this.inspectSurface(e);s=t.containerFound||!s.containerFound?t:s}continue}if(s=await this.scrollSurfaceOnce(e,r,t.distance),c+=1,o>0){await Di(o);const t=await this.inspectSurface(e);s=t.containerFound||!s.containerFound?t:s}}return{success:i.containerFound||s.containerFound||c>0,direction:r,stepsRequested:a,stepsCompleted:c,reachedBoundary:"up"===r?s.atStart:s.atEnd,before:i,after:s}}async readChatCandidates(e={}){const t=e.targetCount??20,n=e.autoScroll?e.maxScrolls??3:0,r=[];for(let e=0;e<=n;e+=1){r.push(...await this.readVisibleChatCandidates());const a=ds(r);if(a.length>=t||e===n)return a;if(!(await this.scrollChatList()).ok)return a;await Di(Ii)}return ds(r)}async openChat(e){if(await wn(this),!await this.isChatSurfaceOpen().catch(()=>!1)){if(!await this.clickSidebarSection("chat",{...void 0!==e.motionObserver?{motionObserver:e.motionObserver}:{}})||!await this.waitForChatSurface())return{found:!1,conversationId:"",candidateId:"",name:e.candidateName??"",index:e.index??-1,position:"",hasUnread:!1,unreadCount:0,lastMessageTime:"",messagePreview:"",error:"消息列表未加载"}}const t=void 0!==e.conversationId||void 0!==e.candidateName||void 0!==e.index,n=Math.max(0,Math.floor(e.maxScrolls??(t?12:4))),r=async t=>{if(!await this.clickChatCandidate(t,{...void 0!==e.motionObserver?{motionObserver:e.motionObserver}:{}}))return{...t,found:!1,error:`未能点击候选人: ${t.name||t.conversationId}`};await Di(Ni);let n=await this.waitForNativeChatReady(t);if(!n){await this.clickChatCandidate(t,{...void 0!==e.motionObserver?{motionObserver:e.motionObserver}:{}})&&(await Di(Ni),n=await this.waitForNativeChatReady(t))}return n?{...t,found:!0}:{...t,found:!1,error:`打开候选人聊天后,右侧会话未同步切换到 ${t.name||t.conversationId}`}},a=async(n,a)=>{const o=[];for(let i=0;i<=a;i+=1){o.push(...await this.readVisibleChatCandidates());const s=ds(o),c=!0!==e.preferUnread||t?ii(s,e):s.find(e=>e.hasUnread);if(void 0!==c)return await r(c);if(i>=a)break;if(!(await this.scrollChatList(n)).ok)break;await Di(Ii)}},o=await a("down",t?0:n);if(void 0!==o)return o;if(t&&n>0){for(let e=0;e<n;e+=1){const e=await this.scrollChatList("up");if(!e.ok||e.after<=1||e.after>=e.before)break;await Di(Ii)}const e=await a("down",n);if(void 0!==e)return e}return{found:!1,conversationId:"",candidateId:"",name:e.candidateName??"",index:e.index??-1,position:"",hasUnread:!1,unreadCount:0,lastMessageTime:"",messagePreview:"",error:`未找到候选人: ${e.candidateName??(void 0!==e.conversationId?`conversationId ${e.conversationId}`:`index ${e.index??0}`)}`}}async readSelectedChatTarget(){return Zi(await this.evaluateJson('(() => {\n const selected = document.querySelector(".geek-item.selected");\n if (!selected) {\n return null;\n }\n\n const conversationId =\n selected.getAttribute("data-id") ??\n selected.closest(\'[role="listitem"]\')?.getAttribute("key") ??\n "";\n const candidateId =\n selected.getAttribute("data-geek") ??\n selected.querySelector("[data-geek]")?.getAttribute("data-geek") ??\n conversationId;\n const candidateName =\n selected\n .querySelector(\'[class*="name"], .nickname, .geek-name, .candidate-name\')\n ?.textContent?.trim() ?? "";\n\n return { conversationId, candidateId, candidateName };\n })()'))}async readActiveChatPanel(){return Qi(await this.evaluateJson('(() => {\n const rootSelectors = [".chat-conversation", ".conversation-box", ".conversation-message"];\n const nameSelectors = [\n ".base-info-single-detial .name-box",\n ".base-info-content .name-box",\n ".base-info-single-container .name-box",\n ".base-info-content .base-name",\n ".chat-user-name",\n ".name-box",\n ".base-name",\n ];\n\n for (const rootSelector of rootSelectors) {\n const root = document.querySelector(rootSelector);\n if (!root) continue;\n\n for (const nameSelector of nameSelectors) {\n const candidateName = root.querySelector(nameSelector)?.textContent?.trim() ?? "";\n if (candidateName.length > 0) {\n return { candidateName };\n }\n }\n }\n\n return null;\n })()'))}async waitForChatMessages(e=8e3){const t=Date.now();for(;Date.now()-t<e;){if(await this.evaluateJson('document.querySelector(".chat-message-list .message-item, .conversation-message .message-item") !== null').catch(()=>!1))return!0;await Di(Si)}return await this.evaluateJson('document.querySelector(".chat-message-list .message-item, .conversation-message .message-item") !== null').catch(()=>!1)}async readCandidateChatDetails(e){const t=Math.max(0,Math.floor(e));return ns(await this.evaluateJson(`(() => {\n const maxMsgs = ${JSON.stringify(t)};\n const selected = document.querySelector(".geek-item.selected");\n const selectedTarget = selected\n ? {\n conversationId:\n selected.getAttribute("data-id") ??\n selected.closest('[role="listitem"]')?.getAttribute("key") ??\n "",\n candidateId:\n selected.getAttribute("data-geek") ??\n selected.querySelector("[data-geek]")?.getAttribute("data-geek") ??\n selected.getAttribute("data-id") ??\n selected.closest('[role="listitem"]')?.getAttribute("key") ??\n "",\n candidateName:\n selected\n .querySelector('[class*="name"], .nickname, .geek-name, .candidate-name')\n ?.textContent?.trim() ?? ""\n }\n : null;\n\n const conversationRoot =\n document.querySelector(".chat-conversation") ??\n document.querySelector(".conversation-box") ??\n document;\n\n const nameSelectors = [\n ".base-info-single-detial .name-box",\n ".base-info-content .name-box",\n ".base-info-single-container .name-box",\n ".base-info-content .base-name",\n ".chat-user-name",\n ".name-box",\n ".base-name"\n ];\n let activePanel = null;\n for (const nameSelector of nameSelectors) {\n const candidateName =\n conversationRoot.querySelector(nameSelector)?.textContent?.trim() ?? "";\n if (candidateName.length > 0) {\n activePanel = { candidateName };\n break;\n }\n }\n\n const detailArea = conversationRoot.querySelector(\n ".base-info-single-detial, .base-info-content, .base-info-single-container"\n );\n const name =\n detailArea\n ?.querySelector(".name-box, .base-name, .chat-user-name, .geek-name")\n ?.textContent?.trim() ?? "";\n\n const infoItems = detailArea\n ? detailArea.querySelectorAll(":scope > div")\n : conversationRoot.querySelectorAll(".geek-info-item, .base-info-item");\n const infoTexts = [];\n infoItems.forEach((el) => {\n const text = el.textContent?.trim();\n if (text) infoTexts.push(text);\n });\n const fullInfo = infoTexts.join(" ");\n\n const ageMatch = fullInfo.match(/(\\d{2,3})岁/);\n const age = ageMatch ? ageMatch[1] + "岁" : "";\n const expMatch = fullInfo.match(/(\\d+年(?:以上)?|应届生|在校生)/);\n const experience = expMatch?.[1] ?? "";\n const education = fullInfo.match(/(初中|高中|中专|大专|本科|硕士|博士)/)?.[1] ?? "";\n\n let communicationPosition = "";\n const posNameEl = conversationRoot.querySelector(".position-name");\n if (posNameEl) {\n const cloned = posNameEl.cloneNode(true);\n cloned.querySelectorAll(".popover-wrap, .tooltip-job").forEach((element) => element.remove());\n communicationPosition = cloned.textContent?.trim() ?? "";\n }\n\n let expectedJobText = "";\n const expectValue = conversationRoot.querySelector(".position-item.expect .value.job");\n if (expectValue) {\n expectedJobText = expectValue.textContent?.trim() ?? "";\n }\n const expectedSalary =\n conversationRoot\n .querySelector(".position-item.expect .high-light-orange")\n ?.textContent?.trim() ?? "";\n\n const tags = [];\n if (detailArea) {\n detailArea\n .querySelectorAll(".geek-tag, .base-info-item .high-light-boss")\n .forEach((element) => {\n const text = element.textContent?.trim();\n if (text && !text.includes("更换职位") && text.length < 20) tags.push(text);\n });\n }\n\n const msgItems = conversationRoot.querySelectorAll(\n ".chat-message-list > .message-item, .conversation-message .message-item"\n );\n const timeRegex = /\\d{1,2}:\\d{2}(?::\\d{2})?|\\d{4}-\\d{2}-\\d{2}/;\n const messages = [];\n let msgIdx = 0;\n\n msgItems.forEach((item) => {\n if (msgIdx >= maxMsgs) return;\n\n const hasFriend = item.querySelector(".item-friend") !== null;\n const hasMyself = item.querySelector(".item-myself") !== null;\n const hasSystem = item.querySelector(".item-system") !== null;\n const hasResume = item.querySelector(".item-resume") !== null;\n const hasDialog = item.querySelector(".message-dialog-center") !== null;\n\n let sender = "system";\n let messageType = "text";\n if (hasFriend) {\n sender = "candidate";\n } else if (hasMyself) {\n sender = "recruiter";\n } else if (hasSystem || hasDialog) {\n sender = "system";\n messageType = "system";\n }\n if (hasResume) messageType = "resume";\n\n const cardEl = item.querySelector(".message-card-top-wrap, [class*='d-top-text']");\n if (cardEl) {\n const cardText = cardEl.textContent ?? "";\n if (cardText.includes("微信") || cardText.includes("WeChat")) {\n messageType = "wechat-exchange";\n }\n }\n\n const timeEl = item.querySelector(".message-time .time, .message-time");\n const timeMatch = (timeEl?.textContent ?? "").match(timeRegex);\n const time = timeMatch ? timeMatch[0] : "";\n\n let content = "";\n if (messageType === "wechat-exchange" && cardEl) {\n const cardText = cardEl.textContent ?? "";\n const digitMatch = cardText.match(/\\b(\\d{8,15})\\b/);\n const wxMatch = cardText.match(/微信[::号]*\\s*([a-zA-Z0-9_-]{5,20})/);\n if (digitMatch) content = "[微信号: " + digitMatch[1] + "]";\n else if (wxMatch) content = "[微信号: " + wxMatch[1] + "]";\n else content = "[交换微信]";\n } else if (cardEl) {\n const titleEl = item.querySelector(".message-card-top-title");\n const descEl = item.querySelector(".dialog-content, .message-card-top-text");\n content = (titleEl?.textContent?.trim() ?? descEl?.textContent?.trim() ?? "").trim();\n } else {\n const textEl = item.querySelector(".text span, .text-content, .text");\n if (textEl) {\n content = (textEl.textContent?.trim() ?? "")\n .replace(timeRegex, "")\n .replace("已读", "")\n .trim();\n }\n }\n\n if (content || messageType !== "text") {\n messages.push({ index: msgIdx, sender, messageType, content, time });\n msgIdx += 1;\n }\n });\n\n return {\n selectedTarget,\n activePanel,\n candidateInfo: {\n name,\n age,\n experience,\n education,\n communicationPosition,\n expectedJobText,\n expectedSalary,\n tags\n },\n messages\n };\n })()`))}async inspectRecommendCard(e){const t=Math.max(0,Math.floor(e)),n=this.buildRecommendCardInspectionExpression(t),r=os(await this.evaluateJson(n).catch(()=>{}));if(r.found)return r;const a=os(await this.evaluateRecommendFrameJson(n));return a.found?a:r}async clickRecommendGreet(e,t={}){const n=await this.inspectRecommendCard(e);if(!n.found||!n.hasGreetButton)return{...n,clicked:!1,...n.found||void 0!==n.error?{}:{error:"索引超出范围"},...n.found&&!n.hasGreetButton?{error:"未找到打招呼按钮"}:{}};const r=await this.resolveRecommendClickTarget(this.buildRecommendGreetClickExpression(Math.max(0,Math.floor(e)))),a=await this.dispatchNativeClick(r,t);return{...n,clicked:a,...a?{}:{error:"未能点击打招呼按钮"}}}async exchangeWechat(e={}){const t=rs(await this.evaluateJson('(() => {\n const selectors = [\n ".chat-conversation .conversation-operate .operate-exchange-left span.operate-btn",\n ".chat-conversation .conversation-operate span.operate-btn",\n ".conversation-box .conversation-operate .operate-exchange-left span.operate-btn",\n ".conversation-box .conversation-operate span.operate-btn",\n ".conversation-operate .operate-exchange-left span.operate-btn",\n ".conversation-operate .operate-exchange-left span"\n ];\n const normalize = (text) => (text ?? "").replace(/\\s+/g, "").trim();\n const visible = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0;\n };\n for (const selector of selectors) {\n for (const element of Array.from(document.querySelectorAll(selector))) {\n if (normalize(element.textContent) !== "换微信" || !visible(element)) continue;\n element.scrollIntoView({ block: "center", inline: "center" });\n const rect = element.getBoundingClientRect();\n return {\n found: true,\n x: Math.round(rect.left + rect.width / 2),\n y: Math.round(rect.top + rect.height / 2)\n };\n }\n }\n return { found: false, x: 0, y: 0 };\n })()').catch(()=>{}));if(!await this.dispatchNativeClick(t,e))return{success:!1,exchanged:!1,error:"未找到当前聊天输入区的「换微信」按钮"};if(!await this.waitForWechatExchangeDialog())return{success:!1,exchanged:!1,error:"确认对话框未弹出"};const n=rs(await this.evaluateJson('(() => {\n const visible = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0;\n };\n const normalize = (text) => (text ?? "").replace(/\\s+/g, "").trim();\n const tooltip = document.querySelector(".exchange-tooltip");\n const selectorGroups = tooltip\n ? [\n [tooltip, ".btn-box .boss-btn-primary.boss-btn"],\n [tooltip, ".btn-box span.boss-btn-primary"],\n [tooltip, "span.boss-btn-primary"],\n [tooltip, ".boss-btn-primary"]\n ]\n : [];\n for (const [root, selector] of selectorGroups) {\n const button = root.querySelector(selector);\n if (button && visible(button)) {\n const rect = button.getBoundingClientRect();\n return {\n found: true,\n x: Math.round(rect.left + rect.width / 2),\n y: Math.round(rect.top + rect.height / 2)\n };\n }\n }\n\n for (const container of Array.from(document.querySelectorAll("div, section, aside"))) {\n const text = container.textContent ?? "";\n if (!text.includes("交换微信") || !visible(container)) continue;\n const buttons = container.querySelectorAll(\n "span.boss-btn-primary, button.boss-btn-primary, span.boss-btn, button.boss-btn"\n );\n for (const button of Array.from(buttons)) {\n if (normalize(button.textContent) !== "确定" || !visible(button)) continue;\n const rect = button.getBoundingClientRect();\n return {\n found: true,\n x: Math.round(rect.left + rect.width / 2),\n y: Math.round(rect.top + rect.height / 2)\n };\n }\n }\n return { found: false, x: 0, y: 0 };\n })()').catch(()=>{}));if(!await this.dispatchNativeClick(n,e))return{success:!1,exchanged:!1,error:"未找到确认按钮"};await Di(1800);const r=await this.readWechatNumber();return{success:!0,exchanged:!0,...void 0!==r?{wechatNumber:r}:{}}}async sendChatReply(e,t={}){const n=rs(await this.evaluateJson('(() => {\n const selectors = ["#boss-chat-editor-input", "textarea.chat-input", ".chat-input"];\n const visible = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0;\n };\n for (const selector of selectors) {\n const element = document.querySelector(selector);\n if (!element || !visible(element)) continue;\n element.scrollIntoView({ block: "center", inline: "center" });\n const rect = element.getBoundingClientRect();\n return {\n found: true,\n x: Math.round(rect.left + rect.width / 2),\n y: Math.round(rect.top + rect.height / 2)\n };\n }\n return { found: false, x: 0, y: 0 };\n })()').catch(()=>{}));if(!await this.dispatchNativeClick(n,t))return{success:!1,error:"未找到聊天输入框"};await this.selectAllFocusedText(),await this.controller.dispatchKeyEvent({type:"rawKeyDown",key:"Backspace",code:"Backspace",windowsVirtualKeyCode:8,nativeVirtualKeyCode:8}),await this.controller.dispatchKeyEvent({type:"keyUp",key:"Backspace",code:"Backspace",windowsVirtualKeyCode:8,nativeVirtualKeyCode:8}),await this.controller.insertText(e),await Di(250);const r=rs(await this.evaluateJson('(() => {\n const selectors = [\n ".submit-content .submit.active",\n ".submit-content .submit",\n ".submit-content",\n ".btn-send"\n ];\n const visible = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0;\n };\n for (const selector of selectors) {\n const button = document.querySelector(selector);\n if (!button || !visible(button)) continue;\n const rect = button.getBoundingClientRect();\n return {\n found: true,\n x: Math.round(rect.left + rect.width / 2),\n y: Math.round(rect.top + rect.height / 2)\n };\n }\n for (const span of Array.from(document.querySelectorAll("span, button"))) {\n if ((span.textContent ?? "").replace(/\\s+/g, "").trim() !== "发送" || !visible(span)) {\n continue;\n }\n const rect = span.getBoundingClientRect();\n return {\n found: true,\n x: Math.round(rect.left + rect.width / 2),\n y: Math.round(rect.top + rect.height / 2)\n };\n }\n return { found: false, x: 0, y: 0 };\n })()').catch(()=>{}));return await this.dispatchNativeClick(r,t)?(await Di(800),{success:!0}):{success:!1,error:"未找到发送按钮"}}async applyRecommendFilter(e,t={}){const n=await this.waitForRecommendFilterSurface(3e3);if(!await this.openRecommendFilterPanel(t))return{status:n?"filter_not_found":"recommend_not_ready",requested:e,error:n?"未找到或无法打开筛选按钮":"推荐牛人页未就绪"};if(await this.detectVipModal())return{status:"requires_vip",requested:e,error:"筛选条件触发 VIP 弹窗"};if(!await this.clickRecommendFilterOption("性别",e.gender,t))return{status:"filter_not_found",requested:e,error:`未找到性别筛选项:${e.gender}`};if(!await this.clickRecommendFilterOption("活跃度",e.activity,t))return{status:"filter_not_found",requested:e,error:`未找到活跃度筛选项:${e.activity}`};const r=await this.setRecommendAgeRange(e,t);if(!r.success)return{status:"age_not_applied",requested:e,error:r.error};if(await this.detectVipModal())return{status:"requires_vip",requested:e,error:"年龄筛选触发 VIP 弹窗"};const a=await this.readNativeAppliedFilterState(e,r.state);if(!await this.clickRecommendFilterSubmit(t))return{status:"submit_failed",requested:e,applied:a,error:"筛选确认失败"};const o=await this.readRecommendFilterButtonText();return{status:"applied",requested:e,applied:a,...void 0!==o?{filterButtonText:o}:{}}}async readRecommendCandidates(e={}){const t=e.targetCount,n=e.autoScroll?e.maxScrolls??4:0,r=await this.inspectSurface("recommend-list");let a=r;const o=new Map;let i=0,s=0,c=0,l="max-steps";const d=async()=>{let e=0;const t=await this.readVisibleRecommendCandidates();for(const n of t){const t=us(n);void 0!==t&&0!==t.length&&(o.has(t)?s+=1:(o.set(t,n),e+=1))}return e};await d();for(let e=0;e<n;e+=1){if(void 0!==t&&o.size>=t){l="target-count";break}if(a.atEnd){let e=!1;for(let t=0;t<ki;t+=1){await Di(Ri);const t=await d(),n=await this.inspectSurface("recommend-list"),r=t>0||n.scrollHeight>a.scrollHeight||n.itemCount>a.itemCount||!n.atEnd;if(a=n,r){t>0&&(c=0),e=!0;break}}if(!e){l="boundary";break}if(void 0!==t&&o.size>=t){l="target-count";break}}if(c>=Ai){l="no-new-items";break}const e=await this.scrollSurface("recommend-list",{direction:"down",steps:1,settleMs:Ci});a=e.after,i+=e.stepsCompleted;c=await d()>0?0:c+1}void 0!==t&&o.size>=t?l="target-count":i>=n&&(l="max-steps");const u=[...o.values()];return{success:r.containerFound,direction:"down",stepsRequested:n,stepsCompleted:i,reachedBoundary:a.atEnd,before:r,after:a,items:u,uniqueCount:u.length,duplicateCount:s,noNewRounds:c,stopReason:l}}async readUsernameEvidence(){return Ki(await this.evaluateJson(`(() => {\n const limit = ${ui};\n const evidence = [];\n const viewportWidth = window.innerWidth || 1280;\n const push = (entry) => {\n const text = String(entry.text ?? "").trim();\n if (text.length > 0 && text.length <= limit) {\n evidence.push({ ...entry, text });\n }\n };\n const scope =\n document.querySelector("header") ??\n document.querySelector("#header") ??\n document.querySelector('[role="banner"]') ??\n document.querySelector('[role="navigation"]') ??\n document.body;\n\n if (scope) {\n for (const element of Array.from(scope.querySelectorAll('a, [role="link"]'))) {\n const text = element.textContent?.trim() ?? "";\n const rect = element.getBoundingClientRect();\n push({\n text,\n strategy: "role-link",\n priority: 1,\n source: "role:link",\n xRatio: (rect.x + rect.width / 2) / viewportWidth\n });\n }\n for (const element of Array.from(scope.querySelectorAll('button, [role="button"]'))) {\n const text = element.textContent?.trim() ?? "";\n const rect = element.getBoundingClientRect();\n push({\n text,\n strategy: "role-button",\n priority: 1,\n source: "role:button",\n xRatio: (rect.x + rect.width / 2) / viewportWidth\n });\n }\n\n const walker = document.createTreeWalker(scope, NodeFilter.SHOW_TEXT);\n while (walker.nextNode()) {\n const text = walker.currentNode.textContent?.trim() ?? "";\n push({\n text,\n strategy: "leaf-text",\n priority: 3,\n source: "leaf-text"\n });\n }\n }\n\n for (const selector of ${JSON.stringify([di.username.primary,...di.username.fallbacks])}) {\n try {\n push({\n text: document.querySelector(selector)?.textContent?.trim() ?? "",\n strategy: "css-fallback",\n priority: 4,\n source: selector\n });\n } catch {\n // Ignore invalid selectors from site-specific fallback list.\n }\n }\n\n return evidence;\n })()`))}close(){this.controller.close()}buildRecommendCardInspectionExpression(e){return`(() => {\n const index = ${JSON.stringify(e)};\n const primarySelector = ${JSON.stringify(yi)};\n const fallbackSelector = ${JSON.stringify(vi)};\n const iframe = document.querySelector(${JSON.stringify(di.recommend.iframe)});\n const href = location.href;\n const recommendUrlMarkers = ${JSON.stringify(xi)};\n const hasRecommendUrl = recommendUrlMarkers.some((marker) => href.includes(marker));\n if (!hasRecommendUrl && href.includes("/web/chat/index")) {\n return {\n found: false,\n cardSelector: primarySelector,\n candidateId: "",\n name: "",\n hasGreetButton: false,\n error: "推荐列表未加载"\n };\n }\n\n const root = iframe?.contentDocument ?? document;\n const primaryCards = Array.from(root.querySelectorAll(primarySelector));\n const cardSelector = primaryCards.length > 0 ? primarySelector : fallbackSelector;\n const cards = primaryCards.length > 0 ? primaryCards : Array.from(root.querySelectorAll(cardSelector));\n if (cards.length <= index) {\n return {\n found: false,\n cardSelector,\n candidateId: "",\n name: "",\n hasGreetButton: false,\n error: "索引超出范围"\n };\n }\n\n const item = cards[index];\n const splitParts = (text) => (text ?? "")\n .split(/[丨·|]/)\n .map((part) => part.trim())\n .filter(Boolean);\n const candidateId =\n item.getAttribute("data-geek") ??\n item.querySelector("[data-geek]")?.getAttribute("data-geek") ??\n "";\n const name = item.querySelector(".name")?.textContent?.trim() ?? "";\n let age = "";\n let experience = "";\n let education = "";\n let workStatus = "";\n const baseInfoEl = item.querySelector(".base-info.join-text-wrap, .base-info");\n if (baseInfoEl) {\n let textParts = Array.from(baseInfoEl.querySelectorAll(":scope > *"))\n .map((child) => child.textContent?.trim() ?? "")\n .filter(Boolean);\n\n if (textParts.length <= 1) {\n textParts = splitParts(baseInfoEl.textContent?.trim() ?? "");\n }\n\n for (const part of textParts) {\n if (!age && part.includes("岁")) {\n age = part;\n } else if (!experience && (part.includes("年") || part.includes("应届") || part.includes("在校"))) {\n experience = part;\n } else if (!education && /(初中|高中|中专|中技|大专|本科|硕士|博士)/.test(part)) {\n education = part;\n } else if (!workStatus && /(在职|离职|在校)/.test(part)) {\n workStatus = part;\n }\n }\n }\n const workExpEl =\n item.querySelector(".timeline-wrap.work-exps .content.join-text-wrap") ??\n item.querySelector(".timeline-wrap.work-exps .content");\n const workParts = splitParts(workExpEl?.textContent?.trim() ?? "");\n const company = workParts[0] ?? "";\n const currentPosition = workParts[1] ?? "";\n let expectedLocation = "";\n let expectedPosition = "";\n const expectRow = item.querySelector(".row-flex:not(.geek-desc)");\n if (expectRow) {\n const labelText = expectRow.querySelector(".label")?.textContent ?? "";\n const contentEl = expectRow.querySelector(".content");\n if ((labelText.includes("期望") || labelText.includes("最近关注")) && contentEl) {\n const parts = splitParts(contentEl.textContent?.trim() ?? "");\n expectedLocation = parts[0] ?? "";\n expectedPosition = parts[1] ?? "";\n }\n }\n if (!expectedLocation) {\n const expectEl =\n item.querySelector(".timeline-wrap.expect .content.join-text-wrap") ??\n item.querySelector(".timeline-wrap.expect .content");\n if (expectEl) {\n const parts = splitParts(expectEl.textContent?.trim() ?? "");\n expectedLocation = parts[0] ?? "";\n expectedPosition = parts[1] ?? "";\n }\n }\n const greetButton =\n item.querySelector("button.btn.btn-greet") ??\n item.querySelector("button.btn-greet") ??\n item.querySelector(".btn-greet") ??\n item.querySelector(".op-btn");\n const rect = greetButton?.getBoundingClientRect();\n const hasGreetButton = Boolean(rect && rect.width > 0 && rect.height > 0);\n\n return {\n found: true,\n cardSelector,\n candidateId,\n name,\n age,\n experience,\n education,\n workStatus,\n company,\n currentPosition,\n expectedLocation,\n expectedPosition,\n expectedSalary: item.querySelector(".salary-wrap")?.textContent?.trim() ?? "",\n hasGreetButton\n };\n })()`}buildRecommendGreetClickExpression(e){return`(() => {\n const index = ${JSON.stringify(e)};\n const primarySelector = ${JSON.stringify(yi)};\n const fallbackSelector = ${JSON.stringify(vi)};\n const iframe = document.querySelector(${JSON.stringify(di.recommend.iframe)});\n const root = iframe?.contentDocument ?? document;\n const primaryCards = Array.from(root.querySelectorAll(primarySelector));\n const cards =\n primaryCards.length > 0\n ? primaryCards\n : Array.from(root.querySelectorAll(fallbackSelector));\n const item = cards[index];\n if (!item) return { found: false, x: 0, y: 0 };\n const button =\n item.querySelector("button.btn.btn-greet") ??\n item.querySelector("button.btn-greet") ??\n item.querySelector(".btn-greet") ??\n item.querySelector(".op-btn");\n if (!button) return { found: false, x: 0, y: 0 };\n button.scrollIntoView({ block: "center", inline: "center" });\n const rect = button.getBoundingClientRect();\n if (rect.width <= 0 || rect.height <= 0) return { found: false, x: 0, y: 0 };\n return {\n found: true,\n x: Math.round(rect.left + rect.width / 2),\n y: Math.round(rect.top + rect.height / 2)\n };\n })()`}async waitForWechatExchangeDialog(e=5e3){const t=Date.now();for(;Date.now()-t<e;){if(await this.evaluateJson('(() => {\n const visible = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0;\n };\n const tooltip = document.querySelector(".exchange-tooltip");\n if (tooltip && visible(tooltip)) return true;\n for (const element of Array.from(document.querySelectorAll("div, section, aside"))) {\n const text = element.textContent ?? "";\n if (\n text.includes("交换微信") &&\n element.querySelector(".boss-btn-primary, .boss-btn") &&\n visible(element)\n ) {\n return true;\n }\n }\n return false;\n })()').catch(()=>!1))return!0;await Di(450)}return!1}async readWechatNumber(){const e=await this.evaluateJson('(() => {\n const cardSelectors = [\n ".message-card-top-wrap",\n \'[class*="d-top-text"]\',\n ".message-card-top-title"\n ];\n const parse = (text) => {\n const digitMatch = text.match(/\\b(\\d{8,15})\\b/);\n if (digitMatch) return digitMatch[1];\n const wxMatch = text.match(/微信[::号]*\\s*([a-zA-Z0-9_-]{5,20})/);\n if (wxMatch) return wxMatch[1];\n const letterMatch = text.match(/\\b([a-zA-Z][a-zA-Z0-9_-]{5,19})\\b/);\n if (letterMatch && !["微信", "WeChat"].includes(letterMatch[1])) {\n return letterMatch[1];\n }\n return null;\n };\n\n for (const selector of cardSelectors) {\n const cards = Array.from(document.querySelectorAll(selector));\n for (let index = cards.length - 1; index >= 0; index -= 1) {\n const parsed = parse(cards[index]?.textContent ?? "");\n if (parsed) return parsed;\n }\n }\n\n const msgItems = Array.from(document.querySelectorAll(".message-item"));\n for (let index = msgItems.length - 1; index >= 0; index -= 1) {\n const card = msgItems[index]?.querySelector(\'.message-card-top-wrap, [class*="d-top-text"]\');\n if (!card) continue;\n const parsed = parse(card.textContent ?? "");\n if (parsed) return parsed;\n }\n return null;\n })()').catch(()=>null);return"string"==typeof e&&e.length>0?e:void 0}async selectAllFocusedText(){const e=[4,2];for(const t of e)await this.controller.dispatchKeyEvent({type:"rawKeyDown",key:"a",code:"KeyA",windowsVirtualKeyCode:65,nativeVirtualKeyCode:65,modifiers:t}),await this.controller.dispatchKeyEvent({type:"keyUp",key:"a",code:"KeyA",windowsVirtualKeyCode:65,nativeVirtualKeyCode:65,modifiers:t}),await Di(40)}async waitForRecommendFilterSurface(e=1e4){const t=`(() => {\n return document.querySelector(${JSON.stringify(`${di.recommend.filterButton}, ${yi}, ${di.recommend.candidateItem}`)}) !== null;\n })()`,n=Date.now();for(;Date.now()-n<e;){if(await this.evaluateJson(t).catch(()=>!1)||await this.evaluateRecommendFrameJson(t))return!0;await Di(Si)}return!1}async isRecommendFilterPanelVisible(){const e=`(() => {\n const panel = document.querySelector(${JSON.stringify(di.recommend.filterPanel)});\n if (!panel) return false;\n const rect = panel.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0;\n })()`;return await this.evaluateJson(e).catch(()=>!1)||(await this.evaluateRecommendFrameJson(e)??!1)}async openRecommendFilterPanel(e){if(await this.isRecommendFilterPanelVisible())return!0;for(let t=0;t<3;t+=1){await this.dismissPreviousFilterPrompt(e);const t=await this.resolveRecommendClickTarget(`(() => {\n const filterButtonSelector = ${JSON.stringify(di.recommend.filterButton)};\n const normalize = (text) => (text ?? "").replace(/\\s+/g, " ").trim();\n const visible = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0;\n };\n const classText = (element) =>\n typeof element.className === "string" ? element.className : "";\n const scoreCandidate = (element) => {\n const classes = classText(element);\n const parentClasses = element.parentElement ? classText(element.parentElement) : "";\n const ancestorClasses =\n element.closest(".recommend-filter, .filter-label-wrap, .filter-wrap") !== null\n ? "recommend-filter"\n : "";\n let score = 0;\n for (const value of [classes, parentClasses, ancestorClasses]) {\n if (/recommend-filter/.test(value)) score += 3;\n else if (/filter-label/.test(value)) score += 2;\n else if (/filter/.test(value)) score += 1;\n }\n return score;\n };\n const selectorCandidates = Array.from(document.querySelectorAll(filterButtonSelector));\n const textCandidates = Array.from(\n document.querySelectorAll("button, a, span, div, [role='button']")\n ).filter((element) => /^筛选(?:·\\d+)?$/.test(normalize(element.textContent)));\n const candidate = [...selectorCandidates, ...textCandidates]\n .filter(visible)\n .sort((a, b) => {\n const scoreDelta = scoreCandidate(b) - scoreCandidate(a);\n if (scoreDelta !== 0) return scoreDelta;\n const aRect = a.getBoundingClientRect();\n const bRect = b.getBoundingClientRect();\n return aRect.width * aRect.height - bRect.width * bRect.height;\n })[0];\n if (!candidate) return { found: false, x: 0, y: 0 };\n candidate.scrollIntoView({ block: "center", inline: "center" });\n const rect = candidate.getBoundingClientRect();\n return {\n found: true,\n x: Math.round(rect.left + rect.width / 2),\n y: Math.round(rect.top + rect.height / 2)\n };\n })()`);if(await this.dispatchNativeClick(t,e)){const t=Date.now();for(;Date.now()-t<4e3;){if(await this.isRecommendFilterPanelVisible())return await this.dismissPreviousFilterPrompt(e),!0;await Di(Si)}}await Di(300)}return!1}async dismissPreviousFilterPrompt(e){const t=await this.resolveRecommendClickTarget('(() => {\n const normalize = (text) => (text ?? "").replace(/\\s+/g, " ").trim();\n const visible = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0;\n };\n const roots = Array.from(document.body.querySelectorAll("div, section, aside"))\n .filter((element) => visible(element))\n .sort((a, b) => {\n const aRect = a.getBoundingClientRect();\n const bRect = b.getBoundingClientRect();\n return aRect.width * aRect.height - bRect.width * bRect.height;\n });\n for (const root of roots) {\n const text = normalize(root.textContent);\n if (!text.includes("是否应用上次") && !text.includes("上次的筛选条件")) continue;\n const candidates = Array.from(\n root.querySelectorAll("button, a, span, div, [role=\'button\']")\n ).filter(visible);\n for (const candidate of candidates) {\n const buttonText = normalize(candidate.textContent);\n if (/^(取消|不应用|否|关闭|稍后)$/.test(buttonText)) {\n const rect = candidate.getBoundingClientRect();\n return {\n found: true,\n x: Math.round(rect.left + rect.width / 2),\n y: Math.round(rect.top + rect.height / 2)\n };\n }\n }\n }\n return { found: false, x: 0, y: 0 };\n })()');return await this.dispatchNativeClick(t,e)}async clickRecommendFilterOption(e,t,n){const r=await this.resolveRecommendClickTarget(`(() => {\n const panelSelector = ${JSON.stringify(di.recommend.filterPanel)};\n const rowLabel = ${JSON.stringify(e)};\n const optionLabel = ${JSON.stringify(t)};\n const clickableSelector = ${JSON.stringify($i)};\n const normalize = (text) => (text ?? "").replace(/\\s+/g, "").trim();\n const visible = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0;\n };\n const area = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width * rect.height;\n };\n const resolveClickable = (element, row) => {\n let current = element;\n while (current && current !== row.parentElement) {\n const tag = current.tagName.toLowerCase();\n const role = current.getAttribute("role") ?? "";\n if (\n tag === "button" ||\n tag === "a" ||\n tag === "label" ||\n tag === "li" ||\n role === "button" ||\n role === "radio"\n ) {\n return current;\n }\n current = current.parentElement;\n }\n return element;\n };\n\n const panel = Array.from(document.querySelectorAll(panelSelector))\n .filter(visible)\n .sort((a, b) => area(a) - area(b))[0];\n if (!panel) return { found: false, x: 0, y: 0 };\n\n const rows = Array.from(panel.querySelectorAll("div, li, dl, dd, section, ul"))\n .filter((element) => {\n const text = normalize(element.textContent);\n return visible(element) && text.includes(rowLabel) && text.includes(optionLabel);\n })\n .sort((a, b) => {\n const areaDelta = area(a) - area(b);\n if (areaDelta !== 0) return areaDelta;\n return normalize(a.textContent).length - normalize(b.textContent).length;\n });\n\n for (const row of rows) {\n const option = Array.from(row.querySelectorAll(clickableSelector))\n .filter((element) => visible(element) && normalize(element.textContent) === optionLabel)\n .sort((a, b) => area(a) - area(b))[0];\n if (!option) continue;\n const clickable = resolveClickable(option, row);\n clickable.scrollIntoView({ block: "center", inline: "center" });\n const rect = clickable.getBoundingClientRect();\n return {\n found: true,\n x: Math.round(rect.left + rect.width / 2),\n y: Math.round(rect.top + rect.height / 2)\n };\n }\n\n return { found: false, x: 0, y: 0 };\n })()`);return await this.dispatchNativeClick(r,n)}async detectVipModal(){const e='(() => {\n const normalize = (text) => (text ?? "").replace(/\\s+/g, " ").trim();\n const visible = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0;\n };\n const modalPattern =\n /(购买VIP|VIP账号|开通VIP|开启VIP|专享筛选特权|扫码支付|立即开通|支付金额)/;\n return Array.from(document.body.querySelectorAll("div, section, aside"))\n .some((element) => visible(element) && modalPattern.test(normalize(element.textContent)));\n })()';return await this.evaluateJson(e).catch(()=>!1)||(await this.evaluateRecommendFrameJson(e)??!1)}async readNativeAgeState(){const e=`(() => {\n const panelSelector = ${JSON.stringify(di.recommend.filterPanel)};\n const normalize = (text) => (text ?? "").replace(/\\s+/g, "").trim();\n const parseAgeValue = (text) => {\n if (text.includes("不限")) return undefined;\n const match = text.match(/\\d+/);\n return match ? Number.parseInt(match[0], 10) : undefined;\n };\n const parseAgeState = (text) => {\n const normalized = normalize(text);\n const ageText = normalized.includes("年龄")\n ? normalized.slice(normalized.indexOf("年龄") + "年龄".length)\n : normalized;\n const numbers = Array.from(ageText.matchAll(/\\d+/g), (match) =>\n Number.parseInt(match[0], 10)\n ).filter((value) => Number.isInteger(value));\n const ageMin = numbers[0];\n const ageMax = ageText.includes("不限") ? undefined : numbers[1];\n return {\n ...(ageMin !== undefined ? { ageMin } : {}),\n ...(ageMax !== undefined ? { ageMax } : {})\n };\n };\n const visible = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0;\n };\n const area = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width * rect.height;\n };\n const classText = (element) =>\n typeof element.className === "string" ? element.className : "";\n const preferRailTrack = (elements) =>\n [...elements].sort((a, b) => {\n const aClasses = classText(a);\n const bClasses = classText(b);\n if (/vue-slider-rail/.test(aClasses) && !/vue-slider-rail/.test(bClasses)) return -1;\n if (!/vue-slider-rail/.test(aClasses) && /vue-slider-rail/.test(bClasses)) return 1;\n const aRect = a.getBoundingClientRect();\n const bRect = b.getBoundingClientRect();\n const heightDelta = aRect.height - bRect.height;\n if (heightDelta !== 0) return heightDelta;\n return bRect.width - aRect.width;\n });\n const looksLikeSlider = (element) => {\n const classes = classText(element);\n const role = element.getAttribute("role") ?? "";\n return /slider|range|track|bar/i.test(classes) || role === "slider";\n };\n const looksLikeHandle = (element) => {\n const rect = element.getBoundingClientRect();\n const classes = classText(element);\n const role = element.getAttribute("role") ?? "";\n return (\n role === "slider" ||\n (/handle|handler|button|thumb|slider-btn|dot|point|circle|knob/i.test(classes) &&\n rect.width <= 80 &&\n rect.height <= 80)\n );\n };\n const readRatio = (dot, track) => {\n const styleLeft = dot.style.left;\n if (styleLeft.endsWith("%")) {\n const parsed = Number.parseFloat(styleLeft);\n if (Number.isFinite(parsed)) return Math.max(0, Math.min(1, parsed / 100));\n }\n const dotRect = dot.getBoundingClientRect();\n const trackRect = track.getBoundingClientRect();\n if (trackRect.width <= 0) return undefined;\n return Math.max(\n 0,\n Math.min(1, (dotRect.left + dotRect.width / 2 - trackRect.left) / trackRect.width)\n );\n };\n const ratioToAge = (ratio) =>\n Math.round(\n ${JSON.stringify(Pi)} +\n Math.max(0, Math.min(1, ratio)) *\n (${JSON.stringify(Ti)} -\n ${JSON.stringify(Pi)})\n );\n const panel = Array.from(document.querySelectorAll(panelSelector))\n .filter(visible)\n .sort((a, b) => area(a) - area(b))[0];\n if (!panel) return {};\n const row = Array.from(panel.querySelectorAll("div, li, section, dl, dd"))\n .filter((element) => {\n const text = normalize(element.textContent);\n return (\n visible(element) &&\n text.includes("年龄") &&\n (/\\d+|不限/.test(text) ||\n Array.from(element.querySelectorAll("*")).some(\n (child) => looksLikeSlider(child) || looksLikeHandle(child),\n ))\n );\n })\n .sort((a, b) => {\n const areaDelta = area(a) - area(b);\n if (areaDelta !== 0) return areaDelta;\n return normalize(a.textContent).length - normalize(b.textContent).length;\n })[0];\n if (!row) return {};\n const dots = Array.from(row.querySelectorAll(".vue-slider-dot"))\n .filter(visible)\n .sort((a, b) => a.getBoundingClientRect().left - b.getBoundingClientRect().left);\n const track = preferRailTrack(\n Array.from(row.querySelectorAll(".vue-slider-rail, .vue-slider")).filter(visible)\n )[0];\n if (dots.length >= 2) {\n const minDot = dots[0];\n const maxDot = dots[dots.length - 1];\n const minText = normalize(minDot?.querySelector(".vue-slider-dot-tooltip-text")?.textContent);\n const maxText = normalize(maxDot?.querySelector(".vue-slider-dot-tooltip-text")?.textContent);\n const rowText = normalize(row.textContent);\n const rowState = parseAgeState(rowText);\n const minRatio = track && minDot ? readRatio(minDot, track) : undefined;\n const maxRatio = track && maxDot ? readRatio(maxDot, track) : undefined;\n const ageMin =\n parseAgeValue(minText) ??\n rowState.ageMin ??\n (minRatio !== undefined ? ratioToAge(minRatio) : undefined);\n let ageMax = parseAgeValue(maxText) ?? rowState.ageMax;\n if (\n ageMax === undefined &&\n !maxText.includes("不限") &&\n !rowText.includes("不限") &&\n maxRatio !== undefined\n ) {\n ageMax = ratioToAge(maxRatio);\n }\n return {\n ...(ageMin !== undefined ? { ageMin } : {}),\n ...(ageMax !== undefined ? { ageMax } : {}),\n ...(minRatio !== undefined ? { minRatio } : {}),\n ...(maxRatio !== undefined ? { maxRatio } : {})\n };\n }\n return parseAgeState(normalize(row.textContent));\n })()`,t=is(await this.evaluateJson(e).catch(()=>{}));return void 0!==t.ageMin||void 0!==t.ageMax?t:is(await this.evaluateRecommendFrameJson(e))}async resolveNativeAgeSlider(){const e=`(() => {\n const panelSelector = ${JSON.stringify(di.recommend.filterPanel)};\n const normalize = (text) => (text ?? "").replace(/\\s+/g, "").trim();\n const parseAgeState = (text) => {\n const normalized = normalize(text);\n const ageText = normalized.includes("年龄")\n ? normalized.slice(normalized.indexOf("年龄") + "年龄".length)\n : normalized;\n const numbers = Array.from(ageText.matchAll(/\\d+/g), (match) =>\n Number.parseInt(match[0], 10)\n ).filter((value) => Number.isInteger(value));\n const ageMin = numbers[0];\n const ageMax = ageText.includes("不限") ? undefined : numbers[1];\n return {\n ...(ageMin !== undefined ? { ageMin } : {}),\n ...(ageMax !== undefined ? { ageMax } : {})\n };\n };\n const visible = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0;\n };\n const area = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width * rect.height;\n };\n const classText = (element) =>\n typeof element.className === "string" ? element.className : "";\n const preferRailTrack = (elements) =>\n [...elements].sort((a, b) => {\n const aClasses = classText(a);\n const bClasses = classText(b);\n if (/vue-slider-rail/.test(aClasses) && !/vue-slider-rail/.test(bClasses)) return -1;\n if (!/vue-slider-rail/.test(aClasses) && /vue-slider-rail/.test(bClasses)) return 1;\n const aRect = a.getBoundingClientRect();\n const bRect = b.getBoundingClientRect();\n const heightDelta = aRect.height - bRect.height;\n if (heightDelta !== 0) return heightDelta;\n return bRect.width - aRect.width;\n });\n const looksLikeSlider = (element) => {\n const classes = classText(element);\n const role = element.getAttribute("role") ?? "";\n return /slider|range|track|bar/i.test(classes) || role === "slider";\n };\n const looksLikeHandle = (element) => {\n const rect = element.getBoundingClientRect();\n const classes = classText(element);\n const role = element.getAttribute("role") ?? "";\n return (\n role === "slider" ||\n (/handle|handler|button|thumb|slider-btn|dot|point|circle|knob/i.test(classes) &&\n rect.width <= 80 &&\n rect.height <= 80)\n );\n };\n const panel = Array.from(document.querySelectorAll(panelSelector))\n .filter(visible)\n .sort((a, b) => area(a) - area(b))[0];\n if (!panel) return { ok: false, error: "未找到筛选面板" };\n const row = Array.from(panel.querySelectorAll("div, li, section, dl, dd"))\n .filter((element) => {\n const text = normalize(element.textContent);\n return (\n visible(element) &&\n text.includes("年龄") &&\n Array.from(element.querySelectorAll("*")).some(\n (child) => looksLikeSlider(child) || looksLikeHandle(child)\n )\n );\n })\n .sort((a, b) => {\n const areaDelta = area(a) - area(b);\n if (areaDelta !== 0) return areaDelta;\n return normalize(a.textContent).length - normalize(b.textContent).length;\n })[0];\n if (!row) return { ok: false, error: "未找到年龄滑块" };\n\n const vueSliderDots = Array.from(row.querySelectorAll(".vue-slider-dot"))\n .filter(visible)\n .sort((a, b) => a.getBoundingClientRect().left - b.getBoundingClientRect().left);\n const fallbackHandles = Array.from(row.querySelectorAll("*"))\n .filter((element) => visible(element) && looksLikeHandle(element))\n .sort((a, b) => a.getBoundingClientRect().left - b.getBoundingClientRect().left);\n const handles = vueSliderDots.length >= 2 ? vueSliderDots : fallbackHandles;\n if (handles.length < 2) {\n return { ok: false, error: "未找到年龄滑块双手柄" };\n }\n\n const minHandle = handles[0];\n const maxHandle = handles[handles.length - 1];\n const minRect = minHandle.getBoundingClientRect();\n const maxRect = maxHandle.getBoundingClientRect();\n const minDistance = Math.max(40, maxRect.left - minRect.left);\n const tracks = [\n ...preferRailTrack(Array.from(row.querySelectorAll(".vue-slider-rail, .vue-slider"))),\n ...Array.from(row.querySelectorAll("*")).filter(looksLikeSlider)\n ]\n .filter((element, index, array) => array.indexOf(element) === index)\n .filter((element) => {\n if (!visible(element)) return false;\n const rect = element.getBoundingClientRect();\n return (\n rect.width >= Math.max(80, minDistance) &&\n rect.height <= 100 &&\n rect.left <= minRect.left + minRect.width &&\n rect.right >= maxRect.right - maxRect.width\n );\n })\n .sort((a, b) => {\n const aClasses = classText(a);\n const bClasses = classText(b);\n if (/vue-slider-rail/.test(aClasses) && !/vue-slider-rail/.test(bClasses)) return -1;\n if (!/vue-slider-rail/.test(aClasses) && /vue-slider-rail/.test(bClasses)) return 1;\n const aRect = a.getBoundingClientRect();\n const bRect = b.getBoundingClientRect();\n const heightDelta = aRect.height - bRect.height;\n if (heightDelta !== 0) return heightDelta;\n return bRect.width - aRect.width;\n });\n const track = tracks[0];\n if (!track) return { ok: false, error: "未找到年龄滑块轨道" };\n const trackRect = track.getBoundingClientRect();\n return {\n ok: true,\n current: parseAgeState(normalize(row.textContent)),\n trackLeft: trackRect.left,\n trackTop: trackRect.top,\n trackWidth: trackRect.width,\n trackHeight: trackRect.height,\n minHandleX: Math.round(minRect.left + minRect.width / 2),\n minHandleY: Math.round(minRect.top + minRect.height / 2),\n maxHandleX: Math.round(maxRect.left + maxRect.width / 2),\n maxHandleY: Math.round(maxRect.top + maxRect.height / 2)\n };\n })()`,t=ss(await this.evaluateJson(e).catch(()=>{}));if(t.ok)return t;const n=ss(await this.evaluateRecommendFrameJson(e));if(!n.ok)return n;const r=await this.readRecommendFrameOffset();return r.found?{...n,trackLeft:n.trackLeft+r.left,trackTop:n.trackTop+r.top,minHandleX:n.minHandleX+r.left,minHandleY:n.minHandleY+r.top,maxHandleX:n.maxHandleX+r.left,maxHandleY:n.maxHandleY+r.top}:n}async dispatchNativeDrag(e,t,n,r,a={}){await this.mouse.drag({x:e,y:t},{x:n,y:r},{...void 0!==a.motionObserver?{motionObserver:a.motionObserver}:{},pressDurationMs:a.pressDurationMs??Mi})}async dragAgeHandleToRatio(e,t,n){const r=await this.resolveNativeAgeSlider();if(!r.ok||r.trackWidth<=0)return!1;const a="min"===e?r.minHandleX:r.maxHandleX,o="min"===e?r.minHandleY:r.maxHandleY,i=r.trackLeft+Math.max(0,Math.min(1,t))*r.trackWidth,s=r.trackTop+Math.max(1,r.trackHeight/2);return await this.dispatchNativeDrag(a,o,i,s,n),await Di(_i),!0}estimateAgeRatio(e){return Math.max(0,Math.min(1,(e-Pi)/(Ti-Pi)))}clampRatio(e,t,n){return Math.max(t,Math.min(n,e))}async setAgeHandleToNumber(e,t,n){const r=await this.readNativeAgeState(),a=r.minRatio??0,o=r.maxRatio??1;let i="min"===e?0:Math.min(1,a+Oi),s="min"===e?Math.max(0,o-Oi):1,c=this.clampRatio(this.estimateAgeRatio(t),i,s);for(let r=0;r<Bi;r+=1){if(!await this.dragAgeHandleToRatio(e,c,n))return!1;const r=await this.readNativeAgeState(),a="min"===e?r.ageMin:r.ageMax;if(a===t)return!0;void 0===a?"max"===e?s=c:i=c:a<t?i=c:s=c;const o=(i+s)/2;if(Math.abs(o-c)<.001)break;c=this.clampRatio(o,i,s)}const l=await this.readNativeAgeState();return"min"===e?l.ageMin===t:l.ageMax===t}isDesiredAgeState(e,t,n){return e.ageMin===t&&e.ageMax===n}async setRecommendAgeRange(e,t){const n=e.ageMin??Pi,r=e.ageMax,a=await this.resolveNativeAgeSlider();if(!a.ok)return{success:!1,error:a.error};if(!await this.dragAgeHandleToRatio("max",1,t))return{success:!1,error:"年龄上限无法重置为不限"};if(!await this.setAgeHandleToNumber("min",n,t))return{success:!1,error:`年龄下限无法设置为 ${n}`};if(void 0===r){if(void 0!==(await this.readNativeAgeState()).ageMax&&!await this.dragAgeHandleToRatio("max",1,t))return{success:!1,error:"年龄上限无法设置为不限"}}else if(!await this.setAgeHandleToNumber("max",r,t))return{success:!1,error:`年龄上限无法设置为 ${r}`};const o=await this.readNativeAgeState();if(!this.isDesiredAgeState(o,n,r)){const e=void 0===o.ageMax?"不限":String(o.ageMax);return{success:!1,error:`年龄筛选未精确生效,当前为 ${o.ageMin??"未知"}-${e}`}}return{success:!0,state:o}}async readSelectedRecommendOptionText(e,t){const n=`(() => {\n const panelSelector = ${JSON.stringify(di.recommend.filterPanel)};\n const rowLabel = ${JSON.stringify(e)};\n const fallback = ${JSON.stringify(t)};\n const clickableSelector = ${JSON.stringify($i)};\n const selectedClassPattern = /active|selected|checked|current|choose|chosen/i;\n const normalize = (text) => (text ?? "").replace(/\\s+/g, "").trim();\n const visible = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0;\n };\n const area = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width * rect.height;\n };\n const isSelected = (element) => {\n const classes = typeof element.className === "string" ? element.className : "";\n return (\n selectedClassPattern.test(classes) ||\n element.getAttribute("aria-checked") === "true" ||\n element.getAttribute("aria-selected") === "true"\n );\n };\n const panel = Array.from(document.querySelectorAll(panelSelector))\n .filter(visible)\n .sort((a, b) => area(a) - area(b))[0];\n if (!panel) return fallback;\n const row = Array.from(panel.querySelectorAll("div, li, dl, dd, section, ul"))\n .filter((element) => visible(element) && normalize(element.textContent).includes(rowLabel))\n .sort((a, b) => {\n const areaDelta = area(a) - area(b);\n if (areaDelta !== 0) return areaDelta;\n return normalize(a.textContent).length - normalize(b.textContent).length;\n })[0];\n if (!row) return fallback;\n const selected = Array.from(row.querySelectorAll(clickableSelector))\n .filter((element) => visible(element) && isSelected(element))\n .map((element) => normalize(element.textContent))\n .find((text) => text !== "" && text !== rowLabel);\n return selected ?? fallback;\n })()`,r=await this.evaluateJson(n).catch(()=>"");if(r.length>0&&r!==t)return r;const a=await this.evaluateRecommendFrameJson(n);return"string"==typeof a&&a.length>0?a:t}async readNativeAppliedFilterState(e,t){return{...void 0!==t.ageMin?{ageMin:t.ageMin}:{},...void 0!==t.ageMax?{ageMax:t.ageMax}:{},gender:await this.readSelectedRecommendOptionText("性别",e.gender),activity:await this.readSelectedRecommendOptionText("活跃度",e.activity)}}async clickRecommendFilterSubmit(e){const t=await this.resolveRecommendClickTarget(`(() => {\n const panelSelector = ${JSON.stringify(di.recommend.filterPanel)};\n const normalize = (text) => (text ?? "").replace(/\\s+/g, "").trim();\n const visible = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0;\n };\n const panel = Array.from(document.querySelectorAll(panelSelector)).filter(visible)[0];\n if (!panel) return { found: false, x: 0, y: 0 };\n const button = Array.from(\n panel.querySelectorAll("button, a, span, div, [role='button']")\n )\n .filter(visible)\n .find((element) => normalize(element.textContent) === "确定");\n if (!button) return { found: false, x: 0, y: 0 };\n const rect = button.getBoundingClientRect();\n return {\n found: true,\n x: Math.round(rect.left + rect.width / 2),\n y: Math.round(rect.top + rect.height / 2)\n };\n })()`);if(!await this.dispatchNativeClick(t,e))return!1;const n=Date.now();for(;Date.now()-n<4e3;){if(!await this.isRecommendFilterPanelVisible())return await Di(600),!0;await Di(Si)}return!1}async readRecommendFilterButtonText(){const e=`(() => {\n const element = document.querySelector(${JSON.stringify(di.recommend.filterButton)});\n const text = element?.textContent?.replace(/\\s+/g, " ").trim() ?? "";\n return text.length > 0 ? text : null;\n })()`,t=await this.evaluateJson(e).catch(()=>null);if("string"==typeof t&&t.length>0)return t;const n=await this.evaluateRecommendFrameJson(e);return"string"==typeof n&&n.length>0?n:void 0}async readVisibleChatCandidates(){return Wi(await this.evaluateJson(`(() => {\n const items = Array.from(document.querySelectorAll(${JSON.stringify(hi)}));\n return items.map((item, idx) => {\n const conversationId =\n item.getAttribute("data-id") ??\n item.closest('[role="listitem"]')?.getAttribute("key") ??\n "";\n const candidateId =\n item.getAttribute("data-geek") ??\n item.querySelector("[data-geek]")?.getAttribute("data-geek") ??\n conversationId;\n const nameEl = item.querySelector(\n '[class*="name"], .nickname, .geek-name, .candidate-name'\n );\n const name = nameEl?.textContent?.trim() ?? "";\n const position = item.querySelector(".source-job")?.textContent?.trim() ?? "";\n const badgeEl = item.querySelector(".badge-count");\n const unreadCount = parseInt(badgeEl?.textContent?.trim() ?? "0", 10) || 0;\n const hasUnread = unreadCount > 0 || item.querySelector(".red-dot") !== null;\n const lastMessageTime =\n item.querySelector(".time, .time-shadow")?.textContent?.trim() ?? "";\n const messagePreview = (\n item.querySelector(".push-text, .chat-last-msg")?.textContent?.trim() ?? ""\n ).slice(0, 100);\n\n return {\n conversationId,\n candidateId,\n name,\n index: idx,\n position,\n hasUnread,\n unreadCount,\n lastMessageTime,\n messagePreview,\n };\n });\n })()`))}async waitForNativeChatReady(e,t=6e3){const n=Date.now();for(;Date.now()-n<t;){const t=await this.readSelectedChatTarget().catch(()=>null),n=await this.readActiveChatPanel().catch(()=>null),r=null!==t&&(e.conversationId.length>0&&t.conversationId===e.conversationId||0===e.conversationId.length&&e.candidateId.length>0&&t.candidateId===e.candidateId),a=0===e.name.length||null!==n&&Ji(e.name,n.candidateName);if(r&&a)return!0;await Di(Si)}return!1}async clickChatCandidate(e,t={}){const n=rs(await this.evaluateJson(`(() => {\n const expected = ${JSON.stringify({conversationId:e.conversationId,candidateId:e.candidateId,index:e.index})};\n const items = Array.from(document.querySelectorAll(${JSON.stringify(hi)}));\n const readCandidate = (item, idx) => {\n const conversationId =\n item.getAttribute("data-id") ??\n item.closest('[role="listitem"]')?.getAttribute("key") ??\n "";\n const candidateId =\n item.getAttribute("data-geek") ??\n item.querySelector("[data-geek]")?.getAttribute("data-geek") ??\n conversationId;\n return { item, idx, conversationId, candidateId };\n };\n\n const candidates = items.map(readCandidate);\n const matched =\n candidates.find((entry) =>\n expected.conversationId.length > 0 &&\n entry.conversationId === expected.conversationId\n ) ??\n candidates.find((entry) =>\n expected.candidateId.length > 0 &&\n entry.candidateId === expected.candidateId\n ) ??\n candidates.find((entry) => entry.idx === expected.index);\n\n if (!matched) {\n return { found: false, x: 0, y: 0 };\n }\n\n matched.item.scrollIntoView({ block: "center", inline: "center" });\n const rect = matched.item.getBoundingClientRect();\n if (rect.width <= 0 || rect.height <= 0) {\n return { found: false, x: 0, y: 0 };\n }\n\n return {\n found: true,\n x: Math.round(rect.left + rect.width / 2),\n y: Math.round(rect.top + rect.height / 2)\n };\n })()`));return!!n.found&&await this.dispatchNativeClick(n,t)}async readVisibleRecommendCandidates(){if(!await this.isRecommendSurfaceOpen().catch(()=>!1))return[];const e=`(() => {\n const iframe = document.querySelector(${JSON.stringify(di.recommend.iframe)});\n const href = location.href;\n const recommendUrlMarkers = ${JSON.stringify(xi)};\n const hasRecommendUrl = recommendUrlMarkers.some((marker) => href.includes(marker));\n if (!hasRecommendUrl && href.includes("/web/chat/index")) {\n return [];\n }\n\n const hasRecommendShell =\n document.querySelector(".recommendV2, .recommend-list-wrap, .recommend-list, .candidate-list, .recommend-filter, .candidate-card-wrap") !== null;\n if (!hasRecommendUrl && !iframe && !hasRecommendShell) {\n return [];\n }\n\n const root = iframe?.contentDocument ?? document;\n let items = Array.from(root.querySelectorAll(${JSON.stringify(yi)}));\n if (items.length === 0 && (hasRecommendUrl || iframe || hasRecommendShell)) {\n items = Array.from(root.querySelectorAll(${JSON.stringify(vi)}));\n }\n\n return items.map((item, idx) => {\n const candidateId =\n item.getAttribute("data-geek") ??\n item.querySelector("[data-geek]")?.getAttribute("data-geek") ??\n "";\n const name = item.querySelector(".name")?.textContent?.trim() ?? "";\n\n let age = "";\n let experience = "";\n let education = "";\n let workStatus = "";\n const baseInfoEl = item.querySelector(".base-info.join-text-wrap, .base-info");\n if (baseInfoEl) {\n let textParts = Array.from(baseInfoEl.querySelectorAll(":scope > *"))\n .map((child) => child.textContent?.trim() ?? "")\n .filter(Boolean);\n\n if (textParts.length <= 1) {\n textParts = [];\n baseInfoEl.childNodes.forEach((node) => {\n if (node.nodeType === Node.TEXT_NODE) {\n const text = node.textContent?.trim() ?? "";\n if (text) textParts.push(text);\n }\n });\n }\n\n if (textParts.length <= 1) {\n textParts = (baseInfoEl.textContent?.trim() ?? "")\n .split(/[丨·|]/)\n .map((text) => text.trim())\n .filter(Boolean);\n }\n\n for (const part of textParts) {\n if (!age && part.includes("岁")) {\n age = part;\n } else if (!experience && (part.includes("年") || part.includes("应届") || part.includes("在校"))) {\n experience = part;\n } else if (!education && /(初中|高中|中专|中技|大专|本科|硕士|博士)/.test(part)) {\n education = part;\n } else if (!workStatus && /(在职|离职|在校)/.test(part)) {\n workStatus = part;\n }\n }\n }\n\n const workExpEl =\n item.querySelector(".timeline-wrap.work-exps .content.join-text-wrap") ??\n item.querySelector(".timeline-wrap.work-exps .content");\n const workParts = (workExpEl?.textContent?.trim() ?? "")\n .split("·")\n .map((text) => text.trim());\n const company = workParts[0] ?? "";\n const currentPosition = workParts[1] ?? "";\n\n let expectedLocation = "";\n let expectedPosition = "";\n const expectRow = item.querySelector(".row-flex:not(.geek-desc)");\n if (expectRow) {\n const labelText = expectRow.querySelector(".label")?.textContent ?? "";\n const contentEl = expectRow.querySelector(".content");\n if ((labelText.includes("期望") || labelText.includes("最近关注")) && contentEl) {\n const parts = (contentEl.textContent?.trim() ?? "")\n .split("·")\n .map((text) => text.trim());\n expectedLocation = parts[0] ?? "";\n expectedPosition = parts[1] ?? "";\n }\n }\n if (!expectedLocation) {\n const expectEl =\n item.querySelector(".timeline-wrap.expect .content.join-text-wrap") ??\n item.querySelector(".timeline-wrap.expect .content");\n if (expectEl) {\n const parts = (expectEl.textContent?.trim() ?? "")\n .split("·")\n .map((text) => text.trim());\n expectedLocation = parts[0] ?? "";\n expectedPosition = parts[1] ?? "";\n }\n }\n\n const tags = Array.from(\n item.querySelectorAll(".tags-wrap .tag-item, .tags-wrap .tag, .tags-wrap span")\n )\n .map((tag) => tag.textContent?.trim() ?? "")\n .filter(Boolean);\n\n return {\n index: idx,\n candidateId,\n name,\n age,\n experience,\n education,\n workStatus,\n company,\n currentPosition,\n expectedLocation,\n expectedPosition,\n expectedSalary: item.querySelector(".salary-wrap")?.textContent?.trim() ?? "",\n tags,\n buttonText: item.querySelector("button.btn.btn-greet")?.textContent?.trim() ?? "",\n };\n });\n })()`,t=Yi(await this.evaluateJson(e));if(t.length>0)return t;return Yi(await this.evaluateRecommendFrameJson(e))}async inspectSurface(e){const t=li(e),n=`(() => {\n const surface = ${JSON.stringify(e)};\n const containerSelectors = ${JSON.stringify(t.containerSelectors)};\n const itemSelector = ${JSON.stringify(t.itemSelector)};\n const iframe = document.querySelector(${JSON.stringify(di.recommend.iframe)});\n const href = location.href;\n const recommendUrlMarkers = ${JSON.stringify(xi)};\n const hasRecommendUrl = recommendUrlMarkers.some((marker) => href.includes(marker));\n if (surface === "recommend-list" && !hasRecommendUrl && href.includes("/web/chat/index")) {\n return {\n containerFound: false,\n containerLabel: "",\n scrollTop: 0,\n scrollHeight: 0,\n clientHeight: 0,\n itemCount: 0,\n atStart: true,\n atEnd: true\n };\n }\n\n const hasRecommendShell =\n document.querySelector(".recommendV2, .recommend-list-wrap, .recommend-list, .candidate-list, .recommend-filter, .candidate-card-wrap") !== null;\n if (surface === "recommend-list" && !hasRecommendUrl && !iframe && !hasRecommendShell) {\n return {\n containerFound: false,\n containerLabel: "",\n scrollTop: 0,\n scrollHeight: 0,\n clientHeight: 0,\n itemCount: 0,\n atStart: true,\n atEnd: true\n };\n }\n\n const root = surface === "recommend-list" ? (iframe?.contentDocument ?? document) : document;\n const readItemCount = () => {\n if (surface === "chat-list") {\n const chatList = root.querySelector(".user-list.b-scroll-stable");\n const roleItems = chatList?.querySelectorAll('[role="listitem"]');\n if (roleItems && roleItems.length > 0) return roleItems.length;\n }\n return root.querySelectorAll(itemSelector).length;\n };\n const itemCount = readItemCount();\n const isVisible = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0;\n };\n\n const isScrollable = (element) => {\n if (!isVisible(element)) return false;\n const view = element.ownerDocument?.defaultView ?? window;\n const style = view.getComputedStyle(element);\n if (style.overflowY === "hidden" || style.overflowY === "clip") return false;\n return element.scrollHeight > element.clientHeight + 2;\n };\n const labelFor = (element, fallback) => {\n if (element === document.scrollingElement) return "document";\n if (element === root.scrollingElement) return root === document ? "document" : "frame-document";\n return (\n element.id ||\n Array.from(element.classList ?? []).join(".") ||\n fallback ||\n element.tagName.toLowerCase()\n );\n };\n const targets = [];\n const pushTarget = (element, fallback) => {\n if (element && !isVisible(element)) return;\n if (!element || targets.some((target) => target.element === element)) return;\n targets.push({ element, label: labelFor(element, fallback) });\n };\n const readCssPixel = (value) => {\n const parsed = Number.parseFloat(value);\n return Number.isFinite(parsed) ? parsed : 0;\n };\n const findChatListElement = (element) => {\n if (surface !== "chat-list") return null;\n if (element.matches?.(".user-list.b-scroll-stable")) return element;\n return (\n element.querySelector?.(".user-list.b-scroll-stable") ??\n element.closest?.(".user-list.b-scroll-stable") ??\n null\n );\n };\n const readChatListSnapshot = (target) => {\n const list = findChatListElement(target.element);\n if (!list || itemCount <= 0 || !isVisible(list)) return null;\n\n const nativeScrollTop = Math.max(0, list.scrollTop);\n const nativeScrollHeight = Math.max(0, list.scrollHeight);\n const nativeClientHeight = Math.max(0, list.clientHeight);\n const nativeMaxScrollTop = Math.max(0, nativeScrollHeight - nativeClientHeight);\n if (nativeScrollHeight > nativeClientHeight + 2) {\n return {\n containerFound: true,\n containerLabel: labelFor(list, ".user-list.b-scroll-stable"),\n scrollTop: Math.round(nativeScrollTop),\n scrollHeight: Math.round(nativeScrollHeight),\n clientHeight: Math.round(nativeClientHeight),\n itemCount,\n atStart: nativeScrollTop <= 1,\n atEnd: nativeScrollTop >= nativeMaxScrollTop - 1\n };\n }\n\n const listRect = list.getBoundingClientRect();\n if (listRect.width <= 0 || listRect.height <= 0) return null;\n const group = list.querySelector('[role="group"]');\n if (!group) return null;\n\n const view = list.ownerDocument?.defaultView ?? window;\n const groupStyle = view.getComputedStyle(group);\n const paddingTop = Math.max(0, readCssPixel(groupStyle.paddingTop));\n const paddingBottom = Math.max(0, readCssPixel(groupStyle.paddingBottom));\n const roleItems = Array.from(list.querySelectorAll('[role="listitem"]'));\n const renderedItems =\n roleItems.length > 0 ? roleItems : Array.from(list.querySelectorAll(".geek-item"));\n const renderedHeight = renderedItems.reduce((sum, item) => {\n const rect = item.getBoundingClientRect();\n return sum + Math.max(0, rect.height);\n }, 0);\n const virtualHeight = Math.max(\n Math.round(paddingTop + renderedHeight + paddingBottom),\n Math.round(listRect.height)\n );\n return {\n containerFound: true,\n containerLabel: labelFor(list, ".user-list.b-scroll-stable") + ":virtual",\n scrollTop: Math.round(paddingTop),\n scrollHeight: virtualHeight,\n clientHeight: Math.round(listRect.height),\n itemCount,\n atStart: paddingTop <= 1,\n atEnd: paddingBottom <= 1\n };\n };\n\n for (const selector of containerSelectors) {\n try {\n for (const element of Array.from(root.querySelectorAll(selector))) {\n pushTarget(element, selector);\n }\n } catch {}\n }\n\n const firstVisibleItem = Array.from(root.querySelectorAll(itemSelector)).find(isVisible);\n let current = firstVisibleItem?.parentElement ?? null;\n while (current && current !== root.body && current !== root.documentElement) {\n pushTarget(current, "item-ancestor");\n current = current.parentElement;\n }\n\n if (surface === "recommend-list" && root !== document) {\n const outerFrame = iframe ?? window.frameElement;\n let outer = outerFrame?.parentElement ?? null;\n while (outer && outer !== document.body && outer !== document.documentElement) {\n pushTarget(outer, "iframe-ancestor");\n outer = outer.parentElement;\n }\n pushTarget(document.scrollingElement, "document");\n pushTarget(document.documentElement, "documentElement");\n pushTarget(document.body, "body");\n }\n pushTarget(root.scrollingElement, root === document ? "document" : "frame-document");\n\n for (const target of targets) {\n const chatListSnapshot = readChatListSnapshot(target);\n if (chatListSnapshot) return chatListSnapshot;\n }\n\n const scrollTarget = targets.find((target) => isScrollable(target.element));\n if (!scrollTarget) {\n return {\n containerFound: false,\n containerLabel: targets[0]?.label ?? "",\n scrollTop: 0,\n scrollHeight: 0,\n clientHeight: 0,\n itemCount,\n atStart: true,\n atEnd: true\n };\n }\n\n const scrollable = scrollTarget.element;\n const max = Math.max(0, scrollable.scrollHeight - scrollable.clientHeight);\n return {\n containerFound: true,\n containerLabel: scrollTarget.label,\n scrollTop: scrollable.scrollTop,\n scrollHeight: scrollable.scrollHeight,\n clientHeight: scrollable.clientHeight,\n itemCount,\n atStart: scrollable.scrollTop <= 1,\n atEnd: scrollable.scrollTop >= max - 1\n };\n })()`,r=cs(await this.evaluateJson(n));if("recommend-list"!==e||r.itemCount>0)return r;const a=cs(await this.evaluateRecommendFrameJson(n));return a.itemCount>0?a:r}async scrollSurfaceWithWheel(e,t,n){const r=li(e);await wn(this);const a=rs(await this.evaluateJson(`(() => {\n const nativeWheelTarget = true;\n const surface = ${JSON.stringify(e)};\n const containerSelectors = ${JSON.stringify(r.containerSelectors)};\n const itemSelector = ${JSON.stringify(r.itemSelector)};\n const iframe = document.querySelector(${JSON.stringify(di.recommend.iframe)});\n const root = surface === "recommend-list" ? (iframe?.contentDocument ?? document) : document;\n const viewportWidth = window.innerWidth || document.documentElement.clientWidth || 0;\n const viewportHeight = window.innerHeight || document.documentElement.clientHeight || 0;\n const targets = [];\n const pushTarget = (element) => {\n if (!element || targets.includes(element)) return;\n targets.push(element);\n };\n\n for (const selector of containerSelectors) {\n try {\n for (const element of Array.from(root.querySelectorAll(selector))) {\n pushTarget(element);\n }\n } catch {}\n }\n\n const firstItem = Array.from(root.querySelectorAll(itemSelector)).find((element) => {\n const rect = element.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0;\n });\n pushTarget(firstItem);\n let current = firstItem?.parentElement ?? null;\n while (current && current !== root.body && current !== root.documentElement) {\n pushTarget(current);\n current = current.parentElement;\n }\n\n const readPoint = (element) => {\n const rect = element.getBoundingClientRect();\n if (rect.width <= 0 || rect.height <= 0) return null;\n let left = rect.left;\n let top = rect.top;\n if (root !== document && iframe) {\n const frameRect = iframe.getBoundingClientRect();\n left += frameRect.left;\n top += frameRect.top;\n }\n const x = Math.round(Math.min(Math.max(left + rect.width / 2, 4), Math.max(4, viewportWidth - 4)));\n const y = Math.round(Math.min(Math.max(top + rect.height / 2, 4), Math.max(4, viewportHeight - 4)));\n return { found: true, x, y };\n };\n\n for (const element of targets) {\n const point = readPoint(element);\n if (point) return point;\n }\n\n return { found: false, x: 0, y: 0 };\n })()`));if(!a.found)return;await this.mouse.moveTo(qi(a)),await this.controller.dispatchMouseEvent({type:"mouseWheel",x:a.x,y:a.y,buttons:0,deltaX:0,deltaY:"up"===t?-(n??Ei):n??Ei}),await Di(120);const o=await this.inspectSurface(e);return o.containerFound?o:{...o,containerFound:!0,containerLabel:o.containerLabel.length>0?o.containerLabel:"native-wheel",atStart:"up"!==t&&o.atStart,atEnd:"down"!==t&&o.atEnd}}async scrollSurfaceOnce(e,t,n){const r=li(e),a=`(() => {\n const surface = ${JSON.stringify(e)};\n const direction = ${JSON.stringify(t)};\n const explicitDistance = ${void 0!==n?JSON.stringify(n):"undefined"};\n const containerSelectors = ${JSON.stringify(r.containerSelectors)};\n const itemSelector = ${JSON.stringify(r.itemSelector)};\n const iframe = document.querySelector(${JSON.stringify(di.recommend.iframe)});\n const href = location.href;\n const recommendUrlMarkers = ${JSON.stringify(xi)};\n const hasRecommendUrl = recommendUrlMarkers.some((marker) => href.includes(marker));\n if (surface === "recommend-list" && !hasRecommendUrl && href.includes("/web/chat/index")) {\n return {\n containerFound: false,\n containerLabel: "",\n scrollTop: 0,\n scrollHeight: 0,\n clientHeight: 0,\n itemCount: 0,\n atStart: true,\n atEnd: true\n };\n }\n\n const hasRecommendShell =\n document.querySelector(".recommendV2, .recommend-list-wrap, .recommend-list, .candidate-list, .recommend-filter, .candidate-card-wrap") !== null;\n if (surface === "recommend-list" && !hasRecommendUrl && !iframe && !hasRecommendShell) {\n return {\n containerFound: false,\n containerLabel: "",\n scrollTop: 0,\n scrollHeight: 0,\n clientHeight: 0,\n itemCount: 0,\n atStart: true,\n atEnd: true\n };\n }\n\n const root = surface === "recommend-list" ? (iframe?.contentDocument ?? document) : document;\n const itemCount = root.querySelectorAll(itemSelector).length;\n const isVisible = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0;\n };\n const isScrollable = (element) => {\n if (!isVisible(element)) return false;\n const view = element.ownerDocument?.defaultView ?? window;\n const style = view.getComputedStyle(element);\n if (style.overflowY === "hidden" || style.overflowY === "clip") return false;\n return element.scrollHeight > element.clientHeight + 2;\n };\n const labelFor = (element, fallback) => {\n if (element === document.scrollingElement) return "document";\n if (element === root.scrollingElement) return root === document ? "document" : "frame-document";\n return (\n element.id ||\n Array.from(element.classList ?? []).join(".") ||\n fallback ||\n element.tagName.toLowerCase()\n );\n };\n const targets = [];\n const pushTarget = (element, fallback) => {\n if (element && !isVisible(element)) return;\n if (!element || targets.some((target) => target.element === element)) return;\n targets.push({ element, label: labelFor(element, fallback) });\n };\n\n for (const selector of containerSelectors) {\n try {\n for (const element of Array.from(root.querySelectorAll(selector))) {\n pushTarget(element, selector);\n }\n } catch {}\n }\n\n const firstVisibleItem = Array.from(root.querySelectorAll(itemSelector)).find(isVisible);\n let current = firstVisibleItem?.parentElement ?? null;\n while (current && current !== root.body && current !== root.documentElement) {\n pushTarget(current, "item-ancestor");\n current = current.parentElement;\n }\n\n if (surface === "recommend-list" && root !== document) {\n const outerFrame = iframe ?? window.frameElement;\n let outer = outerFrame?.parentElement ?? null;\n while (outer && outer !== document.body && outer !== document.documentElement) {\n pushTarget(outer, "iframe-ancestor");\n outer = outer.parentElement;\n }\n pushTarget(document.scrollingElement, "document");\n pushTarget(document.documentElement, "documentElement");\n pushTarget(document.body, "body");\n }\n pushTarget(root.scrollingElement, root === document ? "document" : "frame-document");\n\n const scrollTarget = targets.find((target) => isScrollable(target.element));\n if (!scrollTarget) {\n return {\n containerFound: false,\n containerLabel: targets[0]?.label ?? "",\n scrollTop: 0,\n scrollHeight: 0,\n clientHeight: 0,\n itemCount,\n atStart: true,\n atEnd: true\n };\n }\n\n const scrollable = scrollTarget.element;\n const max = Math.max(0, scrollable.scrollHeight - scrollable.clientHeight);\n const amount = explicitDistance ?? Math.max(320, Math.floor(scrollable.clientHeight * 0.85));\n scrollable.scrollTop =\n direction === "up"\n ? Math.max(0, scrollable.scrollTop - amount)\n : Math.min(max, scrollable.scrollTop + amount);\n\n return {\n containerFound: true,\n containerLabel: scrollTarget.label,\n scrollTop: scrollable.scrollTop,\n scrollHeight: scrollable.scrollHeight,\n clientHeight: scrollable.clientHeight,\n itemCount,\n atStart: scrollable.scrollTop <= 1,\n atEnd: scrollable.scrollTop >= max - 1\n };\n })()`,o=cs(await this.evaluateJson(a));if("recommend-list"!==e||o.itemCount>0)return o;const i=cs(await this.evaluateRecommendFrameJson(a));return i.itemCount>0?i:o}async scrollChatList(e="down"){const t=await this.scrollSurface("chat-list",{direction:e,steps:1,settleMs:0});return{ok:t.success&&t.stepsCompleted>0,before:t.before.scrollTop,after:t.after.scrollTop,max:Math.max(0,t.after.scrollHeight-t.after.clientHeight)}}};import{createHash as fs}from"node:crypto";var hs,bs,ys={fetch:fetch,env:process.env},vs="https://huajune.duliday.com",ws=new Set;function xs(e,t){const n=e[t]?.trim();return void 0===n||0===n.length?void 0:n}function Ss(e,t){const n=xs(e,t);if(void 0!==n){if("true"===n)return!0;if("false"===n)return!1;throw new Error(`Expected boolean env value "true" or "false" for ${t}, received "${n}".`)}}function Is(e){const t=Ss(e,"RECRUITMENT_EVENTS_ENABLED"),n=xs(e,"RECRUITMENT_EVENTS_API_BASE_URL")??vs,r=xs(e,"RECRUITMENT_EVENTS_API_TOKEN"),a=xs(e,"RECRUITMENT_EVENTS_DEFAULT_AGENT_ID");return{enabled:t??!0,apiBaseUrl:n,...void 0!==r?{apiToken:r}:{},...void 0!==a?{defaultAgentId:a}:{}}}function Cs(e,t){const n=be(e.defaultAgentId);if(void 0!==n)return n;he()&&Rs(t,"missing-instance-tracking","Recruitment event skipped: select a browserInstance, configure tracking-agent-id on the active browser instance, or set RECRUITMENT_EVENTS_DEFAULT_AGENT_ID.")}function Rs(e,t,n){ws.has(t)||(ws.add(t),e.warn(n))}function ks(e){return`${e.replace(/\/+$/,"")}/api/v1/recruitment-events`}function As(e){return"object"==typeof e&&null!==e}function Ns(e,t){const n=e[t];return"string"==typeof n?n:void 0}function Ms(e){if(!As(e)||!As(e.data)||!Array.isArray(e.data.results))return;const t=e.data.results.find(e=>As(e)&&"error"===Ns(e,"status"));if(!As(t))return;const n=Ns(t,"idempotencyKey"),r=t.error,a=As(r)?Ns(r,"code"):void 0,o=As(r)?Ns(r,"message"):void 0;return`Recruitment events API rejected event${void 0!==n?` ${n}`:""}${void 0!==a?` ${a}`:""}${void 0!==o?`: ${o}`:""}`}async function Es(e,t,n){const r=Is(n.env);if(!r.enabled)return;const a=Cs(r,t);if(void 0===r.apiToken)return void Rs(t,"missing-required-config","Recruitment events tracking is enabled by default; require RECRUITMENT_EVENTS_API_TOKEN.");if(void 0===a)return void(he()||Rs(t,"missing-required-config","Recruitment events tracking is enabled by default; require RECRUITMENT_EVENTS_DEFAULT_AGENT_ID."));const o={events:[{...e,agentId:a,eventTime:e.eventTime??(new Date).toISOString()}]},i=await n.fetch(ks(r.apiBaseUrl),{method:"POST",headers:{Authorization:`Bearer ${r.apiToken}`,"Content-Type":"application/json"},body:JSON.stringify(o)});if(!i.ok){const e=await i.text().catch(()=>"");throw new Error(`Recruitment events API request failed (${i.status})${e.length>0?`: ${e}`:""}`)}const s=Ms(await i.json().catch(()=>{}));if(void 0!==s)throw new Error(s)}function Ps(e,t){return`${e}:${fs("sha256").update(JSON.stringify(t.map(e=>e??""))).digest("hex").slice(0,24)}`}function Ts(e,t){(async()=>{const n=bs??(async(e,t)=>{await Es(e,t,{...ys,...hs})});await n(e,t)})().catch(e=>{t.warn(`Recruitment event tracking failed: ${e instanceof Error?e.message:String(e)}`)})}function _s(){return(new Date).toISOString().slice(0,10)}function Bs(e){const t=e?.trim();return void 0!==t&&t.length>0?t:void 0}function Os(e,t,n){const r=e?.candidateInfo,a=Bs(r?.age),o=Bs(r?.education),i=Bs(r?.expectedSalary);return{name:Bs(r?.name)??t,position:n,...void 0!==a?{age:a}:{},...void 0!==o?{education:o}:{},...void 0!==i?{expectedSalary:i}:{}}}function $s(e){return Bs(e?.candidateInfo.communicationPosition)??""}function Ds(e){const t=Bs(e?.candidateInfo.expectedJobText);if(void 0===t)return"";const n=t.split(/[·||]/).map(e=>e.trim()).filter(Boolean);return n.length>1?n[1]??"":t}function qs(e){const t=Bs(e?.candidateInfo.expectedJobText);if(void 0===t)return;const n=t.split(/[·||]/).map(e=>e.trim()).filter(Boolean);return n.length>1?Bs(n[0]):void 0}function js(e){return e.length>0?{job:{jobName:e}}:{}}function Fs(e,t){return e.trim().length>0&&t.trim().length>0}function Ls(e){const t=e.content.trim(),n=/微信(?:号)?\s*[::]?\s*([A-Za-z0-9_-]{5,})/.exec(t);return void 0!==n?.[1]?n[1]:/^[A-Za-z][A-Za-z0-9_-]{5,}$/.test(t)?t:void 0}function zs(e,t){for(const n of e)n.hasUnread&&0!==n.name.length&&Fs(n.name,n.position)&&Ts({idempotencyKey:Ps("zhipin-message-received",[n.conversationId,n.candidateId,n.name,n.position,_s()]),sourcePlatform:"zhipin",dataSource:"api_callback",eventType:"message_received",candidate:{name:n.name,position:n.position},job:{jobId:0,jobName:n.position},details:{unreadCount:n.unreadCount>0?n.unreadCount:1,lastMessagePreview:n.preview,conversationId:n.conversationId,candidateId:n.candidateId}},t)}function Js(e,t){const n=$s(e.candidateDetails),r=n,a=Os(e.candidateDetails,e.candidateName,r);if(!Fs(a.name,a.position))return;const o=qs(e.candidateDetails);Ts({idempotencyKey:Ps("zhipin-message-sent",[e.conversationId,e.candidateId,e.replyId]),sourcePlatform:"zhipin",dataSource:"api_callback",eventType:"message_sent",candidate:{...a,...void 0!==o?{expectedLocation:o}:{}},...js(n),details:{content:e.message,isAutoReply:!0,unreadCountBeforeReply:e.unreadCountBeforeReply,wasUnreadBeforeReply:e.unreadCountBeforeReply>0,conversationId:e.conversationId,candidateId:e.candidateId}},t)}function Vs(e,t){if(!e.clicked||0===e.name.length)return;const n=Bs(e.expectedPosition);if(void 0===n||!Fs(e.name,n))return;const r=Bs(e.age),a=Bs(e.education),o=Bs(e.expectedSalary),i=Bs(e.expectedLocation);Ts({idempotencyKey:Ps("zhipin-candidate-contacted",[e.candidateId,e.name,_s()]),sourcePlatform:"zhipin",dataSource:"api_callback",eventType:"candidate_contacted",candidate:{name:e.name,position:n,...void 0!==r?{age:r}:{},...void 0!==a?{education:a}:{},...void 0!==o?{expectedSalary:o}:{},...void 0!==i?{expectedLocation:i}:{}},details:{candidateId:e.candidateId}},t)}function Hs(e,t){const n=$s(e.candidateDetails),r=Os(e.candidateDetails,e.candidateName,n);if(!Fs(r.name,r.position))return;const a=qs(e.candidateDetails);Ts({idempotencyKey:Ps("zhipin-wechat-requested",[e.conversationId,e.candidateId,_s()]),sourcePlatform:"zhipin",dataSource:"api_callback",eventType:"wechat_exchanged",candidate:{...r,...void 0!==a?{expectedLocation:a}:{}},...js(n),details:{exchangeType:e.exchangeType??(void 0!==e.wechatNumber?"accepted":"requested"),conversationId:e.conversationId,candidateId:e.candidateId,...void 0!==e.wechatNumber?{wechatNumber:e.wechatNumber}:{}}},t)}function Us(e,t,n,r){const a=$s(e),o=Ds(e),i=qs(e),s=Os(e,e.candidateInfo.name,o);if(!Fs(s.name,s.position))return;const c=e.messages.find(e=>"wechat-exchange"===e.messageType);if(void 0===c)return;const l=Ls(c);Ts({idempotencyKey:Ps("zhipin-wechat-completed",[t,n]),sourcePlatform:"zhipin",dataSource:"api_callback",eventType:"wechat_exchanged",candidate:{...s,...void 0!==i?{expectedLocation:i}:{}},...js(a),details:{exchangeType:"completed",conversationId:t,candidateId:n,messageIndex:c.index,...void 0!==l?{wechatNumber:l}:{}}},r)}var Ws,Ks=ti.object({name:ti.string(),conversationId:ti.string(),candidateId:ti.string(),position:ti.string(),time:ti.string(),preview:ti.string(),unreadCount:ti.number(),hasUnread:ti.boolean(),index:ti.number()}),Ys=ti.object({success:ti.boolean(),candidates:ti.array(Ks),total:ti.number(),stats:ti.object({withName:ti.number(),withUnread:ti.number()})});function Gs(){return{openNativePagePort:ps,createNativeVisualActivitySession:e=>new Xr(e),...Ws}}function Xs(e){return e.conversationId.length>0?e.conversationId:e.candidateId.length>0?e.candidateId:0!==e.name.length?[e.name,e.position,e.lastMessageTime].join("|"):void 0}function Zs(e){const t=new Set,n=[];for(const r of e){const e=Xs(r);void 0!==e&&t.has(e)||(void 0!==e&&t.add(e),n.push(r))}return n}var Qs=ei({name:"zhipin_read_messages",description:"读取 BOSS直聘消息列表,默认返回全部候选人;若只看未读消息,传 onlyUnread=true",input:ti.object({limit:ti.number().optional().describe("最多返回条数"),onlyUnread:ti.boolean().default(!1).describe("是否只返回有未读消息的候选人;用户说“全部/所有消息列表”时应为 false,说“未读消息”时应为 true"),sortBy:ti.enum(["time","unreadCount","name"]).default("time"),autoScroll:ti.boolean().default(!0).describe("是否自动向下滚动消息列表并合并采集结果"),maxScrolls:ti.number().int().min(0).max(50).default(4).describe("自动滚动的最大步数")}),output:Ys,execute:async(e,t)=>{const n=e.onlyUnread??!1;let r,a;t.logger.info(`Reading zhipin messages (limit: ${e.limit??"all"}, onlyUnread: ${n})`);const o=Gs();try{r=await o.openNativePagePort({requireChatPage:!0}),a=o.createNativeVisualActivitySession(r),await a.begin("正在读取消息列表");if(!await r.waitForSelector('.user-list.b-scroll-stable, .user-list.b-scroll-stable [role="listitem"], .geek-item',5e3))return await a.fail("未找到消息列表"),{success:!1,candidates:[],total:0,stats:{withName:0,withUnread:0}};const i=n?"正在读取未读消息列表":"正在读取消息列表";await a.highlightSelector(".user-list.b-scroll-stable, .chat-user .user-container, .chat-user",{label:i,padding:8});const s=e.autoScroll??!0,c=e.maxScrolls??4,l=Zs(await r.readChatCandidates({autoScroll:s,maxScrolls:c,...void 0===e.limit||n?{}:{targetCount:e.limit}})).map(e=>({name:e.name,conversationId:e.conversationId,candidateId:e.candidateId,position:e.position,time:e.lastMessageTime,preview:e.messagePreview,unreadCount:e.unreadCount,hasUnread:e.hasUnread,index:e.index}));let d=n?l.filter(e=>e.hasUnread):l;const u=e.sortBy??"time";"time"===u||("unreadCount"===u?d.sort((e,t)=>t.unreadCount-e.unreadCount):"name"===u&&d.sort((e,t)=>e.name.localeCompare(t.name))),void 0!==e.limit&&(d=d.slice(0,e.limit));const m={withName:l.filter(e=>e.name.length>0).length,withUnread:l.filter(e=>e.hasUnread).length};return await a.succeed(n?`已读取 ${d.length} 条未读消息`:`已读取 ${d.length} 条消息`),t.logger.info(`Found ${d.length} candidates (${m.withUnread} with unread)`),zs(d,t.logger),{success:!0,candidates:d,total:l.length,stats:m}}catch(e){return await(a?.fail("读取消息列表失败")),t.logger.warn(`Native zhipin message read failed: ${e instanceof Error?e.message:String(e)}`),{success:!1,candidates:[],total:0,stats:{withName:0,withUnread:0}}}finally{r?.close()}}});import{BrowserPageInfoSchema as ec}from"@roll-agent/browser";import{defineTool as tc}from"@roll-agent/sdk";import{z as nc}from"zod";var rc,ac=nc.object({success:nc.boolean(),alreadyOnChat:nc.boolean(),usedSidebarClick:nc.boolean(),chatReady:nc.boolean(),page:ec.optional(),error:nc.string().optional()});function oc(){return{getContextManager:ue,openNativePagePort:ps,createNativeVisualActivitySession:e=>new Xr(e),...rc}}async function ic(e,t){return Wt(e,await t.inspectPage())}var sc=tc({name:"zhipin_open_chat_page",description:"通过点击 Boss 左侧导航切换回「沟通」页,避免让编排器依赖站内 URL 猜测。",input:nc.object({}),output:ac,execute:async(e,t)=>{const n=oc(),r=n.getContextManager();let a,o;t.logger.info("Opening Boss chat page via native sidebar navigation");try{a=await n.openNativePagePort(),o=n.createNativeVisualActivitySession(a),await wn(a);const e="正在切换到沟通页";if(await o.begin(e),await o.highlightSelector(di.nav.sidebar,{label:e,padding:10}),await a.isChatSurfaceOpen())return await o.succeed("已在沟通页"),{success:!0,alreadyOnChat:!0,usedSidebarClick:!1,chatReady:!0,page:await ic(r,a)};if(!await a.clickSidebarSection("chat",{...void 0!==o?{motionObserver:o}:{}}))return await o.fail("未找到沟通导航"),{success:!1,alreadyOnChat:!1,usedSidebarClick:!1,chatReady:!1,page:await ic(r,a),error:"未找到沟通导航"};t.logger.info("Clicked Boss sidebar nav: 沟通");return await a.waitForChatSurface()?(await o.succeed("已切换到沟通页"),{success:!0,alreadyOnChat:!1,usedSidebarClick:!0,chatReady:!0,page:await ic(r,a)}):(await o.fail("沟通页未就绪"),{success:!1,alreadyOnChat:!1,usedSidebarClick:!0,chatReady:!1,page:await ic(r,a),error:"沟通页未就绪"})}catch(e){return await(o?.fail("切换沟通页失败")),{success:!1,alreadyOnChat:!1,usedSidebarClick:!1,chatReady:!1,error:e instanceof Error?e.message:"切换沟通页失败"}}finally{a?.close()}}});import{defineTool as cc}from"@roll-agent/sdk";import{z as lc}from"zod";var dc,uc=lc.object({success:lc.boolean(),conversationId:lc.string(),candidateId:lc.string(),candidateName:lc.string(),index:lc.number(),hasUnread:lc.boolean(),unreadCount:lc.number(),lastMessageTime:lc.string(),messagePreview:lc.string(),error:lc.string().optional()});function mc(){return{openNativePagePort:ps,createNativeVisualActivitySession:e=>new Xr(e),...dc}}var pc=cc({name:"zhipin_open_chat",description:"打开指定候选人的聊天窗口(优先按 conversationId,其次姓名,最后才用索引)",input:lc.object({conversationId:lc.string().optional().describe("会话 ID。若已从 `zhipin_read_messages` 获取,优先传这个,最稳定"),candidateName:lc.string().optional().describe("候选人姓名。若用户说“打开鲁倩的聊天”,这里应提取为“鲁倩”"),index:lc.number().optional().describe("候选人在列表中的索引。仅在缺少 conversationId 时兜底"),preferUnread:lc.boolean().default(!1).describe("优先选择有未读消息的候选人")}),output:uc,execute:async(e,t)=>{t.logger.info(`Opening chat: name=${e.candidateName??"N/A"}, index=${e.index??"N/A"}`);const n=mc();let r,a;try{r=await n.openNativePagePort(),a=n.createNativeVisualActivitySession(r),await a.begin("正在打开目标聊天"),await a.highlightSelector(".user-list.b-scroll-stable, .chat-user .user-container, .chat-user",{label:"正在定位候选人",padding:8});const o=await r.openChat({conversationId:e.conversationId,candidateName:e.candidateName,index:e.index,preferUnread:e.preferUnread??!1,...void 0!==a?{motionObserver:a}:{}});return o.found?(await a.succeed(`已打开 ${o.name||"目标"} 的聊天`),t.logger.info(`Opened chat with ${o.name} (index: ${o.index})`),{success:!0,conversationId:o.conversationId,candidateId:o.candidateId,candidateName:o.name,index:o.index,hasUnread:o.hasUnread,unreadCount:o.unreadCount,lastMessageTime:o.lastMessageTime,messagePreview:o.messagePreview}):(await a.fail("打开聊天失败"),{success:!1,conversationId:"",candidateId:"",candidateName:e.candidateName??"",index:e.index??-1,hasUnread:!1,unreadCount:0,lastMessageTime:"",messagePreview:"",error:o.error??`未找到候选人: ${e.candidateName??`index ${e.index}`}`})}catch(n){return await(a?.fail("打开聊天失败")),t.logger.warn(`Native zhipin open chat failed: ${n instanceof Error?n.message:String(n)}`),{success:!1,conversationId:"",candidateId:"",candidateName:e.candidateName??"",index:e.index??-1,hasUnread:!1,unreadCount:0,lastMessageTime:"",messagePreview:"",error:n instanceof Error?n.message:"打开聊天失败"}}finally{r?.close()}}});import{defineTool as gc}from"@roll-agent/sdk";import{z as fc}from"zod";var hc="·",bc=/[--—–]/;function yc(e){return(e??"").trim()}function vc(e){const t=yc(e);if(!t||!bc.test(t))return;const[n=""]=t.split(bc);return yc(n)||void 0}function wc(e){const t=yc(e);if(!t)return{expectedLocation:"",expectedPosition:""};const[n="",r=""]=t.split(hc).map(e=>yc(e));return{expectedLocation:n,expectedPosition:r}}function xc(e){const t=yc(e.communicationPosition),{expectedLocation:n,expectedPosition:r}=wc(e.expectedJobText),a=vc(t);return{communicationPosition:t,expectedLocation:n,expectedPosition:r,...void 0!==a?{preferredBrand:a}:{}}}var Sc,Ic=fc.object({index:fc.number(),sender:fc.enum(["candidate","recruiter","system"]),messageType:fc.enum(["text","system","resume","wechat-exchange"]),content:fc.string(),time:fc.string()}),Cc=fc.object({name:fc.string(),age:fc.string(),experience:fc.string(),education:fc.string(),communicationPosition:fc.string(),expectedPosition:fc.string(),expectedLocation:fc.string(),expectedSalary:fc.string(),tags:fc.array(fc.string())}),Rc=fc.object({success:fc.boolean(),conversationId:fc.string(),candidateId:fc.string(),candidateInfo:Cc,preferredBrand:fc.string().optional(),chatMessages:fc.array(Ic),formattedHistory:fc.array(fc.string()),stats:fc.object({totalMessages:fc.number(),candidateMessages:fc.number(),recruiterMessages:fc.number(),systemMessages:fc.number()}),error:fc.string().optional()});function kc(){return{name:"",age:"",experience:"",education:"",communicationPosition:"",expectedPosition:"",expectedLocation:"",expectedSalary:"",tags:[]}}function Ac(e){return{success:!1,conversationId:"",candidateId:"",candidateInfo:kc(),chatMessages:[],formattedHistory:[],stats:{totalMessages:0,candidateMessages:0,recruiterMessages:0,systemMessages:0},error:e}}function Nc(e,t){const n=e.trim().toLocaleLowerCase("zh-CN"),r=t.trim().toLocaleLowerCase("zh-CN");return n.length>0&&r.length>0&&(n===r||n.includes(r)||r.includes(n))}function Mc(){return{openNativePagePort:ps,createNativeVisualActivitySession:e=>new Xr(e),...Sc}}var Ec=gc({name:"zhipin_get_candidate_info",description:"提取候选人资料和完整聊天记录。可指定 conversationId 或 candidateName 自动打开对应聊天;若已从 `zhipin_read_messages` 获取 conversationId,优先传它。",input:fc.object({conversationId:fc.string().optional().describe("会话 ID。若已从 `zhipin_read_messages` 获取,优先传这个,最稳定"),candidateName:fc.string().optional().describe("候选人姓名。若用户说“查看鲁倩的聊天详情”,这里应提取为“鲁倩”"),index:fc.number().optional().describe("候选人在列表中的索引(可选,仅兜底)"),maxMessages:fc.number().default(100).describe("最多返回的消息条数")}),output:Rc,execute:async(e,t)=>{const n=e.maxMessages??100,r=Mc(),a=void 0!==e.conversationId||void 0!==e.candidateName||void 0!==e.index;let o,i;const s=a?"正在打开目标聊天":"正在准备当前聊天",c="正在提取聊天记录",l=async(e,t)=>(await(i?.fail(e)),Ac(t));try{o=await r.openNativePagePort(),i=r.createNativeVisualActivitySession(o),await i.begin(s);const d=a?await o.openChat({conversationId:e.conversationId,candidateName:e.candidateName,index:e.index,maxScrolls:4}):void 0;if(void 0!==d&&!d.found)return await l("打开聊天失败",d.error??"打开聊天失败");if(void 0===d&&!await o.isChatSurfaceOpen().catch(()=>!1))return await l("当前不是沟通页","当前页面不是 BOSS 沟通页,无法读取当前聊天详情");t.logger.info("Extracting candidate info"+(void 0!==d?` for ${d.name}`:" (current window)")),await i.begin(c),await i.highlightSelector(".chat-conversation, .conversation-box, .conversation-message",{label:c,padding:12});const u=d?.name??e.candidateName??"",m=await o.readActiveChatPanel();if(u.length>0&&(!m||!Nc(u,m.candidateName)))return await l("聊天面板未同步",`右侧聊天面板未切换到 ${u}`);const p=await o.readSelectedChatTarget();if(!p)return await l("未识别当前会话","未能提取当前选中聊天的 conversationId/candidateId");if(!(void 0===d||d.conversationId.length>0&&p.conversationId===d.conversationId||0===d.conversationId.length&&d.candidateId.length>0&&p.candidateId===d.candidateId))return await l("当前会话不一致",`当前选中会话与目标会话不一致: ${d?.name||d?.conversationId||""}`);if(m&&p.candidateName.length>0&&!Nc(p.candidateName,m.candidateName))return await l("左右面板不一致",`左侧选中会话与右侧聊天面板不一致: ${p.candidateName} / ${m.candidateName}`);await o.waitForChatMessages();const g=await o.readCandidateChatDetails(n),f=xc({communicationPosition:g.candidateInfo.communicationPosition,expectedJobText:g.candidateInfo.expectedJobText}),h=g.messages.filter(e=>"candidate"===e.sender||"recruiter"===e.sender).map(e=>`${"candidate"===e.sender?"求职者":"我"}: ${e.content}`),b={totalMessages:g.messages.length,candidateMessages:g.messages.filter(e=>"candidate"===e.sender).length,recruiterMessages:g.messages.filter(e=>"recruiter"===e.sender).length,systemMessages:g.messages.filter(e=>"system"===e.sender).length};return await i.succeed(`已提取 ${b.totalMessages} 条聊天记录`),t.logger.info(`Extracted info for ${g.candidateInfo.name}: ${b.totalMessages} messages`),Us(g,p.conversationId,p.candidateId,t.logger),{success:!0,conversationId:p.conversationId,candidateId:p.candidateId,candidateInfo:{name:g.candidateInfo.name,age:g.candidateInfo.age,experience:g.candidateInfo.experience,education:g.candidateInfo.education,communicationPosition:f.communicationPosition,expectedPosition:f.expectedPosition,expectedLocation:f.expectedLocation,expectedSalary:g.candidateInfo.expectedSalary,tags:[...g.candidateInfo.tags]},...void 0!==f.preferredBrand?{preferredBrand:f.preferredBrand}:{},chatMessages:[...g.messages],formattedHistory:h,stats:b}}catch(e){return await(i?.fail("提取聊天记录失败")),t.logger.warn(`Native zhipin candidate info read failed: ${e instanceof Error?e.message:String(e)}`),Ac(e instanceof Error?e.message:"提取聊天记录失败")}finally{o?.close()}}});import{defineTool as Pc}from"@roll-agent/sdk";import{GenerateSignedReplyResponseSchema as Tc,ReasoningConfigSchema as _c,ReplyStreamFinalEventSchema as Bc,streamGenerateSignedReply as Oc}from"@roll-agent/reply-authority-client";import{z as $c}from"zod";import{randomUUID as Dc}from"node:crypto";var qc=new Map;function jc(e){for(const[t,n]of qc)n.expiresAt<=e&&qc.delete(t)}function Fc(e,t=Math.floor(Date.now()/1e3)){if(jc(t),e.expiresAt<=t)throw new Error("Prepared reply 已过期,禁止保存。");const n=`prep_${Dc()}`,r={preparedReplyId:n,...e};return qc.set(n,{...r,consumed:!1}),r}function Lc(e,t=Math.floor(Date.now()/1e3)){const n=qc.get(e);return void 0===n?(jc(t),{ok:!1,reason:"not_found"}):n.expiresAt<=t?(qc.delete(e),jc(t),{ok:!1,reason:"expired"}):n.consumed?{ok:!1,reason:"consumed"}:(qc.set(e,{...n,consumed:!0}),{ok:!0,record:Jc(n)})}function zc(e,t=Math.floor(Date.now()/1e3)){const n=qc.get(e);return void 0===n?(jc(t),{ok:!1,reason:"not_found"}):n.expiresAt<=t?(qc.delete(e),jc(t),{ok:!1,reason:"expired"}):n.consumed?{ok:!1,reason:"consumed"}:{ok:!0,record:Jc(n)}}function Jc(e){return{preparedReplyId:e.preparedReplyId,signedEnvelope:e.signedEnvelope,suggestedReply:e.suggestedReply,stage:e.stage,confidence:e.confidence,expiresAt:e.expiresAt,...void 0!==e.requestId?{requestId:e.requestId}:{}}}function Vc(e){return`(() => {\n const input = ${JSON.stringify(e)};\n const rootId = "roll-agent-reply-preview-root";\n const statusId = "roll-agent-reply-preview-status";\n const draftId = "roll-agent-reply-preview-draft";\n const badgeId = "roll-agent-reply-preview-badge";\n const spinnerId = "roll-agent-reply-preview-spinner";\n const styleId = "roll-agent-reply-preview-style";\n\n if (input.mode === "clear") {\n const existingRoot = document.getElementById(rootId);\n if (!existingRoot) return true;\n\n existingRoot.style.opacity = "0";\n existingRoot.style.transform = "translateY(8px) scale(0.98)";\n window.setTimeout(() => existingRoot.remove(), 240);\n return true;\n }\n\n const ensureRoot = () => {\n let root = document.getElementById(rootId);\n if (root) return root;\n\n if (!document.getElementById(styleId)) {\n const style = document.createElement("style");\n style.id = styleId;\n style.textContent = "@keyframes rollAgentReplyPreviewSpin { to { transform: rotate(360deg); } }";\n document.head.append(style);\n }\n\n root = document.createElement("div");\n root.id = rootId;\n root.style.position = "fixed";\n root.style.right = "20px";\n root.style.bottom = "20px";\n root.style.width = "min(420px, calc(100vw - 40px))";\n root.style.maxHeight = "42vh";\n root.style.zIndex = "2147483646";\n root.style.pointerEvents = "none";\n root.style.display = "flex";\n root.style.flexDirection = "column";\n root.style.gap = "10px";\n root.style.padding = "14px";\n root.style.borderRadius = "16px";\n root.style.border = "1px solid rgba(45, 212, 191, 0.32)";\n root.style.background = "rgba(15, 23, 42, 0.88)";\n root.style.color = "#F8FAFC";\n root.style.boxShadow = "0 22px 58px rgba(15, 23, 42, 0.34)";\n root.style.backdropFilter = "blur(14px)";\n root.style.fontFamily =\n "-apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif";\n root.style.opacity = "0";\n root.style.transform = "translateY(8px)";\n root.style.transition = "opacity 180ms ease, transform 220ms ease";\n\n const header = document.createElement("div");\n header.style.display = "flex";\n header.style.alignItems = "center";\n header.style.gap = "8px";\n header.style.minWidth = "0";\n\n const spinner = document.createElement("div");\n spinner.id = spinnerId;\n spinner.setAttribute("aria-hidden", "true");\n spinner.style.width = "14px";\n spinner.style.height = "14px";\n spinner.style.flex = "0 0 auto";\n spinner.style.borderRadius = "999px";\n spinner.style.border = "2px solid rgba(153, 246, 228, 0.24)";\n spinner.style.borderTopColor = "#99F6E4";\n spinner.style.animation = "rollAgentReplyPreviewSpin 820ms linear infinite";\n spinner.style.transition =\n "border-color 160ms ease, background 160ms ease, box-shadow 160ms ease, transform 160ms ease";\n\n const status = document.createElement("div");\n status.id = statusId;\n status.style.minWidth = "0";\n status.style.fontSize = "13px";\n status.style.fontWeight = "700";\n status.style.lineHeight = "18px";\n status.style.overflow = "hidden";\n status.style.textOverflow = "ellipsis";\n status.style.whiteSpace = "nowrap";\n\n const badge = document.createElement("div");\n badge.id = badgeId;\n badge.style.alignSelf = "flex-start";\n badge.style.fontSize = "11px";\n badge.style.lineHeight = "16px";\n badge.style.padding = "3px 8px";\n badge.style.borderRadius = "999px";\n badge.style.background = "rgba(20, 184, 166, 0.18)";\n badge.style.color = "#99F6E4";\n badge.textContent = "临时草稿";\n\n const draft = document.createElement("div");\n draft.id = draftId;\n draft.style.maxHeight = "30vh";\n draft.style.overflow = "hidden auto";\n draft.style.whiteSpace = "pre-wrap";\n draft.style.fontSize = "14px";\n draft.style.lineHeight = "21px";\n draft.style.color = "#E2E8F0";\n\n header.append(spinner, status);\n root.append(header, badge, draft);\n document.documentElement.append(root);\n return root;\n };\n\n const root = ensureRoot();\n const status = document.getElementById(statusId);\n const draft = document.getElementById(draftId);\n const badge = document.getElementById(badgeId);\n const spinner = document.getElementById(spinnerId);\n if (!status || !draft || !badge || !spinner) return false;\n\n root.style.opacity = "1";\n root.style.transform = "translateY(0)";\n\n if (typeof input.label === "string") {\n status.textContent = input.label;\n }\n\n if (typeof input.draftText === "string") {\n draft.textContent = input.draftText;\n }\n\n if (input.mode === "final" || input.mode === "complete") {\n spinner.style.animation = "none";\n spinner.style.borderColor = "rgba(34, 197, 94, 0.24)";\n spinner.style.borderTopColor = "rgba(34, 197, 94, 0.24)";\n spinner.style.background = "#22C55E";\n spinner.style.boxShadow = "0 0 0 3px rgba(34, 197, 94, 0.14)";\n badge.textContent = "最终回复";\n badge.style.background = "rgba(34, 197, 94, 0.16)";\n badge.style.color = "#BBF7D0";\n root.style.borderColor = "rgba(74, 222, 128, 0.34)";\n } else if (input.mode === "fail") {\n spinner.style.animation = "none";\n spinner.style.borderColor = "rgba(245, 158, 11, 0.28)";\n spinner.style.borderTopColor = "rgba(245, 158, 11, 0.28)";\n spinner.style.background = "#F59E0B";\n spinner.style.boxShadow = "0 0 0 3px rgba(245, 158, 11, 0.14)";\n badge.textContent = "生成失败";\n badge.style.background = "rgba(245, 158, 11, 0.18)";\n badge.style.color = "#FDE68A";\n root.style.borderColor = "rgba(251, 191, 36, 0.4)";\n } else {\n spinner.style.width = "14px";\n spinner.style.height = "14px";\n spinner.style.animation = "rollAgentReplyPreviewSpin 820ms linear infinite";\n spinner.style.border = "2px solid rgba(153, 246, 228, 0.24)";\n spinner.style.borderTopColor = "#99F6E4";\n spinner.style.background = "transparent";\n spinner.style.boxShadow = "none";\n badge.textContent = input.provisional === false ? "最终回复" : "临时草稿";\n badge.style.background = "rgba(20, 184, 166, 0.18)";\n badge.style.color = "#99F6E4";\n root.style.borderColor = "rgba(45, 212, 191, 0.32)";\n }\n\n return true;\n })()`}var Hc,Uc=class{target;constructor(e){this.target=e}async begin(e){return await this.render({mode:"begin",label:e,draftText:"",provisional:!0})}async updateStatus(e){return await this.render({mode:"status",label:e})}async updateDraft(e,t){return await this.render({mode:t?"draft":"final",draftText:e,provisional:t})}async complete(e,t){return await this.render({mode:"complete",label:e,draftText:t,provisional:!1})}async fail(e){return await this.render({mode:"fail",label:e})}async clear(){return await this.render({mode:"clear"})}async render(e){if(!Xe())return!1;try{return await this.target.evaluateJson(Vc(e))}catch{return!1}}},Wc=$c.object({conversationId:$c.string().optional().describe("会话 ID。若已从 `zhipin_read_messages` 获取,优先传这个,最稳定"),candidateName:$c.string().optional().describe("候选人姓名。若用户说“给鲁倩生成回复”,这里应提取为“鲁倩”"),index:$c.number().optional().describe("候选人在列表中的索引(可选,仅兜底)"),maxMessages:$c.number().default(100).describe("最多读取的聊天消息条数"),reasoning:_c.optional().describe("可选 reasoning/thinking 控制。enabled=true 会请求 Reply Authority 使用模型推理模式;effort 可选 low/medium/high;scope 可选 reply/all")}),Kc=$c.object({success:$c.boolean(),preparedReplyId:$c.string().optional(),suggestedReply:$c.string().optional(),stage:$c.string().optional(),confidence:$c.number().optional(),expiresAt:$c.number().optional(),requestId:$c.string().optional(),error:$c.string().optional()}),Yc={tenant_context:"加载租户上下文",binding_check:"校验招聘账号绑定",turn_planning:"分析候选人意图",context_building:"准备业务上下文",qualification_check:"检查候选人资格",reply_generation:"生成回复草稿",fact_gate:"检查事实安全",reply_gate:"检查回复策略",signing:"签发安全信封"};function Gc(){return{openNativePagePort:ps,createNativeVisualActivitySession:e=>new Xr(e),createReplyPreviewVisualSession:e=>new Uc(e),streamGenerateSignedReply:Oc,savePreparedReply:Fc,...Hc}}function Xc(e,t){const n=e.trim().toLocaleLowerCase("zh-CN"),r=t.trim().toLocaleLowerCase("zh-CN");return n.length>0&&r.length>0&&(n===r||n.includes(r)||r.includes(n))}function Zc(e,t){const n=e[t];return"string"==typeof n&&n.trim().length>0?n:void 0}function Qc(e){return e.filter(e=>"candidate"===e.sender||"recruiter"===e.sender).map(e=>`${"candidate"===e.sender?"求职者":"我"}: ${e.content}`)}function el(e){const t=[...e].reverse().find(e=>"candidate"===e.sender&&e.content.trim().length>0);return t?.content.trim()??""}function tl(e){const t=xc({communicationPosition:e.data.candidateInfo.communicationPosition,expectedJobText:e.data.candidateInfo.expectedJobText});return{candidateMessage:el(e.data.messages),conversationHistory:Qc(e.data.messages),candidateInfo:{name:e.data.candidateInfo.name,age:e.data.candidateInfo.age,experience:e.data.candidateInfo.experience,education:e.data.candidateInfo.education,communicationPosition:t.communicationPosition,expectedPosition:t.expectedPosition,expectedLocation:t.expectedLocation,expectedSalary:e.data.candidateInfo.expectedSalary,info:[...e.data.candidateInfo.tags]},...void 0!==t.preferredBrand?{preferredBrand:t.preferredBrand}:{},...void 0!==e.reasoning?{modelConfig:{reasoning:e.reasoning}}:{},target:{platform:"zhipin",conversationId:e.conversationId,candidateId:e.candidateId,recruiterUsername:e.recruiterUsername}}}function nl(e){return"phase.started"===e.type?Zc(e,"label")??Yc[Zc(e,"phase")??""]??"正在处理回复生成阶段":"tool.started"===e.type?"正在执行工具"+(Zc(e,"toolName")?`: ${Zc(e,"toolName")}`:""):"tool.completed"===e.type?"工具执行完成"+(Zc(e,"toolName")?`: ${Zc(e,"toolName")}`:""):"draft.started"===e.type?"正在生成回复草稿":"reasoning.started"===e.type?"正在推理回复策略":"reasoning.completed"===e.type?"回复策略推理完成":void 0}function rl(e){return{success:!1,error:e}}function al(e){return{success:!0,preparedReplyId:e.preparedReplyId,suggestedReply:e.suggestedReply,stage:e.stage,confidence:e.confidence,expiresAt:e.expiresAt,...void 0!==e.requestId?{requestId:e.requestId}:{}}}var ol=Pc({name:"zhipin_generate_reply_preview",description:"读取当前或指定 BOSS 聊天,流式生成智能回复并在浏览器中展示阶段和临时草稿;返回 preparedReplyId 供发送。",input:Wc,output:Kc,execute:async(e,t)=>{const n=Gc(),r=e.maxMessages??100,a=void 0!==e.conversationId||void 0!==e.candidateName||void 0!==e.index;let o,i,s;try{o=await n.openNativePagePort(),i=n.createNativeVisualActivitySession(o),s=n.createReplyPreviewVisualSession(o),await wn(o),await i.begin(a?"正在打开目标聊天":"正在准备当前聊天");const c=a?await o.openChat({conversationId:e.conversationId,candidateName:e.candidateName,index:e.index,maxScrolls:4}):void 0;if(void 0!==c&&!c.found){const e=c.error??"打开聊天失败";return await i.fail(e),rl(e)}if(void 0===c&&!await o.isChatSurfaceOpen().catch(()=>!1)){const e="当前页面不是 BOSS 沟通页,无法生成回复";return await i.fail("当前不是沟通页"),rl(e)}await i.begin("正在读取聊天上下文"),await i.highlightSelector(".chat-conversation, .conversation-box, .conversation-message",{label:"正在读取聊天上下文",padding:12});const l=c?.name??e.candidateName??"",d=await o.readActiveChatPanel();if(l.length>0&&(!d||!Xc(l,d.candidateName))){const e=`右侧聊天面板未切换到 ${l}`;return await i.fail("聊天面板未同步"),rl(e)}const u=await o.readSelectedChatTarget();if(!u){const e="未能提取当前选中聊天的 conversationId/candidateId";return await i.fail("未识别当前会话"),rl(e)}if(null!==d&&u.candidateName.length>0&&!Xc(u.candidateName,d.candidateName)){const e=`左侧选中会话与右侧聊天面板不一致: ${u.candidateName} / ${d.candidateName}`;return await i.fail("当前会话不一致"),rl(e)}if(!(void 0===c||c.conversationId.length>0&&u.conversationId===c.conversationId||0===c.conversationId.length&&c.candidateId.length>0&&u.candidateId===c.candidateId)){const e=`当前选中会话与目标会话不一致: ${c?.name||c?.conversationId||""}`;return await i.fail("当前会话不一致"),rl(e)}await o.waitForChatMessages();const m=await o.readCandidateChatDetails(r);if(null!==m.selectedTarget&&(m.selectedTarget.conversationId!==u.conversationId||m.selectedTarget.candidateId!==u.candidateId)){const e=`聊天详情目标与当前选中会话不一致: ${m.selectedTarget.conversationId}/${m.selectedTarget.candidateId}`;return await i.fail("聊天详情目标不一致"),rl(e)}const p=fi(await o.readUsernameEvidence());if(!p.found){const e="未找到用户名,请确认当前页面已登录招聘者账号。";return await i.fail("未找到用户名"),rl(e)}const g=tl({data:m,conversationId:u.conversationId,candidateId:u.candidateId,recruiterUsername:p.username,reasoning:e.reasoning});if(0===g.candidateMessage.length){const e="未找到候选人最新消息,无法生成回复";return await i.fail("候选人消息为空"),rl(e)}t.logger.info(`Generating reply preview for ${u.candidateName||u.candidateId}`),await i.begin("正在生成回复"),await s.begin("正在生成回复");let f,h,b="";for await(const e of n.streamGenerateSignedReply(g)){"stream.started"===e.type&&(f=Zc(e,"requestId"));const t=nl(e);if(void 0!==t&&(await i.begin(t),await s.updateStatus(t)),"draft.started"===e.type&&(b="",await s.updateDraft(b,!0)),"draft.delta"===e.type){b+=Zc(e,"delta")??"",await s.updateDraft(b,!0)}if("final"===e.type){const t=Bc.parse(e),r=Tc.parse(t);h=n.savePreparedReply({signedEnvelope:r.signedEnvelope,suggestedReply:r.suggestedReply,stage:r.stage,confidence:r.confidence,expiresAt:r.envelopeExp,...void 0!==f?{requestId:f}:{}}),await s.complete("回复已生成",r.suggestedReply)}}if(void 0===h){const e="Reply Authority stream 未返回 final";return await s.fail(e),await i.fail(e),rl(e)}return await i.succeed("回复已生成"),al(h)}catch(e){const t=e instanceof Error?e.message:String(e);return await(s?.fail(t)),await(i?.fail(t)),rl(t)}finally{o?.close()}}});import{createHash as il}from"node:crypto";import{defineTool as sl}from"@roll-agent/sdk";import{BrowserActionApprovalSchema as cl}from"@roll-agent/browser";import{z as ll}from"zod";import{defineTool as dl}from"@roll-agent/sdk";import{z as ul}from"zod";function ml(e,t){return void 0!==t.accountId?e.accountId===t.accountId:e.username===t.username}import{z as pl}from"zod";var gl="reply-authority-service",fl="browser-use-agent/zhipin_send_reply",hl="zhipin",bl=60,yl=pl.object({platform:pl.literal(hl),username:pl.string().min(1),accountId:pl.string().min(1).optional()}),vl=pl.object({v:pl.literal(2),iss:pl.literal(gl),kid:pl.string().min(1),jti:pl.string().min(1),iat:pl.number().int(),exp:pl.number().int(),aud:pl.literal(fl),platform:pl.literal(hl),tenantId:pl.string().min(1),conversationId:pl.string().min(1),candidateId:pl.string().min(1),reply:pl.string(),policyVersion:pl.string().min(1),recruiterBinding:yl}),wl=pl.object({kid:pl.string().min(1),algorithm:pl.literal("Ed25519"),publicKey:pl.string().min(1),validFrom:pl.string().min(1),validUntil:pl.string().optional()}),xl=pl.object({keys:pl.array(wl)}),Sl=new Map;function Il(e){for(const[t,n]of Sl)n<e-bl&&Sl.delete(t)}function Cl(e,t=Math.floor(Date.now()/1e3)){return Il(t),Sl.has(e)}function Rl(e,t,n=Math.floor(Date.now()/1e3)){Il(n),Sl.set(e,t)}import{createPublicKey as kl,verify as Al}from"node:crypto";var Nl=new Map,Ml=null;function El(){const e=process.env.REPLY_AUTHORITY_KEYS_URL?.trim();if(!e)throw new Error("REPLY_AUTHORITY_KEYS_URL 未配置,browser-use-agent 无法拉取 Reply Authority 公钥。");return e}function Pl(e){return Nl=new Map(e.map(e=>[e.kid,e]))}async function Tl(){if(Ml)return Ml;Ml=(async()=>{const e=await fetch(El()),t=await e.json();if(!e.ok)throw new Error(`Reply Authority 公钥拉取失败 (${e.status})`);return Pl(xl.parse(t).keys)})();try{return await Ml}finally{Ml=null}}async function _l(){await Tl()}async function Bl(e){const t=Nl.get(e);if(t)return t;const n=(await Tl()).get(e);if(!n)throw new Error(`Unknown key ID: ${e}`);return n}function Ol(e){if("object"==typeof e&&null!==e&&"v"in e&&"number"==typeof e.v&&2!==e.v)throw new Error("unexpected envelope version")}function $l(e){const t=e.split("."),n=t[0],r=t[1];if(2!==t.length||void 0===n||void 0===r||0===n.length||0===r.length)throw new Error("Invalid signed envelope format");let a,o="";try{o=Buffer.from(n,"base64url").toString("utf-8")}catch{throw new Error("Invalid signed envelope format")}try{a=JSON.parse(o)}catch{throw new Error("Envelope payload schema validation failed")}Ol(a);const i=vl.safeParse(a);if(!i.success)throw new Error("Envelope payload schema validation failed");return{payload:i.data,payloadJson:o,signatureBase64:r}}function Dl(e,t){if(e.exp<=e.iat)throw new Error("Envelope expiry must be after issue time");if(e.exp<t-bl)throw new Error("Envelope expired");if(e.iat>t+bl)throw new Error("Envelope issued in the future")}async function ql(e,t=Math.floor(Date.now()/1e3)){const n=$l(e),r=await Bl(n.payload.kid),a=kl({key:Buffer.from(r.publicKey,"base64url"),format:"der",type:"spki"});if(!Al(null,Buffer.from(n.payloadJson,"utf-8"),a,Buffer.from(n.signatureBase64,"base64url")))throw new Error("Signature verification failed");return Dl(n.payload,t),n.payload}var jl,Fl=ul.object({success:ul.boolean(),sentMessage:ul.string(),error:ul.string().optional()});function Ll(){return{getReplyAuthorityKeysLoaded:pe,openNativePagePort:ps,createNativeVisualActivitySession:e=>new Xr(e),...jl}}function zl(e,t){const n=e.trim().toLocaleLowerCase("zh-CN"),r=t.trim().toLocaleLowerCase("zh-CN");return n.length>0&&r.length>0&&(n===r||n.includes(r)||r.includes(n))}function Jl(e){return"function"==typeof e.readCandidateChatDetails}async function Vl(e){if(Jl(e))return await e.readCandidateChatDetails(50).catch(()=>{})}function Hl(e,t){return null!==e&&e.conversationId===t.conversationId&&e.candidateId===t.candidateId}function Ul(e,t){return null===t||0===e.candidateName.length||zl(e.candidateName,t.candidateName)}async function Wl(e,t){const n=Ll();let r,a,o="";if(!n.getReplyAuthorityKeysLoaded()){const e="Reply Authority 公钥尚未成功预加载,当前无法发送签名回复。请检查启动日志、`REPLY_AUTHORITY_KEYS_URL` 配置,以及 `browser_status.replyAuthorityKeysLoaded`。";return t.logger.error(e),{success:!1,sentMessage:o,error:e}}try{const i=await ql(e.signedEnvelope);if(o=i.reply,Cl(i.jti))return{success:!1,sentMessage:o,error:"token 已消费,禁止重放"};r=await n.openNativePagePort(),a=n.createNativeVisualActivitySession(r),await wn(r),await new Uc(r).clear(),await a.begin("正在发送回复");let s=await r.readActiveChatPanel().catch(()=>null),c=await r.readSelectedChatTarget().catch(()=>null),l=0;if(!Hl(c,i)||!Ul(c,s)){const t=await r.openChat({conversationId:i.conversationId,candidateName:e.candidateName,index:e.index});if(!t.found)return await a.fail(t.error??"未找到目标聊天"),{success:!1,sentMessage:o,error:t.error??"未找到目标聊天"};l=t.unreadCount,s=await r.readActiveChatPanel(),c=await r.readSelectedChatTarget()}if(null===c)return await a.fail("未能提取当前聊天的 conversationId/candidateId"),{success:!1,sentMessage:o,error:"未能提取当前聊天的 conversationId/candidateId"};if(null!==s&&c.candidateName.length>0&&!zl(c.candidateName,s.candidateName)){const e=`左侧选中会话与右侧聊天面板不一致: ${c.candidateName} / ${s.candidateName}`;return await a.fail(e),{success:!1,sentMessage:o,error:e}}if(c.conversationId!==i.conversationId||c.candidateId!==i.candidateId)return await a.fail("发送目标与签名不匹配"),{success:!1,sentMessage:o,error:"发送目标与签名不匹配"};const d=fi(await r.readUsernameEvidence());if(!d.found)return await a.fail("未找到用户名"),{success:!1,sentMessage:o,error:"未找到用户名,请确认当前页面已登录招聘者账号。"};const u={platform:"zhipin",username:d.username,strategy:d.strategy,source:d.source};if(!ml(u,i.recruiterBinding)){const e=`recruiter 绑定不匹配:当前账号 ${u.username} 与签发时 ${i.recruiterBinding.username} 不一致`;return await a.fail(e),{success:!1,sentMessage:o,error:e}}t.logger.info(`Sending native message (${o.length} chars) to ${c.candidateName||c.candidateId}`);const m=await r.sendChatReply(o,{...void 0!==a?{motionObserver:a}:{}});if(!m.success)return await a.fail(m.error??"发送失败"),{success:!1,sentMessage:o,error:m.error??"发送失败"};const p=await Vl(r);return Js({conversationId:c.conversationId,candidateId:c.candidateId,replyId:i.jti,candidateName:c.candidateName,message:o,unreadCountBeforeReply:l,...void 0!==p?{candidateDetails:p}:{}},t.logger),Rl(i.jti,i.exp),await a.succeed("已发送回复"),{success:!0,sentMessage:o}}catch(e){const t=e instanceof Error?e.message:String(e);return await(a?.fail(t)),{success:!1,sentMessage:o,error:t}}finally{r?.close()}}var Kl,Yl=dl({name:"zhipin_send_reply",description:"发送消息。只接受由 Reply Authority Service 签发的 signedEnvelope;可指定 candidateName 自动打开对应聊天后发送,或不传则发送到当前选中的聊天窗口。",input:ul.object({signedEnvelope:ul.string().describe("Reply Authority Service 返回的紧凑签名信封"),candidateName:ul.string().optional().describe("候选人姓名。若用户说“回复鲁倩”,这里应提取为“鲁倩”"),index:ul.number().optional().describe("候选人在列表中的索引(可选)")}),output:Fl,execute:async(e,t)=>await Wl(e,t)}),Gl="zhipin_send_prepared_reply",Xl=80,Zl=ll.object({success:ll.boolean(),sentMessage:ll.string(),error:ll.string().optional()}),Ql=ll.object({preparedReplyId:ll.string().min(1).describe("预备回复 ID,由 zhipin_generate_reply_preview 返回"),toolActionApproval:nt.optional().describe("当 browser-use tool policy 返回 needs_confirmation 后,由 orchestrator 原样带回的批准 ID。"),browserActionApproval:cl.optional().describe("当 BROWSER_SECURITY_JSON.actionPolicy=confirm 返回 needs_confirmation 后,由 orchestrator 原样带回的批准 ID。")});function ed(){return{sendSignedZhipinReply:Wl,...Kl}}function td(e){return"expired"===e?"preparedReplyId 已过期,请重新生成回复":"consumed"===e?"preparedReplyId 已消费,禁止重复发送":"preparedReplyId 不存在,请重新生成回复"}function nd(e){return`sha256:${il("sha256").update(JSON.stringify([e.preparedReplyId,e.signedEnvelope,e.suggestedReply,e.expiresAt])).digest("hex")}`}function rd(e){const t=e.suggestedReply.replace(/\s+/g," ").trim(),n=t.length>Xl?`${t.slice(0,Xl-1)}…`:t;return n.length>0?`发送预备回复: ${n}`:"发送预备回复"}var ad=sl({name:Gl,description:"发送由 zhipin_generate_reply_preview 生成的预备回复;只接收 preparedReplyId,不接收 signedEnvelope。",input:Ql,output:Zl,execute:async(e,t)=>{const n=ed(),r=zc(e.preparedReplyId);if(!r.ok)return{success:!1,sentMessage:"",error:td(r.reason)};const a=Ct(t,{subject:{tool:Gl,target:r.record.preparedReplyId,summary:rd(r.record),digest:nd(r.record)},...void 0!==e.toolActionApproval?{approval:e.toolActionApproval}:{},deferApprovalConsumption:!0});hn(t,de(),{action:Gl,target:r.record.preparedReplyId,...void 0!==e.browserActionApproval?{approval:e.browserActionApproval}:{}}),a.consumeApproval();const o=Lc(e.preparedReplyId);return o.ok?await n.sendSignedZhipinReply({signedEnvelope:o.record.signedEnvelope},t):{success:!1,sentMessage:"",error:td(o.reason)}}});import{defineTool as od}from"@roll-agent/sdk";import{z as id}from"zod";var sd,cd=id.object({success:id.boolean(),exchanged:id.boolean(),wechatNumber:id.string().optional(),error:id.string().optional()}),ld=900,dd=160,ud=1100;function md(){return{openNativePagePort:ps,createNativeVisualActivitySession:e=>new Xr(e),...sd}}function pd(e,t){const n=e.trim().toLocaleLowerCase("zh-CN"),r=t.trim().toLocaleLowerCase("zh-CN");return n.length>0&&r.length>0&&(n===r||n.includes(r)||r.includes(n))}function gd(e){return"function"==typeof e.readCandidateChatDetails}async function fd(e){if(gd(e))return await e.readCandidateChatDetails(50).catch(()=>{})}var hd=od({name:"zhipin_exchange_wechat",description:'换微信。可指定 candidateName 自动打开对应聊天后执行,或不传则在当前窗口执行;例如"和鲁倩换微信"应提取 candidateName=鲁倩。',input:id.object({conversationId:id.string().optional().describe("会话 ID。若已从消息列表拿到,优先传这个"),candidateName:id.string().optional().describe('候选人姓名。若用户说"和鲁倩换微信",这里应提取为"鲁倩"'),index:id.number().optional().describe("候选人在列表中的索引(可选)")}),output:cd,execute:async(e,t)=>{const n=md();let r,a;try{if(r=await n.openNativePagePort(),a=n.createNativeVisualActivitySession(r),await wn(r),await a.begin("正在换微信"),void 0!==e.conversationId||void 0!==e.candidateName||void 0!==e.index){const t=await r.openChat({conversationId:e.conversationId,candidateName:e.candidateName,index:e.index,...void 0!==a?{motionObserver:a}:{}});if(!t.found)return await a.fail(t.error??"未找到目标聊天"),{success:!1,exchanged:!1,error:t.error??"未找到目标聊天"}}else if(!await r.isChatSurfaceOpen())return await a.fail("消息列表未加载"),{success:!1,exchanged:!1,error:"消息列表未加载"};const o=await r.readSelectedChatTarget();if(null===o)return await a.fail("未选中聊天联系人"),{success:!1,exchanged:!1,error:"未选中聊天联系人,无法点击当前聊天输入区的「换微信」按钮"};const i=await r.readActiveChatPanel();if(null!==i&&o.candidateName.length>0&&!pd(o.candidateName,i.candidateName)){const e=`左侧选中会话与右侧聊天面板不一致: ${o.candidateName} / ${i.candidateName}`;return await a.fail(e),{success:!1,exchanged:!1,error:e}}t.logger.info(`Starting native WeChat exchange with ${o.candidateName}`);const s=await fd(r),c=await r.exchangeWechat({preClickDelayMs:ld,pressDurationMs:dd,settleMs:ud,...void 0!==a?{motionObserver:a}:{}});return c.success?(c.exchanged&&Hs({conversationId:o.conversationId,candidateId:o.candidateId,candidateName:o.candidateName,...void 0!==c.wechatNumber?{wechatNumber:c.wechatNumber}:{},...void 0!==s?{candidateDetails:s}:{}},t.logger),await a.succeed("已完成换微信"),c):(await a.fail(c.error??"换微信失败"),c)}catch(e){const t=e instanceof Error?e.message:String(e);return await(a?.fail(t)),{success:!1,exchanged:!1,error:t}}finally{r?.close()}}});import{defineTool as bd}from"@roll-agent/sdk";import{z as yd}from"zod";var vd,wd=yd.object({success:yd.boolean(),username:yd.string(),usedSelector:yd.string().optional(),usedStrategy:yd.string().optional(),source:yd.string().optional(),error:yd.string().optional()});function xd(){return{openNativePagePort:ps,pickBestUsername:fi,createNativeVisualActivitySession:e=>new Xr(e),...vd}}var Sd=bd({name:"zhipin_get_username",description:"获取当前登录的招聘者用户名",input:yd.object({}),output:wd,execute:async(e,t)=>{t.logger.info("Getting zhipin username");const n=xd();let r,a;try{r=await n.openNativePagePort(),a=n.createNativeVisualActivitySession(r),await a.begin("正在识别登录账号"),await a.highlightSelector('header, #header, [role="banner"], [role="navigation"]',{label:"正在识别登录账号",padding:10});const e=n.pickBestUsername(await r.readUsernameEvidence());if(!e.found)throw new Error("未找到用户名,请确认当前页面已登录招聘者账号。");return await a.succeed(`已识别账号:${e.username}`),t.logger.info(`Username: ${e.username} (strategy: ${e.strategy}, source: ${e.source})`),{success:!0,username:e.username,usedSelector:"css-fallback"===e.strategy?e.source:void 0,usedStrategy:e.strategy,source:e.source}}catch(e){return await(a?.fail("获取用户名失败")),{success:!1,username:"",error:e instanceof Error?`获取用户名失败:${e.message}`:"获取用户名失败"}}finally{r?.close()}}});import{defineTool as Id}from"@roll-agent/sdk";import{z as Cd}from"zod";var Rd,kd=["unknown","top","middle","bottom","only-page"],Ad=Cd.object({containerFound:Cd.boolean(),containerLabel:Cd.string(),scrollTop:Cd.number(),scrollHeight:Cd.number(),clientHeight:Cd.number(),itemCount:Cd.number(),atStart:Cd.boolean(),atEnd:Cd.boolean()}),Nd=Cd.object({success:Cd.boolean(),surface:Cd.enum(si),direction:Cd.enum(["up","down"]),stepsRequested:Cd.number(),stepsCompleted:Cd.number(),reachedBoundary:Cd.boolean(),atTop:Cd.boolean(),atBottom:Cd.boolean(),canScrollUp:Cd.boolean(),canScrollDown:Cd.boolean(),position:Cd.enum(kd),before:Ad,after:Ad,error:Cd.string().optional()});function Md(){return{openNativePagePort:ps,createNativeVisualActivitySession:e=>new Xr(e),...Rd}}function Ed(){return{containerFound:!1,containerLabel:"",scrollTop:0,scrollHeight:0,clientHeight:0,itemCount:0,atStart:!0,atEnd:!0}}function Pd(e){return e.containerFound?e.atStart&&e.atEnd?"only-page":e.atStart?"top":e.atEnd?"bottom":"middle":"unknown"}function Td(e){return{atTop:e.containerFound&&e.atStart,atBottom:e.containerFound&&e.atEnd,canScrollUp:e.containerFound&&!e.atStart,canScrollDown:e.containerFound&&!e.atEnd,position:Pd(e)}}var _d=Id({name:"zhipin_scroll_view",description:"滚动或检查 BOSS直聘页面内部动态列表容器。用于调试或显式翻页,支持 chat-list、chat-history、recommend-list;steps=0 时只返回当前位置和顶部/底部边界。",input:Cd.object({surface:Cd.enum(si).describe("要滚动的页面区域"),direction:Cd.enum(["up","down"]).optional().describe("滚动方向;不传则使用该区域默认方向"),steps:Cd.number().int().min(0).max(20).default(1).describe("滚动步数;传 0 时不滚动,只检查当前列表是否在顶部/底部"),distance:Cd.number().int().positive().optional().describe("每步滚动像素;不传则按容器高度估算"),settleMs:Cd.number().int().min(0).max(5e3).default(700).describe("每步后等待 DOM 更新的毫秒数")}),output:Nd,execute:async(e,t)=>{const n=Md(),r=li(e.surface),a=e.direction??r.defaultDirection,o=e.steps??1,i=e.settleMs??700;let s,c;try{s=await n.openNativePagePort({requireChatPage:"chat-list"===e.surface||"chat-history"===e.surface}),c=n.createNativeVisualActivitySession(s);const l=`正在滚动 ${e.surface}`;await c.begin(l),await c.highlightSelector(r.highlightSelector,{label:l,padding:8});const d=await s.scrollSurface(e.surface,{direction:a,steps:o,settleMs:i,...void 0!==e.distance?{distance:e.distance}:{}});return d.success?(await c.succeed(`已滚动 ${d.stepsCompleted}/${d.stepsRequested} 步`),t.logger.info(`Scrolled ${e.surface}: ${d.stepsCompleted}/${d.stepsRequested}, items ${d.before.itemCount} -> ${d.after.itemCount}`),{success:d.success,surface:e.surface,direction:d.direction,stepsRequested:d.stepsRequested,stepsCompleted:d.stepsCompleted,reachedBoundary:d.reachedBoundary,...Td(d.after),before:d.before,after:d.after}):(await c.fail("列表未加载"),{success:!1,surface:e.surface,direction:a,stepsRequested:o,stepsCompleted:0,reachedBoundary:!0,...Td(d.after),before:d.before,after:d.after,error:"列表未加载"})}catch(t){await(c?.fail("滚动失败"));const n=Ed();return{success:!1,surface:e.surface,direction:a,stepsRequested:o,stepsCompleted:0,reachedBoundary:!0,...Td(n),before:n,after:n,error:t instanceof Error?t.message:"滚动失败"}}finally{s?.close()}}});import{defineTool as Bd}from"@roll-agent/sdk";import{z as Od}from"zod";var $d,Dd=["不限","男","女"],qd=["不限","刚刚活跃","今日活跃","3日内活跃","本周活跃","本月活跃"],jd=["applied","recommend_not_ready","filter_not_found","requires_vip","age_not_applied","submit_failed","error"],Fd=Od.object({ageMin:Od.number().int().min(16).optional(),ageMax:Od.number().int().min(16).optional(),gender:Od.enum(Dd),activity:Od.enum(qd)}),Ld=Od.object({ageMin:Od.number().optional(),ageMax:Od.number().optional(),gender:Od.string(),activity:Od.string()}),zd=Od.object({success:Od.boolean(),status:Od.enum(jd),requested:Fd,applied:Ld.optional(),filterButtonText:Od.string().optional(),error:Od.string().optional()}),Jd=Od.object({ageMin:Od.number().int().min(16).optional().describe("年龄下限;未传则重置为 16"),ageMax:Od.number().int().min(16).optional().describe("年龄上限;未传则重置为不限"),gender:Od.enum(Dd).default("不限").describe("性别筛选,只支持:不限、男、女"),activity:Od.enum(qd).default("不限").describe("活跃度[单选],只支持:不限、刚刚活跃、今日活跃、3日内活跃、本周活跃、本月活跃")}).refine(e=>void 0===e.ageMin||void 0===e.ageMax||e.ageMin<=e.ageMax,{path:["ageMax"],message:"ageMax must be greater than or equal to ageMin"}),Vd=350,Hd=130,Ud=600;function Wd(){return{openNativePagePort:ps,createNativeVisualActivitySession:e=>new Xr(e),...$d}}function Kd(e){const t=e.gender??"不限",n=e.activity??"不限";return{...void 0!==e.ageMin?{ageMin:e.ageMin}:{},...void 0!==e.ageMax?{ageMax:e.ageMax}:{},gender:t,activity:n}}function Yd(e){return{success:"applied"===e.status,status:e.status,requested:e.requested,...void 0!==e.applied?{applied:e.applied}:{},...void 0!==e.filterButtonText?{filterButtonText:e.filterButtonText}:{},...void 0!==e.error?{error:e.error}:{}}}var Gd=Bd({name:"zhipin_filter_recommend_candidates",description:"在 BOSS「推荐牛人」页打开筛选面板,只设置年龄、性别、活跃度[单选] 三个维度并提交。",input:Jd,output:zd,execute:async(e,t)=>{const n=Wd(),r=Kd(e);let a,o;t.logger.info(`Filtering Boss recommend candidates through native CDP: gender=${r.gender}, activity=${r.activity}, ageMin=${r.ageMin??"16"}, ageMax=${r.ageMax??"不限"}`);try{a=await n.openNativePagePort(),o=n.createNativeVisualActivitySession(a),await wn(a),await o.begin("正在打开推荐筛选");if(!await a.waitForRecommendList(3e3))return await o.fail("推荐牛人页未就绪"),Yd({status:"recommend_not_ready",requested:r,error:"推荐牛人页未就绪"});await o.begin("正在设置推荐筛选"),await o.highlightSelector(di.recommend.filterButton,{label:"正在设置推荐筛选",padding:8});const e=await a.applyRecommendFilter(r,{preClickDelayMs:Vd,pressDurationMs:Hd,settleMs:Ud,...void 0!==o?{motionObserver:o}:{}});return"applied"===e.status?await o.succeed("已应用推荐筛选"):await o.fail(e.error??e.status),Yd(e)}catch(e){const t=e instanceof Error?e.message:"推荐筛选失败";return await(o?.fail(t)),Yd({status:"error",requested:r,error:t})}finally{a?.close()}}});import{defineTool as Xd}from"@roll-agent/sdk";import{z as Zd}from"zod";var Qd=["target-count","boundary","no-new-items","max-steps"];import{AsyncLocalStorage as eu}from"node:async_hooks";var tu="@c",nu="@j",ru="legacy",au=/^@?c([1-9]\d*)$/i,ou=/^@?j([1-9]\d*)$/i,iu=new Map,su=new Map,cu=new eu;function lu(e){if(!Number.isInteger(e)||e<0)throw new Error("候选人索引必须是从 0 开始的非负整数");return`${tu}${String(e+1)}`}function du(e){if(!Number.isInteger(e)||e<0)throw new Error("岗位索引必须是从 0 开始的非负整数");return`${nu}${String(e+1)}`}function uu(e){const t=au.exec(e.trim()),n=t?.[1];if(!n)return;const r=Number(n);return Number.isInteger(r)?r-1:void 0}function mu(e){const t=ou.exec(e.trim()),n=t?.[1];if(!n)return;const r=Number(n);return Number.isInteger(r)?r-1:void 0}function pu(e){if(void 0!==e.index){if(!Number.isInteger(e.index)||e.index<0)throw new Error("index 必须是从 0 开始的非负整数");return e.index}if(void 0===e.candidateRef)throw new Error("必须提供 index 或 candidateRef");return hu(e.candidateRef).index}function gu(e){const t=e.map((e,t)=>({...e,candidateRef:lu(t)}));return iu.set(Su(),new Map(t.map(e=>[e.candidateRef,e]))),t}function fu(e){const t=e.map((e,t)=>({...e,jobRef:du(t)}));return su.set(Su(),new Map(t.map(e=>[e.jobRef,e]))),t}function hu(e){const t=uu(e);if(void 0===t)throw new Error(`candidateRef "${e}" 格式无效,应类似 @c1`);const n=lu(t);return iu.get(Su())?.get(n)??{index:t,candidateRef:n,candidateId:""}}function bu(e){const t=mu(e);if(void 0===t)throw new Error(`jobRef "${e}" 格式无效,应类似 @j1`);const n=du(t),r=su.get(Su())?.get(n);if(void 0===r)throw new Error(`岗位引用 ${n} 已过期,请先调用 zhipin_list_recommend_jobs`);return r}function yu(e){const t=[];for(const n of e.indices??[])t.push({index:pu({index:n}),candidateRef:lu(n),candidateId:""});for(const n of e.candidateRefs??[])t.push(hu(n));if(0===t.length)throw new Error("必须提供 indices 或 candidateRefs");return wu(t)}function vu(e,t){return!1!==t.found&&(e.candidateId.length>0&&t.candidateId.length>0?e.candidateId===t.candidateId:!(e.name&&t.name&&t.name.length>0)||xu(e.name)===xu(t.name))}function wu(e){const t=new Map;for(const n of e)t.has(n.candidateRef)||t.set(n.candidateRef,n);return[...t.values()]}function xu(e){return e.trim().toLocaleLowerCase("zh-CN")}function Su(){const e=cu.getStore();if(void 0!==e)return e;try{return ye().id}catch{return ru}}var Iu,Cu=Zd.object({index:Zd.number(),candidateRef:Zd.string(),candidateId:Zd.string(),name:Zd.string(),age:Zd.string(),experience:Zd.string(),education:Zd.string(),workStatus:Zd.string(),company:Zd.string(),currentPosition:Zd.string(),expectedLocation:Zd.string(),expectedPosition:Zd.string(),expectedSalary:Zd.string(),tags:Zd.array(Zd.string()),buttonText:Zd.string()}),Ru=Zd.object({containerLabel:Zd.string(),stepsRequested:Zd.number(),stepsCompleted:Zd.number(),reachedBoundary:Zd.boolean(),stopReason:Zd.enum(Qd),uniqueCount:Zd.number(),duplicateCount:Zd.number(),noNewRounds:Zd.number(),beforeItemCount:Zd.number(),afterItemCount:Zd.number(),beforeScrollHeight:Zd.number(),afterScrollHeight:Zd.number()}),ku=Zd.object({success:Zd.boolean(),candidates:Zd.array(Cu),total:Zd.number(),scrollStats:Ru.optional(),error:Zd.string().optional()});function Au(){return{openNativePagePort:ps,createNativeVisualActivitySession:e=>new Xr(e),...Iu}}var Nu=Xd({name:"zhipin_get_candidate_list",description:"获取推荐列表页的候选人卡片信息",input:Zd.object({maxResults:Zd.number().optional().describe("最多返回条数"),autoScroll:Zd.boolean().default(!0).describe("是否自动向下滚动动态列表并合并采集结果"),maxScrolls:Zd.number().int().min(0).max(50).default(4).describe("自动滚动的最大步数")}),output:ku,execute:async(e,t)=>{t.logger.info("Getting candidate list from recommend page through native backend");const n=Au();let r,a;try{r=await n.openNativePagePort(),a=n.createNativeVisualActivitySession(r),await a.begin("正在打开推荐列表");if(!await r.waitForRecommendList())return await a.fail("推荐列表未加载"),{success:!1,candidates:[],total:0,error:"推荐列表未加载"};const o="正在读取推荐列表";await a.begin(o),await a.highlightSelector(".candidate-card-wrap, li.card-item, [data-geek], .geek-item",{label:o,padding:8});const i=await r.readRecommendCandidates({autoScroll:e.autoScroll??!0,maxScrolls:e.maxScrolls??4,...void 0!==e.maxResults?{targetCount:e.maxResults}:{}}),s=void 0!==e.maxResults?i.items.slice(0,e.maxResults):[...i.items],c=gu(s),l=s.map((e,t)=>{const n=c[t];if(!n)throw new Error(`候选人引用生成失败:position ${String(t)}`);return{...e,candidateRef:n.candidateRef}}),d=!1===e.autoScroll?void 0:{containerLabel:i.after.containerLabel,stepsRequested:i.stepsRequested,stepsCompleted:i.stepsCompleted,reachedBoundary:i.reachedBoundary,stopReason:i.stopReason,uniqueCount:i.uniqueCount,duplicateCount:i.duplicateCount,noNewRounds:i.noNewRounds,beforeItemCount:i.before.itemCount,afterItemCount:i.after.itemCount,beforeScrollHeight:i.before.scrollHeight,afterScrollHeight:i.after.scrollHeight};return await a.succeed(`已读取 ${l.length} 位候选人`),t.logger.info(`Found ${l.length} candidates in recommend list`+(d?`, scroll stop: ${d.stopReason}`:"")),{success:!0,candidates:l,total:l.length,...void 0!==d?{scrollStats:d}:{}}}catch(e){return await(a?.fail("读取推荐列表失败")),{success:!1,candidates:[],total:0,error:e instanceof Error?e.message:"读取推荐列表失败"}}finally{r?.close()}}});import{defineTool as Mu}from"@roll-agent/sdk";import{z as Eu}from"zod";var Pu,Tu=["listed","recommend_not_ready","selector_not_found"],_u=Eu.object({index:Eu.number(),jobRef:Eu.string().optional(),value:Eu.string(),label:Eu.string(),isCurrent:Eu.boolean()}),Bu=Eu.object({success:Eu.boolean(),status:Eu.enum(Tu),current:_u.optional(),jobs:Eu.array(_u),availableCount:Eu.number(),canSwitch:Eu.boolean(),error:Eu.string().optional()}),Ou=450,$u=140,Du=750;function qu(){return{openNativePagePort:ps,createNativeVisualActivitySession:e=>new Xr(e),...Pu}}function ju(e,t){return{index:e.index,...void 0!==t?{jobRef:t}:{},value:e.value,label:e.label,isCurrent:e.isCurrent}}function Fu(e,t){return e.value.length>0&&t.value.length>0?e.value===t.value:e.index===t.index&&e.label===t.label}function Lu(e){const t=fu(e.options),n=e.options.map((e,n)=>ju(e,t[n]?.jobRef));let r;if(void 0!==e.current){const t=e.current;r=n.find(e=>Fu(e,t))??ju(t)}return{success:e.success,status:e.status,...void 0!==r?{current:r}:{},jobs:n,availableCount:e.availableCount,canSwitch:e.canSwitch,...void 0!==e.error?{error:e.error}:{}}}var zu=Mu({name:"zhipin_list_recommend_jobs",description:"读取 BOSS「推荐牛人」页顶部招聘岗位下拉选项,只读不切换;返回 jobRef/jobValue/current/canSwitch。",input:Eu.object({}),output:Bu,execute:async(e,t)=>{const n=qu();let r,a;t.logger.info("Listing Boss recommend jobs through native CDP");try{r=await n.openNativePagePort(),a=n.createNativeVisualActivitySession(r),await wn(r),await a.begin("正在读取推荐岗位"),await a.highlightSelector(".job-selecter-wrap",{label:"正在读取推荐岗位",padding:8});const e=await r.listRecommendJobs({preClickDelayMs:Ou,pressDurationMs:$u,settleMs:Du,...void 0!==a?{motionObserver:a}:{}});return e.success?await a.succeed(`已读取 ${e.availableCount} 个推荐岗位`):await a.fail(e.error??"读取推荐岗位失败"),Lu(e)}catch(e){const t=e instanceof Error?e.message:"读取推荐岗位失败";return await(a?.fail(t)),Lu({success:!1,status:"selector_not_found",options:[],availableCount:0,canSwitch:!1,error:t})}finally{r?.close()}}});import{BrowserPageInfoSchema as Ju}from"@roll-agent/browser";import{defineTool as Vu}from"@roll-agent/sdk";import{z as Hu}from"zod";var Uu,Wu=Hu.object({success:Hu.boolean(),alreadyOnRecommend:Hu.boolean(),usedSidebarClick:Hu.boolean(),recommendReady:Hu.boolean(),page:Ju.optional(),error:Hu.string().optional()});function Ku(){return{getContextManager:ue,openNativePagePort:ps,createNativeVisualActivitySession:e=>new Xr(e),...Uu}}async function Yu(e,t){return Wt(e,await t.inspectPage())}var Gu=Vu({name:"zhipin_open_recommend_page",description:"通过点击 Boss 左侧导航切换到「推荐牛人」页,避免让编排器依赖站内 URL 猜测。",input:Hu.object({}),output:Wu,execute:async(e,t)=>{const n=Ku(),r=n.getContextManager();let a,o;t.logger.info("Opening Boss recommend page via native sidebar navigation");try{a=await n.openNativePagePort(),o=n.createNativeVisualActivitySession(a),await wn(a);const e="正在切换到推荐牛人页";if(await o.begin(e),await o.highlightSelector(di.nav.sidebar,{label:e,padding:10}),await a.isRecommendSurfaceOpen())return await o.succeed("已在推荐牛人页"),{success:!0,alreadyOnRecommend:!0,usedSidebarClick:!1,recommendReady:!0,page:await Yu(r,a)};if(!await a.clickSidebarSection("recommend",{...void 0!==o?{motionObserver:o}:{}}))return await o.fail("未找到推荐牛人导航"),{success:!1,alreadyOnRecommend:!1,usedSidebarClick:!1,recommendReady:!1,page:await Yu(r,a),error:"未找到推荐牛人导航"};t.logger.info("Clicked Boss sidebar nav: 推荐牛人");return await a.waitForRecommendSurface()?(await o.succeed("已切换到推荐牛人页"),{success:!0,alreadyOnRecommend:!1,usedSidebarClick:!0,recommendReady:!0,page:await Yu(r,a)}):(await o.fail("推荐牛人页未就绪"),{success:!1,alreadyOnRecommend:!1,usedSidebarClick:!0,recommendReady:!1,page:await Yu(r,a),error:"推荐牛人页未就绪"})}catch(e){return await(o?.fail("切换推荐牛人页失败")),{success:!1,alreadyOnRecommend:!1,usedSidebarClick:!1,recommendReady:!1,error:e instanceof Error?e.message:"切换推荐牛人页失败"}}finally{a?.close()}}});import{defineTool as Xu}from"@roll-agent/sdk";import{z as Zu}from"zod";var Qu,em=["selected","already_selected","not_found","recommend_not_ready","selector_not_found"],tm=Zu.object({index:Zu.number(),value:Zu.string(),label:Zu.string(),isCurrent:Zu.boolean()}),nm=Zu.object({jobRef:Zu.string().optional(),jobValue:Zu.string().optional(),jobName:Zu.string().optional(),index:Zu.number().optional(),searchKeyword:Zu.string().optional(),useSearch:Zu.boolean().optional(),forceClick:Zu.boolean().optional()}),rm=Zu.object({success:Zu.boolean(),status:Zu.enum(em),requested:nm,current:tm.optional(),selected:tm.optional(),options:Zu.array(tm),matchedCount:Zu.number(),error:Zu.string().optional()}),am=Zu.object({jobRef:Zu.string().regex(ou,"jobRef 应类似 @j1").optional().describe("岗位语义引用,如 @j1;来自 zhipin_list_recommend_jobs 输出,优先级最高"),jobValue:Zu.string().min(1).optional().describe("岗位下拉 li.job-item 的 value,来自本工具或页面 DOM;最稳定,优先匹配"),jobName:Zu.string().min(1).optional().describe("岗位标题/名称,缺少 jobValue 时用于文本匹配"),index:Zu.number().int().min(0).optional().describe("当前岗位下拉快照里的 index,仅在缺少 jobValue/jobName 时兜底"),searchKeyword:Zu.string().min(1).optional().describe("下拉搜索框关键词;不传时用 jobName 作为搜索关键词"),useSearch:Zu.boolean().default(!0).describe("初始可见项未命中时是否使用下拉搜索框收敛候选项"),forceClick:Zu.boolean().default(!1).describe("目标岗位已选中时是否仍点击一次岗位项;默认 false,避免无意义重复点击")}).refine(e=>void 0!==e.jobRef||void 0!==e.jobValue||void 0!==e.jobName||void 0!==e.index,{path:["jobRef"],message:"jobRef、jobValue、jobName、index 至少需要提供一个"}),om=900,im=180,sm=1400;function cm(){return{openNativePagePort:ps,createNativeVisualActivitySession:e=>new Xr(e),...Qu}}function lm(e){if(void 0!==e.jobRef){const t=bu(e.jobRef);return{jobRef:t.jobRef,...t.value.length>0?{jobValue:t.value}:{},...0===t.value.length&&t.label.length>0?{jobName:t.label}:{},index:t.index,...void 0!==e.searchKeyword?{searchKeyword:e.searchKeyword}:{},useSearch:e.useSearch??!0,forceClick:e.forceClick??!1}}return{...void 0!==e.jobValue?{jobValue:e.jobValue}:{},...void 0!==e.jobName?{jobName:e.jobName}:{},...void 0!==e.index?{index:e.index}:{},...void 0!==e.searchKeyword?{searchKeyword:e.searchKeyword}:{},useSearch:e.useSearch??!0,forceClick:e.forceClick??!1}}function dm(e){return{...void 0!==e.jobRef?{jobRef:e.jobRef}:{},...void 0!==e.jobValue?{jobValue:e.jobValue}:{},...void 0!==e.jobName?{jobName:e.jobName}:{},...void 0!==e.index?{index:e.index}:{},...void 0!==e.searchKeyword?{searchKeyword:e.searchKeyword}:{},useSearch:e.useSearch??!0,forceClick:e.forceClick??!1}}function um(e){return{index:e.index,value:e.value,label:e.label,isCurrent:e.isCurrent}}function mm(e){return{success:e.success,status:e.status,requested:e.requested,...void 0!==e.current?{current:um(e.current)}:{},...void 0!==e.selected?{selected:um(e.selected)}:{},options:e.options.map(um),matchedCount:e.matchedCount,...void 0!==e.error?{error:e.error}:{}}}var pm=Xu({name:"zhipin_select_recommend_job",description:"在 BOSS「推荐牛人」页切换顶部招聘岗位筛选。优先传 jobRef,其次 jobValue,再次 jobName,index 仅作当前快照兜底。",input:am,output:rm,execute:async(e,t)=>{const n=cm();let r,a;try{const o=lm(e);t.logger.info(`Selecting Boss recommend job: ref=${o.jobRef??"N/A"}, value=${o.jobValue??"N/A"}, name=${o.jobName??"N/A"}, index=${o.index??"N/A"}, forceClick=${!0===o.forceClick}`),r=await n.openNativePagePort(),a=n.createNativeVisualActivitySession(r),await wn(r),await a.begin("正在选择推荐岗位"),await a.highlightSelector(".job-selecter-wrap",{label:"正在选择推荐岗位",padding:8});const i=await r.selectRecommendJob(o,{preClickDelayMs:om,pressDurationMs:im,settleMs:sm,...void 0!==a?{motionObserver:a}:{}});return i.success?await a.succeed("already_selected"===i.status?"推荐岗位已是目标岗位":"已选择推荐岗位"):await a.fail(i.error??"选择推荐岗位失败"),mm(i)}catch(t){const n=t instanceof Error?t.message:"选择推荐岗位失败";return await(a?.fail(n)),mm({success:!1,status:void 0!==e.jobRef?"not_found":"selector_not_found",requested:dm(e),options:[],matchedCount:0,error:n})}finally{r?.close()}}});import{defineTool as gm}from"@roll-agent/sdk";import{z as fm}from"zod";var hm,bm=fm.object({index:fm.number(),candidateRef:fm.string(),candidateName:fm.string(),candidateId:fm.string(),success:fm.boolean(),error:fm.string().optional()}),ym=fm.object({success:fm.boolean(),results:fm.array(bm),summary:fm.object({total:fm.number(),succeeded:fm.number(),failed:fm.number()})}),vm=[1400,1800,2200],wm=450,xm=140,Sm=750,Im=fm.object({indices:fm.array(fm.number().int().min(0)).min(1).optional().describe("要打招呼的候选人索引列表"),candidateRefs:fm.array(fm.string().regex(au,"candidateRef 应类似 @c1")).min(1).optional().describe("要打招呼的候选人语义引用列表,如 @c1;来自 zhipin_get_candidate_list 输出")}).refine(e=>(e.indices?.length??0)>0||(e.candidateRefs?.length??0)>0,"必须提供 indices 或 candidateRefs");function Cm(){return{openNativePagePort:ps,createNativeVisualActivitySession:e=>new Xr(e),sleep:async e=>await new Promise(t=>{setTimeout(t,e)}),...hm}}var Rm=gm({name:"zhipin_say_hello",description:"在推荐列表页对候选人点击「打招呼」按钮(支持批量)",input:Im,output:ym,execute:async(e,t)=>{const n=yu(e);t.logger.info(`Saying hello to ${n.length} candidates through native CDP`);const r=Cm();let a,o;try{a=await r.openNativePagePort(),o=r.createNativeVisualActivitySession(a),await o.begin("正在打开推荐列表");if(!await a.waitForRecommendList()){await o.fail("推荐列表未加载");const e=n.map(e=>({index:e.index,candidateRef:e.candidateRef,candidateName:"",candidateId:"",success:!1,error:"推荐列表未加载"}));return{success:!1,results:e,summary:{total:e.length,succeeded:0,failed:e.length}}}const e=n.length>1?"正在批量打招呼":"正在打招呼";await o.begin(e),await o.highlightSelector(".candidate-card-wrap, [data-geek], .geek-item",{label:e,padding:8});const i=[];for(const[e,s]of n.entries()){if(e>0){const t=vm[(e-1)%vm.length]??vm[0];await r.sleep(t)}if(km(s)){const e=await a.inspectRecommendCard(s.index);if(!vu(s,e)){i.push({index:s.index,candidateRef:s.candidateRef,candidateName:e.name,candidateId:e.candidateId,success:!1,error:`候选人引用 ${s.candidateRef} 已过期,请重新获取推荐列表`});continue}}const n=await a.clickRecommendGreet(s.index,{preClickDelayMs:wm,pressDurationMs:xm,settleMs:Sm,...void 0!==o?{motionObserver:o}:{}});i.push({index:s.index,candidateRef:s.candidateRef,candidateName:n.name,candidateId:n.candidateId,success:n.clicked,...void 0!==n.error?{error:n.error}:{}}),Vs(n,t.logger)}const s={total:i.length,succeeded:i.filter(e=>e.success).length,failed:i.filter(e=>!e.success).length};return 0===s.failed?await o.succeed(`已完成 ${s.succeeded}/${s.total} 位候选人`):await o.fail(`已完成 ${s.succeeded}/${s.total} 位候选人`),{success:0===s.failed,results:i,summary:s}}catch(e){const t=e instanceof Error?e.message:String(e);await(o?.fail(t));const r=n.map(e=>({index:e.index,candidateRef:e.candidateRef,candidateName:"",candidateId:"",success:!1,error:t}));return{success:!1,results:r,summary:{total:r.length,succeeded:0,failed:r.length}}}finally{a?.close()}}});function km(e){return e.candidateId.length>0||void 0!==e.name&&e.name.length>0}import{defineTool as Am}from"@roll-agent/sdk";import{z as Nm}from"zod";var Mm="recommendFrame",Em="recommend",Pm="#recommendFrame",Tm=".candidate-card-wrap",_m="[data-geek], .geek-item",Bm=`${Tm}, ${_m}`,Om="[data-geek], .card-inner, .geek-item",$m="[data-geek]",Dm=".name",qm=[".recommendV2 .boss-popup__close",".dialog-lib-resume .boss-popup__close",".boss-dialog .boss-popup__close",".boss-popup__close",".close-btn",".dialog-close"],jm=[".boss-popup__close",".close-btn",".dialog-close",".modal-close"],Fm=".boss-popup__wrapper, .dialog-lib-resume, .boss-dialog",Lm=".boss-popup__wrapper",zm='iframe[src*="c-resume"]',Jm="canvas#resume, div#resume canvas";function Vm(e){return e.hasNamedRecommendFrame?"named-frame":e.hasRecommendUrlFrame?"recommend-url-frame":"main-page"}function Hm(e){return e>0?Tm:_m}function Um(e){return{candidateId:(e.ownDataGeek??e.childDataGeek??"").trim(),name:(e.nameText??"").trim()}}function Wm(e){const t=(e.recommendFrameRect?.x??0)+(e.resumeFrameRect?.x??0),n=(e.recommendFrameRect?.y??0)+(e.resumeFrameRect?.y??0);return{x:Math.round(t+e.canvasRect.x),y:Math.round(n+e.canvasRect.y),width:Math.round(e.canvasRect.width),height:Math.round(e.canvasRect.height)}}function Km(e){return e.evaluate(e=>document.querySelectorAll(e).length,Tm).then(Hm)}function Ym(e){const t=e.frame(Mm),n=e.frames().find(e=>e.url().includes(Em)),r=Vm({hasNamedRecommendFrame:null!==t,hasRecommendUrlFrame:void 0!==n});return"named-frame"===r?t??e:"recommend-url-frame"===r?n??e:e}async function Gm(e,t=1e4){try{return await e.waitForSelector(Bm,{timeout:t}),!0}catch{return!1}}async function Xm(e,t){const n=await Km(e),r=e.locator(n);if(await r.count()<=t)return{found:!1,cardSelector:n,candidateId:"",name:"",hasGreetButton:!1,error:"索引超出范围"};const a=r.nth(t),o=await a.evaluate((e,t)=>{const n=e.getAttribute("data-geek")??e.querySelector(t.candidateIdSelector)?.getAttribute("data-geek")??"",r=e.querySelector(t.candidateNameSelector)?.textContent?.trim()??"",a=e.querySelector("button.btn.btn-greet");return{candidateId:n,name:r,hasGreetButton:null!==a&&a.offsetWidth>0}},{candidateIdSelector:$m,candidateNameSelector:Dm}),i=Um({ownDataGeek:o.candidateId,nameText:o.name});return{found:!0,cardSelector:n,candidateId:i.candidateId,name:i.name,hasGreetButton:o.hasGreetButton}}var Zm=Nm.object({success:Nm.boolean(),candidateRef:Nm.string().optional(),candidateName:Nm.string(),candidateId:Nm.string(),error:Nm.string().optional()}),Qm=Nm.object({index:Nm.number().int().min(0).optional().describe("候选人在列表中的 0-based 索引"),candidateRef:Nm.string().regex(au,"candidateRef 应类似 @c1").optional().describe("候选人语义引用,如 @c1;来自 zhipin_get_candidate_list 输出")}).refine(e=>void 0!==e.index||void 0!==e.candidateRef,"必须提供 index 或 candidateRef"),ep=Am({name:"zhipin_open_resume",description:"在推荐列表页点击候选人卡片打开简历详情弹窗",input:Qm,output:Zm,execute:async(e,t)=>{const n=tp(e),r=n.index,a=n.candidateRef;t.logger.info(`Opening resume for candidate ${a} at index ${r}`);const o=ue(),i=await o.getPage("zhipin"),s=Ym(i);if(!await Gm(s))return{success:!1,candidateRef:a,candidateName:"",candidateId:"",error:"推荐列表未加载"};const c=await Xm(s,r);if(!c.found)return{success:!1,candidateRef:a,candidateName:"",candidateId:"",error:c.error??`候选人引用 ${a} 超出范围`};if(np(n)&&!vu(n,c))return{success:!1,candidateRef:a,candidateName:c.name,candidateId:c.candidateId,error:`候选人引用 ${a} 已过期,请重新获取推荐列表`};const l=s.locator(c.cardSelector).nth(r),d=await l.locator(Om).count()>0?l.locator(Om).first():l;return await d.scrollIntoViewIfNeeded(),await Ke(i,d,{target:s}),await d.hover(),await ri(i,200,400),await Ye(i,d,{target:s}),await d.click(),await ri(i,1e3,2e3),t.logger.info(`Opened resume for ${c.name}`),{success:!0,candidateRef:a,candidateName:c.name,candidateId:c.candidateId}}});function tp(e){if(void 0!==e.candidateRef)return hu(e.candidateRef);const t=pu(e);return{index:t,candidateRef:lu(t),candidateId:""}}function np(e){return e.candidateId.length>0||void 0!==e.name&&e.name.length>0}import{defineTool as rp}from"@roll-agent/sdk";import{z as ap}from"zod";var op=ap.object({x:ap.number(),y:ap.number(),width:ap.number(),height:ap.number()}),ip=ap.object({success:ap.boolean(),screenshotArea:op.optional(),canvasInfo:ap.object({width:ap.number(),height:ap.number()}).optional(),error:ap.string().optional()}),sp=rp({name:"zhipin_locate_resume_canvas",description:"定位简历详情中嵌套 iframe 内的 canvas 元素坐标(用于截图)",input:ap.object({}),output:ip,execute:async(e,t)=>{t.logger.info("Locating resume canvas in nested iframes");const n=ue(),r=await n.getPage("zhipin");try{const e=r.frame(Mm)??r.frames().find(e=>e.url().includes(Em));if(!e)return{success:!1,error:"未找到推荐页 iframe"};const n=await e.$(zm);if(!n)return{success:!1,error:"未找到简历 iframe"};const a=await n.contentFrame();if(!a)return{success:!1,error:"无法访问简历 iframe 内容"};try{await a.waitForSelector(Jm,{timeout:5e3})}catch{return{success:!1,error:"简历 canvas 未加载"}}const o=await a.evaluate(e=>{const t=document.querySelector(e);if(!t)return null;const n=t.getBoundingClientRect();return{width:t.width,height:t.height,clientWidth:n.width,clientHeight:n.height,x:n.x,y:n.y}},Jm);if(!o)return{success:!1,error:"无法获取 canvas 信息"};const i=await r.evaluate(e=>{const t=document.querySelector(e);if(!t)return null;const n=t.getBoundingClientRect();return{x:n.x,y:n.y}},Pm),s=Wm({recommendFrameRect:i,resumeFrameRect:await e.evaluate(e=>{const t=document.querySelector(e);if(!t)return null;const n=t.getBoundingClientRect();return{x:n.x,y:n.y}},zm),canvasRect:{x:o.x,y:o.y,width:o.clientWidth,height:o.clientHeight}});return t.logger.info(`Canvas located at (${s.x}, ${s.y})`),{success:!0,screenshotArea:s,canvasInfo:{width:o.width,height:o.height}}}catch(e){return{success:!1,error:e instanceof Error?e.message:String(e)}}}});import{defineTool as cp}from"@roll-agent/sdk";import{z as lp}from"zod";var dp=lp.object({success:lp.boolean(),closed:lp.boolean(),error:lp.string().optional()}),up=cp({name:"zhipin_close_resume",description:"关闭简历详情弹窗",input:lp.object({}),output:dp,execute:async(e,t)=>{t.logger.info("Closing resume detail modal");const n=ue(),r=await n.getPage("zhipin"),a=r.frame(Mm)??r.frames().find(e=>e.url().includes(Em));if(!await(async()=>{if(a)for(const e of qm){const t=a.locator(e).first();if(await t.isVisible())return await Ke(r,t,{target:a}),await Ye(r,t,{target:a}),await t.click(),!0}for(const e of jm){const t=r.locator(e).first();if(await t.isVisible())return await Ke(r,t),await Ye(r,t),await t.click(),!0}return!1})())return{success:!1,closed:!1,error:"未找到关闭按钮"};let o=!1;for(let e=0;e<5;e++){await r.waitForTimeout(300);const e=a?await a.$(Fm):await r.$(Lm);if(!e||!await e.isVisible()){o=!0;break}}return t.logger.info(o?"Resume modal closed and verified":"Resume modal close unverified"),{success:!0,closed:!0}}});import{defineTool as mp}from"@roll-agent/sdk";import{z as pp}from"zod";import{waitForSelector as gp}from"@roll-agent/browser";var fp={login:{qrCode:".login-qr img, .qr-code img",loginSuccess:".user-info, .header-user"},messageList:{container:".chat-list, .msg-list",item:".chat-item, .msg-item",candidateName:".chat-item .name, .msg-item .name",lastMessage:".chat-item .msg, .msg-item .content",unreadBadge:".chat-item .unread, .msg-item .badge",timestamp:".chat-item .time, .msg-item .time"},chat:{input:".chat-input textarea, .msg-input textarea",sendButton:".btn-send, .send-btn",messageItem:".chat-msg, .msg-bubble",messageText:".chat-msg .text, .msg-bubble .text"}};import{navigateTo as hp,waitForSelector as bp}from"@roll-agent/browser";var yp="https://www.yupao.com",vp=`${yp}/chat`,wp=`${yp}/login`;async function xp(e,t={}){e.url().includes("/chat")||await hp(e,vp,t),await bp(e,fp.messageList.container,{timeout:15e3})}async function Sp(e,t,n={}){const r=`${yp}/chat?id=${encodeURIComponent(t)}`;await hp(e,r,n),await bp(e,fp.chat.input,{timeout:15e3})}async function Ip(e,t){await xp(e),await gp(e,fp.messageList.item,{timeout:1e4});const n=fp.messageList;return await e.$$eval(n.item,(e,t)=>{const n=[],r=t.maxItems?e.slice(0,t.maxItems):e;for(const e of r){const r=e.querySelector(t.sel.candidateName),a=e.querySelector(t.sel.lastMessage),o=e.querySelector(t.sel.unreadBadge),i=e.querySelector(t.sel.timestamp),s=e.getAttribute("data-id")??e.getAttribute("data-conversation-id")??e.querySelector("a")?.getAttribute("href")?.match(/id=([^&]+)/)?.[1]??"";n.push({conversationId:s,candidateName:r?.textContent?.trim()??"",lastMessage:a?.textContent?.trim()??"",unreadCount:parseInt(o?.textContent?.trim()??"0",10)||0,timestamp:i?.textContent?.trim()??""})}return n},{sel:n,maxItems:t})}var Cp=pp.object({limit:pp.number().optional().describe("最多返回的消息条数")}),Rp=pp.object({conversationId:pp.string(),candidateName:pp.string(),lastMessage:pp.string(),unreadCount:pp.number(),timestamp:pp.string()}),kp=pp.object({messages:pp.array(Rp),total:pp.number()}),Ap=mp({name:"yupao_read_messages",description:"读取鱼泡未读消息列表",input:Cp,output:kp,execute:async(e,t)=>{t.logger.info(`Reading yupao messages (limit: ${e.limit??"all"})`);const n=ue(),r=await n.getPage("yupao"),a=await Ip(r,e.limit);return t.logger.info(`Found ${a.length} messages`),{messages:a.map(e=>({...e})),total:a.length}}});import{defineTool as Np}from"@roll-agent/sdk";import{z as Mp}from"zod";import{BrowserActionApprovalSchema as Ep}from"@roll-agent/browser";import{clickElement as Pp,isBrowserActionPolicyError as Tp,typeText as _p,waitForSelector as Bp}from"@roll-agent/browser";async function Op(e,t,n,r={}){try{return await Sp(e,t,r),await _p(e,fp.chat.input,n,r),await Pp(e,fp.chat.sendButton,r),await Bp(e,fp.chat.messageItem,{timeout:5e3}),{success:!0}}catch(e){if(Tp(e))throw e;return{success:!1,error:e instanceof Error?e.message:String(e)}}}var $p=Mp.object({conversationId:Mp.string().describe("对话 ID"),message:Mp.string().describe("要发送的回复消息"),browserActionApproval:Ep.optional().describe("当 actionPolicy=confirm 返回 needs_confirmation 后,由 orchestrator 原样带回的批准 ID。")}),Dp=Mp.object({success:Mp.boolean(),conversationId:Mp.string(),sentMessage:Mp.string(),error:Mp.string().optional()}),qp=Np({name:"yupao_send_reply",description:"向鱼泡指定对话发送回复消息",input:$p,output:Dp,execute:async(e,t)=>{const{conversationId:n,message:r}=e;t.logger.info(`Sending reply to yupao conversation ${n}`);const a=ue(),o=de(),i=hn(t,o,{action:"yupao_send_reply",target:n,...void 0!==e.browserActionApproval?{approval:e.browserActionApproval}:{}}),s=await a.getPage("yupao");let c;try{c=await Op(s,n,r,fn(t,o,{approval:e.browserActionApproval,approvedByConfirmation:i.approvedByConfirmation}))}catch(e){const t=bn(e);if(void 0!==t)throw t;throw e}return c.success?t.logger.info("Reply sent successfully"):t.logger.error(`Failed to send reply: ${c.error}`),{success:c.success,conversationId:n,sentMessage:r,error:c.error}}});import{BrowserRuntimeConfigSchema as jp,BrowserRuntimeModeSchema as Fp,BrowserChannelSchema as Lp,BrowserProfileColorSchema as zp,BrowserWindowBoundsSchema as Jp,PlatformSchema as Vp}from"@roll-agent/browser";import{z as Hp}from"zod";var Up=Hp.object({platform:Vp.optional(),mode:Fp.default("managed-cdp"),headless:Hp.boolean().optional(),cdpUrl:Hp.string().optional(),cdpHost:Hp.string().default("127.0.0.1"),cdpPort:Hp.number().int().min(1).max(65535).optional(),channel:Lp.default("chrome"),executablePath:Hp.string().optional(),userDataDir:Hp.string().trim().min(1),sessionsDir:Hp.string().trim().min(1).optional(),args:Hp.array(Hp.string()).optional(),profileName:Hp.string().trim().min(1).optional(),profileColor:zp.optional(),windowBounds:Jp.optional(),trackingAgentId:Hp.string().trim().min(1).optional()}).superRefine((e,t)=>{"managed-cdp"===e.mode&&void 0===e.cdpPort&&t.addIssue({code:Hp.ZodIssueCode.custom,path:["cdpPort"],message:"managed-cdp browser instance requires cdpPort"}),"remote-cdp"!==e.mode&&"existing-session"!==e.mode||void 0!==e.cdpUrl||t.addIssue({code:Hp.ZodIssueCode.custom,path:["cdpUrl"],message:`${e.mode} browser instance requires cdpUrl`})}),Wp=Hp.object({defaultInstance:Hp.string().trim().min(1).optional(),instances:Hp.record(Hp.string(),Up).default({})}).superRefine((e,t)=>{void 0!==e.defaultInstance&&void 0===e.instances[e.defaultInstance]&&t.addIssue({code:Hp.ZodIssueCode.custom,path:["defaultInstance"],message:`defaultInstance "${e.defaultInstance}" is not declared in browser.instances`});const n=new Map,r=new Map;for(const[a,o]of Object.entries(e.instances)){if(void 0!==o.cdpPort){const e=n.get(o.cdpPort);void 0!==e?t.addIssue({code:Hp.ZodIssueCode.custom,path:["instances",a,"cdpPort"],message:`cdpPort ${String(o.cdpPort)} is already used by browser instance "${e}"`}):n.set(o.cdpPort,a)}const e=r.get(o.userDataDir);void 0!==e?t.addIssue({code:Hp.ZodIssueCode.custom,path:["instances",a,"userDataDir"],message:`userDataDir is already used by browser instance "${e}"`}):r.set(o.userDataDir,a)}});function Kp(e){if(void 0!==e){if("true"===e)return!0;if("false"===e)return!1;throw new Error(`Expected boolean env value "true" or "false", received "${e}".`)}}function Yp(e,t){if(void 0===e)return;const n=Number.parseInt(e,10);if(!Number.isInteger(n))throw new Error(`${t} must be an integer, received "${e}".`);return n}function Gp(e){if(void 0===e)return;const t=JSON.parse(e);if(!Array.isArray(t)||!t.every(e=>"string"==typeof e))throw new Error("BROWSER_ARGS_JSON must be a JSON string array.");return t}function Xp(e){if(void 0!==e)try{return JSON.parse(e)}catch(e){throw new Error(`BROWSER_SECURITY_JSON must be valid JSON: ${e instanceof Error?e.message:String(e)}`)}}function Zp(e){if(void 0===e)return;let t;try{t=JSON.parse(e)}catch(e){throw new Error(`BROWSER_INSTANCES_JSON must be valid JSON: ${e instanceof Error?e.message:String(e)}`)}return Wp.parse(t)}function Qp(e=process.env){return jp.parse({mode:e.BROWSER_MODE,headless:Kp(e.BROWSER_HEADLESS),cdpUrl:e.BROWSER_CDP_URL,cdpHost:e.BROWSER_CDP_HOST,cdpPort:Yp(e.BROWSER_CDP_PORT,"BROWSER_CDP_PORT"),channel:e.BROWSER_CHANNEL,executablePath:e.BROWSER_EXECUTABLE_PATH,userDataDir:e.BROWSER_USER_DATA_DIR,args:Gp(e.BROWSER_ARGS_JSON),profileColor:e.BROWSER_PROFILE_COLOR,sessionsDir:e.BROWSER_SESSIONS_DIR,security:Xp(e.BROWSER_SECURITY_JSON)})}function eg(e=process.env){return Zp(e.BROWSER_INSTANCES_JSON)}import{z as tg}from"zod";import{StructuredToolError as ng}from"@roll-agent/sdk";function rg(e){if(void 0===e)return;const t=ge().getBundle();if(void 0!==t.platform&&t.platform!==e)throw new ng({code:"platform_mismatch",message:`Tool platform "${e}" does not match browser instance "${t.id}" platform "${t.platform}".`,details:{browserInstance:t.id,expectedPlatform:t.platform,requestedPlatform:e}})}function ag(e){if("object"!=typeof e||null===e||!("platform"in e))return;const t=e.platform;return"zhipin"===t||"yupao"===t?t:void 0}var og={browserInstance:tg.string().trim().min(1).optional().describe("可选 browser instance id;多浏览器实例时用于选择目标 profile/CDP runtime。")};function ig(e){return e.startsWith("zhipin_")?"zhipin":e.startsWith("yupao_")?"yupao":void 0}function sg(e,t={}){const n=lg(e.input);if(void 0===n)return e;const r=t.startRuntime??!0,a=t.expectedPlatform??ig(e.name);return{...e,input:n,execute:async(t,n)=>{const o=t;return await Y(o.browserInstance,async()=>(void 0!==o.browserInstance&&ge().getBundle(),rg(cg(t,a)),r&&await fe(),await e.execute(t,n)))}}}function cg(e,t){const n=ag(e);return t??n}function lg(e){if(e instanceof tg.ZodObject)return e.extend(og);if(e instanceof tg.ZodEffects){const t=lg(e.innerType());if(void 0===t)return;const n=e._def.effect;return"preprocess"===n.type?tg.ZodEffects.createWithPreprocess(n.transform,t,e._def):tg.ZodEffects.create(t,n,e._def)}}var dg=t("browser-use-agent");function ug(e){return"browser_stop"===e}function mg(e){return ug(e.name)?e:sg(e,{startRuntime:"browser_status"!==e.name})}var pg=e({name:"browser-use-agent",tools:[At,Xt,Dn,Wn,er,da,Ia,Pa,Qo,Qs,sc,pc,Ec,ol,ad,hd,Sd,_d,Gu,zu,pm,Gd,Nu,Rm,ep,sp,up,Ap,qp,xe,Ot].map(mg)},{onShutdown:ve});async function gg(){xt(wt()),await le(Qp(),eg());try{await _l(),me(!0)}catch(e){me(!1),dg.error(`Failed to preload Reply Authority keys during startup; browser_status.replyAuthorityKeysLoaded=false. ${e instanceof Error?e.stack??e.message:String(e)}`)}await pg.listen({transport:{type:"http",port:parseInt(process.env.BROWSER_AGENT_PORT??"3100",10),host:process.env.BROWSER_AGENT_HOST??"127.0.0.1"}})}gg().catch(async e=>{dg.error(`Fatal error: ${e instanceof Error?e.stack??e.message:String(e)}`),await ve().catch(()=>{}),process.exit(1)});
|
|
1
|
+
import{defineAgent as e,createAgentLogger as t}from"@roll-agent/sdk";import{defineTool as n}from"@roll-agent/sdk";import{z as r}from"zod";import{createAgentLogger as a}from"@roll-agent/sdk";import"@roll-agent/browser";import{AsyncLocalStorage as o}from"node:async_hooks";import{access as i}from"node:fs/promises";import{constants as s}from"node:fs";import{homedir as c}from"node:os";import{join as l}from"node:path";import{createHash as d}from"node:crypto";import{StructuredToolError as u}from"@roll-agent/sdk";import{BrowserContextManager as m,BrowserRuntime as p,BrowserRuntimeConfigSchema as g,probeBrowserRuntimeCdpHealth as f,SessionStore as h}from"@roll-agent/browser";import{execFileSync as b}from"node:child_process";var y,v={x:0,y:0,width:1920,height:1080},w=25,x=80,S=4,I=["Add-Type -AssemblyName System.Windows.Forms;","$area = [System.Windows.Forms.Screen]::PrimaryScreen.WorkingArea;","[pscustomobject]@{ x = $area.X; y = $area.Y; width = $area.Width; height = $area.Height } | ConvertTo-Json -Compress"].join(" ");function C(){return y??=A(),y}function R(e){if(e<=1)return[1];if(2===e)return[2];if(3===e)return[3];if(4===e)return[2,2];const t=Math.ceil(e/S),n=Math.floor(e/t),r=e%t;return Array.from({length:t},(e,t)=>n+(t<r?1:0))}function k(e){if(!Number.isInteger(e.index)||e.index<0||!Number.isInteger(e.total)||e.total<=0||e.index>=e.total)throw new RangeError("Auto window layout index must be within the configured instance count.");const t=R(e.total),n=t.length;let r=0,a=e.index;for(const[e,n]of t.entries()){if(a<n){r=e;break}a-=n}const o=t[r]??1,i=e.workArea.x+Math.floor(e.workArea.width*a/o),s=e.workArea.x+Math.floor(e.workArea.width*(a+1)/o),c=e.workArea.y+Math.floor(e.workArea.height*r/n);return{x:i,y:c,width:s-i,height:e.workArea.y+Math.floor(e.workArea.height*(r+1)/n)-c}}function A(){const e=N(process.env.ROLL_BROWSER_WORK_AREA);if(void 0!==e)return e;if("darwin"===process.platform){const e=B();if(void 0!==e)return{x:e.x,y:e.y+w,width:e.width,height:Math.max(400,e.height-w-x)}}if("linux"===process.platform){const e=$();if(void 0!==e)return e}if("win32"===process.platform){const e=O();if(void 0!==e)return e}return v}function N(e){if(void 0===e||0===e.trim().length)return;const t=e.split(",").map(e=>Number.parseInt(e.trim(),10));if(4!==t.length||t.some(e=>!Number.isFinite(e)||e<0))return;const[n,r,a,o]=t;return a<=0||o<=0?void 0:{x:n,y:r,width:a,height:o}}function M(e){const t=E(e,/UI Looks like:\s*(\d+)\s*x\s*(\d+)/i);if(void 0!==t)return t;for(const t of e.split("\n")){if(!t.includes("Resolution:")||/\bRetina\b/i.test(t))continue;const e=E(t,/Resolution:\s*(\d+)\s*x\s*(\d+)/i);if(void 0!==e)return e}}function E(e,t){const n=e.match(t);if(void 0===n?.[1]||void 0===n[2])return;const r=Number.parseInt(n[1],10),a=Number.parseInt(n[2],10);return r<=0||a<=0?void 0:{x:0,y:0,width:r,height:a}}function P(e){const t=e.trim().replace(/^\uFEFF/,"");if(0===t.length)return;let n;try{n=JSON.parse(t)}catch{return}if(!T(n))return;const r=_(n.x),a=_(n.y),o=_(n.width),i=_(n.height);return void 0===r||void 0===a||void 0===o||void 0===i||o<=0||i<=0?void 0:{x:r,y:a,width:o,height:i}}function T(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function _(e){if("number"==typeof e&&Number.isInteger(e))return e;if("string"==typeof e&&e.trim().length>0){const t=Number(e.trim());return Number.isInteger(t)?t:void 0}}function B(){try{return M(b("system_profiler",["SPDisplaysDataType"],{encoding:"utf8",timeout:2e3,stdio:["ignore","pipe","ignore"]}).trim())}catch{return}}function O(){try{return P(b("powershell.exe",["-NoProfile","-NonInteractive","-Command",I],{encoding:"utf8",timeout:2e3,windowsHide:!0,stdio:["ignore","pipe","ignore"]}))}catch{return}}function $(){try{const e=b("xrandr",["--current"],{encoding:"utf8",timeout:2e3,stdio:["ignore","pipe","ignore"]}).match(/(\d+)x(\d+)\+/);if(void 0===e?.[1]||void 0===e[2])return;const t=Number.parseInt(e[1],10),n=Number.parseInt(e[2],10);if(t<=0||n<=0)return;return{x:0,y:0,width:t,height:n}}catch{return}}var D,q,F,j,L="default",z=l(c(),".roll-agent","browser","sessions"),J=["#2563EB","#DC2626","#16A34A","#D97706","#7C3AED","#0891B2","#DB2777","#65A30D"],U=["stopped","not_running","not_found","failed"],V=new o,H=class{bundles=new Map;defaultInstanceId;startPromises=new Map;constructor(e,t){if(void 0===t||0===Object.keys(t.instances).length){const t=ne({id:L,runtimeConfig:e});return this.bundles.set(t.id,t),void(this.defaultInstanceId=t.id)}this.defaultInstanceId=t.defaultInstance;const n=Object.entries(t.instances);for(const[t,[r,a]]of n.entries()){const o=ne({id:r,runtimeConfig:G(e,r,a,{index:t,total:n.length}),...void 0!==a.platform?{platform:a.platform}:{},...void 0!==a.trackingAgentId?{trackingAgentId:a.trackingAgentId}:{}});this.bundles.set(r,o)}}getDefaultInstanceId(){return this.defaultInstanceId}listBundles(){return[...this.bundles.values()]}isLegacySingleInstancePool(){return 1===this.bundles.size&&this.bundles.keys().next().value===L}resolvePrimaryInstanceId(){return this.defaultInstanceId??this.getOnlyInstanceId()}async ensureBundleStarted(e){const t=this.getBundle(e);return await this.ensureStarted(t.id),t}async ensureStarted(e){const t=this.bundles.get(e);if(void 0===t)throw new Error(`Browser instance "${e}" was not found.`);if(t.runtime.isRunning())return;const n=this.startPromises.get(e);if(void 0!==n)return void await n;const r=t.runtime.start().catch(async t=>{throw this.startPromises.delete(e),t});this.startPromises.set(e,r);try{await r}finally{this.startPromises.delete(e)}}getBundle(e){const t=e??V.getStore()??this.defaultInstanceId??this.getOnlyInstanceId();if(void 0===t)throw new u({code:"needs_input",message:"browserInstance is required because multiple browser instances are configured.",details:{availableInstances:[...this.bundles.keys()]}});const n=this.bundles.get(t);if(void 0===n)throw new u({code:"browser_instance_not_found",message:`Browser instance "${t}" was not found.`,details:{availableInstances:[...this.bundles.keys()]}});return n}async getInstanceStatuses(){return await Promise.all(this.listBundles().map(async e=>{const[t,n]=await Promise.all([f(e.config),re(e.config.userDataDir)]);return{id:e.id,...void 0!==e.platform?{platform:e.platform}:{},mode:e.config.mode,cdp:t,profile:n,tracking:oe(e.trackingAgentId)}}))}async closeAll(){const e=(await this.closeInstances([...this.bundles.keys()])).filter(e=>"failed"===e.status).map(e=>new Error(`Failed to stop browser runtime for ${e.browserInstance}: ${e.message??"unknown error"}`));if(e.length>0)throw new AggregateError(e,"Browser instance pool shutdown failed")}async closeInstances(e){const t=[...new Set(e)];return await Promise.all(t.map(async e=>await this.closeInstance(e)))}async closeInstance(e){const t=this.bundles.get(e);if(void 0===t)return{browserInstance:e,status:"not_found",message:`Browser instance "${e}" was not found.`};const n=[],r=this.startPromises.get(e);if(void 0!==r)try{await r}catch(t){n.push(new Error(`Failed to finish browser startup for ${e}`,{cause:t}))}if(!t.runtime.isRunning())return n.length>0?{browserInstance:e,status:"failed",mode:t.config.mode,message:W(n)}:{browserInstance:e,status:"not_running",mode:t.config.mode};try{await t.contextManager.closeAll()}catch(t){n.push(new Error(`Failed to close browser contexts for ${e}`,{cause:t}))}try{"managed-cdp"===t.config.mode?await t.runtime.stop():await t.runtime.disconnect()}catch(t){n.push(new Error(`Failed to stop browser runtime for ${e}`,{cause:t}))}return n.length>0?{browserInstance:e,status:"failed",mode:t.config.mode,message:W(n)}:{browserInstance:e,status:"stopped",mode:t.config.mode}}getOnlyInstanceId(){if(1===this.bundles.size)return this.bundles.keys().next().value}};function W(e){return e.map(e=>void 0===e.cause?e.message:`${e.message}: ${K(e.cause)}`).join("; ")}function K(e){return e instanceof Error?e.message:String(e)}async function Y(e,t){return await V.run(e,t)}function G(e,t,n,r){const a=n.headless??e.headless,o=n.windowBounds??te({instance:n,headless:a,...r});return g.parse({...e,mode:n.mode,headless:a,instanceId:t,profileName:n.profileName??t,profileColor:n.profileColor??X(r.index),cdpUrl:n.cdpUrl,cdpHost:n.cdpHost,cdpPort:n.cdpPort,channel:n.channel,executablePath:n.executablePath,userDataDir:n.userDataDir,args:n.args,windowBounds:o,sessionsDir:n.sessionsDir??l(z,t)})}function X(e){return J[e]??Z(e)}function Z(e){return Q(137.508*e%360,.68,.45)}function Q(e,t,n){const r=(1-Math.abs(2*n-1))*t,a=e/60,o=r*(1-Math.abs(a%2-1));let i,s,c;[i,s,c]=a<1?[r,o,0]:a<2?[o,r,0]:a<3?[0,r,o]:a<4?[0,o,r]:a<5?[o,0,r]:[r,0,o];const l=n-r/2;return`#${ee(i+l)}${ee(s+l)}${ee(c+l)}`}function ee(e){return Math.round(255*e).toString(16).padStart(2,"0").toUpperCase()}function te(e){if(!(e.total<=1||e.headless||"managed-cdp"!==e.instance.mode))return k({index:e.index,total:e.total,workArea:C()})}function ne(e){const t=new h(e.runtimeConfig.sessionsDir),n=new p(e.runtimeConfig),r=new m(n,t);return{id:e.id,...void 0!==e.platform?{platform:e.platform}:{},...void 0!==e.trackingAgentId?{trackingAgentId:e.trackingAgentId}:{},runtime:n,contextManager:r,sessionStore:t,config:e.runtimeConfig}}async function re(e){if(void 0===e)return{exists:!1,writable:!1};return{userDataDir:e,exists:await ae(e,s.F_OK),writable:await ae(e,s.W_OK)}}async function ae(e,t){try{return await i(e,t),!0}catch{return!1}}function oe(e){if(void 0!==e)return{source:"instance",agentIdFingerprint:ie(e)};const t=process.env.RECRUITMENT_EVENTS_DEFAULT_AGENT_ID?.trim();return void 0!==t&&t.length>0?{source:"default-env",agentIdFingerprint:ie(t)}:{source:"missing"}}function ie(e){return d("sha256").update(e).digest("hex").slice(0,8)}var se=!1,ce=a("browser-use-agent");async function le(e,t){if(D||q)return;se=!1;const n=(D=new H(e,t)).getDefaultInstanceId(),r=D.listBundles()[0],a=void 0!==n?D.getBundle(n):r;void 0!==a&&(q=a.runtime,F=a.contextManager,j=a.sessionStore)}function de(){if(D)return D.getBundle().runtime;if(!q)throw new Error("BrowserRuntime not initialized. Call initRuntime() first.");return q}function ue(){if(D)return D.getBundle().contextManager;if(!F)throw new Error("BrowserContextManager not initialized. Call initRuntime() first.");return F}function me(e){se=e}function pe(){return se}function ge(){if(!D)throw new Error("BrowserInstancePool not initialized. Call initRuntime() first.");return D}async function fe(){await ge().ensureBundleStarted()}function he(){return void 0!==D&&!D.isLegacySingleInstancePool()}function be(e){if(!D)return e;let t;try{t=D.getBundle()}catch{return}return t.trackingAgentId??e}function ye(){return ge().getBundle()}async function ve(){const e=D,t=F,n=q,r=[];if(D=void 0,F=void 0,q=void 0,j=void 0,se=!1,e){ce.info("Closing browser instance pool...");try{await e.closeAll()}catch(e){r.push(new Error("Failed to close browser instance pool",{cause:e})),ce.error(`Failed to close browser instance pool: ${e instanceof Error?e.stack??e.message:String(e)}`)}}else if(t){ce.info("Closing browser contexts...");try{await t.closeAll()}catch(e){r.push(new Error("Failed to close browser contexts",{cause:e})),ce.error(`Failed to close browser contexts: ${e instanceof Error?e.stack??e.message:String(e)}`)}}if(!e&&n){ce.info("Stopping browser process...");try{await n.stop()}catch(e){r.push(new Error("Failed to stop browser runtime",{cause:e})),ce.error(`Failed to stop browser runtime: ${e instanceof Error?e.stack??e.message:String(e)}`)}}if(ce.info("Browser runtime shutdown complete"),r.length>0)throw new AggregateError(r,"Browser runtime shutdown failed")}var we=r.object({success:r.boolean(),mode:r.string(),connected:r.boolean()}),xe=n({name:"attach_browser_session",description:"调试工具:显式执行一次 connectOverCDP(),仅建立 Playwright Browser 连接,不做页面导航或 DOM 操作。",input:r.object({}),output:we,execute:async(e,t)=>{const n=de();return t.logger.info("Attaching Playwright browser session over CDP"),await n.getBrowser(),{success:!0,mode:n.mode,connected:!0}}});import{defineTool as Se}from"@roll-agent/sdk";import{z as Ie}from"zod";import{BrowserSecurityConfigSchema as Ce,BrowserStatusSchema as Re}from"@roll-agent/browser";import{createHash as ke}from"node:crypto";import{z as Ae}from"zod";var Ne=["REPLY_AUTHORITY_URL","REPLY_AUTHORITY_BEARER_TOKEN","REPLY_AUTHORITY_KEYS_URL","RECRUITMENT_EVENTS_ENABLED","RECRUITMENT_EVENTS_API_BASE_URL","RECRUITMENT_EVENTS_API_TOKEN","RECRUITMENT_EVENTS_DEFAULT_AGENT_ID","BROWSER_SECURITY_JSON","BROWSER_INSTANCES_JSON","BROWSER_USE_POLICY_JSON","BROWSER_VISUAL_CURSOR","BROWSER_VISUAL_ACTIVITY"],Me=/^[0-9a-f]{8}$/,Ee=Ae.object({present:Ae.boolean(),fingerprint:Ae.string().regex(Me).optional()}),Pe=Ae.record(Ee);function Te(e,t=process.env){return Object.fromEntries(e.map(e=>{const n=t[e];return"string"==typeof n&&n.length>0?[e,{present:!0,fingerprint:_e(n)}]:[e,{present:!1}]}))}function _e(e){return ke("sha256").update(e).digest("hex").slice(0,8)}var Be,Oe,$e=180,De=60,qe=280,Fe="roll-agent-visual-cursor-root",je="__rollVisualCursorState";function Le(e){if(void 0!==e)return"true"===e||"false"!==e&&void 0}function ze(){return void 0!==Be?Be:Le(process.env.BROWSER_VISUAL_CURSOR)??!0}async function Je(e){return await e.evaluate(e=>{const t=e.getBoundingClientRect();return t.width<=0||t.height<=0?null:{x:Math.round(t.left+t.width/2),y:Math.round(t.top+t.height/2)}})}async function Ue(e,t){await e.evaluate(e=>{const t="roll-agent-visual-cursor-root",n="roll-agent-visual-cursor-pointer",r="__rollVisualCursorState",a=(()=>{const e=document.getElementById(t);if(e)return e;const r=document.createElement("div");r.id=t,r.style.position="fixed",r.style.left="0",r.style.top="0",r.style.width="0",r.style.height="0",r.style.pointerEvents="none",r.style.zIndex="2147483647";const a=document.createElement("div");return a.id=n,a.setAttribute("aria-hidden","true"),a.style.position="fixed",a.style.left="0",a.style.top="0",a.style.width="24px",a.style.height="24px",a.style.opacity="0",a.style.transform="translate(-9999px, -9999px)",a.style.willChange="transform, opacity",a.style.filter="drop-shadow(0 4px 8px rgba(15, 23, 42, 0.28))",a.innerHTML='<svg viewBox="0 0 24 24" width="24" height="24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M4 2L18 14L11.4 15.3L14.6 22L10.7 23.5L7.6 16.8L3 21V2Z" fill="#FFFFFF" stroke="#0F172A" stroke-width="1.5" stroke-linejoin="round"/></svg>',r.append(a),document.documentElement.append(r),r})(),o=a.querySelector(`#${n}`);if(!o)return;const i=window[r],s=e.point,c=e.durationMs,l=s.x-2,d=s.y-2;if(i?o.style.transition=`transform ${c}ms cubic-bezier(0.22, 1, 0.36, 1), opacity 120ms ease`:(o.style.transition="opacity 120ms ease",o.style.transform=`translate(${l}px, ${d}px)`),o.style.opacity="1",o.style.transform=`translate(${l}px, ${d}px)`,window[r]={x:s.x,y:s.y},!e.clickPulse)return;const u=document.createElement("div");u.setAttribute("aria-hidden","true"),u.style.position="fixed",u.style.left="0",u.style.top="0",u.style.width="18px",u.style.height="18px",u.style.borderRadius="9999px",u.style.border="2px solid rgba(20, 184, 166, 0.95)",u.style.background="rgba(20, 184, 166, 0.18)",u.style.pointerEvents="none",u.style.opacity="0.9",u.style.transform=`translate(${s.x-9}px, ${s.y-9}px) scale(0.55)`,u.style.transition=`transform ${e.pulseDurationMs}ms ease, opacity ${e.pulseDurationMs}ms ease`,a.append(u),requestAnimationFrame(()=>{u.style.opacity="0",u.style.transform=`translate(${s.x-18}px, ${s.y-18}px) scale(2)`}),globalThis.setTimeout(()=>{u.remove()},e.pulseDurationMs+40)},{point:t.point,durationMs:t.durationMs,clickPulse:t.clickPulse,pulseDurationMs:t.pulseDurationMs})}function Ve(e){const t=[e],n="function"==typeof e.frames?e.frames():[];return t.push(...n),t}async function He(e){await e.evaluate(({rootId:e,stateKey:t})=>{document.getElementById(e)?.remove(),delete window[t]},{rootId:Fe,stateKey:je})}async function We(e,t={}){if(e.isClosed())return!1;let n=!1;for(const r of Ve(e))if(r!==t.preserveTarget)try{await He(r),n=!0}catch{}return n}async function Ke(e,t,n={}){if(!ze()||e.isClosed())return!1;try{await t.scrollIntoViewIfNeeded();const r=await Je(t);if(!r)return!1;const a=n.durationMs??$e,o=n.settleMs??De,i=n.target??e;return await We(e,{preserveTarget:i}),await Ue(n.target??e,{point:r,durationMs:a,clickPulse:!1,pulseDurationMs:qe}),await e.waitForTimeout(Math.max(a+o,0)),!0}catch{return!1}}async function Ye(e,t,n={}){if(!ze()||e.isClosed())return!1;try{const r=await Je(t);if(!r)return!1;const a=n.pulseDurationMs??qe,o=n.target??e;return await We(e,{preserveTarget:o}),await Ue(o,{point:r,durationMs:0,clickPulse:!0,pulseDurationMs:a}),await e.waitForTimeout(a),!0}catch{return!1}}function Ge(e){if(void 0!==e)return"true"===e||"false"!==e&&void 0}function Xe(){return void 0!==Oe?Oe:Ge(process.env.BROWSER_VISUAL_ACTIVITY)??!0}import{StructuredToolError as Ze}from"@roll-agent/sdk";import{z as Qe}from"zod";import{randomUUID as et}from"node:crypto";import{z as tt}from"zod";var nt=tt.object({id:tt.string().trim().min(1)}),rt=new Map;function at(e=Date.now()){for(const[t,n]of rt)n.expiresAtMs<=e&&rt.delete(t)}function ot(e,t){return e.tool===t.tool&&e.target===t.target&&e.digest===t.digest}function it(e,t,n=Date.now()){at(n);const r=et(),a=n+t;return rt.set(r,{id:r,tool:e.tool,target:e.target,digest:e.digest,...void 0!==e.summary?{summary:e.summary}:{},expiresAtMs:a}),{id:r,expiresAt:new Date(a).toISOString(),tool:e.tool,target:e.target,...void 0!==e.summary?{summary:e.summary}:{},retryInput:{toolActionApproval:{id:r}}}}function st(e){return at(),!!ct(e)&&(rt.delete(e.approval.id),!0)}function ct(e){at();const t=rt.get(e.approval.id);return void 0!==t&&!!ot(e.subject,t)}var lt=["log","deny","confirm"],dt=Qe.enum(lt),ut=["zhipin_send_prepared_reply"],mt=["unknown_tool_policy","double_confirmation","browser_action_policy_not_recommended"],pt=Qe.object({code:Qe.enum(mt),message:Qe.string()}),gt=Qe.object({policy:dt}),ft=Qe.object({approvalTtlMs:Qe.number().int().positive().max(36e5).default(3e5),tools:Qe.record(gt).default({})}),ht=ft.parse({}),bt=new Set(ut),yt=ht;function vt(e){if(void 0===e)return{};try{return JSON.parse(e)}catch(e){throw new Error(`BROWSER_USE_POLICY_JSON must be valid JSON: ${e instanceof Error?e.message:String(e)}`)}}function wt(e=process.env){try{return ft.parse(vt(e.BROWSER_USE_POLICY_JSON))}catch(e){if(e instanceof Error&&e.message.startsWith("BROWSER_USE_POLICY_JSON must be valid JSON"))throw e;throw new Error(`BROWSER_USE_POLICY_JSON is invalid: ${e instanceof Error?e.message:String(e)}`)}}function xt(e){yt=ft.parse(e)}function St(){return yt}function It(e){const t=e.toolPolicy??yt,n=[];for(const e of Object.keys(t.tools))bt.has(e)||n.push({code:"unknown_tool_policy",message:`BROWSER_USE_POLICY_JSON 配置了未接入 tool-level policy 的工具: ${e}`});return"confirm"===e.browserSecurity.actionPolicy&&Object.values(t.tools).some(e=>"confirm"===e.policy)&&n.push({code:"double_confirmation",message:"BROWSER_SECURITY_JSON.actionPolicy=confirm 与 tool policy confirm 同时启用,可能导致双重确认。"}),"confirm"!==e.browserSecurity.actionPolicy&&"deny"!==e.browserSecurity.actionPolicy||n.push({code:"browser_action_policy_not_recommended",message:"BROWSER_SECURITY_JSON.actionPolicy=confirm/deny 是高级调试模式,Boss 日常编排建议使用 actionPolicy=log。"}),n}function Ct(e,t){const n=yt.tools[t.subject.tool],r=n?.policy??"log";if("log"===r)return e.logger.info(`Browser-use tool allowed by tool policy: ${t.subject.tool}`),{consumeApproval:()=>{}};if("deny"===r){const n="Tool execution denied by browser-use tool policy.";throw e.logger.warn(`${n} ${JSON.stringify(Rt(t.subject,"tool_policy_deny"))}`),new Ze({code:"action_denied",message:n,details:Rt(t.subject,"tool_policy_deny")})}if(void 0!==t.approval&&(!0===t.deferApprovalConsumption?ct({approval:t.approval,subject:t.subject}):st({approval:t.approval,subject:t.subject})))return e.logger.info(`Browser-use tool approved by toolActionApproval: ${t.subject.tool}`),{consumeApproval:()=>{!0===t.deferApprovalConsumption&&void 0!==t.approval&&st({approval:t.approval,subject:t.subject})}};const a="Tool execution requires confirmation by browser-use tool policy.",o={...Rt(t.subject,"tool_policy_confirm"),approvalRequest:it(t.subject,yt.approvalTtlMs)};throw e.logger.warn(`${a} ${JSON.stringify(Rt(t.subject,"tool_policy_confirm"))}`),new Ze({code:"needs_confirmation",message:a,details:o})}function Rt(e,t){return{reason:t,tool:e.tool,target:e.target,...void 0!==e.summary?{summary:e.summary}:{}}}var kt=Re.extend({replyAuthorityKeysLoaded:Ie.boolean(),visualCursorEnabled:Ie.boolean(),visualActivityEnabled:Ie.boolean(),security:Ce,toolPolicy:ft,policyWarnings:Ie.array(pt),effectiveEnvSources:Pe}),At=Se({name:"browser_status",description:"查询浏览器运行状态和活跃 session 信息",input:Ie.object({}),output:kt,execute:async(e,t)=>{t.logger.info("Querying browser status");const n=ge(),r=n.listBundles(),a=n.resolvePrimaryInstanceId(),o=r.find(e=>e.id===a)??r[0];if(void 0===o)throw new Error("BrowserInstancePool has no runtime bundles.");const i=r.some(e=>e.runtime.isRunning()),{headless:s,mode:c,security:l}=o.runtime.getConfig(),d=St(),u=[];for(const e of r){const t=e.runtime,n=e.contextManager,r=e.sessionStore,a=n.getActivePlatforms();for(const o of a){const a=n.getPageCount(o),i=n.getCurrentUrl(o);let s=null,c="unknown";if(t.shouldRestoreSessionSnapshot()){const[e,t]=await Promise.all([r.loadCookies(o),r.loadLocalStorage(o)]);s=void 0!==e&&e.length>0||void 0!==t&&Object.keys(t).length>0,c=s?"snapshot":"none"}else t.usesPersistentProfile()&&(s=null,c="profile");u.push({browserInstance:e.id,platform:o,pagesOpen:a,currentUrl:i,hasLoginState:s,loginStateSource:c})}}return{running:i,headless:s,mode:c,activeSessions:u,defaultInstanceId:n.getDefaultInstanceId(),primaryInstanceId:a,instances:await n.getInstanceStatuses(),replyAuthorityKeysLoaded:pe(),visualCursorEnabled:ze(),visualActivityEnabled:Xe(),security:l,toolPolicy:d,policyWarnings:It({browserSecurity:l,toolPolicy:d}),effectiveEnvSources:Te(Ne)}}});import{BrowserRuntimeModeSchema as Nt}from"@roll-agent/browser";import{StructuredToolError as Mt,defineTool as Et}from"@roll-agent/sdk";import{z as Pt}from"zod";var Tt=Pt.object({browserInstance:Pt.string().trim().min(1).optional(),browserInstances:Pt.array(Pt.string().trim().min(1)).min(1).optional(),all:Pt.boolean().optional()}).superRefine((e,t)=>{const n=void 0!==e.browserInstance||void 0!==e.browserInstances&&e.browserInstances.length>0;e.all&&n&&t.addIssue({code:Pt.ZodIssueCode.custom,path:["all"],message:"all cannot be combined with browserInstance or browserInstances"})}),_t=Pt.object({browserInstance:Pt.string(),status:Pt.enum(U),mode:Nt.optional(),message:Pt.string().optional()}),Bt=Pt.object({ok:Pt.boolean(),stopped:Pt.number().int().nonnegative(),results:Pt.array(_t)}),Ot=Et({name:"browser_stop",description:"关闭 browser-use-agent 当前托管的一个、多个或全部浏览器实例;不停止 browser-use-agent 服务进程。",input:Tt,output:Bt,execute:async(e,t)=>{const n=ge(),r=$t(e,n.listBundles().map(e=>e.id));t.logger.info(`Stopping browser instances: ${r.join(", ")}`);return Dt(await n.closeInstances(r))}});function $t(e,t){if(!0===e.all)return t;const n=[...void 0!==e.browserInstance?[e.browserInstance]:[],...e.browserInstances??[]],r=[...new Set(n)];if(0===r.length)throw new Mt({code:"needs_input",message:"browserInstance, browserInstances, or all is required.",details:{availableInstances:t}});return r}function Dt(e){return{ok:e.every(e=>"not_found"!==e.status&&"failed"!==e.status),stopped:e.filter(e=>"stopped"===e.status).length,results:[...e]}}import{defineTool as qt}from"@roll-agent/sdk";import{BrowserPageInfoSchema as Ft,PlatformSchema as jt}from"@roll-agent/browser";import{z as Lt}from"zod";import{PLATFORMS as zt}from"@roll-agent/browser";var Jt={zhipin:"https://www.zhipin.com",yupao:"https://www.yupao.com"};function Ut(e){return new URL(Jt[e]).host}function Vt(e,t){try{return new URL(e).host.includes(Ut(t))}catch{return!1}}function Ht(e){return zt.find(t=>Vt(e,t))}function Wt(e,t){const n=Ht(t.url)??null;return{pageId:t.targetId,url:t.url,title:t.title,boundPlatform:e.getBoundPlatformForNativePage(t.targetId)??null,detectedPlatform:n,isSelectedForPlatform:e.isNativePageSelected(t.targetId)}}async function Kt(e,t){const n=t.url();return{pageId:e.getPageId(t),url:n,title:await t.title().catch(()=>""),boundPlatform:e.getBoundPlatformForPage(t)??null,detectedPlatform:Ht(n)??null,isSelectedForPlatform:e.isSelectedPageForPlatform(t)}}var Yt=Lt.object({platform:jt.optional().describe("可选:仅返回指定平台相关的页面")}),Gt=Lt.object({pages:Lt.array(Ft)}),Xt=qt({name:"list_pages",description:"通过原生 CDP 列出当前浏览器可见页面及其可选择的 pageId;登录前该值等同于原生 targetId。",input:Yt,output:Gt,execute:async(e,t)=>{const n=ue();t.logger.info("Listing browser pages");const r=(await n.listNativePages()).map(e=>Wt(n,e));return{pages:void 0===e.platform?r:r.filter(t=>t.boundPlatform===e.platform||t.detectedPlatform===e.platform)}}});import{setTimeout as Zt}from"node:timers/promises";import{defineTool as Qt}from"@roll-agent/sdk";import{BrowserActionApprovalSchema as en,BrowserPageInfoSchema as tn}from"@roll-agent/browser";import{z as nn}from"zod";import{StructuredToolError as rn}from"@roll-agent/sdk";import{isBrowserActionPolicyError as an,preflightBrowserAction as on}from"@roll-agent/browser";import{randomUUID as sn}from"node:crypto";var cn=6e4,ln=new Map;function dn(e=Date.now()){for(const[t,n]of ln)n.expiresAtMs<=e&&ln.delete(t)}function un(e,t){return e.action===t.action&&e.target===t.target&&(e.url??void 0)===(t.url??void 0)}function mn(e,t=Date.now()){dn(t);const n=sn(),r=t+cn,a={id:n,action:e.action,target:e.target,...void 0!==e.url?{url:e.url}:{},expiresAtMs:r};return ln.set(n,a),{id:n,expiresAt:new Date(r).toISOString(),action:e.action,target:e.target,...void 0!==e.url?{url:e.url}:{},retryInput:{browserActionApproval:{id:n}}}}function pn(e){dn();const t=ln.get(e.approval.id);return void 0!==t&&(!!un(e.details,t)&&(ln.delete(e.approval.id),!0))}function gn(e,t){const n=e.getConfig().security;return!0===t.approvedByConfirmation&&"confirm"===n.actionPolicy?{...n,actionPolicy:"log"}:n}function fn(e,t,n={}){return{security:gn(t,n),approveAction:pn,...void 0!==n.approval?{approval:n.approval}:{},...!1===n.logActions?{}:{onActionLog:t=>{e.logger.info(t)}}}}function hn(e,t,n){const r=on({security:t.getConfig().security,action:n.action,target:n.target,...void 0!==n.url?{url:n.url}:{}});if(r.ok)return r.log&&e.logger.info(r.message),{approvedByConfirmation:!1};if("needs_confirmation"===r.code&&void 0!==n.approval&&pn({approval:n.approval,details:r.details}))return e.logger.info(`Browser action approved by browserActionApproval: ${n.action} ${n.target}`),{approvedByConfirmation:!0};throw e.logger.warn(`${r.message} ${JSON.stringify(r.details)}`),new rn({code:r.code,message:r.message,details:{...r.details,..."needs_confirmation"===r.code?{approvalRequest:mn(r.details)}:{}}})}function bn(e){if(an(e))return new rn({code:e.payload.code,message:e.payload.message,details:{...e.payload.details,..."needs_confirmation"===e.payload.code?{approvalRequest:mn(e.payload.details)}:{}}})}function yn(){try{return de()}catch{return}}async function vn(e){await e.bringToFront().catch(()=>{})}async function wn(e,t={}){const n=t.runtime??yn();if(void 0===n)return;const r=n.getConfig().security.foregroundPolicy;if("never"===r)return;if("always"===r)return void await vn(e);const a=n.getNativePageWindowState;if("function"!=typeof a)return;"minimized"===await a.call(n,e.targetId).catch(()=>"unknown")&&await vn(e)}var xn,Sn=15e3,In=250,Cn=["/web/chat"],Rn=nn.object({url:nn.string().url().describe("要导航到的目标 URL"),browserActionApproval:en.optional().describe("当 actionPolicy=confirm 返回 needs_confirmation 后,由 orchestrator 原样带回的批准 ID。")}),kn=nn.object({success:nn.boolean(),page:tn});function An(){return{getContextManager:ue,getRuntime:de,detectPlatformFromUrl:Ht,matchesPlatformHost:Vt,toNativePageInfo:Wt,delay:Zt,...xn}}function Nn(e){return"object"==typeof e&&null!==e}function Mn(e){return!!Nn(e)&&("string"==typeof e.url&&"string"==typeof e.title&&"string"==typeof e.readyState)}function En(e,t){if("zhipin"!==t)return;const n=new URL(e).pathname;if(void 0!==Cn.find(e=>n===e||n.startsWith(`${e}/`)))throw new Error("navigate_active_tab 不支持直接导航 BOSS 后台聊天/推荐路径;请使用 zhipin_open_chat_page 或 zhipin_open_recommend_page。")}async function Pn(e,t,n,r,a){const o=n.detectPlatformFromUrl(r),i=await t.listNativePages();if(o){const s=i.find(e=>n.matchesPlatformHost(e.url,o));if(s)return a.info(`Reusing native ${o} page for navigation`),await t.activateNativePage(s.targetId),e.rememberNativePageSelection(o,s),{page:s,platform:o};a.info(`Opening native ${o} page for navigation`);const c=await t.openNativePage(r);return e.rememberNativePageSelection(o,c),{page:c,platform:o}}return a.info("Opening a new native page for non-platform navigation"),{page:await t.openNativePage(r)}}async function Tn(e){const t=await e.evaluateJson("(() => ({ url: location.href, title: document.title, readyState: document.readyState }))()");if(!Mn(t))throw new Error("Native CDP Runtime.evaluate returned an unexpected page load state.");return t}async function _n(e,t,n,r){const a=Date.now();let o;for(;Date.now()-a<Sn;){try{const t=await Tn(e);if(("interactive"===t.readyState||"complete"===t.readyState)&&Bn(t.url,n,r))return t}catch(e){o=e instanceof Error?e:new Error(String(e))}await t.delay(In)}throw new Error(`Native navigation did not reach document ready state within ${Sn}ms${o?`: ${o.message}`:""}`)}function Bn(e,t,n){if(e===t)return!0;try{const t=new URL(e);return("http:"===t.protocol||"https:"===t.protocol)&&e!==n}catch{return!1}}async function On(e,t,n){t.url!==n&&await e.navigate(n)}async function $n(e,t,n){return{...(await e.listNativePages()).find(e=>e.targetId===t.targetId)??t,url:n.url,title:n.title}}var Dn=Qt({name:"navigate_active_tab",description:"通过 native CDP 打开或导航页面;已知平台优先复用平台 tab,不触发 Playwright attach,不直接跳转 BOSS 后台聊天/推荐路径。",input:Rn,output:kn,execute:async(e,t)=>{const n=An(),r=n.getContextManager(),a=n.getRuntime(),o=n.detectPlatformFromUrl(e.url);En(e.url,o);const i=hn(t,a,{action:"navigate",target:e.url,url:e.url,...void 0!==e.browserActionApproval?{approval:e.browserActionApproval}:{}});t.logger.info(`Native navigating to ${e.url}`);const s=await Pn(r,a,n,e.url,t.logger),c=await a.connectNativePage(s.page,{...fn(t,a,{approval:e.browserActionApproval,approvedByConfirmation:i.approvedByConfirmation,logActions:!1})});try{await wn({targetId:s.page.targetId,bringToFront:async()=>{await c.bringToFront()}},{runtime:a}),await On(c,s.page,e.url);const o=await _n(c,n,e.url,s.page.url),i=await $n(a,s.page,o),l=s.platform??n.detectPlatformFromUrl(i.url);return l&&(r.rememberNativePageSelection(l,i),t.logger.info(`Bound native navigated page to ${l}`)),{success:!0,page:n.toNativePageInfo(r,i)}}finally{c.close()}}});import{BrowserActionApprovalSchema as qn,BrowserPageInfoSchema as Fn}from"@roll-agent/browser";import{defineTool as jn}from"@roll-agent/sdk";import{z as Ln}from"zod";import{setTimeout as zn}from"node:timers/promises";var Jn=15e3,Un=250,Vn="__rollReloadMark";function Hn(e){return"object"==typeof e&&null!==e}function Wn(e){if(!Hn(e))return!1;const t=e.mark;return(null===t||"string"==typeof t)&&"string"==typeof e.readyState}function Kn(){return`roll-reload-${String(Date.now())}-${Math.random().toString(36).slice(2)}`}async function Yn(e){const t=await e.evaluateJson(`(() => ({ mark: window.${Vn} ?? null, readyState: document.readyState }))()`);if(!Wn(t))throw new Error("Native CDP Runtime.evaluate returned an unexpected reload state.");return t}async function Gn(e,t){const n=(t.createToken??Kn)(),r=t.now??(()=>Date.now()),a=t.delay??zn,o=t.timeoutMs??Jn,i=t.pollMs??Un;await e.evaluateJson(`(() => { window.${Vn} = ${JSON.stringify(n)}; return true; })()`),await e.reload({url:t.url,...void 0!==t.ignoreCache?{ignoreCache:t.ignoreCache}:{}}),t.onReloadSent?.();const s=r();let c;for(;r()-s<o;){try{const t=await Yn(e);if(t.mark!==n&&("interactive"===t.readyState||"complete"===t.readyState))return}catch(e){c=e instanceof Error?e:new Error(String(e))}await a(i)}throw new Error(`Native page reload did not swap document within ${String(o)}ms${c?`: ${c.message}`:""}`)}var Xn,Zn=Ln.object({ignoreCache:Ln.boolean().optional().describe("是否绕过缓存强制重新拉取资源(等价 Ctrl+Shift+R),默认 false。"),browserActionApproval:qn.optional().describe("当 actionPolicy=confirm 返回 needs_confirmation 后,由 orchestrator 原样带回的批准 ID。")}),Qn=Ln.object({success:Ln.boolean(),reloaded:Ln.boolean(),page:Fn});function er(){return{getContextManager:ue,getRuntime:de,toNativePageInfo:Wt,reloadNativePageAndWaitForSwap:Gn,...Xn}}function tr(e,t){const n=t.filter(t=>e.isNativePageSelected(t.targetId));if(1===n.length){const e=n[0];if(e)return e}if(n.length>1)throw new Error("Multiple selected native tabs found; select a single tab before reloading.");if(1===t.length){const e=t[0];if(e)return e}if(0===t.length)throw new Error("No native page is open; navigate before reloading.");throw new Error("Multiple native pages are open and none is selected; select the target tab before reloading.")}var nr=jn({name:"browser_reload_active_tab",description:"对当前 tracked native page 执行 CDP Page.reload,清空页面内 DOM 与 SPA 状态后等待文档完成换页;不触发 Playwright attach,走现有 actionPolicy / domainAllowlist 边界。",input:Zn,output:Qn,execute:async(e,t)=>{const n=er(),r=n.getContextManager(),a=n.getRuntime(),o=tr(r,await a.listNativePages()),i=hn(t,a,{action:"navigate",target:o.url,url:o.url,...void 0!==e.browserActionApproval?{approval:e.browserActionApproval}:{}});t.logger.info(`Reloading native tab ${o.targetId} (${o.url})`);const s=await a.connectNativePage(o,{...fn(t,a,{approval:e.browserActionApproval,approvedByConfirmation:i.approvedByConfirmation,logActions:!1})});try{await wn({targetId:o.targetId,bringToFront:async()=>{await s.bringToFront()}},{runtime:a}),await n.reloadNativePageAndWaitForSwap(s,{url:o.url,...void 0!==e.ignoreCache?{ignoreCache:e.ignoreCache}:{}});const t=(await a.listNativePages()).find(e=>e.targetId===o.targetId)??o;return{success:!0,reloaded:!0,page:n.toNativePageInfo(r,t)}}finally{s.close()}}});import{defineTool as rr}from"@roll-agent/sdk";import{BrowserActionApprovalSchema as ar,BrowserPageInfoSchema as or,PlatformSchema as ir}from"@roll-agent/browser";import{z as sr}from"zod";async function cr(e,t){return(await e.listNativePages()).find(e=>Vt(e.url,t))}async function lr(e,t,n={}){const r=await cr(e,t);if(r)return await e.activateNativePage(r.targetId),{page:r,reusedExistingPage:!0};return{page:await e.openNativePage(Jt[t],n),reusedExistingPage:!1}}var dr=sr.object({platform:ir.describe("目标平台:`zhipin` 代表 BOSS直聘,`yupao` 代表鱼泡"),browserActionApproval:ar.optional().describe("当 actionPolicy=confirm 返回 needs_confirmation 后,由 orchestrator 原样带回的批准 ID。")}),ur=sr.object({success:sr.boolean(),page:or,reusedExistingTab:sr.boolean()}),mr=rr({name:"open_platform",description:"打开并聚焦招聘平台主页,供用户手动登录或后续执行站内操作。",input:dr,output:ur,execute:async(e,t)=>{const{platform:n}=e,r=de(),a=ue(),o=Jt[n],i=hn(t,r,{action:"navigate",target:o,url:o,...void 0!==e.browserActionApproval?{approval:e.browserActionApproval}:{}});t.logger.info(`Opening platform page for ${n}`);const{page:s,reusedExistingPage:c}=await lr(r,n,fn(t,r,{approval:e.browserActionApproval,approvedByConfirmation:i.approvedByConfirmation,logActions:!1}));return a.rememberNativePageSelection(n,s),{success:!0,page:Wt(a,s),reusedExistingTab:c}}});import{defineTool as pr}from"@roll-agent/sdk";import{BrowserPageInfoSchema as gr,PlatformSchema as fr}from"@roll-agent/browser";import{z as hr}from"zod";var br=hr.object({platform:fr.describe("要将该页面绑定为当前活跃页的平台"),pageId:hr.string().describe("通过 list_pages 返回的 pageId;登录前就是原生 targetId,登录后仍可作为稳定选择句柄")}),yr=hr.object({success:hr.boolean(),page:gr}),vr=pr({name:"select_page",description:"将指定 pageId 绑定为平台当前活跃页,并切换到前台;登录前走原生 CDP target 激活。",input:br,output:yr,execute:async(e,t)=>{const n=ue();t.logger.info(`Selecting page ${e.pageId} for ${e.platform}`);const r=await n.selectNativePage(e.platform,e.pageId);return{success:!0,page:Wt(n,r)}}});import{defineTool as wr}from"@roll-agent/sdk";import{BrowserAxSnapshotSchema as xr,BrowserPageInfoSchema as Sr,createBrowserAxSnapshot as Ir}from"@roll-agent/browser";import{z as Cr}from"zod";import{BrowserElementRefStore as Rr}from"@roll-agent/browser";var kr=new Rr;async function Ar(e){const t=await e.runtime.listNativePages();if(void 0!==e.pageId){const n=t.find(t=>t.targetId===e.pageId);if(void 0===n)throw new Error(`Page "${e.pageId}" not found. Run list_pages to inspect pageId values.`);return n}const n=t.filter(t=>e.ctxManager.isNativePageSelected(t.targetId));if(1===n.length&&void 0!==n[0])return n[0];if(1===t.length&&void 0!==t[0])return t[0];throw new Error("browser_snapshot/click_ref/type_ref need pageId when multiple native pages are open. Run list_pages first.")}import{randomUUID as Nr}from"node:crypto";var Mr="data-roll-browser-action-",Er=120;function Pr(){return`${Mr}${Nr().replaceAll("-","")}`}function Tr(e){return Number.isFinite(e)?Math.max(0,Math.min(Math.trunc(e),Er)):Er}function _r(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function Br(e){if(!_r(e)||!_r(e.root))return;const t=e.root.nodeId;return"number"==typeof t&&Number.isInteger(t)?t:void 0}function Or(e){if(Array.isArray(e)&&!e.some(e=>"string"!=typeof e))return e}function $r(e){return Array.isArray(e)?e.flatMap(e=>{const t=Dr(e);return void 0===t?[]:[t]}):[]}function Dr(e){if(!_r(e))return;const t=e.nodeId,n=e.backendNodeId,r=Or(e.attributes),a=Dr(e.contentDocument),o=Dr(e.templateContent);return{..."number"==typeof t&&Number.isInteger(t)?{nodeId:t}:{},..."number"==typeof n&&Number.isInteger(n)?{backendNodeId:n}:{},...void 0!==r?{attributes:r}:{},children:$r(e.children),...void 0!==a?{contentDocument:a}:{},pseudoElements:$r(e.pseudoElements),shadowRoots:$r(e.shadowRoots),...void 0!==o?{templateContent:o}:{}}}function qr(e,t){if(void 0!==t)for(let n=0;n<t.length-1;n+=2)if(t[n]===e)return t[n+1]}function Fr(e){if(!_r(e))return;const t=e.marker,n=e.name;return"string"==typeof t&&"string"==typeof n&&0!==n.trim().length?{marker:t,name:n.trim(),disabled:!0===e.disabled,hasClassHint:!0===e.hasClassHint,hasCursorPointer:!0===e.hasCursorPointer,hasOnClick:!0===e.hasOnClick,hasTabIndex:!0===e.hasTabIndex,isEditable:!0===e.isEditable}:void 0}function jr(e){return Array.isArray(e)?e.flatMap(e=>{const t=Fr(e);return void 0===t?[]:[t]}):[]}function Lr(e){return e.isEditable?"editable":e.hasCursorPointer||e.hasOnClick||e.hasClassHint?"clickable":"focusable"}function zr(e){const t=[];return e.hasCursorPointer&&t.push("cursor:pointer"),e.hasOnClick&&t.push("onclick"),e.hasTabIndex&&t.push("tabindex"),e.isEditable&&t.push("contenteditable"),e.hasClassHint&&t.push("class:action"),t}function Jr(e,t){const n=new Map;for(const r of t){const t=qr(e,r.attributes);void 0!==t&&void 0!==r.backendNodeId&&n.set(t,r.backendNodeId)}return n}function Ur(e,t){const n=new Map,r=t=>{const a=qr(e,t.attributes);void 0!==a&&void 0!==t.backendNodeId&&n.set(a,t.backendNodeId);for(const e of t.children)r(e);void 0!==t.contentDocument&&r(t.contentDocument);for(const e of t.pseudoElements)r(e);for(const e of t.shadowRoots)r(e);void 0!==t.templateContent&&r(t.templateContent)};return r(t),n}function Vr(e,t){return`(() => {\n const markerAttribute = ${JSON.stringify(e)};\n const maxCandidates = ${JSON.stringify(t)};\n const normalize = (value) => String(value ?? "").replace(/\\s+/g, " ").trim();\n const classTextOf = (element) => String(element.getAttribute("class") ?? "");\n const directTextOf = (element) => normalize(Array.from(element.childNodes)\n .filter((node) => node.nodeType === Node.TEXT_NODE)\n .map((node) => node.textContent ?? "")\n .join(" "));\n const visibleTextOf = (element) => normalize(\n element instanceof HTMLElement ? element.innerText : element.textContent\n );\n const hasCompositeOptionHint = (element) => {\n const pattern = /dropdown|menu|option|select|item/i;\n let current = element;\n for (let depth = 0; current && depth < 4; depth += 1) {\n if (pattern.test(classTextOf(current))) return true;\n current = current.parentElement;\n }\n return false;\n };\n const domActionNameOf = (element) => {\n const direct = directTextOf(element);\n if (direct) return direct;\n if (element.childElementCount === 0) return visibleTextOf(element);\n if (hasCompositeOptionHint(element)) return visibleTextOf(element);\n return "";\n };\n const isVisible = (element) => {\n if (element.closest("[hidden], [aria-hidden=\\"true\\"]")) return false;\n const style = window.getComputedStyle(element);\n if (style.visibility === "hidden" || style.display === "none") return false;\n const rect = element.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0;\n };\n const isDisabled = (element) =>\n element.matches(":disabled") ||\n element.getAttribute("aria-disabled") === "true" ||\n element.getAttribute("disabled") !== null;\n const isNativeSemantic = (element) => {\n const tag = element.tagName.toLowerCase();\n return (\n (tag === "a" && element.hasAttribute("href")) ||\n tag === "button" ||\n tag === "input" ||\n tag === "textarea" ||\n tag === "select" ||\n tag === "option" ||\n tag === "summary" ||\n element.hasAttribute("role")\n );\n };\n const hasNearbyClassHint = (element) => {\n const pattern = /btn|button|click|dropdown|tab|tabs|filter|menu|nav|option|select|switch|toggle/i;\n let current = element;\n for (let depth = 0; current && depth < 4; depth += 1) {\n if (pattern.test(classTextOf(current))) return true;\n current = current.parentElement;\n }\n return false;\n };\n const isCandidate = (element) => {\n if (!isVisible(element) || isNativeSemantic(element)) return false;\n const tag = element.tagName.toLowerCase();\n if (!["span", "div", "li", "label", "em", "i", "b", "strong"].includes(tag)) return false;\n const name = domActionNameOf(element);\n if (name.length === 0 || name.length > 100) return false;\n const style = window.getComputedStyle(element);\n const hasCursorPointer = style.cursor === "pointer";\n const hasOnClick = element.hasAttribute("onclick") || element.onclick !== null;\n const hasTabIndex = element.getAttribute("tabindex") !== null && element.getAttribute("tabindex") !== "-1";\n const contentEditable = element.getAttribute("contenteditable");\n const isEditable = contentEditable === "" || contentEditable === "true";\n const hasClassHint = hasNearbyClassHint(element);\n\n if (!hasCursorPointer && !hasOnClick && !hasTabIndex && !isEditable && !hasClassHint) {\n return false;\n }\n\n if (hasCursorPointer && !hasOnClick && !hasTabIndex && !isEditable && !hasClassHint) {\n const parent = element.parentElement;\n if (parent && window.getComputedStyle(parent).cursor === "pointer") return false;\n }\n return true;\n };\n const output = [];\n for (const element of document.querySelectorAll("body *")) {\n if (!isCandidate(element)) continue;\n if (element.closest("[" + markerAttribute + "]")) continue;\n const marker = String(output.length);\n const style = window.getComputedStyle(element);\n const contentEditable = element.getAttribute("contenteditable");\n element.setAttribute(markerAttribute, marker);\n output.push({\n marker,\n name: domActionNameOf(element),\n disabled: isDisabled(element),\n hasClassHint: hasNearbyClassHint(element),\n hasCursorPointer: style.cursor === "pointer",\n hasOnClick: element.hasAttribute("onclick") || element.onclick !== null,\n hasTabIndex: element.getAttribute("tabindex") !== null && element.getAttribute("tabindex") !== "-1",\n isEditable: contentEditable === "" || contentEditable === "true"\n });\n if (output.length >= maxCandidates) break;\n }\n return output;\n })()`}function Hr(e){return`(() => {\n const markerAttribute = ${JSON.stringify(e)};\n const elements = document.querySelectorAll("[" + markerAttribute + "]");\n for (const element of elements) {\n element.removeAttribute(markerAttribute);\n }\n return elements.length;\n })()`}async function Wr(e,t,n){if(void 0!==n.frameId){const n=await e.getDocument({depth:-1,pierce:!0});if(!_r(n))return new Map;const r=Dr(n.root);return void 0===r?new Map:Ur(t,r)}const r=Br(await e.getDocument({depth:0}));if(void 0===r)return new Map;const a=await e.querySelectorAllByNodeId({nodeId:r,selector:`[${t}]`});return Jr(t,await Promise.all(a.map(async t=>await e.describeNode({nodeId:t}))))}async function Kr(e,t={}){const n="number"==typeof t?{maxCandidates:t}:t,r=Tr(n.maxCandidates??Er);if(0===r)return[];const a=Pr(),o=void 0===n.frameId?void 0:await e.createIsolatedWorld(n.frameId,{worldName:`roll-dom-action-${a.slice(Mr.length)}`}).catch(()=>{});if(void 0!==n.frameId&&void 0===o)return[];const i=void 0===o?{}:{contextId:o},s=jr(await e.evaluateJson(Vr(a,r),i).catch(()=>[]));try{if(0===s.length)return[];const t=await Wr(e,a,n);return s.flatMap(e=>{const n=t.get(e.marker);return void 0===n?[]:[{backendNodeId:n,kind:Lr(e),name:e.name,hints:zr(e),disabled:e.disabled}]})}finally{await e.evaluateJson(Hr(a),i).catch(()=>{})}}var Yr=28,Gr=90,Xr=250,Zr=620,Qr=8,ea=32,ta=8;function na(e){return new Promise(t=>{setTimeout(t,e)})}function ra(e,t,n){return Math.min(Math.max(e,t),n)}function aa(e,t){return Math.max(0,Math.floor(e??t))}function oa(e){return{x:Math.round(Number.isFinite(e.x)?e.x:0),y:Math.round(Number.isFinite(e.y)?e.y:0)}}function ia(e,t){return Math.hypot(t.x-e.x,t.y-e.y)}function sa(e){return e<.5?4*e*e*e:1-Math.pow(-2*e+2,3)/2}function ca(e){const t=e.x>=96?-72:72,n=e.y>=72?-36:36;return{x:Math.max(1,e.x+t),y:Math.max(1,e.y+n)}}function la(e,t){return Math.round(e.x+e.y+t.x+t.y)%2==0?1:-1}function da(e,t){const n=ia(e,t);if(n<=Qr)return[e,t];const r=ra(Math.round(n/30),ta,ea),a=t.x-e.x,o=t.y-e.y,i=Math.max(n,1),s=-o/i,c=a/i,l=ra(.08*n,4,28)*la(e,t),d=[e];for(let i=1;i<r;i+=1){const u=i/r,m=sa(u),p=Math.sin(Math.PI*u)*l,g=Math.sin(.13*(e.x+t.y+17*i))*Math.min(1.8,n/180);d.push({x:Math.round(e.x+a*m+s*(p+g)),y:Math.round(e.y+o*m+c*(p+g))})}return d.push(t),d}function ua(e,t){const n=oa(t);return da(void 0===e?ca(n):oa(e),n)}var ma=class{dispatcher;sleep;defaultStepDelayMs;lastPoint;constructor(e,t={}){this.dispatcher=e,this.sleep=t.sleep??na,this.defaultStepDelayMs=aa(t.stepDelayMs,Yr)}reset(e){this.lastPoint=void 0===e?void 0:oa(e)}async moveTo(e,t={}){const n=aa(t.stepDelayMs,this.defaultStepDelayMs),r=ua(this.lastPoint,e),a=Math.max(r.length-1,0)*n;await(t.motionObserver?.previewMouseMotion({points:r,durationMs:a}));for(let e=0;e<r.length;e+=1){const a=r[e];void 0!==a&&(await this.dispatcher.dispatchMouseEvent({type:"mouseMoved",x:a.x,y:a.y,...void 0!==t.button?{button:t.button}:{},buttons:t.buttons??0}),e<r.length-1&&n>0&&await this.sleep(n))}return this.lastPoint=oa(e),{points:r,durationMs:a}}async click(e,t={}){const n=t.button??"left",r=t.clickCount??1;await this.moveTo(e,{button:"none",buttons:0,...void 0!==t.motionObserver?{motionObserver:t.motionObserver}:{}}),await this.delayIfPositive(t.preClickDelayMs),await(t.motionObserver?.previewMouseClick?.({point:oa(e),durationMs:Zr})),await this.dispatcher.dispatchMouseEvent({type:"mousePressed",x:Math.round(e.x),y:Math.round(e.y),button:n,buttons:"left"===n?1:0,clickCount:r}),await this.delayIfPositive(t.pressDurationMs??Gr),await this.dispatcher.dispatchMouseEvent({type:"mouseReleased",x:Math.round(e.x),y:Math.round(e.y),button:n,buttons:0,clickCount:r}),await this.delayIfPositive(t.settleMs??Xr),this.lastPoint=oa(e)}async drag(e,t,n={}){await this.moveTo(e,{button:"none",buttons:0,...void 0!==n.motionObserver?{motionObserver:n.motionObserver}:{},...void 0!==n.stepDelayMs?{stepDelayMs:n.stepDelayMs}:{}}),await this.dispatcher.dispatchMouseEvent({type:"mousePressed",x:Math.round(e.x),y:Math.round(e.y),button:"left",buttons:1,clickCount:1}),await this.delayIfPositive(n.pressDurationMs??Gr),this.reset(e),await this.moveTo(t,{button:"left",buttons:1,...void 0!==n.motionObserver?{motionObserver:n.motionObserver}:{},...void 0!==n.stepDelayMs?{stepDelayMs:n.stepDelayMs}:{}}),await this.dispatcher.dispatchMouseEvent({type:"mouseReleased",x:Math.round(t.x),y:Math.round(t.y),button:"left",buttons:0,clickCount:1}),this.lastPoint=oa(t)}async delayIfPositive(e){const t=Math.max(0,Math.floor(e??0));t>0&&await this.sleep(t)}},pa=14,ga=720;function fa(e){return`(() => {\n const args = ${JSON.stringify(e)};\n const activityRootId = "roll-agent-visual-activity-root";\n const activityViewportId = "roll-agent-visual-activity-viewport";\n const activityRegionId = "roll-agent-visual-activity-region";\n const activityCapsuleId = "roll-agent-visual-activity-capsule";\n const activityDotId = "roll-agent-visual-activity-dot";\n const activityLabelId = "roll-agent-visual-activity-label";\n const cursorRootId = "roll-agent-visual-cursor-root";\n const cursorPointerId = "roll-agent-visual-cursor-pointer";\n const cursorStateKey = "__rollVisualCursorState";\n\n const themes = {\n info: {\n accent: "#14b8a6",\n accentSoft: "rgba(20, 184, 166, 0.42)",\n accentGlow: "rgba(20, 184, 166, 0.18)",\n capsuleBg: "rgba(15, 23, 42, 0.82)",\n capsuleBorder: "rgba(45, 212, 191, 0.38)",\n text: "#F8FAFC",\n dot: "#2DD4BF"\n },\n success: {\n accent: "#22c55e",\n accentSoft: "rgba(34, 197, 94, 0.42)",\n accentGlow: "rgba(34, 197, 94, 0.18)",\n capsuleBg: "rgba(10, 24, 16, 0.86)",\n capsuleBorder: "rgba(74, 222, 128, 0.38)",\n text: "#F0FDF4",\n dot: "#4ADE80"\n },\n error: {\n accent: "#f59e0b",\n accentSoft: "rgba(245, 158, 11, 0.42)",\n accentGlow: "rgba(245, 158, 11, 0.2)",\n capsuleBg: "rgba(41, 24, 10, 0.88)",\n capsuleBorder: "rgba(251, 191, 36, 0.4)",\n text: "#FFFBEB",\n dot: "#FBBF24"\n }\n };\n\n const readRect = (selector, padding) => {\n if (!selector) return null;\n const element = document.querySelector(selector);\n if (!element) return null;\n const rect = element.getBoundingClientRect();\n if (rect.width <= 0 || rect.height <= 0) return null;\n const safePadding = Math.max(padding ?? 0, 0);\n const left = Math.max(rect.left - safePadding, 0);\n const top = Math.max(rect.top - safePadding, 0);\n const right = Math.min(rect.right + safePadding, window.innerWidth);\n const bottom = Math.min(rect.bottom + safePadding, window.innerHeight);\n return {\n x: Math.round(left),\n y: Math.round(top),\n width: Math.max(Math.round(right - left), 0),\n height: Math.max(Math.round(bottom - top), 0),\n centerX: Math.round(rect.left + rect.width / 2),\n centerY: Math.round(rect.top + rect.height / 2)\n };\n };\n\n const normalizeActivityViewport = (viewport) => {\n viewport.style.position = "fixed";\n viewport.style.inset = "0";\n viewport.style.opacity = "0";\n viewport.style.pointerEvents = "none";\n viewport.style.display = "none";\n viewport.style.border = "0";\n viewport.style.boxShadow = "none";\n viewport.style.borderRadius = "0";\n viewport.style.transform = "none";\n viewport.style.transition = "none";\n viewport.style.background = "transparent";\n };\n\n const showActivityViewportFrame = (viewport, theme, mode) => {\n normalizeActivityViewport(viewport);\n viewport.style.display = "block";\n viewport.style.opacity = mode === "complete" ? "0.28" : "0.22";\n viewport.style.background =\n "linear-gradient(180deg, " +\n theme.accentGlow +\n " 0%, transparent 16%, transparent 84%, " +\n theme.accentGlow +\n " 100%), linear-gradient(90deg, " +\n theme.accentGlow +\n " 0%, transparent 12%, transparent 88%, " +\n theme.accentGlow +\n " 100%)";\n viewport.style.boxShadow =\n "inset 0 0 0 2px " + theme.accentSoft + ", inset 0 0 28px " + theme.accentGlow;\n };\n\n const ensureActivityRoot = () => {\n let root = document.getElementById(activityRootId);\n if (root) {\n const viewport = document.getElementById(activityViewportId);\n if (viewport) normalizeActivityViewport(viewport);\n return root;\n }\n root = document.createElement("div");\n root.id = activityRootId;\n root.style.position = "fixed";\n root.style.inset = "0";\n root.style.pointerEvents = "none";\n root.style.zIndex = "2147483646";\n\n const viewport = document.createElement("div");\n viewport.id = activityViewportId;\n normalizeActivityViewport(viewport);\n\n const region = document.createElement("div");\n region.id = activityRegionId;\n region.style.position = "fixed";\n region.style.left = "0";\n region.style.top = "0";\n region.style.width = "0";\n region.style.height = "0";\n region.style.borderRadius = "18px";\n region.style.opacity = "0";\n region.style.transform = "translate(-9999px, -9999px)";\n region.style.transition =\n "transform 220ms cubic-bezier(0.22, 1, 0.36, 1), width 220ms ease, height 220ms ease, opacity 180ms ease";\n\n const capsule = document.createElement("div");\n capsule.id = activityCapsuleId;\n capsule.style.position = "fixed";\n capsule.style.left = "50%";\n capsule.style.top = "20px";\n capsule.style.display = "inline-flex";\n capsule.style.alignItems = "center";\n capsule.style.gap = "10px";\n capsule.style.padding = "10px 14px";\n capsule.style.borderRadius = "999px";\n capsule.style.opacity = "0";\n capsule.style.transform = "translate(-50%, -8px)";\n capsule.style.transition = "opacity 180ms ease, transform 220ms ease";\n capsule.style.backdropFilter = "blur(12px)";\n capsule.style.fontSize = "13px";\n capsule.style.fontWeight = "600";\n capsule.style.lineHeight = "18px";\n capsule.style.whiteSpace = "nowrap";\n\n const dot = document.createElement("div");\n dot.id = activityDotId;\n dot.style.width = "8px";\n dot.style.height = "8px";\n dot.style.borderRadius = "999px";\n\n const label = document.createElement("div");\n label.id = activityLabelId;\n label.setAttribute("aria-live", "polite");\n\n capsule.append(dot, label);\n root.append(viewport, region, capsule);\n document.documentElement.append(root);\n return root;\n };\n\n const applyTheme = (themeName, mode) => {\n const theme = themes[themeName] ?? themes.info;\n const viewport = document.getElementById(activityViewportId);\n const region = document.getElementById(activityRegionId);\n const capsule = document.getElementById(activityCapsuleId);\n const dot = document.getElementById(activityDotId);\n if (!viewport || !region || !capsule || !dot) return;\n showActivityViewportFrame(viewport, theme, mode);\n region.style.border = "1px solid " + theme.accentSoft;\n region.style.background = theme.accentGlow;\n region.style.boxShadow =\n "0 0 0 1px " + theme.accentSoft + ", 0 16px 42px " + theme.accentGlow;\n capsule.style.border = "1px solid " + theme.capsuleBorder;\n capsule.style.background = theme.capsuleBg;\n capsule.style.color = theme.text;\n capsule.style.boxShadow =\n "0 18px 46px rgba(15, 23, 42, 0.24), 0 0 0 1px " + theme.capsuleBorder;\n dot.style.background = theme.dot;\n dot.style.boxShadow = "0 0 0 5px " + theme.accentGlow;\n };\n\n const renderActivity = () => {\n if (!args.activity) return;\n ensureActivityRoot();\n const viewport = document.getElementById(activityViewportId);\n const region = document.getElementById(activityRegionId);\n const capsule = document.getElementById(activityCapsuleId);\n const label = document.getElementById(activityLabelId);\n if (!viewport || !region || !capsule || !label) return;\n\n if (args.activity.mode === "clear") {\n normalizeActivityViewport(viewport);\n region.style.opacity = "0";\n region.style.transform = "translate(-9999px, -9999px)";\n capsule.style.opacity = "0";\n capsule.style.transform = "translate(-50%, -8px)";\n return;\n }\n\n applyTheme(args.activity.tone ?? "info", args.activity.mode);\n\n if (typeof args.activity.label === "string") {\n label.textContent = args.activity.label;\n }\n\n capsule.style.opacity = "1";\n capsule.style.transform = "translate(-50%, 0)";\n\n const rect = args.activity.selector\n ? readRect(args.activity.selector, args.activity.padding ?? 14)\n : null;\n if (rect) {\n region.style.width = rect.width + "px";\n region.style.height = rect.height + "px";\n region.style.transform = "translate(" + rect.x + "px, " + rect.y + "px)";\n region.style.opacity = "1";\n } else {\n region.style.opacity = "0";\n region.style.transform = "translate(-9999px, -9999px)";\n }\n\n if (args.activity.mode === "complete") {\n window.setTimeout(() => {\n normalizeActivityViewport(viewport);\n region.style.opacity = "0";\n capsule.style.opacity = "0";\n capsule.style.transform = "translate(-50%, -8px)";\n }, Math.max(args.activity.lingerMs ?? 720, 0));\n }\n };\n\n const ensureCursorRoot = () => {\n let root = document.getElementById(cursorRootId);\n if (root) return root;\n root = document.createElement("div");\n root.id = cursorRootId;\n root.style.position = "fixed";\n root.style.left = "0";\n root.style.top = "0";\n root.style.width = "0";\n root.style.height = "0";\n root.style.pointerEvents = "none";\n root.style.zIndex = "2147483647";\n\n const pointer = document.createElement("div");\n pointer.id = cursorPointerId;\n pointer.setAttribute("aria-hidden", "true");\n pointer.style.position = "fixed";\n pointer.style.left = "0";\n pointer.style.top = "0";\n pointer.style.width = "24px";\n pointer.style.height = "24px";\n pointer.style.opacity = "0";\n pointer.style.transform = "translate(-9999px, -9999px)";\n pointer.style.willChange = "transform, opacity";\n pointer.style.filter = "drop-shadow(0 4px 8px rgba(15, 23, 42, 0.28))";\n pointer.innerHTML =\n '<svg viewBox="0 0 24 24" width="24" height="24" fill="none" xmlns="http://www.w3.org/2000/svg">' +\n '<path d="M4 2L18 14L11.4 15.3L14.6 22L10.7 23.5L7.6 16.8L3 21V2Z" fill="#FFFFFF" stroke="#0F172A" stroke-width="1.5" stroke-linejoin="round"/>' +\n '</svg>';\n\n root.append(pointer);\n document.documentElement.append(root);\n return root;\n };\n\n const readCursorPath = () => {\n if (!Array.isArray(args.cursor?.path?.points)) return null;\n const points = args.cursor.path.points\n .map((point) => {\n const x = Number(point?.x);\n const y = Number(point?.y);\n return Number.isFinite(x) && Number.isFinite(y)\n ? { centerX: Math.round(x), centerY: Math.round(y) }\n : null;\n })\n .filter((point) => point !== null);\n return points.length > 0 ? points : null;\n };\n\n const readCursorClick = () => {\n const point = args.cursor?.click?.point;\n const x = Number(point?.x);\n const y = Number(point?.y);\n if (!Number.isFinite(x) || !Number.isFinite(y)) return null;\n return {\n point: { centerX: Math.round(x), centerY: Math.round(y) },\n durationMs: Math.max(Number(args.cursor?.click?.durationMs ?? 620), 0)\n };\n };\n\n const renderClickPulse = (root, point, durationMs) => {\n const createPulse = (size, border, background, shadow, startScale, endScale, delayMs) => {\n const radius = size / 2;\n const pulse = document.createElement("div");\n pulse.setAttribute("aria-hidden", "true");\n pulse.style.position = "fixed";\n pulse.style.left = "0";\n pulse.style.top = "0";\n pulse.style.width = size + "px";\n pulse.style.height = size + "px";\n pulse.style.borderRadius = "9999px";\n pulse.style.border = border;\n pulse.style.background = background;\n pulse.style.boxShadow = shadow;\n pulse.style.pointerEvents = "none";\n pulse.style.opacity = "0.96";\n pulse.style.transformOrigin = "center center";\n pulse.style.transform =\n "translate(" + (point.centerX - radius) + "px, " + (point.centerY - radius) + "px) scale(" + startScale + ")";\n pulse.style.transition =\n "transform " + durationMs + "ms cubic-bezier(0.16, 1, 0.3, 1), opacity " + durationMs + "ms ease-out";\n root.append(pulse);\n\n window.setTimeout(() => {\n window.requestAnimationFrame(() => {\n pulse.style.opacity = "0";\n pulse.style.transform =\n "translate(" + (point.centerX - radius) + "px, " + (point.centerY - radius) + "px) scale(" + endScale + ")";\n });\n }, delayMs);\n\n window.setTimeout(() => {\n pulse.remove();\n }, durationMs + delayMs + 80);\n };\n\n createPulse(\n 28,\n "3px solid rgba(45, 212, 191, 0.98)",\n "rgba(20, 184, 166, 0.24)",\n "0 0 0 5px rgba(20, 184, 166, 0.18), 0 0 26px rgba(20, 184, 166, 0.34)",\n 0.55,\n 2.35,\n 0\n );\n createPulse(\n 14,\n "2px solid rgba(255, 255, 255, 0.95)",\n "rgba(255, 255, 255, 0.34)",\n "0 0 18px rgba(45, 212, 191, 0.45)",\n 0.7,\n 1.55,\n 65\n );\n };\n\n const renderCursor = () => {\n const path = readCursorPath();\n const click = readCursorClick();\n const point = path ? path[path.length - 1] : click?.point ?? null;\n if (!point) return;\n const root = ensureCursorRoot();\n const pointer = document.getElementById(cursorPointerId);\n if (!pointer) return;\n const targetX = point.centerX - 2;\n const targetY = point.centerY - 2;\n if (path && path.length > 1 && typeof pointer.animate === "function") {\n for (const animation of pointer.getAnimations()) {\n animation.cancel();\n }\n pointer.style.opacity = "1";\n const keyframes = path.map((entry) => ({\n transform: "translate(" + (entry.centerX - 2) + "px, " + (entry.centerY - 2) + "px)"\n }));\n const duration = Math.max(args.cursor.path.durationMs ?? 180, 0);\n const animation = pointer.animate(keyframes, {\n duration,\n easing: "cubic-bezier(0.22, 1, 0.36, 1)",\n fill: "forwards"\n });\n animation.onfinish = () => {\n pointer.style.transform = "translate(" + targetX + "px, " + targetY + "px)";\n };\n window[cursorStateKey] = { x: point.centerX, y: point.centerY };\n if (click) {\n renderClickPulse(root, click.point, click.durationMs);\n }\n return;\n }\n pointer.style.transition = "opacity 120ms ease";\n pointer.style.opacity = "1";\n pointer.style.transform = "translate(" + targetX + "px, " + targetY + "px)";\n window[cursorStateKey] = { x: point.centerX, y: point.centerY };\n if (click) {\n renderClickPulse(root, click.point, click.durationMs);\n }\n };\n\n renderActivity();\n renderCursor();\n return true;\n })()`}var ha=class{target;constructor(e){this.target=e}async begin(e,t="info"){return!!Xe()&&await this.render({activity:{mode:"begin",label:e,tone:t}})}async highlightSelector(e,t={}){const n={...Xe()?{activity:{mode:"highlight",selector:e,label:t.label,padding:t.padding??pa,tone:t.tone??"info"}}:{}};return"activity"in n&&await this.render(n)}async previewMouseMotion(e){ze()&&0!==e.points.length&&await this.render({cursor:{path:{points:e.points,durationMs:e.durationMs}}})}async previewMouseClick(e){ze()&&await this.render({cursor:{click:{point:e.point,durationMs:e.durationMs}}})}async succeed(e,t=ga){return!!Xe()&&await this.render({activity:{mode:"complete",label:e,tone:"success",lingerMs:t}})}async fail(e,t=ga){return!!Xe()&&await this.render({activity:{mode:"complete",label:e,tone:"error",lingerMs:t}})}async clear(){return!!Xe()&&await this.render({activity:{mode:"clear"}})}async render(e){try{return await this.target.evaluateJson(fa(e))}catch{return!1}}};function ba(e){return new ha(e)}async function ya(e,t,n){const r=new ma(e);await r.click({x:n.x,y:n.y},{motionObserver:t})}var va=Cr.object({pageId:Cr.string().optional().describe("可选:通过 list_pages 返回的 pageId/native targetId"),maxDepth:Cr.number().int().nonnegative().optional().describe("可选:限制 AX Tree 深度"),maxNodes:Cr.number().int().positive().optional().describe("可选:返回节点上限;实际值不会超过 Browser security maxSnapshotNodes"),interactiveOnly:Cr.boolean().default(!0).describe("默认 true:只返回可交互节点")}),wa=Cr.object({page:Sr,snapshot:xr});function xa(e){const t=[],n=e=>{"iframe"===e.role.toLowerCase()&&void 0!==e.backendNodeId&&t.push(e);for(const t of e.children??[])n(t)};for(const t of e)n(t);return t}async function Sa(e,t){if(void 0===t.backendNodeId)return;const n=await e.describeNode({backendNodeId:t.backendNodeId,depth:1}).catch(()=>{});return n?.contentDocumentFrameId??n?.frameId}async function Ia(e,t){const n=xa(t);return(await Promise.all(n.map(async t=>{const n=await Sa(e,t);return void 0===n?void 0:{node:t,frameId:n}}))).filter(e=>void 0!==e)}function Ca(e){const t=Number.parseInt(e.slice(2),10);return Number.isFinite(t)?t:0}function Ra(e){return e.refs.reduce((e,t)=>Math.max(e,Ca(t.ref)),0)}function ka(e,t){return e.flatMap(e=>{const n=void 0===e.ref?void 0:t.get(e.ref);return void 0===n?[e]:[e,...ka(n.nodes,t)]})}function Aa(e,t){return e.map(e=>{const n=void 0===e.ref?void 0:t.get(e.ref),r=Aa(e.children??[],t),a=void 0===n?[]:Aa(n.nodes,t),o=void 0===n?r:[...r,...a];return 0===o.length?e:{...e,children:o}})}async function Na(e){let t=Ra(e.snapshot),n=Math.max(0,e.snapshot.maxNodes-e.snapshot.nodeCount),r=e.snapshot.truncated;const a=new Set,o=[],i=[...await Ia(e.controller,e.snapshot.nodes)];for(let s=0;s<i.length;s+=1){const c=i[s];if(void 0===c)continue;if(n<=0){r=!0;break}if(void 0===c.node.ref||a.has(c.frameId))continue;a.add(c.frameId);const l=await Kr(e.controller,{frameId:c.frameId,maxCandidates:n}).catch(()=>[]),d=await Ir(e.controller,{depthOffset:c.node.depth+1,domActionHints:l,frameId:c.frameId,initialRefCount:t,interactiveOnly:e.snapshot.interactiveOnly,maxNodes:n,...void 0!==e.maxDepth?{maxDepth:e.maxDepth}:{}}).catch(()=>{});if(void 0===d||0===d.nodeCount||0===d.refs.length)continue;const u=await Ia(e.controller,d.nodes);o.push({iframeRef:c.node.ref,snapshot:d}),i.push(...u),t=Ra(d),n=Math.max(0,n-d.nodeCount),r=r||d.truncated}if(0===o.length)return{...e.snapshot,truncated:r};const s=new Map(o.map(e=>[e.iframeRef,e.snapshot])),c=o.flatMap(e=>e.snapshot.refs),l=o.reduce((e,t)=>e+t.snapshot.nodeCount,0);return{...e.snapshot,nodes:e.snapshot.interactiveOnly?ka(e.snapshot.nodes,s):Aa(e.snapshot.nodes,s),refs:[...e.snapshot.refs,...c],nodeCount:e.snapshot.nodeCount+l,truncated:r}}var Ma=wr({name:"browser_snapshot",description:"读取当前或指定页面的 Accessibility Tree,并为可交互节点生成 @eN ref;默认只返回可交互节点。",input:va,output:wa,execute:async(e,t)=>{const n=de(),r=ue(),a=await Ar({runtime:n,ctxManager:r,...void 0!==e.pageId?{pageId:e.pageId}:{}});t.logger.info(`Creating browser AX snapshot for page ${a.targetId}`);const o=await n.connectNativePage(a),i=ba(o);try{await i.begin("正在读取页面快照");const t=n.getConfig().security,s=Math.min(e.maxNodes??t.maxSnapshotNodes,t.maxSnapshotNodes),c=await Kr(o,s),l=await Ir(o,{domActionHints:c,interactiveOnly:e.interactiveOnly??!0,maxNodes:s,...void 0!==e.maxDepth?{maxDepth:e.maxDepth}:{}}),d=await Na({controller:o,snapshot:l,...void 0!==e.maxDepth?{maxDepth:e.maxDepth}:{}});return kr.saveSnapshot(a.targetId,d),await i.succeed(`已识别 ${d.refs.length} 个可操作元素`),{page:Wt(r,a),snapshot:d}}catch(e){throw await i.fail("读取页面快照失败"),e}finally{o.close()}}});import{StructuredToolError as Ea,defineTool as Pa}from"@roll-agent/sdk";import{BrowserActionApprovalSchema as Ta,BrowserElementRefHandleSchema as _a,clickElementRef as Ba}from"@roll-agent/browser";import{z as Oa}from"zod";import{BrowserElementRefHandleSchema as $a}from"@roll-agent/browser";import{z as Da}from"zod";var qa=Da.enum(["backend_node_id","role_name_nth"]),Fa=Da.object({ref:$a,role:Da.string(),name:Da.string(),x:Da.number(),y:Da.number(),resolvedBy:qa,backendNodeId:Da.number().int().positive().optional(),frameId:Da.string().optional(),disabled:Da.boolean()}),ja=Da.object({success:Da.literal(!0),ref:$a,resolvedBy:qa,target:Fa}),La=Oa.object({ref:_a.describe("browser_snapshot 返回的 @eN element ref"),pageId:Oa.string().optional().describe("可选:通过 list_pages 返回的 pageId/native targetId"),browserActionApproval:Ta.optional().describe("当 actionPolicy=confirm 返回 needs_confirmation 后,由 orchestrator 原样带回的批准 ID。")}),za=Pa({name:"click_ref",description:"点击 browser_snapshot 返回的 @eN ref;优先使用 backendNodeId,失效时使用 role/name/nth fallback。",input:La,output:ja,execute:async(e,t)=>{const n=de(),r=ue(),a=await Ar({runtime:n,ctxManager:r,...void 0!==e.pageId?{pageId:e.pageId}:{}}),o=kr.getRef(a.targetId,e.ref);if(void 0===o)throw new Ea({code:"not_found",message:`Element ref ${e.ref} is not available. Run browser_snapshot for this page first.`,details:{ref:e.ref,pageId:a.targetId}});const i=hn(t,n,{action:"click",target:e.ref,...void 0!==e.browserActionApproval?{approval:e.browserActionApproval}:{}}),s=await n.connectNativePage(a,{...fn(t,n,{approval:e.browserActionApproval,approvedByConfirmation:i.approvedByConfirmation,logActions:!1})});try{await wn({targetId:a.targetId,bringToFront:async()=>{await s.bringToFront()}},{runtime:n});const t=ba(s);await t.begin(`正在点击 ${e.ref}`);const r=await Ba({controller:s,elementRef:o,options:{clickTarget:async e=>{await ya(s,t,e)}}});return await t.succeed(`已点击 ${e.ref}`),r}catch(t){await ba(s).fail(`点击 ${e.ref} 失败`);const n=bn(t);if(void 0!==n)throw n;throw t}finally{s.close()}}});import{StructuredToolError as Ja,defineTool as Ua}from"@roll-agent/sdk";import{BrowserActionApprovalSchema as Va,BrowserElementRefHandleSchema as Ha,typeElementRef as Wa}from"@roll-agent/browser";import{z as Ka}from"zod";var Ya=Ka.object({ref:Ha.describe("browser_snapshot 返回的 @eN element ref"),text:Ka.string().describe("要输入的文本"),clear:Ka.boolean().default(!1).describe("输入前是否先清空当前控件内容"),pageId:Ka.string().optional().describe("可选:通过 list_pages 返回的 pageId/native targetId"),browserActionApproval:Va.optional().describe("当 actionPolicy=confirm 返回 needs_confirmation 后,由 orchestrator 原样带回的批准 ID。")}),Ga=Ua({name:"type_ref",description:"向 browser_snapshot 返回的 @eN ref 输入文本;优先使用 backendNodeId,失效时使用 role/name/nth fallback。",input:Ya,output:ja,execute:async(e,t)=>{const n=de(),r=ue(),a=await Ar({runtime:n,ctxManager:r,...void 0!==e.pageId?{pageId:e.pageId}:{}}),o=kr.getRef(a.targetId,e.ref);if(void 0===o)throw new Ja({code:"not_found",message:`Element ref ${e.ref} is not available. Run browser_snapshot for this page first.`,details:{ref:e.ref,pageId:a.targetId}});const i=hn(t,n,{action:"type",target:e.ref,...void 0!==e.browserActionApproval?{approval:e.browserActionApproval}:{}}),s=await n.connectNativePage(a,{...fn(t,n,{approval:e.browserActionApproval,approvedByConfirmation:i.approvedByConfirmation,logActions:!1})});try{await wn({targetId:a.targetId,bringToFront:async()=>{await s.bringToFront()}},{runtime:n});const t=ba(s);await t.begin(`正在输入到 ${e.ref}`);const r=await Wa({controller:s,elementRef:o,text:e.text,options:{...void 0!==e.clear?{clear:e.clear}:{},clickTarget:async e=>{await ya(s,t,e)}}});return await t.succeed(`已输入到 ${e.ref}`),r}catch(t){await ba(s).fail(`输入到 ${e.ref} 失败`);const n=bn(t);if(void 0!==n)throw n;throw t}finally{s.close()}}});import{defineTool as Xa}from"@roll-agent/sdk";import{BrowserPageInfoSchema as Za}from"@roll-agent/browser";import{z as Qa}from"zod";var eo=["native","native-watch","native-ws-connect","native-page-bring-front","native-evaluate-url-no-runtime-enable","native-dom-read-no-runtime-enable","native-input-move-no-runtime-enable","native-runtime-enable","native-evaluate-url","native-dom-read","browser-attach","page-attach","network-watch","page-evaluate","detector-fingerprint","storage-summary"],to=[...eo,"native-ws-connect-watch","native-page-bring-front-watch","native-evaluate-url-no-runtime-enable-watch","native-dom-read-no-runtime-enable-watch","native-input-move-no-runtime-enable-watch","native-runtime-enable-watch","native-evaluate-url-watch","native-dom-read-watch","browser-attach-watch"],no=Qa.enum(["localStorage","sessionStorage"]),ro=Qa.enum(["array","object","string","number","boolean","null"]),ao=Qa.enum(["empty","json","string"]),oo=Qa.enum(eo),io=Qa.enum(to),so=Qa.enum(["request","response"]),co=Qa.enum(["apm-action-log","device-action-report","boss-risk-report","zhipin-security"]),lo=Qa.object({area:no,key:Qa.string(),valueLength:Qa.number().int().nonnegative(),valueKind:ao,jsonKind:ro.optional(),jsonTopLevelKeys:Qa.array(Qa.string()).optional(),jsonArrayLength:Qa.number().int().nonnegative().optional(),numericFields:Qa.record(Qa.number()).optional(),booleanFields:Qa.record(Qa.boolean()).optional(),arrayLengths:Qa.record(Qa.number().int().nonnegative()).optional()}),uo=Qa.object({name:Qa.string(),domain:Qa.string(),path:Qa.string(),expires:Qa.string(),valueLength:Qa.number().int().nonnegative(),httpOnly:Qa.boolean(),secure:Qa.boolean(),sameSite:Qa.string().optional()}),mo=Qa.object({before:Qa.number().optional(),after:Qa.number().optional(),delta:Qa.number().optional()}),po=Qa.object({before:Qa.boolean().optional(),after:Qa.boolean().optional()}),go=Qa.object({before:Qa.number().int().nonnegative().optional(),after:Qa.number().int().nonnegative().optional(),delta:Qa.number().int().optional()}),fo=Qa.object({area:no,key:Qa.string(),beforePresent:Qa.boolean(),afterPresent:Qa.boolean(),numericDeltas:Qa.record(mo).optional(),booleanChanges:Qa.record(po).optional(),arrayLengthDeltas:Qa.record(go).optional()}),ho=Qa.object({url:Qa.string(),title:Qa.string(),visibilityState:Qa.string(),hasFocus:Qa.boolean()}),bo=Qa.object({navigatorWebdriver:Qa.boolean().optional(),userAgentContainsHeadless:Qa.boolean(),languagesLength:Qa.number().int().nonnegative(),pluginsLength:Qa.number().int().nonnegative(),hasChromeRuntime:Qa.boolean(),permissionQueryIsNative:Qa.boolean().optional(),hasPlaywrightBinding:Qa.boolean(),hasPwInitScripts:Qa.boolean(),cdcKeys:Qa.array(Qa.string()),webdriverKeys:Qa.array(Qa.string()),automationLikeWindowKeys:Qa.array(Qa.string())}),yo=Qa.object({rootNodeId:Qa.number().int(),rootNodeName:Qa.string(),childNodeCount:Qa.number().int().nonnegative().optional(),bodyTextLength:Qa.number().int().nonnegative().optional(),elementCount:Qa.number().int().nonnegative().optional()}),vo=Qa.object({type:Qa.literal("mouseMoved"),x:Qa.number(),y:Qa.number()}),wo=Qa.object({targetId:Qa.string(),websocketUrlAvailable:Qa.boolean(),connected:Qa.boolean(),pageBroughtToFront:Qa.boolean().optional(),runtimeEnabled:Qa.boolean().optional(),evaluate:ho.optional(),dom:yo.optional(),input:vo.optional()}),xo=Qa.object({phase:oo,success:Qa.boolean(),durationMs:Qa.number().int().nonnegative(),error:Qa.string().optional()}),So=Qa.object({phase:io,capturedAt:Qa.string(),targetFound:Qa.boolean(),page:Za.optional(),urlChangedFromPrevious:Qa.boolean(),titleChangedFromPrevious:Qa.boolean(),previousUrl:Qa.string().optional(),currentUrl:Qa.string().optional(),previousTitle:Qa.string().optional(),currentTitle:Qa.string().optional()}),Io=Qa.object({kind:so,reason:co,capturedAt:Qa.string(),url:Qa.string(),method:Qa.string().optional(),resourceType:Qa.string().optional(),status:Qa.number().int().optional()}),Co=Qa.object({capturedAt:Qa.string(),url:Qa.string()}),Ro=Qa.object({phase:oo.default("native").describe("诊断阶段。默认 native 只枚举原生 CDP target;native-* 阶段使用原生 CDP page WebSocket;browser-attach 及更深阶段才会使用 Playwright attach。"),targetPageId:Qa.string().optional().describe("可选:通过 list_pages 或本工具 native 阶段看到的 BOSS 页面 pageId/targetId。"),watchMs:Qa.number().int().min(500).max(1e4).default(3e3).describe("native-watch / browser-attach 后置观察 / network-watch / storage-summary 内部等待窗口,单位毫秒。"),networkEventLimit:Qa.number().int().min(1).max(100).default(30).describe("network-watch 最多返回的相关 request/response 事件数。")}),ko=Qa.object({success:Qa.boolean(),requestedPhase:oo,mode:Qa.string(),nativePages:Qa.array(Za),targetPage:Za.optional(),browserAttached:Qa.boolean(),pageAttached:Qa.boolean(),nativeTimeline:Qa.array(So),networkEvents:Qa.array(Io).optional(),navigationEvents:Qa.array(Co).optional(),nativeCdp:wo.optional(),evaluate:ho.optional(),detectorFingerprint:bo.optional(),storage:Qa.object({localStorage:Qa.array(lo),sessionStorage:Qa.array(lo),cookies:Qa.array(uo),counterDiffs:Qa.array(fo)}).optional(),phases:Qa.array(xo),warnings:Qa.array(Qa.string())}),Ao=["_AEG_CNT","_ZP_CNT_","__local__sec__store___"],No=new Set(Ao),Mo=["native-ws-connect","native-page-bring-front","native-evaluate-url-no-runtime-enable","native-dom-read-no-runtime-enable","native-input-move-no-runtime-enable","native-runtime-enable","native-evaluate-url","native-dom-read"],Eo=["native-page-bring-front","native-evaluate-url-no-runtime-enable","native-dom-read-no-runtime-enable","native-input-move-no-runtime-enable"],Po={"native-ws-connect":"native-ws-connect-watch","native-page-bring-front":"native-page-bring-front-watch","native-evaluate-url-no-runtime-enable":"native-evaluate-url-no-runtime-enable-watch","native-dom-read-no-runtime-enable":"native-dom-read-no-runtime-enable-watch","native-input-move-no-runtime-enable":"native-input-move-no-runtime-enable-watch","native-runtime-enable":"native-runtime-enable-watch","native-evaluate-url":"native-evaluate-url-watch","native-dom-read":"native-dom-read-watch"};function To(e){if(null===e)return"null";if(Array.isArray(e))return"array";switch(typeof e){case"boolean":return"boolean";case"number":return"number";case"string":default:return"string";case"object":return"object"}}function _o(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function Bo(e){return Mo.includes(e)}function Oo(e){return Eo.includes(e)}function $o(e){try{return JSON.parse(e)}catch{return}}function Do(e){const t=Object.fromEntries(Object.entries(e).filter(e=>"number"==typeof e[1])),n=Object.fromEntries(Object.entries(e).filter(e=>"boolean"==typeof e[1])),r=Object.fromEntries(Object.entries(e).filter(e=>Array.isArray(e[1])).map(([e,t])=>[e,t.length]));return{...Object.keys(t).length>0?{numericFields:t}:{},...Object.keys(n).length>0?{booleanFields:n}:{},...Object.keys(r).length>0?{arrayLengths:r}:{}}}function qo(e){return new Promise(t=>{setTimeout(t,e)})}function Fo(e){return No.has(e)}function jo(e,t){if(0===t.value.length)return{area:e,key:t.key,valueLength:0,valueKind:"empty"};const n=$o(t.value);if(void 0===n)return{area:e,key:t.key,valueLength:t.value.length,valueKind:"string"};const r=To(n),a=_o(n)&&Fo(t.key)?Do(n):{};return{area:e,key:t.key,valueLength:t.value.length,valueKind:"json",jsonKind:r,..._o(n)?{jsonTopLevelKeys:Object.keys(n)}:{},...Array.isArray(n)?{jsonArrayLength:n.length}:{},...a}}function Lo(e){return{name:e.name,domain:e.domain,path:e.path,expires:e.expires>0?new Date(1e3*e.expires).toISOString():"Session",valueLength:e.value.length,httpOnly:e.httpOnly,secure:e.secure,...void 0!==e.sameSite?{sameSite:e.sameSite}:{}}}async function zo(e,t){const n=Date.now();try{return{result:await t(),phaseResult:{phase:e,success:!0,durationMs:Date.now()-n}}}catch(t){return{phaseResult:{phase:e,success:!1,durationMs:Date.now()-n,error:t instanceof Error?t.message:String(t)}}}}function Jo(e,t,n){if(void 0!==t){const r=e.find(e=>e.targetId===t);return r?Vt(r.url,"zhipin")?r:void n.push(`targetPageId "${t}" is not a zhipin page.`):void n.push(`targetPageId "${t}" not found in native pages.`)}const r=e.filter(e=>Vt(e.url,"zhipin"));if(1===r.length)return r[0];0===r.length?n.push("No zhipin native page found. Open Boss first or pass targetPageId."):n.push("Multiple zhipin native pages found. Pass targetPageId to avoid ambiguity.")}function Uo(e,t,n,r){const a=n?.url,o=n?.title,i=r?.currentUrl,s=r?.currentTitle;return{phase:t,capturedAt:(new Date).toISOString(),targetFound:void 0!==n,...void 0!==n?{page:Wt(e,n)}:{},urlChangedFromPrevious:void 0!==i&&void 0!==a&&i!==a,titleChangedFromPrevious:void 0!==s&&void 0!==o&&s!==o,...void 0!==i?{previousUrl:i}:{},...void 0!==a?{currentUrl:a}:{},...void 0!==s?{previousTitle:s}:{},...void 0!==o?{currentTitle:o}:{}}}async function Vo(e,t,n,r){const a=await e.listNativePages();return Uo(e,t,void 0!==n?a.find(e=>e.targetId===n):a.filter(e=>Vt(e.url,"zhipin"))[0],r)}async function Ho(e,t,n,r,a){try{const o=t[t.length-1],i=await Vo(e,n,r,o);t.push(i),i.urlChangedFromPrevious&&a.push(`Target URL changed after ${n}: ${i.previousUrl??"(unknown)"} -> ${i.currentUrl??"(missing)"}.`)}catch(e){a.push(`Failed to capture native snapshot after ${n}: ${e instanceof Error?e.message:String(e)}.`)}}async function Wo(e,t,n,r,a,o){const i=t.length,s=Date.now();for(;;){await Ho(e,t,n,r,o);const i=a-(Date.now()-s);if(i<=0)break;await qo(Math.min(500,i))}return t.slice(i).some(e=>e.urlChangedFromPrevious)}function Ko(e){if(!_o(e))throw new Error("Native CDP evaluate did not return an object value.");const t=e.url,n=e.title,r=e.visibilityState,a=e.hasFocus;if("string"!=typeof t||"string"!=typeof n||"string"!=typeof r||"boolean"!=typeof a)throw new Error("Native CDP evaluate returned an unexpected page summary shape.");return{url:t,title:n,visibilityState:r,hasFocus:a}}function Yo(e,t){if(!_o(e))throw new Error("Native CDP DOM.getDocument did not return an object.");const n=e.root;if(!_o(n))throw new Error("Native CDP DOM.getDocument did not return a root node.");const r=n.nodeId,a=n.nodeName,o=n.childNodeCount;if("number"!=typeof r||"string"!=typeof a)throw new Error("Native CDP DOM root node has an unexpected shape.");const i=_o(t)?t:{},s=i.bodyTextLength,c=i.elementCount;return{rootNodeId:r,rootNodeName:a,..."number"==typeof o?{childNodeCount:o}:{},..."number"==typeof s?{bodyTextLength:s}:{},..."number"==typeof c?{elementCount:c}:{}}}async function Go(e){return Ko(await e.evaluateJson("(() => ({\n url: location.href,\n title: document.title,\n visibilityState: document.visibilityState,\n hasFocus: document.hasFocus()\n }))()"))}async function Xo(e){return Yo(await e.getDocument({depth:1,pierce:!1}),await e.evaluateJson('(() => ({\n bodyTextLength: document.body?.innerText?.length ?? 0,\n elementCount: document.querySelectorAll("*").length\n }))()'))}async function Zo(e){return Yo(await e.getDocument({depth:1,pierce:!1}),void 0)}async function Qo(e){return await e.bringToFront(),!0}async function ei(e){const t={type:"mouseMoved",x:0,y:0};return await e.dispatchMouseEvent({type:t.type,x:t.x,y:t.y}),t}async function ti(e,t,n,r,a,o){await Ho(e,t,n,r,o);const i=await Wo(e,t,Po[n],r,a,o);return i&&o.push(`Native CDP phase ${n} was followed by a native URL change; stop before deeper native CDP operations.`),i}async function ni(e,t,n,r){switch(e){case"native-page-bring-front":{const a=await zo(e,async()=>await Qo(t));return n.push(a.phaseResult),void 0!==a.result&&(r.pageBroughtToFront=a.result),a.phaseResult}case"native-evaluate-url-no-runtime-enable":{const a=await zo(e,async()=>await Go(t));return n.push(a.phaseResult),void 0!==a.result&&(r.evaluate=a.result),a.phaseResult}case"native-dom-read-no-runtime-enable":{const a=await zo(e,async()=>await Zo(t));return n.push(a.phaseResult),void 0!==a.result&&(r.dom=a.result),a.phaseResult}case"native-input-move-no-runtime-enable":{const a=await zo(e,async()=>await ei(t));return n.push(a.phaseResult),void 0!==a.result&&(r.input=a.result),a.phaseResult}}}async function ri(e){const t={targetId:e.target.targetId,websocketUrlAvailable:"string"==typeof e.target.webSocketDebuggerUrl&&e.target.webSocketDebuggerUrl.length>0,connected:!1},n=e.target.webSocketDebuggerUrl;let r;try{const a=await zo("native-ws-connect",async()=>{if(void 0===n||0===n.length)throw new Error("Native CDP target does not expose webSocketDebuggerUrl.");return await e.runtime.connectNativePage(e.target,{allowUnsafeRuntimeEnableForDiagnostics:!0})});if(e.phases.push(a.phaseResult),r=a.result,t.connected=a.phaseResult.success,!a.phaseResult.success||void 0===r)return{summary:t,triggeredNavigation:!1};const o=r;let i=await ti(e.ctxManager,e.nativeTimeline,"native-ws-connect",e.targetPageId,e.watchMs,e.warnings);if("native-ws-connect"===e.requestedPhase||i)return{summary:t,triggeredNavigation:i};if(Oo(e.requestedPhase))return await ni(e.requestedPhase,o,e.phases,t),i=await ti(e.ctxManager,e.nativeTimeline,e.requestedPhase,e.targetPageId,e.watchMs,e.warnings),{summary:t,triggeredNavigation:i};const s=await zo("native-runtime-enable",async()=>await o.unsafeEnableRuntimeForDiagnostics());if(e.phases.push(s.phaseResult),t.runtimeEnabled=s.phaseResult.success,i=await ti(e.ctxManager,e.nativeTimeline,"native-runtime-enable",e.targetPageId,e.watchMs,e.warnings),!s.phaseResult.success||"native-runtime-enable"===e.requestedPhase||i)return{summary:t,triggeredNavigation:i};const c=await zo("native-evaluate-url",async()=>await Go(o));if(e.phases.push(c.phaseResult),void 0!==c.result&&(t.evaluate=c.result),i=await ti(e.ctxManager,e.nativeTimeline,"native-evaluate-url",e.targetPageId,e.watchMs,e.warnings),!c.phaseResult.success||"native-evaluate-url"===e.requestedPhase||i)return{summary:t,triggeredNavigation:i};const l=await zo("native-dom-read",async()=>await Xo(o));return e.phases.push(l.phaseResult),void 0!==l.result&&(t.dom=l.result),i=await ti(e.ctxManager,e.nativeTimeline,"native-dom-read",e.targetPageId,e.watchMs,e.warnings),l.phaseResult.success,{summary:t,triggeredNavigation:i}}finally{r?.close()}}function ai(e){const t=e.toLowerCase();return t.includes("device-action-report")?"device-action-report":t.includes("boss_risk_report")?"boss-risk-report":t.includes("apm-fe.zhipin.com")||t.includes("/wapi/zpapm/actionlog/")?"apm-action-log":t.includes("zhipin-security")||t.includes("/security/")?"zhipin-security":void 0}async function oi(e,t,n){const r=[],a=[],o=e=>{r.length<n&&r.push(e)},i=e=>{const t=e.url(),n=ai(t);void 0!==n&&o({kind:"request",reason:n,capturedAt:(new Date).toISOString(),url:t,method:e.method(),resourceType:e.resourceType()})},s=e=>{const t=e.url(),n=ai(t);if(void 0===n)return;const r=e.request();o({kind:"response",reason:n,capturedAt:(new Date).toISOString(),url:t,method:r.method(),resourceType:r.resourceType(),status:e.status()})},c=e=>{a.push({capturedAt:(new Date).toISOString(),url:e.url()})};e.on("request",i),e.on("response",s),e.on("framenavigated",c);try{await qo(t)}finally{e.off("request",i),e.off("response",s),e.off("framenavigated",c)}return{networkEvents:r,navigationEvents:a}}function ii(e,t){const n=e.contexts().flatMap(e=>e.pages()).filter(e=>!e.isClosed()&&Vt(e.url(),"zhipin"));return n.find(e=>e.url()===t.url)??n[0]}function si(e,t){return{networkEvents:e.flatMap(e=>e.networkEvents).slice(0,t),navigationEvents:e.flatMap(e=>e.navigationEvents)}}async function ci(e,t){return await e.evaluate(e=>{const t="localStorage"===e?window.localStorage:window.sessionStorage;return Array.from({length:t.length},(e,n)=>{const r=t.key(n)??"";return{key:r,value:r.length>0?t.getItem(r)??"":""}}).filter(e=>e.key.length>0)},t)}async function li(e){return(await e.evaluate(e=>{const t=["localStorage","sessionStorage"],n=[];for(const r of t){const t="localStorage"===r?window.localStorage:window.sessionStorage;for(const a of e){const e=t.getItem(a);null!==e&&n.push({area:r,key:a,value:e})}}return n},Ao)).map(e=>jo(e.area,{key:e.key,value:e.value}))}async function di(e){return await e.evaluate(()=>({url:location.href,title:document.title,visibilityState:document.visibilityState,hasFocus:document.hasFocus()}))}async function ui(e){return await e.evaluate(()=>{const e=window,t=Object.keys(e),n=t.filter(e=>e.startsWith("cdc_")||e.includes("_cdc_")).slice(0,20),r=t.filter(e=>e.toLowerCase().includes("webdriver")).slice(0,20),a=t.filter(e=>{const t=e.toLowerCase();return t.includes("playwright")||t.includes("puppeteer")||t.includes("selenium")||t.includes("chromedriver")}).slice(0,20),o=navigator.permissions?.query,i="function"==typeof o?o.toString().includes("[native code]"):void 0;return{..."boolean"==typeof navigator.webdriver?{navigatorWebdriver:navigator.webdriver}:{},userAgentContainsHeadless:navigator.userAgent.toLowerCase().includes("headless"),languagesLength:navigator.languages?.length??0,pluginsLength:navigator.plugins?.length??0,hasChromeRuntime:"object"==typeof e.chrome&&null!==e.chrome&&"runtime"in e.chrome,...void 0!==i?{permissionQueryIsNative:i}:{},hasPlaywrightBinding:"__playwright__binding__"in e,hasPwInitScripts:"__pwInitScripts"in e,cdcKeys:n,webdriverKeys:r,automationLikeWindowKeys:a}})}function mi(e){return new Map(e.map(e=>[`${e.area}:${e.key}`,e]))}function pi(e,t){return[...new Set([...Object.keys(e??{}),...Object.keys(t??{})])]}function gi(e,t){return{...void 0!==e?{before:e}:{},...void 0!==t?{after:t}:{},...void 0!==e&&void 0!==t?{delta:t-e}:{}}}function fi(e,t){return{...void 0!==e?{before:e}:{},...void 0!==t?{after:t}:{},...void 0!==e&&void 0!==t?{delta:t-e}:{}}}function hi(e,t){const n=mi(e),r=mi(t),a=[...new Set([...n.keys(),...r.keys()])],o=[];for(const e of a){const t=n.get(e),a=r.get(e),i=a??t;if(!i)continue;const s={};for(const e of pi(t?.numericFields,a?.numericFields)){const n=t?.numericFields?.[e],r=a?.numericFields?.[e];n!==r&&(s[e]=gi(n,r))}const c={};for(const e of pi(t?.booleanFields,a?.booleanFields)){const n=t?.booleanFields?.[e],r=a?.booleanFields?.[e];n!==r&&(c[e]={...void 0!==n?{before:n}:{},...void 0!==r?{after:r}:{}})}const l={};for(const e of pi(t?.arrayLengths,a?.arrayLengths)){const n=t?.arrayLengths?.[e],r=a?.arrayLengths?.[e];n!==r&&(l[e]=fi(n,r))}void 0!==t&&void 0!==a&&0===Object.keys(s).length&&0===Object.keys(c).length&&0===Object.keys(l).length||o.push({area:i.area,key:i.key,beforePresent:void 0!==t,afterPresent:void 0!==a,...Object.keys(s).length>0?{numericDeltas:s}:{},...Object.keys(c).length>0?{booleanChanges:c}:{},...Object.keys(l).length>0?{arrayLengthDeltas:l}:{}})}return o}async function bi(e,t){const[n,r,a]=await Promise.all([ci(e,"localStorage"),ci(e,"sessionStorage"),e.context().cookies()]),o=[...n.filter(e=>Fo(e.key)).map(e=>jo("localStorage",e)),...r.filter(e=>Fo(e.key)).map(e=>jo("sessionStorage",e))];return{localStorage:n.map(e=>jo("localStorage",e)),sessionStorage:r.map(e=>jo("sessionStorage",e)),cookies:a.filter(e=>e.domain.includes("zhipin.com")||e.domain.includes("bosszhipin.com")).map(e=>Lo(e)),counterDiffs:hi(t,o)}}var yi=Xa({name:"zhipin_diagnose_browser_state",description:"分阶段诊断 Boss 页面在原生 CDP page WebSocket、Playwright CDP attach、页面绑定、网络上报、evaluate、检测指纹、storage/cookie 读取时的状态;默认只做 native target 枚举,所有 storage/cookie 值均脱敏。",input:Ro,output:ko,execute:async(e,t)=>{const n=e.phase??"native",r=e.watchMs??3e3,a=e.networkEventLimit??30,o=ue(),i=de(),s=[],c=[],l=[];let d,u,m,p=!1,g=!1,f=e.targetPageId;t.logger.info(`Diagnosing zhipin browser state (phase: ${n})`);const h=await zo("native",async()=>await o.listNativePages());c.push(h.phaseResult);const b=h.result??[],y=b.map(e=>Wt(o,e)),v=Jo(b,e.targetPageId,s);if(v&&(d=Wt(o,v),f=v.targetId,l.push(Uo(o,"native",v,void 0))),!h.phaseResult.success||"native"===n)return{success:h.phaseResult.success,requestedPhase:n,mode:i.mode,nativePages:y,...void 0!==d?{targetPage:d}:{},browserAttached:p,pageAttached:g,nativeTimeline:l,phases:c,warnings:s};if("native-watch"===n)return await Wo(o,l,"native-watch",f,r,s),{success:h.phaseResult.success&&void 0!==f,requestedPhase:n,mode:i.mode,nativePages:y,...void 0!==d?{targetPage:d}:{},browserAttached:p,pageAttached:g,nativeTimeline:l,phases:c,warnings:s};if(!v)return{success:!1,requestedPhase:n,mode:i.mode,nativePages:y,browserAttached:p,pageAttached:g,nativeTimeline:l,phases:c,warnings:s};if(Bo(n)){const e=await ri({requestedPhase:n,target:v,runtime:i,ctxManager:o,targetPageId:f,watchMs:r,phases:c,nativeTimeline:l,warnings:s});return{success:c.every(e=>e.success)&&!e.triggeredNavigation,requestedPhase:n,mode:i.mode,nativePages:y,...void 0!==d?{targetPage:d}:{},browserAttached:p,pageAttached:g,nativeTimeline:l,nativeCdp:e.summary,phases:c,warnings:s}}const w=await zo("browser-attach",async()=>await i.getBrowser());c.push(w.phaseResult);const x=w.result;p=w.phaseResult.success,await Ho(o,l,"browser-attach",f,s);const S=await Wo(o,l,"browser-attach-watch",f,r,s);if(S&&s.push("Browser attach was followed by a native URL change; treat this account/browser profile as unsafe for Playwright-backed zhipin tools."),!w.phaseResult.success||"browser-attach"===n)return{success:c.every(e=>e.success)&&!S,requestedPhase:n,mode:i.mode,nativePages:y,...void 0!==d?{targetPage:d}:{},browserAttached:p,pageAttached:g,nativeTimeline:l,phases:c,warnings:s};if(S)return{success:!1,requestedPhase:n,mode:i.mode,nativePages:y,...void 0!==d?{targetPage:d}:{},browserAttached:p,pageAttached:g,nativeTimeline:l,phases:c,warnings:s};const I=[];let C;"network-watch"===n&&void 0!==x&&(C=ii(x,v),C?I.push(oi(C,r,a)):s.push("No attached zhipin page found before page-attach; network-watch starts after page-attach.")),o.rememberNativePageSelection("zhipin",v);const R=await zo("page-attach",async()=>await o.getPage("zhipin"));c.push(R.phaseResult);const k=R.result;if(g=R.phaseResult.success,k&&(d=await Kt(o,k)),await Ho(o,l,"page-attach",f,s),!R.phaseResult.success||!k){if("network-watch"===n&&I.length>0){const e=await zo("network-watch",async()=>si(await Promise.all(I),a));c.push(e.phaseResult),e.result&&(u=e.result.networkEvents,m=e.result.navigationEvents)}return{success:c.every(e=>e.success),requestedPhase:n,mode:i.mode,nativePages:y,...void 0!==d?{targetPage:d}:{},browserAttached:p,pageAttached:g,nativeTimeline:l,...void 0!==u?{networkEvents:u}:{},...void 0!==m?{navigationEvents:m}:{},phases:c,warnings:s}}if("page-attach"===n)return{success:c.every(e=>e.success),requestedPhase:n,mode:i.mode,nativePages:y,...void 0!==d?{targetPage:d}:{},browserAttached:p,pageAttached:g,nativeTimeline:l,phases:c,warnings:s};if("network-watch"===n){C!==k&&I.push(oi(k,r,a));const e=await zo("network-watch",async()=>si(await Promise.all(I),a));return c.push(e.phaseResult),e.result&&(u=e.result.networkEvents,m=e.result.navigationEvents),await Ho(o,l,"network-watch",f,s),{success:c.every(e=>e.success),requestedPhase:n,mode:i.mode,nativePages:y,...void 0!==d?{targetPage:d}:{},browserAttached:p,pageAttached:g,nativeTimeline:l,...void 0!==u?{networkEvents:u}:{},...void 0!==m?{navigationEvents:m}:{},phases:c,warnings:s}}let A=[];if("storage-summary"===n){try{A=await li(k)}catch(e){s.push(`Failed to read storage counter baseline: ${e instanceof Error?e.message:String(e)}.`)}r>0&&await qo(r)}const N=await zo("page-evaluate",async()=>await di(k));c.push(N.phaseResult);const M=N.result;if(await Ho(o,l,"page-evaluate",f,s),!N.phaseResult.success||"page-evaluate"===n)return{success:c.every(e=>e.success),requestedPhase:n,mode:i.mode,nativePages:y,...void 0!==d?{targetPage:d}:{},browserAttached:p,pageAttached:g,nativeTimeline:l,...void 0!==M?{evaluate:M}:{},phases:c,warnings:s};const E=await zo("detector-fingerprint",async()=>await ui(k));c.push(E.phaseResult);const P=E.result;if(await Ho(o,l,"detector-fingerprint",f,s),!E.phaseResult.success||"detector-fingerprint"===n)return{success:c.every(e=>e.success),requestedPhase:n,mode:i.mode,nativePages:y,...void 0!==d?{targetPage:d}:{},browserAttached:p,pageAttached:g,nativeTimeline:l,...void 0!==M?{evaluate:M}:{},...void 0!==P?{detectorFingerprint:P}:{},phases:c,warnings:s};const T=await zo("storage-summary",async()=>await bi(k,A));c.push(T.phaseResult);const _=T.result;return await Ho(o,l,"storage-summary",f,s),{success:c.every(e=>e.success),requestedPhase:n,mode:i.mode,nativePages:y,...void 0!==d?{targetPage:d}:{},browserAttached:p,pageAttached:g,nativeTimeline:l,...void 0!==M?{evaluate:M}:{},...void 0!==P?{detectorFingerprint:P}:{},...void 0!==_?{storage:_}:{},phases:c,warnings:s}}});import{defineTool as vi}from"@roll-agent/sdk";import{z as wi}from"zod";import{setTimeout as xi}from"node:timers/promises";async function Si(e,t=300,n=800){const r=Math.floor(Math.random()*(n-t))+t;await e.waitForTimeout(r)}function Ii(e){return e.trim().toLocaleLowerCase("zh-CN")}function Ci(e,t){let n=0;for(const r of e)t.includes(r)&&(n+=1);return n}function Ri(e,t){if(void 0!==t.conversationId){const n=e.find(e=>e.conversationId===t.conversationId);if(n)return n}const n=t.candidateName;if(n){const t=Ii(n),r=e.filter(e=>e.name.length>0);let a=r.find(e=>Ii(e.name)===t);if(a)return a;if(a=r.find(e=>{const n=Ii(e.name);return n.includes(t)||t.includes(n)}),a)return a;const o=t.length<=2?1:t.length<=4?.75:.6;if(a=r.find(e=>{const n=Ii(e.name);return Ci(t,n)>=Math.ceil(Math.min(t.length,n.length)*o)}),a)return a}if(void 0!==t.index)return e[t.index]}var ki=["chat-list","chat-history","recommend-list"],Ai={"chat-list":{surface:"chat-list",defaultDirection:"down",containerSelectors:[".user-list.b-scroll-stable",".chat-user .user-list",".chat-user-list",".chat-list-wrapper",".chat-list-wrap",".chat-user .b-scroll-stable",".b-scroll-stable",".chat-user .user-container",".chat-user"],itemSelector:'.user-list.b-scroll-stable [role="listitem"], .geek-item',highlightSelector:".user-list.b-scroll-stable, .chat-user .user-container, .chat-user"},"chat-history":{surface:"chat-history",defaultDirection:"up",containerSelectors:[".conversation-message",".chat-message-list",".conversation-main",".conversation-box"],itemSelector:".chat-message-list > .message-item, .conversation-message .message-item",highlightSelector:".conversation-message, .chat-message-list, .conversation-main"},"recommend-list":{surface:"recommend-list",defaultDirection:"down",containerSelectors:["#recommend-list",".list-wrap.card-list-wrap",".card-list-wrap",".recommend-list-wrap",".recommend-list",".card-list",".candidate-list",".candidate-body",".geek-list",".list-wrap",".recommendV2"],itemSelector:".candidate-card-wrap, li.card-item, .geek-item",highlightSelector:".candidate-card-wrap, li.card-item, .geek-item"}};function Ni(e){return Ai[e]}var Mi={login:{notLoggedIn:".header-login-btn"},unread:{container:".chat-list-wrap",listItem:'[role="listitem"]',geekItemWrap:".geek-item-wrap",item:".chat-item",unreadBadge:".badge-count",unreadBadgeNew:".badge-count.badge-count-common-less",unreadBadgeSpan:".badge-count span",unreadDot:".red-dot",figure:".figure",badge:".badge",candidateName:".candidate-name",candidateNameAlt:".chat-item-name",candidateNameSelectors:'[class*="name"], .nickname, .geek-name',candidateNameNew:".geek-name",jobTitle:".source-job",lastMessage:".push-text",lastMessageAlt:".chat-last-msg",messageTime:".time, .time-shadow",clickArea:".chat-item-content",unreadCandidates:".geek-item"},chat:{chatContainer:".chat-container",messageList:".message-list",messageItem:".message-item",messageContent:".message-content",messageText:".text-content",userMessage:".message-right",candidateMessage:".message-left",messageTime:".message-time",senderName:".sender-name",inputBox:".chat-input",inputTextarea:"textarea.chat-input",inputEditorId:"#boss-chat-editor-input",sendButton:".btn-send",conversationEditor:".conversation-editor",submitButton:".submit-content .submit",submitButtonActive:".submit-content .submit.active",submitContent:".submit-content",sendButtonAlt:".conversation-editor .submit-content",sendIcon:".submit-content .icon-send",systemMessage:".system-msg"},chatDetails:{candidateInfoContainer:".base-info-single-container, .base-info-content",candidateName:".name-box, .geek-name, .base-name",candidateInfoItem:".geek-info-item, .base-info-item, .base-info-single-detial > div",candidateTag:".geek-tag, .high-light-boss",communicationPosition:".position-name",communicationPositionAlt:".position-item:not(.expect) .value.high-light-boss",candidateExpectContainer:".position-item.expect",candidateExpectValue:".position-item.expect .value.job",candidateExpectSalary:".position-item.expect .high-light-orange",candidatePosition:".geek-position, .position-name",candidatePositionAlt:".position-content .value, .position-item .value",chatMessageContainer:".conversation-message, .message-list",messageItem:".message-item",messageTime:".message-time .time",messageTextSpan:".text span",systemMessage:".item-system",friendMessage:".item-friend",myMessage:".item-myself",resumeMessage:".item-resume",readStatus:".status-read"},exchangeWechat:{exchangeButtonPath:"#container > div:nth-child(1) > div > div.chat-box > div.chat-container > div.chat-conversation > div.conversation-box > div.conversation-operate > div.toolbar-box > div.toolbar-box-right > div.operate-exchange-left > div:nth-child(3) > span.operate-btn",exchangeButtonFallback:".operate-exchange-left .operate-btn",confirmDialog:".exchange-tooltip",confirmButton:".exchange-tooltip .btn-box .boss-btn-primary.boss-btn",confirmButtonPath:"#container > div:nth-child(1) > div > div.chat-box > div.chat-container > div.chat-conversation > div.conversation-box > div.conversation-operate > div.toolbar-box > div.toolbar-box-right > div.operate-exchange-left > div:nth-child(3) > div > div > span.boss-btn-primary.boss-btn",cancelButton:".exchange-tooltip .btn-box .boss-btn-outline.boss-btn",wechatCard:".message-card-top-wrap",wechatCardAlt:'[class*="d-top-text"]'},username:{primary:".nav-item.nav-logout .user-name",fallbacks:["#header > div > div > div.nav-item.nav-logout > div.top-profile-logout.ui-dropmenu.ui-dropmenu-drop-arrow > div.ui-dropmenu-label > div > span.user-name",".ui-dropmenu-label .user-name",".nav-logout .user-name","#header .user-name",".top-profile .user-name",".nav-user .user-name",".user-name",'[class*="user-name"]','[class*="username"]','[data-qa="user-name"]',".header-user-name","#header .label-name"]},nav:{sidebar:".side-wrap.side-wrap-v2",chatLink:'.side-wrap.side-wrap-v2 a[href*="/web/chat/index"]',recommendLink:'.side-wrap.side-wrap-v2 a[href*="/web/chat/recommend"]'},recommend:{iframe:"#recommendFrame",resumeIframe:'iframe[src*="c-resume"]',filterButton:".recommend-filter .filter-label, .filter-label-wrap .filter-label, .filter-label",filterPanel:".filter-panel",candidateItem:"[data-geek], .geek-item",candidateName:".name",candidateBaseInfo:".base-info",workExps:".timeline-wrap.work-exps",expectInfo:".row-flex, .timeline-wrap.expect",salaryWrap:".salary-wrap",tagsWrap:".tags-wrap",greetButton:".btn-greet, .op-btn",resumeCanvas:"div#resume > canvas#resume, canvas#resume",closeResumeBtn:".close-btn, .dialog-close",closeResumeBtnV2:".recommendV2 .close-btn"},candidateProfile:{panel:".candidate-info, .resume-info, .geek-info",name:".candidate-info .name, .geek-info .name",age:".candidate-info .age, .geek-info .age",gender:".candidate-info .gender, .geek-info .gender",experience:".candidate-info .experience, .geek-info .work-exp",education:".candidate-info .education, .geek-info .edu",expectedSalary:".candidate-info .salary, .geek-info .expect-salary",expectedPosition:".candidate-info .position, .geek-info .expect-position",activeTime:".candidate-info .active-time, .geek-info .active"}},Ei=30,Pi=new Set(["招聘规范","消息","首页","推荐牛人","看简历","我的客服","面试","招聘数据","账号权益","升级VIP","职位","职位管理","牛人","公司","数据统计","设置","帮助中心","登录","注册","退出登录","退出","BOSS直聘","下载APP","搜索","发布职位"]);function Ti(e){const t=e.trim();return!(0===t.length||t.length>Ei)&&(!Pi.has(t)&&!/登录|注册|退出|下载|帮助|设置|管理/.test(t))}function _i(e){let t=e.priority;return Pi.has(e.text.trim())&&(t+=10),e.text.trim().length>10&&(t+=5),/^[\u4e00-\u9fff]{2,4}$/.test(e.text.trim())&&(t-=.5),void 0!==e.xRatio&&(t-=4*(e.xRatio-.5)),t}function Bi(e){const t=e.filter(e=>Ti(e.text));if(0===t.length)return{found:!1};const n=new Map;for(const e of t){const t=e.text.trim(),r=n.get(t)??new Set;r.add(e.strategy),n.set(t,r)}const r=t.map(e=>{let t=_i(e);const r=n.get(e.text.trim())?.size??1;return r>1&&(t-=.5*r),{evidence:e,score:t}}).sort((e,t)=>e.score-t.score)[0];return r?{found:!0,username:r.evidence.text.trim(),strategy:r.evidence.strategy,source:r.evidence.source}:{found:!1}}var Oi='.user-list.b-scroll-stable [role="listitem"], .geek-item',$i='.user-list.b-scroll-stable, .user-list.b-scroll-stable [role="listitem"], .geek-item',Di=".candidate-card-wrap",qi="[data-geek], .geek-item",Fi=`${Di}, ${qi}`,ji=["/web/chat/recommend"],Li=250,zi=300,Ji=900,Ui=1200,Vi=4,Hi=4,Wi=250,Ki=90,Yi=520,Gi=16,Xi=50,Zi=650,Qi=10,es=.015,ts="button, a, label, li, span, div, [role='button'], [role='radio']",ns=["not_chat_page"];function rs(e){return new Promise(t=>{setTimeout(t,e)})}function as(e){return{x:e.x,y:e.y}}function os(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function is(e){try{return"/web/chat/index"===new URL(e).pathname}catch{return e.includes("/web/chat/index")}}function ss(e){return e.trim().toLocaleLowerCase("zh-CN")}function cs(e){return e.replace(/\s+/g,"").trim().toLocaleLowerCase("zh-CN")}function ls(e,t){const n=ss(e),r=ss(t);return n.length>0&&r.length>0&&(n===r||n.includes(r)||r.includes(n))}function ds(e){return"string"==typeof e?e:""}function us(e){return"number"==typeof e&&Number.isFinite(e)?e:0}function ms(e){return"boolean"==typeof e&&e}function ps(e){return Array.isArray(e)?e.map((e,t)=>{const n=os(e)?e:{};return{conversationId:ds(n.conversationId),candidateId:ds(n.candidateId),name:ds(n.name),index:"number"==typeof n.index&&Number.isInteger(n.index)?n.index:t,position:ds(n.position),hasUnread:ms(n.hasUnread),unreadCount:"number"==typeof n.unreadCount&&Number.isInteger(n.unreadCount)?n.unreadCount:0,lastMessageTime:ds(n.lastMessageTime),messagePreview:ds(n.messagePreview)}}):[]}function gs(e){return Array.isArray(e)?e.flatMap(e=>{if(!os(e))return[];const t=e.text,n=e.strategy,r=e.priority,a=e.source,o=e.xRatio;return"string"!=typeof t||"role-link"!==n&&"role-button"!==n&&"leaf-text"!==n&&"css-fallback"!==n||"number"!=typeof r||"string"!=typeof a?[]:[{text:t,strategy:n,priority:r,source:a,..."number"==typeof o?{xRatio:o}:{}}]}):[]}function fs(e){return Array.isArray(e)?e.map((e,t)=>{const n=os(e)?e:{},r=n.tags;return{index:"number"==typeof n.index&&Number.isInteger(n.index)?n.index:t,candidateId:ds(n.candidateId),name:ds(n.name),age:ds(n.age),experience:ds(n.experience),education:ds(n.education),workStatus:ds(n.workStatus),company:ds(n.company),currentPosition:ds(n.currentPosition),expectedLocation:ds(n.expectedLocation),expectedPosition:ds(n.expectedPosition),expectedSalary:ds(n.expectedSalary),tags:Array.isArray(r)?r.map(e=>ds(e)).filter(Boolean):[],buttonText:ds(n.buttonText)}}):[]}function hs(e){return Array.isArray(e)?e.map((e,t)=>{const n=os(e)?e:{};return{index:"number"==typeof n.index&&Number.isInteger(n.index)?n.index:t,value:ds(n.value),label:ds(n.label),isCurrent:ms(n.isCurrent)}}):[]}function bs(e){return os(e)?{found:ms(e.found),isOpen:ms(e.isOpen),currentLabel:ds(e.currentLabel),currentValue:ds(e.currentValue),options:hs(e.options)}:{found:!1,isOpen:!1,currentLabel:"",currentValue:"",options:[]}}function ys(e){if(!os(e))return null;const t=ds(e.conversationId),n=ds(e.candidateId);return 0===t.length||0===n.length?null:{conversationId:t,candidateId:n,candidateName:ds(e.candidateName)}}function vs(e){if(!os(e))return null;const t=ds(e.candidateName);return t.length>0?{candidateName:t}:null}function ws(e){return Array.isArray(e)?e.flatMap((e,t)=>{if(!os(e))return[];const n=e.sender,r=e.messageType;return"candidate"!==n&&"recruiter"!==n&&"system"!==n||"text"!==r&&"system"!==r&&"resume"!==r&&"wechat-exchange"!==r?[]:[{index:"number"==typeof e.index&&Number.isInteger(e.index)?e.index:t,sender:n,messageType:r,content:ds(e.content),time:ds(e.time)}]}):[]}function xs(e){const t=os(e)?e:{},n=t.tags;return{name:ds(t.name),age:ds(t.age),experience:ds(t.experience),education:ds(t.education),communicationPosition:ds(t.communicationPosition),expectedJobText:ds(t.expectedJobText),expectedSalary:ds(t.expectedSalary),tags:Array.isArray(n)?n.map(e=>ds(e)).filter(Boolean):[]}}function Ss(e){const t=os(e)?e:{};return{selectedTarget:ys(t.selectedTarget),activePanel:vs(t.activePanel),candidateInfo:xs(t.candidateInfo),messages:ws(t.messages)}}function Is(e){return os(e)?{found:ms(e.found),x:us(e.x),y:us(e.y)}:{found:!1,x:0,y:0}}function Cs(e){return os(e)?{found:ms(e.found),left:us(e.left),top:us(e.top)}:{found:!1,left:0,top:0}}function Rs(e){return os(e)?{found:ms(e.found),cardSelector:ds(e.cardSelector)||Di,candidateId:ds(e.candidateId),name:ds(e.name),..."string"==typeof e.age?{age:e.age}:{},..."string"==typeof e.experience?{experience:e.experience}:{},..."string"==typeof e.education?{education:e.education}:{},..."string"==typeof e.workStatus?{workStatus:e.workStatus}:{},..."string"==typeof e.company?{company:e.company}:{},..."string"==typeof e.currentPosition?{currentPosition:e.currentPosition}:{},..."string"==typeof e.expectedLocation?{expectedLocation:e.expectedLocation}:{},..."string"==typeof e.expectedPosition?{expectedPosition:e.expectedPosition}:{},..."string"==typeof e.expectedSalary?{expectedSalary:e.expectedSalary}:{},hasGreetButton:ms(e.hasGreetButton),..."string"==typeof e.error?{error:e.error}:{}}:{found:!1,cardSelector:Di,candidateId:"",name:"",hasGreetButton:!1}}function ks(e){return os(e)?{..."number"==typeof e.ageMin?{ageMin:e.ageMin}:{},..."number"==typeof e.ageMax?{ageMax:e.ageMax}:{},..."number"==typeof e.minRatio?{minRatio:e.minRatio}:{},..."number"==typeof e.maxRatio?{maxRatio:e.maxRatio}:{}}:{}}function As(e){return os(e)&&!0===e.ok?{ok:!0,current:ks(e.current),trackLeft:us(e.trackLeft),trackTop:us(e.trackTop),trackWidth:us(e.trackWidth),trackHeight:us(e.trackHeight),minHandleX:us(e.minHandleX),minHandleY:us(e.minHandleY),maxHandleX:us(e.maxHandleX),maxHandleY:us(e.maxHandleY)}:{ok:!1,error:os(e)&&ds(e.error)||"未找到年龄滑块"}}function Ns(e){return os(e)?{containerFound:ms(e.containerFound),containerLabel:ds(e.containerLabel),scrollTop:us(e.scrollTop),scrollHeight:us(e.scrollHeight),clientHeight:us(e.clientHeight),itemCount:us(e.itemCount),atStart:ms(e.atStart),atEnd:ms(e.atEnd)}:{containerFound:!1,containerLabel:"",scrollTop:0,scrollHeight:0,clientHeight:0,itemCount:0,atStart:!0,atEnd:!0}}function Ms(e){return[e,...(e.childFrames??[]).flatMap(e=>Ms(e))]}function Es(e){const t=new Set,n=[];for(const r of e){const e=r.conversationId.length>0?`conversation:${r.conversationId}`:`fallback:${r.name}:${r.messagePreview}:${r.index}`;t.has(e)||(t.add(e),n.push(r))}return n}function Ps(e){return e.candidateId.length>0?e.candidateId:0!==e.name.length?[e.name,e.age,e.experience,e.expectedLocation,e.expectedPosition,e.expectedSalary].join("|"):void 0}function Ts(e,t,n){const r=t.filter(e=>Vt(e.url,"zhipin")),a=r.find(t=>e.isNativePageSelected(t.targetId));if(n.requireChatPage){if(a&&is(a.url))return a;const e=r.filter(e=>is(e.url));if(1===e.length){const t=e[0];if(t)return t}if(a)throw new Error("Selected BOSS page is not a chat page; switch to chat page first.");if(e.length>1)throw new Error("Multiple BOSS chat pages found; select the target tab first.");throw new Error("No BOSS chat page found; switch to chat page first.")}if(a)return a;if(1===r.length){const e=r[0];if(e)return e}if(r.length>1)throw new Error("Multiple BOSS pages found; select the target tab first.");throw new Error("No BOSS page found.")}async function _s(e={},t={}){const n=t.ctxManager??ue(),r=t.runtime??de(),a=Ts(n,await n.listNativePages(),e),o=await r.connectNativePage(a);return new Bs({target:a,controller:o})}var Bs=class{target;controller;mouse;recommendFrameContextId;recommendFrameContextFrameId;constructor(e){this.target=e.target,this.controller=e.controller,this.mouse=new ma(e.controller)}get targetId(){return this.target.targetId}async inspectPage(){return{...this.target,url:await this.url().catch(()=>this.target.url),title:await this.title().catch(()=>this.target.title)}}async url(){return await this.evaluateJson("location.href")}async title(){return await this.evaluateJson("document.title")}async waitForSelector(e,t=5e3){const n=Date.now();for(;Date.now()-n<t;){if(await this.evaluateJson(`document.querySelector(${JSON.stringify(e)}) !== null`).catch(()=>!1))return!0;await rs(Li)}return!1}async evaluateJson(e){return await this.controller.evaluateJson(e)}async bringToFront(){await this.controller.bringToFront()}async inspectChatReloadTarget(){const e=await this.url().catch(()=>this.target.url);return is(e)?{ok:!0,url:e}:{ok:!1,url:e,skippedReason:"not_chat_page",error:"当前 BOSS 页面不是沟通页,已跳过 reload;请先切换到沟通页。"}}async reload(e){await Gn(this.controller,{url:e.url,...void 0!==e.ignoreCache?{ignoreCache:e.ignoreCache}:{},...void 0!==e.onReloadSent?{onReloadSent:e.onReloadSent}:{}})}async isChatSurfaceOpen(){return await this.evaluateJson(`location.href.includes("/web/chat/index") ||\n document.querySelector("#container.chat-container-private") !== null ||\n document.querySelector(${JSON.stringify($i)}) !== null`)}async waitForChatSurface(e=8e3){const t=Date.now();for(;Date.now()-t<e;){if(await this.isChatSurfaceOpen().catch(()=>!1))return!0;await rs(Li)}return!1}async isRecommendSurfaceOpen(){const e=[Mi.recommend.iframe,'iframe[name="recommendFrame"]','iframe[src*="recommend"]'].join(", ");return await this.evaluateJson(`(() => {\n const href = location.href;\n const recommendUrlMarkers = ${JSON.stringify(ji)};\n const hasRecommendUrl = recommendUrlMarkers.some((marker) => href.includes(marker));\n if (hasRecommendUrl) {\n return true;\n }\n\n if (href.includes("/web/chat/index")) {\n return false;\n }\n\n const recommendFrame = document.querySelector(${JSON.stringify(e)});\n return recommendFrame !== null;\n })()`)}async waitForRecommendSurface(e=8e3){const t=Date.now();for(;Date.now()-t<e;){if(await this.isRecommendSurfaceOpen().catch(()=>!1))return!0;await rs(Li)}return!1}async resolveRecommendFrameContextId(){const e=await this.controller.getFrameTree().catch(()=>{});if(void 0===e)return;const t=Ms(e).map(e=>e.frame),n=t.find(e=>"recommendFrame"===e.name),r=t.find(t=>t.id!==e.frame.id&&t.url.includes("recommend")),a=n??r;if(void 0===a)return;if(void 0!==this.recommendFrameContextId&&this.recommendFrameContextFrameId===a.id)return this.recommendFrameContextId;const o=await this.controller.createIsolatedWorld(a.id).catch(()=>{});return void 0!==o?(this.recommendFrameContextId=o,this.recommendFrameContextFrameId=a.id,o):void 0}async evaluateRecommendFrameJson(e){const t=await this.resolveRecommendFrameContextId();if(void 0!==t)return await this.controller.evaluateJson(e,{contextId:t}).catch(()=>{})}async readRecommendFrameOffset(){return Cs(await this.evaluateJson(`(() => {\n const iframe =\n document.querySelector(${JSON.stringify(Mi.recommend.iframe)}) ??\n document.querySelector('iframe[name="recommendFrame"]') ??\n document.querySelector('iframe[src*="recommend"]');\n if (!iframe) {\n return { found: false, left: 0, top: 0 };\n }\n const rect = iframe.getBoundingClientRect();\n return { found: rect.width > 0 && rect.height > 0, left: rect.left, top: rect.top };\n })()`).catch(()=>{}))}async resolveRecommendClickTarget(e){const t=Is(await this.evaluateJson(e).catch(()=>{}));if(t.found)return t;const n=Is(await this.evaluateRecommendFrameJson(e));if(!n.found)return n;const r=await this.readRecommendFrameOffset();return r.found?{found:!0,x:Math.round(n.x+r.left),y:Math.round(n.y+r.top)}:n}async dispatchNativeClick(e,t={}){return!!e.found&&(await this.mouse.click(as(e),{...void 0!==t.motionObserver?{motionObserver:t.motionObserver}:{},...void 0!==t.preClickDelayMs?{preClickDelayMs:t.preClickDelayMs}:{},pressDurationMs:t.pressDurationMs??Ki,settleMs:t.settleMs??Wi}),!0)}async hasRecommendList(){if(!await this.isRecommendSurfaceOpen().catch(()=>!1))return!1;const e=`document.querySelector(${JSON.stringify(Fi)}) !== null`;return!!await this.evaluateJson(e).catch(()=>!1)||(await this.evaluateRecommendFrameJson(e)??!1)}async waitForRecommendList(e=1e4){const t=Date.now();for(;Date.now()-t<e;)if(await this.isRecommendSurfaceOpen().catch(()=>!1)){if(await this.hasRecommendList().catch(()=>!1))return!0;await rs(Li)}else await rs(Li);return await this.hasRecommendList().catch(()=>!1)}async readRecommendJobSelectorState(){const e='(() => {\n const visible = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0;\n };\n const text = (element) => (element.textContent ?? "").replace(/\\s+/g, " ").trim();\n const wrap = document.querySelector(".job-selecter-wrap");\n if (!wrap) {\n return {\n found: false,\n isOpen: false,\n currentLabel: "",\n currentValue: "",\n options: []\n };\n }\n\n const list = wrap.querySelector(".ui-dropmenu-list");\n const options = Array.from(wrap.querySelectorAll(".job-list .job-item")).map(\n (item, index) => {\n const labelElement = item.querySelector(".label") ?? item;\n return {\n index,\n value: item.getAttribute("value") ?? item.getAttribute("data-value") ?? "",\n label: text(labelElement),\n isCurrent: item.classList.contains("curr")\n };\n },\n );\n const current = options.find((option) => option.isCurrent);\n const label = wrap.querySelector(".ui-dropmenu-label");\n return {\n found: true,\n isOpen: Boolean(list && visible(list)),\n currentLabel: current?.label ?? (label ? text(label) : ""),\n currentValue: current?.value ?? "",\n options\n };\n })()',t=bs(await this.evaluateJson(e).catch(()=>{}));return t.found?t:bs(await this.evaluateRecommendFrameJson(e))}async openRecommendJobSelector(e={}){if((await this.readRecommendJobSelectorState()).isOpen)return!0;const t=await this.resolveRecommendClickTarget('(() => {\n const visible = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0;\n };\n const wrap = document.querySelector(".job-selecter-wrap");\n const label = wrap?.querySelector(".ui-dropmenu-label") ?? wrap;\n if (!label || !visible(label)) {\n return { found: false, x: 0, y: 0 };\n }\n label.scrollIntoView({ block: "center", inline: "center" });\n const rect = label.getBoundingClientRect();\n return {\n found: true,\n x: Math.round(rect.left + rect.width / 2),\n y: Math.round(rect.top + rect.height / 2)\n };\n })()');return!!await this.dispatchNativeClick(t,e)&&(await rs(900),(await this.readRecommendJobSelectorState()).isOpen)}async setRecommendJobSearch(e,t={}){const n=await this.resolveRecommendClickTarget('(() => {\n const visible = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0;\n };\n const input = document.querySelector(".job-selecter-wrap .top-chat-search input.ipt.chat-job-search");\n if (!(input instanceof HTMLInputElement) || !visible(input)) {\n return { found: false, x: 0, y: 0 };\n }\n input.scrollIntoView({ block: "center", inline: "center" });\n const rect = input.getBoundingClientRect();\n return {\n found: true,\n x: Math.round(rect.left + rect.width / 2),\n y: Math.round(rect.top + rect.height / 2)\n };\n })()');if(!await this.dispatchNativeClick(n,t))return!1;if(await rs(260),await this.selectAllFocusedText(),await rs(160),await this.controller.dispatchKeyEvent({type:"rawKeyDown",key:"Backspace",code:"Backspace",windowsVirtualKeyCode:8,nativeVirtualKeyCode:8}),await rs(90),await this.controller.dispatchKeyEvent({type:"keyUp",key:"Backspace",code:"Backspace",windowsVirtualKeyCode:8,nativeVirtualKeyCode:8}),0===e.length)return await rs(500),!0;await rs(350);for(const t of Array.from(e))await this.controller.insertText(t),await rs(110);return await rs(650),!0}selectRecommendJobMatch(e,t){const n=e=>{const t=e[0];return{...void 0!==t?{selected:t}:{},matchedCount:e.length}};if(void 0!==e.jobValue){return n(t.filter(t=>t.value===e.jobValue))}if(void 0!==e.jobName){const r=cs(e.jobName),a=t.filter(e=>cs(e.label)===r);if(a.length>0)return n(a);return n(t.filter(e=>cs(e.label).includes(r)))}if(void 0!==e.index){return n(t.filter(t=>t.index===e.index))}return{matchedCount:0}}getCurrentRecommendJobOption(e){const t=e.options.find(e=>e.isCurrent);return void 0!==t?t:0!==e.currentLabel.length||0!==e.currentValue.length?{index:-1,value:e.currentValue,label:e.currentLabel,isCurrent:!0}:void 0}currentRecommendJobMatchesRequest(e,t){if(void 0===t)return!1;if(void 0!==e.jobValue&&t.value.length>0)return t.value===e.jobValue;if(void 0!==e.jobName&&t.label.length>0){const n=cs(e.jobName),r=cs(t.label);return r===n||r.includes(n)}return void 0!==e.index&&t.index===e.index}hasRecommendJobAlternative(e,t){return t.some(n=>!n.isCurrent&&(void 0===e?t.length>1:n.value.length>0&&e.value.length>0?n.value!==e.value:n.label!==e.label||n.index!==e.index))}async clickRecommendJobOption(e,t={}){const n=await this.resolveRecommendClickTarget(`(() => {\n const expectedValue = ${JSON.stringify(e.value)};\n const expectedIndex = ${JSON.stringify(e.index)};\n const visible = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0;\n };\n const items = Array.from(document.querySelectorAll(".job-selecter-wrap .job-list .job-item"));\n const item = items.find((candidate, index) => {\n const value = candidate.getAttribute("value") ?? candidate.getAttribute("data-value") ?? "";\n return expectedValue.length > 0 ? value === expectedValue : index === expectedIndex;\n });\n if (!item || !visible(item)) {\n return { found: false, x: 0, y: 0 };\n }\n item.scrollIntoView({ block: "center", inline: "center" });\n const rect = item.getBoundingClientRect();\n return {\n found: true,\n x: Math.round(rect.left + rect.width / 2),\n y: Math.round(rect.top + rect.height / 2)\n };\n })()`);return await this.dispatchNativeClick(n,t)}async listRecommendJobs(e={}){if(!await this.waitForRecommendList(3e3))return{success:!1,status:"recommend_not_ready",options:[],availableCount:0,canSwitch:!1,error:"推荐牛人页未就绪"};if(!await this.openRecommendJobSelector(e)){const e=await this.readRecommendJobSelectorState(),t=this.getCurrentRecommendJobOption(e);return{success:!1,status:e.found?"selector_not_found":"recommend_not_ready",...void 0!==t?{current:t}:{},options:e.options,availableCount:e.options.length,canSwitch:!1,error:e.found?"未找到或无法打开岗位下拉":"未找到岗位下拉"}}await this.setRecommendJobSearch("",e),await rs(700);const t=await this.readRecommendJobSelectorState(),n=this.getCurrentRecommendJobOption(t);return{success:!0,status:"listed",...void 0!==n?{current:n}:{},options:t.options,availableCount:t.options.length,canSwitch:this.hasRecommendJobAlternative(n,t.options)}}async selectRecommendJob(e,t={}){const n={...e};if(!await this.waitForRecommendList(3e3))return{success:!1,status:"recommend_not_ready",requested:n,options:[],matchedCount:0,error:"推荐牛人页未就绪"};if(!await this.openRecommendJobSelector(t)){const e=await this.readRecommendJobSelectorState(),t=e.options.find(e=>e.isCurrent);return{success:!1,status:e.found?"selector_not_found":"recommend_not_ready",requested:n,...void 0!==t?{current:t}:{},options:e.options,matchedCount:0,error:e.found?"未找到或无法打开岗位下拉":"未找到岗位下拉"}}await this.setRecommendJobSearch("",t),await rs(700);let r=await this.readRecommendJobSelectorState();const a=this.getCurrentRecommendJobOption(r);if(void 0!==a&&this.currentRecommendJobMatchesRequest(n,a)&&!0!==n.forceClick)return{success:!0,status:"already_selected",requested:n,current:a,selected:a,options:r.options,matchedCount:1};let o=this.selectRecommendJobMatch(n,r.options);const i=n.searchKeyword??n.jobName;void 0===o.selected&&!1!==n.useSearch&&void 0!==i&&i.trim().length>0&&await this.setRecommendJobSearch(i,t)&&(await rs(900),r=await this.readRecommendJobSelectorState(),o=this.selectRecommendJobMatch(n,r.options));const s=this.getCurrentRecommendJobOption(r);if(void 0===o.selected)return{success:!1,status:"not_found",requested:n,...void 0!==s?{current:s}:{},options:r.options,matchedCount:o.matchedCount,error:"未找到匹配的招聘岗位"};if(o.selected.isCurrent&&!0!==n.forceClick)return{success:!0,status:"already_selected",requested:n,current:o.selected,selected:o.selected,options:r.options,matchedCount:o.matchedCount};if(!await this.clickRecommendJobOption(o.selected,t))return{success:!1,status:"selector_not_found",requested:n,...void 0!==s?{current:s}:{},selected:o.selected,options:r.options,matchedCount:o.matchedCount,error:"未能点击匹配的招聘岗位"};let c=await this.readRecommendJobSelectorState();for(let e=0;e<6;e+=1){const e=this.getCurrentRecommendJobOption(c);if(e?.value===o.selected.value||e?.label===o.selected.label)break;await rs(600),c=await this.readRecommendJobSelectorState()}const l=c.options.find(e=>e.value===o.selected?.value)??o.selected;return{success:!0,status:"selected",requested:n,current:l,selected:l,options:c.options.length>0?c.options:r.options,matchedCount:o.matchedCount}}async clickSidebarSection(e,t={}){const n="chat"===e?Mi.nav.chatLink:Mi.nav.recommendLink,r=Is(await this.evaluateJson(`(() => {\n const selector = ${JSON.stringify(n)};\n const labels = ${JSON.stringify("chat"===e?["沟通","消息"]:["推荐牛人"])};\n const normalizedLabels = labels.map((label) => label.replace(/\\s+/g, ""));\n const interactiveSelector = 'a, button, [role="link"], [role="button"]';\n const textSelector = 'span, div, li, a, button, [role="link"], [role="button"]';\n const visible = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0;\n };\n const normalizeText = (element) =>\n (element.textContent ?? "").replace(/\\s+/g, "").trim();\n const matchesExactLabel = (element) => {\n const text = normalizeText(element);\n return normalizedLabels.some((label) => text === label);\n };\n const matchesInteractiveLabel = (element) => {\n const text = normalizeText(element);\n return normalizedLabels.some(\n (label) =>\n text === label ||\n text.startsWith(label) ||\n (text.includes(label) && text.length <= label.length + 8),\n );\n };\n const area = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width * rect.height;\n };\n const readCenter = (element) => {\n element.scrollIntoView({ block: "center", inline: "center" });\n const rect = element.getBoundingClientRect();\n return {\n found: true,\n x: Math.round(rect.left + rect.width / 2),\n y: Math.round(rect.top + rect.height / 2)\n };\n };\n\n const sidebar = document.querySelector(${JSON.stringify(Mi.nav.sidebar)}) ?? document;\n const selectorTargets = Array.from(document.querySelectorAll(selector))\n .filter((element) => visible(element))\n .sort((left, right) => area(left) - area(right));\n if (selectorTargets[0]) {\n return readCenter(selectorTargets[0]);\n }\n\n const interactiveTargets = Array.from(sidebar.querySelectorAll(interactiveSelector))\n .filter((element) => visible(element) && matchesInteractiveLabel(element))\n .sort((left, right) => area(left) - area(right));\n if (interactiveTargets[0]) {\n return readCenter(interactiveTargets[0]);\n }\n\n const exactTextTargets = Array.from(sidebar.querySelectorAll(textSelector))\n .filter((element) => visible(element) && matchesExactLabel(element))\n .sort((left, right) => area(left) - area(right));\n if (exactTextTargets[0]) {\n return readCenter(exactTextTargets[0]);\n }\n\n return { found: false, x: 0, y: 0 };\n })()`));return!!r.found&&await this.dispatchNativeClick(r,t)}async scrollSurface(e,t={}){const n=Ni(e),r=t.direction??n.defaultDirection,a=Math.max(0,Math.floor(t.steps??1)),o=Math.max(0,Math.floor(t.settleMs??700)),i=await this.inspectSurface(e);let s=i,c=0;for(let n=0;n<a;n+=1){if("chat-list"===e&&s.itemCount>0){const n=await this.scrollSurfaceWithWheel(e,r,t.distance);if(void 0===n)break;if(s=n,c+=1,o>0){await rs(o);const t=await this.inspectSurface(e);s=t.containerFound||!s.containerFound?t:s}continue}if("up"===r&&s.atStart||"down"===r&&s.atEnd){if(s.itemCount<=0)break;const n=await this.scrollSurfaceWithWheel(e,r,t.distance);if(void 0===n)break;if(s=n,c+=1,o>0){await rs(o);const t=await this.inspectSurface(e);s=t.containerFound||!s.containerFound?t:s}continue}if(s=await this.scrollSurfaceOnce(e,r,t.distance),c+=1,o>0){await rs(o);const t=await this.inspectSurface(e);s=t.containerFound||!s.containerFound?t:s}}return{success:i.containerFound||s.containerFound||c>0,direction:r,stepsRequested:a,stepsCompleted:c,reachedBoundary:"up"===r?s.atStart:s.atEnd,before:i,after:s}}async readChatCandidates(e={}){const t=e.targetCount??20,n=e.autoScroll?e.maxScrolls??3:0,r=[];for(let e=0;e<=n;e+=1){r.push(...await this.readVisibleChatCandidates());const a=Es(r);if(a.length>=t||e===n)return a;if(!(await this.scrollChatList()).ok)return a;await rs(zi)}return Es(r)}async openChat(e){if(await wn(this),!await this.isChatSurfaceOpen().catch(()=>!1)){if(!await this.clickSidebarSection("chat",{...void 0!==e.motionObserver?{motionObserver:e.motionObserver}:{}})||!await this.waitForChatSurface())return{found:!1,conversationId:"",candidateId:"",name:e.candidateName??"",index:e.index??-1,position:"",hasUnread:!1,unreadCount:0,lastMessageTime:"",messagePreview:"",error:"消息列表未加载"}}const t=void 0!==e.conversationId||void 0!==e.candidateName||void 0!==e.index,n=Math.max(0,Math.floor(e.maxScrolls??(t?12:4))),r=async t=>{if(!await this.clickChatCandidate(t,{...void 0!==e.motionObserver?{motionObserver:e.motionObserver}:{}}))return{...t,found:!1,error:`未能点击候选人: ${t.name||t.conversationId}`};await rs(Wi);let n=await this.waitForNativeChatReady(t);if(!n){await this.clickChatCandidate(t,{...void 0!==e.motionObserver?{motionObserver:e.motionObserver}:{}})&&(await rs(Wi),n=await this.waitForNativeChatReady(t))}return n?{...t,found:!0}:{...t,found:!1,error:`打开候选人聊天后,右侧会话未同步切换到 ${t.name||t.conversationId}`}},a=async(n,a)=>{const o=[];for(let i=0;i<=a;i+=1){o.push(...await this.readVisibleChatCandidates());const s=Es(o),c=!0!==e.preferUnread||t?Ri(s,e):s.find(e=>e.hasUnread);if(void 0!==c)return await r(c);if(i>=a)break;if(!(await this.scrollChatList(n)).ok)break;await rs(zi)}},o=await a("down",t?0:n);if(void 0!==o)return o;if(t&&n>0){for(let e=0;e<n;e+=1){const e=await this.scrollChatList("up");if(!e.ok||e.after<=1||e.after>=e.before)break;await rs(zi)}const e=await a("down",n);if(void 0!==e)return e}return{found:!1,conversationId:"",candidateId:"",name:e.candidateName??"",index:e.index??-1,position:"",hasUnread:!1,unreadCount:0,lastMessageTime:"",messagePreview:"",error:`未找到候选人: ${e.candidateName??(void 0!==e.conversationId?`conversationId ${e.conversationId}`:`index ${e.index??0}`)}`}}async readSelectedChatTarget(){return ys(await this.evaluateJson('(() => {\n const selected = document.querySelector(".geek-item.selected");\n if (!selected) {\n return null;\n }\n\n const conversationId =\n selected.getAttribute("data-id") ??\n selected.closest(\'[role="listitem"]\')?.getAttribute("key") ??\n "";\n const candidateId =\n selected.getAttribute("data-geek") ??\n selected.querySelector("[data-geek]")?.getAttribute("data-geek") ??\n conversationId;\n const candidateName =\n selected\n .querySelector(\'[class*="name"], .nickname, .geek-name, .candidate-name\')\n ?.textContent?.trim() ?? "";\n\n return { conversationId, candidateId, candidateName };\n })()'))}async readActiveChatPanel(){return vs(await this.evaluateJson('(() => {\n const rootSelectors = [".chat-conversation", ".conversation-box", ".conversation-message"];\n const nameSelectors = [\n ".base-info-single-detial .name-box",\n ".base-info-content .name-box",\n ".base-info-single-container .name-box",\n ".base-info-content .base-name",\n ".chat-user-name",\n ".name-box",\n ".base-name",\n ];\n\n for (const rootSelector of rootSelectors) {\n const root = document.querySelector(rootSelector);\n if (!root) continue;\n\n for (const nameSelector of nameSelectors) {\n const candidateName = root.querySelector(nameSelector)?.textContent?.trim() ?? "";\n if (candidateName.length > 0) {\n return { candidateName };\n }\n }\n }\n\n return null;\n })()'))}async waitForChatMessages(e=8e3){const t=Date.now();for(;Date.now()-t<e;){if(await this.evaluateJson('document.querySelector(".chat-message-list .message-item, .conversation-message .message-item") !== null').catch(()=>!1))return!0;await rs(Li)}return await this.evaluateJson('document.querySelector(".chat-message-list .message-item, .conversation-message .message-item") !== null').catch(()=>!1)}async readCandidateChatDetails(e){const t=Math.max(0,Math.floor(e));return Ss(await this.evaluateJson(`(() => {\n const maxMsgs = ${JSON.stringify(t)};\n const selected = document.querySelector(".geek-item.selected");\n const selectedTarget = selected\n ? {\n conversationId:\n selected.getAttribute("data-id") ??\n selected.closest('[role="listitem"]')?.getAttribute("key") ??\n "",\n candidateId:\n selected.getAttribute("data-geek") ??\n selected.querySelector("[data-geek]")?.getAttribute("data-geek") ??\n selected.getAttribute("data-id") ??\n selected.closest('[role="listitem"]')?.getAttribute("key") ??\n "",\n candidateName:\n selected\n .querySelector('[class*="name"], .nickname, .geek-name, .candidate-name')\n ?.textContent?.trim() ?? ""\n }\n : null;\n\n const conversationRoot =\n document.querySelector(".chat-conversation") ??\n document.querySelector(".conversation-box") ??\n document;\n\n const nameSelectors = [\n ".base-info-single-detial .name-box",\n ".base-info-content .name-box",\n ".base-info-single-container .name-box",\n ".base-info-content .base-name",\n ".chat-user-name",\n ".name-box",\n ".base-name"\n ];\n let activePanel = null;\n for (const nameSelector of nameSelectors) {\n const candidateName =\n conversationRoot.querySelector(nameSelector)?.textContent?.trim() ?? "";\n if (candidateName.length > 0) {\n activePanel = { candidateName };\n break;\n }\n }\n\n const detailArea = conversationRoot.querySelector(\n ".base-info-single-detial, .base-info-content, .base-info-single-container"\n );\n const name =\n detailArea\n ?.querySelector(".name-box, .base-name, .chat-user-name, .geek-name")\n ?.textContent?.trim() ?? "";\n\n const infoItems = detailArea\n ? detailArea.querySelectorAll(":scope > div")\n : conversationRoot.querySelectorAll(".geek-info-item, .base-info-item");\n const infoTexts = [];\n infoItems.forEach((el) => {\n const text = el.textContent?.trim();\n if (text) infoTexts.push(text);\n });\n const fullInfo = infoTexts.join(" ");\n\n const ageMatch = fullInfo.match(/(\\d{2,3})岁/);\n const age = ageMatch ? ageMatch[1] + "岁" : "";\n const expMatch = fullInfo.match(/(\\d+年(?:以上)?|应届生|在校生)/);\n const experience = expMatch?.[1] ?? "";\n const education = fullInfo.match(/(初中|高中|中专|大专|本科|硕士|博士)/)?.[1] ?? "";\n\n let communicationPosition = "";\n const posNameEl = conversationRoot.querySelector(".position-name");\n if (posNameEl) {\n const cloned = posNameEl.cloneNode(true);\n cloned.querySelectorAll(".popover-wrap, .tooltip-job").forEach((element) => element.remove());\n communicationPosition = cloned.textContent?.trim() ?? "";\n }\n\n let expectedJobText = "";\n const expectValue = conversationRoot.querySelector(".position-item.expect .value.job");\n if (expectValue) {\n expectedJobText = expectValue.textContent?.trim() ?? "";\n }\n const expectedSalary =\n conversationRoot\n .querySelector(".position-item.expect .high-light-orange")\n ?.textContent?.trim() ?? "";\n\n const tags = [];\n if (detailArea) {\n detailArea\n .querySelectorAll(".geek-tag, .base-info-item .high-light-boss")\n .forEach((element) => {\n const text = element.textContent?.trim();\n if (text && !text.includes("更换职位") && text.length < 20) tags.push(text);\n });\n }\n\n const msgItems = conversationRoot.querySelectorAll(\n ".chat-message-list > .message-item, .conversation-message .message-item"\n );\n const timeRegex = /\\d{1,2}:\\d{2}(?::\\d{2})?|\\d{4}-\\d{2}-\\d{2}/;\n const messages = [];\n let msgIdx = 0;\n\n msgItems.forEach((item) => {\n if (msgIdx >= maxMsgs) return;\n\n const hasFriend = item.querySelector(".item-friend") !== null;\n const hasMyself = item.querySelector(".item-myself") !== null;\n const hasSystem = item.querySelector(".item-system") !== null;\n const hasResume = item.querySelector(".item-resume") !== null;\n const hasDialog = item.querySelector(".message-dialog-center") !== null;\n\n let sender = "system";\n let messageType = "text";\n if (hasFriend) {\n sender = "candidate";\n } else if (hasMyself) {\n sender = "recruiter";\n } else if (hasSystem || hasDialog) {\n sender = "system";\n messageType = "system";\n }\n if (hasResume) messageType = "resume";\n\n const cardEl = item.querySelector(".message-card-top-wrap, [class*='d-top-text']");\n if (cardEl) {\n const cardText = cardEl.textContent ?? "";\n if (cardText.includes("微信") || cardText.includes("WeChat")) {\n messageType = "wechat-exchange";\n }\n }\n\n const timeEl = item.querySelector(".message-time .time, .message-time");\n const timeMatch = (timeEl?.textContent ?? "").match(timeRegex);\n const time = timeMatch ? timeMatch[0] : "";\n\n let content = "";\n if (messageType === "wechat-exchange" && cardEl) {\n const cardText = cardEl.textContent ?? "";\n const digitMatch = cardText.match(/\\b(\\d{8,15})\\b/);\n const wxMatch = cardText.match(/微信[::号]*\\s*([a-zA-Z0-9_-]{5,20})/);\n if (digitMatch) content = "[微信号: " + digitMatch[1] + "]";\n else if (wxMatch) content = "[微信号: " + wxMatch[1] + "]";\n else content = "[交换微信]";\n } else if (cardEl) {\n const titleEl = item.querySelector(".message-card-top-title");\n const descEl = item.querySelector(".dialog-content, .message-card-top-text");\n content = (titleEl?.textContent?.trim() ?? descEl?.textContent?.trim() ?? "").trim();\n } else {\n const textEl = item.querySelector(".text span, .text-content, .text");\n if (textEl) {\n content = (textEl.textContent?.trim() ?? "")\n .replace(timeRegex, "")\n .replace("已读", "")\n .trim();\n }\n }\n\n if (content || messageType !== "text") {\n messages.push({ index: msgIdx, sender, messageType, content, time });\n msgIdx += 1;\n }\n });\n\n return {\n selectedTarget,\n activePanel,\n candidateInfo: {\n name,\n age,\n experience,\n education,\n communicationPosition,\n expectedJobText,\n expectedSalary,\n tags\n },\n messages\n };\n })()`))}async inspectRecommendCard(e){const t=Math.max(0,Math.floor(e)),n=this.buildRecommendCardInspectionExpression(t),r=Rs(await this.evaluateJson(n).catch(()=>{}));if(r.found)return r;const a=Rs(await this.evaluateRecommendFrameJson(n));return a.found?a:r}async clickRecommendGreet(e,t={}){const n=await this.inspectRecommendCard(e);if(!n.found||!n.hasGreetButton)return{...n,clicked:!1,...n.found||void 0!==n.error?{}:{error:"索引超出范围"},...n.found&&!n.hasGreetButton?{error:"未找到打招呼按钮"}:{}};const r=await this.resolveRecommendClickTarget(this.buildRecommendGreetClickExpression(Math.max(0,Math.floor(e)))),a=await this.dispatchNativeClick(r,t);return{...n,clicked:a,...a?{}:{error:"未能点击打招呼按钮"}}}async exchangeWechat(e={}){const t=Is(await this.evaluateJson('(() => {\n const selectors = [\n ".chat-conversation .conversation-operate .operate-exchange-left span.operate-btn",\n ".chat-conversation .conversation-operate span.operate-btn",\n ".conversation-box .conversation-operate .operate-exchange-left span.operate-btn",\n ".conversation-box .conversation-operate span.operate-btn",\n ".conversation-operate .operate-exchange-left span.operate-btn",\n ".conversation-operate .operate-exchange-left span"\n ];\n const normalize = (text) => (text ?? "").replace(/\\s+/g, "").trim();\n const visible = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0;\n };\n for (const selector of selectors) {\n for (const element of Array.from(document.querySelectorAll(selector))) {\n if (normalize(element.textContent) !== "换微信" || !visible(element)) continue;\n element.scrollIntoView({ block: "center", inline: "center" });\n const rect = element.getBoundingClientRect();\n return {\n found: true,\n x: Math.round(rect.left + rect.width / 2),\n y: Math.round(rect.top + rect.height / 2)\n };\n }\n }\n return { found: false, x: 0, y: 0 };\n })()').catch(()=>{}));if(!await this.dispatchNativeClick(t,e))return{success:!1,exchanged:!1,error:"未找到当前聊天输入区的「换微信」按钮"};if(!await this.waitForWechatExchangeDialog())return{success:!1,exchanged:!1,error:"确认对话框未弹出"};const n=Is(await this.evaluateJson('(() => {\n const visible = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0;\n };\n const normalize = (text) => (text ?? "").replace(/\\s+/g, "").trim();\n const tooltip = document.querySelector(".exchange-tooltip");\n const selectorGroups = tooltip\n ? [\n [tooltip, ".btn-box .boss-btn-primary.boss-btn"],\n [tooltip, ".btn-box span.boss-btn-primary"],\n [tooltip, "span.boss-btn-primary"],\n [tooltip, ".boss-btn-primary"]\n ]\n : [];\n for (const [root, selector] of selectorGroups) {\n const button = root.querySelector(selector);\n if (button && visible(button)) {\n const rect = button.getBoundingClientRect();\n return {\n found: true,\n x: Math.round(rect.left + rect.width / 2),\n y: Math.round(rect.top + rect.height / 2)\n };\n }\n }\n\n for (const container of Array.from(document.querySelectorAll("div, section, aside"))) {\n const text = container.textContent ?? "";\n if (!text.includes("交换微信") || !visible(container)) continue;\n const buttons = container.querySelectorAll(\n "span.boss-btn-primary, button.boss-btn-primary, span.boss-btn, button.boss-btn"\n );\n for (const button of Array.from(buttons)) {\n if (normalize(button.textContent) !== "确定" || !visible(button)) continue;\n const rect = button.getBoundingClientRect();\n return {\n found: true,\n x: Math.round(rect.left + rect.width / 2),\n y: Math.round(rect.top + rect.height / 2)\n };\n }\n }\n return { found: false, x: 0, y: 0 };\n })()').catch(()=>{}));if(!await this.dispatchNativeClick(n,e))return{success:!1,exchanged:!1,error:"未找到确认按钮"};await rs(1800);const r=await this.readWechatNumber();return{success:!0,exchanged:!0,...void 0!==r?{wechatNumber:r}:{}}}async sendChatReply(e,t={}){const n=Is(await this.evaluateJson('(() => {\n const selectors = ["#boss-chat-editor-input", "textarea.chat-input", ".chat-input"];\n const visible = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0;\n };\n for (const selector of selectors) {\n const element = document.querySelector(selector);\n if (!element || !visible(element)) continue;\n element.scrollIntoView({ block: "center", inline: "center" });\n const rect = element.getBoundingClientRect();\n return {\n found: true,\n x: Math.round(rect.left + rect.width / 2),\n y: Math.round(rect.top + rect.height / 2)\n };\n }\n return { found: false, x: 0, y: 0 };\n })()').catch(()=>{}));if(!await this.dispatchNativeClick(n,t))return{success:!1,error:"未找到聊天输入框"};await this.selectAllFocusedText(),await this.controller.dispatchKeyEvent({type:"rawKeyDown",key:"Backspace",code:"Backspace",windowsVirtualKeyCode:8,nativeVirtualKeyCode:8}),await this.controller.dispatchKeyEvent({type:"keyUp",key:"Backspace",code:"Backspace",windowsVirtualKeyCode:8,nativeVirtualKeyCode:8}),await this.controller.insertText(e),await rs(250);const r=Is(await this.evaluateJson('(() => {\n const selectors = [\n ".submit-content .submit.active",\n ".submit-content .submit",\n ".submit-content",\n ".btn-send"\n ];\n const visible = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0;\n };\n for (const selector of selectors) {\n const button = document.querySelector(selector);\n if (!button || !visible(button)) continue;\n const rect = button.getBoundingClientRect();\n return {\n found: true,\n x: Math.round(rect.left + rect.width / 2),\n y: Math.round(rect.top + rect.height / 2)\n };\n }\n for (const span of Array.from(document.querySelectorAll("span, button"))) {\n if ((span.textContent ?? "").replace(/\\s+/g, "").trim() !== "发送" || !visible(span)) {\n continue;\n }\n const rect = span.getBoundingClientRect();\n return {\n found: true,\n x: Math.round(rect.left + rect.width / 2),\n y: Math.round(rect.top + rect.height / 2)\n };\n }\n return { found: false, x: 0, y: 0 };\n })()').catch(()=>{}));return await this.dispatchNativeClick(r,t)?(await rs(800),{success:!0}):{success:!1,error:"未找到发送按钮"}}async applyRecommendFilter(e,t={}){const n=await this.waitForRecommendFilterSurface(3e3);if(!await this.openRecommendFilterPanel(t))return{status:n?"filter_not_found":"recommend_not_ready",requested:e,error:n?"未找到或无法打开筛选按钮":"推荐牛人页未就绪"};if(await this.detectVipModal())return{status:"requires_vip",requested:e,error:"筛选条件触发 VIP 弹窗"};if(!await this.clickRecommendFilterOption("性别",e.gender,t))return{status:"filter_not_found",requested:e,error:`未找到性别筛选项:${e.gender}`};if(!await this.clickRecommendFilterOption("活跃度",e.activity,t))return{status:"filter_not_found",requested:e,error:`未找到活跃度筛选项:${e.activity}`};const r=await this.setRecommendAgeRange(e,t);if(!r.success)return{status:"age_not_applied",requested:e,error:r.error};if(await this.detectVipModal())return{status:"requires_vip",requested:e,error:"年龄筛选触发 VIP 弹窗"};const a=await this.readNativeAppliedFilterState(e,r.state);if(!await this.clickRecommendFilterSubmit(t))return{status:"submit_failed",requested:e,applied:a,error:"筛选确认失败"};const o=await this.readRecommendFilterButtonText();return{status:"applied",requested:e,applied:a,...void 0!==o?{filterButtonText:o}:{}}}async readRecommendCandidates(e={}){const t=e.targetCount,n=e.autoScroll?e.maxScrolls??4:0,r=await this.inspectSurface("recommend-list");let a=r;const o=new Map;let i=0,s=0,c=0,l="max-steps";const d=async()=>{let e=0;const t=await this.readVisibleRecommendCandidates();for(const n of t){const t=Ps(n);void 0!==t&&0!==t.length&&(o.has(t)?s+=1:(o.set(t,n),e+=1))}return e};await d();for(let e=0;e<n;e+=1){if(void 0!==t&&o.size>=t){l="target-count";break}if(a.atEnd){let e=!1;for(let t=0;t<Vi;t+=1){await rs(Ui);const t=await d(),n=await this.inspectSurface("recommend-list"),r=t>0||n.scrollHeight>a.scrollHeight||n.itemCount>a.itemCount||!n.atEnd;if(a=n,r){t>0&&(c=0),e=!0;break}}if(!e){l="boundary";break}if(void 0!==t&&o.size>=t){l="target-count";break}}if(c>=Hi){l="no-new-items";break}const e=await this.scrollSurface("recommend-list",{direction:"down",steps:1,settleMs:Ji});a=e.after,i+=e.stepsCompleted;c=await d()>0?0:c+1}void 0!==t&&o.size>=t?l="target-count":i>=n&&(l="max-steps");const u=[...o.values()];return{success:r.containerFound,direction:"down",stepsRequested:n,stepsCompleted:i,reachedBoundary:a.atEnd,before:r,after:a,items:u,uniqueCount:u.length,duplicateCount:s,noNewRounds:c,stopReason:l}}async readUsernameEvidence(){return gs(await this.evaluateJson(`(() => {\n const limit = ${Ei};\n const evidence = [];\n const viewportWidth = window.innerWidth || 1280;\n const push = (entry) => {\n const text = String(entry.text ?? "").trim();\n if (text.length > 0 && text.length <= limit) {\n evidence.push({ ...entry, text });\n }\n };\n const scope =\n document.querySelector("header") ??\n document.querySelector("#header") ??\n document.querySelector('[role="banner"]') ??\n document.querySelector('[role="navigation"]') ??\n document.body;\n\n if (scope) {\n for (const element of Array.from(scope.querySelectorAll('a, [role="link"]'))) {\n const text = element.textContent?.trim() ?? "";\n const rect = element.getBoundingClientRect();\n push({\n text,\n strategy: "role-link",\n priority: 1,\n source: "role:link",\n xRatio: (rect.x + rect.width / 2) / viewportWidth\n });\n }\n for (const element of Array.from(scope.querySelectorAll('button, [role="button"]'))) {\n const text = element.textContent?.trim() ?? "";\n const rect = element.getBoundingClientRect();\n push({\n text,\n strategy: "role-button",\n priority: 1,\n source: "role:button",\n xRatio: (rect.x + rect.width / 2) / viewportWidth\n });\n }\n\n const walker = document.createTreeWalker(scope, NodeFilter.SHOW_TEXT);\n while (walker.nextNode()) {\n const text = walker.currentNode.textContent?.trim() ?? "";\n push({\n text,\n strategy: "leaf-text",\n priority: 3,\n source: "leaf-text"\n });\n }\n }\n\n for (const selector of ${JSON.stringify([Mi.username.primary,...Mi.username.fallbacks])}) {\n try {\n push({\n text: document.querySelector(selector)?.textContent?.trim() ?? "",\n strategy: "css-fallback",\n priority: 4,\n source: selector\n });\n } catch {\n // Ignore invalid selectors from site-specific fallback list.\n }\n }\n\n return evidence;\n })()`))}close(){this.controller.close()}buildRecommendCardInspectionExpression(e){return`(() => {\n const index = ${JSON.stringify(e)};\n const primarySelector = ${JSON.stringify(Di)};\n const fallbackSelector = ${JSON.stringify(qi)};\n const iframe = document.querySelector(${JSON.stringify(Mi.recommend.iframe)});\n const href = location.href;\n const recommendUrlMarkers = ${JSON.stringify(ji)};\n const hasRecommendUrl = recommendUrlMarkers.some((marker) => href.includes(marker));\n if (!hasRecommendUrl && href.includes("/web/chat/index")) {\n return {\n found: false,\n cardSelector: primarySelector,\n candidateId: "",\n name: "",\n hasGreetButton: false,\n error: "推荐列表未加载"\n };\n }\n\n const root = iframe?.contentDocument ?? document;\n const primaryCards = Array.from(root.querySelectorAll(primarySelector));\n const cardSelector = primaryCards.length > 0 ? primarySelector : fallbackSelector;\n const cards = primaryCards.length > 0 ? primaryCards : Array.from(root.querySelectorAll(cardSelector));\n if (cards.length <= index) {\n return {\n found: false,\n cardSelector,\n candidateId: "",\n name: "",\n hasGreetButton: false,\n error: "索引超出范围"\n };\n }\n\n const item = cards[index];\n const splitParts = (text) => (text ?? "")\n .split(/[丨·|]/)\n .map((part) => part.trim())\n .filter(Boolean);\n const candidateId =\n item.getAttribute("data-geek") ??\n item.querySelector("[data-geek]")?.getAttribute("data-geek") ??\n "";\n const name = item.querySelector(".name")?.textContent?.trim() ?? "";\n let age = "";\n let experience = "";\n let education = "";\n let workStatus = "";\n const baseInfoEl = item.querySelector(".base-info.join-text-wrap, .base-info");\n if (baseInfoEl) {\n let textParts = Array.from(baseInfoEl.querySelectorAll(":scope > *"))\n .map((child) => child.textContent?.trim() ?? "")\n .filter(Boolean);\n\n if (textParts.length <= 1) {\n textParts = splitParts(baseInfoEl.textContent?.trim() ?? "");\n }\n\n for (const part of textParts) {\n if (!age && part.includes("岁")) {\n age = part;\n } else if (!experience && (part.includes("年") || part.includes("应届") || part.includes("在校"))) {\n experience = part;\n } else if (!education && /(初中|高中|中专|中技|大专|本科|硕士|博士)/.test(part)) {\n education = part;\n } else if (!workStatus && /(在职|离职|在校)/.test(part)) {\n workStatus = part;\n }\n }\n }\n const workExpEl =\n item.querySelector(".timeline-wrap.work-exps .content.join-text-wrap") ??\n item.querySelector(".timeline-wrap.work-exps .content");\n const workParts = splitParts(workExpEl?.textContent?.trim() ?? "");\n const company = workParts[0] ?? "";\n const currentPosition = workParts[1] ?? "";\n let expectedLocation = "";\n let expectedPosition = "";\n const expectRow = item.querySelector(".row-flex:not(.geek-desc)");\n if (expectRow) {\n const labelText = expectRow.querySelector(".label")?.textContent ?? "";\n const contentEl = expectRow.querySelector(".content");\n if ((labelText.includes("期望") || labelText.includes("最近关注")) && contentEl) {\n const parts = splitParts(contentEl.textContent?.trim() ?? "");\n expectedLocation = parts[0] ?? "";\n expectedPosition = parts[1] ?? "";\n }\n }\n if (!expectedLocation) {\n const expectEl =\n item.querySelector(".timeline-wrap.expect .content.join-text-wrap") ??\n item.querySelector(".timeline-wrap.expect .content");\n if (expectEl) {\n const parts = splitParts(expectEl.textContent?.trim() ?? "");\n expectedLocation = parts[0] ?? "";\n expectedPosition = parts[1] ?? "";\n }\n }\n const greetButton =\n item.querySelector("button.btn.btn-greet") ??\n item.querySelector("button.btn-greet") ??\n item.querySelector(".btn-greet") ??\n item.querySelector(".op-btn");\n const rect = greetButton?.getBoundingClientRect();\n const hasGreetButton = Boolean(rect && rect.width > 0 && rect.height > 0);\n\n return {\n found: true,\n cardSelector,\n candidateId,\n name,\n age,\n experience,\n education,\n workStatus,\n company,\n currentPosition,\n expectedLocation,\n expectedPosition,\n expectedSalary: item.querySelector(".salary-wrap")?.textContent?.trim() ?? "",\n hasGreetButton\n };\n })()`}buildRecommendGreetClickExpression(e){return`(() => {\n const index = ${JSON.stringify(e)};\n const primarySelector = ${JSON.stringify(Di)};\n const fallbackSelector = ${JSON.stringify(qi)};\n const iframe = document.querySelector(${JSON.stringify(Mi.recommend.iframe)});\n const root = iframe?.contentDocument ?? document;\n const primaryCards = Array.from(root.querySelectorAll(primarySelector));\n const cards =\n primaryCards.length > 0\n ? primaryCards\n : Array.from(root.querySelectorAll(fallbackSelector));\n const item = cards[index];\n if (!item) return { found: false, x: 0, y: 0 };\n const button =\n item.querySelector("button.btn.btn-greet") ??\n item.querySelector("button.btn-greet") ??\n item.querySelector(".btn-greet") ??\n item.querySelector(".op-btn");\n if (!button) return { found: false, x: 0, y: 0 };\n button.scrollIntoView({ block: "center", inline: "center" });\n const rect = button.getBoundingClientRect();\n if (rect.width <= 0 || rect.height <= 0) return { found: false, x: 0, y: 0 };\n return {\n found: true,\n x: Math.round(rect.left + rect.width / 2),\n y: Math.round(rect.top + rect.height / 2)\n };\n })()`}async waitForWechatExchangeDialog(e=5e3){const t=Date.now();for(;Date.now()-t<e;){if(await this.evaluateJson('(() => {\n const visible = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0;\n };\n const tooltip = document.querySelector(".exchange-tooltip");\n if (tooltip && visible(tooltip)) return true;\n for (const element of Array.from(document.querySelectorAll("div, section, aside"))) {\n const text = element.textContent ?? "";\n if (\n text.includes("交换微信") &&\n element.querySelector(".boss-btn-primary, .boss-btn") &&\n visible(element)\n ) {\n return true;\n }\n }\n return false;\n })()').catch(()=>!1))return!0;await rs(450)}return!1}async readWechatNumber(){const e=await this.evaluateJson('(() => {\n const cardSelectors = [\n ".message-card-top-wrap",\n \'[class*="d-top-text"]\',\n ".message-card-top-title"\n ];\n const parse = (text) => {\n const digitMatch = text.match(/\\b(\\d{8,15})\\b/);\n if (digitMatch) return digitMatch[1];\n const wxMatch = text.match(/微信[::号]*\\s*([a-zA-Z0-9_-]{5,20})/);\n if (wxMatch) return wxMatch[1];\n const letterMatch = text.match(/\\b([a-zA-Z][a-zA-Z0-9_-]{5,19})\\b/);\n if (letterMatch && !["微信", "WeChat"].includes(letterMatch[1])) {\n return letterMatch[1];\n }\n return null;\n };\n\n for (const selector of cardSelectors) {\n const cards = Array.from(document.querySelectorAll(selector));\n for (let index = cards.length - 1; index >= 0; index -= 1) {\n const parsed = parse(cards[index]?.textContent ?? "");\n if (parsed) return parsed;\n }\n }\n\n const msgItems = Array.from(document.querySelectorAll(".message-item"));\n for (let index = msgItems.length - 1; index >= 0; index -= 1) {\n const card = msgItems[index]?.querySelector(\'.message-card-top-wrap, [class*="d-top-text"]\');\n if (!card) continue;\n const parsed = parse(card.textContent ?? "");\n if (parsed) return parsed;\n }\n return null;\n })()').catch(()=>null);return"string"==typeof e&&e.length>0?e:void 0}async selectAllFocusedText(){const e=[4,2];for(const t of e)await this.controller.dispatchKeyEvent({type:"rawKeyDown",key:"a",code:"KeyA",windowsVirtualKeyCode:65,nativeVirtualKeyCode:65,modifiers:t}),await this.controller.dispatchKeyEvent({type:"keyUp",key:"a",code:"KeyA",windowsVirtualKeyCode:65,nativeVirtualKeyCode:65,modifiers:t}),await rs(40)}async waitForRecommendFilterSurface(e=1e4){const t=`(() => {\n return document.querySelector(${JSON.stringify(`${Mi.recommend.filterButton}, ${Di}, ${Mi.recommend.candidateItem}`)}) !== null;\n })()`,n=Date.now();for(;Date.now()-n<e;){if(await this.evaluateJson(t).catch(()=>!1)||await this.evaluateRecommendFrameJson(t))return!0;await rs(Li)}return!1}async isRecommendFilterPanelVisible(){const e=`(() => {\n const panel = document.querySelector(${JSON.stringify(Mi.recommend.filterPanel)});\n if (!panel) return false;\n const rect = panel.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0;\n })()`;return await this.evaluateJson(e).catch(()=>!1)||(await this.evaluateRecommendFrameJson(e)??!1)}async openRecommendFilterPanel(e){if(await this.isRecommendFilterPanelVisible())return!0;for(let t=0;t<3;t+=1){await this.dismissPreviousFilterPrompt(e);const t=await this.resolveRecommendClickTarget(`(() => {\n const filterButtonSelector = ${JSON.stringify(Mi.recommend.filterButton)};\n const normalize = (text) => (text ?? "").replace(/\\s+/g, " ").trim();\n const visible = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0;\n };\n const classText = (element) =>\n typeof element.className === "string" ? element.className : "";\n const scoreCandidate = (element) => {\n const classes = classText(element);\n const parentClasses = element.parentElement ? classText(element.parentElement) : "";\n const ancestorClasses =\n element.closest(".recommend-filter, .filter-label-wrap, .filter-wrap") !== null\n ? "recommend-filter"\n : "";\n let score = 0;\n for (const value of [classes, parentClasses, ancestorClasses]) {\n if (/recommend-filter/.test(value)) score += 3;\n else if (/filter-label/.test(value)) score += 2;\n else if (/filter/.test(value)) score += 1;\n }\n return score;\n };\n const selectorCandidates = Array.from(document.querySelectorAll(filterButtonSelector));\n const textCandidates = Array.from(\n document.querySelectorAll("button, a, span, div, [role='button']")\n ).filter((element) => /^筛选(?:·\\d+)?$/.test(normalize(element.textContent)));\n const candidate = [...selectorCandidates, ...textCandidates]\n .filter(visible)\n .sort((a, b) => {\n const scoreDelta = scoreCandidate(b) - scoreCandidate(a);\n if (scoreDelta !== 0) return scoreDelta;\n const aRect = a.getBoundingClientRect();\n const bRect = b.getBoundingClientRect();\n return aRect.width * aRect.height - bRect.width * bRect.height;\n })[0];\n if (!candidate) return { found: false, x: 0, y: 0 };\n candidate.scrollIntoView({ block: "center", inline: "center" });\n const rect = candidate.getBoundingClientRect();\n return {\n found: true,\n x: Math.round(rect.left + rect.width / 2),\n y: Math.round(rect.top + rect.height / 2)\n };\n })()`);if(await this.dispatchNativeClick(t,e)){const t=Date.now();for(;Date.now()-t<4e3;){if(await this.isRecommendFilterPanelVisible())return await this.dismissPreviousFilterPrompt(e),!0;await rs(Li)}}await rs(300)}return!1}async dismissPreviousFilterPrompt(e){const t=await this.resolveRecommendClickTarget('(() => {\n const normalize = (text) => (text ?? "").replace(/\\s+/g, " ").trim();\n const visible = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0;\n };\n const roots = Array.from(document.body.querySelectorAll("div, section, aside"))\n .filter((element) => visible(element))\n .sort((a, b) => {\n const aRect = a.getBoundingClientRect();\n const bRect = b.getBoundingClientRect();\n return aRect.width * aRect.height - bRect.width * bRect.height;\n });\n for (const root of roots) {\n const text = normalize(root.textContent);\n if (!text.includes("是否应用上次") && !text.includes("上次的筛选条件")) continue;\n const candidates = Array.from(\n root.querySelectorAll("button, a, span, div, [role=\'button\']")\n ).filter(visible);\n for (const candidate of candidates) {\n const buttonText = normalize(candidate.textContent);\n if (/^(取消|不应用|否|关闭|稍后)$/.test(buttonText)) {\n const rect = candidate.getBoundingClientRect();\n return {\n found: true,\n x: Math.round(rect.left + rect.width / 2),\n y: Math.round(rect.top + rect.height / 2)\n };\n }\n }\n }\n return { found: false, x: 0, y: 0 };\n })()');return await this.dispatchNativeClick(t,e)}async clickRecommendFilterOption(e,t,n){const r=await this.resolveRecommendClickTarget(`(() => {\n const panelSelector = ${JSON.stringify(Mi.recommend.filterPanel)};\n const rowLabel = ${JSON.stringify(e)};\n const optionLabel = ${JSON.stringify(t)};\n const clickableSelector = ${JSON.stringify(ts)};\n const normalize = (text) => (text ?? "").replace(/\\s+/g, "").trim();\n const visible = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0;\n };\n const area = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width * rect.height;\n };\n const resolveClickable = (element, row) => {\n let current = element;\n while (current && current !== row.parentElement) {\n const tag = current.tagName.toLowerCase();\n const role = current.getAttribute("role") ?? "";\n if (\n tag === "button" ||\n tag === "a" ||\n tag === "label" ||\n tag === "li" ||\n role === "button" ||\n role === "radio"\n ) {\n return current;\n }\n current = current.parentElement;\n }\n return element;\n };\n\n const panel = Array.from(document.querySelectorAll(panelSelector))\n .filter(visible)\n .sort((a, b) => area(a) - area(b))[0];\n if (!panel) return { found: false, x: 0, y: 0 };\n\n const rows = Array.from(panel.querySelectorAll("div, li, dl, dd, section, ul"))\n .filter((element) => {\n const text = normalize(element.textContent);\n return visible(element) && text.includes(rowLabel) && text.includes(optionLabel);\n })\n .sort((a, b) => {\n const areaDelta = area(a) - area(b);\n if (areaDelta !== 0) return areaDelta;\n return normalize(a.textContent).length - normalize(b.textContent).length;\n });\n\n for (const row of rows) {\n const option = Array.from(row.querySelectorAll(clickableSelector))\n .filter((element) => visible(element) && normalize(element.textContent) === optionLabel)\n .sort((a, b) => area(a) - area(b))[0];\n if (!option) continue;\n const clickable = resolveClickable(option, row);\n clickable.scrollIntoView({ block: "center", inline: "center" });\n const rect = clickable.getBoundingClientRect();\n return {\n found: true,\n x: Math.round(rect.left + rect.width / 2),\n y: Math.round(rect.top + rect.height / 2)\n };\n }\n\n return { found: false, x: 0, y: 0 };\n })()`);return await this.dispatchNativeClick(r,n)}async detectVipModal(){const e='(() => {\n const normalize = (text) => (text ?? "").replace(/\\s+/g, " ").trim();\n const visible = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0;\n };\n const modalPattern =\n /(购买VIP|VIP账号|开通VIP|开启VIP|专享筛选特权|扫码支付|立即开通|支付金额)/;\n return Array.from(document.body.querySelectorAll("div, section, aside"))\n .some((element) => visible(element) && modalPattern.test(normalize(element.textContent)));\n })()';return await this.evaluateJson(e).catch(()=>!1)||(await this.evaluateRecommendFrameJson(e)??!1)}async readNativeAgeState(){const e=`(() => {\n const panelSelector = ${JSON.stringify(Mi.recommend.filterPanel)};\n const normalize = (text) => (text ?? "").replace(/\\s+/g, "").trim();\n const parseAgeValue = (text) => {\n if (text.includes("不限")) return undefined;\n const match = text.match(/\\d+/);\n return match ? Number.parseInt(match[0], 10) : undefined;\n };\n const parseAgeState = (text) => {\n const normalized = normalize(text);\n const ageText = normalized.includes("年龄")\n ? normalized.slice(normalized.indexOf("年龄") + "年龄".length)\n : normalized;\n const numbers = Array.from(ageText.matchAll(/\\d+/g), (match) =>\n Number.parseInt(match[0], 10)\n ).filter((value) => Number.isInteger(value));\n const ageMin = numbers[0];\n const ageMax = ageText.includes("不限") ? undefined : numbers[1];\n return {\n ...(ageMin !== undefined ? { ageMin } : {}),\n ...(ageMax !== undefined ? { ageMax } : {})\n };\n };\n const visible = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0;\n };\n const area = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width * rect.height;\n };\n const classText = (element) =>\n typeof element.className === "string" ? element.className : "";\n const preferRailTrack = (elements) =>\n [...elements].sort((a, b) => {\n const aClasses = classText(a);\n const bClasses = classText(b);\n if (/vue-slider-rail/.test(aClasses) && !/vue-slider-rail/.test(bClasses)) return -1;\n if (!/vue-slider-rail/.test(aClasses) && /vue-slider-rail/.test(bClasses)) return 1;\n const aRect = a.getBoundingClientRect();\n const bRect = b.getBoundingClientRect();\n const heightDelta = aRect.height - bRect.height;\n if (heightDelta !== 0) return heightDelta;\n return bRect.width - aRect.width;\n });\n const looksLikeSlider = (element) => {\n const classes = classText(element);\n const role = element.getAttribute("role") ?? "";\n return /slider|range|track|bar/i.test(classes) || role === "slider";\n };\n const looksLikeHandle = (element) => {\n const rect = element.getBoundingClientRect();\n const classes = classText(element);\n const role = element.getAttribute("role") ?? "";\n return (\n role === "slider" ||\n (/handle|handler|button|thumb|slider-btn|dot|point|circle|knob/i.test(classes) &&\n rect.width <= 80 &&\n rect.height <= 80)\n );\n };\n const readRatio = (dot, track) => {\n const styleLeft = dot.style.left;\n if (styleLeft.endsWith("%")) {\n const parsed = Number.parseFloat(styleLeft);\n if (Number.isFinite(parsed)) return Math.max(0, Math.min(1, parsed / 100));\n }\n const dotRect = dot.getBoundingClientRect();\n const trackRect = track.getBoundingClientRect();\n if (trackRect.width <= 0) return undefined;\n return Math.max(\n 0,\n Math.min(1, (dotRect.left + dotRect.width / 2 - trackRect.left) / trackRect.width)\n );\n };\n const ratioToAge = (ratio) =>\n Math.round(\n ${JSON.stringify(Gi)} +\n Math.max(0, Math.min(1, ratio)) *\n (${JSON.stringify(Xi)} -\n ${JSON.stringify(Gi)})\n );\n const panel = Array.from(document.querySelectorAll(panelSelector))\n .filter(visible)\n .sort((a, b) => area(a) - area(b))[0];\n if (!panel) return {};\n const row = Array.from(panel.querySelectorAll("div, li, section, dl, dd"))\n .filter((element) => {\n const text = normalize(element.textContent);\n return (\n visible(element) &&\n text.includes("年龄") &&\n (/\\d+|不限/.test(text) ||\n Array.from(element.querySelectorAll("*")).some(\n (child) => looksLikeSlider(child) || looksLikeHandle(child),\n ))\n );\n })\n .sort((a, b) => {\n const areaDelta = area(a) - area(b);\n if (areaDelta !== 0) return areaDelta;\n return normalize(a.textContent).length - normalize(b.textContent).length;\n })[0];\n if (!row) return {};\n const dots = Array.from(row.querySelectorAll(".vue-slider-dot"))\n .filter(visible)\n .sort((a, b) => a.getBoundingClientRect().left - b.getBoundingClientRect().left);\n const track = preferRailTrack(\n Array.from(row.querySelectorAll(".vue-slider-rail, .vue-slider")).filter(visible)\n )[0];\n if (dots.length >= 2) {\n const minDot = dots[0];\n const maxDot = dots[dots.length - 1];\n const minText = normalize(minDot?.querySelector(".vue-slider-dot-tooltip-text")?.textContent);\n const maxText = normalize(maxDot?.querySelector(".vue-slider-dot-tooltip-text")?.textContent);\n const rowText = normalize(row.textContent);\n const rowState = parseAgeState(rowText);\n const minRatio = track && minDot ? readRatio(minDot, track) : undefined;\n const maxRatio = track && maxDot ? readRatio(maxDot, track) : undefined;\n const ageMin =\n parseAgeValue(minText) ??\n rowState.ageMin ??\n (minRatio !== undefined ? ratioToAge(minRatio) : undefined);\n let ageMax = parseAgeValue(maxText) ?? rowState.ageMax;\n if (\n ageMax === undefined &&\n !maxText.includes("不限") &&\n !rowText.includes("不限") &&\n maxRatio !== undefined\n ) {\n ageMax = ratioToAge(maxRatio);\n }\n return {\n ...(ageMin !== undefined ? { ageMin } : {}),\n ...(ageMax !== undefined ? { ageMax } : {}),\n ...(minRatio !== undefined ? { minRatio } : {}),\n ...(maxRatio !== undefined ? { maxRatio } : {})\n };\n }\n return parseAgeState(normalize(row.textContent));\n })()`,t=ks(await this.evaluateJson(e).catch(()=>{}));return void 0!==t.ageMin||void 0!==t.ageMax?t:ks(await this.evaluateRecommendFrameJson(e))}async resolveNativeAgeSlider(){const e=`(() => {\n const panelSelector = ${JSON.stringify(Mi.recommend.filterPanel)};\n const normalize = (text) => (text ?? "").replace(/\\s+/g, "").trim();\n const parseAgeState = (text) => {\n const normalized = normalize(text);\n const ageText = normalized.includes("年龄")\n ? normalized.slice(normalized.indexOf("年龄") + "年龄".length)\n : normalized;\n const numbers = Array.from(ageText.matchAll(/\\d+/g), (match) =>\n Number.parseInt(match[0], 10)\n ).filter((value) => Number.isInteger(value));\n const ageMin = numbers[0];\n const ageMax = ageText.includes("不限") ? undefined : numbers[1];\n return {\n ...(ageMin !== undefined ? { ageMin } : {}),\n ...(ageMax !== undefined ? { ageMax } : {})\n };\n };\n const visible = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0;\n };\n const area = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width * rect.height;\n };\n const classText = (element) =>\n typeof element.className === "string" ? element.className : "";\n const preferRailTrack = (elements) =>\n [...elements].sort((a, b) => {\n const aClasses = classText(a);\n const bClasses = classText(b);\n if (/vue-slider-rail/.test(aClasses) && !/vue-slider-rail/.test(bClasses)) return -1;\n if (!/vue-slider-rail/.test(aClasses) && /vue-slider-rail/.test(bClasses)) return 1;\n const aRect = a.getBoundingClientRect();\n const bRect = b.getBoundingClientRect();\n const heightDelta = aRect.height - bRect.height;\n if (heightDelta !== 0) return heightDelta;\n return bRect.width - aRect.width;\n });\n const looksLikeSlider = (element) => {\n const classes = classText(element);\n const role = element.getAttribute("role") ?? "";\n return /slider|range|track|bar/i.test(classes) || role === "slider";\n };\n const looksLikeHandle = (element) => {\n const rect = element.getBoundingClientRect();\n const classes = classText(element);\n const role = element.getAttribute("role") ?? "";\n return (\n role === "slider" ||\n (/handle|handler|button|thumb|slider-btn|dot|point|circle|knob/i.test(classes) &&\n rect.width <= 80 &&\n rect.height <= 80)\n );\n };\n const panel = Array.from(document.querySelectorAll(panelSelector))\n .filter(visible)\n .sort((a, b) => area(a) - area(b))[0];\n if (!panel) return { ok: false, error: "未找到筛选面板" };\n const row = Array.from(panel.querySelectorAll("div, li, section, dl, dd"))\n .filter((element) => {\n const text = normalize(element.textContent);\n return (\n visible(element) &&\n text.includes("年龄") &&\n Array.from(element.querySelectorAll("*")).some(\n (child) => looksLikeSlider(child) || looksLikeHandle(child)\n )\n );\n })\n .sort((a, b) => {\n const areaDelta = area(a) - area(b);\n if (areaDelta !== 0) return areaDelta;\n return normalize(a.textContent).length - normalize(b.textContent).length;\n })[0];\n if (!row) return { ok: false, error: "未找到年龄滑块" };\n\n const vueSliderDots = Array.from(row.querySelectorAll(".vue-slider-dot"))\n .filter(visible)\n .sort((a, b) => a.getBoundingClientRect().left - b.getBoundingClientRect().left);\n const fallbackHandles = Array.from(row.querySelectorAll("*"))\n .filter((element) => visible(element) && looksLikeHandle(element))\n .sort((a, b) => a.getBoundingClientRect().left - b.getBoundingClientRect().left);\n const handles = vueSliderDots.length >= 2 ? vueSliderDots : fallbackHandles;\n if (handles.length < 2) {\n return { ok: false, error: "未找到年龄滑块双手柄" };\n }\n\n const minHandle = handles[0];\n const maxHandle = handles[handles.length - 1];\n const minRect = minHandle.getBoundingClientRect();\n const maxRect = maxHandle.getBoundingClientRect();\n const minDistance = Math.max(40, maxRect.left - minRect.left);\n const tracks = [\n ...preferRailTrack(Array.from(row.querySelectorAll(".vue-slider-rail, .vue-slider"))),\n ...Array.from(row.querySelectorAll("*")).filter(looksLikeSlider)\n ]\n .filter((element, index, array) => array.indexOf(element) === index)\n .filter((element) => {\n if (!visible(element)) return false;\n const rect = element.getBoundingClientRect();\n return (\n rect.width >= Math.max(80, minDistance) &&\n rect.height <= 100 &&\n rect.left <= minRect.left + minRect.width &&\n rect.right >= maxRect.right - maxRect.width\n );\n })\n .sort((a, b) => {\n const aClasses = classText(a);\n const bClasses = classText(b);\n if (/vue-slider-rail/.test(aClasses) && !/vue-slider-rail/.test(bClasses)) return -1;\n if (!/vue-slider-rail/.test(aClasses) && /vue-slider-rail/.test(bClasses)) return 1;\n const aRect = a.getBoundingClientRect();\n const bRect = b.getBoundingClientRect();\n const heightDelta = aRect.height - bRect.height;\n if (heightDelta !== 0) return heightDelta;\n return bRect.width - aRect.width;\n });\n const track = tracks[0];\n if (!track) return { ok: false, error: "未找到年龄滑块轨道" };\n const trackRect = track.getBoundingClientRect();\n return {\n ok: true,\n current: parseAgeState(normalize(row.textContent)),\n trackLeft: trackRect.left,\n trackTop: trackRect.top,\n trackWidth: trackRect.width,\n trackHeight: trackRect.height,\n minHandleX: Math.round(minRect.left + minRect.width / 2),\n minHandleY: Math.round(minRect.top + minRect.height / 2),\n maxHandleX: Math.round(maxRect.left + maxRect.width / 2),\n maxHandleY: Math.round(maxRect.top + maxRect.height / 2)\n };\n })()`,t=As(await this.evaluateJson(e).catch(()=>{}));if(t.ok)return t;const n=As(await this.evaluateRecommendFrameJson(e));if(!n.ok)return n;const r=await this.readRecommendFrameOffset();return r.found?{...n,trackLeft:n.trackLeft+r.left,trackTop:n.trackTop+r.top,minHandleX:n.minHandleX+r.left,minHandleY:n.minHandleY+r.top,maxHandleX:n.maxHandleX+r.left,maxHandleY:n.maxHandleY+r.top}:n}async dispatchNativeDrag(e,t,n,r,a={}){await this.mouse.drag({x:e,y:t},{x:n,y:r},{...void 0!==a.motionObserver?{motionObserver:a.motionObserver}:{},pressDurationMs:a.pressDurationMs??Ki})}async dragAgeHandleToRatio(e,t,n){const r=await this.resolveNativeAgeSlider();if(!r.ok||r.trackWidth<=0)return!1;const a="min"===e?r.minHandleX:r.maxHandleX,o="min"===e?r.minHandleY:r.maxHandleY,i=r.trackLeft+Math.max(0,Math.min(1,t))*r.trackWidth,s=r.trackTop+Math.max(1,r.trackHeight/2);return await this.dispatchNativeDrag(a,o,i,s,n),await rs(Zi),!0}estimateAgeRatio(e){return Math.max(0,Math.min(1,(e-Gi)/(Xi-Gi)))}clampRatio(e,t,n){return Math.max(t,Math.min(n,e))}async setAgeHandleToNumber(e,t,n){const r=await this.readNativeAgeState(),a=r.minRatio??0,o=r.maxRatio??1;let i="min"===e?0:Math.min(1,a+es),s="min"===e?Math.max(0,o-es):1,c=this.clampRatio(this.estimateAgeRatio(t),i,s);for(let r=0;r<Qi;r+=1){if(!await this.dragAgeHandleToRatio(e,c,n))return!1;const r=await this.readNativeAgeState(),a="min"===e?r.ageMin:r.ageMax;if(a===t)return!0;void 0===a?"max"===e?s=c:i=c:a<t?i=c:s=c;const o=(i+s)/2;if(Math.abs(o-c)<.001)break;c=this.clampRatio(o,i,s)}const l=await this.readNativeAgeState();return"min"===e?l.ageMin===t:l.ageMax===t}isDesiredAgeState(e,t,n){return e.ageMin===t&&e.ageMax===n}async setRecommendAgeRange(e,t){const n=e.ageMin??Gi,r=e.ageMax,a=await this.resolveNativeAgeSlider();if(!a.ok)return{success:!1,error:a.error};if(!await this.dragAgeHandleToRatio("max",1,t))return{success:!1,error:"年龄上限无法重置为不限"};if(!await this.setAgeHandleToNumber("min",n,t))return{success:!1,error:`年龄下限无法设置为 ${n}`};if(void 0===r){if(void 0!==(await this.readNativeAgeState()).ageMax&&!await this.dragAgeHandleToRatio("max",1,t))return{success:!1,error:"年龄上限无法设置为不限"}}else if(!await this.setAgeHandleToNumber("max",r,t))return{success:!1,error:`年龄上限无法设置为 ${r}`};const o=await this.readNativeAgeState();if(!this.isDesiredAgeState(o,n,r)){const e=void 0===o.ageMax?"不限":String(o.ageMax);return{success:!1,error:`年龄筛选未精确生效,当前为 ${o.ageMin??"未知"}-${e}`}}return{success:!0,state:o}}async readSelectedRecommendOptionText(e,t){const n=`(() => {\n const panelSelector = ${JSON.stringify(Mi.recommend.filterPanel)};\n const rowLabel = ${JSON.stringify(e)};\n const fallback = ${JSON.stringify(t)};\n const clickableSelector = ${JSON.stringify(ts)};\n const selectedClassPattern = /active|selected|checked|current|choose|chosen/i;\n const normalize = (text) => (text ?? "").replace(/\\s+/g, "").trim();\n const visible = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0;\n };\n const area = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width * rect.height;\n };\n const isSelected = (element) => {\n const classes = typeof element.className === "string" ? element.className : "";\n return (\n selectedClassPattern.test(classes) ||\n element.getAttribute("aria-checked") === "true" ||\n element.getAttribute("aria-selected") === "true"\n );\n };\n const panel = Array.from(document.querySelectorAll(panelSelector))\n .filter(visible)\n .sort((a, b) => area(a) - area(b))[0];\n if (!panel) return fallback;\n const row = Array.from(panel.querySelectorAll("div, li, dl, dd, section, ul"))\n .filter((element) => visible(element) && normalize(element.textContent).includes(rowLabel))\n .sort((a, b) => {\n const areaDelta = area(a) - area(b);\n if (areaDelta !== 0) return areaDelta;\n return normalize(a.textContent).length - normalize(b.textContent).length;\n })[0];\n if (!row) return fallback;\n const selected = Array.from(row.querySelectorAll(clickableSelector))\n .filter((element) => visible(element) && isSelected(element))\n .map((element) => normalize(element.textContent))\n .find((text) => text !== "" && text !== rowLabel);\n return selected ?? fallback;\n })()`,r=await this.evaluateJson(n).catch(()=>"");if(r.length>0&&r!==t)return r;const a=await this.evaluateRecommendFrameJson(n);return"string"==typeof a&&a.length>0?a:t}async readNativeAppliedFilterState(e,t){return{...void 0!==t.ageMin?{ageMin:t.ageMin}:{},...void 0!==t.ageMax?{ageMax:t.ageMax}:{},gender:await this.readSelectedRecommendOptionText("性别",e.gender),activity:await this.readSelectedRecommendOptionText("活跃度",e.activity)}}async clickRecommendFilterSubmit(e){const t=await this.resolveRecommendClickTarget(`(() => {\n const panelSelector = ${JSON.stringify(Mi.recommend.filterPanel)};\n const normalize = (text) => (text ?? "").replace(/\\s+/g, "").trim();\n const visible = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0;\n };\n const panel = Array.from(document.querySelectorAll(panelSelector)).filter(visible)[0];\n if (!panel) return { found: false, x: 0, y: 0 };\n const button = Array.from(\n panel.querySelectorAll("button, a, span, div, [role='button']")\n )\n .filter(visible)\n .find((element) => normalize(element.textContent) === "确定");\n if (!button) return { found: false, x: 0, y: 0 };\n const rect = button.getBoundingClientRect();\n return {\n found: true,\n x: Math.round(rect.left + rect.width / 2),\n y: Math.round(rect.top + rect.height / 2)\n };\n })()`);if(!await this.dispatchNativeClick(t,e))return!1;const n=Date.now();for(;Date.now()-n<4e3;){if(!await this.isRecommendFilterPanelVisible())return await rs(600),!0;await rs(Li)}return!1}async readRecommendFilterButtonText(){const e=`(() => {\n const element = document.querySelector(${JSON.stringify(Mi.recommend.filterButton)});\n const text = element?.textContent?.replace(/\\s+/g, " ").trim() ?? "";\n return text.length > 0 ? text : null;\n })()`,t=await this.evaluateJson(e).catch(()=>null);if("string"==typeof t&&t.length>0)return t;const n=await this.evaluateRecommendFrameJson(e);return"string"==typeof n&&n.length>0?n:void 0}async readVisibleChatCandidates(){return ps(await this.evaluateJson(`(() => {\n const items = Array.from(document.querySelectorAll(${JSON.stringify(Oi)}));\n return items.map((item, idx) => {\n const conversationId =\n item.getAttribute("data-id") ??\n item.closest('[role="listitem"]')?.getAttribute("key") ??\n "";\n const candidateId =\n item.getAttribute("data-geek") ??\n item.querySelector("[data-geek]")?.getAttribute("data-geek") ??\n conversationId;\n const nameEl = item.querySelector(\n '[class*="name"], .nickname, .geek-name, .candidate-name'\n );\n const name = nameEl?.textContent?.trim() ?? "";\n const position = item.querySelector(".source-job")?.textContent?.trim() ?? "";\n const badgeEl = item.querySelector(".badge-count");\n const unreadCount = parseInt(badgeEl?.textContent?.trim() ?? "0", 10) || 0;\n const hasUnread = unreadCount > 0 || item.querySelector(".red-dot") !== null;\n const lastMessageTime =\n item.querySelector(".time, .time-shadow")?.textContent?.trim() ?? "";\n const messagePreview = (\n item.querySelector(".push-text, .chat-last-msg")?.textContent?.trim() ?? ""\n ).slice(0, 100);\n\n return {\n conversationId,\n candidateId,\n name,\n index: idx,\n position,\n hasUnread,\n unreadCount,\n lastMessageTime,\n messagePreview,\n };\n });\n })()`))}async waitForNativeChatReady(e,t=6e3){const n=Date.now();for(;Date.now()-n<t;){const t=await this.readSelectedChatTarget().catch(()=>null),n=await this.readActiveChatPanel().catch(()=>null),r=null!==t&&(e.conversationId.length>0&&t.conversationId===e.conversationId||0===e.conversationId.length&&e.candidateId.length>0&&t.candidateId===e.candidateId),a=0===e.name.length||null!==n&&ls(e.name,n.candidateName);if(r&&a)return!0;await rs(Li)}return!1}async clickChatCandidate(e,t={}){const n=Is(await this.evaluateJson(`(() => {\n const expected = ${JSON.stringify({conversationId:e.conversationId,candidateId:e.candidateId,index:e.index})};\n const items = Array.from(document.querySelectorAll(${JSON.stringify(Oi)}));\n const readCandidate = (item, idx) => {\n const conversationId =\n item.getAttribute("data-id") ??\n item.closest('[role="listitem"]')?.getAttribute("key") ??\n "";\n const candidateId =\n item.getAttribute("data-geek") ??\n item.querySelector("[data-geek]")?.getAttribute("data-geek") ??\n conversationId;\n return { item, idx, conversationId, candidateId };\n };\n\n const candidates = items.map(readCandidate);\n const matched =\n candidates.find((entry) =>\n expected.conversationId.length > 0 &&\n entry.conversationId === expected.conversationId\n ) ??\n candidates.find((entry) =>\n expected.candidateId.length > 0 &&\n entry.candidateId === expected.candidateId\n ) ??\n candidates.find((entry) => entry.idx === expected.index);\n\n if (!matched) {\n return { found: false, x: 0, y: 0 };\n }\n\n matched.item.scrollIntoView({ block: "center", inline: "center" });\n const rect = matched.item.getBoundingClientRect();\n if (rect.width <= 0 || rect.height <= 0) {\n return { found: false, x: 0, y: 0 };\n }\n\n return {\n found: true,\n x: Math.round(rect.left + rect.width / 2),\n y: Math.round(rect.top + rect.height / 2)\n };\n })()`));return!!n.found&&await this.dispatchNativeClick(n,t)}async readVisibleRecommendCandidates(){if(!await this.isRecommendSurfaceOpen().catch(()=>!1))return[];const e=`(() => {\n const iframe = document.querySelector(${JSON.stringify(Mi.recommend.iframe)});\n const href = location.href;\n const recommendUrlMarkers = ${JSON.stringify(ji)};\n const hasRecommendUrl = recommendUrlMarkers.some((marker) => href.includes(marker));\n if (!hasRecommendUrl && href.includes("/web/chat/index")) {\n return [];\n }\n\n const hasRecommendShell =\n document.querySelector(".recommendV2, .recommend-list-wrap, .recommend-list, .candidate-list, .recommend-filter, .candidate-card-wrap") !== null;\n if (!hasRecommendUrl && !iframe && !hasRecommendShell) {\n return [];\n }\n\n const root = iframe?.contentDocument ?? document;\n let items = Array.from(root.querySelectorAll(${JSON.stringify(Di)}));\n if (items.length === 0 && (hasRecommendUrl || iframe || hasRecommendShell)) {\n items = Array.from(root.querySelectorAll(${JSON.stringify(qi)}));\n }\n\n return items.map((item, idx) => {\n const candidateId =\n item.getAttribute("data-geek") ??\n item.querySelector("[data-geek]")?.getAttribute("data-geek") ??\n "";\n const name = item.querySelector(".name")?.textContent?.trim() ?? "";\n\n let age = "";\n let experience = "";\n let education = "";\n let workStatus = "";\n const baseInfoEl = item.querySelector(".base-info.join-text-wrap, .base-info");\n if (baseInfoEl) {\n let textParts = Array.from(baseInfoEl.querySelectorAll(":scope > *"))\n .map((child) => child.textContent?.trim() ?? "")\n .filter(Boolean);\n\n if (textParts.length <= 1) {\n textParts = [];\n baseInfoEl.childNodes.forEach((node) => {\n if (node.nodeType === Node.TEXT_NODE) {\n const text = node.textContent?.trim() ?? "";\n if (text) textParts.push(text);\n }\n });\n }\n\n if (textParts.length <= 1) {\n textParts = (baseInfoEl.textContent?.trim() ?? "")\n .split(/[丨·|]/)\n .map((text) => text.trim())\n .filter(Boolean);\n }\n\n for (const part of textParts) {\n if (!age && part.includes("岁")) {\n age = part;\n } else if (!experience && (part.includes("年") || part.includes("应届") || part.includes("在校"))) {\n experience = part;\n } else if (!education && /(初中|高中|中专|中技|大专|本科|硕士|博士)/.test(part)) {\n education = part;\n } else if (!workStatus && /(在职|离职|在校)/.test(part)) {\n workStatus = part;\n }\n }\n }\n\n const workExpEl =\n item.querySelector(".timeline-wrap.work-exps .content.join-text-wrap") ??\n item.querySelector(".timeline-wrap.work-exps .content");\n const workParts = (workExpEl?.textContent?.trim() ?? "")\n .split("·")\n .map((text) => text.trim());\n const company = workParts[0] ?? "";\n const currentPosition = workParts[1] ?? "";\n\n let expectedLocation = "";\n let expectedPosition = "";\n const expectRow = item.querySelector(".row-flex:not(.geek-desc)");\n if (expectRow) {\n const labelText = expectRow.querySelector(".label")?.textContent ?? "";\n const contentEl = expectRow.querySelector(".content");\n if ((labelText.includes("期望") || labelText.includes("最近关注")) && contentEl) {\n const parts = (contentEl.textContent?.trim() ?? "")\n .split("·")\n .map((text) => text.trim());\n expectedLocation = parts[0] ?? "";\n expectedPosition = parts[1] ?? "";\n }\n }\n if (!expectedLocation) {\n const expectEl =\n item.querySelector(".timeline-wrap.expect .content.join-text-wrap") ??\n item.querySelector(".timeline-wrap.expect .content");\n if (expectEl) {\n const parts = (expectEl.textContent?.trim() ?? "")\n .split("·")\n .map((text) => text.trim());\n expectedLocation = parts[0] ?? "";\n expectedPosition = parts[1] ?? "";\n }\n }\n\n const tags = Array.from(\n item.querySelectorAll(".tags-wrap .tag-item, .tags-wrap .tag, .tags-wrap span")\n )\n .map((tag) => tag.textContent?.trim() ?? "")\n .filter(Boolean);\n\n return {\n index: idx,\n candidateId,\n name,\n age,\n experience,\n education,\n workStatus,\n company,\n currentPosition,\n expectedLocation,\n expectedPosition,\n expectedSalary: item.querySelector(".salary-wrap")?.textContent?.trim() ?? "",\n tags,\n buttonText: item.querySelector("button.btn.btn-greet")?.textContent?.trim() ?? "",\n };\n });\n })()`,t=fs(await this.evaluateJson(e));if(t.length>0)return t;return fs(await this.evaluateRecommendFrameJson(e))}async inspectSurface(e){const t=Ni(e),n=`(() => {\n const surface = ${JSON.stringify(e)};\n const containerSelectors = ${JSON.stringify(t.containerSelectors)};\n const itemSelector = ${JSON.stringify(t.itemSelector)};\n const iframe = document.querySelector(${JSON.stringify(Mi.recommend.iframe)});\n const href = location.href;\n const recommendUrlMarkers = ${JSON.stringify(ji)};\n const hasRecommendUrl = recommendUrlMarkers.some((marker) => href.includes(marker));\n if (surface === "recommend-list" && !hasRecommendUrl && href.includes("/web/chat/index")) {\n return {\n containerFound: false,\n containerLabel: "",\n scrollTop: 0,\n scrollHeight: 0,\n clientHeight: 0,\n itemCount: 0,\n atStart: true,\n atEnd: true\n };\n }\n\n const hasRecommendShell =\n document.querySelector(".recommendV2, .recommend-list-wrap, .recommend-list, .candidate-list, .recommend-filter, .candidate-card-wrap") !== null;\n if (surface === "recommend-list" && !hasRecommendUrl && !iframe && !hasRecommendShell) {\n return {\n containerFound: false,\n containerLabel: "",\n scrollTop: 0,\n scrollHeight: 0,\n clientHeight: 0,\n itemCount: 0,\n atStart: true,\n atEnd: true\n };\n }\n\n const root = surface === "recommend-list" ? (iframe?.contentDocument ?? document) : document;\n const readItemCount = () => {\n if (surface === "chat-list") {\n const chatList = root.querySelector(".user-list.b-scroll-stable");\n const roleItems = chatList?.querySelectorAll('[role="listitem"]');\n if (roleItems && roleItems.length > 0) return roleItems.length;\n }\n return root.querySelectorAll(itemSelector).length;\n };\n const itemCount = readItemCount();\n const isVisible = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0;\n };\n\n const isScrollable = (element) => {\n if (!isVisible(element)) return false;\n const view = element.ownerDocument?.defaultView ?? window;\n const style = view.getComputedStyle(element);\n if (style.overflowY === "hidden" || style.overflowY === "clip") return false;\n return element.scrollHeight > element.clientHeight + 2;\n };\n const labelFor = (element, fallback) => {\n if (element === document.scrollingElement) return "document";\n if (element === root.scrollingElement) return root === document ? "document" : "frame-document";\n return (\n element.id ||\n Array.from(element.classList ?? []).join(".") ||\n fallback ||\n element.tagName.toLowerCase()\n );\n };\n const targets = [];\n const pushTarget = (element, fallback) => {\n if (element && !isVisible(element)) return;\n if (!element || targets.some((target) => target.element === element)) return;\n targets.push({ element, label: labelFor(element, fallback) });\n };\n const readCssPixel = (value) => {\n const parsed = Number.parseFloat(value);\n return Number.isFinite(parsed) ? parsed : 0;\n };\n const findChatListElement = (element) => {\n if (surface !== "chat-list") return null;\n if (element.matches?.(".user-list.b-scroll-stable")) return element;\n return (\n element.querySelector?.(".user-list.b-scroll-stable") ??\n element.closest?.(".user-list.b-scroll-stable") ??\n null\n );\n };\n const readChatListSnapshot = (target) => {\n const list = findChatListElement(target.element);\n if (!list || itemCount <= 0 || !isVisible(list)) return null;\n\n const nativeScrollTop = Math.max(0, list.scrollTop);\n const nativeScrollHeight = Math.max(0, list.scrollHeight);\n const nativeClientHeight = Math.max(0, list.clientHeight);\n const nativeMaxScrollTop = Math.max(0, nativeScrollHeight - nativeClientHeight);\n if (nativeScrollHeight > nativeClientHeight + 2) {\n return {\n containerFound: true,\n containerLabel: labelFor(list, ".user-list.b-scroll-stable"),\n scrollTop: Math.round(nativeScrollTop),\n scrollHeight: Math.round(nativeScrollHeight),\n clientHeight: Math.round(nativeClientHeight),\n itemCount,\n atStart: nativeScrollTop <= 1,\n atEnd: nativeScrollTop >= nativeMaxScrollTop - 1\n };\n }\n\n const listRect = list.getBoundingClientRect();\n if (listRect.width <= 0 || listRect.height <= 0) return null;\n const group = list.querySelector('[role="group"]');\n if (!group) return null;\n\n const view = list.ownerDocument?.defaultView ?? window;\n const groupStyle = view.getComputedStyle(group);\n const paddingTop = Math.max(0, readCssPixel(groupStyle.paddingTop));\n const paddingBottom = Math.max(0, readCssPixel(groupStyle.paddingBottom));\n const roleItems = Array.from(list.querySelectorAll('[role="listitem"]'));\n const renderedItems =\n roleItems.length > 0 ? roleItems : Array.from(list.querySelectorAll(".geek-item"));\n const renderedHeight = renderedItems.reduce((sum, item) => {\n const rect = item.getBoundingClientRect();\n return sum + Math.max(0, rect.height);\n }, 0);\n const virtualHeight = Math.max(\n Math.round(paddingTop + renderedHeight + paddingBottom),\n Math.round(listRect.height)\n );\n return {\n containerFound: true,\n containerLabel: labelFor(list, ".user-list.b-scroll-stable") + ":virtual",\n scrollTop: Math.round(paddingTop),\n scrollHeight: virtualHeight,\n clientHeight: Math.round(listRect.height),\n itemCount,\n atStart: paddingTop <= 1,\n atEnd: paddingBottom <= 1\n };\n };\n\n for (const selector of containerSelectors) {\n try {\n for (const element of Array.from(root.querySelectorAll(selector))) {\n pushTarget(element, selector);\n }\n } catch {}\n }\n\n const firstVisibleItem = Array.from(root.querySelectorAll(itemSelector)).find(isVisible);\n let current = firstVisibleItem?.parentElement ?? null;\n while (current && current !== root.body && current !== root.documentElement) {\n pushTarget(current, "item-ancestor");\n current = current.parentElement;\n }\n\n if (surface === "recommend-list" && root !== document) {\n const outerFrame = iframe ?? window.frameElement;\n let outer = outerFrame?.parentElement ?? null;\n while (outer && outer !== document.body && outer !== document.documentElement) {\n pushTarget(outer, "iframe-ancestor");\n outer = outer.parentElement;\n }\n pushTarget(document.scrollingElement, "document");\n pushTarget(document.documentElement, "documentElement");\n pushTarget(document.body, "body");\n }\n pushTarget(root.scrollingElement, root === document ? "document" : "frame-document");\n\n for (const target of targets) {\n const chatListSnapshot = readChatListSnapshot(target);\n if (chatListSnapshot) return chatListSnapshot;\n }\n\n const scrollTarget = targets.find((target) => isScrollable(target.element));\n if (!scrollTarget) {\n return {\n containerFound: false,\n containerLabel: targets[0]?.label ?? "",\n scrollTop: 0,\n scrollHeight: 0,\n clientHeight: 0,\n itemCount,\n atStart: true,\n atEnd: true\n };\n }\n\n const scrollable = scrollTarget.element;\n const max = Math.max(0, scrollable.scrollHeight - scrollable.clientHeight);\n return {\n containerFound: true,\n containerLabel: scrollTarget.label,\n scrollTop: scrollable.scrollTop,\n scrollHeight: scrollable.scrollHeight,\n clientHeight: scrollable.clientHeight,\n itemCount,\n atStart: scrollable.scrollTop <= 1,\n atEnd: scrollable.scrollTop >= max - 1\n };\n })()`,r=Ns(await this.evaluateJson(n));if("recommend-list"!==e||r.itemCount>0)return r;const a=Ns(await this.evaluateRecommendFrameJson(n));return a.itemCount>0?a:r}async scrollSurfaceWithWheel(e,t,n){const r=Ni(e);await wn(this);const a=Is(await this.evaluateJson(`(() => {\n const nativeWheelTarget = true;\n const surface = ${JSON.stringify(e)};\n const containerSelectors = ${JSON.stringify(r.containerSelectors)};\n const itemSelector = ${JSON.stringify(r.itemSelector)};\n const iframe = document.querySelector(${JSON.stringify(Mi.recommend.iframe)});\n const root = surface === "recommend-list" ? (iframe?.contentDocument ?? document) : document;\n const viewportWidth = window.innerWidth || document.documentElement.clientWidth || 0;\n const viewportHeight = window.innerHeight || document.documentElement.clientHeight || 0;\n const targets = [];\n const pushTarget = (element) => {\n if (!element || targets.includes(element)) return;\n targets.push(element);\n };\n\n for (const selector of containerSelectors) {\n try {\n for (const element of Array.from(root.querySelectorAll(selector))) {\n pushTarget(element);\n }\n } catch {}\n }\n\n const firstItem = Array.from(root.querySelectorAll(itemSelector)).find((element) => {\n const rect = element.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0;\n });\n pushTarget(firstItem);\n let current = firstItem?.parentElement ?? null;\n while (current && current !== root.body && current !== root.documentElement) {\n pushTarget(current);\n current = current.parentElement;\n }\n\n const readPoint = (element) => {\n const rect = element.getBoundingClientRect();\n if (rect.width <= 0 || rect.height <= 0) return null;\n let left = rect.left;\n let top = rect.top;\n if (root !== document && iframe) {\n const frameRect = iframe.getBoundingClientRect();\n left += frameRect.left;\n top += frameRect.top;\n }\n const x = Math.round(Math.min(Math.max(left + rect.width / 2, 4), Math.max(4, viewportWidth - 4)));\n const y = Math.round(Math.min(Math.max(top + rect.height / 2, 4), Math.max(4, viewportHeight - 4)));\n return { found: true, x, y };\n };\n\n for (const element of targets) {\n const point = readPoint(element);\n if (point) return point;\n }\n\n return { found: false, x: 0, y: 0 };\n })()`));if(!a.found)return;await this.mouse.moveTo(as(a)),await this.controller.dispatchMouseEvent({type:"mouseWheel",x:a.x,y:a.y,buttons:0,deltaX:0,deltaY:"up"===t?-(n??Yi):n??Yi}),await rs(120);const o=await this.inspectSurface(e);return o.containerFound?o:{...o,containerFound:!0,containerLabel:o.containerLabel.length>0?o.containerLabel:"native-wheel",atStart:"up"!==t&&o.atStart,atEnd:"down"!==t&&o.atEnd}}async scrollSurfaceOnce(e,t,n){const r=Ni(e),a=`(() => {\n const surface = ${JSON.stringify(e)};\n const direction = ${JSON.stringify(t)};\n const explicitDistance = ${void 0!==n?JSON.stringify(n):"undefined"};\n const containerSelectors = ${JSON.stringify(r.containerSelectors)};\n const itemSelector = ${JSON.stringify(r.itemSelector)};\n const iframe = document.querySelector(${JSON.stringify(Mi.recommend.iframe)});\n const href = location.href;\n const recommendUrlMarkers = ${JSON.stringify(ji)};\n const hasRecommendUrl = recommendUrlMarkers.some((marker) => href.includes(marker));\n if (surface === "recommend-list" && !hasRecommendUrl && href.includes("/web/chat/index")) {\n return {\n containerFound: false,\n containerLabel: "",\n scrollTop: 0,\n scrollHeight: 0,\n clientHeight: 0,\n itemCount: 0,\n atStart: true,\n atEnd: true\n };\n }\n\n const hasRecommendShell =\n document.querySelector(".recommendV2, .recommend-list-wrap, .recommend-list, .candidate-list, .recommend-filter, .candidate-card-wrap") !== null;\n if (surface === "recommend-list" && !hasRecommendUrl && !iframe && !hasRecommendShell) {\n return {\n containerFound: false,\n containerLabel: "",\n scrollTop: 0,\n scrollHeight: 0,\n clientHeight: 0,\n itemCount: 0,\n atStart: true,\n atEnd: true\n };\n }\n\n const root = surface === "recommend-list" ? (iframe?.contentDocument ?? document) : document;\n const itemCount = root.querySelectorAll(itemSelector).length;\n const isVisible = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0;\n };\n const isScrollable = (element) => {\n if (!isVisible(element)) return false;\n const view = element.ownerDocument?.defaultView ?? window;\n const style = view.getComputedStyle(element);\n if (style.overflowY === "hidden" || style.overflowY === "clip") return false;\n return element.scrollHeight > element.clientHeight + 2;\n };\n const labelFor = (element, fallback) => {\n if (element === document.scrollingElement) return "document";\n if (element === root.scrollingElement) return root === document ? "document" : "frame-document";\n return (\n element.id ||\n Array.from(element.classList ?? []).join(".") ||\n fallback ||\n element.tagName.toLowerCase()\n );\n };\n const targets = [];\n const pushTarget = (element, fallback) => {\n if (element && !isVisible(element)) return;\n if (!element || targets.some((target) => target.element === element)) return;\n targets.push({ element, label: labelFor(element, fallback) });\n };\n\n for (const selector of containerSelectors) {\n try {\n for (const element of Array.from(root.querySelectorAll(selector))) {\n pushTarget(element, selector);\n }\n } catch {}\n }\n\n const firstVisibleItem = Array.from(root.querySelectorAll(itemSelector)).find(isVisible);\n let current = firstVisibleItem?.parentElement ?? null;\n while (current && current !== root.body && current !== root.documentElement) {\n pushTarget(current, "item-ancestor");\n current = current.parentElement;\n }\n\n if (surface === "recommend-list" && root !== document) {\n const outerFrame = iframe ?? window.frameElement;\n let outer = outerFrame?.parentElement ?? null;\n while (outer && outer !== document.body && outer !== document.documentElement) {\n pushTarget(outer, "iframe-ancestor");\n outer = outer.parentElement;\n }\n pushTarget(document.scrollingElement, "document");\n pushTarget(document.documentElement, "documentElement");\n pushTarget(document.body, "body");\n }\n pushTarget(root.scrollingElement, root === document ? "document" : "frame-document");\n\n const scrollTarget = targets.find((target) => isScrollable(target.element));\n if (!scrollTarget) {\n return {\n containerFound: false,\n containerLabel: targets[0]?.label ?? "",\n scrollTop: 0,\n scrollHeight: 0,\n clientHeight: 0,\n itemCount,\n atStart: true,\n atEnd: true\n };\n }\n\n const scrollable = scrollTarget.element;\n const max = Math.max(0, scrollable.scrollHeight - scrollable.clientHeight);\n const amount = explicitDistance ?? Math.max(320, Math.floor(scrollable.clientHeight * 0.85));\n scrollable.scrollTop =\n direction === "up"\n ? Math.max(0, scrollable.scrollTop - amount)\n : Math.min(max, scrollable.scrollTop + amount);\n\n return {\n containerFound: true,\n containerLabel: scrollTarget.label,\n scrollTop: scrollable.scrollTop,\n scrollHeight: scrollable.scrollHeight,\n clientHeight: scrollable.clientHeight,\n itemCount,\n atStart: scrollable.scrollTop <= 1,\n atEnd: scrollable.scrollTop >= max - 1\n };\n })()`,o=Ns(await this.evaluateJson(a));if("recommend-list"!==e||o.itemCount>0)return o;const i=Ns(await this.evaluateRecommendFrameJson(a));return i.itemCount>0?i:o}async scrollChatList(e="down"){const t=await this.scrollSurface("chat-list",{direction:e,steps:1,settleMs:0});return{ok:t.success&&t.stepsCompleted>0,before:t.before.scrollTop,after:t.after.scrollTop,max:Math.max(0,t.after.scrollHeight-t.after.clientHeight)}}};import{createHash as Os}from"node:crypto";var $s,Ds,qs={fetch:fetch,env:process.env},Fs="https://huajune.duliday.com",js=new Set;function Ls(e,t){const n=e[t]?.trim();return void 0===n||0===n.length?void 0:n}function zs(e,t){const n=Ls(e,t);if(void 0!==n){if("true"===n)return!0;if("false"===n)return!1;throw new Error(`Expected boolean env value "true" or "false" for ${t}, received "${n}".`)}}function Js(e){const t=zs(e,"RECRUITMENT_EVENTS_ENABLED"),n=Ls(e,"RECRUITMENT_EVENTS_API_BASE_URL")??Fs,r=Ls(e,"RECRUITMENT_EVENTS_API_TOKEN"),a=Ls(e,"RECRUITMENT_EVENTS_DEFAULT_AGENT_ID");return{enabled:t??!0,apiBaseUrl:n,...void 0!==r?{apiToken:r}:{},...void 0!==a?{defaultAgentId:a}:{}}}function Us(e,t){const n=be(e.defaultAgentId);if(void 0!==n)return n;he()&&Vs(t,"missing-instance-tracking","Recruitment event skipped: select a browserInstance, configure tracking-agent-id on the active browser instance, or set RECRUITMENT_EVENTS_DEFAULT_AGENT_ID.")}function Vs(e,t,n){js.has(t)||(js.add(t),e.warn(n))}function Hs(e){return`${e.replace(/\/+$/,"")}/api/v1/recruitment-events`}function Ws(e){return"object"==typeof e&&null!==e}function Ks(e,t){const n=e[t];return"string"==typeof n?n:void 0}function Ys(e){if(!Ws(e)||!Ws(e.data)||!Array.isArray(e.data.results))return;const t=e.data.results.find(e=>Ws(e)&&"error"===Ks(e,"status"));if(!Ws(t))return;const n=Ks(t,"idempotencyKey"),r=t.error,a=Ws(r)?Ks(r,"code"):void 0,o=Ws(r)?Ks(r,"message"):void 0;return`Recruitment events API rejected event${void 0!==n?` ${n}`:""}${void 0!==a?` ${a}`:""}${void 0!==o?`: ${o}`:""}`}async function Gs(e,t,n){const r=Js(n.env);if(!r.enabled)return;const a=Us(r,t);if(void 0===r.apiToken)return void Vs(t,"missing-required-config","Recruitment events tracking is enabled by default; require RECRUITMENT_EVENTS_API_TOKEN.");if(void 0===a)return void(he()||Vs(t,"missing-required-config","Recruitment events tracking is enabled by default; require RECRUITMENT_EVENTS_DEFAULT_AGENT_ID."));const o={events:[{...e,agentId:a,eventTime:e.eventTime??(new Date).toISOString()}]},i=await n.fetch(Hs(r.apiBaseUrl),{method:"POST",headers:{Authorization:`Bearer ${r.apiToken}`,"Content-Type":"application/json"},body:JSON.stringify(o)});if(!i.ok){const e=await i.text().catch(()=>"");throw new Error(`Recruitment events API request failed (${i.status})${e.length>0?`: ${e}`:""}`)}const s=Ys(await i.json().catch(()=>{}));if(void 0!==s)throw new Error(s)}function Xs(e,t){return`${e}:${Os("sha256").update(JSON.stringify(t.map(e=>e??""))).digest("hex").slice(0,24)}`}function Zs(e,t){(async()=>{const n=Ds??(async(e,t)=>{await Gs(e,t,{...qs,...$s})});await n(e,t)})().catch(e=>{t.warn(`Recruitment event tracking failed: ${e instanceof Error?e.message:String(e)}`)})}function Qs(){return(new Date).toISOString().slice(0,10)}function ec(e){const t=e?.trim();return void 0!==t&&t.length>0?t:void 0}function tc(e,t,n){const r=e?.candidateInfo,a=ec(r?.age),o=ec(r?.education),i=ec(r?.expectedSalary);return{name:ec(r?.name)??t,position:n,...void 0!==a?{age:a}:{},...void 0!==o?{education:o}:{},...void 0!==i?{expectedSalary:i}:{}}}function nc(e){return ec(e?.candidateInfo.communicationPosition)??""}function rc(e){const t=ec(e?.candidateInfo.expectedJobText);if(void 0===t)return"";const n=t.split(/[·||]/).map(e=>e.trim()).filter(Boolean);return n.length>1?n[1]??"":t}function ac(e){const t=ec(e?.candidateInfo.expectedJobText);if(void 0===t)return;const n=t.split(/[·||]/).map(e=>e.trim()).filter(Boolean);return n.length>1?ec(n[0]):void 0}function oc(e){return e.length>0?{job:{jobName:e}}:{}}function ic(e,t){return e.trim().length>0&&t.trim().length>0}function sc(e){const t=e.content.trim(),n=/微信(?:号)?\s*[::]?\s*([A-Za-z0-9_-]{5,})/.exec(t);return void 0!==n?.[1]?n[1]:/^[A-Za-z][A-Za-z0-9_-]{5,}$/.test(t)?t:void 0}function cc(e,t){for(const n of e)n.hasUnread&&0!==n.name.length&&ic(n.name,n.position)&&Zs({idempotencyKey:Xs("zhipin-message-received",[n.conversationId,n.candidateId,n.name,n.position,Qs()]),sourcePlatform:"zhipin",dataSource:"api_callback",eventType:"message_received",candidate:{name:n.name,position:n.position},job:{jobId:0,jobName:n.position},details:{unreadCount:n.unreadCount>0?n.unreadCount:1,lastMessagePreview:n.preview,conversationId:n.conversationId,candidateId:n.candidateId}},t)}function lc(e,t){const n=nc(e.candidateDetails),r=n,a=tc(e.candidateDetails,e.candidateName,r);if(!ic(a.name,a.position))return;const o=ac(e.candidateDetails);Zs({idempotencyKey:Xs("zhipin-message-sent",[e.conversationId,e.candidateId,e.replyId]),sourcePlatform:"zhipin",dataSource:"api_callback",eventType:"message_sent",candidate:{...a,...void 0!==o?{expectedLocation:o}:{}},...oc(n),details:{content:e.message,isAutoReply:!0,unreadCountBeforeReply:e.unreadCountBeforeReply,wasUnreadBeforeReply:e.unreadCountBeforeReply>0,conversationId:e.conversationId,candidateId:e.candidateId}},t)}function dc(e,t){if(!e.clicked||0===e.name.length)return;const n=ec(e.expectedPosition);if(void 0===n||!ic(e.name,n))return;const r=ec(e.age),a=ec(e.education),o=ec(e.expectedSalary),i=ec(e.expectedLocation);Zs({idempotencyKey:Xs("zhipin-candidate-contacted",[e.candidateId,e.name,Qs()]),sourcePlatform:"zhipin",dataSource:"api_callback",eventType:"candidate_contacted",candidate:{name:e.name,position:n,...void 0!==r?{age:r}:{},...void 0!==a?{education:a}:{},...void 0!==o?{expectedSalary:o}:{},...void 0!==i?{expectedLocation:i}:{}},details:{candidateId:e.candidateId}},t)}function uc(e,t){const n=nc(e.candidateDetails),r=tc(e.candidateDetails,e.candidateName,n);if(!ic(r.name,r.position))return;const a=ac(e.candidateDetails);Zs({idempotencyKey:Xs("zhipin-wechat-requested",[e.conversationId,e.candidateId,Qs()]),sourcePlatform:"zhipin",dataSource:"api_callback",eventType:"wechat_exchanged",candidate:{...r,...void 0!==a?{expectedLocation:a}:{}},...oc(n),details:{exchangeType:e.exchangeType??(void 0!==e.wechatNumber?"accepted":"requested"),conversationId:e.conversationId,candidateId:e.candidateId,...void 0!==e.wechatNumber?{wechatNumber:e.wechatNumber}:{}}},t)}function mc(e,t,n,r){const a=nc(e),o=rc(e),i=ac(e),s=tc(e,e.candidateInfo.name,o);if(!ic(s.name,s.position))return;const c=e.messages.find(e=>"wechat-exchange"===e.messageType);if(void 0===c)return;const l=sc(c);Zs({idempotencyKey:Xs("zhipin-wechat-completed",[t,n]),sourcePlatform:"zhipin",dataSource:"api_callback",eventType:"wechat_exchanged",candidate:{...s,...void 0!==i?{expectedLocation:i}:{}},...oc(a),details:{exchangeType:"completed",conversationId:t,candidateId:n,messageIndex:c.index,...void 0!==l?{wechatNumber:l}:{}}},r)}var pc,gc=wi.object({name:wi.string(),conversationId:wi.string(),candidateId:wi.string(),position:wi.string(),time:wi.string(),preview:wi.string(),unreadCount:wi.number(),hasUnread:wi.boolean(),index:wi.number()}),fc=wi.object({success:wi.boolean(),candidates:wi.array(gc),total:wi.number(),stats:wi.object({withName:wi.number(),withUnread:wi.number()})});function hc(){return{openNativePagePort:_s,createNativeVisualActivitySession:e=>new ha(e),...pc}}function bc(e){return e.conversationId.length>0?e.conversationId:e.candidateId.length>0?e.candidateId:0!==e.name.length?[e.name,e.position,e.lastMessageTime].join("|"):void 0}function yc(e){const t=new Set,n=[];for(const r of e){const e=bc(r);void 0!==e&&t.has(e)||(void 0!==e&&t.add(e),n.push(r))}return n}var vc=vi({name:"zhipin_read_messages",description:"读取 BOSS直聘消息列表,默认返回全部候选人;若只看未读消息,传 onlyUnread=true",input:wi.object({limit:wi.number().optional().describe("最多返回条数"),onlyUnread:wi.boolean().default(!1).describe("是否只返回有未读消息的候选人;用户说“全部/所有消息列表”时应为 false,说“未读消息”时应为 true"),sortBy:wi.enum(["time","unreadCount","name"]).default("time"),autoScroll:wi.boolean().default(!0).describe("是否自动向下滚动消息列表并合并采集结果"),maxScrolls:wi.number().int().min(0).max(50).default(4).describe("自动滚动的最大步数")}),output:fc,execute:async(e,t)=>{const n=e.onlyUnread??!1;let r,a;t.logger.info(`Reading zhipin messages (limit: ${e.limit??"all"}, onlyUnread: ${n})`);const o=hc();try{r=await o.openNativePagePort({requireChatPage:!0}),a=o.createNativeVisualActivitySession(r),await a.begin("正在读取消息列表");if(!await r.waitForSelector('.user-list.b-scroll-stable, .user-list.b-scroll-stable [role="listitem"], .geek-item',5e3))return await a.fail("未找到消息列表"),{success:!1,candidates:[],total:0,stats:{withName:0,withUnread:0}};const i=n?"正在读取未读消息列表":"正在读取消息列表";await a.highlightSelector(".user-list.b-scroll-stable, .chat-user .user-container, .chat-user",{label:i,padding:8});const s=e.autoScroll??!0,c=e.maxScrolls??4,l=yc(await r.readChatCandidates({autoScroll:s,maxScrolls:c,...void 0===e.limit||n?{}:{targetCount:e.limit}})).map(e=>({name:e.name,conversationId:e.conversationId,candidateId:e.candidateId,position:e.position,time:e.lastMessageTime,preview:e.messagePreview,unreadCount:e.unreadCount,hasUnread:e.hasUnread,index:e.index}));let d=n?l.filter(e=>e.hasUnread):l;const u=e.sortBy??"time";"time"===u||("unreadCount"===u?d.sort((e,t)=>t.unreadCount-e.unreadCount):"name"===u&&d.sort((e,t)=>e.name.localeCompare(t.name))),void 0!==e.limit&&(d=d.slice(0,e.limit));const m={withName:l.filter(e=>e.name.length>0).length,withUnread:l.filter(e=>e.hasUnread).length};return await a.succeed(n?`已读取 ${d.length} 条未读消息`:`已读取 ${d.length} 条消息`),t.logger.info(`Found ${d.length} candidates (${m.withUnread} with unread)`),cc(d,t.logger),{success:!0,candidates:d,total:l.length,stats:m}}catch(e){return await(a?.fail("读取消息列表失败")),t.logger.warn(`Native zhipin message read failed: ${e instanceof Error?e.message:String(e)}`),{success:!1,candidates:[],total:0,stats:{withName:0,withUnread:0}}}finally{r?.close()}}});import{BrowserActionApprovalSchema as wc,BrowserPageInfoSchema as xc}from"@roll-agent/browser";import{defineTool as Sc,StructuredToolError as Ic}from"@roll-agent/sdk";import{z as Cc}from"zod";var Rc,kc=Cc.object({forceReload:Cc.boolean().optional().describe("为 true 时先对当前沟通页执行 native CDP Page.reload,清空长跑累积的 DOM/SPA 状态后再确认沟通页就绪;用于长跑 tab 的周期性恢复。"),browserActionApproval:wc.optional().describe("当 actionPolicy=confirm 返回 needs_confirmation 后,由 orchestrator 原样带回的批准 ID(仅 forceReload 时需要)。")}),Ac=Cc.object({success:Cc.boolean(),alreadyOnChat:Cc.boolean(),usedSidebarClick:Cc.boolean(),usedReload:Cc.boolean(),chatReady:Cc.boolean(),reloadSkippedReason:Cc.enum(ns).optional(),page:xc.optional(),error:Cc.string().optional()});function Nc(){return{getContextManager:ue,getRuntime:de,openNativePagePort:_s,createNativeVisualActivitySession:e=>new ha(e),...Rc}}async function Mc(e,t){return Wt(e,await t.inspectPage())}var Ec=Sc({name:"zhipin_open_chat_page",description:"通过点击 Boss 左侧导航切换回「沟通」页,避免让编排器依赖站内 URL 猜测;forceReload=true 时改为对当前沟通页执行 native reload 做恢复。",input:kc,output:Ac,execute:async(e,t)=>{const n=Nc(),r=n.getContextManager();let a,o,i=!1;t.logger.info("Opening Boss chat page via native sidebar navigation");try{if(a=await n.openNativePagePort(!0===e.forceReload?{requireChatPage:!0}:{}),o=n.createNativeVisualActivitySession(a),await wn(a),!0===e.forceReload){const s=await a.inspectChatReloadTarget();if(!s.ok)return await o.fail("当前不是沟通页"),{success:!1,alreadyOnChat:!1,usedSidebarClick:!1,usedReload:!1,chatReady:!1,reloadSkippedReason:s.skippedReason,page:await Mc(r,a),error:s.error};hn(t,n.getRuntime(),{action:"navigate",target:s.url,url:s.url,...void 0!==e.browserActionApproval?{approval:e.browserActionApproval}:{}}),await o.begin("正在刷新沟通页"),t.logger.info("Reloading Boss chat page via native CDP Page.reload"),await a.reload({url:s.url,onReloadSent:()=>{i=!0}})}else{const e="正在切换到沟通页";await o.begin(e),await o.highlightSelector(Mi.nav.sidebar,{label:e,padding:10})}if(await a.isChatSurfaceOpen())return await o.succeed(i?"已刷新沟通页":"已在沟通页"),{success:!0,alreadyOnChat:!i,usedSidebarClick:!1,usedReload:i,chatReady:!0,page:await Mc(r,a)};if(!await a.clickSidebarSection("chat",{...void 0!==o?{motionObserver:o}:{}}))return await o.fail("未找到沟通导航"),{success:!1,alreadyOnChat:!1,usedSidebarClick:!1,usedReload:i,chatReady:!1,page:await Mc(r,a),error:"未找到沟通导航"};t.logger.info("Clicked Boss sidebar nav: 沟通");return await a.waitForChatSurface()?(await o.succeed("已切换到沟通页"),{success:!0,alreadyOnChat:!1,usedSidebarClick:!0,usedReload:i,chatReady:!0,page:await Mc(r,a)}):(await o.fail("沟通页未就绪"),{success:!1,alreadyOnChat:!1,usedSidebarClick:!0,usedReload:i,chatReady:!1,page:await Mc(r,a),error:"沟通页未就绪"})}catch(e){if(e instanceof Ic)throw await(o?.fail("沟通页操作未获授权")),e;return await(o?.fail("切换沟通页失败")),{success:!1,alreadyOnChat:!1,usedSidebarClick:!1,usedReload:i,chatReady:!1,error:e instanceof Error?e.message:"切换沟通页失败"}}finally{a?.close()}}});import{defineTool as Pc}from"@roll-agent/sdk";import{z as Tc}from"zod";var _c,Bc=Tc.object({success:Tc.boolean(),conversationId:Tc.string(),candidateId:Tc.string(),candidateName:Tc.string(),index:Tc.number(),hasUnread:Tc.boolean(),unreadCount:Tc.number(),lastMessageTime:Tc.string(),messagePreview:Tc.string(),error:Tc.string().optional()});function Oc(){return{openNativePagePort:_s,createNativeVisualActivitySession:e=>new ha(e),..._c}}var $c=Pc({name:"zhipin_open_chat",description:"打开指定候选人的聊天窗口(优先按 conversationId,其次姓名,最后才用索引)",input:Tc.object({conversationId:Tc.string().optional().describe("会话 ID。若已从 `zhipin_read_messages` 获取,优先传这个,最稳定"),candidateName:Tc.string().optional().describe("候选人姓名。若用户说“打开鲁倩的聊天”,这里应提取为“鲁倩”"),index:Tc.number().optional().describe("候选人在列表中的索引。仅在缺少 conversationId 时兜底"),preferUnread:Tc.boolean().default(!1).describe("优先选择有未读消息的候选人")}),output:Bc,execute:async(e,t)=>{t.logger.info(`Opening chat: name=${e.candidateName??"N/A"}, index=${e.index??"N/A"}`);const n=Oc();let r,a;try{r=await n.openNativePagePort(),a=n.createNativeVisualActivitySession(r),await a.begin("正在打开目标聊天"),await a.highlightSelector(".user-list.b-scroll-stable, .chat-user .user-container, .chat-user",{label:"正在定位候选人",padding:8});const o=await r.openChat({conversationId:e.conversationId,candidateName:e.candidateName,index:e.index,preferUnread:e.preferUnread??!1,...void 0!==a?{motionObserver:a}:{}});return o.found?(await a.succeed(`已打开 ${o.name||"目标"} 的聊天`),t.logger.info(`Opened chat with ${o.name} (index: ${o.index})`),{success:!0,conversationId:o.conversationId,candidateId:o.candidateId,candidateName:o.name,index:o.index,hasUnread:o.hasUnread,unreadCount:o.unreadCount,lastMessageTime:o.lastMessageTime,messagePreview:o.messagePreview}):(await a.fail("打开聊天失败"),{success:!1,conversationId:"",candidateId:"",candidateName:e.candidateName??"",index:e.index??-1,hasUnread:!1,unreadCount:0,lastMessageTime:"",messagePreview:"",error:o.error??`未找到候选人: ${e.candidateName??`index ${e.index}`}`})}catch(n){return await(a?.fail("打开聊天失败")),t.logger.warn(`Native zhipin open chat failed: ${n instanceof Error?n.message:String(n)}`),{success:!1,conversationId:"",candidateId:"",candidateName:e.candidateName??"",index:e.index??-1,hasUnread:!1,unreadCount:0,lastMessageTime:"",messagePreview:"",error:n instanceof Error?n.message:"打开聊天失败"}}finally{r?.close()}}});import{defineTool as Dc}from"@roll-agent/sdk";import{z as qc}from"zod";var Fc="·",jc=/[--—–]/;function Lc(e){return(e??"").trim()}function zc(e){const t=Lc(e);if(!t||!jc.test(t))return;const[n=""]=t.split(jc);return Lc(n)||void 0}function Jc(e){const t=Lc(e);if(!t)return{expectedLocation:"",expectedPosition:""};const[n="",r=""]=t.split(Fc).map(e=>Lc(e));return{expectedLocation:n,expectedPosition:r}}function Uc(e){const t=Lc(e.communicationPosition),{expectedLocation:n,expectedPosition:r}=Jc(e.expectedJobText),a=zc(t);return{communicationPosition:t,expectedLocation:n,expectedPosition:r,...void 0!==a?{preferredBrand:a}:{}}}var Vc,Hc=qc.object({index:qc.number(),sender:qc.enum(["candidate","recruiter","system"]),messageType:qc.enum(["text","system","resume","wechat-exchange"]),content:qc.string(),time:qc.string()}),Wc=qc.object({name:qc.string(),age:qc.string(),experience:qc.string(),education:qc.string(),communicationPosition:qc.string(),expectedPosition:qc.string(),expectedLocation:qc.string(),expectedSalary:qc.string(),tags:qc.array(qc.string())}),Kc=qc.object({success:qc.boolean(),conversationId:qc.string(),candidateId:qc.string(),candidateInfo:Wc,preferredBrand:qc.string().optional(),chatMessages:qc.array(Hc),formattedHistory:qc.array(qc.string()),stats:qc.object({totalMessages:qc.number(),candidateMessages:qc.number(),recruiterMessages:qc.number(),systemMessages:qc.number()}),error:qc.string().optional()});function Yc(){return{name:"",age:"",experience:"",education:"",communicationPosition:"",expectedPosition:"",expectedLocation:"",expectedSalary:"",tags:[]}}function Gc(e){return{success:!1,conversationId:"",candidateId:"",candidateInfo:Yc(),chatMessages:[],formattedHistory:[],stats:{totalMessages:0,candidateMessages:0,recruiterMessages:0,systemMessages:0},error:e}}function Xc(e,t){const n=e.trim().toLocaleLowerCase("zh-CN"),r=t.trim().toLocaleLowerCase("zh-CN");return n.length>0&&r.length>0&&(n===r||n.includes(r)||r.includes(n))}function Zc(){return{openNativePagePort:_s,createNativeVisualActivitySession:e=>new ha(e),...Vc}}var Qc=Dc({name:"zhipin_get_candidate_info",description:"提取候选人资料和完整聊天记录。可指定 conversationId 或 candidateName 自动打开对应聊天;若已从 `zhipin_read_messages` 获取 conversationId,优先传它。",input:qc.object({conversationId:qc.string().optional().describe("会话 ID。若已从 `zhipin_read_messages` 获取,优先传这个,最稳定"),candidateName:qc.string().optional().describe("候选人姓名。若用户说“查看鲁倩的聊天详情”,这里应提取为“鲁倩”"),index:qc.number().optional().describe("候选人在列表中的索引(可选,仅兜底)"),maxMessages:qc.number().default(100).describe("最多返回的消息条数")}),output:Kc,execute:async(e,t)=>{const n=e.maxMessages??100,r=Zc(),a=void 0!==e.conversationId||void 0!==e.candidateName||void 0!==e.index;let o,i;const s=a?"正在打开目标聊天":"正在准备当前聊天",c="正在提取聊天记录",l=async(e,t)=>(await(i?.fail(e)),Gc(t));try{o=await r.openNativePagePort(),i=r.createNativeVisualActivitySession(o),await i.begin(s);const d=a?await o.openChat({conversationId:e.conversationId,candidateName:e.candidateName,index:e.index,maxScrolls:4}):void 0;if(void 0!==d&&!d.found)return await l("打开聊天失败",d.error??"打开聊天失败");if(void 0===d&&!await o.isChatSurfaceOpen().catch(()=>!1))return await l("当前不是沟通页","当前页面不是 BOSS 沟通页,无法读取当前聊天详情");t.logger.info("Extracting candidate info"+(void 0!==d?` for ${d.name}`:" (current window)")),await i.begin(c),await i.highlightSelector(".chat-conversation, .conversation-box, .conversation-message",{label:c,padding:12});const u=d?.name??e.candidateName??"",m=await o.readActiveChatPanel();if(u.length>0&&(!m||!Xc(u,m.candidateName)))return await l("聊天面板未同步",`右侧聊天面板未切换到 ${u}`);const p=await o.readSelectedChatTarget();if(!p)return await l("未识别当前会话","未能提取当前选中聊天的 conversationId/candidateId");if(!(void 0===d||d.conversationId.length>0&&p.conversationId===d.conversationId||0===d.conversationId.length&&d.candidateId.length>0&&p.candidateId===d.candidateId))return await l("当前会话不一致",`当前选中会话与目标会话不一致: ${d?.name||d?.conversationId||""}`);if(m&&p.candidateName.length>0&&!Xc(p.candidateName,m.candidateName))return await l("左右面板不一致",`左侧选中会话与右侧聊天面板不一致: ${p.candidateName} / ${m.candidateName}`);await o.waitForChatMessages();const g=await o.readCandidateChatDetails(n),f=Uc({communicationPosition:g.candidateInfo.communicationPosition,expectedJobText:g.candidateInfo.expectedJobText}),h=g.messages.filter(e=>"candidate"===e.sender||"recruiter"===e.sender).map(e=>`${"candidate"===e.sender?"求职者":"我"}: ${e.content}`),b={totalMessages:g.messages.length,candidateMessages:g.messages.filter(e=>"candidate"===e.sender).length,recruiterMessages:g.messages.filter(e=>"recruiter"===e.sender).length,systemMessages:g.messages.filter(e=>"system"===e.sender).length};return await i.succeed(`已提取 ${b.totalMessages} 条聊天记录`),t.logger.info(`Extracted info for ${g.candidateInfo.name}: ${b.totalMessages} messages`),mc(g,p.conversationId,p.candidateId,t.logger),{success:!0,conversationId:p.conversationId,candidateId:p.candidateId,candidateInfo:{name:g.candidateInfo.name,age:g.candidateInfo.age,experience:g.candidateInfo.experience,education:g.candidateInfo.education,communicationPosition:f.communicationPosition,expectedPosition:f.expectedPosition,expectedLocation:f.expectedLocation,expectedSalary:g.candidateInfo.expectedSalary,tags:[...g.candidateInfo.tags]},...void 0!==f.preferredBrand?{preferredBrand:f.preferredBrand}:{},chatMessages:[...g.messages],formattedHistory:h,stats:b}}catch(e){return await(i?.fail("提取聊天记录失败")),t.logger.warn(`Native zhipin candidate info read failed: ${e instanceof Error?e.message:String(e)}`),Gc(e instanceof Error?e.message:"提取聊天记录失败")}finally{o?.close()}}});import{defineTool as el}from"@roll-agent/sdk";import{GenerateSignedReplyResponseSchema as tl,ReasoningConfigSchema as nl,ReplyStreamFinalEventSchema as rl,streamGenerateSignedReply as al}from"@roll-agent/reply-authority-client";import{z as ol}from"zod";import{randomUUID as il}from"node:crypto";var sl=new Map;function cl(e){for(const[t,n]of sl)n.expiresAt<=e&&sl.delete(t)}function ll(e,t=Math.floor(Date.now()/1e3)){if(cl(t),e.expiresAt<=t)throw new Error("Prepared reply 已过期,禁止保存。");const n=`prep_${il()}`,r={preparedReplyId:n,...e};return sl.set(n,{...r,consumed:!1}),r}function dl(e,t=Math.floor(Date.now()/1e3)){const n=sl.get(e);return void 0===n?(cl(t),{ok:!1,reason:"not_found"}):n.expiresAt<=t?(sl.delete(e),cl(t),{ok:!1,reason:"expired"}):n.consumed?{ok:!1,reason:"consumed"}:(sl.set(e,{...n,consumed:!0}),{ok:!0,record:ml(n)})}function ul(e,t=Math.floor(Date.now()/1e3)){const n=sl.get(e);return void 0===n?(cl(t),{ok:!1,reason:"not_found"}):n.expiresAt<=t?(sl.delete(e),cl(t),{ok:!1,reason:"expired"}):n.consumed?{ok:!1,reason:"consumed"}:{ok:!0,record:ml(n)}}function ml(e){return{preparedReplyId:e.preparedReplyId,signedEnvelope:e.signedEnvelope,suggestedReply:e.suggestedReply,stage:e.stage,confidence:e.confidence,expiresAt:e.expiresAt,...void 0!==e.requestId?{requestId:e.requestId}:{},...void 0!==e.unreadCountBeforeReply?{unreadCountBeforeReply:e.unreadCountBeforeReply}:{}}}function pl(e){return`(() => {\n const input = ${JSON.stringify(e)};\n const rootId = "roll-agent-reply-preview-root";\n const statusId = "roll-agent-reply-preview-status";\n const draftId = "roll-agent-reply-preview-draft";\n const badgeId = "roll-agent-reply-preview-badge";\n const spinnerId = "roll-agent-reply-preview-spinner";\n const styleId = "roll-agent-reply-preview-style";\n\n if (input.mode === "clear") {\n const existingRoot = document.getElementById(rootId);\n if (!existingRoot) return true;\n\n existingRoot.style.opacity = "0";\n existingRoot.style.transform = "translateY(8px) scale(0.98)";\n window.setTimeout(() => existingRoot.remove(), 240);\n return true;\n }\n\n const ensureRoot = () => {\n let root = document.getElementById(rootId);\n if (root) return root;\n\n if (!document.getElementById(styleId)) {\n const style = document.createElement("style");\n style.id = styleId;\n style.textContent = "@keyframes rollAgentReplyPreviewSpin { to { transform: rotate(360deg); } }";\n document.head.append(style);\n }\n\n root = document.createElement("div");\n root.id = rootId;\n root.style.position = "fixed";\n root.style.right = "20px";\n root.style.bottom = "20px";\n root.style.width = "min(420px, calc(100vw - 40px))";\n root.style.maxHeight = "42vh";\n root.style.zIndex = "2147483646";\n root.style.pointerEvents = "none";\n root.style.display = "flex";\n root.style.flexDirection = "column";\n root.style.gap = "10px";\n root.style.padding = "14px";\n root.style.borderRadius = "16px";\n root.style.border = "1px solid rgba(45, 212, 191, 0.32)";\n root.style.background = "rgba(15, 23, 42, 0.88)";\n root.style.color = "#F8FAFC";\n root.style.boxShadow = "0 22px 58px rgba(15, 23, 42, 0.34)";\n root.style.backdropFilter = "blur(14px)";\n root.style.fontFamily =\n "-apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif";\n root.style.opacity = "0";\n root.style.transform = "translateY(8px)";\n root.style.transition = "opacity 180ms ease, transform 220ms ease";\n\n const header = document.createElement("div");\n header.style.display = "flex";\n header.style.alignItems = "center";\n header.style.gap = "8px";\n header.style.minWidth = "0";\n\n const spinner = document.createElement("div");\n spinner.id = spinnerId;\n spinner.setAttribute("aria-hidden", "true");\n spinner.style.width = "14px";\n spinner.style.height = "14px";\n spinner.style.flex = "0 0 auto";\n spinner.style.borderRadius = "999px";\n spinner.style.border = "2px solid rgba(153, 246, 228, 0.24)";\n spinner.style.borderTopColor = "#99F6E4";\n spinner.style.animation = "rollAgentReplyPreviewSpin 820ms linear infinite";\n spinner.style.transition =\n "border-color 160ms ease, background 160ms ease, box-shadow 160ms ease, transform 160ms ease";\n\n const status = document.createElement("div");\n status.id = statusId;\n status.style.minWidth = "0";\n status.style.fontSize = "13px";\n status.style.fontWeight = "700";\n status.style.lineHeight = "18px";\n status.style.overflow = "hidden";\n status.style.textOverflow = "ellipsis";\n status.style.whiteSpace = "nowrap";\n\n const badge = document.createElement("div");\n badge.id = badgeId;\n badge.style.alignSelf = "flex-start";\n badge.style.fontSize = "11px";\n badge.style.lineHeight = "16px";\n badge.style.padding = "3px 8px";\n badge.style.borderRadius = "999px";\n badge.style.background = "rgba(20, 184, 166, 0.18)";\n badge.style.color = "#99F6E4";\n badge.textContent = "临时草稿";\n\n const draft = document.createElement("div");\n draft.id = draftId;\n draft.style.maxHeight = "30vh";\n draft.style.overflow = "hidden auto";\n draft.style.whiteSpace = "pre-wrap";\n draft.style.fontSize = "14px";\n draft.style.lineHeight = "21px";\n draft.style.color = "#E2E8F0";\n\n header.append(spinner, status);\n root.append(header, badge, draft);\n document.documentElement.append(root);\n return root;\n };\n\n const root = ensureRoot();\n const status = document.getElementById(statusId);\n const draft = document.getElementById(draftId);\n const badge = document.getElementById(badgeId);\n const spinner = document.getElementById(spinnerId);\n if (!status || !draft || !badge || !spinner) return false;\n\n root.style.opacity = "1";\n root.style.transform = "translateY(0)";\n\n if (typeof input.label === "string") {\n status.textContent = input.label;\n }\n\n if (typeof input.draftText === "string") {\n draft.textContent = input.draftText;\n }\n\n if (input.mode === "final" || input.mode === "complete") {\n spinner.style.animation = "none";\n spinner.style.borderColor = "rgba(34, 197, 94, 0.24)";\n spinner.style.borderTopColor = "rgba(34, 197, 94, 0.24)";\n spinner.style.background = "#22C55E";\n spinner.style.boxShadow = "0 0 0 3px rgba(34, 197, 94, 0.14)";\n badge.textContent = "最终回复";\n badge.style.background = "rgba(34, 197, 94, 0.16)";\n badge.style.color = "#BBF7D0";\n root.style.borderColor = "rgba(74, 222, 128, 0.34)";\n } else if (input.mode === "fail") {\n spinner.style.animation = "none";\n spinner.style.borderColor = "rgba(245, 158, 11, 0.28)";\n spinner.style.borderTopColor = "rgba(245, 158, 11, 0.28)";\n spinner.style.background = "#F59E0B";\n spinner.style.boxShadow = "0 0 0 3px rgba(245, 158, 11, 0.14)";\n badge.textContent = "生成失败";\n badge.style.background = "rgba(245, 158, 11, 0.18)";\n badge.style.color = "#FDE68A";\n root.style.borderColor = "rgba(251, 191, 36, 0.4)";\n } else {\n spinner.style.width = "14px";\n spinner.style.height = "14px";\n spinner.style.animation = "rollAgentReplyPreviewSpin 820ms linear infinite";\n spinner.style.border = "2px solid rgba(153, 246, 228, 0.24)";\n spinner.style.borderTopColor = "#99F6E4";\n spinner.style.background = "transparent";\n spinner.style.boxShadow = "none";\n badge.textContent = input.provisional === false ? "最终回复" : "临时草稿";\n badge.style.background = "rgba(20, 184, 166, 0.18)";\n badge.style.color = "#99F6E4";\n root.style.borderColor = "rgba(45, 212, 191, 0.32)";\n }\n\n return true;\n })()`}var gl,fl=class{target;constructor(e){this.target=e}async begin(e){return await this.render({mode:"begin",label:e,draftText:"",provisional:!0})}async updateStatus(e){return await this.render({mode:"status",label:e})}async updateDraft(e,t){return await this.render({mode:t?"draft":"final",draftText:e,provisional:t})}async complete(e,t){return await this.render({mode:"complete",label:e,draftText:t,provisional:!1})}async fail(e){return await this.render({mode:"fail",label:e})}async clear(){return await this.render({mode:"clear"})}async render(e){if(!Xe())return!1;try{return await this.target.evaluateJson(pl(e))}catch{return!1}}},hl=ol.object({conversationId:ol.string().optional().describe("会话 ID。若已从 `zhipin_read_messages` 获取,优先传这个,最稳定"),candidateName:ol.string().optional().describe("候选人姓名。若用户说“给鲁倩生成回复”,这里应提取为“鲁倩”"),index:ol.number().optional().describe("候选人在列表中的索引(可选,仅兜底)"),maxMessages:ol.number().default(100).describe("最多读取的聊天消息条数"),reasoning:nl.optional().describe("可选 reasoning/thinking 控制。enabled=true 会请求 Reply Authority 使用模型推理模式;effort 可选 low/medium/high;scope 可选 reply/all")}),bl=ol.object({success:ol.boolean(),preparedReplyId:ol.string().optional(),suggestedReply:ol.string().optional(),stage:ol.string().optional(),confidence:ol.number().optional(),expiresAt:ol.number().optional(),requestId:ol.string().optional(),error:ol.string().optional()}),yl={tenant_context:"加载租户上下文",binding_check:"校验招聘账号绑定",turn_planning:"分析候选人意图",context_building:"准备业务上下文",qualification_check:"检查候选人资格",reply_generation:"生成回复草稿",fact_gate:"检查事实安全",reply_gate:"检查回复策略",signing:"签发安全信封"};function vl(){return{openNativePagePort:_s,createNativeVisualActivitySession:e=>new ha(e),createReplyPreviewVisualSession:e=>new fl(e),streamGenerateSignedReply:al,savePreparedReply:ll,...gl}}function wl(e,t){const n=e.trim().toLocaleLowerCase("zh-CN"),r=t.trim().toLocaleLowerCase("zh-CN");return n.length>0&&r.length>0&&(n===r||n.includes(r)||r.includes(n))}function xl(e,t){const n=e[t];return"string"==typeof n&&n.trim().length>0?n:void 0}function Sl(e){return e.filter(e=>"candidate"===e.sender||"recruiter"===e.sender).map(e=>`${"candidate"===e.sender?"求职者":"我"}: ${e.content}`)}function Il(e){const t=[...e].reverse().find(e=>"candidate"===e.sender&&e.content.trim().length>0);return t?.content.trim()??""}function Cl(e){return[...e].reverse().find(e=>("candidate"===e.sender||"recruiter"===e.sender)&&e.content.trim().length>0)}function Rl(e){return void 0===e||!Number.isFinite(e)||e<=0?0:Math.floor(e)}function kl(e){const t=Rl(e.navigationUnreadCount);return t>0?t:"candidate"===Cl(e.data.messages)?.sender?1:0}function Al(e){const t=Uc({communicationPosition:e.data.candidateInfo.communicationPosition,expectedJobText:e.data.candidateInfo.expectedJobText});return{candidateMessage:Il(e.data.messages),conversationHistory:Sl(e.data.messages),candidateInfo:{name:e.data.candidateInfo.name,age:e.data.candidateInfo.age,experience:e.data.candidateInfo.experience,education:e.data.candidateInfo.education,communicationPosition:t.communicationPosition,expectedPosition:t.expectedPosition,expectedLocation:t.expectedLocation,expectedSalary:e.data.candidateInfo.expectedSalary,info:[...e.data.candidateInfo.tags]},...void 0!==t.preferredBrand?{preferredBrand:t.preferredBrand}:{},...void 0!==e.reasoning?{modelConfig:{reasoning:e.reasoning}}:{},target:{platform:"zhipin",conversationId:e.conversationId,candidateId:e.candidateId,recruiterUsername:e.recruiterUsername}}}function Nl(e){return"phase.started"===e.type?xl(e,"label")??yl[xl(e,"phase")??""]??"正在处理回复生成阶段":"tool.started"===e.type?"正在执行工具"+(xl(e,"toolName")?`: ${xl(e,"toolName")}`:""):"tool.completed"===e.type?"工具执行完成"+(xl(e,"toolName")?`: ${xl(e,"toolName")}`:""):"draft.started"===e.type?"正在生成回复草稿":"reasoning.started"===e.type?"正在推理回复策略":"reasoning.completed"===e.type?"回复策略推理完成":void 0}function Ml(e){return{success:!1,error:e}}function El(e){return{success:!0,preparedReplyId:e.preparedReplyId,suggestedReply:e.suggestedReply,stage:e.stage,confidence:e.confidence,expiresAt:e.expiresAt,...void 0!==e.requestId?{requestId:e.requestId}:{}}}var Pl=el({name:"zhipin_generate_reply_preview",description:"读取当前或指定 BOSS 聊天,流式生成智能回复并在浏览器中展示阶段和临时草稿;返回 preparedReplyId 供发送。",input:hl,output:bl,execute:async(e,t)=>{const n=vl(),r=e.maxMessages??100,a=void 0!==e.conversationId||void 0!==e.candidateName||void 0!==e.index;let o,i,s;try{o=await n.openNativePagePort(),i=n.createNativeVisualActivitySession(o),s=n.createReplyPreviewVisualSession(o),await wn(o),await i.begin(a?"正在打开目标聊天":"正在准备当前聊天");const c=a?await o.openChat({conversationId:e.conversationId,candidateName:e.candidateName,index:e.index,maxScrolls:4}):void 0;if(void 0!==c&&!c.found){const e=c.error??"打开聊天失败";return await i.fail(e),Ml(e)}if(void 0===c&&!await o.isChatSurfaceOpen().catch(()=>!1)){const e="当前页面不是 BOSS 沟通页,无法生成回复";return await i.fail("当前不是沟通页"),Ml(e)}await i.begin("正在读取聊天上下文"),await i.highlightSelector(".chat-conversation, .conversation-box, .conversation-message",{label:"正在读取聊天上下文",padding:12});const l=c?.name??e.candidateName??"",d=await o.readActiveChatPanel();if(l.length>0&&(!d||!wl(l,d.candidateName))){const e=`右侧聊天面板未切换到 ${l}`;return await i.fail("聊天面板未同步"),Ml(e)}const u=await o.readSelectedChatTarget();if(!u){const e="未能提取当前选中聊天的 conversationId/candidateId";return await i.fail("未识别当前会话"),Ml(e)}if(null!==d&&u.candidateName.length>0&&!wl(u.candidateName,d.candidateName)){const e=`左侧选中会话与右侧聊天面板不一致: ${u.candidateName} / ${d.candidateName}`;return await i.fail("当前会话不一致"),Ml(e)}if(!(void 0===c||c.conversationId.length>0&&u.conversationId===c.conversationId||0===c.conversationId.length&&c.candidateId.length>0&&u.candidateId===c.candidateId)){const e=`当前选中会话与目标会话不一致: ${c?.name||c?.conversationId||""}`;return await i.fail("当前会话不一致"),Ml(e)}await o.waitForChatMessages();const m=await o.readCandidateChatDetails(r);if(null!==m.selectedTarget&&(m.selectedTarget.conversationId!==u.conversationId||m.selectedTarget.candidateId!==u.candidateId)){const e=`聊天详情目标与当前选中会话不一致: ${m.selectedTarget.conversationId}/${m.selectedTarget.candidateId}`;return await i.fail("聊天详情目标不一致"),Ml(e)}const p=Bi(await o.readUsernameEvidence());if(!p.found){const e="未找到用户名,请确认当前页面已登录招聘者账号。";return await i.fail("未找到用户名"),Ml(e)}const g=Al({data:m,conversationId:u.conversationId,candidateId:u.candidateId,recruiterUsername:p.username,reasoning:e.reasoning}),f=kl({navigationUnreadCount:c?.unreadCount,data:m});if(0===g.candidateMessage.length){const e="未找到候选人最新消息,无法生成回复";return await i.fail("候选人消息为空"),Ml(e)}t.logger.info(`Generating reply preview for ${u.candidateName||u.candidateId}`),await i.begin("正在生成回复"),await s.begin("正在生成回复");let h,b,y="";for await(const e of n.streamGenerateSignedReply(g)){"stream.started"===e.type&&(h=xl(e,"requestId"));const t=Nl(e);if(void 0!==t&&(await i.begin(t),await s.updateStatus(t)),"draft.started"===e.type&&(y="",await s.updateDraft(y,!0)),"draft.delta"===e.type){y+=xl(e,"delta")??"",await s.updateDraft(y,!0)}if("final"===e.type){const t=rl.parse(e),r=tl.parse(t);b=n.savePreparedReply({signedEnvelope:r.signedEnvelope,suggestedReply:r.suggestedReply,stage:r.stage,confidence:r.confidence,expiresAt:r.envelopeExp,unreadCountBeforeReply:f,...void 0!==h?{requestId:h}:{}}),await s.complete("回复已生成",r.suggestedReply)}}if(void 0===b){const e="Reply Authority stream 未返回 final";return await s.fail(e),await i.fail(e),Ml(e)}return await i.succeed("回复已生成"),El(b)}catch(e){const t=e instanceof Error?e.message:String(e);return await(s?.fail(t)),await(i?.fail(t)),Ml(t)}finally{o?.close()}}});import{createHash as Tl}from"node:crypto";import{defineTool as _l}from"@roll-agent/sdk";import{BrowserActionApprovalSchema as Bl}from"@roll-agent/browser";import{z as Ol}from"zod";import{defineTool as $l}from"@roll-agent/sdk";import{z as Dl}from"zod";function ql(e,t){return void 0!==t.accountId?e.accountId===t.accountId:e.username===t.username}import{z as Fl}from"zod";var jl="reply-authority-service",Ll="browser-use-agent/zhipin_send_reply",zl="zhipin",Jl=60,Ul=Fl.object({platform:Fl.literal(zl),username:Fl.string().min(1),accountId:Fl.string().min(1).optional()}),Vl=Fl.object({v:Fl.literal(2),iss:Fl.literal(jl),kid:Fl.string().min(1),jti:Fl.string().min(1),iat:Fl.number().int(),exp:Fl.number().int(),aud:Fl.literal(Ll),platform:Fl.literal(zl),tenantId:Fl.string().min(1),conversationId:Fl.string().min(1),candidateId:Fl.string().min(1),reply:Fl.string(),policyVersion:Fl.string().min(1),recruiterBinding:Ul}),Hl=Fl.object({kid:Fl.string().min(1),algorithm:Fl.literal("Ed25519"),publicKey:Fl.string().min(1),validFrom:Fl.string().min(1),validUntil:Fl.string().optional()}),Wl=Fl.object({keys:Fl.array(Hl)}),Kl=new Map;function Yl(e){for(const[t,n]of Kl)n<e-Jl&&Kl.delete(t)}function Gl(e,t=Math.floor(Date.now()/1e3)){return Yl(t),Kl.has(e)}function Xl(e,t,n=Math.floor(Date.now()/1e3)){Yl(n),Kl.set(e,t)}import{createPublicKey as Zl,verify as Ql}from"node:crypto";var ed=new Map,td=null;function nd(){const e=process.env.REPLY_AUTHORITY_KEYS_URL?.trim();if(!e)throw new Error("REPLY_AUTHORITY_KEYS_URL 未配置,browser-use-agent 无法拉取 Reply Authority 公钥。");return e}function rd(e){return ed=new Map(e.map(e=>[e.kid,e]))}async function ad(){if(td)return td;td=(async()=>{const e=await fetch(nd()),t=await e.json();if(!e.ok)throw new Error(`Reply Authority 公钥拉取失败 (${e.status})`);return rd(Wl.parse(t).keys)})();try{return await td}finally{td=null}}async function od(){await ad()}async function id(e){const t=ed.get(e);if(t)return t;const n=(await ad()).get(e);if(!n)throw new Error(`Unknown key ID: ${e}`);return n}function sd(e){if("object"==typeof e&&null!==e&&"v"in e&&"number"==typeof e.v&&2!==e.v)throw new Error("unexpected envelope version")}function cd(e){const t=e.split("."),n=t[0],r=t[1];if(2!==t.length||void 0===n||void 0===r||0===n.length||0===r.length)throw new Error("Invalid signed envelope format");let a,o="";try{o=Buffer.from(n,"base64url").toString("utf-8")}catch{throw new Error("Invalid signed envelope format")}try{a=JSON.parse(o)}catch{throw new Error("Envelope payload schema validation failed")}sd(a);const i=Vl.safeParse(a);if(!i.success)throw new Error("Envelope payload schema validation failed");return{payload:i.data,payloadJson:o,signatureBase64:r}}function ld(e,t){if(e.exp<=e.iat)throw new Error("Envelope expiry must be after issue time");if(e.exp<t-Jl)throw new Error("Envelope expired");if(e.iat>t+Jl)throw new Error("Envelope issued in the future")}async function dd(e,t=Math.floor(Date.now()/1e3)){const n=cd(e),r=await id(n.payload.kid),a=Zl({key:Buffer.from(r.publicKey,"base64url"),format:"der",type:"spki"});if(!Ql(null,Buffer.from(n.payloadJson,"utf-8"),a,Buffer.from(n.signatureBase64,"base64url")))throw new Error("Signature verification failed");return ld(n.payload,t),n.payload}var ud,md=Dl.object({success:Dl.boolean(),sentMessage:Dl.string(),error:Dl.string().optional()});function pd(){return{getReplyAuthorityKeysLoaded:pe,openNativePagePort:_s,createNativeVisualActivitySession:e=>new ha(e),...ud}}function gd(e,t){const n=e.trim().toLocaleLowerCase("zh-CN"),r=t.trim().toLocaleLowerCase("zh-CN");return n.length>0&&r.length>0&&(n===r||n.includes(r)||r.includes(n))}function fd(e){return"function"==typeof e.readCandidateChatDetails}async function hd(e){if(fd(e))return await e.readCandidateChatDetails(50).catch(()=>{})}function bd(e,t){return null!==e&&e.conversationId===t.conversationId&&e.candidateId===t.candidateId}function yd(e,t){return null===t||0===e.candidateName.length||gd(e.candidateName,t.candidateName)}function vd(e){return void 0===e||!Number.isFinite(e)||e<=0?0:Math.floor(e)}async function wd(e,t){const n=pd();let r,a,o="";if(!n.getReplyAuthorityKeysLoaded()){const e="Reply Authority 公钥尚未成功预加载,当前无法发送签名回复。请检查启动日志、`REPLY_AUTHORITY_KEYS_URL` 配置,以及 `browser_status.replyAuthorityKeysLoaded`。";return t.logger.error(e),{success:!1,sentMessage:o,error:e}}try{const i=await dd(e.signedEnvelope);if(o=i.reply,Gl(i.jti))return{success:!1,sentMessage:o,error:"token 已消费,禁止重放"};r=await n.openNativePagePort(),a=n.createNativeVisualActivitySession(r),await wn(r),await new fl(r).clear(),await a.begin("正在发送回复");let s=await r.readActiveChatPanel().catch(()=>null),c=await r.readSelectedChatTarget().catch(()=>null),l=vd(e.unreadCountBeforeReply);if(!bd(c,i)||!yd(c,s)){const t=await r.openChat({conversationId:i.conversationId,candidateName:e.candidateName,index:e.index});if(!t.found)return await a.fail(t.error??"未找到目标聊天"),{success:!1,sentMessage:o,error:t.error??"未找到目标聊天"};l=Math.max(l,vd(t.unreadCount)),s=await r.readActiveChatPanel(),c=await r.readSelectedChatTarget()}if(null===c)return await a.fail("未能提取当前聊天的 conversationId/candidateId"),{success:!1,sentMessage:o,error:"未能提取当前聊天的 conversationId/candidateId"};if(null!==s&&c.candidateName.length>0&&!gd(c.candidateName,s.candidateName)){const e=`左侧选中会话与右侧聊天面板不一致: ${c.candidateName} / ${s.candidateName}`;return await a.fail(e),{success:!1,sentMessage:o,error:e}}if(c.conversationId!==i.conversationId||c.candidateId!==i.candidateId)return await a.fail("发送目标与签名不匹配"),{success:!1,sentMessage:o,error:"发送目标与签名不匹配"};const d=Bi(await r.readUsernameEvidence());if(!d.found)return await a.fail("未找到用户名"),{success:!1,sentMessage:o,error:"未找到用户名,请确认当前页面已登录招聘者账号。"};const u={platform:"zhipin",username:d.username,strategy:d.strategy,source:d.source};if(!ql(u,i.recruiterBinding)){const e=`recruiter 绑定不匹配:当前账号 ${u.username} 与签发时 ${i.recruiterBinding.username} 不一致`;return await a.fail(e),{success:!1,sentMessage:o,error:e}}t.logger.info(`Sending native message (${o.length} chars) to ${c.candidateName||c.candidateId}`);const m=await r.sendChatReply(o,{...void 0!==a?{motionObserver:a}:{}});if(!m.success)return await a.fail(m.error??"发送失败"),{success:!1,sentMessage:o,error:m.error??"发送失败"};const p=await hd(r);return lc({conversationId:c.conversationId,candidateId:c.candidateId,replyId:i.jti,candidateName:c.candidateName,message:o,unreadCountBeforeReply:l,...void 0!==p?{candidateDetails:p}:{}},t.logger),Xl(i.jti,i.exp),await a.succeed("已发送回复"),{success:!0,sentMessage:o}}catch(e){const t=e instanceof Error?e.message:String(e);return await(a?.fail(t)),{success:!1,sentMessage:o,error:t}}finally{r?.close()}}var xd,Sd=$l({name:"zhipin_send_reply",description:"发送消息。只接受由 Reply Authority Service 签发的 signedEnvelope;可指定 candidateName 自动打开对应聊天后发送,或不传则发送到当前选中的聊天窗口。",input:Dl.object({signedEnvelope:Dl.string().describe("Reply Authority Service 返回的紧凑签名信封"),candidateName:Dl.string().optional().describe("候选人姓名。若用户说“回复鲁倩”,这里应提取为“鲁倩”"),index:Dl.number().optional().describe("候选人在列表中的索引(可选)")}),output:md,execute:async(e,t)=>await wd(e,t)}),Id="zhipin_send_prepared_reply",Cd=80,Rd=Ol.object({success:Ol.boolean(),sentMessage:Ol.string(),error:Ol.string().optional()}),kd=Ol.object({preparedReplyId:Ol.string().min(1).describe("预备回复 ID,由 zhipin_generate_reply_preview 返回"),toolActionApproval:nt.optional().describe("当 browser-use tool policy 返回 needs_confirmation 后,由 orchestrator 原样带回的批准 ID。"),browserActionApproval:Bl.optional().describe("当 BROWSER_SECURITY_JSON.actionPolicy=confirm 返回 needs_confirmation 后,由 orchestrator 原样带回的批准 ID。")});function Ad(){return{sendSignedZhipinReply:wd,...xd}}function Nd(e){return"expired"===e?"preparedReplyId 已过期,请重新生成回复":"consumed"===e?"preparedReplyId 已消费,禁止重复发送":"preparedReplyId 不存在,请重新生成回复"}function Md(e){return`sha256:${Tl("sha256").update(JSON.stringify([e.preparedReplyId,e.signedEnvelope,e.suggestedReply,e.expiresAt,e.unreadCountBeforeReply])).digest("hex")}`}function Ed(e){const t=e.suggestedReply.replace(/\s+/g," ").trim(),n=t.length>Cd?`${t.slice(0,Cd-1)}…`:t;return n.length>0?`发送预备回复: ${n}`:"发送预备回复"}var Pd=_l({name:Id,description:"发送由 zhipin_generate_reply_preview 生成的预备回复;只接收 preparedReplyId,不接收 signedEnvelope。",input:kd,output:Rd,execute:async(e,t)=>{const n=Ad(),r=ul(e.preparedReplyId);if(!r.ok)return{success:!1,sentMessage:"",error:Nd(r.reason)};const a=Ct(t,{subject:{tool:Id,target:r.record.preparedReplyId,summary:Ed(r.record),digest:Md(r.record)},...void 0!==e.toolActionApproval?{approval:e.toolActionApproval}:{},deferApprovalConsumption:!0});hn(t,de(),{action:Id,target:r.record.preparedReplyId,...void 0!==e.browserActionApproval?{approval:e.browserActionApproval}:{}}),a.consumeApproval();const o=dl(e.preparedReplyId);return o.ok?await n.sendSignedZhipinReply({signedEnvelope:o.record.signedEnvelope,...void 0!==o.record.unreadCountBeforeReply?{unreadCountBeforeReply:o.record.unreadCountBeforeReply}:{}},t):{success:!1,sentMessage:"",error:Nd(o.reason)}}});import{defineTool as Td}from"@roll-agent/sdk";import{z as _d}from"zod";var Bd,Od=_d.object({success:_d.boolean(),exchanged:_d.boolean(),wechatNumber:_d.string().optional(),error:_d.string().optional()}),$d=900,Dd=160,qd=1100;function Fd(){return{openNativePagePort:_s,createNativeVisualActivitySession:e=>new ha(e),...Bd}}function jd(e,t){const n=e.trim().toLocaleLowerCase("zh-CN"),r=t.trim().toLocaleLowerCase("zh-CN");return n.length>0&&r.length>0&&(n===r||n.includes(r)||r.includes(n))}function Ld(e){return"function"==typeof e.readCandidateChatDetails}async function zd(e){if(Ld(e))return await e.readCandidateChatDetails(50).catch(()=>{})}var Jd=Td({name:"zhipin_exchange_wechat",description:'换微信。可指定 candidateName 自动打开对应聊天后执行,或不传则在当前窗口执行;例如"和鲁倩换微信"应提取 candidateName=鲁倩。',input:_d.object({conversationId:_d.string().optional().describe("会话 ID。若已从消息列表拿到,优先传这个"),candidateName:_d.string().optional().describe('候选人姓名。若用户说"和鲁倩换微信",这里应提取为"鲁倩"'),index:_d.number().optional().describe("候选人在列表中的索引(可选)")}),output:Od,execute:async(e,t)=>{const n=Fd();let r,a;try{if(r=await n.openNativePagePort(),a=n.createNativeVisualActivitySession(r),await wn(r),await a.begin("正在换微信"),void 0!==e.conversationId||void 0!==e.candidateName||void 0!==e.index){const t=await r.openChat({conversationId:e.conversationId,candidateName:e.candidateName,index:e.index,...void 0!==a?{motionObserver:a}:{}});if(!t.found)return await a.fail(t.error??"未找到目标聊天"),{success:!1,exchanged:!1,error:t.error??"未找到目标聊天"}}else if(!await r.isChatSurfaceOpen())return await a.fail("消息列表未加载"),{success:!1,exchanged:!1,error:"消息列表未加载"};const o=await r.readSelectedChatTarget();if(null===o)return await a.fail("未选中聊天联系人"),{success:!1,exchanged:!1,error:"未选中聊天联系人,无法点击当前聊天输入区的「换微信」按钮"};const i=await r.readActiveChatPanel();if(null!==i&&o.candidateName.length>0&&!jd(o.candidateName,i.candidateName)){const e=`左侧选中会话与右侧聊天面板不一致: ${o.candidateName} / ${i.candidateName}`;return await a.fail(e),{success:!1,exchanged:!1,error:e}}t.logger.info(`Starting native WeChat exchange with ${o.candidateName}`);const s=await zd(r),c=await r.exchangeWechat({preClickDelayMs:$d,pressDurationMs:Dd,settleMs:qd,...void 0!==a?{motionObserver:a}:{}});return c.success?(c.exchanged&&uc({conversationId:o.conversationId,candidateId:o.candidateId,candidateName:o.candidateName,...void 0!==c.wechatNumber?{wechatNumber:c.wechatNumber}:{},...void 0!==s?{candidateDetails:s}:{}},t.logger),await a.succeed("已完成换微信"),c):(await a.fail(c.error??"换微信失败"),c)}catch(e){const t=e instanceof Error?e.message:String(e);return await(a?.fail(t)),{success:!1,exchanged:!1,error:t}}finally{r?.close()}}});import{defineTool as Ud}from"@roll-agent/sdk";import{z as Vd}from"zod";var Hd,Wd=Vd.object({success:Vd.boolean(),username:Vd.string(),usedSelector:Vd.string().optional(),usedStrategy:Vd.string().optional(),source:Vd.string().optional(),error:Vd.string().optional()});function Kd(){return{openNativePagePort:_s,pickBestUsername:Bi,createNativeVisualActivitySession:e=>new ha(e),...Hd}}var Yd=Ud({name:"zhipin_get_username",description:"获取当前登录的招聘者用户名",input:Vd.object({}),output:Wd,execute:async(e,t)=>{t.logger.info("Getting zhipin username");const n=Kd();let r,a;try{r=await n.openNativePagePort(),a=n.createNativeVisualActivitySession(r),await a.begin("正在识别登录账号"),await a.highlightSelector('header, #header, [role="banner"], [role="navigation"]',{label:"正在识别登录账号",padding:10});const e=n.pickBestUsername(await r.readUsernameEvidence());if(!e.found)throw new Error("未找到用户名,请确认当前页面已登录招聘者账号。");return await a.succeed(`已识别账号:${e.username}`),t.logger.info(`Username: ${e.username} (strategy: ${e.strategy}, source: ${e.source})`),{success:!0,username:e.username,usedSelector:"css-fallback"===e.strategy?e.source:void 0,usedStrategy:e.strategy,source:e.source}}catch(e){return await(a?.fail("获取用户名失败")),{success:!1,username:"",error:e instanceof Error?`获取用户名失败:${e.message}`:"获取用户名失败"}}finally{r?.close()}}});import{defineTool as Gd}from"@roll-agent/sdk";import{z as Xd}from"zod";var Zd,Qd=["unknown","top","middle","bottom","only-page"],eu=Xd.object({containerFound:Xd.boolean(),containerLabel:Xd.string(),scrollTop:Xd.number(),scrollHeight:Xd.number(),clientHeight:Xd.number(),itemCount:Xd.number(),atStart:Xd.boolean(),atEnd:Xd.boolean()}),tu=Xd.object({success:Xd.boolean(),surface:Xd.enum(ki),direction:Xd.enum(["up","down"]),stepsRequested:Xd.number(),stepsCompleted:Xd.number(),reachedBoundary:Xd.boolean(),atTop:Xd.boolean(),atBottom:Xd.boolean(),canScrollUp:Xd.boolean(),canScrollDown:Xd.boolean(),position:Xd.enum(Qd),before:eu,after:eu,error:Xd.string().optional()});function nu(){return{openNativePagePort:_s,createNativeVisualActivitySession:e=>new ha(e),...Zd}}function ru(){return{containerFound:!1,containerLabel:"",scrollTop:0,scrollHeight:0,clientHeight:0,itemCount:0,atStart:!0,atEnd:!0}}function au(e){return e.containerFound?e.atStart&&e.atEnd?"only-page":e.atStart?"top":e.atEnd?"bottom":"middle":"unknown"}function ou(e){return{atTop:e.containerFound&&e.atStart,atBottom:e.containerFound&&e.atEnd,canScrollUp:e.containerFound&&!e.atStart,canScrollDown:e.containerFound&&!e.atEnd,position:au(e)}}var iu=Gd({name:"zhipin_scroll_view",description:"滚动或检查 BOSS直聘页面内部动态列表容器。用于调试或显式翻页,支持 chat-list、chat-history、recommend-list;steps=0 时只返回当前位置和顶部/底部边界。",input:Xd.object({surface:Xd.enum(ki).describe("要滚动的页面区域"),direction:Xd.enum(["up","down"]).optional().describe("滚动方向;不传则使用该区域默认方向"),steps:Xd.number().int().min(0).max(20).default(1).describe("滚动步数;传 0 时不滚动,只检查当前列表是否在顶部/底部"),distance:Xd.number().int().positive().optional().describe("每步滚动像素;不传则按容器高度估算"),settleMs:Xd.number().int().min(0).max(5e3).default(700).describe("每步后等待 DOM 更新的毫秒数")}),output:tu,execute:async(e,t)=>{const n=nu(),r=Ni(e.surface),a=e.direction??r.defaultDirection,o=e.steps??1,i=e.settleMs??700;let s,c;try{s=await n.openNativePagePort({requireChatPage:"chat-list"===e.surface||"chat-history"===e.surface}),c=n.createNativeVisualActivitySession(s);const l=`正在滚动 ${e.surface}`;await c.begin(l),await c.highlightSelector(r.highlightSelector,{label:l,padding:8});const d=await s.scrollSurface(e.surface,{direction:a,steps:o,settleMs:i,...void 0!==e.distance?{distance:e.distance}:{}});return d.success?(await c.succeed(`已滚动 ${d.stepsCompleted}/${d.stepsRequested} 步`),t.logger.info(`Scrolled ${e.surface}: ${d.stepsCompleted}/${d.stepsRequested}, items ${d.before.itemCount} -> ${d.after.itemCount}`),{success:d.success,surface:e.surface,direction:d.direction,stepsRequested:d.stepsRequested,stepsCompleted:d.stepsCompleted,reachedBoundary:d.reachedBoundary,...ou(d.after),before:d.before,after:d.after}):(await c.fail("列表未加载"),{success:!1,surface:e.surface,direction:a,stepsRequested:o,stepsCompleted:0,reachedBoundary:!0,...ou(d.after),before:d.before,after:d.after,error:"列表未加载"})}catch(t){await(c?.fail("滚动失败"));const n=ru();return{success:!1,surface:e.surface,direction:a,stepsRequested:o,stepsCompleted:0,reachedBoundary:!0,...ou(n),before:n,after:n,error:t instanceof Error?t.message:"滚动失败"}}finally{s?.close()}}});import{defineTool as su}from"@roll-agent/sdk";import{z as cu}from"zod";var lu,du=["不限","男","女"],uu=["不限","刚刚活跃","今日活跃","3日内活跃","本周活跃","本月活跃"],mu=["applied","recommend_not_ready","filter_not_found","requires_vip","age_not_applied","submit_failed","error"],pu=cu.object({ageMin:cu.number().int().min(16).optional(),ageMax:cu.number().int().min(16).optional(),gender:cu.enum(du),activity:cu.enum(uu)}),gu=cu.object({ageMin:cu.number().optional(),ageMax:cu.number().optional(),gender:cu.string(),activity:cu.string()}),fu=cu.object({success:cu.boolean(),status:cu.enum(mu),requested:pu,applied:gu.optional(),filterButtonText:cu.string().optional(),error:cu.string().optional()}),hu=cu.object({ageMin:cu.number().int().min(16).optional().describe("年龄下限;未传则重置为 16"),ageMax:cu.number().int().min(16).optional().describe("年龄上限;未传则重置为不限"),gender:cu.enum(du).default("不限").describe("性别筛选,只支持:不限、男、女"),activity:cu.enum(uu).default("不限").describe("活跃度[单选],只支持:不限、刚刚活跃、今日活跃、3日内活跃、本周活跃、本月活跃")}).refine(e=>void 0===e.ageMin||void 0===e.ageMax||e.ageMin<=e.ageMax,{path:["ageMax"],message:"ageMax must be greater than or equal to ageMin"}),bu=350,yu=130,vu=600;function wu(){return{openNativePagePort:_s,createNativeVisualActivitySession:e=>new ha(e),...lu}}function xu(e){const t=e.gender??"不限",n=e.activity??"不限";return{...void 0!==e.ageMin?{ageMin:e.ageMin}:{},...void 0!==e.ageMax?{ageMax:e.ageMax}:{},gender:t,activity:n}}function Su(e){return{success:"applied"===e.status,status:e.status,requested:e.requested,...void 0!==e.applied?{applied:e.applied}:{},...void 0!==e.filterButtonText?{filterButtonText:e.filterButtonText}:{},...void 0!==e.error?{error:e.error}:{}}}var Iu=su({name:"zhipin_filter_recommend_candidates",description:"在 BOSS「推荐牛人」页打开筛选面板,只设置年龄、性别、活跃度[单选] 三个维度并提交。",input:hu,output:fu,execute:async(e,t)=>{const n=wu(),r=xu(e);let a,o;t.logger.info(`Filtering Boss recommend candidates through native CDP: gender=${r.gender}, activity=${r.activity}, ageMin=${r.ageMin??"16"}, ageMax=${r.ageMax??"不限"}`);try{a=await n.openNativePagePort(),o=n.createNativeVisualActivitySession(a),await wn(a),await o.begin("正在打开推荐筛选");if(!await a.waitForRecommendList(3e3))return await o.fail("推荐牛人页未就绪"),Su({status:"recommend_not_ready",requested:r,error:"推荐牛人页未就绪"});await o.begin("正在设置推荐筛选"),await o.highlightSelector(Mi.recommend.filterButton,{label:"正在设置推荐筛选",padding:8});const e=await a.applyRecommendFilter(r,{preClickDelayMs:bu,pressDurationMs:yu,settleMs:vu,...void 0!==o?{motionObserver:o}:{}});return"applied"===e.status?await o.succeed("已应用推荐筛选"):await o.fail(e.error??e.status),Su(e)}catch(e){const t=e instanceof Error?e.message:"推荐筛选失败";return await(o?.fail(t)),Su({status:"error",requested:r,error:t})}finally{a?.close()}}});import{defineTool as Cu}from"@roll-agent/sdk";import{z as Ru}from"zod";var ku=["target-count","boundary","no-new-items","max-steps"];import{AsyncLocalStorage as Au}from"node:async_hooks";var Nu="@c",Mu="@j",Eu="legacy",Pu=/^@?c([1-9]\d*)$/i,Tu=/^@?j([1-9]\d*)$/i,_u=new Map,Bu=new Map,Ou=new Au;function $u(e){if(!Number.isInteger(e)||e<0)throw new Error("候选人索引必须是从 0 开始的非负整数");return`${Nu}${String(e+1)}`}function Du(e){if(!Number.isInteger(e)||e<0)throw new Error("岗位索引必须是从 0 开始的非负整数");return`${Mu}${String(e+1)}`}function qu(e){const t=Pu.exec(e.trim()),n=t?.[1];if(!n)return;const r=Number(n);return Number.isInteger(r)?r-1:void 0}function Fu(e){const t=Tu.exec(e.trim()),n=t?.[1];if(!n)return;const r=Number(n);return Number.isInteger(r)?r-1:void 0}function ju(e){if(void 0!==e.index){if(!Number.isInteger(e.index)||e.index<0)throw new Error("index 必须是从 0 开始的非负整数");return e.index}if(void 0===e.candidateRef)throw new Error("必须提供 index 或 candidateRef");return Ju(e.candidateRef).index}function Lu(e){const t=e.map((e,t)=>({...e,candidateRef:$u(t)}));return _u.set(Yu(),new Map(t.map(e=>[e.candidateRef,e]))),t}function zu(e){const t=e.map((e,t)=>({...e,jobRef:Du(t)}));return Bu.set(Yu(),new Map(t.map(e=>[e.jobRef,e]))),t}function Ju(e){const t=qu(e);if(void 0===t)throw new Error(`candidateRef "${e}" 格式无效,应类似 @c1`);const n=$u(t);return _u.get(Yu())?.get(n)??{index:t,candidateRef:n,candidateId:""}}function Uu(e){const t=Fu(e);if(void 0===t)throw new Error(`jobRef "${e}" 格式无效,应类似 @j1`);const n=Du(t),r=Bu.get(Yu())?.get(n);if(void 0===r)throw new Error(`岗位引用 ${n} 已过期,请先调用 zhipin_list_recommend_jobs`);return r}function Vu(e){const t=[];for(const n of e.indices??[])t.push({index:ju({index:n}),candidateRef:$u(n),candidateId:""});for(const n of e.candidateRefs??[])t.push(Ju(n));if(0===t.length)throw new Error("必须提供 indices 或 candidateRefs");return Wu(t)}function Hu(e,t){return!1!==t.found&&(e.candidateId.length>0&&t.candidateId.length>0?e.candidateId===t.candidateId:!(e.name&&t.name&&t.name.length>0)||Ku(e.name)===Ku(t.name))}function Wu(e){const t=new Map;for(const n of e)t.has(n.candidateRef)||t.set(n.candidateRef,n);return[...t.values()]}function Ku(e){return e.trim().toLocaleLowerCase("zh-CN")}function Yu(){const e=Ou.getStore();if(void 0!==e)return e;try{return ye().id}catch{return Eu}}var Gu,Xu=Ru.object({index:Ru.number(),candidateRef:Ru.string(),candidateId:Ru.string(),name:Ru.string(),age:Ru.string(),experience:Ru.string(),education:Ru.string(),workStatus:Ru.string(),company:Ru.string(),currentPosition:Ru.string(),expectedLocation:Ru.string(),expectedPosition:Ru.string(),expectedSalary:Ru.string(),tags:Ru.array(Ru.string()),buttonText:Ru.string()}),Zu=Ru.object({containerLabel:Ru.string(),stepsRequested:Ru.number(),stepsCompleted:Ru.number(),reachedBoundary:Ru.boolean(),stopReason:Ru.enum(ku),uniqueCount:Ru.number(),duplicateCount:Ru.number(),noNewRounds:Ru.number(),beforeItemCount:Ru.number(),afterItemCount:Ru.number(),beforeScrollHeight:Ru.number(),afterScrollHeight:Ru.number()}),Qu=Ru.object({success:Ru.boolean(),candidates:Ru.array(Xu),total:Ru.number(),scrollStats:Zu.optional(),error:Ru.string().optional()});function em(){return{openNativePagePort:_s,createNativeVisualActivitySession:e=>new ha(e),...Gu}}var tm=Cu({name:"zhipin_get_candidate_list",description:"获取推荐列表页的候选人卡片信息",input:Ru.object({maxResults:Ru.number().optional().describe("最多返回条数"),autoScroll:Ru.boolean().default(!0).describe("是否自动向下滚动动态列表并合并采集结果"),maxScrolls:Ru.number().int().min(0).max(50).default(4).describe("自动滚动的最大步数")}),output:Qu,execute:async(e,t)=>{t.logger.info("Getting candidate list from recommend page through native backend");const n=em();let r,a;try{r=await n.openNativePagePort(),a=n.createNativeVisualActivitySession(r),await a.begin("正在打开推荐列表");if(!await r.waitForRecommendList())return await a.fail("推荐列表未加载"),{success:!1,candidates:[],total:0,error:"推荐列表未加载"};const o="正在读取推荐列表";await a.begin(o),await a.highlightSelector(".candidate-card-wrap, li.card-item, [data-geek], .geek-item",{label:o,padding:8});const i=await r.readRecommendCandidates({autoScroll:e.autoScroll??!0,maxScrolls:e.maxScrolls??4,...void 0!==e.maxResults?{targetCount:e.maxResults}:{}}),s=void 0!==e.maxResults?i.items.slice(0,e.maxResults):[...i.items],c=Lu(s),l=s.map((e,t)=>{const n=c[t];if(!n)throw new Error(`候选人引用生成失败:position ${String(t)}`);return{...e,candidateRef:n.candidateRef}}),d=!1===e.autoScroll?void 0:{containerLabel:i.after.containerLabel,stepsRequested:i.stepsRequested,stepsCompleted:i.stepsCompleted,reachedBoundary:i.reachedBoundary,stopReason:i.stopReason,uniqueCount:i.uniqueCount,duplicateCount:i.duplicateCount,noNewRounds:i.noNewRounds,beforeItemCount:i.before.itemCount,afterItemCount:i.after.itemCount,beforeScrollHeight:i.before.scrollHeight,afterScrollHeight:i.after.scrollHeight};return await a.succeed(`已读取 ${l.length} 位候选人`),t.logger.info(`Found ${l.length} candidates in recommend list`+(d?`, scroll stop: ${d.stopReason}`:"")),{success:!0,candidates:l,total:l.length,...void 0!==d?{scrollStats:d}:{}}}catch(e){return await(a?.fail("读取推荐列表失败")),{success:!1,candidates:[],total:0,error:e instanceof Error?e.message:"读取推荐列表失败"}}finally{r?.close()}}});import{defineTool as nm}from"@roll-agent/sdk";import{z as rm}from"zod";var am,om=["listed","recommend_not_ready","selector_not_found"],im=rm.object({index:rm.number(),jobRef:rm.string().optional(),value:rm.string(),label:rm.string(),isCurrent:rm.boolean()}),sm=rm.object({success:rm.boolean(),status:rm.enum(om),current:im.optional(),jobs:rm.array(im),availableCount:rm.number(),canSwitch:rm.boolean(),error:rm.string().optional()}),cm=450,lm=140,dm=750;function um(){return{openNativePagePort:_s,createNativeVisualActivitySession:e=>new ha(e),...am}}function mm(e,t){return{index:e.index,...void 0!==t?{jobRef:t}:{},value:e.value,label:e.label,isCurrent:e.isCurrent}}function pm(e,t){return e.value.length>0&&t.value.length>0?e.value===t.value:e.index===t.index&&e.label===t.label}function gm(e){const t=zu(e.options),n=e.options.map((e,n)=>mm(e,t[n]?.jobRef));let r;if(void 0!==e.current){const t=e.current;r=n.find(e=>pm(e,t))??mm(t)}return{success:e.success,status:e.status,...void 0!==r?{current:r}:{},jobs:n,availableCount:e.availableCount,canSwitch:e.canSwitch,...void 0!==e.error?{error:e.error}:{}}}var fm=nm({name:"zhipin_list_recommend_jobs",description:"读取 BOSS「推荐牛人」页顶部招聘岗位下拉选项,只读不切换;返回 jobRef/jobValue/current/canSwitch。",input:rm.object({}),output:sm,execute:async(e,t)=>{const n=um();let r,a;t.logger.info("Listing Boss recommend jobs through native CDP");try{r=await n.openNativePagePort(),a=n.createNativeVisualActivitySession(r),await wn(r),await a.begin("正在读取推荐岗位"),await a.highlightSelector(".job-selecter-wrap",{label:"正在读取推荐岗位",padding:8});const e=await r.listRecommendJobs({preClickDelayMs:cm,pressDurationMs:lm,settleMs:dm,...void 0!==a?{motionObserver:a}:{}});return e.success?await a.succeed(`已读取 ${e.availableCount} 个推荐岗位`):await a.fail(e.error??"读取推荐岗位失败"),gm(e)}catch(e){const t=e instanceof Error?e.message:"读取推荐岗位失败";return await(a?.fail(t)),gm({success:!1,status:"selector_not_found",options:[],availableCount:0,canSwitch:!1,error:t})}finally{r?.close()}}});import{BrowserPageInfoSchema as hm}from"@roll-agent/browser";import{defineTool as bm}from"@roll-agent/sdk";import{z as ym}from"zod";var vm,wm=ym.object({success:ym.boolean(),alreadyOnRecommend:ym.boolean(),usedSidebarClick:ym.boolean(),recommendReady:ym.boolean(),page:hm.optional(),error:ym.string().optional()});function xm(){return{getContextManager:ue,openNativePagePort:_s,createNativeVisualActivitySession:e=>new ha(e),...vm}}async function Sm(e,t){return Wt(e,await t.inspectPage())}var Im=bm({name:"zhipin_open_recommend_page",description:"通过点击 Boss 左侧导航切换到「推荐牛人」页,避免让编排器依赖站内 URL 猜测。",input:ym.object({}),output:wm,execute:async(e,t)=>{const n=xm(),r=n.getContextManager();let a,o;t.logger.info("Opening Boss recommend page via native sidebar navigation");try{a=await n.openNativePagePort(),o=n.createNativeVisualActivitySession(a),await wn(a);const e="正在切换到推荐牛人页";if(await o.begin(e),await o.highlightSelector(Mi.nav.sidebar,{label:e,padding:10}),await a.isRecommendSurfaceOpen())return await o.succeed("已在推荐牛人页"),{success:!0,alreadyOnRecommend:!0,usedSidebarClick:!1,recommendReady:!0,page:await Sm(r,a)};if(!await a.clickSidebarSection("recommend",{...void 0!==o?{motionObserver:o}:{}}))return await o.fail("未找到推荐牛人导航"),{success:!1,alreadyOnRecommend:!1,usedSidebarClick:!1,recommendReady:!1,page:await Sm(r,a),error:"未找到推荐牛人导航"};t.logger.info("Clicked Boss sidebar nav: 推荐牛人");return await a.waitForRecommendSurface()?(await o.succeed("已切换到推荐牛人页"),{success:!0,alreadyOnRecommend:!1,usedSidebarClick:!0,recommendReady:!0,page:await Sm(r,a)}):(await o.fail("推荐牛人页未就绪"),{success:!1,alreadyOnRecommend:!1,usedSidebarClick:!0,recommendReady:!1,page:await Sm(r,a),error:"推荐牛人页未就绪"})}catch(e){return await(o?.fail("切换推荐牛人页失败")),{success:!1,alreadyOnRecommend:!1,usedSidebarClick:!1,recommendReady:!1,error:e instanceof Error?e.message:"切换推荐牛人页失败"}}finally{a?.close()}}});import{defineTool as Cm}from"@roll-agent/sdk";import{z as Rm}from"zod";var km,Am=["selected","already_selected","not_found","recommend_not_ready","selector_not_found"],Nm=Rm.object({index:Rm.number(),value:Rm.string(),label:Rm.string(),isCurrent:Rm.boolean()}),Mm=Rm.object({jobRef:Rm.string().optional(),jobValue:Rm.string().optional(),jobName:Rm.string().optional(),index:Rm.number().optional(),searchKeyword:Rm.string().optional(),useSearch:Rm.boolean().optional(),forceClick:Rm.boolean().optional()}),Em=Rm.object({success:Rm.boolean(),status:Rm.enum(Am),requested:Mm,current:Nm.optional(),selected:Nm.optional(),options:Rm.array(Nm),matchedCount:Rm.number(),error:Rm.string().optional()}),Pm=Rm.object({jobRef:Rm.string().regex(Tu,"jobRef 应类似 @j1").optional().describe("岗位语义引用,如 @j1;来自 zhipin_list_recommend_jobs 输出,优先级最高"),jobValue:Rm.string().min(1).optional().describe("岗位下拉 li.job-item 的 value,来自本工具或页面 DOM;最稳定,优先匹配"),jobName:Rm.string().min(1).optional().describe("岗位标题/名称,缺少 jobValue 时用于文本匹配"),index:Rm.number().int().min(0).optional().describe("当前岗位下拉快照里的 index,仅在缺少 jobValue/jobName 时兜底"),searchKeyword:Rm.string().min(1).optional().describe("下拉搜索框关键词;不传时用 jobName 作为搜索关键词"),useSearch:Rm.boolean().default(!0).describe("初始可见项未命中时是否使用下拉搜索框收敛候选项"),forceClick:Rm.boolean().default(!1).describe("目标岗位已选中时是否仍点击一次岗位项;默认 false,避免无意义重复点击")}).refine(e=>void 0!==e.jobRef||void 0!==e.jobValue||void 0!==e.jobName||void 0!==e.index,{path:["jobRef"],message:"jobRef、jobValue、jobName、index 至少需要提供一个"}),Tm=900,_m=180,Bm=1400;function Om(){return{openNativePagePort:_s,createNativeVisualActivitySession:e=>new ha(e),...km}}function $m(e){if(void 0!==e.jobRef){const t=Uu(e.jobRef);return{jobRef:t.jobRef,...t.value.length>0?{jobValue:t.value}:{},...0===t.value.length&&t.label.length>0?{jobName:t.label}:{},index:t.index,...void 0!==e.searchKeyword?{searchKeyword:e.searchKeyword}:{},useSearch:e.useSearch??!0,forceClick:e.forceClick??!1}}return{...void 0!==e.jobValue?{jobValue:e.jobValue}:{},...void 0!==e.jobName?{jobName:e.jobName}:{},...void 0!==e.index?{index:e.index}:{},...void 0!==e.searchKeyword?{searchKeyword:e.searchKeyword}:{},useSearch:e.useSearch??!0,forceClick:e.forceClick??!1}}function Dm(e){return{...void 0!==e.jobRef?{jobRef:e.jobRef}:{},...void 0!==e.jobValue?{jobValue:e.jobValue}:{},...void 0!==e.jobName?{jobName:e.jobName}:{},...void 0!==e.index?{index:e.index}:{},...void 0!==e.searchKeyword?{searchKeyword:e.searchKeyword}:{},useSearch:e.useSearch??!0,forceClick:e.forceClick??!1}}function qm(e){return{index:e.index,value:e.value,label:e.label,isCurrent:e.isCurrent}}function Fm(e){return{success:e.success,status:e.status,requested:e.requested,...void 0!==e.current?{current:qm(e.current)}:{},...void 0!==e.selected?{selected:qm(e.selected)}:{},options:e.options.map(qm),matchedCount:e.matchedCount,...void 0!==e.error?{error:e.error}:{}}}var jm=Cm({name:"zhipin_select_recommend_job",description:"在 BOSS「推荐牛人」页切换顶部招聘岗位筛选。优先传 jobRef,其次 jobValue,再次 jobName,index 仅作当前快照兜底。",input:Pm,output:Em,execute:async(e,t)=>{const n=Om();let r,a;try{const o=$m(e);t.logger.info(`Selecting Boss recommend job: ref=${o.jobRef??"N/A"}, value=${o.jobValue??"N/A"}, name=${o.jobName??"N/A"}, index=${o.index??"N/A"}, forceClick=${!0===o.forceClick}`),r=await n.openNativePagePort(),a=n.createNativeVisualActivitySession(r),await wn(r),await a.begin("正在选择推荐岗位"),await a.highlightSelector(".job-selecter-wrap",{label:"正在选择推荐岗位",padding:8});const i=await r.selectRecommendJob(o,{preClickDelayMs:Tm,pressDurationMs:_m,settleMs:Bm,...void 0!==a?{motionObserver:a}:{}});return i.success?await a.succeed("already_selected"===i.status?"推荐岗位已是目标岗位":"已选择推荐岗位"):await a.fail(i.error??"选择推荐岗位失败"),Fm(i)}catch(t){const n=t instanceof Error?t.message:"选择推荐岗位失败";return await(a?.fail(n)),Fm({success:!1,status:void 0!==e.jobRef?"not_found":"selector_not_found",requested:Dm(e),options:[],matchedCount:0,error:n})}finally{r?.close()}}});import{defineTool as Lm}from"@roll-agent/sdk";import{z as zm}from"zod";var Jm,Um=zm.object({index:zm.number(),candidateRef:zm.string(),candidateName:zm.string(),candidateId:zm.string(),success:zm.boolean(),error:zm.string().optional()}),Vm=zm.object({success:zm.boolean(),results:zm.array(Um),summary:zm.object({total:zm.number(),succeeded:zm.number(),failed:zm.number()})}),Hm=[1400,1800,2200],Wm=450,Km=140,Ym=750,Gm=zm.object({indices:zm.array(zm.number().int().min(0)).min(1).optional().describe("要打招呼的候选人索引列表"),candidateRefs:zm.array(zm.string().regex(Pu,"candidateRef 应类似 @c1")).min(1).optional().describe("要打招呼的候选人语义引用列表,如 @c1;来自 zhipin_get_candidate_list 输出")}).refine(e=>(e.indices?.length??0)>0||(e.candidateRefs?.length??0)>0,"必须提供 indices 或 candidateRefs");function Xm(){return{openNativePagePort:_s,createNativeVisualActivitySession:e=>new ha(e),sleep:async e=>await new Promise(t=>{setTimeout(t,e)}),...Jm}}var Zm=Lm({name:"zhipin_say_hello",description:"在推荐列表页对候选人点击「打招呼」按钮(支持批量)",input:Gm,output:Vm,execute:async(e,t)=>{const n=Vu(e);t.logger.info(`Saying hello to ${n.length} candidates through native CDP`);const r=Xm();let a,o;try{a=await r.openNativePagePort(),o=r.createNativeVisualActivitySession(a),await o.begin("正在打开推荐列表");if(!await a.waitForRecommendList()){await o.fail("推荐列表未加载");const e=n.map(e=>({index:e.index,candidateRef:e.candidateRef,candidateName:"",candidateId:"",success:!1,error:"推荐列表未加载"}));return{success:!1,results:e,summary:{total:e.length,succeeded:0,failed:e.length}}}const e=n.length>1?"正在批量打招呼":"正在打招呼";await o.begin(e),await o.highlightSelector(".candidate-card-wrap, [data-geek], .geek-item",{label:e,padding:8});const i=[];for(const[e,s]of n.entries()){if(e>0){const t=Hm[(e-1)%Hm.length]??Hm[0];await r.sleep(t)}if(Qm(s)){const e=await a.inspectRecommendCard(s.index);if(!Hu(s,e)){i.push({index:s.index,candidateRef:s.candidateRef,candidateName:e.name,candidateId:e.candidateId,success:!1,error:`候选人引用 ${s.candidateRef} 已过期,请重新获取推荐列表`});continue}}const n=await a.clickRecommendGreet(s.index,{preClickDelayMs:Wm,pressDurationMs:Km,settleMs:Ym,...void 0!==o?{motionObserver:o}:{}});i.push({index:s.index,candidateRef:s.candidateRef,candidateName:n.name,candidateId:n.candidateId,success:n.clicked,...void 0!==n.error?{error:n.error}:{}}),dc(n,t.logger)}const s={total:i.length,succeeded:i.filter(e=>e.success).length,failed:i.filter(e=>!e.success).length};return 0===s.failed?await o.succeed(`已完成 ${s.succeeded}/${s.total} 位候选人`):await o.fail(`已完成 ${s.succeeded}/${s.total} 位候选人`),{success:0===s.failed,results:i,summary:s}}catch(e){const t=e instanceof Error?e.message:String(e);await(o?.fail(t));const r=n.map(e=>({index:e.index,candidateRef:e.candidateRef,candidateName:"",candidateId:"",success:!1,error:t}));return{success:!1,results:r,summary:{total:r.length,succeeded:0,failed:r.length}}}finally{a?.close()}}});function Qm(e){return e.candidateId.length>0||void 0!==e.name&&e.name.length>0}import{defineTool as ep}from"@roll-agent/sdk";import{z as tp}from"zod";var np="recommendFrame",rp="recommend",ap="#recommendFrame",op=".candidate-card-wrap",ip="[data-geek], .geek-item",sp=`${op}, ${ip}`,cp="[data-geek], .card-inner, .geek-item",lp="[data-geek]",dp=".name",up=[".recommendV2 .boss-popup__close",".dialog-lib-resume .boss-popup__close",".boss-dialog .boss-popup__close",".boss-popup__close",".close-btn",".dialog-close"],mp=[".boss-popup__close",".close-btn",".dialog-close",".modal-close"],pp=".boss-popup__wrapper, .dialog-lib-resume, .boss-dialog",gp=".boss-popup__wrapper",fp='iframe[src*="c-resume"]',hp="canvas#resume, div#resume canvas";function bp(e){return e.hasNamedRecommendFrame?"named-frame":e.hasRecommendUrlFrame?"recommend-url-frame":"main-page"}function yp(e){return e>0?op:ip}function vp(e){return{candidateId:(e.ownDataGeek??e.childDataGeek??"").trim(),name:(e.nameText??"").trim()}}function wp(e){const t=(e.recommendFrameRect?.x??0)+(e.resumeFrameRect?.x??0),n=(e.recommendFrameRect?.y??0)+(e.resumeFrameRect?.y??0);return{x:Math.round(t+e.canvasRect.x),y:Math.round(n+e.canvasRect.y),width:Math.round(e.canvasRect.width),height:Math.round(e.canvasRect.height)}}function xp(e){return e.evaluate(e=>document.querySelectorAll(e).length,op).then(yp)}function Sp(e){const t=e.frame(np),n=e.frames().find(e=>e.url().includes(rp)),r=bp({hasNamedRecommendFrame:null!==t,hasRecommendUrlFrame:void 0!==n});return"named-frame"===r?t??e:"recommend-url-frame"===r?n??e:e}async function Ip(e,t=1e4){try{return await e.waitForSelector(sp,{timeout:t}),!0}catch{return!1}}async function Cp(e,t){const n=await xp(e),r=e.locator(n);if(await r.count()<=t)return{found:!1,cardSelector:n,candidateId:"",name:"",hasGreetButton:!1,error:"索引超出范围"};const a=r.nth(t),o=await a.evaluate((e,t)=>{const n=e.getAttribute("data-geek")??e.querySelector(t.candidateIdSelector)?.getAttribute("data-geek")??"",r=e.querySelector(t.candidateNameSelector)?.textContent?.trim()??"",a=e.querySelector("button.btn.btn-greet");return{candidateId:n,name:r,hasGreetButton:null!==a&&a.offsetWidth>0}},{candidateIdSelector:lp,candidateNameSelector:dp}),i=vp({ownDataGeek:o.candidateId,nameText:o.name});return{found:!0,cardSelector:n,candidateId:i.candidateId,name:i.name,hasGreetButton:o.hasGreetButton}}var Rp=tp.object({success:tp.boolean(),candidateRef:tp.string().optional(),candidateName:tp.string(),candidateId:tp.string(),error:tp.string().optional()}),kp=tp.object({index:tp.number().int().min(0).optional().describe("候选人在列表中的 0-based 索引"),candidateRef:tp.string().regex(Pu,"candidateRef 应类似 @c1").optional().describe("候选人语义引用,如 @c1;来自 zhipin_get_candidate_list 输出")}).refine(e=>void 0!==e.index||void 0!==e.candidateRef,"必须提供 index 或 candidateRef"),Ap=ep({name:"zhipin_open_resume",description:"在推荐列表页点击候选人卡片打开简历详情弹窗",input:kp,output:Rp,execute:async(e,t)=>{const n=Np(e),r=n.index,a=n.candidateRef;t.logger.info(`Opening resume for candidate ${a} at index ${r}`);const o=ue(),i=await o.getPage("zhipin"),s=Sp(i);if(!await Ip(s))return{success:!1,candidateRef:a,candidateName:"",candidateId:"",error:"推荐列表未加载"};const c=await Cp(s,r);if(!c.found)return{success:!1,candidateRef:a,candidateName:"",candidateId:"",error:c.error??`候选人引用 ${a} 超出范围`};if(Mp(n)&&!Hu(n,c))return{success:!1,candidateRef:a,candidateName:c.name,candidateId:c.candidateId,error:`候选人引用 ${a} 已过期,请重新获取推荐列表`};const l=s.locator(c.cardSelector).nth(r),d=await l.locator(cp).count()>0?l.locator(cp).first():l;return await d.scrollIntoViewIfNeeded(),await Ke(i,d,{target:s}),await d.hover(),await Si(i,200,400),await Ye(i,d,{target:s}),await d.click(),await Si(i,1e3,2e3),t.logger.info(`Opened resume for ${c.name}`),{success:!0,candidateRef:a,candidateName:c.name,candidateId:c.candidateId}}});function Np(e){if(void 0!==e.candidateRef)return Ju(e.candidateRef);const t=ju(e);return{index:t,candidateRef:$u(t),candidateId:""}}function Mp(e){return e.candidateId.length>0||void 0!==e.name&&e.name.length>0}import{defineTool as Ep}from"@roll-agent/sdk";import{z as Pp}from"zod";var Tp=Pp.object({x:Pp.number(),y:Pp.number(),width:Pp.number(),height:Pp.number()}),_p=Pp.object({success:Pp.boolean(),screenshotArea:Tp.optional(),canvasInfo:Pp.object({width:Pp.number(),height:Pp.number()}).optional(),error:Pp.string().optional()}),Bp=Ep({name:"zhipin_locate_resume_canvas",description:"定位简历详情中嵌套 iframe 内的 canvas 元素坐标(用于截图)",input:Pp.object({}),output:_p,execute:async(e,t)=>{t.logger.info("Locating resume canvas in nested iframes");const n=ue(),r=await n.getPage("zhipin");try{const e=r.frame(np)??r.frames().find(e=>e.url().includes(rp));if(!e)return{success:!1,error:"未找到推荐页 iframe"};const n=await e.$(fp);if(!n)return{success:!1,error:"未找到简历 iframe"};const a=await n.contentFrame();if(!a)return{success:!1,error:"无法访问简历 iframe 内容"};try{await a.waitForSelector(hp,{timeout:5e3})}catch{return{success:!1,error:"简历 canvas 未加载"}}const o=await a.evaluate(e=>{const t=document.querySelector(e);if(!t)return null;const n=t.getBoundingClientRect();return{width:t.width,height:t.height,clientWidth:n.width,clientHeight:n.height,x:n.x,y:n.y}},hp);if(!o)return{success:!1,error:"无法获取 canvas 信息"};const i=await r.evaluate(e=>{const t=document.querySelector(e);if(!t)return null;const n=t.getBoundingClientRect();return{x:n.x,y:n.y}},ap),s=wp({recommendFrameRect:i,resumeFrameRect:await e.evaluate(e=>{const t=document.querySelector(e);if(!t)return null;const n=t.getBoundingClientRect();return{x:n.x,y:n.y}},fp),canvasRect:{x:o.x,y:o.y,width:o.clientWidth,height:o.clientHeight}});return t.logger.info(`Canvas located at (${s.x}, ${s.y})`),{success:!0,screenshotArea:s,canvasInfo:{width:o.width,height:o.height}}}catch(e){return{success:!1,error:e instanceof Error?e.message:String(e)}}}});import{defineTool as Op}from"@roll-agent/sdk";import{z as $p}from"zod";var Dp=$p.object({success:$p.boolean(),closed:$p.boolean(),error:$p.string().optional()}),qp=Op({name:"zhipin_close_resume",description:"关闭简历详情弹窗",input:$p.object({}),output:Dp,execute:async(e,t)=>{t.logger.info("Closing resume detail modal");const n=ue(),r=await n.getPage("zhipin"),a=r.frame(np)??r.frames().find(e=>e.url().includes(rp));if(!await(async()=>{if(a)for(const e of up){const t=a.locator(e).first();if(await t.isVisible())return await Ke(r,t,{target:a}),await Ye(r,t,{target:a}),await t.click(),!0}for(const e of mp){const t=r.locator(e).first();if(await t.isVisible())return await Ke(r,t),await Ye(r,t),await t.click(),!0}return!1})())return{success:!1,closed:!1,error:"未找到关闭按钮"};let o=!1;for(let e=0;e<5;e++){await r.waitForTimeout(300);const e=a?await a.$(pp):await r.$(gp);if(!e||!await e.isVisible()){o=!0;break}}return t.logger.info(o?"Resume modal closed and verified":"Resume modal close unverified"),{success:!0,closed:!0}}});import{defineTool as Fp}from"@roll-agent/sdk";import{z as jp}from"zod";import{waitForSelector as Lp}from"@roll-agent/browser";var zp={login:{qrCode:".login-qr img, .qr-code img",loginSuccess:".user-info, .header-user"},messageList:{container:".chat-list, .msg-list",item:".chat-item, .msg-item",candidateName:".chat-item .name, .msg-item .name",lastMessage:".chat-item .msg, .msg-item .content",unreadBadge:".chat-item .unread, .msg-item .badge",timestamp:".chat-item .time, .msg-item .time"},chat:{input:".chat-input textarea, .msg-input textarea",sendButton:".btn-send, .send-btn",messageItem:".chat-msg, .msg-bubble",messageText:".chat-msg .text, .msg-bubble .text"}};import{navigateTo as Jp,waitForSelector as Up}from"@roll-agent/browser";var Vp="https://www.yupao.com",Hp=`${Vp}/chat`,Wp=`${Vp}/login`;async function Kp(e,t={}){e.url().includes("/chat")||await Jp(e,Hp,t),await Up(e,zp.messageList.container,{timeout:15e3})}async function Yp(e,t,n={}){const r=`${Vp}/chat?id=${encodeURIComponent(t)}`;await Jp(e,r,n),await Up(e,zp.chat.input,{timeout:15e3})}async function Gp(e,t){await Kp(e),await Lp(e,zp.messageList.item,{timeout:1e4});const n=zp.messageList;return await e.$$eval(n.item,(e,t)=>{const n=[],r=t.maxItems?e.slice(0,t.maxItems):e;for(const e of r){const r=e.querySelector(t.sel.candidateName),a=e.querySelector(t.sel.lastMessage),o=e.querySelector(t.sel.unreadBadge),i=e.querySelector(t.sel.timestamp),s=e.getAttribute("data-id")??e.getAttribute("data-conversation-id")??e.querySelector("a")?.getAttribute("href")?.match(/id=([^&]+)/)?.[1]??"";n.push({conversationId:s,candidateName:r?.textContent?.trim()??"",lastMessage:a?.textContent?.trim()??"",unreadCount:parseInt(o?.textContent?.trim()??"0",10)||0,timestamp:i?.textContent?.trim()??""})}return n},{sel:n,maxItems:t})}var Xp=jp.object({limit:jp.number().optional().describe("最多返回的消息条数")}),Zp=jp.object({conversationId:jp.string(),candidateName:jp.string(),lastMessage:jp.string(),unreadCount:jp.number(),timestamp:jp.string()}),Qp=jp.object({messages:jp.array(Zp),total:jp.number()}),eg=Fp({name:"yupao_read_messages",description:"读取鱼泡未读消息列表",input:Xp,output:Qp,execute:async(e,t)=>{t.logger.info(`Reading yupao messages (limit: ${e.limit??"all"})`);const n=ue(),r=await n.getPage("yupao"),a=await Gp(r,e.limit);return t.logger.info(`Found ${a.length} messages`),{messages:a.map(e=>({...e})),total:a.length}}});import{defineTool as tg}from"@roll-agent/sdk";import{z as ng}from"zod";import{BrowserActionApprovalSchema as rg}from"@roll-agent/browser";import{clickElement as ag,isBrowserActionPolicyError as og,typeText as ig,waitForSelector as sg}from"@roll-agent/browser";async function cg(e,t,n,r={}){try{return await Yp(e,t,r),await ig(e,zp.chat.input,n,r),await ag(e,zp.chat.sendButton,r),await sg(e,zp.chat.messageItem,{timeout:5e3}),{success:!0}}catch(e){if(og(e))throw e;return{success:!1,error:e instanceof Error?e.message:String(e)}}}var lg=ng.object({conversationId:ng.string().describe("对话 ID"),message:ng.string().describe("要发送的回复消息"),browserActionApproval:rg.optional().describe("当 actionPolicy=confirm 返回 needs_confirmation 后,由 orchestrator 原样带回的批准 ID。")}),dg=ng.object({success:ng.boolean(),conversationId:ng.string(),sentMessage:ng.string(),error:ng.string().optional()}),ug=tg({name:"yupao_send_reply",description:"向鱼泡指定对话发送回复消息",input:lg,output:dg,execute:async(e,t)=>{const{conversationId:n,message:r}=e;t.logger.info(`Sending reply to yupao conversation ${n}`);const a=ue(),o=de(),i=hn(t,o,{action:"yupao_send_reply",target:n,...void 0!==e.browserActionApproval?{approval:e.browserActionApproval}:{}}),s=await a.getPage("yupao");let c;try{c=await cg(s,n,r,fn(t,o,{approval:e.browserActionApproval,approvedByConfirmation:i.approvedByConfirmation}))}catch(e){const t=bn(e);if(void 0!==t)throw t;throw e}return c.success?t.logger.info("Reply sent successfully"):t.logger.error(`Failed to send reply: ${c.error}`),{success:c.success,conversationId:n,sentMessage:r,error:c.error}}});import{BrowserRuntimeConfigSchema as mg,BrowserRuntimeModeSchema as pg,BrowserChannelSchema as gg,BrowserProfileColorSchema as fg,BrowserWindowBoundsSchema as hg,PlatformSchema as bg}from"@roll-agent/browser";import{z as yg}from"zod";var vg=yg.object({platform:bg.optional(),mode:pg.default("managed-cdp"),headless:yg.boolean().optional(),cdpUrl:yg.string().optional(),cdpHost:yg.string().default("127.0.0.1"),cdpPort:yg.number().int().min(1).max(65535).optional(),channel:gg.default("chrome"),executablePath:yg.string().optional(),userDataDir:yg.string().trim().min(1),sessionsDir:yg.string().trim().min(1).optional(),args:yg.array(yg.string()).optional(),profileName:yg.string().trim().min(1).optional(),profileColor:fg.optional(),windowBounds:hg.optional(),trackingAgentId:yg.string().trim().min(1).optional()}).superRefine((e,t)=>{"managed-cdp"===e.mode&&void 0===e.cdpPort&&t.addIssue({code:yg.ZodIssueCode.custom,path:["cdpPort"],message:"managed-cdp browser instance requires cdpPort"}),"remote-cdp"!==e.mode&&"existing-session"!==e.mode||void 0!==e.cdpUrl||t.addIssue({code:yg.ZodIssueCode.custom,path:["cdpUrl"],message:`${e.mode} browser instance requires cdpUrl`})}),wg=yg.object({defaultInstance:yg.string().trim().min(1).optional(),instances:yg.record(yg.string(),vg).default({})}).superRefine((e,t)=>{void 0!==e.defaultInstance&&void 0===e.instances[e.defaultInstance]&&t.addIssue({code:yg.ZodIssueCode.custom,path:["defaultInstance"],message:`defaultInstance "${e.defaultInstance}" is not declared in browser.instances`});const n=new Map,r=new Map;for(const[a,o]of Object.entries(e.instances)){if(void 0!==o.cdpPort){const e=n.get(o.cdpPort);void 0!==e?t.addIssue({code:yg.ZodIssueCode.custom,path:["instances",a,"cdpPort"],message:`cdpPort ${String(o.cdpPort)} is already used by browser instance "${e}"`}):n.set(o.cdpPort,a)}const e=r.get(o.userDataDir);void 0!==e?t.addIssue({code:yg.ZodIssueCode.custom,path:["instances",a,"userDataDir"],message:`userDataDir is already used by browser instance "${e}"`}):r.set(o.userDataDir,a)}});function xg(e){if(void 0!==e){if("true"===e)return!0;if("false"===e)return!1;throw new Error(`Expected boolean env value "true" or "false", received "${e}".`)}}function Sg(e,t){if(void 0===e)return;const n=Number.parseInt(e,10);if(!Number.isInteger(n))throw new Error(`${t} must be an integer, received "${e}".`);return n}function Ig(e){if(void 0===e)return;const t=JSON.parse(e);if(!Array.isArray(t)||!t.every(e=>"string"==typeof e))throw new Error("BROWSER_ARGS_JSON must be a JSON string array.");return t}function Cg(e){if(void 0!==e)try{return JSON.parse(e)}catch(e){throw new Error(`BROWSER_SECURITY_JSON must be valid JSON: ${e instanceof Error?e.message:String(e)}`)}}function Rg(e){if(void 0===e)return;let t;try{t=JSON.parse(e)}catch(e){throw new Error(`BROWSER_INSTANCES_JSON must be valid JSON: ${e instanceof Error?e.message:String(e)}`)}return wg.parse(t)}function kg(e=process.env){return mg.parse({mode:e.BROWSER_MODE,headless:xg(e.BROWSER_HEADLESS),cdpUrl:e.BROWSER_CDP_URL,cdpHost:e.BROWSER_CDP_HOST,cdpPort:Sg(e.BROWSER_CDP_PORT,"BROWSER_CDP_PORT"),channel:e.BROWSER_CHANNEL,executablePath:e.BROWSER_EXECUTABLE_PATH,userDataDir:e.BROWSER_USER_DATA_DIR,args:Ig(e.BROWSER_ARGS_JSON),profileColor:e.BROWSER_PROFILE_COLOR,sessionsDir:e.BROWSER_SESSIONS_DIR,security:Cg(e.BROWSER_SECURITY_JSON)})}function Ag(e=process.env){return Rg(e.BROWSER_INSTANCES_JSON)}import{z as Ng}from"zod";import{StructuredToolError as Mg}from"@roll-agent/sdk";function Eg(e){if(void 0===e)return;const t=ge().getBundle();if(void 0!==t.platform&&t.platform!==e)throw new Mg({code:"platform_mismatch",message:`Tool platform "${e}" does not match browser instance "${t.id}" platform "${t.platform}".`,details:{browserInstance:t.id,expectedPlatform:t.platform,requestedPlatform:e}})}function Pg(e){if("object"!=typeof e||null===e||!("platform"in e))return;const t=e.platform;return"zhipin"===t||"yupao"===t?t:void 0}var Tg={browserInstance:Ng.string().trim().min(1).optional().describe("可选 browser instance id;多浏览器实例时用于选择目标 profile/CDP runtime。")};function _g(e){return e.startsWith("zhipin_")?"zhipin":e.startsWith("yupao_")?"yupao":void 0}function Bg(e,t={}){const n=$g(e.input);if(void 0===n)return e;const r=t.startRuntime??!0,a=t.expectedPlatform??_g(e.name);return{...e,input:n,execute:async(t,n)=>{const o=t;return await Y(o.browserInstance,async()=>(void 0!==o.browserInstance&&ge().getBundle(),Eg(Og(t,a)),r&&await fe(),await e.execute(t,n)))}}}function Og(e,t){const n=Pg(e);return t??n}function $g(e){if(e instanceof Ng.ZodObject)return e.extend(Tg);if(e instanceof Ng.ZodEffects){const t=$g(e.innerType());if(void 0===t)return;const n=e._def.effect;return"preprocess"===n.type?Ng.ZodEffects.createWithPreprocess(n.transform,t,e._def):Ng.ZodEffects.create(t,n,e._def)}}var Dg=t("browser-use-agent");function qg(e){return"browser_stop"===e}function Fg(e){return qg(e.name)?e:Bg(e,{startRuntime:"browser_status"!==e.name})}var jg=e({name:"browser-use-agent",tools:[At,Xt,Dn,nr,mr,vr,Ma,za,Ga,yi,vc,Ec,$c,Qc,Pl,Pd,Jd,Yd,iu,Im,fm,jm,Iu,tm,Zm,Ap,Bp,qp,eg,ug,xe,Ot].map(Fg)},{onShutdown:ve});async function Lg(){xt(wt()),await le(kg(),Ag());try{await od(),me(!0)}catch(e){me(!1),Dg.error(`Failed to preload Reply Authority keys during startup; browser_status.replyAuthorityKeysLoaded=false. ${e instanceof Error?e.stack??e.message:String(e)}`)}await jg.listen({transport:{type:"http",port:parseInt(process.env.BROWSER_AGENT_PORT??"3100",10),host:process.env.BROWSER_AGENT_HOST??"127.0.0.1"}})}Lg().catch(async e=>{Dg.error(`Fatal error: ${e instanceof Error?e.stack??e.message:String(e)}`),await ve().catch(()=>{}),process.exit(1)});
|