@bodhiapp/bodhi-js-ext 0.0.30 → 0.0.32
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 +528 -434
- package/dist/chrome-storage.d.ts +6 -0
- package/dist/constants.d.ts +6 -0
- package/dist/direct-client.d.ts +3 -6
- package/dist/ext-client.d.ts +6 -1
- package/dist/ext2ext-client.d.ts +20 -5
- package/dist/facade-client.d.ts +5 -1
- package/dist/index.d.ts +3 -0
- package/dist/messages.d.ts +47 -0
- package/package.json +4 -4
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { IStorage } from '@bodhiapp/bodhi-js-core';
|
|
2
|
+
export declare class ChromeSessionStorageAdapter implements IStorage {
|
|
3
|
+
get(key: string): Promise<string | null>;
|
|
4
|
+
set(items: Record<string, string | number>): Promise<void>;
|
|
5
|
+
remove(keys: string[]): Promise<void>;
|
|
6
|
+
}
|
package/dist/constants.d.ts
CHANGED
|
@@ -9,8 +9,14 @@ export declare const EXT2EXT_CLIENT_MESSAGE_TYPES: {
|
|
|
9
9
|
readonly EXT2EXT_CLIENT_STREAM_ERROR: "EXT2EXT_CLIENT_STREAM_ERROR";
|
|
10
10
|
readonly EXT2EXT_CLIENT_STREAM_API_ERROR: "EXT2EXT_CLIENT_STREAM_API_ERROR";
|
|
11
11
|
readonly EXT2EXT_CLIENT_STREAM_DONE: "EXT2EXT_CLIENT_STREAM_DONE";
|
|
12
|
+
readonly EXT2EXT_CLIENT_STREAM_TEXT_REQUEST: "EXT2EXT_CLIENT_STREAM_TEXT_REQUEST";
|
|
13
|
+
readonly EXT2EXT_CLIENT_STREAM_TEXT_START: "EXT2EXT_CLIENT_STREAM_TEXT_START";
|
|
14
|
+
readonly EXT2EXT_CLIENT_STREAM_TEXT_CHUNK: "EXT2EXT_CLIENT_STREAM_TEXT_CHUNK";
|
|
15
|
+
readonly EXT2EXT_CLIENT_STREAM_TEXT_DONE: "EXT2EXT_CLIENT_STREAM_TEXT_DONE";
|
|
16
|
+
readonly EXT2EXT_CLIENT_STREAM_TEXT_ERROR: "EXT2EXT_CLIENT_STREAM_TEXT_ERROR";
|
|
12
17
|
};
|
|
13
18
|
export declare const EXT2EXT_CLIENT_STREAM_PORT = "ext2ext-client-stream";
|
|
19
|
+
export declare const EXT2EXT_CLIENT_STREAM_TEXT_PORT = "ext2ext-client-stream-text";
|
|
14
20
|
export declare const EXT2EXT_CLIENT_ACTIONS: {
|
|
15
21
|
readonly LOGIN: "login";
|
|
16
22
|
readonly LOGOUT: "logout";
|
package/dist/direct-client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DirectClientBase, AuthState, LoginOptions, LogLevel, StateChangeCallback } from '@bodhiapp/bodhi-js-core';
|
|
1
|
+
import { DirectClientBase, AuthState, IStorage, InitialTokens, LoginOptions, LogLevel, StateChangeCallback } from '@bodhiapp/bodhi-js-core';
|
|
2
2
|
/**
|
|
3
3
|
* Configuration for DirectExtClient
|
|
4
4
|
*/
|
|
@@ -8,6 +8,8 @@ export interface DirectExtClientConfig {
|
|
|
8
8
|
basePath: string;
|
|
9
9
|
logLevel: LogLevel;
|
|
10
10
|
apiTimeoutMs?: number;
|
|
11
|
+
storage?: IStorage;
|
|
12
|
+
initialTokens?: InitialTokens;
|
|
11
13
|
}
|
|
12
14
|
/**
|
|
13
15
|
* DirectExtClient - Extension mode implementation using chrome.identity OAuth
|
|
@@ -16,10 +18,5 @@ export declare class DirectExtClient extends DirectClientBase {
|
|
|
16
18
|
constructor(config: DirectExtClientConfig, onStateChange?: StateChangeCallback);
|
|
17
19
|
login(options?: LoginOptions): Promise<AuthState>;
|
|
18
20
|
protected performOAuthPkce(scope: string): Promise<AuthState>;
|
|
19
|
-
logout(): Promise<AuthState>;
|
|
20
|
-
protected exchangeCodeForTokens(code: string): Promise<void>;
|
|
21
|
-
protected _storageGet(key: string): Promise<string | null>;
|
|
22
|
-
protected _storageSet(items: Record<string, string | number>): Promise<void>;
|
|
23
|
-
protected _storageRemove(keys: string[]): Promise<void>;
|
|
24
21
|
protected _getRedirectUri(): string;
|
|
25
22
|
}
|
package/dist/ext-client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AccessRequestStatusResponse, CreateAccessRequest, CreateAccessRequestResponse, PingResponse } from '@bodhiapp/ts-client';
|
|
2
|
-
import { IExtensionClient, Chat, Models, Embeddings, Mcps, AuthState, BackendServerState, ClientState, ExtensionState, InitParams, LoginOptions, LogLevel, StateChangeCallback } from '@bodhiapp/bodhi-js-core';
|
|
2
|
+
import { IExtensionClient, Chat, Models, Embeddings, Mcps, AuthState, BackendServerState, ClientState, ExtensionState, InitParams, LoginOptions, LogLevel, StateChangeCallback, StreamTextResult } from '@bodhiapp/bodhi-js-core';
|
|
3
3
|
import { ApiResponse } from '@bodhiapp/bodhi-browser-types';
|
|
4
4
|
export type SerializedExt2ExtState = {
|
|
5
5
|
extensionId?: string;
|
|
@@ -135,6 +135,11 @@ export declare class ExtClient implements IExtensionClient {
|
|
|
135
135
|
* Generic streaming method
|
|
136
136
|
*/
|
|
137
137
|
stream<TReq = unknown, TRes = unknown>(method: string, endpoint: string, body?: TReq, headers?: Record<string, string>, authenticated?: boolean): AsyncGenerator<TRes>;
|
|
138
|
+
/**
|
|
139
|
+
* Raw text streaming method - no SSE/JSON parsing
|
|
140
|
+
* Returns status, headers, and async generator of raw text chunks
|
|
141
|
+
*/
|
|
142
|
+
streamText(method: string, endpoint: string, body?: unknown, headers?: Record<string, string>, authenticated?: boolean): Promise<StreamTextResult>;
|
|
138
143
|
get chat(): Chat;
|
|
139
144
|
get models(): Models;
|
|
140
145
|
get embeddings(): Embeddings;
|
package/dist/ext2ext-client.d.ts
CHANGED
|
@@ -159,16 +159,31 @@ export declare class BodhiExtClient {
|
|
|
159
159
|
*/
|
|
160
160
|
private static readonly STREAM_TIMEOUT;
|
|
161
161
|
/**
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
* @param uiPort Port connected from UI
|
|
165
|
-
* @param message Stream request message from UI
|
|
162
|
+
* Register a chrome.runtime.onConnect listener for a streaming port.
|
|
163
|
+
* Validates port name and message type, then delegates to handler.
|
|
166
164
|
*/
|
|
167
|
-
private
|
|
165
|
+
private registerStreamPortListener;
|
|
166
|
+
/**
|
|
167
|
+
* Generic stream relay: validates auth, connects to bodhi-browser-ext,
|
|
168
|
+
* sets up timeout/disconnect handling, and delegates message forwarding
|
|
169
|
+
* to the onBodhiMessage callback.
|
|
170
|
+
*
|
|
171
|
+
* @param onBodhiMessage Called for each message from bodhi-browser-ext.
|
|
172
|
+
* Returns true if the stream is complete (triggers cleanup).
|
|
173
|
+
*/
|
|
174
|
+
private handleGenericStreamRelay;
|
|
168
175
|
/**
|
|
169
176
|
* Clean up a streaming port connection
|
|
170
177
|
*/
|
|
171
178
|
private cleanupStreamPort;
|
|
179
|
+
/**
|
|
180
|
+
* Handle SSE-parsed streaming request — translates STREAM_* messages to EXT2EXT_CLIENT_STREAM_*
|
|
181
|
+
*/
|
|
182
|
+
private handleStreamRequest;
|
|
183
|
+
/**
|
|
184
|
+
* Handle raw text streaming request — translates STREAM_TEXT_* messages to EXT2EXT_CLIENT_STREAM_TEXT_*
|
|
185
|
+
*/
|
|
186
|
+
private handleStreamTextRequest;
|
|
172
187
|
private storeTokens;
|
|
173
188
|
protected _getAccessTokenRaw(): Promise<string | null>;
|
|
174
189
|
/**
|
package/dist/facade-client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseFacadeClient, Logger, LogLevel, StateChange, StateChangeCallback, UIClient } from '@bodhiapp/bodhi-js-core';
|
|
1
|
+
import { BaseFacadeClient, Logger, InitialTokens, IStorage, LogLevel, StateChange, StateChangeCallback, UIClient } from '@bodhiapp/bodhi-js-core';
|
|
2
2
|
import { DirectExtClient } from './direct-client';
|
|
3
3
|
import { ExtClient } from './ext-client';
|
|
4
4
|
/**
|
|
@@ -10,6 +10,8 @@ export interface ExtUIClientConfig {
|
|
|
10
10
|
basePath: string;
|
|
11
11
|
logLevel: LogLevel;
|
|
12
12
|
apiTimeoutMs?: number;
|
|
13
|
+
storage?: IStorage;
|
|
14
|
+
initialTokens?: InitialTokens;
|
|
13
15
|
initParams?: {
|
|
14
16
|
extension?: {
|
|
15
17
|
timeoutMs?: number;
|
|
@@ -28,6 +30,8 @@ export interface ExtUIClientParams {
|
|
|
28
30
|
basePath?: string;
|
|
29
31
|
logLevel?: LogLevel;
|
|
30
32
|
apiTimeoutMs?: number;
|
|
33
|
+
storage?: IStorage;
|
|
34
|
+
initialTokens?: InitialTokens;
|
|
31
35
|
initParams?: {
|
|
32
36
|
extension?: {
|
|
33
37
|
timeoutMs?: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -3,4 +3,7 @@ export { type SerializedExt2ExtState } from './ext-client';
|
|
|
3
3
|
export * from './messages';
|
|
4
4
|
export { ExtUIClient, type ExtUIClientParams } from './facade-client';
|
|
5
5
|
export { BodhiExtClient } from './ext2ext-client';
|
|
6
|
+
export { ChromeSessionStorageAdapter } from './chrome-storage';
|
|
7
|
+
export { InMemoryStorage } from '@bodhiapp/bodhi-js-core';
|
|
8
|
+
export type { IStorage, InitialTokens } from '@bodhiapp/bodhi-js-core';
|
|
6
9
|
export { BUILD_MODE as EXT_BUILD_MODE } from './build-info';
|
package/dist/messages.d.ts
CHANGED
|
@@ -136,3 +136,50 @@ export interface ExtClientStreamDoneMessage {
|
|
|
136
136
|
* Union type for all ext2ext streaming messages
|
|
137
137
|
*/
|
|
138
138
|
export type ExtClientStreamMessage<TRes = unknown> = ExtClientStreamChunkMessage<TRes> | ExtClientStreamApiErrorMessage | ExtClientStreamErrorMessage | ExtClientStreamDoneMessage;
|
|
139
|
+
/**
|
|
140
|
+
* Stream text request message
|
|
141
|
+
*/
|
|
142
|
+
export interface ExtClientStreamTextRequestMessage<TReq = unknown> {
|
|
143
|
+
type: typeof EXT2EXT_CLIENT_MESSAGE_TYPES.EXT2EXT_CLIENT_STREAM_TEXT_REQUEST;
|
|
144
|
+
requestId: string;
|
|
145
|
+
request: ExtClientStreamRequest<TReq> & {
|
|
146
|
+
authenticated?: boolean;
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Stream text start message - response metadata (status + headers)
|
|
151
|
+
* Sent once before any stream text chunk messages
|
|
152
|
+
*/
|
|
153
|
+
export interface ExtClientStreamTextStartMessage {
|
|
154
|
+
type: typeof EXT2EXT_CLIENT_MESSAGE_TYPES.EXT2EXT_CLIENT_STREAM_TEXT_START;
|
|
155
|
+
requestId: string;
|
|
156
|
+
status: number;
|
|
157
|
+
headers: Record<string, string>;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Stream text chunk message - raw text from response body
|
|
161
|
+
*/
|
|
162
|
+
export interface ExtClientStreamTextChunkMessage {
|
|
163
|
+
type: typeof EXT2EXT_CLIENT_MESSAGE_TYPES.EXT2EXT_CLIENT_STREAM_TEXT_CHUNK;
|
|
164
|
+
requestId: string;
|
|
165
|
+
chunk: string;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Stream text done message - stream completed
|
|
169
|
+
*/
|
|
170
|
+
export interface ExtClientStreamTextDoneMessage {
|
|
171
|
+
type: typeof EXT2EXT_CLIENT_MESSAGE_TYPES.EXT2EXT_CLIENT_STREAM_TEXT_DONE;
|
|
172
|
+
requestId: string;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Stream text error message - network/extension level error
|
|
176
|
+
*/
|
|
177
|
+
export interface ExtClientStreamTextErrorMessage {
|
|
178
|
+
type: typeof EXT2EXT_CLIENT_MESSAGE_TYPES.EXT2EXT_CLIENT_STREAM_TEXT_ERROR;
|
|
179
|
+
requestId: string;
|
|
180
|
+
error: OperationErrorResponse;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Union type for all ext2ext stream text messages (received by UI)
|
|
184
|
+
*/
|
|
185
|
+
export type ExtClientStreamTextMessage = ExtClientStreamTextStartMessage | ExtClientStreamTextChunkMessage | ExtClientStreamTextDoneMessage | ExtClientStreamTextErrorMessage;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bodhiapp/bodhi-js-ext",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.32",
|
|
4
4
|
"description": "Extension SDK for Bodhi Browser - chrome.runtime communication",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/bodhi-ext.cjs.js",
|
|
@@ -37,9 +37,9 @@
|
|
|
37
37
|
"typecheck": "tsc --noEmit"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@bodhiapp/bodhi-browser-types": "0.0.
|
|
41
|
-
"@bodhiapp/bodhi-js-core": "0.0.
|
|
42
|
-
"@bodhiapp/ts-client": "0.1.
|
|
40
|
+
"@bodhiapp/bodhi-browser-types": "0.0.32",
|
|
41
|
+
"@bodhiapp/bodhi-js-core": "0.0.32",
|
|
42
|
+
"@bodhiapp/ts-client": "0.1.26"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@eslint/js": "^9.23.0",
|