@adaline/gateway 0.9.0 → 0.10.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 +24 -13
- package/dist/index.d.ts +24 -13
- package/dist/index.js +10 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -83,19 +83,19 @@ declare class QueueTaskTimeoutError extends GatewayBaseError {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
interface Cache<T> {
|
|
86
|
-
get(key: string): T | undefined
|
|
87
|
-
set(key: string, value: T): void
|
|
88
|
-
delete(key: string): void
|
|
89
|
-
clear(): void
|
|
86
|
+
get(key: string): Promise<T | undefined>;
|
|
87
|
+
set(key: string, value: T): Promise<void>;
|
|
88
|
+
delete(key: string): Promise<void>;
|
|
89
|
+
clear(): Promise<void>;
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
declare class LRUCache<T extends object> implements Cache<T> {
|
|
93
93
|
private cache;
|
|
94
94
|
constructor(maxEntries?: number);
|
|
95
|
-
get(key: string): T | undefined
|
|
96
|
-
set(key: string, value: T): void
|
|
97
|
-
delete(key: string): void
|
|
98
|
-
clear(): void
|
|
95
|
+
get(key: string): Promise<T | undefined>;
|
|
96
|
+
set(key: string, value: T): Promise<void>;
|
|
97
|
+
delete(key: string): Promise<void>;
|
|
98
|
+
clear(): Promise<void>;
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
type QueueTask<Request, Response> = {
|
|
@@ -702,6 +702,7 @@ declare const CompleteChatHandlerRequest: z.ZodObject<{
|
|
|
702
702
|
};
|
|
703
703
|
metadata?: any;
|
|
704
704
|
}>]>, "many">>;
|
|
705
|
+
enableCache: z.ZodBoolean;
|
|
705
706
|
callbacks: z.ZodOptional<z.ZodArray<z.ZodType<CompleteChatCallbackType<any>, z.ZodTypeDef, CompleteChatCallbackType<any>>, "atleastone">>;
|
|
706
707
|
metadataForCallbacks: z.ZodOptional<z.ZodAny>;
|
|
707
708
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -787,6 +788,7 @@ declare const CompleteChatHandlerRequest: z.ZodObject<{
|
|
|
787
788
|
})[];
|
|
788
789
|
metadata?: undefined;
|
|
789
790
|
}[];
|
|
791
|
+
enableCache: boolean;
|
|
790
792
|
cache: Cache<{
|
|
791
793
|
request: {
|
|
792
794
|
config: Record<string, any>;
|
|
@@ -995,6 +997,7 @@ declare const CompleteChatHandlerRequest: z.ZodObject<{
|
|
|
995
997
|
})[];
|
|
996
998
|
metadata?: undefined;
|
|
997
999
|
}[];
|
|
1000
|
+
enableCache: boolean;
|
|
998
1001
|
cache: Cache<{
|
|
999
1002
|
request: {
|
|
1000
1003
|
config: Record<string, any>;
|
|
@@ -2230,6 +2233,7 @@ declare const GetEmbeddingsHandlerRequest: z.ZodObject<{
|
|
|
2230
2233
|
requests: number[][];
|
|
2231
2234
|
metadata?: undefined;
|
|
2232
2235
|
}>]>;
|
|
2236
|
+
enableCache: z.ZodBoolean;
|
|
2233
2237
|
callbacks: z.ZodOptional<z.ZodArray<z.ZodType<GetEmbeddingsCallbackType<any>, z.ZodTypeDef, GetEmbeddingsCallbackType<any>>, "atleastone">>;
|
|
2234
2238
|
metadataForCallbacks: z.ZodOptional<z.ZodAny>;
|
|
2235
2239
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -2279,6 +2283,7 @@ declare const GetEmbeddingsHandlerRequest: z.ZodObject<{
|
|
|
2279
2283
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
2280
2284
|
};
|
|
2281
2285
|
}>;
|
|
2286
|
+
enableCache: boolean;
|
|
2282
2287
|
cache: Cache<{
|
|
2283
2288
|
request: {
|
|
2284
2289
|
config: Record<string, any>;
|
|
@@ -2377,6 +2382,7 @@ declare const GetEmbeddingsHandlerRequest: z.ZodObject<{
|
|
|
2377
2382
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
2378
2383
|
};
|
|
2379
2384
|
}>;
|
|
2385
|
+
enableCache: boolean;
|
|
2380
2386
|
cache: Cache<{
|
|
2381
2387
|
request: {
|
|
2382
2388
|
config: Record<string, any>;
|
|
@@ -4909,10 +4915,13 @@ declare const GatewayCompleteChatRequest: z.ZodObject<{
|
|
|
4909
4915
|
metadata?: any;
|
|
4910
4916
|
}>]>, "many">>;
|
|
4911
4917
|
options: z.ZodOptional<z.ZodObject<{
|
|
4918
|
+
enableCache: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
4912
4919
|
metadataForCallbacks: z.ZodOptional<z.ZodAny>;
|
|
4913
4920
|
}, "strip", z.ZodTypeAny, {
|
|
4921
|
+
enableCache: boolean;
|
|
4914
4922
|
metadataForCallbacks?: any;
|
|
4915
4923
|
}, {
|
|
4924
|
+
enableCache?: boolean | undefined;
|
|
4916
4925
|
metadataForCallbacks?: any;
|
|
4917
4926
|
}>>;
|
|
4918
4927
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -4999,6 +5008,7 @@ declare const GatewayCompleteChatRequest: z.ZodObject<{
|
|
|
4999
5008
|
metadata?: undefined;
|
|
5000
5009
|
}[];
|
|
5001
5010
|
options?: {
|
|
5011
|
+
enableCache: boolean;
|
|
5002
5012
|
metadataForCallbacks?: any;
|
|
5003
5013
|
} | undefined;
|
|
5004
5014
|
tools?: {
|
|
@@ -5097,6 +5107,7 @@ declare const GatewayCompleteChatRequest: z.ZodObject<{
|
|
|
5097
5107
|
metadata?: undefined;
|
|
5098
5108
|
}[];
|
|
5099
5109
|
options?: {
|
|
5110
|
+
enableCache?: boolean | undefined;
|
|
5100
5111
|
metadataForCallbacks?: any;
|
|
5101
5112
|
} | undefined;
|
|
5102
5113
|
tools?: {
|
|
@@ -5764,14 +5775,14 @@ declare const GatewayGetEmbeddingsRequest: z.ZodObject<{
|
|
|
5764
5775
|
metadata?: undefined;
|
|
5765
5776
|
}>]>;
|
|
5766
5777
|
options: z.ZodOptional<z.ZodObject<{
|
|
5767
|
-
|
|
5778
|
+
enableCache: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
5768
5779
|
metadataForCallbacks: z.ZodOptional<z.ZodAny>;
|
|
5769
5780
|
}, "strip", z.ZodTypeAny, {
|
|
5781
|
+
enableCache: boolean;
|
|
5770
5782
|
metadataForCallbacks?: any;
|
|
5771
|
-
queuePriority?: number | undefined;
|
|
5772
5783
|
}, {
|
|
5784
|
+
enableCache?: boolean | undefined;
|
|
5773
5785
|
metadataForCallbacks?: any;
|
|
5774
|
-
queuePriority?: number | undefined;
|
|
5775
5786
|
}>>;
|
|
5776
5787
|
}, "strip", z.ZodTypeAny, {
|
|
5777
5788
|
config: Record<string, any>;
|
|
@@ -5830,8 +5841,8 @@ declare const GatewayGetEmbeddingsRequest: z.ZodObject<{
|
|
|
5830
5841
|
metadata?: undefined;
|
|
5831
5842
|
};
|
|
5832
5843
|
options?: {
|
|
5844
|
+
enableCache: boolean;
|
|
5833
5845
|
metadataForCallbacks?: any;
|
|
5834
|
-
queuePriority?: number | undefined;
|
|
5835
5846
|
} | undefined;
|
|
5836
5847
|
}, {
|
|
5837
5848
|
config: Record<string, any>;
|
|
@@ -5890,8 +5901,8 @@ declare const GatewayGetEmbeddingsRequest: z.ZodObject<{
|
|
|
5890
5901
|
metadata?: undefined;
|
|
5891
5902
|
};
|
|
5892
5903
|
options?: {
|
|
5904
|
+
enableCache?: boolean | undefined;
|
|
5893
5905
|
metadataForCallbacks?: any;
|
|
5894
|
-
queuePriority?: number | undefined;
|
|
5895
5906
|
} | undefined;
|
|
5896
5907
|
}>;
|
|
5897
5908
|
type GatewayGetEmbeddingsRequestType = z.infer<typeof GatewayGetEmbeddingsRequest>;
|
package/dist/index.d.ts
CHANGED
|
@@ -83,19 +83,19 @@ declare class QueueTaskTimeoutError extends GatewayBaseError {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
interface Cache<T> {
|
|
86
|
-
get(key: string): T | undefined
|
|
87
|
-
set(key: string, value: T): void
|
|
88
|
-
delete(key: string): void
|
|
89
|
-
clear(): void
|
|
86
|
+
get(key: string): Promise<T | undefined>;
|
|
87
|
+
set(key: string, value: T): Promise<void>;
|
|
88
|
+
delete(key: string): Promise<void>;
|
|
89
|
+
clear(): Promise<void>;
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
declare class LRUCache<T extends object> implements Cache<T> {
|
|
93
93
|
private cache;
|
|
94
94
|
constructor(maxEntries?: number);
|
|
95
|
-
get(key: string): T | undefined
|
|
96
|
-
set(key: string, value: T): void
|
|
97
|
-
delete(key: string): void
|
|
98
|
-
clear(): void
|
|
95
|
+
get(key: string): Promise<T | undefined>;
|
|
96
|
+
set(key: string, value: T): Promise<void>;
|
|
97
|
+
delete(key: string): Promise<void>;
|
|
98
|
+
clear(): Promise<void>;
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
type QueueTask<Request, Response> = {
|
|
@@ -702,6 +702,7 @@ declare const CompleteChatHandlerRequest: z.ZodObject<{
|
|
|
702
702
|
};
|
|
703
703
|
metadata?: any;
|
|
704
704
|
}>]>, "many">>;
|
|
705
|
+
enableCache: z.ZodBoolean;
|
|
705
706
|
callbacks: z.ZodOptional<z.ZodArray<z.ZodType<CompleteChatCallbackType<any>, z.ZodTypeDef, CompleteChatCallbackType<any>>, "atleastone">>;
|
|
706
707
|
metadataForCallbacks: z.ZodOptional<z.ZodAny>;
|
|
707
708
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -787,6 +788,7 @@ declare const CompleteChatHandlerRequest: z.ZodObject<{
|
|
|
787
788
|
})[];
|
|
788
789
|
metadata?: undefined;
|
|
789
790
|
}[];
|
|
791
|
+
enableCache: boolean;
|
|
790
792
|
cache: Cache<{
|
|
791
793
|
request: {
|
|
792
794
|
config: Record<string, any>;
|
|
@@ -995,6 +997,7 @@ declare const CompleteChatHandlerRequest: z.ZodObject<{
|
|
|
995
997
|
})[];
|
|
996
998
|
metadata?: undefined;
|
|
997
999
|
}[];
|
|
1000
|
+
enableCache: boolean;
|
|
998
1001
|
cache: Cache<{
|
|
999
1002
|
request: {
|
|
1000
1003
|
config: Record<string, any>;
|
|
@@ -2230,6 +2233,7 @@ declare const GetEmbeddingsHandlerRequest: z.ZodObject<{
|
|
|
2230
2233
|
requests: number[][];
|
|
2231
2234
|
metadata?: undefined;
|
|
2232
2235
|
}>]>;
|
|
2236
|
+
enableCache: z.ZodBoolean;
|
|
2233
2237
|
callbacks: z.ZodOptional<z.ZodArray<z.ZodType<GetEmbeddingsCallbackType<any>, z.ZodTypeDef, GetEmbeddingsCallbackType<any>>, "atleastone">>;
|
|
2234
2238
|
metadataForCallbacks: z.ZodOptional<z.ZodAny>;
|
|
2235
2239
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -2279,6 +2283,7 @@ declare const GetEmbeddingsHandlerRequest: z.ZodObject<{
|
|
|
2279
2283
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
2280
2284
|
};
|
|
2281
2285
|
}>;
|
|
2286
|
+
enableCache: boolean;
|
|
2282
2287
|
cache: Cache<{
|
|
2283
2288
|
request: {
|
|
2284
2289
|
config: Record<string, any>;
|
|
@@ -2377,6 +2382,7 @@ declare const GetEmbeddingsHandlerRequest: z.ZodObject<{
|
|
|
2377
2382
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
2378
2383
|
};
|
|
2379
2384
|
}>;
|
|
2385
|
+
enableCache: boolean;
|
|
2380
2386
|
cache: Cache<{
|
|
2381
2387
|
request: {
|
|
2382
2388
|
config: Record<string, any>;
|
|
@@ -4909,10 +4915,13 @@ declare const GatewayCompleteChatRequest: z.ZodObject<{
|
|
|
4909
4915
|
metadata?: any;
|
|
4910
4916
|
}>]>, "many">>;
|
|
4911
4917
|
options: z.ZodOptional<z.ZodObject<{
|
|
4918
|
+
enableCache: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
4912
4919
|
metadataForCallbacks: z.ZodOptional<z.ZodAny>;
|
|
4913
4920
|
}, "strip", z.ZodTypeAny, {
|
|
4921
|
+
enableCache: boolean;
|
|
4914
4922
|
metadataForCallbacks?: any;
|
|
4915
4923
|
}, {
|
|
4924
|
+
enableCache?: boolean | undefined;
|
|
4916
4925
|
metadataForCallbacks?: any;
|
|
4917
4926
|
}>>;
|
|
4918
4927
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -4999,6 +5008,7 @@ declare const GatewayCompleteChatRequest: z.ZodObject<{
|
|
|
4999
5008
|
metadata?: undefined;
|
|
5000
5009
|
}[];
|
|
5001
5010
|
options?: {
|
|
5011
|
+
enableCache: boolean;
|
|
5002
5012
|
metadataForCallbacks?: any;
|
|
5003
5013
|
} | undefined;
|
|
5004
5014
|
tools?: {
|
|
@@ -5097,6 +5107,7 @@ declare const GatewayCompleteChatRequest: z.ZodObject<{
|
|
|
5097
5107
|
metadata?: undefined;
|
|
5098
5108
|
}[];
|
|
5099
5109
|
options?: {
|
|
5110
|
+
enableCache?: boolean | undefined;
|
|
5100
5111
|
metadataForCallbacks?: any;
|
|
5101
5112
|
} | undefined;
|
|
5102
5113
|
tools?: {
|
|
@@ -5764,14 +5775,14 @@ declare const GatewayGetEmbeddingsRequest: z.ZodObject<{
|
|
|
5764
5775
|
metadata?: undefined;
|
|
5765
5776
|
}>]>;
|
|
5766
5777
|
options: z.ZodOptional<z.ZodObject<{
|
|
5767
|
-
|
|
5778
|
+
enableCache: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
5768
5779
|
metadataForCallbacks: z.ZodOptional<z.ZodAny>;
|
|
5769
5780
|
}, "strip", z.ZodTypeAny, {
|
|
5781
|
+
enableCache: boolean;
|
|
5770
5782
|
metadataForCallbacks?: any;
|
|
5771
|
-
queuePriority?: number | undefined;
|
|
5772
5783
|
}, {
|
|
5784
|
+
enableCache?: boolean | undefined;
|
|
5773
5785
|
metadataForCallbacks?: any;
|
|
5774
|
-
queuePriority?: number | undefined;
|
|
5775
5786
|
}>>;
|
|
5776
5787
|
}, "strip", z.ZodTypeAny, {
|
|
5777
5788
|
config: Record<string, any>;
|
|
@@ -5830,8 +5841,8 @@ declare const GatewayGetEmbeddingsRequest: z.ZodObject<{
|
|
|
5830
5841
|
metadata?: undefined;
|
|
5831
5842
|
};
|
|
5832
5843
|
options?: {
|
|
5844
|
+
enableCache: boolean;
|
|
5833
5845
|
metadataForCallbacks?: any;
|
|
5834
|
-
queuePriority?: number | undefined;
|
|
5835
5846
|
} | undefined;
|
|
5836
5847
|
}, {
|
|
5837
5848
|
config: Record<string, any>;
|
|
@@ -5890,8 +5901,8 @@ declare const GatewayGetEmbeddingsRequest: z.ZodObject<{
|
|
|
5890
5901
|
metadata?: undefined;
|
|
5891
5902
|
};
|
|
5892
5903
|
options?: {
|
|
5904
|
+
enableCache?: boolean | undefined;
|
|
5893
5905
|
metadataForCallbacks?: any;
|
|
5894
|
-
queuePriority?: number | undefined;
|
|
5895
5906
|
} | undefined;
|
|
5896
5907
|
}>;
|
|
5897
5908
|
type GatewayGetEmbeddingsRequestType = z.infer<typeof GatewayGetEmbeddingsRequest>;
|
package/dist/index.js
CHANGED
|
@@ -12,30 +12,30 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
12
12
|
var V__default = /*#__PURE__*/_interopDefault(V);
|
|
13
13
|
var xe__default = /*#__PURE__*/_interopDefault(xe);
|
|
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 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 m=(a,t,e)=>new Promise((s,n)=>{var o=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?s(r.value):Promise.resolve(r.value).then(o,p);d((e=e.apply(a,t)).next());}),h=function(a,t){this[0]=a,this[1]=t;},q=(a,t,e)=>{var s=(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?s(p==="return"?p:"next",d[1]?{done:y.done,value:y.value}:y,r,c):r({value:y,done:G})).catch(y=>s("throw",y,r,c));}catch(y){c(y);}},n=p=>o[p]=d=>new Promise((r,c)=>s(p,d,r,c)),o={};return e=e.apply(a,t),o[D("asyncIterator")]=()=>o,n("next"),n("throw"),n("return"),o};var k=(a,t,e)=>(t=a[D("asyncIterator")])?t.call(a):(a=a[D("iterator")](),t={},e=(s,n)=>(n=a[s])&&(t[s]=o=>new Promise((p,d,r)=>(o=n.call(a,o),r=o.done,Promise.resolve(o.value).then(c=>p({value:c,done:r}),d)))),e("next"),e("return"),t);var f=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",g=class a extends types.GatewayBaseError{constructor(t,e=500,s,n){super({info:t,cause:{status:e,headers:s,data:n}},Ge),this.info=t,this.cause={status:e,headers:s,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,s])=>{Array.isArray(s)?t[e]=s.join(", "):typeof s=="string"?t[e]=s:t[e]="";}),t},X=a=>{var o,p,d;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((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,s,n)},j=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 n=zod.z.number().int().positive().optional();if(this.defaultTimeout=n.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(p,d,r){return m(this,arguments,function*(t,e,s,n={},o){try{let c=U(x(x({},t==="get"||t==="delete"?{params:s}:{data:s}),n),{timeout:o||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,U(x({},c),{params:c.params}));return {data:i.data,headers:F(i.headers),status:{code:i.status,text:i.statusText}}}}catch(c){throw V__default.default.isAxiosError(c)?X(c):new H({info:"An unexpected error occurred",cause:c})}})}stream(t,e,s,n,o){return q(this,null,function*(){try{if(this.isNodeEnvironment()){let i=yield new h(this.client.request({method:e,url:t,headers:n,data:s,responseType:"stream",signal:o==null?void 0:o.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(s):void 0,signal:o==null?void 0:o.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,{},{}):V__default.default.isAxiosError(i)?X(i):new H({info:"An unexpected error occurred",cause:i})}})}get(t,e,s){return m(this,null,function*(){return this.makeRequest("get",t,e||{},{headers:s})})}post(t,e,s){return m(this,null,function*(){return this.makeRequest("post",t,e||{},{headers:s})})}put(t,e,s){return m(this,null,function*(){return this.makeRequest("put",t,e||{},{headers:s})})}delete(t,e,s){return m(this,null,function*(){return this.makeRequest("delete",t,e||{},{headers:s})})}patch(t,e,s){return m(this,null,function*(){return this.makeRequest("patch",t,e||{},{headers:s})})}};var ve="QueueTaskTimeoutError",Q=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 f?a:a instanceof Error?new f(a.message):new f(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)=>m(void 0,null,function*(){let s=[];a.forEach(n=>{let o=n[t];if(typeof o=="function")try{let p=o(...e);p instanceof Promise&&s.push(p);}catch(p){Me("error",`SAFELY_INVOKE_CALLBACKS:${String(t)}:`,p);}}),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 n=setTimeout(()=>s(new Q({info:"Queue task timeout",cause:new Error("Queue task timeout")})),this.options.timeout);t.execute(t.request).then(o=>{clearTimeout(n),e(o);}).catch(o=>{clearTimeout(n),s(o);});})}executeWithRetry(t,e){return m(this,null,function*(){try{return yield this.withTimeout(t)}catch(s){if(e===0)throw s;let n=!0,o=this.options.retry.initialDelay*Math.pow(this.options.retry.exponentialFactor,this.options.retryCount-e);if(g.isHttpRequestError(s)){if(s.cause.status===429){let p=M.safeParse(t.request);if(p.success){let d=p.data.model.getRetryDelay(s.cause.headers);n=d.shouldRetry,d.delayMs>0&&(o=d.delayMs);}}s.cause.status>=500&&s.cause.status<600;}if(n)return yield _(o),this.executeWithRetry(t,e-1);throw s}})}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});}get(t){return m(this,null,function*(){return new Promise((e,s)=>{e(this.cache.get(t));})})}set(t,e){return m(this,null,function*(){return new Promise((s,n)=>{this.cache.set(t,e),s();})})}delete(t){return m(this,null,function*(){return new Promise((e,s)=>{this.cache.delete(t),e();})})}clear(){return m(this,null,function*(){return new Promise((t,e)=>{this.cache.clear(),t();})})}};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({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:Fe.optional()}),je=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:je.optional()}),Qe=zod.z.object({enableCache:zod.z.boolean().optional().default(!0),metadataForCallbacks:zod.z.any().optional()}),B=zod.z.object({model:zod.z.custom(),config:types.Config(),embeddingRequests:types.EmbeddingRequests(),options:Qe.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(),enableCache:zod.z.boolean(),callbacks:zod.z.array(zod.z.custom()).nonempty().optional(),metadataForCallbacks:zod.z.any().optional()}),Gt=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 m(this,null,function*(){let e=ie.parse(a),s=a.callbacks||[];try{b(s,"onChatStart",a.metadataForCallbacks);let n={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)},p=I(`complete-chat:${o.url}:${e.model.modelSchema.name}`,n);if(e.enableCache){let u=yield a.cache.get(p);if(u)return u.cached=!0,b(s,"onChatCached",a.metadataForCallbacks,u),u}let d=Date.now(),r=yield t.post(o.url,o.data,o.headers),c=Date.now()-d,i={request:n,response:e.model.transformCompleteChatResponse(r.data),cached:!1,latencyInMs:c,metadataForCallbacks:a.metadataForCallbacks,provider:{request:o,response:r}};return e.enableCache&&(yield a.cache.set(p,i)),b(s,"onChatComplete",a.metadataForCallbacks,i),i}catch(n){let o;throw g.isHttpRequestError(n)||n instanceof f?o=n:o=v(n),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(),enableCache:zod.z.boolean(),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(),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 m(this,null,function*(){let e=de.parse(a),s=a.callbacks||[];try{b(s,"onGetEmbeddingsStart",a.metadataForCallbacks);let n={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)},p=I(`get-embeddings:${o.url}:${e.model.modelSchema.name}`,n);if(e.enableCache){let u=yield a.cache.get(p);if(u)return u.cached=!0,b(s,"onGetEmbeddingsCached",a.metadataForCallbacks,u),u}let d=Date.now(),r=yield t.post(o.url,o.data,o.headers),c=Date.now()-d,i={request:n,response:e.model.transformGetEmbeddingsResponse(r.data),cached:!1,latencyInMs:c,metadataForCallbacks:a.metadataForCallbacks,provider:{request:o,response:r}};return e.enableCache&&(yield a.cache.set(p,i)),b(s,"onGetEmbeddingsComplete",a.metadataForCallbacks,i),i}catch(n){let o;throw g.isHttpRequestError(n)||n instanceof f?o=n:o=v(n),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()}),_t=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 fe(a,t){return q(this,null,function*(){let e=Ce.parse(a),s=a.callbacks||[],n={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)),i,u,G;i=!(u=yield new h(c.next())).done;i=!1){let z=u.value;try{for(var o=k(e.model.transformStreamChatResponseChunk(z,w)),p,d,r;p=!(d=yield new h(o.next())).done;p=!1){let ge=d.value;let $={request:n,response:ge.partialResponse,metadataForCallbacks:a.metadataForCallbacks,provider:{request:y,response:z}};b(s,A?"onStreamFirstResponse":"onStreamNewResponse",a.metadataForCallbacks,$),A&&(A=!1),yield $;}}catch(d){r=[d];}finally{try{p&&(d=o.return)&&(yield new h(d.call(o)));}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(s,"onStreamEnd",a.metadataForCallbacks);}catch(y){let w;throw y instanceof f?w=y:w=v(y),b(s,"onStreamError",a.metadataForCallbacks,w),w}})}var K=class{constructor(t){var s,n,o,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=ae.parse(t);let e={maxConcurrentTasks:((s=this.options.queueOptions)==null?void 0:s.maxConcurrentTasks)||4,retryCount:((
|
|
20
|
+
`);this.options=ae.parse(t);let e={maxConcurrentTasks:((s=this.options.queueOptions)==null?void 0:s.maxConcurrentTasks)||4,retryCount:((n=this.options.queueOptions)==null?void 0:n.retryCount)||3,retry:((o=this.options.queueOptions)==null?void 0:o.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((s,n)=>{let o={request:e,cache:this.caches.completeChat,resolve:s,reject:n,execute:this.executeCompleteChat.bind(this)};this.queues.completeChat.enqueue(o);})})}executeCompleteChat(t){return m(this,null,function*(){var s,n,o;let e=M.parse(t);return pe({cache:this.caches.completeChat,model:e.model,config:e.config,messages:e.messages,tools:e.tools,enableCache:(n=(s=e.options)==null?void 0:s.enableCache)!=null?n:!0,callbacks:this.options.completeChatCallbacks,metadataForCallbacks:(o=e.options)==null?void 0:o.metadataForCallbacks},this.httpClient)})}streamChat(t){return q(this,null,function*(){var e,d;try{let r=se.parse(t);try{for(var s=k(fe({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,o,p;n=!(o=yield new h(s.next())).done;n=!1){let c=o.value;yield c;}}catch(o){p=[o];}finally{try{n&&(o=s.return)&&(yield new h(o.call(s)));}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=B.parse(t);return new Promise((s,n)=>{let o={request:e,cache:this.caches.getEmbeddings,resolve:s,reject:n,execute:this.executeGetEmbeddingsTask.bind(this)};this.queues.getEmbeddings.enqueue(o);})})}executeGetEmbeddingsTask(t){return m(this,null,function*(){var s,n,o;let e=B.parse(t);return me({cache:this.caches.getEmbeddings,model:e.model,config:e.config,embeddingRequests:e.embeddingRequests,enableCache:(n=(s=e.options)==null?void 0:s.enableCache)!=null?n:!0,callbacks:this.options.getEmbeddingsCallbacks,metadataForCallbacks:(o=e.options)==null?void 0:o.metadataForCallbacks},this.httpClient)})}};K.GatewayError=f;
|
|
21
21
|
|
|
22
22
|
exports.CompleteChatHandlerRequest = ie;
|
|
23
|
-
exports.CompleteChatHandlerResponse =
|
|
23
|
+
exports.CompleteChatHandlerResponse = Gt;
|
|
24
24
|
exports.Gateway = K;
|
|
25
|
-
exports.GatewayError =
|
|
25
|
+
exports.GatewayError = f;
|
|
26
26
|
exports.GetEmbeddingsHandlerRequest = de;
|
|
27
|
-
exports.GetEmbeddingsHandlerResponse =
|
|
27
|
+
exports.GetEmbeddingsHandlerResponse = zt;
|
|
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
32
|
exports.QueueOptions = Z;
|
|
33
|
-
exports.QueueTaskTimeoutError =
|
|
33
|
+
exports.QueueTaskTimeoutError = Q;
|
|
34
34
|
exports.SimpleQueue = P;
|
|
35
35
|
exports.StreamChatHandlerRequest = Ce;
|
|
36
|
-
exports.StreamChatHandlerResponse =
|
|
36
|
+
exports.StreamChatHandlerResponse = _t;
|
|
37
37
|
exports.handleCompleteChat = pe;
|
|
38
38
|
exports.handleGetEmbeddings = me;
|
|
39
|
-
exports.handleStreamChat =
|
|
39
|
+
exports.handleStreamChat = fe;
|
|
40
40
|
//# sourceMappingURL=index.js.map
|
|
41
41
|
//# sourceMappingURL=index.js.map
|