@bodhiapp/bodhi-browser-types 0.0.31 → 0.0.33
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/bodhiext.d.ts +23 -3
- package/dist/common.d.ts +1 -0
- package/dist/errors.d.ts +3 -3
- package/dist/index.d.ts +2 -2
- package/dist/index.js +7 -0
- package/dist/protocol.d.ts +49 -15
- package/package.json +2 -2
package/dist/bodhiext.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { AppStatus,
|
|
1
|
+
import { AppStatus, PingResponse } from '@bodhiapp/ts-client';
|
|
2
|
+
import { ErrorResponse, CreateChatCompletionRequest, CreateChatCompletionResponse, CreateChatCompletionStreamResponse } from '@bodhiapp/ts-client/openai';
|
|
2
3
|
/**
|
|
3
4
|
* HTTP response wrapper - body can be success type OR error type
|
|
4
5
|
* Use isApiErrorResponse() to narrow the type based on status
|
|
5
6
|
*/
|
|
6
7
|
export interface ApiResponse<T = unknown> {
|
|
7
|
-
body: T |
|
|
8
|
+
body: T | ErrorResponse;
|
|
8
9
|
status: number;
|
|
9
10
|
headers: Record<string, string>;
|
|
10
11
|
}
|
|
@@ -110,6 +111,25 @@ export interface BodhiExtPublicApi {
|
|
|
110
111
|
* @returns ReadableStream yielding StreamChunk objects
|
|
111
112
|
*/
|
|
112
113
|
sendStreamRequest<TReq = unknown>(method: string, endpoint: string, body?: TReq, headers?: Record<string, string>): ReadableStream<StreamChunk>;
|
|
114
|
+
/**
|
|
115
|
+
* Send a raw text streaming request through the extension.
|
|
116
|
+
*
|
|
117
|
+
* Unlike sendStreamRequest which parses SSE/JSON, this forwards raw response
|
|
118
|
+
* bytes as text strings without any parsing. Returns response metadata (status,
|
|
119
|
+
* headers) plus a ReadableStream of raw text chunks.
|
|
120
|
+
*
|
|
121
|
+
* @template TReq - Request body type (inferred from body parameter)
|
|
122
|
+
* @param method - HTTP method
|
|
123
|
+
* @param endpoint - API endpoint path
|
|
124
|
+
* @param body - Optional request body
|
|
125
|
+
* @param headers - Optional additional headers
|
|
126
|
+
* @returns Promise with status, headers, and ReadableStream<string> body
|
|
127
|
+
*/
|
|
128
|
+
sendStreamText<TReq = unknown>(method: string, endpoint: string, body?: TReq, headers?: Record<string, string>): Promise<{
|
|
129
|
+
status: number;
|
|
130
|
+
headers: Record<string, string>;
|
|
131
|
+
body: ReadableStream<string>;
|
|
132
|
+
}>;
|
|
113
133
|
/**
|
|
114
134
|
* Send a generic extension request.
|
|
115
135
|
*
|
|
@@ -125,7 +145,7 @@ export interface BodhiExtPublicApi {
|
|
|
125
145
|
* Simple health check to verify extension connectivity.
|
|
126
146
|
*
|
|
127
147
|
* Returns ApiResponse - caller should check status to determine success/error.
|
|
128
|
-
* On success (2xx), body is PingResponse. On error (4xx/5xx), body is
|
|
148
|
+
* On success (2xx), body is PingResponse. On error (4xx/5xx), body is ErrorResponse.
|
|
129
149
|
*
|
|
130
150
|
* @returns Promise resolving to ApiResponse<PingResponse>
|
|
131
151
|
*/
|
package/dist/common.d.ts
CHANGED
|
@@ -32,6 +32,7 @@ export type ConnectionErrorType = (typeof ERROR_TYPES)[keyof typeof ERROR_TYPES]
|
|
|
32
32
|
export declare const DOCUMENT_STATE_COMPLETE = "complete";
|
|
33
33
|
export declare const EVENT_INITIALIZED = "bodhiext:initialized";
|
|
34
34
|
export declare const BODHI_STREAM_PORT = "BODHI_STREAM_PORT";
|
|
35
|
+
export declare const BODHI_STREAM_TEXT_PORT = "BODHI_STREAM_TEXT_PORT";
|
|
35
36
|
export declare const ORIGIN_WILDCARD = "*";
|
|
36
37
|
export declare const ERROR_MISSING_REQUEST_ID = "Invalid message format: missing requestId or request";
|
|
37
38
|
export declare const ERROR_CONNECTION_CLOSED = "Connection closed unexpectedly";
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ErrorResponse } from '@bodhiapp/ts-client/openai';
|
|
2
2
|
import { ApiResponse } from './bodhiext';
|
|
3
3
|
/**
|
|
4
4
|
* Error codes for BodhiError
|
|
@@ -23,9 +23,9 @@ export declare class BodhiError extends Error {
|
|
|
23
23
|
*/
|
|
24
24
|
export declare class BodhiApiError extends BodhiError {
|
|
25
25
|
readonly status: number;
|
|
26
|
-
readonly body:
|
|
26
|
+
readonly body: ErrorResponse;
|
|
27
27
|
readonly headers?: Record<string, string>;
|
|
28
|
-
constructor(status: number, body:
|
|
28
|
+
constructor(status: number, body: ErrorResponse, message: string, headers?: Record<string, string>);
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
31
|
* Extract response body or throw BodhiApiError if status >= 400
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type { ApiResponse, StreamChunk, ServerStateInfo, ChatCompletionsApi, ChatApi, BodhiExtPublicApi } from './bodhiext';
|
|
2
2
|
export { BodhiError, BodhiApiError, unwrapResponse, type BodhiErrorCode } from './errors';
|
|
3
|
-
export type { ApiRequest, ApiRequestMessage, OperationErrorResponse, ApiResponseSuccessMessage, OperationErrorResponseMessage, ApiResponseMessage,
|
|
3
|
+
export type { ApiRequest, ApiRequestMessage, OperationErrorResponse, ApiResponseSuccessMessage, OperationErrorResponseMessage, ApiResponseMessage, StreamChunkMessage, StreamApiErrorMessage, StreamErrorMessage, StreamMessage, StreamTextStartMessage, StreamTextChunkMessage, StreamTextDoneMessage, StreamTextErrorMessage, StreamTextMessage, StreamController, SSEChunk, ExtRequest, ExtRequestMessage, ExtError, ExtErrorResponse, ExtResponse, ExtResponseMessage, GetExtensionIdRequest, GetExtensionIdResponse, TestConnectionRequest, TestConnectionResponse, } from './protocol';
|
|
4
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';
|
|
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, BODHI_STREAM_TEXT_PORT, ORIGIN_WILDCARD, ERROR_MISSING_REQUEST_ID, ERROR_CONNECTION_CLOSED, } from './common';
|
|
6
6
|
export type { ConnectionErrorType } from './common';
|
package/dist/index.js
CHANGED
|
@@ -40,6 +40,11 @@ const MESSAGE_TYPES = {
|
|
|
40
40
|
STREAM_CHUNK: "BODHI_STREAM_CHUNK",
|
|
41
41
|
STREAM_ERROR: "BODHI_STREAM_ERROR",
|
|
42
42
|
STREAM_API_ERROR: "BODHI_STREAM_API_ERROR",
|
|
43
|
+
STREAM_TEXT_REQUEST: "BODHI_STREAM_TEXT_REQUEST",
|
|
44
|
+
STREAM_TEXT_START: "BODHI_STREAM_TEXT_START",
|
|
45
|
+
STREAM_TEXT_CHUNK: "BODHI_STREAM_TEXT_CHUNK",
|
|
46
|
+
STREAM_TEXT_DONE: "BODHI_STREAM_TEXT_DONE",
|
|
47
|
+
STREAM_TEXT_ERROR: "BODHI_STREAM_TEXT_ERROR",
|
|
43
48
|
ERROR: "BODHI_ERROR",
|
|
44
49
|
EXT_REQUEST: "BODHI_EXT_REQUEST",
|
|
45
50
|
EXT_RESPONSE: "BODHI_EXT_RESPONSE"
|
|
@@ -92,11 +97,13 @@ const ERROR_TYPES = {
|
|
|
92
97
|
const DOCUMENT_STATE_COMPLETE = "complete";
|
|
93
98
|
const EVENT_INITIALIZED = "bodhiext:initialized";
|
|
94
99
|
const BODHI_STREAM_PORT = "BODHI_STREAM_PORT";
|
|
100
|
+
const BODHI_STREAM_TEXT_PORT = "BODHI_STREAM_TEXT_PORT";
|
|
95
101
|
const ORIGIN_WILDCARD = "*";
|
|
96
102
|
const ERROR_MISSING_REQUEST_ID = "Invalid message format: missing requestId or request";
|
|
97
103
|
const ERROR_CONNECTION_CLOSED = "Connection closed unexpectedly";
|
|
98
104
|
export {
|
|
99
105
|
BODHI_STREAM_PORT,
|
|
106
|
+
BODHI_STREAM_TEXT_PORT,
|
|
100
107
|
BodhiApiError,
|
|
101
108
|
BodhiError,
|
|
102
109
|
CONTENT_TYPE_EVENT_STREAM,
|
package/dist/protocol.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ErrorResponse } from '@bodhiapp/ts-client/openai';
|
|
2
2
|
import { ApiResponse, ServerStateInfo } from './bodhiext';
|
|
3
3
|
/**
|
|
4
4
|
* Validate OpenAI API error body structure
|
|
5
5
|
* { error: { message: string, type: string } }
|
|
6
6
|
*/
|
|
7
|
-
export declare function isOpenAiApiErrorBody(body: unknown): body is
|
|
7
|
+
export declare function isOpenAiApiErrorBody(body: unknown): body is ErrorResponse;
|
|
8
8
|
/**
|
|
9
9
|
* Validate OperationErrorResponse structure
|
|
10
10
|
* { message: string, type: string }
|
|
@@ -17,6 +17,11 @@ export declare const MESSAGE_TYPES: {
|
|
|
17
17
|
readonly STREAM_CHUNK: "BODHI_STREAM_CHUNK";
|
|
18
18
|
readonly STREAM_ERROR: "BODHI_STREAM_ERROR";
|
|
19
19
|
readonly STREAM_API_ERROR: "BODHI_STREAM_API_ERROR";
|
|
20
|
+
readonly STREAM_TEXT_REQUEST: "BODHI_STREAM_TEXT_REQUEST";
|
|
21
|
+
readonly STREAM_TEXT_START: "BODHI_STREAM_TEXT_START";
|
|
22
|
+
readonly STREAM_TEXT_CHUNK: "BODHI_STREAM_TEXT_CHUNK";
|
|
23
|
+
readonly STREAM_TEXT_DONE: "BODHI_STREAM_TEXT_DONE";
|
|
24
|
+
readonly STREAM_TEXT_ERROR: "BODHI_STREAM_TEXT_ERROR";
|
|
20
25
|
readonly ERROR: "BODHI_ERROR";
|
|
21
26
|
readonly EXT_REQUEST: "BODHI_EXT_REQUEST";
|
|
22
27
|
readonly EXT_RESPONSE: "BODHI_EXT_RESPONSE";
|
|
@@ -34,7 +39,7 @@ export interface ApiRequestMessage<TReq = unknown> {
|
|
|
34
39
|
}
|
|
35
40
|
/**
|
|
36
41
|
* Operation-level error response (network unreachable, timeout, extension error)
|
|
37
|
-
* NOT an API error (those come through ApiResponse with
|
|
42
|
+
* NOT an API error (those come through ApiResponse with ErrorResponse body)
|
|
38
43
|
* This is a response type, not a thrown error
|
|
39
44
|
*/
|
|
40
45
|
export interface OperationErrorResponse {
|
|
@@ -67,10 +72,10 @@ export type ApiResponseMessage<T = unknown> = ApiResponseSuccessMessage<T> | Ope
|
|
|
67
72
|
export declare function isOperationErrorResponse(msg: ApiResponseMessage): msg is OperationErrorResponseMessage;
|
|
68
73
|
/**
|
|
69
74
|
* Type guard to check if response is an API error (4xx/5xx)
|
|
70
|
-
* Narrows body type to
|
|
75
|
+
* Narrows body type to ErrorResponse
|
|
71
76
|
*/
|
|
72
77
|
export declare function isApiErrorResponse<T>(response: ApiResponse<T>): response is ApiResponse<T> & {
|
|
73
|
-
body:
|
|
78
|
+
body: ErrorResponse;
|
|
74
79
|
status: number;
|
|
75
80
|
};
|
|
76
81
|
/**
|
|
@@ -81,15 +86,6 @@ export declare function isApiSuccessResponse<T>(response: ApiResponse<T>): respo
|
|
|
81
86
|
body: T;
|
|
82
87
|
status: number;
|
|
83
88
|
};
|
|
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
89
|
/**
|
|
94
90
|
* Stream chunk message - successful SSE chunk received
|
|
95
91
|
* Uses ApiResponse<T> wrapper for consistency with non-streaming pattern
|
|
@@ -106,7 +102,7 @@ export interface StreamChunkMessage<T = unknown> {
|
|
|
106
102
|
export interface StreamApiErrorMessage {
|
|
107
103
|
type: typeof MESSAGE_TYPES.STREAM_API_ERROR;
|
|
108
104
|
requestId: string;
|
|
109
|
-
response: ApiResponse<
|
|
105
|
+
response: ApiResponse<ErrorResponse>;
|
|
110
106
|
}
|
|
111
107
|
/**
|
|
112
108
|
* Stream error message - network/extension level error
|
|
@@ -133,6 +129,44 @@ export declare function isStreamApiError(msg: StreamMessage): msg is StreamApiEr
|
|
|
133
129
|
* Type guard for stream error
|
|
134
130
|
*/
|
|
135
131
|
export declare function isStreamError(msg: StreamMessage): msg is StreamErrorMessage;
|
|
132
|
+
/**
|
|
133
|
+
* Stream text start message — response metadata (status + headers)
|
|
134
|
+
* Sent once before any STREAM_TEXT_CHUNK messages
|
|
135
|
+
*/
|
|
136
|
+
export interface StreamTextStartMessage {
|
|
137
|
+
type: typeof MESSAGE_TYPES.STREAM_TEXT_START;
|
|
138
|
+
requestId: string;
|
|
139
|
+
status: number;
|
|
140
|
+
headers: Record<string, string>;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Stream text chunk message — raw text from response body
|
|
144
|
+
* No SSE parsing, no JSON.parse, no data: prefix stripping
|
|
145
|
+
*/
|
|
146
|
+
export interface StreamTextChunkMessage {
|
|
147
|
+
type: typeof MESSAGE_TYPES.STREAM_TEXT_CHUNK;
|
|
148
|
+
requestId: string;
|
|
149
|
+
chunk: string;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Stream text done message — stream completed
|
|
153
|
+
*/
|
|
154
|
+
export interface StreamTextDoneMessage {
|
|
155
|
+
type: typeof MESSAGE_TYPES.STREAM_TEXT_DONE;
|
|
156
|
+
requestId: string;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Stream text error message — network/extension level error
|
|
160
|
+
*/
|
|
161
|
+
export interface StreamTextErrorMessage {
|
|
162
|
+
type: typeof MESSAGE_TYPES.STREAM_TEXT_ERROR;
|
|
163
|
+
requestId: string;
|
|
164
|
+
error: OperationErrorResponse;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Union type for all stream text messages
|
|
168
|
+
*/
|
|
169
|
+
export type StreamTextMessage = StreamTextStartMessage | StreamTextChunkMessage | StreamTextDoneMessage | StreamTextErrorMessage;
|
|
136
170
|
/**
|
|
137
171
|
* Interface for stream controller to handle SSE responses
|
|
138
172
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bodhiapp/bodhi-browser-types",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.33",
|
|
4
4
|
"description": "TypeScript types for Bodhi Browser Extension",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"clean": "rimraf dist"
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
|
-
"@bodhiapp/ts-client": "
|
|
22
|
+
"@bodhiapp/ts-client": "0.1.29"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"rimraf": "^6.0.1",
|