publishport-opencli 1.8.5-pp.43 → 1.8.5-pp.44

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.
@@ -1 +1 @@
1
- import{sleep as F}from"../utils.js";import{BrowserConnectError as O}from"../errors.js";import{classifyBrowserError as P}from"./errors.js";import{resolveProfileContextId as W}from"./profile.js";import{DEFAULT_BROWSER_CONNECT_TIMEOUT as b}from"./config.js";import{ensureBrowserBridgeReady as A}from"./daemon-lifecycle.js";import{isPreDispatchError as D}from"./bridge-readiness.js";import{fetchDaemonStatus,getDaemonHealth,requestDaemon as _,requestDaemonShutdown}from"./daemon-transport.js";let f=0;function j(){return`cmd_${process.pid}_${Date.now()}_${++f}`}export class BrowserCommandError extends Error{code;hint;constructor(K,J,Q){super(K);this.code=J;this.hint=Q;this.name="BrowserCommandError"}}export{fetchDaemonStatus,getDaemonHealth,requestDaemonShutdown};async function L(K,J){const Q=4;let V=!1,$=!1,X=!1;for(let k=1;k<=Q;k++){const N=j(),Z=process.env.OPENCLI_WINDOW,S=Z==="foreground"||Z==="background"?Z:void 0,Y=J.contextId??W(),H=J.windowMode??S,x={id:N,action:K,...J,...Y&&{contextId:Y},...H&&{windowMode:H}};try{const G=await _("/command",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(x),timeout:30000}),z=await G.json();if(z.ok)return z;if(z.errorCode==="command_result_unknown")throw new BrowserCommandError(z.error??"Browser command result is unknown",z.errorCode,z.errorHint);if(!V&&D(z.errorCode)){V=!0;await A({timeoutSeconds:b,contextId:Y,verbose:!1});continue}if(G.status===409&&!z.errorCode&&(z.error??"").includes("Duplicate command id")&&!$){$=!0;continue}const q=P(Error(z.error??""));if(q.retryable&&!X){X=!0;await F(q.delayMs);continue}throw new BrowserCommandError(z.error??"Daemon command failed",z.errorCode,z.errorHint)}catch(G){if(G instanceof BrowserCommandError||G instanceof O)throw G;if(G instanceof Error&&G.name==="AbortError")throw new BrowserCommandError("Browser command timed out client-side; the page may still have applied it.","command_result_unknown","Inspect the page state before retrying. Idempotent reads are safe to retry; non-idempotent writes may have already happened.");if(!V&&G instanceof TypeError){V=!0;await A({timeoutSeconds:b,contextId:Y,verbose:!1});continue}if(G instanceof Error){const z=P(G);if(z.retryable&&!X){X=!0;await F(z.delayMs);continue}}throw G}}throw new BrowserCommandError("sendCommand: max attempts exhausted","max_attempts_exhausted")}export async function sendCommand(K,J={}){return(await L(K,J)).data}export async function sendCommandFull(K,J={}){const Q=await L(K,J);return{data:Q.data,page:Q.page}}export async function bindTab(K,J={}){return sendCommand("bind",{session:K,surface:"browser",...J})}
1
+ import{sleep as L}from"../utils.js";import{BrowserConnectError as D}from"../errors.js";import{classifyBrowserError as S}from"./errors.js";import{resolveProfileContextId as M}from"./profile.js";import{DEFAULT_BROWSER_CONNECT_TIMEOUT as $}from"./config.js";import{ensureBrowserBridgeReady as H}from"./daemon-lifecycle.js";import{isPreDispatchError as O}from"./bridge-readiness.js";import{fetchDaemonStatus,getDaemonHealth,requestDaemon as _,requestDaemonShutdown}from"./daemon-transport.js";let g=0;function N(){return`cmd_${process.pid}_${Date.now()}_${++g}`}export class BrowserCommandError extends Error{code;hint;constructor(K,J,Q){super(K);this.code=J;this.hint=Q;this.name="BrowserCommandError"}}export{fetchDaemonStatus,getDaemonHealth,requestDaemonShutdown};async function f(K,J){const Q=4;let X=!1,P=!1,Y=!1;const b=K==="navigate";let Z=!1;for(let F=1;F<=Q;F++){const j=N(),q=process.env.OPENCLI_WINDOW,x=q==="foreground"||q==="background"?q:void 0,V=J.contextId??M(),k=J.windowMode??x,W={id:j,action:K,...J,...V&&{contextId:V},...k&&{windowMode:k}};try{const G=await _("/command",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(W),timeout:30000}),z=await G.json();if(z.ok)return z;if(z.errorCode==="command_result_unknown"){if(b&&!Z){Z=!0;await H({timeoutSeconds:$,contextId:V,verbose:!1});continue}throw new BrowserCommandError(z.error??"Browser command result is unknown",z.errorCode,z.errorHint)}if(!X&&O(z.errorCode)){X=!0;await H({timeoutSeconds:$,contextId:V,verbose:!1});continue}if(G.status===409&&!z.errorCode&&(z.error??"").includes("Duplicate command id")&&!P){P=!0;continue}const A=S(Error(z.error??""));if(A.retryable&&!Y){Y=!0;await L(A.delayMs);continue}throw new BrowserCommandError(z.error??"Daemon command failed",z.errorCode,z.errorHint)}catch(G){if(G instanceof BrowserCommandError||G instanceof D)throw G;if(G instanceof Error&&G.name==="AbortError"){if(b&&!Z){Z=!0;await H({timeoutSeconds:$,contextId:V,verbose:!1});continue}throw new BrowserCommandError("Browser command timed out client-side; the page may still have applied it.","command_result_unknown","Inspect the page state before retrying. Idempotent reads are safe to retry; non-idempotent writes may have already happened.")}if(!X&&G instanceof TypeError){X=!0;await H({timeoutSeconds:$,contextId:V,verbose:!1});continue}if(G instanceof Error){const z=S(G);if(z.retryable&&!Y){Y=!0;await L(z.delayMs);continue}}throw G}}throw new BrowserCommandError("sendCommand: max attempts exhausted","max_attempts_exhausted")}export async function sendCommand(K,J={}){return(await f(K,J)).data}export async function sendCommandFull(K,J={}){const Q=await f(K,J);return{data:Q.data,page:Q.page}}export async function bindTab(K,J={}){return sendCommand("bind",{session:K,surface:"browser",...J})}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "publishport-opencli",
3
- "version": "1.8.5-pp.43",
3
+ "version": "1.8.5-pp.44",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": false