@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DirectClientBase, AuthState, LoginOptions, LogLevel, StateChangeCallback } from '
|
|
1
|
+
import { DirectClientBase, AuthState, LoginOptions, LogLevel, StateChangeCallback } from '@bodhiapp/bodhi-js-core';
|
|
2
2
|
/**
|
|
3
3
|
* Configuration for DirectExtClient
|
|
4
4
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IExtensionClient, Chat, Models, Embeddings, ApiResponseResult, AuthState, BackendServerState, ClientState, ExtensionState, InitParams, LoginOptions, LogLevel, StateChangeCallback } from '
|
|
1
|
+
import { IExtensionClient, Chat, Models, Embeddings, ApiResponseResult, AuthState, BackendServerState, ClientState, ExtensionState, InitParams, LoginOptions, LogLevel, StateChangeCallback } from '@bodhiapp/bodhi-js-core';
|
|
2
2
|
export type SerializedExt2ExtState = {
|
|
3
3
|
extensionId?: string;
|
|
4
4
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ExtClientApiRequestMessage, ExtClientApiResponseMessage, ExtClientRequestMessage, ExtClientResponseMessage } from './messages';
|
|
2
|
-
import { AuthState, LoginOptions, LogLevel, UserScope } from '
|
|
2
|
+
import { AuthState, LoginOptions, LogLevel, UserScope } from '@bodhiapp/bodhi-js-core';
|
|
3
3
|
export type ClientExtState = 'setup' | 'ready' | 'error';
|
|
4
4
|
export interface BodhiExtClientConfig {
|
|
5
5
|
authServerUrl?: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseFacadeClient, Logger, LogLevel, StateChange, StateChangeCallback, UIClient, UserScope } from '
|
|
1
|
+
import { BaseFacadeClient, Logger, LogLevel, StateChange, StateChangeCallback, UIClient, UserScope } from '@bodhiapp/bodhi-js-core';
|
|
2
2
|
import { DirectExtClient } from './direct-client';
|
|
3
3
|
import { ExtClient } from './ext-client';
|
|
4
4
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { UserInfo } from '
|
|
2
|
-
import { ApiRequest, ApiResponse, ExtRequest, ExtResponse, OperationErrorResponse } from '
|
|
1
|
+
import { UserInfo } from '@bodhiapp/bodhi-js-core';
|
|
2
|
+
import { ApiRequest, ApiResponse, ExtRequest, ExtResponse, OperationErrorResponse } from '@bodhiapp/bodhi-browser-types';
|
|
3
3
|
import { OpenAiApiError } from '@bodhiapp/ts-client';
|
|
4
4
|
import { EXT2EXT_CLIENT_MESSAGE_TYPES } from './constants';
|
|
5
5
|
export type ExtClientApiRequest<T = unknown> = ApiRequest<T> & {
|
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.21",
|
|
4
4
|
"description": "Extension SDK for Bodhi Browser - chrome.runtime communication",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/bodhi-ext.cjs.js",
|
|
@@ -37,7 +37,8 @@
|
|
|
37
37
|
"typecheck": "tsc --noEmit"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@bodhiapp/bodhi-
|
|
40
|
+
"@bodhiapp/bodhi-browser-types": "0.0.21",
|
|
41
|
+
"@bodhiapp/bodhi-js-core": "0.0.21",
|
|
41
42
|
"@bodhiapp/ts-client": "0.1.14"
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
import { OpenAiApiError, PingResponse, CreateChatCompletionRequest, CreateChatCompletionResponse, CreateChatCompletionStreamResponse } from '@bodhiapp/ts-client';
|
|
2
|
-
/**
|
|
3
|
-
* HTTP response wrapper - body can be success type OR error type
|
|
4
|
-
* Use isApiErrorResponse() to narrow the type based on status
|
|
5
|
-
*/
|
|
6
|
-
export interface ApiResponse<T = unknown> {
|
|
7
|
-
body: T | OpenAiApiError;
|
|
8
|
-
status: number;
|
|
9
|
-
headers: Record<string, string>;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Stream chunk returned by sendStreamRequest
|
|
13
|
-
*
|
|
14
|
-
* This is the chunk structure yielded by the ReadableStream from sendStreamRequest.
|
|
15
|
-
* Different from StreamChunkMessage which is the internal message wrapper.
|
|
16
|
-
*/
|
|
17
|
-
export interface StreamChunk {
|
|
18
|
-
body: unknown;
|
|
19
|
-
headers?: Record<string, string>;
|
|
20
|
-
status?: number;
|
|
21
|
-
done?: boolean;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Server state information returned by /bodhi/v1/info endpoint
|
|
25
|
-
*/
|
|
26
|
-
export interface ServerStateInfo {
|
|
27
|
-
/** Current application status */
|
|
28
|
-
status: 'setup' | 'ready' | 'resource-admin' | 'error' | 'unreachable';
|
|
29
|
-
/** Application version */
|
|
30
|
-
version?: string;
|
|
31
|
-
/** Server URL (added by extension) */
|
|
32
|
-
url?: string;
|
|
33
|
-
/** Error details if status is 'error' or 'unreachable' */
|
|
34
|
-
error?: {
|
|
35
|
-
message: string;
|
|
36
|
-
type?: string;
|
|
37
|
-
code?: string;
|
|
38
|
-
param?: string;
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* API error thrown when server returns HTTP 4xx/5xx
|
|
43
|
-
* Used for streaming responses (non-streaming returns ApiResponse)
|
|
44
|
-
*/
|
|
45
|
-
export interface ApiError extends Error {
|
|
46
|
-
response: {
|
|
47
|
-
status: number;
|
|
48
|
-
body: OpenAiApiError;
|
|
49
|
-
headers?: Record<string, string>;
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Operation error thrown when HTTP request couldn't complete
|
|
54
|
-
* (network unreachable, timeout, extension error)
|
|
55
|
-
*/
|
|
56
|
-
export interface OperationError extends Error {
|
|
57
|
-
error: {
|
|
58
|
-
message: string;
|
|
59
|
-
type: string;
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Union of all extension-thrown errors
|
|
64
|
-
*/
|
|
65
|
-
export type ExtensionError = ApiError | OperationError;
|
|
66
|
-
/**
|
|
67
|
-
* Type guard: API error (has response field)
|
|
68
|
-
*/
|
|
69
|
-
export declare function isApiError(err: unknown): err is ApiError;
|
|
70
|
-
/**
|
|
71
|
-
* Type guard: Operation error (has error field, no response)
|
|
72
|
-
*/
|
|
73
|
-
export declare function isOperationError(err: unknown): err is OperationError;
|
|
74
|
-
/**
|
|
75
|
-
* Chat API uses types from @bodhiapp/ts-client.
|
|
76
|
-
* Consumers should import these types directly from @bodhiapp/ts-client:
|
|
77
|
-
* - ChatCompletionRequestMessage
|
|
78
|
-
* - ChatCompletionResponseMessage
|
|
79
|
-
* - CreateChatCompletionRequest
|
|
80
|
-
* - CreateChatCompletionResponse
|
|
81
|
-
* - CreateChatCompletionStreamResponse
|
|
82
|
-
* - ChatChoice
|
|
83
|
-
* - ChatChoiceStream
|
|
84
|
-
* - ChatCompletionStreamResponseDelta
|
|
85
|
-
*/
|
|
86
|
-
/**
|
|
87
|
-
* Chat completions API interface
|
|
88
|
-
*/
|
|
89
|
-
export interface ChatCompletionsApi {
|
|
90
|
-
/**
|
|
91
|
-
* Create a chat completion
|
|
92
|
-
*
|
|
93
|
-
* Non-streaming: Returns ApiResponse - caller checks status for success/error
|
|
94
|
-
* Streaming: Yields chunks via AsyncIterable - throws ApiError or OperationError on error
|
|
95
|
-
*
|
|
96
|
-
* @param params - Chat completion parameters
|
|
97
|
-
* @returns Non-streaming: Promise<ApiResponse<CreateChatCompletionResponse>>, Streaming: AsyncIterable<CreateChatCompletionStreamResponse>
|
|
98
|
-
*/
|
|
99
|
-
create(params: CreateChatCompletionRequest & {
|
|
100
|
-
stream?: false;
|
|
101
|
-
}): Promise<ApiResponse<CreateChatCompletionResponse>>;
|
|
102
|
-
create(params: CreateChatCompletionRequest & {
|
|
103
|
-
stream: true;
|
|
104
|
-
}): AsyncIterable<CreateChatCompletionStreamResponse>;
|
|
105
|
-
create(params: CreateChatCompletionRequest): Promise<ApiResponse<CreateChatCompletionResponse>> | AsyncIterable<CreateChatCompletionStreamResponse>;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Chat API namespace
|
|
109
|
-
*/
|
|
110
|
-
export interface ChatApi {
|
|
111
|
-
completions: ChatCompletionsApi;
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Public window.bodhiext interface
|
|
115
|
-
*
|
|
116
|
-
* This interface defines all methods available to web pages through window.bodhiext.
|
|
117
|
-
* The extension creates this interface in inject.ts and attaches it to the window object.
|
|
118
|
-
*/
|
|
119
|
-
export interface BodhiExtPublicApi {
|
|
120
|
-
/**
|
|
121
|
-
* Send a generic API request through the extension to the backend server.
|
|
122
|
-
*
|
|
123
|
-
* @template TReq - Request body type (inferred from body parameter)
|
|
124
|
-
* @template TRes - Response body type (must be specified explicitly)
|
|
125
|
-
* @param method - HTTP method (GET, POST, PUT, DELETE, etc.)
|
|
126
|
-
* @param endpoint - API endpoint path (e.g., '/v1/chat/completions')
|
|
127
|
-
* @param body - Optional request body (will be JSON stringified)
|
|
128
|
-
* @param headers - Optional additional headers
|
|
129
|
-
* @returns Promise resolving to ApiResponse with body, headers, and status
|
|
130
|
-
*/
|
|
131
|
-
sendApiRequest<TReq = unknown, TRes = unknown>(method: string, endpoint: string, body?: TReq, headers?: Record<string, string>): Promise<ApiResponse<TRes>>;
|
|
132
|
-
/**
|
|
133
|
-
* Send a streaming API request through the extension.
|
|
134
|
-
*
|
|
135
|
-
* Used for SSE (Server-Sent Events) endpoints like streaming chat completions.
|
|
136
|
-
* Returns a ReadableStream that yields StreamChunk objects.
|
|
137
|
-
*
|
|
138
|
-
* @template TReq - Request body type (inferred from body parameter)
|
|
139
|
-
* @param method - HTTP method (typically POST for streaming)
|
|
140
|
-
* @param endpoint - API endpoint path (e.g., '/v1/chat/completions')
|
|
141
|
-
* @param body - Optional request body
|
|
142
|
-
* @param headers - Optional additional headers
|
|
143
|
-
* @returns ReadableStream yielding StreamChunk objects
|
|
144
|
-
*/
|
|
145
|
-
sendStreamRequest<TReq = unknown>(method: string, endpoint: string, body?: TReq, headers?: Record<string, string>): ReadableStream<StreamChunk>;
|
|
146
|
-
/**
|
|
147
|
-
* Send a generic extension request.
|
|
148
|
-
*
|
|
149
|
-
* Used for extension-specific operations like test_connection, get_extension_id, etc.
|
|
150
|
-
* This is a low-level API for extension capabilities.
|
|
151
|
-
*
|
|
152
|
-
* @param action - Extension action name (e.g., 'test_connection')
|
|
153
|
-
* @param params - Optional action parameters
|
|
154
|
-
* @returns Promise resolving to action-specific response
|
|
155
|
-
*/
|
|
156
|
-
sendExtRequest(action: string, params?: any): Promise<any>;
|
|
157
|
-
/**
|
|
158
|
-
* Simple health check to verify extension connectivity.
|
|
159
|
-
*
|
|
160
|
-
* Returns ApiResponse - caller should check status to determine success/error.
|
|
161
|
-
* On success (2xx), body is PingResponse. On error (4xx/5xx), body is OpenAiApiError.
|
|
162
|
-
*
|
|
163
|
-
* @returns Promise resolving to ApiResponse<PingResponse>
|
|
164
|
-
*/
|
|
165
|
-
ping(): Promise<ApiResponse<PingResponse>>;
|
|
166
|
-
/**
|
|
167
|
-
* Get server state information from /bodhi/v1/info endpoint.
|
|
168
|
-
*
|
|
169
|
-
* Returns the current status of the backend server including
|
|
170
|
-
* whether it's in setup mode, ready, or has errors.
|
|
171
|
-
*
|
|
172
|
-
* @returns Promise resolving to ServerStateInfo
|
|
173
|
-
*/
|
|
174
|
-
serverState(): Promise<ServerStateInfo>;
|
|
175
|
-
/**
|
|
176
|
-
* OpenAI-compatible chat API.
|
|
177
|
-
*
|
|
178
|
-
* Provides chat completion functionality compatible with OpenAI's API structure.
|
|
179
|
-
*/
|
|
180
|
-
chat: ChatApi;
|
|
181
|
-
/**
|
|
182
|
-
* Get the extension ID.
|
|
183
|
-
*
|
|
184
|
-
* The extension ID is fetched asynchronously during initialization.
|
|
185
|
-
* This method returns a promise that resolves to the extension ID once available.
|
|
186
|
-
*
|
|
187
|
-
* @returns Promise resolving to the extension ID string
|
|
188
|
-
*/
|
|
189
|
-
getExtensionId(): Promise<string>;
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Window augmentation for TypeScript
|
|
193
|
-
*
|
|
194
|
-
* Declares the optional bodhiext property on the Window interface.
|
|
195
|
-
* This allows TypeScript code to access window.bodhiext with proper typing.
|
|
196
|
-
*/
|
|
197
|
-
declare global {
|
|
198
|
-
interface Window {
|
|
199
|
-
bodhiext?: BodhiExtPublicApi;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared constants for Bodhi Browser Extension
|
|
3
|
-
*
|
|
4
|
-
* Constants used by both inject.ts and background/content.ts scripts,
|
|
5
|
-
* or common to the entire extension.
|
|
6
|
-
*/
|
|
7
|
-
export declare const CONTENT_TYPE_JSON = "application/json";
|
|
8
|
-
export declare const CONTENT_TYPE_EVENT_STREAM = "text/event-stream";
|
|
9
|
-
export declare const CONTENT_TYPE_HEADER = "Content-Type";
|
|
10
|
-
export declare const HTTP_METHOD_GET = "GET";
|
|
11
|
-
export declare const HTTP_METHOD_POST = "POST";
|
|
12
|
-
export declare const ENDPOINT_PING = "/ping";
|
|
13
|
-
export declare const ENDPOINT_CHAT_COMPLETIONS = "/v1/chat/completions";
|
|
14
|
-
export declare const DEFAULT_API_BASE_URL = "http://localhost:1135";
|
|
15
|
-
export declare const DEFAULT_API_TIMEOUT = 10000;
|
|
16
|
-
export declare const DEFAULT_STREAM_TIMEOUT = 60000;
|
|
17
|
-
export declare const STORAGE_KEY_BACKEND_URL = "backendUrl";
|
|
18
|
-
export declare const SSE_DONE_MARKER = "[DONE]";
|
|
19
|
-
export declare const SSE_DATA_PREFIX = "data: ";
|
|
20
|
-
export declare const SSE_CHUNK_DELIMITER = "\n\n";
|
|
21
|
-
export declare const EXT_ACTIONS: {
|
|
22
|
-
readonly GET_EXTENSION_ID: "get_extension_id";
|
|
23
|
-
readonly TEST_CONNECTION: "test_connection";
|
|
24
|
-
};
|
|
25
|
-
export declare const ERROR_TYPES: {
|
|
26
|
-
readonly NETWORK_ERROR: "network_error";
|
|
27
|
-
readonly EXTENSION_ERROR: "extension_error";
|
|
28
|
-
readonly TIMEOUT_ERROR: "timeout_error";
|
|
29
|
-
readonly AUTH_ERROR: "auth_error";
|
|
30
|
-
};
|
|
31
|
-
export type ConnectionErrorType = (typeof ERROR_TYPES)[keyof typeof ERROR_TYPES];
|
|
32
|
-
export declare const DOCUMENT_STATE_COMPLETE = "complete";
|
|
33
|
-
export declare const EVENT_INITIALIZED = "bodhiext:initialized";
|
|
34
|
-
export declare const BODHI_STREAM_PORT = "BODHI_STREAM_PORT";
|
|
35
|
-
export declare const ORIGIN_WILDCARD = "*";
|
|
36
|
-
export declare const ERROR_MISSING_REQUEST_ID = "Invalid message format: missing requestId or request";
|
|
37
|
-
export declare const ERROR_CONNECTION_CLOSED = "Connection closed unexpectedly";
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export type { ApiResponse, StreamChunk, ServerStateInfo, ApiError, OperationError, ExtensionError, ChatCompletionsApi, ChatApi, BodhiExtPublicApi } from './bodhiext';
|
|
2
|
-
export { isApiError, isOperationError } from './bodhiext';
|
|
3
|
-
export type { ApiRequest, ApiRequestMessage, OperationErrorResponse, ApiResponseSuccessMessage, OperationErrorResponseMessage, ApiResponseMessage, ErrorMessage, StreamChunkMessage, StreamApiErrorMessage, StreamErrorMessage, StreamMessage, StreamController, SSEChunk, ExtRequest, ExtRequestMessage, ExtError, ExtErrorResponse, ExtResponse, ExtResponseMessage, GetExtensionIdRequest, GetExtensionIdResponse, TestConnectionRequest, TestConnectionResponse, } from './protocol';
|
|
4
|
-
export { MESSAGE_TYPES, isOperationErrorResponse, isApiErrorResponse, isApiSuccessResponse, isStreamChunk, isStreamApiError, isStreamError, isExtError, isOpenAiApiErrorBody, isOperationErrorStructure, } from './protocol';
|
|
5
|
-
export { CONTENT_TYPE_JSON, CONTENT_TYPE_EVENT_STREAM, CONTENT_TYPE_HEADER, HTTP_METHOD_GET, HTTP_METHOD_POST, ENDPOINT_PING, ENDPOINT_CHAT_COMPLETIONS, DEFAULT_API_BASE_URL, DEFAULT_API_TIMEOUT, DEFAULT_STREAM_TIMEOUT, STORAGE_KEY_BACKEND_URL, SSE_DONE_MARKER, SSE_DATA_PREFIX, SSE_CHUNK_DELIMITER, EXT_ACTIONS, ERROR_TYPES, DOCUMENT_STATE_COMPLETE, EVENT_INITIALIZED, BODHI_STREAM_PORT, ORIGIN_WILDCARD, ERROR_MISSING_REQUEST_ID, ERROR_CONNECTION_CLOSED, } from './common';
|
|
6
|
-
export type { ConnectionErrorType } from './common';
|
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
import { OpenAiApiError, ErrorBody } from '@bodhiapp/ts-client';
|
|
2
|
-
import { ApiResponse, ServerStateInfo } from './bodhiext';
|
|
3
|
-
/**
|
|
4
|
-
* Validate OpenAI API error body structure
|
|
5
|
-
* { error: { message: string, type: string } }
|
|
6
|
-
*/
|
|
7
|
-
export declare function isOpenAiApiErrorBody(body: unknown): body is OpenAiApiError;
|
|
8
|
-
/**
|
|
9
|
-
* Validate OperationErrorResponse structure
|
|
10
|
-
* { message: string, type: string }
|
|
11
|
-
*/
|
|
12
|
-
export declare function isOperationErrorStructure(obj: unknown): obj is OperationErrorResponse;
|
|
13
|
-
export declare const MESSAGE_TYPES: {
|
|
14
|
-
readonly API_REQUEST: "BODHI_API_REQUEST";
|
|
15
|
-
readonly API_RESPONSE: "BODHI_API_RESPONSE";
|
|
16
|
-
readonly STREAM_REQUEST: "BODHI_STREAM_REQUEST";
|
|
17
|
-
readonly STREAM_CHUNK: "BODHI_STREAM_CHUNK";
|
|
18
|
-
readonly STREAM_ERROR: "BODHI_STREAM_ERROR";
|
|
19
|
-
readonly STREAM_API_ERROR: "BODHI_STREAM_API_ERROR";
|
|
20
|
-
readonly ERROR: "BODHI_ERROR";
|
|
21
|
-
readonly EXT_REQUEST: "BODHI_EXT_REQUEST";
|
|
22
|
-
readonly EXT_RESPONSE: "BODHI_EXT_RESPONSE";
|
|
23
|
-
};
|
|
24
|
-
export interface ApiRequest<T = unknown> {
|
|
25
|
-
method: string;
|
|
26
|
-
endpoint: string;
|
|
27
|
-
body?: T;
|
|
28
|
-
headers?: Record<string, string>;
|
|
29
|
-
}
|
|
30
|
-
export interface ApiRequestMessage<TReq = unknown> {
|
|
31
|
-
type: string;
|
|
32
|
-
requestId: string;
|
|
33
|
-
request: ApiRequest<TReq>;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Operation-level error response (network unreachable, timeout, extension error)
|
|
37
|
-
* NOT an API error (those come through ApiResponse with OpenAiApiError body)
|
|
38
|
-
* This is a response type, not a thrown error
|
|
39
|
-
*/
|
|
40
|
-
export interface OperationErrorResponse {
|
|
41
|
-
message: string;
|
|
42
|
-
type: string;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Success API response message (HTTP request completed, regardless of status code)
|
|
46
|
-
*/
|
|
47
|
-
export interface ApiResponseSuccessMessage<T = unknown> {
|
|
48
|
-
type: string;
|
|
49
|
-
requestId: string;
|
|
50
|
-
response: ApiResponse<T>;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Operation error response message - HTTP request couldn't complete
|
|
54
|
-
*/
|
|
55
|
-
export interface OperationErrorResponseMessage {
|
|
56
|
-
type: string;
|
|
57
|
-
requestId: string;
|
|
58
|
-
error: OperationErrorResponse;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* API response message - discriminated union
|
|
62
|
-
*/
|
|
63
|
-
export type ApiResponseMessage<T = unknown> = ApiResponseSuccessMessage<T> | OperationErrorResponseMessage;
|
|
64
|
-
/**
|
|
65
|
-
* Type guard for operation error response
|
|
66
|
-
*/
|
|
67
|
-
export declare function isOperationErrorResponse(msg: ApiResponseMessage): msg is OperationErrorResponseMessage;
|
|
68
|
-
/**
|
|
69
|
-
* Type guard to check if response is an API error (4xx/5xx)
|
|
70
|
-
* Narrows body type to OpenAiApiError
|
|
71
|
-
*/
|
|
72
|
-
export declare function isApiErrorResponse<T>(response: ApiResponse<T>): response is ApiResponse<T> & {
|
|
73
|
-
body: OpenAiApiError;
|
|
74
|
-
status: number;
|
|
75
|
-
};
|
|
76
|
-
/**
|
|
77
|
-
* Type guard to check if response is successful (2xx)
|
|
78
|
-
* Narrows body type to T
|
|
79
|
-
*/
|
|
80
|
-
export declare function isApiSuccessResponse<T>(response: ApiResponse<T>): response is ApiResponse<T> & {
|
|
81
|
-
body: T;
|
|
82
|
-
status: number;
|
|
83
|
-
};
|
|
84
|
-
export interface ErrorMessage {
|
|
85
|
-
type: string;
|
|
86
|
-
requestId: string;
|
|
87
|
-
response: {
|
|
88
|
-
body: ErrorBody;
|
|
89
|
-
status: number;
|
|
90
|
-
headers: Record<string, string>;
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Stream chunk message - successful SSE chunk received
|
|
95
|
-
* Uses ApiResponse<T> wrapper for consistency with non-streaming pattern
|
|
96
|
-
*/
|
|
97
|
-
export interface StreamChunkMessage<T = unknown> {
|
|
98
|
-
type: typeof MESSAGE_TYPES.STREAM_CHUNK;
|
|
99
|
-
requestId: string;
|
|
100
|
-
response: ApiResponse<T>;
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Stream API error message - server returned error response (not SSE)
|
|
104
|
-
* E.g., 400/401/500 JSON error instead of SSE stream
|
|
105
|
-
*/
|
|
106
|
-
export interface StreamApiErrorMessage {
|
|
107
|
-
type: typeof MESSAGE_TYPES.STREAM_API_ERROR;
|
|
108
|
-
requestId: string;
|
|
109
|
-
response: ApiResponse<OpenAiApiError>;
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Stream error message - network/extension level error
|
|
113
|
-
* E.g., connection refused, timeout, extension error
|
|
114
|
-
*/
|
|
115
|
-
export interface StreamErrorMessage {
|
|
116
|
-
type: typeof MESSAGE_TYPES.STREAM_ERROR;
|
|
117
|
-
requestId: string;
|
|
118
|
-
error: OperationErrorResponse;
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Union type for all streaming messages
|
|
122
|
-
*/
|
|
123
|
-
export type StreamMessage<T = unknown> = StreamChunkMessage<T> | StreamApiErrorMessage | StreamErrorMessage;
|
|
124
|
-
/**
|
|
125
|
-
* Type guard for stream chunk message
|
|
126
|
-
*/
|
|
127
|
-
export declare function isStreamChunk<T>(msg: StreamMessage<T>): msg is StreamChunkMessage<T>;
|
|
128
|
-
/**
|
|
129
|
-
* Type guard for stream API error
|
|
130
|
-
*/
|
|
131
|
-
export declare function isStreamApiError(msg: StreamMessage): msg is StreamApiErrorMessage;
|
|
132
|
-
/**
|
|
133
|
-
* Type guard for stream error
|
|
134
|
-
*/
|
|
135
|
-
export declare function isStreamError(msg: StreamMessage): msg is StreamErrorMessage;
|
|
136
|
-
/**
|
|
137
|
-
* Interface for stream controller to handle SSE responses
|
|
138
|
-
*/
|
|
139
|
-
export interface StreamController {
|
|
140
|
-
enqueue: (chunk: any) => void;
|
|
141
|
-
error: (err: Error) => void;
|
|
142
|
-
complete: () => void;
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Interface for SSE data chunk
|
|
146
|
-
*/
|
|
147
|
-
export interface SSEChunk {
|
|
148
|
-
done?: boolean;
|
|
149
|
-
[key: string]: any;
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Generic extension request interface
|
|
153
|
-
*/
|
|
154
|
-
export interface ExtRequest {
|
|
155
|
-
action: string;
|
|
156
|
-
params?: any;
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Generic extension request message
|
|
160
|
-
*/
|
|
161
|
-
export interface ExtRequestMessage {
|
|
162
|
-
type: 'BODHI_EXT_REQUEST';
|
|
163
|
-
requestId: string;
|
|
164
|
-
request: ExtRequest;
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Extension-level error structure
|
|
168
|
-
*/
|
|
169
|
-
export interface ExtError {
|
|
170
|
-
message: string;
|
|
171
|
-
type?: string;
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Error response for extension operations
|
|
175
|
-
*/
|
|
176
|
-
export interface ExtErrorResponse {
|
|
177
|
-
error: ExtError;
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Union type for extension response (flattened - no wrapper for success)
|
|
181
|
-
* Success: T (the actual response data)
|
|
182
|
-
* Error: { error: ExtError }
|
|
183
|
-
*/
|
|
184
|
-
export type ExtResponse<T = unknown> = T | ExtErrorResponse;
|
|
185
|
-
/**
|
|
186
|
-
* Type guard to check if extension response is an error
|
|
187
|
-
*/
|
|
188
|
-
export declare function isExtError<T>(res: ExtResponse<T>): res is ExtErrorResponse;
|
|
189
|
-
/**
|
|
190
|
-
* Generic extension response message
|
|
191
|
-
*/
|
|
192
|
-
export interface ExtResponseMessage<T = unknown> {
|
|
193
|
-
type: 'BODHI_EXT_RESPONSE';
|
|
194
|
-
requestId: string;
|
|
195
|
-
response: ExtResponse<T>;
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* Get Extension ID request (no params needed)
|
|
199
|
-
*/
|
|
200
|
-
export interface GetExtensionIdRequest extends ExtRequest {
|
|
201
|
-
action: 'get_extension_id';
|
|
202
|
-
params?: undefined;
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* Get Extension ID response body
|
|
206
|
-
*/
|
|
207
|
-
export interface GetExtensionIdResponse {
|
|
208
|
-
extension_id: string;
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* Test Connection request
|
|
212
|
-
*/
|
|
213
|
-
export interface TestConnectionRequest extends ExtRequest {
|
|
214
|
-
action: 'test_connection';
|
|
215
|
-
params: {
|
|
216
|
-
url: string;
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Test Connection response body (reuses ServerStateInfo)
|
|
221
|
-
*/
|
|
222
|
-
export type TestConnectionResponse = ServerStateInfo;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export type ExtensionErrorCode = 'ext-not-installed' | 'ext-connection-failed' | 'ext-unsupported-version';
|
|
2
|
-
export declare const EXT_NOT_INSTALLED: ExtensionErrorCode;
|
|
3
|
-
export declare const EXT_CONNECTION_FAILED: ExtensionErrorCode;
|
|
4
|
-
export declare const EXT_UNSUPPORTED_VERSION: ExtensionErrorCode;
|
|
5
|
-
export interface ExtensionStateReady {
|
|
6
|
-
/** Current extension status */
|
|
7
|
-
status: 'ready';
|
|
8
|
-
/** Extension version */
|
|
9
|
-
version: string;
|
|
10
|
-
/** Extension ID (always present when ready) */
|
|
11
|
-
id: string;
|
|
12
|
-
}
|
|
13
|
-
export interface ExtensionStateNotReady {
|
|
14
|
-
/** Current extension status */
|
|
15
|
-
status: 'unreachable' | 'not-installed' | 'unsupported';
|
|
16
|
-
/** Error details */
|
|
17
|
-
error: {
|
|
18
|
-
/** Error message */
|
|
19
|
-
message: string;
|
|
20
|
-
/** Error code */
|
|
21
|
-
code: ExtensionErrorCode;
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
export type ExtensionState = ExtensionStateReady | ExtensionStateNotReady;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Consolidated types for setup-modal
|
|
3
|
-
*
|
|
4
|
-
* This folder contains all domain and protocol types organized by domain.
|
|
5
|
-
* It is designed to be independent and copyable to other packages.
|
|
6
|
-
*/
|
|
7
|
-
export type { BrowserType, OSType, EnvState, SupportedBrowser, NotSupportedBrowser, Browser, SupportedOS, NotSupportedOS, OS } from './platform';
|
|
8
|
-
export type { ExtensionErrorCode, ExtensionStateReady, ExtensionStateNotReady, ExtensionState } from './extension';
|
|
9
|
-
export { EXT_NOT_INSTALLED, EXT_CONNECTION_FAILED, EXT_UNSUPPORTED_VERSION } from './extension';
|
|
10
|
-
export type { ServerErrorCode, ServerStateReady, ServerStateReachable, ServerStatePending, ServerStateUnreachable, ServerStateError, ServerState } from './server';
|
|
11
|
-
export { SERVER_PENDING_EXT_READY, SERVER_CONN_REFUSED, SERVER_CONN_TIMEOUT, SERVER_NOT_FOUND, SERVER_NETWORK_UNREACHABLE, SERVER_SERVICE_UNAVAILABLE, SERVER_UNEXPECTED_ERROR, SERVER_IN_SETUP_STATUS, SERVER_IN_ADMIN_STATUS, } from './server';
|
|
12
|
-
export type { LnaErrorCode, LnaStatePrompt, LnaStateSkipped, LnaStateGranted, LnaStateUnreachable, LnaStateDenied, LnaStateUnsupported, LnaState, LnaServerStatePending, LnaServerStateReady, LnaServerStateSetup, LnaServerStateResourceAdmin, LnaServerStateError, LnaServerState, } from './lna';
|
|
13
|
-
export { LNA_UNREACHABLE, LNA_PERMISSION_DENIED } from './lna';
|
|
14
|
-
export { SetupStep, DEFAULT_USER_CONFIRMATIONS, DEFAULT_SETUP_STATE } from './state';
|
|
15
|
-
export type { SelectedConnection, UserConfirmations, SetupState } from './state';
|
|
16
|
-
export type { RequestId, MessageKind, RequestMessage, ResponseMessage, ErrorMessage, EventMessage, ProtocolMessage } from './protocol';
|
|
17
|
-
export { isRequestMessage, isResponseMessage, isErrorMessage, isEventMessage } from './protocol';
|
|
18
|
-
export type { MessageTypeRegistry, MessageType, RequestPayload, ResponsePayload, RequestHandlers } from './message-types';
|
|
19
|
-
export { MSG, isMessageType } from './message-types';
|
|
20
|
-
export { isExtensionStateReady, isExtensionStateNotReady, isServerStateReady, isServerStateReachable, isServerStatePending, isServerStateUnreachable, isServerStateError, isLnaStatePrompt, isLnaStateSkipped, isLnaStateGranted, isLnaStateUnreachable, isLnaStateDenied, isLnaStateUnsupported, isLnaServerStatePending, isLnaServerStateReady, isLnaServerStateSetup, isLnaServerStateResourceAdmin, isLnaServerStateError, isSupportedBrowser, isNotSupportedBrowser, isSupportedOS, isNotSupportedOS, } from './type-guards';
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
export type LnaErrorCode = 'lna-unreachable' | 'lna-permission-denied';
|
|
2
|
-
export declare const LNA_UNREACHABLE: LnaErrorCode;
|
|
3
|
-
export declare const LNA_PERMISSION_DENIED: LnaErrorCode;
|
|
4
|
-
export interface LnaStatePrompt {
|
|
5
|
-
status: 'prompt';
|
|
6
|
-
serverUrl?: string;
|
|
7
|
-
}
|
|
8
|
-
export interface LnaStateSkipped {
|
|
9
|
-
status: 'skipped';
|
|
10
|
-
serverUrl?: string;
|
|
11
|
-
}
|
|
12
|
-
export interface LnaStateGranted {
|
|
13
|
-
status: 'granted';
|
|
14
|
-
serverUrl: string;
|
|
15
|
-
}
|
|
16
|
-
export interface LnaStateUnreachable {
|
|
17
|
-
status: 'unreachable';
|
|
18
|
-
serverUrl: string;
|
|
19
|
-
error: {
|
|
20
|
-
message: string;
|
|
21
|
-
code: LnaErrorCode;
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
export interface LnaStateDenied {
|
|
25
|
-
status: 'denied';
|
|
26
|
-
error: {
|
|
27
|
-
message: string;
|
|
28
|
-
code: LnaErrorCode;
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
export interface LnaStateUnsupported {
|
|
32
|
-
status: 'unsupported';
|
|
33
|
-
}
|
|
34
|
-
export type LnaState = LnaStatePrompt | LnaStateSkipped | LnaStateGranted | LnaStateUnreachable | LnaStateDenied | LnaStateUnsupported;
|
|
35
|
-
export interface LnaServerStatePending {
|
|
36
|
-
status: 'pending-lna-ready';
|
|
37
|
-
}
|
|
38
|
-
export interface LnaServerStateReady {
|
|
39
|
-
status: 'ready';
|
|
40
|
-
version: string;
|
|
41
|
-
}
|
|
42
|
-
export interface LnaServerStateSetup {
|
|
43
|
-
status: 'setup';
|
|
44
|
-
version: string;
|
|
45
|
-
}
|
|
46
|
-
export interface LnaServerStateResourceAdmin {
|
|
47
|
-
status: 'resource-admin';
|
|
48
|
-
version: string;
|
|
49
|
-
}
|
|
50
|
-
export interface LnaServerStateError {
|
|
51
|
-
status: 'error';
|
|
52
|
-
error: {
|
|
53
|
-
message: string;
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
export type LnaServerState = LnaServerStatePending | LnaServerStateReady | LnaServerStateSetup | LnaServerStateResourceAdmin | LnaServerStateError;
|