@bodhiapp/bodhi-js-ext 0.0.19 → 0.0.21
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.d.ts +1 -1
- package/dist/bodhi-ext.esm.js +217 -255
- package/dist/{bodhi-js-sdk/ext/src/direct-client.d.ts → direct-client.d.ts} +1 -1
- package/dist/{bodhi-js-sdk/ext/src/ext-client.d.ts → ext-client.d.ts} +1 -1
- package/dist/{bodhi-js-sdk/ext/src/ext2ext-client.d.ts → ext2ext-client.d.ts} +1 -1
- package/dist/{bodhi-js-sdk/ext/src/facade-client.d.ts → facade-client.d.ts} +1 -1
- package/dist/{bodhi-js-sdk/ext/src/messages.d.ts → messages.d.ts} +2 -2
- package/package.json +3 -2
- package/dist/bodhi-browser-ext/src/types/bodhiext.d.ts +0 -201
- package/dist/bodhi-browser-ext/src/types/common.d.ts +0 -37
- package/dist/bodhi-browser-ext/src/types/index.d.ts +0 -6
- package/dist/bodhi-browser-ext/src/types/protocol.d.ts +0 -222
- package/dist/setup-modal/src/types/extension.d.ts +0 -24
- package/dist/setup-modal/src/types/index.d.ts +0 -20
- package/dist/setup-modal/src/types/lna.d.ts +0 -56
- package/dist/setup-modal/src/types/message-types.d.ts +0 -168
- package/dist/setup-modal/src/types/platform.d.ts +0 -32
- package/dist/setup-modal/src/types/protocol.d.ts +0 -70
- package/dist/setup-modal/src/types/server.d.ts +0 -63
- package/dist/setup-modal/src/types/state.d.ts +0 -42
- package/dist/setup-modal/src/types/type-guards.d.ts +0 -26
- /package/dist/{bodhi-js-sdk/ext/src/build-info.d.ts → build-info.d.ts} +0 -0
- /package/dist/{bodhi-js-sdk/ext/src/constants.d.ts → constants.d.ts} +0 -0
- /package/dist/{bodhi-js-sdk/ext/src/index.d.ts → index.d.ts} +0 -0
- /package/dist/{bodhi-js-sdk/ext/src/vite-env.d.ts → vite-env.d.ts} +0 -0
package/dist/bodhi-ext.esm.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { DirectClientBase as K, createStoragePrefixWithBasePath as L, STORAGE_PREFIXES as U, isApiResultOperationError as v, createOperationError as d, isApiResultError as M, isApiResultSuccess as
|
|
2
|
-
|
|
1
|
+
import { DirectClientBase as K, createStoragePrefixWithBasePath as L, STORAGE_PREFIXES as U, isApiResultOperationError as v, createOperationError as d, isApiResultError as M, isApiResultSuccess as X, getMissingToolsetScopeIds as D, getRequestedToolsetScopes as q, generateCodeVerifier as k, generateCodeChallenge as V, PENDING_EXTENSION_READY as w, Logger as P, NOOP_STATE_CALLBACK as F, createExtensionStateNotInitialized as z, BACKEND_SERVER_NOT_REACHABLE as Q, createExtensionStateNotFound as G, INITIAL_AUTH_STATE as H, createApiError as W, Chat as J, Models as Y, Embeddings as Z, isAuthError as j, BaseFacadeClient as ee, refreshAccessToken as te } from "@bodhiapp/bodhi-js-core";
|
|
2
|
+
import { isExtError as N, isOperationError as re, isApiSuccessResponse as se, MESSAGE_TYPES as I, EXT_ACTIONS as oe, BODHI_STREAM_PORT as ie, isStreamChunk as ne, isStreamApiError as ae, isStreamError as ce } from "@bodhiapp/bodhi-browser-types";
|
|
3
|
+
const a = {
|
|
3
4
|
EXT2EXT_CLIENT_REQUEST: "EXT2EXT_CLIENT_REQUEST",
|
|
4
5
|
EXT2EXT_CLIENT_RESPONSE: "EXT2EXT_CLIENT_RESPONSE",
|
|
5
6
|
EXT2EXT_CLIENT_BROADCAST: "EXT2EXT_CLIENT_BROADCAST",
|
|
@@ -11,18 +12,18 @@ const c = {
|
|
|
11
12
|
EXT2EXT_CLIENT_STREAM_ERROR: "EXT2EXT_CLIENT_STREAM_ERROR",
|
|
12
13
|
EXT2EXT_CLIENT_STREAM_API_ERROR: "EXT2EXT_CLIENT_STREAM_API_ERROR",
|
|
13
14
|
EXT2EXT_CLIENT_STREAM_DONE: "EXT2EXT_CLIENT_STREAM_DONE"
|
|
14
|
-
}, $ = "ext2ext-client-stream",
|
|
15
|
+
}, $ = "ext2ext-client-stream", p = {
|
|
15
16
|
LOGIN: "login",
|
|
16
17
|
LOGOUT: "logout",
|
|
17
18
|
GET_AUTH_STATE: "getAuthState",
|
|
18
19
|
DISCOVER_EXTENSION: "discoverBodhiExtension",
|
|
19
20
|
GET_EXTENSION_ID: "get_extension_id",
|
|
20
21
|
SET_EXTENSION_ID: "setExtensionId"
|
|
21
|
-
},
|
|
22
|
-
function
|
|
23
|
-
return "error" in
|
|
22
|
+
}, he = 5e3, Ee = 3, de = 500, ue = 500, le = 3e4;
|
|
23
|
+
function ge(x) {
|
|
24
|
+
return "error" in x;
|
|
24
25
|
}
|
|
25
|
-
class
|
|
26
|
+
class Te extends K {
|
|
26
27
|
constructor(e, t) {
|
|
27
28
|
const r = L(
|
|
28
29
|
e.basePath,
|
|
@@ -49,10 +50,10 @@ class ce extends K {
|
|
|
49
50
|
if (v(r))
|
|
50
51
|
throw d(r.error.message, r.error.type);
|
|
51
52
|
if (M(r)) {
|
|
52
|
-
const { message:
|
|
53
|
-
throw d(
|
|
53
|
+
const { message: g } = r.body.error;
|
|
54
|
+
throw d(g, "auth_error");
|
|
54
55
|
}
|
|
55
|
-
if (!
|
|
56
|
+
if (!X(r))
|
|
56
57
|
throw d(`Unexpected HTTP ${r.status}`, "auth_error");
|
|
57
58
|
const i = r.body.scope;
|
|
58
59
|
await chrome.storage.session.set({ [this.storageKeys.RESOURCE_SCOPE]: i });
|
|
@@ -62,47 +63,47 @@ class ce extends K {
|
|
|
62
63
|
`toolsetScopeIds not received back from request-access call: [${o.join(", ")}], check developer console on configuring the toolset scopes correctly`,
|
|
63
64
|
"auth_error"
|
|
64
65
|
);
|
|
65
|
-
const n = q(e?.toolsetScopeIds, s),
|
|
66
|
+
const n = q(e?.toolsetScopeIds, s), h = `openid profile email roles ${this.userScope} ${i} ${n}`.trim(), c = k(), u = await V(c), E = k();
|
|
66
67
|
await chrome.storage.session.set({
|
|
67
|
-
[this.storageKeys.CODE_VERIFIER]:
|
|
68
|
-
[this.storageKeys.STATE]:
|
|
68
|
+
[this.storageKeys.CODE_VERIFIER]: c,
|
|
69
|
+
[this.storageKeys.STATE]: E
|
|
69
70
|
});
|
|
70
|
-
const
|
|
71
|
-
return
|
|
71
|
+
const m = chrome.identity.getRedirectURL("callback"), l = new URL(this.authEndpoints.authorize);
|
|
72
|
+
return l.searchParams.set("client_id", this.authClientId), l.searchParams.set("response_type", "code"), l.searchParams.set("redirect_uri", m), l.searchParams.set("scope", h), l.searchParams.set("code_challenge", u), l.searchParams.set("code_challenge_method", "S256"), l.searchParams.set("state", E), new Promise((g, T) => {
|
|
72
73
|
chrome.identity.launchWebAuthFlow(
|
|
73
74
|
{
|
|
74
|
-
url:
|
|
75
|
+
url: l.toString(),
|
|
75
76
|
interactive: !0
|
|
76
77
|
},
|
|
77
|
-
async (
|
|
78
|
+
async (y) => {
|
|
78
79
|
if (chrome.runtime.lastError) {
|
|
79
80
|
await chrome.storage.session.remove([
|
|
80
81
|
this.storageKeys.CODE_VERIFIER,
|
|
81
82
|
this.storageKeys.STATE
|
|
82
|
-
]),
|
|
83
|
+
]), T(chrome.runtime.lastError);
|
|
83
84
|
return;
|
|
84
85
|
}
|
|
85
|
-
if (!
|
|
86
|
+
if (!y) {
|
|
86
87
|
await chrome.storage.session.remove([
|
|
87
88
|
this.storageKeys.CODE_VERIFIER,
|
|
88
89
|
this.storageKeys.STATE
|
|
89
|
-
]),
|
|
90
|
+
]), T(d("No redirect URL received", "oauth-error"));
|
|
90
91
|
return;
|
|
91
92
|
}
|
|
92
93
|
try {
|
|
93
|
-
const
|
|
94
|
-
if (
|
|
94
|
+
const _ = new URL(y), f = _.searchParams.get("code"), R = _.searchParams.get("state"), B = (await chrome.storage.session.get(this.storageKeys.STATE))[this.storageKeys.STATE];
|
|
95
|
+
if (R !== B) {
|
|
95
96
|
await chrome.storage.session.remove([
|
|
96
97
|
this.storageKeys.CODE_VERIFIER,
|
|
97
98
|
this.storageKeys.STATE
|
|
98
|
-
]),
|
|
99
|
+
]), T(d("State mismatch - possible CSRF", "oauth-error"));
|
|
99
100
|
return;
|
|
100
101
|
}
|
|
101
102
|
if (!f) {
|
|
102
103
|
await chrome.storage.session.remove([
|
|
103
104
|
this.storageKeys.CODE_VERIFIER,
|
|
104
105
|
this.storageKeys.STATE
|
|
105
|
-
]),
|
|
106
|
+
]), T(d("No authorization code received", "oauth-error"));
|
|
106
107
|
return;
|
|
107
108
|
}
|
|
108
109
|
await this.exchangeCodeForTokens(f);
|
|
@@ -112,12 +113,12 @@ class ce extends K {
|
|
|
112
113
|
this.setAuthState(C), await chrome.storage.session.remove([
|
|
113
114
|
this.storageKeys.CODE_VERIFIER,
|
|
114
115
|
this.storageKeys.STATE
|
|
115
|
-
]),
|
|
116
|
-
} catch (
|
|
116
|
+
]), g(C);
|
|
117
|
+
} catch (_) {
|
|
117
118
|
await chrome.storage.session.remove([
|
|
118
119
|
this.storageKeys.CODE_VERIFIER,
|
|
119
120
|
this.storageKeys.STATE
|
|
120
|
-
]), _
|
|
121
|
+
]), T(_);
|
|
121
122
|
}
|
|
122
123
|
}
|
|
123
124
|
);
|
|
@@ -174,8 +175,8 @@ class ce extends K {
|
|
|
174
175
|
})
|
|
175
176
|
});
|
|
176
177
|
if (!s.ok) {
|
|
177
|
-
const
|
|
178
|
-
throw new Error(`Token exchange failed: ${s.status} ${
|
|
178
|
+
const h = await s.text();
|
|
179
|
+
throw new Error(`Token exchange failed: ${s.status} ${h}`);
|
|
179
180
|
}
|
|
180
181
|
const o = await s.json(), n = Date.now() + (o.expires_in || 3600) * 1e3;
|
|
181
182
|
await chrome.storage.session.set({
|
|
@@ -201,45 +202,6 @@ class ce extends K {
|
|
|
201
202
|
return chrome.identity.getRedirectURL("callback");
|
|
202
203
|
}
|
|
203
204
|
}
|
|
204
|
-
function he(a) {
|
|
205
|
-
return a !== null && typeof a == "object";
|
|
206
|
-
}
|
|
207
|
-
function Ee(a) {
|
|
208
|
-
return he(a) && "message" in a && typeof a.message == "string" && "type" in a && typeof a.type == "string";
|
|
209
|
-
}
|
|
210
|
-
const S = {
|
|
211
|
-
API_REQUEST: "BODHI_API_REQUEST",
|
|
212
|
-
API_RESPONSE: "BODHI_API_RESPONSE",
|
|
213
|
-
STREAM_REQUEST: "BODHI_STREAM_REQUEST",
|
|
214
|
-
STREAM_CHUNK: "BODHI_STREAM_CHUNK",
|
|
215
|
-
STREAM_ERROR: "BODHI_STREAM_ERROR",
|
|
216
|
-
STREAM_API_ERROR: "BODHI_STREAM_API_ERROR",
|
|
217
|
-
ERROR: "BODHI_ERROR",
|
|
218
|
-
EXT_REQUEST: "BODHI_EXT_REQUEST",
|
|
219
|
-
EXT_RESPONSE: "BODHI_EXT_RESPONSE"
|
|
220
|
-
};
|
|
221
|
-
function ue(a) {
|
|
222
|
-
return a !== null && typeof a == "object" && typeof a.status == "number" && a.status >= 200 && a.status < 300 && "body" in a;
|
|
223
|
-
}
|
|
224
|
-
function de(a) {
|
|
225
|
-
return a !== null && typeof a == "object" && a.type === S.STREAM_CHUNK;
|
|
226
|
-
}
|
|
227
|
-
function le(a) {
|
|
228
|
-
return a !== null && typeof a == "object" && a.type === S.STREAM_API_ERROR;
|
|
229
|
-
}
|
|
230
|
-
function ge(a) {
|
|
231
|
-
return a !== null && typeof a == "object" && a.type === S.STREAM_ERROR;
|
|
232
|
-
}
|
|
233
|
-
function N(a) {
|
|
234
|
-
return a !== null && typeof a == "object" && "error" in a;
|
|
235
|
-
}
|
|
236
|
-
function Te(a) {
|
|
237
|
-
return a instanceof Error && "error" in a && !("response" in a) && Ee(a.error);
|
|
238
|
-
}
|
|
239
|
-
const _e = {
|
|
240
|
-
GET_EXTENSION_ID: "get_extension_id",
|
|
241
|
-
TEST_CONNECTION: "test_connection"
|
|
242
|
-
}, pe = "BODHI_STREAM_PORT";
|
|
243
205
|
class me {
|
|
244
206
|
constructor(e = {}, t) {
|
|
245
207
|
this.state = {
|
|
@@ -247,7 +209,7 @@ class me {
|
|
|
247
209
|
extension: "not-initialized",
|
|
248
210
|
extensionId: null,
|
|
249
211
|
server: w
|
|
250
|
-
}, this.extensionId = null, this.broadcastListenerActive = !1, this.config = e, this.logger = new P("ExtClient", e?.logLevel || "warn"), this.onStateChange = t ?? F, this.apiTimeoutMs = e.apiTimeoutMs ??
|
|
212
|
+
}, this.extensionId = null, this.broadcastListenerActive = !1, this.config = e, this.logger = new P("ExtClient", e?.logLevel || "warn"), this.onStateChange = t ?? F, this.apiTimeoutMs = e.apiTimeoutMs ?? le;
|
|
251
213
|
}
|
|
252
214
|
/**
|
|
253
215
|
* Set client state and notify callback
|
|
@@ -274,7 +236,7 @@ class me {
|
|
|
274
236
|
setupBroadcastListener() {
|
|
275
237
|
this.broadcastListenerActive || (this.broadcastListenerActive = !0, chrome.runtime.onMessage.addListener((e) => {
|
|
276
238
|
const t = e;
|
|
277
|
-
return t?.type ===
|
|
239
|
+
return t?.type === a.EXT2EXT_CLIENT_BROADCAST && t.event === "authStateChanged" && this.handleAuthStateChangedBroadcast(), !1;
|
|
278
240
|
}), this.logger.debug("Broadcast listener setup complete"));
|
|
279
241
|
}
|
|
280
242
|
/**
|
|
@@ -315,17 +277,17 @@ class me {
|
|
|
315
277
|
async init(e = {}) {
|
|
316
278
|
if (!e.testConnection && !e.selectedConnection) {
|
|
317
279
|
this.logger.info("No testConnection or selectedConnection, returning not-initialized state");
|
|
318
|
-
const i =
|
|
280
|
+
const i = z();
|
|
319
281
|
return this.setState(i), i;
|
|
320
282
|
}
|
|
321
283
|
if (this.extensionId && !e.testConnection)
|
|
322
284
|
return this.logger.debug("Already initialized with extensionId, skipping discovery"), this.state;
|
|
323
|
-
const t = e.timeoutMs ?? this.config.initParams?.extension?.timeoutMs ??
|
|
285
|
+
const t = e.timeoutMs ?? this.config.initParams?.extension?.timeoutMs ?? he, r = e.savedState?.extensionId;
|
|
324
286
|
try {
|
|
325
287
|
if (!this.extensionId) {
|
|
326
288
|
if (r)
|
|
327
289
|
this.logger.info("Restoring with known extensionId:", r), await this.sendExtMessageWithTimeout(
|
|
328
|
-
|
|
290
|
+
p.SET_EXTENSION_ID,
|
|
329
291
|
{ extensionId: r },
|
|
330
292
|
t
|
|
331
293
|
), this.extensionId = r;
|
|
@@ -336,7 +298,7 @@ class me {
|
|
|
336
298
|
attemptWaitMs: this.config.initParams?.extension?.attemptWaitMs,
|
|
337
299
|
attemptTimeout: this.config.initParams?.extension?.attemptTimeout
|
|
338
300
|
}, n = await this.sendExtMessageWithTimeout(
|
|
339
|
-
|
|
301
|
+
p.DISCOVER_EXTENSION,
|
|
340
302
|
o,
|
|
341
303
|
t
|
|
342
304
|
);
|
|
@@ -355,12 +317,12 @@ class me {
|
|
|
355
317
|
try {
|
|
356
318
|
s = await this.getServerState(), this.logger.info("Server connectivity tested, state:", s.status);
|
|
357
319
|
} catch (o) {
|
|
358
|
-
this.logger.error("Failed to get server state:", o), s =
|
|
320
|
+
this.logger.error("Failed to get server state:", o), s = Q;
|
|
359
321
|
}
|
|
360
322
|
return this.setState({ ...i, server: s }), this.state;
|
|
361
323
|
} catch (i) {
|
|
362
324
|
this.logger.error("Failed to initialize extension:", i), this.extensionId = null;
|
|
363
|
-
const s =
|
|
325
|
+
const s = G();
|
|
364
326
|
return this.setState(s), this.state;
|
|
365
327
|
}
|
|
366
328
|
}
|
|
@@ -380,7 +342,7 @@ class me {
|
|
|
380
342
|
async sendExtRequest(e, t) {
|
|
381
343
|
try {
|
|
382
344
|
const r = this.generateRequestId(), i = await chrome.runtime.sendMessage({
|
|
383
|
-
type:
|
|
345
|
+
type: a.EXT2EXT_CLIENT_REQUEST,
|
|
384
346
|
requestId: r,
|
|
385
347
|
request: {
|
|
386
348
|
action: e,
|
|
@@ -389,7 +351,7 @@ class me {
|
|
|
389
351
|
});
|
|
390
352
|
if (!i)
|
|
391
353
|
throw d("No response from background script", "extension_error");
|
|
392
|
-
if (i.type !==
|
|
354
|
+
if (i.type !== a.EXT2EXT_CLIENT_RESPONSE)
|
|
393
355
|
throw d(
|
|
394
356
|
"Invalid response type from background script",
|
|
395
357
|
"extension_error"
|
|
@@ -401,7 +363,7 @@ class me {
|
|
|
401
363
|
}
|
|
402
364
|
return s;
|
|
403
365
|
} catch (r) {
|
|
404
|
-
throw
|
|
366
|
+
throw re(r) ? r : d(
|
|
405
367
|
r instanceof Error ? r.message : "Unknown error occurred",
|
|
406
368
|
"extension_error"
|
|
407
369
|
);
|
|
@@ -414,7 +376,7 @@ class me {
|
|
|
414
376
|
async sendRawApiMessage(e, t, r, i, s) {
|
|
415
377
|
const o = this.generateRequestId();
|
|
416
378
|
return await chrome.runtime.sendMessage({
|
|
417
|
-
type:
|
|
379
|
+
type: a.EXT2EXT_CLIENT_API_REQUEST,
|
|
418
380
|
requestId: o,
|
|
419
381
|
request: {
|
|
420
382
|
method: e,
|
|
@@ -431,8 +393,8 @@ class me {
|
|
|
431
393
|
async sendApiRequest(e, t, r, i, s) {
|
|
432
394
|
try {
|
|
433
395
|
const o = new Promise(
|
|
434
|
-
(
|
|
435
|
-
() =>
|
|
396
|
+
(h, c) => setTimeout(
|
|
397
|
+
() => c(
|
|
436
398
|
new Error(
|
|
437
399
|
`[bodhi-js-sdk/ext] network timeout: api request not completed within configured/default timeout of ${this.apiTimeoutMs}ms`
|
|
438
400
|
)
|
|
@@ -443,12 +405,12 @@ class me {
|
|
|
443
405
|
this.sendRawApiMessage(e, t, r, i, s),
|
|
444
406
|
o
|
|
445
407
|
]);
|
|
446
|
-
if (
|
|
447
|
-
const
|
|
408
|
+
if (ge(n)) {
|
|
409
|
+
const h = n.error.type || "extension_error";
|
|
448
410
|
return {
|
|
449
411
|
error: {
|
|
450
412
|
message: n.error.message,
|
|
451
|
-
type:
|
|
413
|
+
type: h
|
|
452
414
|
}
|
|
453
415
|
};
|
|
454
416
|
}
|
|
@@ -475,7 +437,7 @@ class me {
|
|
|
475
437
|
chrome.runtime.onMessage.removeListener(i);
|
|
476
438
|
try {
|
|
477
439
|
const o = await this.getAuthState();
|
|
478
|
-
if (
|
|
440
|
+
if (j(o)) {
|
|
479
441
|
r(
|
|
480
442
|
d(`Login failed: ${o.error?.message}`, "auth-error")
|
|
481
443
|
);
|
|
@@ -491,7 +453,7 @@ class me {
|
|
|
491
453
|
}
|
|
492
454
|
}
|
|
493
455
|
};
|
|
494
|
-
chrome.runtime.onMessage.addListener(i), this.sendExtRequest(
|
|
456
|
+
chrome.runtime.onMessage.addListener(i), this.sendExtRequest(p.LOGIN, e).catch((s) => {
|
|
495
457
|
chrome.runtime.onMessage.removeListener(i), r(s);
|
|
496
458
|
});
|
|
497
459
|
});
|
|
@@ -502,7 +464,7 @@ class me {
|
|
|
502
464
|
* @returns AuthLoggedOut with logged out state
|
|
503
465
|
*/
|
|
504
466
|
async logout() {
|
|
505
|
-
await this.sendExtRequest(
|
|
467
|
+
await this.sendExtRequest(p.LOGOUT);
|
|
506
468
|
const e = {
|
|
507
469
|
status: "unauthenticated",
|
|
508
470
|
user: null,
|
|
@@ -518,8 +480,8 @@ class me {
|
|
|
518
480
|
*/
|
|
519
481
|
async getAuthState() {
|
|
520
482
|
return this.isClientInitialized() ? (await this.sendExtRequest(
|
|
521
|
-
|
|
522
|
-
)).authState :
|
|
483
|
+
p.GET_AUTH_STATE
|
|
484
|
+
)).authState : H;
|
|
523
485
|
}
|
|
524
486
|
/**
|
|
525
487
|
* Ping bodhi-browser-ext API via /ping endpoint
|
|
@@ -539,7 +501,7 @@ class me {
|
|
|
539
501
|
version: null,
|
|
540
502
|
error: e.error
|
|
541
503
|
};
|
|
542
|
-
if (!
|
|
504
|
+
if (!X(e))
|
|
543
505
|
return {
|
|
544
506
|
status: "not-reachable",
|
|
545
507
|
version: null,
|
|
@@ -588,55 +550,55 @@ class me {
|
|
|
588
550
|
endpoint: t,
|
|
589
551
|
requestId: o
|
|
590
552
|
});
|
|
591
|
-
const n = chrome.runtime.connect({ name: $ }),
|
|
592
|
-
start: (
|
|
593
|
-
n.onMessage.addListener((
|
|
594
|
-
if (
|
|
595
|
-
switch (
|
|
596
|
-
case
|
|
597
|
-
this.logger.debug("Stream complete", { requestId: o }),
|
|
553
|
+
const n = chrome.runtime.connect({ name: $ }), c = new ReadableStream({
|
|
554
|
+
start: (u) => {
|
|
555
|
+
n.onMessage.addListener((E) => {
|
|
556
|
+
if (E.requestId === o)
|
|
557
|
+
switch (E.type) {
|
|
558
|
+
case a.EXT2EXT_CLIENT_STREAM_DONE:
|
|
559
|
+
this.logger.debug("Stream complete", { requestId: o }), u.close(), n.disconnect();
|
|
598
560
|
break;
|
|
599
|
-
case
|
|
561
|
+
case a.EXT2EXT_CLIENT_STREAM_ERROR:
|
|
600
562
|
this.logger.error("Stream error", {
|
|
601
563
|
requestId: o,
|
|
602
|
-
error: JSON.stringify(
|
|
603
|
-
}),
|
|
564
|
+
error: JSON.stringify(E.error)
|
|
565
|
+
}), u.error(
|
|
604
566
|
d(
|
|
605
|
-
|
|
567
|
+
E.error.message,
|
|
606
568
|
"extension_error"
|
|
607
569
|
)
|
|
608
570
|
), n.disconnect();
|
|
609
571
|
break;
|
|
610
|
-
case
|
|
611
|
-
const
|
|
572
|
+
case a.EXT2EXT_CLIENT_STREAM_API_ERROR: {
|
|
573
|
+
const m = E;
|
|
612
574
|
this.logger.error("Stream API error", {
|
|
613
575
|
requestId: o,
|
|
614
|
-
error:
|
|
615
|
-
}),
|
|
576
|
+
error: m.response.body?.error
|
|
577
|
+
}), u.error(
|
|
616
578
|
W(
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
579
|
+
m.response.body?.error?.message || "API error",
|
|
580
|
+
m.response.status,
|
|
581
|
+
m.response.body
|
|
620
582
|
)
|
|
621
583
|
), n.disconnect();
|
|
622
584
|
break;
|
|
623
585
|
}
|
|
624
|
-
case
|
|
625
|
-
const
|
|
626
|
-
|
|
586
|
+
case a.EXT2EXT_CLIENT_STREAM_CHUNK: {
|
|
587
|
+
const m = E;
|
|
588
|
+
se(m.response) && u.enqueue(m.response.body);
|
|
627
589
|
break;
|
|
628
590
|
}
|
|
629
591
|
}
|
|
630
592
|
}), n.onDisconnect.addListener(() => {
|
|
631
593
|
this.logger.debug("Port disconnected", { requestId: o });
|
|
632
594
|
try {
|
|
633
|
-
|
|
595
|
+
u.error(
|
|
634
596
|
d("Connection closed unexpectedly", "extension_error")
|
|
635
597
|
);
|
|
636
598
|
} catch {
|
|
637
599
|
}
|
|
638
600
|
}), n.postMessage({
|
|
639
|
-
type:
|
|
601
|
+
type: a.EXT2EXT_CLIENT_STREAM_REQUEST,
|
|
640
602
|
requestId: o,
|
|
641
603
|
request: { method: e, endpoint: t, body: r, headers: i, authenticated: s }
|
|
642
604
|
});
|
|
@@ -644,15 +606,15 @@ class me {
|
|
|
644
606
|
}).getReader();
|
|
645
607
|
try {
|
|
646
608
|
for (; ; ) {
|
|
647
|
-
const { done:
|
|
648
|
-
if (
|
|
609
|
+
const { done: u, value: E } = await c.read();
|
|
610
|
+
if (u) {
|
|
649
611
|
this.logger.debug("Stream iteration complete");
|
|
650
612
|
break;
|
|
651
613
|
}
|
|
652
|
-
yield
|
|
614
|
+
yield E;
|
|
653
615
|
}
|
|
654
616
|
} finally {
|
|
655
|
-
|
|
617
|
+
c.releaseLock();
|
|
656
618
|
}
|
|
657
619
|
}
|
|
658
620
|
// ============================================================================
|
|
@@ -665,7 +627,7 @@ class me {
|
|
|
665
627
|
return this._models ??= new Y(this);
|
|
666
628
|
}
|
|
667
629
|
get embeddings() {
|
|
668
|
-
return this._embeddings ??= new
|
|
630
|
+
return this._embeddings ??= new Z(this);
|
|
669
631
|
}
|
|
670
632
|
/**
|
|
671
633
|
* Serialize ext2ext client state for persistence
|
|
@@ -684,7 +646,7 @@ class me {
|
|
|
684
646
|
};
|
|
685
647
|
}
|
|
686
648
|
}
|
|
687
|
-
class
|
|
649
|
+
class Ie extends ee {
|
|
688
650
|
constructor(e, t, r) {
|
|
689
651
|
const i = t || {}, s = {
|
|
690
652
|
basePath: i.basePath || "/",
|
|
@@ -713,7 +675,7 @@ class Re extends ee {
|
|
|
713
675
|
);
|
|
714
676
|
}
|
|
715
677
|
createDirectClient(e, t, r) {
|
|
716
|
-
return new
|
|
678
|
+
return new Te(
|
|
717
679
|
{
|
|
718
680
|
authClientId: e,
|
|
719
681
|
authServerUrl: t.authServerUrl,
|
|
@@ -726,12 +688,12 @@ class Re extends ee {
|
|
|
726
688
|
);
|
|
727
689
|
}
|
|
728
690
|
}
|
|
729
|
-
const
|
|
691
|
+
const pe = ["ggedphdcbekjlomjaidbajglgihbeaon"], _e = ["bjdjhiombmfbcoeojijpfckljjghmjbf"], A = "production", S = class S {
|
|
730
692
|
// ============================================================================
|
|
731
693
|
// Constructor
|
|
732
694
|
// ============================================================================
|
|
733
695
|
constructor(e, t) {
|
|
734
|
-
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.userScope = t?.userScope || "scope_user_user", this.extensionId = t?.extensionId, this.logger = new P("BodhiExtClient", t?.logLevel || "warn"), this.attempts = t?.attempts ??
|
|
696
|
+
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.userScope = t?.userScope || "scope_user_user", this.extensionId = t?.extensionId, this.logger = new P("BodhiExtClient", t?.logLevel || "warn"), this.attempts = t?.attempts ?? Ee, this.attemptWaitMs = t?.attemptWaitMs ?? de, this.attemptTimeout = t?.attemptTimeout ?? ue, this.authEndpoints = {
|
|
735
697
|
authorize: `${this.authServerUrl}/protocol/openid-connect/auth`,
|
|
736
698
|
token: `${this.authServerUrl}/protocol/openid-connect/token`,
|
|
737
699
|
userinfo: `${this.authServerUrl}/protocol/openid-connect/userinfo`,
|
|
@@ -749,11 +711,11 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Ie = ["bjdjhiombmfbcoeojijpfckl
|
|
|
749
711
|
}
|
|
750
712
|
static generateCodeVerifier() {
|
|
751
713
|
const e = new Uint8Array(32);
|
|
752
|
-
return crypto.getRandomValues(e),
|
|
714
|
+
return crypto.getRandomValues(e), S.base64UrlEncode(e.buffer);
|
|
753
715
|
}
|
|
754
716
|
static async generateCodeChallenge(e) {
|
|
755
717
|
const r = new TextEncoder().encode(e), i = await crypto.subtle.digest("SHA-256", r);
|
|
756
|
-
return
|
|
718
|
+
return S.base64UrlEncode(i);
|
|
757
719
|
}
|
|
758
720
|
// ============================================================================
|
|
759
721
|
// State Management
|
|
@@ -772,7 +734,7 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Ie = ["bjdjhiombmfbcoeojijpfckl
|
|
|
772
734
|
* Get extension IDs for current environment
|
|
773
735
|
*/
|
|
774
736
|
getExtensionIdsForEnvironment() {
|
|
775
|
-
const t = A !== "production" ?
|
|
737
|
+
const t = A !== "production" ? pe : _e;
|
|
776
738
|
return this.logger.info("[Ext2Ext/Registry] Environment: production"), this.logger.debug("[Ext2Ext/Registry] Using extension IDs:", t), t;
|
|
777
739
|
}
|
|
778
740
|
/**
|
|
@@ -787,7 +749,7 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Ie = ["bjdjhiombmfbcoeojijpfckl
|
|
|
787
749
|
}, this.attemptTimeout);
|
|
788
750
|
try {
|
|
789
751
|
const s = {
|
|
790
|
-
type:
|
|
752
|
+
type: I.EXT_REQUEST,
|
|
791
753
|
requestId: crypto.randomUUID(),
|
|
792
754
|
request: {
|
|
793
755
|
action: "get_extension_id"
|
|
@@ -803,7 +765,7 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Ie = ["bjdjhiombmfbcoeojijpfckl
|
|
|
803
765
|
}
|
|
804
766
|
this.logger.debug(`[Ext2Ext/Discovery] Response from ${e}:`, o);
|
|
805
767
|
const n = o;
|
|
806
|
-
n && n.type ===
|
|
768
|
+
n && n.type === I.EXT_RESPONSE ? (this.logger.debug(`[Ext2Ext/Discovery] ✓ Extension ${e} responded`), t(!0)) : (this.logger.error(
|
|
807
769
|
`[Ext2Ext/Discovery] Invalid response from ${e}:`,
|
|
808
770
|
o
|
|
809
771
|
), r(new Error("Invalid response")));
|
|
@@ -833,24 +795,24 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Ie = ["bjdjhiombmfbcoeojijpfckl
|
|
|
833
795
|
`[Ext2Ext/Discovery] Will try ${s.length} extension(s):`,
|
|
834
796
|
s
|
|
835
797
|
);
|
|
836
|
-
for (const
|
|
837
|
-
for (let
|
|
798
|
+
for (const h of s) {
|
|
799
|
+
for (let c = 1; c <= t; c++) {
|
|
838
800
|
this.logger.debug(
|
|
839
|
-
`[Ext2Ext/Discovery] Trying ${
|
|
801
|
+
`[Ext2Ext/Discovery] Trying ${h} - attempt ${c}/${t}`
|
|
840
802
|
);
|
|
841
803
|
try {
|
|
842
|
-
return await this.pingExtension(
|
|
804
|
+
return await this.pingExtension(h), this.logger.info(`[Ext2Ext/Discovery] ✓ Found: ${h} on attempt ${c}`), {
|
|
843
805
|
success: !0,
|
|
844
|
-
extensionId:
|
|
806
|
+
extensionId: h
|
|
845
807
|
};
|
|
846
|
-
} catch (
|
|
808
|
+
} catch (u) {
|
|
847
809
|
this.logger.debug(
|
|
848
|
-
`[Ext2Ext/Discovery] Attempt ${
|
|
849
|
-
),
|
|
810
|
+
`[Ext2Ext/Discovery] Attempt ${c} failed for ${h}: ${u instanceof Error ? u.message : "Unknown error"}`
|
|
811
|
+
), c < t && await this.sleep(r);
|
|
850
812
|
}
|
|
851
813
|
}
|
|
852
814
|
this.logger.warn(
|
|
853
|
-
`[Ext2Ext/Discovery] ✗ Not found: ${
|
|
815
|
+
`[Ext2Ext/Discovery] ✗ Not found: ${h} after ${t} attempts`
|
|
854
816
|
);
|
|
855
817
|
}
|
|
856
818
|
const o = s.join(", "), n = `Extension not found. Tried ${s.length} IDs with ${t} attempts each: ${o}`;
|
|
@@ -870,8 +832,8 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Ie = ["bjdjhiombmfbcoeojijpfckl
|
|
|
870
832
|
this.logger.debug("[BodhiExtClient] Listeners already initialized, skipping");
|
|
871
833
|
return;
|
|
872
834
|
}
|
|
873
|
-
this.listenersInitialized = !0, chrome.runtime.onMessage.addListener((e, t, r) => e.type !==
|
|
874
|
-
type:
|
|
835
|
+
this.listenersInitialized = !0, chrome.runtime.onMessage.addListener((e, t, r) => e.type !== a.EXT2EXT_CLIENT_REQUEST && e.type !== a.EXT2EXT_CLIENT_API_REQUEST ? !1 : this.state !== "ready" && !(e.type === a.EXT2EXT_CLIENT_REQUEST && e.request.action === p.DISCOVER_EXTENSION) ? (e.type === a.EXT2EXT_CLIENT_REQUEST ? r({
|
|
836
|
+
type: a.EXT2EXT_CLIENT_RESPONSE,
|
|
875
837
|
requestId: e.requestId,
|
|
876
838
|
response: {
|
|
877
839
|
error: {
|
|
@@ -880,7 +842,7 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Ie = ["bjdjhiombmfbcoeojijpfckl
|
|
|
880
842
|
}
|
|
881
843
|
}
|
|
882
844
|
}) : r({
|
|
883
|
-
type:
|
|
845
|
+
type: a.EXT2EXT_CLIENT_API_RESPONSE,
|
|
884
846
|
requestId: e.requestId,
|
|
885
847
|
error: {
|
|
886
848
|
message: `Client not initialized. Extension discovery not complete, cannot handle type:${e.type}, message:${JSON.stringify(e)}`,
|
|
@@ -895,9 +857,9 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Ie = ["bjdjhiombmfbcoeojijpfckl
|
|
|
895
857
|
return;
|
|
896
858
|
}
|
|
897
859
|
this.logger.info("[BodhiExtClient] Streaming port connected"), e.onMessage.addListener(async (t) => {
|
|
898
|
-
if (t.type !==
|
|
860
|
+
if (t.type !== a.EXT2EXT_CLIENT_STREAM_REQUEST) {
|
|
899
861
|
this.logger.warn("[BodhiExtClient] Unknown stream message type:", t.type), e.postMessage({
|
|
900
|
-
type:
|
|
862
|
+
type: a.EXT2EXT_CLIENT_STREAM_ERROR,
|
|
901
863
|
requestId: t.requestId,
|
|
902
864
|
error: {
|
|
903
865
|
message: "Unknown stream message type",
|
|
@@ -940,7 +902,7 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Ie = ["bjdjhiombmfbcoeojijpfckl
|
|
|
940
902
|
*/
|
|
941
903
|
broadcastAuthStateChange() {
|
|
942
904
|
chrome.runtime.sendMessage({
|
|
943
|
-
type:
|
|
905
|
+
type: a.EXT2EXT_CLIENT_BROADCAST,
|
|
944
906
|
event: "authStateChanged"
|
|
945
907
|
}).catch((e) => {
|
|
946
908
|
this.logger.debug("[BodhiExtClient] No listeners for broadcast:", e.message);
|
|
@@ -970,7 +932,7 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Ie = ["bjdjhiombmfbcoeojijpfckl
|
|
|
970
932
|
const s = await this._getAccessTokenRaw();
|
|
971
933
|
if (!s)
|
|
972
934
|
return {
|
|
973
|
-
type:
|
|
935
|
+
type: a.EXT2EXT_CLIENT_API_RESPONSE,
|
|
974
936
|
requestId: t,
|
|
975
937
|
error: {
|
|
976
938
|
message: "Not authenticated. Please log in first.",
|
|
@@ -989,13 +951,13 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Ie = ["bjdjhiombmfbcoeojijpfckl
|
|
|
989
951
|
r
|
|
990
952
|
);
|
|
991
953
|
return {
|
|
992
|
-
type:
|
|
954
|
+
type: a.EXT2EXT_CLIENT_API_RESPONSE,
|
|
993
955
|
requestId: t,
|
|
994
956
|
response: i
|
|
995
957
|
};
|
|
996
958
|
} catch (r) {
|
|
997
959
|
return this.logger.error("[BodhiExtClient] API request failed:", r), {
|
|
998
|
-
type:
|
|
960
|
+
type: a.EXT2EXT_CLIENT_API_RESPONSE,
|
|
999
961
|
requestId: t,
|
|
1000
962
|
error: {
|
|
1001
963
|
message: r instanceof Error ? r.message : "Unknown error",
|
|
@@ -1016,7 +978,7 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Ie = ["bjdjhiombmfbcoeojijpfckl
|
|
|
1016
978
|
try {
|
|
1017
979
|
let o = {};
|
|
1018
980
|
switch (i) {
|
|
1019
|
-
case
|
|
981
|
+
case p.DISCOVER_EXTENSION: {
|
|
1020
982
|
const n = s;
|
|
1021
983
|
await this.init(n), this.logger.info("[BodhiExtClient] Discovery successful:", {
|
|
1022
984
|
extensionId: this.extensionId,
|
|
@@ -1027,15 +989,15 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Ie = ["bjdjhiombmfbcoeojijpfckl
|
|
|
1027
989
|
};
|
|
1028
990
|
break;
|
|
1029
991
|
}
|
|
1030
|
-
case
|
|
992
|
+
case p.SET_EXTENSION_ID: {
|
|
1031
993
|
const { extensionId: n } = s;
|
|
1032
994
|
this.extensionId = n, this.state = "ready", this.logger.info("[BodhiExtClient] Extension ID set:", { extensionId: n }), o = { success: !0 };
|
|
1033
995
|
break;
|
|
1034
996
|
}
|
|
1035
|
-
case
|
|
1036
|
-
const n = await this.sendExtRequestRaw(
|
|
997
|
+
case p.GET_EXTENSION_ID: {
|
|
998
|
+
const n = await this.sendExtRequestRaw(oe.GET_EXTENSION_ID, s);
|
|
1037
999
|
return N(n.response) ? {
|
|
1038
|
-
type:
|
|
1000
|
+
type: a.EXT2EXT_CLIENT_RESPONSE,
|
|
1039
1001
|
requestId: t,
|
|
1040
1002
|
response: {
|
|
1041
1003
|
error: {
|
|
@@ -1044,25 +1006,25 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Ie = ["bjdjhiombmfbcoeojijpfckl
|
|
|
1044
1006
|
}
|
|
1045
1007
|
}
|
|
1046
1008
|
} : {
|
|
1047
|
-
type:
|
|
1009
|
+
type: a.EXT2EXT_CLIENT_RESPONSE,
|
|
1048
1010
|
requestId: t,
|
|
1049
1011
|
response: n.response
|
|
1050
1012
|
};
|
|
1051
1013
|
}
|
|
1052
|
-
case
|
|
1014
|
+
case p.LOGIN: {
|
|
1053
1015
|
const n = s;
|
|
1054
1016
|
await this.login(n), this.broadcastAuthStateChange();
|
|
1055
1017
|
break;
|
|
1056
1018
|
}
|
|
1057
|
-
case
|
|
1019
|
+
case p.LOGOUT:
|
|
1058
1020
|
await this.logout(), this.broadcastAuthStateChange();
|
|
1059
1021
|
break;
|
|
1060
|
-
case
|
|
1022
|
+
case p.GET_AUTH_STATE:
|
|
1061
1023
|
o = { authState: await this.getAuthState() };
|
|
1062
1024
|
break;
|
|
1063
1025
|
default:
|
|
1064
1026
|
return {
|
|
1065
|
-
type:
|
|
1027
|
+
type: a.EXT2EXT_CLIENT_RESPONSE,
|
|
1066
1028
|
requestId: t,
|
|
1067
1029
|
response: {
|
|
1068
1030
|
error: { message: `Unknown action: ${i}`, type: "UNKNOWN_ACTION" }
|
|
@@ -1070,13 +1032,13 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Ie = ["bjdjhiombmfbcoeojijpfckl
|
|
|
1070
1032
|
};
|
|
1071
1033
|
}
|
|
1072
1034
|
return {
|
|
1073
|
-
type:
|
|
1035
|
+
type: a.EXT2EXT_CLIENT_RESPONSE,
|
|
1074
1036
|
requestId: t,
|
|
1075
1037
|
response: o
|
|
1076
1038
|
};
|
|
1077
1039
|
} catch (o) {
|
|
1078
1040
|
return this.logger.error("[BodhiExtClient] Unexpected error:", o), {
|
|
1079
|
-
type:
|
|
1041
|
+
type: a.EXT2EXT_CLIENT_RESPONSE,
|
|
1080
1042
|
requestId: t,
|
|
1081
1043
|
response: {
|
|
1082
1044
|
error: {
|
|
@@ -1089,14 +1051,14 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Ie = ["bjdjhiombmfbcoeojijpfckl
|
|
|
1089
1051
|
// Implementation signature (must be compatible with all overloads)
|
|
1090
1052
|
async handleAction(e) {
|
|
1091
1053
|
switch (e.type) {
|
|
1092
|
-
case
|
|
1054
|
+
case a.EXT2EXT_CLIENT_API_REQUEST:
|
|
1093
1055
|
return this.handleApiRequest(e);
|
|
1094
|
-
case
|
|
1056
|
+
case a.EXT2EXT_CLIENT_REQUEST:
|
|
1095
1057
|
return this.handleExtClientRequest(e);
|
|
1096
1058
|
default: {
|
|
1097
1059
|
const { requestId: t } = e;
|
|
1098
1060
|
return this.logger.error("[BodhiExtClient] Unknown message type:", e.type), {
|
|
1099
|
-
type:
|
|
1061
|
+
type: a.EXT2EXT_CLIENT_RESPONSE,
|
|
1100
1062
|
requestId: t,
|
|
1101
1063
|
response: {
|
|
1102
1064
|
error: {
|
|
@@ -1126,10 +1088,10 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Ie = ["bjdjhiombmfbcoeojijpfckl
|
|
|
1126
1088
|
if (v(r))
|
|
1127
1089
|
throw d(r.error.message, r.error.type);
|
|
1128
1090
|
if (M(r)) {
|
|
1129
|
-
const { message:
|
|
1130
|
-
throw d(
|
|
1091
|
+
const { message: g } = r.body.error;
|
|
1092
|
+
throw d(g, "auth_error");
|
|
1131
1093
|
}
|
|
1132
|
-
if (!
|
|
1094
|
+
if (!X(r))
|
|
1133
1095
|
throw d(`Unexpected HTTP ${r.status}`, "auth_error");
|
|
1134
1096
|
const i = r.body.scope, s = r.body.toolsets || [], o = D(e?.toolsetScopeIds, s);
|
|
1135
1097
|
if (o.length > 0)
|
|
@@ -1137,41 +1099,41 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Ie = ["bjdjhiombmfbcoeojijpfckl
|
|
|
1137
1099
|
`toolsetScopeIds not received back from request-access call: [${o.join(", ")}], check developer console on configuring the toolset scopes correctly`,
|
|
1138
1100
|
"auth_error"
|
|
1139
1101
|
);
|
|
1140
|
-
const n = q(e?.toolsetScopeIds, s),
|
|
1102
|
+
const n = q(e?.toolsetScopeIds, s), h = `openid profile email roles ${this.userScope} ${i} ${n}`.trim(), c = S.generateCodeVerifier(), u = await S.generateCodeChallenge(c), E = S.generateCodeVerifier();
|
|
1141
1103
|
await chrome.storage.session.set({
|
|
1142
|
-
codeVerifier:
|
|
1143
|
-
state:
|
|
1104
|
+
codeVerifier: c,
|
|
1105
|
+
state: E,
|
|
1144
1106
|
authInProgress: !0
|
|
1145
1107
|
});
|
|
1146
|
-
const
|
|
1147
|
-
return
|
|
1108
|
+
const m = chrome.identity.getRedirectURL("callback"), l = new URL(this.authEndpoints.authorize);
|
|
1109
|
+
return l.searchParams.set("client_id", this.authClientId), l.searchParams.set("response_type", "code"), l.searchParams.set("redirect_uri", m), l.searchParams.set("scope", h), l.searchParams.set("code_challenge", u), l.searchParams.set("code_challenge_method", "S256"), l.searchParams.set("state", E), new Promise((g, T) => {
|
|
1148
1110
|
chrome.identity.launchWebAuthFlow(
|
|
1149
1111
|
{
|
|
1150
|
-
url:
|
|
1112
|
+
url: l.toString(),
|
|
1151
1113
|
interactive: !0
|
|
1152
1114
|
},
|
|
1153
|
-
async (
|
|
1115
|
+
async (y) => {
|
|
1154
1116
|
if (await chrome.storage.session.set({ authInProgress: !1 }), chrome.runtime.lastError) {
|
|
1155
|
-
await chrome.storage.session.remove(["codeVerifier", "state"]),
|
|
1117
|
+
await chrome.storage.session.remove(["codeVerifier", "state"]), T(chrome.runtime.lastError);
|
|
1156
1118
|
return;
|
|
1157
1119
|
}
|
|
1158
|
-
if (!
|
|
1159
|
-
await chrome.storage.session.remove(["codeVerifier", "state"]),
|
|
1120
|
+
if (!y) {
|
|
1121
|
+
await chrome.storage.session.remove(["codeVerifier", "state"]), T(new Error("No redirect URL received"));
|
|
1160
1122
|
return;
|
|
1161
1123
|
}
|
|
1162
1124
|
try {
|
|
1163
|
-
const
|
|
1164
|
-
if (
|
|
1165
|
-
await chrome.storage.session.remove(["codeVerifier", "state"]),
|
|
1125
|
+
const _ = new URL(y), f = _.searchParams.get("code"), R = _.searchParams.get("state"), { state: b } = await chrome.storage.session.get("state");
|
|
1126
|
+
if (R !== b) {
|
|
1127
|
+
await chrome.storage.session.remove(["codeVerifier", "state"]), T(new Error("State mismatch - possible CSRF"));
|
|
1166
1128
|
return;
|
|
1167
1129
|
}
|
|
1168
1130
|
if (!f) {
|
|
1169
|
-
await chrome.storage.session.remove(["codeVerifier", "state"]),
|
|
1131
|
+
await chrome.storage.session.remove(["codeVerifier", "state"]), T(new Error("No authorization code received"));
|
|
1170
1132
|
return;
|
|
1171
1133
|
}
|
|
1172
|
-
await this.exchangeCodeForTokens(f), await chrome.storage.session.remove(["codeVerifier", "state"]),
|
|
1173
|
-
} catch (
|
|
1174
|
-
await chrome.storage.session.remove(["codeVerifier", "state"]), _
|
|
1134
|
+
await this.exchangeCodeForTokens(f), await chrome.storage.session.remove(["codeVerifier", "state"]), g();
|
|
1135
|
+
} catch (_) {
|
|
1136
|
+
await chrome.storage.session.remove(["codeVerifier", "state"]), T(_);
|
|
1175
1137
|
}
|
|
1176
1138
|
}
|
|
1177
1139
|
);
|
|
@@ -1296,7 +1258,7 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Ie = ["bjdjhiombmfbcoeojijpfckl
|
|
|
1296
1258
|
r ? { body: r } : ""
|
|
1297
1259
|
);
|
|
1298
1260
|
const s = crypto.randomUUID(), o = {
|
|
1299
|
-
type:
|
|
1261
|
+
type: I.API_REQUEST,
|
|
1300
1262
|
requestId: s,
|
|
1301
1263
|
request: {
|
|
1302
1264
|
method: e,
|
|
@@ -1305,27 +1267,27 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Ie = ["bjdjhiombmfbcoeojijpfckl
|
|
|
1305
1267
|
headers: i
|
|
1306
1268
|
}
|
|
1307
1269
|
};
|
|
1308
|
-
return this.logger.debug(`[BodhiExtClient] Request ID: ${s}, Extension: ${this.extensionId}`), new Promise((n,
|
|
1270
|
+
return this.logger.debug(`[BodhiExtClient] Request ID: ${s}, Extension: ${this.extensionId}`), new Promise((n, h) => {
|
|
1309
1271
|
try {
|
|
1310
|
-
chrome.runtime.sendMessage(this.extensionId, o, (
|
|
1272
|
+
chrome.runtime.sendMessage(this.extensionId, o, (c) => {
|
|
1311
1273
|
if (chrome.runtime.lastError) {
|
|
1312
1274
|
this.logger.error(
|
|
1313
1275
|
`[BodhiExtClient] Chrome runtime error for request ${s}:`,
|
|
1314
1276
|
chrome.runtime.lastError
|
|
1315
|
-
),
|
|
1277
|
+
), h(new Error(chrome.runtime.lastError.message));
|
|
1316
1278
|
return;
|
|
1317
1279
|
}
|
|
1318
|
-
if (this.logger.debug(`[BodhiExtClient] Response for request ${s}:`,
|
|
1319
|
-
this.logger.error(`[BodhiExtClient] No response received for request ${s}`),
|
|
1280
|
+
if (this.logger.debug(`[BodhiExtClient] Response for request ${s}:`, c), !c) {
|
|
1281
|
+
this.logger.error(`[BodhiExtClient] No response received for request ${s}`), h(new Error("No response from extension"));
|
|
1320
1282
|
return;
|
|
1321
1283
|
}
|
|
1322
|
-
|
|
1284
|
+
c.type === I.API_RESPONSE && c.requestId === s ? "error" in c ? (this.logger.error(`[BodhiExtClient] API error for ${s}:`, c.error), h(new Error(c.error.message))) : (this.logger.debug(`[BodhiExtClient] ✓ Valid API_RESPONSE for ${s}`), n(c.response)) : (this.logger.error(
|
|
1323
1285
|
`[BodhiExtClient] Invalid response format for ${s}:`,
|
|
1324
|
-
|
|
1325
|
-
),
|
|
1286
|
+
c
|
|
1287
|
+
), h(new Error("Invalid response format")));
|
|
1326
1288
|
});
|
|
1327
|
-
} catch (
|
|
1328
|
-
this.logger.error(`[BodhiExtClient] Exception sending message for ${s}:`,
|
|
1289
|
+
} catch (c) {
|
|
1290
|
+
this.logger.error(`[BodhiExtClient] Exception sending message for ${s}:`, c), h(c);
|
|
1329
1291
|
}
|
|
1330
1292
|
});
|
|
1331
1293
|
}
|
|
@@ -1343,7 +1305,7 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Ie = ["bjdjhiombmfbcoeojijpfckl
|
|
|
1343
1305
|
t ? { params: t } : ""
|
|
1344
1306
|
);
|
|
1345
1307
|
const r = crypto.randomUUID(), i = {
|
|
1346
|
-
type:
|
|
1308
|
+
type: I.EXT_REQUEST,
|
|
1347
1309
|
requestId: r,
|
|
1348
1310
|
request: {
|
|
1349
1311
|
action: e,
|
|
@@ -1364,7 +1326,7 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Ie = ["bjdjhiombmfbcoeojijpfckl
|
|
|
1364
1326
|
this.logger.error(`[BodhiExtClient] No response received for request ${r}`), o(new Error("No response from extension"));
|
|
1365
1327
|
return;
|
|
1366
1328
|
}
|
|
1367
|
-
n.type ===
|
|
1329
|
+
n.type === I.EXT_RESPONSE && n.requestId === r ? (this.logger.debug(`[BodhiExtClient] ✓ Valid EXT_RESPONSE for ${r}`), s(n)) : (this.logger.error(
|
|
1368
1330
|
`[BodhiExtClient] Invalid response format for ${r}:`,
|
|
1369
1331
|
n
|
|
1370
1332
|
), o(new Error("Invalid response format")));
|
|
@@ -1381,14 +1343,14 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Ie = ["bjdjhiombmfbcoeojijpfckl
|
|
|
1381
1343
|
* @param message Stream request message from UI
|
|
1382
1344
|
*/
|
|
1383
1345
|
async handleStreamRequest(e, t) {
|
|
1384
|
-
const { requestId: r, request: i } = t, { method: s, endpoint: o, body: n, headers:
|
|
1346
|
+
const { requestId: r, request: i } = t, { method: s, endpoint: o, body: n, headers: h, authenticated: c } = i;
|
|
1385
1347
|
this.logger.debug("[BodhiExtClient] Processing stream request:", {
|
|
1386
1348
|
requestId: r,
|
|
1387
1349
|
method: s,
|
|
1388
1350
|
endpoint: o,
|
|
1389
|
-
authenticated:
|
|
1351
|
+
authenticated: c
|
|
1390
1352
|
}), this.extensionId || e.postMessage({
|
|
1391
|
-
type:
|
|
1353
|
+
type: a.EXT2EXT_CLIENT_STREAM_ERROR,
|
|
1392
1354
|
requestId: r,
|
|
1393
1355
|
error: {
|
|
1394
1356
|
message: this.createErrorClientNotInitialized(t),
|
|
@@ -1396,12 +1358,12 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Ie = ["bjdjhiombmfbcoeojijpfckl
|
|
|
1396
1358
|
}
|
|
1397
1359
|
});
|
|
1398
1360
|
try {
|
|
1399
|
-
let
|
|
1400
|
-
if (
|
|
1401
|
-
const
|
|
1402
|
-
if (!
|
|
1361
|
+
let u = { ...h };
|
|
1362
|
+
if (c !== !1) {
|
|
1363
|
+
const g = await this._getAccessTokenRaw();
|
|
1364
|
+
if (!g) {
|
|
1403
1365
|
e.postMessage({
|
|
1404
|
-
type:
|
|
1366
|
+
type: a.EXT2EXT_CLIENT_STREAM_ERROR,
|
|
1405
1367
|
requestId: r,
|
|
1406
1368
|
error: {
|
|
1407
1369
|
message: "Not authenticated. Please log in first.",
|
|
@@ -1410,60 +1372,60 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Ie = ["bjdjhiombmfbcoeojijpfckl
|
|
|
1410
1372
|
});
|
|
1411
1373
|
return;
|
|
1412
1374
|
}
|
|
1413
|
-
|
|
1414
|
-
...
|
|
1415
|
-
Authorization: `Bearer ${
|
|
1375
|
+
u = {
|
|
1376
|
+
...u,
|
|
1377
|
+
Authorization: `Bearer ${g}`
|
|
1416
1378
|
}, this.logger.debug("[BodhiExtClient] Injected auth token for authenticated request");
|
|
1417
1379
|
}
|
|
1418
|
-
const
|
|
1419
|
-
name:
|
|
1380
|
+
const E = chrome.runtime.connect(this.extensionId, {
|
|
1381
|
+
name: ie
|
|
1420
1382
|
});
|
|
1421
|
-
this.activeStreamPorts.set(r,
|
|
1422
|
-
const
|
|
1383
|
+
this.activeStreamPorts.set(r, E);
|
|
1384
|
+
const m = setTimeout(() => {
|
|
1423
1385
|
this.activeStreamPorts.has(r) && (this.logger.error(`[BodhiExtClient] Stream timeout for ${r}`), e.postMessage({
|
|
1424
|
-
type:
|
|
1386
|
+
type: a.EXT2EXT_CLIENT_STREAM_ERROR,
|
|
1425
1387
|
requestId: r,
|
|
1426
1388
|
error: {
|
|
1427
1389
|
message: "Stream request timed out",
|
|
1428
1390
|
type: "timeout_error"
|
|
1429
1391
|
}
|
|
1430
1392
|
}), this.cleanupStreamPort(r));
|
|
1431
|
-
},
|
|
1432
|
-
|
|
1433
|
-
if (
|
|
1434
|
-
const
|
|
1435
|
-
|
|
1436
|
-
type:
|
|
1393
|
+
}, S.STREAM_TIMEOUT);
|
|
1394
|
+
E.onMessage.addListener((g) => {
|
|
1395
|
+
if (ne(g)) {
|
|
1396
|
+
const T = g.response, y = T.body;
|
|
1397
|
+
T.status >= 400 ? e.postMessage({
|
|
1398
|
+
type: a.EXT2EXT_CLIENT_STREAM_API_ERROR,
|
|
1437
1399
|
requestId: r,
|
|
1438
|
-
response:
|
|
1439
|
-
}) :
|
|
1440
|
-
type:
|
|
1400
|
+
response: T
|
|
1401
|
+
}) : y?.done ? (e.postMessage({
|
|
1402
|
+
type: a.EXT2EXT_CLIENT_STREAM_DONE,
|
|
1441
1403
|
requestId: r
|
|
1442
|
-
}), this.logger.info(`[BodhiExtClient] Stream complete for ${r}`), clearTimeout(
|
|
1443
|
-
type:
|
|
1404
|
+
}), this.logger.info(`[BodhiExtClient] Stream complete for ${r}`), clearTimeout(m), this.cleanupStreamPort(r)) : e.postMessage({
|
|
1405
|
+
type: a.EXT2EXT_CLIENT_STREAM_CHUNK,
|
|
1444
1406
|
requestId: r,
|
|
1445
|
-
response:
|
|
1407
|
+
response: T
|
|
1446
1408
|
});
|
|
1447
|
-
} else
|
|
1448
|
-
`[BodhiExtClient] Stream API error for ${r}: ${
|
|
1409
|
+
} else ae(g) ? (this.logger.error(
|
|
1410
|
+
`[BodhiExtClient] Stream API error for ${r}: ${g.response.status}`
|
|
1449
1411
|
), e.postMessage({
|
|
1450
|
-
type:
|
|
1412
|
+
type: a.EXT2EXT_CLIENT_STREAM_API_ERROR,
|
|
1451
1413
|
requestId: r,
|
|
1452
|
-
response:
|
|
1453
|
-
})) :
|
|
1414
|
+
response: g.response
|
|
1415
|
+
})) : ce(g) && (this.logger.error(
|
|
1454
1416
|
`[BodhiExtClient] Stream error for ${r}:`,
|
|
1455
|
-
|
|
1417
|
+
g.error.message
|
|
1456
1418
|
), e.postMessage({
|
|
1457
|
-
type:
|
|
1419
|
+
type: a.EXT2EXT_CLIENT_STREAM_ERROR,
|
|
1458
1420
|
requestId: r,
|
|
1459
1421
|
error: {
|
|
1460
|
-
message: `stream error: ${JSON.stringify(
|
|
1422
|
+
message: `stream error: ${JSON.stringify(g)}`,
|
|
1461
1423
|
type: "extension_error"
|
|
1462
1424
|
}
|
|
1463
|
-
}), clearTimeout(
|
|
1464
|
-
}),
|
|
1465
|
-
clearTimeout(
|
|
1466
|
-
type:
|
|
1425
|
+
}), clearTimeout(m), this.cleanupStreamPort(r));
|
|
1426
|
+
}), E.onDisconnect.addListener(() => {
|
|
1427
|
+
clearTimeout(m), this.activeStreamPorts.has(r) && (this.logger.error(`[BodhiExtClient] Bodhi port disconnected for ${r}`), e.postMessage({
|
|
1428
|
+
type: a.EXT2EXT_CLIENT_STREAM_ERROR,
|
|
1467
1429
|
requestId: r,
|
|
1468
1430
|
error: {
|
|
1469
1431
|
message: "Connection to Bodhi extension closed unexpectedly",
|
|
@@ -1471,24 +1433,24 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Ie = ["bjdjhiombmfbcoeojijpfckl
|
|
|
1471
1433
|
}
|
|
1472
1434
|
}), this.activeStreamPorts.delete(r));
|
|
1473
1435
|
});
|
|
1474
|
-
const
|
|
1475
|
-
type:
|
|
1436
|
+
const l = {
|
|
1437
|
+
type: I.STREAM_REQUEST,
|
|
1476
1438
|
requestId: r,
|
|
1477
1439
|
request: {
|
|
1478
1440
|
method: s,
|
|
1479
1441
|
endpoint: o,
|
|
1480
1442
|
body: n,
|
|
1481
|
-
headers:
|
|
1443
|
+
headers: u
|
|
1482
1444
|
}
|
|
1483
1445
|
};
|
|
1484
|
-
this.logger.debug("[BodhiExtClient] Sending stream request to bodhi port:",
|
|
1485
|
-
} catch (
|
|
1486
|
-
const
|
|
1487
|
-
this.logger.error("[BodhiExtClient] Stream error:", JSON.stringify(
|
|
1488
|
-
type:
|
|
1446
|
+
this.logger.debug("[BodhiExtClient] Sending stream request to bodhi port:", l), E.postMessage(l);
|
|
1447
|
+
} catch (u) {
|
|
1448
|
+
const E = u;
|
|
1449
|
+
this.logger.error("[BodhiExtClient] Stream error:", JSON.stringify(E.message)), e.postMessage({
|
|
1450
|
+
type: a.EXT2EXT_CLIENT_STREAM_ERROR,
|
|
1489
1451
|
requestId: r,
|
|
1490
1452
|
error: {
|
|
1491
|
-
message: `uncaught error: ${JSON.stringify({ error:
|
|
1453
|
+
message: `uncaught error: ${JSON.stringify({ error: E, message: E.message })}`,
|
|
1492
1454
|
type: "extension_error"
|
|
1493
1455
|
}
|
|
1494
1456
|
});
|
|
@@ -1621,20 +1583,20 @@ const Se = ["ggedphdcbekjlomjaidbajglgihbeaon"], Ie = ["bjdjhiombmfbcoeojijpfckl
|
|
|
1621
1583
|
return `Client not initialized. Extension discovery not triggered nor extensionId set, cannot handle request: ${JSON.stringify(e)}`;
|
|
1622
1584
|
}
|
|
1623
1585
|
};
|
|
1624
|
-
|
|
1625
|
-
let
|
|
1586
|
+
S.STREAM_TIMEOUT = 6e4;
|
|
1587
|
+
let O = S;
|
|
1626
1588
|
const fe = "production";
|
|
1627
1589
|
export {
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1590
|
+
O as BodhiExtClient,
|
|
1591
|
+
le as DEFAULT_API_TIMEOUT_MS,
|
|
1592
|
+
Ee as DISCOVERY_ATTEMPTS,
|
|
1593
|
+
ue as DISCOVERY_ATTEMPT_TIMEOUT,
|
|
1594
|
+
de as DISCOVERY_ATTEMPT_WAIT_MS,
|
|
1595
|
+
he as DISCOVERY_TIMEOUT_MS,
|
|
1596
|
+
p as EXT2EXT_CLIENT_ACTIONS,
|
|
1597
|
+
a as EXT2EXT_CLIENT_MESSAGE_TYPES,
|
|
1636
1598
|
$ as EXT2EXT_CLIENT_STREAM_PORT,
|
|
1637
1599
|
fe as EXT_BUILD_MODE,
|
|
1638
|
-
|
|
1639
|
-
|
|
1600
|
+
Ie as ExtUIClient,
|
|
1601
|
+
ge as isExtClientApiError
|
|
1640
1602
|
};
|