pi2dsh 0.3.1 → 0.3.2

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 (101) hide show
  1. package/README.md +15 -10
  2. package/README.zh.md +15 -10
  3. package/dist/all-Rt4K68QA.mjs +28512 -0
  4. package/dist/all-Rt4K68QA.mjs.map +1 -0
  5. package/dist/anthropic-messages-Beym0_aC.mjs +6438 -0
  6. package/dist/anthropic-messages-Beym0_aC.mjs.map +1 -0
  7. package/dist/azure-openai-responses-cHqZTgLD.mjs +209 -0
  8. package/dist/azure-openai-responses-cHqZTgLD.mjs.map +1 -0
  9. package/dist/{build-DsGYAgiT.mjs → build-BG7p2Lbr.mjs} +2 -2
  10. package/dist/{build-DsGYAgiT.mjs.map → build-BG7p2Lbr.mjs.map} +1 -1
  11. package/dist/cli.mjs +1 -1
  12. package/dist/compat/pi-ai.d.mts +16 -3
  13. package/dist/compat/pi-ai.d.mts.map +1 -1
  14. package/dist/compat/pi-ai.mjs +3 -3
  15. package/dist/compat/pi-coding-agent.d.mts +12 -1
  16. package/dist/compat/pi-coding-agent.d.mts.map +1 -1
  17. package/dist/compat/pi-coding-agent.mjs +2 -2
  18. package/dist/credentials-oauth.mjs +3 -3
  19. package/dist/deferred-tools-BD4g5QUx.mjs +32 -0
  20. package/dist/deferred-tools-BD4g5QUx.mjs.map +1 -0
  21. package/dist/diagnostics-CJye1UFh.mjs +99 -0
  22. package/dist/diagnostics-CJye1UFh.mjs.map +1 -0
  23. package/dist/dist-IQKOgQyt.mjs +10035 -0
  24. package/dist/dist-IQKOgQyt.mjs.map +1 -0
  25. package/dist/dist-QBBA-dL_.mjs +1246 -0
  26. package/dist/dist-QBBA-dL_.mjs.map +1 -0
  27. package/dist/error-body-DKA3lknR.mjs +104 -0
  28. package/dist/error-body-DKA3lknR.mjs.map +1 -0
  29. package/dist/github-copilot-headers-CZo2QHrt.mjs +25 -0
  30. package/dist/github-copilot-headers-CZo2QHrt.mjs.map +1 -0
  31. package/dist/google-generative-ai-B7OZs5lu.mjs +358 -0
  32. package/dist/google-generative-ai-B7OZs5lu.mjs.map +1 -0
  33. package/dist/google-shared-CRsAUItF.mjs +29042 -0
  34. package/dist/google-shared-CRsAUItF.mjs.map +1 -0
  35. package/dist/google-vertex-DmdaHQtB.mjs +402 -0
  36. package/dist/google-vertex-DmdaHQtB.mjs.map +1 -0
  37. package/dist/hash-Dbggamac.mjs +19 -0
  38. package/dist/hash-Dbggamac.mjs.map +1 -0
  39. package/dist/headers-CPzZhJQn.mjs +17 -0
  40. package/dist/headers-CPzZhJQn.mjs.map +1 -0
  41. package/dist/host.d.mts.map +1 -1
  42. package/dist/host.mjs +13 -3
  43. package/dist/host.mjs.map +1 -1
  44. package/dist/images-models-DJtHo9Rp.mjs +1068 -0
  45. package/dist/images-models-DJtHo9Rp.mjs.map +1 -0
  46. package/dist/index.d.mts.map +1 -1
  47. package/dist/index.mjs +1 -1
  48. package/dist/json-parse-CFyFZSLJ.mjs +384 -0
  49. package/dist/json-parse-CFyFZSLJ.mjs.map +1 -0
  50. package/dist/{mcp-config-gqg7GJEE.mjs → mcp-config-D2B3kv-Z.mjs} +34 -16
  51. package/dist/mcp-config-D2B3kv-Z.mjs.map +1 -0
  52. package/dist/mistral-conversations-HHZCcFv_.mjs +42007 -0
  53. package/dist/mistral-conversations-HHZCcFv_.mjs.map +1 -0
  54. package/dist/multipart-parser-CIa5BbwO.mjs +301 -0
  55. package/dist/multipart-parser-CIa5BbwO.mjs.map +1 -0
  56. package/dist/{oauth-bridge-BpPrppjR.mjs → oauth-bridge-C6fL1qSv.mjs} +20 -4
  57. package/dist/oauth-bridge-C6fL1qSv.mjs.map +1 -0
  58. package/dist/openai-DkzRh5_G.mjs +6732 -0
  59. package/dist/openai-DkzRh5_G.mjs.map +1 -0
  60. package/dist/openai-codex-responses-vmovNu-q.mjs +1169 -0
  61. package/dist/openai-codex-responses-vmovNu-q.mjs.map +1 -0
  62. package/dist/openai-completions-fXHhRolF.mjs +947 -0
  63. package/dist/openai-completions-fXHhRolF.mjs.map +1 -0
  64. package/dist/openai-prompt-cache-BDWtZRKh.mjs +11 -0
  65. package/dist/openai-prompt-cache-BDWtZRKh.mjs.map +1 -0
  66. package/dist/openai-responses-DKdCYf3h.mjs +247 -0
  67. package/dist/openai-responses-DKdCYf3h.mjs.map +1 -0
  68. package/dist/openai-responses-shared-D0Jq7yVP.mjs +572 -0
  69. package/dist/openai-responses-shared-D0Jq7yVP.mjs.map +1 -0
  70. package/dist/openrouter-images-fG3Aj6M4.mjs +127 -0
  71. package/dist/openrouter-images-fG3Aj6M4.mjs.map +1 -0
  72. package/dist/otel-BQSQRBLF.mjs +24935 -0
  73. package/dist/otel-BQSQRBLF.mjs.map +1 -0
  74. package/dist/{pi-ai-CWFlgigJ.mjs → pi-ai-DhYGgq4Y.mjs} +49 -12
  75. package/dist/{pi-ai-CWFlgigJ.mjs.map → pi-ai-DhYGgq4Y.mjs.map} +1 -1
  76. package/dist/{pi-coding-agent-Z1hTs61i.mjs → pi-coding-agent-fPHwKP4d.mjs} +27 -3
  77. package/dist/{pi-coding-agent-Z1hTs61i.mjs.map → pi-coding-agent-fPHwKP4d.mjs.map} +1 -1
  78. package/dist/pi-messages-CV-Ts8An.mjs +306 -0
  79. package/dist/pi-messages-CV-Ts8An.mjs.map +1 -0
  80. package/dist/provider-env-C72pF4vP.mjs +40 -0
  81. package/dist/provider-env-C72pF4vP.mjs.map +1 -0
  82. package/dist/provider-retry-Cw6YJ4cr.mjs +80 -0
  83. package/dist/provider-retry-Cw6YJ4cr.mjs.map +1 -0
  84. package/dist/rolldown-runtime-CTfmNlz1.mjs +44 -0
  85. package/dist/{runtime-6DefpI6h.mjs → runtime-B9R7bDWT.mjs} +874 -37
  86. package/dist/runtime-B9R7bDWT.mjs.map +1 -0
  87. package/dist/runtime.d.mts.map +1 -1
  88. package/dist/runtime.mjs +1 -1
  89. package/dist/sanitize-unicode-wLA11KvZ.mjs +29 -0
  90. package/dist/sanitize-unicode-wLA11KvZ.mjs.map +1 -0
  91. package/dist/src-C3WBfOks.mjs +5031 -0
  92. package/dist/src-C3WBfOks.mjs.map +1 -0
  93. package/dist/transform-messages-DGq9mvhA.mjs +379 -0
  94. package/dist/transform-messages-DGq9mvhA.mjs.map +1 -0
  95. package/dist/uuid-DtFT7tOE.mjs +65 -0
  96. package/dist/uuid-DtFT7tOE.mjs.map +1 -0
  97. package/package.json +1 -1
  98. package/dist/mcp-config-gqg7GJEE.mjs.map +0 -1
  99. package/dist/oauth-bridge-BpPrppjR.mjs.map +0 -1
  100. package/dist/rolldown-runtime-D-uZhY3_.mjs +0 -16
  101. package/dist/runtime-6DefpI6h.mjs.map +0 -1
@@ -0,0 +1,301 @@
1
+
2
+ import { n as __esmMin } from "./rolldown-runtime-CTfmNlz1.mjs";
3
+ import { i as File, n as FormData, r as init_esm_min, t as init_from } from "./src-C3WBfOks.mjs";
4
+ //#region node_modules/.pnpm/node-fetch@3.3.2/node_modules/node-fetch/src/utils/multipart-parser.js
5
+ function _fileName(headerValue) {
6
+ const m = headerValue.match(/\bfilename=("(.*?)"|([^()<>@,;:\\"/[\]?={}\s\t]+))($|;\s)/i);
7
+ if (!m) return;
8
+ const match = m[2] || m[3] || "";
9
+ let filename = match.slice(match.lastIndexOf("\\") + 1);
10
+ filename = filename.replace(/%22/g, "\"");
11
+ filename = filename.replace(/&#(\d{4});/g, (m, code) => {
12
+ return String.fromCharCode(code);
13
+ });
14
+ return filename;
15
+ }
16
+ async function toFormData(Body, ct) {
17
+ if (!/multipart/i.test(ct)) throw new TypeError("Failed to fetch");
18
+ const m = ct.match(/boundary=(?:"([^"]+)"|([^;]+))/i);
19
+ if (!m) throw new TypeError("no or bad content-type header, no multipart boundary");
20
+ const parser = new MultipartParser(m[1] || m[2]);
21
+ let headerField;
22
+ let headerValue;
23
+ let entryValue;
24
+ let entryName;
25
+ let contentType;
26
+ let filename;
27
+ const entryChunks = [];
28
+ const formData = new FormData();
29
+ const onPartData = (ui8a) => {
30
+ entryValue += decoder.decode(ui8a, { stream: true });
31
+ };
32
+ const appendToFile = (ui8a) => {
33
+ entryChunks.push(ui8a);
34
+ };
35
+ const appendFileToFormData = () => {
36
+ const file = new File(entryChunks, filename, { type: contentType });
37
+ formData.append(entryName, file);
38
+ };
39
+ const appendEntryToFormData = () => {
40
+ formData.append(entryName, entryValue);
41
+ };
42
+ const decoder = new TextDecoder("utf-8");
43
+ decoder.decode();
44
+ parser.onPartBegin = function() {
45
+ parser.onPartData = onPartData;
46
+ parser.onPartEnd = appendEntryToFormData;
47
+ headerField = "";
48
+ headerValue = "";
49
+ entryValue = "";
50
+ entryName = "";
51
+ contentType = "";
52
+ filename = null;
53
+ entryChunks.length = 0;
54
+ };
55
+ parser.onHeaderField = function(ui8a) {
56
+ headerField += decoder.decode(ui8a, { stream: true });
57
+ };
58
+ parser.onHeaderValue = function(ui8a) {
59
+ headerValue += decoder.decode(ui8a, { stream: true });
60
+ };
61
+ parser.onHeaderEnd = function() {
62
+ headerValue += decoder.decode();
63
+ headerField = headerField.toLowerCase();
64
+ if (headerField === "content-disposition") {
65
+ const m = headerValue.match(/\bname=("([^"]*)"|([^()<>@,;:\\"/[\]?={}\s\t]+))/i);
66
+ if (m) entryName = m[2] || m[3] || "";
67
+ filename = _fileName(headerValue);
68
+ if (filename) {
69
+ parser.onPartData = appendToFile;
70
+ parser.onPartEnd = appendFileToFormData;
71
+ }
72
+ } else if (headerField === "content-type") contentType = headerValue;
73
+ headerValue = "";
74
+ headerField = "";
75
+ };
76
+ for await (const chunk of Body) parser.write(chunk);
77
+ parser.end();
78
+ return formData;
79
+ }
80
+ var s, S, f, F, LF, CR, SPACE, HYPHEN, COLON, A, Z, lower, noop, MultipartParser;
81
+ //#endregion
82
+ __esmMin((() => {
83
+ init_from();
84
+ init_esm_min();
85
+ s = 0;
86
+ S = {
87
+ START_BOUNDARY: s++,
88
+ HEADER_FIELD_START: s++,
89
+ HEADER_FIELD: s++,
90
+ HEADER_VALUE_START: s++,
91
+ HEADER_VALUE: s++,
92
+ HEADER_VALUE_ALMOST_DONE: s++,
93
+ HEADERS_ALMOST_DONE: s++,
94
+ PART_DATA_START: s++,
95
+ PART_DATA: s++,
96
+ END: s++
97
+ };
98
+ f = 1;
99
+ F = {
100
+ PART_BOUNDARY: f,
101
+ LAST_BOUNDARY: f *= 2
102
+ };
103
+ LF = 10;
104
+ CR = 13;
105
+ SPACE = 32;
106
+ HYPHEN = 45;
107
+ COLON = 58;
108
+ A = 97;
109
+ Z = 122;
110
+ lower = (c) => c | 32;
111
+ noop = () => {};
112
+ MultipartParser = class {
113
+ /**
114
+ * @param {string} boundary
115
+ */
116
+ constructor(boundary) {
117
+ this.index = 0;
118
+ this.flags = 0;
119
+ this.onHeaderEnd = noop;
120
+ this.onHeaderField = noop;
121
+ this.onHeadersEnd = noop;
122
+ this.onHeaderValue = noop;
123
+ this.onPartBegin = noop;
124
+ this.onPartData = noop;
125
+ this.onPartEnd = noop;
126
+ this.boundaryChars = {};
127
+ boundary = "\r\n--" + boundary;
128
+ const ui8a = new Uint8Array(boundary.length);
129
+ for (let i = 0; i < boundary.length; i++) {
130
+ ui8a[i] = boundary.charCodeAt(i);
131
+ this.boundaryChars[ui8a[i]] = true;
132
+ }
133
+ this.boundary = ui8a;
134
+ this.lookbehind = new Uint8Array(this.boundary.length + 8);
135
+ this.state = S.START_BOUNDARY;
136
+ }
137
+ /**
138
+ * @param {Uint8Array} data
139
+ */
140
+ write(data) {
141
+ let i = 0;
142
+ const length_ = data.length;
143
+ let previousIndex = this.index;
144
+ let { lookbehind, boundary, boundaryChars, index, state, flags } = this;
145
+ const boundaryLength = this.boundary.length;
146
+ const boundaryEnd = boundaryLength - 1;
147
+ const bufferLength = data.length;
148
+ let c;
149
+ let cl;
150
+ const mark = (name) => {
151
+ this[name + "Mark"] = i;
152
+ };
153
+ const clear = (name) => {
154
+ delete this[name + "Mark"];
155
+ };
156
+ const callback = (callbackSymbol, start, end, ui8a) => {
157
+ if (start === void 0 || start !== end) this[callbackSymbol](ui8a && ui8a.subarray(start, end));
158
+ };
159
+ const dataCallback = (name, clear) => {
160
+ const markSymbol = name + "Mark";
161
+ if (!(markSymbol in this)) return;
162
+ if (clear) {
163
+ callback(name, this[markSymbol], i, data);
164
+ delete this[markSymbol];
165
+ } else {
166
+ callback(name, this[markSymbol], data.length, data);
167
+ this[markSymbol] = 0;
168
+ }
169
+ };
170
+ for (i = 0; i < length_; i++) {
171
+ c = data[i];
172
+ switch (state) {
173
+ case S.START_BOUNDARY:
174
+ if (index === boundary.length - 2) {
175
+ if (c === HYPHEN) flags |= F.LAST_BOUNDARY;
176
+ else if (c !== CR) return;
177
+ index++;
178
+ break;
179
+ } else if (index - 1 === boundary.length - 2) {
180
+ if (flags & F.LAST_BOUNDARY && c === HYPHEN) {
181
+ state = S.END;
182
+ flags = 0;
183
+ } else if (!(flags & F.LAST_BOUNDARY) && c === LF) {
184
+ index = 0;
185
+ callback("onPartBegin");
186
+ state = S.HEADER_FIELD_START;
187
+ } else return;
188
+ break;
189
+ }
190
+ if (c !== boundary[index + 2]) index = -2;
191
+ if (c === boundary[index + 2]) index++;
192
+ break;
193
+ case S.HEADER_FIELD_START:
194
+ state = S.HEADER_FIELD;
195
+ mark("onHeaderField");
196
+ index = 0;
197
+ case S.HEADER_FIELD:
198
+ if (c === CR) {
199
+ clear("onHeaderField");
200
+ state = S.HEADERS_ALMOST_DONE;
201
+ break;
202
+ }
203
+ index++;
204
+ if (c === HYPHEN) break;
205
+ if (c === COLON) {
206
+ if (index === 1) return;
207
+ dataCallback("onHeaderField", true);
208
+ state = S.HEADER_VALUE_START;
209
+ break;
210
+ }
211
+ cl = lower(c);
212
+ if (cl < A || cl > Z) return;
213
+ break;
214
+ case S.HEADER_VALUE_START:
215
+ if (c === SPACE) break;
216
+ mark("onHeaderValue");
217
+ state = S.HEADER_VALUE;
218
+ case S.HEADER_VALUE:
219
+ if (c === CR) {
220
+ dataCallback("onHeaderValue", true);
221
+ callback("onHeaderEnd");
222
+ state = S.HEADER_VALUE_ALMOST_DONE;
223
+ }
224
+ break;
225
+ case S.HEADER_VALUE_ALMOST_DONE:
226
+ if (c !== LF) return;
227
+ state = S.HEADER_FIELD_START;
228
+ break;
229
+ case S.HEADERS_ALMOST_DONE:
230
+ if (c !== LF) return;
231
+ callback("onHeadersEnd");
232
+ state = S.PART_DATA_START;
233
+ break;
234
+ case S.PART_DATA_START:
235
+ state = S.PART_DATA;
236
+ mark("onPartData");
237
+ case S.PART_DATA:
238
+ previousIndex = index;
239
+ if (index === 0) {
240
+ i += boundaryEnd;
241
+ while (i < bufferLength && !(data[i] in boundaryChars)) i += boundaryLength;
242
+ i -= boundaryEnd;
243
+ c = data[i];
244
+ }
245
+ if (index < boundary.length) {
246
+ if (boundary[index] === c) {
247
+ if (index === 0) dataCallback("onPartData", true);
248
+ index++;
249
+ } else index = 0;
250
+ } else if (index === boundary.length) {
251
+ index++;
252
+ if (c === CR) flags |= F.PART_BOUNDARY;
253
+ else if (c === HYPHEN) flags |= F.LAST_BOUNDARY;
254
+ else index = 0;
255
+ } else if (index - 1 === boundary.length) {
256
+ if (flags & F.PART_BOUNDARY) {
257
+ index = 0;
258
+ if (c === LF) {
259
+ flags &= ~F.PART_BOUNDARY;
260
+ callback("onPartEnd");
261
+ callback("onPartBegin");
262
+ state = S.HEADER_FIELD_START;
263
+ break;
264
+ }
265
+ } else if (flags & F.LAST_BOUNDARY) {
266
+ if (c === HYPHEN) {
267
+ callback("onPartEnd");
268
+ state = S.END;
269
+ flags = 0;
270
+ } else index = 0;
271
+ } else index = 0;
272
+ }
273
+ if (index > 0) lookbehind[index - 1] = c;
274
+ else if (previousIndex > 0) {
275
+ const _lookbehind = new Uint8Array(lookbehind.buffer, lookbehind.byteOffset, lookbehind.byteLength);
276
+ callback("onPartData", 0, previousIndex, _lookbehind);
277
+ previousIndex = 0;
278
+ mark("onPartData");
279
+ i--;
280
+ }
281
+ break;
282
+ case S.END: break;
283
+ default: throw new Error(`Unexpected state entered: ${state}`);
284
+ }
285
+ }
286
+ dataCallback("onHeaderField");
287
+ dataCallback("onHeaderValue");
288
+ dataCallback("onPartData");
289
+ this.index = index;
290
+ this.state = state;
291
+ this.flags = flags;
292
+ }
293
+ end() {
294
+ if (this.state === S.HEADER_FIELD_START && this.index === 0 || this.state === S.PART_DATA && this.index === this.boundary.length) this.onPartEnd();
295
+ else if (this.state !== S.END) throw new Error("MultipartParser.end(): stream ended unexpectedly");
296
+ }
297
+ };
298
+ }))();
299
+ export { toFormData };
300
+
301
+ //# sourceMappingURL=multipart-parser-CIa5BbwO.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multipart-parser-CIa5BbwO.mjs","names":[],"sources":["../node_modules/.pnpm/node-fetch@3.3.2/node_modules/node-fetch/src/utils/multipart-parser.js"],"sourcesContent":["import {File} from 'fetch-blob/from.js';\nimport {FormData} from 'formdata-polyfill/esm.min.js';\n\nlet s = 0;\nconst S = {\n\tSTART_BOUNDARY: s++,\n\tHEADER_FIELD_START: s++,\n\tHEADER_FIELD: s++,\n\tHEADER_VALUE_START: s++,\n\tHEADER_VALUE: s++,\n\tHEADER_VALUE_ALMOST_DONE: s++,\n\tHEADERS_ALMOST_DONE: s++,\n\tPART_DATA_START: s++,\n\tPART_DATA: s++,\n\tEND: s++\n};\n\nlet f = 1;\nconst F = {\n\tPART_BOUNDARY: f,\n\tLAST_BOUNDARY: f *= 2\n};\n\nconst LF = 10;\nconst CR = 13;\nconst SPACE = 32;\nconst HYPHEN = 45;\nconst COLON = 58;\nconst A = 97;\nconst Z = 122;\n\nconst lower = c => c | 0x20;\n\nconst noop = () => {};\n\nclass MultipartParser {\n\t/**\n\t * @param {string} boundary\n\t */\n\tconstructor(boundary) {\n\t\tthis.index = 0;\n\t\tthis.flags = 0;\n\n\t\tthis.onHeaderEnd = noop;\n\t\tthis.onHeaderField = noop;\n\t\tthis.onHeadersEnd = noop;\n\t\tthis.onHeaderValue = noop;\n\t\tthis.onPartBegin = noop;\n\t\tthis.onPartData = noop;\n\t\tthis.onPartEnd = noop;\n\n\t\tthis.boundaryChars = {};\n\n\t\tboundary = '\\r\\n--' + boundary;\n\t\tconst ui8a = new Uint8Array(boundary.length);\n\t\tfor (let i = 0; i < boundary.length; i++) {\n\t\t\tui8a[i] = boundary.charCodeAt(i);\n\t\t\tthis.boundaryChars[ui8a[i]] = true;\n\t\t}\n\n\t\tthis.boundary = ui8a;\n\t\tthis.lookbehind = new Uint8Array(this.boundary.length + 8);\n\t\tthis.state = S.START_BOUNDARY;\n\t}\n\n\t/**\n\t * @param {Uint8Array} data\n\t */\n\twrite(data) {\n\t\tlet i = 0;\n\t\tconst length_ = data.length;\n\t\tlet previousIndex = this.index;\n\t\tlet {lookbehind, boundary, boundaryChars, index, state, flags} = this;\n\t\tconst boundaryLength = this.boundary.length;\n\t\tconst boundaryEnd = boundaryLength - 1;\n\t\tconst bufferLength = data.length;\n\t\tlet c;\n\t\tlet cl;\n\n\t\tconst mark = name => {\n\t\t\tthis[name + 'Mark'] = i;\n\t\t};\n\n\t\tconst clear = name => {\n\t\t\tdelete this[name + 'Mark'];\n\t\t};\n\n\t\tconst callback = (callbackSymbol, start, end, ui8a) => {\n\t\t\tif (start === undefined || start !== end) {\n\t\t\t\tthis[callbackSymbol](ui8a && ui8a.subarray(start, end));\n\t\t\t}\n\t\t};\n\n\t\tconst dataCallback = (name, clear) => {\n\t\t\tconst markSymbol = name + 'Mark';\n\t\t\tif (!(markSymbol in this)) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (clear) {\n\t\t\t\tcallback(name, this[markSymbol], i, data);\n\t\t\t\tdelete this[markSymbol];\n\t\t\t} else {\n\t\t\t\tcallback(name, this[markSymbol], data.length, data);\n\t\t\t\tthis[markSymbol] = 0;\n\t\t\t}\n\t\t};\n\n\t\tfor (i = 0; i < length_; i++) {\n\t\t\tc = data[i];\n\n\t\t\tswitch (state) {\n\t\t\t\tcase S.START_BOUNDARY:\n\t\t\t\t\tif (index === boundary.length - 2) {\n\t\t\t\t\t\tif (c === HYPHEN) {\n\t\t\t\t\t\t\tflags |= F.LAST_BOUNDARY;\n\t\t\t\t\t\t} else if (c !== CR) {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tindex++;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t} else if (index - 1 === boundary.length - 2) {\n\t\t\t\t\t\tif (flags & F.LAST_BOUNDARY && c === HYPHEN) {\n\t\t\t\t\t\t\tstate = S.END;\n\t\t\t\t\t\t\tflags = 0;\n\t\t\t\t\t\t} else if (!(flags & F.LAST_BOUNDARY) && c === LF) {\n\t\t\t\t\t\t\tindex = 0;\n\t\t\t\t\t\t\tcallback('onPartBegin');\n\t\t\t\t\t\t\tstate = S.HEADER_FIELD_START;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (c !== boundary[index + 2]) {\n\t\t\t\t\t\tindex = -2;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (c === boundary[index + 2]) {\n\t\t\t\t\t\tindex++;\n\t\t\t\t\t}\n\n\t\t\t\t\tbreak;\n\t\t\t\tcase S.HEADER_FIELD_START:\n\t\t\t\t\tstate = S.HEADER_FIELD;\n\t\t\t\t\tmark('onHeaderField');\n\t\t\t\t\tindex = 0;\n\t\t\t\t\t// falls through\n\t\t\t\tcase S.HEADER_FIELD:\n\t\t\t\t\tif (c === CR) {\n\t\t\t\t\t\tclear('onHeaderField');\n\t\t\t\t\t\tstate = S.HEADERS_ALMOST_DONE;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tindex++;\n\t\t\t\t\tif (c === HYPHEN) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (c === COLON) {\n\t\t\t\t\t\tif (index === 1) {\n\t\t\t\t\t\t\t// empty header field\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tdataCallback('onHeaderField', true);\n\t\t\t\t\t\tstate = S.HEADER_VALUE_START;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcl = lower(c);\n\t\t\t\t\tif (cl < A || cl > Z) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tbreak;\n\t\t\t\tcase S.HEADER_VALUE_START:\n\t\t\t\t\tif (c === SPACE) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tmark('onHeaderValue');\n\t\t\t\t\tstate = S.HEADER_VALUE;\n\t\t\t\t\t// falls through\n\t\t\t\tcase S.HEADER_VALUE:\n\t\t\t\t\tif (c === CR) {\n\t\t\t\t\t\tdataCallback('onHeaderValue', true);\n\t\t\t\t\t\tcallback('onHeaderEnd');\n\t\t\t\t\t\tstate = S.HEADER_VALUE_ALMOST_DONE;\n\t\t\t\t\t}\n\n\t\t\t\t\tbreak;\n\t\t\t\tcase S.HEADER_VALUE_ALMOST_DONE:\n\t\t\t\t\tif (c !== LF) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tstate = S.HEADER_FIELD_START;\n\t\t\t\t\tbreak;\n\t\t\t\tcase S.HEADERS_ALMOST_DONE:\n\t\t\t\t\tif (c !== LF) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tcallback('onHeadersEnd');\n\t\t\t\t\tstate = S.PART_DATA_START;\n\t\t\t\t\tbreak;\n\t\t\t\tcase S.PART_DATA_START:\n\t\t\t\t\tstate = S.PART_DATA;\n\t\t\t\t\tmark('onPartData');\n\t\t\t\t\t// falls through\n\t\t\t\tcase S.PART_DATA:\n\t\t\t\t\tpreviousIndex = index;\n\n\t\t\t\t\tif (index === 0) {\n\t\t\t\t\t\t// boyer-moore derrived algorithm to safely skip non-boundary data\n\t\t\t\t\t\ti += boundaryEnd;\n\t\t\t\t\t\twhile (i < bufferLength && !(data[i] in boundaryChars)) {\n\t\t\t\t\t\t\ti += boundaryLength;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\ti -= boundaryEnd;\n\t\t\t\t\t\tc = data[i];\n\t\t\t\t\t}\n\n\t\t\t\t\tif (index < boundary.length) {\n\t\t\t\t\t\tif (boundary[index] === c) {\n\t\t\t\t\t\t\tif (index === 0) {\n\t\t\t\t\t\t\t\tdataCallback('onPartData', true);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tindex++;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tindex = 0;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (index === boundary.length) {\n\t\t\t\t\t\tindex++;\n\t\t\t\t\t\tif (c === CR) {\n\t\t\t\t\t\t\t// CR = part boundary\n\t\t\t\t\t\t\tflags |= F.PART_BOUNDARY;\n\t\t\t\t\t\t} else if (c === HYPHEN) {\n\t\t\t\t\t\t\t// HYPHEN = end boundary\n\t\t\t\t\t\t\tflags |= F.LAST_BOUNDARY;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tindex = 0;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (index - 1 === boundary.length) {\n\t\t\t\t\t\tif (flags & F.PART_BOUNDARY) {\n\t\t\t\t\t\t\tindex = 0;\n\t\t\t\t\t\t\tif (c === LF) {\n\t\t\t\t\t\t\t\t// unset the PART_BOUNDARY flag\n\t\t\t\t\t\t\t\tflags &= ~F.PART_BOUNDARY;\n\t\t\t\t\t\t\t\tcallback('onPartEnd');\n\t\t\t\t\t\t\t\tcallback('onPartBegin');\n\t\t\t\t\t\t\t\tstate = S.HEADER_FIELD_START;\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else if (flags & F.LAST_BOUNDARY) {\n\t\t\t\t\t\t\tif (c === HYPHEN) {\n\t\t\t\t\t\t\t\tcallback('onPartEnd');\n\t\t\t\t\t\t\t\tstate = S.END;\n\t\t\t\t\t\t\t\tflags = 0;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tindex = 0;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tindex = 0;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (index > 0) {\n\t\t\t\t\t\t// when matching a possible boundary, keep a lookbehind reference\n\t\t\t\t\t\t// in case it turns out to be a false lead\n\t\t\t\t\t\tlookbehind[index - 1] = c;\n\t\t\t\t\t} else if (previousIndex > 0) {\n\t\t\t\t\t\t// if our boundary turned out to be rubbish, the captured lookbehind\n\t\t\t\t\t\t// belongs to partData\n\t\t\t\t\t\tconst _lookbehind = new Uint8Array(lookbehind.buffer, lookbehind.byteOffset, lookbehind.byteLength);\n\t\t\t\t\t\tcallback('onPartData', 0, previousIndex, _lookbehind);\n\t\t\t\t\t\tpreviousIndex = 0;\n\t\t\t\t\t\tmark('onPartData');\n\n\t\t\t\t\t\t// reconsider the current character even so it interrupted the sequence\n\t\t\t\t\t\t// it could be the beginning of a new sequence\n\t\t\t\t\t\ti--;\n\t\t\t\t\t}\n\n\t\t\t\t\tbreak;\n\t\t\t\tcase S.END:\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error(`Unexpected state entered: ${state}`);\n\t\t\t}\n\t\t}\n\n\t\tdataCallback('onHeaderField');\n\t\tdataCallback('onHeaderValue');\n\t\tdataCallback('onPartData');\n\n\t\t// Update properties for the next call\n\t\tthis.index = index;\n\t\tthis.state = state;\n\t\tthis.flags = flags;\n\t}\n\n\tend() {\n\t\tif ((this.state === S.HEADER_FIELD_START && this.index === 0) ||\n\t\t\t(this.state === S.PART_DATA && this.index === this.boundary.length)) {\n\t\t\tthis.onPartEnd();\n\t\t} else if (this.state !== S.END) {\n\t\t\tthrow new Error('MultipartParser.end(): stream ended unexpectedly');\n\t\t}\n\t}\n}\n\nfunction _fileName(headerValue) {\n\t// matches either a quoted-string or a token (RFC 2616 section 19.5.1)\n\tconst m = headerValue.match(/\\bfilename=(\"(.*?)\"|([^()<>@,;:\\\\\"/[\\]?={}\\s\\t]+))($|;\\s)/i);\n\tif (!m) {\n\t\treturn;\n\t}\n\n\tconst match = m[2] || m[3] || '';\n\tlet filename = match.slice(match.lastIndexOf('\\\\') + 1);\n\tfilename = filename.replace(/%22/g, '\"');\n\tfilename = filename.replace(/&#(\\d{4});/g, (m, code) => {\n\t\treturn String.fromCharCode(code);\n\t});\n\treturn filename;\n}\n\nexport async function toFormData(Body, ct) {\n\tif (!/multipart/i.test(ct)) {\n\t\tthrow new TypeError('Failed to fetch');\n\t}\n\n\tconst m = ct.match(/boundary=(?:\"([^\"]+)\"|([^;]+))/i);\n\n\tif (!m) {\n\t\tthrow new TypeError('no or bad content-type header, no multipart boundary');\n\t}\n\n\tconst parser = new MultipartParser(m[1] || m[2]);\n\n\tlet headerField;\n\tlet headerValue;\n\tlet entryValue;\n\tlet entryName;\n\tlet contentType;\n\tlet filename;\n\tconst entryChunks = [];\n\tconst formData = new FormData();\n\n\tconst onPartData = ui8a => {\n\t\tentryValue += decoder.decode(ui8a, {stream: true});\n\t};\n\n\tconst appendToFile = ui8a => {\n\t\tentryChunks.push(ui8a);\n\t};\n\n\tconst appendFileToFormData = () => {\n\t\tconst file = new File(entryChunks, filename, {type: contentType});\n\t\tformData.append(entryName, file);\n\t};\n\n\tconst appendEntryToFormData = () => {\n\t\tformData.append(entryName, entryValue);\n\t};\n\n\tconst decoder = new TextDecoder('utf-8');\n\tdecoder.decode();\n\n\tparser.onPartBegin = function () {\n\t\tparser.onPartData = onPartData;\n\t\tparser.onPartEnd = appendEntryToFormData;\n\n\t\theaderField = '';\n\t\theaderValue = '';\n\t\tentryValue = '';\n\t\tentryName = '';\n\t\tcontentType = '';\n\t\tfilename = null;\n\t\tentryChunks.length = 0;\n\t};\n\n\tparser.onHeaderField = function (ui8a) {\n\t\theaderField += decoder.decode(ui8a, {stream: true});\n\t};\n\n\tparser.onHeaderValue = function (ui8a) {\n\t\theaderValue += decoder.decode(ui8a, {stream: true});\n\t};\n\n\tparser.onHeaderEnd = function () {\n\t\theaderValue += decoder.decode();\n\t\theaderField = headerField.toLowerCase();\n\n\t\tif (headerField === 'content-disposition') {\n\t\t\t// matches either a quoted-string or a token (RFC 2616 section 19.5.1)\n\t\t\tconst m = headerValue.match(/\\bname=(\"([^\"]*)\"|([^()<>@,;:\\\\\"/[\\]?={}\\s\\t]+))/i);\n\n\t\t\tif (m) {\n\t\t\t\tentryName = m[2] || m[3] || '';\n\t\t\t}\n\n\t\t\tfilename = _fileName(headerValue);\n\n\t\t\tif (filename) {\n\t\t\t\tparser.onPartData = appendToFile;\n\t\t\t\tparser.onPartEnd = appendFileToFormData;\n\t\t\t}\n\t\t} else if (headerField === 'content-type') {\n\t\t\tcontentType = headerValue;\n\t\t}\n\n\t\theaderValue = '';\n\t\theaderField = '';\n\t};\n\n\tfor await (const chunk of Body) {\n\t\tparser.write(chunk);\n\t}\n\n\tparser.end();\n\n\treturn formData;\n}\n"],"x_google_ignoreList":[0],"mappings":";;;;AA+TA,SAAS,UAAU,aAAa;CAE/B,MAAM,IAAI,YAAY,MAAM,4DAA4D;CACxF,IAAI,CAAC,GACJ;CAGD,MAAM,QAAQ,EAAE,MAAM,EAAE,MAAM;CAC9B,IAAI,WAAW,MAAM,MAAM,MAAM,YAAY,IAAI,IAAI,CAAC;CACtD,WAAW,SAAS,QAAQ,QAAQ,IAAG;CACvC,WAAW,SAAS,QAAQ,gBAAgB,GAAG,SAAS;EACvD,OAAO,OAAO,aAAa,IAAI;CAChC,CAAC;CACD,OAAO;AACR;AAEA,eAAsB,WAAW,MAAM,IAAI;CAC1C,IAAI,CAAC,aAAa,KAAK,EAAE,GACxB,MAAM,IAAI,UAAU,iBAAiB;CAGtC,MAAM,IAAI,GAAG,MAAM,iCAAiC;CAEpD,IAAI,CAAC,GACJ,MAA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OACD,OAAO,IAAI,QAAQ,EAAE,eAAe;QACnC,IAAI,MAAM,QAAQ;SACjB,SAAS,WAAW;SACpB,QAAQ,EAAE;SACV,QAAQ;QACT,OACC,QAAQ;OAEV,OACC,QAAQ;MAEV;MAEA,IAAI,QAAQ,GAGX,WAAW,QAAQ,KAAK;WAClB,IAAI,gBAAgB,GAAG;OAG7B,MAAM,cAAc,IAAI,WAAW,WAAW,QAAQ,WAAW,YAAY,WAAW,UAAU;OAClG,SAAS,cAAc,GAAG,eAAe,WAAW;OACpD,gBAAgB;OAChB,KAAK,YAAY;OAIjB;MACD;MAEA;KACD,KAAK,EAAE,KACN;KACD,SACC,MAAM,IAAI,MAAM,6BAA6B,OAAO;IACtD;GACD;GAEA,aAAa,eAAe;GAC5B,aAAa,eAAe;GAC5B,aAAa,YAAY;GAGzB,KAAK,QAAQ;GACb,KAAK,QAAQ;GACb,KAAK,QAAQ;EACd;EAEA,MAAM;GACL,IAAK,KAAK,UAAU,EAAE,sBAAsB,KAAK,UAAU,KACzD,KAAK,UAAU,EAAE,aAAa,KAAK,UAAU,KAAK,SAAS,QAC5D,KAAK,UAAU;QACT,IAAI,KAAK,UAAU,EAAE,KAC3B,MAAM,IAAI,MAAM,kDAAkD;EAEpE;CACD"}
@@ -1,7 +1,7 @@
1
1
 
2
2
  import { mkdir, rename, writeFile } from "node:fs/promises";
3
3
  import { dirname } from "node:path";
4
- import { readFileSync } from "node:fs";
4
+ import { existsSync, readFileSync } from "node:fs";
5
5
  //#region src/compat/vendor/pi-ai-abort.ts
6
6
  function abortReason(signal) {
7
7
  if (signal.reason !== void 0) return signal.reason;
@@ -323,7 +323,7 @@ function oauthInteraction(ui, signal) {
323
323
  };
324
324
  }
325
325
  function oauthConfigOf(providerConfig) {
326
- const oauth = providerConfig?.oauth;
326
+ const oauth = providerConfig?.oauth ?? (providerConfig?.auth)?.oauth;
327
327
  return typeof oauth === "object" && oauth !== null && typeof oauth.login === "function" ? oauth : void 0;
328
328
  }
329
329
  function oauthAdapterOf(oauthConfig) {
@@ -353,7 +353,23 @@ async function storedOAuthCredential(store, providerId) {
353
353
  const stored = await store.read(providerId, void 0);
354
354
  return stored?.type === "oauth" ? stored : void 0;
355
355
  }
356
+ async function resolvePiProviderAuth(options) {
357
+ const oauthConfig = oauthConfigOf(options.providerConfig);
358
+ const declaredApiKey = options.providerConfig.auth?.apiKey;
359
+ if (oauthConfig === void 0 && declaredApiKey === void 0) return void 0;
360
+ const auth = {};
361
+ if (oauthConfig !== void 0) auth.oauth = oauthAdapterOf(oauthConfig);
362
+ if (declaredApiKey !== void 0) auth.apiKey = declaredApiKey;
363
+ return await resolveProviderAuth({
364
+ id: options.providerId,
365
+ name: options.providerName ?? options.providerId,
366
+ auth
367
+ }, options.store, {
368
+ env: async (name) => process.env[name],
369
+ fileExists: async (path) => existsSync(path)
370
+ }, options.signal !== void 0 ? { signal: options.signal } : void 0);
371
+ }
356
372
  //#endregion
357
- export { storedOAuthCredential as a, resolveOAuthApiKey as i, loginPiProvider as n, providerSupportsOAuth as r, FileCredentialStore as t };
373
+ export { resolvePiProviderAuth as a, resolveOAuthApiKey as i, loginPiProvider as n, storedOAuthCredential as o, providerSupportsOAuth as r, FileCredentialStore as t };
358
374
 
359
- //# sourceMappingURL=oauth-bridge-BpPrppjR.mjs.map
375
+ //# sourceMappingURL=oauth-bridge-C6fL1qSv.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth-bridge-C6fL1qSv.mjs","names":["#path","#persist"],"sources":["../src/compat/vendor/pi-ai-abort.ts","../src/compat/vendor/pi-ai-credential-store.ts","../src/compat/vendor/pi-ai-diagnostics.ts","../src/compat/vendor/pi-ai-auth-resolve.ts","../src/compat/vendor/pi-oauth-adapt.ts","../src/oauth-bridge.ts"],"sourcesContent":["// @ts-nocheck — vendored Pi source (pi-ai utils/abort.js @0.84.1, MIT, see ./PI-LICENSE); unchanged.\nfunction abortReason(signal) {\n if (signal.reason !== undefined)\n return signal.reason;\n const error = new Error(\"The operation was aborted\");\n error.name = \"AbortError\";\n return error;\n}\n/** Create an operation-local signal for public APIs whose signal is optional. */\nexport function operationSignal(signal) {\n return signal ?? new AbortController().signal;\n}\n/**\n * Stop waiting for an operation when its signal aborts while continuing to\n * observe the abandoned promise so a later rejection is always handled.\n */\nexport function raceWithAbortSignal(operation, signal) {\n if (signal.aborted) {\n void operation.catch(() => { });\n return Promise.reject(abortReason(signal));\n }\n return new Promise((resolve, reject) => {\n let settled = false;\n const cleanup = () => signal.removeEventListener(\"abort\", onAbort);\n const onAbort = () => {\n if (settled)\n return;\n settled = true;\n cleanup();\n reject(abortReason(signal));\n };\n signal.addEventListener(\"abort\", onAbort, { once: true });\n void operation.then((value) => {\n if (settled)\n return;\n settled = true;\n cleanup();\n resolve(value);\n }, (error) => {\n if (settled)\n return;\n settled = true;\n cleanup();\n reject(error);\n });\n if (signal.aborted)\n onAbort();\n });\n}\n//# sourceMappingURL=abort.js.map","// @ts-nocheck — vendored Pi source (pi-ai auth/credential-store.js @0.84.1, MIT, see ./PI-LICENSE); import remapped, logic unchanged.\nimport { operationSignal, raceWithAbortSignal } from './pi-ai-abort.js';\n/**\n * Default in-memory credential store. Apps inject persistent stores.\n * Keyed by `Provider.id`, one credential per provider; see `CredentialStore`.\n * Writes are serialized per provider through a promise chain.\n */\nexport class InMemoryCredentialStore {\n credentials = new Map();\n chains = new Map();\n /** Serialize tasks per provider id without releasing the chain before active work settles. */\n enqueue(providerId, task, options) {\n const signal = operationSignal(options?.signal);\n const previous = this.chains.get(providerId) ?? Promise.resolve();\n const queued = (async () => {\n await previous.catch(() => { });\n signal.throwIfAborted();\n return task();\n })();\n const tail = queued.catch(() => { });\n this.chains.set(providerId, tail);\n void tail.then(() => {\n if (this.chains.get(providerId) === tail)\n this.chains.delete(providerId);\n });\n return raceWithAbortSignal(queued, signal);\n }\n async read(providerId, options) {\n options?.signal?.throwIfAborted();\n return this.credentials.get(providerId);\n }\n async list(options) {\n options?.signal?.throwIfAborted();\n return [...this.credentials].map(([providerId, credential]) => ({ providerId, type: credential.type }));\n }\n modify(providerId, fn, options) {\n return this.enqueue(providerId, async () => {\n const current = this.credentials.get(providerId);\n const next = await fn(current);\n options?.signal?.throwIfAborted();\n if (next !== undefined)\n this.credentials.set(providerId, next);\n return next ?? current;\n }, options);\n }\n delete(providerId, options) {\n return this.enqueue(providerId, async () => {\n this.credentials.delete(providerId);\n }, options);\n }\n}\n//# sourceMappingURL=credential-store.js.map","// @ts-nocheck — vendored Pi source (pi-ai utils/diagnostics.js @0.84.1, MIT, see ./PI-LICENSE); unchanged.\nexport function formatThrownValue(value) {\n if (value instanceof Error)\n return value.message || value.name;\n if (typeof value === \"string\")\n return value;\n return String(value);\n}\nexport function extractDiagnosticError(error) {\n if (!(error instanceof Error))\n return { name: \"ThrownValue\", message: formatThrownValue(error) };\n const code = error.code;\n return {\n name: error.name || undefined,\n message: error.message || error.name,\n stack: error.stack,\n code: typeof code === \"string\" || typeof code === \"number\" ? code : undefined,\n };\n}\nexport function createAssistantMessageDiagnostic(type, error, details) {\n return { type, timestamp: Date.now(), error: extractDiagnosticError(error), details };\n}\nexport function appendAssistantMessageDiagnostic(message, diagnostic) {\n message.diagnostics = [...(message.diagnostics ?? []), diagnostic];\n}\n//# sourceMappingURL=diagnostics.js.map","// @ts-nocheck — vendored Pi source (pi-ai auth/resolve.js @0.84.1, MIT, see ./PI-LICENSE); imports remapped, logic unchanged\n// (double-checked-lock OAuth refresh with persistence, no silent env fallback).\nimport { operationSignal, raceWithAbortSignal } from './pi-ai-abort.js';\nimport { formatThrownValue } from './pi-ai-diagnostics.js';\nexport class ModelsError extends Error {\n code;\n constructor(code, message, options) {\n super(withCauseDetail(message, options?.cause), options);\n this.name = \"ModelsError\";\n this.code = code;\n }\n}\n/** Callers surface `error.message` only, so keep the underlying reason in it. */\nfunction withCauseDetail(message, cause) {\n if (cause === undefined || cause === null)\n return message;\n const detail = formatThrownValue(cause).trim();\n if (!detail || message.includes(detail))\n return message;\n return `${message}: ${detail}`;\n}\n/**\n * Auth resolution shared by the `Models` and `ImagesModels` collections.\n * A stored credential owns the provider: ambient/env is consulted only when\n * nothing is stored. No silent env fallback after a failed refresh or for a\n * credential type without a matching handler.\n */\nexport function resolveProviderAuth(provider, credentials, authContext, overrides) {\n const signal = operationSignal(overrides?.signal);\n return raceWithAbortSignal(resolveProviderAuthWithSignal(provider, credentials, authContext, overrides, signal), signal);\n}\nasync function resolveProviderAuthWithSignal(provider, credentials, authContext, overrides, signal) {\n signal.throwIfAborted();\n const requestAuthContext = overrides?.env ? overlayEnvAuthContext(authContext, overrides.env) : authContext;\n if (overrides?.apiKey !== undefined && provider.auth.apiKey) {\n return resolveApiKey(requestAuthContext, provider.auth.apiKey, provider.id, {\n type: \"api_key\",\n key: overrides.apiKey,\n env: overrides.env,\n }, signal);\n }\n const stored = await readCredential(credentials, provider.id, signal);\n if (stored) {\n if (stored.type === \"oauth\" && provider.auth.oauth) {\n return resolveStoredOAuth(credentials, provider.id, provider.auth.oauth, stored, signal, overrides?.minOAuthValidityMs);\n }\n if (stored.type === \"api_key\" && provider.auth.apiKey) {\n const credential = overrides?.env ? { ...stored, env: { ...stored.env, ...overrides.env } } : stored;\n return resolveApiKey(requestAuthContext, provider.auth.apiKey, provider.id, credential, signal);\n }\n return undefined;\n }\n // Ambient (env vars, AWS profiles, ADC files).\n return provider.auth.apiKey\n ? resolveApiKey(requestAuthContext, provider.auth.apiKey, provider.id, undefined, signal)\n : undefined;\n}\nfunction overlayEnvAuthContext(base, env) {\n return {\n env: async (name) => env[name] || (await base.env(name)),\n fileExists: (path) => base.fileExists(path),\n };\n}\nconst DEFAULT_OAUTH_MINIMUM_VALIDITY_MS = 5 * 60 * 1000;\nconst DEFAULT_OAUTH_REFRESH_TIMEOUT_MS = 15_000;\n/**\n * OAuth resolution with double-checked locking: tokens with less than five\n * minutes remaining lock, re-check expiry under the lock, refresh once\n * globally, and persist the rotated credential before release.\n */\nasync function resolveStoredOAuth(credentials, providerId, oauth, stored, signal, minOAuthValidityMs) {\n const minimumValidityMs = Math.max(DEFAULT_OAUTH_MINIMUM_VALIDITY_MS, minOAuthValidityMs ?? 0);\n const expiresSoon = (credential) => Date.now() + minimumValidityMs >= credential.expires;\n let credential = stored;\n if (expiresSoon(credential)) {\n // Optimistic check said expired; the authoritative check runs under the lock.\n let post;\n try {\n post = await credentials.modify(providerId, async (current) => {\n if (current?.type !== \"oauth\")\n return undefined; // logged out meanwhile\n if (!expiresSoon(current))\n return undefined; // another process/request refreshed\n try {\n const refreshSignal = AbortSignal.any([\n signal,\n AbortSignal.timeout(DEFAULT_OAUTH_REFRESH_TIMEOUT_MS),\n ]);\n return await oauth.refresh(current, refreshSignal);\n }\n catch (error) {\n throw new ModelsError(\"oauth\", `OAuth refresh failed for ${providerId}`, { cause: error });\n }\n }, { signal });\n }\n catch (error) {\n if (error instanceof ModelsError)\n throw error;\n throw new ModelsError(\"auth\", `Credential store modify failed for ${providerId}`, { cause: error });\n }\n if (post?.type !== \"oauth\")\n return undefined; // logged out meanwhile\n credential = post;\n // The normal five-minute window triggers a refresh but does not impose a\n // provider contract. Explicit callers (such as bearer-token export) do\n // require the requested minimum after the refresh.\n if (minOAuthValidityMs !== undefined && expiresSoon(credential)) {\n throw new ModelsError(\"oauth\", `OAuth refresh returned a token that expires too soon for ${providerId}`);\n }\n }\n try {\n return { auth: await oauth.toAuth(credential), source: \"OAuth\" };\n }\n catch (error) {\n throw new ModelsError(\"oauth\", `OAuth auth derivation failed for ${providerId}`, { cause: error });\n }\n}\nasync function resolveApiKey(authContext, apiKey, providerId, credential, signal) {\n try {\n return await apiKey.resolve({ ctx: authContext, credential, signal });\n }\n catch (error) {\n throw new ModelsError(\"auth\", `API key auth failed for provider ${providerId}`, { cause: error });\n }\n}\nasync function readCredential(credentials, providerId, signal) {\n try {\n return await credentials.read(providerId, { signal });\n }\n catch (error) {\n throw new ModelsError(\"auth\", `Credential store read failed for ${providerId}`, { cause: error });\n }\n}\n//# sourceMappingURL=resolve.js.map","// @ts-nocheck — vendored Pi source excerpt (pi-coding-agent core/provider-composer.js adaptOAuth @0.84.1, MIT, see ./PI-LICENSE); logic unchanged.\n// The official two-generation adapter: extension oauth callbacks (onAuth/onDeviceCode/onPrompt/onSelect)\n// over the pi-ai interaction surface (prompt/notify/signal), plus refresh and toAuth->getApiKey.\nexport function adaptOAuth(config) {\n return {\n name: config.name,\n isSubscription: config.isSubscription,\n login: async (callbacks) => {\n const credential = await config.login({\n onAuth: (info) => callbacks.notify({ type: \"auth_url\", ...info }),\n onDeviceCode: (info) => callbacks.notify({ type: \"device_code\", ...info }),\n onPrompt: (prompt) => callbacks.prompt({ type: \"text\", ...prompt }),\n onProgress: (message) => callbacks.notify({ type: \"progress\", message }),\n onManualCodeInput: () => callbacks.prompt({ type: \"manual_code\", message: \"Paste the authorization code\" }),\n onSelect: (prompt) => callbacks.prompt({ type: \"select\", ...prompt }),\n signal: callbacks.signal,\n });\n return { ...credential, type: \"oauth\" };\n },\n refresh: async (credential, signal) => ({ ...(await config.refreshToken(credential, signal)), type: \"oauth\" }),\n toAuth: async (credential) => ({ apiKey: config.getApiKey(credential) }),\n };\n}\n","import { existsSync, readFileSync } from 'node:fs'\nimport { mkdir, rename, writeFile } from 'node:fs/promises'\nimport { dirname } from 'node:path'\nimport { InMemoryCredentialStore } from './compat/vendor/pi-ai-credential-store.js'\nimport { resolveProviderAuth } from './compat/vendor/pi-ai-auth-resolve.js'\nimport { adaptOAuth } from './compat/vendor/pi-oauth-adapt.js'\n\ntype UnknownRecord = Record<string, unknown>\n\n// The interactive OAuth host seam, four layers with one owner each:\n// L1 protocol — the package's own oauth.login/refreshToken/getApiKey code\n// runs verbatim (device-code, auth-code, rotation). The\n// bridge implements zero protocol.\n// L2 interaction— Pi's official adaptOAuth (vendored) turns the package's\n// callbacks into prompt/notify events; this file routes\n// those onto the Pi ui surface, which pi2dsh already maps\n// to DSH userQuestions with real waits.\n// L3 credentials— Pi's auth.json contract: one file keyed by provider id,\n// 0600, atomic replace, per-provider serialized writes\n// (the vendored InMemoryCredentialStore chain), refresh via\n// Pi's vendored double-checked-lock resolver.\n// L4 routing — resolveOAuthApiKey yields the request key for dsh-llm's\n// one-shot credential seam; tokens never enter DSH settings.\n\nexport class FileCredentialStore extends InMemoryCredentialStore {\n readonly #path: string\n\n constructor(path: string) {\n super()\n this.#path = path\n try {\n const data = JSON.parse(readFileSync(path, 'utf8')) as Record<string, UnknownRecord>\n for (const [providerId, credential] of Object.entries(data)) {\n ;(this as unknown as { credentials: Map<string, unknown> }).credentials.set(providerId, credential)\n }\n } catch {\n // Missing or unreadable auth.json starts empty, exactly like Pi.\n }\n }\n\n get path(): string {\n return this.#path\n }\n\n async #persist(): Promise<void> {\n const credentials = (this as unknown as { credentials: Map<string, unknown> }).credentials\n const data = Object.fromEntries(credentials)\n await mkdir(dirname(this.#path), { recursive: true })\n // Atomic replace so a crash mid-write never truncates the store; 0600 so\n // tokens stay owner-readable only. Same contract Pi's file store keeps.\n const temp = `${this.#path}.tmp-${process.pid}-${Math.floor(Math.random() * 1e9).toString(36)}`\n await writeFile(temp, `${JSON.stringify(data, null, 2)}\\n`, { mode: 0o600 })\n await rename(temp, this.#path)\n }\n\n override modify(providerId: string, fn: (current: unknown) => unknown, options?: UnknownRecord): Promise<unknown> {\n // The vendored per-provider chain already serializes writers; persisting\n // inside the chained task keeps disk order identical to memory order.\n return super.modify(providerId, async (current: unknown) => {\n const next = await fn(current)\n if (next !== undefined) {\n const credentials = (this as unknown as { credentials: Map<string, unknown> }).credentials\n credentials.set(providerId, next)\n await this.#persist()\n }\n return next\n }, options)\n }\n\n override delete(providerId: string, options?: UnknownRecord): Promise<void> {\n return super.delete(providerId, options).then(() => this.#persist()) as Promise<void>\n }\n}\n\nexport interface OAuthUiSurface {\n input(title: unknown, placeholder?: unknown): Promise<string | undefined>\n select(title: unknown, options: unknown[]): Promise<string | undefined>\n notify(message: unknown): void\n}\n\ninterface OAuthPromptEvent {\n type: 'text' | 'manual_code' | 'select'\n message: string\n placeholder?: string\n options?: Array<{ id: string, label: string }>\n}\n\ninterface OAuthNotifyEvent {\n type: 'auth_url' | 'device_code' | 'progress'\n url?: string\n instructions?: string\n userCode?: string\n verificationUri?: string\n message?: string\n}\n\n// The pi-ai interaction surface ({prompt, notify, signal}) over the Pi ui\n// surface pi2dsh already maps to DSH userQuestions.\nexport function oauthInteraction(ui: OAuthUiSurface, signal?: AbortSignal): {\n prompt(prompt: OAuthPromptEvent): Promise<string | undefined>\n notify(event: OAuthNotifyEvent): void\n signal: AbortSignal\n} {\n // Pi hosts always hand flows a live signal; flows attach abort listeners\n // unconditionally, so an absent caller signal becomes a never-aborting one.\n const effectiveSignal = signal ?? new AbortController().signal\n return {\n signal: effectiveSignal,\n async prompt(prompt) {\n if (prompt.type === 'select') {\n const options = prompt.options ?? []\n const picked = await ui.select(prompt.message, options.map(option => option.label))\n return options.find(option => option.label === picked)?.id ?? picked\n }\n return ui.input(prompt.message, prompt.placeholder)\n },\n notify(event) {\n if (event.type === 'auth_url') {\n ui.notify(`Open this URL to authorize: ${event.url}${event.instructions !== undefined ? `\\n${event.instructions}` : ''}`)\n } else if (event.type === 'device_code') {\n ui.notify(`Visit ${event.verificationUri} and enter code ${event.userCode}`)\n } else if (event.message !== undefined) {\n ui.notify(event.message)\n }\n },\n }\n}\n\nfunction oauthConfigOf(providerConfig: UnknownRecord | undefined): UnknownRecord | undefined {\n // Extension-generation configs carry oauth at the top level; pi-ai\n // createProvider() objects carry it under auth.oauth. Pi accepts both.\n const oauth = providerConfig?.oauth\n ?? (providerConfig?.auth as UnknownRecord | undefined)?.oauth\n return typeof oauth === 'object' && oauth !== null && typeof (oauth as UnknownRecord).login === 'function'\n ? oauth as UnknownRecord\n : undefined\n}\n\n// Pi accepts both oauth generations: pi-ai native flows carry toAuth and take\n// the interaction surface directly; extension configs carry getApiKey and go\n// through Pi's adaptOAuth (vendored). Same acceptance here.\nfunction oauthAdapterOf(oauthConfig: UnknownRecord): {\n login(interaction: unknown): Promise<UnknownRecord>\n refresh(credential: unknown, signal?: AbortSignal): Promise<UnknownRecord>\n toAuth(credential: unknown): Promise<UnknownRecord>\n} {\n if (typeof oauthConfig.toAuth === 'function') {\n return oauthConfig as never\n }\n return adaptOAuth(oauthConfig) as never\n}\n\nexport function providerSupportsOAuth(providerConfig: UnknownRecord | undefined): boolean {\n return oauthConfigOf(providerConfig) !== undefined\n}\n\n// Pi models.login semantics: find the provider's oauth surface, run the\n// package's own login through the vendored adapter, persist through the\n// store's serialized modify.\nexport async function loginPiProvider(options: {\n providerId: string\n providerName?: string\n providerConfig: UnknownRecord\n store: FileCredentialStore\n ui: OAuthUiSurface\n signal?: AbortSignal\n}): Promise<UnknownRecord> {\n const oauthConfig = oauthConfigOf(options.providerConfig)\n if (oauthConfig === undefined) {\n throw new Error(`${options.providerName ?? options.providerId} does not support oauth login`)\n }\n const adapter = oauthAdapterOf(oauthConfig)\n const credential = await adapter.login(oauthInteraction(options.ui, options.signal))\n await options.store.modify(options.providerId, async () => credential)\n return credential\n}\n\n// Pi's resolveProviderAuth over the stored credential: five-minute expiry\n// window, double-checked-lock refresh through the package's own refreshToken,\n// rotated credential persisted before release, key derived by the package's\n// own getApiKey. Returns undefined when nothing is stored.\nexport async function resolveOAuthApiKey(options: {\n providerId: string\n providerName?: string\n providerConfig: UnknownRecord\n store: FileCredentialStore\n signal?: AbortSignal\n}): Promise<string | undefined> {\n const oauthConfig = oauthConfigOf(options.providerConfig)\n if (oauthConfig === undefined) return undefined\n const provider = {\n id: options.providerId,\n name: options.providerName ?? options.providerId,\n auth: { oauth: oauthAdapterOf(oauthConfig) },\n }\n const resolved = await resolveProviderAuth(\n provider,\n options.store,\n { env: async () => undefined },\n options.signal !== undefined ? { signal: options.signal } : undefined,\n ) as { auth?: { apiKey?: string } } | undefined\n return resolved?.auth?.apiKey\n}\n\nexport async function storedOAuthCredential(store: FileCredentialStore, providerId: string): Promise<UnknownRecord | undefined> {\n const stored = await store.read(providerId, undefined) as UnknownRecord | undefined\n return stored?.type === 'oauth' ? stored : undefined\n}\n\n// Pi's FULL getProviderAuth precedence over the vendored resolver — stored\n// OAuth (double-checked-lock refresh), then stored api_key, then the\n// provider's own auth.apiKey ambient resolution (its resolve() reads env vars\n// and probes credential files through the auth context). The package's\n// resolve code runs verbatim; the bridge supplies only the context.\nexport async function resolvePiProviderAuth(options: {\n providerId: string\n providerName?: string\n providerConfig: UnknownRecord\n store: FileCredentialStore\n signal?: AbortSignal\n}): Promise<{ auth?: UnknownRecord, source?: string } | undefined> {\n const oauthConfig = oauthConfigOf(options.providerConfig)\n const declaredApiKey = (options.providerConfig.auth as UnknownRecord | undefined)?.apiKey\n if (oauthConfig === undefined && declaredApiKey === undefined) return undefined\n const auth: UnknownRecord = {}\n if (oauthConfig !== undefined) auth.oauth = oauthAdapterOf(oauthConfig)\n if (declaredApiKey !== undefined) auth.apiKey = declaredApiKey\n const provider = { id: options.providerId, name: options.providerName ?? options.providerId, auth }\n return await resolveProviderAuth(\n provider,\n options.store,\n {\n env: async (name: string) => process.env[name],\n fileExists: async (path: string) => existsSync(path),\n },\n options.signal !== undefined ? { signal: options.signal } : undefined,\n ) as { auth?: UnknownRecord, source?: string } | undefined\n}\n"],"mappings":";;;;;AACA,SAAS,YAAY,QAAQ;CACzB,IAAI,OAAO,WAAW,KAAA,GAClB,OAAO,OAAO;CAClB,MAAM,wBAAQ,IAAI,MAAM,2BAA2B;CACnD,MAAM,OAAO;CACb,OAAO;AACX;;AAEA,SAAgB,gBAAgB,QAAQ;CACpC,OAAO,UAAU,IAAI,gBAAgB,CAAC,CAAC;AAC3C;;;;;AAKA,SAAgB,oBAAoB,WAAW,QAAQ;CACnD,IAAI,OAAO,SAAS;EAChB,UAAe,YAAY,CAAE,CAAC;EAC9B,OAAO,QAAQ,OAAO,YAAY,MAAM,CAAC;CAC7C;CACA,OAAO,IAAI,SAAS,SAAS,WAAW;EACpC,IAAI,UAAU;EACd,MAAM,gBAAgB,OAAO,oBAA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