@xiaoso/dsh-tool-plus 0.1.0-beta.2 → 0.1.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +122 -0
- package/README.md +3 -2
- package/THIRD_PARTY_NOTICES.md +4 -35
- package/lib/abort-B7izMMna.mjs +51 -0
- package/lib/abort-D1_Z5Ut5.mjs +51 -0
- package/lib/abort-dIkZBV7Q.mjs +51 -0
- package/lib/amazon-bedrock-B0nxT06F.mjs +917 -0
- package/lib/amazon-bedrock-D-shAr1X.mjs +917 -0
- package/lib/amazon-bedrock-WQhvjHYu.mjs +917 -0
- package/lib/anthropic-BWsZFzU8.mjs +262 -0
- package/lib/anthropic-CJCauvYz.mjs +3115 -0
- package/lib/anthropic-CMT1Qj1t.mjs +3115 -0
- package/lib/anthropic-CZghe_9U.mjs +3115 -0
- package/lib/anthropic-sCMH7JID.mjs +262 -0
- package/lib/anthropic-tTntD8BD.mjs +262 -0
- package/lib/api-key-login-BzqNdM2y.mjs +157 -0
- package/lib/api-key-login-CWVwvHT1.mjs +157 -0
- package/lib/api-key-login-CpzSezsi.mjs +157 -0
- package/lib/aws-credentials-8Mgn5MAy.mjs +867 -0
- package/lib/aws-credentials-CXryMobh.mjs +867 -0
- package/lib/aws-credentials-ChG79ey-.mjs +867 -0
- package/lib/azure-openai-responses-CNkHiLUh.mjs +274 -0
- package/lib/azure-openai-responses-Cgmc-rbL.mjs +274 -0
- package/lib/azure-openai-responses-DuukbD0F.mjs +274 -0
- package/lib/bun-shim.mjs +252 -12
- package/lib/bundled-references-CSuBco5p.mjs +55 -0
- package/lib/bundled-references-Cavaffah.mjs +55 -0
- package/lib/bundled-references-sLN0YdXU.mjs +55 -0
- package/lib/callback-server-BEFNf-jf.mjs +398 -0
- package/lib/callback-server-CQ5Jo8F-.mjs +398 -0
- package/lib/callback-server-DDSrZ6l_.mjs +398 -0
- package/lib/client.js +111 -41
- package/lib/cursor-B3zg7EHj.mjs +273 -0
- package/lib/cursor-B6TUEmgP.mjs +135 -0
- package/lib/cursor-BIQfBC6V.mjs +135 -0
- package/lib/cursor-D8gvtTL3.mjs +135 -0
- package/lib/cursor-DNk6eXDd.mjs +5470 -0
- package/lib/cursor-DkSX2h3H.mjs +5441 -0
- package/lib/cursor-MjSm74IJ.mjs +273 -0
- package/lib/cursor-aJrXeYCb.mjs +273 -0
- package/lib/cursor-mJQwUKXK.mjs +5441 -0
- package/lib/device-code-DBo3B5nh.mjs +51 -0
- package/lib/device-code-DIb0FU-H.mjs +51 -0
- package/lib/device-code-OI_tQcmc.mjs +51 -0
- package/lib/devin-BHZZyMhO.mjs +95 -0
- package/lib/devin-BK7DHeca.mjs +114 -0
- package/lib/devin-CfMp3cXS.mjs +95 -0
- package/lib/devin-CldyPD8K.mjs +95 -0
- package/lib/devin-CzRpTUOA.mjs +114 -0
- package/lib/devin-D9zR5B_R.mjs +542 -0
- package/lib/devin-DXOeNyU7.mjs +542 -0
- package/lib/devin-Q1yem3lp.mjs +114 -0
- package/lib/devin-vNZTNUON.mjs +542 -0
- package/lib/error-B3bevhrs.mjs +1449 -0
- package/lib/error-Dd8DIqs-.mjs +1449 -0
- package/lib/error-yCSG0mGC.mjs +1449 -0
- package/lib/event-stream-BDPi64mK.mjs +151 -0
- package/lib/event-stream-BbFZJy-z.mjs +151 -0
- package/lib/event-stream-loUa0s1T.mjs +151 -0
- package/lib/fs-promises-shim-Bx0fpxuk.mjs +57 -0
- package/lib/github-copilot-4GaMtQmg.mjs +208 -0
- package/lib/github-copilot-B1yiyVRh.mjs +104 -0
- package/lib/github-copilot-B2HGSIJK.mjs +104 -0
- package/lib/github-copilot-BWT3eAOF.mjs +208 -0
- package/lib/github-copilot-CYkjeTi3.mjs +208 -0
- package/lib/github-copilot-jscUZ8Hf.mjs +104 -0
- package/lib/gitlab-duo-CM7Ref1H.mjs +155 -0
- package/lib/gitlab-duo-akICyfeD.mjs +155 -0
- package/lib/gitlab-duo-gubO4FNw.mjs +155 -0
- package/lib/gitlab-duo-workflow-BGAF6JDw.mjs +91 -0
- package/lib/gitlab-duo-workflow-CSEgYk3N.mjs +91 -0
- package/lib/gitlab-duo-workflow-D78tdn8E.mjs +91 -0
- package/lib/google-BS4T25Pn.mjs +30 -0
- package/lib/google-TFe-7-of.mjs +30 -0
- package/lib/google-antigravity-DGmwC2KV.mjs +198 -0
- package/lib/google-antigravity-DNYhgTpA.mjs +198 -0
- package/lib/google-antigravity-Dlkdhahq.mjs +198 -0
- package/lib/google-auth-B6gjsZvg.mjs +232 -0
- package/lib/google-auth-De7_s3eo.mjs +232 -0
- package/lib/google-auth-DhqpOYrX.mjs +232 -0
- package/lib/google-gemini-cli-BG_LRdIV.mjs +850 -0
- package/lib/google-gemini-cli-CWu8HvXW.mjs +211 -0
- package/lib/google-gemini-cli-Cb97bzQc.mjs +850 -0
- package/lib/google-gemini-cli-Cqds_Q5T.mjs +850 -0
- package/lib/google-gemini-cli-Dsztq0N5.mjs +211 -0
- package/lib/google-gemini-cli-zJhiOcND.mjs +211 -0
- package/lib/google-oauth-shared-CuEHaDDj.mjs +147 -0
- package/lib/google-oauth-shared-CwNWYdmR.mjs +147 -0
- package/lib/google-oauth-shared-yqlyqPPC.mjs +147 -0
- package/lib/google-shared-CgKmmdO3.mjs +760 -0
- package/lib/google-shared-Dr-VG-ap.mjs +760 -0
- package/lib/google-shared-DzhCb9b0.mjs +760 -0
- package/lib/google-vertex-BDN2tLaD.mjs +99 -0
- package/lib/google-vertex-DopVOQOG.mjs +99 -0
- package/lib/google-vertex-kscbkyRb.mjs +99 -0
- package/lib/google-zyDOG9x7.mjs +30 -0
- package/lib/identity-Da1GPU9a.mjs +219 -0
- package/lib/identity-DnB63pS7.mjs +219 -0
- package/lib/identity-xRP7_eSR.mjs +219 -0
- package/lib/idle-iterator-Baoyn3Hp.mjs +366 -0
- package/lib/idle-iterator-C6XbWcuB.mjs +366 -0
- package/lib/idle-iterator-DUjKQEGT.mjs +366 -0
- package/lib/index.mjs +4608 -3935
- package/lib/kimi--wUOWER5.mjs +236 -0
- package/lib/kimi-DMVI-zrZ.mjs +236 -0
- package/lib/kimi-Dh0pv3WZ.mjs +236 -0
- package/lib/markit-BL3cH47U.mjs +1417 -0
- package/lib/markit-BNiNY6SE.mjs +1417 -0
- package/lib/markit-M0jhziqU.mjs +1417 -0
- package/lib/minimax-code-BK-3eBbz.mjs +53 -0
- package/lib/minimax-code-DCbuA6Yk.mjs +53 -0
- package/lib/minimax-code-Uq8Qu9LW.mjs +53 -0
- package/lib/models-CfT4coYT.mjs +104660 -0
- package/lib/models-D_XnT6ay.mjs +104660 -0
- package/lib/models-SGASygJ3.mjs +104660 -0
- package/lib/ollama-BQMGPxtV.mjs +589 -0
- package/lib/ollama-DPzBmq89.mjs +589 -0
- package/lib/ollama-DoBz5SFm.mjs +589 -0
- package/lib/openai-codex-Bi-4S4PX.mjs +255 -0
- package/lib/openai-codex-CQL_kvYL.mjs +255 -0
- package/lib/openai-codex-Ch8CkT3p.mjs +255 -0
- package/lib/openai-codex-responses-CvxL_FMF.mjs +3144 -0
- package/lib/openai-codex-responses-Cz-2qpC7.mjs +3144 -0
- package/lib/openai-codex-responses-pejZgdZo.mjs +3144 -0
- package/lib/openai-completions-CF8IyNtP.mjs +1360 -0
- package/lib/openai-completions-DIf361kF.mjs +1360 -0
- package/lib/openai-completions-i8doczAk.mjs +1360 -0
- package/lib/openai-reasoning-fallback-DGVVLgd1.mjs +286 -0
- package/lib/openai-reasoning-fallback-Nj6yB2rY.mjs +286 -0
- package/lib/openai-reasoning-fallback-OdJREP1o.mjs +286 -0
- package/lib/openai-responses-BqXJInHX.mjs +867 -0
- package/lib/openai-responses-DTkBiiy-.mjs +867 -0
- package/lib/openai-responses-Db_a-U4-.mjs +867 -0
- package/lib/opencode-DaJjcUbf.mjs +38 -0
- package/lib/opencode-DhMolSoB.mjs +38 -0
- package/lib/opencode-Rq_Q2vAO.mjs +38 -0
- package/lib/perplexity-9b-RQ0mV.mjs +194 -0
- package/lib/perplexity-C4iLVMUj.mjs +194 -0
- package/lib/perplexity-Uu7Jzg5b.mjs +194 -0
- package/lib/proxy-DDqrmjjC.mjs +190 -0
- package/lib/proxy-ZtUcl6r5.mjs +190 -0
- package/lib/proxy-pM_NIv-H.mjs +190 -0
- package/lib/request-debug-HJMoJncL.mjs +183 -0
- package/lib/sanitize-text-CfcXzw5X.mjs +33 -0
- package/lib/scrapers-BkFfcPHj.mjs +9198 -0
- package/lib/scrapers-CL-WgdU1.mjs +9198 -0
- package/lib/scrapers-CVptboMs.mjs +9198 -0
- package/lib/scrapers-CipyKyCH.mjs +9198 -0
- package/lib/scrapers-DGfrYhtw.mjs +9198 -0
- package/lib/scrapers-DSUPYoUF.mjs +9198 -0
- package/lib/scrapers-DZ2GXmp7.mjs +9198 -0
- package/lib/scrapers-nhQAvc8d.mjs +9198 -0
- package/lib/shell-snapshot-fn-env.sh +67 -43
- package/lib/src-BgpusnsB.mjs +5076 -0
- package/lib/src-DTid0g4K.mjs +5001 -0
- package/lib/src-lDmkSRbm.mjs +5006 -0
- package/lib/stream-BlldLkVq.mjs +10236 -0
- package/lib/stream-CRtexYLe.mjs +10236 -0
- package/lib/stream-C_RAoxJC.mjs +10236 -0
- package/lib/stream-markup-healing-2toHXWXM.mjs +491 -0
- package/lib/stream-markup-healing-DMsxBx1L.mjs +491 -0
- package/lib/stream-markup-healing-KMkiAA00.mjs +491 -0
- package/lib/turndown-DN7ByzEI.mjs +667 -0
- package/lib/types/client/locales.d.ts +1 -1
- package/lib/types/config/fields.d.ts +1 -1
- package/lib/types/config/settings.d.ts +25 -3
- package/lib/types/config/truncate.d.ts +9 -5
- package/lib/types/tools/bash/background.d.ts +1 -1
- package/lib/types/tools/bash/bash-executor.d.ts +4 -0
- package/lib/types/tools/bash/bash-interceptor.d.ts +10 -8
- package/lib/types/tools/bash/cd-workdir.d.ts +35 -0
- package/lib/types/tools/bash/non-interactive-env.d.ts +2 -0
- package/lib/types/tools/bash/render.d.ts +4 -3
- package/lib/types/tools/bash/sanitize-text.d.ts +5 -0
- package/lib/types/tools/bash/shell-snapshot.d.ts +4 -1
- package/lib/types/tools/bash/shell-tokenize.d.ts +60 -0
- package/lib/types/tools/bash/streaming-output.d.ts +12 -212
- package/lib/types/tools/bash/which.d.ts +20 -0
- package/lib/types/tools/bash/windows-shell.d.ts +31 -0
- package/lib/types/tools/edit/adapter/index.d.ts +25 -3
- package/lib/types/tools/edit/adapter/tools/auto-generated-guard.d.ts +7 -17
- package/lib/types/tools/glob/adapter/index.d.ts +27 -1
- package/lib/types/tools/grep/adapter/index.d.ts +29 -1
- package/lib/types/tools/omp/edit/dispatch.d.ts +43 -0
- package/lib/types/tools/omp/edit/hashline/noop-loop-guard.d.ts +3 -1
- package/lib/types/tools/omp/sdk.d.ts +6 -0
- package/lib/types/tools/omp/tools/auto-generated-guard.d.ts +20 -0
- package/lib/types/tools/omp/tools/fetch.d.ts +2 -0
- package/lib/types/tools/omp/tools/read.d.ts +2 -8
- package/lib/types/tools/omp/tools/write.d.ts +4 -4
- package/lib/types/tools/omp/utils/image-loading.d.ts +10 -36
- package/lib/types/tools/read/adapter/index.d.ts +4 -1
- package/lib/types/tools/read-image/index.d.ts +4 -0
- package/lib/types/tools/shared/auto-generated-guard.dsh.d.ts +16 -4
- package/lib/types/tools/shared/bun-shim.d.ts +39 -3
- package/lib/types/tools/shared/fs-promises-shim.d.ts +3 -1
- package/lib/types/tools/shared/image-bridge.d.ts +98 -0
- package/lib/types/tools/shared/omp-prompt.d.ts +17 -9
- package/lib/types/tools/shared/session-state.d.ts +9 -3
- package/lib/utils-2Wq2eATG.mjs +8119 -0
- package/lib/utils-BnX8O3vi.mjs +12303 -0
- package/lib/utils-Bw139LTz.mjs +8119 -0
- package/lib/utils-CE8N8P4Q.mjs +12315 -0
- package/lib/utils-CZw4tVZQ.mjs +12315 -0
- package/lib/utils-C_MrQ_0z.mjs +12301 -0
- package/lib/utils-CiGN7OHR.mjs +12315 -0
- package/lib/utils-Cp76gCyk.mjs +8119 -0
- package/lib/utils-D0GRDgAr.mjs +12315 -0
- package/lib/utils-D0Z1fyoO.mjs +12299 -0
- package/lib/utils-D2YknRk4.mjs +51 -0
- package/lib/utils-DppGHXQB.mjs +51 -0
- package/lib/utils-DzXZDfYc.mjs +51 -0
- package/lib/utils-W8WdSBpX.mjs +12315 -0
- package/lib/vision-guard-01qSwFpf.mjs +92 -0
- package/lib/vision-guard-BDD4OrKo.mjs +92 -0
- package/lib/vision-guard-DzZGaOga.mjs +92 -0
- package/lib/wafer-CgtPHerf.mjs +17 -0
- package/lib/wafer-DRU0EjZX.mjs +17 -0
- package/lib/wafer-cBtrn6q9.mjs +17 -0
- package/lib/xai-oauth-Buk8XVvM.mjs +446 -0
- package/lib/xai-oauth-CMal8l1O.mjs +446 -0
- package/lib/xai-oauth-DPHDXKD7.mjs +446 -0
- package/lib/xiaomi-CZgwvX2G.mjs +157 -0
- package/lib/xiaomi-D2qT5cAC.mjs +157 -0
- package/lib/xiaomi-Dd87KSg5.mjs +157 -0
- package/lib/zai-7DWMkEqM.mjs +203 -0
- package/lib/zai-C59YnomG.mjs +203 -0
- package/lib/zai-CFeOt-53.mjs +203 -0
- package/lib/zip-Cg9ANN_U.mjs +1316 -0
- package/lib/zip-D36ZKsP8.mjs +1316 -0
- package/lib/zip-D6QXpvaJ.mjs +1316 -0
- package/package.json +14 -10
- package/presets/package.json +1 -1
- package/presets/tool-plus-ptc/preset.yml +1 -1
- package/presets/tool-plus-standard/preset.yml +1 -1
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { installBunShim as __installBunShim } from "./bun-shim.mjs";
|
|
2
|
+
__installBunShim();
|
|
3
|
+
import { _ as OnPromptRequiredError, h as LoginCancelledError, m as ApiKeyRequiredError } from "./error-B3bevhrs.mjs";
|
|
4
|
+
//#region node_modules/.pnpm/@oh-my-pi+pi-ai@17.3.5/node_modules/@oh-my-pi/pi-ai/src/registry/oauth/opencode.ts
|
|
5
|
+
/**
|
|
6
|
+
* OpenCode Zen login flow.
|
|
7
|
+
*
|
|
8
|
+
* OpenCode Zen is a subscription service that provides access to various AI models
|
|
9
|
+
* (GPT-5.x, Claude 4.x, Gemini 3, etc.) through a unified API at opencode.ai/zen.
|
|
10
|
+
* This is not OAuth - it's a simple API key flow:
|
|
11
|
+
* 1. Open browser to https://opencode.ai/auth
|
|
12
|
+
* 2. User logs in and copies their API key
|
|
13
|
+
* 3. User pastes the API key back into the CLI
|
|
14
|
+
*/
|
|
15
|
+
const AUTH_URL = "https://opencode.ai/auth";
|
|
16
|
+
/**
|
|
17
|
+
* Login to OpenCode Zen.
|
|
18
|
+
*
|
|
19
|
+
* Opens browser to auth page, prompts user to paste their API key.
|
|
20
|
+
* Returns the API key directly (not OAuthCredentials - this isn't OAuth).
|
|
21
|
+
*/
|
|
22
|
+
async function loginOpenCode(options) {
|
|
23
|
+
if (!options.onPrompt) throw new OnPromptRequiredError("OpenCode Zen");
|
|
24
|
+
options.onAuth?.({
|
|
25
|
+
url: AUTH_URL,
|
|
26
|
+
instructions: "Log in and copy your API key"
|
|
27
|
+
});
|
|
28
|
+
const apiKey = await options.onPrompt({
|
|
29
|
+
message: "Paste your OpenCode Zen API key",
|
|
30
|
+
placeholder: "sk-..."
|
|
31
|
+
});
|
|
32
|
+
if (options.signal?.aborted) throw new LoginCancelledError();
|
|
33
|
+
const trimmed = apiKey.trim();
|
|
34
|
+
if (!trimmed) throw new ApiKeyRequiredError();
|
|
35
|
+
return trimmed;
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
38
|
+
export { loginOpenCode };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { installBunShim as __installBunShim } from "./bun-shim.mjs";
|
|
2
|
+
__installBunShim();
|
|
3
|
+
import { _ as OnPromptRequiredError, h as LoginCancelledError, m as ApiKeyRequiredError } from "./error-yCSG0mGC.mjs";
|
|
4
|
+
//#region node_modules/.pnpm/@oh-my-pi+pi-ai@17.3.5/node_modules/@oh-my-pi/pi-ai/src/registry/oauth/opencode.ts
|
|
5
|
+
/**
|
|
6
|
+
* OpenCode Zen login flow.
|
|
7
|
+
*
|
|
8
|
+
* OpenCode Zen is a subscription service that provides access to various AI models
|
|
9
|
+
* (GPT-5.x, Claude 4.x, Gemini 3, etc.) through a unified API at opencode.ai/zen.
|
|
10
|
+
* This is not OAuth - it's a simple API key flow:
|
|
11
|
+
* 1. Open browser to https://opencode.ai/auth
|
|
12
|
+
* 2. User logs in and copies their API key
|
|
13
|
+
* 3. User pastes the API key back into the CLI
|
|
14
|
+
*/
|
|
15
|
+
const AUTH_URL = "https://opencode.ai/auth";
|
|
16
|
+
/**
|
|
17
|
+
* Login to OpenCode Zen.
|
|
18
|
+
*
|
|
19
|
+
* Opens browser to auth page, prompts user to paste their API key.
|
|
20
|
+
* Returns the API key directly (not OAuthCredentials - this isn't OAuth).
|
|
21
|
+
*/
|
|
22
|
+
async function loginOpenCode(options) {
|
|
23
|
+
if (!options.onPrompt) throw new OnPromptRequiredError("OpenCode Zen");
|
|
24
|
+
options.onAuth?.({
|
|
25
|
+
url: AUTH_URL,
|
|
26
|
+
instructions: "Log in and copy your API key"
|
|
27
|
+
});
|
|
28
|
+
const apiKey = await options.onPrompt({
|
|
29
|
+
message: "Paste your OpenCode Zen API key",
|
|
30
|
+
placeholder: "sk-..."
|
|
31
|
+
});
|
|
32
|
+
if (options.signal?.aborted) throw new LoginCancelledError();
|
|
33
|
+
const trimmed = apiKey.trim();
|
|
34
|
+
if (!trimmed) throw new ApiKeyRequiredError();
|
|
35
|
+
return trimmed;
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
38
|
+
export { loginOpenCode };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { installBunShim as __installBunShim } from "./bun-shim.mjs";
|
|
2
|
+
__installBunShim();
|
|
3
|
+
import { _ as OnPromptRequiredError, h as LoginCancelledError, m as ApiKeyRequiredError } from "./error-Dd8DIqs-.mjs";
|
|
4
|
+
//#region node_modules/.pnpm/@oh-my-pi+pi-ai@17.3.5/node_modules/@oh-my-pi/pi-ai/src/registry/oauth/opencode.ts
|
|
5
|
+
/**
|
|
6
|
+
* OpenCode Zen login flow.
|
|
7
|
+
*
|
|
8
|
+
* OpenCode Zen is a subscription service that provides access to various AI models
|
|
9
|
+
* (GPT-5.x, Claude 4.x, Gemini 3, etc.) through a unified API at opencode.ai/zen.
|
|
10
|
+
* This is not OAuth - it's a simple API key flow:
|
|
11
|
+
* 1. Open browser to https://opencode.ai/auth
|
|
12
|
+
* 2. User logs in and copies their API key
|
|
13
|
+
* 3. User pastes the API key back into the CLI
|
|
14
|
+
*/
|
|
15
|
+
const AUTH_URL = "https://opencode.ai/auth";
|
|
16
|
+
/**
|
|
17
|
+
* Login to OpenCode Zen.
|
|
18
|
+
*
|
|
19
|
+
* Opens browser to auth page, prompts user to paste their API key.
|
|
20
|
+
* Returns the API key directly (not OAuthCredentials - this isn't OAuth).
|
|
21
|
+
*/
|
|
22
|
+
async function loginOpenCode(options) {
|
|
23
|
+
if (!options.onPrompt) throw new OnPromptRequiredError("OpenCode Zen");
|
|
24
|
+
options.onAuth?.({
|
|
25
|
+
url: AUTH_URL,
|
|
26
|
+
instructions: "Log in and copy your API key"
|
|
27
|
+
});
|
|
28
|
+
const apiKey = await options.onPrompt({
|
|
29
|
+
message: "Paste your OpenCode Zen API key",
|
|
30
|
+
placeholder: "sk-..."
|
|
31
|
+
});
|
|
32
|
+
if (options.signal?.aborted) throw new LoginCancelledError();
|
|
33
|
+
const trimmed = apiKey.trim();
|
|
34
|
+
if (!trimmed) throw new ApiKeyRequiredError();
|
|
35
|
+
return trimmed;
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
38
|
+
export { loginOpenCode };
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { installBunShim as __installBunShim } from "./bun-shim.mjs";
|
|
2
|
+
__installBunShim();
|
|
3
|
+
import { D as Cookie, E as $, O as CookieMap, P as $env } from "./src-DTid0g4K.mjs";
|
|
4
|
+
import { V as ProviderHttpError, _ as OnPromptRequiredError, c as OAuthError, h as LoginCancelledError } from "./error-B3bevhrs.mjs";
|
|
5
|
+
import * as os from "node:os";
|
|
6
|
+
//#region node_modules/.pnpm/@oh-my-pi+pi-ai@17.3.5/node_modules/@oh-my-pi/pi-ai/src/registry/oauth/perplexity.ts
|
|
7
|
+
/**
|
|
8
|
+
* Perplexity login and token refresh.
|
|
9
|
+
*
|
|
10
|
+
* Login paths (in priority order):
|
|
11
|
+
* 1. macOS native app: reads JWT from NSUserDefaults (`defaults read ai.perplexity.mac authToken`)
|
|
12
|
+
* 2. HTTP email OTP: `GET /api/auth/csrf` → `POST /api/auth/signin-email` → `POST /api/auth/signin-otp`
|
|
13
|
+
*
|
|
14
|
+
* No browser or manual cookie paste required.
|
|
15
|
+
* Refresh: Socket.IO `refreshJWT` RPC over authenticated WebSocket connection.
|
|
16
|
+
*
|
|
17
|
+
* Protocol: Engine.IO v4 + Socket.IO v4 over WebSocket (bypasses Cloudflare managed challenge).
|
|
18
|
+
* Architecture reverse-engineered from Perplexity macOS app (ai.perplexity.mac).
|
|
19
|
+
*/
|
|
20
|
+
const API_VERSION = "2.18";
|
|
21
|
+
const NATIVE_APP_BUNDLE = "ai.perplexity.mac";
|
|
22
|
+
const APP_USER_AGENT = "Perplexity/641 CFNetwork/1568 Darwin/25.2.0";
|
|
23
|
+
function serializeCookies(cookies) {
|
|
24
|
+
let header = "";
|
|
25
|
+
for (const [name, value] of cookies) header += `${header ? "; " : ""}${name}=${value}`;
|
|
26
|
+
return header;
|
|
27
|
+
}
|
|
28
|
+
function rememberCookies(cookies, response) {
|
|
29
|
+
for (const setCookie of response.headers.getSetCookie()) {
|
|
30
|
+
const cookie = Cookie.parse(setCookie);
|
|
31
|
+
if (cookie.isExpired()) cookies.delete(cookie.name);
|
|
32
|
+
else cookies.set(cookie.name, cookie.value);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Extract expiry from a JWT. Perplexity tokens generally lack an `exp` claim
|
|
37
|
+
* (their sessions are server-side and effectively non-expiring from the client's
|
|
38
|
+
* point of view), so we return a far-future sentinel when no `exp` is present.
|
|
39
|
+
* When `exp` IS present, subtract a 5-minute safety margin.
|
|
40
|
+
*/
|
|
41
|
+
const NEVER_EXPIRES = 864e13;
|
|
42
|
+
function getJwtExpiry(token) {
|
|
43
|
+
try {
|
|
44
|
+
const parts = token.split(".");
|
|
45
|
+
if (parts.length !== 3) return NEVER_EXPIRES;
|
|
46
|
+
const payload = parts[1] ?? "";
|
|
47
|
+
const decoded = JSON.parse(atob(payload.replace(/-/g, "+").replace(/_/g, "/")));
|
|
48
|
+
if (typeof decoded?.exp === "number" && Number.isFinite(decoded.exp)) return decoded.exp * 1e3 - 3e5;
|
|
49
|
+
} catch {}
|
|
50
|
+
return NEVER_EXPIRES;
|
|
51
|
+
}
|
|
52
|
+
/** Build OAuthCredentials from a Perplexity JWT string. */
|
|
53
|
+
function jwtToCredentials(jwt, email) {
|
|
54
|
+
return {
|
|
55
|
+
access: jwt,
|
|
56
|
+
refresh: jwt,
|
|
57
|
+
expires: getJwtExpiry(jwt),
|
|
58
|
+
email
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Read the Perplexity JWT from the native macOS Catalyst app's UserDefaults.
|
|
63
|
+
* Tokens are stored in NSUserDefaults (not Keychain), readable by any same-UID process.
|
|
64
|
+
*/
|
|
65
|
+
async function extractFromNativeApp() {
|
|
66
|
+
if (os.platform() !== "darwin") return null;
|
|
67
|
+
try {
|
|
68
|
+
const result = await $`defaults read ${NATIVE_APP_BUNDLE} authToken`.quiet().nothrow();
|
|
69
|
+
if (result.exitCode !== 0) return null;
|
|
70
|
+
const token = result.text().trim();
|
|
71
|
+
if (!token || token === "(null)") return null;
|
|
72
|
+
return token;
|
|
73
|
+
} catch {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Send email OTP and exchange it for a Perplexity JWT via HTTP endpoints.
|
|
79
|
+
*/
|
|
80
|
+
async function httpEmailLogin(ctrl) {
|
|
81
|
+
if (!ctrl.onPrompt) throw new OnPromptRequiredError("Perplexity");
|
|
82
|
+
const trimmedEmail = (await ctrl.onPrompt({
|
|
83
|
+
message: "Enter your Perplexity email address",
|
|
84
|
+
placeholder: "user@example.com"
|
|
85
|
+
})).trim();
|
|
86
|
+
if (!trimmedEmail) throw new OAuthError("Email is required for Perplexity login", {
|
|
87
|
+
kind: "validation",
|
|
88
|
+
provider: "perplexity"
|
|
89
|
+
});
|
|
90
|
+
if (ctrl.signal?.aborted) throw new LoginCancelledError();
|
|
91
|
+
const fetchImpl = ctrl.fetch ?? fetch;
|
|
92
|
+
const cookies = new CookieMap();
|
|
93
|
+
const request = async (url, init = {}) => {
|
|
94
|
+
const headers = new Headers(init.headers);
|
|
95
|
+
if (cookies.size > 0) headers.set("Cookie", serializeCookies(cookies));
|
|
96
|
+
const response = await fetchImpl(url, {
|
|
97
|
+
...init,
|
|
98
|
+
headers
|
|
99
|
+
});
|
|
100
|
+
rememberCookies(cookies, response);
|
|
101
|
+
return response;
|
|
102
|
+
};
|
|
103
|
+
ctrl.onProgress?.("Fetching Perplexity CSRF token...");
|
|
104
|
+
const csrfResponse = await request("https://www.perplexity.ai/api/auth/csrf", {
|
|
105
|
+
headers: {
|
|
106
|
+
"User-Agent": APP_USER_AGENT,
|
|
107
|
+
"X-App-ApiVersion": API_VERSION
|
|
108
|
+
},
|
|
109
|
+
signal: ctrl.signal
|
|
110
|
+
});
|
|
111
|
+
if (!csrfResponse.ok) throw new ProviderHttpError(`Perplexity CSRF request failed: ${csrfResponse.status}`, csrfResponse.status);
|
|
112
|
+
const csrfData = await csrfResponse.json();
|
|
113
|
+
if (!csrfData.csrfToken) throw new OAuthError("Perplexity CSRF response missing csrfToken", {
|
|
114
|
+
kind: "validation",
|
|
115
|
+
provider: "perplexity"
|
|
116
|
+
});
|
|
117
|
+
ctrl.onProgress?.("Sending login code to your email...");
|
|
118
|
+
const sendResponse = await request("https://www.perplexity.ai/api/auth/signin-email", {
|
|
119
|
+
method: "POST",
|
|
120
|
+
headers: {
|
|
121
|
+
"Content-Type": "application/json",
|
|
122
|
+
"User-Agent": APP_USER_AGENT,
|
|
123
|
+
"X-App-ApiVersion": API_VERSION
|
|
124
|
+
},
|
|
125
|
+
body: JSON.stringify({
|
|
126
|
+
email: trimmedEmail,
|
|
127
|
+
csrfToken: csrfData.csrfToken
|
|
128
|
+
}),
|
|
129
|
+
signal: ctrl.signal
|
|
130
|
+
});
|
|
131
|
+
if (!sendResponse.ok) {
|
|
132
|
+
const body = await sendResponse.text();
|
|
133
|
+
throw new ProviderHttpError(`Perplexity send login code failed (${sendResponse.status}): ${body}`, sendResponse.status);
|
|
134
|
+
}
|
|
135
|
+
const trimmedOtp = (await ctrl.onPrompt({
|
|
136
|
+
message: "Enter the code sent to your email",
|
|
137
|
+
placeholder: "123456"
|
|
138
|
+
})).trim();
|
|
139
|
+
if (!trimmedOtp) throw new OAuthError("OTP code is required", {
|
|
140
|
+
kind: "validation",
|
|
141
|
+
provider: "perplexity"
|
|
142
|
+
});
|
|
143
|
+
if (ctrl.signal?.aborted) throw new LoginCancelledError();
|
|
144
|
+
ctrl.onProgress?.("Verifying login code...");
|
|
145
|
+
const verifyResponse = await request("https://www.perplexity.ai/api/auth/signin-otp", {
|
|
146
|
+
method: "POST",
|
|
147
|
+
headers: {
|
|
148
|
+
"Content-Type": "application/json",
|
|
149
|
+
"User-Agent": APP_USER_AGENT,
|
|
150
|
+
"X-App-ApiVersion": API_VERSION
|
|
151
|
+
},
|
|
152
|
+
body: JSON.stringify({
|
|
153
|
+
email: trimmedEmail,
|
|
154
|
+
otp: trimmedOtp,
|
|
155
|
+
csrfToken: csrfData.csrfToken
|
|
156
|
+
}),
|
|
157
|
+
signal: ctrl.signal
|
|
158
|
+
});
|
|
159
|
+
const verifyData = await verifyResponse.json();
|
|
160
|
+
if (!verifyResponse.ok) {
|
|
161
|
+
const reason = verifyData.text ?? verifyData.error_code ?? verifyData.status ?? "OTP verification failed";
|
|
162
|
+
throw new OAuthError(`Perplexity OTP verification failed: ${reason}`, {
|
|
163
|
+
kind: "validation",
|
|
164
|
+
provider: "perplexity",
|
|
165
|
+
status: verifyResponse.status
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
if (!verifyData.token) throw new OAuthError("Perplexity OTP verification response missing token", {
|
|
169
|
+
kind: "validation",
|
|
170
|
+
provider: "perplexity"
|
|
171
|
+
});
|
|
172
|
+
return jwtToCredentials(verifyData.token, trimmedEmail);
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Login to Perplexity.
|
|
176
|
+
*
|
|
177
|
+
* Tries auto-extraction from the desktop app, then runs HTTP email OTP login.
|
|
178
|
+
*
|
|
179
|
+
* No browser/manual token paste fallback is used.
|
|
180
|
+
*/
|
|
181
|
+
async function loginPerplexity(ctrl) {
|
|
182
|
+
if (!ctrl.onPrompt) throw new OnPromptRequiredError("Perplexity");
|
|
183
|
+
if (!$env.PI_AUTH_NO_BORROW) {
|
|
184
|
+
ctrl.onProgress?.("Checking for Perplexity desktop app...");
|
|
185
|
+
const nativeJwt = await extractFromNativeApp();
|
|
186
|
+
if (nativeJwt) {
|
|
187
|
+
ctrl.onProgress?.("Found Perplexity JWT from native app");
|
|
188
|
+
return jwtToCredentials(nativeJwt);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return httpEmailLogin(ctrl);
|
|
192
|
+
}
|
|
193
|
+
//#endregion
|
|
194
|
+
export { loginPerplexity };
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { installBunShim as __installBunShim } from "./bun-shim.mjs";
|
|
2
|
+
__installBunShim();
|
|
3
|
+
import { D as Cookie, E as $, O as CookieMap, P as $env } from "./src-BgpusnsB.mjs";
|
|
4
|
+
import { V as ProviderHttpError, _ as OnPromptRequiredError, c as OAuthError, h as LoginCancelledError } from "./error-Dd8DIqs-.mjs";
|
|
5
|
+
import * as os from "node:os";
|
|
6
|
+
//#region node_modules/.pnpm/@oh-my-pi+pi-ai@17.3.5/node_modules/@oh-my-pi/pi-ai/src/registry/oauth/perplexity.ts
|
|
7
|
+
/**
|
|
8
|
+
* Perplexity login and token refresh.
|
|
9
|
+
*
|
|
10
|
+
* Login paths (in priority order):
|
|
11
|
+
* 1. macOS native app: reads JWT from NSUserDefaults (`defaults read ai.perplexity.mac authToken`)
|
|
12
|
+
* 2. HTTP email OTP: `GET /api/auth/csrf` → `POST /api/auth/signin-email` → `POST /api/auth/signin-otp`
|
|
13
|
+
*
|
|
14
|
+
* No browser or manual cookie paste required.
|
|
15
|
+
* Refresh: Socket.IO `refreshJWT` RPC over authenticated WebSocket connection.
|
|
16
|
+
*
|
|
17
|
+
* Protocol: Engine.IO v4 + Socket.IO v4 over WebSocket (bypasses Cloudflare managed challenge).
|
|
18
|
+
* Architecture reverse-engineered from Perplexity macOS app (ai.perplexity.mac).
|
|
19
|
+
*/
|
|
20
|
+
const API_VERSION = "2.18";
|
|
21
|
+
const NATIVE_APP_BUNDLE = "ai.perplexity.mac";
|
|
22
|
+
const APP_USER_AGENT = "Perplexity/641 CFNetwork/1568 Darwin/25.2.0";
|
|
23
|
+
function serializeCookies(cookies) {
|
|
24
|
+
let header = "";
|
|
25
|
+
for (const [name, value] of cookies) header += `${header ? "; " : ""}${name}=${value}`;
|
|
26
|
+
return header;
|
|
27
|
+
}
|
|
28
|
+
function rememberCookies(cookies, response) {
|
|
29
|
+
for (const setCookie of response.headers.getSetCookie()) {
|
|
30
|
+
const cookie = Cookie.parse(setCookie);
|
|
31
|
+
if (cookie.isExpired()) cookies.delete(cookie.name);
|
|
32
|
+
else cookies.set(cookie.name, cookie.value);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Extract expiry from a JWT. Perplexity tokens generally lack an `exp` claim
|
|
37
|
+
* (their sessions are server-side and effectively non-expiring from the client's
|
|
38
|
+
* point of view), so we return a far-future sentinel when no `exp` is present.
|
|
39
|
+
* When `exp` IS present, subtract a 5-minute safety margin.
|
|
40
|
+
*/
|
|
41
|
+
const NEVER_EXPIRES = 864e13;
|
|
42
|
+
function getJwtExpiry(token) {
|
|
43
|
+
try {
|
|
44
|
+
const parts = token.split(".");
|
|
45
|
+
if (parts.length !== 3) return NEVER_EXPIRES;
|
|
46
|
+
const payload = parts[1] ?? "";
|
|
47
|
+
const decoded = JSON.parse(atob(payload.replace(/-/g, "+").replace(/_/g, "/")));
|
|
48
|
+
if (typeof decoded?.exp === "number" && Number.isFinite(decoded.exp)) return decoded.exp * 1e3 - 3e5;
|
|
49
|
+
} catch {}
|
|
50
|
+
return NEVER_EXPIRES;
|
|
51
|
+
}
|
|
52
|
+
/** Build OAuthCredentials from a Perplexity JWT string. */
|
|
53
|
+
function jwtToCredentials(jwt, email) {
|
|
54
|
+
return {
|
|
55
|
+
access: jwt,
|
|
56
|
+
refresh: jwt,
|
|
57
|
+
expires: getJwtExpiry(jwt),
|
|
58
|
+
email
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Read the Perplexity JWT from the native macOS Catalyst app's UserDefaults.
|
|
63
|
+
* Tokens are stored in NSUserDefaults (not Keychain), readable by any same-UID process.
|
|
64
|
+
*/
|
|
65
|
+
async function extractFromNativeApp() {
|
|
66
|
+
if (os.platform() !== "darwin") return null;
|
|
67
|
+
try {
|
|
68
|
+
const result = await $`defaults read ${NATIVE_APP_BUNDLE} authToken`.quiet().nothrow();
|
|
69
|
+
if (result.exitCode !== 0) return null;
|
|
70
|
+
const token = result.text().trim();
|
|
71
|
+
if (!token || token === "(null)") return null;
|
|
72
|
+
return token;
|
|
73
|
+
} catch {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Send email OTP and exchange it for a Perplexity JWT via HTTP endpoints.
|
|
79
|
+
*/
|
|
80
|
+
async function httpEmailLogin(ctrl) {
|
|
81
|
+
if (!ctrl.onPrompt) throw new OnPromptRequiredError("Perplexity");
|
|
82
|
+
const trimmedEmail = (await ctrl.onPrompt({
|
|
83
|
+
message: "Enter your Perplexity email address",
|
|
84
|
+
placeholder: "user@example.com"
|
|
85
|
+
})).trim();
|
|
86
|
+
if (!trimmedEmail) throw new OAuthError("Email is required for Perplexity login", {
|
|
87
|
+
kind: "validation",
|
|
88
|
+
provider: "perplexity"
|
|
89
|
+
});
|
|
90
|
+
if (ctrl.signal?.aborted) throw new LoginCancelledError();
|
|
91
|
+
const fetchImpl = ctrl.fetch ?? fetch;
|
|
92
|
+
const cookies = new CookieMap();
|
|
93
|
+
const request = async (url, init = {}) => {
|
|
94
|
+
const headers = new Headers(init.headers);
|
|
95
|
+
if (cookies.size > 0) headers.set("Cookie", serializeCookies(cookies));
|
|
96
|
+
const response = await fetchImpl(url, {
|
|
97
|
+
...init,
|
|
98
|
+
headers
|
|
99
|
+
});
|
|
100
|
+
rememberCookies(cookies, response);
|
|
101
|
+
return response;
|
|
102
|
+
};
|
|
103
|
+
ctrl.onProgress?.("Fetching Perplexity CSRF token...");
|
|
104
|
+
const csrfResponse = await request("https://www.perplexity.ai/api/auth/csrf", {
|
|
105
|
+
headers: {
|
|
106
|
+
"User-Agent": APP_USER_AGENT,
|
|
107
|
+
"X-App-ApiVersion": API_VERSION
|
|
108
|
+
},
|
|
109
|
+
signal: ctrl.signal
|
|
110
|
+
});
|
|
111
|
+
if (!csrfResponse.ok) throw new ProviderHttpError(`Perplexity CSRF request failed: ${csrfResponse.status}`, csrfResponse.status);
|
|
112
|
+
const csrfData = await csrfResponse.json();
|
|
113
|
+
if (!csrfData.csrfToken) throw new OAuthError("Perplexity CSRF response missing csrfToken", {
|
|
114
|
+
kind: "validation",
|
|
115
|
+
provider: "perplexity"
|
|
116
|
+
});
|
|
117
|
+
ctrl.onProgress?.("Sending login code to your email...");
|
|
118
|
+
const sendResponse = await request("https://www.perplexity.ai/api/auth/signin-email", {
|
|
119
|
+
method: "POST",
|
|
120
|
+
headers: {
|
|
121
|
+
"Content-Type": "application/json",
|
|
122
|
+
"User-Agent": APP_USER_AGENT,
|
|
123
|
+
"X-App-ApiVersion": API_VERSION
|
|
124
|
+
},
|
|
125
|
+
body: JSON.stringify({
|
|
126
|
+
email: trimmedEmail,
|
|
127
|
+
csrfToken: csrfData.csrfToken
|
|
128
|
+
}),
|
|
129
|
+
signal: ctrl.signal
|
|
130
|
+
});
|
|
131
|
+
if (!sendResponse.ok) {
|
|
132
|
+
const body = await sendResponse.text();
|
|
133
|
+
throw new ProviderHttpError(`Perplexity send login code failed (${sendResponse.status}): ${body}`, sendResponse.status);
|
|
134
|
+
}
|
|
135
|
+
const trimmedOtp = (await ctrl.onPrompt({
|
|
136
|
+
message: "Enter the code sent to your email",
|
|
137
|
+
placeholder: "123456"
|
|
138
|
+
})).trim();
|
|
139
|
+
if (!trimmedOtp) throw new OAuthError("OTP code is required", {
|
|
140
|
+
kind: "validation",
|
|
141
|
+
provider: "perplexity"
|
|
142
|
+
});
|
|
143
|
+
if (ctrl.signal?.aborted) throw new LoginCancelledError();
|
|
144
|
+
ctrl.onProgress?.("Verifying login code...");
|
|
145
|
+
const verifyResponse = await request("https://www.perplexity.ai/api/auth/signin-otp", {
|
|
146
|
+
method: "POST",
|
|
147
|
+
headers: {
|
|
148
|
+
"Content-Type": "application/json",
|
|
149
|
+
"User-Agent": APP_USER_AGENT,
|
|
150
|
+
"X-App-ApiVersion": API_VERSION
|
|
151
|
+
},
|
|
152
|
+
body: JSON.stringify({
|
|
153
|
+
email: trimmedEmail,
|
|
154
|
+
otp: trimmedOtp,
|
|
155
|
+
csrfToken: csrfData.csrfToken
|
|
156
|
+
}),
|
|
157
|
+
signal: ctrl.signal
|
|
158
|
+
});
|
|
159
|
+
const verifyData = await verifyResponse.json();
|
|
160
|
+
if (!verifyResponse.ok) {
|
|
161
|
+
const reason = verifyData.text ?? verifyData.error_code ?? verifyData.status ?? "OTP verification failed";
|
|
162
|
+
throw new OAuthError(`Perplexity OTP verification failed: ${reason}`, {
|
|
163
|
+
kind: "validation",
|
|
164
|
+
provider: "perplexity",
|
|
165
|
+
status: verifyResponse.status
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
if (!verifyData.token) throw new OAuthError("Perplexity OTP verification response missing token", {
|
|
169
|
+
kind: "validation",
|
|
170
|
+
provider: "perplexity"
|
|
171
|
+
});
|
|
172
|
+
return jwtToCredentials(verifyData.token, trimmedEmail);
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Login to Perplexity.
|
|
176
|
+
*
|
|
177
|
+
* Tries auto-extraction from the desktop app, then runs HTTP email OTP login.
|
|
178
|
+
*
|
|
179
|
+
* No browser/manual token paste fallback is used.
|
|
180
|
+
*/
|
|
181
|
+
async function loginPerplexity(ctrl) {
|
|
182
|
+
if (!ctrl.onPrompt) throw new OnPromptRequiredError("Perplexity");
|
|
183
|
+
if (!$env.PI_AUTH_NO_BORROW) {
|
|
184
|
+
ctrl.onProgress?.("Checking for Perplexity desktop app...");
|
|
185
|
+
const nativeJwt = await extractFromNativeApp();
|
|
186
|
+
if (nativeJwt) {
|
|
187
|
+
ctrl.onProgress?.("Found Perplexity JWT from native app");
|
|
188
|
+
return jwtToCredentials(nativeJwt);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return httpEmailLogin(ctrl);
|
|
192
|
+
}
|
|
193
|
+
//#endregion
|
|
194
|
+
export { loginPerplexity };
|