@xsai/shared 0.0.12 → 0.0.14
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/index.d.ts +8 -2
- package/dist/index.js +14 -3
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
interface CommonRequestOptions {
|
|
2
2
|
abortSignal?: AbortSignal;
|
|
3
|
+
apiKey?: string;
|
|
3
4
|
/** @default `undefined` */
|
|
4
5
|
headers?: Headers | Record<string, string>;
|
|
6
|
+
/** @example `gpt-4o` */
|
|
7
|
+
model: string;
|
|
8
|
+
/** @example `https://openai.com/v1/chat/completions` */
|
|
5
9
|
url: string | URL;
|
|
6
10
|
}
|
|
7
11
|
|
|
@@ -12,6 +16,8 @@ declare const objCamelToSnake: (obj: Record<string, unknown>) => {
|
|
|
12
16
|
|
|
13
17
|
declare const clean: <T extends Record<string, undefined | unknown> = Record<string, unknown>>(record: T) => Record<keyof T, Exclude<T[keyof T], unknown>>;
|
|
14
18
|
|
|
15
|
-
declare const
|
|
19
|
+
declare const requestBody: (body: Record<string, unknown>) => string;
|
|
16
20
|
|
|
17
|
-
|
|
21
|
+
declare const requestHeaders: (headers?: CommonRequestOptions["headers"], apiKey?: CommonRequestOptions["apiKey"]) => Record<"Authorization", never>;
|
|
22
|
+
|
|
23
|
+
export { type CommonRequestOptions, clean, objCamelToSnake, requestBody, requestHeaders, strCamelToSnake };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
const strCamelToSnake = (str) => str.replace(/[A-Z]/g, (s) => `_${s.toLowerCase()}`);
|
|
2
2
|
const objCamelToSnake = (obj) => Object.fromEntries(Object.entries(obj).map(([k, v]) => [strCamelToSnake(k), v]));
|
|
3
3
|
|
|
4
|
-
const clean = (record) => Object.fromEntries(Object.entries(record).filter(([, v]) =>
|
|
4
|
+
const clean = (record) => Object.fromEntries(Object.entries(record).filter(([, v]) => v !== void 0));
|
|
5
5
|
|
|
6
|
-
const
|
|
6
|
+
const requestBody = (body) => JSON.stringify(clean({
|
|
7
|
+
...body,
|
|
8
|
+
abortSignal: void 0,
|
|
9
|
+
apiKey: void 0,
|
|
10
|
+
headers: void 0,
|
|
11
|
+
url: void 0
|
|
12
|
+
}));
|
|
7
13
|
|
|
8
|
-
|
|
14
|
+
const requestHeaders = (headers, apiKey) => clean({
|
|
15
|
+
Authorization: apiKey ? `Bearer ${apiKey}` : void 0,
|
|
16
|
+
...headers
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export { clean, objCamelToSnake, requestBody, requestHeaders, strCamelToSnake };
|