@adaline/provider 0.7.0 → 0.9.0

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,274 +1,92 @@
1
+ import { GatewayBaseError, RoleEnum, ModalityEnum, MessageType, ConfigType, ToolType, ChatResponseType, PartialChatResponseType, EmbeddingModalityEnum, EmbeddingRequestsType, EmbeddingResponseType } from '@adaline/types';
1
2
  import { z } from 'zod';
2
- import { RoleEnum, ModalityEnum, MessageType, ConfigType, ToolType, ChatResponseType, PartialChatResponseType, EmbeddingModalityEnum, EmbeddingRequestsType, EmbeddingResponseType } from '@adaline/types';
3
3
 
4
- declare class ApiRequestError extends Error {
5
- readonly name = "Gateway_ApiRequestError";
4
+ declare class ProviderError extends GatewayBaseError {
5
+ readonly name: "ProviderError";
6
6
  readonly info: string;
7
7
  readonly cause: unknown;
8
- constructor({ info, error }: {
8
+ constructor({ info, cause }: {
9
9
  info: string;
10
- error: unknown;
11
- });
12
- static isApiRequestError(error: unknown): error is ApiRequestError;
13
- toJSON(): {
14
- name: string;
15
- message: string;
16
10
  cause: unknown;
17
- stack: string | undefined;
18
- info: string;
19
- };
20
- }
21
-
22
- declare class ApiResponseError extends Error {
23
- readonly name = "Gateway_ApiResponseError";
24
- readonly info: string;
25
- readonly cause: unknown;
26
- constructor({ info, error }: {
27
- info: string;
28
- error: unknown;
29
11
  });
30
- static isApiResponseError(error: unknown): error is ApiResponseError;
31
- toJSON(): {
32
- name: string;
33
- message: string;
34
- cause: unknown;
35
- stack: string | undefined;
36
- info: string;
37
- };
12
+ static isProviderError(error: unknown): error is ProviderError;
38
13
  }
39
14
 
40
- declare class DownloadError extends Error {
41
- readonly name = "Gateway_DownloadError";
15
+ declare class ModelError extends GatewayBaseError {
16
+ readonly name: "ModelError";
42
17
  readonly info: string;
43
18
  readonly cause: unknown;
44
- constructor({ info, error }: {
19
+ constructor({ info, cause }: {
45
20
  info: string;
46
- error: unknown;
47
- });
48
- static isDownloadError(error: unknown): error is DownloadError;
49
- toJSON(): {
50
- name: string;
51
- message: string;
52
21
  cause: unknown;
53
- stack: string | undefined;
54
- info: string;
55
- };
56
- }
57
-
58
- declare class InvalidAuthError extends Error {
59
- readonly name = "Gateway_InvalidAuthError";
60
- readonly info: string;
61
- readonly cause: unknown;
62
- constructor({ info, error }: {
63
- info: string;
64
- error: unknown;
65
22
  });
66
- static isInvalidAuthError(error: unknown): error is InvalidAuthError;
67
- toJSON(): {
68
- name: string;
69
- message: string;
70
- cause: unknown;
71
- stack: string | undefined;
72
- info: string;
73
- };
23
+ static isModelError(error: unknown): error is ModelError;
74
24
  }
75
25
 
76
- declare class InvalidConfigError extends Error {
77
- readonly name = "Gateway_InvalidConfigError";
26
+ declare class ModelResponseError extends GatewayBaseError {
27
+ readonly name: "ModelResponseError";
78
28
  readonly info: string;
79
29
  readonly cause: unknown;
80
- constructor({ info, error }: {
30
+ constructor({ info, cause }: {
81
31
  info: string;
82
- error: unknown;
83
- });
84
- static isInvalidConfigError(error: unknown): error is InvalidConfigError;
85
- toJSON(): {
86
- name: string;
87
- message: string;
88
32
  cause: unknown;
89
- stack: string | undefined;
90
- info: string;
91
- };
92
- }
93
-
94
- declare class InvalidEndpointError extends Error {
95
- readonly name = "Gateway_InvalidEndpointError";
96
- readonly info: string;
97
- readonly cause: unknown;
98
- constructor({ info, error }: {
99
- info: string;
100
- error: unknown;
101
33
  });
102
- static isInvalidEndpointError(error: unknown): error is InvalidEndpointError;
103
- toJSON(): {
104
- name: string;
105
- message: string;
106
- cause: unknown;
107
- stack: string | undefined;
108
- info: string;
109
- };
34
+ static isModelResponseError(error: unknown): error is ModelResponseError;
110
35
  }
111
36
 
112
- declare class InvalidMessagesError extends Error {
113
- readonly name = "Gateway_InvalidMessagesError";
37
+ declare class InvalidModelRequestError extends GatewayBaseError {
38
+ readonly name: "InvalidModelRequestError";
114
39
  readonly info: string;
115
40
  readonly cause: unknown;
116
- constructor({ info, error }: {
41
+ constructor({ info, cause }: {
117
42
  info: string;
118
- error: unknown;
119
- });
120
- static isInvalidMessagesError(error: unknown): error is InvalidMessagesError;
121
- toJSON(): {
122
- name: string;
123
- message: string;
124
43
  cause: unknown;
125
- stack: string | undefined;
126
- info: string;
127
- };
128
- }
129
-
130
- declare class InvalidModalityError extends Error {
131
- readonly name = "Gateway_InvalidModalityError";
132
- readonly info: string;
133
- readonly cause: unknown;
134
- constructor({ info, error }: {
135
- info: string;
136
- error: unknown;
137
44
  });
138
- static isInvalidModalityError(error: unknown): error is InvalidModalityError;
139
- toJSON(): {
140
- name: string;
141
- message: string;
142
- cause: unknown;
143
- stack: string | undefined;
144
- info: string;
145
- };
45
+ static isInvalidModelRequestError(error: unknown): error is InvalidModelRequestError;
146
46
  }
147
47
 
148
- declare class InvalidModelError extends Error {
149
- readonly name = "Gateway_InvalidModelError";
48
+ declare class InvalidConfigError extends GatewayBaseError {
49
+ readonly name: "InvalidConfigError";
150
50
  readonly info: string;
151
51
  readonly cause: unknown;
152
- constructor({ info, error }: {
52
+ constructor({ info, cause }: {
153
53
  info: string;
154
- error: unknown;
155
- });
156
- static isInvalidModelError(error: unknown): error is InvalidModelError;
157
- toJSON(): {
158
- name: string;
159
- message: string;
160
54
  cause: unknown;
161
- stack: string | undefined;
162
- info: string;
163
- };
164
- }
165
-
166
- declare class InvalidPromptError extends Error {
167
- readonly name = "Gateway_InvalidPromptError";
168
- readonly info: string;
169
- readonly cause: unknown;
170
- constructor({ info, error }: {
171
- info: string;
172
- error: unknown;
173
55
  });
174
- static isInvalidPromptError(error: unknown): error is InvalidPromptError;
175
- toJSON(): {
176
- name: string;
177
- message: string;
178
- cause: unknown;
179
- stack: string | undefined;
180
- info: string;
181
- };
56
+ static isInvalidConfigError(error: unknown): error is InvalidConfigError;
182
57
  }
183
58
 
184
- declare class InvalidRoleError extends Error {
185
- readonly name = "Gateway_InvalidRoleError";
59
+ declare class InvalidMessagesError extends GatewayBaseError {
60
+ readonly name: "InvalidMessagesError";
186
61
  readonly info: string;
187
62
  readonly cause: unknown;
188
- constructor({ info, error }: {
63
+ constructor({ info, cause }: {
189
64
  info: string;
190
- error: unknown;
191
- });
192
- static isInvalidRoleError(error: unknown): error is InvalidRoleError;
193
- toJSON(): {
194
- name: string;
195
- message: string;
196
65
  cause: unknown;
197
- stack: string | undefined;
198
- info: string;
199
- };
200
- }
201
-
202
- declare class InvalidToolsError extends Error {
203
- readonly name = "Gateway_InvalidToolsError";
204
- readonly info: string;
205
- readonly cause: unknown;
206
- constructor({ info, error }: {
207
- info: string;
208
- error: unknown;
209
66
  });
210
- static isInvalidToolsError(error: unknown): error is InvalidToolsError;
211
- toJSON(): {
212
- name: string;
213
- message: string;
214
- cause: unknown;
215
- stack: string | undefined;
216
- info: string;
217
- };
67
+ static isInvalidMessagesError(error: unknown): error is InvalidMessagesError;
218
68
  }
219
69
 
220
- declare class InvalidEmbeddingRequestsError extends Error {
221
- readonly name = "Gateway_InvalidEmbeddingRequestsError";
70
+ declare class InvalidToolsError extends GatewayBaseError {
71
+ readonly name: "InvalidToolsError";
222
72
  readonly info: string;
223
73
  readonly cause: unknown;
224
- constructor({ info, error }: {
74
+ constructor({ info, cause }: {
225
75
  info: string;
226
- error: unknown;
227
- });
228
- static isInvalidEmbeddingRequestsError(error: unknown): error is InvalidEmbeddingRequestsError;
229
- toJSON(): {
230
- name: string;
231
- message: string;
232
76
  cause: unknown;
233
- info: string;
234
- stack: string | undefined;
235
- };
236
- }
237
-
238
- declare class JsonParseError extends Error {
239
- readonly name = "Gateway_JsonParseError";
240
- readonly info: string;
241
- readonly cause: unknown;
242
- constructor({ info, error }: {
243
- info: string;
244
- error: unknown;
245
77
  });
246
- static isJsonParseError(error: unknown): error is JsonParseError;
247
- toJSON(): {
248
- name: string;
249
- message: string;
250
- cause: unknown;
251
- stack: string | undefined;
252
- info: string;
253
- };
78
+ static isInvalidToolsError(error: unknown): error is InvalidToolsError;
254
79
  }
255
80
 
256
- declare class ValidationError extends Error {
257
- readonly name = "Gateway_ValidationError";
81
+ declare class InvalidEmbeddingRequestsError extends GatewayBaseError {
82
+ readonly name: "InvalidEmbeddingRequestsError";
258
83
  readonly info: string;
259
84
  readonly cause: unknown;
260
- constructor({ info, error }: {
85
+ constructor({ info, cause }: {
261
86
  info: string;
262
- error: unknown;
263
- });
264
- static isValidationError(error: unknown): error is ValidationError;
265
- toJSON(): {
266
- name: string;
267
- message: string;
268
87
  cause: unknown;
269
- stack: string | undefined;
270
- info: string;
271
- };
88
+ });
89
+ static isInvalidEmbeddingRequestsError(error: unknown): error is InvalidEmbeddingRequestsError;
272
90
  }
273
91
 
274
92
  declare const ChatModelSchema: <R extends z.ZodEnum<[string, ...string[]]> = z.ZodEnum<["system", "user", "assistant", "tool"]>, M extends z.ZodEnum<[string, ...string[]]> = z.ZodEnum<["text", "image", "tool-call", "tool-response"]>>(Roles?: R, Modalities?: M) => z.ZodObject<{
@@ -1889,20 +1707,30 @@ declare const ObjectSchemaConfigItem: (data: Omit<ObjectSchemaConfigItemType, "t
1889
1707
  interface ChatModelV1<MS extends ChatModelSchemaType = ChatModelSchemaType> {
1890
1708
  readonly version: "v1";
1891
1709
  readonly modelSchema: MS;
1892
- getTokenCount(messages: MessageType[]): number;
1893
1710
  getDefaultBaseUrl(): UrlType;
1894
1711
  getDefaultHeaders(): HeadersType;
1895
1712
  getDefaultParams(): ParamsType;
1713
+ getRetryDelay(responseHeaders: HeadersType): {
1714
+ shouldRetry: boolean;
1715
+ delayMs: number;
1716
+ };
1717
+ getTokenCount(messages: MessageType[]): number;
1718
+ transformModelRequest(request: any): {
1719
+ modelName: string | undefined;
1720
+ config: ConfigType;
1721
+ messages: MessageType[];
1722
+ tools: ToolType[] | undefined;
1723
+ };
1896
1724
  transformConfig(config: ConfigType, messages?: MessageType[], tools?: ToolType[]): ParamsType;
1897
1725
  transformMessages(messages: MessageType[]): ParamsType;
1898
1726
  transformTools(tools: ToolType[]): ParamsType;
1899
- getCompleteChatUrl(config?: ConfigType, messages?: MessageType[], tools?: ToolType[]): UrlType;
1727
+ getCompleteChatUrl(config?: ConfigType, messages?: MessageType[], tools?: ToolType[]): Promise<UrlType>;
1900
1728
  getCompleteChatHeaders(config?: ConfigType, messages?: MessageType[], tools?: ToolType[]): Promise<HeadersType>;
1901
- getCompleteChatData(config: ConfigType, messages: MessageType[], tools?: ToolType[]): ParamsType;
1729
+ getCompleteChatData(config: ConfigType, messages: MessageType[], tools?: ToolType[]): Promise<ParamsType>;
1902
1730
  transformCompleteChatResponse(response: any): ChatResponseType;
1903
- getStreamChatUrl(config?: ConfigType, messages?: MessageType[], tools?: ToolType[]): UrlType;
1731
+ getStreamChatUrl(config?: ConfigType, messages?: MessageType[], tools?: ToolType[]): Promise<UrlType>;
1904
1732
  getStreamChatHeaders(config?: ConfigType, messages?: MessageType[], tools?: ToolType[]): Promise<HeadersType>;
1905
- getStreamChatData(config: ConfigType, messages: MessageType[], tools?: ToolType[]): ParamsType;
1733
+ getStreamChatData(config: ConfigType, messages: MessageType[], tools?: ToolType[]): Promise<ParamsType>;
1906
1734
  transformStreamChatResponseChunk(chunk: string, buffer: string): AsyncGenerator<{
1907
1735
  partialResponse: PartialChatResponseType;
1908
1736
  buffer: string;
@@ -2263,16 +2091,25 @@ type EmbeddingModelSchemaType<M extends z.ZodEnum<[string, ...string[]]> = typeo
2263
2091
  interface EmbeddingModelV1<MS extends EmbeddingModelSchemaType = EmbeddingModelSchemaType> {
2264
2092
  readonly version: "v1";
2265
2093
  readonly modelSchema: MS;
2266
- getTokenCount: (requests: EmbeddingRequestsType) => number;
2267
- getDefaultBaseUrl: () => UrlType;
2268
- getDefaultHeaders: () => HeadersType;
2269
- getDefaultParams: () => ParamsType;
2270
- transformConfig: (config: ConfigType, requests?: EmbeddingRequestsType) => ParamsType;
2271
- transformEmbeddingRequests: (requests: EmbeddingRequestsType) => ParamsType;
2272
- getGetEmbeddingsUrl: (config?: ConfigType, requests?: EmbeddingRequestsType) => UrlType;
2273
- getGetEmbeddingsHeaders: (config?: ConfigType, requests?: EmbeddingRequestsType) => HeadersType;
2274
- getGetEmbeddingsData: (config: ConfigType, requests: EmbeddingRequestsType) => ParamsType;
2275
- transformGetEmbeddingsResponse: (response: any) => EmbeddingResponseType;
2094
+ getDefaultBaseUrl(): UrlType;
2095
+ getDefaultHeaders(): HeadersType;
2096
+ getDefaultParams(): ParamsType;
2097
+ getRetryDelay(responseHeaders: HeadersType): {
2098
+ shouldRetry: boolean;
2099
+ delayMs: number;
2100
+ };
2101
+ getTokenCount(requests: EmbeddingRequestsType): number;
2102
+ transformModelRequest(request: any): {
2103
+ modelName: string | undefined;
2104
+ config: ConfigType;
2105
+ embeddingRequests: EmbeddingRequestsType;
2106
+ };
2107
+ transformConfig(config: ConfigType, requests?: EmbeddingRequestsType): ParamsType;
2108
+ transformEmbeddingRequests(requests: EmbeddingRequestsType): ParamsType;
2109
+ getGetEmbeddingsUrl(config?: ConfigType, requests?: EmbeddingRequestsType): Promise<UrlType>;
2110
+ getGetEmbeddingsHeaders(config?: ConfigType, requests?: EmbeddingRequestsType): Promise<HeadersType>;
2111
+ getGetEmbeddingsData(config: ConfigType, requests: EmbeddingRequestsType): Promise<ParamsType>;
2112
+ transformGetEmbeddingsResponse(response: any): EmbeddingResponseType;
2276
2113
  }
2277
2114
 
2278
2115
  interface ProviderV1<O extends Record<string, any> = Record<string, any>> {
@@ -2338,4 +2175,4 @@ declare const urlWithoutTrailingSlash: (url: string) => string;
2338
2175
 
2339
2176
  declare const isRunningInBrowser: () => boolean;
2340
2177
 
2341
- export { ApiRequestError, ApiResponseError, CONFIG, ChatModelSchema, type ChatModelSchemaType, type ChatModelV1, ConfigItemDef, type ConfigItemDefType, ConfigItemEnum, type ConfigItemEnumType, ConfigItemLiterals, DownloadError, EmbeddingModelSchema, type EmbeddingModelSchemaType, type EmbeddingModelV1, Headers, type HeadersType, InvalidAuthError, InvalidConfigError, InvalidEmbeddingRequestsError, InvalidEndpointError, InvalidMessagesError, InvalidModalityError, InvalidModelError, InvalidPromptError, InvalidRoleError, InvalidToolsError, JsonParseError, MultiStringConfigItem, MultiStringConfigItemDef, MultiStringConfigItemSchema, type MultiStringConfigItemSchemaType, type MultiStringConfigItemType, MultiStringConfigItemTypeLiteral, ObjectSchemaConfigItem, ObjectSchemaConfigItemDef, ObjectSchemaConfigItemSchema, type ObjectSchemaConfigItemSchemaType, type ObjectSchemaConfigItemType, ObjectSchemaConfigItemTypeLiteral, Params, type ParamsType, type ProviderV1, RangeConfigItem, RangeConfigItemDef, type RangeConfigItemDefType, RangeConfigItemSchema, type RangeConfigItemSchemaType, RangeConfigItemTypeLiteral, SelectBooleanConfigItem, SelectBooleanConfigItemDef, type SelectBooleanConfigItemDefType, SelectBooleanConfigItemSchema, type SelectBooleanConfigItemSchemaType, SelectBooleanConfigItemTypeLiteral, SelectStringConfigItem, SelectStringConfigItemDef, type SelectStringConfigItemDefType, SelectStringConfigItemSchema, type SelectStringConfigItemSchemaType, SelectStringConfigItemTypeLiteral, Url, type UrlType, ValidationError, convertBase64ToUint8Array, convertUint8ArrayToBase64, encodedBase64ToString, getErrorMessage, isRunningInBrowser, removeUndefinedEntries, urlWithoutTrailingSlash };
2178
+ export { CONFIG, ChatModelSchema, type ChatModelSchemaType, type ChatModelV1, ConfigItemDef, type ConfigItemDefType, ConfigItemEnum, type ConfigItemEnumType, ConfigItemLiterals, EmbeddingModelSchema, type EmbeddingModelSchemaType, type EmbeddingModelV1, Headers, type HeadersType, InvalidConfigError, InvalidEmbeddingRequestsError, InvalidMessagesError, InvalidModelRequestError, InvalidToolsError, ModelError, ModelResponseError, MultiStringConfigItem, MultiStringConfigItemDef, MultiStringConfigItemSchema, type MultiStringConfigItemSchemaType, type MultiStringConfigItemType, MultiStringConfigItemTypeLiteral, ObjectSchemaConfigItem, ObjectSchemaConfigItemDef, ObjectSchemaConfigItemSchema, type ObjectSchemaConfigItemSchemaType, type ObjectSchemaConfigItemType, ObjectSchemaConfigItemTypeLiteral, Params, type ParamsType, ProviderError, type ProviderV1, RangeConfigItem, RangeConfigItemDef, type RangeConfigItemDefType, RangeConfigItemSchema, type RangeConfigItemSchemaType, RangeConfigItemTypeLiteral, SelectBooleanConfigItem, SelectBooleanConfigItemDef, type SelectBooleanConfigItemDefType, SelectBooleanConfigItemSchema, type SelectBooleanConfigItemSchemaType, SelectBooleanConfigItemTypeLiteral, SelectStringConfigItem, SelectStringConfigItemDef, type SelectStringConfigItemDefType, SelectStringConfigItemSchema, type SelectStringConfigItemSchemaType, SelectStringConfigItemTypeLiteral, Url, type UrlType, convertBase64ToUint8Array, convertUint8ArrayToBase64, encodedBase64ToString, getErrorMessage, isRunningInBrowser, removeUndefinedEntries, urlWithoutTrailingSlash };
package/dist/index.js CHANGED
@@ -1,75 +1,53 @@
1
1
  'use strict';
2
2
 
3
- var zod = require('zod');
4
3
  var types = require('@adaline/types');
4
+ var zod = require('zod');
5
5
 
6
- var V=Object.defineProperty;var R=Object.getOwnPropertySymbols;var Y=Object.prototype.hasOwnProperty,W=Object.prototype.propertyIsEnumerable;var O=(t,r,e)=>r in t?V(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e,m=(t,r)=>{for(var e in r||(r={}))Y.call(r,e)&&O(t,e,r[e]);if(R)for(var e of R(r))W.call(r,e)&&O(t,e,r[e]);return t};var Q={type:"range",title:"Temperature",description:"Adjusts the model's creativity level. With a setting of 0, the model strictly picks the most probable next word. For endeavors that benefit from a dash of inventiveness, consider dialing it up to 0.7 or higher, enabling the model to produce text that's unexpectedly fresh."},X={type:"range",title:"Max tokens",description:"Specify the total tokens for generation, where one token approximates four English characters. Setting this to 0 defaults to the model's maximum capacity."},ee=t=>({type:"multi",title:"Stop sequence",description:`Enter up to ${t} sequences that will halt additional text output. The generated text will exclude these sequences.`}),te={type:"range",title:"Top P",description:"Selects a subset of likely tokens for generation, restricting choices to the top-P fraction of possibilities, such as the top 10% when P=0.1. This approach can limit the variety of the output. By default, it's set to 1, indicating no restriction. It's advised to adjust this parameter or temperature to modulate output diversity, but not to modify both simultaneously."},ne={type:"range",title:"Top K",description:"Select only from the highest K probabilities for each following word, effectively eliminating the less likely 'long tail' options."},re={type:"range",title:"Frequency penalty",description:"Minimize redundancy. By assigning a penalty to frequently used tokens within the text, the likelihood of repeating identical phrases is reduced. The default setting for this penalty is zero."},oe={type:"range",title:"Presence penalty",description:"Enhance the introduction of novel subjects by reducing the preference for tokens that have already appeared in the text, thus boosting the chances of exploring fresh topics. The standard setting for this is zero."},de={TEMPERATURE:Q,MAX_TOKENS:X,STOP:ee,TOP_P:te,TOP_K:ne,FREQUENCY_PENALTY:re,PRESENCE_PENALTY:oe};var o=t=>t==null?"unknown error":typeof t=="string"?t:t instanceof Error?t.message:JSON.stringify(t);var Se=t=>Object.fromEntries(Object.entries(t).filter(([r,e])=>e!=null));var z=()=>typeof window!="undefined"&&typeof window.document!="undefined"&&typeof navigator!="undefined";var be=t=>{let r=t.replace(/-/g,"+").replace(/_/g,"/"),e=globalThis.atob(r);return Uint8Array.from(e,n=>n.codePointAt(0))},xe=t=>{let r="";for(let e=0;e<t.length;e++)r+=String.fromCodePoint(t[e]);return globalThis.btoa(r)},Te=t=>{if(z()){let r=atob(t),e=new Uint8Array(r.length);for(let a=0;a<r.length;a++)e[a]=r.charCodeAt(a);return new TextDecoder("utf-8").decode(e)}else return Buffer.from(t,"base64").toString("utf-8")};var Me=t=>t==null?void 0:t.replace(/\/$/,"");var j=class extends Error{constructor({info:e,error:n}){super(`[Gateway_ApiRequestError]: ${e}.
7
- Message: ${o(n)}`);this.name="Gateway_ApiRequestError";this.cause=n,this.info=e;}static isApiRequestError(e){return e instanceof Error&&e.name===this.name&&typeof e.info=="string"}toJSON(){return {name:this.name,message:this.message,cause:this.cause,stack:this.stack,info:this.info}}};var _=class extends Error{constructor({info:e,error:n}){super(`[Gateway_ApiResponseError]: ${e}.
8
- Message: ${o(n)}`);this.name="Gateway_ApiResponseError";this.cause=n,this.info=e;}static isApiResponseError(e){return e instanceof Error&&e.name===this.name&&typeof e.info=="string"}toJSON(){return {name:this.name,message:this.message,cause:this.cause,stack:this.stack,info:this.info}}};var D=class extends Error{constructor({info:e,error:n}){super(`[Gateway_DownloadError]: ${e}.
9
- Message: ${o(n)}`);this.name="Gateway_DownloadError";this.cause=n,this.info=e;}static isDownloadError(e){return e instanceof Error&&e.name===this.name&&typeof e.info=="string"}toJSON(){return {name:this.name,message:this.message,cause:this.cause,stack:this.stack,info:this.info}}};var $=class extends Error{constructor({info:e,error:n}){super(`[Gateway_InvalidAuthError]: ${e}.
10
- Message: ${o(n)}`);this.name="Gateway_InvalidAuthError";this.cause=n,this.info=e;}static isInvalidAuthError(e){return e instanceof Error&&e.name===this.name&&typeof e.info=="string"}toJSON(){return {name:this.name,message:this.message,cause:this.cause,stack:this.stack,info:this.info}}};var G=class extends Error{constructor({info:e,error:n}){super(`[Gateway_InvalidConfigError]: ${e}.
11
- Message: ${o(n)}`);this.name="Gateway_InvalidConfigError";this.cause=n,this.info=e;}static isInvalidConfigError(e){return e instanceof Error&&e.name===this.name&&typeof e.info=="string"}toJSON(){return {name:this.name,message:this.message,cause:this.cause,stack:this.stack,info:this.info}}};var P=class extends Error{constructor({info:e,error:n}){super(`[Gateway_InvalidEndpointError]: ${e}.
12
- Message: ${o(n)}`);this.name="Gateway_InvalidEndpointError";this.cause=n,this.info=e;}static isInvalidEndpointError(e){return e instanceof Error&&e.name===this.name&&typeof e.info=="string"}toJSON(){return {name:this.name,message:this.message,cause:this.cause,stack:this.stack,info:this.info}}};var A=class extends Error{constructor({info:e,error:n}){super(`[Gateway_InvalidMessagesError]: ${e}.
13
- Message: ${o(n)}`);this.name="Gateway_InvalidMessagesError";this.cause=n,this.info=e;}static isInvalidMessagesError(e){return e instanceof Error&&e.name===this.name&&typeof e.info=="string"}toJSON(){return {name:this.name,message:this.message,cause:this.cause,stack:this.stack,info:this.info}}};var N=class extends Error{constructor({info:e,error:n}){super(`[Gateway_InvalidModalityError]: ${e}.
14
- Message: ${o(n)}`);this.name="Gateway_InvalidModalityError";this.cause=n,this.info=e;}static isInvalidModalityError(e){return e instanceof Error&&e.name===this.name&&typeof e.info=="string"}toJSON(){return {name:this.name,message:this.message,cause:this.cause,stack:this.stack,info:this.info}}};var B=class extends Error{constructor({info:e,error:n}){super(`[Gateway_InvalidModelError]: ${e}.
15
- Message: ${o(n)}`);this.name="Gateway_InvalidModelError";this.cause=n,this.info=e;}static isInvalidModelError(e){return e instanceof Error&&e.name===this.name&&typeof e.info=="string"}toJSON(){return {name:this.name,message:this.message,cause:this.cause,stack:this.stack,info:this.info}}};var J=class extends Error{constructor({info:e,error:n}){super(`[Gateway_InvalidPromptError]: ${e}.
16
- Message: ${o(n)}`);this.name="Gateway_InvalidPromptError";this.cause=n,this.info=e;}static isInvalidPromptError(e){return e instanceof Error&&e.name===this.name&&typeof e.info=="string"}toJSON(){return {name:this.name,message:this.message,cause:this.cause,stack:this.stack,info:this.info}}};var U=class extends Error{constructor({info:e,error:n}){super(`[Gateway_InvalidRoleError]: ${e}.
17
- Message: ${o(n)}`);this.name="Gateway_InvalidRoleError";this.cause=n,this.info=e;}static isInvalidRoleError(e){return e instanceof Error&&e.name===this.name&&typeof e.info=="string"}toJSON(){return {name:this.name,message:this.message,cause:this.cause,stack:this.stack,info:this.info}}};var q=class extends Error{constructor({info:e,error:n}){super(`[Gateway_InvalidToolsError]: ${e}.
18
- Message: ${o(n)}`);this.name="Gateway_InvalidToolsError";this.cause=n,this.info=e;}static isInvalidToolsError(e){return e instanceof Error&&e.name===this.name&&typeof e.info=="string"}toJSON(){return {name:this.name,message:this.message,cause:this.cause,stack:this.stack,info:this.info}}};var L=class extends Error{constructor({info:e,error:n}){super(`[Gateway_InvalidEmbeddingRequestsError]: ${e}.
19
- Message: ${o(n)}`);this.name="Gateway_InvalidEmbeddingRequestsError";this.info=e,this.cause=n;}static isInvalidEmbeddingRequestsError(e){return e instanceof Error&&e.name===this.name&&typeof e.info=="string"}toJSON(){return {name:this.name,message:this.message,cause:this.cause,info:this.info,stack:this.stack}}};var Z=class extends Error{constructor({info:e,error:n}){super(`[Gateway_JsonParseError]: ${e}.
20
- Message: ${o(n)}`);this.name="Gateway_JsonParseError";this.cause=n,this.info=e;}static isJsonParseError(e){return e instanceof Error&&e.name===this.name&&typeof e.info=="string"}toJSON(){return {name:this.name,message:this.message,cause:this.cause,stack:this.stack,info:this.info}}};var K=class extends Error{constructor({info:e,error:n}){super(`[Gateway_ValidationError]: ${e}.
21
- Message: ${o(n)}`);this.name="Gateway_ValidationError";this.cause=n,this.info=e;}static isValidationError(e){return e instanceof Error&&e.name===this.name&&typeof e.info=="string"}toJSON(){return {name:this.name,message:this.message,cause:this.cause,stack:this.stack,info:this.info}}};var h="multi-string",x=zod.z.object({type:zod.z.literal(h),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),max:zod.z.number().int().positive()}),se=t=>zod.z.array(zod.z.string()).max(t).default([]).optional(),it=t=>({def:x.parse(m({type:h},t)),schema:se(t.max)});var E="range",T=zod.z.object({type:zod.z.literal(E),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),min:zod.z.number().int(),max:zod.z.number().int(),step:zod.z.number().positive(),default:zod.z.number().int()}),ie=(t,r,e,n)=>zod.z.number().min(t).max(r).step(e).default(n).optional(),ft=t=>({def:T.parse(m({type:E},t)),schema:ie(t.min,t.max,t.step,t.default)});var S="select-string",C=zod.z.object({type:zod.z.literal(S),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),default:zod.z.string().min(1),choices:zod.z.array(zod.z.string().min(1))}),ae=(t,r)=>zod.z.enum(r).default(t).optional(),ut=t=>({def:C.parse(m({type:S},t)),schema:ae(t.default,t.choices)});var I="object-schema",M=zod.z.object({type:zod.z.literal(I),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),objectSchema:zod.z.any()}),me=t=>t,Et=t=>({def:M.parse(m({type:I},t)),schema:me(t.objectSchema)});var w="select-boolean",v=zod.z.object({type:zod.z.literal(w),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),default:zod.z.boolean().nullable()}),ce=t=>zod.z.boolean().nullable().default(t).optional(),kt=t=>({def:v.parse(m({type:w},t)),schema:ce(t.default)});var fe=[E,h,S,I,w],zt=zod.z.enum(fe),k=zod.z.discriminatedUnion("type",[T,x,C,v,M]);var Gt=(t=types.RoleEnum,r=types.ModalityEnum)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),roles:zod.z.record(t,zod.z.string().min(1).optional()),modalities:zod.z.array(r).nonempty(),maxInputTokens:zod.z.number().int().positive().min(1),maxOutputTokens:zod.z.number().int().positive().min(1),config:zod.z.object({def:zod.z.record(zod.z.string().min(1),k),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(e=>{var d,u;let n=Object.keys(e.def),a=Object.keys((u=(d=e.schema)==null?void 0:d.shape)!=null?u:{});return n.every(b=>a.includes(b))&&a.every(b=>n.includes(b))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"})});var Jt=(t=types.EmbeddingModalityEnum)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),modalities:zod.z.array(t).nonempty(),maxInputTokens:zod.z.number().int().positive().min(1),maxOutputTokens:zod.z.number().int().positive().min(1),config:zod.z.object({def:zod.z.record(zod.z.string().min(1),k),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(r=>{var a,d;let e=Object.keys(r.def),n=Object.keys((d=(a=r.schema)==null?void 0:a.shape)!=null?d:{});return e.every(u=>n.includes(u))&&n.every(u=>e.includes(u))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"})});var Lt=zod.z.record(zod.z.string());var Ft=zod.z.record(zod.z.union([zod.z.boolean(),zod.z.string(),zod.z.number(),zod.z.object({}),zod.z.array(zod.z.any()),zod.z.null(),zod.z.undefined()]));var Yt=zod.z.string().url();
6
+ var J=Object.defineProperty;var R=Object.getOwnPropertySymbols;var Q=Object.prototype.hasOwnProperty,X=Object.prototype.propertyIsEnumerable;var O=(e,n,t)=>n in e?J(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t,a=(e,n)=>{for(var t in n||(n={}))Q.call(n,t)&&O(e,t,n[t]);if(R)for(var t of R(n))X.call(n,t)&&O(e,t,n[t]);return e};var j="ProviderError",v=class e extends types.GatewayBaseError{constructor({info:t,cause:o}){super({info:t,cause:o},j);this.name=j;this.info=t,this.cause=o;}static isProviderError(t){return t instanceof e}};var z="ModelError",D=class e extends types.GatewayBaseError{constructor({info:t,cause:o}){super({info:t,cause:o},z);this.name=z;this.info=t,this.cause=o;}static isModelError(t){return t instanceof e}};var B="ModelResponseError",P=class e extends types.GatewayBaseError{constructor({info:t,cause:o}){super({info:t,cause:o},B);this.name=B;this.cause=o,this.info=t;}static isModelResponseError(t){return t instanceof e}};var L="InvalidModelRequestError",U=class e extends types.GatewayBaseError{constructor({info:t,cause:o}){super({info:t,cause:o},L);this.name=L;this.cause=o,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidModelRequestError(t){return t instanceof e}};var A="InvalidConfigError",Z=class e extends types.GatewayBaseError{constructor({info:t,cause:o}){super({info:t,cause:o},A);this.name=A;this.cause=o,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidConfigError(t){return t instanceof e}};var q="InvalidMessagesError",K=class e extends types.GatewayBaseError{constructor({info:t,cause:o}){super({info:t,cause:o},q);this.name=q;this.cause=o,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidMessagesError(t){return t instanceof e}};var G="InvalidToolsError",N=class e extends types.GatewayBaseError{constructor({info:t,cause:o}){super({info:t,cause:o},G);this.name=G;this.cause=o,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidToolsError(t){return t instanceof e}};var F="InvalidEmbeddingRequestsError",H=class e extends types.GatewayBaseError{constructor({info:t,cause:o}){super({info:t,cause:o},F);this.name=F;this.info=t,this.cause=o,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidEmbeddingRequestsError(t){return t instanceof e}};var d="multi-string",E=zod.z.object({type:zod.z.literal(d),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),max:zod.z.number().int().positive()}),se=e=>zod.z.array(zod.z.string()).max(e).default([]).optional(),Ke=e=>({def:E.parse(a({type:d},e)),schema:se(e.max)});var h="range",x=zod.z.object({type:zod.z.literal(h),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),min:zod.z.number().int(),max:zod.z.number().int(),step:zod.z.number().positive(),default:zod.z.number().int()}),ae=(e,n,t,o)=>zod.z.number().min(e).max(n).step(t).default(o).optional(),He=e=>({def:x.parse(a({type:h},e)),schema:ae(e.min,e.max,e.step,e.default)});var S="select-string",w=zod.z.object({type:zod.z.literal(S),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),default:zod.z.string().min(1),choices:zod.z.array(zod.z.string().min(1))}),ce=(e,n)=>zod.z.enum(n).default(e).optional(),Je=e=>({def:w.parse(a({type:S},e)),schema:ce(e.default,e.choices)});var I="object-schema",M=zod.z.object({type:zod.z.literal(I),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),objectSchema:zod.z.any()}),me=e=>e,_e=e=>({def:M.parse(a({type:I},e)),schema:me(e.objectSchema)});var b="select-boolean",k=zod.z.object({type:zod.z.literal(b),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),default:zod.z.boolean().nullable()}),pe=e=>zod.z.boolean().nullable().default(e).optional(),ot=e=>({def:k.parse(a({type:b},e)),schema:pe(e.default)});var fe=[h,d,S,I,b],lt=zod.z.enum(fe),T=zod.z.discriminatedUnion("type",[x,E,w,k,M]);var ht=(e=types.RoleEnum,n=types.ModalityEnum)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),roles:zod.z.record(e,zod.z.string().min(1).optional()),modalities:zod.z.array(n).nonempty(),maxInputTokens:zod.z.number().int().positive().min(1),maxOutputTokens:zod.z.number().int().positive().min(1),config:zod.z.object({def:zod.z.record(zod.z.string().min(1),T),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(t=>{var u,g;let o=Object.keys(t.def),s=Object.keys((g=(u=t.schema)==null?void 0:u.shape)!=null?g:{});return o.every(C=>s.includes(C))&&s.every(C=>o.includes(C))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"})});var Ct=(e=types.EmbeddingModalityEnum)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),modalities:zod.z.array(e).nonempty(),maxInputTokens:zod.z.number().int().positive().min(1),maxOutputTokens:zod.z.number().int().positive().min(1),config:zod.z.object({def:zod.z.record(zod.z.string().min(1),T),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(n=>{var s,u;let t=Object.keys(n.def),o=Object.keys((u=(s=n.schema)==null?void 0:s.shape)!=null?u:{});return t.every(g=>o.includes(g))&&o.every(g=>t.includes(g))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"})});var wt=zod.z.record(zod.z.string());var Rt=zod.z.record(zod.z.union([zod.z.boolean(),zod.z.string(),zod.z.number(),zod.z.object({}),zod.z.array(zod.z.any()),zod.z.null(),zod.z.undefined()]));var vt=zod.z.string().url();var de={type:"range",title:"Temperature",description:"Adjusts the model's creativity level. With a setting of 0, the model strictly picks the most probable next word. For endeavors that benefit from a dash of inventiveness, consider dialing it up to 0.7 or higher, enabling the model to produce text that's unexpectedly fresh."},he={type:"range",title:"Max tokens",description:"Specify the total tokens for generation, where one token approximates four English characters. Setting this to 0 defaults to the model's maximum capacity."},Se=e=>({type:"multi",title:"Stop sequence",description:`Enter up to ${e} sequences that will halt additional text output. The generated text will exclude these sequences.`}),Ie={type:"range",title:"Top P",description:"Selects a subset of likely tokens for generation, restricting choices to the top-P fraction of possibilities, such as the top 10% when P=0.1. This approach can limit the variety of the output. By default, it's set to 1, indicating no restriction. It's advised to adjust this parameter or temperature to modulate output diversity, but not to modify both simultaneously."},be={type:"range",title:"Top K",description:"Select only from the highest K probabilities for each following word, effectively eliminating the less likely 'long tail' options."},Te={type:"range",title:"Frequency penalty",description:"Minimize redundancy. By assigning a penalty to frequently used tokens within the text, the likelihood of repeating identical phrases is reduced. The default setting for this penalty is zero."},Ce={type:"range",title:"Presence penalty",description:"Enhance the introduction of novel subjects by reducing the preference for tokens that have already appeared in the text, thus boosting the chances of exploring fresh topics. The standard setting for this is zero."},Dt={TEMPERATURE:de,MAX_TOKENS:he,STOP:Se,TOP_P:Ie,TOP_K:be,FREQUENCY_PENALTY:Te,PRESENCE_PENALTY:Ce};var Pt=e=>e==null?"unknown error":typeof e=="string"?e:e instanceof Error?e.message:JSON.stringify(e);var Ut=e=>Object.fromEntries(Object.entries(e).filter(([n,t])=>t!=null));var $=()=>typeof window!="undefined"&&typeof window.document!="undefined"&&typeof navigator!="undefined";var Kt=e=>{let n=e.replace(/-/g,"+").replace(/_/g,"/"),t=globalThis.atob(n);return Uint8Array.from(t,o=>o.codePointAt(0))},Gt=e=>{let n="";for(let t=0;t<e.length;t++)n+=String.fromCodePoint(e[t]);return globalThis.btoa(n)},Nt=e=>{if($()){let n=atob(e),t=new Uint8Array(n.length);for(let s=0;s<n.length;s++)t[s]=n.charCodeAt(s);return new TextDecoder("utf-8").decode(t)}else return Buffer.from(e,"base64").toString("utf-8")};var Ht=e=>e==null?void 0:e.replace(/\/$/,"");
22
7
 
23
- exports.ApiRequestError = j;
24
- exports.ApiResponseError = _;
25
- exports.CONFIG = de;
26
- exports.ChatModelSchema = Gt;
27
- exports.ConfigItemDef = k;
28
- exports.ConfigItemEnum = zt;
8
+ exports.CONFIG = Dt;
9
+ exports.ChatModelSchema = ht;
10
+ exports.ConfigItemDef = T;
11
+ exports.ConfigItemEnum = lt;
29
12
  exports.ConfigItemLiterals = fe;
30
- exports.DownloadError = D;
31
- exports.EmbeddingModelSchema = Jt;
32
- exports.Headers = Lt;
33
- exports.InvalidAuthError = $;
34
- exports.InvalidConfigError = G;
35
- exports.InvalidEmbeddingRequestsError = L;
36
- exports.InvalidEndpointError = P;
37
- exports.InvalidMessagesError = A;
38
- exports.InvalidModalityError = N;
39
- exports.InvalidModelError = B;
40
- exports.InvalidPromptError = J;
41
- exports.InvalidRoleError = U;
42
- exports.InvalidToolsError = q;
43
- exports.JsonParseError = Z;
44
- exports.MultiStringConfigItem = it;
45
- exports.MultiStringConfigItemDef = x;
13
+ exports.EmbeddingModelSchema = Ct;
14
+ exports.Headers = wt;
15
+ exports.InvalidConfigError = Z;
16
+ exports.InvalidEmbeddingRequestsError = H;
17
+ exports.InvalidMessagesError = K;
18
+ exports.InvalidModelRequestError = U;
19
+ exports.InvalidToolsError = N;
20
+ exports.ModelError = D;
21
+ exports.ModelResponseError = P;
22
+ exports.MultiStringConfigItem = Ke;
23
+ exports.MultiStringConfigItemDef = E;
46
24
  exports.MultiStringConfigItemSchema = se;
47
- exports.MultiStringConfigItemTypeLiteral = h;
48
- exports.ObjectSchemaConfigItem = Et;
25
+ exports.MultiStringConfigItemTypeLiteral = d;
26
+ exports.ObjectSchemaConfigItem = _e;
49
27
  exports.ObjectSchemaConfigItemDef = M;
50
28
  exports.ObjectSchemaConfigItemSchema = me;
51
29
  exports.ObjectSchemaConfigItemTypeLiteral = I;
52
- exports.Params = Ft;
53
- exports.RangeConfigItem = ft;
54
- exports.RangeConfigItemDef = T;
55
- exports.RangeConfigItemSchema = ie;
56
- exports.RangeConfigItemTypeLiteral = E;
57
- exports.SelectBooleanConfigItem = kt;
58
- exports.SelectBooleanConfigItemDef = v;
59
- exports.SelectBooleanConfigItemSchema = ce;
60
- exports.SelectBooleanConfigItemTypeLiteral = w;
61
- exports.SelectStringConfigItem = ut;
62
- exports.SelectStringConfigItemDef = C;
63
- exports.SelectStringConfigItemSchema = ae;
30
+ exports.Params = Rt;
31
+ exports.ProviderError = v;
32
+ exports.RangeConfigItem = He;
33
+ exports.RangeConfigItemDef = x;
34
+ exports.RangeConfigItemSchema = ae;
35
+ exports.RangeConfigItemTypeLiteral = h;
36
+ exports.SelectBooleanConfigItem = ot;
37
+ exports.SelectBooleanConfigItemDef = k;
38
+ exports.SelectBooleanConfigItemSchema = pe;
39
+ exports.SelectBooleanConfigItemTypeLiteral = b;
40
+ exports.SelectStringConfigItem = Je;
41
+ exports.SelectStringConfigItemDef = w;
42
+ exports.SelectStringConfigItemSchema = ce;
64
43
  exports.SelectStringConfigItemTypeLiteral = S;
65
- exports.Url = Yt;
66
- exports.ValidationError = K;
67
- exports.convertBase64ToUint8Array = be;
68
- exports.convertUint8ArrayToBase64 = xe;
69
- exports.encodedBase64ToString = Te;
70
- exports.getErrorMessage = o;
71
- exports.isRunningInBrowser = z;
72
- exports.removeUndefinedEntries = Se;
73
- exports.urlWithoutTrailingSlash = Me;
44
+ exports.Url = vt;
45
+ exports.convertBase64ToUint8Array = Kt;
46
+ exports.convertUint8ArrayToBase64 = Gt;
47
+ exports.encodedBase64ToString = Nt;
48
+ exports.getErrorMessage = Pt;
49
+ exports.isRunningInBrowser = $;
50
+ exports.removeUndefinedEntries = Ut;
51
+ exports.urlWithoutTrailingSlash = Ht;
74
52
  //# sourceMappingURL=index.js.map
75
53
  //# sourceMappingURL=index.js.map