dsh-cliworker-now 0.0.0-stage → 0.7.7

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 (344) hide show
  1. package/LICENSE +21 -0
  2. package/README.en.md +364 -0
  3. package/README.md +368 -2
  4. package/cordis.patch.yml +3 -0
  5. package/lib/account-models.mjs +262 -0
  6. package/lib/client.js +22139 -0
  7. package/lib/client.js.map +1 -0
  8. package/lib/grok-catalog.mjs +145 -0
  9. package/lib/hermes-native-entry.py +96 -0
  10. package/lib/hermes-nous-refresh.py +331 -0
  11. package/lib/index.js +14544 -0
  12. package/lib/index.js.map +1 -0
  13. package/lib/native-launch.mjs +234 -0
  14. package/lib/native-spawn.mjs +32 -0
  15. package/lib/own-account-lease.mjs +105 -0
  16. package/lib/pi-installation.mjs +87 -0
  17. package/lib/pi-login.mjs +80 -0
  18. package/lib/pi-native-catalog.mjs +417 -0
  19. package/lib/pi-omp-bridge.mjs +602 -0
  20. package/lib/pi-omp-environment.mjs +15 -0
  21. package/lib/pi-omp-refresh.mjs +324 -0
  22. package/lib/private-launch.mjs +23 -0
  23. package/lib/terminal-bridge.mjs +18 -0
  24. package/lib/typert.host.d.ts +3 -0
  25. package/lib/typert.host.js +1430 -0
  26. package/lib/typert.remote-client.d.ts +72 -0
  27. package/lib/typert.remote-client.d.ts.map +1 -0
  28. package/lib/typert.remote-client.js +1256 -0
  29. package/lib/types/client/account-query-queue.d.ts +16 -0
  30. package/lib/types/client/account-query-queue.js +61 -0
  31. package/lib/types/client/account-query-queue.js.map +1 -0
  32. package/lib/types/client/account-terminal-css.d.ts +1 -0
  33. package/lib/types/client/account-terminal-css.js +3 -0
  34. package/lib/types/client/account-terminal-css.js.map +1 -0
  35. package/lib/types/client/account-terminal.d.ts +17 -0
  36. package/lib/types/client/account-terminal.js +525 -0
  37. package/lib/types/client/account-terminal.js.map +1 -0
  38. package/lib/types/client/assets/antigravity.png +0 -0
  39. package/lib/types/client/assets/claude-code.png +0 -0
  40. package/lib/types/client/assets/cliworker-now-logo.png +0 -0
  41. package/lib/types/client/assets/codex.png +0 -0
  42. package/lib/types/client/assets/grok.png +0 -0
  43. package/lib/types/client/assets/hermes.png +0 -0
  44. package/lib/types/client/assets/kimi-dark.png +0 -0
  45. package/lib/types/client/assets/kimi-light.png +0 -0
  46. package/lib/types/client/assets/mimo-code.png +0 -0
  47. package/lib/types/client/assets/omp.png +0 -0
  48. package/lib/types/client/assets/opencode.png +0 -0
  49. package/lib/types/client/assets/pi.png +0 -0
  50. package/lib/types/client/assets/zcode.png +0 -0
  51. package/lib/types/client/composer-keymap.d.ts +18 -0
  52. package/lib/types/client/composer-keymap.js +49 -0
  53. package/lib/types/client/composer-keymap.js.map +1 -0
  54. package/lib/types/client/conversation-timeline.d.ts +6 -0
  55. package/lib/types/client/conversation-timeline.js +65 -0
  56. package/lib/types/client/conversation-timeline.js.map +1 -0
  57. package/lib/types/client/copy-text.d.ts +5 -0
  58. package/lib/types/client/copy-text.js +45 -0
  59. package/lib/types/client/copy-text.js.map +1 -0
  60. package/lib/types/client/icons.d.ts +21 -0
  61. package/lib/types/client/icons.js +68 -0
  62. package/lib/types/client/icons.js.map +1 -0
  63. package/lib/types/client/index.d.ts +3 -0
  64. package/lib/types/client/index.js +124 -0
  65. package/lib/types/client/index.js.map +1 -0
  66. package/lib/types/client/management-styles.d.ts +1 -0
  67. package/lib/types/client/management-styles.js +17 -0
  68. package/lib/types/client/management-styles.js.map +1 -0
  69. package/lib/types/client/name-copy.d.ts +5 -0
  70. package/lib/types/client/name-copy.js +107 -0
  71. package/lib/types/client/name-copy.js.map +1 -0
  72. package/lib/types/client/native-job-overlay.d.ts +11 -0
  73. package/lib/types/client/native-job-overlay.js +129 -0
  74. package/lib/types/client/native-job-overlay.js.map +1 -0
  75. package/lib/types/client/operation-error.d.ts +2 -0
  76. package/lib/types/client/operation-error.js +12 -0
  77. package/lib/types/client/operation-error.js.map +1 -0
  78. package/lib/types/client/panel.d.ts +8 -0
  79. package/lib/types/client/panel.js +310 -0
  80. package/lib/types/client/panel.js.map +1 -0
  81. package/lib/types/client/rename-copy-styles.d.ts +1 -0
  82. package/lib/types/client/rename-copy-styles.js +21 -0
  83. package/lib/types/client/rename-copy-styles.js.map +1 -0
  84. package/lib/types/client/rename-worker.d.ts +9 -0
  85. package/lib/types/client/rename-worker.js +53 -0
  86. package/lib/types/client/rename-worker.js.map +1 -0
  87. package/lib/types/client/role-presets.d.ts +6 -0
  88. package/lib/types/client/role-presets.js +111 -0
  89. package/lib/types/client/role-presets.js.map +1 -0
  90. package/lib/types/client/settings-dialog.d.ts +13 -0
  91. package/lib/types/client/settings-dialog.js +442 -0
  92. package/lib/types/client/settings-dialog.js.map +1 -0
  93. package/lib/types/client/stat-popover.d.ts +10 -0
  94. package/lib/types/client/stat-popover.js +32 -0
  95. package/lib/types/client/stat-popover.js.map +1 -0
  96. package/lib/types/client/styles.d.ts +9 -0
  97. package/lib/types/client/styles.js +221 -0
  98. package/lib/types/client/styles.js.map +1 -0
  99. package/lib/types/client/telemetry.d.ts +11 -0
  100. package/lib/types/client/telemetry.js +24 -0
  101. package/lib/types/client/telemetry.js.map +1 -0
  102. package/lib/types/client/worker-card.d.ts +10 -0
  103. package/lib/types/client/worker-card.js +75 -0
  104. package/lib/types/client/worker-card.js.map +1 -0
  105. package/lib/types/client/worker-model-menu.d.ts +9 -0
  106. package/lib/types/client/worker-model-menu.js +136 -0
  107. package/lib/types/client/worker-model-menu.js.map +1 -0
  108. package/lib/types/client/workers.d.ts +21 -0
  109. package/lib/types/client/workers.js +59 -0
  110. package/lib/types/client/workers.js.map +1 -0
  111. package/lib/types/client/zcode-login-link-provider.d.ts +9 -0
  112. package/lib/types/client/zcode-login-link-provider.js +105 -0
  113. package/lib/types/client/zcode-login-link-provider.js.map +1 -0
  114. package/lib/types/client/zcode-login-link.d.ts +16 -0
  115. package/lib/types/client/zcode-login-link.js +194 -0
  116. package/lib/types/client/zcode-login-link.js.map +1 -0
  117. package/lib/types/host/account-identity.d.ts +16 -0
  118. package/lib/types/host/account-identity.js +126 -0
  119. package/lib/types/host/account-identity.js.map +1 -0
  120. package/lib/types/host/account-login.d.ts +10 -0
  121. package/lib/types/host/account-login.js +126 -0
  122. package/lib/types/host/account-login.js.map +1 -0
  123. package/lib/types/host/account-models.d.mts +21 -0
  124. package/lib/types/host/account-models.mjs +262 -0
  125. package/lib/types/host/accounts.d.ts +42 -0
  126. package/lib/types/host/accounts.js +945 -0
  127. package/lib/types/host/accounts.js.map +1 -0
  128. package/lib/types/host/adapters.d.ts +24 -0
  129. package/lib/types/host/adapters.js +380 -0
  130. package/lib/types/host/adapters.js.map +1 -0
  131. package/lib/types/host/agy-context.d.ts +8 -0
  132. package/lib/types/host/agy-context.js +122 -0
  133. package/lib/types/host/agy-context.js.map +1 -0
  134. package/lib/types/host/agy-models.d.ts +5 -0
  135. package/lib/types/host/agy-models.js +37 -0
  136. package/lib/types/host/agy-models.js.map +1 -0
  137. package/lib/types/host/agy-windows-account.d.ts +14 -0
  138. package/lib/types/host/agy-windows-account.js +104 -0
  139. package/lib/types/host/agy-windows-account.js.map +1 -0
  140. package/lib/types/host/authorized-catalog.d.ts +14 -0
  141. package/lib/types/host/authorized-catalog.js +35 -0
  142. package/lib/types/host/authorized-catalog.js.map +1 -0
  143. package/lib/types/host/bridge-protocol.d.ts +15 -0
  144. package/lib/types/host/bridge-protocol.js +80 -0
  145. package/lib/types/host/bridge-protocol.js.map +1 -0
  146. package/lib/types/host/claude-native-oauth.d.ts +17 -0
  147. package/lib/types/host/claude-native-oauth.js +272 -0
  148. package/lib/types/host/claude-native-oauth.js.map +1 -0
  149. package/lib/types/host/claude-own-route.d.ts +33 -0
  150. package/lib/types/host/claude-own-route.js +250 -0
  151. package/lib/types/host/claude-own-route.js.map +1 -0
  152. package/lib/types/host/cli-account-binding.d.ts +33 -0
  153. package/lib/types/host/cli-account-binding.js +540 -0
  154. package/lib/types/host/cli-account-binding.js.map +1 -0
  155. package/lib/types/host/cli-protocol.d.ts +27 -0
  156. package/lib/types/host/cli-protocol.js +212 -0
  157. package/lib/types/host/cli-protocol.js.map +1 -0
  158. package/lib/types/host/codex-account.d.ts +8 -0
  159. package/lib/types/host/codex-account.js +143 -0
  160. package/lib/types/host/codex-account.js.map +1 -0
  161. package/lib/types/host/codex-models.d.ts +6 -0
  162. package/lib/types/host/codex-models.js +169 -0
  163. package/lib/types/host/codex-models.js.map +1 -0
  164. package/lib/types/host/extended-adapters.d.ts +44 -0
  165. package/lib/types/host/extended-adapters.js +207 -0
  166. package/lib/types/host/extended-adapters.js.map +1 -0
  167. package/lib/types/host/first-party-account-context.d.ts +26 -0
  168. package/lib/types/host/first-party-account-context.js +55 -0
  169. package/lib/types/host/first-party-account-context.js.map +1 -0
  170. package/lib/types/host/first-party-models.d.ts +29 -0
  171. package/lib/types/host/first-party-models.js +459 -0
  172. package/lib/types/host/first-party-models.js.map +1 -0
  173. package/lib/types/host/grok-adapter.d.ts +44 -0
  174. package/lib/types/host/grok-adapter.js +293 -0
  175. package/lib/types/host/grok-adapter.js.map +1 -0
  176. package/lib/types/host/grok-models.d.ts +47 -0
  177. package/lib/types/host/grok-models.js +320 -0
  178. package/lib/types/host/grok-models.js.map +1 -0
  179. package/lib/types/host/harness-opencode-accounts.d.ts +17 -0
  180. package/lib/types/host/harness-opencode-accounts.js +80 -0
  181. package/lib/types/host/harness-opencode-accounts.js.map +1 -0
  182. package/lib/types/host/hermes-account-context.d.ts +8 -0
  183. package/lib/types/host/hermes-account-context.js +99 -0
  184. package/lib/types/host/hermes-account-context.js.map +1 -0
  185. package/lib/types/host/hermes-accounts.d.ts +19 -0
  186. package/lib/types/host/hermes-accounts.js +356 -0
  187. package/lib/types/host/hermes-accounts.js.map +1 -0
  188. package/lib/types/host/hermes-adapter.d.ts +93 -0
  189. package/lib/types/host/hermes-adapter.js +455 -0
  190. package/lib/types/host/hermes-adapter.js.map +1 -0
  191. package/lib/types/host/hermes-env.d.ts +4 -0
  192. package/lib/types/host/hermes-env.js +22 -0
  193. package/lib/types/host/hermes-env.js.map +1 -0
  194. package/lib/types/host/hermes-installation.d.ts +10 -0
  195. package/lib/types/host/hermes-installation.js +181 -0
  196. package/lib/types/host/hermes-installation.js.map +1 -0
  197. package/lib/types/host/hermes-models.d.ts +26 -0
  198. package/lib/types/host/hermes-models.js +328 -0
  199. package/lib/types/host/hermes-models.js.map +1 -0
  200. package/lib/types/host/hermes-native-entry.py +96 -0
  201. package/lib/types/host/hermes-nous-refresh.py +331 -0
  202. package/lib/types/host/hermes-nous.d.ts +53 -0
  203. package/lib/types/host/hermes-nous.js +343 -0
  204. package/lib/types/host/hermes-nous.js.map +1 -0
  205. package/lib/types/host/hermes-renewal.d.ts +27 -0
  206. package/lib/types/host/hermes-renewal.js +292 -0
  207. package/lib/types/host/hermes-renewal.js.map +1 -0
  208. package/lib/types/host/hermes-suppression.d.ts +7 -0
  209. package/lib/types/host/hermes-suppression.js +69 -0
  210. package/lib/types/host/hermes-suppression.js.map +1 -0
  211. package/lib/types/host/hermes-windows-installation.d.ts +5 -0
  212. package/lib/types/host/hermes-windows-installation.js +91 -0
  213. package/lib/types/host/hermes-windows-installation.js.map +1 -0
  214. package/lib/types/host/index.d.ts +140 -0
  215. package/lib/types/host/index.js +947 -0
  216. package/lib/types/host/index.js.map +1 -0
  217. package/lib/types/host/kimi-accounts.d.ts +17 -0
  218. package/lib/types/host/kimi-accounts.js +220 -0
  219. package/lib/types/host/kimi-accounts.js.map +1 -0
  220. package/lib/types/host/kimi-oauth-models.d.ts +14 -0
  221. package/lib/types/host/kimi-oauth-models.js +246 -0
  222. package/lib/types/host/kimi-oauth-models.js.map +1 -0
  223. package/lib/types/host/managed-agent.d.ts +4 -0
  224. package/lib/types/host/managed-agent.js +127 -0
  225. package/lib/types/host/managed-agent.js.map +1 -0
  226. package/lib/types/host/mimo-configuration.d.ts +22 -0
  227. package/lib/types/host/mimo-configuration.js +258 -0
  228. package/lib/types/host/mimo-configuration.js.map +1 -0
  229. package/lib/types/host/mimo-metadata-cache.d.ts +22 -0
  230. package/lib/types/host/mimo-metadata-cache.js +121 -0
  231. package/lib/types/host/mimo-metadata-cache.js.map +1 -0
  232. package/lib/types/host/native-capability-cache.d.ts +11 -0
  233. package/lib/types/host/native-capability-cache.js +94 -0
  234. package/lib/types/host/native-capability-cache.js.map +1 -0
  235. package/lib/types/host/native-launch.d.mts +2 -0
  236. package/lib/types/host/native-launch.mjs +234 -0
  237. package/lib/types/host/native-process.d.ts +5 -0
  238. package/lib/types/host/native-process.js +41 -0
  239. package/lib/types/host/native-process.js.map +1 -0
  240. package/lib/types/host/native-spawn.mjs +32 -0
  241. package/lib/types/host/opencode-adapter.d.ts +94 -0
  242. package/lib/types/host/opencode-adapter.js +507 -0
  243. package/lib/types/host/opencode-adapter.js.map +1 -0
  244. package/lib/types/host/opencode-native.d.ts +27 -0
  245. package/lib/types/host/opencode-native.js +403 -0
  246. package/lib/types/host/opencode-native.js.map +1 -0
  247. package/lib/types/host/own-account-lease.d.mts +5 -0
  248. package/lib/types/host/own-account-lease.mjs +105 -0
  249. package/lib/types/host/pi-installation.d.mts +7 -0
  250. package/lib/types/host/pi-installation.mjs +87 -0
  251. package/lib/types/host/pi-omp-accounts.d.ts +28 -0
  252. package/lib/types/host/pi-omp-accounts.js +175 -0
  253. package/lib/types/host/pi-omp-accounts.js.map +1 -0
  254. package/lib/types/host/pi-omp-adapter.d.ts +32 -0
  255. package/lib/types/host/pi-omp-adapter.js +190 -0
  256. package/lib/types/host/pi-omp-adapter.js.map +1 -0
  257. package/lib/types/host/pi-omp-environment.d.mts +1 -0
  258. package/lib/types/host/pi-omp-environment.mjs +15 -0
  259. package/lib/types/host/pi-omp-identity.d.ts +2 -0
  260. package/lib/types/host/pi-omp-identity.js +142 -0
  261. package/lib/types/host/pi-omp-identity.js.map +1 -0
  262. package/lib/types/host/pi-omp-logout.d.ts +3 -0
  263. package/lib/types/host/pi-omp-logout.js +152 -0
  264. package/lib/types/host/pi-omp-logout.js.map +1 -0
  265. package/lib/types/host/pi-omp-native.d.ts +71 -0
  266. package/lib/types/host/pi-omp-native.js +753 -0
  267. package/lib/types/host/pi-omp-native.js.map +1 -0
  268. package/lib/types/host/pi-omp-refresh.d.mts +7 -0
  269. package/lib/types/host/pi-omp-refresh.mjs +324 -0
  270. package/lib/types/host/private-launch.mjs +23 -0
  271. package/lib/types/host/process.d.ts +43 -0
  272. package/lib/types/host/process.js +134 -0
  273. package/lib/types/host/process.js.map +1 -0
  274. package/lib/types/host/protocol.d.ts +23 -0
  275. package/lib/types/host/protocol.js +112 -0
  276. package/lib/types/host/protocol.js.map +1 -0
  277. package/lib/types/host/roles.d.ts +34 -0
  278. package/lib/types/host/roles.js +80 -0
  279. package/lib/types/host/roles.js.map +1 -0
  280. package/lib/types/host/routing.d.ts +31 -0
  281. package/lib/types/host/routing.js +248 -0
  282. package/lib/types/host/routing.js.map +1 -0
  283. package/lib/types/host/runtime.d.ts +60 -0
  284. package/lib/types/host/runtime.js +598 -0
  285. package/lib/types/host/runtime.js.map +1 -0
  286. package/lib/types/host/storage.d.ts +48 -0
  287. package/lib/types/host/storage.js +449 -0
  288. package/lib/types/host/storage.js.map +1 -0
  289. package/lib/types/host/telemetry.d.ts +17 -0
  290. package/lib/types/host/telemetry.js +158 -0
  291. package/lib/types/host/telemetry.js.map +1 -0
  292. package/lib/types/host/windows-account-bootstrap.ps1 +44 -0
  293. package/lib/types/host/windows-account-launch.mjs +47 -0
  294. package/lib/types/host/windows-account-owner.ps1 +137 -0
  295. package/lib/types/host/windows-account-stdio.mjs +19 -0
  296. package/lib/types/host/windows-account-terminal.d.ts +17 -0
  297. package/lib/types/host/windows-account-terminal.js +208 -0
  298. package/lib/types/host/windows-account-terminal.js.map +1 -0
  299. package/lib/types/host/windows-agy-account.ps1 +81 -0
  300. package/lib/types/host/windows-cli-installation.d.ts +31 -0
  301. package/lib/types/host/windows-cli-installation.js +157 -0
  302. package/lib/types/host/windows-cli-installation.js.map +1 -0
  303. package/lib/types/host/windows-hidden-launch.mjs +49 -0
  304. package/lib/types/host/windows-hidden-process.d.ts +12 -0
  305. package/lib/types/host/windows-hidden-process.js +116 -0
  306. package/lib/types/host/windows-hidden-process.js.map +1 -0
  307. package/lib/types/host/zcode-account-models.d.ts +16 -0
  308. package/lib/types/host/zcode-account-models.js +114 -0
  309. package/lib/types/host/zcode-account-models.js.map +1 -0
  310. package/lib/types/host/zcode-adapter.d.ts +93 -0
  311. package/lib/types/host/zcode-adapter.js +808 -0
  312. package/lib/types/host/zcode-adapter.js.map +1 -0
  313. package/lib/types/host/zcode-grok-accounts.d.ts +30 -0
  314. package/lib/types/host/zcode-grok-accounts.js +408 -0
  315. package/lib/types/host/zcode-grok-accounts.js.map +1 -0
  316. package/lib/types/shared/accounts.d.ts +47 -0
  317. package/lib/types/shared/accounts.js +2 -0
  318. package/lib/types/shared/accounts.js.map +1 -0
  319. package/lib/types/shared/builtin-presets.d.ts +2 -0
  320. package/lib/types/shared/builtin-presets.js +231 -0
  321. package/lib/types/shared/builtin-presets.js.map +1 -0
  322. package/lib/types/shared/cli-settings.d.ts +5 -0
  323. package/lib/types/shared/cli-settings.js +2 -0
  324. package/lib/types/shared/cli-settings.js.map +1 -0
  325. package/lib/types/shared/model-presentation.d.ts +10 -0
  326. package/lib/types/shared/model-presentation.js +95 -0
  327. package/lib/types/shared/model-presentation.js.map +1 -0
  328. package/lib/types/shared/models.d.ts +7 -0
  329. package/lib/types/shared/models.js +35 -0
  330. package/lib/types/shared/models.js.map +1 -0
  331. package/lib/types/shared/telemetry.d.ts +18 -0
  332. package/lib/types/shared/telemetry.js +16 -0
  333. package/lib/types/shared/telemetry.js.map +1 -0
  334. package/lib/types/shared/types.d.ts +127 -0
  335. package/lib/types/shared/types.js +147 -0
  336. package/lib/types/shared/types.js.map +1 -0
  337. package/lib/windows-account-bootstrap.ps1 +44 -0
  338. package/lib/windows-account-launch.mjs +47 -0
  339. package/lib/windows-account-owner.ps1 +137 -0
  340. package/lib/windows-account-stdio.mjs +19 -0
  341. package/lib/windows-agy-account.ps1 +81 -0
  342. package/lib/windows-hidden-launch.mjs +49 -0
  343. package/lib/zcode-resume.mjs +423 -0
  344. package/package.json +109 -4
@@ -0,0 +1,417 @@
1
+ // Native metadata only. No prompts, API keys, OAuth objects, headers or raw errors leave this boundary.
2
+ import { join } from 'node:path'
3
+ import { pathToFileURL } from 'node:url'
4
+ import { spawnNativeProcess } from './native-spawn.mjs'
5
+ import { inspectPiInstallation } from './pi-installation.mjs'
6
+ import { nativeLaunchArgv } from './native-launch.mjs'
7
+
8
+ const levels = ['none', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max', 'ultra']
9
+ export function snapshotNativeCandidates(candidates, env = {}) {
10
+ const secrets = Object.entries(env)
11
+ .filter(([key, value]) => /_(?:API_KEY|TOKEN|SECRET)$/.test(key) && typeof value === 'string' && value)
12
+ .map(([, value]) => value)
13
+ const echoes = (value) =>
14
+ typeof value === 'string' &&
15
+ secrets.some((secret) => value === secret || (secret.length >= 12 && value.includes(secret)))
16
+ return candidates.flatMap((model) => {
17
+ if (
18
+ !model ||
19
+ typeof model !== 'object' ||
20
+ echoes(model.provider) ||
21
+ echoes(model.id) ||
22
+ echoes(model.baseUrl) ||
23
+ echoes(model.api)
24
+ )
25
+ return []
26
+ // Do not persist a native SDK credential/header expansion. Metadata only
27
+ // needs exact routing, effort evidence, and header names to fail closed.
28
+ return [
29
+ {
30
+ provider: model.provider,
31
+ id: model.id,
32
+ name: echoes(model.name) ? model.id : model.name,
33
+ baseUrl: model.baseUrl,
34
+ api: model.api,
35
+ ...(model.headers && typeof model.headers === 'object'
36
+ ? {
37
+ headers: Object.fromEntries(
38
+ Object.keys(model.headers).map((name) => [echoes(name) ? 'authorization' : name, true]),
39
+ ),
40
+ }
41
+ : {}),
42
+ ...(model.thinkingLevelMap && typeof model.thinkingLevelMap === 'object'
43
+ ? {
44
+ thinkingLevelMap: Object.fromEntries(
45
+ ['off', ...levels]
46
+ .filter((level) => model.thinkingLevelMap[level] != null)
47
+ .map((level) => [level, true]),
48
+ ),
49
+ }
50
+ : {}),
51
+ ...(Array.isArray(model.thinking) || Array.isArray(model.thinking?.efforts)
52
+ ? {
53
+ thinking: {
54
+ efforts: (Array.isArray(model.thinking) ? model.thinking : model.thinking.efforts).filter(
55
+ (level) => ['off', ...levels].includes(level),
56
+ ),
57
+ },
58
+ }
59
+ : {}),
60
+ },
61
+ ]
62
+ })
63
+ }
64
+ export function projectNativeModel(model, cli) {
65
+ if (
66
+ !model ||
67
+ typeof model.provider !== 'string' ||
68
+ !/^[A-Za-z0-9_.:-]+$/.test(model.provider) ||
69
+ typeof model.id !== 'string' ||
70
+ !model.id ||
71
+ /[\s\x00-\x1f]/.test(model.id)
72
+ )
73
+ throw new Error('Invalid native model identity')
74
+ const efforts =
75
+ cli === 'pi' && model.thinkingLevelMap && typeof model.thinkingLevelMap === 'object'
76
+ ? levels.filter((level) => model.thinkingLevelMap[level === 'none' ? 'off' : level] != null)
77
+ : cli === 'omp' && (Array.isArray(model.thinking) || Array.isArray(model.thinking?.efforts))
78
+ ? levels.filter((level) =>
79
+ (Array.isArray(model.thinking) ? model.thinking : model.thinking.efforts).includes(
80
+ level === 'none' ? 'off' : level,
81
+ ),
82
+ )
83
+ : []
84
+ return {
85
+ id: `${model.provider}/${model.id}`,
86
+ label: String(model.name ?? model.id),
87
+ efforts: efforts.length ? efforts : ['default'],
88
+ }
89
+ }
90
+ export async function queryNativeCatalog(...args) {
91
+ try {
92
+ const [cli, executable, directory, env = process.env, onChild = () => {}, options = {}] = args
93
+ return await accountSupportedChoices(
94
+ cli,
95
+ directory,
96
+ await queryNativeCandidates(cli, executable, directory, env, onChild, options),
97
+ env,
98
+ options,
99
+ )
100
+ } catch {
101
+ throw new Error('无法读取 Pi/OMP 原生模型目录,请检查本机配置')
102
+ }
103
+ }
104
+ export async function queryNativeCandidates(...args) {
105
+ try {
106
+ return await nativeCandidates(...args)
107
+ } catch {
108
+ throw new Error('无法读取 Pi/OMP 原生模型目录,请检查本机配置')
109
+ }
110
+ }
111
+ // The Host runs this entire phase under its one offline sandbox. Applying a
112
+ // second Seatbelt profile inside that process is rejected by macOS (exit 71).
113
+ async function nativeCandidates(
114
+ cli,
115
+ executable,
116
+ directory,
117
+ env = process.env,
118
+ onChild = () => {},
119
+ options = {},
120
+ ) {
121
+ if (cli === 'pi') {
122
+ const { dist } = inspectPiInstallation(executable)
123
+ const { ModelRuntime } = await import(pathToFileURL(join(dist, 'core/model-runtime.js')).href)
124
+ const { AuthStorage } = await import(pathToFileURL(join(dist, 'core/auth-storage.js')).href)
125
+ if (typeof ModelRuntime?.create !== 'function' || typeof AuthStorage?.inMemory !== 'function')
126
+ throw new Error('Unsupported Pi catalog SDK capabilities')
127
+ const auth = await privateJSON(join(directory, 'auth.json'))
128
+ const usable = Object.fromEntries(
129
+ Object.entries(auth).filter(
130
+ ([, entry]) =>
131
+ entry?.type !== 'oauth' ||
132
+ (typeof entry.expires === 'number' && entry.expires > Date.now() + 30000),
133
+ ),
134
+ )
135
+ const runtime = await ModelRuntime.create({
136
+ credentials: AuthStorage.inMemory(usable),
137
+ modelsPath: join(directory, 'models.json'),
138
+ modelsStorePath: join(directory, 'models-store.json'),
139
+ allowModelNetwork: false,
140
+ signal: options.signal,
141
+ })
142
+ if (runtime.getError()) throw new Error('Invalid native Pi model config')
143
+ return runtime.getAvailableSnapshot()
144
+ }
145
+ const args = ['models', '--json', '--no-extensions', '--config', join(directory, 'config.yml')]
146
+ const nativeArgs = nativeLaunchArgv([executable, ...args])
147
+ const child = spawnNativeProcess(nativeArgs[0], nativeArgs.slice(1), {
148
+ cwd: directory,
149
+ env,
150
+ stdio: ['ignore', 'pipe', 'pipe'],
151
+ })
152
+ onChild(child)
153
+ let stdout = '',
154
+ stderr = '',
155
+ size = 0,
156
+ errorSize = 0,
157
+ timedOut = false
158
+ child.stdout.on('data', (chunk) => {
159
+ size += chunk.length
160
+ if (size > 16 * 1024 * 1024) child.kill('SIGTERM')
161
+ else stdout += chunk
162
+ })
163
+ // Native diagnostics can contain endpoint credentials. Drain without forwarding.
164
+ child.stderr.on('data', (chunk) => {
165
+ errorSize += chunk.length
166
+ if (errorSize > 2 * 1024 * 1024) child.kill('SIGTERM')
167
+ else stderr += chunk
168
+ })
169
+ let force
170
+ const timer = setTimeout(() => {
171
+ timedOut = true
172
+ child.kill('SIGTERM')
173
+ force = setTimeout(() => child.kill('SIGKILL'), 5000)
174
+ }, 20000)
175
+ const outcome = await new Promise((resolve, reject) => {
176
+ child.once('error', () => reject(new Error('Unable to start native catalog')))
177
+ child.once('close', (code) => resolve(code))
178
+ }).finally(() => {
179
+ clearTimeout(timer)
180
+ clearTimeout(force)
181
+ })
182
+ if (
183
+ timedOut ||
184
+ outcome !== 0 ||
185
+ size > 16 * 1024 * 1024 ||
186
+ errorSize > 2 * 1024 * 1024 ||
187
+ /models\.yml validation failed/i.test(stderr)
188
+ )
189
+ throw new Error('Native OMP catalog query failed')
190
+ const value = JSON.parse(stdout)
191
+ const models = Array.isArray(value) ? value : value.models
192
+ if (!Array.isArray(models)) throw new Error('Invalid native OMP catalog')
193
+ return models
194
+ }
195
+
196
+ // Availability is deliberately separate from native catalog presence. A model
197
+ // is selectable only through current account scope or a declared exact API route.
198
+ async function privateJSON(path, fallback = {}) {
199
+ const { open } = await import('node:fs/promises')
200
+ const { constants } = await import('node:fs')
201
+ let handle
202
+ try {
203
+ handle = await open(path, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK)
204
+ const info = await handle.stat()
205
+ if (!info.isFile() || info.nlink !== 1 || info.size > 2 * 1024 * 1024)
206
+ throw new Error('Unsafe private metadata input')
207
+ const text = await handle.readFile('utf8')
208
+ const after = await handle.stat()
209
+ const value = JSON.parse(text)
210
+ if (
211
+ !value ||
212
+ typeof value !== 'object' ||
213
+ Array.isArray(value) ||
214
+ Buffer.byteLength(text) > 2 * 1024 * 1024 ||
215
+ info.size !== after.size ||
216
+ info.mtimeMs !== after.mtimeMs
217
+ )
218
+ throw new Error('Invalid private metadata input')
219
+ return value
220
+ } catch (error) {
221
+ if (error?.code === 'ENOENT') return fallback
222
+ throw error
223
+ } finally {
224
+ await handle?.close()
225
+ }
226
+ }
227
+ const builtinAPI = {
228
+ 'zai-coding-cn': { key: 'ZAI_CODING_CN_API_KEY', url: 'https://open.bigmodel.cn/api/coding/paas/v4' },
229
+ 'cliworker-zai-cn': { key: 'ZAI_CODING_CN_API_KEY', url: 'https://open.bigmodel.cn/api/coding/paas/v4' },
230
+ 'zhipu-coding-plan': { key: 'ZHIPU_API_KEY', url: 'https://open.bigmodel.cn/api/coding/paas/v4' },
231
+ openrouter: { key: 'OPENROUTER_API_KEY', url: 'https://openrouter.ai/api/v1' },
232
+ groq: { key: 'GROQ_API_KEY', url: 'https://api.groq.com/openai/v1' },
233
+ openai: { key: 'OPENAI_API_KEY', url: 'https://api.openai.com/v1' },
234
+ anthropic: { key: 'ANTHROPIC_API_KEY', url: 'https://api.anthropic.com/v1', api: 'anthropic-messages' },
235
+ xai: { key: 'XAI_API_KEY', url: 'https://api.x.ai/v1' },
236
+ 'xai-oauth': { url: 'https://api.x.ai/v1' },
237
+ 'openai-codex': { url: 'https://chatgpt.com/backend-api' },
238
+ }
239
+ function configuredKey(value, env) {
240
+ if (typeof value !== 'string' || !value.trim()) return undefined
241
+ if (/^[A-Z][A-Z0-9_]*$/.test(value)) return env[value]
242
+ return value.startsWith('!') ? undefined : value
243
+ }
244
+ async function privateCredentials(cli, directory) {
245
+ const credentials = new Map()
246
+ if (cli === 'pi') {
247
+ for (const [provider, value] of Object.entries(await privateJSON(join(directory, 'auth.json'))))
248
+ credentials.set(provider, [value])
249
+ } else {
250
+ const { lstat } = await import('node:fs/promises')
251
+ const path = join(directory, 'agent.db')
252
+ const info = await lstat(path)
253
+ if (!info.isFile() || info.isSymbolicLink() || info.nlink !== 1)
254
+ throw new Error('Unsafe private credential database')
255
+ const { DatabaseSync } = await import('node:sqlite')
256
+ const db = new DatabaseSync(path, { readOnly: true })
257
+ try {
258
+ for (const row of db
259
+ .prepare('SELECT provider,credential_type,data,disabled_cause FROM auth_credentials')
260
+ .all()) {
261
+ if (row.disabled_cause) continue
262
+ const list = credentials.get(row.provider) ?? []
263
+ list.push({ ...JSON.parse(row.data), type: row.credential_type })
264
+ credentials.set(row.provider, list)
265
+ }
266
+ } finally {
267
+ db.close()
268
+ }
269
+ }
270
+ return credentials
271
+ }
272
+ export async function accountSupportedChoices(cli, directory, candidates, env = process.env, options = {}) {
273
+ const { probeAccountModels } = await import('./account-models.mjs')
274
+ const custom =
275
+ (await privateJSON(join(directory, cli === 'pi' ? 'models.json' : 'models.yml'))).providers ?? {}
276
+ const credentials = await privateCredentials(cli, directory)
277
+ const groups = new Map()
278
+ for (const model of candidates) {
279
+ const provider = model.provider ?? model.id.slice(0, model.id.indexOf('/'))
280
+ const nativeId = model.provider ? model.id : model.id.slice(model.id.indexOf('/') + 1)
281
+ const config = custom[provider]
282
+ const definition = config?.models?.find((entry) => entry.id === nativeId)
283
+ const defaults = builtinAPI[provider] ?? {}
284
+ const authHeaders =
285
+ /authorization|auth[-_]|api[-_]?key|token|cookie|organization|organisation|project|account[-_]?id|tenant|workspace[-_]?id/i
286
+ // Native configured headers can replace the execution credential/scope.
287
+ // Until the metadata probe mirrors that exact identity, do not query another
288
+ // credential or publish a misleading availability/cost result for this model.
289
+ if (
290
+ [model.headers, definition?.headers, config?.headers].some(
291
+ (headers) =>
292
+ headers &&
293
+ typeof headers === 'object' &&
294
+ Object.keys(headers).some((name) => authHeaders.test(name)),
295
+ )
296
+ )
297
+ continue
298
+ // Effective SDK model routing wins; OMP's summary omits this information,
299
+ // so use the explicit model/provider configuration before pinned native defaults.
300
+ const baseUrl = model.baseUrl ?? definition?.baseUrl ?? config?.baseUrl ?? defaults.url
301
+ const apiType = model.api ?? definition?.api ?? config?.api ?? defaults.api
302
+ if (typeof baseUrl !== 'string') continue
303
+ const key = JSON.stringify([provider, baseUrl, apiType])
304
+ const group = groups.get(key) ?? { provider, baseUrl, apiType, models: [] }
305
+ group.models.push(model)
306
+ groups.set(key, group)
307
+ }
308
+ const results = await Promise.all(
309
+ [...groups.values()].map(async ({ provider, baseUrl, apiType, models }) => {
310
+ const config = custom[provider]
311
+ const defaults = builtinAPI[provider] ?? {}
312
+ const stored = credentials.get(provider) ?? []
313
+ const groupIds = new Set(
314
+ models.map((model) => (model.provider ? model.id : model.id.slice(model.id.indexOf('/') + 1))),
315
+ )
316
+ const customIds = Array.isArray(config?.models)
317
+ ? config.models.map((model) => model.id).filter((id) => groupIds.has(id))
318
+ : []
319
+ // No historic credential fingerprint is bound to this snapshot. A provider
320
+ // name or Host reference alone cannot transfer old successful-model proof.
321
+ const verifiedIds = []
322
+ if (typeof config?.apiKey === 'string' && config.apiKey.trimStart().startsWith('!')) return []
323
+ const explicitKey = configuredKey(config?.apiKey, env)
324
+ if (cli === 'omp' && config?.apiKey !== undefined && !explicitKey) return []
325
+ const defaultKey = defaults.key ? env[defaults.key] : undefined
326
+ const oauthEntries = stored.filter((entry) => entry.type === 'oauth')
327
+ const loginEntries = stored.filter(
328
+ (entry) => ['api', 'api_key'].includes(entry.type) && entry.source === 'login',
329
+ )
330
+ // Pi1.0.2 resolves stored auth before models.json/env. OMP16.4.4 has
331
+ // config override -> OAuth -> login API -> default env -> stored static API.
332
+ const entries =
333
+ cli === 'pi'
334
+ ? stored.length
335
+ ? stored
336
+ : explicitKey || defaultKey
337
+ ? [{ type: 'api', key: explicitKey ?? defaultKey }]
338
+ : []
339
+ : explicitKey
340
+ ? [{ type: 'api', key: explicitKey }]
341
+ : oauthEntries.length
342
+ ? oauthEntries
343
+ : loginEntries.length
344
+ ? loginEntries
345
+ : defaultKey
346
+ ? [{ type: 'api', key: defaultKey }]
347
+ : stored
348
+ const secrets = [
349
+ ...stored.map((entry) => entry.access ?? entry.key ?? entry.apiKey),
350
+ explicitKey,
351
+ defaultKey,
352
+ ].filter((value) => typeof value === 'string' && value)
353
+ const echoes = (value) =>
354
+ typeof value === 'string' &&
355
+ secrets.some((secret) => value === secret || (secret.length >= 12 && value.includes(secret)))
356
+ const scopes = await Promise.all(
357
+ entries.map(async (credential) => {
358
+ const type =
359
+ credential.type === 'oauth'
360
+ ? 'oauth'
361
+ : ['api', 'api_key'].includes(credential.type)
362
+ ? 'api'
363
+ : undefined
364
+ if (!type) return { state: 'unknown', models: [] }
365
+ return probeAccountModels(
366
+ {
367
+ provider,
368
+ baseUrl,
369
+ apiType,
370
+ customModelIds: customIds,
371
+ verifiedModelIds: verifiedIds,
372
+ credential:
373
+ type === 'oauth'
374
+ ? {
375
+ type,
376
+ access: credential.access,
377
+ expires: credential.expires,
378
+ accountId: credential.accountId,
379
+ }
380
+ : { type, key: credential.key ?? credential.apiKey },
381
+ },
382
+ options,
383
+ )
384
+ }),
385
+ )
386
+ // Native pools may choose any active login. A union/any-free projection can
387
+ // promise an unsupported or paid execution, so use the conservative intersection.
388
+ const supported = new Map()
389
+ if (scopes.length && scopes.every((scope) => scope.state === 'supported'))
390
+ for (const model of scopes[0].models) {
391
+ const variants = scopes.map((scope) => scope.models.find((entry) => entry.id === model.id))
392
+ if (variants.some((entry) => !entry)) continue
393
+ const cost = variants.every((entry) => entry.cost === 'free')
394
+ ? 'free'
395
+ : variants.some((entry) => entry.cost === 'unknown')
396
+ ? 'unknown'
397
+ : 'paid'
398
+ supported.set(model.id, { ...model, cost })
399
+ }
400
+ return models.flatMap((model) => {
401
+ const choice = model.provider ? projectNativeModel(model, cli) : model
402
+ const id = choice.id.slice(choice.id.indexOf('/') + 1)
403
+ const scope = supported.get(id)
404
+ if (!scope || echoes(id) || echoes(choice.id)) return []
405
+ const label = scope.name ?? (typeof model.name === 'string' ? model.name : choice.label)
406
+ return [
407
+ {
408
+ ...choice,
409
+ label: echoes(label) ? id : label,
410
+ cost: scope.cost,
411
+ },
412
+ ]
413
+ })
414
+ }),
415
+ )
416
+ return results.flat()
417
+ }