@xsai/shared 0.0.11 → 0.0.13

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 CHANGED
@@ -1,10 +1,12 @@
1
- interface CommonRequestOptions<T extends string> {
1
+ interface CommonRequestOptions {
2
2
  abortSignal?: AbortSignal;
3
- /** @default `http://localhost:11434/v1` */
4
- base?: string;
3
+ apiKey?: string;
5
4
  /** @default `undefined` */
6
5
  headers?: Headers | Record<string, string>;
7
- path?: ({} & string) | T;
6
+ /** @example `gpt-4o` */
7
+ model: string;
8
+ /** @example `https://openai.com/v1/chat/completions` */
9
+ url: string | URL;
8
10
  }
9
11
 
10
12
  declare const strCamelToSnake: (str: string) => string;
@@ -14,6 +16,8 @@ declare const objCamelToSnake: (obj: Record<string, unknown>) => {
14
16
 
15
17
  declare const clean: <T extends Record<string, undefined | unknown> = Record<string, unknown>>(record: T) => Record<keyof T, Exclude<T[keyof T], unknown>>;
16
18
 
17
- declare const requestUrl: (path: string, base?: string | URL) => URL;
19
+ declare const requestBody: (body: Record<string, unknown>) => string;
18
20
 
19
- export { type CommonRequestOptions, clean, objCamelToSnake, requestUrl, strCamelToSnake };
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]) => !!v));
4
+ const clean = (record) => Object.fromEntries(Object.entries(record).filter(([, v]) => v !== void 0));
5
5
 
6
- const requestUrl = (path, base = "http://localhost:11434/v1/") => new URL(path, base);
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
- export { clean, objCamelToSnake, requestUrl, strCamelToSnake };
14
+ const requestHeaders = (headers, apiKey) => clean({
15
+ Authorization: apiKey ? `Bearer ${apiKey}` : void 0,
16
+ ...headers
17
+ });
18
+
19
+ export { clean, objCamelToSnake, requestBody, requestHeaders, strCamelToSnake };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xsai/shared",
3
- "version": "0.0.11",
3
+ "version": "0.0.13",
4
4
  "type": "module",
5
5
  "author": "Moeru AI",
6
6
  "license": "MIT",