@adaline/gateway 0.9.0 → 0.11.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.mts +26 -13
- package/dist/index.d.ts +26 -13
- package/dist/index.js +18 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -83,19 +83,21 @@ declare class QueueTaskTimeoutError extends GatewayBaseError {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
interface Cache<T> {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
86
|
+
getCacheKey(data: any): string;
|
|
87
|
+
get(key: string): Promise<T | undefined>;
|
|
88
|
+
set(key: string, value: T): Promise<void>;
|
|
89
|
+
delete(key: string): Promise<void>;
|
|
90
|
+
clear(): Promise<void>;
|
|
90
91
|
}
|
|
91
92
|
|
|
92
93
|
declare class LRUCache<T extends object> implements Cache<T> {
|
|
93
94
|
private cache;
|
|
94
95
|
constructor(maxEntries?: number);
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
96
|
+
getCacheKey(data: any): string;
|
|
97
|
+
get(key: string): Promise<T | undefined>;
|
|
98
|
+
set(key: string, value: T): Promise<void>;
|
|
99
|
+
delete(key: string): Promise<void>;
|
|
100
|
+
clear(): Promise<void>;
|
|
99
101
|
}
|
|
100
102
|
|
|
101
103
|
type QueueTask<Request, Response> = {
|
|
@@ -702,6 +704,7 @@ declare const CompleteChatHandlerRequest: z.ZodObject<{
|
|
|
702
704
|
};
|
|
703
705
|
metadata?: any;
|
|
704
706
|
}>]>, "many">>;
|
|
707
|
+
enableCache: z.ZodBoolean;
|
|
705
708
|
callbacks: z.ZodOptional<z.ZodArray<z.ZodType<CompleteChatCallbackType<any>, z.ZodTypeDef, CompleteChatCallbackType<any>>, "atleastone">>;
|
|
706
709
|
metadataForCallbacks: z.ZodOptional<z.ZodAny>;
|
|
707
710
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -787,6 +790,7 @@ declare const CompleteChatHandlerRequest: z.ZodObject<{
|
|
|
787
790
|
})[];
|
|
788
791
|
metadata?: undefined;
|
|
789
792
|
}[];
|
|
793
|
+
enableCache: boolean;
|
|
790
794
|
cache: Cache<{
|
|
791
795
|
request: {
|
|
792
796
|
config: Record<string, any>;
|
|
@@ -995,6 +999,7 @@ declare const CompleteChatHandlerRequest: z.ZodObject<{
|
|
|
995
999
|
})[];
|
|
996
1000
|
metadata?: undefined;
|
|
997
1001
|
}[];
|
|
1002
|
+
enableCache: boolean;
|
|
998
1003
|
cache: Cache<{
|
|
999
1004
|
request: {
|
|
1000
1005
|
config: Record<string, any>;
|
|
@@ -2230,6 +2235,7 @@ declare const GetEmbeddingsHandlerRequest: z.ZodObject<{
|
|
|
2230
2235
|
requests: number[][];
|
|
2231
2236
|
metadata?: undefined;
|
|
2232
2237
|
}>]>;
|
|
2238
|
+
enableCache: z.ZodBoolean;
|
|
2233
2239
|
callbacks: z.ZodOptional<z.ZodArray<z.ZodType<GetEmbeddingsCallbackType<any>, z.ZodTypeDef, GetEmbeddingsCallbackType<any>>, "atleastone">>;
|
|
2234
2240
|
metadataForCallbacks: z.ZodOptional<z.ZodAny>;
|
|
2235
2241
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -2279,6 +2285,7 @@ declare const GetEmbeddingsHandlerRequest: z.ZodObject<{
|
|
|
2279
2285
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
2280
2286
|
};
|
|
2281
2287
|
}>;
|
|
2288
|
+
enableCache: boolean;
|
|
2282
2289
|
cache: Cache<{
|
|
2283
2290
|
request: {
|
|
2284
2291
|
config: Record<string, any>;
|
|
@@ -2377,6 +2384,7 @@ declare const GetEmbeddingsHandlerRequest: z.ZodObject<{
|
|
|
2377
2384
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
2378
2385
|
};
|
|
2379
2386
|
}>;
|
|
2387
|
+
enableCache: boolean;
|
|
2380
2388
|
cache: Cache<{
|
|
2381
2389
|
request: {
|
|
2382
2390
|
config: Record<string, any>;
|
|
@@ -4909,10 +4917,13 @@ declare const GatewayCompleteChatRequest: z.ZodObject<{
|
|
|
4909
4917
|
metadata?: any;
|
|
4910
4918
|
}>]>, "many">>;
|
|
4911
4919
|
options: z.ZodOptional<z.ZodObject<{
|
|
4920
|
+
enableCache: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
4912
4921
|
metadataForCallbacks: z.ZodOptional<z.ZodAny>;
|
|
4913
4922
|
}, "strip", z.ZodTypeAny, {
|
|
4923
|
+
enableCache: boolean;
|
|
4914
4924
|
metadataForCallbacks?: any;
|
|
4915
4925
|
}, {
|
|
4926
|
+
enableCache?: boolean | undefined;
|
|
4916
4927
|
metadataForCallbacks?: any;
|
|
4917
4928
|
}>>;
|
|
4918
4929
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -4999,6 +5010,7 @@ declare const GatewayCompleteChatRequest: z.ZodObject<{
|
|
|
4999
5010
|
metadata?: undefined;
|
|
5000
5011
|
}[];
|
|
5001
5012
|
options?: {
|
|
5013
|
+
enableCache: boolean;
|
|
5002
5014
|
metadataForCallbacks?: any;
|
|
5003
5015
|
} | undefined;
|
|
5004
5016
|
tools?: {
|
|
@@ -5097,6 +5109,7 @@ declare const GatewayCompleteChatRequest: z.ZodObject<{
|
|
|
5097
5109
|
metadata?: undefined;
|
|
5098
5110
|
}[];
|
|
5099
5111
|
options?: {
|
|
5112
|
+
enableCache?: boolean | undefined;
|
|
5100
5113
|
metadataForCallbacks?: any;
|
|
5101
5114
|
} | undefined;
|
|
5102
5115
|
tools?: {
|
|
@@ -5764,14 +5777,14 @@ declare const GatewayGetEmbeddingsRequest: z.ZodObject<{
|
|
|
5764
5777
|
metadata?: undefined;
|
|
5765
5778
|
}>]>;
|
|
5766
5779
|
options: z.ZodOptional<z.ZodObject<{
|
|
5767
|
-
|
|
5780
|
+
enableCache: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
5768
5781
|
metadataForCallbacks: z.ZodOptional<z.ZodAny>;
|
|
5769
5782
|
}, "strip", z.ZodTypeAny, {
|
|
5783
|
+
enableCache: boolean;
|
|
5770
5784
|
metadataForCallbacks?: any;
|
|
5771
|
-
queuePriority?: number | undefined;
|
|
5772
5785
|
}, {
|
|
5786
|
+
enableCache?: boolean | undefined;
|
|
5773
5787
|
metadataForCallbacks?: any;
|
|
5774
|
-
queuePriority?: number | undefined;
|
|
5775
5788
|
}>>;
|
|
5776
5789
|
}, "strip", z.ZodTypeAny, {
|
|
5777
5790
|
config: Record<string, any>;
|
|
@@ -5830,8 +5843,8 @@ declare const GatewayGetEmbeddingsRequest: z.ZodObject<{
|
|
|
5830
5843
|
metadata?: undefined;
|
|
5831
5844
|
};
|
|
5832
5845
|
options?: {
|
|
5846
|
+
enableCache: boolean;
|
|
5833
5847
|
metadataForCallbacks?: any;
|
|
5834
|
-
queuePriority?: number | undefined;
|
|
5835
5848
|
} | undefined;
|
|
5836
5849
|
}, {
|
|
5837
5850
|
config: Record<string, any>;
|
|
@@ -5890,8 +5903,8 @@ declare const GatewayGetEmbeddingsRequest: z.ZodObject<{
|
|
|
5890
5903
|
metadata?: undefined;
|
|
5891
5904
|
};
|
|
5892
5905
|
options?: {
|
|
5906
|
+
enableCache?: boolean | undefined;
|
|
5893
5907
|
metadataForCallbacks?: any;
|
|
5894
|
-
queuePriority?: number | undefined;
|
|
5895
5908
|
} | undefined;
|
|
5896
5909
|
}>;
|
|
5897
5910
|
type GatewayGetEmbeddingsRequestType = z.infer<typeof GatewayGetEmbeddingsRequest>;
|
package/dist/index.d.ts
CHANGED
|
@@ -83,19 +83,21 @@ declare class QueueTaskTimeoutError extends GatewayBaseError {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
interface Cache<T> {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
86
|
+
getCacheKey(data: any): string;
|
|
87
|
+
get(key: string): Promise<T | undefined>;
|
|
88
|
+
set(key: string, value: T): Promise<void>;
|
|
89
|
+
delete(key: string): Promise<void>;
|
|
90
|
+
clear(): Promise<void>;
|
|
90
91
|
}
|
|
91
92
|
|
|
92
93
|
declare class LRUCache<T extends object> implements Cache<T> {
|
|
93
94
|
private cache;
|
|
94
95
|
constructor(maxEntries?: number);
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
96
|
+
getCacheKey(data: any): string;
|
|
97
|
+
get(key: string): Promise<T | undefined>;
|
|
98
|
+
set(key: string, value: T): Promise<void>;
|
|
99
|
+
delete(key: string): Promise<void>;
|
|
100
|
+
clear(): Promise<void>;
|
|
99
101
|
}
|
|
100
102
|
|
|
101
103
|
type QueueTask<Request, Response> = {
|
|
@@ -702,6 +704,7 @@ declare const CompleteChatHandlerRequest: z.ZodObject<{
|
|
|
702
704
|
};
|
|
703
705
|
metadata?: any;
|
|
704
706
|
}>]>, "many">>;
|
|
707
|
+
enableCache: z.ZodBoolean;
|
|
705
708
|
callbacks: z.ZodOptional<z.ZodArray<z.ZodType<CompleteChatCallbackType<any>, z.ZodTypeDef, CompleteChatCallbackType<any>>, "atleastone">>;
|
|
706
709
|
metadataForCallbacks: z.ZodOptional<z.ZodAny>;
|
|
707
710
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -787,6 +790,7 @@ declare const CompleteChatHandlerRequest: z.ZodObject<{
|
|
|
787
790
|
})[];
|
|
788
791
|
metadata?: undefined;
|
|
789
792
|
}[];
|
|
793
|
+
enableCache: boolean;
|
|
790
794
|
cache: Cache<{
|
|
791
795
|
request: {
|
|
792
796
|
config: Record<string, any>;
|
|
@@ -995,6 +999,7 @@ declare const CompleteChatHandlerRequest: z.ZodObject<{
|
|
|
995
999
|
})[];
|
|
996
1000
|
metadata?: undefined;
|
|
997
1001
|
}[];
|
|
1002
|
+
enableCache: boolean;
|
|
998
1003
|
cache: Cache<{
|
|
999
1004
|
request: {
|
|
1000
1005
|
config: Record<string, any>;
|
|
@@ -2230,6 +2235,7 @@ declare const GetEmbeddingsHandlerRequest: z.ZodObject<{
|
|
|
2230
2235
|
requests: number[][];
|
|
2231
2236
|
metadata?: undefined;
|
|
2232
2237
|
}>]>;
|
|
2238
|
+
enableCache: z.ZodBoolean;
|
|
2233
2239
|
callbacks: z.ZodOptional<z.ZodArray<z.ZodType<GetEmbeddingsCallbackType<any>, z.ZodTypeDef, GetEmbeddingsCallbackType<any>>, "atleastone">>;
|
|
2234
2240
|
metadataForCallbacks: z.ZodOptional<z.ZodAny>;
|
|
2235
2241
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -2279,6 +2285,7 @@ declare const GetEmbeddingsHandlerRequest: z.ZodObject<{
|
|
|
2279
2285
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
2280
2286
|
};
|
|
2281
2287
|
}>;
|
|
2288
|
+
enableCache: boolean;
|
|
2282
2289
|
cache: Cache<{
|
|
2283
2290
|
request: {
|
|
2284
2291
|
config: Record<string, any>;
|
|
@@ -2377,6 +2384,7 @@ declare const GetEmbeddingsHandlerRequest: z.ZodObject<{
|
|
|
2377
2384
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
2378
2385
|
};
|
|
2379
2386
|
}>;
|
|
2387
|
+
enableCache: boolean;
|
|
2380
2388
|
cache: Cache<{
|
|
2381
2389
|
request: {
|
|
2382
2390
|
config: Record<string, any>;
|
|
@@ -4909,10 +4917,13 @@ declare const GatewayCompleteChatRequest: z.ZodObject<{
|
|
|
4909
4917
|
metadata?: any;
|
|
4910
4918
|
}>]>, "many">>;
|
|
4911
4919
|
options: z.ZodOptional<z.ZodObject<{
|
|
4920
|
+
enableCache: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
4912
4921
|
metadataForCallbacks: z.ZodOptional<z.ZodAny>;
|
|
4913
4922
|
}, "strip", z.ZodTypeAny, {
|
|
4923
|
+
enableCache: boolean;
|
|
4914
4924
|
metadataForCallbacks?: any;
|
|
4915
4925
|
}, {
|
|
4926
|
+
enableCache?: boolean | undefined;
|
|
4916
4927
|
metadataForCallbacks?: any;
|
|
4917
4928
|
}>>;
|
|
4918
4929
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -4999,6 +5010,7 @@ declare const GatewayCompleteChatRequest: z.ZodObject<{
|
|
|
4999
5010
|
metadata?: undefined;
|
|
5000
5011
|
}[];
|
|
5001
5012
|
options?: {
|
|
5013
|
+
enableCache: boolean;
|
|
5002
5014
|
metadataForCallbacks?: any;
|
|
5003
5015
|
} | undefined;
|
|
5004
5016
|
tools?: {
|
|
@@ -5097,6 +5109,7 @@ declare const GatewayCompleteChatRequest: z.ZodObject<{
|
|
|
5097
5109
|
metadata?: undefined;
|
|
5098
5110
|
}[];
|
|
5099
5111
|
options?: {
|
|
5112
|
+
enableCache?: boolean | undefined;
|
|
5100
5113
|
metadataForCallbacks?: any;
|
|
5101
5114
|
} | undefined;
|
|
5102
5115
|
tools?: {
|
|
@@ -5764,14 +5777,14 @@ declare const GatewayGetEmbeddingsRequest: z.ZodObject<{
|
|
|
5764
5777
|
metadata?: undefined;
|
|
5765
5778
|
}>]>;
|
|
5766
5779
|
options: z.ZodOptional<z.ZodObject<{
|
|
5767
|
-
|
|
5780
|
+
enableCache: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
5768
5781
|
metadataForCallbacks: z.ZodOptional<z.ZodAny>;
|
|
5769
5782
|
}, "strip", z.ZodTypeAny, {
|
|
5783
|
+
enableCache: boolean;
|
|
5770
5784
|
metadataForCallbacks?: any;
|
|
5771
|
-
queuePriority?: number | undefined;
|
|
5772
5785
|
}, {
|
|
5786
|
+
enableCache?: boolean | undefined;
|
|
5773
5787
|
metadataForCallbacks?: any;
|
|
5774
|
-
queuePriority?: number | undefined;
|
|
5775
5788
|
}>>;
|
|
5776
5789
|
}, "strip", z.ZodTypeAny, {
|
|
5777
5790
|
config: Record<string, any>;
|
|
@@ -5830,8 +5843,8 @@ declare const GatewayGetEmbeddingsRequest: z.ZodObject<{
|
|
|
5830
5843
|
metadata?: undefined;
|
|
5831
5844
|
};
|
|
5832
5845
|
options?: {
|
|
5846
|
+
enableCache: boolean;
|
|
5833
5847
|
metadataForCallbacks?: any;
|
|
5834
|
-
queuePriority?: number | undefined;
|
|
5835
5848
|
} | undefined;
|
|
5836
5849
|
}, {
|
|
5837
5850
|
config: Record<string, any>;
|
|
@@ -5890,8 +5903,8 @@ declare const GatewayGetEmbeddingsRequest: z.ZodObject<{
|
|
|
5890
5903
|
metadata?: undefined;
|
|
5891
5904
|
};
|
|
5892
5905
|
options?: {
|
|
5906
|
+
enableCache?: boolean | undefined;
|
|
5893
5907
|
metadataForCallbacks?: any;
|
|
5894
|
-
queuePriority?: number | undefined;
|
|
5895
5908
|
} | undefined;
|
|
5896
5909
|
}>;
|
|
5897
5910
|
type GatewayGetEmbeddingsRequestType = z.infer<typeof GatewayGetEmbeddingsRequest>;
|
package/dist/index.js
CHANGED
|
@@ -3,39 +3,39 @@
|
|
|
3
3
|
var zod = require('zod');
|
|
4
4
|
var types = require('@adaline/types');
|
|
5
5
|
var proxyAgent = require('proxy-agent');
|
|
6
|
-
var
|
|
7
|
-
var xe = require('crypto-js/sha256.js');
|
|
6
|
+
var U = require('axios');
|
|
8
7
|
var lruCache = require('lru-cache');
|
|
8
|
+
var Me = require('crypto-js/sha256.js');
|
|
9
9
|
|
|
10
10
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
11
|
|
|
12
|
-
var
|
|
13
|
-
var
|
|
12
|
+
var U__default = /*#__PURE__*/_interopDefault(U);
|
|
13
|
+
var Me__default = /*#__PURE__*/_interopDefault(Me);
|
|
14
14
|
|
|
15
|
-
var be=Object.defineProperty,Re=Object.defineProperties;var Te=Object.getOwnPropertyDescriptors;var N=Object.getOwnPropertySymbols;var we=Object.prototype.hasOwnProperty,ke=Object.prototype.propertyIsEnumerable;var D=(a,t)=>(t=Symbol[a])?t:Symbol.for("Symbol."+a);var W=(a,t,e)=>t in a?be(a,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[t]=e,x=(a,t)=>{for(var e in t||(t={}))we.call(t,e)&&W(a,e,t[e]);if(N)for(var e of N(t))ke.call(t,e)&&W(a,e,t[e]);return a},U=(a,t)=>Re(a,Te(t));var u=(a,t,e)=>new Promise((s,r)=>{var o=n=>{try{i(e.next(n));}catch(c){r(c);}},l=n=>{try{i(e.throw(n));}catch(c){r(c);}},i=n=>n.done?s(n.value):Promise.resolve(n.value).then(o,l);i((e=e.apply(a,t)).next());}),h=function(a,t){this[0]=a,this[1]=t;},q=(a,t,e)=>{var s=(l,i,n,c)=>{try{var p=e[l](i),m=(i=p.value)instanceof h,G=p.done;Promise.resolve(m?i[0]:i).then(y=>m?s(l==="return"?l:"next",i[1]?{done:y.done,value:y.value}:y,n,c):n({value:y,done:G})).catch(y=>s("throw",y,n,c));}catch(y){c(y);}},r=l=>o[l]=i=>new Promise((n,c)=>s(l,i,n,c)),o={};return e=e.apply(a,t),o[D("asyncIterator")]=()=>o,r("next"),r("throw"),r("return"),o};var k=(a,t,e)=>(t=a[D("asyncIterator")])?t.call(a):(a=a[D("iterator")](),t={},e=(s,r)=>(r=a[s])&&(t[s]=o=>new Promise((l,i,n)=>(o=r.call(a,o),n=o.done,Promise.resolve(o.value).then(c=>l({value:c,done:n}),i)))),e("next"),e("return"),t);var g=class a extends Error{constructor(t,e=500,s){super(t),this.name="GatewayError",this.status=e,this.data=s,Error.captureStackTrace&&Error.captureStackTrace(this,a);}};var Ee="HttpClientError",H=class a extends types.GatewayBaseError{constructor({info:t,cause:e}){super({info:t,cause:e},Ee),this.info=t,this.cause=e,Object.setPrototypeOf(this,new.target.prototype);}static isHttpClientError(t){return t instanceof a}},Ge="HttpRequestError",f=class a extends types.GatewayBaseError{constructor(t,e=500,s,r){super({info:t,cause:{status:e,headers:s,data:r}},Ge),this.info=t,this.cause={status:e,headers:s,data:r},Object.setPrototypeOf(this,new.target.prototype);}static isHttpRequestError(t){return t instanceof a}};var F=a=>{let t={};return a&&(typeof a=="object"||a instanceof Headers)&&Object.entries(a).forEach(([e,s])=>{Array.isArray(s)?t[e]=s.join(", "):typeof s=="string"?t[e]=s:t[e]="";}),t},X=a=>{var o,l,i;let t=(a==null?void 0:a.message)||"An unexpected error occurred",e=((o=a==null?void 0:a.response)==null?void 0:o.status)||500,s=F((l=a==null?void 0:a.response)==null?void 0:l.headers)||{},r=((i=a==null?void 0:a.response)==null?void 0:i.data)||{};return new f(t,e,s,r)},Q=class{constructor(t){this.isNodeEnvironment=()=>typeof process!="undefined"&&process.versions!=null&&process.versions.node!=null;let{axiosInstance:e,timeoutInMilliseconds:s}=t;this.client=e||V__default.default.create();let r=zod.z.number().int().positive().optional();if(this.defaultTimeout=r.parse(s),this.client.defaults.timeout=this.defaultTimeout,t.proxyUrl)if(t.proxyUrl.startsWith("http://"))process.env.HTTP_PROXY=t.proxyUrl,this.httpProxyAgent=new proxyAgent.ProxyAgent;else if(t.proxyUrl.startsWith("https://"))process.env.HTTPS_PROXY=t.proxyUrl,this.httpsProxyAgent=new proxyAgent.ProxyAgent({rejectUnauthorized:!1});else throw new H({info:"Invalid proxy URL, only http and https proxies are supported",cause:{proxyUrl:t.proxyUrl}})}makeRequest(l,i,n){return u(this,arguments,function*(t,e,s,r={},o){try{let c=U(x(x({},t==="get"||t==="delete"?{params:s}:{data:s}),r),{timeout:o||this.defaultTimeout});if(this.httpProxyAgent?c.httpsAgent=this.httpProxyAgent:this.httpsProxyAgent&&(c.httpsAgent=this.httpsProxyAgent),t==="get"||t==="delete"){let p=yield this.client[t](e,c);return {data:p.data,headers:F(p.headers),status:{code:p.status,text:p.statusText}}}else {let p=yield this.client[t](e,c.data,U(x({},c),{params:c.params}));return {data:p.data,headers:F(p.headers),status:{code:p.status,text:p.statusText}}}}catch(c){throw V__default.default.isAxiosError(c)?X(c):new H({info:"An unexpected error occurred",cause:c})}})}stream(t,e,s,r,o){return q(this,null,function*(){try{if(this.isNodeEnvironment()){let p=yield new h(this.client.request({method:e,url:t,headers:r,data:s,responseType:"stream",signal:o==null?void 0:o.abortSignal}));try{for(var l=k(p.data),i,n,c;i=!(n=yield new h(l.next())).done;i=!1){let m=n.value;yield m.toString();}}catch(n){c=[n];}finally{try{i&&(n=l.return)&&(yield new h(n.call(l)));}finally{if(c)throw c[0]}}}else {let p={method:e,headers:new Headers(x({},r)),body:e!=="get"?JSON.stringify(s):void 0,signal:o==null?void 0:o.abortSignal},m=yield new h(fetch(t,p));if(!m.ok){let G=yield new h(m.json());throw new f(`Request failed with status ${m.status}`,m.status,F(m.headers),G)}if(m.body){let G=m.body.getReader();for(;;){let{done:y,value:w}=yield new h(G.read());if(y){yield new TextDecoder().decode(w,{stream:!0});break}yield new TextDecoder().decode(w,{stream:!0});}}else throw new f("Cannot stream the body of the response.",500,{},m)}}catch(p){throw f.isHttpRequestError(p)?p:(p==null?void 0:p.name)==="AbortError"?new f("AbortError",408,{},{}):(p==null?void 0:p.name)==="CanceledError"?new f("AbortError",408,{},{}):V__default.default.isAxiosError(p)?X(p):new H({info:"An unexpected error occurred",cause:p})}})}get(t,e,s){return u(this,null,function*(){return this.makeRequest("get",t,e||{},{headers:s})})}post(t,e,s){return u(this,null,function*(){return this.makeRequest("post",t,e||{},{headers:s})})}put(t,e,s){return u(this,null,function*(){return this.makeRequest("put",t,e||{},{headers:s})})}delete(t,e,s){return u(this,null,function*(){return this.makeRequest("delete",t,e||{},{headers:s})})}patch(t,e,s){return u(this,null,function*(){return this.makeRequest("patch",t,e||{},{headers:s})})}};var ve="QueueTaskTimeoutError",j=class a extends types.GatewayBaseError{constructor({info:t,cause:e}){super({info:t,cause:e},ve),this.info=t,this.cause=e,Object.setPrototypeOf(this,new.target.prototype);}static isQueueTaskTimeoutError(t){return t instanceof a}};var Z=zod.z.object({maxConcurrentTasks:zod.z.number().int().positive(),retryCount:zod.z.number().int().positive(),timeout:zod.z.number().int().positive(),retry:zod.z.object({initialDelay:zod.z.number().int().positive(),exponentialFactor:zod.z.number().int().positive()})});var I=(a,t)=>xe__default.default(a+JSON.stringify(t)).toString(),v=a=>a instanceof g?a:a instanceof Error?new g(a.message):new g(a),S=()=>typeof window!="undefined"&&typeof window.document!="undefined"&&typeof navigator!="undefined";var Se={error:"color: red",warn:"color: yellow",info:"color: green"},Pe=(a,t,...e)=>{if(S())S()&&console.log(`%c[${a.toUpperCase()}] [${t}]`,Se[a],...e);else switch(a){case"error":console.error(...e);break;case"warn":console.warn(...e);break;default:console.log(...e);}},Me=(a,t,...e)=>{var s;S()||((s=process==null?void 0:process.env)==null?void 0:s.DEBUG)==="true"&&Pe(a,t,...e);},b=(a,t,...e)=>u(void 0,null,function*(){let s=[];a.forEach(r=>{let o=r[t];if(typeof o=="function")try{let l=o(...e);l instanceof Promise&&s.push(l);}catch(l){Me("error",`SAFELY_INVOKE_CALLBACKS:${String(t)}:`,l);}}),yield Promise.allSettled(s);}),_=a=>new Promise(t=>setTimeout(t,a));var P=class{constructor(t){this.activeTasks=0;this.queue=[];this.options=t;}enqueue(t){this.queue.push(t),this.processQueue();}withTimeout(t){return new Promise((e,s)=>{let r=setTimeout(()=>s(new j({info:"Queue task timeout",cause:new Error("Queue task timeout")})),this.options.timeout);t.execute(t.request).then(o=>{clearTimeout(r),e(o);}).catch(o=>{clearTimeout(r),s(o);});})}executeWithRetry(t,e){return u(this,null,function*(){try{return yield this.withTimeout(t)}catch(s){if(e===0)throw s;let r=!0,o=this.options.retry.initialDelay*Math.pow(this.options.retry.exponentialFactor,this.options.retryCount-e);if(f.isHttpRequestError(s)){if(s.cause.status===429){let l=M.safeParse(t.request);if(l.success){let i=l.data.model.getRetryDelay(s.cause.headers);r=i.shouldRetry,i.delayMs>0&&(o=i.delayMs);}}s.cause.status>=500&&s.cause.status<600;}if(r)return yield _(o),this.executeWithRetry(t,e-1);throw s}})}processQueue(){return u(this,null,function*(){if(this.activeTasks>=this.options.maxConcurrentTasks)return;let t=this.queue.shift();if(t){this.activeTasks+=1;try{let e=yield this.executeWithRetry(t,this.options.retryCount);t.resolve(e);}catch(e){t.reject(e);}finally{this.activeTasks-=1,this.processQueue();}}})}};var O=class{constructor(t=1e3){this.cache=new lruCache.LRUCache({max:t,allowStale:!1,updateAgeOnGet:!1});}get(t){return this.cache.get(t)}set(t,e){this.cache.set(t,e);}delete(t){this.cache.delete(t);}clear(){this.cache.clear();}};var ae=zod.z.object({queueOptions:Z.partial().optional(),dangerouslyAllowBrowser:zod.z.boolean().optional(),httpClient:zod.z.custom().optional(),completeChatCache:zod.z.custom().optional(),completeChatCallbacks:zod.z.array(zod.z.custom()).nonempty().optional(),getEmbeddingsCache:zod.z.custom().optional(),getEmbeddingsCallbacks:zod.z.array(zod.z.custom()).nonempty().optional(),streamChatCallbacks:zod.z.array(zod.z.custom()).nonempty().optional()}),Fe=zod.z.object({metadataForCallbacks:zod.z.any().optional()}),M=zod.z.object({model:zod.z.custom(),config:types.Config(),messages:zod.z.array(types.Message()),tools:zod.z.array(types.Tool()).optional(),options:Fe.optional()}),Qe=zod.z.object({metadataForCallbacks:zod.z.any().optional()}),se=zod.z.object({model:zod.z.custom(),config:types.Config(),messages:zod.z.array(types.Message()),tools:zod.z.array(types.Tool()).optional(),options:Qe.optional()}),je=zod.z.object({queuePriority:zod.z.number().int().positive().optional(),metadataForCallbacks:zod.z.any().optional()}),B=zod.z.object({model:zod.z.custom(),config:types.Config(),embeddingRequests:types.EmbeddingRequests(),options:je.optional()});var ie=zod.z.object({cache:zod.z.custom(),model:zod.z.custom(),config:types.Config(),messages:zod.z.array(types.Message()),tools:zod.z.array(types.Tool()).optional(),callbacks:zod.z.array(zod.z.custom()).nonempty().optional(),metadataForCallbacks:zod.z.any().optional()}),Et=zod.z.object({request:zod.z.object({config:types.Config(),messages:zod.z.array(types.Message()),tools:zod.z.array(types.Tool()).optional()}),response:types.ChatResponse,cached:zod.z.boolean(),latencyInMs:zod.z.number().int().positive(),metadataForCallbacks:zod.z.any().optional(),provider:zod.z.object({request:zod.z.any(),response:zod.z.any()})});function pe(a,t){return u(this,null,function*(){let e=ie.parse(a),s=a.callbacks||[];try{b(s,"onChatStart",a.metadataForCallbacks);let r={config:e.config,messages:e.messages,tools:e.tools},o={url:yield e.model.getCompleteChatUrl(e.config,e.messages,e.tools),headers:yield e.model.getCompleteChatHeaders(e.config,e.messages,e.tools),data:yield e.model.getCompleteChatData(e.config,e.messages,e.tools)},l=I(`complete-chat:${o.url}:${e.model.modelSchema.name}`,r),i=a.cache.get(l);if(i)return i.cached=!0,b(s,"onChatCached",a.metadataForCallbacks,i),i;let n=Date.now(),c=yield t.post(o.url,o.data,o.headers),p=Date.now()-n,m={request:r,response:e.model.transformCompleteChatResponse(c.data),cached:!1,latencyInMs:p,metadataForCallbacks:a.metadataForCallbacks,provider:{request:o,response:c}};return a.cache.set(l,m),b(s,"onChatComplete",a.metadataForCallbacks,m),m}catch(r){let o;throw f.isHttpRequestError(r)||r instanceof g?o=r:o=v(r),b(s,"onChatError",a.metadataForCallbacks,o),o}})}var de=zod.z.object({cache:zod.z.custom(),model:zod.z.custom(),config:types.Config(),embeddingRequests:types.EmbeddingRequests(),callbacks:zod.z.array(zod.z.custom()).nonempty().optional(),metadataForCallbacks:zod.z.any().optional()}),It=zod.z.object({request:zod.z.object({config:types.Config(),embeddingRequests:types.EmbeddingRequests()}),response:types.EmbeddingResponse,cached:zod.z.boolean(),latencyInMs:zod.z.number().int().positive(),metadataForCallbacks:zod.z.any().optional(),provider:zod.z.object({request:zod.z.any(),response:zod.z.any()})});function me(a,t){return u(this,null,function*(){let e=de.parse(a),s=a.callbacks||[];try{b(s,"onGetEmbeddingsStart",a.metadataForCallbacks);let r={config:e.config,embeddingRequests:e.embeddingRequests},o={url:yield e.model.getGetEmbeddingsUrl(e.config,e.embeddingRequests),headers:yield e.model.getGetEmbeddingsHeaders(e.config,e.embeddingRequests),data:yield e.model.getGetEmbeddingsData(e.config,e.embeddingRequests)},l=I(`get-embeddings:${o.url}:${e.model.modelSchema.name}`,r),i=a.cache.get(l);if(i)return i.cached=!0,b(s,"onGetEmbeddingsCached",a.metadataForCallbacks,i),i;let n=Date.now(),c=yield t.post(o.url,o.data,o.headers),p=Date.now()-n,m={request:r,response:e.model.transformGetEmbeddingsResponse(c.data),cached:!1,latencyInMs:p,metadataForCallbacks:a.metadataForCallbacks,provider:{request:o,response:c}};return a.cache.set(l,m),b(s,"onGetEmbeddingsComplete",a.metadataForCallbacks,m),m}catch(r){let o;throw f.isHttpRequestError(r)||r instanceof g?o=r:o=v(r),b(s,"onGetEmbeddingsError",a.metadataForCallbacks,o),o}})}var Ce=zod.z.object({model:zod.z.custom(),config:types.Config(),messages:zod.z.array(types.Message()),tools:zod.z.array(types.Tool()).optional(),callbacks:zod.z.array(zod.z.custom()).nonempty().optional(),metadataForCallbacks:zod.z.any().optional()}),Zt=zod.z.object({request:zod.z.object({config:types.Config(),messages:zod.z.array(types.Message()),tools:zod.z.array(types.Tool()).optional()}),response:types.PartialChatResponse,metadataForCallbacks:zod.z.any().optional(),provider:zod.z.object({request:zod.z.any(),response:zod.z.any()})});function ge(a,t){return q(this,null,function*(){let e=Ce.parse(a),s=a.callbacks||[],r={config:e.config,messages:e.messages,tools:e.tools};try{b(s,"onStreamStart",a.metadataForCallbacks);let y={url:yield new h(e.model.getStreamChatUrl(e.config,e.messages,e.tools)),headers:yield new h(e.model.getStreamChatHeaders(e.config,e.messages,e.tools)),data:yield new h(e.model.getStreamChatData(e.config,e.messages,e.tools))},w="",A=!0;try{for(var c=k(t.stream(y.url,"post",y.data,y.headers)),p,m,G;p=!(m=yield new h(c.next())).done;p=!1){let z=m.value;try{for(var o=k(e.model.transformStreamChatResponseChunk(z,w)),l,i,n;l=!(i=yield new h(o.next())).done;l=!1){let fe=i.value;let $={request:r,response:fe.partialResponse,metadataForCallbacks:a.metadataForCallbacks,provider:{request:y,response:z}};b(s,A?"onStreamFirstResponse":"onStreamNewResponse",a.metadataForCallbacks,$),A&&(A=!1),yield $;}}catch(i){n=[i];}finally{try{l&&(i=o.return)&&(yield new h(i.call(o)));}finally{if(n)throw n[0]}}}}catch(m){G=[m];}finally{try{p&&(m=c.return)&&(yield new h(m.call(c)));}finally{if(G)throw G[0]}}b(s,"onStreamEnd",a.metadataForCallbacks);}catch(y){let w;throw y instanceof g?w=y:w=v(y),b(s,"onStreamError",a.metadataForCallbacks,w),w}})}var K=class{constructor(t){var s,r,o,l;if(!t.dangerouslyAllowBrowser&&S())throw new g(`It looks like you're running in a browser-like environment.
|
|
15
|
+
var ge=Object.defineProperty,be=Object.defineProperties;var Re=Object.getOwnPropertyDescriptors;var N=Object.getOwnPropertySymbols;var Te=Object.prototype.hasOwnProperty,we=Object.prototype.propertyIsEnumerable;var z=(a,t)=>(t=Symbol[a])?t:Symbol.for("Symbol."+a);var $=(a,t,e)=>t in a?ge(a,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[t]=e,x=(a,t)=>{for(var e in t||(t={}))Te.call(t,e)&&$(a,e,t[e]);if(N)for(var e of N(t))we.call(t,e)&&$(a,e,t[e]);return a},D=(a,t)=>be(a,Re(t));var m=(a,t,e)=>new Promise((o,n)=>{var s=r=>{try{d(e.next(r));}catch(c){n(c);}},p=r=>{try{d(e.throw(r));}catch(c){n(c);}},d=r=>r.done?o(r.value):Promise.resolve(r.value).then(s,p);d((e=e.apply(a,t)).next());}),h=function(a,t){this[0]=a,this[1]=t;},q=(a,t,e)=>{var o=(p,d,r,c)=>{try{var i=e[p](d),u=(d=i.value)instanceof h,G=i.done;Promise.resolve(u?d[0]:d).then(y=>u?o(p==="return"?p:"next",d[1]?{done:y.done,value:y.value}:y,r,c):r({value:y,done:G})).catch(y=>o("throw",y,r,c));}catch(y){c(y);}},n=p=>s[p]=d=>new Promise((r,c)=>o(p,d,r,c)),s={};return e=e.apply(a,t),s[z("asyncIterator")]=()=>s,n("next"),n("throw"),n("return"),s};var k=(a,t,e)=>(t=a[z("asyncIterator")])?t.call(a):(a=a[z("iterator")](),t={},e=(o,n)=>(n=a[o])&&(t[o]=s=>new Promise((p,d,r)=>(s=n.call(a,s),r=s.done,Promise.resolve(s.value).then(c=>p({value:c,done:r}),d)))),e("next"),e("return"),t);var f=class a extends Error{constructor(t,e=500,o){super(t),this.name="GatewayError",this.status=e,this.data=o,Error.captureStackTrace&&Error.captureStackTrace(this,a);}};var ke="HttpClientError",H=class a extends types.GatewayBaseError{constructor({info:t,cause:e}){super({info:t,cause:e},ke),this.info=t,this.cause=e,Object.setPrototypeOf(this,new.target.prototype);}static isHttpClientError(t){return t instanceof a}},Ee="HttpRequestError",g=class a extends types.GatewayBaseError{constructor(t,e=500,o,n){super({info:t,cause:{status:e,headers:o,data:n}},Ee),this.info=t,this.cause={status:e,headers:o,data:n},Object.setPrototypeOf(this,new.target.prototype);}static isHttpRequestError(t){return t instanceof a}};var F=a=>{let t={};return a&&(typeof a=="object"||a instanceof Headers)&&Object.entries(a).forEach(([e,o])=>{Array.isArray(o)?t[e]=o.join(", "):typeof o=="string"?t[e]=o:t[e]="";}),t},J=a=>{var s,p,d;let t=(a==null?void 0:a.message)||"An unexpected error occurred",e=((s=a==null?void 0:a.response)==null?void 0:s.status)||500,o=F((p=a==null?void 0:a.response)==null?void 0:p.headers)||{},n=((d=a==null?void 0:a.response)==null?void 0:d.data)||{};return new g(t,e,o,n)},j=class{constructor(t){this.isNodeEnvironment=()=>typeof process!="undefined"&&process.versions!=null&&process.versions.node!=null;let{axiosInstance:e,timeoutInMilliseconds:o}=t;this.client=e||U__default.default.create();let n=zod.z.number().int().positive().optional();if(this.defaultTimeout=n.parse(o),this.client.defaults.timeout=this.defaultTimeout,t.proxyUrl)if(t.proxyUrl.startsWith("http://"))process.env.HTTP_PROXY=t.proxyUrl,this.httpProxyAgent=new proxyAgent.ProxyAgent;else if(t.proxyUrl.startsWith("https://"))process.env.HTTPS_PROXY=t.proxyUrl,this.httpsProxyAgent=new proxyAgent.ProxyAgent({rejectUnauthorized:!1});else throw new H({info:"Invalid proxy URL, only http and https proxies are supported",cause:{proxyUrl:t.proxyUrl}})}makeRequest(p,d,r){return m(this,arguments,function*(t,e,o,n={},s){try{let c=D(x(x({},t==="get"||t==="delete"?{params:o}:{data:o}),n),{timeout:s||this.defaultTimeout});if(this.httpProxyAgent?c.httpsAgent=this.httpProxyAgent:this.httpsProxyAgent&&(c.httpsAgent=this.httpsProxyAgent),t==="get"||t==="delete"){let i=yield this.client[t](e,c);return {data:i.data,headers:F(i.headers),status:{code:i.status,text:i.statusText}}}else {let i=yield this.client[t](e,c.data,D(x({},c),{params:c.params}));return {data:i.data,headers:F(i.headers),status:{code:i.status,text:i.statusText}}}}catch(c){throw U__default.default.isAxiosError(c)?J(c):new H({info:"An unexpected error occurred",cause:c})}})}stream(t,e,o,n,s){return q(this,null,function*(){try{if(this.isNodeEnvironment()){let i=yield new h(this.client.request({method:e,url:t,headers:n,data:o,responseType:"stream",signal:s==null?void 0:s.abortSignal}));try{for(var p=k(i.data),d,r,c;d=!(r=yield new h(p.next())).done;d=!1){let u=r.value;yield u.toString();}}catch(r){c=[r];}finally{try{d&&(r=p.return)&&(yield new h(r.call(p)));}finally{if(c)throw c[0]}}}else {let i={method:e,headers:new Headers(x({},n)),body:e!=="get"?JSON.stringify(o):void 0,signal:s==null?void 0:s.abortSignal},u=yield new h(fetch(t,i));if(!u.ok){let G=yield new h(u.json());throw new g(`Request failed with status ${u.status}`,u.status,F(u.headers),G)}if(u.body){let G=u.body.getReader();for(;;){let{done:y,value:w}=yield new h(G.read());if(y){yield new TextDecoder().decode(w,{stream:!0});break}yield new TextDecoder().decode(w,{stream:!0});}}else throw new g("Cannot stream the body of the response.",500,{},u)}}catch(i){throw g.isHttpRequestError(i)?i:(i==null?void 0:i.name)==="AbortError"?new g("AbortError",408,{},{}):(i==null?void 0:i.name)==="CanceledError"?new g("AbortError",408,{},{}):U__default.default.isAxiosError(i)?J(i):new H({info:"An unexpected error occurred",cause:i})}})}get(t,e,o){return m(this,null,function*(){return this.makeRequest("get",t,e||{},{headers:o})})}post(t,e,o){return m(this,null,function*(){return this.makeRequest("post",t,e||{},{headers:o})})}put(t,e,o){return m(this,null,function*(){return this.makeRequest("put",t,e||{},{headers:o})})}delete(t,e,o){return m(this,null,function*(){return this.makeRequest("delete",t,e||{},{headers:o})})}patch(t,e,o){return m(this,null,function*(){return this.makeRequest("patch",t,e||{},{headers:o})})}};var He="QueueTaskTimeoutError",Q=class a extends types.GatewayBaseError{constructor({info:t,cause:e}){super({info:t,cause:e},He),this.info=t,this.cause=e,Object.setPrototypeOf(this,new.target.prototype);}static isQueueTaskTimeoutError(t){return t instanceof a}};var X=zod.z.object({maxConcurrentTasks:zod.z.number().int().positive(),retryCount:zod.z.number().int().positive(),timeout:zod.z.number().int().positive(),retry:zod.z.object({initialDelay:zod.z.number().int().positive(),exponentialFactor:zod.z.number().int().positive()})});var v=a=>a instanceof f?a:a instanceof Error?new f(a.message):new f(a),S=()=>typeof window!="undefined"&&typeof window.document!="undefined"&&typeof navigator!="undefined";var ve={error:"color: red",warn:"color: yellow",info:"color: green"},xe=(a,t,...e)=>{if(S())S()&&console.log(`%c[${a.toUpperCase()}] [${t}]`,ve[a],...e);else switch(a){case"error":console.error(...e);break;case"warn":console.warn(...e);break;default:console.log(...e);}},Se=(a,t,...e)=>{var o;S()||((o=process==null?void 0:process.env)==null?void 0:o.DEBUG)==="true"&&xe(a,t,...e);},b=(a,t,...e)=>m(void 0,null,function*(){let o=[];a.forEach(n=>{let s=n[t];if(typeof s=="function")try{let p=s(...e);p instanceof Promise&&o.push(p);}catch(p){Se("error",`SAFELY_INVOKE_CALLBACKS:${String(t)}:`,p);}}),yield Promise.allSettled(o);}),Z=a=>new Promise(t=>setTimeout(t,a));var P=class{constructor(t){this.activeTasks=0;this.queue=[];this.options=t;}enqueue(t){this.queue.push(t),this.processQueue();}withTimeout(t){return new Promise((e,o)=>{let n=setTimeout(()=>o(new Q({info:"Queue task timeout",cause:new Error("Queue task timeout")})),this.options.timeout);t.execute(t.request).then(s=>{clearTimeout(n),e(s);}).catch(s=>{clearTimeout(n),o(s);});})}executeWithRetry(t,e){return m(this,null,function*(){try{return yield this.withTimeout(t)}catch(o){if(e===0)throw o;let n=!0,s=this.options.retry.initialDelay*Math.pow(this.options.retry.exponentialFactor,this.options.retryCount-e);if(g.isHttpRequestError(o)){if(o.cause.status===429){let p=M.safeParse(t.request);if(p.success){let d=p.data.model.getRetryDelay(o.cause.headers);n=d.shouldRetry,d.delayMs>0&&(s=d.delayMs);}}o.cause.status>=500&&o.cause.status<600;}if(n)return yield Z(s),this.executeWithRetry(t,e-1);throw o}})}processQueue(){return m(this,null,function*(){if(this.activeTasks>=this.options.maxConcurrentTasks)return;let t=this.queue.shift();if(t){this.activeTasks+=1;try{let e=yield this.executeWithRetry(t,this.options.retryCount);t.resolve(e);}catch(e){t.reject(e);}finally{this.activeTasks-=1,this.processQueue();}}})}};var O=class{constructor(t=1e3){this.cache=new lruCache.LRUCache({max:t,allowStale:!1,updateAgeOnGet:!1});}getCacheKey(t){return Me__default.default(`${t.prefix}:${t.url}:${t.modelName}:${JSON.stringify(t.data)}`).toString()}get(t){return m(this,null,function*(){return new Promise((e,o)=>{e(this.cache.get(t));})})}set(t,e){return m(this,null,function*(){return new Promise((o,n)=>{this.cache.set(t,e),o();})})}delete(t){return m(this,null,function*(){return new Promise((e,o)=>{this.cache.delete(t),e();})})}clear(){return m(this,null,function*(){return new Promise((t,e)=>{this.cache.clear(),t();})})}};var te=zod.z.object({queueOptions:X.partial().optional(),dangerouslyAllowBrowser:zod.z.boolean().optional(),httpClient:zod.z.custom().optional(),completeChatCache:zod.z.custom().optional(),completeChatCallbacks:zod.z.array(zod.z.custom()).nonempty().optional(),getEmbeddingsCache:zod.z.custom().optional(),getEmbeddingsCallbacks:zod.z.array(zod.z.custom()).nonempty().optional(),streamChatCallbacks:zod.z.array(zod.z.custom()).nonempty().optional()}),Ae=zod.z.object({enableCache:zod.z.boolean().optional().default(!0),metadataForCallbacks:zod.z.any().optional()}),M=zod.z.object({model:zod.z.custom(),config:types.Config(),messages:zod.z.array(types.Message()),tools:zod.z.array(types.Tool()).optional(),options:Ae.optional()}),Fe=zod.z.object({metadataForCallbacks:zod.z.any().optional()}),ae=zod.z.object({model:zod.z.custom(),config:types.Config(),messages:zod.z.array(types.Message()),tools:zod.z.array(types.Tool()).optional(),options:Fe.optional()}),je=zod.z.object({enableCache:zod.z.boolean().optional().default(!0),metadataForCallbacks:zod.z.any().optional()}),L=zod.z.object({model:zod.z.custom(),config:types.Config(),embeddingRequests:types.EmbeddingRequests(),options:je.optional()});var re=zod.z.object({cache:zod.z.custom(),model:zod.z.custom(),config:types.Config(),messages:zod.z.array(types.Message()),tools:zod.z.array(types.Tool()).optional(),enableCache:zod.z.boolean(),callbacks:zod.z.array(zod.z.custom()).nonempty().optional(),metadataForCallbacks:zod.z.any().optional()}),Et=zod.z.object({request:zod.z.object({config:types.Config(),messages:zod.z.array(types.Message()),tools:zod.z.array(types.Tool()).optional()}),response:types.ChatResponse,cached:zod.z.boolean(),latencyInMs:zod.z.number().int().positive(),metadataForCallbacks:zod.z.any().optional(),provider:zod.z.object({request:zod.z.any(),response:zod.z.any()})});function ie(a,t){return m(this,null,function*(){let e=re.parse(a),o=a.callbacks||[];try{b(o,"onChatStart",a.metadataForCallbacks);let n={config:e.config,messages:e.messages,tools:e.tools},s={url:yield e.model.getCompleteChatUrl(e.config,e.messages,e.tools),headers:yield e.model.getCompleteChatHeaders(e.config,e.messages,e.tools),data:yield e.model.getCompleteChatData(e.config,e.messages,e.tools)},p=a.cache.getCacheKey({prefix:"complete-chat",url:s.url,modelName:e.model.modelSchema.name,data:n});if(e.enableCache){let u=yield a.cache.get(p);if(u)return u.cached=!0,b(o,"onChatCached",a.metadataForCallbacks,u),u}let d=Date.now(),r=yield t.post(s.url,s.data,s.headers),c=Date.now()-d,i={request:n,response:e.model.transformCompleteChatResponse(r.data),cached:!1,latencyInMs:c,metadataForCallbacks:a.metadataForCallbacks,provider:{request:s,response:r}};return e.enableCache&&(yield a.cache.set(p,i)),b(o,"onChatComplete",a.metadataForCallbacks,i),i}catch(n){let s;throw g.isHttpRequestError(n)||n instanceof f?s=n:s=v(n),b(o,"onChatError",a.metadataForCallbacks,s),s}})}var ce=zod.z.object({cache:zod.z.custom(),model:zod.z.custom(),config:types.Config(),embeddingRequests:types.EmbeddingRequests(),enableCache:zod.z.boolean(),callbacks:zod.z.array(zod.z.custom()).nonempty().optional(),metadataForCallbacks:zod.z.any().optional()}),It=zod.z.object({request:zod.z.object({config:types.Config(),embeddingRequests:types.EmbeddingRequests()}),response:types.EmbeddingResponse,cached:zod.z.boolean(),latencyInMs:zod.z.number().int().positive(),metadataForCallbacks:zod.z.any().optional(),provider:zod.z.object({request:zod.z.any(),response:zod.z.any()})});function de(a,t){return m(this,null,function*(){let e=ce.parse(a),o=a.callbacks||[];try{b(o,"onGetEmbeddingsStart",a.metadataForCallbacks);let n={config:e.config,embeddingRequests:e.embeddingRequests},s={url:yield e.model.getGetEmbeddingsUrl(e.config,e.embeddingRequests),headers:yield e.model.getGetEmbeddingsHeaders(e.config,e.embeddingRequests),data:yield e.model.getGetEmbeddingsData(e.config,e.embeddingRequests)},p=a.cache.getCacheKey({prefix:"get-embeddings",url:s.url,modelName:e.model.modelSchema.name,data:n});if(e.enableCache){let u=yield a.cache.get(p);if(u)return u.cached=!0,b(o,"onGetEmbeddingsCached",a.metadataForCallbacks,u),u}let d=Date.now(),r=yield t.post(s.url,s.data,s.headers),c=Date.now()-d,i={request:n,response:e.model.transformGetEmbeddingsResponse(r.data),cached:!1,latencyInMs:c,metadataForCallbacks:a.metadataForCallbacks,provider:{request:s,response:r}};return e.enableCache&&(yield a.cache.set(p,i)),b(o,"onGetEmbeddingsComplete",a.metadataForCallbacks,i),i}catch(n){let s;throw g.isHttpRequestError(n)||n instanceof f?s=n:s=v(n),b(o,"onGetEmbeddingsError",a.metadataForCallbacks,s),s}})}var he=zod.z.object({model:zod.z.custom(),config:types.Config(),messages:zod.z.array(types.Message()),tools:zod.z.array(types.Tool()).optional(),callbacks:zod.z.array(zod.z.custom()).nonempty().optional(),metadataForCallbacks:zod.z.any().optional()}),Zt=zod.z.object({request:zod.z.object({config:types.Config(),messages:zod.z.array(types.Message()),tools:zod.z.array(types.Tool()).optional()}),response:types.PartialChatResponse,metadataForCallbacks:zod.z.any().optional(),provider:zod.z.object({request:zod.z.any(),response:zod.z.any()})});function Ce(a,t){return q(this,null,function*(){let e=he.parse(a),o=a.callbacks||[],n={config:e.config,messages:e.messages,tools:e.tools};try{b(o,"onStreamStart",a.metadataForCallbacks);let y={url:yield new h(e.model.getStreamChatUrl(e.config,e.messages,e.tools)),headers:yield new h(e.model.getStreamChatHeaders(e.config,e.messages,e.tools)),data:yield new h(e.model.getStreamChatData(e.config,e.messages,e.tools))},w="",A=!0;try{for(var c=k(t.stream(y.url,"post",y.data,y.headers)),i,u,G;i=!(u=yield new h(c.next())).done;i=!1){let I=u.value;try{for(var s=k(e.model.transformStreamChatResponseChunk(I,w)),p,d,r;p=!(d=yield new h(s.next())).done;p=!1){let fe=d.value;let K={request:n,response:fe.partialResponse,metadataForCallbacks:a.metadataForCallbacks,provider:{request:y,response:I}};b(o,A?"onStreamFirstResponse":"onStreamNewResponse",a.metadataForCallbacks,K),A&&(A=!1),yield K;}}catch(d){r=[d];}finally{try{p&&(d=s.return)&&(yield new h(d.call(s)));}finally{if(r)throw r[0]}}}}catch(u){G=[u];}finally{try{i&&(u=c.return)&&(yield new h(u.call(c)));}finally{if(G)throw G[0]}}b(o,"onStreamEnd",a.metadataForCallbacks);}catch(y){let w;throw y instanceof f?w=y:w=v(y),b(o,"onStreamError",a.metadataForCallbacks,w),w}})}var B=class{constructor(t){var o,n,s,p;if(!t.dangerouslyAllowBrowser&&S())throw new f(`It looks like you're running in a browser-like environment.
|
|
16
16
|
|
|
17
17
|
This is disabled by default, as it risks exposing your provider secrets to attackers.
|
|
18
18
|
If you understand the risks and have appropriate mitigation in place,
|
|
19
19
|
you can set the \`dangerouslyAllowBrowser\` option to \`true\`.
|
|
20
|
-
`);this.options=
|
|
20
|
+
`);this.options=te.parse(t);let e={maxConcurrentTasks:((o=this.options.queueOptions)==null?void 0:o.maxConcurrentTasks)||4,retryCount:((n=this.options.queueOptions)==null?void 0:n.retryCount)||3,retry:((s=this.options.queueOptions)==null?void 0:s.retry)||{initialDelay:1e3,exponentialFactor:2},timeout:((p=this.options.queueOptions)==null?void 0:p.timeout)||9e4};this.queues={completeChat:new P(e),getEmbeddings:new P(e)},this.httpClient=t.httpClient||new j({timeoutInMilliseconds:e.timeout*.9}),this.caches={completeChat:t.completeChatCache||new O,getEmbeddings:t.getEmbeddingsCache||new O};}completeChat(t){return m(this,null,function*(){let e=M.parse(t);return new Promise((o,n)=>{let s={request:e,cache:this.caches.completeChat,resolve:o,reject:n,execute:this.executeCompleteChat.bind(this)};this.queues.completeChat.enqueue(s);})})}executeCompleteChat(t){return m(this,null,function*(){var o,n,s;let e=M.parse(t);return ie({cache:this.caches.completeChat,model:e.model,config:e.config,messages:e.messages,tools:e.tools,enableCache:(n=(o=e.options)==null?void 0:o.enableCache)!=null?n:!0,callbacks:this.options.completeChatCallbacks,metadataForCallbacks:(s=e.options)==null?void 0:s.metadataForCallbacks},this.httpClient)})}streamChat(t){return q(this,null,function*(){var e,d;try{let r=ae.parse(t);try{for(var o=k(Ce({model:r.model,config:r.config,messages:r.messages,tools:r.tools,callbacks:this.options.streamChatCallbacks,metadataForCallbacks:(e=r.options)==null?void 0:e.metadataForCallbacks},this.httpClient)),n,s,p;n=!(s=yield new h(o.next())).done;n=!1){let c=s.value;yield c;}}catch(s){p=[s];}finally{try{n&&(s=o.return)&&(yield new h(s.call(o)));}finally{if(p)throw p[0]}}}catch(r){throw r instanceof f?r:new f(r==null?void 0:r.message,500,(d=r==null?void 0:r.response)==null?void 0:d.data)}})}getEmbeddings(t){return m(this,null,function*(){let e=L.parse(t);return new Promise((o,n)=>{let s={request:e,cache:this.caches.getEmbeddings,resolve:o,reject:n,execute:this.executeGetEmbeddingsTask.bind(this)};this.queues.getEmbeddings.enqueue(s);})})}executeGetEmbeddingsTask(t){return m(this,null,function*(){var o,n,s;let e=L.parse(t);return de({cache:this.caches.getEmbeddings,model:e.model,config:e.config,embeddingRequests:e.embeddingRequests,enableCache:(n=(o=e.options)==null?void 0:o.enableCache)!=null?n:!0,callbacks:this.options.getEmbeddingsCallbacks,metadataForCallbacks:(s=e.options)==null?void 0:s.metadataForCallbacks},this.httpClient)})}};B.GatewayError=f;
|
|
21
21
|
|
|
22
|
-
exports.CompleteChatHandlerRequest =
|
|
22
|
+
exports.CompleteChatHandlerRequest = re;
|
|
23
23
|
exports.CompleteChatHandlerResponse = Et;
|
|
24
|
-
exports.Gateway =
|
|
25
|
-
exports.GatewayError =
|
|
26
|
-
exports.GetEmbeddingsHandlerRequest =
|
|
24
|
+
exports.Gateway = B;
|
|
25
|
+
exports.GatewayError = f;
|
|
26
|
+
exports.GetEmbeddingsHandlerRequest = ce;
|
|
27
27
|
exports.GetEmbeddingsHandlerResponse = It;
|
|
28
28
|
exports.HttpClientError = H;
|
|
29
|
-
exports.HttpRequestError =
|
|
30
|
-
exports.IsomorphicHttpClient =
|
|
29
|
+
exports.HttpRequestError = g;
|
|
30
|
+
exports.IsomorphicHttpClient = j;
|
|
31
31
|
exports.LRUCache = O;
|
|
32
|
-
exports.QueueOptions =
|
|
33
|
-
exports.QueueTaskTimeoutError =
|
|
32
|
+
exports.QueueOptions = X;
|
|
33
|
+
exports.QueueTaskTimeoutError = Q;
|
|
34
34
|
exports.SimpleQueue = P;
|
|
35
|
-
exports.StreamChatHandlerRequest =
|
|
35
|
+
exports.StreamChatHandlerRequest = he;
|
|
36
36
|
exports.StreamChatHandlerResponse = Zt;
|
|
37
|
-
exports.handleCompleteChat =
|
|
38
|
-
exports.handleGetEmbeddings =
|
|
39
|
-
exports.handleStreamChat =
|
|
37
|
+
exports.handleCompleteChat = ie;
|
|
38
|
+
exports.handleGetEmbeddings = de;
|
|
39
|
+
exports.handleStreamChat = Ce;
|
|
40
40
|
//# sourceMappingURL=index.js.map
|
|
41
41
|
//# sourceMappingURL=index.js.map
|