@xiaoso/dsh-tool-plus 0.1.0-beta.3 → 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.
Files changed (155) hide show
  1. package/lib/abort-D1_Z5Ut5.mjs +51 -0
  2. package/lib/abort-dIkZBV7Q.mjs +51 -0
  3. package/lib/amazon-bedrock-B0nxT06F.mjs +917 -0
  4. package/lib/amazon-bedrock-WQhvjHYu.mjs +917 -0
  5. package/lib/anthropic-CJCauvYz.mjs +3115 -0
  6. package/lib/anthropic-CZghe_9U.mjs +3115 -0
  7. package/lib/anthropic-sCMH7JID.mjs +262 -0
  8. package/lib/anthropic-tTntD8BD.mjs +262 -0
  9. package/lib/api-key-login-BzqNdM2y.mjs +157 -0
  10. package/lib/api-key-login-CWVwvHT1.mjs +157 -0
  11. package/lib/aws-credentials-CXryMobh.mjs +867 -0
  12. package/lib/aws-credentials-ChG79ey-.mjs +867 -0
  13. package/lib/azure-openai-responses-Cgmc-rbL.mjs +274 -0
  14. package/lib/azure-openai-responses-DuukbD0F.mjs +274 -0
  15. package/lib/bun-shim.mjs +81 -6
  16. package/lib/bundled-references-Cavaffah.mjs +55 -0
  17. package/lib/bundled-references-sLN0YdXU.mjs +55 -0
  18. package/lib/callback-server-CQ5Jo8F-.mjs +398 -0
  19. package/lib/callback-server-DDSrZ6l_.mjs +398 -0
  20. package/lib/client.js +1 -1
  21. package/lib/cursor-B3zg7EHj.mjs +273 -0
  22. package/lib/cursor-B6TUEmgP.mjs +135 -0
  23. package/lib/cursor-D8gvtTL3.mjs +135 -0
  24. package/lib/cursor-DkSX2h3H.mjs +5441 -0
  25. package/lib/cursor-aJrXeYCb.mjs +273 -0
  26. package/lib/cursor-mJQwUKXK.mjs +5441 -0
  27. package/lib/device-code-DBo3B5nh.mjs +51 -0
  28. package/lib/device-code-DIb0FU-H.mjs +51 -0
  29. package/lib/devin-BHZZyMhO.mjs +95 -0
  30. package/lib/devin-BK7DHeca.mjs +114 -0
  31. package/lib/devin-CfMp3cXS.mjs +95 -0
  32. package/lib/devin-D9zR5B_R.mjs +542 -0
  33. package/lib/devin-Q1yem3lp.mjs +114 -0
  34. package/lib/devin-vNZTNUON.mjs +542 -0
  35. package/lib/error-Dd8DIqs-.mjs +1449 -0
  36. package/lib/error-yCSG0mGC.mjs +1449 -0
  37. package/lib/event-stream-BbFZJy-z.mjs +151 -0
  38. package/lib/event-stream-loUa0s1T.mjs +151 -0
  39. package/lib/fs-promises-shim-Bx0fpxuk.mjs +57 -0
  40. package/lib/github-copilot-B1yiyVRh.mjs +104 -0
  41. package/lib/github-copilot-BWT3eAOF.mjs +208 -0
  42. package/lib/github-copilot-CYkjeTi3.mjs +208 -0
  43. package/lib/github-copilot-jscUZ8Hf.mjs +104 -0
  44. package/lib/gitlab-duo-CM7Ref1H.mjs +155 -0
  45. package/lib/gitlab-duo-gubO4FNw.mjs +155 -0
  46. package/lib/gitlab-duo-workflow-BGAF6JDw.mjs +91 -0
  47. package/lib/gitlab-duo-workflow-D78tdn8E.mjs +91 -0
  48. package/lib/google-BS4T25Pn.mjs +30 -0
  49. package/lib/google-TFe-7-of.mjs +30 -0
  50. package/lib/google-antigravity-DGmwC2KV.mjs +198 -0
  51. package/lib/google-antigravity-DNYhgTpA.mjs +198 -0
  52. package/lib/google-auth-B6gjsZvg.mjs +232 -0
  53. package/lib/google-auth-De7_s3eo.mjs +232 -0
  54. package/lib/google-gemini-cli-CWu8HvXW.mjs +211 -0
  55. package/lib/google-gemini-cli-Cb97bzQc.mjs +850 -0
  56. package/lib/google-gemini-cli-Cqds_Q5T.mjs +850 -0
  57. package/lib/google-gemini-cli-Dsztq0N5.mjs +211 -0
  58. package/lib/google-oauth-shared-CuEHaDDj.mjs +147 -0
  59. package/lib/google-oauth-shared-yqlyqPPC.mjs +147 -0
  60. package/lib/google-shared-CgKmmdO3.mjs +760 -0
  61. package/lib/google-shared-Dr-VG-ap.mjs +760 -0
  62. package/lib/google-vertex-BDN2tLaD.mjs +99 -0
  63. package/lib/google-vertex-DopVOQOG.mjs +99 -0
  64. package/lib/identity-Da1GPU9a.mjs +219 -0
  65. package/lib/identity-xRP7_eSR.mjs +219 -0
  66. package/lib/idle-iterator-Baoyn3Hp.mjs +366 -0
  67. package/lib/idle-iterator-DUjKQEGT.mjs +366 -0
  68. package/lib/index.mjs +1731 -1178
  69. package/lib/kimi--wUOWER5.mjs +236 -0
  70. package/lib/kimi-Dh0pv3WZ.mjs +236 -0
  71. package/lib/markit-BL3cH47U.mjs +1417 -0
  72. package/lib/markit-BNiNY6SE.mjs +1417 -0
  73. package/lib/minimax-code-DCbuA6Yk.mjs +53 -0
  74. package/lib/minimax-code-Uq8Qu9LW.mjs +53 -0
  75. package/lib/models-D_XnT6ay.mjs +104660 -0
  76. package/lib/models-SGASygJ3.mjs +104660 -0
  77. package/lib/ollama-DPzBmq89.mjs +589 -0
  78. package/lib/ollama-DoBz5SFm.mjs +589 -0
  79. package/lib/openai-codex-Bi-4S4PX.mjs +255 -0
  80. package/lib/openai-codex-Ch8CkT3p.mjs +255 -0
  81. package/lib/openai-codex-responses-CvxL_FMF.mjs +3144 -0
  82. package/lib/openai-codex-responses-pejZgdZo.mjs +3144 -0
  83. package/lib/openai-completions-CF8IyNtP.mjs +1360 -0
  84. package/lib/openai-completions-DIf361kF.mjs +1360 -0
  85. package/lib/openai-reasoning-fallback-Nj6yB2rY.mjs +286 -0
  86. package/lib/openai-reasoning-fallback-OdJREP1o.mjs +286 -0
  87. package/lib/openai-responses-BqXJInHX.mjs +867 -0
  88. package/lib/openai-responses-Db_a-U4-.mjs +867 -0
  89. package/lib/opencode-DhMolSoB.mjs +38 -0
  90. package/lib/opencode-Rq_Q2vAO.mjs +38 -0
  91. package/lib/perplexity-C4iLVMUj.mjs +194 -0
  92. package/lib/perplexity-Uu7Jzg5b.mjs +194 -0
  93. package/lib/proxy-DDqrmjjC.mjs +190 -0
  94. package/lib/proxy-pM_NIv-H.mjs +190 -0
  95. package/lib/request-debug-HJMoJncL.mjs +183 -0
  96. package/lib/sanitize-text-CfcXzw5X.mjs +33 -0
  97. package/lib/scrapers-BkFfcPHj.mjs +9198 -0
  98. package/lib/scrapers-CVptboMs.mjs +9198 -0
  99. package/lib/scrapers-nhQAvc8d.mjs +9198 -0
  100. package/lib/shell-snapshot-fn-env.sh +67 -43
  101. package/lib/src-BgpusnsB.mjs +5076 -0
  102. package/lib/src-lDmkSRbm.mjs +5006 -0
  103. package/lib/stream-BlldLkVq.mjs +10236 -0
  104. package/lib/stream-CRtexYLe.mjs +10236 -0
  105. package/lib/stream-markup-healing-DMsxBx1L.mjs +491 -0
  106. package/lib/stream-markup-healing-KMkiAA00.mjs +491 -0
  107. package/lib/turndown-DN7ByzEI.mjs +667 -0
  108. package/lib/types/config/settings.d.ts +9 -1
  109. package/lib/types/config/truncate.d.ts +9 -5
  110. package/lib/types/tools/bash/background.d.ts +1 -1
  111. package/lib/types/tools/bash/bash-executor.d.ts +4 -0
  112. package/lib/types/tools/bash/bash-interceptor.d.ts +10 -8
  113. package/lib/types/tools/bash/cd-workdir.d.ts +35 -0
  114. package/lib/types/tools/bash/non-interactive-env.d.ts +2 -0
  115. package/lib/types/tools/bash/render.d.ts +4 -3
  116. package/lib/types/tools/bash/sanitize-text.d.ts +5 -0
  117. package/lib/types/tools/bash/shell-snapshot.d.ts +4 -1
  118. package/lib/types/tools/bash/shell-tokenize.d.ts +60 -0
  119. package/lib/types/tools/bash/streaming-output.d.ts +12 -212
  120. package/lib/types/tools/bash/which.d.ts +20 -0
  121. package/lib/types/tools/bash/windows-shell.d.ts +31 -0
  122. package/lib/types/tools/edit/adapter/index.d.ts +25 -3
  123. package/lib/types/tools/edit/adapter/tools/auto-generated-guard.d.ts +7 -17
  124. package/lib/types/tools/glob/adapter/index.d.ts +27 -1
  125. package/lib/types/tools/grep/adapter/index.d.ts +29 -1
  126. package/lib/types/tools/omp/edit/dispatch.d.ts +43 -0
  127. package/lib/types/tools/omp/edit/hashline/noop-loop-guard.d.ts +3 -1
  128. package/lib/types/tools/omp/tools/auto-generated-guard.d.ts +20 -0
  129. package/lib/types/tools/omp/tools/write.d.ts +4 -4
  130. package/lib/types/tools/shared/auto-generated-guard.dsh.d.ts +16 -4
  131. package/lib/types/tools/shared/bun-shim.d.ts +4 -0
  132. package/lib/types/tools/shared/fs-promises-shim.d.ts +3 -1
  133. package/lib/types/tools/shared/omp-prompt.d.ts +13 -7
  134. package/lib/types/tools/shared/session-state.d.ts +9 -3
  135. package/lib/utils-Bw139LTz.mjs +8119 -0
  136. package/lib/utils-CZw4tVZQ.mjs +12315 -0
  137. package/lib/utils-CiGN7OHR.mjs +12315 -0
  138. package/lib/utils-Cp76gCyk.mjs +8119 -0
  139. package/lib/utils-D0GRDgAr.mjs +12315 -0
  140. package/lib/utils-D2YknRk4.mjs +51 -0
  141. package/lib/utils-DzXZDfYc.mjs +51 -0
  142. package/lib/vision-guard-01qSwFpf.mjs +92 -0
  143. package/lib/vision-guard-DzZGaOga.mjs +92 -0
  144. package/lib/wafer-CgtPHerf.mjs +17 -0
  145. package/lib/wafer-cBtrn6q9.mjs +17 -0
  146. package/lib/xai-oauth-Buk8XVvM.mjs +446 -0
  147. package/lib/xai-oauth-CMal8l1O.mjs +446 -0
  148. package/lib/xiaomi-CZgwvX2G.mjs +157 -0
  149. package/lib/xiaomi-D2qT5cAC.mjs +157 -0
  150. package/lib/zai-7DWMkEqM.mjs +203 -0
  151. package/lib/zai-C59YnomG.mjs +203 -0
  152. package/lib/zip-Cg9ANN_U.mjs +1316 -0
  153. package/lib/zip-D36ZKsP8.mjs +1316 -0
  154. package/package.json +1 -1
  155. package/presets/package.json +1 -1
@@ -0,0 +1,190 @@
1
+ import { installBunShim as __installBunShim } from "./bun-shim.mjs";
2
+ __installBunShim();
3
+ import { n as StreamTimeoutError, r as ValidationError, v as AbortError } from "./error-Dd8DIqs-.mjs";
4
+ import * as tls from "node:tls";
5
+ import * as net from "node:net";
6
+ //#region node_modules/.pnpm/@oh-my-pi+pi-ai@17.3.5/node_modules/@oh-my-pi/pi-ai/src/utils/proxy.ts
7
+ /**
8
+ * Checks if a host is local or cloud metadata, which should always bypass the proxy
9
+ * (e.g. localhost, 127/8, ::1, 169.254.169.254, metadata.google.internal).
10
+ */
11
+ function isLocalOrMetadataHost(host) {
12
+ const lowerHost = host.toLowerCase();
13
+ if (lowerHost === "localhost" || lowerHost.endsWith(".localhost") || lowerHost === "metadata.google.internal") return true;
14
+ const ip = lowerHost.replace(/^\[|\]$/g, "");
15
+ const v4 = ip.match(/^(\d{1,3})\.(\d{1,3})\.\d{1,3}\.\d{1,3}$/);
16
+ if (v4) {
17
+ const a = Number(v4[1]);
18
+ const b = Number(v4[2]);
19
+ if (a === 127 || a === 10 || a === 0) return true;
20
+ if (a === 169 && b === 254) return true;
21
+ if (a === 192 && b === 168) return true;
22
+ if (a === 172 && b >= 16 && b <= 31) return true;
23
+ return false;
24
+ }
25
+ if (ip === "::1" || ip === "::") return true;
26
+ if (/^fe[89ab][0-9a-f]:/.test(ip)) return true;
27
+ if (/^f[cd][0-9a-f]{2}:/.test(ip)) return true;
28
+ return false;
29
+ }
30
+ /**
31
+ * Check if the url should bypass the proxy due to hard-coded localhost/metadata checks
32
+ * or custom NO_PROXY/no_proxy environment variables rules.
33
+ */
34
+ function shouldBypassProxy(urlObj) {
35
+ if (isLocalOrMetadataHost(urlObj.hostname)) return true;
36
+ const noProxyVal = Bun.env.NO_PROXY || Bun.env.no_proxy;
37
+ if (!noProxyVal) return false;
38
+ const rules = noProxyVal.split(/[,\s]+/).map((r) => r.trim()).filter(Boolean);
39
+ const targetHost = urlObj.hostname.toLowerCase();
40
+ const targetPort = urlObj.port || (urlObj.protocol === "https:" || urlObj.protocol === "wss:" ? "443" : "80");
41
+ for (const rule of rules) {
42
+ if (rule === "*") return true;
43
+ let ruleHost = rule.toLowerCase();
44
+ let rulePort;
45
+ if (ruleHost.includes("]:")) {
46
+ const lastColon = ruleHost.lastIndexOf(":");
47
+ rulePort = ruleHost.slice(lastColon + 1);
48
+ ruleHost = ruleHost.slice(0, lastColon);
49
+ } else if (!ruleHost.includes("]") && ruleHost.includes(":")) {
50
+ const lastColon = ruleHost.lastIndexOf(":");
51
+ rulePort = ruleHost.slice(lastColon + 1);
52
+ ruleHost = ruleHost.slice(0, lastColon);
53
+ }
54
+ ruleHost = ruleHost.replace(/^\[|\]$/g, "");
55
+ if (rulePort && rulePort !== targetPort) continue;
56
+ if (ruleHost.startsWith(".")) {
57
+ const suffix = ruleHost;
58
+ if (targetHost === ruleHost.slice(1) || targetHost.endsWith(suffix)) return true;
59
+ } else if (targetHost === ruleHost || targetHost.endsWith(`.${ruleHost}`)) return true;
60
+ }
61
+ return false;
62
+ }
63
+ const proxyCache = /* @__PURE__ */ new Map();
64
+ /**
65
+ * Normalizes provider id (e.g. github-copilot -> PI_PROXY_GITHUB_COPILOT) and looks it up.
66
+ * If not found, falls back to PI_PROXY. Results are memoized because env values are static
67
+ * for the lifetime of the process and this function is called for every outgoing request.
68
+ */
69
+ function getProxyForProvider(provider) {
70
+ if (proxyCache.has(provider)) return proxyCache.get(provider);
71
+ const envKey = `PI_PROXY_${provider.toUpperCase().replace(/[^A-Z0-9]/g, "_")}`;
72
+ const value = Bun.env[envKey] || Bun.env.PI_PROXY;
73
+ proxyCache.set(provider, value);
74
+ return value;
75
+ }
76
+ /** Resolves provider-specific and standard proxy variables for a target URL, honoring NO_PROXY. */
77
+ function getProxyForUrl(provider, url) {
78
+ if (shouldBypassProxy(url)) return void 0;
79
+ const protocolProxy = url.protocol === "https:" || url.protocol === "wss:" ? Bun.env.HTTPS_PROXY || Bun.env.https_proxy : Bun.env.HTTP_PROXY || Bun.env.http_proxy;
80
+ return getProxyForProvider(provider) || protocolProxy || Bun.env.ALL_PROXY || Bun.env.all_proxy || void 0;
81
+ }
82
+ /**
83
+ * Tunnel a socket connection through an HTTP CONNECT proxy.
84
+ * This is used specifically to wrap Node's `http2.connect(baseUrl, { createConnection })` for Cursor.
85
+ */
86
+ async function connectProxiedSocket(proxyUrlStr, targetUrlStr, options) {
87
+ if (options?.signal?.aborted) throw new AbortError("Proxy tunnel aborted");
88
+ const proxyUrl = new URL(proxyUrlStr);
89
+ const targetUrl = new URL(targetUrlStr);
90
+ const useProxySsl = proxyUrl.protocol === "https:";
91
+ const proxyPort = proxyUrl.port ? parseInt(proxyUrl.port, 10) : useProxySsl ? 443 : 80;
92
+ const proxyHost = proxyUrl.hostname;
93
+ const targetPort = targetUrl.port ? parseInt(targetUrl.port, 10) : 443;
94
+ const targetHost = targetUrl.hostname;
95
+ const { promise, resolve, reject } = Promise.withResolvers();
96
+ const readyEvent = useProxySsl ? "secureConnect" : "connect";
97
+ let rawSocket;
98
+ let tunnelSocket;
99
+ let timeout;
100
+ let responseData = "";
101
+ let settled = false;
102
+ const cleanup = () => {
103
+ if (timeout) {
104
+ clearTimeout(timeout);
105
+ timeout = void 0;
106
+ }
107
+ options?.signal?.removeEventListener("abort", onAbort);
108
+ rawSocket?.off("error", onRawError);
109
+ rawSocket?.off(readyEvent, onProxyReady);
110
+ rawSocket?.off("data", onProxyData);
111
+ tunnelSocket?.off("secureConnect", onTunnelReady);
112
+ tunnelSocket?.off("error", onTunnelError);
113
+ };
114
+ const destroyInProgress = () => {
115
+ tunnelSocket?.destroy();
116
+ rawSocket?.destroy();
117
+ };
118
+ const rejectOnce = (error) => {
119
+ if (settled) return;
120
+ settled = true;
121
+ cleanup();
122
+ destroyInProgress();
123
+ reject(error);
124
+ };
125
+ const resolveOnce = (socket) => {
126
+ if (settled) return;
127
+ settled = true;
128
+ cleanup();
129
+ resolve(socket);
130
+ };
131
+ const onAbort = () => rejectOnce(new AbortError("Proxy tunnel aborted"));
132
+ const onRawError = (error) => rejectOnce(error);
133
+ const onTunnelError = (error) => rejectOnce(error);
134
+ const onTunnelReady = () => {
135
+ if (!tunnelSocket) return;
136
+ resolveOnce(tunnelSocket);
137
+ };
138
+ const onProxyData = (chunk) => {
139
+ if (!rawSocket) return;
140
+ responseData += chunk.toString("binary");
141
+ if (!responseData.includes("\r\n\r\n")) return;
142
+ rawSocket.off("data", onProxyData);
143
+ rawSocket.off("error", onRawError);
144
+ const firstLine = responseData.split("\r\n")[0];
145
+ if (!firstLine.includes(" 200 ")) {
146
+ rejectOnce(new ValidationError(`Proxy tunnel failed: ${firstLine}`));
147
+ return;
148
+ }
149
+ const tlsOptions = options?.tls;
150
+ tunnelSocket = tls.connect({
151
+ ...tlsOptions,
152
+ socket: rawSocket,
153
+ servername: tlsOptions?.servername ?? targetHost,
154
+ ALPNProtocols: tlsOptions?.ALPNProtocols ?? ["h2"]
155
+ });
156
+ tunnelSocket.once("secureConnect", onTunnelReady);
157
+ tunnelSocket.once("error", onTunnelError);
158
+ };
159
+ const onProxyReady = () => {
160
+ if (!rawSocket) return;
161
+ let connectReq = `CONNECT ${targetHost}:${targetPort} HTTP/1.1\r\nHost: ${targetHost}:${targetPort}\r\n`;
162
+ if (proxyUrl.username || proxyUrl.password) {
163
+ const creds = Buffer.from(`${decodeURIComponent(proxyUrl.username)}:${decodeURIComponent(proxyUrl.password)}`).toString("base64");
164
+ connectReq += `Proxy-Authorization: Basic ${creds}\r\n`;
165
+ }
166
+ connectReq += "\r\n";
167
+ rawSocket.write(connectReq);
168
+ rawSocket.on("data", onProxyData);
169
+ };
170
+ options?.signal?.addEventListener("abort", onAbort, { once: true });
171
+ if (options?.timeoutMs !== void 0 && Number.isFinite(options.timeoutMs) && options.timeoutMs > 0) {
172
+ const timeoutMs = Math.trunc(options.timeoutMs);
173
+ timeout = setTimeout(() => {
174
+ rejectOnce(new StreamTimeoutError(`Proxy tunnel timed out after ${timeoutMs}ms`));
175
+ }, timeoutMs);
176
+ timeout.unref?.();
177
+ }
178
+ rawSocket = useProxySsl ? tls.connect({
179
+ host: proxyHost,
180
+ port: proxyPort
181
+ }) : net.connect({
182
+ host: proxyHost,
183
+ port: proxyPort
184
+ });
185
+ rawSocket.once("error", onRawError);
186
+ rawSocket.once(readyEvent, onProxyReady);
187
+ return promise;
188
+ }
189
+ //#endregion
190
+ export { shouldBypassProxy as a, isLocalOrMetadataHost as i, getProxyForProvider as n, getProxyForUrl as r, connectProxiedSocket as t };
@@ -0,0 +1,183 @@
1
+ import { installBunShim as __installBunShim } from "./bun-shim.mjs";
2
+ __installBunShim();
3
+ import { n as fs_promises_shim_exports } from "./fs-promises-shim-Bx0fpxuk.mjs";
4
+ import "node:buffer";
5
+ //#region node_modules/.pnpm/@oh-my-pi+pi-ai@17.3.5/node_modules/@oh-my-pi/pi-ai/src/utils/request-debug.ts
6
+ const REQUEST_DEBUG_ENV = "PI_REQ_DEBUG";
7
+ const textEncoder = new TextEncoder();
8
+ new TextDecoder("utf-8", { fatal: true });
9
+ let nextSessionId = 1;
10
+ function isRequestDebugEnvEnabled() {
11
+ return Bun.env[REQUEST_DEBUG_ENV] === "1";
12
+ }
13
+ function isRequestDebugEnabled() {
14
+ return isRequestDebugEnvEnabled();
15
+ }
16
+ async function createRequestDebugSession(payload) {
17
+ const { id, requestPath, responsePath, handle, overwrite } = await reserveRequestDebugFile();
18
+ const requestDump = {
19
+ id,
20
+ protocol: payload.protocol ?? "http",
21
+ method: payload.method,
22
+ url: payload.url
23
+ };
24
+ const headers = headersToRecord(payload.headers);
25
+ if (headers) requestDump.headers = headers;
26
+ if (payload.body !== void 0) requestDump.body = payload.body;
27
+ if (payload.bodyText !== void 0) requestDump.bodyText = payload.bodyText;
28
+ if (payload.bodyBase64 !== void 0) requestDump.bodyBase64 = payload.bodyBase64;
29
+ if (payload.bodyUnavailable !== void 0) requestDump.bodyUnavailable = payload.bodyUnavailable;
30
+ try {
31
+ await handle.writeFile(`${JSON.stringify(requestDump, null, 2)}\n`, "utf8");
32
+ } finally {
33
+ await handle.close();
34
+ }
35
+ return new FileRequestDebugSession(id, requestPath, responsePath, overwrite);
36
+ }
37
+ var FileRequestDebugSession = class {
38
+ id;
39
+ requestPath;
40
+ responsePath;
41
+ #overwriteResponseLog;
42
+ constructor(id, requestPath, responsePath, overwriteResponseLog) {
43
+ this.id = id;
44
+ this.requestPath = requestPath;
45
+ this.responsePath = responsePath;
46
+ this.#overwriteResponseLog = overwriteResponseLog;
47
+ }
48
+ async openResponseLog(statusLine, headers) {
49
+ const handle = await fs_promises_shim_exports.open(this.responsePath, this.#overwriteResponseLog ? "w" : "wx");
50
+ const headerBlock = formatResponseHeaderBlock(statusLine, headers);
51
+ await handle.write(textEncoder.encode(headerBlock));
52
+ return new FileRequestDebugResponseLog(handle);
53
+ }
54
+ async wrapResponse(response) {
55
+ const log = await this.openResponseLog(`HTTP ${response.status} ${response.statusText}`.trim(), response.headers);
56
+ if (!response.body) {
57
+ await log.close();
58
+ return response;
59
+ }
60
+ const reader = response.body.getReader();
61
+ const teed = new ReadableStream({
62
+ async pull(controller) {
63
+ try {
64
+ const { done, value } = await reader.read();
65
+ if (done) {
66
+ await log.close();
67
+ controller.close();
68
+ return;
69
+ }
70
+ log.write(value);
71
+ controller.enqueue(value);
72
+ } catch (error) {
73
+ await log.close().catch(() => void 0);
74
+ controller.error(error);
75
+ }
76
+ },
77
+ async cancel(reason) {
78
+ try {
79
+ await reader.cancel(reason);
80
+ } finally {
81
+ await log.close();
82
+ }
83
+ }
84
+ });
85
+ const wrapped = new Response(teed, {
86
+ status: response.status,
87
+ statusText: response.statusText,
88
+ headers: response.headers
89
+ });
90
+ copyResponseMetadata(wrapped, response);
91
+ return wrapped;
92
+ }
93
+ };
94
+ var FileRequestDebugResponseLog = class {
95
+ #handle;
96
+ #pending = Promise.resolve();
97
+ #closed;
98
+ constructor(handle) {
99
+ this.#handle = handle;
100
+ }
101
+ write(chunk) {
102
+ const handle = this.#handle;
103
+ if (!handle) return;
104
+ const bytes = typeof chunk === "string" ? textEncoder.encode(chunk) : chunk.slice();
105
+ this.#pending = this.#pending.then(async () => {
106
+ await handle.write(bytes);
107
+ });
108
+ }
109
+ close() {
110
+ if (this.#closed) return this.#closed;
111
+ const handle = this.#handle;
112
+ if (!handle) return Promise.resolve();
113
+ this.#handle = void 0;
114
+ this.#closed = (async () => {
115
+ try {
116
+ await this.#pending;
117
+ } finally {
118
+ await handle.close();
119
+ }
120
+ })();
121
+ return this.#closed;
122
+ }
123
+ };
124
+ function copyResponseMetadata(target, source) {
125
+ const sourceUrl = source.url;
126
+ if (!sourceUrl) return;
127
+ try {
128
+ Object.defineProperty(target, "url", {
129
+ value: sourceUrl,
130
+ configurable: true
131
+ });
132
+ } catch {}
133
+ }
134
+ async function reserveRequestDebugFile() {
135
+ for (;;) {
136
+ const id = nextSessionId++;
137
+ const requestPath = `rr-session-${id}.json`;
138
+ try {
139
+ const handle = await fs_promises_shim_exports.open(requestPath, "wx");
140
+ return {
141
+ id,
142
+ requestPath,
143
+ responsePath: `rr-session-${id}.res.log`,
144
+ handle,
145
+ overwrite: false
146
+ };
147
+ } catch (error) {
148
+ if (isFileExistsError(error)) continue;
149
+ throw error;
150
+ }
151
+ }
152
+ }
153
+ function formatResponseHeaderBlock(statusLine, headers) {
154
+ const lines = [statusLine];
155
+ const record = headersToRecord(headers);
156
+ if (record) for (const name in record) {
157
+ const value = record[name];
158
+ if (Array.isArray(value)) for (const item of value) lines.push(`${name}: ${item}`);
159
+ else lines.push(`${name}: ${value}`);
160
+ }
161
+ return `${lines.join("\r\n")}\r\n\r\n`;
162
+ }
163
+ function headersToRecord(headers) {
164
+ if (!headers) return void 0;
165
+ const record = {};
166
+ let hasHeaders = false;
167
+ if (headers instanceof Headers) headers.forEach((value, key) => {
168
+ hasHeaders = true;
169
+ record[key] = value;
170
+ });
171
+ else for (const key in headers) {
172
+ const value = headers[key];
173
+ if (value === void 0 || value === null) continue;
174
+ hasHeaders = true;
175
+ record[key] = Array.isArray(value) ? value.map(String) : String(value);
176
+ }
177
+ return hasHeaders ? record : void 0;
178
+ }
179
+ function isFileExistsError(error) {
180
+ return typeof error === "object" && error !== null && error.code === "EEXIST";
181
+ }
182
+ //#endregion
183
+ export { isRequestDebugEnabled as n, createRequestDebugSession as t };
@@ -0,0 +1,33 @@
1
+ import { installBunShim as __installBunShim } from "./bun-shim.mjs";
2
+ __installBunShim();
3
+ //#region node_modules/.pnpm/@oh-my-pi+pi-utils@17.3.5/node_modules/@oh-my-pi/pi-utils/src/sanitize-text.ts
4
+ /**
5
+ * Strip ANSI escape sequences, remove control characters / lone surrogates,
6
+ * and normalize line endings.
7
+ *
8
+ * Bun-native implementation of the former native `sanitizeText` (see
9
+ * `crates/pi-natives/src/text.rs::sanitize_text`). JavaScript strings are
10
+ * already UTF-16 code-unit arrays. `toWellFormed()` handles the uncommon
11
+ * malformed path; when it changes the input, replacement characters are
12
+ * dropped and the normalized result goes through the well-formed sanitizer.
13
+ *
14
+ * Fast path: well-formed input with no controls or ANSI returns the original
15
+ * string after the control probe.
16
+ */
17
+ const ESC_CHAR = "\x1B";
18
+ const CONTROL_RE = /[\x00-\x08\x0B-\x1F\x7F-\x9F]/g;
19
+ const REPLACEMENT_CHAR = "�";
20
+ function sanitizeText(text) {
21
+ const wellFormed = text.toWellFormed();
22
+ if (wellFormed !== text) return sanitizeWellFormedText(wellFormed.replaceAll(REPLACEMENT_CHAR, ""));
23
+ return sanitizeWellFormedText(text);
24
+ }
25
+ function sanitizeWellFormedText(text) {
26
+ CONTROL_RE.lastIndex = 0;
27
+ if (CONTROL_RE.exec(text) === null) return text;
28
+ const stripped = text.indexOf(ESC_CHAR) === -1 ? text : Bun.stripANSI(text);
29
+ CONTROL_RE.lastIndex = 0;
30
+ return stripped.replace(CONTROL_RE, "");
31
+ }
32
+ //#endregion
33
+ export { sanitizeText as t };