@bodhiapp/bodhi-browser-types 0.0.33 → 0.0.34
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 +4 -4
- package/dist/errors.d.ts +3 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -3
- package/dist/protocol.d.ts +7 -7
- package/package.json +2 -2
package/dist/bodhiext.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { AppStatus, PingResponse } from '@bodhiapp/ts-client';
|
|
2
|
-
import {
|
|
1
|
+
import { AppStatus, BodhiErrorResponse, PingResponse } from '@bodhiapp/ts-client';
|
|
2
|
+
import { CreateChatCompletionRequest, CreateChatCompletionResponse, CreateChatCompletionStreamResponse } from '@bodhiapp/ts-client/openai';
|
|
3
3
|
/**
|
|
4
4
|
* HTTP response wrapper - body can be success type OR error type
|
|
5
5
|
* Use isApiErrorResponse() to narrow the type based on status
|
|
6
6
|
*/
|
|
7
7
|
export interface ApiResponse<T = unknown> {
|
|
8
|
-
body: T |
|
|
8
|
+
body: T | BodhiErrorResponse;
|
|
9
9
|
status: number;
|
|
10
10
|
headers: Record<string, string>;
|
|
11
11
|
}
|
|
@@ -145,7 +145,7 @@ export interface BodhiExtPublicApi {
|
|
|
145
145
|
* Simple health check to verify extension connectivity.
|
|
146
146
|
*
|
|
147
147
|
* Returns ApiResponse - caller should check status to determine success/error.
|
|
148
|
-
* 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 BodhiErrorResponse.
|
|
149
149
|
*
|
|
150
150
|
* @returns Promise resolving to ApiResponse<PingResponse>
|
|
151
151
|
*/
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BodhiErrorResponse } from '@bodhiapp/ts-client';
|
|
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: BodhiErrorResponse;
|
|
27
27
|
readonly headers?: Record<string, string>;
|
|
28
|
-
constructor(status: number, body:
|
|
28
|
+
constructor(status: number, body: BodhiErrorResponse, 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
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
|
-
export { MESSAGE_TYPES, isOperationErrorResponse, isApiErrorResponse, isApiSuccessResponse, isStreamChunk, isStreamApiError, isStreamError, isExtError,
|
|
4
|
+
export { MESSAGE_TYPES, isOperationErrorResponse, isApiErrorResponse, isApiSuccessResponse, isStreamChunk, isStreamApiError, isStreamError, isExtError, isBodhiErrorResponseBody, isOperationErrorStructure, } from './protocol';
|
|
5
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
|
@@ -27,7 +27,7 @@ function unwrapResponse(response) {
|
|
|
27
27
|
function isNonNullObject(value) {
|
|
28
28
|
return value !== null && typeof value === "object";
|
|
29
29
|
}
|
|
30
|
-
function
|
|
30
|
+
function isBodhiErrorResponseBody(body) {
|
|
31
31
|
return isNonNullObject(body) && "error" in body && isNonNullObject(body.error) && "message" in body.error && typeof body.error.message === "string" && "type" in body.error && typeof body.error.type === "string";
|
|
32
32
|
}
|
|
33
33
|
function isOperationErrorStructure(obj) {
|
|
@@ -53,7 +53,7 @@ function isOperationErrorResponse(msg) {
|
|
|
53
53
|
return isNonNullObject(msg) && "error" in msg && isOperationErrorStructure(msg.error);
|
|
54
54
|
}
|
|
55
55
|
function isApiErrorResponse(response) {
|
|
56
|
-
return isNonNullObject(response) && typeof response.status === "number" && response.status >= 400 &&
|
|
56
|
+
return isNonNullObject(response) && typeof response.status === "number" && response.status >= 400 && isBodhiErrorResponseBody(response.body);
|
|
57
57
|
}
|
|
58
58
|
function isApiSuccessResponse(response) {
|
|
59
59
|
return response !== null && typeof response === "object" && typeof response.status === "number" && response.status >= 200 && response.status < 300 && "body" in response;
|
|
@@ -130,8 +130,8 @@ export {
|
|
|
130
130
|
STORAGE_KEY_BACKEND_URL,
|
|
131
131
|
isApiErrorResponse,
|
|
132
132
|
isApiSuccessResponse,
|
|
133
|
+
isBodhiErrorResponseBody,
|
|
133
134
|
isExtError,
|
|
134
|
-
isOpenAiApiErrorBody,
|
|
135
135
|
isOperationErrorResponse,
|
|
136
136
|
isOperationErrorStructure,
|
|
137
137
|
isStreamApiError,
|
package/dist/protocol.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BodhiErrorResponse } from '@bodhiapp/ts-client';
|
|
2
2
|
import { ApiResponse, ServerStateInfo } from './bodhiext';
|
|
3
3
|
/**
|
|
4
|
-
* Validate
|
|
4
|
+
* Validate Bodhi API error body structure
|
|
5
5
|
* { error: { message: string, type: string } }
|
|
6
6
|
*/
|
|
7
|
-
export declare function
|
|
7
|
+
export declare function isBodhiErrorResponseBody(body: unknown): body is BodhiErrorResponse;
|
|
8
8
|
/**
|
|
9
9
|
* Validate OperationErrorResponse structure
|
|
10
10
|
* { message: string, type: string }
|
|
@@ -39,7 +39,7 @@ export interface ApiRequestMessage<TReq = unknown> {
|
|
|
39
39
|
}
|
|
40
40
|
/**
|
|
41
41
|
* Operation-level error response (network unreachable, timeout, extension error)
|
|
42
|
-
* NOT an API error (those come through ApiResponse with
|
|
42
|
+
* NOT an API error (those come through ApiResponse with BodhiErrorResponse body)
|
|
43
43
|
* This is a response type, not a thrown error
|
|
44
44
|
*/
|
|
45
45
|
export interface OperationErrorResponse {
|
|
@@ -72,10 +72,10 @@ export type ApiResponseMessage<T = unknown> = ApiResponseSuccessMessage<T> | Ope
|
|
|
72
72
|
export declare function isOperationErrorResponse(msg: ApiResponseMessage): msg is OperationErrorResponseMessage;
|
|
73
73
|
/**
|
|
74
74
|
* Type guard to check if response is an API error (4xx/5xx)
|
|
75
|
-
* Narrows body type to
|
|
75
|
+
* Narrows body type to BodhiErrorResponse
|
|
76
76
|
*/
|
|
77
77
|
export declare function isApiErrorResponse<T>(response: ApiResponse<T>): response is ApiResponse<T> & {
|
|
78
|
-
body:
|
|
78
|
+
body: BodhiErrorResponse;
|
|
79
79
|
status: number;
|
|
80
80
|
};
|
|
81
81
|
/**
|
|
@@ -102,7 +102,7 @@ export interface StreamChunkMessage<T = unknown> {
|
|
|
102
102
|
export interface StreamApiErrorMessage {
|
|
103
103
|
type: typeof MESSAGE_TYPES.STREAM_API_ERROR;
|
|
104
104
|
requestId: string;
|
|
105
|
-
response: ApiResponse<
|
|
105
|
+
response: ApiResponse<BodhiErrorResponse>;
|
|
106
106
|
}
|
|
107
107
|
/**
|
|
108
108
|
* Stream error message - network/extension level error
|
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.34",
|
|
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": "0.1.
|
|
22
|
+
"@bodhiapp/ts-client": "0.1.31"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"rimraf": "^6.0.1",
|