@dorokuma/magpie-gemini-web 0.0.0-stage → 0.15.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.
- package/CHANGELOG.md +188 -0
- package/LICENSE +21 -0
- package/LICENSE-AISTUDIO +21 -0
- package/LICENSE-UPSTREAM +21 -0
- package/README.en.md +278 -0
- package/README.md +281 -2
- package/docs/backend-release.md +62 -0
- package/docs/logo.svg +16 -0
- package/docs/studio-release.md +312 -0
- package/index.mjs +285 -0
- package/lib/backend-release.json +31 -0
- package/lib/backend.mjs +731 -0
- package/lib/cite.mjs +166 -0
- package/lib/cleanup-detached.cjs +69 -0
- package/lib/cleanup.mjs +515 -0
- package/lib/native.mjs +734 -0
- package/lib/setup.mjs +261 -0
- package/lib/studio-connect-legacy.mjs +273 -0
- package/lib/studio-connect.mjs +269 -0
- package/lib/studio-native.mjs +2543 -0
- package/lib/studio-page.mjs +173 -0
- package/lib/studio-release.json +122 -0
- package/lib/studio-updates.mjs +320 -0
- package/lib/studio-upstream.mjs +135 -0
- package/lib/studio.mjs +1170 -0
- package/lib/usage.mjs +322 -0
- package/package.json +96 -4
- package/patches/studio-0.2.17-preserve-request-bodies.patch +190 -0
- package/patches/studio-0.2.19-managed-config.patch +121 -0
- package/patches/studio-0.3.4-magpie-signin.patch +676 -0
- package/patches/studio-0.3.5-signin-reauth.patch +25 -0
- package/patches/studio-0.3.7-magpie-signin.patch +676 -0
- package/patches/studio-0.3.7-managed-config.patch +121 -0
- package/patches/studio-0.3.7-signin-reauth.patch +25 -0
- package/scripts/backend-smoke.mjs +123 -0
- package/scripts/backend.mjs +57 -0
- package/scripts/studio-archive.go +92 -0
- package/scripts/studio-auto-update-smoke.mjs +116 -0
- package/scripts/studio-lifecycle-smoke.mjs +149 -0
- package/scripts/studio-managed-smoke.mjs +198 -0
- package/scripts/studio-official-smoke.mjs +12 -0
- package/scripts/studio-pins.mjs +52 -0
- package/scripts/studio-regzip.go +75 -0
- package/scripts/studio-release.mjs +287 -0
- package/scripts/studio-signin-candidate.json +102 -0
- package/scripts/studio-smoke.mjs +195 -0
- package/scripts/studio-update-smoke.mjs +82 -0
- package/scripts/studio-user-smoke.mjs +206 -0
- package/scripts/studio.mjs +468 -0
- package/scripts/sync-backend-pins.mjs +217 -0
package/lib/backend.mjs
ADDED
|
@@ -0,0 +1,731 @@
|
|
|
1
|
+
import { citeStream, citeJSON } from './cite.mjs';
|
|
2
|
+
import { validateProxyURL } from './setup.mjs';
|
|
3
|
+
|
|
4
|
+
export const DEFAULT_BASE = 'http://127.0.0.1:8083/v1';
|
|
5
|
+
export const PLUGIN_ICON = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIj48ZGVmcz48bGluZWFyR3JhZGllbnQgaWQ9ImEiIHgxPSIyIiB5MT0iMyIgeDI9IjIwIiB5Mj0iMjEiIGdyYWRpZW50VW5pdHM9InVzZXJTcGFjZU9uVXNlIj48c3RvcCBvZmZzZXQ9IjAlIiBzdG9wLWNvbG9yPSIjMDZCNkQ0Ii8+PHN0b3Agb2Zmc2V0PSI1MCUiIHN0b3AtY29sb3I9IiMzQjgyRjYiLz48c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiM4QjVDRjYiLz48L2xpbmVhckdyYWRpZW50PjxsaW5lYXJHcmFkaWVudCBpZD0iYiIgeDE9IjE0IiB5MT0iMiIgeDI9IjIyIiB5Mj0iMTAiIGdyYWRpZW50VW5pdHM9InVzZXJTcGFjZU9uVXNlIj48c3RvcCBvZmZzZXQ9IjAlIiBzdG9wLWNvbG9yPSIjOEI1Q0Y2Ii8+PHN0b3Agb2Zmc2V0PSIxMDAlIiBzdG9wLWNvbG9yPSIjRUM0ODk5Ii8+PC9saW5lYXJHcmFkaWVudD48L2RlZnM+PHBhdGggZD0iTTEwIDMuMkMxMC4zNSAzLjIgMTAuNjIgMy40NSAxMC43MiAzLjhDMTEuNDUgNi44NSAxMy4xNSA4LjU1IDE2LjIgOS4yOEMxNi41NSA5LjM4IDE2LjggOS42NSAxNi44IDEwQzE2LjggMTAuMzUgMTYuNTUgMTAuNjIgMTYuMiAxMC43MkMxMy4xNSAxMS40NSAxMS40NSAxMy4xNSAxMC43MiAxNi4yQzEwLjYyIDE2LjU1IDEwLjM1IDE2LjggMTAgMTYuOEM5LjY1IDE2LjggOS4zOCAxNi41NSA5LjI4IDE2LjJDOC41NSAxMy4xNSA2Ljg1IDExLjQ1IDMuOCAxMC43MkMzLjQ1IDEwLjYyIDMuMiAxMC4zNSAzLjIgMTBDMy4yIDkuNjUgMy40NSA5LjM4IDMuOCA5LjI4QzYuODUgOC41NSA4LjU1IDYuODUgOS4yOCAzLjhDOS4zOCAzLjQ1IDkuNjUgMy4yIDEwIDMuMloiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0wLjUgMi41KSBzY2FsZSgxLjEyKSIgZmlsbD0idXJsKCNhKSIvPjxwYXRoIGQ9Ik0xOC4yIDEuOEMxOC40MiAxLjggMTguNiAxLjk1IDE4LjY2IDIuMTZDMTkuMDggMy44MiAyMC4wMiA0Ljc2IDIxLjY4IDUuMThDMjEuODkgNS4yNCAyMi4wNCA1LjQyIDIyLjA0IDUuNjRDMjIuMDQgNS44NiAyMS44OSA2LjA0IDIxLjY4IDYuMUMyMC4wMiA2LjUyIDE5LjA4IDcuNDYgMTguNjYgOS4xMkMxOC42IDkuMzMgMTguNDIgOS40OCAxOC4yIDkuNDhDMTcuOTggOS40OCAxNy44IDkuMzMgMTcuNzQgOS4xMkMxNy4zMiA3LjQ2IDE2LjM4IDYuNTIgMTQuNzIgNi4xQzE0LjUxIDYuMDQgMTQuMzYgNS44NiAxNC4zNiA1LjY0QzE0LjM2IDUuNDIgMTQuNTEgNS4yNCAxNC43MiA1LjE4QzE2LjM4IDQuNzYgMTcuMzIgMy44MiAxNy43NCAyLjE2QzE3LjggMS45NSAxNy45OCAxLjggMTguMiAxLjhaIiBmaWxsPSJ1cmwoI2IpIi8+PGNpcmNsZSBjeD0iMTcuOCIgY3k9IjE4LjIiIHI9IjEuMzUiIGZpbGw9IiM2MzY2RjEiLz48L3N2Zz4=';
|
|
6
|
+
|
|
7
|
+
const MEDIA_SPECIAL = /(?:^|[-_])(image|music|canvas|video|research)(?:[-_]|$)/i;
|
|
8
|
+
const CONTROL_CHARS = /[\x00-\x1f\x7f]/;
|
|
9
|
+
const NEWLINE_CHARS = /[\r\n]/;
|
|
10
|
+
|
|
11
|
+
// The backend has no effort parameter: extended thinking uses separate "<id>-thinking-medium"
|
|
12
|
+
// and "<id>-thinking" models. A base model with such twins offers low (itself), medium (when
|
|
13
|
+
// "<id>-thinking-medium" exists), and high ("<id>-thinking"), while the twins aren't listed on
|
|
14
|
+
// their own; a request that names one directly still goes through. Magpie maps any other level
|
|
15
|
+
// to the nearest declared one before it reaches us; direct callers get the same rule.
|
|
16
|
+
const THINKING_SUFFIX = '-thinking';
|
|
17
|
+
const MEDIUM_THINKING_SUFFIX = '-thinking-medium';
|
|
18
|
+
const LOW_EFFORTS = new Set(['none', 'minimal', 'low']);
|
|
19
|
+
const MODEL_CACHE_MS = 10 * 60 * 1000;
|
|
20
|
+
const knownModels = new Map();
|
|
21
|
+
|
|
22
|
+
// Set on the 502 forward() returns when the backend can't be reached at all, so a caller that
|
|
23
|
+
// manages the backend can start it and retry.
|
|
24
|
+
export const UNREACHABLE_HEADER = 'X-Gemini-Web-Backend';
|
|
25
|
+
|
|
26
|
+
const KNOWN_OPTIONS = new Set([
|
|
27
|
+
'baseURL',
|
|
28
|
+
'proxy',
|
|
29
|
+
'allowTools',
|
|
30
|
+
'allowImages',
|
|
31
|
+
'contextLimit',
|
|
32
|
+
'outputLimit',
|
|
33
|
+
'requestTimeoutMs',
|
|
34
|
+
'modelTimeoutMs',
|
|
35
|
+
'stripCitations'
|
|
36
|
+
]);
|
|
37
|
+
|
|
38
|
+
export function makeOpenAIError(status, message, extraHeaders = {}) {
|
|
39
|
+
const codeMap = {
|
|
40
|
+
400: 'invalid_request_error',
|
|
41
|
+
401: 'unauthorized',
|
|
42
|
+
404: 'not_found',
|
|
43
|
+
502: 'bad_gateway',
|
|
44
|
+
504: 'gateway_timeout'
|
|
45
|
+
};
|
|
46
|
+
const body = JSON.stringify({
|
|
47
|
+
error: {
|
|
48
|
+
message,
|
|
49
|
+
type: status >= 500 ? 'api_error' : 'invalid_request_error',
|
|
50
|
+
param: null,
|
|
51
|
+
code: codeMap[status] || null
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
const headers = new Headers({
|
|
55
|
+
'content-type': 'application/json',
|
|
56
|
+
...extraHeaders
|
|
57
|
+
});
|
|
58
|
+
if (status === 401) {
|
|
59
|
+
headers.set('X-Magpie-Sign-In', 'expired');
|
|
60
|
+
}
|
|
61
|
+
return new Response(body, { status, headers });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function normalizeBaseURL(value) {
|
|
65
|
+
if (typeof value !== 'string') {
|
|
66
|
+
throw new Error('Invalid base URL: must be a string');
|
|
67
|
+
}
|
|
68
|
+
const trimmed = value.trim();
|
|
69
|
+
if (!trimmed) {
|
|
70
|
+
throw new Error('Invalid base URL: must not be empty');
|
|
71
|
+
}
|
|
72
|
+
let parsed;
|
|
73
|
+
try {
|
|
74
|
+
parsed = new URL(trimmed);
|
|
75
|
+
} catch {
|
|
76
|
+
throw new Error('Invalid base URL: malformed URL');
|
|
77
|
+
}
|
|
78
|
+
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
|
|
79
|
+
throw new Error('Invalid base URL: protocol must be HTTP or HTTPS');
|
|
80
|
+
}
|
|
81
|
+
if (parsed.username || parsed.password) {
|
|
82
|
+
throw new Error('Invalid base URL: credentials not allowed in URL');
|
|
83
|
+
}
|
|
84
|
+
if (parsed.search) {
|
|
85
|
+
throw new Error('Invalid base URL: query parameters not allowed');
|
|
86
|
+
}
|
|
87
|
+
if (parsed.hash) {
|
|
88
|
+
throw new Error('Invalid base URL: URL fragment not allowed');
|
|
89
|
+
}
|
|
90
|
+
const isLoopback = parsed.hostname === 'localhost' || parsed.hostname === '127.0.0.1' || parsed.hostname === '[::1]';
|
|
91
|
+
if (parsed.protocol === 'http:' && !isLoopback) {
|
|
92
|
+
throw new Error('Invalid base URL: HTTP only allowed for local loopback (localhost, 127.0.0.1, [::1]); remote must use HTTPS');
|
|
93
|
+
}
|
|
94
|
+
let pathname = parsed.pathname;
|
|
95
|
+
while (pathname.length > 1 && pathname.endsWith('/')) {
|
|
96
|
+
pathname = pathname.slice(0, -1);
|
|
97
|
+
}
|
|
98
|
+
if (pathname === '/' || pathname === '') {
|
|
99
|
+
pathname = '/v1';
|
|
100
|
+
} else if (pathname === '/v1' || pathname.endsWith('/v1')) {
|
|
101
|
+
// valid
|
|
102
|
+
} else {
|
|
103
|
+
throw new Error('Invalid base URL: path must end in /v1 or be root');
|
|
104
|
+
}
|
|
105
|
+
return `${parsed.origin}${pathname}`;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function settings(options = {}) {
|
|
109
|
+
if (!options || typeof options !== 'object' || Array.isArray(options)) {
|
|
110
|
+
throw new Error('Plugin options must be an object');
|
|
111
|
+
}
|
|
112
|
+
for (const key of Object.keys(options)) {
|
|
113
|
+
if (!KNOWN_OPTIONS.has(key)) {
|
|
114
|
+
throw new Error(`Unknown plugin option: ${key}`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
let baseURL = DEFAULT_BASE;
|
|
119
|
+
if (options.baseURL !== undefined) {
|
|
120
|
+
baseURL = normalizeBaseURL(options.baseURL);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
let proxy = '';
|
|
124
|
+
if (options.proxy !== undefined) {
|
|
125
|
+
proxy = validateProxyURL(options.proxy);
|
|
126
|
+
} else if (process.env.GEMINI_WEB_PROXY) {
|
|
127
|
+
proxy = validateProxyURL(process.env.GEMINI_WEB_PROXY);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// On by default: coding agents send tools with every request and don't read toolcall,
|
|
131
|
+
// so turning this off only means every one of their requests gets a 400.
|
|
132
|
+
let allowTools = true;
|
|
133
|
+
if (options.allowTools !== undefined) {
|
|
134
|
+
if (typeof options.allowTools !== 'boolean') {
|
|
135
|
+
throw new Error('Invalid option allowTools: must be a boolean');
|
|
136
|
+
}
|
|
137
|
+
allowTools = options.allowTools;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// On by default: multimodal chat models read images in a chat.
|
|
141
|
+
let allowImages = true;
|
|
142
|
+
if (options.allowImages !== undefined) {
|
|
143
|
+
if (typeof options.allowImages !== 'boolean') {
|
|
144
|
+
throw new Error('Invalid option allowImages: must be a boolean');
|
|
145
|
+
}
|
|
146
|
+
allowImages = options.allowImages;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
let contextLimit = 1000000;
|
|
150
|
+
if (options.contextLimit !== undefined) {
|
|
151
|
+
if (!Number.isInteger(options.contextLimit) || options.contextLimit <= 0) {
|
|
152
|
+
throw new Error('Invalid option contextLimit: must be a positive integer');
|
|
153
|
+
}
|
|
154
|
+
contextLimit = options.contextLimit;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
let outputLimit = 8192;
|
|
158
|
+
if (options.outputLimit !== undefined) {
|
|
159
|
+
if (!Number.isInteger(options.outputLimit) || options.outputLimit <= 0) {
|
|
160
|
+
throw new Error('Invalid option outputLimit: must be a positive integer');
|
|
161
|
+
}
|
|
162
|
+
outputLimit = options.outputLimit;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (outputLimit > contextLimit) {
|
|
166
|
+
throw new Error('Invalid option outputLimit: cannot exceed contextLimit');
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// The backend sends nothing until a reply's first words, and Gemini Web can queue a request
|
|
170
|
+
// for minutes before them (3.6 Flash: 48 s to 6.5 minutes), sending the backend only a heartbeat
|
|
171
|
+
// a minute, which it waits through. The plugin can't tell that queue from a stuck backend, so
|
|
172
|
+
// it waits as long as it may: under the 10 minutes Magpie gives a provider to begin answering,
|
|
173
|
+
// so this timeout reaches the client rather than Magpie's. That also outlasts
|
|
174
|
+
// 4.26.0-magpie.1's three tries of 180 s each, 2 s apart: 544 s (#33).
|
|
175
|
+
let requestTimeoutMs = 570000;
|
|
176
|
+
if (options.requestTimeoutMs !== undefined) {
|
|
177
|
+
if (!Number.isInteger(options.requestTimeoutMs) || options.requestTimeoutMs <= 0) {
|
|
178
|
+
throw new Error('Invalid option requestTimeoutMs: must be a positive integer');
|
|
179
|
+
}
|
|
180
|
+
requestTimeoutMs = options.requestTimeoutMs;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
let modelTimeoutMs = 10000;
|
|
184
|
+
if (options.modelTimeoutMs !== undefined) {
|
|
185
|
+
if (!Number.isInteger(options.modelTimeoutMs) || options.modelTimeoutMs <= 0) {
|
|
186
|
+
throw new Error('Invalid option modelTimeoutMs: must be a positive integer');
|
|
187
|
+
}
|
|
188
|
+
modelTimeoutMs = options.modelTimeoutMs;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Gemini's citation markers come out of replies unless this is false: text that means them,
|
|
192
|
+
// as code about them does, would lose them too.
|
|
193
|
+
let stripCitations = true;
|
|
194
|
+
if (options.stripCitations !== undefined) {
|
|
195
|
+
if (typeof options.stripCitations !== 'boolean') {
|
|
196
|
+
throw new Error('Invalid option stripCitations: must be a boolean');
|
|
197
|
+
}
|
|
198
|
+
stripCitations = options.stripCitations;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return {
|
|
202
|
+
baseURL,
|
|
203
|
+
proxy,
|
|
204
|
+
allowTools,
|
|
205
|
+
allowImages,
|
|
206
|
+
contextLimit,
|
|
207
|
+
outputLimit,
|
|
208
|
+
requestTimeoutMs,
|
|
209
|
+
modelTimeoutMs,
|
|
210
|
+
stripCitations
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export function credentials(auth, opts) {
|
|
215
|
+
if (!auth || typeof auth !== 'object' || auth.type !== 'api') {
|
|
216
|
+
throw new Error('Invalid authentication: expected api type');
|
|
217
|
+
}
|
|
218
|
+
if (typeof auth.key !== 'string') {
|
|
219
|
+
throw new Error('API key must be a string');
|
|
220
|
+
}
|
|
221
|
+
if (NEWLINE_CHARS.test(auth.key)) {
|
|
222
|
+
throw new Error('API key must not contain newline characters');
|
|
223
|
+
}
|
|
224
|
+
const key = auth.key.trim();
|
|
225
|
+
if (key.length === 0) {
|
|
226
|
+
throw new Error('API key must not be empty');
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
let baseURL = opts?.baseURL || DEFAULT_BASE;
|
|
230
|
+
const metaBase = auth.metadata?.baseURL;
|
|
231
|
+
if (typeof metaBase === 'string' && metaBase.trim().length > 0) {
|
|
232
|
+
baseURL = normalizeBaseURL(metaBase);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return { key, baseURL };
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export async function listModels(c, opts) {
|
|
239
|
+
const url = `${c.baseURL}/models`;
|
|
240
|
+
let res;
|
|
241
|
+
try {
|
|
242
|
+
res = await fetch(url, {
|
|
243
|
+
method: 'GET',
|
|
244
|
+
headers: {
|
|
245
|
+
'Authorization': `Bearer ${c.key}`,
|
|
246
|
+
'Accept': 'application/json'
|
|
247
|
+
},
|
|
248
|
+
redirect: 'error',
|
|
249
|
+
signal: AbortSignal.timeout(opts.modelTimeoutMs)
|
|
250
|
+
});
|
|
251
|
+
} catch (err) {
|
|
252
|
+
const error = new Error('Failed to reach backend models endpoint: ' + (err?.message || err));
|
|
253
|
+
error.status = 502;
|
|
254
|
+
error.unreachable = true;
|
|
255
|
+
throw error;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
if (!res.ok) {
|
|
259
|
+
const error = new Error(`Failed to list models: HTTP ${res.status}`);
|
|
260
|
+
error.status = res.status;
|
|
261
|
+
if (res.status === 401) {
|
|
262
|
+
error.signIn = 'expired';
|
|
263
|
+
}
|
|
264
|
+
throw error;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
let body;
|
|
268
|
+
try {
|
|
269
|
+
body = await res.json();
|
|
270
|
+
} catch {
|
|
271
|
+
throw new Error('Invalid models response: failed to parse JSON');
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
if (!body || typeof body !== 'object' || !Array.isArray(body.data)) {
|
|
275
|
+
throw new Error('Invalid models response: expected data array');
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
const seen = new Set();
|
|
279
|
+
const validIds = [];
|
|
280
|
+
|
|
281
|
+
for (const item of body.data) {
|
|
282
|
+
if (!item || typeof item !== 'object' || typeof item.id !== 'string') {
|
|
283
|
+
throw new Error('Invalid model entry in response: expected object with string id');
|
|
284
|
+
}
|
|
285
|
+
const id = item.id;
|
|
286
|
+
if (!id || CONTROL_CHARS.test(id)) {
|
|
287
|
+
throw new Error('Invalid model entry in response: invalid id format');
|
|
288
|
+
}
|
|
289
|
+
if (!id.startsWith('gemini-')) {
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
if (MEDIA_SPECIAL.test(id)) {
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
if (seen.has(id)) {
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
seen.add(id);
|
|
299
|
+
validIds.push(id);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
if (validIds.length === 0) {
|
|
303
|
+
throw new Error('No usable Gemini models found in backend response');
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const ids = new Set(validIds);
|
|
307
|
+
knownModels.set(modelCacheKey(c), { ids, at: Date.now() });
|
|
308
|
+
|
|
309
|
+
const result = Object.create(null);
|
|
310
|
+
for (const id of validIds) {
|
|
311
|
+
if (id.endsWith(THINKING_SUFFIX) && ids.has(id.slice(0, -THINKING_SUFFIX.length))) continue;
|
|
312
|
+
if (id.endsWith(MEDIUM_THINKING_SUFFIX) && ids.has(id.slice(0, -MEDIUM_THINKING_SUFFIX.length))) continue;
|
|
313
|
+
const isTwin = id.endsWith(THINKING_SUFFIX) || id.endsWith(MEDIUM_THINKING_SUFFIX);
|
|
314
|
+
const hasMedium = !isTwin && ids.has(id + MEDIUM_THINKING_SUFFIX);
|
|
315
|
+
const hasHigh = !isTwin && ids.has(id + THINKING_SUFFIX);
|
|
316
|
+
const variants = {};
|
|
317
|
+
if (hasMedium || hasHigh) {
|
|
318
|
+
variants.low = {};
|
|
319
|
+
if (hasMedium) variants.medium = {};
|
|
320
|
+
if (hasHigh) variants.high = {};
|
|
321
|
+
}
|
|
322
|
+
result[id] = {
|
|
323
|
+
id,
|
|
324
|
+
providerID: 'gemini-web',
|
|
325
|
+
name: id,
|
|
326
|
+
api: {
|
|
327
|
+
id,
|
|
328
|
+
url: c.baseURL,
|
|
329
|
+
npm: '@ai-sdk/openai-compatible'
|
|
330
|
+
},
|
|
331
|
+
limit: {
|
|
332
|
+
context: opts.contextLimit,
|
|
333
|
+
output: opts.outputLimit
|
|
334
|
+
},
|
|
335
|
+
capabilities: {
|
|
336
|
+
temperature: false,
|
|
337
|
+
reasoning: true,
|
|
338
|
+
attachment: opts.allowImages,
|
|
339
|
+
toolcall: opts.allowTools,
|
|
340
|
+
input: {
|
|
341
|
+
text: true,
|
|
342
|
+
image: opts.allowImages
|
|
343
|
+
},
|
|
344
|
+
output: {
|
|
345
|
+
text: true
|
|
346
|
+
}
|
|
347
|
+
},
|
|
348
|
+
cost: {
|
|
349
|
+
input: 0,
|
|
350
|
+
output: 0,
|
|
351
|
+
cache: {
|
|
352
|
+
read: 0,
|
|
353
|
+
write: 0
|
|
354
|
+
}
|
|
355
|
+
},
|
|
356
|
+
options: {},
|
|
357
|
+
headers: {},
|
|
358
|
+
variants,
|
|
359
|
+
status: 'active'
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
return result;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
function modelCacheKey(c) {
|
|
367
|
+
return `${c.baseURL}\n${c.key}`;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// thinkingTwin returns the model a chat request should run on for its reasoning_effort, or null
|
|
371
|
+
// to leave it alone. The twin is only used when the backend lists it; if the list can't be
|
|
372
|
+
// fetched the request goes out unchanged.
|
|
373
|
+
async function thinkingTwin(body, c, opts) {
|
|
374
|
+
const effort = body.reasoning_effort;
|
|
375
|
+
const model = body.model;
|
|
376
|
+
if (typeof effort !== 'string' || LOW_EFFORTS.has(effort)) return null;
|
|
377
|
+
if (typeof model !== 'string' || model.endsWith(THINKING_SUFFIX) || model.endsWith(MEDIUM_THINKING_SUFFIX)) return null;
|
|
378
|
+
|
|
379
|
+
let cached = knownModels.get(modelCacheKey(c));
|
|
380
|
+
if (!cached || Date.now() - cached.at > MODEL_CACHE_MS) {
|
|
381
|
+
try {
|
|
382
|
+
await listModels(c, opts);
|
|
383
|
+
} catch {
|
|
384
|
+
return null;
|
|
385
|
+
}
|
|
386
|
+
cached = knownModels.get(modelCacheKey(c));
|
|
387
|
+
}
|
|
388
|
+
if (effort === 'medium' && cached?.ids.has(model + MEDIUM_THINKING_SUFFIX)) {
|
|
389
|
+
return model + MEDIUM_THINKING_SUFFIX;
|
|
390
|
+
}
|
|
391
|
+
const twin = model + THINKING_SUFFIX;
|
|
392
|
+
return cached?.ids.has(twin) ? twin : null;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// waitTimer aborts its signal when one wait on the backend, from start() to stop(), outlasts ms.
|
|
396
|
+
function waitTimer(ms) {
|
|
397
|
+
const controller = new AbortController();
|
|
398
|
+
let timeout;
|
|
399
|
+
return {
|
|
400
|
+
signal: controller.signal,
|
|
401
|
+
start() {
|
|
402
|
+
clearTimeout(timeout);
|
|
403
|
+
timeout = setTimeout(() => {
|
|
404
|
+
controller.abort(new DOMException(`The backend sent nothing for ${ms} ms`, 'TimeoutError'));
|
|
405
|
+
}, ms);
|
|
406
|
+
},
|
|
407
|
+
stop() {
|
|
408
|
+
clearTimeout(timeout);
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
// timedBody passes a response body on, timing each read from the backend with timer. Time the
|
|
414
|
+
// reader of the returned stream takes between reads doesn't count.
|
|
415
|
+
function timedBody(body, timer) {
|
|
416
|
+
const reader = body.getReader();
|
|
417
|
+
return new ReadableStream({
|
|
418
|
+
async pull(controller) {
|
|
419
|
+
timer.start();
|
|
420
|
+
let piece;
|
|
421
|
+
try {
|
|
422
|
+
piece = await reader.read();
|
|
423
|
+
} finally {
|
|
424
|
+
timer.stop();
|
|
425
|
+
}
|
|
426
|
+
if (piece.done) controller.close();
|
|
427
|
+
else controller.enqueue(piece.value);
|
|
428
|
+
},
|
|
429
|
+
cancel(reason) {
|
|
430
|
+
timer.stop();
|
|
431
|
+
return reader.cancel(reason);
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
// keyRefused says whether an error on Gemini's own API is the AI Studio service refusing the key.
|
|
437
|
+
// From 0.2.18 it says so as Gemini does: 400 API_KEY_INVALID for a wrong key, 403 for none. A 403
|
|
438
|
+
// from Google itself ("The caller does not have permission") is about the account, not the key.
|
|
439
|
+
function keyRefused(status, text) {
|
|
440
|
+
let error;
|
|
441
|
+
try {
|
|
442
|
+
const body = JSON.parse(text);
|
|
443
|
+
error = (Array.isArray(body) ? body[0] : body)?.error;
|
|
444
|
+
} catch {
|
|
445
|
+
return false;
|
|
446
|
+
}
|
|
447
|
+
if (status === 400) return Array.isArray(error?.details) && error.details.some(detail => detail?.reason === 'API_KEY_INVALID');
|
|
448
|
+
return error?.status === 'PERMISSION_DENIED' && /unregistered callers/.test(error.message);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
const GEMINI_CALL = /^\/models\/([^/:]+):(generateContent|streamGenerateContent)$/;
|
|
452
|
+
|
|
453
|
+
// geminiTarget is where a call on Gemini's own API goes at the AI Studio service, with the model
|
|
454
|
+
// it names: the service's /v1beta, beside the /v1 that baseURL always ends in. Magpie draws with
|
|
455
|
+
// an image model there (the model's npm is @ai-sdk/google, see listStudioModels), asking
|
|
456
|
+
// <baseURL>/models/<id>:streamGenerateContent?alt=sse. null for any other request, and for one
|
|
457
|
+
// with any other query.
|
|
458
|
+
function geminiTarget(url, baseURL) {
|
|
459
|
+
const base = new URL(baseURL);
|
|
460
|
+
if (url.origin !== base.origin || !url.pathname.startsWith(base.pathname + '/')) return null;
|
|
461
|
+
const m = GEMINI_CALL.exec(url.pathname.slice(base.pathname.length));
|
|
462
|
+
if (!m || url.hash || (url.search && url.search !== '?alt=sse')) return null;
|
|
463
|
+
let model;
|
|
464
|
+
try {
|
|
465
|
+
model = decodeURIComponent(m[1]);
|
|
466
|
+
} catch {
|
|
467
|
+
return null;
|
|
468
|
+
}
|
|
469
|
+
return { url: `${baseURL}beta/models/${m[1]}:${m[2]}${url.search}`, model };
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
// The line Magpie ends a drawing's prompt with when a size is asked for (drawPrompt): a ratio
|
|
473
|
+
// given as one, or the nearest of its usual ones to a WIDTHxHEIGHT size.
|
|
474
|
+
const ASPECT_LINE = /\n\nAspect ratio: (\d+(?:\.\d+)?):(\d+(?:\.\d+)?)\./;
|
|
475
|
+
|
|
476
|
+
// aspectRatio moves the aspect ratio a generateContent request's prompt names to
|
|
477
|
+
// imageConfig.aspectRatio, as one of aspects, the model's: the one named when the model takes it,
|
|
478
|
+
// else the nearest. With the line in its prompt, gemini-3.1-flash-lite-image (seen on
|
|
479
|
+
// AIStudio2API 0.2.17) answered with no image at all, each of three times; with imageConfig it
|
|
480
|
+
// drew. A request that names a ratio in imageConfig already is left as it is.
|
|
481
|
+
function aspectRatio(body, aspects) {
|
|
482
|
+
const config = body.generationConfig && typeof body.generationConfig === 'object' ? body.generationConfig : {};
|
|
483
|
+
if (config.imageConfig?.aspectRatio) return;
|
|
484
|
+
const contents = Array.isArray(body.contents) ? body.contents : [];
|
|
485
|
+
const content = contents.findLast(c => c?.role === 'user' && Array.isArray(c.parts));
|
|
486
|
+
const part = content?.parts.find(p => typeof p?.text === 'string' && ASPECT_LINE.test(p.text));
|
|
487
|
+
if (!part) return;
|
|
488
|
+
const [, w, h] = ASPECT_LINE.exec(part.text);
|
|
489
|
+
const asked = `${w}:${h}`;
|
|
490
|
+
const log = r => Math.log(Number(r.split(':')[0]) / Number(r.split(':')[1]));
|
|
491
|
+
const nearest = aspects.includes(asked)
|
|
492
|
+
? asked
|
|
493
|
+
: aspects.reduce((best, r) => Math.abs(log(r) - log(asked)) < Math.abs(log(best) - log(asked)) ? r : best);
|
|
494
|
+
part.text = part.text.replace(ASPECT_LINE, '');
|
|
495
|
+
body.generationConfig = { ...config, imageConfig: { ...config.imageConfig, aspectRatio: nearest } };
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
export async function forward(input, init, getAuth, opts) {
|
|
499
|
+
const req = new Request(input, init);
|
|
500
|
+
|
|
501
|
+
let auth;
|
|
502
|
+
try {
|
|
503
|
+
auth = await getAuth();
|
|
504
|
+
} catch {
|
|
505
|
+
return makeOpenAIError(401, 'Authentication loader failed');
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
if (!auth || auth.type !== 'api') {
|
|
509
|
+
return makeOpenAIError(401, 'Unauthorized: backend API key required');
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
let c;
|
|
513
|
+
try {
|
|
514
|
+
c = credentials(auth, opts);
|
|
515
|
+
} catch (err) {
|
|
516
|
+
return makeOpenAIError(401, 'Unauthorized: ' + err.message);
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
let reqUrl;
|
|
520
|
+
try {
|
|
521
|
+
reqUrl = new URL(req.url);
|
|
522
|
+
} catch {
|
|
523
|
+
return makeOpenAIError(400, 'Invalid request URL');
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
// AI Studio's image models are asked on Gemini's own API (opts.imageModel, see imageModelOf)
|
|
527
|
+
const gemini = opts.imageModel ? geminiTarget(reqUrl, c.baseURL) : null;
|
|
528
|
+
const geminiUrl = gemini?.url;
|
|
529
|
+
|
|
530
|
+
if ((reqUrl.search || reqUrl.hash) && !geminiUrl) {
|
|
531
|
+
return makeOpenAIError(400, 'Query parameters and fragments are not allowed');
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
const chatUrl = `${c.baseURL}/chat/completions`;
|
|
535
|
+
const modelsUrl = `${c.baseURL}/models`;
|
|
536
|
+
const incomingUrl = `${reqUrl.origin}${reqUrl.pathname}`;
|
|
537
|
+
|
|
538
|
+
if (incomingUrl !== chatUrl && incomingUrl !== modelsUrl && !geminiUrl) {
|
|
539
|
+
return makeOpenAIError(404, 'Endpoint not found');
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
if (incomingUrl === chatUrl && req.method !== 'POST') {
|
|
543
|
+
return makeOpenAIError(400, 'Method not allowed: /chat/completions requires POST');
|
|
544
|
+
}
|
|
545
|
+
if (geminiUrl && req.method !== 'POST') {
|
|
546
|
+
return makeOpenAIError(400, 'Method not allowed: generateContent requires POST');
|
|
547
|
+
}
|
|
548
|
+
if (incomingUrl === modelsUrl && req.method !== 'GET') {
|
|
549
|
+
return makeOpenAIError(400, 'Method not allowed: /models requires GET');
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
const headers = new Headers();
|
|
553
|
+
headers.set('Authorization', `Bearer ${c.key}`);
|
|
554
|
+
const accept = req.headers.get('accept');
|
|
555
|
+
if (accept) {
|
|
556
|
+
headers.set('accept', accept);
|
|
557
|
+
} else {
|
|
558
|
+
headers.set('accept', 'application/json');
|
|
559
|
+
}
|
|
560
|
+
const contentType = req.headers.get('content-type');
|
|
561
|
+
if (contentType) {
|
|
562
|
+
headers.set('content-type', contentType);
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
let rawBody = null;
|
|
566
|
+
if (incomingUrl === chatUrl) {
|
|
567
|
+
try {
|
|
568
|
+
rawBody = await req.text();
|
|
569
|
+
} catch {
|
|
570
|
+
return makeOpenAIError(400, 'Failed to read request body');
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
let body;
|
|
574
|
+
try {
|
|
575
|
+
body = JSON.parse(rawBody);
|
|
576
|
+
} catch {
|
|
577
|
+
return makeOpenAIError(400, 'Invalid JSON body');
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
if (!body || typeof body !== 'object' || Array.isArray(body)) {
|
|
581
|
+
return makeOpenAIError(400, 'Request body must be a JSON object');
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
const hasTools = (Array.isArray(body.tools) && body.tools.length > 0) ||
|
|
585
|
+
(Array.isArray(body.functions) && body.functions.length > 0);
|
|
586
|
+
if (!opts.allowTools && hasTools) {
|
|
587
|
+
return makeOpenAIError(400, `Tool calls are turned off for magpie-gemini-web. Turn them on with: magpie plugin options @dorokuma/magpie-gemini-web '{"allowTools":true}'`);
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
if (body.messages !== undefined) {
|
|
591
|
+
if (!Array.isArray(body.messages)) {
|
|
592
|
+
return makeOpenAIError(400, 'messages must be an array');
|
|
593
|
+
}
|
|
594
|
+
for (const msg of body.messages) {
|
|
595
|
+
if (!msg || typeof msg !== 'object') {
|
|
596
|
+
return makeOpenAIError(400, 'Message entries must be objects');
|
|
597
|
+
}
|
|
598
|
+
if (Array.isArray(msg.content)) {
|
|
599
|
+
for (const part of msg.content) {
|
|
600
|
+
if (!part || typeof part !== 'object') {
|
|
601
|
+
return makeOpenAIError(400, 'Message content parts must be objects');
|
|
602
|
+
}
|
|
603
|
+
if (part.type === 'text') {
|
|
604
|
+
if (typeof part.text !== 'string') {
|
|
605
|
+
return makeOpenAIError(400, 'Text content must contain a text string');
|
|
606
|
+
}
|
|
607
|
+
} else if (part.type === 'image_url') {
|
|
608
|
+
if (!opts.allowImages) {
|
|
609
|
+
return makeOpenAIError(400, `Image input is turned off for magpie-gemini-web. Turn it on with: magpie plugin options @dorokuma/magpie-gemini-web '{"allowImages":true}'`);
|
|
610
|
+
}
|
|
611
|
+
if (!part.image_url || typeof part.image_url.url !== 'string' || !part.image_url.url.trim()) {
|
|
612
|
+
return makeOpenAIError(400, 'Image content must contain an image_url URL');
|
|
613
|
+
}
|
|
614
|
+
} else {
|
|
615
|
+
return makeOpenAIError(400, 'Unsupported content type; only text and image_url are supported');
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
} else if (msg.content !== null && msg.content !== undefined && typeof msg.content !== 'string') {
|
|
619
|
+
return makeOpenAIError(400, 'Message content must be string or array of parts');
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
const twin = opts.nativeThinking ? null : await thinkingTwin(body, c, opts);
|
|
625
|
+
if (twin) {
|
|
626
|
+
body.model = twin;
|
|
627
|
+
rawBody = JSON.stringify(body);
|
|
628
|
+
}
|
|
629
|
+
} else if (geminiUrl) {
|
|
630
|
+
try {
|
|
631
|
+
rawBody = await req.text();
|
|
632
|
+
} catch {
|
|
633
|
+
return makeOpenAIError(400, 'Failed to read request body');
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
let body;
|
|
637
|
+
try {
|
|
638
|
+
body = JSON.parse(rawBody);
|
|
639
|
+
} catch {
|
|
640
|
+
return makeOpenAIError(400, 'Invalid JSON body');
|
|
641
|
+
}
|
|
642
|
+
if (!body || typeof body !== 'object' || Array.isArray(body)) {
|
|
643
|
+
return makeOpenAIError(400, 'Request body must be a JSON object');
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
if (!opts.allowTools && Array.isArray(body.tools) && body.tools.length > 0) {
|
|
647
|
+
return makeOpenAIError(400, `Tool calls are turned off for magpie-gemini-web. Turn them on with: magpie plugin options @dorokuma/magpie-gemini-web '{"allowTools":true}'`);
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
// A text model is asked on chat completions, where allowImages holds. One the service's list
|
|
651
|
+
// can't tell of goes no further: an unreachable service is answered as one, for a managed one
|
|
652
|
+
// to be started again (forwardManagedStudio).
|
|
653
|
+
let aspects;
|
|
654
|
+
try {
|
|
655
|
+
aspects = await opts.imageModel(c, gemini.model);
|
|
656
|
+
} catch (err) {
|
|
657
|
+
if (err?.unreachable) {
|
|
658
|
+
return makeOpenAIError(502, 'Bad gateway: failed to reach backend service', { [UNREACHABLE_HEADER]: 'unreachable' });
|
|
659
|
+
}
|
|
660
|
+
if (err?.signIn === 'expired') {
|
|
661
|
+
return makeOpenAIError(401, 'Unauthorized: AI Studio refused the key');
|
|
662
|
+
}
|
|
663
|
+
return makeOpenAIError(503, `Can't tell whether ${gemini.model} is one of AI Studio's image models: ${err?.message || err}`);
|
|
664
|
+
}
|
|
665
|
+
if (!aspects) {
|
|
666
|
+
return makeOpenAIError(400, `${gemini.model} isn't one of AI Studio's image models: generateContent here is for those alone, and a text model is asked on /chat/completions`);
|
|
667
|
+
}
|
|
668
|
+
aspectRatio(body, aspects);
|
|
669
|
+
rawBody = JSON.stringify(body);
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
// requestTimeoutMs bounds each wait on the backend, for the response headers and then for each
|
|
673
|
+
// piece of the body, so a long streamed reply that keeps coming is never cut off.
|
|
674
|
+
const timer = waitTimer(opts.requestTimeoutMs);
|
|
675
|
+
const signal = AbortSignal.any([req.signal, timer.signal]);
|
|
676
|
+
|
|
677
|
+
let upstreamRes;
|
|
678
|
+
timer.start();
|
|
679
|
+
try {
|
|
680
|
+
// Bun's fetch drops a connection idle for 300 s; the timer sets the deadline instead.
|
|
681
|
+
upstreamRes = await fetch(geminiUrl || incomingUrl, {
|
|
682
|
+
method: req.method,
|
|
683
|
+
headers,
|
|
684
|
+
body: rawBody,
|
|
685
|
+
signal,
|
|
686
|
+
redirect: 'error',
|
|
687
|
+
timeout: false
|
|
688
|
+
});
|
|
689
|
+
} catch (err) {
|
|
690
|
+
if (req.signal.aborted) {
|
|
691
|
+
throw req.signal.reason || new DOMException('The operation was aborted.', 'AbortError');
|
|
692
|
+
}
|
|
693
|
+
if (timer.signal.aborted || err?.name === 'TimeoutError') {
|
|
694
|
+
return makeOpenAIError(504, 'Gateway timeout: backend request timed out');
|
|
695
|
+
}
|
|
696
|
+
if (err?.name === 'AbortError') {
|
|
697
|
+
throw err;
|
|
698
|
+
}
|
|
699
|
+
return makeOpenAIError(502, 'Bad gateway: failed to reach backend service', { [UNREACHABLE_HEADER]: 'unreachable' });
|
|
700
|
+
} finally {
|
|
701
|
+
timer.stop();
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
const respHeaders = new Headers(upstreamRes.headers);
|
|
705
|
+
respHeaders.delete('content-encoding');
|
|
706
|
+
respHeaders.delete('content-length');
|
|
707
|
+
if (upstreamRes.status === 401) {
|
|
708
|
+
respHeaders.set('X-Magpie-Sign-In', 'expired');
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
// Gemini's citation markers come out of a chat reply, streamed or whole (see cite.mjs).
|
|
712
|
+
let respBody = upstreamRes.body && timedBody(upstreamRes.body, timer);
|
|
713
|
+
if (geminiUrl && (upstreamRes.status === 400 || upstreamRes.status === 403) && respBody) {
|
|
714
|
+
const text = await new Response(respBody).text();
|
|
715
|
+
if (keyRefused(upstreamRes.status, text)) {
|
|
716
|
+
return makeOpenAIError(401, 'Unauthorized: AI Studio refused the key');
|
|
717
|
+
}
|
|
718
|
+
respBody = text;
|
|
719
|
+
}
|
|
720
|
+
if (opts.stripCitations && incomingUrl === chatUrl && upstreamRes.ok && respBody) {
|
|
721
|
+
const type = upstreamRes.headers.get('content-type') || '';
|
|
722
|
+
if (type.includes('text/event-stream')) respBody = citeStream(respBody);
|
|
723
|
+
else if (type.includes('json')) respBody = citeJSON(await new Response(respBody).text());
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
return new Response(respBody, {
|
|
727
|
+
status: upstreamRes.status,
|
|
728
|
+
statusText: upstreamRes.statusText,
|
|
729
|
+
headers: respHeaders
|
|
730
|
+
});
|
|
731
|
+
}
|