@bodhiapp/bodhi-js-ext 0.0.41 → 0.0.43
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/dist/bodhi-ext.cjs.js +1 -1
- package/dist/bodhi-ext.esm.js +239 -239
- package/dist/ext2ext-client.d.ts +1 -0
- package/package.json +4 -4
package/dist/bodhi-ext.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { DirectClientBase as
|
|
1
|
+
import { DirectClientBase as z, createStoragePrefixWithNamespace as X, STORAGE_PREFIXES as N, generateCodeVerifier as w, generateCodeChallenge as V, buildAuthorizeUrl as v, BASE_OAUTH_SCOPE as L, buildErrorUrl as b, AccessRequestBuilder as P, unwrapResponse as k, buildReviewUrl as O, createOperationError as d, throwAccessRequestDenialError as M, PENDING_EXTENSION_READY as f, Logger as x, NOOP_STATE_CALLBACK as Q, createExtensionStateNotInitialized as G, BACKEND_SERVER_NOT_REACHABLE as K, createExtensionStateNotFound as F, BodhiError as T, INITIAL_AUTH_STATE as H, BodhiApiError as W, Chat as J, Models as Y, Embeddings as j, Mcps as Z, isAuthError as ee, BaseFacadeClient as te, refreshAccessToken as re } from "@bodhiapp/bodhi-js-core";
|
|
2
2
|
import { InMemoryStorage as Ae } from "@bodhiapp/bodhi-js-core";
|
|
3
|
-
import { isExtError as y, isApiSuccessResponse as se, MESSAGE_TYPES as _, EXT_ACTIONS as
|
|
3
|
+
import { isExtError as y, isApiSuccessResponse as se, MESSAGE_TYPES as _, EXT_ACTIONS as ie, BODHI_STREAM_PORT as oe, isStreamChunk as ne, isStreamApiError as ae, isStreamError as he, BODHI_STREAM_TEXT_PORT as ce } from "@bodhiapp/bodhi-browser-types";
|
|
4
4
|
const a = {
|
|
5
5
|
EXT2EXT_CLIENT_REQUEST: "EXT2EXT_CLIENT_REQUEST",
|
|
6
6
|
EXT2EXT_CLIENT_RESPONSE: "EXT2EXT_CLIENT_RESPONSE",
|
|
@@ -42,12 +42,12 @@ class _e {
|
|
|
42
42
|
await chrome.storage.session.remove(e);
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
-
class me extends
|
|
45
|
+
class me extends z {
|
|
46
46
|
constructor(e, t) {
|
|
47
47
|
const r = X(
|
|
48
48
|
e.basePath,
|
|
49
49
|
N.EXT_DIRECT
|
|
50
|
-
),
|
|
50
|
+
), o = {
|
|
51
51
|
authClientId: e.authClientId,
|
|
52
52
|
authServerUrl: e.authServerUrl,
|
|
53
53
|
storagePrefix: r,
|
|
@@ -57,47 +57,47 @@ class me extends V {
|
|
|
57
57
|
storage: e.storage ?? new _e(),
|
|
58
58
|
initialTokens: e.initialTokens
|
|
59
59
|
};
|
|
60
|
-
super(
|
|
60
|
+
super(o, t);
|
|
61
61
|
}
|
|
62
62
|
// ============================================================================
|
|
63
63
|
// Authentication (chrome.identity OAuth)
|
|
64
64
|
// ============================================================================
|
|
65
65
|
async login(e) {
|
|
66
66
|
const t = await this.getAuthState();
|
|
67
|
-
if (t.status === "authenticated")
|
|
67
|
+
if (t.status === "authenticated" && !e?.reauthorize)
|
|
68
68
|
return t;
|
|
69
|
-
const r = e?.userRole ?? "scope_user_user",
|
|
69
|
+
const r = e?.userRole ?? "scope_user_user", o = this._getRedirectUri();
|
|
70
70
|
e?.onProgress?.("requesting");
|
|
71
|
-
const s = w(),
|
|
71
|
+
const s = w(), i = await V(s), n = w();
|
|
72
72
|
await this._storageSet({
|
|
73
73
|
[this.storageKeys.CODE_VERIFIER]: s,
|
|
74
74
|
[this.storageKeys.STATE]: n
|
|
75
75
|
});
|
|
76
|
-
const
|
|
76
|
+
const c = v(this.authEndpoints, {
|
|
77
77
|
clientId: this.authClientId,
|
|
78
|
-
redirectUri:
|
|
78
|
+
redirectUri: o,
|
|
79
79
|
scope: L,
|
|
80
80
|
state: n,
|
|
81
|
-
codeChallenge:
|
|
82
|
-
}),
|
|
81
|
+
codeChallenge: i
|
|
82
|
+
}), h = b(o), E = new P(this.authClientId).requestedRole(r);
|
|
83
83
|
e?.requested && E.requested(e.requested);
|
|
84
|
-
const l = await this.requestAccess(E.build()), { review_url: u } = k(l), g = O(u,
|
|
84
|
+
const l = await this.requestAccess(E.build()), { review_url: u } = k(l), g = O(u, c, h);
|
|
85
85
|
e?.onProgress?.("reviewing");
|
|
86
86
|
const S = await this.launchReview(g);
|
|
87
87
|
return e?.onProgress?.("authenticating"), this.completeOAuthRedirect(S);
|
|
88
88
|
}
|
|
89
89
|
launchReview(e) {
|
|
90
90
|
return new Promise((t, r) => {
|
|
91
|
-
chrome.identity.launchWebAuthFlow({ url: e, interactive: !0 }, (
|
|
91
|
+
chrome.identity.launchWebAuthFlow({ url: e, interactive: !0 }, (o) => {
|
|
92
92
|
if (chrome.runtime.lastError) {
|
|
93
93
|
r(chrome.runtime.lastError);
|
|
94
94
|
return;
|
|
95
95
|
}
|
|
96
|
-
if (!
|
|
96
|
+
if (!o) {
|
|
97
97
|
r(d("oauth_error", "No redirect URL received"));
|
|
98
98
|
return;
|
|
99
99
|
}
|
|
100
|
-
t(
|
|
100
|
+
t(o);
|
|
101
101
|
});
|
|
102
102
|
});
|
|
103
103
|
}
|
|
@@ -105,12 +105,12 @@ class me extends V {
|
|
|
105
105
|
const t = new URL(e), r = t.searchParams.get("error");
|
|
106
106
|
if (r)
|
|
107
107
|
throw await this._storageRemove([this.storageKeys.CODE_VERIFIER, this.storageKeys.STATE]), t.searchParams.get("error_source") === "bodhi" && M(r === "access_denied" ? "denied" : r), d("oauth_error", t.searchParams.get("error_description") ?? r);
|
|
108
|
-
const
|
|
109
|
-
if (!s || s !==
|
|
108
|
+
const o = t.searchParams.get("code"), s = t.searchParams.get("state"), i = await this._storageGet(this.storageKeys.STATE);
|
|
109
|
+
if (!s || s !== i)
|
|
110
110
|
throw await this._storageRemove([this.storageKeys.CODE_VERIFIER, this.storageKeys.STATE]), d("oauth_error", "State mismatch");
|
|
111
|
-
if (!
|
|
111
|
+
if (!o)
|
|
112
112
|
throw await this._storageRemove([this.storageKeys.CODE_VERIFIER, this.storageKeys.STATE]), d("oauth_error", "No authorization code");
|
|
113
|
-
await this.exchangeCodeForTokens(
|
|
113
|
+
await this.exchangeCodeForTokens(o);
|
|
114
114
|
const n = await this.getAuthState();
|
|
115
115
|
if (n.status !== "authenticated")
|
|
116
116
|
throw await this._storageRemove([this.storageKeys.CODE_VERIFIER, this.storageKeys.STATE]), d("oauth_error", "Login failed");
|
|
@@ -195,8 +195,8 @@ class pe {
|
|
|
195
195
|
async init(e = {}) {
|
|
196
196
|
if (!e.testConnection && !e.selectedConnection) {
|
|
197
197
|
this.logger.info("No testConnection or selectedConnection, returning not-initialized state");
|
|
198
|
-
const
|
|
199
|
-
return this.setState(
|
|
198
|
+
const o = G();
|
|
199
|
+
return this.setState(o), o;
|
|
200
200
|
}
|
|
201
201
|
if (this.extensionId && !e.testConnection)
|
|
202
202
|
return this.logger.debug("Already initialized with extensionId, skipping discovery"), this.state;
|
|
@@ -211,20 +211,20 @@ class pe {
|
|
|
211
211
|
), this.extensionId = r;
|
|
212
212
|
else {
|
|
213
213
|
this.logger.info("Discovering bodhi-browser extension...");
|
|
214
|
-
const
|
|
214
|
+
const i = {
|
|
215
215
|
attempts: this.config.initParams?.extension?.attempts,
|
|
216
216
|
attemptWaitMs: this.config.initParams?.extension?.attemptWaitMs,
|
|
217
217
|
attemptTimeout: this.config.initParams?.extension?.attemptTimeout
|
|
218
218
|
}, n = await this.sendExtMessageWithTimeout(
|
|
219
219
|
m.DISCOVER_EXTENSION,
|
|
220
|
-
|
|
220
|
+
i,
|
|
221
221
|
t
|
|
222
222
|
);
|
|
223
223
|
this.extensionId = n.extensionId, this.logger.info("Extension discovered:", this.extensionId);
|
|
224
224
|
}
|
|
225
225
|
this.setupBroadcastListener();
|
|
226
226
|
}
|
|
227
|
-
const
|
|
227
|
+
const o = {
|
|
228
228
|
type: "extension",
|
|
229
229
|
extension: "ready",
|
|
230
230
|
extensionId: this.extensionId,
|
|
@@ -234,12 +234,12 @@ class pe {
|
|
|
234
234
|
if (e.testConnection)
|
|
235
235
|
try {
|
|
236
236
|
s = await this.getServerState(), this.logger.info("Server connectivity tested, state:", s.status);
|
|
237
|
-
} catch (
|
|
238
|
-
this.logger.error("Failed to get server state:",
|
|
237
|
+
} catch (i) {
|
|
238
|
+
this.logger.error("Failed to get server state:", i), s = K;
|
|
239
239
|
}
|
|
240
|
-
return this.setState({ ...
|
|
241
|
-
} catch (
|
|
242
|
-
this.logger.error("Failed to initialize extension:",
|
|
240
|
+
return this.setState({ ...o, server: s }), this.state;
|
|
241
|
+
} catch (o) {
|
|
242
|
+
this.logger.error("Failed to initialize extension:", o), this.extensionId = null;
|
|
243
243
|
const s = F();
|
|
244
244
|
return this.setState(s), this.state;
|
|
245
245
|
}
|
|
@@ -248,10 +248,10 @@ class pe {
|
|
|
248
248
|
* Helper method to send ext message with timeout support
|
|
249
249
|
*/
|
|
250
250
|
async sendExtMessageWithTimeout(e, t, r = 1e4) {
|
|
251
|
-
const
|
|
252
|
-
(s,
|
|
251
|
+
const o = new Promise(
|
|
252
|
+
(s, i) => setTimeout(() => i(new Error("Timeout")), r)
|
|
253
253
|
);
|
|
254
|
-
return Promise.race([this.sendExtRequest(e, t),
|
|
254
|
+
return Promise.race([this.sendExtRequest(e, t), o]);
|
|
255
255
|
}
|
|
256
256
|
/**
|
|
257
257
|
* Send an EXT2EXT_CLIENT_REQUEST message and await EXT2EXT_CLIENT_RESPONSE
|
|
@@ -259,7 +259,7 @@ class pe {
|
|
|
259
259
|
*/
|
|
260
260
|
async sendExtRequest(e, t) {
|
|
261
261
|
try {
|
|
262
|
-
const r = this.generateRequestId(),
|
|
262
|
+
const r = this.generateRequestId(), o = await chrome.runtime.sendMessage({
|
|
263
263
|
type: a.EXT2EXT_CLIENT_REQUEST,
|
|
264
264
|
requestId: r,
|
|
265
265
|
request: {
|
|
@@ -267,17 +267,17 @@ class pe {
|
|
|
267
267
|
params: t
|
|
268
268
|
}
|
|
269
269
|
});
|
|
270
|
-
if (!
|
|
270
|
+
if (!o)
|
|
271
271
|
throw d("extension_error", "No response from background script");
|
|
272
|
-
if (
|
|
272
|
+
if (o.type !== a.EXT2EXT_CLIENT_RESPONSE)
|
|
273
273
|
throw d(
|
|
274
274
|
"extension_error",
|
|
275
275
|
"Invalid response type from background script"
|
|
276
276
|
);
|
|
277
|
-
const s =
|
|
277
|
+
const s = o.response;
|
|
278
278
|
if (y(s)) {
|
|
279
|
-
const
|
|
280
|
-
throw d(
|
|
279
|
+
const i = s.error.type || "extension_error";
|
|
280
|
+
throw d(i, s.error.message);
|
|
281
281
|
}
|
|
282
282
|
return s;
|
|
283
283
|
} catch (r) {
|
|
@@ -291,16 +291,16 @@ class pe {
|
|
|
291
291
|
* Send an API_REQUEST message and await API_RESPONSE (internal)
|
|
292
292
|
* Returns ext2ext-specific ExtClientApiResponseMessage
|
|
293
293
|
*/
|
|
294
|
-
async sendRawApiMessage(e, t, r,
|
|
295
|
-
const
|
|
294
|
+
async sendRawApiMessage(e, t, r, o, s) {
|
|
295
|
+
const i = this.generateRequestId();
|
|
296
296
|
return await chrome.runtime.sendMessage({
|
|
297
297
|
type: a.EXT2EXT_CLIENT_API_REQUEST,
|
|
298
|
-
requestId:
|
|
298
|
+
requestId: i,
|
|
299
299
|
request: {
|
|
300
300
|
method: e,
|
|
301
301
|
endpoint: t,
|
|
302
302
|
body: r,
|
|
303
|
-
headers:
|
|
303
|
+
headers: o,
|
|
304
304
|
authenticated: s
|
|
305
305
|
}
|
|
306
306
|
});
|
|
@@ -309,11 +309,11 @@ class pe {
|
|
|
309
309
|
* Send an API message and return ApiResponse
|
|
310
310
|
* @throws BodhiError on operational errors (network, timeout, extension-level)
|
|
311
311
|
*/
|
|
312
|
-
async sendApiRequest(e, t, r,
|
|
312
|
+
async sendApiRequest(e, t, r, o, s) {
|
|
313
313
|
try {
|
|
314
|
-
const
|
|
315
|
-
(
|
|
316
|
-
() =>
|
|
314
|
+
const i = new Promise(
|
|
315
|
+
(c, h) => setTimeout(
|
|
316
|
+
() => h(
|
|
317
317
|
new Error(
|
|
318
318
|
`[bodhi-js-sdk/ext] network timeout: api request not completed within configured/default timeout of ${this.apiTimeoutMs}ms`
|
|
319
319
|
)
|
|
@@ -321,18 +321,18 @@ class pe {
|
|
|
321
321
|
this.apiTimeoutMs
|
|
322
322
|
)
|
|
323
323
|
), n = await Promise.race([
|
|
324
|
-
this.sendRawApiMessage(e, t, r,
|
|
325
|
-
|
|
324
|
+
this.sendRawApiMessage(e, t, r, o, s),
|
|
325
|
+
i
|
|
326
326
|
]);
|
|
327
327
|
if (ge(n)) {
|
|
328
|
-
const
|
|
329
|
-
throw new T(
|
|
328
|
+
const c = n.error.type || "extension_error";
|
|
329
|
+
throw new T(c, n.error.message);
|
|
330
330
|
}
|
|
331
331
|
return n.response;
|
|
332
|
-
} catch (
|
|
333
|
-
if (
|
|
334
|
-
throw
|
|
335
|
-
const n =
|
|
332
|
+
} catch (i) {
|
|
333
|
+
if (i instanceof T)
|
|
334
|
+
throw i;
|
|
335
|
+
const n = i instanceof Error ? i.message : String(i);
|
|
336
336
|
throw new T("network_error", n);
|
|
337
337
|
}
|
|
338
338
|
}
|
|
@@ -344,29 +344,29 @@ class pe {
|
|
|
344
344
|
*/
|
|
345
345
|
async login(e) {
|
|
346
346
|
return new Promise((t, r) => {
|
|
347
|
-
const
|
|
347
|
+
const o = async (s) => {
|
|
348
348
|
if (s && typeof s == "object" && "type" in s && s.type === "EXT2EXT_CLIENT_BROADCAST" && "event" in s && s.event === "authStateChanged") {
|
|
349
|
-
chrome.runtime.onMessage.removeListener(
|
|
349
|
+
chrome.runtime.onMessage.removeListener(o);
|
|
350
350
|
try {
|
|
351
|
-
const
|
|
352
|
-
if (ee(
|
|
351
|
+
const i = await this.getAuthState();
|
|
352
|
+
if (ee(i)) {
|
|
353
353
|
r(
|
|
354
|
-
d("auth_error", `Login failed: ${
|
|
354
|
+
d("auth_error", `Login failed: ${i.error?.message}`)
|
|
355
355
|
);
|
|
356
356
|
return;
|
|
357
357
|
}
|
|
358
|
-
if (
|
|
358
|
+
if (i.status !== "authenticated") {
|
|
359
359
|
r(d("auth_error", "Login failed: User is not logged in"));
|
|
360
360
|
return;
|
|
361
361
|
}
|
|
362
|
-
this.setAuthState(
|
|
363
|
-
} catch (
|
|
364
|
-
r(
|
|
362
|
+
this.setAuthState(i), t(i);
|
|
363
|
+
} catch (i) {
|
|
364
|
+
r(i);
|
|
365
365
|
}
|
|
366
366
|
}
|
|
367
367
|
};
|
|
368
|
-
chrome.runtime.onMessage.addListener(
|
|
369
|
-
chrome.runtime.onMessage.removeListener(
|
|
368
|
+
chrome.runtime.onMessage.addListener(o), this.sendExtRequest(m.LOGIN, e).catch((s) => {
|
|
369
|
+
chrome.runtime.onMessage.removeListener(o), r(s);
|
|
370
370
|
});
|
|
371
371
|
});
|
|
372
372
|
}
|
|
@@ -413,11 +413,11 @@ class pe {
|
|
|
413
413
|
try {
|
|
414
414
|
e = await this.sendApiRequest("GET", "/bodhi/v1/info");
|
|
415
415
|
} catch (s) {
|
|
416
|
-
const
|
|
416
|
+
const i = s instanceof Error ? s.message : "Connection failed", n = s instanceof T ? s.code : "extension_error";
|
|
417
417
|
return {
|
|
418
418
|
status: "not-reachable",
|
|
419
419
|
version: null,
|
|
420
|
-
error: { message:
|
|
420
|
+
error: { message: i, type: n }
|
|
421
421
|
};
|
|
422
422
|
}
|
|
423
423
|
if (e.status >= 400)
|
|
@@ -426,30 +426,30 @@ class pe {
|
|
|
426
426
|
version: null,
|
|
427
427
|
error: { message: "API error from server", type: "extension_error" }
|
|
428
428
|
};
|
|
429
|
-
const t = e.body, r = t.version || "unknown",
|
|
429
|
+
const t = e.body, r = t.version || "unknown", o = { deployment: t.deployment ?? null, client_id: t.client_id ?? null };
|
|
430
430
|
switch (t.status) {
|
|
431
431
|
case "ready":
|
|
432
|
-
return { status: "ready", version: r, error: null, ...
|
|
432
|
+
return { status: "ready", version: r, error: null, ...o };
|
|
433
433
|
case "setup":
|
|
434
434
|
return {
|
|
435
435
|
status: "setup",
|
|
436
436
|
version: r,
|
|
437
437
|
error: t.error ? { message: t.error.message, type: t.error.type } : { message: "Setup required", type: "extension_error" },
|
|
438
|
-
...
|
|
438
|
+
...o
|
|
439
439
|
};
|
|
440
440
|
case "resource_admin":
|
|
441
441
|
return {
|
|
442
442
|
status: "resource_admin",
|
|
443
443
|
version: r,
|
|
444
444
|
error: t.error ? { message: t.error.message, type: t.error.type } : { message: "Resource admin required", type: "extension_error" },
|
|
445
|
-
...
|
|
445
|
+
...o
|
|
446
446
|
};
|
|
447
447
|
case "error":
|
|
448
448
|
return {
|
|
449
449
|
status: "error",
|
|
450
450
|
version: r,
|
|
451
451
|
error: t.error ? { message: t.error.message, type: t.error.type } : { message: "Server error", type: "extension_error" },
|
|
452
|
-
...
|
|
452
|
+
...o
|
|
453
453
|
};
|
|
454
454
|
default:
|
|
455
455
|
return {
|
|
@@ -465,24 +465,24 @@ class pe {
|
|
|
465
465
|
/**
|
|
466
466
|
* Generic streaming method
|
|
467
467
|
*/
|
|
468
|
-
async *stream(e, t, r,
|
|
469
|
-
const
|
|
468
|
+
async *stream(e, t, r, o, s = !0) {
|
|
469
|
+
const i = this.generateRequestId();
|
|
470
470
|
this.logger.debug("Starting stream", {
|
|
471
471
|
method: e,
|
|
472
472
|
endpoint: t,
|
|
473
|
-
requestId:
|
|
473
|
+
requestId: i
|
|
474
474
|
});
|
|
475
|
-
const n = chrome.runtime.connect({ name: U }),
|
|
475
|
+
const n = chrome.runtime.connect({ name: U }), h = new ReadableStream({
|
|
476
476
|
start: (E) => {
|
|
477
477
|
n.onMessage.addListener((l) => {
|
|
478
|
-
if (l.requestId ===
|
|
478
|
+
if (l.requestId === i)
|
|
479
479
|
switch (l.type) {
|
|
480
480
|
case a.EXT2EXT_CLIENT_STREAM_DONE:
|
|
481
|
-
this.logger.debug("Stream complete", { requestId:
|
|
481
|
+
this.logger.debug("Stream complete", { requestId: i }), E.close(), n.disconnect();
|
|
482
482
|
break;
|
|
483
483
|
case a.EXT2EXT_CLIENT_STREAM_ERROR:
|
|
484
484
|
this.logger.error("Stream error", {
|
|
485
|
-
requestId:
|
|
485
|
+
requestId: i,
|
|
486
486
|
error: JSON.stringify(l.error)
|
|
487
487
|
}), E.error(
|
|
488
488
|
new T(
|
|
@@ -494,7 +494,7 @@ class pe {
|
|
|
494
494
|
case a.EXT2EXT_CLIENT_STREAM_API_ERROR: {
|
|
495
495
|
const u = l;
|
|
496
496
|
this.logger.error("Stream API error", {
|
|
497
|
-
requestId:
|
|
497
|
+
requestId: i,
|
|
498
498
|
error: u.response.body?.error
|
|
499
499
|
}), E.error(
|
|
500
500
|
new W(
|
|
@@ -512,21 +512,21 @@ class pe {
|
|
|
512
512
|
}
|
|
513
513
|
}
|
|
514
514
|
}), n.onDisconnect.addListener(() => {
|
|
515
|
-
this.logger.debug("Port disconnected", { requestId:
|
|
515
|
+
this.logger.debug("Port disconnected", { requestId: i });
|
|
516
516
|
try {
|
|
517
517
|
E.error(new T("connection_closed", "Connection closed unexpectedly"));
|
|
518
518
|
} catch {
|
|
519
519
|
}
|
|
520
520
|
}), n.postMessage({
|
|
521
521
|
type: a.EXT2EXT_CLIENT_STREAM_REQUEST,
|
|
522
|
-
requestId:
|
|
523
|
-
request: { method: e, endpoint: t, body: r, headers:
|
|
522
|
+
requestId: i,
|
|
523
|
+
request: { method: e, endpoint: t, body: r, headers: o, authenticated: s }
|
|
524
524
|
});
|
|
525
525
|
}
|
|
526
526
|
}).getReader();
|
|
527
527
|
try {
|
|
528
528
|
for (; ; ) {
|
|
529
|
-
const { done: E, value: l } = await
|
|
529
|
+
const { done: E, value: l } = await h.read();
|
|
530
530
|
if (E) {
|
|
531
531
|
this.logger.debug("Stream iteration complete");
|
|
532
532
|
break;
|
|
@@ -534,24 +534,24 @@ class pe {
|
|
|
534
534
|
yield l;
|
|
535
535
|
}
|
|
536
536
|
} finally {
|
|
537
|
-
|
|
537
|
+
h.releaseLock();
|
|
538
538
|
}
|
|
539
539
|
}
|
|
540
540
|
/**
|
|
541
541
|
* Raw text streaming method - no SSE/JSON parsing
|
|
542
542
|
* Returns status, headers, and async generator of raw text chunks
|
|
543
543
|
*/
|
|
544
|
-
async streamText(e, t, r,
|
|
545
|
-
const
|
|
546
|
-
return new Promise((n,
|
|
547
|
-
let
|
|
544
|
+
async streamText(e, t, r, o, s = !0) {
|
|
545
|
+
const i = this.generateRequestId();
|
|
546
|
+
return new Promise((n, c) => {
|
|
547
|
+
let h, E = !1;
|
|
548
548
|
const l = new ReadableStream({
|
|
549
549
|
start: (g) => {
|
|
550
|
-
|
|
550
|
+
h = g;
|
|
551
551
|
}
|
|
552
552
|
}), u = chrome.runtime.connect({ name: D });
|
|
553
553
|
u.onMessage.addListener((g) => {
|
|
554
|
-
if (g.requestId ===
|
|
554
|
+
if (g.requestId === i)
|
|
555
555
|
switch (g.type) {
|
|
556
556
|
case a.EXT2EXT_CLIENT_STREAM_TEXT_START: {
|
|
557
557
|
E = !0;
|
|
@@ -575,31 +575,31 @@ class pe {
|
|
|
575
575
|
break;
|
|
576
576
|
}
|
|
577
577
|
case a.EXT2EXT_CLIENT_STREAM_TEXT_CHUNK:
|
|
578
|
-
|
|
578
|
+
h.enqueue(g.chunk);
|
|
579
579
|
break;
|
|
580
580
|
case a.EXT2EXT_CLIENT_STREAM_TEXT_DONE:
|
|
581
|
-
|
|
581
|
+
h.close(), u.disconnect();
|
|
582
582
|
break;
|
|
583
583
|
case a.EXT2EXT_CLIENT_STREAM_TEXT_ERROR: {
|
|
584
584
|
const S = d("extension_error", g.error.message);
|
|
585
|
-
E ?
|
|
585
|
+
E ? h.error(S) : c(S), u.disconnect();
|
|
586
586
|
break;
|
|
587
587
|
}
|
|
588
588
|
}
|
|
589
589
|
}), u.onDisconnect.addListener(() => {
|
|
590
590
|
if (!E)
|
|
591
|
-
|
|
591
|
+
c(d("extension_error", "Connection closed unexpectedly"));
|
|
592
592
|
else
|
|
593
593
|
try {
|
|
594
|
-
|
|
594
|
+
h.error(
|
|
595
595
|
d("extension_error", "Connection closed unexpectedly")
|
|
596
596
|
);
|
|
597
597
|
} catch {
|
|
598
598
|
}
|
|
599
599
|
}), u.postMessage({
|
|
600
600
|
type: a.EXT2EXT_CLIENT_STREAM_TEXT_REQUEST,
|
|
601
|
-
requestId:
|
|
602
|
-
request: { method: e, endpoint: t, body: r, headers:
|
|
601
|
+
requestId: i,
|
|
602
|
+
request: { method: e, endpoint: t, body: r, headers: o, authenticated: s }
|
|
603
603
|
});
|
|
604
604
|
});
|
|
605
605
|
}
|
|
@@ -649,14 +649,14 @@ class pe {
|
|
|
649
649
|
}
|
|
650
650
|
class ye extends te {
|
|
651
651
|
constructor(e, t, r) {
|
|
652
|
-
const
|
|
653
|
-
basePath:
|
|
654
|
-
authServerUrl:
|
|
655
|
-
logLevel:
|
|
656
|
-
apiTimeoutMs:
|
|
657
|
-
storage:
|
|
658
|
-
initialTokens:
|
|
659
|
-
initParams:
|
|
652
|
+
const o = t || {}, s = {
|
|
653
|
+
basePath: o.basePath || "/",
|
|
654
|
+
authServerUrl: o.authServerUrl || "https://id.getbodhi.app/realms/bodhi",
|
|
655
|
+
logLevel: o.logLevel || "warn",
|
|
656
|
+
apiTimeoutMs: o.apiTimeoutMs,
|
|
657
|
+
storage: o.storage,
|
|
658
|
+
initialTokens: o.initialTokens,
|
|
659
|
+
initParams: o.initParams
|
|
660
660
|
};
|
|
661
661
|
super(e, s, r);
|
|
662
662
|
}
|
|
@@ -697,7 +697,7 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Re = ["bjdjhiombmfbcoeojijpfckl
|
|
|
697
697
|
// Constructor
|
|
698
698
|
// ============================================================================
|
|
699
699
|
constructor(e, t) {
|
|
700
|
-
this.isAuthenticating = !1, this.state = "setup", this.listenersInitialized = !1, this.refreshPromise = null, this.activeStreamPorts = /* @__PURE__ */ new Map(), this.authClientId = e, this.authServerUrl = t?.authServerUrl || "https://id.getbodhi.app/realms/bodhi", this.extensionId = t?.extensionId, this.logger = new x("BodhiExtClient", t?.logLevel || "warn"), this.attempts = t?.attempts ?? ue, this.attemptWaitMs = t?.attemptWaitMs ?? de, this.attemptTimeout = t?.attemptTimeout ?? le, this.authEndpoints = {
|
|
700
|
+
this.isAuthenticating = !1, this.isReauthorizing = !1, this.state = "setup", this.listenersInitialized = !1, this.refreshPromise = null, this.activeStreamPorts = /* @__PURE__ */ new Map(), this.authClientId = e, this.authServerUrl = t?.authServerUrl || "https://id.getbodhi.app/realms/bodhi", this.extensionId = t?.extensionId, this.logger = new x("BodhiExtClient", t?.logLevel || "warn"), this.attempts = t?.attempts ?? ue, this.attemptWaitMs = t?.attemptWaitMs ?? de, this.attemptTimeout = t?.attemptTimeout ?? le, this.authEndpoints = {
|
|
701
701
|
authorize: `${this.authServerUrl}/protocol/openid-connect/auth`,
|
|
702
702
|
token: `${this.authServerUrl}/protocol/openid-connect/token`,
|
|
703
703
|
userinfo: `${this.authServerUrl}/protocol/openid-connect/userinfo`,
|
|
@@ -718,8 +718,8 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Re = ["bjdjhiombmfbcoeojijpfckl
|
|
|
718
718
|
return crypto.getRandomValues(e), p.base64UrlEncode(e.buffer);
|
|
719
719
|
}
|
|
720
720
|
static async generateCodeChallenge(e) {
|
|
721
|
-
const r = new TextEncoder().encode(e),
|
|
722
|
-
return p.base64UrlEncode(
|
|
721
|
+
const r = new TextEncoder().encode(e), o = await crypto.subtle.digest("SHA-256", r);
|
|
722
|
+
return p.base64UrlEncode(o);
|
|
723
723
|
}
|
|
724
724
|
// ============================================================================
|
|
725
725
|
// State Management
|
|
@@ -748,7 +748,7 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Re = ["bjdjhiombmfbcoeojijpfckl
|
|
|
748
748
|
return this.logger.debug(
|
|
749
749
|
`[Ext2Ext/Discovery] Pinging extension: ${e} with timeout ${this.attemptTimeout}ms`
|
|
750
750
|
), new Promise((t, r) => {
|
|
751
|
-
const
|
|
751
|
+
const o = setTimeout(() => {
|
|
752
752
|
this.logger.debug(`[Ext2Ext/Discovery] Timeout waiting for extension ${e}`), r(new Error("Timeout"));
|
|
753
753
|
}, this.attemptTimeout);
|
|
754
754
|
try {
|
|
@@ -759,23 +759,23 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Re = ["bjdjhiombmfbcoeojijpfckl
|
|
|
759
759
|
action: "get_extension_id"
|
|
760
760
|
}
|
|
761
761
|
};
|
|
762
|
-
this.logger.debug(`[Ext2Ext/Discovery] Sending message to ${e}:`, s), chrome.runtime.sendMessage(e, s, (
|
|
763
|
-
if (clearTimeout(
|
|
762
|
+
this.logger.debug(`[Ext2Ext/Discovery] Sending message to ${e}:`, s), chrome.runtime.sendMessage(e, s, (i) => {
|
|
763
|
+
if (clearTimeout(o), chrome.runtime.lastError) {
|
|
764
764
|
this.logger.error(
|
|
765
765
|
`[Ext2Ext/Discovery] Error from extension ${e}:`,
|
|
766
766
|
chrome.runtime.lastError.message
|
|
767
767
|
), r(new Error(chrome.runtime.lastError.message));
|
|
768
768
|
return;
|
|
769
769
|
}
|
|
770
|
-
this.logger.debug(`[Ext2Ext/Discovery] Response from ${e}:`,
|
|
771
|
-
const n =
|
|
770
|
+
this.logger.debug(`[Ext2Ext/Discovery] Response from ${e}:`, i);
|
|
771
|
+
const n = i;
|
|
772
772
|
n && n.type === _.EXT_RESPONSE ? (this.logger.debug(`[Ext2Ext/Discovery] ✓ Extension ${e} responded`), t(!0)) : (this.logger.error(
|
|
773
773
|
`[Ext2Ext/Discovery] Invalid response from ${e}:`,
|
|
774
|
-
|
|
774
|
+
i
|
|
775
775
|
), r(new Error("Invalid response")));
|
|
776
776
|
});
|
|
777
777
|
} catch (s) {
|
|
778
|
-
this.logger.error(`[Ext2Ext/Discovery] Exception pinging ${e}:`, s), clearTimeout(
|
|
778
|
+
this.logger.error(`[Ext2Ext/Discovery] Exception pinging ${e}:`, s), clearTimeout(o), r(s);
|
|
779
779
|
}
|
|
780
780
|
});
|
|
781
781
|
}
|
|
@@ -790,36 +790,36 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Re = ["bjdjhiombmfbcoeojijpfckl
|
|
|
790
790
|
* @param params Resolved discovery params
|
|
791
791
|
*/
|
|
792
792
|
async discoverBodhiExtension(e) {
|
|
793
|
-
const { attempts: t, attemptWaitMs: r, attemptTimeout:
|
|
793
|
+
const { attempts: t, attemptWaitMs: r, attemptTimeout: o } = e;
|
|
794
794
|
this.logger.info(
|
|
795
|
-
`[Ext2Ext/Discovery] Starting discovery: ${t} attempts per ID, ${
|
|
795
|
+
`[Ext2Ext/Discovery] Starting discovery: ${t} attempts per ID, ${o}ms timeout, ${r}ms between attempts`
|
|
796
796
|
);
|
|
797
797
|
const s = this.getExtensionIdsForEnvironment();
|
|
798
798
|
this.logger.debug(
|
|
799
799
|
`[Ext2Ext/Discovery] Will try ${s.length} extension(s):`,
|
|
800
800
|
s
|
|
801
801
|
);
|
|
802
|
-
for (const
|
|
803
|
-
for (let
|
|
802
|
+
for (const c of s) {
|
|
803
|
+
for (let h = 1; h <= t; h++) {
|
|
804
804
|
this.logger.debug(
|
|
805
|
-
`[Ext2Ext/Discovery] Trying ${
|
|
805
|
+
`[Ext2Ext/Discovery] Trying ${c} - attempt ${h}/${t}`
|
|
806
806
|
);
|
|
807
807
|
try {
|
|
808
|
-
return await this.pingExtension(
|
|
808
|
+
return await this.pingExtension(c), this.logger.info(`[Ext2Ext/Discovery] ✓ Found: ${c} on attempt ${h}`), {
|
|
809
809
|
success: !0,
|
|
810
|
-
extensionId:
|
|
810
|
+
extensionId: c
|
|
811
811
|
};
|
|
812
812
|
} catch (E) {
|
|
813
813
|
this.logger.debug(
|
|
814
|
-
`[Ext2Ext/Discovery] Attempt ${
|
|
815
|
-
),
|
|
814
|
+
`[Ext2Ext/Discovery] Attempt ${h} failed for ${c}: ${E instanceof Error ? E.message : "Unknown error"}`
|
|
815
|
+
), h < t && await this.sleep(r);
|
|
816
816
|
}
|
|
817
817
|
}
|
|
818
818
|
this.logger.warn(
|
|
819
|
-
`[Ext2Ext/Discovery] ✗ Not found: ${
|
|
819
|
+
`[Ext2Ext/Discovery] ✗ Not found: ${c} after ${t} attempts`
|
|
820
820
|
);
|
|
821
821
|
}
|
|
822
|
-
const
|
|
822
|
+
const i = s.join(", "), n = `Extension not found. Tried ${s.length} IDs with ${t} attempts each: ${i}`;
|
|
823
823
|
return this.logger.error(`[Ext2Ext/Discovery] ${n}`), {
|
|
824
824
|
success: !1,
|
|
825
825
|
error: n
|
|
@@ -853,8 +853,8 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Re = ["bjdjhiombmfbcoeojijpfckl
|
|
|
853
853
|
type: "NOT_INITIALIZED"
|
|
854
854
|
}
|
|
855
855
|
}), !0) : (this.logger.debug(`[BodhiExtClient] Processing message.type=${e.type}`), (async () => {
|
|
856
|
-
const
|
|
857
|
-
r(
|
|
856
|
+
const o = await this.handleAction(e);
|
|
857
|
+
r(o);
|
|
858
858
|
})(), !0)), this.registerStreamPortListener(
|
|
859
859
|
U,
|
|
860
860
|
a.EXT2EXT_CLIENT_STREAM_REQUEST,
|
|
@@ -937,7 +937,7 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Re = ["bjdjhiombmfbcoeojijpfckl
|
|
|
937
937
|
Authorization: `Bearer ${s}`
|
|
938
938
|
}, this.logger.debug("[BodhiExtClient] Injected auth token for authenticated request");
|
|
939
939
|
}
|
|
940
|
-
const
|
|
940
|
+
const o = await this.sendApiRequest(
|
|
941
941
|
e.request.method,
|
|
942
942
|
e.request.endpoint,
|
|
943
943
|
e.request.body,
|
|
@@ -946,7 +946,7 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Re = ["bjdjhiombmfbcoeojijpfckl
|
|
|
946
946
|
return {
|
|
947
947
|
type: a.EXT2EXT_CLIENT_API_RESPONSE,
|
|
948
948
|
requestId: t,
|
|
949
|
-
response:
|
|
949
|
+
response: o
|
|
950
950
|
};
|
|
951
951
|
} catch (r) {
|
|
952
952
|
return this.logger.error("[BodhiExtClient] API request failed:", r), {
|
|
@@ -966,17 +966,17 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Re = ["bjdjhiombmfbcoeojijpfckl
|
|
|
966
966
|
* @returns Action response message (success or error)
|
|
967
967
|
*/
|
|
968
968
|
async handleExtClientRequest(e) {
|
|
969
|
-
const { requestId: t, request: r } = e, { action:
|
|
970
|
-
this.logger.debug(`[BodhiExtClient] Handling action: ${
|
|
969
|
+
const { requestId: t, request: r } = e, { action: o, params: s } = r;
|
|
970
|
+
this.logger.debug(`[BodhiExtClient] Handling action: ${o}`);
|
|
971
971
|
try {
|
|
972
|
-
let
|
|
973
|
-
switch (
|
|
972
|
+
let i = {};
|
|
973
|
+
switch (o) {
|
|
974
974
|
case m.DISCOVER_EXTENSION: {
|
|
975
975
|
const n = s;
|
|
976
976
|
await this.init(n), this.logger.info("[BodhiExtClient] Discovery successful:", {
|
|
977
977
|
extensionId: this.extensionId,
|
|
978
978
|
environment: I
|
|
979
|
-
}),
|
|
979
|
+
}), i = {
|
|
980
980
|
extensionId: this.extensionId,
|
|
981
981
|
environment: I
|
|
982
982
|
};
|
|
@@ -984,11 +984,11 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Re = ["bjdjhiombmfbcoeojijpfckl
|
|
|
984
984
|
}
|
|
985
985
|
case m.SET_EXTENSION_ID: {
|
|
986
986
|
const { extensionId: n } = s;
|
|
987
|
-
this.extensionId = n, this.state = "ready", this.logger.info("[BodhiExtClient] Extension ID set:", { extensionId: n }),
|
|
987
|
+
this.extensionId = n, this.state = "ready", this.logger.info("[BodhiExtClient] Extension ID set:", { extensionId: n }), i = { success: !0 };
|
|
988
988
|
break;
|
|
989
989
|
}
|
|
990
990
|
case m.GET_EXTENSION_ID: {
|
|
991
|
-
const n = await this.sendExtRequestRaw(
|
|
991
|
+
const n = await this.sendExtRequestRaw(ie.GET_EXTENSION_ID, s);
|
|
992
992
|
return y(n.response) ? {
|
|
993
993
|
type: a.EXT2EXT_CLIENT_RESPONSE,
|
|
994
994
|
requestId: t,
|
|
@@ -1013,29 +1013,29 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Re = ["bjdjhiombmfbcoeojijpfckl
|
|
|
1013
1013
|
await this.logout(), this.broadcastAuthStateChange();
|
|
1014
1014
|
break;
|
|
1015
1015
|
case m.GET_AUTH_STATE:
|
|
1016
|
-
|
|
1016
|
+
i = { authState: await this.getAuthState() };
|
|
1017
1017
|
break;
|
|
1018
1018
|
default:
|
|
1019
1019
|
return {
|
|
1020
1020
|
type: a.EXT2EXT_CLIENT_RESPONSE,
|
|
1021
1021
|
requestId: t,
|
|
1022
1022
|
response: {
|
|
1023
|
-
error: { message: `Unknown action: ${
|
|
1023
|
+
error: { message: `Unknown action: ${o}`, type: "UNKNOWN_ACTION" }
|
|
1024
1024
|
}
|
|
1025
1025
|
};
|
|
1026
1026
|
}
|
|
1027
1027
|
return {
|
|
1028
1028
|
type: a.EXT2EXT_CLIENT_RESPONSE,
|
|
1029
1029
|
requestId: t,
|
|
1030
|
-
response:
|
|
1030
|
+
response: i
|
|
1031
1031
|
};
|
|
1032
|
-
} catch (
|
|
1033
|
-
return this.logger.error("[BodhiExtClient] Unexpected error:",
|
|
1032
|
+
} catch (i) {
|
|
1033
|
+
return this.logger.error("[BodhiExtClient] Unexpected error:", i), {
|
|
1034
1034
|
type: a.EXT2EXT_CLIENT_RESPONSE,
|
|
1035
1035
|
requestId: t,
|
|
1036
1036
|
response: {
|
|
1037
1037
|
error: {
|
|
1038
|
-
message:
|
|
1038
|
+
message: i instanceof Error ? i.message : `Unexpected error: ${JSON.stringify(i)}`
|
|
1039
1039
|
}
|
|
1040
1040
|
}
|
|
1041
1041
|
};
|
|
@@ -1072,25 +1072,25 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Re = ["bjdjhiombmfbcoeojijpfckl
|
|
|
1072
1072
|
* @throws Error if login fails
|
|
1073
1073
|
*/
|
|
1074
1074
|
async login(e) {
|
|
1075
|
-
if (!(this.isAuthenticating || (await this.getAuthState()).status === "authenticated")) {
|
|
1076
|
-
this.isAuthenticating = !0;
|
|
1075
|
+
if (!(this.isAuthenticating || (await this.getAuthState()).status === "authenticated" && !e?.reauthorize)) {
|
|
1076
|
+
this.isAuthenticating = !0, this.isReauthorizing = e?.reauthorize ?? !1;
|
|
1077
1077
|
try {
|
|
1078
1078
|
if (!this.extensionId)
|
|
1079
1079
|
throw new Error("Extension not discovered. Please detect Bodhi extension before login.");
|
|
1080
|
-
const r = e?.userRole ?? "scope_user_user",
|
|
1080
|
+
const r = e?.userRole ?? "scope_user_user", o = chrome.identity.getRedirectURL("callback"), s = p.generateCodeVerifier(), i = await p.generateCodeChallenge(s), n = p.generateCodeVerifier();
|
|
1081
1081
|
await chrome.storage.session.set({ codeVerifier: s, state: n, authInProgress: !0 });
|
|
1082
|
-
const
|
|
1082
|
+
const c = v(this.authEndpoints, {
|
|
1083
1083
|
clientId: this.authClientId,
|
|
1084
|
-
redirectUri:
|
|
1084
|
+
redirectUri: o,
|
|
1085
1085
|
scope: L,
|
|
1086
1086
|
state: n,
|
|
1087
|
-
codeChallenge:
|
|
1088
|
-
}),
|
|
1087
|
+
codeChallenge: i
|
|
1088
|
+
}), h = b(o), E = new P(this.authClientId).requestedRole(r);
|
|
1089
1089
|
e?.requested && E.requested(e.requested);
|
|
1090
|
-
const l = await this.requestAccess(E.build()), { review_url: u } = k(l), g = O(u,
|
|
1090
|
+
const l = await this.requestAccess(E.build()), { review_url: u } = k(l), g = O(u, c, h), S = await this.launchReview(g);
|
|
1091
1091
|
await this.completeOAuthRedirect(S);
|
|
1092
1092
|
} finally {
|
|
1093
|
-
this.isAuthenticating = !1;
|
|
1093
|
+
this.isAuthenticating = !1, this.isReauthorizing = !1;
|
|
1094
1094
|
}
|
|
1095
1095
|
}
|
|
1096
1096
|
}
|
|
@@ -1099,9 +1099,9 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Re = ["bjdjhiombmfbcoeojijpfckl
|
|
|
1099
1099
|
* @param code Authorization code from OAuth callback
|
|
1100
1100
|
*/
|
|
1101
1101
|
async exchangeCodeForTokens(e) {
|
|
1102
|
-
if ((await this.getAuthState()).status === "authenticated")
|
|
1102
|
+
if ((await this.getAuthState()).status === "authenticated" && !this.isReauthorizing)
|
|
1103
1103
|
return;
|
|
1104
|
-
const { codeVerifier: r } = await chrome.storage.session.get("codeVerifier"),
|
|
1104
|
+
const { codeVerifier: r } = await chrome.storage.session.get("codeVerifier"), o = chrome.identity.getRedirectURL("callback"), s = await fetch(this.authEndpoints.token, {
|
|
1105
1105
|
method: "POST",
|
|
1106
1106
|
headers: {
|
|
1107
1107
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
@@ -1109,7 +1109,7 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Re = ["bjdjhiombmfbcoeojijpfckl
|
|
|
1109
1109
|
body: new URLSearchParams({
|
|
1110
1110
|
grant_type: "authorization_code",
|
|
1111
1111
|
code: e,
|
|
1112
|
-
redirect_uri:
|
|
1112
|
+
redirect_uri: o,
|
|
1113
1113
|
client_id: this.authClientId,
|
|
1114
1114
|
code_verifier: r
|
|
1115
1115
|
})
|
|
@@ -1118,12 +1118,12 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Re = ["bjdjhiombmfbcoeojijpfckl
|
|
|
1118
1118
|
const n = await s.text();
|
|
1119
1119
|
throw new Error(`Token exchange failed: ${s.status} ${n}`);
|
|
1120
1120
|
}
|
|
1121
|
-
const
|
|
1121
|
+
const i = await s.json();
|
|
1122
1122
|
await this.storeTokens({
|
|
1123
|
-
accessToken:
|
|
1124
|
-
refreshToken:
|
|
1125
|
-
idToken:
|
|
1126
|
-
expiresIn:
|
|
1123
|
+
accessToken: i.access_token,
|
|
1124
|
+
refreshToken: i.refresh_token,
|
|
1125
|
+
idToken: i.id_token,
|
|
1126
|
+
expiresIn: i.expires_in
|
|
1127
1127
|
});
|
|
1128
1128
|
}
|
|
1129
1129
|
/**
|
|
@@ -1208,16 +1208,16 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Re = ["bjdjhiombmfbcoeojijpfckl
|
|
|
1208
1208
|
}
|
|
1209
1209
|
launchReview(e) {
|
|
1210
1210
|
return new Promise((t, r) => {
|
|
1211
|
-
chrome.identity.launchWebAuthFlow({ url: e, interactive: !0 }, async (
|
|
1211
|
+
chrome.identity.launchWebAuthFlow({ url: e, interactive: !0 }, async (o) => {
|
|
1212
1212
|
if (await chrome.storage.session.set({ authInProgress: !1 }), chrome.runtime.lastError) {
|
|
1213
1213
|
await chrome.storage.session.remove(["codeVerifier", "state"]), r(chrome.runtime.lastError);
|
|
1214
1214
|
return;
|
|
1215
1215
|
}
|
|
1216
|
-
if (!
|
|
1216
|
+
if (!o) {
|
|
1217
1217
|
await chrome.storage.session.remove(["codeVerifier", "state"]), r(d("oauth_error", "No redirect URL received"));
|
|
1218
1218
|
return;
|
|
1219
1219
|
}
|
|
1220
|
-
t(
|
|
1220
|
+
t(o);
|
|
1221
1221
|
});
|
|
1222
1222
|
});
|
|
1223
1223
|
}
|
|
@@ -1225,12 +1225,12 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Re = ["bjdjhiombmfbcoeojijpfckl
|
|
|
1225
1225
|
const t = new URL(e), r = t.searchParams.get("error");
|
|
1226
1226
|
if (r)
|
|
1227
1227
|
throw await chrome.storage.session.remove(["codeVerifier", "state"]), t.searchParams.get("error_source") === "bodhi" && M(r === "access_denied" ? "denied" : r), d("oauth_error", t.searchParams.get("error_description") ?? r);
|
|
1228
|
-
const
|
|
1229
|
-
if (!s || s !==
|
|
1228
|
+
const o = t.searchParams.get("code"), s = t.searchParams.get("state"), { state: i } = await chrome.storage.session.get("state");
|
|
1229
|
+
if (!s || s !== i)
|
|
1230
1230
|
throw await chrome.storage.session.remove(["codeVerifier", "state"]), d("oauth_error", "State mismatch");
|
|
1231
|
-
if (!
|
|
1231
|
+
if (!o)
|
|
1232
1232
|
throw await chrome.storage.session.remove(["codeVerifier", "state"]), d("oauth_error", "No authorization code");
|
|
1233
|
-
if (await this.exchangeCodeForTokens(
|
|
1233
|
+
if (await this.exchangeCodeForTokens(o), await chrome.storage.session.remove(["codeVerifier", "state"]), (await this.getAuthState()).status !== "authenticated")
|
|
1234
1234
|
throw d("oauth_error", "Login failed");
|
|
1235
1235
|
}
|
|
1236
1236
|
// Ext2Ext Communication (Private Methods)
|
|
@@ -1257,7 +1257,7 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Re = ["bjdjhiombmfbcoeojijpfckl
|
|
|
1257
1257
|
* @param headers Optional headers
|
|
1258
1258
|
* @returns API response from LLM server via bodhi-browser-ext
|
|
1259
1259
|
*/
|
|
1260
|
-
async sendApiRequest(e, t, r,
|
|
1260
|
+
async sendApiRequest(e, t, r, o) {
|
|
1261
1261
|
if (!this.extensionId)
|
|
1262
1262
|
throw new T(
|
|
1263
1263
|
"not_initialized",
|
|
@@ -1267,24 +1267,24 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Re = ["bjdjhiombmfbcoeojijpfckl
|
|
|
1267
1267
|
`[BodhiExtClient] Sending API_REQUEST: method=${e}, endpoint=${t}`,
|
|
1268
1268
|
r ? { body: r } : ""
|
|
1269
1269
|
);
|
|
1270
|
-
const s = crypto.randomUUID(),
|
|
1270
|
+
const s = crypto.randomUUID(), i = {
|
|
1271
1271
|
type: _.API_REQUEST,
|
|
1272
1272
|
requestId: s,
|
|
1273
1273
|
request: {
|
|
1274
1274
|
method: e,
|
|
1275
1275
|
endpoint: t,
|
|
1276
1276
|
body: r,
|
|
1277
|
-
headers:
|
|
1277
|
+
headers: o
|
|
1278
1278
|
}
|
|
1279
1279
|
};
|
|
1280
|
-
return this.logger.debug(`[BodhiExtClient] Request ID: ${s}, Extension: ${this.extensionId}`), new Promise((n,
|
|
1280
|
+
return this.logger.debug(`[BodhiExtClient] Request ID: ${s}, Extension: ${this.extensionId}`), new Promise((n, c) => {
|
|
1281
1281
|
try {
|
|
1282
|
-
chrome.runtime.sendMessage(this.extensionId,
|
|
1282
|
+
chrome.runtime.sendMessage(this.extensionId, i, (h) => {
|
|
1283
1283
|
if (chrome.runtime.lastError) {
|
|
1284
1284
|
this.logger.error(
|
|
1285
1285
|
`[BodhiExtClient] Chrome runtime error for request ${s}:`,
|
|
1286
1286
|
chrome.runtime.lastError
|
|
1287
|
-
),
|
|
1287
|
+
), c(
|
|
1288
1288
|
new T(
|
|
1289
1289
|
"extension_error",
|
|
1290
1290
|
chrome.runtime.lastError.message ?? "Chrome runtime error"
|
|
@@ -1292,19 +1292,19 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Re = ["bjdjhiombmfbcoeojijpfckl
|
|
|
1292
1292
|
);
|
|
1293
1293
|
return;
|
|
1294
1294
|
}
|
|
1295
|
-
if (this.logger.debug(`[BodhiExtClient] Response for request ${s}:`,
|
|
1296
|
-
this.logger.error(`[BodhiExtClient] No response received for request ${s}`),
|
|
1295
|
+
if (this.logger.debug(`[BodhiExtClient] Response for request ${s}:`, h), !h) {
|
|
1296
|
+
this.logger.error(`[BodhiExtClient] No response received for request ${s}`), c(new T("extension_error", "No response from extension"));
|
|
1297
1297
|
return;
|
|
1298
1298
|
}
|
|
1299
|
-
|
|
1300
|
-
new T(
|
|
1301
|
-
)) : (this.logger.debug(`[BodhiExtClient] ✓ Valid API_RESPONSE for ${s}`), n(
|
|
1299
|
+
h.type === _.API_RESPONSE && h.requestId === s ? "error" in h ? (this.logger.error(`[BodhiExtClient] API error for ${s}:`, h.error), c(
|
|
1300
|
+
new T(h.error.type || "extension_error", h.error.message)
|
|
1301
|
+
)) : (this.logger.debug(`[BodhiExtClient] ✓ Valid API_RESPONSE for ${s}`), n(h.response)) : (this.logger.error(
|
|
1302
1302
|
`[BodhiExtClient] Invalid response format for ${s}:`,
|
|
1303
|
-
|
|
1304
|
-
),
|
|
1303
|
+
h
|
|
1304
|
+
), c(new T("extension_error", "Invalid response format")));
|
|
1305
1305
|
});
|
|
1306
|
-
} catch (
|
|
1307
|
-
this.logger.error(`[BodhiExtClient] Exception sending message for ${s}:`,
|
|
1306
|
+
} catch (h) {
|
|
1307
|
+
this.logger.error(`[BodhiExtClient] Exception sending message for ${s}:`, h), c(h);
|
|
1308
1308
|
}
|
|
1309
1309
|
});
|
|
1310
1310
|
}
|
|
@@ -1324,7 +1324,7 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Re = ["bjdjhiombmfbcoeojijpfckl
|
|
|
1324
1324
|
`[BodhiExtClient] Sending EXT_REQUEST (raw): action=${e}`,
|
|
1325
1325
|
t ? { params: t } : ""
|
|
1326
1326
|
);
|
|
1327
|
-
const r = crypto.randomUUID(),
|
|
1327
|
+
const r = crypto.randomUUID(), o = {
|
|
1328
1328
|
type: _.EXT_REQUEST,
|
|
1329
1329
|
requestId: r,
|
|
1330
1330
|
request: {
|
|
@@ -1332,27 +1332,27 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Re = ["bjdjhiombmfbcoeojijpfckl
|
|
|
1332
1332
|
params: t
|
|
1333
1333
|
}
|
|
1334
1334
|
};
|
|
1335
|
-
return this.logger.debug(`[BodhiExtClient] Request ID: ${r}, Extension: ${this.extensionId}`), new Promise((s,
|
|
1335
|
+
return this.logger.debug(`[BodhiExtClient] Request ID: ${r}, Extension: ${this.extensionId}`), new Promise((s, i) => {
|
|
1336
1336
|
try {
|
|
1337
|
-
chrome.runtime.sendMessage(this.extensionId,
|
|
1337
|
+
chrome.runtime.sendMessage(this.extensionId, o, (n) => {
|
|
1338
1338
|
if (chrome.runtime.lastError) {
|
|
1339
1339
|
this.logger.error(
|
|
1340
1340
|
`[BodhiExtClient] Chrome runtime error for request ${r}:`,
|
|
1341
1341
|
chrome.runtime.lastError
|
|
1342
|
-
),
|
|
1342
|
+
), i(new Error(chrome.runtime.lastError.message));
|
|
1343
1343
|
return;
|
|
1344
1344
|
}
|
|
1345
1345
|
if (this.logger.debug(`[BodhiExtClient] Response for request ${r}:`, n), !n) {
|
|
1346
|
-
this.logger.error(`[BodhiExtClient] No response received for request ${r}`),
|
|
1346
|
+
this.logger.error(`[BodhiExtClient] No response received for request ${r}`), i(new Error("No response from extension"));
|
|
1347
1347
|
return;
|
|
1348
1348
|
}
|
|
1349
1349
|
n.type === _.EXT_RESPONSE && n.requestId === r ? (this.logger.debug(`[BodhiExtClient] ✓ Valid EXT_RESPONSE for ${r}`), s(n)) : (this.logger.error(
|
|
1350
1350
|
`[BodhiExtClient] Invalid response format for ${r}:`,
|
|
1351
1351
|
n
|
|
1352
|
-
),
|
|
1352
|
+
), i(new T("extension_error", "Invalid response format")));
|
|
1353
1353
|
});
|
|
1354
1354
|
} catch (n) {
|
|
1355
|
-
this.logger.error(`[BodhiExtClient] Exception sending message for ${r}:`, n),
|
|
1355
|
+
this.logger.error(`[BodhiExtClient] Exception sending message for ${r}:`, n), i(n);
|
|
1356
1356
|
}
|
|
1357
1357
|
});
|
|
1358
1358
|
}
|
|
@@ -1360,18 +1360,18 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Re = ["bjdjhiombmfbcoeojijpfckl
|
|
|
1360
1360
|
* Register a chrome.runtime.onConnect listener for a streaming port.
|
|
1361
1361
|
* Validates port name and message type, then delegates to handler.
|
|
1362
1362
|
*/
|
|
1363
|
-
registerStreamPortListener(e, t, r,
|
|
1363
|
+
registerStreamPortListener(e, t, r, o) {
|
|
1364
1364
|
chrome.runtime.onConnect.addListener((s) => {
|
|
1365
|
-
s.name === e && (this.logger.info(`[BodhiExtClient] Port connected: ${e}`), s.onMessage.addListener(async (
|
|
1366
|
-
if (
|
|
1367
|
-
this.logger.warn(`[BodhiExtClient] Unknown message type on ${e}:`,
|
|
1365
|
+
s.name === e && (this.logger.info(`[BodhiExtClient] Port connected: ${e}`), s.onMessage.addListener(async (i) => {
|
|
1366
|
+
if (i.type !== t) {
|
|
1367
|
+
this.logger.warn(`[BodhiExtClient] Unknown message type on ${e}:`, i.type), s.postMessage({
|
|
1368
1368
|
type: r,
|
|
1369
|
-
requestId:
|
|
1369
|
+
requestId: i.requestId,
|
|
1370
1370
|
error: { message: "Unknown message type", type: "extension_error" }
|
|
1371
1371
|
});
|
|
1372
1372
|
return;
|
|
1373
1373
|
}
|
|
1374
|
-
await
|
|
1374
|
+
await o(s, i);
|
|
1375
1375
|
}), s.onDisconnect.addListener(() => {
|
|
1376
1376
|
this.logger.info(`[BodhiExtClient] Port disconnected: ${e}`);
|
|
1377
1377
|
}));
|
|
@@ -1385,48 +1385,48 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Re = ["bjdjhiombmfbcoeojijpfckl
|
|
|
1385
1385
|
* @param onBodhiMessage Called for each message from bodhi-browser-ext.
|
|
1386
1386
|
* Returns true if the stream is complete (triggers cleanup).
|
|
1387
1387
|
*/
|
|
1388
|
-
async handleGenericStreamRelay(e, t, r,
|
|
1388
|
+
async handleGenericStreamRelay(e, t, r, o, s, i, n) {
|
|
1389
1389
|
if (this.logger.debug("[BodhiExtClient] Processing stream relay:", {
|
|
1390
1390
|
requestId: t,
|
|
1391
1391
|
method: r.method,
|
|
1392
1392
|
endpoint: r.endpoint,
|
|
1393
|
-
bodhiPortName:
|
|
1393
|
+
bodhiPortName: o
|
|
1394
1394
|
}), !this.extensionId) {
|
|
1395
1395
|
e.postMessage({
|
|
1396
|
-
type:
|
|
1396
|
+
type: i,
|
|
1397
1397
|
requestId: t,
|
|
1398
1398
|
error: { message: "Client not initialized (no extensionId)", type: "extension_error" }
|
|
1399
1399
|
});
|
|
1400
1400
|
return;
|
|
1401
1401
|
}
|
|
1402
1402
|
try {
|
|
1403
|
-
let
|
|
1403
|
+
let c = { ...r.headers };
|
|
1404
1404
|
if (r.authenticated !== !1) {
|
|
1405
1405
|
const u = await this._getAccessTokenRaw();
|
|
1406
1406
|
if (!u) {
|
|
1407
1407
|
e.postMessage({
|
|
1408
|
-
type:
|
|
1408
|
+
type: i,
|
|
1409
1409
|
requestId: t,
|
|
1410
1410
|
error: { message: "Not authenticated. Please log in first.", type: "extension_error" }
|
|
1411
1411
|
});
|
|
1412
1412
|
return;
|
|
1413
1413
|
}
|
|
1414
|
-
|
|
1414
|
+
c = { ...c, Authorization: `Bearer ${u}` }, this.logger.debug("[BodhiExtClient] Injected auth token for stream relay");
|
|
1415
1415
|
}
|
|
1416
|
-
const
|
|
1417
|
-
this.activeStreamPorts.set(t,
|
|
1416
|
+
const h = chrome.runtime.connect(this.extensionId, { name: o });
|
|
1417
|
+
this.activeStreamPorts.set(t, h);
|
|
1418
1418
|
const E = setTimeout(() => {
|
|
1419
1419
|
this.activeStreamPorts.has(t) && (this.logger.error(`[BodhiExtClient] Stream timeout for ${t}`), e.postMessage({
|
|
1420
|
-
type:
|
|
1420
|
+
type: i,
|
|
1421
1421
|
requestId: t,
|
|
1422
1422
|
error: { message: "Stream request timed out", type: "timeout_error" }
|
|
1423
1423
|
}), this.cleanupStreamPort(t));
|
|
1424
1424
|
}, p.STREAM_TIMEOUT);
|
|
1425
|
-
|
|
1425
|
+
h.onMessage.addListener((u) => {
|
|
1426
1426
|
n(u, e, t) && (clearTimeout(E), this.cleanupStreamPort(t));
|
|
1427
|
-
}),
|
|
1427
|
+
}), h.onDisconnect.addListener(() => {
|
|
1428
1428
|
clearTimeout(E), this.activeStreamPorts.has(t) && (this.logger.error(`[BodhiExtClient] Bodhi port disconnected for ${t}`), e.postMessage({
|
|
1429
|
-
type:
|
|
1429
|
+
type: i,
|
|
1430
1430
|
requestId: t,
|
|
1431
1431
|
error: {
|
|
1432
1432
|
message: "Connection to Bodhi extension closed unexpectedly",
|
|
@@ -1441,17 +1441,17 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Re = ["bjdjhiombmfbcoeojijpfckl
|
|
|
1441
1441
|
method: r.method,
|
|
1442
1442
|
endpoint: r.endpoint,
|
|
1443
1443
|
body: r.body,
|
|
1444
|
-
headers:
|
|
1444
|
+
headers: c
|
|
1445
1445
|
}
|
|
1446
1446
|
};
|
|
1447
|
-
this.logger.debug("[BodhiExtClient] Sending stream request to bodhi port:", l),
|
|
1448
|
-
} catch (
|
|
1449
|
-
const
|
|
1450
|
-
this.logger.error("[BodhiExtClient] Stream relay error:", JSON.stringify(
|
|
1451
|
-
type:
|
|
1447
|
+
this.logger.debug("[BodhiExtClient] Sending stream request to bodhi port:", l), h.postMessage(l);
|
|
1448
|
+
} catch (c) {
|
|
1449
|
+
const h = c;
|
|
1450
|
+
this.logger.error("[BodhiExtClient] Stream relay error:", JSON.stringify(h.message)), e.postMessage({
|
|
1451
|
+
type: i,
|
|
1452
1452
|
requestId: t,
|
|
1453
1453
|
error: {
|
|
1454
|
-
message: `uncaught error: ${JSON.stringify({ error:
|
|
1454
|
+
message: `uncaught error: ${JSON.stringify({ error: h, message: h.message })}`,
|
|
1455
1455
|
type: "extension_error"
|
|
1456
1456
|
}
|
|
1457
1457
|
});
|
|
@@ -1474,43 +1474,43 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Re = ["bjdjhiombmfbcoeojijpfckl
|
|
|
1474
1474
|
* Handle SSE-parsed streaming request — translates STREAM_* messages to EXT2EXT_CLIENT_STREAM_*
|
|
1475
1475
|
*/
|
|
1476
1476
|
async handleStreamRequest(e, t) {
|
|
1477
|
-
const { requestId: r, request:
|
|
1477
|
+
const { requestId: r, request: o } = t;
|
|
1478
1478
|
await this.handleGenericStreamRelay(
|
|
1479
1479
|
e,
|
|
1480
1480
|
r,
|
|
1481
|
-
|
|
1482
|
-
|
|
1481
|
+
o,
|
|
1482
|
+
oe,
|
|
1483
1483
|
_.STREAM_REQUEST,
|
|
1484
1484
|
a.EXT2EXT_CLIENT_STREAM_ERROR,
|
|
1485
|
-
(s,
|
|
1485
|
+
(s, i, n) => {
|
|
1486
1486
|
if (ne(s)) {
|
|
1487
|
-
const
|
|
1488
|
-
return
|
|
1487
|
+
const c = s.response, h = c.body;
|
|
1488
|
+
return c.status >= 400 ? (i.postMessage({
|
|
1489
1489
|
type: a.EXT2EXT_CLIENT_STREAM_API_ERROR,
|
|
1490
1490
|
requestId: n,
|
|
1491
|
-
response:
|
|
1492
|
-
}), !1) :
|
|
1491
|
+
response: c
|
|
1492
|
+
}), !1) : h?.done ? (i.postMessage({
|
|
1493
1493
|
type: a.EXT2EXT_CLIENT_STREAM_DONE,
|
|
1494
1494
|
requestId: n
|
|
1495
|
-
}), this.logger.info(`[BodhiExtClient] Stream complete for ${n}`), !0) : (
|
|
1495
|
+
}), this.logger.info(`[BodhiExtClient] Stream complete for ${n}`), !0) : (i.postMessage({
|
|
1496
1496
|
type: a.EXT2EXT_CLIENT_STREAM_CHUNK,
|
|
1497
1497
|
requestId: n,
|
|
1498
|
-
response:
|
|
1498
|
+
response: c
|
|
1499
1499
|
}), !1);
|
|
1500
1500
|
} else {
|
|
1501
1501
|
if (ae(s))
|
|
1502
1502
|
return this.logger.error(
|
|
1503
1503
|
`[BodhiExtClient] Stream API error for ${n}: ${s.response.status}`
|
|
1504
|
-
),
|
|
1504
|
+
), i.postMessage({
|
|
1505
1505
|
type: a.EXT2EXT_CLIENT_STREAM_API_ERROR,
|
|
1506
1506
|
requestId: n,
|
|
1507
1507
|
response: s.response
|
|
1508
1508
|
}), !1;
|
|
1509
|
-
if (
|
|
1509
|
+
if (he(s))
|
|
1510
1510
|
return this.logger.error(
|
|
1511
1511
|
`[BodhiExtClient] Stream error for ${n}:`,
|
|
1512
1512
|
s.error.message
|
|
1513
|
-
),
|
|
1513
|
+
), i.postMessage({
|
|
1514
1514
|
type: a.EXT2EXT_CLIENT_STREAM_ERROR,
|
|
1515
1515
|
requestId: n,
|
|
1516
1516
|
error: {
|
|
@@ -1527,31 +1527,31 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Re = ["bjdjhiombmfbcoeojijpfckl
|
|
|
1527
1527
|
* Handle raw text streaming request — translates STREAM_TEXT_* messages to EXT2EXT_CLIENT_STREAM_TEXT_*
|
|
1528
1528
|
*/
|
|
1529
1529
|
async handleStreamTextRequest(e, t) {
|
|
1530
|
-
const { requestId: r, request:
|
|
1530
|
+
const { requestId: r, request: o } = t;
|
|
1531
1531
|
await this.handleGenericStreamRelay(
|
|
1532
1532
|
e,
|
|
1533
1533
|
r,
|
|
1534
|
-
|
|
1535
|
-
|
|
1534
|
+
o,
|
|
1535
|
+
ce,
|
|
1536
1536
|
_.STREAM_TEXT_REQUEST,
|
|
1537
1537
|
a.EXT2EXT_CLIENT_STREAM_TEXT_ERROR,
|
|
1538
|
-
(s,
|
|
1538
|
+
(s, i, n) => {
|
|
1539
1539
|
switch (s.type) {
|
|
1540
1540
|
case _.STREAM_TEXT_START:
|
|
1541
|
-
return
|
|
1541
|
+
return i.postMessage({
|
|
1542
1542
|
type: a.EXT2EXT_CLIENT_STREAM_TEXT_START,
|
|
1543
1543
|
requestId: n,
|
|
1544
1544
|
status: s.status,
|
|
1545
1545
|
headers: s.headers
|
|
1546
1546
|
}), !1;
|
|
1547
1547
|
case _.STREAM_TEXT_CHUNK:
|
|
1548
|
-
return
|
|
1548
|
+
return i.postMessage({
|
|
1549
1549
|
type: a.EXT2EXT_CLIENT_STREAM_TEXT_CHUNK,
|
|
1550
1550
|
requestId: n,
|
|
1551
1551
|
chunk: s.chunk
|
|
1552
1552
|
}), !1;
|
|
1553
1553
|
case _.STREAM_TEXT_DONE:
|
|
1554
|
-
return this.logger.info(`[BodhiExtClient] Stream text complete for ${n}`),
|
|
1554
|
+
return this.logger.info(`[BodhiExtClient] Stream text complete for ${n}`), i.postMessage({
|
|
1555
1555
|
type: a.EXT2EXT_CLIENT_STREAM_TEXT_DONE,
|
|
1556
1556
|
requestId: n
|
|
1557
1557
|
}), !0;
|
|
@@ -1559,7 +1559,7 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Re = ["bjdjhiombmfbcoeojijpfckl
|
|
|
1559
1559
|
return this.logger.error(
|
|
1560
1560
|
`[BodhiExtClient] Stream text error for ${n}:`,
|
|
1561
1561
|
s.error.message
|
|
1562
|
-
),
|
|
1562
|
+
), i.postMessage({
|
|
1563
1563
|
type: a.EXT2EXT_CLIENT_STREAM_TEXT_ERROR,
|
|
1564
1564
|
requestId: n,
|
|
1565
1565
|
error: s.error
|
|
@@ -1654,10 +1654,10 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Re = ["bjdjhiombmfbcoeojijpfckl
|
|
|
1654
1654
|
]);
|
|
1655
1655
|
}
|
|
1656
1656
|
parseJwt(e) {
|
|
1657
|
-
const r = e.split(".")[1].replace(/-/g, "+").replace(/_/g, "/"),
|
|
1657
|
+
const r = e.split(".")[1].replace(/-/g, "+").replace(/_/g, "/"), o = decodeURIComponent(
|
|
1658
1658
|
atob(r).split("").map((s) => "%" + ("00" + s.charCodeAt(0).toString(16)).slice(-2)).join("")
|
|
1659
1659
|
);
|
|
1660
|
-
return JSON.parse(
|
|
1660
|
+
return JSON.parse(o);
|
|
1661
1661
|
}
|
|
1662
1662
|
createErrorClientNotInitialized(e) {
|
|
1663
1663
|
return `Client not initialized. Extension discovery not triggered nor extensionId set, cannot handle request: ${JSON.stringify(e)}`;
|