@doubao-dev/cli 0.0.25 → 0.0.27

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.
Files changed (110) hide show
  1. package/dist/2168.js +60 -0
  2. package/dist/{4091.js → 2611.js} +14 -14
  3. package/dist/275.js +25 -0
  4. package/dist/2932.js +1 -1
  5. package/dist/318.js +1 -1
  6. package/dist/3768.js +1 -0
  7. package/dist/3974.js +10 -10
  8. package/dist/4594.js +7 -0
  9. package/dist/4931.js +2 -2
  10. package/dist/{react.js → 6831.js} +1 -1
  11. package/dist/7410.js +1 -1
  12. package/dist/@byted-doubao-apps/create.js +1 -1
  13. package/dist/@byted-doubao-apps/login.js +1 -1
  14. package/dist/@byted-doubao-apps/login~1.js +1 -1
  15. package/dist/@byted-doubao-apps/template-empty/package.json +3 -3
  16. package/dist/@byted-doubao-apps/template-starter/package.json +3 -3
  17. package/dist/@byted-hdt/cli.js +1 -1
  18. package/dist/@inquirer/select.js +1 -1
  19. package/dist/agentic-service.js +1 -0
  20. package/dist/app.js +1 -1
  21. package/dist/assets/web-sdk-debugger/index.html +1 -1
  22. package/dist/assets/web-sdk-debugger/static/css/index.cc3b255797.css +1 -0
  23. package/dist/assets/web-sdk-debugger/static/js/index.1448a806d8.js +26 -0
  24. package/dist/assets/web-sdk-debugger/wsd/doubao-apps-api.template.js +0 -0
  25. package/dist/assets/web-sdk-debugger/wsd/doubao-apps-framework.template.js +0 -0
  26. package/dist/browser.js +1 -1
  27. package/dist/check.js +1 -0
  28. package/dist/dbx.js +2 -2
  29. package/dist/demo-server.js +3 -3
  30. package/dist/demo.js +2 -0
  31. package/dist/dev-config.js +2 -2
  32. package/dist/dev-service-client.js +1 -25
  33. package/dist/dev-shell.js +1 -1
  34. package/dist/dev.js +10 -10
  35. package/dist/gen-explore.js +1 -1
  36. package/dist/gen-trajectory.js +1 -1
  37. package/dist/get.js +1 -1
  38. package/dist/init.js +4 -4
  39. package/dist/ink.js +3 -3
  40. package/dist/json-file.js +1 -1
  41. package/dist/login.js +1 -1
  42. package/dist/main.js +1 -1
  43. package/dist/manifest-mcp-config.js +1 -1
  44. package/dist/ora.js +1 -1
  45. package/dist/portal.js +1 -1
  46. package/dist/project-layout.js +1 -1
  47. package/dist/prompt.js +7 -7
  48. package/dist/prompts.js +1 -1
  49. package/dist/report.js +1 -1
  50. package/dist/run-registry.js +1 -1
  51. package/dist/run.js +122 -122
  52. package/dist/sandbox.js +1 -1
  53. package/dist/scan.js +1 -1
  54. package/dist/sdk.js +20 -20
  55. package/dist/sdk~1.js +20 -20
  56. package/dist/server.js +4 -4
  57. package/dist/simulator-client.js +1 -1
  58. package/dist/skill.js +1 -1
  59. package/dist/skills.js +1 -1
  60. package/dist/skills~2.js +2 -2
  61. package/dist/status.js +2 -2
  62. package/dist/status~1.js +1 -1
  63. package/dist/stop.js +1 -1
  64. package/dist/templates/README.md +1 -1
  65. package/dist/update.js +1 -1
  66. package/dist/upgrade.js +1 -1
  67. package/dist/upload.js +6 -6
  68. package/dist/workspace.js +1 -1
  69. package/dist/yaml.js +2 -2
  70. package/package.json +2 -2
  71. package/skills/dbx-eval/SKILL.md +2 -2
  72. package/skills/doubao-agentic-service-development/SKILL.md +8 -8
  73. package/skills/doubao-agentic-service-development/references/auth.md +2 -2
  74. package/skills/doubao-agentic-service-development/references/business-template-debug.md +3 -3
  75. package/skills/doubao-agentic-service-development/references/dev-debug.md +2 -2
  76. package/skills/doubao-agentic-service-development/references/frontend/doubao-agentic-service-api/01-/345/237/272/347/241/200.md +175 -15
  77. package/skills/doubao-agentic-service-development/references/frontend/doubao-agentic-service-api/02-/347/263/273/347/273/237.md +3 -3
  78. package/skills/doubao-agentic-service-development/references/frontend/doubao-agentic-service-api/03-/350/207/252/345/256/232/344/271/211/351/200/232/344/277/241.md +1 -1
  79. package/skills/doubao-agentic-service-development/references/frontend/doubao-agentic-service-api/04-/345/256/232/344/275/215.md +1 -1
  80. package/skills/doubao-agentic-service-development/references/frontend/doubao-agentic-service-api/08-/344/272/244/344/272/222.md +221 -7
  81. package/skills/doubao-agentic-service-development/references/frontend/doubao-agentic-service-api/10-/347/275/221/347/273/234.md +20 -20
  82. package/skills/doubao-agentic-service-development/references/frontend/doubao-agentic-service-api/11-/345/252/222/344/275/223.md +2 -2
  83. package/skills/doubao-agentic-service-development/references/frontend/doubao-agentic-service-api/12-/344/270/232/345/212/241/350/203/275/345/212/233.md +3 -4
  84. package/skills/doubao-agentic-service-development/references/frontend/doubao-agentic-service-api/16-/350/223/235/347/211/231.md +3 -3
  85. package/skills/doubao-agentic-service-development/references/frontend/doubao-agentic-service-api/25-/346/227/240/351/232/234/347/242/215.md +1 -1
  86. package/skills/doubao-agentic-service-development/references/frontend/doubao-agentic-service-api/26-/345/237/272/347/241/200/344/277/241/346/201/257.md +3 -3
  87. package/skills/doubao-agentic-service-development/references/frontend/doubao-agentic-service-api/28-/345/211/252/350/264/264/346/235/277.md +2 -2
  88. package/skills/doubao-agentic-service-development/references/frontend/doubao-agentic-service-api/32-/346/211/253/347/240/201.md +1 -1
  89. package/skills/doubao-agentic-service-development/references/frontend/doubao-agentic-service-api/33-/345/261/217/345/271/225.md +1 -1
  90. package/skills/doubao-agentic-service-development/references/frontend/doubao-agentic-service-api/34-/351/234/207/345/212/250.md +2 -2
  91. package/skills/doubao-agentic-service-development/references/frontend/doubao-agentic-service-api/common-errors.md +1 -1
  92. package/skills/doubao-agentic-service-development/references/frontend/doubao-agentic-service-api/groups.md +3 -3
  93. package/skills/doubao-agentic-service-development/references/frontend/doubao-agentic-service-api/quick-reference.md +7 -3
  94. package/skills/doubao-agentic-service-development/references/frontend-dev.md +3 -3
  95. package/skills/doubao-agentic-service-development/references/generate-skill.md +1 -1
  96. package/skills/doubao-agentic-service-development/references/local-debug/simulator-eval.md +26 -22
  97. package/skills/doubao-agentic-service-development/references/manifest-guide.md +3 -3
  98. package/skills/doubao-agentic-service-development/references/mcp-protocol.md +1 -1
  99. package/skills/doubao-agentic-service-development/references/overview.md +2 -3
  100. package/skills/doubao-agentic-service-development/references/service-notice.md +1 -3
  101. package/skills/doubao-agentic-service-development/references/task-management.md +1 -3
  102. package/dist/1664.js +0 -66
  103. package/dist/assets/web-sdk-debugger/static/css/index.3fba1d83fd.css +0 -1
  104. package/dist/assets/web-sdk-debugger/static/js/index.c19e6628b4.js +0 -26
  105. package/dist/dbx-demo.js +0 -2
  106. package/dist/eval.js +0 -1
  107. package/dist/validate.js +0 -1
  108. /package/dist/{4091.js.LICENSE.txt → 2611.js.LICENSE.txt} +0 -0
  109. /package/dist/{dev-service-client.js.LICENSE.txt → 275.js.LICENSE.txt} +0 -0
  110. /package/dist/{react.js.LICENSE.txt → 6831.js.LICENSE.txt} +0 -0
package/dist/dev.js CHANGED
@@ -1,4 +1,4 @@
1
- import"node:module";import{__webpack_require__ as e}from"./rslib-runtime.js";import{external_node_stream_promises_namespaceObject as t,getApiBaseUrl as n,chalk_source as r,version_version as o,option_Option as i,flushEvents as s,setEventTrackingUid as a,build_getAuthOptions as d,reportCommand as l,runTrackedDevAction as c,command_Command as u,reportDevAction as p,runCommand as h,classifyEventStatus as f,isRecord as m}from"./1664.js";import{DEV_ACTIONS as g,ensureDevActionSucceeded as _,summarizeData as w,parseJsonData as y,DEV_EVENTS as b,connectDevService as v,ServiceManager as E,startForegroundDevService as I}from"./dev-service-client.js";import{listMiniAppVersions as A}from"./app.js";import{openUrlInBrowser as T}from"./browser.js";import{resolveDevSimulatorPaths as C,prepareDevBusinessTemplates as S,extractDevPermissions as j,normalizeLoopbackUrl as k,prepareDevManifest as D,resolveDevMcpEndpoint as P,formatFinalDevWarnings as x}from"./dev-config.js";import{resolveProjectLayout as L}from"./project-layout.js";import{extractMCPHeadersFromManifest as R}from"./manifest-mcp-config.js";import{createKitDevOptions as O}from"./kit-dev-options.js";import"./180.js";import"./3551.js";e.add({"../../../node_modules/.pnpm/@byted-doubao-tools+real-device-debug-auth@0.1.3/node_modules/@byted-doubao-tools/real-device-debug-auth/dist/lib/index.js"(e,t,n){t.Ph=void 0;var r=n("../../../node_modules/.pnpm/@byted-doubao-tools+real-device-debug-auth@0.1.3/node_modules/@byted-doubao-tools/real-device-debug-auth/dist/lib/realDeviceDebugQRCode.js");Object.defineProperty(t,"Ph",{enumerable:!0,get:function(){return r.createRealDeviceDebugQRCodeValue}})},"../../../node_modules/.pnpm/@byted-doubao-tools+real-device-debug-auth@0.1.3/node_modules/@byted-doubao-tools/real-device-debug-auth/dist/lib/realDeviceDebugQRCode.js"(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.createRealDeviceDebugQRCodeValue=t.REAL_DEVICE_DEBUG_QR_ACTION=t.DEFAULT_REAL_DEVICE_DEBUG_BASE_API_URL=void 0;let r=n("../../../node_modules/.pnpm/tslib@2.8.1/node_modules/tslib/tslib.es6.mjs"),o=r.__importStar(n("../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.24/node_modules/@byted-doubao-apps/auth-cli/dist/index.js"));t.DEFAULT_REAL_DEVICE_DEBUG_BASE_API_URL="https://hello.doubao-dev.com",t.REAL_DEVICE_DEBUG_QR_ACTION="start_real_device_debug";class i extends Error{constructor(e,t){super(t),this.name="RealDeviceDebugAuthError",this.code=e}}let s=null;function a(e,t){let n=e.trim();if(!n)throw Error(t);return n}t.createRealDeviceDebugQRCodeValue=function(e){var n,d,l;return r.__awaiter(this,void 0,void 0,function*(){var c;let u=Object.assign(Object.assign({hostUrl:a(e.hostUrl,"hostUrl is required to request real-device debug ticket"),appKey:a(e.appKey,"appKey is required to request real-device debug ticket"),isSigned:e.isSigned,isEncrypted:!!e.isEncrypted,signPublicKeyVersion:null==(n=e.signPublicKeyVersion)?void 0:n.trim(),versionTag:(c=e.versionTag,void 0===c?void 0:a(c,"versionTag must not be empty")),appletType:e.appletType,baseApiUrl:e.baseApiUrl||t.DEFAULT_REAL_DEVICE_DEBUG_BASE_API_URL},!1===e.defaultDebugTagState?{defaultDebugTagState:!1}:{}),e.wifiConnectUrl?{wifiConnectUrl:e.wifiConnectUrl}:{}),p=yield function(e,n){return r.__awaiter(this,void 0,void 0,function*(){var r;let o,i=(r=e.appKey,o=a(e.baseApiUrl||t.DEFAULT_REAL_DEVICE_DEBUG_BASE_API_URL,"baseApiUrl is required to request real-device debug ticket"),new URL(`/developer/check_api/apps/${encodeURIComponent(r)}/debug/ticket`,o).toString()),s=yield n({method:"POST",url:i,data:{debug_context:JSON.stringify(Object.assign(Object.assign(Object.assign(Object.assign({appletName:e.appKey,appletHost:e.hostUrl,appletType:e.appletType,isSigned:e.isSigned,isEncrypted:e.isEncrypted},e.versionTag?{versionTag:e.versionTag}:{}),e.isSigned&&e.signPublicKeyVersion?{signPublicKeyVersion:e.signPublicKeyVersion}:{}),!1===e.defaultDebugTagState?{defaultDebugTagState:!1}:{}),e.wifiConnectUrl?{wifiConnectUrl:e.wifiConnectUrl}:{}))}});return null==s?void 0:s.data})}(u,function(e){return({method:t,url:n,data:a,headers:d})=>r.__awaiter(this,void 0,void 0,function*(){try{let r,i=Object.entries(Object.assign(Object.assign({},void 0===a?{}:{"Content-Type":"application/json"}),d)).reduce((e,[t,n])=>("string"==typeof n&&(e[t]=n),e),{}),l=yield(e?o.withAuth(fetch,e):(!s&&(s=o.withAuth()),s))(n,{method:t,headers:i,body:void 0===a?void 0:JSON.stringify(a)}),c=yield l.text();if(c)try{r=JSON.parse(c)}catch(e){r=c}if(!l.ok)throw Error(`Authed request failed with HTTP ${l.status}${c?`: ${c}`:""}`);return{data:r,status:l.status,headers:l.headers}}catch(e){throw e instanceof o.NotLoggedInError?new i("NOT_LOGGED_IN","No open-platform login session is available. Please run dbx auth:login first, then retry."):e instanceof o.TokenExpiredError?new i("TOKEN_EXPIRED","The open-platform login session has expired. Please run dbx auth:login again, then retry."):e instanceof o.AuthError?new i("AUTH_FAILED",`Open-platform authentication failed: ${e.message}`):e instanceof Error?e:Error(String(e))}})}(e.authOptions));if(!p||0!==p.code){let e=(null==p?void 0:p.code)===void 0?"unknown":String(p.code);if((null==p?void 0:p.code)===0x2fb1793)throw new i("APP_ROLE_PERMISSION_REQUIRED",`真机调试授权失败:当前账号没有工程所配置智能服务的角色权限。
1
+ import"node:module";import{__webpack_require__ as e}from"./rslib-runtime.js";import{external_node_stream_promises_namespaceObject as t}from"./3768.js";import{DEV_ACTIONS as n,ensureDevActionSucceeded as r,summarizeData as o,parseJsonData as i,DEV_EVENTS as s,connectDevService as a,ServiceManager as d,startForegroundDevService as l}from"./275.js";import{isRecord as c,getApiBaseUrl as u,reportCommand as p,version_version as h,runTrackedDevAction as f,flushEvents as m,reportDevAction as g,command_Command as _,option_Option as w,runCommand as y,setEventTrackingUid as b,classifyEventStatus as v,build_getAuthOptions as E}from"./2168.js";import{listMiniAppVersions as I}from"./app.js";import{openUrlInBrowser as A}from"./browser.js";import{source as T}from"./4594.js";import{resolveDevSimulatorPaths as C,prepareDevBusinessTemplates as S,extractDevPermissions as j,normalizeLoopbackUrl as k,prepareDevManifest as D,resolveDevMcpEndpoint as P,formatFinalDevWarnings as x}from"./dev-config.js";import{resolveProjectLayout as L}from"./project-layout.js";import{extractMCPHeadersFromManifest as R}from"./manifest-mcp-config.js";import{createKitDevOptions as O}from"./kit-dev-options.js";import"./180.js";import"./3551.js";e.add({"../../../node_modules/.pnpm/@byted-doubao-tools+real-device-debug-auth@0.1.3/node_modules/@byted-doubao-tools/real-device-debug-auth/dist/lib/index.js"(e,t,n){t.Ph=void 0;var r=n("../../../node_modules/.pnpm/@byted-doubao-tools+real-device-debug-auth@0.1.3/node_modules/@byted-doubao-tools/real-device-debug-auth/dist/lib/realDeviceDebugQRCode.js");Object.defineProperty(t,"Ph",{enumerable:!0,get:function(){return r.createRealDeviceDebugQRCodeValue}})},"../../../node_modules/.pnpm/@byted-doubao-tools+real-device-debug-auth@0.1.3/node_modules/@byted-doubao-tools/real-device-debug-auth/dist/lib/realDeviceDebugQRCode.js"(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.createRealDeviceDebugQRCodeValue=t.REAL_DEVICE_DEBUG_QR_ACTION=t.DEFAULT_REAL_DEVICE_DEBUG_BASE_API_URL=void 0;let r=n("../../../node_modules/.pnpm/tslib@2.8.1/node_modules/tslib/tslib.es6.mjs"),o=r.__importStar(n("../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.26/node_modules/@byted-doubao-apps/auth-cli/dist/index.js"));t.DEFAULT_REAL_DEVICE_DEBUG_BASE_API_URL="https://hello.doubao-dev.com",t.REAL_DEVICE_DEBUG_QR_ACTION="start_real_device_debug";class i extends Error{constructor(e,t){super(t),this.name="RealDeviceDebugAuthError",this.code=e}}let s=null;function a(e,t){let n=e.trim();if(!n)throw Error(t);return n}t.createRealDeviceDebugQRCodeValue=function(e){var n,d,l;return r.__awaiter(this,void 0,void 0,function*(){var c;let u=Object.assign(Object.assign({hostUrl:a(e.hostUrl,"hostUrl is required to request real-device debug ticket"),appKey:a(e.appKey,"appKey is required to request real-device debug ticket"),isSigned:e.isSigned,isEncrypted:!!e.isEncrypted,signPublicKeyVersion:null==(n=e.signPublicKeyVersion)?void 0:n.trim(),versionTag:(c=e.versionTag,void 0===c?void 0:a(c,"versionTag must not be empty")),appletType:e.appletType,baseApiUrl:e.baseApiUrl||t.DEFAULT_REAL_DEVICE_DEBUG_BASE_API_URL},!1===e.defaultDebugTagState?{defaultDebugTagState:!1}:{}),e.wifiConnectUrl?{wifiConnectUrl:e.wifiConnectUrl}:{}),p=yield function(e,n){return r.__awaiter(this,void 0,void 0,function*(){var r;let o,i=(r=e.appKey,o=a(e.baseApiUrl||t.DEFAULT_REAL_DEVICE_DEBUG_BASE_API_URL,"baseApiUrl is required to request real-device debug ticket"),new URL(`/developer/check_api/apps/${encodeURIComponent(r)}/debug/ticket`,o).toString()),s=yield n({method:"POST",url:i,data:{debug_context:JSON.stringify(Object.assign(Object.assign(Object.assign(Object.assign({appletName:e.appKey,appletHost:e.hostUrl,appletType:e.appletType,isSigned:e.isSigned,isEncrypted:e.isEncrypted},e.versionTag?{versionTag:e.versionTag}:{}),e.isSigned&&e.signPublicKeyVersion?{signPublicKeyVersion:e.signPublicKeyVersion}:{}),!1===e.defaultDebugTagState?{defaultDebugTagState:!1}:{}),e.wifiConnectUrl?{wifiConnectUrl:e.wifiConnectUrl}:{}))}});return null==s?void 0:s.data})}(u,function(e){return({method:t,url:n,data:a,headers:d})=>r.__awaiter(this,void 0,void 0,function*(){try{let r,i=Object.entries(Object.assign(Object.assign({},void 0===a?{}:{"Content-Type":"application/json"}),d)).reduce((e,[t,n])=>("string"==typeof n&&(e[t]=n),e),{}),l=yield(e?o.withAuth(fetch,e):(!s&&(s=o.withAuth()),s))(n,{method:t,headers:i,body:void 0===a?void 0:JSON.stringify(a)}),c=yield l.text();if(c)try{r=JSON.parse(c)}catch(e){r=c}if(!l.ok)throw Error(`Authed request failed with HTTP ${l.status}${c?`: ${c}`:""}`);return{data:r,status:l.status,headers:l.headers}}catch(e){throw e instanceof o.NotLoggedInError?new i("NOT_LOGGED_IN","No open-platform login session is available. Please run dbx auth:login first, then retry."):e instanceof o.TokenExpiredError?new i("TOKEN_EXPIRED","The open-platform login session has expired. Please run dbx auth:login again, then retry."):e instanceof o.AuthError?new i("AUTH_FAILED",`Open-platform authentication failed: ${e.message}`):e instanceof Error?e:Error(String(e))}})}(e.authOptions));if(!p||0!==p.code){let e=(null==p?void 0:p.code)===void 0?"unknown":String(p.code);if((null==p?void 0:p.code)===0x2fb1793)throw new i("APP_ROLE_PERMISSION_REQUIRED",`真机调试授权失败:当前账号没有工程所配置智能服务的角色权限。
2
2
  工程 AppKey:${u.appKey}
3
3
  请先检查本地工程的 app_key 是否正确,且不是 mock 或占位值;该 AppKey 应属于你有权限的智能服务。
4
4
  权限开通:进入豆包开发者平台 → 对应智能服务 → 成员管理,请应用管理员邀请你的账号并授予开发或调试权限。
@@ -6,12 +6,12 @@ import"node:module";import{__webpack_require__ as e}from"./rslib-runtime.js";imp
6
6
  工程 AppKey:${u.appKey}
7
7
  请先检查本地工程的 app_key 是否正确,且不是 mock 或占位值;该 AppKey 应属于你要调试的智能服务。
8
8
  权限配置:进入豆包开发者平台 → 对应智能服务 → 白名单配置,添加真机调试所需权限后重试。
9
- 错误码:${e}`);let t=(null==p?void 0:p.message)||"Failed to get debug ticket";throw Error(`${t} (code=${e}, appKey=${u.appKey}, baseApiUrl=${u.baseApiUrl})`)}let h=String((null==(d=p.data)?void 0:d.debug_token)||"").trim(),f=String((null==(l=p.data)?void 0:l.encrypted_debug_payload)||"").trim();if(!h||!f)throw Error("Debug ticket response is missing required fields");return{qrCodeValue:JSON.stringify({action:t.REAL_DEVICE_DEBUG_QR_ACTION,debug_token:h,encrypted_debug_payload:f}),debugToken:h,encryptedDebugPayload:f}})}},"../../../node_modules/.pnpm/dijkstrajs@1.0.3/node_modules/dijkstrajs/dijkstra.js"(e){var t={single_source_shortest_paths:function(e,n,r){var o,i,s,a,d,l,c,u={},p={};p[n]=0;var h=t.PriorityQueue.make();for(h.push(n,0);!h.empty();)for(s in i=(o=h.pop()).value,a=o.cost,d=e[i]||{})d.hasOwnProperty(s)&&(l=a+d[s],c=p[s],(void 0===p[s]||c>l)&&(p[s]=l,h.push(s,l),u[s]=i));if(void 0!==r&&void 0===p[r])throw Error(["Could not find a path from ",n," to ",r,"."].join(""));return u},extract_shortest_path_from_predecessor_list:function(e,t){for(var n=[],r=t;r;)n.push(r),e[r],r=e[r];return n.reverse(),n},find_path:function(e,n,r){var o=t.single_source_shortest_paths(e,n,r);return t.extract_shortest_path_from_predecessor_list(o,r)},PriorityQueue:{make:function(e){var n,r=t.PriorityQueue,o={};for(n in e=e||{},r)r.hasOwnProperty(n)&&(o[n]=r[n]);return o.queue=[],o.sorter=e.sorter||r.default_sorter,o},default_sorter:function(e,t){return e.cost-t.cost},push:function(e,t){this.queue.push({value:e,cost:t}),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return 0===this.queue.length}}};e.exports=t},"../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/bitmapper.js"(e,t,n){let r=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/interlace.js"),o=[function(){},function(e,t,n,r){if(r===t.length)throw Error("Ran out of data");let o=t[r];e[n]=o,e[n+1]=o,e[n+2]=o,e[n+3]=255},function(e,t,n,r){if(r+1>=t.length)throw Error("Ran out of data");let o=t[r];e[n]=o,e[n+1]=o,e[n+2]=o,e[n+3]=t[r+1]},function(e,t,n,r){if(r+2>=t.length)throw Error("Ran out of data");e[n]=t[r],e[n+1]=t[r+1],e[n+2]=t[r+2],e[n+3]=255},function(e,t,n,r){if(r+3>=t.length)throw Error("Ran out of data");e[n]=t[r],e[n+1]=t[r+1],e[n+2]=t[r+2],e[n+3]=t[r+3]}],i=[function(){},function(e,t,n,r){let o=t[0];e[n]=o,e[n+1]=o,e[n+2]=o,e[n+3]=r},function(e,t,n){let r=t[0];e[n]=r,e[n+1]=r,e[n+2]=r,e[n+3]=t[1]},function(e,t,n,r){e[n]=t[0],e[n+1]=t[1],e[n+2]=t[2],e[n+3]=r},function(e,t,n){e[n]=t[0],e[n+1]=t[1],e[n+2]=t[2],e[n+3]=t[3]}];t.dataToBitMap=function(e,t){let n,s,a,d,l,c,u=t.width,p=t.height,h=t.depth,f=t.bpp,m=t.interlace;8!==h&&(n=[],s=0,a={get:function(t){for(;n.length<t;)!function(){let t,r,o,i;if(s===e.length)throw Error("Ran out of data");let a=e[s];switch(s++,h){default:throw Error("unrecognised depth");case 16:o=e[s],s++,n.push((a<<8)+o);break;case 4:o=15&a,i=a>>4,n.push(i,o);break;case 2:t=3&a,r=a>>2&3,o=a>>4&3,i=a>>6&3,n.push(i,o,r,t);break;case 1:t=a>>4&1,r=a>>5&1,o=a>>6&1,i=a>>7&1,n.push(i,o,r,t,a>>3&1,a>>2&1,a>>1&1,1&a)}}();let r=n.slice(0,t);return n=n.slice(t),r},resetAfterLine:function(){n.length=0},end:function(){if(s!==e.length)throw Error("extra data found")}}),d=h<=8?Buffer.alloc(u*p*4):new Uint16Array(u*p*4);let g=Math.pow(2,h)-1,_=0;if(m)l=r.getImagePasses(u,p),c=r.getInterlaceIterator(u,p);else{let e=0;c=function(){let t=e;return e+=4,t},l=[{width:u,height:p}]}for(let t=0;t<l.length;t++)8===h?_=function(e,t,n,r,i,s){let a=e.width,d=e.height,l=e.index;for(let e=0;e<d;e++)for(let d=0;d<a;d++){let a=n(d,e,l);o[r](t,i,a,s),s+=r}return s}(l[t],d,c,f,e,_):function(e,t,n,r,o,s){let a=e.width,d=e.height,l=e.index;for(let e=0;e<d;e++){for(let d=0;d<a;d++){let a=o.get(r),c=n(d,e,l);i[r](t,a,c,s)}o.resetAfterLine()}}(l[t],d,c,f,a,g);if(8===h){if(_!==e.length)throw Error("extra data found")}else a.end();return d}},"../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/bitpacker.js"(e,t,n){let r=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/constants.js");e.exports=function(e,t,n,o){let i=-1!==[r.COLORTYPE_COLOR_ALPHA,r.COLORTYPE_ALPHA].indexOf(o.colorType);if(o.colorType===o.inputColorType){let t,n=(new DataView(t=new ArrayBuffer(2)).setInt16(0,256,!0),256!==new Int16Array(t)[0]);if(8===o.bitDepth||16===o.bitDepth&&n)return e}let s=16!==o.bitDepth?e:new Uint16Array(e.buffer),a=255,d=r.COLORTYPE_TO_BPP_MAP[o.inputColorType];4!==d||o.inputHasAlpha||(d=3);let l=r.COLORTYPE_TO_BPP_MAP[o.colorType];16===o.bitDepth&&(a=65535,l*=2);let c=Buffer.alloc(t*n*l),u=0,p=0,h=o.bgColor||{};void 0===h.red&&(h.red=a),void 0===h.green&&(h.green=a),void 0===h.blue&&(h.blue=a);for(let e=0;e<n;e++)for(let e=0;e<t;e++){let e=function(){let e,t,n,d=a;switch(o.inputColorType){case r.COLORTYPE_COLOR_ALPHA:d=s[u+3],e=s[u],t=s[u+1],n=s[u+2];break;case r.COLORTYPE_COLOR:e=s[u],t=s[u+1],n=s[u+2];break;case r.COLORTYPE_ALPHA:d=s[u+1],t=e=s[u],n=e;break;case r.COLORTYPE_GRAYSCALE:t=e=s[u],n=e;break;default:throw Error("input color type:"+o.inputColorType+" is not supported at present")}return o.inputHasAlpha&&!i&&(d/=a,e=Math.min(Math.max(Math.round((1-d)*h.red+d*e),0),a),t=Math.min(Math.max(Math.round((1-d)*h.green+d*t),0),a),n=Math.min(Math.max(Math.round((1-d)*h.blue+d*n),0),a)),{red:e,green:t,blue:n,alpha:d}}();switch(o.colorType){case r.COLORTYPE_COLOR_ALPHA:case r.COLORTYPE_COLOR:8===o.bitDepth?(c[p]=e.red,c[p+1]=e.green,c[p+2]=e.blue,i&&(c[p+3]=e.alpha)):(c.writeUInt16BE(e.red,p),c.writeUInt16BE(e.green,p+2),c.writeUInt16BE(e.blue,p+4),i&&c.writeUInt16BE(e.alpha,p+6));break;case r.COLORTYPE_ALPHA:case r.COLORTYPE_GRAYSCALE:{let t=(e.red+e.green+e.blue)/3;8===o.bitDepth?(c[p]=t,i&&(c[p+1]=e.alpha)):(c.writeUInt16BE(t,p),i&&c.writeUInt16BE(e.alpha,p+2));break}default:throw Error("unrecognised color Type "+o.colorType)}u+=d,p+=l}return c}},"../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/chunkstream.js"(e,t,n){let r=n("util"),o=n("stream"),i=e.exports=function(){o.call(this),this._buffers=[],this._buffered=0,this._reads=[],this._paused=!1,this._encoding="utf8",this.writable=!0};r.inherits(i,o),i.prototype.read=function(e,t){this._reads.push({length:Math.abs(e),allowLess:e<0,func:t}),process.nextTick((function(){this._process(),this._paused&&this._reads&&this._reads.length>0&&(this._paused=!1,this.emit("drain"))}).bind(this))},i.prototype.write=function(e,t){let n;return this.writable?(n=Buffer.isBuffer(e)?e:Buffer.from(e,t||this._encoding),this._buffers.push(n),this._buffered+=n.length,this._process(),this._reads&&0===this._reads.length&&(this._paused=!0),this.writable&&!this._paused):(this.emit("error",Error("Stream not writable")),!1)},i.prototype.end=function(e,t){e&&this.write(e,t),this.writable=!1,this._buffers&&(0===this._buffers.length?this._end():(this._buffers.push(null),this._process()))},i.prototype.destroySoon=i.prototype.end,i.prototype._end=function(){this._reads.length>0&&this.emit("error",Error("Unexpected end of input")),this.destroy()},i.prototype.destroy=function(){this._buffers&&(this.writable=!1,this._reads=null,this._buffers=null,this.emit("close"))},i.prototype._processReadAllowingLess=function(e){this._reads.shift();let t=this._buffers[0];t.length>e.length?(this._buffered-=e.length,this._buffers[0]=t.slice(e.length),e.func.call(this,t.slice(0,e.length))):(this._buffered-=t.length,this._buffers.shift(),e.func.call(this,t))},i.prototype._processRead=function(e){this._reads.shift();let t=0,n=0,r=Buffer.alloc(e.length);for(;t<e.length;){let o=this._buffers[n++],i=Math.min(o.length,e.length-t);o.copy(r,t,0,i),t+=i,i!==o.length&&(this._buffers[--n]=o.slice(i))}n>0&&this._buffers.splice(0,n),this._buffered-=e.length,e.func.call(this,r)},i.prototype._process=function(){try{for(;this._buffered>0&&this._reads&&this._reads.length>0;){let e=this._reads[0];if(e.allowLess)this._processReadAllowingLess(e);else if(this._buffered>=e.length)this._processRead(e);else break}this._buffers&&!this.writable&&this._end()}catch(e){this.emit("error",e)}}},"../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/constants.js"(e){e.exports={PNG_SIGNATURE:[137,80,78,71,13,10,26,10],TYPE_IHDR:0x49484452,TYPE_IEND:0x49454e44,TYPE_IDAT:0x49444154,TYPE_PLTE:0x504c5445,TYPE_tRNS:0x74524e53,TYPE_gAMA:0x67414d41,COLORTYPE_GRAYSCALE:0,COLORTYPE_PALETTE:1,COLORTYPE_COLOR:2,COLORTYPE_ALPHA:4,COLORTYPE_PALETTE_COLOR:3,COLORTYPE_COLOR_ALPHA:6,COLORTYPE_TO_BPP_MAP:{0:1,2:3,3:1,4:2,6:4},GAMMA_DIVISION:1e5}},"../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/crc.js"(e){let t=[];for(let e=0;e<256;e++){let n=e;for(let e=0;e<8;e++)1&n?n=0xedb88320^n>>>1:n>>>=1;t[e]=n}let n=e.exports=function(){this._crc=-1};n.prototype.write=function(e){for(let n=0;n<e.length;n++)this._crc=t[(this._crc^e[n])&255]^this._crc>>>8;return!0},n.prototype.crc32=function(){return -1^this._crc},n.crc32=function(e){let n=-1;for(let r=0;r<e.length;r++)n=t[(n^e[r])&255]^n>>>8;return -1^n}},"../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/filter-pack.js"(e,t,n){let r=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/paeth-predictor.js"),o={0:function(e,t,n,r,o){for(let i=0;i<n;i++)r[o+i]=e[t+i]},1:function(e,t,n,r,o,i){for(let s=0;s<n;s++){let n=s>=i?e[t+s-i]:0,a=e[t+s]-n;r[o+s]=a}},2:function(e,t,n,r,o){for(let i=0;i<n;i++){let s=t>0?e[t+i-n]:0,a=e[t+i]-s;r[o+i]=a}},3:function(e,t,n,r,o,i){for(let s=0;s<n;s++){let a=s>=i?e[t+s-i]:0,d=t>0?e[t+s-n]:0,l=e[t+s]-(a+d>>1);r[o+s]=l}},4:function(e,t,n,o,i,s){for(let a=0;a<n;a++){let d=a>=s?e[t+a-s]:0,l=t>0?e[t+a-n]:0,c=t>0&&a>=s?e[t+a-(n+s)]:0,u=e[t+a]-r(d,l,c);o[i+a]=u}}},i={0:function(e,t,n){let r=0,o=t+n;for(let n=t;n<o;n++)r+=Math.abs(e[n]);return r},1:function(e,t,n,r){let o=0;for(let i=0;i<n;i++){let n=i>=r?e[t+i-r]:0;o+=Math.abs(e[t+i]-n)}return o},2:function(e,t,n){let r=0,o=t+n;for(let i=t;i<o;i++){let o=t>0?e[i-n]:0;r+=Math.abs(e[i]-o)}return r},3:function(e,t,n,r){let o=0;for(let i=0;i<n;i++){let s=i>=r?e[t+i-r]:0,a=t>0?e[t+i-n]:0;o+=Math.abs(e[t+i]-(s+a>>1))}return o},4:function(e,t,n,o){let i=0;for(let s=0;s<n;s++){let a=s>=o?e[t+s-o]:0,d=t>0?e[t+s-n]:0,l=t>0&&s>=o?e[t+s-(n+o)]:0;i+=Math.abs(e[t+s]-r(a,d,l))}return i}};e.exports=function(e,t,n,r,s){let a;if("filterType"in r&&-1!==r.filterType)if("number"==typeof r.filterType)a=[r.filterType];else throw Error("unrecognised filter types");else a=[0,1,2,3,4];16===r.bitDepth&&(s*=2);let d=t*s,l=0,c=0,u=Buffer.alloc((d+1)*n),p=a[0];for(let t=0;t<n;t++){if(a.length>1){let t=1/0;for(let n=0;n<a.length;n++){let r=i[a[n]](e,c,d,s);r<t&&(p=a[n],t=r)}}u[l]=p,l++,o[p](e,c,d,u,l,s),l+=d,c+=d}return u}},"../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/filter-parse-async.js"(e,t,n){let r=n("util"),o=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/chunkstream.js"),i=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/filter-parse.js"),s=e.exports=function(e){o.call(this);let t=[],n=this;this._filter=new i(e,{read:this.read.bind(this),write:function(e){t.push(e)},complete:function(){n.emit("complete",Buffer.concat(t))}}),this._filter.start()};r.inherits(s,o)},"../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/filter-parse-sync.js"(e,t,n){let r=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/sync-reader.js"),o=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/filter-parse.js");t.process=function(e,t){let n=[],i=new r(e);return new o(t,{read:i.read.bind(i),write:function(e){n.push(e)},complete:function(){}}).start(),i.process(),Buffer.concat(n)}},"../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/filter-parse.js"(e,t,n){let r=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/interlace.js"),o=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/paeth-predictor.js");function i(e,t,n){let r=e*t;return 8!==n&&(r=Math.ceil(r/(8/n))),r}let s=e.exports=function(e,t){let n=e.width,o=e.height,s=e.interlace,a=e.bpp,d=e.depth;if(this.read=t.read,this.write=t.write,this.complete=t.complete,this._imageIndex=0,this._images=[],s){let e=r.getImagePasses(n,o);for(let t=0;t<e.length;t++)this._images.push({byteWidth:i(e[t].width,a,d),height:e[t].height,lineIndex:0})}else this._images.push({byteWidth:i(n,a,d),height:o,lineIndex:0});8===d?this._xComparison=a:16===d?this._xComparison=2*a:this._xComparison=1};s.prototype.start=function(){this.read(this._images[this._imageIndex].byteWidth+1,this._reverseFilterLine.bind(this))},s.prototype._unFilterType1=function(e,t,n){let r=this._xComparison,o=r-1;for(let i=0;i<n;i++){let n=e[1+i],s=i>o?t[i-r]:0;t[i]=n+s}},s.prototype._unFilterType2=function(e,t,n){let r=this._lastLine;for(let o=0;o<n;o++){let n=e[1+o],i=r?r[o]:0;t[o]=n+i}},s.prototype._unFilterType3=function(e,t,n){let r=this._xComparison,o=r-1,i=this._lastLine;for(let s=0;s<n;s++){let n=e[1+s],a=i?i[s]:0,d=Math.floor(((s>o?t[s-r]:0)+a)/2);t[s]=n+d}},s.prototype._unFilterType4=function(e,t,n){let r=this._xComparison,i=r-1,s=this._lastLine;for(let a=0;a<n;a++){let n=e[1+a],d=s?s[a]:0,l=o(a>i?t[a-r]:0,d,a>i&&s?s[a-r]:0);t[a]=n+l}},s.prototype._reverseFilterLine=function(e){let t,n=e[0],r=this._images[this._imageIndex],o=r.byteWidth;if(0===n)t=e.slice(1,o+1);else switch(t=Buffer.alloc(o),n){case 1:this._unFilterType1(e,t,o);break;case 2:this._unFilterType2(e,t,o);break;case 3:this._unFilterType3(e,t,o);break;case 4:this._unFilterType4(e,t,o);break;default:throw Error("Unrecognised filter type - "+n)}this.write(t),r.lineIndex++,r.lineIndex>=r.height?(this._lastLine=null,this._imageIndex++,r=this._images[this._imageIndex]):this._lastLine=t,r?this.read(r.byteWidth+1,this._reverseFilterLine.bind(this)):(this._lastLine=null,this.complete())}},"../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/format-normaliser.js"(e){e.exports=function(e,t){let n=t.depth,r=t.width,o=t.height,i=t.colorType,s=t.transColor,a=t.palette,d=e;return 3===i?!function(e,t,n,r,o){let i=0;for(let s=0;s<r;s++)for(let r=0;r<n;r++){let n=o[e[i]];if(!n)throw Error("index "+e[i]+" not in palette");for(let e=0;e<4;e++)t[i+e]=n[e];i+=4}}(e,d,r,o,a):(s&&function(e,t,n,r,o){let i=0;for(let s=0;s<r;s++)for(let r=0;r<n;r++){let n=!1;if(1===o.length?o[0]===e[i]&&(n=!0):o[0]===e[i]&&o[1]===e[i+1]&&o[2]===e[i+2]&&(n=!0),n)for(let e=0;e<4;e++)t[i+e]=0;i+=4}}(e,d,r,o,s),8!==n&&(16===n&&(d=Buffer.alloc(r*o*4)),!function(e,t,n,r,o){let i=Math.pow(2,o)-1,s=0;for(let o=0;o<r;o++)for(let r=0;r<n;r++){for(let n=0;n<4;n++)t[s+n]=Math.floor(255*e[s+n]/i+.5);s+=4}}(e,d,r,o,n))),d}},"../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/interlace.js"(e,t){let n=[{x:[0],y:[0]},{x:[4],y:[0]},{x:[0,4],y:[4]},{x:[2,6],y:[0,4]},{x:[0,2,4,6],y:[2,6]},{x:[1,3,5,7],y:[0,2,4,6]},{x:[0,1,2,3,4,5,6,7],y:[1,3,5,7]}];t.getImagePasses=function(e,t){let r=[],o=e%8,i=t%8,s=(e-o)/8,a=(t-i)/8;for(let e=0;e<n.length;e++){let t=n[e],d=s*t.x.length,l=a*t.y.length;for(let e=0;e<t.x.length;e++)if(t.x[e]<o)d++;else break;for(let e=0;e<t.y.length;e++)if(t.y[e]<i)l++;else break;d>0&&l>0&&r.push({width:d,height:l,index:e})}return r},t.getInterlaceIterator=function(e){return function(t,r,o){let i=t%n[o].x.length,s=(t-i)/n[o].x.length*8+n[o].x[i],a=r%n[o].y.length;return 4*s+((r-a)/n[o].y.length*8+n[o].y[a])*e*4}}},"../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/packer-async.js"(e,t,n){let r=n("util"),o=n("stream"),i=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/constants.js"),s=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/packer.js"),a=e.exports=function(e){o.call(this),this._packer=new s(e||{}),this._deflate=this._packer.createDeflate(),this.readable=!0};r.inherits(a,o),a.prototype.pack=function(e,t,n,r){this.emit("data",Buffer.from(i.PNG_SIGNATURE)),this.emit("data",this._packer.packIHDR(t,n)),r&&this.emit("data",this._packer.packGAMA(r));let o=this._packer.filterData(e,t,n);this._deflate.on("error",this.emit.bind(this,"error")),this._deflate.on("data",(function(e){this.emit("data",this._packer.packIDAT(e))}).bind(this)),this._deflate.on("end",(function(){this.emit("data",this._packer.packIEND()),this.emit("end")}).bind(this)),this._deflate.end(o)}},"../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/packer-sync.js"(e,t,n){let r=!0,o=n("zlib");o.deflateSync||(r=!1);let i=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/constants.js"),s=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/packer.js");e.exports=function(e,t){if(!r)throw Error("To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0");let n=new s(t||{}),a=[];a.push(Buffer.from(i.PNG_SIGNATURE)),a.push(n.packIHDR(e.width,e.height)),e.gamma&&a.push(n.packGAMA(e.gamma));let d=n.filterData(e.data,e.width,e.height),l=o.deflateSync(d,n.getDeflateOptions());if(d=null,!l||!l.length)throw Error("bad png - invalid compressed data response");return a.push(n.packIDAT(l)),a.push(n.packIEND()),Buffer.concat(a)}},"../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/packer.js"(e,t,n){let r=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/constants.js"),o=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/crc.js"),i=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/bitpacker.js"),s=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/filter-pack.js"),a=n("zlib"),d=e.exports=function(e){if(this._options=e,e.deflateChunkSize=e.deflateChunkSize||32768,e.deflateLevel=null!=e.deflateLevel?e.deflateLevel:9,e.deflateStrategy=null!=e.deflateStrategy?e.deflateStrategy:3,e.inputHasAlpha=null==e.inputHasAlpha||e.inputHasAlpha,e.deflateFactory=e.deflateFactory||a.createDeflate,e.bitDepth=e.bitDepth||8,e.colorType="number"==typeof e.colorType?e.colorType:r.COLORTYPE_COLOR_ALPHA,e.inputColorType="number"==typeof e.inputColorType?e.inputColorType:r.COLORTYPE_COLOR_ALPHA,-1===[r.COLORTYPE_GRAYSCALE,r.COLORTYPE_COLOR,r.COLORTYPE_COLOR_ALPHA,r.COLORTYPE_ALPHA].indexOf(e.colorType))throw Error("option color type:"+e.colorType+" is not supported at present");if(-1===[r.COLORTYPE_GRAYSCALE,r.COLORTYPE_COLOR,r.COLORTYPE_COLOR_ALPHA,r.COLORTYPE_ALPHA].indexOf(e.inputColorType))throw Error("option input color type:"+e.inputColorType+" is not supported at present");if(8!==e.bitDepth&&16!==e.bitDepth)throw Error("option bit depth:"+e.bitDepth+" is not supported at present")};d.prototype.getDeflateOptions=function(){return{chunkSize:this._options.deflateChunkSize,level:this._options.deflateLevel,strategy:this._options.deflateStrategy}},d.prototype.createDeflate=function(){return this._options.deflateFactory(this.getDeflateOptions())},d.prototype.filterData=function(e,t,n){let o=i(e,t,n,this._options),a=r.COLORTYPE_TO_BPP_MAP[this._options.colorType];return s(o,t,n,this._options,a)},d.prototype._packChunk=function(e,t){let n=t?t.length:0,r=Buffer.alloc(n+12);return r.writeUInt32BE(n,0),r.writeUInt32BE(e,4),t&&t.copy(r,8),r.writeInt32BE(o.crc32(r.slice(4,r.length-4)),r.length-4),r},d.prototype.packGAMA=function(e){let t=Buffer.alloc(4);return t.writeUInt32BE(Math.floor(e*r.GAMMA_DIVISION),0),this._packChunk(r.TYPE_gAMA,t)},d.prototype.packIHDR=function(e,t){let n=Buffer.alloc(13);return n.writeUInt32BE(e,0),n.writeUInt32BE(t,4),n[8]=this._options.bitDepth,n[9]=this._options.colorType,n[10]=0,n[11]=0,n[12]=0,this._packChunk(r.TYPE_IHDR,n)},d.prototype.packIDAT=function(e){return this._packChunk(r.TYPE_IDAT,e)},d.prototype.packIEND=function(){return this._packChunk(r.TYPE_IEND,null)}},"../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/paeth-predictor.js"(e){e.exports=function(e,t,n){let r=e+t-n,o=Math.abs(r-e),i=Math.abs(r-t),s=Math.abs(r-n);return o<=i&&o<=s?e:i<=s?t:n}},"../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/parser-async.js"(e,t,n){let r=n("util"),o=n("zlib"),i=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/chunkstream.js"),s=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/filter-parse-async.js"),a=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/parser.js"),d=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/bitmapper.js"),l=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/format-normaliser.js"),c=e.exports=function(e){i.call(this),this._parser=new a(e,{read:this.read.bind(this),error:this._handleError.bind(this),metadata:this._handleMetaData.bind(this),gamma:this.emit.bind(this,"gamma"),palette:this._handlePalette.bind(this),transColor:this._handleTransColor.bind(this),finished:this._finished.bind(this),inflateData:this._inflateData.bind(this),simpleTransparency:this._simpleTransparency.bind(this),headersFinished:this._headersFinished.bind(this)}),this._options=e,this.writable=!0,this._parser.start()};r.inherits(c,i),c.prototype._handleError=function(e){this.emit("error",e),this.writable=!1,this.destroy(),this._inflate&&this._inflate.destroy&&this._inflate.destroy(),this._filter&&(this._filter.destroy(),this._filter.on("error",function(){})),this.errord=!0},c.prototype._inflateData=function(e){if(!this._inflate)if(this._bitmapInfo.interlace)this._inflate=o.createInflate(),this._inflate.on("error",this.emit.bind(this,"error")),this._filter.on("complete",this._complete.bind(this)),this._inflate.pipe(this._filter);else{let e=((this._bitmapInfo.width*this._bitmapInfo.bpp*this._bitmapInfo.depth+7>>3)+1)*this._bitmapInfo.height,t=Math.max(e,o.Z_MIN_CHUNK);this._inflate=o.createInflate({chunkSize:t});let n=e,r=this.emit.bind(this,"error");this._inflate.on("error",function(e){n&&r(e)}),this._filter.on("complete",this._complete.bind(this));let i=this._filter.write.bind(this._filter);this._inflate.on("data",function(e){n&&(e.length>n&&(e=e.slice(0,n)),n-=e.length,i(e))}),this._inflate.on("end",this._filter.end.bind(this._filter))}this._inflate.write(e)},c.prototype._handleMetaData=function(e){this._metaData=e,this._bitmapInfo=Object.create(e),this._filter=new s(this._bitmapInfo)},c.prototype._handleTransColor=function(e){this._bitmapInfo.transColor=e},c.prototype._handlePalette=function(e){this._bitmapInfo.palette=e},c.prototype._simpleTransparency=function(){this._metaData.alpha=!0},c.prototype._headersFinished=function(){this.emit("metadata",this._metaData)},c.prototype._finished=function(){this.errord||(this._inflate?this._inflate.end():this.emit("error","No Inflate block"))},c.prototype._complete=function(e){let t;if(!this.errord){try{let n=d.dataToBitMap(e,this._bitmapInfo);t=l(n,this._bitmapInfo),n=null}catch(e){this._handleError(e);return}this.emit("parsed",t)}}},"../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/parser-sync.js"(e,t,n){let r=!0,o=n("zlib"),i=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/sync-inflate.js");o.deflateSync||(r=!1);let s=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/sync-reader.js"),a=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/filter-parse-sync.js"),d=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/parser.js"),l=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/bitmapper.js"),c=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/format-normaliser.js");e.exports=function(e,t){let n,u,p,h;if(!r)throw Error("To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0");let f=[],m=new s(e);if(new d(t,{read:m.read.bind(m),error:function(e){n=e},metadata:function(e){u=e},gamma:function(e){p=e},palette:function(e){u.palette=e},transColor:function(e){u.transColor=e},inflateData:function(e){f.push(e)},simpleTransparency:function(){u.alpha=!0}}).start(),m.process(),n)throw n;let g=Buffer.concat(f);if(f.length=0,u.interlace)h=o.inflateSync(g);else{let e=((u.width*u.bpp*u.depth+7>>3)+1)*u.height;h=i(g,{chunkSize:e,maxLength:e})}if(g=null,!h||!h.length)throw Error("bad png - invalid inflate data response");let _=a.process(h,u);g=null;let w=l.dataToBitMap(_,u);_=null;let y=c(w,u);return u.data=y,u.gamma=p||0,u}},"../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/parser.js"(e,t,n){let r=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/constants.js"),o=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/crc.js"),i=e.exports=function(e,t){this._options=e,e.checkCRC=!1!==e.checkCRC,this._hasIHDR=!1,this._hasIEND=!1,this._emittedHeadersFinished=!1,this._palette=[],this._colorType=0,this._chunks={},this._chunks[r.TYPE_IHDR]=this._handleIHDR.bind(this),this._chunks[r.TYPE_IEND]=this._handleIEND.bind(this),this._chunks[r.TYPE_IDAT]=this._handleIDAT.bind(this),this._chunks[r.TYPE_PLTE]=this._handlePLTE.bind(this),this._chunks[r.TYPE_tRNS]=this._handleTRNS.bind(this),this._chunks[r.TYPE_gAMA]=this._handleGAMA.bind(this),this.read=t.read,this.error=t.error,this.metadata=t.metadata,this.gamma=t.gamma,this.transColor=t.transColor,this.palette=t.palette,this.parsed=t.parsed,this.inflateData=t.inflateData,this.finished=t.finished,this.simpleTransparency=t.simpleTransparency,this.headersFinished=t.headersFinished||function(){}};i.prototype.start=function(){this.read(r.PNG_SIGNATURE.length,this._parseSignature.bind(this))},i.prototype._parseSignature=function(e){let t=r.PNG_SIGNATURE;for(let n=0;n<t.length;n++)if(e[n]!==t[n])return void this.error(Error("Invalid file signature"));this.read(8,this._parseChunkBegin.bind(this))},i.prototype._parseChunkBegin=function(e){let t=e.readUInt32BE(0),n=e.readUInt32BE(4),i="";for(let t=4;t<8;t++)i+=String.fromCharCode(e[t]);let s=!!(32&e[4]);return this._hasIHDR||n===r.TYPE_IHDR?(this._crc=new o,this._crc.write(Buffer.from(i)),this._chunks[n])?this._chunks[n](t):s?void this.read(t+4,this._skipChunk.bind(this)):void this.error(Error("Unsupported critical chunk type "+i)):void this.error(Error("Expected IHDR on beggining"))},i.prototype._skipChunk=function(){this.read(8,this._parseChunkBegin.bind(this))},i.prototype._handleChunkEnd=function(){this.read(4,this._parseChunkEnd.bind(this))},i.prototype._parseChunkEnd=function(e){let t=e.readInt32BE(0),n=this._crc.crc32();this._options.checkCRC&&n!==t?this.error(Error("Crc error - "+t+" - "+n)):this._hasIEND||this.read(8,this._parseChunkBegin.bind(this))},i.prototype._handleIHDR=function(e){this.read(e,this._parseIHDR.bind(this))},i.prototype._parseIHDR=function(e){this._crc.write(e);let t=e.readUInt32BE(0),n=e.readUInt32BE(4),o=e[8],i=e[9],s=e[10],a=e[11],d=e[12];if(8!==o&&4!==o&&2!==o&&1!==o&&16!==o)return void this.error(Error("Unsupported bit depth "+o));if(!(i in r.COLORTYPE_TO_BPP_MAP))return void this.error(Error("Unsupported color type"));if(0!==s)return void this.error(Error("Unsupported compression method"));if(0!==a)return void this.error(Error("Unsupported filter method"));if(0!==d&&1!==d)return void this.error(Error("Unsupported interlace method"));this._colorType=i;let l=r.COLORTYPE_TO_BPP_MAP[this._colorType];this._hasIHDR=!0,this.metadata({width:t,height:n,depth:o,interlace:!!d,palette:!!(i&r.COLORTYPE_PALETTE),color:!!(i&r.COLORTYPE_COLOR),alpha:!!(i&r.COLORTYPE_ALPHA),bpp:l,colorType:i}),this._handleChunkEnd()},i.prototype._handlePLTE=function(e){this.read(e,this._parsePLTE.bind(this))},i.prototype._parsePLTE=function(e){this._crc.write(e);let t=Math.floor(e.length/3);for(let n=0;n<t;n++)this._palette.push([e[3*n],e[3*n+1],e[3*n+2],255]);this.palette(this._palette),this._handleChunkEnd()},i.prototype._handleTRNS=function(e){this.simpleTransparency(),this.read(e,this._parseTRNS.bind(this))},i.prototype._parseTRNS=function(e){if(this._crc.write(e),this._colorType===r.COLORTYPE_PALETTE_COLOR){if(0===this._palette.length)return void this.error(Error("Transparency chunk must be after palette"));if(e.length>this._palette.length)return void this.error(Error("More transparent colors than palette size"));for(let t=0;t<e.length;t++)this._palette[t][3]=e[t];this.palette(this._palette)}this._colorType===r.COLORTYPE_GRAYSCALE&&this.transColor([e.readUInt16BE(0)]),this._colorType===r.COLORTYPE_COLOR&&this.transColor([e.readUInt16BE(0),e.readUInt16BE(2),e.readUInt16BE(4)]),this._handleChunkEnd()},i.prototype._handleGAMA=function(e){this.read(e,this._parseGAMA.bind(this))},i.prototype._parseGAMA=function(e){this._crc.write(e),this.gamma(e.readUInt32BE(0)/r.GAMMA_DIVISION),this._handleChunkEnd()},i.prototype._handleIDAT=function(e){this._emittedHeadersFinished||(this._emittedHeadersFinished=!0,this.headersFinished()),this.read(-e,this._parseIDAT.bind(this,e))},i.prototype._parseIDAT=function(e,t){if(this._crc.write(t),this._colorType===r.COLORTYPE_PALETTE_COLOR&&0===this._palette.length)throw Error("Expected palette not found");this.inflateData(t);let n=e-t.length;n>0?this._handleIDAT(n):this._handleChunkEnd()},i.prototype._handleIEND=function(e){this.read(e,this._parseIEND.bind(this))},i.prototype._parseIEND=function(e){this._crc.write(e),this._hasIEND=!0,this._handleChunkEnd(),this.finished&&this.finished()}},"../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/png-sync.js"(e,t,n){let r=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/parser-sync.js"),o=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/packer-sync.js");t.read=function(e,t){return r(e,t||{})},t.write=function(e,t){return o(e,t)}},"../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/png.js"(e,t,n){let r=n("util"),o=n("stream"),i=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/parser-async.js"),s=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/packer-async.js"),a=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/png-sync.js"),d=t.O=function(e){o.call(this),e=e||{},this.width=0|e.width,this.height=0|e.height,this.data=this.width>0&&this.height>0?Buffer.alloc(4*this.width*this.height):null,e.fill&&this.data&&this.data.fill(0),this.gamma=0,this.readable=this.writable=!0,this._parser=new i(e),this._parser.on("error",this.emit.bind(this,"error")),this._parser.on("close",this._handleClose.bind(this)),this._parser.on("metadata",this._metadata.bind(this)),this._parser.on("gamma",this._gamma.bind(this)),this._parser.on("parsed",(function(e){this.data=e,this.emit("parsed",e)}).bind(this)),this._packer=new s(e),this._packer.on("data",this.emit.bind(this,"data")),this._packer.on("end",this.emit.bind(this,"end")),this._parser.on("close",this._handleClose.bind(this)),this._packer.on("error",this.emit.bind(this,"error"))};r.inherits(d,o),d.sync=a,d.prototype.pack=function(){return this.data&&this.data.length?process.nextTick((function(){this._packer.pack(this.data,this.width,this.height,this.gamma)}).bind(this)):this.emit("error","No data provided"),this},d.prototype.parse=function(e,t){if(t){let e,n;e=(function(e){this.removeListener("error",n),this.data=e,t(null,this)}).bind(this),n=(function(n){this.removeListener("parsed",e),t(n,null)}).bind(this),this.once("parsed",e),this.once("error",n)}return this.end(e),this},d.prototype.write=function(e){return this._parser.write(e),!0},d.prototype.end=function(e){this._parser.end(e)},d.prototype._metadata=function(e){this.width=e.width,this.height=e.height,this.emit("metadata",e)},d.prototype._gamma=function(e){this.gamma=e},d.prototype._handleClose=function(){this._parser.writable||this._packer.readable||this.emit("close")},d.bitblt=function(e,t,n,r,o,i,s,a){if(r|=0,o|=0,i|=0,s|=0,a|=0,(n|=0)>e.width||r>e.height||n+o>e.width||r+i>e.height)throw Error("bitblt reading outside image");if(s>t.width||a>t.height||s+o>t.width||a+i>t.height)throw Error("bitblt writing outside image");for(let d=0;d<i;d++)e.data.copy(t.data,(a+d)*t.width+s<<2,(r+d)*e.width+n<<2,(r+d)*e.width+n+o<<2)},d.prototype.bitblt=function(e,t,n,r,o,i,s){return d.bitblt(this,e,t,n,r,o,i,s),this},d.adjustGamma=function(e){if(e.gamma){for(let t=0;t<e.height;t++)for(let n=0;n<e.width;n++){let r=e.width*t+n<<2;for(let t=0;t<3;t++){let n=e.data[r+t]/255;n=Math.pow(n,1/2.2/e.gamma),e.data[r+t]=Math.round(255*n)}}e.gamma=0}},d.prototype.adjustGamma=function(){d.adjustGamma(this)}},"../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/sync-inflate.js"(e,t,n){let r=n("assert").ok,o=n("zlib"),i=n("util"),s=n("buffer").kMaxLength;function a(e){if(!(this instanceof a))return new a(e);e&&e.chunkSize<o.Z_MIN_CHUNK&&(e.chunkSize=o.Z_MIN_CHUNK),o.Inflate.call(this,e),this._offset=void 0===this._offset?this._outOffset:this._offset,this._buffer=this._buffer||this._outBuffer,e&&null!=e.maxLength&&(this._maxLength=e.maxLength)}function d(e,t){t&&process.nextTick(t),e._handle&&(e._handle.close(),e._handle=null)}function l(e,t){var n=new a(t),r=e;if("string"==typeof r&&(r=Buffer.from(r)),!(r instanceof Buffer))throw TypeError("Not a string or buffer");let i=n._finishFlushFlag;return null==i&&(i=o.Z_FINISH),n._processChunk(r,i)}a.prototype._processChunk=function(e,t,n){let i,a;if("function"==typeof n)return o.Inflate._processChunk.call(this,e,t,n);let l=this,c=e&&e.length,u=this._chunkSize-this._offset,p=this._maxLength,h=0,f=[],m=0;this.on("error",function(e){i=e}),r(this._handle,"zlib binding closed");do a=(a=this._handle.writeSync(t,e,h,c,this._buffer,this._offset,u))||this._writeState;while(!this._hadError&&function(e,t){if(l._hadError)return;let n=u-t;if(r(n>=0,"have should not go down"),n>0){let e=l._buffer.slice(l._offset,l._offset+n);if(l._offset+=n,e.length>p&&(e=e.slice(0,p)),f.push(e),m+=e.length,0==(p-=e.length))return!1}return(0===t||l._offset>=l._chunkSize)&&(u=l._chunkSize,l._offset=0,l._buffer=Buffer.allocUnsafe(l._chunkSize)),0===t&&(h+=c-e,c=e,!0)}(a[0],a[1]));if(this._hadError)throw i;if(m>=s)throw d(this),RangeError("Cannot create final Buffer. It would be larger than 0x"+s.toString(16)+" bytes");let g=Buffer.concat(f,m);return d(this),g},i.inherits(a,o.Inflate),e.exports=t=l,t.Inflate=a,t.createInflate=function(e){return new a(e)},t.inflateSync=l},"../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/sync-reader.js"(e){let t=e.exports=function(e){this._buffer=e,this._reads=[]};t.prototype.read=function(e,t){this._reads.push({length:Math.abs(e),allowLess:e<0,func:t})},t.prototype.process=function(){for(;this._reads.length>0&&this._buffer.length;){let e=this._reads[0];if(this._buffer.length&&(this._buffer.length>=e.length||e.allowLess)){this._reads.shift();let t=this._buffer;this._buffer=t.slice(e.length),e.func.call(this,t.slice(0,e.length))}else break}return this._reads.length>0?Error("There are some read requests waitng on finished stream"):this._buffer.length>0?Error("unrecognised content at end of stream"):void 0}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/browser.js"(e,t,n){let r=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/can-promise.js"),o=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/qrcode.js"),i=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/canvas.js"),s=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/svg-tag.js");function a(e,t,n,i,s){let a=[].slice.call(arguments,1),d=a.length,l="function"==typeof a[d-1];if(!l&&!r())throw Error("Callback required as last argument");if(l){if(d<2)throw Error("Too few arguments provided");2===d?(s=n,n=t,t=i=void 0):3===d&&(t.getContext&&void 0===s?(s=i,i=void 0):(s=i,i=n,n=t,t=void 0))}else{if(d<1)throw Error("Too few arguments provided");return 1===d?(n=t,t=i=void 0):2!==d||t.getContext||(i=n,n=t,t=void 0),new Promise(function(r,s){try{let s=o.create(n,i);r(e(s,t,i))}catch(e){s(e)}})}try{let r=o.create(n,i);s(null,e(r,t,i))}catch(e){s(e)}}o.create,a.bind(null,i.render),a.bind(null,i.renderToDataURL),a.bind(null,function(e,t,n){return s.render(e,n)})},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/can-promise.js"(e){e.exports=function(){return"function"==typeof Promise&&Promise.prototype&&Promise.prototype.then}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/alignment-pattern.js"(e,t,n){let r=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/utils.js").getSymbolSize;t.getRowColCoords=function(e){if(1===e)return[];let t=Math.floor(e/7)+2,n=r(e),o=145===n?26:2*Math.ceil((n-13)/(2*t-2)),i=[n-7];for(let e=1;e<t-1;e++)i[e]=i[e-1]-o;return i.push(6),i.reverse()},t.getPositions=function(e){let n=[],r=t.getRowColCoords(e),o=r.length;for(let e=0;e<o;e++)for(let t=0;t<o;t++)(0!==e||0!==t)&&(0!==e||t!==o-1)&&(e!==o-1||0!==t)&&n.push([r[e],r[t]]);return n}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/alphanumeric-data.js"(e,t,n){let r=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/mode.js"),o=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"," ","$","%","*","+","-",".","/",":"];function i(e){this.mode=r.ALPHANUMERIC,this.data=e}i.getBitsLength=function(e){return 11*Math.floor(e/2)+e%2*6},i.prototype.getLength=function(){return this.data.length},i.prototype.getBitsLength=function(){return i.getBitsLength(this.data.length)},i.prototype.write=function(e){let t;for(t=0;t+2<=this.data.length;t+=2){let n=45*o.indexOf(this.data[t]);n+=o.indexOf(this.data[t+1]),e.put(n,11)}this.data.length%2&&e.put(o.indexOf(this.data[t]),6)},e.exports=i},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/bit-buffer.js"(e){function t(){this.buffer=[],this.length=0}t.prototype={get:function(e){let t=Math.floor(e/8);return(this.buffer[t]>>>7-e%8&1)==1},put:function(e,t){for(let n=0;n<t;n++)this.putBit((e>>>t-n-1&1)==1)},getLengthInBits:function(){return this.length},putBit:function(e){let t=Math.floor(this.length/8);this.buffer.length<=t&&this.buffer.push(0),e&&(this.buffer[t]|=128>>>this.length%8),this.length++}},e.exports=t},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/bit-matrix.js"(e){function t(e){if(!e||e<1)throw Error("BitMatrix size must be defined and greater than 0");this.size=e,this.data=new Uint8Array(e*e),this.reservedBit=new Uint8Array(e*e)}t.prototype.set=function(e,t,n,r){let o=e*this.size+t;this.data[o]=n,r&&(this.reservedBit[o]=!0)},t.prototype.get=function(e,t){return this.data[e*this.size+t]},t.prototype.xor=function(e,t,n){this.data[e*this.size+t]^=n},t.prototype.isReserved=function(e,t){return this.reservedBit[e*this.size+t]},e.exports=t},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/byte-data.js"(e,t,n){let r=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/mode.js");function o(e){this.mode=r.BYTE,"string"==typeof e?this.data=new TextEncoder().encode(e):this.data=new Uint8Array(e)}o.getBitsLength=function(e){return 8*e},o.prototype.getLength=function(){return this.data.length},o.prototype.getBitsLength=function(){return o.getBitsLength(this.data.length)},o.prototype.write=function(e){for(let t=0,n=this.data.length;t<n;t++)e.put(this.data[t],8)},e.exports=o},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/error-correction-code.js"(e,t,n){let r=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/error-correction-level.js"),o=[1,1,1,1,1,1,1,1,1,1,2,2,1,2,2,4,1,2,4,4,2,4,4,4,2,4,6,5,2,4,6,6,2,5,8,8,4,5,8,8,4,5,8,11,4,8,10,11,4,9,12,16,4,9,16,16,6,10,12,18,6,10,17,16,6,11,16,19,6,13,18,21,7,14,21,25,8,16,20,25,8,17,23,25,9,17,23,34,9,18,25,30,10,20,27,32,12,21,29,35,12,23,34,37,12,25,34,40,13,26,35,42,14,28,38,45,15,29,40,48,16,31,43,51,17,33,45,54,18,35,48,57,19,37,51,60,19,38,53,63,20,40,56,66,21,43,59,70,22,45,62,74,24,47,65,77,25,49,68,81],i=[7,10,13,17,10,16,22,28,15,26,36,44,20,36,52,64,26,48,72,88,36,64,96,112,40,72,108,130,48,88,132,156,60,110,160,192,72,130,192,224,80,150,224,264,96,176,260,308,104,198,288,352,120,216,320,384,132,240,360,432,144,280,408,480,168,308,448,532,180,338,504,588,196,364,546,650,224,416,600,700,224,442,644,750,252,476,690,816,270,504,750,900,300,560,810,960,312,588,870,1050,336,644,952,1110,360,700,1020,1200,390,728,1050,1260,420,784,1140,1350,450,812,1200,1440,480,868,1290,1530,510,924,1350,1620,540,980,1440,1710,570,1036,1530,1800,570,1064,1590,1890,600,1120,1680,1980,630,1204,1770,2100,660,1260,1860,2220,720,1316,1950,2310,750,1372,2040,2430];t.getBlocksCount=function(e,t){switch(t){case r.L:return o[(e-1)*4+0];case r.M:return o[(e-1)*4+1];case r.Q:return o[(e-1)*4+2];case r.H:return o[(e-1)*4+3];default:return}},t.getTotalCodewordsCount=function(e,t){switch(t){case r.L:return i[(e-1)*4+0];case r.M:return i[(e-1)*4+1];case r.Q:return i[(e-1)*4+2];case r.H:return i[(e-1)*4+3];default:return}}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/error-correction-level.js"(e,t){t.L={bit:1},t.M={bit:0},t.Q={bit:3},t.H={bit:2},t.isValid=function(e){return e&&void 0!==e.bit&&e.bit>=0&&e.bit<4},t.from=function(e,n){if(t.isValid(e))return e;try{if("string"!=typeof e)throw Error("Param is not a string");switch(e.toLowerCase()){case"l":case"low":return t.L;case"m":case"medium":return t.M;case"q":case"quartile":return t.Q;case"h":case"high":return t.H;default:throw Error("Unknown EC Level: "+e)}}catch(e){return n}}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/finder-pattern.js"(e,t,n){let r=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/utils.js").getSymbolSize;t.getPositions=function(e){let t=r(e);return[[0,0],[t-7,0],[0,t-7]]}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/format-info.js"(e,t,n){let r=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/utils.js"),o=r.getBCHDigit(1335);t.getEncodedBits=function(e,t){let n=e.bit<<3|t,i=n<<10;for(;r.getBCHDigit(i)-o>=0;)i^=1335<<r.getBCHDigit(i)-o;return(n<<10|i)^21522}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/galois-field.js"(e,t){let n=new Uint8Array(512),r=new Uint8Array(256),o=1;for(let e=0;e<255;e++)n[e]=o,r[o]=e,256&(o<<=1)&&(o^=285);for(let e=255;e<512;e++)n[e]=n[e-255];t.exp=function(e){return n[e]},t.mul=function(e,t){return 0===e||0===t?0:n[r[e]+r[t]]}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/kanji-data.js"(e,t,n){let r=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/mode.js"),o=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/utils.js");function i(e){this.mode=r.KANJI,this.data=e}i.getBitsLength=function(e){return 13*e},i.prototype.getLength=function(){return this.data.length},i.prototype.getBitsLength=function(){return i.getBitsLength(this.data.length)},i.prototype.write=function(e){let t;for(t=0;t<this.data.length;t++){let n=o.toSJIS(this.data[t]);if(n>=33088&&n<=40956)n-=33088;else if(n>=57408&&n<=60351)n-=49472;else throw Error("Invalid SJIS character: "+this.data[t]+"\nMake sure your charset is UTF-8");n=(n>>>8&255)*192+(255&n),e.put(n,13)}},e.exports=i},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/mask-pattern.js"(e,t){t.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};t.isValid=function(e){return null!=e&&""!==e&&!isNaN(e)&&e>=0&&e<=7},t.from=function(e){return t.isValid(e)?parseInt(e,10):void 0},t.getPenaltyN1=function(e){let t=e.size,n=0,r=0,o=0,i=null,s=null;for(let a=0;a<t;a++){r=o=0,i=s=null;for(let d=0;d<t;d++){let t=e.get(a,d);t===i?r++:(r>=5&&(n+=3+(r-5)),i=t,r=1),(t=e.get(d,a))===s?o++:(o>=5&&(n+=3+(o-5)),s=t,o=1)}r>=5&&(n+=3+(r-5)),o>=5&&(n+=3+(o-5))}return n},t.getPenaltyN2=function(e){let t=e.size,n=0;for(let r=0;r<t-1;r++)for(let o=0;o<t-1;o++){let t=e.get(r,o)+e.get(r,o+1)+e.get(r+1,o)+e.get(r+1,o+1);(4===t||0===t)&&n++}return 3*n},t.getPenaltyN3=function(e){let t=e.size,n=0,r=0,o=0;for(let i=0;i<t;i++){r=o=0;for(let s=0;s<t;s++)r=r<<1&2047|e.get(i,s),s>=10&&(1488===r||93===r)&&n++,o=o<<1&2047|e.get(s,i),s>=10&&(1488===o||93===o)&&n++}return 40*n},t.getPenaltyN4=function(e){let t=0,n=e.data.length;for(let r=0;r<n;r++)t+=e.data[r];return 10*Math.abs(Math.ceil(100*t/n/5)-10)},t.applyMask=function(e,n){let r=n.size;for(let o=0;o<r;o++)for(let i=0;i<r;i++)n.isReserved(i,o)||n.xor(i,o,function(e,n,r){switch(e){case t.Patterns.PATTERN000:return(n+r)%2==0;case t.Patterns.PATTERN001:return n%2==0;case t.Patterns.PATTERN010:return r%3==0;case t.Patterns.PATTERN011:return(n+r)%3==0;case t.Patterns.PATTERN100:return(Math.floor(n/2)+Math.floor(r/3))%2==0;case t.Patterns.PATTERN101:return n*r%2+n*r%3==0;case t.Patterns.PATTERN110:return(n*r%2+n*r%3)%2==0;case t.Patterns.PATTERN111:return(n*r%3+(n+r)%2)%2==0;default:throw Error("bad maskPattern:"+e)}}(e,i,o))},t.getBestMask=function(e,n){let r=Object.keys(t.Patterns).length,o=0,i=1/0;for(let s=0;s<r;s++){n(s),t.applyMask(s,e);let r=t.getPenaltyN1(e)+t.getPenaltyN2(e)+t.getPenaltyN3(e)+t.getPenaltyN4(e);t.applyMask(s,e),r<i&&(i=r,o=s)}return o}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/mode.js"(e,t,n){let r=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/version-check.js"),o=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/regex.js");t.NUMERIC={id:"Numeric",bit:1,ccBits:[10,12,14]},t.ALPHANUMERIC={id:"Alphanumeric",bit:2,ccBits:[9,11,13]},t.BYTE={id:"Byte",bit:4,ccBits:[8,16,16]},t.KANJI={id:"Kanji",bit:8,ccBits:[8,10,12]},t.MIXED={bit:-1},t.getCharCountIndicator=function(e,t){if(!e.ccBits)throw Error("Invalid mode: "+e);if(!r.isValid(t))throw Error("Invalid version: "+t);return t>=1&&t<10?e.ccBits[0]:t<27?e.ccBits[1]:e.ccBits[2]},t.getBestModeForData=function(e){return o.testNumeric(e)?t.NUMERIC:o.testAlphanumeric(e)?t.ALPHANUMERIC:o.testKanji(e)?t.KANJI:t.BYTE},t.toString=function(e){if(e&&e.id)return e.id;throw Error("Invalid mode")},t.isValid=function(e){return e&&e.bit&&e.ccBits},t.from=function(e,n){if(t.isValid(e))return e;try{if("string"!=typeof e)throw Error("Param is not a string");switch(e.toLowerCase()){case"numeric":return t.NUMERIC;case"alphanumeric":return t.ALPHANUMERIC;case"kanji":return t.KANJI;case"byte":return t.BYTE;default:throw Error("Unknown mode: "+e)}}catch(e){return n}}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/numeric-data.js"(e,t,n){let r=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/mode.js");function o(e){this.mode=r.NUMERIC,this.data=e.toString()}o.getBitsLength=function(e){return 10*Math.floor(e/3)+(e%3?e%3*3+1:0)},o.prototype.getLength=function(){return this.data.length},o.prototype.getBitsLength=function(){return o.getBitsLength(this.data.length)},o.prototype.write=function(e){let t,n;for(t=0;t+3<=this.data.length;t+=3)n=parseInt(this.data.substr(t,3),10),e.put(n,10);let r=this.data.length-t;r>0&&(n=parseInt(this.data.substr(t),10),e.put(n,3*r+1))},e.exports=o},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/polynomial.js"(e,t,n){let r=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/galois-field.js");t.mul=function(e,t){let n=new Uint8Array(e.length+t.length-1);for(let o=0;o<e.length;o++)for(let i=0;i<t.length;i++)n[o+i]^=r.mul(e[o],t[i]);return n},t.mod=function(e,t){let n=new Uint8Array(e);for(;n.length-t.length>=0;){let e=n[0];for(let o=0;o<t.length;o++)n[o]^=r.mul(t[o],e);let o=0;for(;o<n.length&&0===n[o];)o++;n=n.slice(o)}return n},t.generateECPolynomial=function(e){let n=new Uint8Array([1]);for(let o=0;o<e;o++)n=t.mul(n,new Uint8Array([1,r.exp(o)]));return n}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/qrcode.js"(e,t,n){let r=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/utils.js"),o=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/error-correction-level.js"),i=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/bit-buffer.js"),s=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/bit-matrix.js"),a=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/alignment-pattern.js"),d=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/finder-pattern.js"),l=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/mask-pattern.js"),c=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/error-correction-code.js"),u=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/reed-solomon-encoder.js"),p=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/version.js"),h=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/format-info.js"),f=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/mode.js"),m=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/segments.js");function g(e,t,n){let r,o,i=e.size,s=h.getEncodedBits(t,n);for(r=0;r<15;r++)o=(s>>r&1)==1,r<6?e.set(r,8,o,!0):r<8?e.set(r+1,8,o,!0):e.set(i-15+r,8,o,!0),r<8?e.set(8,i-r-1,o,!0):r<9?e.set(8,15-r-1+1,o,!0):e.set(8,15-r-1,o,!0);e.set(i-8,8,1,!0)}t.create=function(e,t){let n,h;if(void 0===e||""===e)throw Error("No input text");let _=o.M;return void 0!==t&&(_=o.from(t.errorCorrectionLevel,o.M),n=p.from(t.version),h=l.from(t.maskPattern),t.toSJISFunc&&r.setToSJISFunction(t.toSJISFunc)),function(e,t,n,o){let h;if(Array.isArray(e))h=m.fromArray(e);else if("string"==typeof e){let r=t;if(!r){let t=m.rawSplit(e);r=p.getBestVersionForData(t,n)}h=m.fromString(e,r||40)}else throw Error("Invalid data");let _=p.getBestVersionForData(h,n);if(!_)throw Error("The amount of data is too big to be stored in a QR Code");if(t){if(t<_)throw Error("\nThe chosen QR Code version cannot contain this amount of data.\nMinimum version required to store current data is: "+_+".\n")}else t=_;let w=function(e,t,n){let o=new i;n.forEach(function(t){o.put(t.mode.bit,4),o.put(t.getLength(),f.getCharCountIndicator(t.mode,e)),t.write(o)});let s=(r.getSymbolTotalCodewords(e)-c.getTotalCodewordsCount(e,t))*8;for(o.getLengthInBits()+4<=s&&o.put(0,4);o.getLengthInBits()%8!=0;)o.putBit(0);let a=(s-o.getLengthInBits())/8;for(let e=0;e<a;e++)o.put(e%2?17:236,8);return function(e,t,n){let o,i,s=r.getSymbolTotalCodewords(t),a=s-c.getTotalCodewordsCount(t,n),d=c.getBlocksCount(t,n),l=s%d,p=d-l,h=Math.floor(s/d),f=Math.floor(a/d),m=f+1,g=h-f,_=new u(g),w=0,y=Array(d),b=Array(d),v=0,E=new Uint8Array(e.buffer);for(let e=0;e<d;e++){let t=e<p?f:m;y[e]=E.slice(w,w+t),b[e]=_.encode(y[e]),w+=t,v=Math.max(v,t)}let I=new Uint8Array(s),A=0;for(o=0;o<v;o++)for(i=0;i<d;i++)o<y[i].length&&(I[A++]=y[i][o]);for(o=0;o<g;o++)for(i=0;i<d;i++)I[A++]=b[i][o];return I}(o,e,t)}(t,n,h),y=new s(r.getSymbolSize(t));!function(e,t){let n=e.size,r=d.getPositions(t);for(let t=0;t<r.length;t++){let o=r[t][0],i=r[t][1];for(let t=-1;t<=7;t++)if(!(o+t<=-1)&&!(n<=o+t))for(let r=-1;r<=7;r++)i+r<=-1||n<=i+r||(t>=0&&t<=6&&(0===r||6===r)||r>=0&&r<=6&&(0===t||6===t)||t>=2&&t<=4&&r>=2&&r<=4?e.set(o+t,i+r,!0,!0):e.set(o+t,i+r,!1,!0))}}(y,t);let b=y.size;for(let e=8;e<b-8;e++){let t=e%2==0;y.set(e,6,t,!0),y.set(6,e,t,!0)}return!function(e,t){let n=a.getPositions(t);for(let t=0;t<n.length;t++){let r=n[t][0],o=n[t][1];for(let t=-2;t<=2;t++)for(let n=-2;n<=2;n++)-2===t||2===t||-2===n||2===n||0===t&&0===n?e.set(r+t,o+n,!0,!0):e.set(r+t,o+n,!1,!0)}}(y,t),g(y,n,0),t>=7&&function(e,t){let n,r,o,i=e.size,s=p.getEncodedBits(t);for(let t=0;t<18;t++)n=Math.floor(t/3),r=t%3+i-8-3,o=(s>>t&1)==1,e.set(n,r,o,!0),e.set(r,n,o,!0)}(y,t),!function(e,t){let n=e.size,r=-1,o=n-1,i=7,s=0;for(let a=n-1;a>0;a-=2)for(6===a&&a--;;){for(let n=0;n<2;n++)if(!e.isReserved(o,a-n)){let r=!1;s<t.length&&(r=(t[s]>>>i&1)==1),e.set(o,a-n,r),-1==--i&&(s++,i=7)}if((o+=r)<0||n<=o){o-=r,r=-r;break}}}(y,w),isNaN(o)&&(o=l.getBestMask(y,g.bind(null,y,n))),l.applyMask(o,y),g(y,n,o),{modules:y,version:t,errorCorrectionLevel:n,maskPattern:o,segments:h}}(e,n,_,h)}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/reed-solomon-encoder.js"(e,t,n){let r=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/polynomial.js");function o(e){this.genPoly=void 0,this.degree=e,this.degree&&this.initialize(this.degree)}o.prototype.initialize=function(e){this.degree=e,this.genPoly=r.generateECPolynomial(this.degree)},o.prototype.encode=function(e){if(!this.genPoly)throw Error("Encoder not initialized");let t=new Uint8Array(e.length+this.degree);t.set(e);let n=r.mod(t,this.genPoly),o=this.degree-n.length;if(o>0){let e=new Uint8Array(this.degree);return e.set(n,o),e}return n},e.exports=o},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/regex.js"(e,t){let n="[0-9]+",r="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+",o="(?:(?![A-Z0-9 $%*+\\-./:]|"+(r=r.replace(/u/g,"\\u"))+")(?:.|[\r\n]))+";t.KANJI=RegExp(r,"g"),t.BYTE_KANJI=RegExp("[^A-Z0-9 $%*+\\-./:]+","g"),t.BYTE=RegExp(o,"g"),t.NUMERIC=RegExp(n,"g"),t.ALPHANUMERIC=RegExp("[A-Z $%*+\\-./:]+","g");let i=RegExp("^"+r+"$"),s=RegExp("^"+n+"$"),a=RegExp("^[A-Z0-9 $%*+\\-./:]+$");t.testKanji=function(e){return i.test(e)},t.testNumeric=function(e){return s.test(e)},t.testAlphanumeric=function(e){return a.test(e)}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/segments.js"(e,t,n){let r=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/mode.js"),o=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/numeric-data.js"),i=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/alphanumeric-data.js"),s=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/byte-data.js"),a=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/kanji-data.js"),d=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/regex.js"),l=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/utils.js"),c=n("../../../node_modules/.pnpm/dijkstrajs@1.0.3/node_modules/dijkstrajs/dijkstra.js");function u(e){return unescape(encodeURIComponent(e)).length}function p(e,t,n){let r,o=[];for(;null!==(r=e.exec(n));)o.push({data:r[0],index:r.index,mode:t,length:r[0].length});return o}function h(e){let t,n,o=p(d.NUMERIC,r.NUMERIC,e),i=p(d.ALPHANUMERIC,r.ALPHANUMERIC,e);return l.isKanjiModeEnabled()?(t=p(d.BYTE,r.BYTE,e),n=p(d.KANJI,r.KANJI,e)):(t=p(d.BYTE_KANJI,r.BYTE,e),n=[]),o.concat(i,t,n).sort(function(e,t){return e.index-t.index}).map(function(e){return{data:e.data,mode:e.mode,length:e.length}})}function f(e,t){switch(t){case r.NUMERIC:return o.getBitsLength(e);case r.ALPHANUMERIC:return i.getBitsLength(e);case r.KANJI:return a.getBitsLength(e);case r.BYTE:return s.getBitsLength(e)}}function m(e,t){let n,d=r.getBestModeForData(e);if((n=r.from(t,d))!==r.BYTE&&n.bit<d.bit)throw Error('"'+e+'" cannot be encoded with mode '+r.toString(n)+".\n Suggested mode is: "+r.toString(d));switch(n===r.KANJI&&!l.isKanjiModeEnabled()&&(n=r.BYTE),n){case r.NUMERIC:return new o(e);case r.ALPHANUMERIC:return new i(e);case r.KANJI:return new a(e);case r.BYTE:return new s(e)}}t.fromArray=function(e){return e.reduce(function(e,t){return"string"==typeof t?e.push(m(t,null)):t.data&&e.push(m(t.data,t.mode)),e},[])},t.fromString=function(e,n){let o=function(e,t){let n={},o={start:{}},i=["start"];for(let s=0;s<e.length;s++){let a=e[s],d=[];for(let e=0;e<a.length;e++){let l=a[e],c=""+s+e;d.push(c),n[c]={node:l,lastCount:0},o[c]={};for(let e=0;e<i.length;e++){let s=i[e];n[s]&&n[s].node.mode===l.mode?(o[s][c]=f(n[s].lastCount+l.length,l.mode)-f(n[s].lastCount,l.mode),n[s].lastCount+=l.length):(n[s]&&(n[s].lastCount=l.length),o[s][c]=f(l.length,l.mode)+4+r.getCharCountIndicator(l.mode,t))}}i=d}for(let e=0;e<i.length;e++)o[i[e]].end=0;return{map:o,table:n}}(function(e){let t=[];for(let n=0;n<e.length;n++){let o=e[n];switch(o.mode){case r.NUMERIC:t.push([o,{data:o.data,mode:r.ALPHANUMERIC,length:o.length},{data:o.data,mode:r.BYTE,length:o.length}]);break;case r.ALPHANUMERIC:t.push([o,{data:o.data,mode:r.BYTE,length:o.length}]);break;case r.KANJI:t.push([o,{data:o.data,mode:r.BYTE,length:u(o.data)}]);break;case r.BYTE:t.push([{data:o.data,mode:r.BYTE,length:u(o.data)}])}}return t}(h(e,l.isKanjiModeEnabled())),n),i=c.find_path(o.map,"start","end"),s=[];for(let e=1;e<i.length-1;e++)s.push(o.table[i[e]].node);return t.fromArray(s.reduce(function(e,t){let n=e.length-1>=0?e[e.length-1]:null;return n&&n.mode===t.mode?e[e.length-1].data+=t.data:e.push(t),e},[]))},t.rawSplit=function(e){return t.fromArray(h(e,l.isKanjiModeEnabled()))}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/utils.js"(e,t){let n,r=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];t.getSymbolSize=function(e){if(!e)throw Error('"version" cannot be null or undefined');if(e<1||e>40)throw Error('"version" should be in range from 1 to 40');return 4*e+17},t.getSymbolTotalCodewords=function(e){return r[e]},t.getBCHDigit=function(e){let t=0;for(;0!==e;)t++,e>>>=1;return t},t.setToSJISFunction=function(e){if("function"!=typeof e)throw Error('"toSJISFunc" is not a valid function.');n=e},t.isKanjiModeEnabled=function(){return void 0!==n},t.toSJIS=function(e){return n(e)}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/version-check.js"(e,t){t.isValid=function(e){return!isNaN(e)&&e>=1&&e<=40}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/version.js"(e,t,n){let r=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/utils.js"),o=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/error-correction-code.js"),i=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/error-correction-level.js"),s=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/mode.js"),a=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/version-check.js"),d=r.getBCHDigit(7973);function l(e,t){return s.getCharCountIndicator(e,t)+4}t.from=function(e,t){return a.isValid(e)?parseInt(e,10):t},t.getCapacity=function(e,t,n){if(!a.isValid(e))throw Error("Invalid QR Code version");void 0===n&&(n=s.BYTE);let i=(r.getSymbolTotalCodewords(e)-o.getTotalCodewordsCount(e,t))*8;if(n===s.MIXED)return i;let d=i-l(n,e);switch(n){case s.NUMERIC:return Math.floor(d/10*3);case s.ALPHANUMERIC:return Math.floor(d/11*2);case s.KANJI:return Math.floor(d/13);case s.BYTE:default:return Math.floor(d/8)}},t.getBestVersionForData=function(e,n){let r,o=i.from(n,i.M);if(Array.isArray(e)){if(e.length>1){for(let n=1;n<=40;n++)if(function(e,t){let n=0;return e.forEach(function(e){let r=l(e.mode,t);n+=r+e.getBitsLength()}),n}(e,n)<=t.getCapacity(n,o,s.MIXED))return n;return}if(0===e.length)return 1;r=e[0]}else r=e;return function(e,n,r){for(let o=1;o<=40;o++)if(n<=t.getCapacity(o,r,e))return o}(r.mode,r.getLength(),o)},t.getEncodedBits=function(e){if(!a.isValid(e)||e<7)throw Error("Invalid QR Code version");let t=e<<12;for(;r.getBCHDigit(t)-d>=0;)t^=7973<<r.getBCHDigit(t)-d;return e<<12|t}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/index.js"(e,t,n){e.exports=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/server.js")},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/canvas.js"(e,t,n){let r=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/utils.js");t.render=function(e,t,n){var o;let i=n,s=t;void 0!==i||t&&t.getContext||(i=t,t=void 0),t||(s=function(){try{return document.createElement("canvas")}catch(e){throw Error("You need to specify a canvas element")}}()),i=r.getOptions(i);let a=r.getImageWidth(e.modules.size,i),d=s.getContext("2d"),l=d.createImageData(a,a);return r.qrToImageData(l.data,e,i),o=s,d.clearRect(0,0,o.width,o.height),o.style||(o.style={}),o.height=a,o.width=a,o.style.height=a+"px",o.style.width=a+"px",d.putImageData(l,0,0),s},t.renderToDataURL=function(e,n,r){let o=r;void 0!==o||n&&n.getContext||(o=n,n=void 0),o||(o={});let i=t.render(e,n,o),s=o.type||"image/png",a=o.rendererOpts||{};return i.toDataURL(s,a.quality)}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/png.js"(e,t,n){let r=n("fs"),o=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/png.js").O,i=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/utils.js");t.render=function(e,t){let n=i.getOptions(t),r=n.rendererOpts,s=i.getImageWidth(e.modules.size,n);r.width=s,r.height=s;let a=new o(r);return i.qrToImageData(a.data,e,n),a},t.renderToDataURL=function(e,n,r){void 0===r&&(r=n,n=void 0),t.renderToBuffer(e,n,function(e,t){e&&r(e);let n="data:image/png;base64,";n+=t.toString("base64"),r(null,n)})},t.renderToBuffer=function(e,n,r){void 0===r&&(r=n,n=void 0);let o=t.render(e,n),i=[];o.on("error",r),o.on("data",function(e){i.push(e)}),o.on("end",function(){r(null,Buffer.concat(i))}),o.pack()},t.renderToFile=function(e,n,o,i){void 0===i&&(i=o,o=void 0);let s=!1,a=(...e)=>{s||(s=!0,i.apply(null,e))},d=r.createWriteStream(e);d.on("error",a),d.on("close",a),t.renderToFileStream(d,n,o)},t.renderToFileStream=function(e,n,r){t.render(n,r).pack().pipe(e)}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/svg-tag.js"(e,t,n){let r=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/utils.js");function o(e,t){let n=e.a/255,r=t+'="'+e.hex+'"';return n<1?r+" "+t+'-opacity="'+n.toFixed(2).slice(1)+'"':r}function i(e,t,n){let r=e+t;return void 0!==n&&(r+=" "+n),r}t.render=function(e,t,n){let s=r.getOptions(t),a=e.modules.size,d=e.modules.data,l=a+2*s.margin,c=s.color.light.a?"<path "+o(s.color.light,"fill")+' d="M0 0h'+l+"v"+l+'H0z"/>':"",u="<path "+o(s.color.dark,"stroke")+' d="'+function(e,t,n){let r="",o=0,s=!1,a=0;for(let d=0;d<e.length;d++){let l=Math.floor(d%t),c=Math.floor(d/t);l||s||(s=!0),e[d]?(a++,d>0&&l>0&&e[d-1]||(r+=s?i("M",l+n,.5+c+n):i("m",o,0),o=0,s=!1),l+1<t&&e[d+1]||(r+=i("h",a),a=0)):o++}return r}(d,a,s.margin)+'"/>',p='<svg xmlns="http://www.w3.org/2000/svg" '+(s.width?'width="'+s.width+'" height="'+s.width+'" ':"")+('viewBox="0 0 '+l+" ")+l+'" shape-rendering="crispEdges">'+c+u+"</svg>\n";return"function"==typeof n&&n(null,p),p}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/svg.js"(e,t,n){t.render=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/svg-tag.js").render,t.renderToFile=function(e,r,o,i){void 0===i&&(i=o,o=void 0);let s=n("fs"),a=t.render(r,o);s.writeFile(e,'<?xml version="1.0" encoding="utf-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">'+a,i)}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/terminal.js"(e,t,n){let r=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/terminal/terminal.js"),o=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/terminal/terminal-small.js");t.render=function(e,t,n){return t&&t.small?o.render(e,t,n):r.render(e,t,n)}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/terminal/terminal-small.js"(e,t){let n="\x1b[37m",r="\x1b[30m",o="\x1b[0m",i="\x1b[47m"+r,s="\x1b[40m"+n,a=function(e,t,n,r){let o=t+1;return n>=o||r>=o||r<-1||n<-1?"0":n>=t||r>=t||r<0||n<0?"1":e[r*t+n]?"2":"1"},d=function(e,t,n,r){return a(e,t,n,r)+a(e,t,n,r+1)};t.render=function(e,t,a){var l,c;let u=e.modules.size,p=e.modules.data,h=!!(t&&t.inverse),f=t&&t.inverse?s:i,m={"00":o+" "+f,"01":o+(l=h?r:n)+"▄"+f,"02":o+(c=h?n:r)+"▄"+f,10:o+l+"▀"+f,11:" ",12:"▄",20:o+c+"▀"+f,21:"▀",22:"█"},g=o+"\n"+f,_=f;for(let e=-1;e<u+1;e+=2){for(let t=-1;t<u;t++)_+=m[d(p,u,t,e)];_+=m[d(p,u,u,e)]+g}return _+=o,"function"==typeof a&&a(null,_),_}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/terminal/terminal.js"(e,t){t.render=function(e,t,n){let r=e.modules.size,o=e.modules.data,i="\x1b[47m \x1b[0m",s="",a=Array(r+3).join(i),d=[,,].join(i);s+=a+"\n";for(let e=0;e<r;++e){s+=i;for(let t=0;t<r;t++)s+=o[e*r+t]?"\x1b[40m \x1b[0m":i;s+=d+"\n"}return s+=a+"\n","function"==typeof n&&n(null,s),s}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/utf8.js"(e,t,n){let r=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/utils.js"),o={WW:" ",WB:"▄",BB:"█",BW:"▀"},i={BB:" ",BW:"▄",WW:"█",WB:"▀"};t.render=function(e,t,n){let s=r.getOptions(t),a=o;("#ffffff"===s.color.dark.hex||"#000000"===s.color.light.hex)&&(a=i);let d=e.modules.size,l=e.modules.data,c="",u=Array(d+2*s.margin+1).join(a.WW);u=Array(s.margin/2+1).join(u+"\n");let p=Array(s.margin+1).join(a.WW);c+=u;for(let e=0;e<d;e+=2){c+=p;for(let t=0;t<d;t++){var h;let n=l[e*d+t],r=l[(e+1)*d+t];c+=(h=a,n&&r?h.BB:n&&!r?h.BW:!n&&r?h.WB:h.WW)}c+=p+"\n"}return c+=u.slice(0,-1),"function"==typeof n&&n(null,c),c},t.renderToFile=function(e,r,o,i){void 0===i&&(i=o,o=void 0);let s=n("fs"),a=t.render(r,o);s.writeFile(e,a,i)}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/utils.js"(e,t){function n(e){if("number"==typeof e&&(e=e.toString()),"string"!=typeof e)throw Error("Color should be defined as hex string");let t=e.slice().replace("#","").split("");if(t.length<3||5===t.length||t.length>8)throw Error("Invalid hex color: "+e);(3===t.length||4===t.length)&&(t=Array.prototype.concat.apply([],t.map(function(e){return[e,e]}))),6===t.length&&t.push("F","F");let n=parseInt(t.join(""),16);return{r:n>>24&255,g:n>>16&255,b:n>>8&255,a:255&n,hex:"#"+t.slice(0,6).join("")}}t.getOptions=function(e){e||(e={}),e.color||(e.color={});let t=void 0===e.margin||null===e.margin||e.margin<0?4:e.margin,r=e.width&&e.width>=21?e.width:void 0,o=e.scale||4;return{width:r,scale:r?4:o,margin:t,color:{dark:n(e.color.dark||"#000000ff"),light:n(e.color.light||"#ffffffff")},type:e.type,rendererOpts:e.rendererOpts||{}}},t.getScale=function(e,t){return t.width&&t.width>=e+2*t.margin?t.width/(e+2*t.margin):t.scale},t.getImageWidth=function(e,n){let r=t.getScale(e,n);return Math.floor((e+2*n.margin)*r)},t.qrToImageData=function(e,n,r){let o=n.modules.size,i=n.modules.data,s=t.getScale(o,r),a=Math.floor((o+2*r.margin)*s),d=r.margin*s,l=[r.color.light,r.color.dark];for(let t=0;t<a;t++)for(let n=0;n<a;n++){let c=(t*a+n)*4,u=r.color.light;t>=d&&n>=d&&t<a-d&&n<a-d&&(u=l[+!!i[Math.floor((t-d)/s)*o+Math.floor((n-d)/s)]]),e[c++]=u.r,e[c++]=u.g,e[c++]=u.b,e[c]=u.a}}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/server.js"(e,t,n){let r=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/can-promise.js"),o=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/qrcode.js"),i=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/png.js"),s=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/utf8.js"),a=(n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/terminal.js"),n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/svg.js"));function d(e,t,n){if(void 0===e)throw Error("String required as first argument");if(void 0===n&&(n=t,t={}),"function"!=typeof n)if(r())t=n||{},n=null;else throw Error("Callback required as last argument");return{opts:t,cb:n}}function l(e){switch(e){case"svg":return a;case"txt":case"utf8":return s;default:return i}}function c(e,t,n){if(!n.cb)return new Promise(function(r,i){try{let s=o.create(t,n.opts);return e(s,n.opts,function(e,t){return e?i(e):r(t)})}catch(e){i(e)}});try{let r=o.create(t,n.opts);return e(r,n.opts,n.cb)}catch(e){n.cb(e)}}o.create,n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/browser.js"),t.toBuffer=function(e,t,n){let r=d(e,t,n);return c(l(r.opts.type).renderToBuffer,e,r)},t.toFile=function(e,t,n,o){if("string"!=typeof e||"string"!=typeof t&&"object"!=typeof t)throw Error("Invalid argument");if(arguments.length<3&&!r())throw Error("Too few arguments provided");let i=d(t,n,o);return c(l(i.opts.type||e.slice((e.lastIndexOf(".")-1>>>0)+2).toLowerCase()).renderToFile.bind(null,e),t,i)}},"../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.24/node_modules/@byted-doubao-apps/auth-cli/dist/config.js"(e,t,n){var r=n("node:os"),o=n("node:path");let i=o.join(r.homedir(),".dbx","token"),s=o.join(r.homedir(),".doubao","token"),a={};function d(e){Object.assign(a,e)}function l(e={}){let t={...a,...e},n=function(e,t){let n;try{n=new URL(c(e))}catch{throw Error(`${t} must be an absolute HTTPS URL`)}if("https:"!==n.protocol)throw Error(`${t} must use https`);return c(n.toString())}(t.baseUrl??"https://developer.doubao.com","baseUrl"),r=t.tokenPath??i;return{...t,baseUrl:n,allowedOrigins:function(e,t){let n=new Set([new URL(t).origin]);for(let t of e??[]){let e;try{e=new URL(t)}catch{throw Error(`allowedOrigins entries must be absolute HTTPS origins: ${t}`)}if("https:"!==e.protocol)throw Error(`allowedOrigins entries must use https: ${t}`);n.add(e.origin)}return[...n]}(t.allowedOrigins,n),tokenPath:r,legacyTokenPath:t.tokenPath?void 0:s,requestHeaders:new Headers(t.requestHeaders)}}function c(e){return e.replace(/\/+$/,"")}n.d(t,{$i:()=>l,ZI:()=>d},{E:"dbx-cli"})},"../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.24/node_modules/@byted-doubao-apps/auth-cli/dist/credential-store.js"(e,t,n){var r=n("node:child_process"),o=n("node:crypto"),i=n("node:fs"),s=n("node:os"),a=n("node:path");let d=(0,n("node:util").promisify)(r.execFile),l="byted-doubao-open-dbx-cli",c="dbx-cli",u="aes-256-gcm";class p extends Error{constructor(e){super(e),this.name="CredentialStoreError"}}function h(){let e=new m;return"darwin"===process.platform?new f(new g,e):"linux"===process.platform?new f(new _,e):e}class f{constructor(e,t){this.primary=e,this.fallback=t}async get(e){let t;try{let t=await this.primary.get(e);if(t)return t}catch(e){t=e}try{let t=await this.fallback.get(e);if(t)return t}catch(e){if(t)throw new p(`Failed to read token from system credential store (${A(t)}); encrypted-file fallback also failed: ${A(e)}`);throw e}if(t)throw t instanceof Error?t:new p(`Failed to read token from system credential store: ${String(t)}`)}async set(e,t){let n;try{await this.primary.set(e,t)}catch(e){n=e}try{await this.fallback.set(e,t)}catch(e){if(n)throw new p(`Failed to write token to system credential store (${A(n)}) and encrypted-file fallback (${A(e)})`);throw e}}async delete(e){let t;try{await this.primary.delete(e)}catch(e){t=e}try{await this.fallback.delete(e)}catch(e){if(t)throw new p(`Failed to delete token from system credential store (${A(t)}) and encrypted-file fallback (${A(e)})`);throw e}}}class m{constructor(e={}){this.baseDir=e.baseDir??("darwin"===process.platform?a.join(s.homedir(),"Library","Application Support",c):"win32"===process.platform?a.join(process.env.APPDATA||a.join(s.homedir(),"AppData","Roaming"),c):a.join(process.env.XDG_DATA_HOME||a.join(s.homedir(),".local","share"),c))}async get(e){var t,n;let r,s,a=this.credentialFilePath(e);try{r=await i.promises.readFile(a,"utf8")}catch(e){if(I(e)&&"ENOENT"===e.code)return;throw new p(`Failed to read encrypted token file: ${A(e)}`)}try{s=JSON.parse(r)}catch(e){throw new p(`Encrypted token file is not valid JSON: ${A(e)}`)}if(!((t=s)&&"object"==typeof t&&1===t.version&&t.algorithm===u&&"string"==typeof t.iv&&"string"==typeof t.authTag&&"string"==typeof t.ciphertext))throw new p("Encrypted token file has an unsupported format");let d=await this.readMasterKey();try{let t=o.createDecipheriv(u,d,Buffer.from(s.iv,"base64url"));return t.setAAD(Buffer.from((n=e,`${l}:${n}`),"utf8")),t.setAuthTag(Buffer.from(s.authTag,"base64url")),Buffer.concat([t.update(Buffer.from(s.ciphertext,"base64url")),t.final()]).toString("utf8")}catch(e){throw new p(`Failed to decrypt encrypted token file: ${A(e)}`)}}async set(e,t){var n;let r=await this.readOrCreateMasterKey(),i=o.randomBytes(12),s=o.createCipheriv(u,r,i);s.setAAD(Buffer.from((n=e,`${l}:${n}`),"utf8"));let a=Buffer.concat([s.update(t,"utf8"),s.final()]),d={version:1,algorithm:u,iv:i.toString("base64url"),authTag:s.getAuthTag().toString("base64url"),ciphertext:a.toString("base64url")};await w(this.credentialFilePath(e),`${JSON.stringify(d,null,2)}
9
+ 错误码:${e}`);let t=(null==p?void 0:p.message)||"Failed to get debug ticket";throw Error(`${t} (code=${e}, appKey=${u.appKey}, baseApiUrl=${u.baseApiUrl})`)}let h=String((null==(d=p.data)?void 0:d.debug_token)||"").trim(),f=String((null==(l=p.data)?void 0:l.encrypted_debug_payload)||"").trim();if(!h||!f)throw Error("Debug ticket response is missing required fields");return{qrCodeValue:JSON.stringify({action:t.REAL_DEVICE_DEBUG_QR_ACTION,debug_token:h,encrypted_debug_payload:f}),debugToken:h,encryptedDebugPayload:f}})}},"../../../node_modules/.pnpm/dijkstrajs@1.0.3/node_modules/dijkstrajs/dijkstra.js"(e){var t={single_source_shortest_paths:function(e,n,r){var o,i,s,a,d,l,c,u={},p={};p[n]=0;var h=t.PriorityQueue.make();for(h.push(n,0);!h.empty();)for(s in i=(o=h.pop()).value,a=o.cost,d=e[i]||{})d.hasOwnProperty(s)&&(l=a+d[s],c=p[s],(void 0===p[s]||c>l)&&(p[s]=l,h.push(s,l),u[s]=i));if(void 0!==r&&void 0===p[r])throw Error(["Could not find a path from ",n," to ",r,"."].join(""));return u},extract_shortest_path_from_predecessor_list:function(e,t){for(var n=[],r=t;r;)n.push(r),e[r],r=e[r];return n.reverse(),n},find_path:function(e,n,r){var o=t.single_source_shortest_paths(e,n,r);return t.extract_shortest_path_from_predecessor_list(o,r)},PriorityQueue:{make:function(e){var n,r=t.PriorityQueue,o={};for(n in e=e||{},r)r.hasOwnProperty(n)&&(o[n]=r[n]);return o.queue=[],o.sorter=e.sorter||r.default_sorter,o},default_sorter:function(e,t){return e.cost-t.cost},push:function(e,t){this.queue.push({value:e,cost:t}),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return 0===this.queue.length}}};e.exports=t},"../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/bitmapper.js"(e,t,n){let r=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/interlace.js"),o=[function(){},function(e,t,n,r){if(r===t.length)throw Error("Ran out of data");let o=t[r];e[n]=o,e[n+1]=o,e[n+2]=o,e[n+3]=255},function(e,t,n,r){if(r+1>=t.length)throw Error("Ran out of data");let o=t[r];e[n]=o,e[n+1]=o,e[n+2]=o,e[n+3]=t[r+1]},function(e,t,n,r){if(r+2>=t.length)throw Error("Ran out of data");e[n]=t[r],e[n+1]=t[r+1],e[n+2]=t[r+2],e[n+3]=255},function(e,t,n,r){if(r+3>=t.length)throw Error("Ran out of data");e[n]=t[r],e[n+1]=t[r+1],e[n+2]=t[r+2],e[n+3]=t[r+3]}],i=[function(){},function(e,t,n,r){let o=t[0];e[n]=o,e[n+1]=o,e[n+2]=o,e[n+3]=r},function(e,t,n){let r=t[0];e[n]=r,e[n+1]=r,e[n+2]=r,e[n+3]=t[1]},function(e,t,n,r){e[n]=t[0],e[n+1]=t[1],e[n+2]=t[2],e[n+3]=r},function(e,t,n){e[n]=t[0],e[n+1]=t[1],e[n+2]=t[2],e[n+3]=t[3]}];t.dataToBitMap=function(e,t){let n,s,a,d,l,c,u=t.width,p=t.height,h=t.depth,f=t.bpp,m=t.interlace;8!==h&&(n=[],s=0,a={get:function(t){for(;n.length<t;)!function(){let t,r,o,i;if(s===e.length)throw Error("Ran out of data");let a=e[s];switch(s++,h){default:throw Error("unrecognised depth");case 16:o=e[s],s++,n.push((a<<8)+o);break;case 4:o=15&a,i=a>>4,n.push(i,o);break;case 2:t=3&a,r=a>>2&3,o=a>>4&3,i=a>>6&3,n.push(i,o,r,t);break;case 1:t=a>>4&1,r=a>>5&1,o=a>>6&1,i=a>>7&1,n.push(i,o,r,t,a>>3&1,a>>2&1,a>>1&1,1&a)}}();let r=n.slice(0,t);return n=n.slice(t),r},resetAfterLine:function(){n.length=0},end:function(){if(s!==e.length)throw Error("extra data found")}}),d=h<=8?Buffer.alloc(u*p*4):new Uint16Array(u*p*4);let g=Math.pow(2,h)-1,_=0;if(m)l=r.getImagePasses(u,p),c=r.getInterlaceIterator(u,p);else{let e=0;c=function(){let t=e;return e+=4,t},l=[{width:u,height:p}]}for(let t=0;t<l.length;t++)8===h?_=function(e,t,n,r,i,s){let a=e.width,d=e.height,l=e.index;for(let e=0;e<d;e++)for(let d=0;d<a;d++){let a=n(d,e,l);o[r](t,i,a,s),s+=r}return s}(l[t],d,c,f,e,_):function(e,t,n,r,o,s){let a=e.width,d=e.height,l=e.index;for(let e=0;e<d;e++){for(let d=0;d<a;d++){let a=o.get(r),c=n(d,e,l);i[r](t,a,c,s)}o.resetAfterLine()}}(l[t],d,c,f,a,g);if(8===h){if(_!==e.length)throw Error("extra data found")}else a.end();return d}},"../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/bitpacker.js"(e,t,n){let r=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/constants.js");e.exports=function(e,t,n,o){let i=-1!==[r.COLORTYPE_COLOR_ALPHA,r.COLORTYPE_ALPHA].indexOf(o.colorType);if(o.colorType===o.inputColorType){let t,n=(new DataView(t=new ArrayBuffer(2)).setInt16(0,256,!0),256!==new Int16Array(t)[0]);if(8===o.bitDepth||16===o.bitDepth&&n)return e}let s=16!==o.bitDepth?e:new Uint16Array(e.buffer),a=255,d=r.COLORTYPE_TO_BPP_MAP[o.inputColorType];4!==d||o.inputHasAlpha||(d=3);let l=r.COLORTYPE_TO_BPP_MAP[o.colorType];16===o.bitDepth&&(a=65535,l*=2);let c=Buffer.alloc(t*n*l),u=0,p=0,h=o.bgColor||{};void 0===h.red&&(h.red=a),void 0===h.green&&(h.green=a),void 0===h.blue&&(h.blue=a);for(let e=0;e<n;e++)for(let e=0;e<t;e++){let e=function(){let e,t,n,d=a;switch(o.inputColorType){case r.COLORTYPE_COLOR_ALPHA:d=s[u+3],e=s[u],t=s[u+1],n=s[u+2];break;case r.COLORTYPE_COLOR:e=s[u],t=s[u+1],n=s[u+2];break;case r.COLORTYPE_ALPHA:d=s[u+1],t=e=s[u],n=e;break;case r.COLORTYPE_GRAYSCALE:t=e=s[u],n=e;break;default:throw Error("input color type:"+o.inputColorType+" is not supported at present")}return o.inputHasAlpha&&!i&&(d/=a,e=Math.min(Math.max(Math.round((1-d)*h.red+d*e),0),a),t=Math.min(Math.max(Math.round((1-d)*h.green+d*t),0),a),n=Math.min(Math.max(Math.round((1-d)*h.blue+d*n),0),a)),{red:e,green:t,blue:n,alpha:d}}();switch(o.colorType){case r.COLORTYPE_COLOR_ALPHA:case r.COLORTYPE_COLOR:8===o.bitDepth?(c[p]=e.red,c[p+1]=e.green,c[p+2]=e.blue,i&&(c[p+3]=e.alpha)):(c.writeUInt16BE(e.red,p),c.writeUInt16BE(e.green,p+2),c.writeUInt16BE(e.blue,p+4),i&&c.writeUInt16BE(e.alpha,p+6));break;case r.COLORTYPE_ALPHA:case r.COLORTYPE_GRAYSCALE:{let t=(e.red+e.green+e.blue)/3;8===o.bitDepth?(c[p]=t,i&&(c[p+1]=e.alpha)):(c.writeUInt16BE(t,p),i&&c.writeUInt16BE(e.alpha,p+2));break}default:throw Error("unrecognised color Type "+o.colorType)}u+=d,p+=l}return c}},"../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/chunkstream.js"(e,t,n){let r=n("util"),o=n("stream"),i=e.exports=function(){o.call(this),this._buffers=[],this._buffered=0,this._reads=[],this._paused=!1,this._encoding="utf8",this.writable=!0};r.inherits(i,o),i.prototype.read=function(e,t){this._reads.push({length:Math.abs(e),allowLess:e<0,func:t}),process.nextTick((function(){this._process(),this._paused&&this._reads&&this._reads.length>0&&(this._paused=!1,this.emit("drain"))}).bind(this))},i.prototype.write=function(e,t){let n;return this.writable?(n=Buffer.isBuffer(e)?e:Buffer.from(e,t||this._encoding),this._buffers.push(n),this._buffered+=n.length,this._process(),this._reads&&0===this._reads.length&&(this._paused=!0),this.writable&&!this._paused):(this.emit("error",Error("Stream not writable")),!1)},i.prototype.end=function(e,t){e&&this.write(e,t),this.writable=!1,this._buffers&&(0===this._buffers.length?this._end():(this._buffers.push(null),this._process()))},i.prototype.destroySoon=i.prototype.end,i.prototype._end=function(){this._reads.length>0&&this.emit("error",Error("Unexpected end of input")),this.destroy()},i.prototype.destroy=function(){this._buffers&&(this.writable=!1,this._reads=null,this._buffers=null,this.emit("close"))},i.prototype._processReadAllowingLess=function(e){this._reads.shift();let t=this._buffers[0];t.length>e.length?(this._buffered-=e.length,this._buffers[0]=t.slice(e.length),e.func.call(this,t.slice(0,e.length))):(this._buffered-=t.length,this._buffers.shift(),e.func.call(this,t))},i.prototype._processRead=function(e){this._reads.shift();let t=0,n=0,r=Buffer.alloc(e.length);for(;t<e.length;){let o=this._buffers[n++],i=Math.min(o.length,e.length-t);o.copy(r,t,0,i),t+=i,i!==o.length&&(this._buffers[--n]=o.slice(i))}n>0&&this._buffers.splice(0,n),this._buffered-=e.length,e.func.call(this,r)},i.prototype._process=function(){try{for(;this._buffered>0&&this._reads&&this._reads.length>0;){let e=this._reads[0];if(e.allowLess)this._processReadAllowingLess(e);else if(this._buffered>=e.length)this._processRead(e);else break}this._buffers&&!this.writable&&this._end()}catch(e){this.emit("error",e)}}},"../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/constants.js"(e){e.exports={PNG_SIGNATURE:[137,80,78,71,13,10,26,10],TYPE_IHDR:0x49484452,TYPE_IEND:0x49454e44,TYPE_IDAT:0x49444154,TYPE_PLTE:0x504c5445,TYPE_tRNS:0x74524e53,TYPE_gAMA:0x67414d41,COLORTYPE_GRAYSCALE:0,COLORTYPE_PALETTE:1,COLORTYPE_COLOR:2,COLORTYPE_ALPHA:4,COLORTYPE_PALETTE_COLOR:3,COLORTYPE_COLOR_ALPHA:6,COLORTYPE_TO_BPP_MAP:{0:1,2:3,3:1,4:2,6:4},GAMMA_DIVISION:1e5}},"../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/crc.js"(e){let t=[];for(let e=0;e<256;e++){let n=e;for(let e=0;e<8;e++)1&n?n=0xedb88320^n>>>1:n>>>=1;t[e]=n}let n=e.exports=function(){this._crc=-1};n.prototype.write=function(e){for(let n=0;n<e.length;n++)this._crc=t[(this._crc^e[n])&255]^this._crc>>>8;return!0},n.prototype.crc32=function(){return -1^this._crc},n.crc32=function(e){let n=-1;for(let r=0;r<e.length;r++)n=t[(n^e[r])&255]^n>>>8;return -1^n}},"../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/filter-pack.js"(e,t,n){let r=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/paeth-predictor.js"),o={0:function(e,t,n,r,o){for(let i=0;i<n;i++)r[o+i]=e[t+i]},1:function(e,t,n,r,o,i){for(let s=0;s<n;s++){let n=s>=i?e[t+s-i]:0,a=e[t+s]-n;r[o+s]=a}},2:function(e,t,n,r,o){for(let i=0;i<n;i++){let s=t>0?e[t+i-n]:0,a=e[t+i]-s;r[o+i]=a}},3:function(e,t,n,r,o,i){for(let s=0;s<n;s++){let a=s>=i?e[t+s-i]:0,d=t>0?e[t+s-n]:0,l=e[t+s]-(a+d>>1);r[o+s]=l}},4:function(e,t,n,o,i,s){for(let a=0;a<n;a++){let d=a>=s?e[t+a-s]:0,l=t>0?e[t+a-n]:0,c=t>0&&a>=s?e[t+a-(n+s)]:0,u=e[t+a]-r(d,l,c);o[i+a]=u}}},i={0:function(e,t,n){let r=0,o=t+n;for(let n=t;n<o;n++)r+=Math.abs(e[n]);return r},1:function(e,t,n,r){let o=0;for(let i=0;i<n;i++){let n=i>=r?e[t+i-r]:0;o+=Math.abs(e[t+i]-n)}return o},2:function(e,t,n){let r=0,o=t+n;for(let i=t;i<o;i++){let o=t>0?e[i-n]:0;r+=Math.abs(e[i]-o)}return r},3:function(e,t,n,r){let o=0;for(let i=0;i<n;i++){let s=i>=r?e[t+i-r]:0,a=t>0?e[t+i-n]:0;o+=Math.abs(e[t+i]-(s+a>>1))}return o},4:function(e,t,n,o){let i=0;for(let s=0;s<n;s++){let a=s>=o?e[t+s-o]:0,d=t>0?e[t+s-n]:0,l=t>0&&s>=o?e[t+s-(n+o)]:0;i+=Math.abs(e[t+s]-r(a,d,l))}return i}};e.exports=function(e,t,n,r,s){let a;if("filterType"in r&&-1!==r.filterType)if("number"==typeof r.filterType)a=[r.filterType];else throw Error("unrecognised filter types");else a=[0,1,2,3,4];16===r.bitDepth&&(s*=2);let d=t*s,l=0,c=0,u=Buffer.alloc((d+1)*n),p=a[0];for(let t=0;t<n;t++){if(a.length>1){let t=1/0;for(let n=0;n<a.length;n++){let r=i[a[n]](e,c,d,s);r<t&&(p=a[n],t=r)}}u[l]=p,l++,o[p](e,c,d,u,l,s),l+=d,c+=d}return u}},"../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/filter-parse-async.js"(e,t,n){let r=n("util"),o=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/chunkstream.js"),i=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/filter-parse.js"),s=e.exports=function(e){o.call(this);let t=[],n=this;this._filter=new i(e,{read:this.read.bind(this),write:function(e){t.push(e)},complete:function(){n.emit("complete",Buffer.concat(t))}}),this._filter.start()};r.inherits(s,o)},"../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/filter-parse-sync.js"(e,t,n){let r=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/sync-reader.js"),o=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/filter-parse.js");t.process=function(e,t){let n=[],i=new r(e);return new o(t,{read:i.read.bind(i),write:function(e){n.push(e)},complete:function(){}}).start(),i.process(),Buffer.concat(n)}},"../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/filter-parse.js"(e,t,n){let r=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/interlace.js"),o=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/paeth-predictor.js");function i(e,t,n){let r=e*t;return 8!==n&&(r=Math.ceil(r/(8/n))),r}let s=e.exports=function(e,t){let n=e.width,o=e.height,s=e.interlace,a=e.bpp,d=e.depth;if(this.read=t.read,this.write=t.write,this.complete=t.complete,this._imageIndex=0,this._images=[],s){let e=r.getImagePasses(n,o);for(let t=0;t<e.length;t++)this._images.push({byteWidth:i(e[t].width,a,d),height:e[t].height,lineIndex:0})}else this._images.push({byteWidth:i(n,a,d),height:o,lineIndex:0});8===d?this._xComparison=a:16===d?this._xComparison=2*a:this._xComparison=1};s.prototype.start=function(){this.read(this._images[this._imageIndex].byteWidth+1,this._reverseFilterLine.bind(this))},s.prototype._unFilterType1=function(e,t,n){let r=this._xComparison,o=r-1;for(let i=0;i<n;i++){let n=e[1+i],s=i>o?t[i-r]:0;t[i]=n+s}},s.prototype._unFilterType2=function(e,t,n){let r=this._lastLine;for(let o=0;o<n;o++){let n=e[1+o],i=r?r[o]:0;t[o]=n+i}},s.prototype._unFilterType3=function(e,t,n){let r=this._xComparison,o=r-1,i=this._lastLine;for(let s=0;s<n;s++){let n=e[1+s],a=i?i[s]:0,d=Math.floor(((s>o?t[s-r]:0)+a)/2);t[s]=n+d}},s.prototype._unFilterType4=function(e,t,n){let r=this._xComparison,i=r-1,s=this._lastLine;for(let a=0;a<n;a++){let n=e[1+a],d=s?s[a]:0,l=o(a>i?t[a-r]:0,d,a>i&&s?s[a-r]:0);t[a]=n+l}},s.prototype._reverseFilterLine=function(e){let t,n=e[0],r=this._images[this._imageIndex],o=r.byteWidth;if(0===n)t=e.slice(1,o+1);else switch(t=Buffer.alloc(o),n){case 1:this._unFilterType1(e,t,o);break;case 2:this._unFilterType2(e,t,o);break;case 3:this._unFilterType3(e,t,o);break;case 4:this._unFilterType4(e,t,o);break;default:throw Error("Unrecognised filter type - "+n)}this.write(t),r.lineIndex++,r.lineIndex>=r.height?(this._lastLine=null,this._imageIndex++,r=this._images[this._imageIndex]):this._lastLine=t,r?this.read(r.byteWidth+1,this._reverseFilterLine.bind(this)):(this._lastLine=null,this.complete())}},"../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/format-normaliser.js"(e){e.exports=function(e,t){let n=t.depth,r=t.width,o=t.height,i=t.colorType,s=t.transColor,a=t.palette,d=e;return 3===i?!function(e,t,n,r,o){let i=0;for(let s=0;s<r;s++)for(let r=0;r<n;r++){let n=o[e[i]];if(!n)throw Error("index "+e[i]+" not in palette");for(let e=0;e<4;e++)t[i+e]=n[e];i+=4}}(e,d,r,o,a):(s&&function(e,t,n,r,o){let i=0;for(let s=0;s<r;s++)for(let r=0;r<n;r++){let n=!1;if(1===o.length?o[0]===e[i]&&(n=!0):o[0]===e[i]&&o[1]===e[i+1]&&o[2]===e[i+2]&&(n=!0),n)for(let e=0;e<4;e++)t[i+e]=0;i+=4}}(e,d,r,o,s),8!==n&&(16===n&&(d=Buffer.alloc(r*o*4)),!function(e,t,n,r,o){let i=Math.pow(2,o)-1,s=0;for(let o=0;o<r;o++)for(let r=0;r<n;r++){for(let n=0;n<4;n++)t[s+n]=Math.floor(255*e[s+n]/i+.5);s+=4}}(e,d,r,o,n))),d}},"../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/interlace.js"(e,t){let n=[{x:[0],y:[0]},{x:[4],y:[0]},{x:[0,4],y:[4]},{x:[2,6],y:[0,4]},{x:[0,2,4,6],y:[2,6]},{x:[1,3,5,7],y:[0,2,4,6]},{x:[0,1,2,3,4,5,6,7],y:[1,3,5,7]}];t.getImagePasses=function(e,t){let r=[],o=e%8,i=t%8,s=(e-o)/8,a=(t-i)/8;for(let e=0;e<n.length;e++){let t=n[e],d=s*t.x.length,l=a*t.y.length;for(let e=0;e<t.x.length;e++)if(t.x[e]<o)d++;else break;for(let e=0;e<t.y.length;e++)if(t.y[e]<i)l++;else break;d>0&&l>0&&r.push({width:d,height:l,index:e})}return r},t.getInterlaceIterator=function(e){return function(t,r,o){let i=t%n[o].x.length,s=(t-i)/n[o].x.length*8+n[o].x[i],a=r%n[o].y.length;return 4*s+((r-a)/n[o].y.length*8+n[o].y[a])*e*4}}},"../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/packer-async.js"(e,t,n){let r=n("util"),o=n("stream"),i=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/constants.js"),s=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/packer.js"),a=e.exports=function(e){o.call(this),this._packer=new s(e||{}),this._deflate=this._packer.createDeflate(),this.readable=!0};r.inherits(a,o),a.prototype.pack=function(e,t,n,r){this.emit("data",Buffer.from(i.PNG_SIGNATURE)),this.emit("data",this._packer.packIHDR(t,n)),r&&this.emit("data",this._packer.packGAMA(r));let o=this._packer.filterData(e,t,n);this._deflate.on("error",this.emit.bind(this,"error")),this._deflate.on("data",(function(e){this.emit("data",this._packer.packIDAT(e))}).bind(this)),this._deflate.on("end",(function(){this.emit("data",this._packer.packIEND()),this.emit("end")}).bind(this)),this._deflate.end(o)}},"../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/packer-sync.js"(e,t,n){let r=!0,o=n("zlib");o.deflateSync||(r=!1);let i=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/constants.js"),s=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/packer.js");e.exports=function(e,t){if(!r)throw Error("To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0");let n=new s(t||{}),a=[];a.push(Buffer.from(i.PNG_SIGNATURE)),a.push(n.packIHDR(e.width,e.height)),e.gamma&&a.push(n.packGAMA(e.gamma));let d=n.filterData(e.data,e.width,e.height),l=o.deflateSync(d,n.getDeflateOptions());if(d=null,!l||!l.length)throw Error("bad png - invalid compressed data response");return a.push(n.packIDAT(l)),a.push(n.packIEND()),Buffer.concat(a)}},"../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/packer.js"(e,t,n){let r=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/constants.js"),o=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/crc.js"),i=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/bitpacker.js"),s=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/filter-pack.js"),a=n("zlib"),d=e.exports=function(e){if(this._options=e,e.deflateChunkSize=e.deflateChunkSize||32768,e.deflateLevel=null!=e.deflateLevel?e.deflateLevel:9,e.deflateStrategy=null!=e.deflateStrategy?e.deflateStrategy:3,e.inputHasAlpha=null==e.inputHasAlpha||e.inputHasAlpha,e.deflateFactory=e.deflateFactory||a.createDeflate,e.bitDepth=e.bitDepth||8,e.colorType="number"==typeof e.colorType?e.colorType:r.COLORTYPE_COLOR_ALPHA,e.inputColorType="number"==typeof e.inputColorType?e.inputColorType:r.COLORTYPE_COLOR_ALPHA,-1===[r.COLORTYPE_GRAYSCALE,r.COLORTYPE_COLOR,r.COLORTYPE_COLOR_ALPHA,r.COLORTYPE_ALPHA].indexOf(e.colorType))throw Error("option color type:"+e.colorType+" is not supported at present");if(-1===[r.COLORTYPE_GRAYSCALE,r.COLORTYPE_COLOR,r.COLORTYPE_COLOR_ALPHA,r.COLORTYPE_ALPHA].indexOf(e.inputColorType))throw Error("option input color type:"+e.inputColorType+" is not supported at present");if(8!==e.bitDepth&&16!==e.bitDepth)throw Error("option bit depth:"+e.bitDepth+" is not supported at present")};d.prototype.getDeflateOptions=function(){return{chunkSize:this._options.deflateChunkSize,level:this._options.deflateLevel,strategy:this._options.deflateStrategy}},d.prototype.createDeflate=function(){return this._options.deflateFactory(this.getDeflateOptions())},d.prototype.filterData=function(e,t,n){let o=i(e,t,n,this._options),a=r.COLORTYPE_TO_BPP_MAP[this._options.colorType];return s(o,t,n,this._options,a)},d.prototype._packChunk=function(e,t){let n=t?t.length:0,r=Buffer.alloc(n+12);return r.writeUInt32BE(n,0),r.writeUInt32BE(e,4),t&&t.copy(r,8),r.writeInt32BE(o.crc32(r.slice(4,r.length-4)),r.length-4),r},d.prototype.packGAMA=function(e){let t=Buffer.alloc(4);return t.writeUInt32BE(Math.floor(e*r.GAMMA_DIVISION),0),this._packChunk(r.TYPE_gAMA,t)},d.prototype.packIHDR=function(e,t){let n=Buffer.alloc(13);return n.writeUInt32BE(e,0),n.writeUInt32BE(t,4),n[8]=this._options.bitDepth,n[9]=this._options.colorType,n[10]=0,n[11]=0,n[12]=0,this._packChunk(r.TYPE_IHDR,n)},d.prototype.packIDAT=function(e){return this._packChunk(r.TYPE_IDAT,e)},d.prototype.packIEND=function(){return this._packChunk(r.TYPE_IEND,null)}},"../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/paeth-predictor.js"(e){e.exports=function(e,t,n){let r=e+t-n,o=Math.abs(r-e),i=Math.abs(r-t),s=Math.abs(r-n);return o<=i&&o<=s?e:i<=s?t:n}},"../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/parser-async.js"(e,t,n){let r=n("util"),o=n("zlib"),i=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/chunkstream.js"),s=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/filter-parse-async.js"),a=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/parser.js"),d=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/bitmapper.js"),l=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/format-normaliser.js"),c=e.exports=function(e){i.call(this),this._parser=new a(e,{read:this.read.bind(this),error:this._handleError.bind(this),metadata:this._handleMetaData.bind(this),gamma:this.emit.bind(this,"gamma"),palette:this._handlePalette.bind(this),transColor:this._handleTransColor.bind(this),finished:this._finished.bind(this),inflateData:this._inflateData.bind(this),simpleTransparency:this._simpleTransparency.bind(this),headersFinished:this._headersFinished.bind(this)}),this._options=e,this.writable=!0,this._parser.start()};r.inherits(c,i),c.prototype._handleError=function(e){this.emit("error",e),this.writable=!1,this.destroy(),this._inflate&&this._inflate.destroy&&this._inflate.destroy(),this._filter&&(this._filter.destroy(),this._filter.on("error",function(){})),this.errord=!0},c.prototype._inflateData=function(e){if(!this._inflate)if(this._bitmapInfo.interlace)this._inflate=o.createInflate(),this._inflate.on("error",this.emit.bind(this,"error")),this._filter.on("complete",this._complete.bind(this)),this._inflate.pipe(this._filter);else{let e=((this._bitmapInfo.width*this._bitmapInfo.bpp*this._bitmapInfo.depth+7>>3)+1)*this._bitmapInfo.height,t=Math.max(e,o.Z_MIN_CHUNK);this._inflate=o.createInflate({chunkSize:t});let n=e,r=this.emit.bind(this,"error");this._inflate.on("error",function(e){n&&r(e)}),this._filter.on("complete",this._complete.bind(this));let i=this._filter.write.bind(this._filter);this._inflate.on("data",function(e){n&&(e.length>n&&(e=e.slice(0,n)),n-=e.length,i(e))}),this._inflate.on("end",this._filter.end.bind(this._filter))}this._inflate.write(e)},c.prototype._handleMetaData=function(e){this._metaData=e,this._bitmapInfo=Object.create(e),this._filter=new s(this._bitmapInfo)},c.prototype._handleTransColor=function(e){this._bitmapInfo.transColor=e},c.prototype._handlePalette=function(e){this._bitmapInfo.palette=e},c.prototype._simpleTransparency=function(){this._metaData.alpha=!0},c.prototype._headersFinished=function(){this.emit("metadata",this._metaData)},c.prototype._finished=function(){this.errord||(this._inflate?this._inflate.end():this.emit("error","No Inflate block"))},c.prototype._complete=function(e){let t;if(!this.errord){try{let n=d.dataToBitMap(e,this._bitmapInfo);t=l(n,this._bitmapInfo),n=null}catch(e){this._handleError(e);return}this.emit("parsed",t)}}},"../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/parser-sync.js"(e,t,n){let r=!0,o=n("zlib"),i=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/sync-inflate.js");o.deflateSync||(r=!1);let s=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/sync-reader.js"),a=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/filter-parse-sync.js"),d=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/parser.js"),l=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/bitmapper.js"),c=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/format-normaliser.js");e.exports=function(e,t){let n,u,p,h;if(!r)throw Error("To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0");let f=[],m=new s(e);if(new d(t,{read:m.read.bind(m),error:function(e){n=e},metadata:function(e){u=e},gamma:function(e){p=e},palette:function(e){u.palette=e},transColor:function(e){u.transColor=e},inflateData:function(e){f.push(e)},simpleTransparency:function(){u.alpha=!0}}).start(),m.process(),n)throw n;let g=Buffer.concat(f);if(f.length=0,u.interlace)h=o.inflateSync(g);else{let e=((u.width*u.bpp*u.depth+7>>3)+1)*u.height;h=i(g,{chunkSize:e,maxLength:e})}if(g=null,!h||!h.length)throw Error("bad png - invalid inflate data response");let _=a.process(h,u);g=null;let w=l.dataToBitMap(_,u);_=null;let y=c(w,u);return u.data=y,u.gamma=p||0,u}},"../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/parser.js"(e,t,n){let r=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/constants.js"),o=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/crc.js"),i=e.exports=function(e,t){this._options=e,e.checkCRC=!1!==e.checkCRC,this._hasIHDR=!1,this._hasIEND=!1,this._emittedHeadersFinished=!1,this._palette=[],this._colorType=0,this._chunks={},this._chunks[r.TYPE_IHDR]=this._handleIHDR.bind(this),this._chunks[r.TYPE_IEND]=this._handleIEND.bind(this),this._chunks[r.TYPE_IDAT]=this._handleIDAT.bind(this),this._chunks[r.TYPE_PLTE]=this._handlePLTE.bind(this),this._chunks[r.TYPE_tRNS]=this._handleTRNS.bind(this),this._chunks[r.TYPE_gAMA]=this._handleGAMA.bind(this),this.read=t.read,this.error=t.error,this.metadata=t.metadata,this.gamma=t.gamma,this.transColor=t.transColor,this.palette=t.palette,this.parsed=t.parsed,this.inflateData=t.inflateData,this.finished=t.finished,this.simpleTransparency=t.simpleTransparency,this.headersFinished=t.headersFinished||function(){}};i.prototype.start=function(){this.read(r.PNG_SIGNATURE.length,this._parseSignature.bind(this))},i.prototype._parseSignature=function(e){let t=r.PNG_SIGNATURE;for(let n=0;n<t.length;n++)if(e[n]!==t[n])return void this.error(Error("Invalid file signature"));this.read(8,this._parseChunkBegin.bind(this))},i.prototype._parseChunkBegin=function(e){let t=e.readUInt32BE(0),n=e.readUInt32BE(4),i="";for(let t=4;t<8;t++)i+=String.fromCharCode(e[t]);let s=!!(32&e[4]);return this._hasIHDR||n===r.TYPE_IHDR?(this._crc=new o,this._crc.write(Buffer.from(i)),this._chunks[n])?this._chunks[n](t):s?void this.read(t+4,this._skipChunk.bind(this)):void this.error(Error("Unsupported critical chunk type "+i)):void this.error(Error("Expected IHDR on beggining"))},i.prototype._skipChunk=function(){this.read(8,this._parseChunkBegin.bind(this))},i.prototype._handleChunkEnd=function(){this.read(4,this._parseChunkEnd.bind(this))},i.prototype._parseChunkEnd=function(e){let t=e.readInt32BE(0),n=this._crc.crc32();this._options.checkCRC&&n!==t?this.error(Error("Crc error - "+t+" - "+n)):this._hasIEND||this.read(8,this._parseChunkBegin.bind(this))},i.prototype._handleIHDR=function(e){this.read(e,this._parseIHDR.bind(this))},i.prototype._parseIHDR=function(e){this._crc.write(e);let t=e.readUInt32BE(0),n=e.readUInt32BE(4),o=e[8],i=e[9],s=e[10],a=e[11],d=e[12];if(8!==o&&4!==o&&2!==o&&1!==o&&16!==o)return void this.error(Error("Unsupported bit depth "+o));if(!(i in r.COLORTYPE_TO_BPP_MAP))return void this.error(Error("Unsupported color type"));if(0!==s)return void this.error(Error("Unsupported compression method"));if(0!==a)return void this.error(Error("Unsupported filter method"));if(0!==d&&1!==d)return void this.error(Error("Unsupported interlace method"));this._colorType=i;let l=r.COLORTYPE_TO_BPP_MAP[this._colorType];this._hasIHDR=!0,this.metadata({width:t,height:n,depth:o,interlace:!!d,palette:!!(i&r.COLORTYPE_PALETTE),color:!!(i&r.COLORTYPE_COLOR),alpha:!!(i&r.COLORTYPE_ALPHA),bpp:l,colorType:i}),this._handleChunkEnd()},i.prototype._handlePLTE=function(e){this.read(e,this._parsePLTE.bind(this))},i.prototype._parsePLTE=function(e){this._crc.write(e);let t=Math.floor(e.length/3);for(let n=0;n<t;n++)this._palette.push([e[3*n],e[3*n+1],e[3*n+2],255]);this.palette(this._palette),this._handleChunkEnd()},i.prototype._handleTRNS=function(e){this.simpleTransparency(),this.read(e,this._parseTRNS.bind(this))},i.prototype._parseTRNS=function(e){if(this._crc.write(e),this._colorType===r.COLORTYPE_PALETTE_COLOR){if(0===this._palette.length)return void this.error(Error("Transparency chunk must be after palette"));if(e.length>this._palette.length)return void this.error(Error("More transparent colors than palette size"));for(let t=0;t<e.length;t++)this._palette[t][3]=e[t];this.palette(this._palette)}this._colorType===r.COLORTYPE_GRAYSCALE&&this.transColor([e.readUInt16BE(0)]),this._colorType===r.COLORTYPE_COLOR&&this.transColor([e.readUInt16BE(0),e.readUInt16BE(2),e.readUInt16BE(4)]),this._handleChunkEnd()},i.prototype._handleGAMA=function(e){this.read(e,this._parseGAMA.bind(this))},i.prototype._parseGAMA=function(e){this._crc.write(e),this.gamma(e.readUInt32BE(0)/r.GAMMA_DIVISION),this._handleChunkEnd()},i.prototype._handleIDAT=function(e){this._emittedHeadersFinished||(this._emittedHeadersFinished=!0,this.headersFinished()),this.read(-e,this._parseIDAT.bind(this,e))},i.prototype._parseIDAT=function(e,t){if(this._crc.write(t),this._colorType===r.COLORTYPE_PALETTE_COLOR&&0===this._palette.length)throw Error("Expected palette not found");this.inflateData(t);let n=e-t.length;n>0?this._handleIDAT(n):this._handleChunkEnd()},i.prototype._handleIEND=function(e){this.read(e,this._parseIEND.bind(this))},i.prototype._parseIEND=function(e){this._crc.write(e),this._hasIEND=!0,this._handleChunkEnd(),this.finished&&this.finished()}},"../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/png-sync.js"(e,t,n){let r=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/parser-sync.js"),o=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/packer-sync.js");t.read=function(e,t){return r(e,t||{})},t.write=function(e,t){return o(e,t)}},"../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/png.js"(e,t,n){let r=n("util"),o=n("stream"),i=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/parser-async.js"),s=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/packer-async.js"),a=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/png-sync.js"),d=t.O=function(e){o.call(this),e=e||{},this.width=0|e.width,this.height=0|e.height,this.data=this.width>0&&this.height>0?Buffer.alloc(4*this.width*this.height):null,e.fill&&this.data&&this.data.fill(0),this.gamma=0,this.readable=this.writable=!0,this._parser=new i(e),this._parser.on("error",this.emit.bind(this,"error")),this._parser.on("close",this._handleClose.bind(this)),this._parser.on("metadata",this._metadata.bind(this)),this._parser.on("gamma",this._gamma.bind(this)),this._parser.on("parsed",(function(e){this.data=e,this.emit("parsed",e)}).bind(this)),this._packer=new s(e),this._packer.on("data",this.emit.bind(this,"data")),this._packer.on("end",this.emit.bind(this,"end")),this._parser.on("close",this._handleClose.bind(this)),this._packer.on("error",this.emit.bind(this,"error"))};r.inherits(d,o),d.sync=a,d.prototype.pack=function(){return this.data&&this.data.length?process.nextTick((function(){this._packer.pack(this.data,this.width,this.height,this.gamma)}).bind(this)):this.emit("error","No data provided"),this},d.prototype.parse=function(e,t){if(t){let e,n;e=(function(e){this.removeListener("error",n),this.data=e,t(null,this)}).bind(this),n=(function(n){this.removeListener("parsed",e),t(n,null)}).bind(this),this.once("parsed",e),this.once("error",n)}return this.end(e),this},d.prototype.write=function(e){return this._parser.write(e),!0},d.prototype.end=function(e){this._parser.end(e)},d.prototype._metadata=function(e){this.width=e.width,this.height=e.height,this.emit("metadata",e)},d.prototype._gamma=function(e){this.gamma=e},d.prototype._handleClose=function(){this._parser.writable||this._packer.readable||this.emit("close")},d.bitblt=function(e,t,n,r,o,i,s,a){if(r|=0,o|=0,i|=0,s|=0,a|=0,(n|=0)>e.width||r>e.height||n+o>e.width||r+i>e.height)throw Error("bitblt reading outside image");if(s>t.width||a>t.height||s+o>t.width||a+i>t.height)throw Error("bitblt writing outside image");for(let d=0;d<i;d++)e.data.copy(t.data,(a+d)*t.width+s<<2,(r+d)*e.width+n<<2,(r+d)*e.width+n+o<<2)},d.prototype.bitblt=function(e,t,n,r,o,i,s){return d.bitblt(this,e,t,n,r,o,i,s),this},d.adjustGamma=function(e){if(e.gamma){for(let t=0;t<e.height;t++)for(let n=0;n<e.width;n++){let r=e.width*t+n<<2;for(let t=0;t<3;t++){let n=e.data[r+t]/255;n=Math.pow(n,1/2.2/e.gamma),e.data[r+t]=Math.round(255*n)}}e.gamma=0}},d.prototype.adjustGamma=function(){d.adjustGamma(this)}},"../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/sync-inflate.js"(e,t,n){let r=n("assert").ok,o=n("zlib"),i=n("util"),s=n("buffer").kMaxLength;function a(e){if(!(this instanceof a))return new a(e);e&&e.chunkSize<o.Z_MIN_CHUNK&&(e.chunkSize=o.Z_MIN_CHUNK),o.Inflate.call(this,e),this._offset=void 0===this._offset?this._outOffset:this._offset,this._buffer=this._buffer||this._outBuffer,e&&null!=e.maxLength&&(this._maxLength=e.maxLength)}function d(e,t){t&&process.nextTick(t),e._handle&&(e._handle.close(),e._handle=null)}function l(e,t){var n=new a(t),r=e;if("string"==typeof r&&(r=Buffer.from(r)),!(r instanceof Buffer))throw TypeError("Not a string or buffer");let i=n._finishFlushFlag;return null==i&&(i=o.Z_FINISH),n._processChunk(r,i)}a.prototype._processChunk=function(e,t,n){let i,a;if("function"==typeof n)return o.Inflate._processChunk.call(this,e,t,n);let l=this,c=e&&e.length,u=this._chunkSize-this._offset,p=this._maxLength,h=0,f=[],m=0;this.on("error",function(e){i=e}),r(this._handle,"zlib binding closed");do a=(a=this._handle.writeSync(t,e,h,c,this._buffer,this._offset,u))||this._writeState;while(!this._hadError&&function(e,t){if(l._hadError)return;let n=u-t;if(r(n>=0,"have should not go down"),n>0){let e=l._buffer.slice(l._offset,l._offset+n);if(l._offset+=n,e.length>p&&(e=e.slice(0,p)),f.push(e),m+=e.length,0==(p-=e.length))return!1}return(0===t||l._offset>=l._chunkSize)&&(u=l._chunkSize,l._offset=0,l._buffer=Buffer.allocUnsafe(l._chunkSize)),0===t&&(h+=c-e,c=e,!0)}(a[0],a[1]));if(this._hadError)throw i;if(m>=s)throw d(this),RangeError("Cannot create final Buffer. It would be larger than 0x"+s.toString(16)+" bytes");let g=Buffer.concat(f,m);return d(this),g},i.inherits(a,o.Inflate),e.exports=t=l,t.Inflate=a,t.createInflate=function(e){return new a(e)},t.inflateSync=l},"../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/sync-reader.js"(e){let t=e.exports=function(e){this._buffer=e,this._reads=[]};t.prototype.read=function(e,t){this._reads.push({length:Math.abs(e),allowLess:e<0,func:t})},t.prototype.process=function(){for(;this._reads.length>0&&this._buffer.length;){let e=this._reads[0];if(this._buffer.length&&(this._buffer.length>=e.length||e.allowLess)){this._reads.shift();let t=this._buffer;this._buffer=t.slice(e.length),e.func.call(this,t.slice(0,e.length))}else break}return this._reads.length>0?Error("There are some read requests waitng on finished stream"):this._buffer.length>0?Error("unrecognised content at end of stream"):void 0}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/browser.js"(e,t,n){let r=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/can-promise.js"),o=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/qrcode.js"),i=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/canvas.js"),s=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/svg-tag.js");function a(e,t,n,i,s){let a=[].slice.call(arguments,1),d=a.length,l="function"==typeof a[d-1];if(!l&&!r())throw Error("Callback required as last argument");if(l){if(d<2)throw Error("Too few arguments provided");2===d?(s=n,n=t,t=i=void 0):3===d&&(t.getContext&&void 0===s?(s=i,i=void 0):(s=i,i=n,n=t,t=void 0))}else{if(d<1)throw Error("Too few arguments provided");return 1===d?(n=t,t=i=void 0):2!==d||t.getContext||(i=n,n=t,t=void 0),new Promise(function(r,s){try{let s=o.create(n,i);r(e(s,t,i))}catch(e){s(e)}})}try{let r=o.create(n,i);s(null,e(r,t,i))}catch(e){s(e)}}o.create,a.bind(null,i.render),a.bind(null,i.renderToDataURL),a.bind(null,function(e,t,n){return s.render(e,n)})},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/can-promise.js"(e){e.exports=function(){return"function"==typeof Promise&&Promise.prototype&&Promise.prototype.then}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/alignment-pattern.js"(e,t,n){let r=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/utils.js").getSymbolSize;t.getRowColCoords=function(e){if(1===e)return[];let t=Math.floor(e/7)+2,n=r(e),o=145===n?26:2*Math.ceil((n-13)/(2*t-2)),i=[n-7];for(let e=1;e<t-1;e++)i[e]=i[e-1]-o;return i.push(6),i.reverse()},t.getPositions=function(e){let n=[],r=t.getRowColCoords(e),o=r.length;for(let e=0;e<o;e++)for(let t=0;t<o;t++)(0!==e||0!==t)&&(0!==e||t!==o-1)&&(e!==o-1||0!==t)&&n.push([r[e],r[t]]);return n}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/alphanumeric-data.js"(e,t,n){let r=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/mode.js"),o=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"," ","$","%","*","+","-",".","/",":"];function i(e){this.mode=r.ALPHANUMERIC,this.data=e}i.getBitsLength=function(e){return 11*Math.floor(e/2)+e%2*6},i.prototype.getLength=function(){return this.data.length},i.prototype.getBitsLength=function(){return i.getBitsLength(this.data.length)},i.prototype.write=function(e){let t;for(t=0;t+2<=this.data.length;t+=2){let n=45*o.indexOf(this.data[t]);n+=o.indexOf(this.data[t+1]),e.put(n,11)}this.data.length%2&&e.put(o.indexOf(this.data[t]),6)},e.exports=i},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/bit-buffer.js"(e){function t(){this.buffer=[],this.length=0}t.prototype={get:function(e){let t=Math.floor(e/8);return(this.buffer[t]>>>7-e%8&1)==1},put:function(e,t){for(let n=0;n<t;n++)this.putBit((e>>>t-n-1&1)==1)},getLengthInBits:function(){return this.length},putBit:function(e){let t=Math.floor(this.length/8);this.buffer.length<=t&&this.buffer.push(0),e&&(this.buffer[t]|=128>>>this.length%8),this.length++}},e.exports=t},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/bit-matrix.js"(e){function t(e){if(!e||e<1)throw Error("BitMatrix size must be defined and greater than 0");this.size=e,this.data=new Uint8Array(e*e),this.reservedBit=new Uint8Array(e*e)}t.prototype.set=function(e,t,n,r){let o=e*this.size+t;this.data[o]=n,r&&(this.reservedBit[o]=!0)},t.prototype.get=function(e,t){return this.data[e*this.size+t]},t.prototype.xor=function(e,t,n){this.data[e*this.size+t]^=n},t.prototype.isReserved=function(e,t){return this.reservedBit[e*this.size+t]},e.exports=t},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/byte-data.js"(e,t,n){let r=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/mode.js");function o(e){this.mode=r.BYTE,"string"==typeof e?this.data=new TextEncoder().encode(e):this.data=new Uint8Array(e)}o.getBitsLength=function(e){return 8*e},o.prototype.getLength=function(){return this.data.length},o.prototype.getBitsLength=function(){return o.getBitsLength(this.data.length)},o.prototype.write=function(e){for(let t=0,n=this.data.length;t<n;t++)e.put(this.data[t],8)},e.exports=o},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/error-correction-code.js"(e,t,n){let r=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/error-correction-level.js"),o=[1,1,1,1,1,1,1,1,1,1,2,2,1,2,2,4,1,2,4,4,2,4,4,4,2,4,6,5,2,4,6,6,2,5,8,8,4,5,8,8,4,5,8,11,4,8,10,11,4,9,12,16,4,9,16,16,6,10,12,18,6,10,17,16,6,11,16,19,6,13,18,21,7,14,21,25,8,16,20,25,8,17,23,25,9,17,23,34,9,18,25,30,10,20,27,32,12,21,29,35,12,23,34,37,12,25,34,40,13,26,35,42,14,28,38,45,15,29,40,48,16,31,43,51,17,33,45,54,18,35,48,57,19,37,51,60,19,38,53,63,20,40,56,66,21,43,59,70,22,45,62,74,24,47,65,77,25,49,68,81],i=[7,10,13,17,10,16,22,28,15,26,36,44,20,36,52,64,26,48,72,88,36,64,96,112,40,72,108,130,48,88,132,156,60,110,160,192,72,130,192,224,80,150,224,264,96,176,260,308,104,198,288,352,120,216,320,384,132,240,360,432,144,280,408,480,168,308,448,532,180,338,504,588,196,364,546,650,224,416,600,700,224,442,644,750,252,476,690,816,270,504,750,900,300,560,810,960,312,588,870,1050,336,644,952,1110,360,700,1020,1200,390,728,1050,1260,420,784,1140,1350,450,812,1200,1440,480,868,1290,1530,510,924,1350,1620,540,980,1440,1710,570,1036,1530,1800,570,1064,1590,1890,600,1120,1680,1980,630,1204,1770,2100,660,1260,1860,2220,720,1316,1950,2310,750,1372,2040,2430];t.getBlocksCount=function(e,t){switch(t){case r.L:return o[(e-1)*4+0];case r.M:return o[(e-1)*4+1];case r.Q:return o[(e-1)*4+2];case r.H:return o[(e-1)*4+3];default:return}},t.getTotalCodewordsCount=function(e,t){switch(t){case r.L:return i[(e-1)*4+0];case r.M:return i[(e-1)*4+1];case r.Q:return i[(e-1)*4+2];case r.H:return i[(e-1)*4+3];default:return}}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/error-correction-level.js"(e,t){t.L={bit:1},t.M={bit:0},t.Q={bit:3},t.H={bit:2},t.isValid=function(e){return e&&void 0!==e.bit&&e.bit>=0&&e.bit<4},t.from=function(e,n){if(t.isValid(e))return e;try{if("string"!=typeof e)throw Error("Param is not a string");switch(e.toLowerCase()){case"l":case"low":return t.L;case"m":case"medium":return t.M;case"q":case"quartile":return t.Q;case"h":case"high":return t.H;default:throw Error("Unknown EC Level: "+e)}}catch(e){return n}}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/finder-pattern.js"(e,t,n){let r=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/utils.js").getSymbolSize;t.getPositions=function(e){let t=r(e);return[[0,0],[t-7,0],[0,t-7]]}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/format-info.js"(e,t,n){let r=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/utils.js"),o=r.getBCHDigit(1335);t.getEncodedBits=function(e,t){let n=e.bit<<3|t,i=n<<10;for(;r.getBCHDigit(i)-o>=0;)i^=1335<<r.getBCHDigit(i)-o;return(n<<10|i)^21522}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/galois-field.js"(e,t){let n=new Uint8Array(512),r=new Uint8Array(256),o=1;for(let e=0;e<255;e++)n[e]=o,r[o]=e,256&(o<<=1)&&(o^=285);for(let e=255;e<512;e++)n[e]=n[e-255];t.exp=function(e){return n[e]},t.mul=function(e,t){return 0===e||0===t?0:n[r[e]+r[t]]}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/kanji-data.js"(e,t,n){let r=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/mode.js"),o=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/utils.js");function i(e){this.mode=r.KANJI,this.data=e}i.getBitsLength=function(e){return 13*e},i.prototype.getLength=function(){return this.data.length},i.prototype.getBitsLength=function(){return i.getBitsLength(this.data.length)},i.prototype.write=function(e){let t;for(t=0;t<this.data.length;t++){let n=o.toSJIS(this.data[t]);if(n>=33088&&n<=40956)n-=33088;else if(n>=57408&&n<=60351)n-=49472;else throw Error("Invalid SJIS character: "+this.data[t]+"\nMake sure your charset is UTF-8");n=(n>>>8&255)*192+(255&n),e.put(n,13)}},e.exports=i},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/mask-pattern.js"(e,t){t.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};t.isValid=function(e){return null!=e&&""!==e&&!isNaN(e)&&e>=0&&e<=7},t.from=function(e){return t.isValid(e)?parseInt(e,10):void 0},t.getPenaltyN1=function(e){let t=e.size,n=0,r=0,o=0,i=null,s=null;for(let a=0;a<t;a++){r=o=0,i=s=null;for(let d=0;d<t;d++){let t=e.get(a,d);t===i?r++:(r>=5&&(n+=3+(r-5)),i=t,r=1),(t=e.get(d,a))===s?o++:(o>=5&&(n+=3+(o-5)),s=t,o=1)}r>=5&&(n+=3+(r-5)),o>=5&&(n+=3+(o-5))}return n},t.getPenaltyN2=function(e){let t=e.size,n=0;for(let r=0;r<t-1;r++)for(let o=0;o<t-1;o++){let t=e.get(r,o)+e.get(r,o+1)+e.get(r+1,o)+e.get(r+1,o+1);(4===t||0===t)&&n++}return 3*n},t.getPenaltyN3=function(e){let t=e.size,n=0,r=0,o=0;for(let i=0;i<t;i++){r=o=0;for(let s=0;s<t;s++)r=r<<1&2047|e.get(i,s),s>=10&&(1488===r||93===r)&&n++,o=o<<1&2047|e.get(s,i),s>=10&&(1488===o||93===o)&&n++}return 40*n},t.getPenaltyN4=function(e){let t=0,n=e.data.length;for(let r=0;r<n;r++)t+=e.data[r];return 10*Math.abs(Math.ceil(100*t/n/5)-10)},t.applyMask=function(e,n){let r=n.size;for(let o=0;o<r;o++)for(let i=0;i<r;i++)n.isReserved(i,o)||n.xor(i,o,function(e,n,r){switch(e){case t.Patterns.PATTERN000:return(n+r)%2==0;case t.Patterns.PATTERN001:return n%2==0;case t.Patterns.PATTERN010:return r%3==0;case t.Patterns.PATTERN011:return(n+r)%3==0;case t.Patterns.PATTERN100:return(Math.floor(n/2)+Math.floor(r/3))%2==0;case t.Patterns.PATTERN101:return n*r%2+n*r%3==0;case t.Patterns.PATTERN110:return(n*r%2+n*r%3)%2==0;case t.Patterns.PATTERN111:return(n*r%3+(n+r)%2)%2==0;default:throw Error("bad maskPattern:"+e)}}(e,i,o))},t.getBestMask=function(e,n){let r=Object.keys(t.Patterns).length,o=0,i=1/0;for(let s=0;s<r;s++){n(s),t.applyMask(s,e);let r=t.getPenaltyN1(e)+t.getPenaltyN2(e)+t.getPenaltyN3(e)+t.getPenaltyN4(e);t.applyMask(s,e),r<i&&(i=r,o=s)}return o}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/mode.js"(e,t,n){let r=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/version-check.js"),o=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/regex.js");t.NUMERIC={id:"Numeric",bit:1,ccBits:[10,12,14]},t.ALPHANUMERIC={id:"Alphanumeric",bit:2,ccBits:[9,11,13]},t.BYTE={id:"Byte",bit:4,ccBits:[8,16,16]},t.KANJI={id:"Kanji",bit:8,ccBits:[8,10,12]},t.MIXED={bit:-1},t.getCharCountIndicator=function(e,t){if(!e.ccBits)throw Error("Invalid mode: "+e);if(!r.isValid(t))throw Error("Invalid version: "+t);return t>=1&&t<10?e.ccBits[0]:t<27?e.ccBits[1]:e.ccBits[2]},t.getBestModeForData=function(e){return o.testNumeric(e)?t.NUMERIC:o.testAlphanumeric(e)?t.ALPHANUMERIC:o.testKanji(e)?t.KANJI:t.BYTE},t.toString=function(e){if(e&&e.id)return e.id;throw Error("Invalid mode")},t.isValid=function(e){return e&&e.bit&&e.ccBits},t.from=function(e,n){if(t.isValid(e))return e;try{if("string"!=typeof e)throw Error("Param is not a string");switch(e.toLowerCase()){case"numeric":return t.NUMERIC;case"alphanumeric":return t.ALPHANUMERIC;case"kanji":return t.KANJI;case"byte":return t.BYTE;default:throw Error("Unknown mode: "+e)}}catch(e){return n}}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/numeric-data.js"(e,t,n){let r=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/mode.js");function o(e){this.mode=r.NUMERIC,this.data=e.toString()}o.getBitsLength=function(e){return 10*Math.floor(e/3)+(e%3?e%3*3+1:0)},o.prototype.getLength=function(){return this.data.length},o.prototype.getBitsLength=function(){return o.getBitsLength(this.data.length)},o.prototype.write=function(e){let t,n;for(t=0;t+3<=this.data.length;t+=3)n=parseInt(this.data.substr(t,3),10),e.put(n,10);let r=this.data.length-t;r>0&&(n=parseInt(this.data.substr(t),10),e.put(n,3*r+1))},e.exports=o},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/polynomial.js"(e,t,n){let r=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/galois-field.js");t.mul=function(e,t){let n=new Uint8Array(e.length+t.length-1);for(let o=0;o<e.length;o++)for(let i=0;i<t.length;i++)n[o+i]^=r.mul(e[o],t[i]);return n},t.mod=function(e,t){let n=new Uint8Array(e);for(;n.length-t.length>=0;){let e=n[0];for(let o=0;o<t.length;o++)n[o]^=r.mul(t[o],e);let o=0;for(;o<n.length&&0===n[o];)o++;n=n.slice(o)}return n},t.generateECPolynomial=function(e){let n=new Uint8Array([1]);for(let o=0;o<e;o++)n=t.mul(n,new Uint8Array([1,r.exp(o)]));return n}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/qrcode.js"(e,t,n){let r=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/utils.js"),o=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/error-correction-level.js"),i=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/bit-buffer.js"),s=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/bit-matrix.js"),a=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/alignment-pattern.js"),d=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/finder-pattern.js"),l=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/mask-pattern.js"),c=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/error-correction-code.js"),u=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/reed-solomon-encoder.js"),p=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/version.js"),h=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/format-info.js"),f=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/mode.js"),m=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/segments.js");function g(e,t,n){let r,o,i=e.size,s=h.getEncodedBits(t,n);for(r=0;r<15;r++)o=(s>>r&1)==1,r<6?e.set(r,8,o,!0):r<8?e.set(r+1,8,o,!0):e.set(i-15+r,8,o,!0),r<8?e.set(8,i-r-1,o,!0):r<9?e.set(8,15-r-1+1,o,!0):e.set(8,15-r-1,o,!0);e.set(i-8,8,1,!0)}t.create=function(e,t){let n,h;if(void 0===e||""===e)throw Error("No input text");let _=o.M;return void 0!==t&&(_=o.from(t.errorCorrectionLevel,o.M),n=p.from(t.version),h=l.from(t.maskPattern),t.toSJISFunc&&r.setToSJISFunction(t.toSJISFunc)),function(e,t,n,o){let h;if(Array.isArray(e))h=m.fromArray(e);else if("string"==typeof e){let r=t;if(!r){let t=m.rawSplit(e);r=p.getBestVersionForData(t,n)}h=m.fromString(e,r||40)}else throw Error("Invalid data");let _=p.getBestVersionForData(h,n);if(!_)throw Error("The amount of data is too big to be stored in a QR Code");if(t){if(t<_)throw Error("\nThe chosen QR Code version cannot contain this amount of data.\nMinimum version required to store current data is: "+_+".\n")}else t=_;let w=function(e,t,n){let o=new i;n.forEach(function(t){o.put(t.mode.bit,4),o.put(t.getLength(),f.getCharCountIndicator(t.mode,e)),t.write(o)});let s=(r.getSymbolTotalCodewords(e)-c.getTotalCodewordsCount(e,t))*8;for(o.getLengthInBits()+4<=s&&o.put(0,4);o.getLengthInBits()%8!=0;)o.putBit(0);let a=(s-o.getLengthInBits())/8;for(let e=0;e<a;e++)o.put(e%2?17:236,8);return function(e,t,n){let o,i,s=r.getSymbolTotalCodewords(t),a=s-c.getTotalCodewordsCount(t,n),d=c.getBlocksCount(t,n),l=s%d,p=d-l,h=Math.floor(s/d),f=Math.floor(a/d),m=f+1,g=h-f,_=new u(g),w=0,y=Array(d),b=Array(d),v=0,E=new Uint8Array(e.buffer);for(let e=0;e<d;e++){let t=e<p?f:m;y[e]=E.slice(w,w+t),b[e]=_.encode(y[e]),w+=t,v=Math.max(v,t)}let I=new Uint8Array(s),A=0;for(o=0;o<v;o++)for(i=0;i<d;i++)o<y[i].length&&(I[A++]=y[i][o]);for(o=0;o<g;o++)for(i=0;i<d;i++)I[A++]=b[i][o];return I}(o,e,t)}(t,n,h),y=new s(r.getSymbolSize(t));!function(e,t){let n=e.size,r=d.getPositions(t);for(let t=0;t<r.length;t++){let o=r[t][0],i=r[t][1];for(let t=-1;t<=7;t++)if(!(o+t<=-1)&&!(n<=o+t))for(let r=-1;r<=7;r++)i+r<=-1||n<=i+r||(t>=0&&t<=6&&(0===r||6===r)||r>=0&&r<=6&&(0===t||6===t)||t>=2&&t<=4&&r>=2&&r<=4?e.set(o+t,i+r,!0,!0):e.set(o+t,i+r,!1,!0))}}(y,t);let b=y.size;for(let e=8;e<b-8;e++){let t=e%2==0;y.set(e,6,t,!0),y.set(6,e,t,!0)}return!function(e,t){let n=a.getPositions(t);for(let t=0;t<n.length;t++){let r=n[t][0],o=n[t][1];for(let t=-2;t<=2;t++)for(let n=-2;n<=2;n++)-2===t||2===t||-2===n||2===n||0===t&&0===n?e.set(r+t,o+n,!0,!0):e.set(r+t,o+n,!1,!0)}}(y,t),g(y,n,0),t>=7&&function(e,t){let n,r,o,i=e.size,s=p.getEncodedBits(t);for(let t=0;t<18;t++)n=Math.floor(t/3),r=t%3+i-8-3,o=(s>>t&1)==1,e.set(n,r,o,!0),e.set(r,n,o,!0)}(y,t),!function(e,t){let n=e.size,r=-1,o=n-1,i=7,s=0;for(let a=n-1;a>0;a-=2)for(6===a&&a--;;){for(let n=0;n<2;n++)if(!e.isReserved(o,a-n)){let r=!1;s<t.length&&(r=(t[s]>>>i&1)==1),e.set(o,a-n,r),-1==--i&&(s++,i=7)}if((o+=r)<0||n<=o){o-=r,r=-r;break}}}(y,w),isNaN(o)&&(o=l.getBestMask(y,g.bind(null,y,n))),l.applyMask(o,y),g(y,n,o),{modules:y,version:t,errorCorrectionLevel:n,maskPattern:o,segments:h}}(e,n,_,h)}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/reed-solomon-encoder.js"(e,t,n){let r=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/polynomial.js");function o(e){this.genPoly=void 0,this.degree=e,this.degree&&this.initialize(this.degree)}o.prototype.initialize=function(e){this.degree=e,this.genPoly=r.generateECPolynomial(this.degree)},o.prototype.encode=function(e){if(!this.genPoly)throw Error("Encoder not initialized");let t=new Uint8Array(e.length+this.degree);t.set(e);let n=r.mod(t,this.genPoly),o=this.degree-n.length;if(o>0){let e=new Uint8Array(this.degree);return e.set(n,o),e}return n},e.exports=o},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/regex.js"(e,t){let n="[0-9]+",r="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+",o="(?:(?![A-Z0-9 $%*+\\-./:]|"+(r=r.replace(/u/g,"\\u"))+")(?:.|[\r\n]))+";t.KANJI=RegExp(r,"g"),t.BYTE_KANJI=RegExp("[^A-Z0-9 $%*+\\-./:]+","g"),t.BYTE=RegExp(o,"g"),t.NUMERIC=RegExp(n,"g"),t.ALPHANUMERIC=RegExp("[A-Z $%*+\\-./:]+","g");let i=RegExp("^"+r+"$"),s=RegExp("^"+n+"$"),a=RegExp("^[A-Z0-9 $%*+\\-./:]+$");t.testKanji=function(e){return i.test(e)},t.testNumeric=function(e){return s.test(e)},t.testAlphanumeric=function(e){return a.test(e)}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/segments.js"(e,t,n){let r=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/mode.js"),o=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/numeric-data.js"),i=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/alphanumeric-data.js"),s=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/byte-data.js"),a=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/kanji-data.js"),d=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/regex.js"),l=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/utils.js"),c=n("../../../node_modules/.pnpm/dijkstrajs@1.0.3/node_modules/dijkstrajs/dijkstra.js");function u(e){return unescape(encodeURIComponent(e)).length}function p(e,t,n){let r,o=[];for(;null!==(r=e.exec(n));)o.push({data:r[0],index:r.index,mode:t,length:r[0].length});return o}function h(e){let t,n,o=p(d.NUMERIC,r.NUMERIC,e),i=p(d.ALPHANUMERIC,r.ALPHANUMERIC,e);return l.isKanjiModeEnabled()?(t=p(d.BYTE,r.BYTE,e),n=p(d.KANJI,r.KANJI,e)):(t=p(d.BYTE_KANJI,r.BYTE,e),n=[]),o.concat(i,t,n).sort(function(e,t){return e.index-t.index}).map(function(e){return{data:e.data,mode:e.mode,length:e.length}})}function f(e,t){switch(t){case r.NUMERIC:return o.getBitsLength(e);case r.ALPHANUMERIC:return i.getBitsLength(e);case r.KANJI:return a.getBitsLength(e);case r.BYTE:return s.getBitsLength(e)}}function m(e,t){let n,d=r.getBestModeForData(e);if((n=r.from(t,d))!==r.BYTE&&n.bit<d.bit)throw Error('"'+e+'" cannot be encoded with mode '+r.toString(n)+".\n Suggested mode is: "+r.toString(d));switch(n===r.KANJI&&!l.isKanjiModeEnabled()&&(n=r.BYTE),n){case r.NUMERIC:return new o(e);case r.ALPHANUMERIC:return new i(e);case r.KANJI:return new a(e);case r.BYTE:return new s(e)}}t.fromArray=function(e){return e.reduce(function(e,t){return"string"==typeof t?e.push(m(t,null)):t.data&&e.push(m(t.data,t.mode)),e},[])},t.fromString=function(e,n){let o=function(e,t){let n={},o={start:{}},i=["start"];for(let s=0;s<e.length;s++){let a=e[s],d=[];for(let e=0;e<a.length;e++){let l=a[e],c=""+s+e;d.push(c),n[c]={node:l,lastCount:0},o[c]={};for(let e=0;e<i.length;e++){let s=i[e];n[s]&&n[s].node.mode===l.mode?(o[s][c]=f(n[s].lastCount+l.length,l.mode)-f(n[s].lastCount,l.mode),n[s].lastCount+=l.length):(n[s]&&(n[s].lastCount=l.length),o[s][c]=f(l.length,l.mode)+4+r.getCharCountIndicator(l.mode,t))}}i=d}for(let e=0;e<i.length;e++)o[i[e]].end=0;return{map:o,table:n}}(function(e){let t=[];for(let n=0;n<e.length;n++){let o=e[n];switch(o.mode){case r.NUMERIC:t.push([o,{data:o.data,mode:r.ALPHANUMERIC,length:o.length},{data:o.data,mode:r.BYTE,length:o.length}]);break;case r.ALPHANUMERIC:t.push([o,{data:o.data,mode:r.BYTE,length:o.length}]);break;case r.KANJI:t.push([o,{data:o.data,mode:r.BYTE,length:u(o.data)}]);break;case r.BYTE:t.push([{data:o.data,mode:r.BYTE,length:u(o.data)}])}}return t}(h(e,l.isKanjiModeEnabled())),n),i=c.find_path(o.map,"start","end"),s=[];for(let e=1;e<i.length-1;e++)s.push(o.table[i[e]].node);return t.fromArray(s.reduce(function(e,t){let n=e.length-1>=0?e[e.length-1]:null;return n&&n.mode===t.mode?e[e.length-1].data+=t.data:e.push(t),e},[]))},t.rawSplit=function(e){return t.fromArray(h(e,l.isKanjiModeEnabled()))}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/utils.js"(e,t){let n,r=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];t.getSymbolSize=function(e){if(!e)throw Error('"version" cannot be null or undefined');if(e<1||e>40)throw Error('"version" should be in range from 1 to 40');return 4*e+17},t.getSymbolTotalCodewords=function(e){return r[e]},t.getBCHDigit=function(e){let t=0;for(;0!==e;)t++,e>>>=1;return t},t.setToSJISFunction=function(e){if("function"!=typeof e)throw Error('"toSJISFunc" is not a valid function.');n=e},t.isKanjiModeEnabled=function(){return void 0!==n},t.toSJIS=function(e){return n(e)}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/version-check.js"(e,t){t.isValid=function(e){return!isNaN(e)&&e>=1&&e<=40}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/version.js"(e,t,n){let r=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/utils.js"),o=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/error-correction-code.js"),i=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/error-correction-level.js"),s=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/mode.js"),a=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/version-check.js"),d=r.getBCHDigit(7973);function l(e,t){return s.getCharCountIndicator(e,t)+4}t.from=function(e,t){return a.isValid(e)?parseInt(e,10):t},t.getCapacity=function(e,t,n){if(!a.isValid(e))throw Error("Invalid QR Code version");void 0===n&&(n=s.BYTE);let i=(r.getSymbolTotalCodewords(e)-o.getTotalCodewordsCount(e,t))*8;if(n===s.MIXED)return i;let d=i-l(n,e);switch(n){case s.NUMERIC:return Math.floor(d/10*3);case s.ALPHANUMERIC:return Math.floor(d/11*2);case s.KANJI:return Math.floor(d/13);case s.BYTE:default:return Math.floor(d/8)}},t.getBestVersionForData=function(e,n){let r,o=i.from(n,i.M);if(Array.isArray(e)){if(e.length>1){for(let n=1;n<=40;n++)if(function(e,t){let n=0;return e.forEach(function(e){let r=l(e.mode,t);n+=r+e.getBitsLength()}),n}(e,n)<=t.getCapacity(n,o,s.MIXED))return n;return}if(0===e.length)return 1;r=e[0]}else r=e;return function(e,n,r){for(let o=1;o<=40;o++)if(n<=t.getCapacity(o,r,e))return o}(r.mode,r.getLength(),o)},t.getEncodedBits=function(e){if(!a.isValid(e)||e<7)throw Error("Invalid QR Code version");let t=e<<12;for(;r.getBCHDigit(t)-d>=0;)t^=7973<<r.getBCHDigit(t)-d;return e<<12|t}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/index.js"(e,t,n){e.exports=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/server.js")},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/canvas.js"(e,t,n){let r=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/utils.js");t.render=function(e,t,n){var o;let i=n,s=t;void 0!==i||t&&t.getContext||(i=t,t=void 0),t||(s=function(){try{return document.createElement("canvas")}catch(e){throw Error("You need to specify a canvas element")}}()),i=r.getOptions(i);let a=r.getImageWidth(e.modules.size,i),d=s.getContext("2d"),l=d.createImageData(a,a);return r.qrToImageData(l.data,e,i),o=s,d.clearRect(0,0,o.width,o.height),o.style||(o.style={}),o.height=a,o.width=a,o.style.height=a+"px",o.style.width=a+"px",d.putImageData(l,0,0),s},t.renderToDataURL=function(e,n,r){let o=r;void 0!==o||n&&n.getContext||(o=n,n=void 0),o||(o={});let i=t.render(e,n,o),s=o.type||"image/png",a=o.rendererOpts||{};return i.toDataURL(s,a.quality)}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/png.js"(e,t,n){let r=n("fs"),o=n("../../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/png.js").O,i=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/utils.js");t.render=function(e,t){let n=i.getOptions(t),r=n.rendererOpts,s=i.getImageWidth(e.modules.size,n);r.width=s,r.height=s;let a=new o(r);return i.qrToImageData(a.data,e,n),a},t.renderToDataURL=function(e,n,r){void 0===r&&(r=n,n=void 0),t.renderToBuffer(e,n,function(e,t){e&&r(e);let n="data:image/png;base64,";n+=t.toString("base64"),r(null,n)})},t.renderToBuffer=function(e,n,r){void 0===r&&(r=n,n=void 0);let o=t.render(e,n),i=[];o.on("error",r),o.on("data",function(e){i.push(e)}),o.on("end",function(){r(null,Buffer.concat(i))}),o.pack()},t.renderToFile=function(e,n,o,i){void 0===i&&(i=o,o=void 0);let s=!1,a=(...e)=>{s||(s=!0,i.apply(null,e))},d=r.createWriteStream(e);d.on("error",a),d.on("close",a),t.renderToFileStream(d,n,o)},t.renderToFileStream=function(e,n,r){t.render(n,r).pack().pipe(e)}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/svg-tag.js"(e,t,n){let r=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/utils.js");function o(e,t){let n=e.a/255,r=t+'="'+e.hex+'"';return n<1?r+" "+t+'-opacity="'+n.toFixed(2).slice(1)+'"':r}function i(e,t,n){let r=e+t;return void 0!==n&&(r+=" "+n),r}t.render=function(e,t,n){let s=r.getOptions(t),a=e.modules.size,d=e.modules.data,l=a+2*s.margin,c=s.color.light.a?"<path "+o(s.color.light,"fill")+' d="M0 0h'+l+"v"+l+'H0z"/>':"",u="<path "+o(s.color.dark,"stroke")+' d="'+function(e,t,n){let r="",o=0,s=!1,a=0;for(let d=0;d<e.length;d++){let l=Math.floor(d%t),c=Math.floor(d/t);l||s||(s=!0),e[d]?(a++,d>0&&l>0&&e[d-1]||(r+=s?i("M",l+n,.5+c+n):i("m",o,0),o=0,s=!1),l+1<t&&e[d+1]||(r+=i("h",a),a=0)):o++}return r}(d,a,s.margin)+'"/>',p='<svg xmlns="http://www.w3.org/2000/svg" '+(s.width?'width="'+s.width+'" height="'+s.width+'" ':"")+('viewBox="0 0 '+l+" ")+l+'" shape-rendering="crispEdges">'+c+u+"</svg>\n";return"function"==typeof n&&n(null,p),p}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/svg.js"(e,t,n){t.render=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/svg-tag.js").render,t.renderToFile=function(e,r,o,i){void 0===i&&(i=o,o=void 0);let s=n("fs"),a=t.render(r,o);s.writeFile(e,'<?xml version="1.0" encoding="utf-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">'+a,i)}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/terminal.js"(e,t,n){let r=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/terminal/terminal.js"),o=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/terminal/terminal-small.js");t.render=function(e,t,n){return t&&t.small?o.render(e,t,n):r.render(e,t,n)}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/terminal/terminal-small.js"(e,t){let n="\x1b[37m",r="\x1b[30m",o="\x1b[0m",i="\x1b[47m"+r,s="\x1b[40m"+n,a=function(e,t,n,r){let o=t+1;return n>=o||r>=o||r<-1||n<-1?"0":n>=t||r>=t||r<0||n<0?"1":e[r*t+n]?"2":"1"},d=function(e,t,n,r){return a(e,t,n,r)+a(e,t,n,r+1)};t.render=function(e,t,a){var l,c;let u=e.modules.size,p=e.modules.data,h=!!(t&&t.inverse),f=t&&t.inverse?s:i,m={"00":o+" "+f,"01":o+(l=h?r:n)+"▄"+f,"02":o+(c=h?n:r)+"▄"+f,10:o+l+"▀"+f,11:" ",12:"▄",20:o+c+"▀"+f,21:"▀",22:"█"},g=o+"\n"+f,_=f;for(let e=-1;e<u+1;e+=2){for(let t=-1;t<u;t++)_+=m[d(p,u,t,e)];_+=m[d(p,u,u,e)]+g}return _+=o,"function"==typeof a&&a(null,_),_}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/terminal/terminal.js"(e,t){t.render=function(e,t,n){let r=e.modules.size,o=e.modules.data,i="\x1b[47m \x1b[0m",s="",a=Array(r+3).join(i),d=[,,].join(i);s+=a+"\n";for(let e=0;e<r;++e){s+=i;for(let t=0;t<r;t++)s+=o[e*r+t]?"\x1b[40m \x1b[0m":i;s+=d+"\n"}return s+=a+"\n","function"==typeof n&&n(null,s),s}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/utf8.js"(e,t,n){let r=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/utils.js"),o={WW:" ",WB:"▄",BB:"█",BW:"▀"},i={BB:" ",BW:"▄",WW:"█",WB:"▀"};t.render=function(e,t,n){let s=r.getOptions(t),a=o;("#ffffff"===s.color.dark.hex||"#000000"===s.color.light.hex)&&(a=i);let d=e.modules.size,l=e.modules.data,c="",u=Array(d+2*s.margin+1).join(a.WW);u=Array(s.margin/2+1).join(u+"\n");let p=Array(s.margin+1).join(a.WW);c+=u;for(let e=0;e<d;e+=2){c+=p;for(let t=0;t<d;t++){var h;let n=l[e*d+t],r=l[(e+1)*d+t];c+=(h=a,n&&r?h.BB:n&&!r?h.BW:!n&&r?h.WB:h.WW)}c+=p+"\n"}return c+=u.slice(0,-1),"function"==typeof n&&n(null,c),c},t.renderToFile=function(e,r,o,i){void 0===i&&(i=o,o=void 0);let s=n("fs"),a=t.render(r,o);s.writeFile(e,a,i)}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/utils.js"(e,t){function n(e){if("number"==typeof e&&(e=e.toString()),"string"!=typeof e)throw Error("Color should be defined as hex string");let t=e.slice().replace("#","").split("");if(t.length<3||5===t.length||t.length>8)throw Error("Invalid hex color: "+e);(3===t.length||4===t.length)&&(t=Array.prototype.concat.apply([],t.map(function(e){return[e,e]}))),6===t.length&&t.push("F","F");let n=parseInt(t.join(""),16);return{r:n>>24&255,g:n>>16&255,b:n>>8&255,a:255&n,hex:"#"+t.slice(0,6).join("")}}t.getOptions=function(e){e||(e={}),e.color||(e.color={});let t=void 0===e.margin||null===e.margin||e.margin<0?4:e.margin,r=e.width&&e.width>=21?e.width:void 0,o=e.scale||4;return{width:r,scale:r?4:o,margin:t,color:{dark:n(e.color.dark||"#000000ff"),light:n(e.color.light||"#ffffffff")},type:e.type,rendererOpts:e.rendererOpts||{}}},t.getScale=function(e,t){return t.width&&t.width>=e+2*t.margin?t.width/(e+2*t.margin):t.scale},t.getImageWidth=function(e,n){let r=t.getScale(e,n);return Math.floor((e+2*n.margin)*r)},t.qrToImageData=function(e,n,r){let o=n.modules.size,i=n.modules.data,s=t.getScale(o,r),a=Math.floor((o+2*r.margin)*s),d=r.margin*s,l=[r.color.light,r.color.dark];for(let t=0;t<a;t++)for(let n=0;n<a;n++){let c=(t*a+n)*4,u=r.color.light;t>=d&&n>=d&&t<a-d&&n<a-d&&(u=l[+!!i[Math.floor((t-d)/s)*o+Math.floor((n-d)/s)]]),e[c++]=u.r,e[c++]=u.g,e[c++]=u.b,e[c]=u.a}}},"../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/server.js"(e,t,n){let r=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/can-promise.js"),o=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/qrcode.js"),i=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/png.js"),s=n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/utf8.js"),a=(n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/terminal.js"),n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/svg.js"));function d(e,t,n){if(void 0===e)throw Error("String required as first argument");if(void 0===n&&(n=t,t={}),"function"!=typeof n)if(r())t=n||{},n=null;else throw Error("Callback required as last argument");return{opts:t,cb:n}}function l(e){switch(e){case"svg":return a;case"txt":case"utf8":return s;default:return i}}function c(e,t,n){if(!n.cb)return new Promise(function(r,i){try{let s=o.create(t,n.opts);return e(s,n.opts,function(e,t){return e?i(e):r(t)})}catch(e){i(e)}});try{let r=o.create(t,n.opts);return e(r,n.opts,n.cb)}catch(e){n.cb(e)}}o.create,n("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/browser.js"),t.toBuffer=function(e,t,n){let r=d(e,t,n);return c(l(r.opts.type).renderToBuffer,e,r)},t.toFile=function(e,t,n,o){if("string"!=typeof e||"string"!=typeof t&&"object"!=typeof t)throw Error("Invalid argument");if(arguments.length<3&&!r())throw Error("Too few arguments provided");let i=d(t,n,o);return c(l(i.opts.type||e.slice((e.lastIndexOf(".")-1>>>0)+2).toLowerCase()).renderToFile.bind(null,e),t,i)}},"../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.26/node_modules/@byted-doubao-apps/auth-cli/dist/config.js"(e,t,n){var r=n("node:os"),o=n("node:path");let i=o.join(r.homedir(),".dbx","token"),s=o.join(r.homedir(),".doubao","token"),a={};function d(e){Object.assign(a,e)}function l(e={}){let t={...a,...e},n=function(e,t){let n;try{n=new URL(c(e))}catch{throw Error(`${t} must be an absolute HTTPS URL`)}if("https:"!==n.protocol)throw Error(`${t} must use https`);return c(n.toString())}(t.baseUrl??"https://developer.doubao.com","baseUrl"),r=t.tokenPath??i;return{...t,baseUrl:n,allowedOrigins:function(e,t){let n=new Set([new URL(t).origin]);for(let t of e??[]){let e;try{e=new URL(t)}catch{throw Error(`allowedOrigins entries must be absolute HTTPS origins: ${t}`)}if("https:"!==e.protocol)throw Error(`allowedOrigins entries must use https: ${t}`);n.add(e.origin)}return[...n]}(t.allowedOrigins,n),tokenPath:r,legacyTokenPath:t.tokenPath?void 0:s,requestHeaders:new Headers(t.requestHeaders)}}function c(e){return e.replace(/\/+$/,"")}n.d(t,{$i:()=>l,ZI:()=>d},{E:"dbx-cli"})},"../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.26/node_modules/@byted-doubao-apps/auth-cli/dist/credential-store.js"(e,t,n){var r=n("node:child_process"),o=n("node:crypto"),i=n("node:fs"),s=n("node:os"),a=n("node:path");let d=(0,n("node:util").promisify)(r.execFile),l="byted-doubao-open-dbx-cli",c="dbx-cli",u="aes-256-gcm";class p extends Error{constructor(e){super(e),this.name="CredentialStoreError"}}function h(){let e=new m;return"darwin"===process.platform?new f(new g,e):"linux"===process.platform?new f(new _,e):e}class f{constructor(e,t){this.primary=e,this.fallback=t}async get(e){let t;try{let t=await this.primary.get(e);if(t)return t}catch(e){t=e}try{let t=await this.fallback.get(e);if(t)return t}catch(e){if(t)throw new p(`Failed to read token from system credential store (${A(t)}); encrypted-file fallback also failed: ${A(e)}`);throw e}if(t)throw t instanceof Error?t:new p(`Failed to read token from system credential store: ${String(t)}`)}async set(e,t){let n;try{await this.primary.set(e,t)}catch(e){n=e}try{await this.fallback.set(e,t)}catch(e){if(n)throw new p(`Failed to write token to system credential store (${A(n)}) and encrypted-file fallback (${A(e)})`);throw e}}async delete(e){let t;try{await this.primary.delete(e)}catch(e){t=e}try{await this.fallback.delete(e)}catch(e){if(t)throw new p(`Failed to delete token from system credential store (${A(t)}) and encrypted-file fallback (${A(e)})`);throw e}}}class m{constructor(e={}){this.baseDir=e.baseDir??("darwin"===process.platform?a.join(s.homedir(),"Library","Application Support",c):"win32"===process.platform?a.join(process.env.APPDATA||a.join(s.homedir(),"AppData","Roaming"),c):a.join(process.env.XDG_DATA_HOME||a.join(s.homedir(),".local","share"),c))}async get(e){var t,n;let r,s,a=this.credentialFilePath(e);try{r=await i.promises.readFile(a,"utf8")}catch(e){if(I(e)&&"ENOENT"===e.code)return;throw new p(`Failed to read encrypted token file: ${A(e)}`)}try{s=JSON.parse(r)}catch(e){throw new p(`Encrypted token file is not valid JSON: ${A(e)}`)}if(!((t=s)&&"object"==typeof t&&1===t.version&&t.algorithm===u&&"string"==typeof t.iv&&"string"==typeof t.authTag&&"string"==typeof t.ciphertext))throw new p("Encrypted token file has an unsupported format");let d=await this.readMasterKey();try{let t=o.createDecipheriv(u,d,Buffer.from(s.iv,"base64url"));return t.setAAD(Buffer.from((n=e,`${l}:${n}`),"utf8")),t.setAuthTag(Buffer.from(s.authTag,"base64url")),Buffer.concat([t.update(Buffer.from(s.ciphertext,"base64url")),t.final()]).toString("utf8")}catch(e){throw new p(`Failed to decrypt encrypted token file: ${A(e)}`)}}async set(e,t){var n;let r=await this.readOrCreateMasterKey(),i=o.randomBytes(12),s=o.createCipheriv(u,r,i);s.setAAD(Buffer.from((n=e,`${l}:${n}`),"utf8"));let a=Buffer.concat([s.update(t,"utf8"),s.final()]),d={version:1,algorithm:u,iv:i.toString("base64url"),authTag:s.getAuthTag().toString("base64url"),ciphertext:a.toString("base64url")};await w(this.credentialFilePath(e),`${JSON.stringify(d,null,2)}
10
10
  `)}async delete(e){try{await i.promises.unlink(this.credentialFilePath(e))}catch(e){if(!I(e)||"ENOENT"!==e.code)throw new p(`Failed to delete encrypted token file: ${A(e)}`)}}masterKeyPath(){return a.join(this.baseDir,"master.key")}credentialFilePath(e){let t=o.createHash("sha256").update(e).digest("hex");return a.join(this.baseDir,"credentials",`${t}.json`)}async readMasterKey(){try{var e=await i.promises.readFile(this.masterKeyPath(),"utf8");let t=Buffer.from(e.trim(),"base64url");if(32!==t.length)throw new p("Encrypted token master key has an unsupported format");return t}catch(e){if(I(e)&&"ENOENT"===e.code)throw new p("Encrypted token master key is missing");if(e instanceof p)throw e;throw new p(`Failed to read encrypted token master key: ${A(e)}`)}}async readOrCreateMasterKey(){try{return await this.readMasterKey()}catch(e){if(!(e instanceof p)||!e.message.includes("master key is missing"))throw e}let e=o.randomBytes(32);try{return await w(this.masterKeyPath(),`${e.toString("base64url")}
11
- `),e}catch(e){if(I(e)&&"EEXIST"===e.code)return this.readMasterKey();throw new p(`Failed to write encrypted token master key: ${A(e)}`)}}}class g{async get(e){try{let{stdout:t}=await d("security",["find-generic-password","-a",e,"-s",l,"-w"]);return String(t).replace(/\n$/,"")}catch(e){if(y(e))return;throw new p(`Failed to read token from macOS Keychain: ${A(e)}`)}}async set(e,t){try{await d("security",["add-generic-password","-a",e,"-s",l,"-w",t,"-U"])}catch(e){throw new p(`Failed to write token to macOS Keychain: ${A(e)}`)}}async delete(e){try{await d("security",["delete-generic-password","-a",e,"-s",l])}catch(e){if(y(e))return;throw new p(`Failed to delete token from macOS Keychain: ${A(e)}`)}}}class _{async get(e){try{let{stdout:t}=await d("secret-tool",["lookup","service",l,"account",e]);return String(t).replace(/\n$/,"")}catch(e){if(b(e))return;throw new p(`Failed to read token from Secret Service: ${A(e)}`)}}async set(e,t){try{var n,o,i;await (n="secret-tool",o=["store","--label","Doubao Open CLI token","service",l,"account",e],i=t,new Promise((e,t)=>{let s=(0,r.spawn)(n,o,{stdio:["pipe","ignore","pipe"]}),a="";s.stderr.setEncoding("utf8"),s.stderr.on("data",e=>{a+=String(e)}),s.on("error",t),s.on("close",r=>{0===r?e():t(Error(a.trim()||`${n} exited with code ${r}`))}),s.stdin.end(i)}))}catch(e){throw new p(`Failed to write token to Secret Service: ${A(e)}`)}}async delete(e){try{await d("secret-tool",["clear","service",l,"account",e])}catch(e){if(b(e))return;throw new p(`Failed to delete token from Secret Service: ${A(e)}`)}}}async function w(e,t){let n=a.dirname(e);await i.promises.mkdir(n,{recursive:!0,mode:448}),"win32"!==process.platform&&await i.promises.chmod(n,448);let r=a.join(n,`.${a.basename(e)}.${process.pid}.${Date.now()}.tmp`);try{await i.promises.writeFile(r,t,{mode:384,flag:"wx"}),"win32"!==process.platform&&await i.promises.chmod(r,384),await i.promises.rename(r,e),"win32"!==process.platform&&await i.promises.chmod(e,384)}finally{try{await i.promises.unlink(r)}catch{}}}function y(e){let t=v(e),n=E(e);return(1===t||44===t)&&(n.includes("could not be found")||n.includes("The specified item could not be found"))}function b(e){let t=v(e),n=E(e);return 1===t&&(n.includes("could not be found")||n.includes("No matching items")||""===n.trim())}function v(e){return"object"==typeof e&&null!==e&&"code"in e?e.code:void 0}function E(e){return"object"==typeof e&&null!==e&&"stderr"in e?String(e.stderr??""):""}function I(e){return e instanceof Error&&"code"in e}function A(e){if("object"==typeof e&&null!==e&&"stderr"in e){let t=String(e.stderr??"").trim();if(t)return t}return e instanceof Error&&e.message?e.message:String(e)}n.d(t,{Mj:()=>h,RI:()=>p})},"../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.24/node_modules/@byted-doubao-apps/auth-cli/dist/device-flow.js"(e,t,n){var r=n("../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.24/node_modules/@byted-doubao-apps/auth-cli/dist/config.js"),o=n("../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.24/node_modules/@byted-doubao-apps/auth-cli/dist/errors.js"),i=n("../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.24/node_modules/@byted-doubao-apps/auth-cli/dist/jwt.js"),s=n("../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.24/node_modules/@byted-doubao-apps/auth-cli/dist/store.js"),a=n("../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.24/node_modules/@byted-doubao-apps/auth-cli/dist/types.js");async function d(e={}){let t=(0,r.$i)(e),n=t.fetch??fetch,l=t.sleep??w,c=await u(n,t.baseUrl,t.requestHeaders),h=y(t.baseUrl,c.user_code);t.onVerification?.({userCode:c.user_code,verificationUrl:h,expiresIn:c.expires_in,interval:c.interval});let f=Math.max(1,c.interval),m=Date.now()+1e3*c.expires_in;for(;Date.now()<m;){await l(1e3*f);let e=await p(n,t.baseUrl,c.device_code,t.requestHeaders);if(t.onPoll?.({status:e.status,interval:f}),e.status!==a.A.Pending){if(e.status===a.A.SlowDown){f+=Math.max(1,c.interval);continue}if(e.status===a.A.Expired)throw new o.JC("Device authorization expired","DEVICE_AUTH_EXPIRED");if(e.status===a.A.Invalid)throw new o.JC("Device authorization is invalid","DEVICE_AUTH_INVALID");if(e.status===a.A.Authorized){if(!e.access_token)throw new o.JC("Authorization response did not include an access token");let n=_(e,t.baseUrl);return await (0,s.tK)(t.tokenPath,n,{credentialStore:t.credentialStore}),{accessToken:n.accessToken,tokenType:n.tokenType,expiresAt:n.expiresAt,baseUrl:n.baseUrl,uid:(0,i.m)(n.accessToken),tokenPath:t.tokenPath}}throw new o.JC(`Unexpected authorization status: ${String(e.status)}`)}}throw new o.JC("Device authorization timed out","DEVICE_AUTH_EXPIRED")}async function l(e={}){let t=(0,r.$i)(e),n=t.fetch??fetch,o=await u(n,t.baseUrl,t.requestHeaders),i=y(t.baseUrl,o.user_code);return t.onVerification?.({userCode:o.user_code,verificationUrl:i,expiresIn:o.expires_in,interval:o.interval}),{userCode:o.user_code,deviceCode:o.device_code,verificationUrl:i,expiresIn:o.expires_in,interval:o.interval}}async function c(e,t={}){let n=(0,r.$i)(t),d=n.fetch??fetch,l=n.sleep??w,u=n.baseUrl,h=n.requestHeaders,f=5,m=Date.now()+6e5;for(;Date.now()<m;){await l(1e3*f);let t=await p(d,u,e,h);if(n.onPoll?.({status:t.status,interval:f}),t.status!==a.A.Pending){if(t.status===a.A.SlowDown){f+=5;continue}if(t.status===a.A.Expired)throw new o.JC("Device authorization expired","DEVICE_AUTH_EXPIRED");if(t.status===a.A.Invalid)throw new o.JC("Device authorization is invalid","DEVICE_AUTH_INVALID");if(t.status===a.A.Authorized){if(!t.access_token)throw new o.JC("Authorization response did not include an access token");let e=_(t,u);return await (0,s.tK)(n.tokenPath,e,{credentialStore:n.credentialStore}),{accessToken:e.accessToken,tokenType:e.tokenType,expiresAt:e.expiresAt,baseUrl:e.baseUrl,uid:(0,i.m)(e.accessToken),tokenPath:n.tokenPath}}throw new o.JC(`Unexpected authorization status: ${String(t.status)}`)}}throw new o.JC("Device authorization timed out","DEVICE_AUTH_EXPIRED")}async function u(e,t,n){let i=await e(`${t}/app_developer/oauth/device/code`,{method:"POST",headers:g(n),body:JSON.stringify({client_name:r.E})}),s=await h(i),a=m(s);if(!a||!a.device_code||!a.user_code||"number"!=typeof a.expires_in||"number"!=typeof a.interval)throw new o.JC(`Device code response is malformed (HTTP ${i.status}): ${JSON.stringify(s)}`);return a}async function p(e,t,n,r){let i=await e(`${t}/app_developer/oauth/token`,{method:"POST",headers:g(r),body:JSON.stringify({device_code:n})}),s=await h(i),d=m(s);if(d?.access_token)return{status:a.A.Authorized,access_token:d.access_token,token_type:d.token_type,expires_in:d.expires_in,expires_at:d.expires_at};if(!d||"number"!=typeof d.status)throw new o.JC(`Token response is malformed (HTTP ${i.status}): ${JSON.stringify(s)}`);return d}async function h(e){var t;let n,r=e.headers.get("x-tt-logid")??void 0;try{n=await e.json()}catch{throw new o.JC(`Auth server returned non-JSON response with status ${e.status}${f(r)}`,"DEVICE_AUTH_FAILED",{logId:r})}let i=function(e){if(e&&"object"==typeof e)return"string"==typeof e.log_id&&e.log_id?e.log_id:void 0}(n)??r;if(!e.ok)throw new o.JC(`Auth server returned HTTP ${e.status}: ${JSON.stringify(n)}${f(i)}`,"DEVICE_AUTH_FAILED",{logId:i});let s=(t=n)&&"object"==typeof t&&"number"==typeof t.code&&0!==t.code?{code:t.code,message:"string"==typeof t.message?t.message:"Unknown error",logId:"string"==typeof t.log_id?t.log_id:void 0}:null;if(s)throw new o.JC(`Auth server error (code ${s.code}): ${s.message}${f(s.logId??i)}`,"DEVICE_AUTH_FAILED",{logId:s.logId??i});return n}function f(e){return e?` [log_id: ${e}]`:""}function m(e){return e&&"object"==typeof e&&"data"in e?e.data:e}function g(e){let t=new Headers(e);return t.set("Content-Type","application/json"),t}function _(e,t){let n=Math.floor(Date.now()/1e3);return{accessToken:e.access_token??"",tokenType:e.token_type??"Bearer",expiresAt:"number"==typeof e.expires_at?e.expires_at:n+(e.expires_in??0),baseUrl:t}}function w(e){return new Promise(t=>{setTimeout(t,e)})}function y(e,t){let n=new URL(e).host,r=new URL(`https://${n}/oauth/device`);return r.searchParams.set("user_code",t),r.toString()}n.d(t,{R$:()=>c,c$:()=>l,iD:()=>d})},"../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.24/node_modules/@byted-doubao-apps/auth-cli/dist/errors.js"(e,t,n){class r extends Error{constructor(e,t){super(e),this.code=t,this.name="AuthError"}}class o extends r{constructor(e="Not logged in"){super(e,"NOT_LOGGED_IN"),this.name="NotLoggedInError"}}class i extends r{constructor(e="Login token has expired"){super(e,"TOKEN_EXPIRED"),this.name="TokenExpiredError"}}class s extends r{constructor(e,t="DEVICE_AUTH_FAILED",n={}){super(e,t),this.name="DeviceAuthError",this.logId=n.logId}}n.d(t,{BX:()=>i,JC:()=>s,bG:()=>o,lR:()=>r})},"../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.24/node_modules/@byted-doubao-apps/auth-cli/dist/http.js"(e,t,n){var r=n("../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.24/node_modules/@byted-doubao-apps/auth-cli/dist/errors.js"),o=n("../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.24/node_modules/@byted-doubao-apps/auth-cli/dist/config.js"),i=n("../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.24/node_modules/@byted-doubao-apps/auth-cli/dist/store.js");function s(e=fetch,t={}){return async(n,s={})=>{let a=(0,o.$i)(t);var d=n,l=a.allowedOrigins;let c=function(e){try{if("string"==typeof e)return new URL(e);if(e instanceof URL)return e;return new URL(e.url)}catch{throw Error("Authenticated requests must use an absolute HTTPS URL")}}(d);if("https:"!==c.protocol)throw Error(`Authenticated requests must use https: ${c.toString()}`);if(!l.includes(c.origin))throw Error(`Refusing to attach Authorization header to untrusted origin: ${c.origin}`);let u=await (0,i.AI)(a.tokenPath,{allowExpired:!0,envTokenBaseUrl:a.baseUrl,credentialStore:a.credentialStore,legacyTokenPath:a.legacyTokenPath});if(!u)throw new r.bG;if((0,i._d)(u))throw new r.BX;let p=new Headers(s.headers);return a.requestHeaders.forEach((e,t)=>{p.set(t,e)}),p.set("Authorization",`${u.tokenType||"Bearer"} ${u.accessToken}`),e(n,{...s,headers:p})}}n.d(t,{r:()=>s})},"../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.24/node_modules/@byted-doubao-apps/auth-cli/dist/index.js"(e,t,n){n.r(t);var r=n("../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.24/node_modules/@byted-doubao-apps/auth-cli/dist/config.js"),o=n("../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.24/node_modules/@byted-doubao-apps/auth-cli/dist/credential-store.js"),i=n("../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.24/node_modules/@byted-doubao-apps/auth-cli/dist/device-flow.js"),s=n("../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.24/node_modules/@byted-doubao-apps/auth-cli/dist/store.js"),a=n("../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.24/node_modules/@byted-doubao-apps/auth-cli/dist/http.js"),d=n("../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.24/node_modules/@byted-doubao-apps/auth-cli/dist/errors.js"),l=n("../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.24/node_modules/@byted-doubao-apps/auth-cli/dist/types.js");async function c(e={}){let t=(0,r.$i)(e);await (0,s.ni)(t.tokenPath,{credentialStore:t.credentialStore}),t.legacyTokenPath&&await (0,s.ni)(t.legacyTokenPath,{credentialStore:t.credentialStore})}async function u(e={}){let t,n=(0,r.$i)(e);try{t=await (0,s.AI)(n.tokenPath,{envTokenBaseUrl:n.baseUrl,credentialStore:n.credentialStore,legacyTokenPath:n.legacyTokenPath})}catch(e){if(e instanceof o.RI)return{loggedIn:!1,tokenPath:n.tokenPath,baseUrl:n.baseUrl,credentialError:{code:"CREDENTIAL_STORE_UNAVAILABLE",message:e.message}};throw e}if(!t)return{loggedIn:!1,tokenPath:n.tokenPath};let i=await p(e.fetch??fetch,n.baseUrl,t,n.requestHeaders);return i?{loggedIn:!0,uid:i.userId,name:i.name,avatar:i.avatar,expiresAt:t.expiresAt,tokenPath:n.tokenPath,baseUrl:n.baseUrl}:{loggedIn:!1,expiresAt:t.expiresAt,tokenPath:n.tokenPath,baseUrl:n.baseUrl}}async function p(e,t,n,r){let o=new Headers(r);o.set("Authorization",`${n.tokenType||"Bearer"} ${n.accessToken}`);let i=await e(`${t.replace(/\/+$/,"")}/app_developer/api/user/basic`,{method:"GET",headers:o});if(!i.ok)return;let s=await i.json();if(0===s.code){var a;return{userId:"string"==typeof(a=s.data?.user_id)&&a.length>0?a:"number"==typeof a&&Number.isFinite(a)?String(a):void 0,name:s.data?.name,avatar:s.data?.avatar}}}n.d(t,{AuthError:()=>d.lR,CredentialStoreError:()=>o.RI,DeviceAuthError:()=>d.JC,NotLoggedInError:()=>d.bG,TokenExpiredError:()=>d.BX,TokenStatus:()=>l.A,completeLogin:()=>i.R$,configureAuth:()=>r.ZI,login:()=>i.iD,logout:()=>c,startLogin:()=>i.c$,whoami:()=>u,withAuth:()=>a.r})},"../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.24/node_modules/@byted-doubao-apps/auth-cli/dist/jwt.js"(e,t,n){function r(e){let t=function(e){let t=e.split(".")[1];if(t)try{let e=t.replace(/-/g,"+").replace(/_/g,"/"),n=e.padEnd(e.length+(4-e.length%4)%4,"="),r=Buffer.from(n,"base64").toString("utf8"),o=JSON.parse(r);return o&&"object"==typeof o?o:void 0}catch{return}}(e),n=t?.uid??t?.sub;return"string"==typeof n&&n.length>0?n:"number"==typeof n&&Number.isFinite(n)?String(n):void 0}n.d(t,{m:()=>r})},"../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.24/node_modules/@byted-doubao-apps/auth-cli/dist/store.js"(e,t,n){var r=n("node:fs"),o=n("node:crypto"),i=n("node:path"),s=n("../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.24/node_modules/@byted-doubao-apps/auth-cli/dist/credential-store.js");async function a(e,t={}){let n,r=process.env.DBX_ACCESS_TOKEN?.trim()||void 0;if(r)return{accessToken:r,tokenType:"Bearer",expiresAt:0xf4865700,baseUrl:t.envTokenBaseUrl??""};let o=await h(e);if(void 0===o)return f(e,t);try{n=JSON.parse(o)}catch(e){return}if(p(n)){if(!t.allowExpired&&c(n))return void await l(e,t);let r=await m(t).get(n.credentialAccount);if(!r)throw new s.RI("Stored login metadata exists, but the token credential is missing or inaccessible. Run dbx auth login again from a terminal that can access the credential store.");return{accessToken:r,tokenType:n.tokenType,expiresAt:n.expiresAt,baseUrl:n.baseUrl}}if(u(n))return!t.allowExpired&&c(n)?void await l(e,t):(await d(e,n,t),n)}async function d(e,t,n={}){let o={version:2,storage:"keychain",credentialAccount:g(e),tokenType:t.tokenType,expiresAt:t.expiresAt,baseUrl:t.baseUrl};await m(n).set(o.credentialAccount,t.accessToken),await r.promises.mkdir(i.dirname(e),{recursive:!0,mode:448}),"win32"!==process.platform&&await r.promises.chmod(i.dirname(e),448);let s=`${e}.${process.pid}.${Date.now()}.tmp`;await r.promises.writeFile(s,`${JSON.stringify(o,null,2)}
12
- `,{mode:384}),"win32"!==process.platform&&await r.promises.chmod(s,384),await r.promises.rename(s,e),"win32"!==process.platform&&await r.promises.chmod(e,384)}async function l(e,t={}){let n=await h(e);if(void 0!==n)try{let r=JSON.parse(n);p(r)?await m(t).delete(r.credentialAccount):await m(t).delete(g(e))}catch{}try{await r.promises.unlink(e)}catch(e){if(!_(e)||"ENOENT"!==e.code)throw e}}function c(e,t=Math.floor(Date.now()/1e3)){return e.expiresAt<=t}function u(e){return!!e&&"object"==typeof e&&"string"==typeof e.accessToken&&e.accessToken.length>0&&"string"==typeof e.tokenType&&e.tokenType.length>0&&"number"==typeof e.expiresAt&&Number.isFinite(e.expiresAt)&&"string"==typeof e.baseUrl&&e.baseUrl.length>0}function p(e){return!!e&&"object"==typeof e&&2===e.version&&"keychain"===e.storage&&"string"==typeof e.credentialAccount&&e.credentialAccount.length>0&&"string"==typeof e.tokenType&&e.tokenType.length>0&&"number"==typeof e.expiresAt&&Number.isFinite(e.expiresAt)&&"string"==typeof e.baseUrl&&e.baseUrl.length>0}async function h(e){try{return await r.promises.readFile(e,"utf8")}catch(e){_(e)&&e.code;return}}async function f(e,t){let n;if(!t.legacyTokenPath||i.resolve(t.legacyTokenPath)===i.resolve(e))return;let r=await h(t.legacyTokenPath);if(void 0!==r){try{n=JSON.parse(r)}catch{return}if(u(n))return!t.allowExpired&&c(n)?void await l(t.legacyTokenPath,t):(await d(e,n,t),await l(t.legacyTokenPath,t),n)}}function m(e){return e.credentialStore??(0,s.Mj)()}function g(e){let t=o.createHash("sha256").update(i.resolve(e)).digest("hex").slice(0,32);return`token:${t}`}function _(e){return e instanceof Error&&"code"in e}n.d(t,{AI:()=>a,_d:()=>c,ni:()=>l,tK:()=>d})},"../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.24/node_modules/@byted-doubao-apps/auth-cli/dist/types.js"(e,t,n){var r,o;(o=r||(r={}))[o.Pending=1]="Pending",o[o.Authorized=2]="Authorized",o[o.Expired=3]="Expired",o[o.Invalid=4]="Invalid",o[o.SlowDown=5]="SlowDown",n.d(t,{A:()=>r})}});var $={};e.r($),e.d($,{createDeferredDevShellSession:()=>np,default:()=>nl,isInteractiveTerminal:()=>nf,withWebDebuggerFallback:()=>nm});let N=e("node:zlib"),q=e("../../../node_modules/.pnpm/@byted-doubao-tools+devtool-connection-core@0.1.0-beta.12_debug@4.4.3_react@19.2.7/node_modules/@byted-doubao-tools/devtool-connection-core/dist/lib/ipc/index.js"),M=4*Math.ceil(5614250.666666667),B=new Map;class U extends Error{code;cause;constructor(e,t,n){super(t),this.code=e,this.name="RuntimeInspectionError",n&&"cause"in n&&(this.cause=n.cause)}}async function F(e){let t,n=new E(e.namespace,{nodeId:`${e.nodeIdPrefix}-${process.pid}-${Math.random().toString(36).slice(2,8)}`,requestTimeout:12e3}),r=new Set,o=new Set,i=0,s=!0;n.createService({name:`runtimeInspection${process.pid}${Math.random().toString(36).slice(2,8)}`,events:{[q.DEVTOOL_CONNECTION_IPC_EVENTS.messageReceived](e){let n=e.params,o=function(e){if("Page.screencastFrame"===e.method&&m(e.params)&&"string"==typeof e.params.data&&e.params.data)return{data:e.params.data}}(n);for(let e of(o&&Number.isSafeInteger(n.clientId)&&Number.isSafeInteger(n.sessionId)&&(t={clientId:n.clientId,sessionId:n.sessionId,data:o.data}),r))e(n)},[b.runtimeInspectionTargetChanged](e){let t=function(e){if(m(e)&&"number"==typeof e.clientId&&"number"==typeof e.sessionId&&"string"==typeof e.url)return{clientId:e.clientId,sessionId:e.sessionId,url:e.url}}(e.params);if(t)for(let e of o)e(t)}}});try{await n.start()}catch(e){throw await n.stop().catch(()=>void 0),e}let a=(e,t)=>em(()=>n.call(`${q.DEFAULT_DEVTOOL_CONNECTION_IPC_SERVICE_NAME}.${e}`,t),5e3);return{eventSubscriptionWarmupMs:e.eventSubscriptionWarmupMs??5e3,getConnectedClients:()=>a(q.DEVTOOL_CONNECTION_IPC_ACTIONS.getConnectedClients),getLatestScreencastFrame(e){if(t?.clientId===e.clientId&&t.sessionId===e.sessionId)return{data:t.data}},async getRuntimeInspectionTarget(){if(!s)return null;try{return await n.call(g.getRuntimeInspectionTarget)}catch(e){if(ef(e))return s=!1,null;throw e}},subscribeRuntimeInspectionTarget:e=>(o.add(e),()=>{o.delete(e)}),async sendCdp(e,t,n={},r={}){let o={id:1e9+process.pid%1e5*1e3+i++,clientId:e.clientId,sessionId:e.sessionId,method:t,params:n,messageType:"CDP",timeoutMs:!1===r.expectResponse?100:1e4};try{let e=await a(q.DEVTOOL_CONNECTION_IPC_ACTIONS.sendMessageToApp,o);var s,d,l=t,c=e;if(!c.success)throw Error([c.reason,c.apps?.length?`apps=${c.apps.join(",")}`:"",c.clients?.length?`clients=${c.clients.map(e=>`${e.clientId}:${e.info.App}`).join(",")}`:""].filter(Boolean).join("; "));if(m(c.data)&&m(c.data.error)){let e=void 0===c.data.error.code?"unknown":String(c.data.error.code),t=void 0===c.data.error.message?"unknown error":String(c.data.error.message);throw Error(`${l} failed: ${t} (code=${e})`)}return ee(c.data)}catch(e){if(!1===r.expectResponse&&(s=e,d=t,(s instanceof Error?s.message:String(s)).includes(`send CDP message timeout, method: ${d}`)))return;throw Error(`${t} failed: ${e instanceof Error?e.message:String(e)}`)}},subscribeMessage:e=>(r.add(e),()=>{r.delete(e)}),async stop(){r.clear(),o.clear(),t=void 0,await n.stop()}}}async function V(e,t={}){let n=Date.now()+(t.timeoutMs??3e3);for(;;){e_(t.signal);let r=await e.getConnectedClients(),o=function(e,t={}){let n,r=t.explicitTarget??(t.policy?.kind==="fixed"?t.policy.target:void 0);if(r){let n=e.find(e=>e.device.clientId===r.clientId);if(!n){if(t.activeClientId===r.clientId)throw new U("TARGET_CLIENT_DISCONNECTED",`debug client ${r.clientId} is disconnected`);throw new U("TARGET_STALE",`${H(r)} no longer points to a connected debug client`)}let o=n.sessions.find(e=>e.sessionId===r.sessionId&&J(e));if(!o)throw new U("TARGET_STALE",`${H(r)} no longer points to a live Lynx session`);return{clientId:n.device.clientId,sessionId:o.sessionId,url:o.url}}if(void 0!==t.activeClientId){if(!(n=e.find(e=>e.device.clientId===t.activeClientId)))throw new U("TARGET_CLIENT_DISCONNECTED",`authenticated debug client ${t.activeClientId} is disconnected`)}else if(e.length>1)throw new U("TARGET_AMBIGUOUS",`more than one debug device is connected: ${e.map(e=>`${e.device.clientId}:${e.device.info.App||"unknown"}`).join(", ")}`);else n=e[0];if(!n)return;let o=n.sessions.filter(J).sort((e,t)=>t.sessionId-e.sessionId)[0];if(o)return{clientId:n.device.clientId,sessionId:o.sessionId,url:o.url}}(r,t);if(o)return o;if(Date.now()>=n)throw 0===r.length?new U("DEVICE_NOT_CONNECTED","no debug device is connected"):new U("NO_ACTIVE_LYNX_SESSION","the connected device has no active Lynx session");await ew(100,t.signal)}}function H(e){return`@${e.clientId}:${e.sessionId}`}function K(e){let t=/^@([1-9]\d*):([1-9]\d*)$/.exec(e.trim());if(!t)throw new U("INVALID_TARGET_REF",`invalid target ref "${e}"; expected @<clientId>:<sessionId>`);let n={clientId:Number(t[1]),sessionId:Number(t[2])};if(!Number.isSafeInteger(n.clientId)||!Number.isSafeInteger(n.sessionId))throw new U("INVALID_TARGET_REF",`invalid target ref "${e}"; every id must be a safe integer`);return n}function z(e){return`@${e.clientId}:${e.sessionId}:${e.nodeId}`}async function Y(e,t){let n=(await e.getConnectedClients()).find(e=>e.device.clientId===t.clientId),r=n?.sessions.find(e=>e.sessionId===t.sessionId&&J(e));if(!n||!r)throw new U("STALE_NODE_REF",`${z(t)} no longer points to a live Lynx session; run get-page-tree again`);return{clientId:t.clientId,sessionId:t.sessionId,url:r.url}}async function W(e,t,n={}){var r,o,i;let s,a,d,l,c,u=n.depth??-1,p=n.maxNodes??5e3;if(!Number.isInteger(u)||u<-1)throw Error("page tree depth must be -1 or a non-negative integer");if(!Number.isSafeInteger(p)||p<1)throw Error("page tree maxNodes must be a positive integer");await e.sendCdp(t,"DOM.enable",{useCompression:!1});try{c=await e.sendCdp(t,"DOM.getDocument",{depth:u})}catch{c=await e.sendCdp(t,"DOM.getDocument")}let h=function(e){let t=ee(e);if(!m(t))throw ea("DOM.getDocument","response is not an object");let n=t.root;if(!0===t.compress&&"string"==typeof n)try{if(n.length>M)throw Error("compressed root exceeds the input limit");n=JSON.parse((0,N.inflateSync)(Buffer.from(n,"base64"),{maxOutputLength:0x1000000}).toString("utf8"))}catch(e){throw ea("DOM.getDocument","failed to decode compressed root",e)}else if("string"==typeof n)try{n=JSON.parse(n)}catch(e){throw ea("DOM.getDocument","root is not valid JSON",e)}if(!m(n))throw ea("DOM.getDocument","missing root node");return n}(c),f=await Z(e,t,h,u,p),g=(r=h,o=t,i=p,s=0,a=!1,d=[],{root:(l=e=>{var t;let n=en(e.nodeId),r="string"==typeof e.nodeName&&e.nodeName?e.nodeName:"unknown";if(void 0===n)throw ea("DOM.getDocument",`node ${r} has no valid nodeId`);s++;let c=[],u={ref:z({clientId:o.clientId,sessionId:o.sessionId,nodeId:n}),nodeId:n,...void 0===en(e.backendNodeId)?{}:{backendNodeId:en(e.backendNodeId)},nodeType:"number"==typeof e.nodeType&&Number.isSafeInteger(e.nodeType)?e.nodeType:0,nodeName:r,..."string"==typeof e.localName?{localName:e.localName}:{},nodeValue:"string"==typeof e.nodeValue?e.nodeValue:"",attributes:function(e){if(!Array.isArray(e))return{};let t={};for(let n=0;n<e.length;n+=2){let r=e[n];if("string"!=typeof r||!r)continue;let o=e[n+1];t[r]="string"==typeof o?o:String(o??"")}return t}(e.attributes),childNodeCount:"number"==typeof e.childNodeCount&&Number.isSafeInteger(e.childNodeCount)?Math.max(0,e.childNodeCount):et(e).length,children:c};for(let t of(er(u)&&u.nodeValue&&(u.text=u.nodeValue),et(e))){if(s>=i){a=!0;break}c.push(l(t))}if("text"===((t=u).localName||t.nodeName).toLowerCase()){let e=function e(t){return t.children.flatMap(t=>er(t)?[t.nodeValue]:[e(t)]).join("")}(u);e?u.text=e:d.push(u)}return u})(r),nodeCount:s,truncated:a,textCandidates:d});return await eo(e,t,g.textCandidates),{target:t,depth:u,nodeCount:g.nodeCount,truncated:f.truncated||g.truncated,root:g.root}}async function G(e,t,n,r=[]){let o;await e.sendCdp(t,"DOM.enable",{useCompression:!1});try{o=await e.sendCdp(t,"CSS.getComputedStyleForNode",{nodeId:n.nodeId})}catch(e){var i;if(i=e,/(could not find|cannot find|no such|unknown|invalid|stale).{0,40}node|node.{0,40}(not found|does not exist|invalid|stale)/i.test(i instanceof Error?i.message:String(i)))throw new U("STALE_NODE_REF",`${z(n)} is stale; run get-page-tree again`,{cause:e});throw e}let s=ee(o);if(!m(s)||!Array.isArray(s.computedStyle))throw ea("CSS.getComputedStyleForNode","missing computedStyle array");let a=s.computedStyle.filter(m).flatMap(e=>"string"==typeof e.name&&"string"==typeof e.value?[{name:e.name,value:e.value}]:[]),d=0===r.length?a:r.flatMap(e=>{let t=a.find(t=>t.name===e);return t?[t]:[]});return{target:t,nodeRef:z(n),nodeId:n.nodeId,properties:d}}function J(e){return"lynx"===e.type&&Number.isSafeInteger(e.sessionId)&&e.sessionId>0&&!X(e.url)}function Q(e){return`${e.clientId}:${e.sessionId}`}function X(e){return/(?:-main\.js|\.main\.lynx\.js)(?:[?#].*)?$/.test(e)}async function Z(e,t,n,r,o){let i=0,s=!1,a=async(n,d)=>{if(i>=o){s=!0;return}if(i++,r>=0&&d>=r)return;let l=et(n);if(("number"==typeof n.childNodeCount&&Number.isSafeInteger(n.childNodeCount)?Math.max(0,n.childNodeCount):l.length)>l.length&&"number"==typeof n.nodeId&&Number.isSafeInteger(n.nodeId)){let r=ee(await e.sendCdp(t,"DOM.requestChildNodes",{nodeId:n.nodeId}));if(!m(r)||!Array.isArray(r.nodes))throw ea("DOM.requestChildNodes",`missing nodes array for node ${n.nodeId}`);n.children=l=r.nodes.filter(m)}for(let e of l)if(await a(e,d+1),i>=o){l.indexOf(e)<l.length-1&&(s=!0);break}};return await a(n,0),{truncated:s}}function ee(e){return m(e)&&"id"in e&&"result"in e?e.result:e}function et(e){return Array.isArray(e.children)?e.children.filter(m):[]}function en(e){return"number"==typeof e&&Number.isSafeInteger(e)&&e>0?e:void 0}function er(e){return 3===e.nodeType||"#text"===e.nodeName.toLowerCase()}async function eo(e,t,n){let r=n[0];if(!r)return;let o=await ei(e,t,r);if(o.supported){o.text&&(r.text=o.text);for(let r=1;r<n.length;r+=8){let o=n.slice(r,r+8);await Promise.all(o.map(async n=>{let r=await ei(e,t,n);r.text&&(n.text=r.text)}))}}}async function ei(e,t,n){try{let r=ee(await e.sendCdp(t,"DOM.innerText",{nodeId:n.nodeId}));if(!m(r)||!Array.isArray(r.rawTextValues))return{supported:!1};let o=r.rawTextValues.filter(m).flatMap(e=>"string"==typeof e.text?[e.text]:[]).join("");return{supported:!0,...o?{text:o}:{}}}catch{return{supported:!1}}}function es(e,t=120){let n=e.replace(/\s+/g," ").trim();return JSON.stringify(n.length>t?`${n.slice(0,Math.max(0,t-1))}…`:n)}function ea(e,t,n){return new U("INVALID_CDP_RESPONSE",`${e} returned an invalid response: ${t}`,void 0===n?void 0:{cause:n})}async function ed(e,t,n){let r,o,i,s=0,a=!1,d=Q(t),l=new Promise((e,t)=>{o=e,i=t}),c=e=>{a||(a=!0,o({count:s,reason:e}))},u=()=>c("aborted"),p=e.getRuntimeInspectionTarget?.bind(e),h=e=>{if(a||!(Number.isSafeInteger(e.clientId)&&e.clientId>0&&Number.isSafeInteger(e.sessionId)&&e.sessionId>0&&!X(e.url)))return;let r=Q(e);if(r!==d&&(d=r,r!==Q(t)))try{n.onTargetChange?.(e)}catch{}},f=e.subscribeMessage(e=>{if(a||!ec(e,t))return;let r=function(e){var t;if("Runtime.consoleAPICalled"!==e.method||!m(e.params))return;let n={...t=e.params,...Array.isArray(t.args)?{args:t.args.map(e=>m(e)?{...e}:e)}:{},...m(t.stackTrace)?{stackTrace:{...t.stackTrace,...Array.isArray(t.stackTrace.callFrames)?{callFrames:t.stackTrace.callFrames.map(e=>m(e)?{...e}:e)}:{}}}:{}},r="string"==typeof n.consoleTag?n.consoleTag:void 0;return{type:"string"==typeof n.type?n.type:"log",thread:"Lepus"===r?"main":"background",args:Array.isArray(n.args)?n.args:[],...r?{consoleTag:r}:{},..."number"==typeof n.timestamp?{timestamp:n.timestamp}:{},..."stackTrace"in n?{stackTrace:n.stackTrace}:{},params:n}}(e);if(r){try{n.onMessage(r)}catch(e){a||(a=!0,i(e));return}s++,void 0!==n.limit&&s>=n.limit&&c("limit")}}),g=n.onTargetChange?e.subscribeRuntimeInspectionTarget?.(h):void 0;n.signal?.addEventListener("abort",u,{once:!0}),n.onTargetChange&&p&&p().then(e=>{e&&h(e)}).catch(()=>void 0);try{if(n.signal?.aborted)return c("aborted"),await l;if(await eu(e,t,n.subscriptionWarmupMs??e.eventSubscriptionWarmupMs??5e3,n.signal),a)return await l;for(let o of(void 0!==n.timeoutMs&&(r=setTimeout(()=>c("timeout"),n.timeoutMs)),[{method:"Page.getResourceTree",params:{}},{method:"Debugger.enable",params:{}},{method:"Runtime.enable",params:{}}])){if(a)break;await e.sendCdp(t,o.method,o.params,{expectResponse:!1})}return await l}catch(e){if(n.signal?.aborted)return c("aborted"),await l;throw e}finally{r&&clearTimeout(r),n.signal?.removeEventListener("abort",u),g?.(),f()}}async function el(e,t,n={}){return eg(t,async()=>{let r,o=new Promise(e=>{r=e}),i=e.subscribeMessage(e=>{ec(e,t)&&"Page.screencastFrame"===e.method&&m(e.params)&&"string"==typeof e.params.data&&e.params.data&&r({data:e.params.data})}),s=!1;try{var a,d,l;await eu(e,t,e.eventSubscriptionWarmupMs??5e3);let r=n.activeCapture?void 0:e.getLatestScreencastFrame?.(t);!r&&n.activeCapture&&(await e.sendCdp(t,"Page.enable"),s=!0,await e.sendCdp(t,"Page.startScreencast",{format:"jpeg",quality:80},{expectResponse:!1})),r??=await (a=o,d=t,l=n.timeoutMs??1e4,new Promise((e,t)=>{let n=setTimeout(()=>t(new U("SCREENSHOT_TIMEOUT",`no Page.screencastFrame received for ${H(d)} within ${l}ms; make sure the target session is active and can produce screenshot frames`)),l);a.then(t=>{clearTimeout(n),e(t)},e=>{clearTimeout(n),t(e)})})),s&&await e.sendCdp(t,"Page.screencastFrameAck",{},{expectResponse:!1}).catch(()=>void 0);let i=function(e){let t=e.replace(/\s+/g,"");if(!t||t.length%4!=0||!/^[A-Za-z0-9+/]+={0,2}$/.test(t))throw new U("INVALID_SCREENSHOT_DATA","Page.screencastFrame returned invalid base64 data");let n=Buffer.from(t,"base64");if(n.length<4||255!==n[0]||216!==n[1]||255!==n[n.length-2]||217!==n[n.length-1])throw new U("INVALID_SCREENSHOT_DATA","Page.screencastFrame did not return a complete JPEG image");let r=function(e){let t=new Set([192,193,194,195,197,198,199,201,202,203,205,206,207]),n=2;for(;n+3<e.length;){if(255!==e[n]){n++;continue}for(;n<e.length&&255===e[n];)n++;let r=e[n++];if(void 0===r||217===r||218===r)break;if(1===r||r>=208&&r<=215)continue;if(n+1>=e.length)break;let o=e.readUInt16BE(n);if(o<2||n+o>e.length)break;if(t.has(r)){if(o<7)break;let t=e.readUInt16BE(n+3),r=e.readUInt16BE(n+5);if(r>0&&t>0)return{width:r,height:t};break}n+=o}}(n);if(!r)throw new U("INVALID_SCREENSHOT_DATA","Page.screencastFrame JPEG has no readable dimensions");return{buffer:n,data:t,...r}}(r.data);return{data:i.data,format:"jpeg",source:"Page.screencastFrame",width:i.width,height:i.height,byteLength:i.buffer.length}}finally{s&&await e.sendCdp(t,"Page.stopScreencast",{},{expectResponse:!1}).catch(()=>void 0),i()}})}function ec(e,t){return"CDP"===e.messageType&&e.clientId===t.clientId&&e.sessionId===t.sessionId}async function eu(e,t,n,r){let o;if(n<=0)return;let i=Date.now()+n,s=new Promise(e=>{o=e}),a=e.subscribeMessage(e=>{ec(e,t)&&o()});try{for(;Date.now()<i;){if(e_(r),await e.sendCdp(t,"Page.getResourceTree",{},{expectResponse:!1}).catch(()=>void 0),await function(e,t,n){return new Promise((r,o)=>{let i=new AbortController,s=setTimeout(()=>{i.abort(),r(!1)},t);n?.addEventListener("abort",()=>{clearTimeout(s),i.abort(),o(n?.reason instanceof Error?n.reason:Error("operation aborted"))},{once:!0,signal:i.signal}),e.then(()=>{clearTimeout(s),i.abort(),r(!0)},e=>{clearTimeout(s),i.abort(),o(e)})})}(s,Math.min(250,Math.max(0,i-Date.now())),r))return;await ew(Math.min(50,Math.max(0,i-Date.now())),r)}}finally{a()}}function ep(e){return m(e)?e.objectId?`<${String(e.description||e.className||"Object")} (objectId:${String(e.objectId)})>`:"value"in e?eh(e.value):"string"==typeof e.description?e.description:eh(e):eh(e)}function eh(e){if("string"==typeof e)return e;if(void 0===e)return"undefined";try{let t=JSON.stringify(e);return void 0===t?String(e):t}catch{return String(e)}}function ef(e){return/is not (found|available)/i.test(e instanceof Error?e.message:String(e))}async function em(e,t){let n=Date.now()+t;for(;;)try{return await e()}catch(e){if(!ef(e)||Date.now()>=n)throw e;await ew(50)}}async function eg(e,t){let n,r=Q(e),o=B.get(r)??Promise.resolve(),i=new Promise(e=>{n=e});B.set(r,i),await o.catch(()=>void 0);try{return await t()}finally{n(),B.get(r)===i&&B.delete(r)}}function e_(e){if(e?.aborted)throw e.reason instanceof Error?e.reason:Error("operation aborted")}function ew(e,t){return new Promise((n,r)=>{if(t?.aborted)return void r(t.reason instanceof Error?t.reason:Error("operation aborted"));let o=new AbortController,i=setTimeout(()=>{o.abort(),n()},e);t?.addEventListener("abort",()=>{clearTimeout(i),o.abort(),r(t?.reason instanceof Error?t.reason:Error("operation aborted"))},{once:!0,signal:o.signal})})}let ey={schemaVersion:1,cliVersion:o,deviceAppVersion:"1.0.9",packages:{"darwin-arm64":{url:"https://lf3-cdn-tos.bytegoofy.com/obj/tron-demo/7610358476778248474/468636861/1.0.9/darwin-arm64/DoubaoDeveloperTools-v1.0.9-darwin-arm64.zip",sha256:"1b1aaf58f109efdc7cf0107a533ea043807d5f17c5ea9e001cede78511ae80b3",entry:"豆包开发者工具.app",sizeBytes:0x77fdf68},"win32-x64":{url:"https://lf3-cdn-tos.bytegoofy.com/obj/tron-demo/7610358476778248474/468636861/1.0.9/win32-x64/DoubaoDeveloperTools-v1.0.9-win32-x64.zip",sha256:"903ee97e1560006293afc978c16476d0b34c4789d03a709b200cb59da8fa4556",entry:"豆包开发者工具.exe",sizeBytes:0x84c4d6c}}},eb=e("node:child_process"),ev=e("node:crypto");var eE=e.n(ev);let eI=e("node:fs");var eA=e.n(eI);let eT=e("node:http"),eC=e("node:os");var eS=e.n(eC);let ej=e("node:path");var ek=e.n(ej);let eD=e("node:stream"),eP=e("node:url"),ex=e("node:util"),eL=e("../../../node_modules/.pnpm/@byted-doubao-tools+real-device-debug-auth@0.1.3/node_modules/@byted-doubao-tools/real-device-debug-auth/dist/lib/index.js"),eR=e("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/index.js"),eO="DBX_DEVICE_APP_PATH",e$="dbx-device-app.json",eN="state.json",eq="versions",eM=ek().dirname((0,eP.fileURLToPath)(import.meta.url)),eB=[{command:"web",description:"打开 Web 模拟器"},{command:"device",description:"进入真机调试"},{command:"status",description:"查看本地调试服务状态"}],eU=[{command:"qr",description:"重新生成真机调试二维码"},{command:"page [url]",description:"在真机打开页面(省略 url 可选择)"},{command:"pages",description:"列出真机可打开页面"},{command:"widget [id]",description:"向真机推送卡片(省略 id 可选择)"},{command:"widgets",description:"列出真机可推送卡片"},{command:"sessions",description:"列出当前可检查的 Lynx sessions"},{command:"use-session <@client:session|latest>",description:"固定 CLI session 或恢复跟随最新"},{command:"get-console",description:"持续输出当前 Lynx 页面新产生的日志"},{command:"take-screenshot",description:"截取当前 Lynx 页面画面"},{command:"get-page-tree",description:"获取当前 Lynx 页面的 DOM 树"},{command:"get-computed-style [node-ref]",description:"获取 DOM 节点的 computed style"},{command:"back",description:"返回主命令"}];function eF(e){if("complete"===e.phase)return`豆包开发者工具已安装:${e.appPath}`;if("install"===e.phase){let t={verify:"验证",extract:"解压",install:"安装"}[e.stage];return`安装豆包开发者工具:${t}`}let t=[void 0===e.percentage?void 0:`${e.percentage}%`,void 0===e.totalBytes?e.downloadedBytes>0?td(e.downloadedBytes):void 0:`${td(e.downloadedBytes)} / ${td(e.totalBytes)}`,`${Math.max(0,Math.round(e.elapsedMs/1e3))}s`].filter(e=>!!e);return`下载豆包开发者工具:${t.join(" \xb7 ")}`}function eV(e,t){let n,r=!1;return o=>{if(!o)return void t?.(void 0);if("download"===o.phase){n=o,t?.(o);return}if(n&&!r&&(r=!0,nn(e,`✓ ${eF(n)}`)),"complete"===o.phase){t?.(void 0),nn(e,`✓ ${eF(o)}`);return}t?.(o)}}function eH(e,t){if("true"===e)return!0;if("false"===e)return!1;throw Error(`${t} must be "true" or "false"`)}async function eK(e){let t,n,r,o,i=e.output??process.stderr,s=e.client??await v({projectPath:e.projectPath,appDir:e.appDir,nodeIdPrefix:"dev-shell"}),a=e.closeDeviceApp??e8,d=new AbortController,l=e.openBrowser??T,c=new Set,u={runtime:e.runtime,client:s,output:i,manageDeviceApp:!0,runtimeInspectionTargetPolicy:{kind:"latest"},openBrowser:l,openQRCodeViewer:e.openQRCodeViewer??((e,t,n)=>t8(e,l,t,i,n)),signal:d.signal,launchDeviceApp:e.launchDeviceApp??(e=>e5(e,i)),closeDeviceApp:a,prepareDeviceApp:e.prepareDeviceApp??(e=>e3(i,e)),...e.onDeviceAppSetupProgress?{onDeviceAppSetupProgress:e.onDeviceAppSetupProgress}:{},openPreparedDeviceApp:e.openPreparedDeviceApp??e6,runRealDeviceAuth:e.runRealDeviceAuth??tz,...e.realDeviceDebugCoordinator?{realDeviceDebugCoordinator:e.realDeviceDebugCoordinator}:{},...e.createRuntimeInspectionSession?{createRuntimeInspectionSession:e.createRuntimeInspectionSession}:{},listAppVersions:e.listAppVersions??(async e=>{let t=await A(e);return t.data?.version_list??[]}),selectItem:e.selectItem,eventTracking:e.eventTracking},p=(e.createRuntimeInspectionSession??F)({namespace:e.runtime.getState().namespace,nodeIdPrefix:"dev-shell-runtime-inspection"});p.catch(()=>void 0),u.runtimeInspectionSession=p;let h=async()=>r||(r=(async()=>{u.activeDeviceId=void 0,t6(),u.manageDeviceApp&&await eG(u)})().finally(()=>{r=void 0})),f=t0(e.runtime.getState().namespace,async()=>{if(u.activeDeviceId&&!o){nn(i,"检测到真机连接断开,正在返回主命令并清理真机调试资源..."),await h();for(let e of c)try{e("client-disconnected")}catch{}}});return await f.start(),{stopped:e.runtime.stopped,getState:()=>e.runtime.getState(),execute(e){let r=new AbortController,o=AbortSignal.any([d.signal,r.signal]);n=r,u.signal=o;let i=ez(e,u);return t=i,i.finally(()=>{t===i&&(t=void 0),n===r&&(n=void 0),u.signal===o&&(u.signal=d.signal)})},cancelActiveCommand(){if(!n||n.signal.aborted)return!1;let e=Error("command cancelled");return e.name="AbortError",n.abort(e),!0},returnToRoot:()=>eY(u,"back","execute",h),handleClientDisconnected:()=>h(),subscribe:e=>(c.add(e),()=>{c.delete(e)}),close:()=>o??=(async()=>{d.abort(new tZ),await t?.catch(()=>void 0),await f.stop().catch(()=>void 0),await h(),await u.runtimeInspectionSession?.then(e=>e.stop()).catch(()=>void 0),await s.stop().catch(()=>void 0),await e.runtime.stop().catch(()=>void 0)})()}}async function ez(e,t){var n;let r;try{r=function(e){let t,n=[],r="",o=!1,i=()=>{r.length>0&&(n.push(r),r="")};for(let n of e.trim()){if(o){r+=n,o=!1;continue}if("\\"===n&&"'"!==t){o=!0;continue}if("'"===n||'"'===n){if(!t){t=n;continue}if(t===n){t=void 0;continue}}if(!t&&/\s/.test(n)){i();continue}r+=n}if(o&&(r+="\\"),t)throw Error(`unterminated ${t} quote`);return i(),n}(e)}catch(e){return nn(t.output,tQ(no(e))),"continue"}let o=r[0]?.toLowerCase(),i=r.slice(1);if(!o)return"continue";if((n=i).includes("--help")||n.includes("-h")){let e="device"===o&&i[0]&&!i[0].startsWith("-")?`device ${i[0].toLowerCase()}`:o;if(function(e,t){switch(t){case"device widget":return nn(e,"usage: widget [widget-id] [--data <json>] [--bot-id <id>] [--device-id <id>]"),nn(e,"推送卡片到已连接真机;省略 widget-id 时从 `widgets` 列表中选择。"),!0;case"device page":return nn(e,"usage: page [url] [--device-id <id>]"),nn(e,"通过完整 URL 打开页面;省略 url 时从 `pages` 列表中选择。页面参数请写入 URL query。"),!0;case"device":nn(e,"usage: device [--agent] [--mcp] [--timeout <seconds>] [--qr-file <file.png>] [--wifi-connect <true|false>] [--defaultDebugTagState <true|false>]"),nn(e,"进入真机模式并连接调试设备,默认准备并打开豆包开发者工具。"),nn(e,"使用 `device --agent` 进入 Agent 模式,不准备、启动或关闭豆包开发者工具。"),nn(e,"使用 --mcp 进入 MCP 端到端调试,并从当前 AppID 的版本列表中选择 versionTag。");for(let t of(nn(e,"真机调试命令"),eU))nn(e,` ${t.command.padEnd(22)}${t.description}`);return nn(e,"进入真机模式后执行 `<命令> --help` 查看参数。"),nn(e,"get-page-tree、get-computed-style、take-screenshot 支持通用的 --json 输出。"),!0;case"device qr":return nn(e,"usage: qr [--mcp] [--timeout <seconds>] [--qr-file <file.png>] [--wifi-connect <true|false>] [--defaultDebugTagState <true|false>]"),nn(e,"重新生成真机调试二维码;MCP 端到端调试会沿用已选择的 versionTag,也可用 --mcp 重新选择。"),!0;case"device get-console":return nn(e,"usage: get-console [--target <@client:session>] [--limit <count>] [--timeout-seconds <seconds>] [--include-stack-traces]"),nn(e,"持续输出当前 Lynx session 新产生的 console 日志;按 Ctrl+C 停止监听并返回真机命令。"),nn(e,"默认仅 error 日志显示调用栈;使用 --include-stack-traces 展开所有日志的调用栈。"),!0;case"device sessions":return nn(e,"usage: sessions"),nn(e,"列出当前可检查的 Lynx sessions,并标记 latest、CLI fixed 和 Electron current。"),!0;case"device use-session":return nn(e,"usage: use-session <@client:session|latest>"),nn(e,"固定 CLI 后续检查命令使用的 session,或用 latest 恢复到鉴权 client 内最新活跃 session;不会切换 Electron。"),!0;case"device take-screenshot":return nn(e,"usage: take-screenshot [--target <@client:session>] [-o, --output <file.jpeg>] [--json]"),nn(e,"保存 Electron 当前为目标 session 输出的最近一帧 JPEG;截图范围跟随 Electron 当前 mode。"),!0;case"device get-page-tree":return nn(e,"usage: get-page-tree [--target <@client:session>] [--depth <-1|n>] [--json]"),nn(e,"获取当前 Lynx session 的 DevTools Elements DOM 树;默认 depth=-1。"),nn(e,"终端输出紧凑树;--json 输出节点文本、完整 attributes 和可复用 node-ref。"),!0;case"device get-computed-style":return nn(e,"usage: get-computed-style <node-ref> [--properties <name,...>] [--json]"),nn(e,"获取元素节点的 computed style;node-ref 格式为 @<clientId>:<sessionId>:<nodeId>。"),nn(e,"省略 --properties 返回全部属性,例如 --properties color,font-size。"),!0;case"web":return nn(e,"usage: web"),nn(e,"在默认浏览器打开本地 Web 模拟器。"),!0;case"device pages":case"device widgets":{let n="device pages"===t?"打开的页面":"推送的卡片";return nn(e,`usage: ${t.slice(7)}`),nn(e,`列出真机可${n}。`),!0}case"status":return nn(e,"usage: status"),nn(e,"查看本地调试服务状态。"),!0;default:return!1}}(t.output,e))return"continue"}try{switch(o){case"status":return await eY(t,"status","execute",()=>eJ(t)),"continue";case"web":return await eY(t,"web_open","execute",()=>eQ(t)),"continue";case"device":return await eW(t,i)?"enter-device":"continue";default:return nn(t.output,`unknown command: ${o}`),["qr","pages","page","widgets","widget","sessions","use-session","get-console","take-screenshot","get-page-tree","get-computed-style"].includes(o)&&nn(t.output,`\`${o}\` is only available in device mode; run \`device\` first.`),"continue"}}catch(e){return nn(t.output,tQ(no(e))),"continue"}}async function eY(e,t,n,r){let o=e.eventTracking;return o?c({action:t,actionSequence:++o.actionSequence,appId:o.appId??e.runtime.getState().appId,devSessionId:o.devSessionId,errorStage:n},r):r()}async function eW(e,t){let n=t[0]?.toLowerCase();if(!n||n.startsWith("-"))return await eX(e,t,{reuseDeviceAppMode:!1,reuseVersionTag:!1}),!0;let r=function(e){let t=!1,n=[];for(let r of e)"--json"===r?t=!0:n.push(r);return{args:n,json:t}}(t.slice(1)),o=["get-page-tree","get-computed-style","take-screenshot"].includes(n);try{if(r.json&&!o)throw Error(`--json is not supported by device ${n}; use it with get-page-tree, get-computed-style, or take-screenshot`);switch(n){case"qr":return await e2(e,r.args),!0;case"pages":return await eY(e,"pages_list","execute",()=>tD(e,"page",g.discoverPages)),!0;case"page":return await eY(e,"page_push","page_push",()=>tU(e,r.args)),!0;case"widgets":return await eY(e,"widgets_list","execute",()=>tD(e,"widget",g.discoverWidgets)),!0;case"widget":return await eY(e,"widget_push","widget_push",()=>tF(e,r.args)),!0;case"sessions":return await eY(e,"sessions_list","execute",()=>tP(e,r.args)),!0;case"use-session":return await eY(e,"session_select","execute",()=>tx(e,r.args)),!0;case"get-console":return await eY(e,"console_stream","execute",()=>tL(e,r.args)),!0;case"take-screenshot":return await eY(e,"screenshot","execute",()=>tR(e,r.args,r.json)),!0;case"get-page-tree":return await eY(e,"page_tree","execute",()=>tO(e,r.args,r.json)),!0;case"get-computed-style":return await eY(e,"computed_style","execute",()=>t$(e,r.args,r.json)),!0;default:return nn(e.output,`unknown device subcommand: ${n}`),!1}}catch(t){if(!r.json||!o)throw t;return nr(e.output,{ok:!1,error:{code:t instanceof U?t.code:"INSPECTION_FAILED",message:no(t)}}),!0}}async function eG(e){try{var t,n;let r=await e.closeDeviceApp();t=e.output,n=r,"closed"===n.status?nn(t,`豆包开发者工具已关闭:${n.appPath}`):nn(t,`关闭豆包开发者工具失败${n.reason?`:${tQ(n.reason)}`:""}`)}catch(t){nn(e.output,`关闭豆包开发者工具失败:${tQ(no(t))}`)}}async function eJ(e){let t=await e.client.call(g.getInfo);nn(e.output,`status: ${t.status}`),nn(e.output,`app_id: ${t.appId??"-"}`),nn(e.output,`dev_server: ${t.host??"-"}`),nn(e.output,`web_debugger: ${t.webDebuggerUrl??"-"}`)}async function eQ(e){let t=e.runtime.getState().webDebuggerUrl;if(!t)throw Error("web debugger URL is not ready");await e.openBrowser(t),nn(e.output,`Web 模拟器已打开:${t}`)}async function eX(e,t,n){let r=()=>e.realDeviceDebugCoordinator?e.realDeviceDebugCoordinator.runTerminal(()=>eZ(e,t,n)):eZ(e,t,n),o=e.eventTracking;if(!o)return void await r();let i=++o.actionSequence,s=performance.now(),a=n.reuseDeviceAppMode?"qr_refresh":"device_connect";try{let t=await r(),n=t?.status==="connected"?"success":t?.status==="cancelled"?"cancelled":t?.status==="timeout"?"timeout":t?.error?"failed":"skipped";await p({action:a,actionSequence:i,appId:o.appId??e.runtime.getState().appId,devSessionId:o.devSessionId,durationMs:performance.now()-s,...t?.error?{error:t.error,...t.failureStage?{errorStage:t.failureStage}:{},errorType:"device_connection_error"}:{},status:n})}catch(t){throw await p({action:a,actionSequence:i,appId:o.appId??e.runtime.getState().appId,devSessionId:o.devSessionId,durationMs:performance.now()-s,error:t,errorStage:"prepare_device_tool",errorType:"device_connection_error",status:f(t)}),t}}async function eZ(e,t,n){var r,o,i;let s,a,d,l=(0,ex.parseArgs)({args:t,allowPositionals:!1,options:{agent:{type:"boolean"},timeout:{type:"string"},"qr-file":{type:"string"},mcp:{type:"boolean"},"wifi-connect":{type:"string"},defaultDebugTagState:{type:"string"}}});if(n.reuseDeviceAppMode&&l.values.agent)throw Error("--agent is only supported when entering device mode");n.reuseDeviceAppMode||(e.manageDeviceApp=!l.values.agent);let c=function(e){if(void 0===e)return;let t=Number(e);if(!Number.isFinite(t)||t<=0)throw Error("--timeout must be a positive number of seconds");return Math.round(1e3*t)}(l.values.timeout),u=function(e){if(!e)return;let t=ek().resolve(e);if(".png"!==ek().extname(t).toLowerCase())throw Error("--qr-file must point to a .png file");return t}(l.values["qr-file"]),p=tW((r={defaultDebugTagState:l.values.defaultDebugTagState,wifiConnect:l.values["wifi-connect"]},d={},void 0!==r.defaultDebugTagState&&(d.defaultDebugTagState=eH(r.defaultDebugTagState,"--defaultDebugTagState")),void 0!==r.wifiConnect&&(d.usb=!eH(r.wifiConnect,"--wifi-connect")),Object.keys(d).length>0?d:void 0)),h=await e.client.call("dev.setConnectionTransport",{type:p.usb?"usb":"wifi"}),f=e.runtime.getState(),m=l.values.mcp?await e0(e,f.appId):n.reuseVersionTag?e.activeVersionTag:void 0;if(l.values.mcp&&!m)return;e.activeVersionTag=m,m&&!l.values.mcp&&nn(e.output,`沿用 MCP 端到端调试 versionTag:${m}`),e.manageDeviceApp||nn(e.output,"已启用 --agent:不会准备、启动或关闭豆包开发者工具。");let g={namespace:f.namespace,projectPath:f.projectPath,appDir:f.appDir,appKey:f.appId,hostUrl:f.host},_=e.manageDeviceApp?await e1(e):void 0;if(_?.status==="skipped"){let t=_.reason??"豆包开发者工具准备失败";return nn(e.output,`启动真机调试失败:${tQ(t)}`),{ok:!1,status:"skipped",timeoutMs:c??6e4,failureStage:"prepare_device_tool",error:t}}t6();let w=new AbortController,y=e.signal?AbortSignal.any([e.signal,w.signal]):w.signal;try{a=await e.runRealDeviceAuth({hostUrl:h.host||f.host,appKey:h.appId||f.appId,versionTag:m,namespace:f.namespace,timeoutMs:c,settings:p,wifiConnectUrl:h.wifiConnectUrl,output:e.output,signal:y,onQRCodeReady:async(t,n)=>{(s=await e.openQRCodeViewer(t,u,n)).closed.then(()=>{w.abort(new tZ)})}})}finally{await s?.close().catch(()=>void 0),t6()}if(function(e,t){let n;if(t.ok){let n=t.client?.clientId===void 0?"":`:client ${t.client.clientId}`,r=t.qrCodeValue?"扫码鉴权完成":"复用已连接设备,已跳过二维码鉴权";nn(e,`真机调试已连接${n}(${r})。`);return}"cancelled"===t.status?nn(e,"install"===t.waitingFor?"二维码页面已关闭,已取消等待设备安装。":"二维码页面已关闭,已取消等待设备连接。"):(n="timeout"===t.status?"install"===t.waitingFor?`设备已连接,但等待安装完成超时(${Math.max(1,Math.ceil(t.timeoutMs/1e3))} 秒)`:`等待设备连接超时(${Math.max(1,Math.ceil(t.timeoutMs/1e3))} 秒)`:tQ(t.error??"未知错误"),nn(e,`启动真机调试失败:${n}`))}(e.output,a),a.ok&&"connected"===a.status){a.client?.clientId!==void 0&&(void 0!==e.activeClientId&&e.activeClientId!==a.client.clientId&&(e.runtimeInspectionTargetPolicy={kind:"latest"}),e.activeClientId=a.client.clientId);let t=a.client?.deviceId??(a.client?.clientId===void 0?void 0:String(a.client.clientId));t&&(e.activeDeviceId=t)}if(e.manageDeviceApp&&a.ok&&"connected"===a.status){let t=_?await e4(e,_,g):await e.launchDeviceApp(g);o=e.output,"opened"===(i=t).status?nn(o,`豆包开发者工具已启动:${i.appPath}`):nn(o,`启动豆包开发者工具失败${i.reason?`:${tQ(i.reason)}`:""}`)}return a}async function e0(e,t){if(!t)throw Error("无法查询 versionTag,当前工程缺少 AppID。");let n=(await e.listAppVersions(t)).filter(e=>"string"==typeof e.version_tag&&!!e.version_tag.trim());if(!n.length)throw Error(`当前 AppID(${t})没有可选的 versionTag。`);let r=await e.selectItem("versionTag",n,e.output);return r?(nn(e.output,`MCP 端到端调试 versionTag:${r}`),r):void nn(e.output,"已取消 versionTag 选择,未生成二维码。")}async function e1(e){if(e.prepareDeviceApp){e.onDeviceAppSetupProgress?.(void 0);try{return await e.prepareDeviceApp({onProgress:eV(e.output,e.onDeviceAppSetupProgress),signal:e.signal})}catch(t){return e.onDeviceAppSetupProgress?.(void 0),{status:"skipped",reason:no(t)}}}}async function e2(e,t){await eX(e,t,{reuseDeviceAppMode:!0,reuseVersionTag:!0})}async function e4(e,t,n){return"skipped"!==t.status&&t.appPath?e.openPreparedDeviceApp?e.openPreparedDeviceApp(t.appPath,n):e.launchDeviceApp(n):{status:"skipped",reason:t.reason}}async function e5(e,t=process.stderr){let n=await e3(t);return"skipped"!==n.status&&n.appPath?e6(n.appPath,e):{status:"skipped",reason:n.reason}}async function e3(e=process.stderr,t={}){let n=function(e={}){let t=e.env??process.env,n=e.platform??process.platform,r=e.arch??process.arch,o=e.appDir??tn(),i=e.manifest??ey,s=to(t);if(t[eO]?.trim()||!s&&te({...t,[eO]:""},n,o))return;tg(i);let a=tr(n,r);if(!a)return;let d=i.packages[a];if(!d)return;t_(d);let l=tw(i,d),c=tt(t,n);if(!(!s&&ti(c,i,a,d,l)))return{platform:a,version:l,...void 0===d.sizeBytes?{}:{sizeBytes:d.sizeBytes}}}();return n&&!t.onProgress&&(nn(e,"真机调试准备:"),nn(e,`首次或版本更新需要下载豆包开发者工具${n.sizeBytes?`(${td(n.sizeBytes)})`:""}。`),nn(e,"下载完成后才会生成二维码;下载耗时取决于网络,进度和实际耗时将持续显示。")),await e7({runner:{onProgress:t.onProgress??eV(e),signal:t.signal}})}async function e6(e,t){return await function(e,t,n=process.platform){var r,o,i;let s,a=(r=e,o=n,s=(i=t)?[["namespace",i.namespace],["project",i.appDir??i.projectPath],["app-key",i.appKey],["host-url",i.hostUrl]].flatMap(([e,t])=>t?[`--${e}=${t}`]:[]):[],"darwin"===o?{command:"open",args:[r,...s.length?["--args",...s]:[]]}:"win32"===o?{command:"cmd",args:["/c","start","",r,...s],windowsVerbatimArguments:!0}:{command:r,args:s});return new Promise((e,t)=>{let n=(0,eb.spawn)(a.command,a.args,{stdio:"ignore",windowsVerbatimArguments:a.windowsVerbatimArguments});n.once("error",t),n.once("spawn",e)})}(e,t),{status:"opened",appPath:e}}async function e8(){let e=function(e=process.env,t=process.platform,n=process.arch,r=tn()){let o=e[eO]?.trim();if(o)return ek().resolve(o);let i=te({...e,[eO]:""},t,r);if(i)return i;let s=tr(t,n);if(!s)return;let a=tt(e,t),d=tu(a);if(!d||d.platform!==s)return;let l=tv(tf(a,d.activeDeviceAppVersion),d.entry,"device app state entry");return eA().existsSync(l)?l:void 0}();return e?(await function(e,t=process.platform){return"darwin"===t?tT(e):tC(tj(e,t),{rejectOnNonZero:!0}).then(()=>void 0)}(e),{status:"closed",appPath:e}):{status:"skipped",reason:`${eO} is not set and no packaged or cached device app was found`}}async function e7(e={}){let t=e.env??process.env,n=e.platform??process.platform,r=e.arch??process.arch,o=e.appDir??tn(),i=to(t),s=t[eO]?.trim();if(s)return{status:"found",appPath:ek().resolve(s),source:"env"};if(!i){let e=te({...t,[eO]:""},n,o);if(e)return{status:"found",appPath:e,source:"packaged"}}return e9({env:t,platform:n,arch:r,appDir:o,manifest:e.manifest,runner:e.runner})}async function e9(e={}){let t=e.env??process.env,n=e.platform??process.platform,r=e.arch??process.arch,o=e.manifest??ey;tg(o);let i=tr(n,r);if(!i)return{status:"skipped",reason:`device app download is not supported on ${n}/${r}`};let s=o.packages[i];if(!s)return{status:"skipped",reason:`device app package is not configured for ${i} in CLI ${o.cliVersion}`};let a=tt(t,n),d=tw(o,s);if(!to(t)){let e=ti(a,o,i,s,d);if(e)return tp(a,d),{status:"found",appPath:e,source:"cache"}}let l=await ts(a,o,i,s,n,e.runner);return tp(a,d),{status:"found",appPath:l,source:"downloaded"}}function te(e=process.env,t=process.platform,n=tn()){let r=e[eO]?.trim();if(r)return ek().resolve(r);if(!eA().existsSync(n))return;let o=eA().readdirSync(n,{withFileTypes:!0}).find(e=>{var n,r;return n=e,"darwin"===(r=t)?n.isDirectory()&&n.name.endsWith(".app"):"win32"===r?n.isFile()&&n.name.toLowerCase().endsWith(".exe"):n.isFile()&&/\.(appimage|AppImage)$/.test(n.name)});return o?ek().join(n,o.name):void 0}function tt(e=process.env,t=process.platform){let n=e.DBX_DEVICE_APP_CACHE_DIR?.trim();if(n)return ek().resolve(n);if("darwin"===t)return ek().join(eS().homedir(),"Library","Application Support","dbx","device-app");if("win32"===t){let t=e.LOCALAPPDATA?.trim()||ek().join(eS().homedir(),"AppData","Local");return ek().join(t,"dbx","device-app")}return ek().join(eS().homedir(),".local","share","dbx","device-app")}function tn(){return ek().resolve(eM,"../../..","device-app")}function tr(e,t){if(("darwin"===e||"win32"===e)&&("arm64"===t||"x64"===t))return`${e}-${t}`}function to(e){let t=e.DBX_DEVICE_APP_FORCE_DOWNLOAD?.trim().toLowerCase();return!!(t&&"0"!==t&&"false"!==t)}function ti(e,t,n,r,o){var i,s,a,d,l;let c,u=tu(e);if(!u||u.activeDeviceAppVersion!==o||u.cliVersion!==t.cliVersion||u.platform!==n||!tb(u.sha256,r)||u.entry!==r.entry)return;let p=tf(e,o);if(i=p,s=t,a=n,d=r,l=o,!((c=tc(i))&&c.cliVersion===s.cliVersion&&c.deviceAppVersion===l&&c.entry===d.entry&&c.platform===a&&tb(c.sha256,d)))return;let h=tv(p,r.entry,"device app entry");return eA().existsSync(h)?h:void 0}async function ts(e,t,n,r,o,i={}){t_(r);let s=tw(t,r),a=i.now?.()??Date.now(),d=ek().join(e,".tmp");eA().mkdirSync(d,{recursive:!0}),eA().mkdirSync(ek().join(e,eq),{recursive:!0});let l=eA().mkdtempSync(ek().join(d,`${s}-`)),c=ek().join(l,"device-app.zip"),u=ek().join(l,"extract"),p=tf(e,s);try{var h,f,m,g,_,w,y,b;let d,l;if(i.onProgress?.({phase:"download",downloadedBytes:0,...void 0===r.sizeBytes?{}:{totalBytes:r.sizeBytes,percentage:0},elapsedMs:0}),await ta(r.url,c,i.fetch,i.onProgress,i.signal),r.sha256&&(i.onProgress?.({phase:"install",stage:"verify"}),i.signal?.throwIfAborted(),d=await th(c),i.signal?.throwIfAborted(),d!==ty(r.sha256)))throw Error(`device app sha256 mismatch: expected ${r.sha256}, got ${d}`);eA().mkdirSync(u,{recursive:!0}),i.onProgress?.({phase:"install",stage:"extract"}),await tl(c,u,o,i);let v=tv(u,r.entry,"device app package entry");(function(e,t){if(!eA().existsSync(e))throw Error(`device app entry not found after extraction: ${e}`);let n=eA().statSync(e);if("darwin"===t){if(!n.isDirectory()||!e.endsWith(".app"))throw Error(`macOS device app entry must be a .app directory: ${e}`);return}if("win32"===t&&(!n.isFile()||!e.toLowerCase().endsWith(".exe")))throw Error(`Windows device app entry must be an .exe file: ${e}`)})(v,o),function(e,t,n,r,o){let i=tc(e);if(i&&(i.cliVersion!==t.cliVersion||i.deviceAppVersion!==o||i.entry!==r.entry||i.platform!==n||!tb(i.sha256,r)))throw Error(`device app metadata does not match CLI manifest in ${ek().join(e,e$)}`)}(u,t,n,r,s),i.onProgress?.({phase:"install",stage:"install"}),eA().rmSync(p,{recursive:!0,force:!0}),eA().renameSync(u,p),h=p,f=t,m=n,g=r,_=s,w=a,l={name:"Doubao App V2",cliVersion:f.cliVersion,deviceAppVersion:_,entry:g.entry,platform:m,...g.sha256?{sha256:ty(g.sha256)}:{},installedAt:w},tA(ek().join(h,e$),l),y=e,b={activeDeviceAppVersion:s,cliVersion:t.cliVersion,entry:r.entry,platform:n,...r.sha256?{sha256:ty(r.sha256)}:{},installedAt:a},tA(ek().join(y,eN),b);let E=tv(p,r.entry,"device app entry");return i.onProgress?.({phase:"complete",appPath:E}),E}finally{eA().rmSync(l,{recursive:!0,force:!0})}}async function ta(e,n,r=fetch,o,i){var s,a;let d,l,c,u,p,h,f=new URL(e);if("https:"!==f.protocol&&"http:"!==f.protocol)throw Error(`device app package URL must be http(s): ${e}`);i?.throwIfAborted();let m=await r(e,{signal:i});if(!m.ok)throw Error(`device app package download failed: HTTP ${m.status} ${m.statusText}`);if(!m.body)throw Error("device app package download failed: empty response body");let g=m.body;await (0,t.pipeline)(eD.Readable.fromWeb(g),(s=m,a=o,d=function(e){if(!e)return;let t=Number(e);return Number.isFinite(t)&&t>0?t:void 0}(s.headers.get("content-length")),l=0,c=-1,u=0,p=Date.now(),(h=e=>{if(!a)return;if(d){let t=Math.min(100,Math.floor(l/d*100));if(!e&&100!==t&&t<c+10||t===c)return;c=t;let n=Date.now()-p;a({phase:"download",downloadedBytes:l,totalBytes:d,percentage:t,elapsedMs:n});return}if(!e&&l-u<0x3200000||l===u)return;u=l;let t=Date.now()-p;a({phase:"download",downloadedBytes:l,elapsedMs:t})})(!1),new eD.Transform({transform(e,t,n){l+=e.length,h(!1),n(null,e)},flush(e){h(!0),e()}})),eA().createWriteStream(n),{signal:i})}function td(e){let t=["B","KB","MB","GB"],n=e,r=0;for(;n>=1024&&r<t.length-1;)n/=1024,r+=1;return 0===r?`${n} ${t[r]}`:`${n.toFixed(1)} ${t[r]}`}async function tl(e,t,n,r){let o=r.runCommand??((e,t)=>tC(e,{rejectOnNonZero:!0,signal:t?.signal}).then(()=>void 0));if("darwin"===n){r.signal?.throwIfAborted(),await o({command:"ditto",args:["-x","-k",e,t]},{signal:r.signal});return}if("win32"===n){r.signal?.throwIfAborted(),await o({command:"powershell.exe",args:["-NoProfile","-ExecutionPolicy","Bypass","-Command",`Expand-Archive -LiteralPath ${tE(e)} -DestinationPath ${tE(t)} -Force`],windowsVerbatimArguments:!0},{signal:r.signal});return}throw Error(`device app zip extraction is not supported on ${n}`)}function tc(e){let t=tI(ek().join(e,e$));if(!m(t))return;let n=t.cliVersion,r=t.deviceAppVersion,o=t.entry,i=t.platform,s=t.sha256,a=t.installedAt;if("string"==typeof n&&"string"==typeof r&&"string"==typeof o&&"string"==typeof i&&(void 0===s||"string"==typeof s)&&"number"==typeof a)return{name:"string"==typeof t.name?t.name:void 0,cliVersion:n,deviceAppVersion:r,entry:o,platform:i,..."string"==typeof s?{sha256:s}:{},installedAt:a}}function tu(e){let t=tI(ek().join(e,eN));if(m(t)&&"string"==typeof t.activeDeviceAppVersion&&"string"==typeof t.cliVersion&&"string"==typeof t.entry&&"string"==typeof t.platform&&(void 0===t.sha256||"string"==typeof t.sha256)&&"number"==typeof t.installedAt)return{activeDeviceAppVersion:t.activeDeviceAppVersion,cliVersion:t.cliVersion,entry:t.entry,platform:t.platform,..."string"==typeof t.sha256?{sha256:t.sha256}:{},installedAt:t.installedAt}}function tp(e,t){let n=ek().join(e,eq);if(eA().existsSync(n)){for(let e of eA().readdirSync(n,{withFileTypes:!0}))if(e.isDirectory()&&e.name!==t)try{eA().rmSync(ek().join(n,e.name),{recursive:!0,force:!0})}catch{}}}async function th(e){let n=eE().createHash("sha256");return await (0,t.pipeline)(eA().createReadStream(e),n),n.digest("hex")}function tf(e,t){return tm(t),ek().join(e,eq,t)}function tm(e){if(!/^[0-9A-Za-z._+-]+$/.test(e))throw Error(`device app version contains unsupported path characters: ${e}`)}function tg(e){if(1!==e.schemaVersion)throw Error(`unsupported device app manifest schemaVersion: ${e.schemaVersion}`);if(!e.cliVersion.trim())throw Error("device app manifest cliVersion is required");if(!e.deviceAppVersion.trim())throw Error("device app manifest deviceAppVersion is required");tm(e.deviceAppVersion)}function t_(e){if(!e.url||!e.entry)throw Error("device app package requires url and entry");if(void 0!==e.version){if(!e.version.trim())throw Error("device app package version must not be empty");tm(e.version)}if(e.sha256&&!/^[0-9a-fA-F]{64}$/.test(e.sha256))throw Error(`device app package sha256 must be 64 hex characters: ${e.sha256}`);if(void 0!==e.sizeBytes&&(!Number.isSafeInteger(e.sizeBytes)||e.sizeBytes<=0))throw Error(`device app package sizeBytes must be a positive integer: ${e.sizeBytes}`);if(ek().isAbsolute(e.entry)||e.entry.split(/[\\/]+/).includes(".."))throw Error(`device app package entry must be a relative path inside the zip: ${e.entry}`)}function tw(e,t){let n=t.version??e.deviceAppVersion;if(!n.trim())throw Error("device app package version must not be empty");return tm(n),n}function ty(e){return e.toLowerCase()}function tb(e,t){return!t.sha256||e===ty(t.sha256)}function tv(e,t,n){if(ek().isAbsolute(t))throw Error(`${n} must be relative: ${t}`);let r=ek().resolve(e),o=ek().resolve(e,t);if(o!==r&&!o.startsWith(`${r}${ek().sep}`))throw Error(`${n} escapes target directory: ${t}`);return o}function tE(e){return`'${e.replace(/'/g,"''")}'`}function tI(e){try{return JSON.parse(eA().readFileSync(e,"utf8"))}catch{return}}function tA(e,t){eA().mkdirSync(ek().dirname(e),{recursive:!0}),eA().writeFileSync(e,`${JSON.stringify(t,null,2)}
13
- `,"utf8")}async function tT(e){let t=function(e){if(!e.endsWith(".app"))return;let t=function(e){let t=ek().join(e,"Contents","Info.plist");if(!eA().existsSync(t))return;let n=eA().readFileSync(t,"utf8").match(/<key>CFBundleExecutable<\/key>\s*<string>([^<]+)<\/string>/);return n?.[1]}(e)??ek().basename(e,".app");return ek().join(e,"Contents","MacOS",t)}(e);await tC(tj(e,"darwin"),{rejectOnNonZero:!1}),!t||await tS(t)&&await tC({command:"pkill",args:["-f",tk(t)]},{rejectOnNonZero:!1})}function tC(e,t){return new Promise((n,r)=>{let o;t.signal?.throwIfAborted();let i=(0,eb.spawn)(e.command,e.args,{stdio:"ignore",windowsVerbatimArguments:e.windowsVerbatimArguments}),s=!1,a=()=>{i.kill(),(o=setTimeout(()=>i.kill("SIGKILL"),1e3)).unref()},d=e=>{s||(s=!0,clearTimeout(o),t.signal?.removeEventListener("abort",a),e())};t.signal?.addEventListener("abort",a,{once:!0}),i.once("error",e=>d(()=>r(e))),i.once("close",o=>{if(t.signal?.aborted)return void d(()=>r(t.signal?.reason instanceof Error?t.signal.reason:new tZ));let i=o??0;0!==i&&t.rejectOnNonZero?d(()=>r(Error(`${e.command} exited with code ${i}`))):d(()=>n(i))})})}async function tS(e){return 0===await tC({command:"pgrep",args:["-f",tk(e)]},{rejectOnNonZero:!1})}function tj(e,t){return"darwin"===t?{command:"osascript",args:["-e",`tell application (POSIX file "${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}" as alias) to quit`]}:"win32"===t?{command:"cmd",args:["/c","taskkill","/IM",ek().basename(e),"/T"],windowsVerbatimArguments:!0}:{command:"pkill",args:["-f",e]}}function tk(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}async function tD(e,t,n){let r=await e.client.call(n);if(!r.length)return void nn(e.output,`no ${t}s found`);for(let n of r)nn(e.output,`- ${ne(t,n)}`)}async function tP(e,t){if(t.length>0)throw Error("sessions does not accept arguments");let n=await tB(e,"sessions"),{session:r}=n;try{let t=await r.getConnectedClients();if(0===t.length)throw new U("DEVICE_NOT_CONNECTED","no debug device is connected");let n=t.flatMap(e=>e.sessions.filter(J).map(t=>({clientId:e.device.clientId,sessionId:t.sessionId,url:t.url}))).sort((e,t)=>e.clientId-t.clientId||t.sessionId-e.sessionId);if(0===n.length)throw new U("NO_ACTIVE_LYNX_SESSION","the connected device has no active Lynx session");let o=r.getRuntimeInspectionTarget?await r.getRuntimeInspectionTarget().catch(()=>null):null,i=tN(e),s=e.activeClientId??(1===t.length?t[0]?.device.clientId:void 0),a=void 0===s?void 0:n.find(e=>e.clientId===s);for(let t of n){let n=[tq(t,o)?"electron":void 0,"fixed"===i.kind&&tq(t,i.target)?"cli":void 0,tq(t,a)?"latest":void 0].filter(e=>void 0!==e);nn(e.output,`${H(t)}${n.length?` ${n.map(e=>`[${e}]`).join(" ")}`:""} ${t.url||"unknown"}`)}}finally{n.owned&&await r.stop().catch(()=>void 0)}}async function tx(e,t){if(1!==t.length)throw Error("use-session requires @<clientId>:<sessionId> or latest");if(t[0]?.toLowerCase()==="latest"){e.runtimeInspectionTargetPolicy={kind:"latest"},nn(e.output,r.bold.blueBright(`CLI 调试目标已恢复为 latest${void 0===e.activeClientId?"":`(client ${e.activeClientId} 内最新活跃 Lynx session)`};不会切换 Electron。`));return}let n=K(t[0]??""),o=await tB(e,"use-session"),{session:i}=o;try{let t=await V(i,{activeClientId:e.activeClientId,explicitTarget:n,signal:e.signal});e.runtimeInspectionTargetPolicy={kind:"fixed",target:{clientId:t.clientId,sessionId:t.sessionId}},nn(e.output,r.bold.blueBright(`CLI 调试目标已固定为 ${H(t)}(${t.url||"unknown"});不会切换 Electron。`))}finally{o.owned&&await i.stop().catch(()=>void 0)}}async function tL(e,t){let n=(0,ex.parseArgs)({args:t,allowPositionals:!1,options:{limit:{type:"string"},"timeout-seconds":{type:"string"},"include-stack-traces":{type:"boolean"},target:{type:"string"}}}),o=function(e){if(void 0===e)return;let t=Number(e);if(!Number.isSafeInteger(t)||t<1||t>100)throw Error("--limit must be an integer between 1 and 100");return t}(n.values.limit),i=function(e){if(void 0===e)return;let t=Number(e);if(!Number.isFinite(t)||t<=0)throw Error("--timeout-seconds must be a positive number");return Math.round(1e3*t)}(n.values["timeout-seconds"]),s=await tB(e,"get-console"),{session:a}=s;try{let t=await tM(e,a,n.values.target);nn(e.output,r.bold.blueBright(`正在监听 client ${t.clientId}、session ${t.sessionId}(${t.url||"unknown"})的新日志;按 Ctrl+C 停止监听。`));let s=await ed(a,t,{...void 0===o?{}:{limit:o},...void 0===i?{}:{timeoutMs:i},signal:e.signal,onTargetChange(n){nn(e.output,r.bold.blueBright(`提示:Electron 已切换到 client ${n.clientId}、session ${n.sessionId}(${n.url||"unknown"});当前 CLI 仍监听 client ${t.clientId}、session ${t.sessionId},不会自动跟随 Electron。`))},onMessage(t){nn(e.output,function(e,t={}){var n;let r=e.args.map(ep).join(" "),o=t.includeStackTraces||"error"===e.type?(n=e.stackTrace,m(n)&&Array.isArray(n.callFrames)?n.callFrames.filter(m).map(e=>{let t="string"==typeof e.url?e.url:"",n="number"==typeof e.lineNumber?e.lineNumber:"unknown",r="number"==typeof e.columnNumber?e.columnNumber:"unknown";return` at ${t}:${n}:${r}`}).join("\n"):""):"";return`[${e.type}/${e.thread}] ${r}${o?`
14
- ${o}`:""}`}(t,{includeStackTraces:n.values["include-stack-traces"]}))}});nn(e.output,`日志监听已停止,共 ${s.count} 条。`)}finally{s.owned&&await a.stop().catch(()=>void 0)}}async function tR(e,t,n=!1){let r=(0,ex.parseArgs)({args:t,allowPositionals:!1,options:{output:{type:"string",short:"o"},target:{type:"string"}}}),o=await tB(e,"take-screenshot"),{session:i}=o;try{let t=await tM(e,i,r.values.target),o=await el(i,t,{activeCapture:!e.manageDeviceApp}),s=ek().resolve(r.values.output??`screenshot-${Date.now()}.jpeg`);await eA().promises.writeFile(s,Buffer.from(o.data,"base64")),n?nr(e.output,{ok:!0,command:"take-screenshot",target:t,output:s,format:o.format,source:o.source,width:o.width,height:o.height,byteLength:o.byteLength}):nn(e.output,`截图已保存:${s}(${o.width}\xd7${o.height},client ${t.clientId}、session ${t.sessionId},${t.url||"unknown"};${e.manageDeviceApp?"范围跟随 Electron 当前 mode":"由设备按当前截图 mode 生成"})`)}finally{o.owned&&await i.stop().catch(()=>void 0)}}async function tO(e,t,n=!1){let r=(0,ex.parseArgs)({args:t,allowPositionals:!1,options:{depth:{type:"string"},target:{type:"string"}}}),o=function(e){if(void 0===e)return -1;let t=Number(e);if(!Number.isSafeInteger(t)||t<-1)throw Error("--depth must be -1 or a non-negative integer");return t}(r.values.depth),i=await tB(e,"get-page-tree"),{session:s}=i;try{let t=await tM(e,s,r.values.target),i=await W(s,t,{depth:o});if(n)nr(e.output,{ok:!0,command:"get-page-tree",...i});else{let n,r;nn(e.output,`DOM tree: client ${t.clientId}、session ${t.sessionId}(${t.url||"unknown"})`),nn(e.output,(n=[],(r=(e,t,o)=>{n.push(`${t}${o}${function(e){if(er(e))return`${e.ref} #text ${es(e.nodeValue)}`;let t=(e.localName||e.nodeName).toLowerCase();if(t.startsWith("#"))return`${e.ref} ${t}`;let n=Object.entries(e.attributes).map(([e,t])=>`${e}=${es(t,80)}`).join(" "),r=e.text||e.children.filter(er).map(e=>e.nodeValue).join("");return[e.ref,`<${t}${n?` ${n}`:""}>`,r?es(r,120):""].filter(Boolean).join(" ")}(e)}`);let i=e.children.filter(e=>!er(e));i.forEach((e,n)=>{r(e,`${t}${o?"└─ "===o?" ":"│ ":""}`,n===i.length-1?"└─ ":"├─ ")})})(i.root,"",""),i.truncated&&n.push(`… tree truncated after ${i.nodeCount} nodes`),n.join("\n"))),nn(e.output,`共 ${i.nodeCount} 个节点${i.truncated?"(已截断)":""}。`)}}finally{i.owned&&await s.stop().catch(()=>void 0)}}async function t$(e,t,n=!1){let r=(0,ex.parseArgs)({args:t,allowPositionals:!0,options:{properties:{type:"string"}}}),o=r.positionals[0];if(!o)throw new U("INVALID_NODE_REF","node-ref is required; run get-page-tree and pass @<clientId>:<sessionId>:<nodeId>");if(r.positionals.length>1)throw Error("get-computed-style accepts exactly one node-ref");let i=function(e){let t=/^@([1-9]\d*):([1-9]\d*):([1-9]\d*)$/.exec(e.trim());if(!t)throw new U("INVALID_NODE_REF",`invalid node ref "${e}"; expected @<clientId>:<sessionId>:<nodeId>`);let n={clientId:Number(t[1]),sessionId:Number(t[2]),nodeId:Number(t[3])};if(!Number.isSafeInteger(n.clientId)||!Number.isSafeInteger(n.sessionId)||!Number.isSafeInteger(n.nodeId))throw new U("INVALID_NODE_REF",`invalid node ref "${e}"; every id must be a safe integer`);return n}(o),s=function(e){if(void 0===e)return[];let t=e.split(",").map(e=>e.trim());if(0===t.length||t.some(e=>!/^-{0,2}[a-z][a-z0-9-]*$/i.test(e)))throw Error("--properties must be a comma-separated list of CSS property names");return[...new Set(t.map(e=>e.toLowerCase()))]}(r.values.properties),a=await tB(e,"get-computed-style"),{session:d}=a;try{let t=await Y(d,i),r=await G(d,t,i,s);if(n)nr(e.output,{ok:!0,command:"get-computed-style",...r});else if(nn(e.output,`${r.nodeRef} computed style(client ${t.clientId}、session ${t.sessionId})`),0===r.properties.length)nn(e.output,"没有匹配的 computed style 属性。");else{let t=Math.max(...r.properties.map(e=>e.name.length));for(let n of r.properties)nn(e.output,` ${n.name.padEnd(t)} ${n.value}`)}}finally{a.owned&&await d.stop().catch(()=>void 0)}}function tN(e){return e.runtimeInspectionTargetPolicy??{kind:"latest"}}function tq(e,t){return null!=e&&null!=t&&e.clientId===t.clientId&&e.sessionId===t.sessionId}function tM(e,t,n){return V(t,{activeClientId:e.activeClientId,policy:tN(e),...void 0===n?{}:{explicitTarget:K(n)},signal:e.signal})}async function tB(e,t){if(e.runtimeInspectionSession)return{owned:!1,session:await e.runtimeInspectionSession};let n=e.createRuntimeInspectionSession??F;return{owned:!0,session:await n({namespace:e.runtime.getState().namespace,nodeIdPrefix:`dev-shell-${t}`})}}async function tU(e,t){let n=(0,ex.parseArgs)({args:t,allowPositionals:!0,options:{"device-id":{type:"string"}}}),r=n.positionals[0]??await tH(e,"page",g.discoverPages);if(!r)throw Error("page url is required");let o=n.values["device-id"]??e.activeDeviceId;nn(e.output,`debug: page open request ${nt({url:r,deviceId:o})}`);let i=_("page",await e.client.call(g.openPageUrl,{url:r,deviceId:o}));nn(e.output,`page opened: ${r}`),nn(e.output,`status: ${tV(i)}`)}async function tF(e,t){let n=(0,ex.parseArgs)({args:t,allowPositionals:!0,options:{data:{type:"string"},"bot-id":{type:"string"},"device-id":{type:"string"}}}),r=n.positionals[0]??await tH(e,"widget",g.discoverWidgets);if(!r)throw Error("widget id is required");let o=y(n.values.data,"--data"),i=n.values["device-id"]??e.activeDeviceId;nn(e.output,`debug: widget push request ${nt({widgetId:r,data:o,botId:n.values["bot-id"],deviceId:i})}`);let s=_("widget",await e.client.call(g.pushWidget,{widgetId:r,widgetData:o,botId:n.values["bot-id"],deviceId:i}));nn(e.output,`widget pushed: ${r}`),nn(e.output,`status: ${tV(s)}`)}function tV(e){if(!e.ok)return"failed";let t=function(e){if(!e||"object"!=typeof e)return;let t=e.data;if(!t||"object"!=typeof t)return;let n=t.msg;return"string"==typeof n?n:void 0}(e.result);return"string"==typeof t&&t.trim()?t:"ok"}async function tH(e,t,n){let r=await e.client.call(n);if(r.length)return e.selectItem(t,r,e.output)}function tK(e,t){return t.map(t=>{let n=t9(e,t);return n?{label:ne(e,t),value:n}:void 0}).filter(e=>!!e)}async function tz(e){var t,r;let o,i,s,a,l=e.timeoutMs??6e4;if(!e.hostUrl||!e.appKey)return{ok:!1,status:"skipped",timeoutMs:l,failureStage:"create_qr",error:"无法生成二维码,缺少 hostUrl 或 appKey。"};let c=e.hostUrl,u=e.appKey,p=(t=e.namespace,r=l,i=new E(t,{nodeId:`dev-auth-${process.pid}-${Math.random().toString(36).slice(2,8)}`,requestTimeout:2e3}),s=!1,a=new Promise(e=>{o=e}),i.createService({name:`devAuthListener${process.pid}`,events:{"connection.newclient"(e){var t;s||(s=!0,o((t=e.params)&&"object"==typeof t?{scope:"string"==typeof t.scope?t.scope:void 0,type:"string"==typeof t.type?t.type:void 0,clientId:"number"==typeof t.clientId?t.clientId:void 0,deviceId:t4(t),app:"string"==typeof t.app?t.app:void 0}:{}))}}}),{start:()=>i.start(),stop:()=>i.stop(),wait:(e,t=r)=>{var n,o,i;return n=a,o=t,i=e,new Promise((e,t)=>{let r=()=>{clearTimeout(s),t(i?.reason instanceof Error?i.reason:new tZ)},s=setTimeout(()=>{i?.removeEventListener("abort",r),t(new tX(o))},o);i?.aborted?r():(i?.addEventListener("abort",r,{once:!0}),n.then(t=>{clearTimeout(s),i?.removeEventListener("abort",r),e(t)},e=>{clearTimeout(s),i?.removeEventListener("abort",r),t(e)}))})},async findExistingClient(){let e=await t2(()=>i.call("devtoolConnection.getConnectedClients"),2e3).catch(()=>[]);return function(e){if(!e||"object"!=typeof e)return;let t=e.device,n=t?.info,r="number"==typeof t?.clientId?t.clientId:void 0;return{scope:"all",type:String(n?.network??"").toLowerCase().includes("wifi")?"wifi":"usb",...void 0===r?{}:{clientId:r},deviceId:t4({client:e}),app:"string"==typeof n?.App?n.App:""}}(Array.isArray(e)?e[0]:void 0)},async awaitDirectDebugReady(e){let t=Math.min(r,2500);try{return await i.call(g.awaitDirectDebugReady,{clientId:e,timeoutMs:t},{timeout:t+1e3})}catch{return!1}},waitForInstallResult:(e,t,n,r)=>{var o,s;return o=i.call(g.awaitDeviceInstallResult,{clientId:e,packageName:t,timeoutMs:n},{timeout:n+1e3}),(s=r)?new Promise((e,t)=>{let n=()=>{t(s.reason instanceof Error?s.reason:new tZ)};if(s.aborted){o.catch(()=>void 0),n();return}s.addEventListener("abort",n,{once:!0}),o.then(t=>{s.removeEventListener("abort",n),e(t)},e=>{s.removeEventListener("abort",n),t(e)})}):o}}),h={},f="connection",m="wait_device_connection";await p.start();try{let t;e.signal?.throwIfAborted();let r=await p.findExistingClient(),o=r?.clientId!==void 0&&await p.awaitDirectDebugReady(r.clientId);if(o)await e.onPhaseChange?.("reusing_client");else{let r,o,i;m="create_qr",t=await tY(h,()=>(0,eL.Ph)(function(e,t,r={}){let o=tW(r.settings);return{hostUrl:e,appKey:t,...void 0===r.versionTag?{}:{versionTag:r.versionTag},isSigned:!1,appletType:0,baseApiUrl:n(),authOptions:d(),...!1===o.defaultDebugTagState?{defaultDebugTagState:!1}:{},...!o.usb&&r.wifiConnectUrl?{wifiConnectUrl:r.wifiConnectUrl}:{}}}(c,u,{versionTag:e.versionTag,settings:e.settings,wifiConnectUrl:e.wifiConnectUrl})),e.signal),await e.onPhaseChange?.("waiting_for_scan"),nn(e.output,""),nn(e.output,"使用豆包 App 扫码连接调试设备."),nn(e.output,`二维码创建成功,请在 ${(r=Math.max(1,Math.round(l/1e3)),o=Math.floor(r/60),i=r%60,o>0?`${o}m ${i}s`:`${i}s`)} 前扫码; 超时可在真机模式执行 \`qr\` 创建新二维码.`),nn(e.output,""),await e.onQRCodeReady?.(t.qrCodeValue,t.debugToken),e.signal?.throwIfAborted()}m="wait_device_connection";let i=Date.now()+l;nn(e.output,`等待设备连接 (${l/1e3}s timeout)...`);let s=o?r:await p.wait(e.signal,t1(i));if(void 0===s.clientId)throw Error("连接的设备缺少 clientId");f="install",m="install_debug_package",await e.onPhaseChange?.("waiting_for_install");let a=await p.waitForInstallResult(s.clientId,u,t1(i),e.signal);if(!a)throw new tX(l);if(!a.success)return{ok:!1,status:"skipped",timeoutMs:l,failureStage:m,waitingFor:f,client:s,error:a.message||"安装 AIPackage 失败,请检查网络环境并关注客户端提示"};return{ok:!0,status:"connected",timeoutMs:l,...t?{qrCodeValue:t.qrCodeValue,debugToken:t.debugToken,encryptedDebugPayload:t.encryptedDebugPayload}:{},client:s}}catch(o){let t=o instanceof tX,n=o instanceof tZ||!!e.signal?.aborted,r=function(e){if(e&&"object"==typeof e)return tJ(e,"logId")??tJ(e,"log_id")}(o)??h.logId;return{ok:!1,status:n?"cancelled":t?"timeout":"skipped",timeoutMs:l,failureStage:m,waitingFor:f,...r?{logId:r}:{},error:o instanceof Error?o.message:String(o)}}finally{await p.stop()}}async function tY(e,t,n){let r=globalThis.fetch;globalThis.fetch=async(t,o)=>{var i;let s,a=(s=function(e){try{if("string"==typeof e)return new URL(e);if(e instanceof URL)return new URL(e.toString());return new URL(e.url)}catch{return}}(i=t))&&s.pathname.startsWith("/developer/check_api/apps/")&&s.pathname.endsWith("/debug/ticket")?(s.pathname=s.pathname.replace(/^\/developer\/check_api\//,"/app_developer/check_api/"),"string"==typeof i)?s.toString():i instanceof URL?s:new Request(s,i):i,d=await r(a,n&&a!==t&&!o?.signal?{...o,signal:n}:o);return await tG(e,d),d};try{return await t()}finally{globalThis.fetch=r}}function tW(e){return{defaultDebugTagState:e?.defaultDebugTagState??!0,usb:e?.usb??!0}}async function tG(e,t){let n=t.headers.get("x-tt-logid");if(n){e.logId=n;return}try{let n=await t.clone().text();if(!n)return;let r=JSON.parse(n),o=tJ(r,"log_id")??tJ(r,"logId");o&&(e.logId=o)}catch{}}function tJ(e,t){if(!e||"object"!=typeof e)return;let n=e[t];return"string"==typeof n&&n?n:void 0}function tQ(e){return e.replace(/\s*[\[((]log_id:\s*[^\]))]+[\]))]/gi,"").trim()}class tX extends Error{constructor(e){super(`real-device auth timed out after ${e}ms`),this.name="RealDeviceAuthTimeoutError"}}class tZ extends Error{constructor(){super("real-device auth cancelled"),this.name="RealDeviceAuthCancelledError"}}function t0(e,t){let n=new E(e,{nodeId:`dev-disconnect-${process.pid}-${Math.random().toString(36).slice(2,8)}`,requestTimeout:2e3});return n.createService({name:`devDisconnectListener${process.pid}`,events:{"connection.clientDisconnected":()=>t()}}),{start:()=>n.start(),stop:()=>n.stop()}}function t1(e){return Math.max(0,e-Date.now())}async function t2(e,t){let n=Date.now()+t;for(;;)try{return await e()}catch(e){if(Date.now()>=n)throw e;await new Promise(e=>{setTimeout(e,100)})}}function t4(e){let t=e.client?.device,n=t?.info;return n?.usbDeviceId||t?.xdbId||n?.did||n?.debugRouterId}async function t5(e,t){let n=ek().resolve(t);if(".png"!==ek().extname(n).toLowerCase())throw Error("QR file must use the .png extension");return eA().mkdirSync(ek().dirname(n),{recursive:!0}),await eR.toFile(n,e,{errorCorrectionLevel:"L",margin:4,type:"png"}),n}async function t3(e,t){let n=await eR.toBuffer(e,{errorCorrectionLevel:"L",margin:0,type:"png",width:320}),r=t?await eR.toBuffer(`doubaoapp://local_debug?short_token=${t}`,{errorCorrectionLevel:"L",margin:0,type:"png",width:320}):void 0;return{legacy:n,...r?{modern:r}:{}}}function t6(e=eS().tmpdir()){let t;try{t=eA().readdirSync(e,{withFileTypes:!0})}catch{return}for(let n of t)if(/^dbx-real-device-qr-.*\.(?:png|svg)$/i.test(n.name)&&(n.isFile()||n.isSymbolicLink()))try{eA().unlinkSync(ek().join(e,n.name))}catch{}}async function t8(e,t,n,r=process.stderr,o){let i,s,a;if(n){let t=await t5(e,n);nn(r,`二维码图片已导出至:${t}`)}let{legacy:d,modern:l}=await t3(e,o),c=eE().randomBytes(18).toString("hex"),u=`/${c}/`,p=new Set,h=!1,f=new Promise(e=>{s=e}),m=()=>{clearTimeout(i),i=void 0,h||s()},g=(0,eT.createServer)((e,t)=>{let n=e.url?.split("?",1)[0];if(t.setHeader("Cache-Control","no-store, no-cache, must-revalidate, max-age=0"),t.setHeader("Expires","0"),t.setHeader("Pragma","no-cache"),"GET"===e.method&&n===u){var r;t.writeHead(200,{"Content-Security-Policy":"default-src 'none'; img-src 'self'; connect-src 'self'; script-src 'unsafe-inline'; style-src 'unsafe-inline'","Content-Type":"text/html; charset=utf-8"}),t.end((r=!!l,`<!doctype html>
11
+ `),e}catch(e){if(I(e)&&"EEXIST"===e.code)return this.readMasterKey();throw new p(`Failed to write encrypted token master key: ${A(e)}`)}}}class g{async get(e){try{let{stdout:t}=await d("security",["find-generic-password","-a",e,"-s",l,"-w"]);return String(t).replace(/\n$/,"")}catch(e){if(y(e))return;throw new p(`Failed to read token from macOS Keychain: ${A(e)}`)}}async set(e,t){try{await d("security",["add-generic-password","-a",e,"-s",l,"-w",t,"-U"])}catch(e){throw new p(`Failed to write token to macOS Keychain: ${A(e)}`)}}async delete(e){try{await d("security",["delete-generic-password","-a",e,"-s",l])}catch(e){if(y(e))return;throw new p(`Failed to delete token from macOS Keychain: ${A(e)}`)}}}class _{async get(e){try{let{stdout:t}=await d("secret-tool",["lookup","service",l,"account",e]);return String(t).replace(/\n$/,"")}catch(e){if(b(e))return;throw new p(`Failed to read token from Secret Service: ${A(e)}`)}}async set(e,t){try{var n,o,i;await (n="secret-tool",o=["store","--label","Doubao Open CLI token","service",l,"account",e],i=t,new Promise((e,t)=>{let s=(0,r.spawn)(n,o,{stdio:["pipe","ignore","pipe"]}),a="";s.stderr.setEncoding("utf8"),s.stderr.on("data",e=>{a+=String(e)}),s.on("error",t),s.on("close",r=>{0===r?e():t(Error(a.trim()||`${n} exited with code ${r}`))}),s.stdin.end(i)}))}catch(e){throw new p(`Failed to write token to Secret Service: ${A(e)}`)}}async delete(e){try{await d("secret-tool",["clear","service",l,"account",e])}catch(e){if(b(e))return;throw new p(`Failed to delete token from Secret Service: ${A(e)}`)}}}async function w(e,t){let n=a.dirname(e);await i.promises.mkdir(n,{recursive:!0,mode:448}),"win32"!==process.platform&&await i.promises.chmod(n,448);let r=a.join(n,`.${a.basename(e)}.${process.pid}.${Date.now()}.tmp`);try{await i.promises.writeFile(r,t,{mode:384,flag:"wx"}),"win32"!==process.platform&&await i.promises.chmod(r,384),await i.promises.rename(r,e),"win32"!==process.platform&&await i.promises.chmod(e,384)}finally{try{await i.promises.unlink(r)}catch{}}}function y(e){let t=v(e),n=E(e);return(1===t||44===t)&&(n.includes("could not be found")||n.includes("The specified item could not be found"))}function b(e){let t=v(e),n=E(e);return 1===t&&(n.includes("could not be found")||n.includes("No matching items")||""===n.trim())}function v(e){return"object"==typeof e&&null!==e&&"code"in e?e.code:void 0}function E(e){return"object"==typeof e&&null!==e&&"stderr"in e?String(e.stderr??""):""}function I(e){return e instanceof Error&&"code"in e}function A(e){if("object"==typeof e&&null!==e&&"stderr"in e){let t=String(e.stderr??"").trim();if(t)return t}return e instanceof Error&&e.message?e.message:String(e)}n.d(t,{Mj:()=>h,RI:()=>p})},"../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.26/node_modules/@byted-doubao-apps/auth-cli/dist/device-flow.js"(e,t,n){var r=n("../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.26/node_modules/@byted-doubao-apps/auth-cli/dist/config.js"),o=n("../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.26/node_modules/@byted-doubao-apps/auth-cli/dist/errors.js"),i=n("../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.26/node_modules/@byted-doubao-apps/auth-cli/dist/jwt.js"),s=n("../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.26/node_modules/@byted-doubao-apps/auth-cli/dist/store.js"),a=n("../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.26/node_modules/@byted-doubao-apps/auth-cli/dist/types.js");async function d(e={}){let t=(0,r.$i)(e),n=t.fetch??fetch,l=t.sleep??w,c=await u(n,t.baseUrl,t.requestHeaders),h=y(t.baseUrl,c.user_code);t.onVerification?.({userCode:c.user_code,verificationUrl:h,expiresIn:c.expires_in,interval:c.interval});let f=Math.max(1,c.interval),m=Date.now()+1e3*c.expires_in;for(;Date.now()<m;){await l(1e3*f);let e=await p(n,t.baseUrl,c.device_code,t.requestHeaders);if(t.onPoll?.({status:e.status,interval:f}),e.status!==a.A.Pending){if(e.status===a.A.SlowDown){f+=Math.max(1,c.interval);continue}if(e.status===a.A.Expired)throw new o.JC("Device authorization expired","DEVICE_AUTH_EXPIRED");if(e.status===a.A.Invalid)throw new o.JC("Device authorization is invalid","DEVICE_AUTH_INVALID");if(e.status===a.A.Authorized){if(!e.access_token)throw new o.JC("Authorization response did not include an access token");let n=_(e,t.baseUrl);return await (0,s.tK)(t.tokenPath,n,{credentialStore:t.credentialStore}),{accessToken:n.accessToken,tokenType:n.tokenType,expiresAt:n.expiresAt,baseUrl:n.baseUrl,uid:(0,i.m)(n.accessToken),tokenPath:t.tokenPath}}throw new o.JC(`Unexpected authorization status: ${String(e.status)}`)}}throw new o.JC("Device authorization timed out","DEVICE_AUTH_EXPIRED")}async function l(e={}){let t=(0,r.$i)(e),n=t.fetch??fetch,o=await u(n,t.baseUrl,t.requestHeaders),i=y(t.baseUrl,o.user_code);return t.onVerification?.({userCode:o.user_code,verificationUrl:i,expiresIn:o.expires_in,interval:o.interval}),{userCode:o.user_code,deviceCode:o.device_code,verificationUrl:i,expiresIn:o.expires_in,interval:o.interval}}async function c(e,t={}){let n=(0,r.$i)(t),d=n.fetch??fetch,l=n.sleep??w,u=n.baseUrl,h=n.requestHeaders,f=5,m=Date.now()+6e5;for(;Date.now()<m;){await l(1e3*f);let t=await p(d,u,e,h);if(n.onPoll?.({status:t.status,interval:f}),t.status!==a.A.Pending){if(t.status===a.A.SlowDown){f+=5;continue}if(t.status===a.A.Expired)throw new o.JC("Device authorization expired","DEVICE_AUTH_EXPIRED");if(t.status===a.A.Invalid)throw new o.JC("Device authorization is invalid","DEVICE_AUTH_INVALID");if(t.status===a.A.Authorized){if(!t.access_token)throw new o.JC("Authorization response did not include an access token");let e=_(t,u);return await (0,s.tK)(n.tokenPath,e,{credentialStore:n.credentialStore}),{accessToken:e.accessToken,tokenType:e.tokenType,expiresAt:e.expiresAt,baseUrl:e.baseUrl,uid:(0,i.m)(e.accessToken),tokenPath:n.tokenPath}}throw new o.JC(`Unexpected authorization status: ${String(t.status)}`)}}throw new o.JC("Device authorization timed out","DEVICE_AUTH_EXPIRED")}async function u(e,t,n){let i=await e(`${t}/app_developer/oauth/device/code`,{method:"POST",headers:g(n),body:JSON.stringify({client_name:r.E})}),s=await h(i),a=m(s);if(!a||!a.device_code||!a.user_code||"number"!=typeof a.expires_in||"number"!=typeof a.interval)throw new o.JC(`Device code response is malformed (HTTP ${i.status}): ${JSON.stringify(s)}`);return a}async function p(e,t,n,r){let i=await e(`${t}/app_developer/oauth/token`,{method:"POST",headers:g(r),body:JSON.stringify({device_code:n})}),s=await h(i),d=m(s);if(d?.access_token)return{status:a.A.Authorized,access_token:d.access_token,token_type:d.token_type,expires_in:d.expires_in,expires_at:d.expires_at};if(!d||"number"!=typeof d.status)throw new o.JC(`Token response is malformed (HTTP ${i.status}): ${JSON.stringify(s)}`);return d}async function h(e){var t;let n,r=e.headers.get("x-tt-logid")??void 0;try{n=await e.json()}catch{throw new o.JC(`Auth server returned non-JSON response with status ${e.status}${f(r)}`,"DEVICE_AUTH_FAILED",{logId:r})}let i=function(e){if(e&&"object"==typeof e)return"string"==typeof e.log_id&&e.log_id?e.log_id:void 0}(n)??r;if(!e.ok)throw new o.JC(`Auth server returned HTTP ${e.status}: ${JSON.stringify(n)}${f(i)}`,"DEVICE_AUTH_FAILED",{logId:i});let s=(t=n)&&"object"==typeof t&&"number"==typeof t.code&&0!==t.code?{code:t.code,message:"string"==typeof t.message?t.message:"Unknown error",logId:"string"==typeof t.log_id?t.log_id:void 0}:null;if(s)throw new o.JC(`Auth server error (code ${s.code}): ${s.message}${f(s.logId??i)}`,"DEVICE_AUTH_FAILED",{logId:s.logId??i});return n}function f(e){return e?` [log_id: ${e}]`:""}function m(e){return e&&"object"==typeof e&&"data"in e?e.data:e}function g(e){let t=new Headers(e);return t.set("Content-Type","application/json"),t}function _(e,t){let n=Math.floor(Date.now()/1e3);return{accessToken:e.access_token??"",tokenType:e.token_type??"Bearer",expiresAt:"number"==typeof e.expires_at?e.expires_at:n+(e.expires_in??0),baseUrl:t}}function w(e){return new Promise(t=>{setTimeout(t,e)})}function y(e,t){let n=new URL(e).host,r=new URL(`https://${n}/oauth/device`);return r.searchParams.set("user_code",t),r.toString()}n.d(t,{R$:()=>c,c$:()=>l,iD:()=>d})},"../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.26/node_modules/@byted-doubao-apps/auth-cli/dist/errors.js"(e,t,n){class r extends Error{constructor(e,t){super(e),this.code=t,this.name="AuthError"}}class o extends r{constructor(e="Not logged in"){super(e,"NOT_LOGGED_IN"),this.name="NotLoggedInError"}}class i extends r{constructor(e="Login token has expired"){super(e,"TOKEN_EXPIRED"),this.name="TokenExpiredError"}}class s extends r{constructor(e,t="DEVICE_AUTH_FAILED",n={}){super(e,t),this.name="DeviceAuthError",this.logId=n.logId}}n.d(t,{BX:()=>i,JC:()=>s,bG:()=>o,lR:()=>r})},"../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.26/node_modules/@byted-doubao-apps/auth-cli/dist/http.js"(e,t,n){var r=n("../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.26/node_modules/@byted-doubao-apps/auth-cli/dist/errors.js"),o=n("../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.26/node_modules/@byted-doubao-apps/auth-cli/dist/config.js"),i=n("../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.26/node_modules/@byted-doubao-apps/auth-cli/dist/store.js");function s(e=fetch,t={}){return async(n,s={})=>{let a=(0,o.$i)(t);var d=n,l=a.allowedOrigins;let c=function(e){try{if("string"==typeof e)return new URL(e);if(e instanceof URL)return e;return new URL(e.url)}catch{throw Error("Authenticated requests must use an absolute HTTPS URL")}}(d);if("https:"!==c.protocol)throw Error(`Authenticated requests must use https: ${c.toString()}`);if(!l.includes(c.origin))throw Error(`Refusing to attach Authorization header to untrusted origin: ${c.origin}`);let u=await (0,i.AI)(a.tokenPath,{allowExpired:!0,envTokenBaseUrl:a.baseUrl,credentialStore:a.credentialStore,legacyTokenPath:a.legacyTokenPath});if(!u)throw new r.bG;if((0,i._d)(u))throw new r.BX;let p=new Headers(s.headers);return a.requestHeaders.forEach((e,t)=>{p.set(t,e)}),p.set("Authorization",`${u.tokenType||"Bearer"} ${u.accessToken}`),e(n,{...s,headers:p})}}n.d(t,{r:()=>s})},"../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.26/node_modules/@byted-doubao-apps/auth-cli/dist/index.js"(e,t,n){n.r(t);var r=n("../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.26/node_modules/@byted-doubao-apps/auth-cli/dist/config.js"),o=n("../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.26/node_modules/@byted-doubao-apps/auth-cli/dist/credential-store.js"),i=n("../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.26/node_modules/@byted-doubao-apps/auth-cli/dist/device-flow.js"),s=n("../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.26/node_modules/@byted-doubao-apps/auth-cli/dist/store.js"),a=n("../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.26/node_modules/@byted-doubao-apps/auth-cli/dist/http.js"),d=n("../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.26/node_modules/@byted-doubao-apps/auth-cli/dist/errors.js"),l=n("../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.26/node_modules/@byted-doubao-apps/auth-cli/dist/types.js");async function c(e={}){let t=(0,r.$i)(e);await (0,s.ni)(t.tokenPath,{credentialStore:t.credentialStore}),t.legacyTokenPath&&await (0,s.ni)(t.legacyTokenPath,{credentialStore:t.credentialStore})}async function u(e={}){let t,n=(0,r.$i)(e);try{t=await (0,s.AI)(n.tokenPath,{envTokenBaseUrl:n.baseUrl,credentialStore:n.credentialStore,legacyTokenPath:n.legacyTokenPath})}catch(e){if(e instanceof o.RI)return{loggedIn:!1,tokenPath:n.tokenPath,baseUrl:n.baseUrl,credentialError:{code:"CREDENTIAL_STORE_UNAVAILABLE",message:e.message}};throw e}if(!t)return{loggedIn:!1,tokenPath:n.tokenPath};let i=await p(e.fetch??fetch,n.baseUrl,t,n.requestHeaders);return i?{loggedIn:!0,uid:i.userId,name:i.name,avatar:i.avatar,expiresAt:t.expiresAt,tokenPath:n.tokenPath,baseUrl:n.baseUrl}:{loggedIn:!1,expiresAt:t.expiresAt,tokenPath:n.tokenPath,baseUrl:n.baseUrl}}async function p(e,t,n,r){let o=new Headers(r);o.set("Authorization",`${n.tokenType||"Bearer"} ${n.accessToken}`);let i=await e(`${t.replace(/\/+$/,"")}/app_developer/api/user/basic`,{method:"GET",headers:o});if(!i.ok)return;let s=await i.json();if(0===s.code){var a;return{userId:"string"==typeof(a=s.data?.user_id)&&a.length>0?a:"number"==typeof a&&Number.isFinite(a)?String(a):void 0,name:s.data?.name,avatar:s.data?.avatar}}}n.d(t,{AuthError:()=>d.lR,CredentialStoreError:()=>o.RI,DeviceAuthError:()=>d.JC,NotLoggedInError:()=>d.bG,TokenExpiredError:()=>d.BX,TokenStatus:()=>l.A,completeLogin:()=>i.R$,configureAuth:()=>r.ZI,login:()=>i.iD,logout:()=>c,startLogin:()=>i.c$,whoami:()=>u,withAuth:()=>a.r})},"../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.26/node_modules/@byted-doubao-apps/auth-cli/dist/jwt.js"(e,t,n){function r(e){let t=function(e){let t=e.split(".")[1];if(t)try{let e=t.replace(/-/g,"+").replace(/_/g,"/"),n=e.padEnd(e.length+(4-e.length%4)%4,"="),r=Buffer.from(n,"base64").toString("utf8"),o=JSON.parse(r);return o&&"object"==typeof o?o:void 0}catch{return}}(e),n=t?.uid??t?.sub;return"string"==typeof n&&n.length>0?n:"number"==typeof n&&Number.isFinite(n)?String(n):void 0}n.d(t,{m:()=>r})},"../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.26/node_modules/@byted-doubao-apps/auth-cli/dist/store.js"(e,t,n){var r=n("node:fs"),o=n("node:crypto"),i=n("node:path"),s=n("../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.26/node_modules/@byted-doubao-apps/auth-cli/dist/credential-store.js");async function a(e,t={}){let n,r=process.env.DBX_ACCESS_TOKEN?.trim()||void 0;if(r)return{accessToken:r,tokenType:"Bearer",expiresAt:0xf4865700,baseUrl:t.envTokenBaseUrl??""};let o=await h(e);if(void 0===o)return f(e,t);try{n=JSON.parse(o)}catch(e){return}if(p(n)){if(!t.allowExpired&&c(n))return void await l(e,t);let r=await m(t).get(n.credentialAccount);if(!r)throw new s.RI("Stored login metadata exists, but the token credential is missing or inaccessible. Run dbx auth login again from a terminal that can access the credential store.");return{accessToken:r,tokenType:n.tokenType,expiresAt:n.expiresAt,baseUrl:n.baseUrl}}if(u(n))return!t.allowExpired&&c(n)?void await l(e,t):(await d(e,n,t),n)}async function d(e,t,n={}){let o={version:2,storage:"keychain",credentialAccount:g(e),tokenType:t.tokenType,expiresAt:t.expiresAt,baseUrl:t.baseUrl};await m(n).set(o.credentialAccount,t.accessToken),await r.promises.mkdir(i.dirname(e),{recursive:!0,mode:448}),"win32"!==process.platform&&await r.promises.chmod(i.dirname(e),448);let s=`${e}.${process.pid}.${Date.now()}.tmp`;await r.promises.writeFile(s,`${JSON.stringify(o,null,2)}
12
+ `,{mode:384}),"win32"!==process.platform&&await r.promises.chmod(s,384),await r.promises.rename(s,e),"win32"!==process.platform&&await r.promises.chmod(e,384)}async function l(e,t={}){let n=await h(e);if(void 0!==n)try{let r=JSON.parse(n);p(r)?await m(t).delete(r.credentialAccount):await m(t).delete(g(e))}catch{}try{await r.promises.unlink(e)}catch(e){if(!_(e)||"ENOENT"!==e.code)throw e}}function c(e,t=Math.floor(Date.now()/1e3)){return e.expiresAt<=t}function u(e){return!!e&&"object"==typeof e&&"string"==typeof e.accessToken&&e.accessToken.length>0&&"string"==typeof e.tokenType&&e.tokenType.length>0&&"number"==typeof e.expiresAt&&Number.isFinite(e.expiresAt)&&"string"==typeof e.baseUrl&&e.baseUrl.length>0}function p(e){return!!e&&"object"==typeof e&&2===e.version&&"keychain"===e.storage&&"string"==typeof e.credentialAccount&&e.credentialAccount.length>0&&"string"==typeof e.tokenType&&e.tokenType.length>0&&"number"==typeof e.expiresAt&&Number.isFinite(e.expiresAt)&&"string"==typeof e.baseUrl&&e.baseUrl.length>0}async function h(e){try{return await r.promises.readFile(e,"utf8")}catch(e){_(e)&&e.code;return}}async function f(e,t){let n;if(!t.legacyTokenPath||i.resolve(t.legacyTokenPath)===i.resolve(e))return;let r=await h(t.legacyTokenPath);if(void 0!==r){try{n=JSON.parse(r)}catch{return}if(u(n))return!t.allowExpired&&c(n)?void await l(t.legacyTokenPath,t):(await d(e,n,t),await l(t.legacyTokenPath,t),n)}}function m(e){return e.credentialStore??(0,s.Mj)()}function g(e){let t=o.createHash("sha256").update(i.resolve(e)).digest("hex").slice(0,32);return`token:${t}`}function _(e){return e instanceof Error&&"code"in e}n.d(t,{AI:()=>a,_d:()=>c,ni:()=>l,tK:()=>d})},"../../../node_modules/.pnpm/@byted-doubao-apps+auth-cli@0.0.26/node_modules/@byted-doubao-apps/auth-cli/dist/types.js"(e,t,n){var r,o;(o=r||(r={}))[o.Pending=1]="Pending",o[o.Authorized=2]="Authorized",o[o.Expired=3]="Expired",o[o.Invalid=4]="Invalid",o[o.SlowDown=5]="SlowDown",n.d(t,{A:()=>r})}});var $={};e.r($),e.d($,{createDeferredDevShellSession:()=>np,default:()=>nl,isInteractiveTerminal:()=>nf,withWebDebuggerFallback:()=>nm});let N=e("node:zlib"),q=e("../../../node_modules/.pnpm/@byted-doubao-tools+devtool-connection-core@0.1.0-beta.12_debug@4.4.3_react@19.2.7/node_modules/@byted-doubao-tools/devtool-connection-core/dist/lib/ipc/index.js"),M=4*Math.ceil(5614250.666666667),B=new Map;class U extends Error{code;cause;constructor(e,t,n){super(t),this.code=e,this.name="RuntimeInspectionError",n&&"cause"in n&&(this.cause=n.cause)}}async function F(e){let t,r=new d(e.namespace,{nodeId:`${e.nodeIdPrefix}-${process.pid}-${Math.random().toString(36).slice(2,8)}`,requestTimeout:12e3}),o=new Set,i=new Set,a=0,l=!0;r.createService({name:`runtimeInspection${process.pid}${Math.random().toString(36).slice(2,8)}`,events:{[q.DEVTOOL_CONNECTION_IPC_EVENTS.messageReceived](e){let n=e.params,r=function(e){if("Page.screencastFrame"===e.method&&c(e.params)&&"string"==typeof e.params.data&&e.params.data)return{data:e.params.data}}(n);for(let e of(r&&Number.isSafeInteger(n.clientId)&&Number.isSafeInteger(n.sessionId)&&(t={clientId:n.clientId,sessionId:n.sessionId,data:r.data}),o))e(n)},[s.runtimeInspectionTargetChanged](e){let t=function(e){if(c(e)&&"number"==typeof e.clientId&&"number"==typeof e.sessionId&&"string"==typeof e.url)return{clientId:e.clientId,sessionId:e.sessionId,url:e.url}}(e.params);if(t)for(let e of i)e(t)}}});try{await r.start()}catch(e){throw await r.stop().catch(()=>void 0),e}let u=(e,t)=>em(()=>r.call(`${q.DEFAULT_DEVTOOL_CONNECTION_IPC_SERVICE_NAME}.${e}`,t),5e3);return{eventSubscriptionWarmupMs:e.eventSubscriptionWarmupMs??5e3,getConnectedClients:()=>u(q.DEVTOOL_CONNECTION_IPC_ACTIONS.getConnectedClients),getLatestScreencastFrame(e){if(t?.clientId===e.clientId&&t.sessionId===e.sessionId)return{data:t.data}},async getRuntimeInspectionTarget(){if(!l)return null;try{return await r.call(n.getRuntimeInspectionTarget)}catch(e){if(ef(e))return l=!1,null;throw e}},subscribeRuntimeInspectionTarget:e=>(i.add(e),()=>{i.delete(e)}),async sendCdp(e,t,n={},r={}){let o={id:1e9+process.pid%1e5*1e3+a++,clientId:e.clientId,sessionId:e.sessionId,method:t,params:n,messageType:"CDP",timeoutMs:!1===r.expectResponse?100:1e4};try{let e=await u(q.DEVTOOL_CONNECTION_IPC_ACTIONS.sendMessageToApp,o);var i,s,d=t,l=e;if(!l.success)throw Error([l.reason,l.apps?.length?`apps=${l.apps.join(",")}`:"",l.clients?.length?`clients=${l.clients.map(e=>`${e.clientId}:${e.info.App}`).join(",")}`:""].filter(Boolean).join("; "));if(c(l.data)&&c(l.data.error)){let e=void 0===l.data.error.code?"unknown":String(l.data.error.code),t=void 0===l.data.error.message?"unknown error":String(l.data.error.message);throw Error(`${d} failed: ${t} (code=${e})`)}return ee(l.data)}catch(e){if(!1===r.expectResponse&&(i=e,s=t,(i instanceof Error?i.message:String(i)).includes(`send CDP message timeout, method: ${s}`)))return;throw Error(`${t} failed: ${e instanceof Error?e.message:String(e)}`)}},subscribeMessage:e=>(o.add(e),()=>{o.delete(e)}),async stop(){o.clear(),i.clear(),t=void 0,await r.stop()}}}async function V(e,t={}){let n=Date.now()+(t.timeoutMs??3e3);for(;;){e_(t.signal);let r=await e.getConnectedClients(),o=function(e,t={}){let n,r=t.explicitTarget??(t.policy?.kind==="fixed"?t.policy.target:void 0);if(r){let n=e.find(e=>e.device.clientId===r.clientId);if(!n){if(t.activeClientId===r.clientId)throw new U("TARGET_CLIENT_DISCONNECTED",`debug client ${r.clientId} is disconnected`);throw new U("TARGET_STALE",`${H(r)} no longer points to a connected debug client`)}let o=n.sessions.find(e=>e.sessionId===r.sessionId&&J(e));if(!o)throw new U("TARGET_STALE",`${H(r)} no longer points to a live Lynx session`);return{clientId:n.device.clientId,sessionId:o.sessionId,url:o.url}}if(void 0!==t.activeClientId){if(!(n=e.find(e=>e.device.clientId===t.activeClientId)))throw new U("TARGET_CLIENT_DISCONNECTED",`authenticated debug client ${t.activeClientId} is disconnected`)}else if(e.length>1)throw new U("TARGET_AMBIGUOUS",`more than one debug device is connected: ${e.map(e=>`${e.device.clientId}:${e.device.info.App||"unknown"}`).join(", ")}`);else n=e[0];if(!n)return;let o=n.sessions.filter(J).sort((e,t)=>t.sessionId-e.sessionId)[0];if(o)return{clientId:n.device.clientId,sessionId:o.sessionId,url:o.url}}(r,t);if(o)return o;if(Date.now()>=n)throw 0===r.length?new U("DEVICE_NOT_CONNECTED","no debug device is connected"):new U("NO_ACTIVE_LYNX_SESSION","the connected device has no active Lynx session");await ew(100,t.signal)}}function H(e){return`@${e.clientId}:${e.sessionId}`}function K(e){let t=/^@([1-9]\d*):([1-9]\d*)$/.exec(e.trim());if(!t)throw new U("INVALID_TARGET_REF",`invalid target ref "${e}"; expected @<clientId>:<sessionId>`);let n={clientId:Number(t[1]),sessionId:Number(t[2])};if(!Number.isSafeInteger(n.clientId)||!Number.isSafeInteger(n.sessionId))throw new U("INVALID_TARGET_REF",`invalid target ref "${e}"; every id must be a safe integer`);return n}function z(e){return`@${e.clientId}:${e.sessionId}:${e.nodeId}`}async function Y(e,t){let n=(await e.getConnectedClients()).find(e=>e.device.clientId===t.clientId),r=n?.sessions.find(e=>e.sessionId===t.sessionId&&J(e));if(!n||!r)throw new U("STALE_NODE_REF",`${z(t)} no longer points to a live Lynx session; run get-page-tree again`);return{clientId:t.clientId,sessionId:t.sessionId,url:r.url}}async function W(e,t,n={}){var r,o,i;let s,a,d,l,u,p=n.depth??-1,h=n.maxNodes??5e3;if(!Number.isInteger(p)||p<-1)throw Error("page tree depth must be -1 or a non-negative integer");if(!Number.isSafeInteger(h)||h<1)throw Error("page tree maxNodes must be a positive integer");await e.sendCdp(t,"DOM.enable",{useCompression:!1});try{u=await e.sendCdp(t,"DOM.getDocument",{depth:p})}catch{u=await e.sendCdp(t,"DOM.getDocument")}let f=function(e){let t=ee(e);if(!c(t))throw ea("DOM.getDocument","response is not an object");let n=t.root;if(!0===t.compress&&"string"==typeof n)try{if(n.length>M)throw Error("compressed root exceeds the input limit");n=JSON.parse((0,N.inflateSync)(Buffer.from(n,"base64"),{maxOutputLength:0x1000000}).toString("utf8"))}catch(e){throw ea("DOM.getDocument","failed to decode compressed root",e)}else if("string"==typeof n)try{n=JSON.parse(n)}catch(e){throw ea("DOM.getDocument","root is not valid JSON",e)}if(!c(n))throw ea("DOM.getDocument","missing root node");return n}(u),m=await Z(e,t,f,p,h),g=(r=f,o=t,i=h,s=0,a=!1,d=[],{root:(l=e=>{var t;let n=en(e.nodeId),r="string"==typeof e.nodeName&&e.nodeName?e.nodeName:"unknown";if(void 0===n)throw ea("DOM.getDocument",`node ${r} has no valid nodeId`);s++;let c=[],u={ref:z({clientId:o.clientId,sessionId:o.sessionId,nodeId:n}),nodeId:n,...void 0===en(e.backendNodeId)?{}:{backendNodeId:en(e.backendNodeId)},nodeType:"number"==typeof e.nodeType&&Number.isSafeInteger(e.nodeType)?e.nodeType:0,nodeName:r,..."string"==typeof e.localName?{localName:e.localName}:{},nodeValue:"string"==typeof e.nodeValue?e.nodeValue:"",attributes:function(e){if(!Array.isArray(e))return{};let t={};for(let n=0;n<e.length;n+=2){let r=e[n];if("string"!=typeof r||!r)continue;let o=e[n+1];t[r]="string"==typeof o?o:String(o??"")}return t}(e.attributes),childNodeCount:"number"==typeof e.childNodeCount&&Number.isSafeInteger(e.childNodeCount)?Math.max(0,e.childNodeCount):et(e).length,children:c};for(let t of(er(u)&&u.nodeValue&&(u.text=u.nodeValue),et(e))){if(s>=i){a=!0;break}c.push(l(t))}if("text"===((t=u).localName||t.nodeName).toLowerCase()){let e=function e(t){return t.children.flatMap(t=>er(t)?[t.nodeValue]:[e(t)]).join("")}(u);e?u.text=e:d.push(u)}return u})(r),nodeCount:s,truncated:a,textCandidates:d});return await eo(e,t,g.textCandidates),{target:t,depth:p,nodeCount:g.nodeCount,truncated:m.truncated||g.truncated,root:g.root}}async function G(e,t,n,r=[]){let o;await e.sendCdp(t,"DOM.enable",{useCompression:!1});try{o=await e.sendCdp(t,"CSS.getComputedStyleForNode",{nodeId:n.nodeId})}catch(e){var i;if(i=e,/(could not find|cannot find|no such|unknown|invalid|stale).{0,40}node|node.{0,40}(not found|does not exist|invalid|stale)/i.test(i instanceof Error?i.message:String(i)))throw new U("STALE_NODE_REF",`${z(n)} is stale; run get-page-tree again`,{cause:e});throw e}let s=ee(o);if(!c(s)||!Array.isArray(s.computedStyle))throw ea("CSS.getComputedStyleForNode","missing computedStyle array");let a=s.computedStyle.filter(c).flatMap(e=>"string"==typeof e.name&&"string"==typeof e.value?[{name:e.name,value:e.value}]:[]),d=0===r.length?a:r.flatMap(e=>{let t=a.find(t=>t.name===e);return t?[t]:[]});return{target:t,nodeRef:z(n),nodeId:n.nodeId,properties:d}}function J(e){return"lynx"===e.type&&Number.isSafeInteger(e.sessionId)&&e.sessionId>0&&!X(e.url)}function Q(e){return`${e.clientId}:${e.sessionId}`}function X(e){return/(?:-main\.js|\.main\.lynx\.js)(?:[?#].*)?$/.test(e)}async function Z(e,t,n,r,o){let i=0,s=!1,a=async(n,d)=>{if(i>=o){s=!0;return}if(i++,r>=0&&d>=r)return;let l=et(n);if(("number"==typeof n.childNodeCount&&Number.isSafeInteger(n.childNodeCount)?Math.max(0,n.childNodeCount):l.length)>l.length&&"number"==typeof n.nodeId&&Number.isSafeInteger(n.nodeId)){let r=ee(await e.sendCdp(t,"DOM.requestChildNodes",{nodeId:n.nodeId}));if(!c(r)||!Array.isArray(r.nodes))throw ea("DOM.requestChildNodes",`missing nodes array for node ${n.nodeId}`);n.children=l=r.nodes.filter(c)}for(let e of l)if(await a(e,d+1),i>=o){l.indexOf(e)<l.length-1&&(s=!0);break}};return await a(n,0),{truncated:s}}function ee(e){return c(e)&&"id"in e&&"result"in e?e.result:e}function et(e){return Array.isArray(e.children)?e.children.filter(c):[]}function en(e){return"number"==typeof e&&Number.isSafeInteger(e)&&e>0?e:void 0}function er(e){return 3===e.nodeType||"#text"===e.nodeName.toLowerCase()}async function eo(e,t,n){let r=n[0];if(!r)return;let o=await ei(e,t,r);if(o.supported){o.text&&(r.text=o.text);for(let r=1;r<n.length;r+=8){let o=n.slice(r,r+8);await Promise.all(o.map(async n=>{let r=await ei(e,t,n);r.text&&(n.text=r.text)}))}}}async function ei(e,t,n){try{let r=ee(await e.sendCdp(t,"DOM.innerText",{nodeId:n.nodeId}));if(!c(r)||!Array.isArray(r.rawTextValues))return{supported:!1};let o=r.rawTextValues.filter(c).flatMap(e=>"string"==typeof e.text?[e.text]:[]).join("");return{supported:!0,...o?{text:o}:{}}}catch{return{supported:!1}}}function es(e,t=120){let n=e.replace(/\s+/g," ").trim();return JSON.stringify(n.length>t?`${n.slice(0,Math.max(0,t-1))}…`:n)}function ea(e,t,n){return new U("INVALID_CDP_RESPONSE",`${e} returned an invalid response: ${t}`,void 0===n?void 0:{cause:n})}async function ed(e,t,n){let r,o,i,s=0,a=!1,d=Q(t),l=new Promise((e,t)=>{o=e,i=t}),u=e=>{a||(a=!0,o({count:s,reason:e}))},p=()=>u("aborted"),h=e.getRuntimeInspectionTarget?.bind(e),f=e=>{if(a||!(Number.isSafeInteger(e.clientId)&&e.clientId>0&&Number.isSafeInteger(e.sessionId)&&e.sessionId>0&&!X(e.url)))return;let r=Q(e);if(r!==d&&(d=r,r!==Q(t)))try{n.onTargetChange?.(e)}catch{}},m=e.subscribeMessage(e=>{if(a||!ec(e,t))return;let r=function(e){var t;if("Runtime.consoleAPICalled"!==e.method||!c(e.params))return;let n={...t=e.params,...Array.isArray(t.args)?{args:t.args.map(e=>c(e)?{...e}:e)}:{},...c(t.stackTrace)?{stackTrace:{...t.stackTrace,...Array.isArray(t.stackTrace.callFrames)?{callFrames:t.stackTrace.callFrames.map(e=>c(e)?{...e}:e)}:{}}}:{}},r="string"==typeof n.consoleTag?n.consoleTag:void 0;return{type:"string"==typeof n.type?n.type:"log",thread:"Lepus"===r?"main":"background",args:Array.isArray(n.args)?n.args:[],...r?{consoleTag:r}:{},..."number"==typeof n.timestamp?{timestamp:n.timestamp}:{},..."stackTrace"in n?{stackTrace:n.stackTrace}:{},params:n}}(e);if(r){try{n.onMessage(r)}catch(e){a||(a=!0,i(e));return}s++,void 0!==n.limit&&s>=n.limit&&u("limit")}}),g=n.onTargetChange?e.subscribeRuntimeInspectionTarget?.(f):void 0;n.signal?.addEventListener("abort",p,{once:!0}),n.onTargetChange&&h&&h().then(e=>{e&&f(e)}).catch(()=>void 0);try{if(n.signal?.aborted)return u("aborted"),await l;if(await eu(e,t,n.subscriptionWarmupMs??e.eventSubscriptionWarmupMs??5e3,n.signal),a)return await l;for(let o of(void 0!==n.timeoutMs&&(r=setTimeout(()=>u("timeout"),n.timeoutMs)),[{method:"Page.getResourceTree",params:{}},{method:"Debugger.enable",params:{}},{method:"Runtime.enable",params:{}}])){if(a)break;await e.sendCdp(t,o.method,o.params,{expectResponse:!1})}return await l}catch(e){if(n.signal?.aborted)return u("aborted"),await l;throw e}finally{r&&clearTimeout(r),n.signal?.removeEventListener("abort",p),g?.(),m()}}async function el(e,t,n={}){return eg(t,async()=>{let r,o=new Promise(e=>{r=e}),i=e.subscribeMessage(e=>{ec(e,t)&&"Page.screencastFrame"===e.method&&c(e.params)&&"string"==typeof e.params.data&&e.params.data&&r({data:e.params.data})}),s=!1;try{var a,d,l;await eu(e,t,e.eventSubscriptionWarmupMs??5e3);let r=n.activeCapture?void 0:e.getLatestScreencastFrame?.(t);!r&&n.activeCapture&&(await e.sendCdp(t,"Page.enable"),s=!0,await e.sendCdp(t,"Page.startScreencast",{format:"jpeg",quality:80},{expectResponse:!1})),r??=await (a=o,d=t,l=n.timeoutMs??1e4,new Promise((e,t)=>{let n=setTimeout(()=>t(new U("SCREENSHOT_TIMEOUT",`no Page.screencastFrame received for ${H(d)} within ${l}ms; make sure the target session is active and can produce screenshot frames`)),l);a.then(t=>{clearTimeout(n),e(t)},e=>{clearTimeout(n),t(e)})})),s&&await e.sendCdp(t,"Page.screencastFrameAck",{},{expectResponse:!1}).catch(()=>void 0);let i=function(e){let t=e.replace(/\s+/g,"");if(!t||t.length%4!=0||!/^[A-Za-z0-9+/]+={0,2}$/.test(t))throw new U("INVALID_SCREENSHOT_DATA","Page.screencastFrame returned invalid base64 data");let n=Buffer.from(t,"base64");if(n.length<4||255!==n[0]||216!==n[1]||255!==n[n.length-2]||217!==n[n.length-1])throw new U("INVALID_SCREENSHOT_DATA","Page.screencastFrame did not return a complete JPEG image");let r=function(e){let t=new Set([192,193,194,195,197,198,199,201,202,203,205,206,207]),n=2;for(;n+3<e.length;){if(255!==e[n]){n++;continue}for(;n<e.length&&255===e[n];)n++;let r=e[n++];if(void 0===r||217===r||218===r)break;if(1===r||r>=208&&r<=215)continue;if(n+1>=e.length)break;let o=e.readUInt16BE(n);if(o<2||n+o>e.length)break;if(t.has(r)){if(o<7)break;let t=e.readUInt16BE(n+3),r=e.readUInt16BE(n+5);if(r>0&&t>0)return{width:r,height:t};break}n+=o}}(n);if(!r)throw new U("INVALID_SCREENSHOT_DATA","Page.screencastFrame JPEG has no readable dimensions");return{buffer:n,data:t,...r}}(r.data);return{data:i.data,format:"jpeg",source:"Page.screencastFrame",width:i.width,height:i.height,byteLength:i.buffer.length}}finally{s&&await e.sendCdp(t,"Page.stopScreencast",{},{expectResponse:!1}).catch(()=>void 0),i()}})}function ec(e,t){return"CDP"===e.messageType&&e.clientId===t.clientId&&e.sessionId===t.sessionId}async function eu(e,t,n,r){let o;if(n<=0)return;let i=Date.now()+n,s=new Promise(e=>{o=e}),a=e.subscribeMessage(e=>{ec(e,t)&&o()});try{for(;Date.now()<i;){if(e_(r),await e.sendCdp(t,"Page.getResourceTree",{},{expectResponse:!1}).catch(()=>void 0),await function(e,t,n){return new Promise((r,o)=>{let i=new AbortController,s=setTimeout(()=>{i.abort(),r(!1)},t);n?.addEventListener("abort",()=>{clearTimeout(s),i.abort(),o(n?.reason instanceof Error?n.reason:Error("operation aborted"))},{once:!0,signal:i.signal}),e.then(()=>{clearTimeout(s),i.abort(),r(!0)},e=>{clearTimeout(s),i.abort(),o(e)})})}(s,Math.min(250,Math.max(0,i-Date.now())),r))return;await ew(Math.min(50,Math.max(0,i-Date.now())),r)}}finally{a()}}function ep(e){return c(e)?e.objectId?`<${String(e.description||e.className||"Object")} (objectId:${String(e.objectId)})>`:"value"in e?eh(e.value):"string"==typeof e.description?e.description:eh(e):eh(e)}function eh(e){if("string"==typeof e)return e;if(void 0===e)return"undefined";try{let t=JSON.stringify(e);return void 0===t?String(e):t}catch{return String(e)}}function ef(e){return/is not (found|available)/i.test(e instanceof Error?e.message:String(e))}async function em(e,t){let n=Date.now()+t;for(;;)try{return await e()}catch(e){if(!ef(e)||Date.now()>=n)throw e;await ew(50)}}async function eg(e,t){let n,r=Q(e),o=B.get(r)??Promise.resolve(),i=new Promise(e=>{n=e});B.set(r,i),await o.catch(()=>void 0);try{return await t()}finally{n(),B.get(r)===i&&B.delete(r)}}function e_(e){if(e?.aborted)throw e.reason instanceof Error?e.reason:Error("operation aborted")}function ew(e,t){return new Promise((n,r)=>{if(t?.aborted)return void r(t.reason instanceof Error?t.reason:Error("operation aborted"));let o=new AbortController,i=setTimeout(()=>{o.abort(),n()},e);t?.addEventListener("abort",()=>{clearTimeout(i),o.abort(),r(t?.reason instanceof Error?t.reason:Error("operation aborted"))},{once:!0,signal:o.signal})})}let ey={schemaVersion:1,cliVersion:h,deviceAppVersion:"1.0.9",packages:{"darwin-arm64":{url:"https://lf3-cdn-tos.bytegoofy.com/obj/tron-demo/7610358476778248474/468636861/1.0.9/darwin-arm64/DoubaoDeveloperTools-v1.0.9-darwin-arm64.zip",sha256:"1b1aaf58f109efdc7cf0107a533ea043807d5f17c5ea9e001cede78511ae80b3",entry:"豆包开发者工具.app",sizeBytes:0x77fdf68},"win32-x64":{url:"https://lf3-cdn-tos.bytegoofy.com/obj/tron-demo/7610358476778248474/468636861/1.0.9/win32-x64/DoubaoDeveloperTools-v1.0.9-win32-x64.zip",sha256:"903ee97e1560006293afc978c16476d0b34c4789d03a709b200cb59da8fa4556",entry:"豆包开发者工具.exe",sizeBytes:0x84c4d6c}}},eb=e("node:child_process"),ev=e("node:crypto");var eE=e.n(ev);let eI=e("node:fs");var eA=e.n(eI);let eT=e("node:http"),eC=e("node:os");var eS=e.n(eC);let ej=e("node:path");var ek=e.n(ej);let eD=e("node:stream"),eP=e("node:url"),ex=e("node:util"),eL=e("../../../node_modules/.pnpm/@byted-doubao-tools+real-device-debug-auth@0.1.3/node_modules/@byted-doubao-tools/real-device-debug-auth/dist/lib/index.js"),eR=e("../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/index.js"),eO="DBX_DEVICE_APP_PATH",e$="dbx-device-app.json",eN="state.json",eq="versions",eM=ek().dirname((0,eP.fileURLToPath)(import.meta.url)),eB=[{command:"web",description:"打开 Web 模拟器"},{command:"device",description:"进入真机调试"},{command:"status",description:"查看本地调试服务状态"}],eU=[{command:"qr",description:"重新生成真机调试二维码"},{command:"page [url]",description:"在真机打开页面(省略 url 可选择)"},{command:"pages",description:"列出真机可打开页面"},{command:"widget [id]",description:"向真机推送卡片(省略 id 可选择)"},{command:"widgets",description:"列出真机可推送卡片"},{command:"sessions",description:"列出当前可检查的 Lynx sessions"},{command:"use-session <@client:session|latest>",description:"固定 CLI session 或恢复跟随最新"},{command:"get-console",description:"持续输出当前 Lynx 页面新产生的日志"},{command:"take-screenshot",description:"截取当前 Lynx 页面画面"},{command:"get-page-tree",description:"获取当前 Lynx 页面的 DOM 树"},{command:"get-computed-style [node-ref]",description:"获取 DOM 节点的 computed style"},{command:"back",description:"返回主命令"}];function eF(e){if("complete"===e.phase)return`豆包开发者工具已安装:${e.appPath}`;if("install"===e.phase){let t={verify:"验证",extract:"解压",install:"安装"}[e.stage];return`安装豆包开发者工具:${t}`}let t=[void 0===e.percentage?void 0:`${e.percentage}%`,void 0===e.totalBytes?e.downloadedBytes>0?td(e.downloadedBytes):void 0:`${td(e.downloadedBytes)} / ${td(e.totalBytes)}`,`${Math.max(0,Math.round(e.elapsedMs/1e3))}s`].filter(e=>!!e);return`下载豆包开发者工具:${t.join(" \xb7 ")}`}function eV(e,t){let n,r=!1;return o=>{if(!o)return void t?.(void 0);if("download"===o.phase){n=o,t?.(o);return}if(n&&!r&&(r=!0,nn(e,`✓ ${eF(n)}`)),"complete"===o.phase){t?.(void 0),nn(e,`✓ ${eF(o)}`);return}t?.(o)}}function eH(e,t){if("true"===e)return!0;if("false"===e)return!1;throw Error(`${t} must be "true" or "false"`)}async function eK(e){let t,n,r,o,i=e.output??process.stderr,s=e.client??await a({projectPath:e.projectPath,appDir:e.appDir,nodeIdPrefix:"dev-shell"}),d=e.closeDeviceApp??e8,l=new AbortController,c=e.openBrowser??A,u=new Set,p={runtime:e.runtime,client:s,output:i,manageDeviceApp:!0,runtimeInspectionTargetPolicy:{kind:"latest"},openBrowser:c,openQRCodeViewer:e.openQRCodeViewer??((e,t,n)=>t8(e,c,t,i,n)),signal:l.signal,launchDeviceApp:e.launchDeviceApp??(e=>e5(e,i)),closeDeviceApp:d,prepareDeviceApp:e.prepareDeviceApp??(e=>e3(i,e)),...e.onDeviceAppSetupProgress?{onDeviceAppSetupProgress:e.onDeviceAppSetupProgress}:{},openPreparedDeviceApp:e.openPreparedDeviceApp??e6,runRealDeviceAuth:e.runRealDeviceAuth??tz,...e.realDeviceDebugCoordinator?{realDeviceDebugCoordinator:e.realDeviceDebugCoordinator}:{},...e.createRuntimeInspectionSession?{createRuntimeInspectionSession:e.createRuntimeInspectionSession}:{},listAppVersions:e.listAppVersions??(async e=>{let t=await I(e);return t.data?.version_list??[]}),selectItem:e.selectItem,eventTracking:e.eventTracking},h=(e.createRuntimeInspectionSession??F)({namespace:e.runtime.getState().namespace,nodeIdPrefix:"dev-shell-runtime-inspection"});h.catch(()=>void 0),p.runtimeInspectionSession=h;let f=async()=>r||(r=(async()=>{p.activeDeviceId=void 0,t6(),p.manageDeviceApp&&await eG(p)})().finally(()=>{r=void 0})),m=t0(e.runtime.getState().namespace,async()=>{if(p.activeDeviceId&&!o){nn(i,"检测到真机连接断开,正在返回主命令并清理真机调试资源..."),await f();for(let e of u)try{e("client-disconnected")}catch{}}});return await m.start(),{stopped:e.runtime.stopped,getState:()=>e.runtime.getState(),execute(e){let r=new AbortController,o=AbortSignal.any([l.signal,r.signal]);n=r,p.signal=o;let i=ez(e,p);return t=i,i.finally(()=>{t===i&&(t=void 0),n===r&&(n=void 0),p.signal===o&&(p.signal=l.signal)})},cancelActiveCommand(){if(!n||n.signal.aborted)return!1;let e=Error("command cancelled");return e.name="AbortError",n.abort(e),!0},returnToRoot:()=>eY(p,"back","execute",f),handleClientDisconnected:()=>f(),subscribe:e=>(u.add(e),()=>{u.delete(e)}),close:()=>o??=(async()=>{l.abort(new tZ),await t?.catch(()=>void 0),await m.stop().catch(()=>void 0),await f(),await p.runtimeInspectionSession?.then(e=>e.stop()).catch(()=>void 0),await s.stop().catch(()=>void 0),await e.runtime.stop().catch(()=>void 0)})()}}async function ez(e,t){var n;let r;try{r=function(e){let t,n=[],r="",o=!1,i=()=>{r.length>0&&(n.push(r),r="")};for(let n of e.trim()){if(o){r+=n,o=!1;continue}if("\\"===n&&"'"!==t){o=!0;continue}if("'"===n||'"'===n){if(!t){t=n;continue}if(t===n){t=void 0;continue}}if(!t&&/\s/.test(n)){i();continue}r+=n}if(o&&(r+="\\"),t)throw Error(`unterminated ${t} quote`);return i(),n}(e)}catch(e){return nn(t.output,tQ(no(e))),"continue"}let o=r[0]?.toLowerCase(),i=r.slice(1);if(!o)return"continue";if((n=i).includes("--help")||n.includes("-h")){let e="device"===o&&i[0]&&!i[0].startsWith("-")?`device ${i[0].toLowerCase()}`:o;if(function(e,t){switch(t){case"device widget":return nn(e,"usage: widget [widget-id] [--data <json>] [--bot-id <id>] [--device-id <id>]"),nn(e,"推送卡片到已连接真机;省略 widget-id 时从 `widgets` 列表中选择。"),!0;case"device page":return nn(e,"usage: page [url] [--device-id <id>]"),nn(e,"通过完整 URL 打开页面;省略 url 时从 `pages` 列表中选择。页面参数请写入 URL query。"),!0;case"device":nn(e,"usage: device [--agent] [--mcp] [--timeout <seconds>] [--qr-file <file.png>] [--wifi-connect <true|false>] [--defaultDebugTagState <true|false>]"),nn(e,"进入真机模式并连接调试设备,默认准备并打开豆包开发者工具。"),nn(e,"使用 `device --agent` 进入 Agent 模式,不准备、启动或关闭豆包开发者工具。"),nn(e,"使用 --mcp 进入 MCP 端到端调试,并从当前 AppID 的版本列表中选择 versionTag。");for(let t of(nn(e,"真机调试命令"),eU))nn(e,` ${t.command.padEnd(22)}${t.description}`);return nn(e,"进入真机模式后执行 `<命令> --help` 查看参数。"),nn(e,"get-page-tree、get-computed-style、take-screenshot 支持通用的 --json 输出。"),!0;case"device qr":return nn(e,"usage: qr [--mcp] [--timeout <seconds>] [--qr-file <file.png>] [--wifi-connect <true|false>] [--defaultDebugTagState <true|false>]"),nn(e,"重新生成真机调试二维码;MCP 端到端调试会沿用已选择的 versionTag,也可用 --mcp 重新选择。"),!0;case"device get-console":return nn(e,"usage: get-console [--target <@client:session>] [--limit <count>] [--timeout-seconds <seconds>] [--include-stack-traces]"),nn(e,"持续输出当前 Lynx session 新产生的 console 日志;按 Ctrl+C 停止监听并返回真机命令。"),nn(e,"默认仅 error 日志显示调用栈;使用 --include-stack-traces 展开所有日志的调用栈。"),!0;case"device sessions":return nn(e,"usage: sessions"),nn(e,"列出当前可检查的 Lynx sessions,并标记 latest、CLI fixed 和 Electron current。"),!0;case"device use-session":return nn(e,"usage: use-session <@client:session|latest>"),nn(e,"固定 CLI 后续检查命令使用的 session,或用 latest 恢复到鉴权 client 内最新活跃 session;不会切换 Electron。"),!0;case"device take-screenshot":return nn(e,"usage: take-screenshot [--target <@client:session>] [-o, --output <file.jpeg>] [--json]"),nn(e,"保存 Electron 当前为目标 session 输出的最近一帧 JPEG;截图范围跟随 Electron 当前 mode。"),!0;case"device get-page-tree":return nn(e,"usage: get-page-tree [--target <@client:session>] [--depth <-1|n>] [--json]"),nn(e,"获取当前 Lynx session 的 DevTools Elements DOM 树;默认 depth=-1。"),nn(e,"终端输出紧凑树;--json 输出节点文本、完整 attributes 和可复用 node-ref。"),!0;case"device get-computed-style":return nn(e,"usage: get-computed-style <node-ref> [--properties <name,...>] [--json]"),nn(e,"获取元素节点的 computed style;node-ref 格式为 @<clientId>:<sessionId>:<nodeId>。"),nn(e,"省略 --properties 返回全部属性,例如 --properties color,font-size。"),!0;case"web":return nn(e,"usage: web"),nn(e,"在默认浏览器打开本地 Web 模拟器。"),!0;case"device pages":case"device widgets":{let n="device pages"===t?"打开的页面":"推送的卡片";return nn(e,`usage: ${t.slice(7)}`),nn(e,`列出真机可${n}。`),!0}case"status":return nn(e,"usage: status"),nn(e,"查看本地调试服务状态。"),!0;default:return!1}}(t.output,e))return"continue"}try{switch(o){case"status":return await eY(t,"status","execute",()=>eJ(t)),"continue";case"web":return await eY(t,"web_open","execute",()=>eQ(t)),"continue";case"device":return await eW(t,i)?"enter-device":"continue";default:return nn(t.output,`unknown command: ${o}`),["qr","pages","page","widgets","widget","sessions","use-session","get-console","take-screenshot","get-page-tree","get-computed-style"].includes(o)&&nn(t.output,`\`${o}\` is only available in device mode; run \`device\` first.`),"continue"}}catch(e){return nn(t.output,tQ(no(e))),"continue"}}async function eY(e,t,n,r){let o=e.eventTracking;return o?f({action:t,actionSequence:++o.actionSequence,appId:o.appId??e.runtime.getState().appId,devSessionId:o.devSessionId,errorStage:n},r):r()}async function eW(e,t){let r=t[0]?.toLowerCase();if(!r||r.startsWith("-"))return await eX(e,t,{reuseDeviceAppMode:!1,reuseVersionTag:!1}),!0;let o=function(e){let t=!1,n=[];for(let r of e)"--json"===r?t=!0:n.push(r);return{args:n,json:t}}(t.slice(1)),i=["get-page-tree","get-computed-style","take-screenshot"].includes(r);try{if(o.json&&!i)throw Error(`--json is not supported by device ${r}; use it with get-page-tree, get-computed-style, or take-screenshot`);switch(r){case"qr":return await e2(e,o.args),!0;case"pages":return await eY(e,"pages_list","execute",()=>tD(e,"page",n.discoverPages)),!0;case"page":return await eY(e,"page_push","page_push",()=>tU(e,o.args)),!0;case"widgets":return await eY(e,"widgets_list","execute",()=>tD(e,"widget",n.discoverWidgets)),!0;case"widget":return await eY(e,"widget_push","widget_push",()=>tF(e,o.args)),!0;case"sessions":return await eY(e,"sessions_list","execute",()=>tP(e,o.args)),!0;case"use-session":return await eY(e,"session_select","execute",()=>tx(e,o.args)),!0;case"get-console":return await eY(e,"console_stream","execute",()=>tL(e,o.args)),!0;case"take-screenshot":return await eY(e,"screenshot","execute",()=>tR(e,o.args,o.json)),!0;case"get-page-tree":return await eY(e,"page_tree","execute",()=>tO(e,o.args,o.json)),!0;case"get-computed-style":return await eY(e,"computed_style","execute",()=>t$(e,o.args,o.json)),!0;default:return nn(e.output,`unknown device subcommand: ${r}`),!1}}catch(t){if(!o.json||!i)throw t;return nr(e.output,{ok:!1,error:{code:t instanceof U?t.code:"INSPECTION_FAILED",message:no(t)}}),!0}}async function eG(e){try{var t,n;let r=await e.closeDeviceApp();t=e.output,n=r,"closed"===n.status?nn(t,`豆包开发者工具已关闭:${n.appPath}`):nn(t,`关闭豆包开发者工具失败${n.reason?`:${tQ(n.reason)}`:""}`)}catch(t){nn(e.output,`关闭豆包开发者工具失败:${tQ(no(t))}`)}}async function eJ(e){let t=await e.client.call(n.getInfo);nn(e.output,`status: ${t.status}`),nn(e.output,`app_id: ${t.appId??"-"}`),nn(e.output,`dev_server: ${t.host??"-"}`),nn(e.output,`web_debugger: ${t.webDebuggerUrl??"-"}`)}async function eQ(e){let t=e.runtime.getState().webDebuggerUrl;if(!t)throw Error("web debugger URL is not ready");await e.openBrowser(t),nn(e.output,`Web 模拟器已打开:${t}`)}async function eX(e,t,n){let r=()=>e.realDeviceDebugCoordinator?e.realDeviceDebugCoordinator.runTerminal(()=>eZ(e,t,n)):eZ(e,t,n),o=e.eventTracking;if(!o)return void await r();let i=++o.actionSequence,s=performance.now(),a=n.reuseDeviceAppMode?"qr_refresh":"device_connect";try{let t=await r(),n=t?.status==="connected"?"success":t?.status==="cancelled"?"cancelled":t?.status==="timeout"?"timeout":t?.error?"failed":"skipped";await g({action:a,actionSequence:i,appId:o.appId??e.runtime.getState().appId,devSessionId:o.devSessionId,durationMs:performance.now()-s,...t?.error?{error:t.error,...t.failureStage?{errorStage:t.failureStage}:{},errorType:"device_connection_error"}:{},status:n})}catch(t){throw await g({action:a,actionSequence:i,appId:o.appId??e.runtime.getState().appId,devSessionId:o.devSessionId,durationMs:performance.now()-s,error:t,errorStage:"prepare_device_tool",errorType:"device_connection_error",status:v(t)}),t}}async function eZ(e,t,n){var r,o,i;let s,a,d,l=(0,ex.parseArgs)({args:t,allowPositionals:!1,options:{agent:{type:"boolean"},timeout:{type:"string"},"qr-file":{type:"string"},mcp:{type:"boolean"},"wifi-connect":{type:"string"},defaultDebugTagState:{type:"string"}}});if(n.reuseDeviceAppMode&&l.values.agent)throw Error("--agent is only supported when entering device mode");n.reuseDeviceAppMode||(e.manageDeviceApp=!l.values.agent);let c=function(e){if(void 0===e)return;let t=Number(e);if(!Number.isFinite(t)||t<=0)throw Error("--timeout must be a positive number of seconds");return Math.round(1e3*t)}(l.values.timeout),u=function(e){if(!e)return;let t=ek().resolve(e);if(".png"!==ek().extname(t).toLowerCase())throw Error("--qr-file must point to a .png file");return t}(l.values["qr-file"]),p=tW((r={defaultDebugTagState:l.values.defaultDebugTagState,wifiConnect:l.values["wifi-connect"]},d={},void 0!==r.defaultDebugTagState&&(d.defaultDebugTagState=eH(r.defaultDebugTagState,"--defaultDebugTagState")),void 0!==r.wifiConnect&&(d.usb=!eH(r.wifiConnect,"--wifi-connect")),Object.keys(d).length>0?d:void 0)),h=await e.client.call("dev.setConnectionTransport",{type:p.usb?"usb":"wifi"}),f=e.runtime.getState(),m=l.values.mcp?await e0(e,f.appId):n.reuseVersionTag?e.activeVersionTag:void 0;if(l.values.mcp&&!m)return;e.activeVersionTag=m,m&&!l.values.mcp&&nn(e.output,`沿用 MCP 端到端调试 versionTag:${m}`),e.manageDeviceApp||nn(e.output,"已启用 --agent:不会准备、启动或关闭豆包开发者工具。");let g={namespace:f.namespace,projectPath:f.projectPath,appDir:f.appDir,appKey:f.appId,hostUrl:f.host},_=e.manageDeviceApp?await e1(e):void 0;if(_?.status==="skipped"){let t=_.reason??"豆包开发者工具准备失败";return nn(e.output,`启动真机调试失败:${tQ(t)}`),{ok:!1,status:"skipped",timeoutMs:c??6e4,failureStage:"prepare_device_tool",error:t}}t6();let w=new AbortController,y=e.signal?AbortSignal.any([e.signal,w.signal]):w.signal;try{a=await e.runRealDeviceAuth({hostUrl:h.host||f.host,appKey:h.appId||f.appId,versionTag:m,namespace:f.namespace,timeoutMs:c,settings:p,wifiConnectUrl:h.wifiConnectUrl,output:e.output,signal:y,onQRCodeReady:async(t,n)=>{(s=await e.openQRCodeViewer(t,u,n)).closed.then(()=>{w.abort(new tZ)})}})}finally{await s?.close().catch(()=>void 0),t6()}if(function(e,t){let n;if(t.ok){let n=t.client?.clientId===void 0?"":`:client ${t.client.clientId}`,r=t.qrCodeValue?"扫码鉴权完成":"复用已连接设备,已跳过二维码鉴权";nn(e,`真机调试已连接${n}(${r})。`);return}"cancelled"===t.status?nn(e,"install"===t.waitingFor?"二维码页面已关闭,已取消等待设备安装。":"二维码页面已关闭,已取消等待设备连接。"):(n="timeout"===t.status?"install"===t.waitingFor?`设备已连接,但等待安装完成超时(${Math.max(1,Math.ceil(t.timeoutMs/1e3))} 秒)`:`等待设备连接超时(${Math.max(1,Math.ceil(t.timeoutMs/1e3))} 秒)`:tQ(t.error??"未知错误"),nn(e,`启动真机调试失败:${n}`))}(e.output,a),a.ok&&"connected"===a.status){a.client?.clientId!==void 0&&(void 0!==e.activeClientId&&e.activeClientId!==a.client.clientId&&(e.runtimeInspectionTargetPolicy={kind:"latest"}),e.activeClientId=a.client.clientId);let t=a.client?.deviceId??(a.client?.clientId===void 0?void 0:String(a.client.clientId));t&&(e.activeDeviceId=t)}if(e.manageDeviceApp&&a.ok&&"connected"===a.status){let t=_?await e4(e,_,g):await e.launchDeviceApp(g);o=e.output,"opened"===(i=t).status?nn(o,`豆包开发者工具已启动:${i.appPath}`):nn(o,`启动豆包开发者工具失败${i.reason?`:${tQ(i.reason)}`:""}`)}return a}async function e0(e,t){if(!t)throw Error("无法查询 versionTag,当前工程缺少 AppID。");let n=(await e.listAppVersions(t)).filter(e=>"string"==typeof e.version_tag&&!!e.version_tag.trim());if(!n.length)throw Error(`当前 AppID(${t})没有可选的 versionTag。`);let r=await e.selectItem("versionTag",n,e.output);return r?(nn(e.output,`MCP 端到端调试 versionTag:${r}`),r):void nn(e.output,"已取消 versionTag 选择,未生成二维码。")}async function e1(e){if(e.prepareDeviceApp){e.onDeviceAppSetupProgress?.(void 0);try{return await e.prepareDeviceApp({onProgress:eV(e.output,e.onDeviceAppSetupProgress),signal:e.signal})}catch(t){return e.onDeviceAppSetupProgress?.(void 0),{status:"skipped",reason:no(t)}}}}async function e2(e,t){await eX(e,t,{reuseDeviceAppMode:!0,reuseVersionTag:!0})}async function e4(e,t,n){return"skipped"!==t.status&&t.appPath?e.openPreparedDeviceApp?e.openPreparedDeviceApp(t.appPath,n):e.launchDeviceApp(n):{status:"skipped",reason:t.reason}}async function e5(e,t=process.stderr){let n=await e3(t);return"skipped"!==n.status&&n.appPath?e6(n.appPath,e):{status:"skipped",reason:n.reason}}async function e3(e=process.stderr,t={}){let n=function(e={}){let t=e.env??process.env,n=e.platform??process.platform,r=e.arch??process.arch,o=e.appDir??tn(),i=e.manifest??ey,s=to(t);if(t[eO]?.trim()||!s&&te({...t,[eO]:""},n,o))return;tg(i);let a=tr(n,r);if(!a)return;let d=i.packages[a];if(!d)return;t_(d);let l=tw(i,d),c=tt(t,n);if(!(!s&&ti(c,i,a,d,l)))return{platform:a,version:l,...void 0===d.sizeBytes?{}:{sizeBytes:d.sizeBytes}}}();return n&&!t.onProgress&&(nn(e,"真机调试准备:"),nn(e,`首次或版本更新需要下载豆包开发者工具${n.sizeBytes?`(${td(n.sizeBytes)})`:""}。`),nn(e,"下载完成后才会生成二维码;下载耗时取决于网络,进度和实际耗时将持续显示。")),await e7({runner:{onProgress:t.onProgress??eV(e),signal:t.signal}})}async function e6(e,t){return await function(e,t,n=process.platform){var r,o,i;let s,a=(r=e,o=n,s=(i=t)?[["namespace",i.namespace],["project",i.appDir??i.projectPath],["app-key",i.appKey],["host-url",i.hostUrl]].flatMap(([e,t])=>t?[`--${e}=${t}`]:[]):[],"darwin"===o?{command:"open",args:[r,...s.length?["--args",...s]:[]]}:"win32"===o?{command:"cmd",args:["/c","start","",r,...s],windowsVerbatimArguments:!0}:{command:r,args:s});return new Promise((e,t)=>{let n=(0,eb.spawn)(a.command,a.args,{stdio:"ignore",windowsVerbatimArguments:a.windowsVerbatimArguments});n.once("error",t),n.once("spawn",e)})}(e,t),{status:"opened",appPath:e}}async function e8(){let e=function(e=process.env,t=process.platform,n=process.arch,r=tn()){let o=e[eO]?.trim();if(o)return ek().resolve(o);let i=te({...e,[eO]:""},t,r);if(i)return i;let s=tr(t,n);if(!s)return;let a=tt(e,t),d=tu(a);if(!d||d.platform!==s)return;let l=tv(tf(a,d.activeDeviceAppVersion),d.entry,"device app state entry");return eA().existsSync(l)?l:void 0}();return e?(await function(e,t=process.platform){return"darwin"===t?tT(e):tC(tj(e,t),{rejectOnNonZero:!0}).then(()=>void 0)}(e),{status:"closed",appPath:e}):{status:"skipped",reason:`${eO} is not set and no packaged or cached device app was found`}}async function e7(e={}){let t=e.env??process.env,n=e.platform??process.platform,r=e.arch??process.arch,o=e.appDir??tn(),i=to(t),s=t[eO]?.trim();if(s)return{status:"found",appPath:ek().resolve(s),source:"env"};if(!i){let e=te({...t,[eO]:""},n,o);if(e)return{status:"found",appPath:e,source:"packaged"}}return e9({env:t,platform:n,arch:r,appDir:o,manifest:e.manifest,runner:e.runner})}async function e9(e={}){let t=e.env??process.env,n=e.platform??process.platform,r=e.arch??process.arch,o=e.manifest??ey;tg(o);let i=tr(n,r);if(!i)return{status:"skipped",reason:`device app download is not supported on ${n}/${r}`};let s=o.packages[i];if(!s)return{status:"skipped",reason:`device app package is not configured for ${i} in CLI ${o.cliVersion}`};let a=tt(t,n),d=tw(o,s);if(!to(t)){let e=ti(a,o,i,s,d);if(e)return tp(a,d),{status:"found",appPath:e,source:"cache"}}let l=await ts(a,o,i,s,n,e.runner);return tp(a,d),{status:"found",appPath:l,source:"downloaded"}}function te(e=process.env,t=process.platform,n=tn()){let r=e[eO]?.trim();if(r)return ek().resolve(r);if(!eA().existsSync(n))return;let o=eA().readdirSync(n,{withFileTypes:!0}).find(e=>{var n,r;return n=e,"darwin"===(r=t)?n.isDirectory()&&n.name.endsWith(".app"):"win32"===r?n.isFile()&&n.name.toLowerCase().endsWith(".exe"):n.isFile()&&/\.(appimage|AppImage)$/.test(n.name)});return o?ek().join(n,o.name):void 0}function tt(e=process.env,t=process.platform){let n=e.DBX_DEVICE_APP_CACHE_DIR?.trim();if(n)return ek().resolve(n);if("darwin"===t)return ek().join(eS().homedir(),"Library","Application Support","dbx","device-app");if("win32"===t){let t=e.LOCALAPPDATA?.trim()||ek().join(eS().homedir(),"AppData","Local");return ek().join(t,"dbx","device-app")}return ek().join(eS().homedir(),".local","share","dbx","device-app")}function tn(){return ek().resolve(eM,"../../..","device-app")}function tr(e,t){if(("darwin"===e||"win32"===e)&&("arm64"===t||"x64"===t))return`${e}-${t}`}function to(e){let t=e.DBX_DEVICE_APP_FORCE_DOWNLOAD?.trim().toLowerCase();return!!(t&&"0"!==t&&"false"!==t)}function ti(e,t,n,r,o){var i,s,a,d,l;let c,u=tu(e);if(!u||u.activeDeviceAppVersion!==o||u.cliVersion!==t.cliVersion||u.platform!==n||!tb(u.sha256,r)||u.entry!==r.entry)return;let p=tf(e,o);if(i=p,s=t,a=n,d=r,l=o,!((c=tc(i))&&c.cliVersion===s.cliVersion&&c.deviceAppVersion===l&&c.entry===d.entry&&c.platform===a&&tb(c.sha256,d)))return;let h=tv(p,r.entry,"device app entry");return eA().existsSync(h)?h:void 0}async function ts(e,t,n,r,o,i={}){t_(r);let s=tw(t,r),a=i.now?.()??Date.now(),d=ek().join(e,".tmp");eA().mkdirSync(d,{recursive:!0}),eA().mkdirSync(ek().join(e,eq),{recursive:!0});let l=eA().mkdtempSync(ek().join(d,`${s}-`)),c=ek().join(l,"device-app.zip"),u=ek().join(l,"extract"),p=tf(e,s);try{var h,f,m,g,_,w,y,b;let d,l;if(i.onProgress?.({phase:"download",downloadedBytes:0,...void 0===r.sizeBytes?{}:{totalBytes:r.sizeBytes,percentage:0},elapsedMs:0}),await ta(r.url,c,i.fetch,i.onProgress,i.signal),r.sha256&&(i.onProgress?.({phase:"install",stage:"verify"}),i.signal?.throwIfAborted(),d=await th(c),i.signal?.throwIfAborted(),d!==ty(r.sha256)))throw Error(`device app sha256 mismatch: expected ${r.sha256}, got ${d}`);eA().mkdirSync(u,{recursive:!0}),i.onProgress?.({phase:"install",stage:"extract"}),await tl(c,u,o,i);let v=tv(u,r.entry,"device app package entry");(function(e,t){if(!eA().existsSync(e))throw Error(`device app entry not found after extraction: ${e}`);let n=eA().statSync(e);if("darwin"===t){if(!n.isDirectory()||!e.endsWith(".app"))throw Error(`macOS device app entry must be a .app directory: ${e}`);return}if("win32"===t&&(!n.isFile()||!e.toLowerCase().endsWith(".exe")))throw Error(`Windows device app entry must be an .exe file: ${e}`)})(v,o),function(e,t,n,r,o){let i=tc(e);if(i&&(i.cliVersion!==t.cliVersion||i.deviceAppVersion!==o||i.entry!==r.entry||i.platform!==n||!tb(i.sha256,r)))throw Error(`device app metadata does not match CLI manifest in ${ek().join(e,e$)}`)}(u,t,n,r,s),i.onProgress?.({phase:"install",stage:"install"}),eA().rmSync(p,{recursive:!0,force:!0}),eA().renameSync(u,p),h=p,f=t,m=n,g=r,_=s,w=a,l={name:"Doubao App V2",cliVersion:f.cliVersion,deviceAppVersion:_,entry:g.entry,platform:m,...g.sha256?{sha256:ty(g.sha256)}:{},installedAt:w},tA(ek().join(h,e$),l),y=e,b={activeDeviceAppVersion:s,cliVersion:t.cliVersion,entry:r.entry,platform:n,...r.sha256?{sha256:ty(r.sha256)}:{},installedAt:a},tA(ek().join(y,eN),b);let E=tv(p,r.entry,"device app entry");return i.onProgress?.({phase:"complete",appPath:E}),E}finally{eA().rmSync(l,{recursive:!0,force:!0})}}async function ta(e,n,r=fetch,o,i){var s,a;let d,l,c,u,p,h,f=new URL(e);if("https:"!==f.protocol&&"http:"!==f.protocol)throw Error(`device app package URL must be http(s): ${e}`);i?.throwIfAborted();let m=await r(e,{signal:i});if(!m.ok)throw Error(`device app package download failed: HTTP ${m.status} ${m.statusText}`);if(!m.body)throw Error("device app package download failed: empty response body");let g=m.body;await (0,t.pipeline)(eD.Readable.fromWeb(g),(s=m,a=o,d=function(e){if(!e)return;let t=Number(e);return Number.isFinite(t)&&t>0?t:void 0}(s.headers.get("content-length")),l=0,c=-1,u=0,p=Date.now(),(h=e=>{if(!a)return;if(d){let t=Math.min(100,Math.floor(l/d*100));if(!e&&100!==t&&t<c+10||t===c)return;c=t;let n=Date.now()-p;a({phase:"download",downloadedBytes:l,totalBytes:d,percentage:t,elapsedMs:n});return}if(!e&&l-u<0x3200000||l===u)return;u=l;let t=Date.now()-p;a({phase:"download",downloadedBytes:l,elapsedMs:t})})(!1),new eD.Transform({transform(e,t,n){l+=e.length,h(!1),n(null,e)},flush(e){h(!0),e()}})),eA().createWriteStream(n),{signal:i})}function td(e){let t=["B","KB","MB","GB"],n=e,r=0;for(;n>=1024&&r<t.length-1;)n/=1024,r+=1;return 0===r?`${n} ${t[r]}`:`${n.toFixed(1)} ${t[r]}`}async function tl(e,t,n,r){let o=r.runCommand??((e,t)=>tC(e,{rejectOnNonZero:!0,signal:t?.signal}).then(()=>void 0));if("darwin"===n){r.signal?.throwIfAborted(),await o({command:"ditto",args:["-x","-k",e,t]},{signal:r.signal});return}if("win32"===n){r.signal?.throwIfAborted(),await o({command:"powershell.exe",args:["-NoProfile","-ExecutionPolicy","Bypass","-Command",`Expand-Archive -LiteralPath ${tE(e)} -DestinationPath ${tE(t)} -Force`],windowsVerbatimArguments:!0},{signal:r.signal});return}throw Error(`device app zip extraction is not supported on ${n}`)}function tc(e){let t=tI(ek().join(e,e$));if(!c(t))return;let n=t.cliVersion,r=t.deviceAppVersion,o=t.entry,i=t.platform,s=t.sha256,a=t.installedAt;if("string"==typeof n&&"string"==typeof r&&"string"==typeof o&&"string"==typeof i&&(void 0===s||"string"==typeof s)&&"number"==typeof a)return{name:"string"==typeof t.name?t.name:void 0,cliVersion:n,deviceAppVersion:r,entry:o,platform:i,..."string"==typeof s?{sha256:s}:{},installedAt:a}}function tu(e){let t=tI(ek().join(e,eN));if(c(t)&&"string"==typeof t.activeDeviceAppVersion&&"string"==typeof t.cliVersion&&"string"==typeof t.entry&&"string"==typeof t.platform&&(void 0===t.sha256||"string"==typeof t.sha256)&&"number"==typeof t.installedAt)return{activeDeviceAppVersion:t.activeDeviceAppVersion,cliVersion:t.cliVersion,entry:t.entry,platform:t.platform,..."string"==typeof t.sha256?{sha256:t.sha256}:{},installedAt:t.installedAt}}function tp(e,t){let n=ek().join(e,eq);if(eA().existsSync(n)){for(let e of eA().readdirSync(n,{withFileTypes:!0}))if(e.isDirectory()&&e.name!==t)try{eA().rmSync(ek().join(n,e.name),{recursive:!0,force:!0})}catch{}}}async function th(e){let n=eE().createHash("sha256");return await (0,t.pipeline)(eA().createReadStream(e),n),n.digest("hex")}function tf(e,t){return tm(t),ek().join(e,eq,t)}function tm(e){if(!/^[0-9A-Za-z._+-]+$/.test(e))throw Error(`device app version contains unsupported path characters: ${e}`)}function tg(e){if(1!==e.schemaVersion)throw Error(`unsupported device app manifest schemaVersion: ${e.schemaVersion}`);if(!e.cliVersion.trim())throw Error("device app manifest cliVersion is required");if(!e.deviceAppVersion.trim())throw Error("device app manifest deviceAppVersion is required");tm(e.deviceAppVersion)}function t_(e){if(!e.url||!e.entry)throw Error("device app package requires url and entry");if(void 0!==e.version){if(!e.version.trim())throw Error("device app package version must not be empty");tm(e.version)}if(e.sha256&&!/^[0-9a-fA-F]{64}$/.test(e.sha256))throw Error(`device app package sha256 must be 64 hex characters: ${e.sha256}`);if(void 0!==e.sizeBytes&&(!Number.isSafeInteger(e.sizeBytes)||e.sizeBytes<=0))throw Error(`device app package sizeBytes must be a positive integer: ${e.sizeBytes}`);if(ek().isAbsolute(e.entry)||e.entry.split(/[\\/]+/).includes(".."))throw Error(`device app package entry must be a relative path inside the zip: ${e.entry}`)}function tw(e,t){let n=t.version??e.deviceAppVersion;if(!n.trim())throw Error("device app package version must not be empty");return tm(n),n}function ty(e){return e.toLowerCase()}function tb(e,t){return!t.sha256||e===ty(t.sha256)}function tv(e,t,n){if(ek().isAbsolute(t))throw Error(`${n} must be relative: ${t}`);let r=ek().resolve(e),o=ek().resolve(e,t);if(o!==r&&!o.startsWith(`${r}${ek().sep}`))throw Error(`${n} escapes target directory: ${t}`);return o}function tE(e){return`'${e.replace(/'/g,"''")}'`}function tI(e){try{return JSON.parse(eA().readFileSync(e,"utf8"))}catch{return}}function tA(e,t){eA().mkdirSync(ek().dirname(e),{recursive:!0}),eA().writeFileSync(e,`${JSON.stringify(t,null,2)}
13
+ `,"utf8")}async function tT(e){let t=function(e){if(!e.endsWith(".app"))return;let t=function(e){let t=ek().join(e,"Contents","Info.plist");if(!eA().existsSync(t))return;let n=eA().readFileSync(t,"utf8").match(/<key>CFBundleExecutable<\/key>\s*<string>([^<]+)<\/string>/);return n?.[1]}(e)??ek().basename(e,".app");return ek().join(e,"Contents","MacOS",t)}(e);await tC(tj(e,"darwin"),{rejectOnNonZero:!1}),!t||await tS(t)&&await tC({command:"pkill",args:["-f",tk(t)]},{rejectOnNonZero:!1})}function tC(e,t){return new Promise((n,r)=>{let o;t.signal?.throwIfAborted();let i=(0,eb.spawn)(e.command,e.args,{stdio:"ignore",windowsVerbatimArguments:e.windowsVerbatimArguments}),s=!1,a=()=>{i.kill(),(o=setTimeout(()=>i.kill("SIGKILL"),1e3)).unref()},d=e=>{s||(s=!0,clearTimeout(o),t.signal?.removeEventListener("abort",a),e())};t.signal?.addEventListener("abort",a,{once:!0}),i.once("error",e=>d(()=>r(e))),i.once("close",o=>{if(t.signal?.aborted)return void d(()=>r(t.signal?.reason instanceof Error?t.signal.reason:new tZ));let i=o??0;0!==i&&t.rejectOnNonZero?d(()=>r(Error(`${e.command} exited with code ${i}`))):d(()=>n(i))})})}async function tS(e){return 0===await tC({command:"pgrep",args:["-f",tk(e)]},{rejectOnNonZero:!1})}function tj(e,t){return"darwin"===t?{command:"osascript",args:["-e",`tell application (POSIX file "${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}" as alias) to quit`]}:"win32"===t?{command:"cmd",args:["/c","taskkill","/IM",ek().basename(e),"/T"],windowsVerbatimArguments:!0}:{command:"pkill",args:["-f",e]}}function tk(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}async function tD(e,t,n){let r=await e.client.call(n);if(!r.length)return void nn(e.output,`no ${t}s found`);for(let n of r)nn(e.output,`- ${ne(t,n)}`)}async function tP(e,t){if(t.length>0)throw Error("sessions does not accept arguments");let n=await tB(e,"sessions"),{session:r}=n;try{let t=await r.getConnectedClients();if(0===t.length)throw new U("DEVICE_NOT_CONNECTED","no debug device is connected");let n=t.flatMap(e=>e.sessions.filter(J).map(t=>({clientId:e.device.clientId,sessionId:t.sessionId,url:t.url}))).sort((e,t)=>e.clientId-t.clientId||t.sessionId-e.sessionId);if(0===n.length)throw new U("NO_ACTIVE_LYNX_SESSION","the connected device has no active Lynx session");let o=r.getRuntimeInspectionTarget?await r.getRuntimeInspectionTarget().catch(()=>null):null,i=tN(e),s=e.activeClientId??(1===t.length?t[0]?.device.clientId:void 0),a=void 0===s?void 0:n.find(e=>e.clientId===s);for(let t of n){let n=[tq(t,o)?"electron":void 0,"fixed"===i.kind&&tq(t,i.target)?"cli":void 0,tq(t,a)?"latest":void 0].filter(e=>void 0!==e);nn(e.output,`${H(t)}${n.length?` ${n.map(e=>`[${e}]`).join(" ")}`:""} ${t.url||"unknown"}`)}}finally{n.owned&&await r.stop().catch(()=>void 0)}}async function tx(e,t){if(1!==t.length)throw Error("use-session requires @<clientId>:<sessionId> or latest");if(t[0]?.toLowerCase()==="latest"){e.runtimeInspectionTargetPolicy={kind:"latest"},nn(e.output,T.bold.blueBright(`CLI 调试目标已恢复为 latest${void 0===e.activeClientId?"":`(client ${e.activeClientId} 内最新活跃 Lynx session)`};不会切换 Electron。`));return}let n=K(t[0]??""),r=await tB(e,"use-session"),{session:o}=r;try{let t=await V(o,{activeClientId:e.activeClientId,explicitTarget:n,signal:e.signal});e.runtimeInspectionTargetPolicy={kind:"fixed",target:{clientId:t.clientId,sessionId:t.sessionId}},nn(e.output,T.bold.blueBright(`CLI 调试目标已固定为 ${H(t)}(${t.url||"unknown"});不会切换 Electron。`))}finally{r.owned&&await o.stop().catch(()=>void 0)}}async function tL(e,t){let n=(0,ex.parseArgs)({args:t,allowPositionals:!1,options:{limit:{type:"string"},"timeout-seconds":{type:"string"},"include-stack-traces":{type:"boolean"},target:{type:"string"}}}),r=function(e){if(void 0===e)return;let t=Number(e);if(!Number.isSafeInteger(t)||t<1||t>100)throw Error("--limit must be an integer between 1 and 100");return t}(n.values.limit),o=function(e){if(void 0===e)return;let t=Number(e);if(!Number.isFinite(t)||t<=0)throw Error("--timeout-seconds must be a positive number");return Math.round(1e3*t)}(n.values["timeout-seconds"]),i=await tB(e,"get-console"),{session:s}=i;try{let t=await tM(e,s,n.values.target);nn(e.output,T.bold.blueBright(`正在监听 client ${t.clientId}、session ${t.sessionId}(${t.url||"unknown"})的新日志;按 Ctrl+C 停止监听。`));let i=await ed(s,t,{...void 0===r?{}:{limit:r},...void 0===o?{}:{timeoutMs:o},signal:e.signal,onTargetChange(n){nn(e.output,T.bold.blueBright(`提示:Electron 已切换到 client ${n.clientId}、session ${n.sessionId}(${n.url||"unknown"});当前 CLI 仍监听 client ${t.clientId}、session ${t.sessionId},不会自动跟随 Electron。`))},onMessage(t){nn(e.output,function(e,t={}){var n;let r=e.args.map(ep).join(" "),o=t.includeStackTraces||"error"===e.type?(n=e.stackTrace,c(n)&&Array.isArray(n.callFrames)?n.callFrames.filter(c).map(e=>{let t="string"==typeof e.url?e.url:"",n="number"==typeof e.lineNumber?e.lineNumber:"unknown",r="number"==typeof e.columnNumber?e.columnNumber:"unknown";return` at ${t}:${n}:${r}`}).join("\n"):""):"";return`[${e.type}/${e.thread}] ${r}${o?`
14
+ ${o}`:""}`}(t,{includeStackTraces:n.values["include-stack-traces"]}))}});nn(e.output,`日志监听已停止,共 ${i.count} 条。`)}finally{i.owned&&await s.stop().catch(()=>void 0)}}async function tR(e,t,n=!1){let r=(0,ex.parseArgs)({args:t,allowPositionals:!1,options:{output:{type:"string",short:"o"},target:{type:"string"}}}),o=await tB(e,"take-screenshot"),{session:i}=o;try{let t=await tM(e,i,r.values.target),o=await el(i,t,{activeCapture:!e.manageDeviceApp}),s=ek().resolve(r.values.output??`screenshot-${Date.now()}.jpeg`);await eA().promises.writeFile(s,Buffer.from(o.data,"base64")),n?nr(e.output,{ok:!0,command:"take-screenshot",target:t,output:s,format:o.format,source:o.source,width:o.width,height:o.height,byteLength:o.byteLength}):nn(e.output,`截图已保存:${s}(${o.width}\xd7${o.height},client ${t.clientId}、session ${t.sessionId},${t.url||"unknown"};${e.manageDeviceApp?"范围跟随 Electron 当前 mode":"由设备按当前截图 mode 生成"})`)}finally{o.owned&&await i.stop().catch(()=>void 0)}}async function tO(e,t,n=!1){let r=(0,ex.parseArgs)({args:t,allowPositionals:!1,options:{depth:{type:"string"},target:{type:"string"}}}),o=function(e){if(void 0===e)return -1;let t=Number(e);if(!Number.isSafeInteger(t)||t<-1)throw Error("--depth must be -1 or a non-negative integer");return t}(r.values.depth),i=await tB(e,"get-page-tree"),{session:s}=i;try{let t=await tM(e,s,r.values.target),i=await W(s,t,{depth:o});if(n)nr(e.output,{ok:!0,command:"get-page-tree",...i});else{let n,r;nn(e.output,`DOM tree: client ${t.clientId}、session ${t.sessionId}(${t.url||"unknown"})`),nn(e.output,(n=[],(r=(e,t,o)=>{n.push(`${t}${o}${function(e){if(er(e))return`${e.ref} #text ${es(e.nodeValue)}`;let t=(e.localName||e.nodeName).toLowerCase();if(t.startsWith("#"))return`${e.ref} ${t}`;let n=Object.entries(e.attributes).map(([e,t])=>`${e}=${es(t,80)}`).join(" "),r=e.text||e.children.filter(er).map(e=>e.nodeValue).join("");return[e.ref,`<${t}${n?` ${n}`:""}>`,r?es(r,120):""].filter(Boolean).join(" ")}(e)}`);let i=e.children.filter(e=>!er(e));i.forEach((e,n)=>{r(e,`${t}${o?"└─ "===o?" ":"│ ":""}`,n===i.length-1?"└─ ":"├─ ")})})(i.root,"",""),i.truncated&&n.push(`… tree truncated after ${i.nodeCount} nodes`),n.join("\n"))),nn(e.output,`共 ${i.nodeCount} 个节点${i.truncated?"(已截断)":""}。`)}}finally{i.owned&&await s.stop().catch(()=>void 0)}}async function t$(e,t,n=!1){let r=(0,ex.parseArgs)({args:t,allowPositionals:!0,options:{properties:{type:"string"}}}),o=r.positionals[0];if(!o)throw new U("INVALID_NODE_REF","node-ref is required; run get-page-tree and pass @<clientId>:<sessionId>:<nodeId>");if(r.positionals.length>1)throw Error("get-computed-style accepts exactly one node-ref");let i=function(e){let t=/^@([1-9]\d*):([1-9]\d*):([1-9]\d*)$/.exec(e.trim());if(!t)throw new U("INVALID_NODE_REF",`invalid node ref "${e}"; expected @<clientId>:<sessionId>:<nodeId>`);let n={clientId:Number(t[1]),sessionId:Number(t[2]),nodeId:Number(t[3])};if(!Number.isSafeInteger(n.clientId)||!Number.isSafeInteger(n.sessionId)||!Number.isSafeInteger(n.nodeId))throw new U("INVALID_NODE_REF",`invalid node ref "${e}"; every id must be a safe integer`);return n}(o),s=function(e){if(void 0===e)return[];let t=e.split(",").map(e=>e.trim());if(0===t.length||t.some(e=>!/^-{0,2}[a-z][a-z0-9-]*$/i.test(e)))throw Error("--properties must be a comma-separated list of CSS property names");return[...new Set(t.map(e=>e.toLowerCase()))]}(r.values.properties),a=await tB(e,"get-computed-style"),{session:d}=a;try{let t=await Y(d,i),r=await G(d,t,i,s);if(n)nr(e.output,{ok:!0,command:"get-computed-style",...r});else if(nn(e.output,`${r.nodeRef} computed style(client ${t.clientId}、session ${t.sessionId})`),0===r.properties.length)nn(e.output,"没有匹配的 computed style 属性。");else{let t=Math.max(...r.properties.map(e=>e.name.length));for(let n of r.properties)nn(e.output,` ${n.name.padEnd(t)} ${n.value}`)}}finally{a.owned&&await d.stop().catch(()=>void 0)}}function tN(e){return e.runtimeInspectionTargetPolicy??{kind:"latest"}}function tq(e,t){return null!=e&&null!=t&&e.clientId===t.clientId&&e.sessionId===t.sessionId}function tM(e,t,n){return V(t,{activeClientId:e.activeClientId,policy:tN(e),...void 0===n?{}:{explicitTarget:K(n)},signal:e.signal})}async function tB(e,t){if(e.runtimeInspectionSession)return{owned:!1,session:await e.runtimeInspectionSession};let n=e.createRuntimeInspectionSession??F;return{owned:!0,session:await n({namespace:e.runtime.getState().namespace,nodeIdPrefix:`dev-shell-${t}`})}}async function tU(e,t){let o=(0,ex.parseArgs)({args:t,allowPositionals:!0,options:{"device-id":{type:"string"}}}),i=o.positionals[0]??await tH(e,"page",n.discoverPages);if(!i)throw Error("page url is required");let s=o.values["device-id"]??e.activeDeviceId;nn(e.output,`debug: page open request ${nt({url:i,deviceId:s})}`);let a=r("page",await e.client.call(n.openPageUrl,{url:i,deviceId:s}));nn(e.output,`page opened: ${i}`),nn(e.output,`status: ${tV(a)}`)}async function tF(e,t){let o=(0,ex.parseArgs)({args:t,allowPositionals:!0,options:{data:{type:"string"},"bot-id":{type:"string"},"device-id":{type:"string"}}}),s=o.positionals[0]??await tH(e,"widget",n.discoverWidgets);if(!s)throw Error("widget id is required");let a=i(o.values.data,"--data"),d=o.values["device-id"]??e.activeDeviceId;nn(e.output,`debug: widget push request ${nt({widgetId:s,data:a,botId:o.values["bot-id"],deviceId:d})}`);let l=r("widget",await e.client.call(n.pushWidget,{widgetId:s,widgetData:a,botId:o.values["bot-id"],deviceId:d}));nn(e.output,`widget pushed: ${s}`),nn(e.output,`status: ${tV(l)}`)}function tV(e){if(!e.ok)return"failed";let t=function(e){if(!e||"object"!=typeof e)return;let t=e.data;if(!t||"object"!=typeof t)return;let n=t.msg;return"string"==typeof n?n:void 0}(e.result);return"string"==typeof t&&t.trim()?t:"ok"}async function tH(e,t,n){let r=await e.client.call(n);if(r.length)return e.selectItem(t,r,e.output)}function tK(e,t){return t.map(t=>{let n=t9(e,t);return n?{label:ne(e,t),value:n}:void 0}).filter(e=>!!e)}async function tz(e){var t,r;let o,i,s,a,l=e.timeoutMs??6e4;if(!e.hostUrl||!e.appKey)return{ok:!1,status:"skipped",timeoutMs:l,failureStage:"create_qr",error:"无法生成二维码,缺少 hostUrl 或 appKey。"};let c=e.hostUrl,p=e.appKey,h=(t=e.namespace,r=l,i=new d(t,{nodeId:`dev-auth-${process.pid}-${Math.random().toString(36).slice(2,8)}`,requestTimeout:2e3}),s=!1,a=new Promise(e=>{o=e}),i.createService({name:`devAuthListener${process.pid}`,events:{"connection.newclient"(e){var t;s||(s=!0,o((t=e.params)&&"object"==typeof t?{scope:"string"==typeof t.scope?t.scope:void 0,type:"string"==typeof t.type?t.type:void 0,clientId:"number"==typeof t.clientId?t.clientId:void 0,deviceId:t4(t),app:"string"==typeof t.app?t.app:void 0}:{}))}}}),{start:()=>i.start(),stop:()=>i.stop(),wait:(e,t=r)=>{var n,o,i;return n=a,o=t,i=e,new Promise((e,t)=>{let r=()=>{clearTimeout(s),t(i?.reason instanceof Error?i.reason:new tZ)},s=setTimeout(()=>{i?.removeEventListener("abort",r),t(new tX(o))},o);i?.aborted?r():(i?.addEventListener("abort",r,{once:!0}),n.then(t=>{clearTimeout(s),i?.removeEventListener("abort",r),e(t)},e=>{clearTimeout(s),i?.removeEventListener("abort",r),t(e)}))})},async findExistingClient(){let e=await t2(()=>i.call("devtoolConnection.getConnectedClients"),2e3).catch(()=>[]);return function(e){if(!e||"object"!=typeof e)return;let t=e.device,n=t?.info,r="number"==typeof t?.clientId?t.clientId:void 0;return{scope:"all",type:String(n?.network??"").toLowerCase().includes("wifi")?"wifi":"usb",...void 0===r?{}:{clientId:r},deviceId:t4({client:e}),app:"string"==typeof n?.App?n.App:""}}(Array.isArray(e)?e[0]:void 0)},async awaitDirectDebugReady(e){let t=Math.min(r,2500);try{return await i.call(n.awaitDirectDebugReady,{clientId:e,timeoutMs:t},{timeout:t+1e3})}catch{return!1}},waitForInstallResult:(e,t,r,o)=>{var s,a;return s=i.call(n.awaitDeviceInstallResult,{clientId:e,packageName:t,timeoutMs:r},{timeout:r+1e3}),(a=o)?new Promise((e,t)=>{let n=()=>{t(a.reason instanceof Error?a.reason:new tZ)};if(a.aborted){s.catch(()=>void 0),n();return}a.addEventListener("abort",n,{once:!0}),s.then(t=>{a.removeEventListener("abort",n),e(t)},e=>{a.removeEventListener("abort",n),t(e)})}):s}}),f={},m="connection",g="wait_device_connection";await h.start();try{let t;e.signal?.throwIfAborted();let n=await h.findExistingClient(),r=n?.clientId!==void 0&&await h.awaitDirectDebugReady(n.clientId);if(r)await e.onPhaseChange?.("reusing_client");else{let n,r,o;g="create_qr",t=await tY(f,()=>(0,eL.Ph)(function(e,t,n={}){let r=tW(n.settings);return{hostUrl:e,appKey:t,...void 0===n.versionTag?{}:{versionTag:n.versionTag},isSigned:!1,appletType:0,baseApiUrl:u(),authOptions:E(),...!1===r.defaultDebugTagState?{defaultDebugTagState:!1}:{},...!r.usb&&n.wifiConnectUrl?{wifiConnectUrl:n.wifiConnectUrl}:{}}}(c,p,{versionTag:e.versionTag,settings:e.settings,wifiConnectUrl:e.wifiConnectUrl})),e.signal),await e.onPhaseChange?.("waiting_for_scan"),nn(e.output,""),nn(e.output,"使用豆包 App 扫码连接调试设备."),nn(e.output,`二维码创建成功,请在 ${(n=Math.max(1,Math.round(l/1e3)),r=Math.floor(n/60),o=n%60,r>0?`${r}m ${o}s`:`${o}s`)} 前扫码; 超时可在真机模式执行 \`qr\` 创建新二维码.`),nn(e.output,""),await e.onQRCodeReady?.(t.qrCodeValue,t.debugToken),e.signal?.throwIfAborted()}g="wait_device_connection";let o=Date.now()+l;nn(e.output,`等待设备连接 (${l/1e3}s timeout)...`);let i=r?n:await h.wait(e.signal,t1(o));if(void 0===i.clientId)throw Error("连接的设备缺少 clientId");m="install",g="install_debug_package",await e.onPhaseChange?.("waiting_for_install");let s=await h.waitForInstallResult(i.clientId,p,t1(o),e.signal);if(!s)throw new tX(l);if(!s.success)return{ok:!1,status:"skipped",timeoutMs:l,failureStage:g,waitingFor:m,client:i,error:s.message||"安装 AIPackage 失败,请检查网络环境并关注客户端提示"};return{ok:!0,status:"connected",timeoutMs:l,...t?{qrCodeValue:t.qrCodeValue,debugToken:t.debugToken,encryptedDebugPayload:t.encryptedDebugPayload}:{},client:i}}catch(o){let t=o instanceof tX,n=o instanceof tZ||!!e.signal?.aborted,r=function(e){if(e&&"object"==typeof e)return tJ(e,"logId")??tJ(e,"log_id")}(o)??f.logId;return{ok:!1,status:n?"cancelled":t?"timeout":"skipped",timeoutMs:l,failureStage:g,waitingFor:m,...r?{logId:r}:{},error:o instanceof Error?o.message:String(o)}}finally{await h.stop()}}async function tY(e,t,n){let r=globalThis.fetch;globalThis.fetch=async(t,o)=>{var i;let s,a=(s=function(e){try{if("string"==typeof e)return new URL(e);if(e instanceof URL)return new URL(e.toString());return new URL(e.url)}catch{return}}(i=t))&&s.pathname.startsWith("/developer/check_api/apps/")&&s.pathname.endsWith("/debug/ticket")?(s.pathname=s.pathname.replace(/^\/developer\/check_api\//,"/app_developer/check_api/"),"string"==typeof i)?s.toString():i instanceof URL?s:new Request(s,i):i,d=await r(a,n&&a!==t&&!o?.signal?{...o,signal:n}:o);return await tG(e,d),d};try{return await t()}finally{globalThis.fetch=r}}function tW(e){return{defaultDebugTagState:e?.defaultDebugTagState??!0,usb:e?.usb??!0}}async function tG(e,t){let n=t.headers.get("x-tt-logid");if(n){e.logId=n;return}try{let n=await t.clone().text();if(!n)return;let r=JSON.parse(n),o=tJ(r,"log_id")??tJ(r,"logId");o&&(e.logId=o)}catch{}}function tJ(e,t){if(!e||"object"!=typeof e)return;let n=e[t];return"string"==typeof n&&n?n:void 0}function tQ(e){return e.replace(/\s*[\[((]log_id:\s*[^\]))]+[\]))]/gi,"").trim()}class tX extends Error{constructor(e){super(`real-device auth timed out after ${e}ms`),this.name="RealDeviceAuthTimeoutError"}}class tZ extends Error{constructor(){super("real-device auth cancelled"),this.name="RealDeviceAuthCancelledError"}}function t0(e,t){let n=new d(e,{nodeId:`dev-disconnect-${process.pid}-${Math.random().toString(36).slice(2,8)}`,requestTimeout:2e3});return n.createService({name:`devDisconnectListener${process.pid}`,events:{"connection.clientDisconnected":()=>t()}}),{start:()=>n.start(),stop:()=>n.stop()}}function t1(e){return Math.max(0,e-Date.now())}async function t2(e,t){let n=Date.now()+t;for(;;)try{return await e()}catch(e){if(Date.now()>=n)throw e;await new Promise(e=>{setTimeout(e,100)})}}function t4(e){let t=e.client?.device,n=t?.info;return n?.usbDeviceId||t?.xdbId||n?.did||n?.debugRouterId}async function t5(e,t){let n=ek().resolve(t);if(".png"!==ek().extname(n).toLowerCase())throw Error("QR file must use the .png extension");return eA().mkdirSync(ek().dirname(n),{recursive:!0}),await eR.toFile(n,e,{errorCorrectionLevel:"L",margin:4,type:"png"}),n}async function t3(e,t){let n=await eR.toBuffer(e,{errorCorrectionLevel:"L",margin:0,type:"png",width:320}),r=t?await eR.toBuffer(`doubaoapp://local_debug?short_token=${t}`,{errorCorrectionLevel:"L",margin:0,type:"png",width:320}):void 0;return{legacy:n,...r?{modern:r}:{}}}function t6(e=eS().tmpdir()){let t;try{t=eA().readdirSync(e,{withFileTypes:!0})}catch{return}for(let n of t)if(/^dbx-real-device-qr-.*\.(?:png|svg)$/i.test(n.name)&&(n.isFile()||n.isSymbolicLink()))try{eA().unlinkSync(ek().join(e,n.name))}catch{}}async function t8(e,t,n,r=process.stderr,o){let i,s,a;if(n){let t=await t5(e,n);nn(r,`二维码图片已导出至:${t}`)}let{legacy:d,modern:l}=await t3(e,o),c=eE().randomBytes(18).toString("hex"),u=`/${c}/`,p=new Set,h=!1,f=new Promise(e=>{s=e}),m=()=>{clearTimeout(i),i=void 0,h||s()},g=(0,eT.createServer)((e,t)=>{let n=e.url?.split("?",1)[0];if(t.setHeader("Cache-Control","no-store, no-cache, must-revalidate, max-age=0"),t.setHeader("Expires","0"),t.setHeader("Pragma","no-cache"),"GET"===e.method&&n===u){var r;t.writeHead(200,{"Content-Security-Policy":"default-src 'none'; img-src 'self'; connect-src 'self'; script-src 'unsafe-inline'; style-src 'unsafe-inline'","Content-Type":"text/html; charset=utf-8"}),t.end((r=!!l,`<!doctype html>
15
15
  <html lang="zh-CN">
16
16
  <head>
17
17
  <meta charset="utf-8">
@@ -41,7 +41,7 @@ ${o}`:""}`}(t,{includeStackTraces:n.values["include-stack-traces"]}))}});nn(e.ou
41
41
  });
42
42
  </script>
43
43
  </body>
44
- </html>`));return}if("GET"===e.method&&n===`${u}qr.png`){t.writeHead(200,{"Content-Type":"image/png"}),t.end(d);return}if("GET"===e.method&&n===`${u}qr-modern.png`){if(!l){t.writeHead(404,{"Content-Type":"text/plain; charset=utf-8"}),t.end("Not found");return}t.writeHead(200,{"Content-Type":"image/png"}),t.end(l);return}if("GET"===e.method&&n===`${u}events`){clearTimeout(i),i=void 0,t.writeHead(200,{Connection:"keep-alive","Content-Type":"text/event-stream"}),t.write("retry: 250\nevent: ready\ndata: ready\n\n"),p.add(t),t.once("close",()=>{p.delete(t),h||0!==p.size||(i=setTimeout(m,750))});return}if("POST"===e.method&&n===`${u}closed`){e.resume(),t.writeHead(204).end(),m();return}t.writeHead(404,{"Content-Type":"text/plain; charset=utf-8"}),t.end("Not found")});await new Promise((e,t)=>{g.once("error",t),g.listen(0,"127.0.0.1",()=>{g.removeListener("error",t),e()})});let _=g.address();if(!_||"string"==typeof _)throw await t7(g),Error("failed to start QR code viewer");let w=`http://127.0.0.1:${_.port}${u}`,y=()=>a??=(async()=>{h=!0,clearTimeout(i);try{for(let e of p)try{e.destroyed||e.writableEnded||(e.once("error",()=>void 0),e.end("event: close\ndata: close\n\n"))}catch{}}finally{p.clear(),await t7(g)}})();try{await t(w),nn(r,"已在默认浏览器打开二维码。")}catch(e){throw await y(),Error(`二维码页面未能自动打开:${no(e)}`)}return{closed:f,close:y}}function t7(e){return e.listening?new Promise(t=>{e.close(()=>t()),e.closeAllConnections()}):Promise.resolve()}function t9(e,t){if("page"!==e){if(!t||"object"!=typeof t)return;for(let e of["id","pageId","page_id","widgetId","widget_id","versionTag","version_tag","name","path"]){let n=t[e];if("string"==typeof n&&n.trim())return n}return}if(!t||"object"!=typeof t)return;let n=t.path;return"string"==typeof n&&n.trim()?n:void 0}function ne(e,t){let n=t9(e,t);if(!t||"object"!=typeof t)return n??String(t);let r="";return"string"==typeof t.title?r=t.title:"string"==typeof t.name&&(r=t.name),[n,r&&r!==n?r:""].filter(Boolean).join(" ")}function nt(e){return JSON.stringify(Object.fromEntries(Object.entries(e).filter(([,e])=>void 0!==e).map(([e,t])=>[e,"data"===e?w(t):t])))}function nn(e,t=""){e.write(`${t}
45
- `)}function nr(e,t){nn(e,JSON.stringify(t))}function no(e){return e instanceof Error?e.message:String(e)}let ni=new Set(["preparing","downloading","installing_tool","reusing_client","waiting_for_scan","waiting_for_install","launching_tool"]),ns=new eD.Writable({write(e,t,n){n()}});class na{options;provider;state={revision:0,phase:"idle",canCancel:!1,canRetry:!1};activeOperation;controlClient;controlClientPromise;disconnectWatcher;qrImages;qrRevision=0;deviceAppOpened=!1;disposed=!1;dependencies;constructor(e){this.options=e,this.dependencies={connectClient:v,prepareDeviceApp:e3,runAuth:tz,renderQRCodes:t3,openDeviceApp:e6,closeDeviceApp:e8,createDisconnectWatcher:t0,...e.dependencies},this.provider={getState:()=>this.getState(),start:()=>this.startWeb(),cancel:e=>this.cancelWeb(e),getQrImage:(e,t)=>this.getQrImage(e,t)}}async runTerminal(e){if(this.activeOperation&&this.isActive())throw Error("REAL_DEVICE_DEBUG_BUSY: Web 或终端已有真机调试流程正在运行。");"connected"===this.state.phase&&(await this.stopDisconnectWatcher(),this.deviceAppOpened&&(await this.dependencies.closeDeviceApp().catch(()=>void 0),this.deviceAppOpened=!1));let t={id:eE().randomUUID(),owner:"terminal",abortController:new AbortController};this.activeOperation=t,this.clearQrImages(),this.replaceState({operationId:t.id,owner:"terminal",phase:"preparing",connectionMode:void 0,deadlineAt:void 0,canCancel:!1,canRetry:!1});let n=Promise.resolve().then(e);t.promise=n.then(()=>void 0,()=>void 0);try{return await n}finally{this.activeOperation===t&&(this.activeOperation=void 0,this.replaceState({phase:"idle",operationId:void 0,owner:void 0,connectionMode:void 0,deadlineAt:void 0,canCancel:!1,canRetry:!1}))}}async dispose(){if(this.disposed)return;this.disposed=!0;let e=this.activeOperation;e?.abortController.abort(Error("dev runtime stopped")),await e?.promise?.catch(()=>void 0),this.activeOperation=void 0,this.clearQrImages(),await this.stopDisconnectWatcher(),this.deviceAppOpened&&(await this.dependencies.closeDeviceApp().catch(()=>void 0),this.deviceAppOpened=!1);let t=await this.controlClientPromise?.catch(()=>void 0);await (t??this.controlClient)?.stop().catch(()=>void 0),this.controlClient=void 0,this.controlClientPromise=void 0}getState(){return{...this.state,...this.state.progress?{progress:{...this.state.progress}}:{},...this.state.qr?{qr:{...this.state.qr}}:{},...this.state.error?{error:{...this.state.error}}:{}}}startWeb(){if(this.disposed)return this.fail("DEV_RUNTIME_UNAVAILABLE","runtime","本地调试服务已停止,请重新运行 dbx dev。"),this.getState();if("connected"===this.state.phase||this.activeOperation&&this.isActive())return this.getState();let e={id:eE().randomUUID(),owner:"web",abortController:new AbortController};return this.activeOperation=e,this.clearQrImages(),this.replaceState({operationId:e.id,owner:"web",phase:"preparing",connectionMode:void 0,deadlineAt:void 0,canCancel:!0,canRetry:!1}),e.promise=this.runWebOperation(e).finally(()=>{this.activeOperation===e&&(this.activeOperation=void 0)}),e.promise.catch(()=>void 0),this.getState()}async cancelWeb(e){let t=this.activeOperation;return t&&t.id===e&&"web"===t.owner&&this.isActive()&&(t.abortController.abort(Error("真机调试已取消")),await t.promise?.catch(()=>void 0)),this.getState()}async getQrImage(e,t){if(this.state.operationId!==e||"waiting_for_scan"!==this.state.phase)return;let n=this.qrImages?.[t];return n?{body:new Uint8Array(n),contentType:"image/png"}:void 0}async runWebOperation(e){let{signal:t}=e.abortController,n=!1;try{let r=await this.options.getRuntime();t.throwIfAborted();let o=r.getState();if("running"!==o.status)throw new nd("DEV_RUNTIME_UNAVAILABLE","runtime","本地调试服务尚未就绪,请稍后重试。");let i=await this.getControlClient();t.throwIfAborted();let s=await i.call("dev.setConnectionTransport",{type:"usb"});t.throwIfAborted();let a=await this.dependencies.prepareDeviceApp(ns,{signal:t,onProgress:t=>this.handlePreparationProgress(e,t)});if(t.throwIfAborted(),"skipped"===a.status||!a.appPath)throw new nd(a.reason?.includes("not supported")?"UNSUPPORTED_PLATFORM":"TOOL_PREPARE_FAILED","prepare",a.reason?.includes("not supported")?"当前系统暂不支持自动准备 Desktop 工具。":"Desktop 工具准备失败,请重试或使用终端 device 查看详情。");let d=Date.now()+6e4;this.patchState(e,{deadlineAt:d});let l=await this.dependencies.runAuth({hostUrl:s.host||o.host,appKey:s.appId||o.appId,namespace:o.namespace,timeoutMs:6e4,settings:{usb:!0,defaultDebugTagState:!0},output:ns,signal:t,onPhaseChange:t=>{if("reusing_client"===t){this.clearQrImages(),this.patchState(e,{phase:t,connectionMode:"existing_client"});return}"waiting_for_scan"===t?this.patchState(e,{phase:t,connectionMode:"qr"}):(this.clearQrImages(),this.patchState(e,{phase:t}))},onQRCodeReady:async(n,r)=>{let o=await this.dependencies.renderQRCodes(n,r);t.throwIfAborted(),this.isCurrent(e)&&(this.qrImages=o,this.qrRevision+=1,this.patchState(e,{phase:"waiting_for_scan",connectionMode:"qr",qr:{revision:this.qrRevision,modernAvailable:!!o.modern,legacyAvailable:!0}}))}});if(t.throwIfAborted(),!l.ok||"connected"!==l.status){if("cancelled"===l.status)return void this.cancelled(e);if("timeout"===l.status){this.clearQrImages(),this.replaceOperationState(e,{phase:"timed_out",canCancel:!1,canRetry:!0,error:{code:"install"===l.waitingFor?"PACKAGE_INSTALL_TIMEOUT":"CONNECTION_TIMEOUT",stage:"install"===l.waitingFor?"package_install":"connection",message:"install"===l.waitingFor?"设备已连接,但安装调试包超时,请重试。":"等待扫码连接超时,请重新生成二维码。"}});return}let t="waiting_for_scan"===this.state.phase||"reusing_client"===this.state.phase;throw new nd("install"===l.waitingFor?"PACKAGE_INSTALL_FAILED":t?"REAL_DEVICE_DEBUG_FAILED":"TICKET_FAILED","install"===l.waitingFor?"package_install":t?"connection":"ticket","install"===l.waitingFor?"调试包安装失败,请检查客户端提示后重试。":t?"设备连接失败,请重新扫码。":"二维码创建失败,请稍后重试。")}this.clearQrImages(),this.patchState(e,{phase:"launching_tool",qr:void 0});let c=await this.dependencies.openDeviceApp(a.appPath,{namespace:o.namespace,projectPath:o.projectPath,appDir:o.appDir,appKey:o.appId,hostUrl:o.host});if("opened"!==c.status)throw t.throwIfAborted(),new nd("TOOL_LAUNCH_FAILED","launch","Desktop 工具启动失败,请重试。");if(n=!0,this.deviceAppOpened=!0,t.throwIfAborted(),await this.watchForDisconnect(e,o.namespace),t.throwIfAborted(),"failed"===this.state.phase)return;this.replaceOperationState(e,{phase:"connected",deadlineAt:void 0,canCancel:!1,canRetry:!1})}catch(o){if(t.aborted){await this.stopDisconnectWatcher(),n&&this.deviceAppOpened&&(await this.dependencies.closeDeviceApp().catch(()=>void 0),this.deviceAppOpened=!1),this.cancelled(e);return}let r=o instanceof nd?o:new nd("launching_tool"===this.state.phase?"TOOL_LAUNCH_FAILED":"preparing"===this.state.phase||"downloading"===this.state.phase||"installing_tool"===this.state.phase?"TOOL_PREPARE_FAILED":"REAL_DEVICE_DEBUG_FAILED","launching_tool"===this.state.phase?"launch":"preparing"===this.state.phase||"downloading"===this.state.phase||"installing_tool"===this.state.phase?"prepare":"connection","launching_tool"===this.state.phase?"Desktop 工具启动失败,请重试。":"preparing"===this.state.phase||"downloading"===this.state.phase||"installing_tool"===this.state.phase?"Desktop 工具准备失败,请重试或使用终端 device 查看详情。":"真机调试启动失败,请重试。");this.clearQrImages(),this.replaceOperationState(e,{phase:"failed",canCancel:!1,canRetry:!0,error:{code:r.code,stage:r.stage,message:r.message}})}}handlePreparationProgress(e,t){if(t){if("download"===t.phase)return void this.patchState(e,{phase:"downloading",progress:{downloadedBytes:t.downloadedBytes,...void 0===t.totalBytes?{}:{totalBytes:t.totalBytes},...void 0===t.percentage?{}:{percentage:t.percentage}}});"install"===t.phase&&this.patchState(e,{phase:"installing_tool",progress:{installStage:t.stage}})}}async getControlClient(){return this.controlClient?this.controlClient:(this.controlClientPromise||(this.controlClientPromise=this.dependencies.connectClient({projectPath:this.options.projectPath,appDir:this.options.appDir,nodeIdPrefix:"web-real-device"}).then(e=>(this.controlClient=e,e)).catch(e=>{throw this.controlClientPromise=void 0,e})),this.controlClientPromise)}async watchForDisconnect(e,t){await this.stopDisconnectWatcher();let n=this.dependencies.createDisconnectWatcher(t,async()=>{this.isCurrentState(e)&&("launching_tool"===this.state.phase||"connected"===this.state.phase)&&(this.clearQrImages(),this.replaceState({phase:"failed",canCancel:!1,canRetry:!0,error:{code:"DEVICE_DISCONNECTED",stage:"disconnect",message:"真机连接已断开,请重新扫码。"}}),this.deviceAppOpened&&(await this.dependencies.closeDeviceApp().catch(()=>void 0),this.deviceAppOpened=!1))});(await n.start(),this.isCurrent(e))?this.disconnectWatcher=n:await n.stop().catch(()=>void 0)}async stopDisconnectWatcher(){let e=this.disconnectWatcher;this.disconnectWatcher=void 0,await e?.stop().catch(()=>void 0)}cancelled(e){this.clearQrImages(),this.replaceOperationState(e,{phase:"cancelled",connectionMode:void 0,deadlineAt:void 0,canCancel:!1,canRetry:!0})}fail(e,t,n){this.replaceState({phase:"failed",canCancel:!1,canRetry:!0,error:{code:e,stage:t,message:n}})}patchState(e,t){this.isCurrent(e)&&this.replaceState(t)}replaceOperationState(e,t){this.isCurrentState(e)&&this.replaceState(t)}replaceState(e){this.state={...this.state,...e,revision:this.state.revision+1,...e.phase&&!("error"in e)&&"failed"!==e.phase&&"timed_out"!==e.phase?{error:void 0}:{},...e.phase&&"waiting_for_scan"!==e.phase?{qr:void 0}:{},...e.phase&&"downloading"!==e.phase&&"installing_tool"!==e.phase?{progress:void 0}:{}}}clearQrImages(){this.qrImages=void 0}isCurrent(e){return this.activeOperation===e&&!e.abortController.signal.aborted}isCurrentState(e){return this.state.operationId===e.id}isActive(){return ni.has(this.state.phase)}}class nd extends Error{code;stage;constructor(e,t,n){super(n),this.code=e,this.stage=t}}function nl(){return new u("dev").description("启动 dev 调试控制台(Web 模拟器、真机调试、页面和卡片推送)").option("--project-path <path>","dbx 项目路径,状态数据会写入该目录下的 .dbx",".").option("--mcp-endpoint <url>","临时覆盖 manifest.mcp_server.end_point;优先级高于环境变量和 manifest").option("--manifest <path>","manifest.yaml 路径;相对路径按 --project-path 解析,默认按项目布局自动解析").option("--skill <path>","运行态 Skill 目录;显式目录优先,相对路径按 --project-path 解析;未传默认 skill/,递归加载所有 SKILL.md").option("--verbose","输出 dev service 生命周期日志",!1).addOption(new i("--manifest-path <path>","本地调试使用的 simulator manifest 文件路径").hideHelp()).action(async(e,t)=>h(t,t=>nc(t,e)))}async function nc(e,t){let n=(0,ev.randomUUID)(),r=a(),o={devSessionId:n,actionSequence:1,startedAt:performance.now(),runtimeReady:!1,appId:void 0,eventTrackingReady:r};try{return await nu(e,t,o)}catch(e){if(!o.runtimeReady){let t=performance.now()-o.startedAt,r=f(e);await o.eventTrackingReady,await p({action:"start",actionSequence:1,appId:o.appId,devSessionId:n,durationMs:t,error:e,errorStage:"dev_startup",status:r}),await l({appId:o.appId,command:"dev",durationMs:t,error:e,errorStage:"dev_startup",outputMode:"human",status:r})}throw e}}async function nu(e,t,n){let r,o,i,s,a;e.json&&e.error("dbx dev starts an interactive console and does not support --json");let d=nf(),c=(0,ej.resolve)(t.projectPath),{businessTemplatesPath:u,simulatorManifestPath:h,skillsDirectory:f,warnings:m}=C({projectPath:c,manifest:t.manifest,skill:t.skill,manifestPath:t.manifestPath}),g=[...m];u&&await S(u);let _=h,w=!1;if(_){let e=await D(_);g.push(...e.warnings),w=e.validated,e.usable?(n.appId=r=e.appId,o=e.manifest):_=void 0}let y=await P(process.env,t.mcpEndpoint,_,o),b=R(o),v=j(o),E=L(c).frontendDirectory,A=new eD.PassThrough,T=process.stdin,$=new AbortController,N={},q=new na({projectPath:c,appDir:E,getRuntime:()=>N.promise?N.promise:Promise.reject(Error("Dev runtime is not ready"))}),M=process.env.DBX_WEB_REAL_DEVICE_DEBUG?.trim()!=="0",B=I({projectPath:c,appDir:E,installSignalHandlers:!0,signal:$.signal,verbose:t.verbose,...M?{realDeviceDebug:{provider:q.provider,dispose:()=>q.dispose()}}:{},devOptions:O({appId:r,permissions:v,mcpEndpoint:y,mcpHeaders:b,simulatorBusinessTemplatesPath:u,simulatorManifestPath:_,skillsDirectory:f,openBrowser:e=>{i=k(e)},printLogs:d?t.verbose:void 0,onLog:d&&!t.verbose?e=>{("warn"===e.level||"error"===e.level)&&A.write(`${"error"===e.level?"error:":"⚠"} ${e.message}
46
- `)}:void 0,onProgress:d?({percentage:e})=>a?.(e):void 0})}).then(async e=>{s=e,a?.(1),n.appId=e.getState().appId??r,n.runtimeReady=!0;let t=performance.now()-n.startedAt;return await n.eventTrackingReady,await p({action:"start",actionSequence:1,appId:n.appId,devSessionId:n.devSessionId,durationMs:t,status:"success"}),await l({appId:e.getState().appId??r,command:"dev",durationMs:t,outputMode:"human",status:"success"}),e});N.promise=B;let U=x({manifestReady:w,mcpEndpointSet:!!y,warnings:g});if(!d){let t=await B;U&&e.warn(U,{style:"label"});let n=t.getState();return e.log(`Web 模拟器: ${n.webDebuggerUrl??i??"-"}`),e.log(`pid: ${n.pid??process.pid}`),e.log("stop: Ctrl+C or kill the process"),await t.stopped,nh()}U&&A.write(`⚠ ${U}
47
- `);try{let{runInkDevShell:e}=await import("./dev-shell.js");await e({createSession:(e,t,o)=>{A.pipe(e);let a=B.then(r=>{if("running"===r.getState().status)return eK({projectPath:c,appDir:E,runtime:nm(r,c,()=>i),output:e,onDeviceAppSetupProgress:o,realDeviceDebugCoordinator:q,selectItem:t,eventTracking:n})});return Promise.resolve(np({session:a,stopped:B.then(e=>e.stopped),subscribe:e=>{let t,n=!1;return a.then(r=>{n||(t=r?.subscribe(e))}).catch(()=>void 0),()=>{n=!0,t?.()}},close:async()=>{$.abort(),await B.then(e=>e.stop()).catch(()=>void 0),await a.then(e=>e?.close()).catch(()=>void 0)},returnToRoot:async()=>{let e=await a.catch(()=>void 0);await e?.returnToRoot()},handleClientDisconnected:async()=>{let e=await a.catch(()=>void 0);await e?.handleClientDisconnected()},getState:()=>s?.getState()??{projectPath:c,appDir:E??c,appId:r,namespace:"",session_dir:"",status:"starting",created_at:0,updated_at:0}}))},subscribeCompileProgress:e=>(a=e,()=>{a===e&&(a=void 0)}),stdin:T,toChoices:tK})}finally{$.abort(),await B.then(e=>e.stop()).catch(()=>void 0),await q.dispose().catch(()=>void 0),A.destroy()}return nh()}function np(e){let t,n;return e.session.then(e=>{t=e},()=>void 0),{stopped:e.stopped,cancelActiveCommand:()=>n?.phase!=="waiting"||n.cancelled?t?.cancelActiveCommand()??!1:(n.cancelled=!0,n.resolveCancelled("continue"),!0),close:e.close,subscribe:e.subscribe,execute(r){let o,i=new Promise(e=>{o=e}),s={cancelled:!1,phase:"waiting",resolveCancelled:o};return n=s,Promise.race([e.session.then(e=>(t=e,s.cancelled)?"continue":(s.phase="running",e?.execute(r)??"continue")),i]).finally(()=>{n===s&&(n=void 0)})},returnToRoot:e.returnToRoot,handleClientDisconnected:e.handleClientDisconnected,getState:()=>t?.getState()??e.getState()}}async function nh(){await s(),process.exit(process.exitCode??0)}function nf(e=process.stdin,t=process.stderr){return!!(e.isTTY&&t.isTTY)}function nm(e,t,n){return{stopped:e.stopped,stop:()=>e.stop(),getState(){let r=e.getState();return{...r,projectPath:t,webDebuggerUrl:r.webDebuggerUrl??n()}}}}export{eU as DEV_SHELL_DEVICE_HELP_ITEMS,eB as DEV_SHELL_HELP_ITEMS,$ as dev_namespaceObject,eF as formatDeviceAppSetupStatus};
44
+ </html>`));return}if("GET"===e.method&&n===`${u}qr.png`){t.writeHead(200,{"Content-Type":"image/png"}),t.end(d);return}if("GET"===e.method&&n===`${u}qr-modern.png`){if(!l){t.writeHead(404,{"Content-Type":"text/plain; charset=utf-8"}),t.end("Not found");return}t.writeHead(200,{"Content-Type":"image/png"}),t.end(l);return}if("GET"===e.method&&n===`${u}events`){clearTimeout(i),i=void 0,t.writeHead(200,{Connection:"keep-alive","Content-Type":"text/event-stream"}),t.write("retry: 250\nevent: ready\ndata: ready\n\n"),p.add(t),t.once("close",()=>{p.delete(t),h||0!==p.size||(i=setTimeout(m,750))});return}if("POST"===e.method&&n===`${u}closed`){e.resume(),t.writeHead(204).end(),m();return}t.writeHead(404,{"Content-Type":"text/plain; charset=utf-8"}),t.end("Not found")});await new Promise((e,t)=>{g.once("error",t),g.listen(0,"127.0.0.1",()=>{g.removeListener("error",t),e()})});let _=g.address();if(!_||"string"==typeof _)throw await t7(g),Error("failed to start QR code viewer");let w=`http://127.0.0.1:${_.port}${u}`,y=()=>a??=(async()=>{h=!0,clearTimeout(i);try{for(let e of p)try{e.destroyed||e.writableEnded||(e.once("error",()=>void 0),e.end("event: close\ndata: close\n\n"))}catch{}}finally{p.clear(),await t7(g)}})();try{await t(w),nn(r,"已在默认浏览器打开二维码。")}catch(e){throw await y(),Error(`二维码页面未能自动打开:${no(e)}`)}return{closed:f,close:y}}function t7(e){return e.listening?new Promise(t=>{e.close(()=>t()),e.closeAllConnections()}):Promise.resolve()}function t9(e,t){if("page"!==e){if(!t||"object"!=typeof t)return;for(let e of["id","pageId","page_id","widgetId","widget_id","versionTag","version_tag","name","path"]){let n=t[e];if("string"==typeof n&&n.trim())return n}return}if(!t||"object"!=typeof t)return;let n=t.path;return"string"==typeof n&&n.trim()?n:void 0}function ne(e,t){let n=t9(e,t);if(!t||"object"!=typeof t)return n??String(t);let r="";return"string"==typeof t.title?r=t.title:"string"==typeof t.name&&(r=t.name),[n,r&&r!==n?r:""].filter(Boolean).join(" ")}function nt(e){return JSON.stringify(Object.fromEntries(Object.entries(e).filter(([,e])=>void 0!==e).map(([e,t])=>[e,"data"===e?o(t):t])))}function nn(e,t=""){e.write(`${t}
45
+ `)}function nr(e,t){nn(e,JSON.stringify(t))}function no(e){return e instanceof Error?e.message:String(e)}let ni=new Set(["preparing","downloading","installing_tool","reusing_client","waiting_for_scan","waiting_for_install","launching_tool"]),ns=new eD.Writable({write(e,t,n){n()}});class na{options;provider;state={revision:0,phase:"idle",canCancel:!1,canRetry:!1};activeOperation;controlClient;controlClientPromise;disconnectWatcher;qrImages;qrRevision=0;deviceAppOpened=!1;disposed=!1;dependencies;constructor(e){this.options=e,this.dependencies={connectClient:a,prepareDeviceApp:e3,runAuth:tz,renderQRCodes:t3,openDeviceApp:e6,closeDeviceApp:e8,createDisconnectWatcher:t0,...e.dependencies},this.provider={getState:()=>this.getState(),start:()=>this.startWeb(),cancel:e=>this.cancelWeb(e),getQrImage:(e,t)=>this.getQrImage(e,t)}}async runTerminal(e){if(this.activeOperation&&this.isActive())throw Error("REAL_DEVICE_DEBUG_BUSY: Web 或终端已有真机调试流程正在运行。");"connected"===this.state.phase&&(await this.stopDisconnectWatcher(),this.deviceAppOpened&&(await this.dependencies.closeDeviceApp().catch(()=>void 0),this.deviceAppOpened=!1));let t={id:eE().randomUUID(),owner:"terminal",abortController:new AbortController};this.activeOperation=t,this.clearQrImages(),this.replaceState({operationId:t.id,owner:"terminal",phase:"preparing",connectionMode:void 0,deadlineAt:void 0,canCancel:!1,canRetry:!1});let n=Promise.resolve().then(e);t.promise=n.then(()=>void 0,()=>void 0);try{return await n}finally{this.activeOperation===t&&(this.activeOperation=void 0,this.replaceState({phase:"idle",operationId:void 0,owner:void 0,connectionMode:void 0,deadlineAt:void 0,canCancel:!1,canRetry:!1}))}}async dispose(){if(this.disposed)return;this.disposed=!0;let e=this.activeOperation;e?.abortController.abort(Error("dev runtime stopped")),await e?.promise?.catch(()=>void 0),this.activeOperation=void 0,this.clearQrImages(),await this.stopDisconnectWatcher(),this.deviceAppOpened&&(await this.dependencies.closeDeviceApp().catch(()=>void 0),this.deviceAppOpened=!1);let t=await this.controlClientPromise?.catch(()=>void 0);await (t??this.controlClient)?.stop().catch(()=>void 0),this.controlClient=void 0,this.controlClientPromise=void 0}getState(){return{...this.state,...this.state.progress?{progress:{...this.state.progress}}:{},...this.state.qr?{qr:{...this.state.qr}}:{},...this.state.error?{error:{...this.state.error}}:{}}}startWeb(){if(this.disposed)return this.fail("DEV_RUNTIME_UNAVAILABLE","runtime","本地调试服务已停止,请重新运行 dbx dev。"),this.getState();if("connected"===this.state.phase||this.activeOperation&&this.isActive())return this.getState();let e={id:eE().randomUUID(),owner:"web",abortController:new AbortController};return this.activeOperation=e,this.clearQrImages(),this.replaceState({operationId:e.id,owner:"web",phase:"preparing",connectionMode:void 0,deadlineAt:void 0,canCancel:!0,canRetry:!1}),e.promise=this.runWebOperation(e).finally(()=>{this.activeOperation===e&&(this.activeOperation=void 0)}),e.promise.catch(()=>void 0),this.getState()}async cancelWeb(e){let t=this.activeOperation;return t&&t.id===e&&"web"===t.owner&&this.isActive()&&(t.abortController.abort(Error("真机调试已取消")),await t.promise?.catch(()=>void 0)),this.getState()}async getQrImage(e,t){if(this.state.operationId!==e||"waiting_for_scan"!==this.state.phase)return;let n=this.qrImages?.[t];return n?{body:new Uint8Array(n),contentType:"image/png"}:void 0}async runWebOperation(e){let{signal:t}=e.abortController,n=!1;try{let r=await this.options.getRuntime();t.throwIfAborted();let o=r.getState();if("running"!==o.status)throw new nd("DEV_RUNTIME_UNAVAILABLE","runtime","本地调试服务尚未就绪,请稍后重试。");let i=await this.getControlClient();t.throwIfAborted();let s=await i.call("dev.setConnectionTransport",{type:"usb"});t.throwIfAborted();let a=await this.dependencies.prepareDeviceApp(ns,{signal:t,onProgress:t=>this.handlePreparationProgress(e,t)});if(t.throwIfAborted(),"skipped"===a.status||!a.appPath)throw new nd(a.reason?.includes("not supported")?"UNSUPPORTED_PLATFORM":"TOOL_PREPARE_FAILED","prepare",a.reason?.includes("not supported")?"当前系统暂不支持自动准备 Desktop 工具。":"Desktop 工具准备失败,请重试或使用终端 device 查看详情。");let d=Date.now()+6e4;this.patchState(e,{deadlineAt:d});let l=await this.dependencies.runAuth({hostUrl:s.host||o.host,appKey:s.appId||o.appId,namespace:o.namespace,timeoutMs:6e4,settings:{usb:!0,defaultDebugTagState:!0},output:ns,signal:t,onPhaseChange:t=>{if("reusing_client"===t){this.clearQrImages(),this.patchState(e,{phase:t,connectionMode:"existing_client"});return}"waiting_for_scan"===t?this.patchState(e,{phase:t,connectionMode:"qr"}):(this.clearQrImages(),this.patchState(e,{phase:t}))},onQRCodeReady:async(n,r)=>{let o=await this.dependencies.renderQRCodes(n,r);t.throwIfAborted(),this.isCurrent(e)&&(this.qrImages=o,this.qrRevision+=1,this.patchState(e,{phase:"waiting_for_scan",connectionMode:"qr",qr:{revision:this.qrRevision,modernAvailable:!!o.modern,legacyAvailable:!0}}))}});if(t.throwIfAborted(),!l.ok||"connected"!==l.status){if("cancelled"===l.status)return void this.cancelled(e);if("timeout"===l.status){this.clearQrImages(),this.replaceOperationState(e,{phase:"timed_out",canCancel:!1,canRetry:!0,error:{code:"install"===l.waitingFor?"PACKAGE_INSTALL_TIMEOUT":"CONNECTION_TIMEOUT",stage:"install"===l.waitingFor?"package_install":"connection",message:"install"===l.waitingFor?"设备已连接,但安装调试包超时,请重试。":"等待扫码连接超时,请重新生成二维码。"}});return}let t="waiting_for_scan"===this.state.phase||"reusing_client"===this.state.phase;throw new nd("install"===l.waitingFor?"PACKAGE_INSTALL_FAILED":t?"REAL_DEVICE_DEBUG_FAILED":"TICKET_FAILED","install"===l.waitingFor?"package_install":t?"connection":"ticket","install"===l.waitingFor?"调试包安装失败,请检查客户端提示后重试。":t?"设备连接失败,请重新扫码。":"二维码创建失败,请稍后重试。")}this.clearQrImages(),this.patchState(e,{phase:"launching_tool",qr:void 0});let c=await this.dependencies.openDeviceApp(a.appPath,{namespace:o.namespace,projectPath:o.projectPath,appDir:o.appDir,appKey:o.appId,hostUrl:o.host});if("opened"!==c.status)throw t.throwIfAborted(),new nd("TOOL_LAUNCH_FAILED","launch","Desktop 工具启动失败,请重试。");if(n=!0,this.deviceAppOpened=!0,t.throwIfAborted(),await this.watchForDisconnect(e,o.namespace),t.throwIfAborted(),"failed"===this.state.phase)return;this.replaceOperationState(e,{phase:"connected",deadlineAt:void 0,canCancel:!1,canRetry:!1})}catch(o){if(t.aborted){await this.stopDisconnectWatcher(),n&&this.deviceAppOpened&&(await this.dependencies.closeDeviceApp().catch(()=>void 0),this.deviceAppOpened=!1),this.cancelled(e);return}let r=o instanceof nd?o:new nd("launching_tool"===this.state.phase?"TOOL_LAUNCH_FAILED":"preparing"===this.state.phase||"downloading"===this.state.phase||"installing_tool"===this.state.phase?"TOOL_PREPARE_FAILED":"REAL_DEVICE_DEBUG_FAILED","launching_tool"===this.state.phase?"launch":"preparing"===this.state.phase||"downloading"===this.state.phase||"installing_tool"===this.state.phase?"prepare":"connection","launching_tool"===this.state.phase?"Desktop 工具启动失败,请重试。":"preparing"===this.state.phase||"downloading"===this.state.phase||"installing_tool"===this.state.phase?"Desktop 工具准备失败,请重试或使用终端 device 查看详情。":"真机调试启动失败,请重试。");this.clearQrImages(),this.replaceOperationState(e,{phase:"failed",canCancel:!1,canRetry:!0,error:{code:r.code,stage:r.stage,message:r.message}})}}handlePreparationProgress(e,t){if(t){if("download"===t.phase)return void this.patchState(e,{phase:"downloading",progress:{downloadedBytes:t.downloadedBytes,...void 0===t.totalBytes?{}:{totalBytes:t.totalBytes},...void 0===t.percentage?{}:{percentage:t.percentage}}});"install"===t.phase&&this.patchState(e,{phase:"installing_tool",progress:{installStage:t.stage}})}}async getControlClient(){return this.controlClient?this.controlClient:(this.controlClientPromise||(this.controlClientPromise=this.dependencies.connectClient({projectPath:this.options.projectPath,appDir:this.options.appDir,nodeIdPrefix:"web-real-device"}).then(e=>(this.controlClient=e,e)).catch(e=>{throw this.controlClientPromise=void 0,e})),this.controlClientPromise)}async watchForDisconnect(e,t){await this.stopDisconnectWatcher();let n=this.dependencies.createDisconnectWatcher(t,async()=>{this.isCurrentState(e)&&("launching_tool"===this.state.phase||"connected"===this.state.phase)&&(this.clearQrImages(),this.replaceState({phase:"failed",canCancel:!1,canRetry:!0,error:{code:"DEVICE_DISCONNECTED",stage:"disconnect",message:"真机连接已断开,请重新扫码。"}}),this.deviceAppOpened&&(await this.dependencies.closeDeviceApp().catch(()=>void 0),this.deviceAppOpened=!1))});(await n.start(),this.isCurrent(e))?this.disconnectWatcher=n:await n.stop().catch(()=>void 0)}async stopDisconnectWatcher(){let e=this.disconnectWatcher;this.disconnectWatcher=void 0,await e?.stop().catch(()=>void 0)}cancelled(e){this.clearQrImages(),this.replaceOperationState(e,{phase:"cancelled",connectionMode:void 0,deadlineAt:void 0,canCancel:!1,canRetry:!0})}fail(e,t,n){this.replaceState({phase:"failed",canCancel:!1,canRetry:!0,error:{code:e,stage:t,message:n}})}patchState(e,t){this.isCurrent(e)&&this.replaceState(t)}replaceOperationState(e,t){this.isCurrentState(e)&&this.replaceState(t)}replaceState(e){this.state={...this.state,...e,revision:this.state.revision+1,...e.phase&&!("error"in e)&&"failed"!==e.phase&&"timed_out"!==e.phase?{error:void 0}:{},...e.phase&&"waiting_for_scan"!==e.phase?{qr:void 0}:{},...e.phase&&"downloading"!==e.phase&&"installing_tool"!==e.phase?{progress:void 0}:{}}}clearQrImages(){this.qrImages=void 0}isCurrent(e){return this.activeOperation===e&&!e.abortController.signal.aborted}isCurrentState(e){return this.state.operationId===e.id}isActive(){return ni.has(this.state.phase)}}class nd extends Error{code;stage;constructor(e,t,n){super(n),this.code=e,this.stage=t}}function nl(){return new _("dev").description("启动 dev 调试控制台(Web 模拟器、真机调试、页面和卡片推送)").option("--project-path <path>","dbx 项目路径,状态数据会写入该目录下的 .dbx",".").option("--mcp-endpoint <url>","临时覆盖 manifest.mcp_server.end_point;优先级高于环境变量和 manifest").option("--manifest <path>","manifest.yaml 路径;相对路径按 --project-path 解析,默认按项目布局自动解析").option("--skill <path>","运行态 Skill 目录;显式目录优先,相对路径按 --project-path 解析;未传默认 skill/,递归加载所有 SKILL.md").option("--verbose","输出 dev service 生命周期日志",!1).addOption(new w("--manifest-path <path>","本地调试使用的 simulator manifest 文件路径").hideHelp()).action(async(e,t)=>y(t,t=>nc(t,e)))}async function nc(e,t){let n=(0,ev.randomUUID)(),r=b(),o={devSessionId:n,actionSequence:1,startedAt:performance.now(),runtimeReady:!1,appId:void 0,eventTrackingReady:r};try{return await nu(e,t,o)}catch(e){if(!o.runtimeReady){let t=performance.now()-o.startedAt,r=v(e);await o.eventTrackingReady,await g({action:"start",actionSequence:1,appId:o.appId,devSessionId:n,durationMs:t,error:e,errorStage:"dev_startup",status:r}),await p({appId:o.appId,command:"dev",durationMs:t,error:e,errorStage:"dev_startup",outputMode:"human",status:r})}throw e}}async function nu(e,t,n){let r,o,i,s,a;e.json&&e.error("dbx dev starts an interactive console and does not support --json");let d=nf(),c=(0,ej.resolve)(t.projectPath),{businessTemplatesPath:u,simulatorManifestPath:h,skillsDirectory:f,warnings:m}=C({projectPath:c,manifest:t.manifest,skill:t.skill,manifestPath:t.manifestPath}),_=[...m];u&&await S(u);let w=h,y=!1;if(w){let e=await D(w);_.push(...e.warnings),y=e.validated,e.usable?(n.appId=r=e.appId,o=e.manifest):w=void 0}let b=await P(process.env,t.mcpEndpoint,w,o),v=R(o),E=j(o),I=L(c).frontendDirectory,A=new eD.PassThrough,T=process.stdin,$=new AbortController,N={},q=new na({projectPath:c,appDir:I,getRuntime:()=>N.promise?N.promise:Promise.reject(Error("Dev runtime is not ready"))}),M=process.env.DBX_WEB_REAL_DEVICE_DEBUG?.trim()!=="0",B=l({projectPath:c,appDir:I,installSignalHandlers:!0,signal:$.signal,verbose:t.verbose,...M?{realDeviceDebug:{provider:q.provider,dispose:()=>q.dispose()}}:{},devOptions:O({appId:r,permissions:E,mcpEndpoint:b,mcpHeaders:v,simulatorBusinessTemplatesPath:u,simulatorManifestPath:w,skillsDirectory:f,openBrowser:e=>{i=k(e)},printLogs:d?t.verbose:void 0,onLog:d&&!t.verbose?e=>{("warn"===e.level||"error"===e.level)&&A.write(`${"error"===e.level?"error:":"⚠"} ${e.message}
46
+ `)}:void 0,onProgress:d?({percentage:e})=>a?.(e):void 0})}).then(async e=>{s=e,a?.(1),n.appId=e.getState().appId??r,n.runtimeReady=!0;let t=performance.now()-n.startedAt;return await n.eventTrackingReady,await g({action:"start",actionSequence:1,appId:n.appId,devSessionId:n.devSessionId,durationMs:t,status:"success"}),await p({appId:e.getState().appId??r,command:"dev",durationMs:t,outputMode:"human",status:"success"}),e});N.promise=B;let U=x({manifestReady:y,mcpEndpointSet:!!b,warnings:_});if(!d){let t=await B;U&&e.warn(U,{style:"label"});let n=t.getState();return e.log(`Web 模拟器: ${n.webDebuggerUrl??i??"-"}`),e.log(`pid: ${n.pid??process.pid}`),e.log("stop: Ctrl+C or kill the process"),await t.stopped,nh()}U&&A.write(`⚠ ${U}
47
+ `);try{let{runInkDevShell:e}=await import("./dev-shell.js");await e({createSession:(e,t,o)=>{A.pipe(e);let a=B.then(r=>{if("running"===r.getState().status)return eK({projectPath:c,appDir:I,runtime:nm(r,c,()=>i),output:e,onDeviceAppSetupProgress:o,realDeviceDebugCoordinator:q,selectItem:t,eventTracking:n})});return Promise.resolve(np({session:a,stopped:B.then(e=>e.stopped),subscribe:e=>{let t,n=!1;return a.then(r=>{n||(t=r?.subscribe(e))}).catch(()=>void 0),()=>{n=!0,t?.()}},close:async()=>{$.abort(),await B.then(e=>e.stop()).catch(()=>void 0),await a.then(e=>e?.close()).catch(()=>void 0)},returnToRoot:async()=>{let e=await a.catch(()=>void 0);await e?.returnToRoot()},handleClientDisconnected:async()=>{let e=await a.catch(()=>void 0);await e?.handleClientDisconnected()},getState:()=>s?.getState()??{projectPath:c,appDir:I??c,appId:r,namespace:"",session_dir:"",status:"starting",created_at:0,updated_at:0}}))},subscribeCompileProgress:e=>(a=e,()=>{a===e&&(a=void 0)}),stdin:T,toChoices:tK})}finally{$.abort(),await B.then(e=>e.stop()).catch(()=>void 0),await q.dispose().catch(()=>void 0),A.destroy()}return nh()}function np(e){let t,n;return e.session.then(e=>{t=e},()=>void 0),{stopped:e.stopped,cancelActiveCommand:()=>n?.phase!=="waiting"||n.cancelled?t?.cancelActiveCommand()??!1:(n.cancelled=!0,n.resolveCancelled("continue"),!0),close:e.close,subscribe:e.subscribe,execute(r){let o,i=new Promise(e=>{o=e}),s={cancelled:!1,phase:"waiting",resolveCancelled:o};return n=s,Promise.race([e.session.then(e=>(t=e,s.cancelled)?"continue":(s.phase="running",e?.execute(r)??"continue")),i]).finally(()=>{n===s&&(n=void 0)})},returnToRoot:e.returnToRoot,handleClientDisconnected:e.handleClientDisconnected,getState:()=>t?.getState()??e.getState()}}async function nh(){await m(),process.exit(process.exitCode??0)}function nf(e=process.stdin,t=process.stderr){return!!(e.isTTY&&t.isTTY)}function nm(e,t,n){return{stopped:e.stopped,stop:()=>e.stop(),getState(){let r=e.getState();return{...r,projectPath:t,webDebuggerUrl:r.webDebuggerUrl??n()}}}}export{eU as DEV_SHELL_DEVICE_HELP_ITEMS,eB as DEV_SHELL_HELP_ITEMS,$ as dev_namespaceObject,eF as formatDeviceAppSetupStatus};